dragselect 3.0.2 → 3.0.3

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.
Files changed (51) hide show
  1. package/CHANGELOG.md +5 -1
  2. package/dist/{DragSelect.es6m.js → DragSelect.esm.js} +1 -1
  3. package/dist/DragSelect.js +1 -1
  4. package/package.json +2 -2
  5. package/src/DragSelect.ts +0 -425
  6. package/src/methods/addModificationObservers.ts +0 -51
  7. package/src/methods/canScroll.ts +0 -19
  8. package/src/methods/createSelectorAreaElement.ts +0 -8
  9. package/src/methods/createSelectorElement.ts +0 -13
  10. package/src/methods/debounce.ts +0 -31
  11. package/src/methods/ensureArray.ts +0 -13
  12. package/src/methods/getAllParentNodes.ts +0 -15
  13. package/src/methods/getAreaRect.ts +0 -27
  14. package/src/methods/getCurrentScroll.ts +0 -14
  15. package/src/methods/getDocumentScroll.ts +0 -5
  16. package/src/methods/getOverflowEdges.ts +0 -27
  17. package/src/methods/getPointerPos.ts +0 -9
  18. package/src/methods/getSelectionRect.ts +0 -29
  19. package/src/methods/getSelectorPosition.ts +0 -74
  20. package/src/methods/getStylePosition.spec.ts +0 -114
  21. package/src/methods/getStylePosition.ts +0 -83
  22. package/src/methods/handleElementPositionAttribute.ts +0 -15
  23. package/src/methods/handleKeyboardDragPosDifference.ts +0 -35
  24. package/src/methods/handleSelection.ts +0 -26
  25. package/src/methods/handleUnSelection.ts +0 -36
  26. package/src/methods/hydrateSettings.ts +0 -245
  27. package/src/methods/isCollision.ts +0 -66
  28. package/src/methods/limitDirection.ts +0 -36
  29. package/src/methods/moveElement.ts +0 -18
  30. package/src/methods/scrollElement.ts +0 -26
  31. package/src/methods/setStylePosition.ts +0 -16
  32. package/src/methods/subscriberAliases.ts +0 -240
  33. package/src/methods/updateElementStylePos.ts +0 -7
  34. package/src/methods/vect2.ts +0 -34
  35. package/src/modules/Area.ts +0 -169
  36. package/src/modules/Drag.ts +0 -236
  37. package/src/modules/DropZone.ts +0 -223
  38. package/src/modules/DropZones.ts +0 -151
  39. package/src/modules/Interaction.ts +0 -251
  40. package/src/modules/PubSub.ts +0 -111
  41. package/src/modules/SelectableSet.ts +0 -146
  42. package/src/modules/SelectedSet.ts +0 -92
  43. package/src/modules/Selection.ts +0 -133
  44. package/src/modules/Selector.ts +0 -81
  45. package/src/modules/SelectorArea.ts +0 -161
  46. package/src/stores/KeyStore.ts +0 -92
  47. package/src/stores/PointerStore.ts +0 -194
  48. package/src/stores/ScrollStore.ts +0 -87
  49. package/src/stores/SettingsStore.ts +0 -88
  50. package/src/types.ts +0 -158
  51. /package/dist/{ds.es6m.min.js → ds.esm.min.js} +0 -0
package/CHANGELOG.md CHANGED
@@ -1,4 +1,4 @@
1
- # 3.0.0
1
+ # 3.0.0-3
2
2
 
3
3
  ## Breaking Updates
4
4
 
@@ -41,6 +41,10 @@
41
41
  "DS:removed"
42
42
  ```
43
43
 
44
+ ### Renaming of module files
45
+
46
+ - From `.es6m.` to `.esm.` because that makes more sense
47
+
44
48
  ### Box-Dragging as new default
45
49
 
46
50
  - This is the default expected behaviour, hence if should be the default
@@ -1,6 +1,6 @@
1
1
  /***
2
2
 
3
- ~~~ Version 3.0.2 ~~~
3
+ ~~~ Version 3.0.3 ~~~
4
4
 
5
5
  ******************************************
6
6
 
@@ -1,6 +1,6 @@
1
1
  /***
2
2
 
3
- ~~~ Version 3.0.2 ~~~
3
+ ~~~ Version 3.0.3 ~~~
4
4
 
5
5
  ******************************************
6
6
 
package/package.json CHANGED
@@ -1,8 +1,9 @@
1
1
  {
2
2
  "name": "dragselect",
3
- "version": "3.0.2",
3
+ "version": "3.0.3",
4
4
  "description": "Easy JavaScript library for selecting and moving elements. With no dependencies. Drag-Select & Drag-And-Drop.",
5
5
  "main": "./dist/DragSelect.js",
6
+ "module": "./dist/DragSelect.esm.js",
6
7
  "types": "./dist/DragSelect.d.ts",
7
8
  "scripts": {
8
9
  "open": "open __tests__/quicktest.html -a 'Google Chrome'",
@@ -71,7 +72,6 @@
71
72
  ],
72
73
  "files": [
73
74
  "dist",
74
- "src",
75
75
  "README.md",
76
76
  "LICENSE",
77
77
  "CHANGELOG.md",
package/src/DragSelect.ts DELETED
@@ -1,425 +0,0 @@
1
- /*
2
- ____ _____ __ __
3
- / __ \_________ _____ _/ ___/___ / /__ _____/ /_
4
- / / / / ___/ __ `/ __ `/\__ \/ _ \/ / _ \/ ___/ __/
5
- / /_/ / / / /_/ / /_/ /___/ / __/ / __/ /__/ /_
6
- /_____/_/ \__,_/\__, //____/\___/_/\___/\___/\__/
7
- /____/
8
-
9
- {*} {*} STAR THIS PROJECT ON GITHUB {*} {*}
10
-
11
- https://github.com/ThibaultJanBeyer/DragSelect
12
- Please give it a like, this is what makes me happy :-)
13
- Thank You
14
-
15
- {*} {*} STAR THIS PROJECT ON GITHUB {*} {*}
16
-
17
- ***************************************
18
- ********* GPLv3 / Commercial **********
19
- ***************************************
20
- Created 2017 by ThibaultJanBeyer
21
- Web: http://www.DragSelect.com/
22
- GitHub: https://github.com/ThibaultJanBeyer/DragSelect
23
- ***************************************
24
- */
25
-
26
- import Area from './modules/Area'
27
- import Drag from './modules/Drag'
28
- import DropZones from './modules/DropZones'
29
- import Interaction from './modules/Interaction'
30
- import KeyStore from './stores/KeyStore'
31
- import PointerStore from './stores/PointerStore'
32
- import PubSub, {
33
- type DSCallback,
34
- type DSPublishMappings,
35
- } from './modules/PubSub'
36
- import ScrollStore from './stores/ScrollStore'
37
- import SelectableSet from './modules/SelectableSet'
38
- import SelectedSet from './modules/SelectedSet'
39
- import Selector from './modules/Selector'
40
- import Selection from './modules/Selection'
41
- import SelectorArea from './modules/SelectorArea'
42
- import SettingsStore from './stores/SettingsStore'
43
- import {
44
- type DSCallbackName,
45
- type DSInputElement,
46
- type Settings,
47
- type Vect2,
48
- } from './types'
49
- import { IsCollision, isCollision } from './methods/isCollision'
50
- import {
51
- type DSPublicPublish,
52
- deprecatedNamesMap,
53
- subscriberAliases,
54
- } from './methods/subscriberAliases'
55
- import { ensureArray } from './methods/ensureArray'
56
- import { DSDropZone } from './modules/DropZone'
57
-
58
- // Setup
59
- /// ///////////////////////////////////////////////////////////////////////////////////
60
-
61
- class DragSelect<E extends DSInputElement> {
62
- /** used to skip all current Selection and dragNdrop functionality */
63
- public continue: boolean = false
64
- private PubSub: PubSub<E>
65
- public stores: {
66
- SettingsStore: SettingsStore<E>
67
- PointerStore: PointerStore<E>
68
- ScrollStore: ScrollStore<E>
69
- KeyStore: KeyStore<E>
70
- }
71
- public Area: Area<E>
72
- public Selector: Selector<E>
73
- public SelectorArea: SelectorArea<E>
74
- public SelectableSet: SelectableSet<E>
75
- public SelectedSet: SelectedSet<E>
76
- public Selection: Selection<E>
77
- private Drag: Drag<E>
78
- public DropZones: DropZones<E>
79
- public Interaction: Interaction<E>
80
- public stopped: boolean
81
-
82
- constructor(settings: Settings<E>) {
83
- this.stopped = false
84
-
85
- this.PubSub = new PubSub({ DS: this })
86
-
87
- this.stores = {} as {
88
- SettingsStore: SettingsStore<E>
89
- PointerStore: PointerStore<E>
90
- ScrollStore: ScrollStore<E>
91
- KeyStore: KeyStore<E>
92
- }
93
- ;(this.stores.SettingsStore = new SettingsStore({
94
- settings,
95
- PS: this.PubSub,
96
- })),
97
- (this.stores.PointerStore = new PointerStore({
98
- DS: this,
99
- PS: this.PubSub,
100
- })),
101
- (this.stores.ScrollStore = new ScrollStore({
102
- DS: this,
103
- PS: this.PubSub,
104
- })),
105
- (this.stores.KeyStore = new KeyStore({ DS: this, PS: this.PubSub })),
106
- (this.Area = new Area({ DS: this, PS: this.PubSub }))
107
- this.Selector = new Selector({ DS: this, PS: this.PubSub })
108
- this.SelectorArea = new SelectorArea({ DS: this, PS: this.PubSub })
109
-
110
- this.SelectableSet = new SelectableSet({ DS: this, PS: this.PubSub })
111
- this.SelectedSet = new SelectedSet({ DS: this, PS: this.PubSub })
112
- this.Selection = new Selection({ DS: this, PS: this.PubSub })
113
-
114
- this.Drag = new Drag({ DS: this, PS: this.PubSub })
115
- this.DropZones = new DropZones({ DS: this, PS: this.PubSub })
116
- this.Interaction = new Interaction({ DS: this, PS: this.PubSub })
117
-
118
- subscriberAliases({ DS: this, PS: this.PubSub })
119
-
120
- this.PubSub.subscribe('Interaction:end', () => (this.continue = false))
121
- this.PubSub.subscribe('DS:end', ({ items }) => (this.continue = false))
122
-
123
- this.start()
124
- }
125
-
126
- // Useful methods for the user
127
- //////////////////////////////////////////////////////////////////////////////////////
128
-
129
- public static isCollision: IsCollision
130
-
131
- // any input data from the user is valid in this public PubSub but the exposed values are recommended
132
- /** Subscribe to events */
133
- public subscribe = <T extends keyof DSPublicPublish<E>>(
134
- eventName: T,
135
- callback: DSCallback<DSPublishMappings<E>[T]>
136
- ) => {
137
- // Deprecation warnings
138
- if (deprecatedNamesMap[eventName as keyof typeof deprecatedNamesMap])
139
- console.warn(
140
- `[DragSelect]: The event name "${eventName}" is deprecated and was/will be removed in a future version. Please use the new event name "${
141
- deprecatedNamesMap[eventName as keyof typeof deprecatedNamesMap]
142
- }" instead.`
143
- )
144
-
145
- this.PubSub.subscribe(eventName, callback)
146
- }
147
- /** Un-Subscribe from events */
148
- public unsubscribe = <T extends keyof DSPublicPublish<E>>(
149
- eventName: T,
150
- callback?: DSCallback<DSPublishMappings<E>[T]>,
151
- id?: number
152
- ) => this.PubSub.unsubscribe(eventName, callback, id)
153
- /** Publish events */
154
- public publish = <T extends DSCallbackName<E>>(
155
- eventName: T | T[],
156
- data: DSPublishMappings<E>[T]
157
- ) => this.PubSub.publish(eventName, data)
158
-
159
- /** Initializes the functionality. Automatically triggered when created. Also, reset the functionality after a teardown */
160
- public start = () => {
161
- this.stopped = false
162
- this.Interaction.init()
163
- }
164
-
165
- /**
166
- * Complete function teardown
167
- * Will teardown/stop the whole functionality
168
- * @param remove if elements should be removed.
169
- * @param fromSelection if elements should also be added/removed to the selection.
170
- * @param withCallback if elements should also be added/removed to the selection.
171
- */
172
- public stop(
173
- remove: boolean = true,
174
- fromSelection: boolean = true,
175
- withCallback: boolean = false
176
- ) {
177
- if (withCallback)
178
- this.publish('DS:end', {
179
- items: this.SelectedSet.elements,
180
- isDragging: this.Interaction.isDragging,
181
- })
182
-
183
- this.Interaction.stop()
184
- this.Area.stop()
185
- this.Drag.stop()
186
- this.Selector.stop()
187
- this.SelectorArea.stop(remove)
188
- this.stores.KeyStore.stop()
189
- this.stores.PointerStore.stop()
190
- this.stores.ScrollStore.stop()
191
-
192
- if (remove) this.SelectableSet.clear()
193
- if (fromSelection) this.SelectedSet.clear()
194
-
195
- this.stopped = true
196
- }
197
-
198
- /**
199
- * Utility to override DragSelect internal functionality:
200
- * Break will skip the selection or dragging functionality (until after the callback) but let everything continue to run.
201
- * Useful utility to write your own functionality/move/dragNdrop based on DragSelect pointer positions.
202
- */
203
- public break = () => (this.continue = true)
204
-
205
- /** Update any setting dynamically */
206
- public setSettings = (settings: Settings<E>) =>
207
- this.stores.SettingsStore.update({ settings })
208
-
209
- /** Returns the current selected nodes */
210
- public getSelection = () => this.SelectedSet.elements
211
-
212
- /**
213
- * Adds several elements to the selection list also adds the specific classes and take into account all calculations.
214
- * Does not clear the selection, in contrary to .setSelection. Can add multiple elements at once
215
- * @param elements one or multiple elements
216
- * @param triggerCallback if callback should be called
217
- * @param dontAddToSelectables if element should not be added to the list of selectable elements
218
- * @return all selected elements
219
- */
220
- public addSelection(
221
- elements: E | E[],
222
- triggerCallback: boolean = false,
223
- dontAddToSelectables: boolean = false
224
- ) {
225
- const els = ensureArray(elements)
226
- this.SelectedSet.addAll(els)
227
- if (!dontAddToSelectables) this.addSelectables(elements, false, false)
228
- if (triggerCallback)
229
- this.PubSub.publish('DS:end', {
230
- items: this.SelectedSet.elements,
231
- isDragging: this.Interaction.isDragging,
232
- })
233
- return this.getSelection()
234
- }
235
-
236
- /**
237
- * Removes specific elements from the selection
238
- * Multiple elements can be given at once, in contrary to unselect
239
- * @param elements one or multiple elements
240
- * @param triggerCallback if callback should be called
241
- * @param removeFromSelectables if element should be removed from the list of selectable elements
242
- * @return all selected elements
243
- */
244
- public removeSelection(
245
- elements: E | E[],
246
- triggerCallback: boolean = false,
247
- removeFromSelectables: boolean = false
248
- ) {
249
- const els = ensureArray(elements)
250
- this.SelectedSet.deleteAll(els)
251
- if (removeFromSelectables) this.removeSelectables(elements, false, false)
252
- if (triggerCallback)
253
- this.PubSub.publish('DS:end', {
254
- items: this.SelectedSet.elements,
255
- isDragging: this.Interaction.isDragging,
256
- })
257
- return this.getSelection()
258
- }
259
-
260
- /**
261
- * Toggles specific elements from the selection:
262
- * If element is not in selection it will be added, if it is already selected, it will be removed.
263
- * Multiple elements can be given at once.
264
- * @param elements one or multiple elements
265
- * @param triggerCallback if callback should be called
266
- * @param removeFromSelectables if element should not be added/removed to the list of selectable elements accordingly
267
- * @return all selected elements
268
- */
269
- public toggleSelection(
270
- elements: E | E[],
271
- triggerCallback: boolean = false,
272
- removeFromSelectables: boolean = false
273
- ) {
274
- const els = ensureArray(elements)
275
- els.forEach((el: E) =>
276
- this.SelectedSet.has(el)
277
- ? this.removeSelection(elements, triggerCallback, removeFromSelectables)
278
- : this.addSelection(elements, triggerCallback, removeFromSelectables)
279
- )
280
- if (triggerCallback)
281
- this.PubSub.publish('DS:end', {
282
- items: this.SelectedSet.elements,
283
- isDragging: this.Interaction.isDragging,
284
- })
285
- return this.getSelection()
286
- }
287
-
288
- /**
289
- * Sets the current selected elements and optionally run the callback
290
- * By default, adds new elements also to the list of selectables
291
- * @param elements dom elements
292
- * @param triggerCallback if callback should be called
293
- * @param dontAddToSelectables if element should not be added to the list of selectable elements
294
- */
295
- public setSelection(
296
- elements: E | E[],
297
- triggerCallback: boolean = false,
298
- dontAddToSelectables: boolean = false
299
- ) {
300
- this.clearSelection()
301
- this.addSelection(elements, triggerCallback, dontAddToSelectables)
302
- return this.getSelection()
303
- }
304
-
305
- /**
306
- * Unselect / Deselect all current selected Nodes
307
- * @param triggerCallback if callback should be called
308
- * @return this.selected, should be empty
309
- */
310
- public clearSelection(triggerCallback: boolean = false) {
311
- this.SelectedSet.clear()
312
- if (triggerCallback)
313
- this.PubSub.publish('DS:end', {
314
- items: this.SelectedSet.elements,
315
- isDragging: this.Interaction.isDragging,
316
- })
317
- return this.getSelection()
318
- }
319
-
320
- /**
321
- * Add elements that can be selected. No node is added twice
322
- * @param elements dom element(s)
323
- * @param addToSelection if elements should also be added to current selection
324
- * @param triggerCallback if callback should be called
325
- * @return the added element(s)
326
- */
327
- public addSelectables(
328
- elements: E | E[],
329
- addToSelection?: boolean,
330
- triggerCallback?: boolean
331
- ) {
332
- const els = ensureArray(elements)
333
- this.SelectableSet.addAll(els)
334
- if (addToSelection) this.SelectedSet.addAll(els)
335
- if (triggerCallback)
336
- this.PubSub.publish('DS:end', {
337
- items: this.SelectedSet.elements,
338
- isDragging: this.Interaction.isDragging,
339
- })
340
- return els
341
- }
342
-
343
- /** Gets all nodes that can potentially be selected */
344
- public getSelectables = () => this.SelectableSet.elements
345
-
346
- /**
347
- * Remove elements from the elements that can be selected.
348
- * @param elements dom element(s)
349
- * @param removeFromSelection if elements should also be removed from current selection
350
- * @param triggerCallback if callback should be called
351
- * @return the removed element(s)
352
- */
353
- public removeSelectables(
354
- elements: E | E[],
355
- removeFromSelection?: boolean,
356
- triggerCallback?: boolean
357
- ) {
358
- const els = ensureArray(elements)
359
- this.SelectableSet.deleteAll(els)
360
- if (removeFromSelection) this.removeSelection(elements)
361
- if (triggerCallback)
362
- this.PubSub.publish('DS:end', {
363
- items: this.SelectedSet.elements,
364
- isDragging: this.Interaction.isDragging,
365
- })
366
- return els
367
- }
368
-
369
- /** The starting/initial position of the cursor/selector */
370
- public getInitialCursorPosition = (): Vect2 =>
371
- this.stores.PointerStore.initialVal
372
-
373
- /** The last seen position of the cursor/selector */
374
- public getCurrentCursorPosition = (): Vect2 =>
375
- this.stores.PointerStore.currentVal
376
-
377
- /** The previous position of the cursor/selector */
378
- public getPreviousCursorPosition = (): Vect2 =>
379
- this.stores.PointerStore.lastVal
380
-
381
- /** The starting/initial position of the cursor/selector */
382
- public getInitialCursorPositionArea = (): Vect2 =>
383
- this.stores.PointerStore.initialValArea
384
-
385
- /** The last seen position of the cursor/selector */
386
- public getCurrentCursorPositionArea = (): Vect2 =>
387
- this.stores.PointerStore.currentValArea
388
-
389
- /** The previous position of the cursor/selector */
390
- public getPreviousCursorPositionArea = (): Vect2 =>
391
- this.stores.PointerStore.lastValArea
392
-
393
- /** Whether the multi-selection key was pressed */
394
- public isMultiSelect = (
395
- event: MouseEvent | TouchEvent | PointerEvent | KeyboardEvent
396
- ): boolean => this.stores.KeyStore.isMultiSelectKeyPressed(event)
397
-
398
- /** Whether the user is currently drag n dropping elements (instead of selection) */
399
- public isDragging = (): boolean => this.Interaction.isDragging
400
-
401
- /** Returns first DropsZone under coordinates, if no coordinated provided current pointer coordinates are used */
402
- public getZoneByCoordinates = (
403
- coordinates?: Vect2
404
- ): DSDropZone<E> | undefined =>
405
- this.DropZones.getTarget({ coordinates })?.toObject()
406
-
407
- /** Returns itemsDropped into zone by zone id */
408
- public getItemsDroppedByZoneId = (zoneId: string) =>
409
- this.DropZones.getItemsDroppedById(zoneId)
410
-
411
- /**
412
- * Returns itemsInside by zone id
413
- * @param addClasses whether or not to add/remove the "inside" classes to the items
414
- */
415
- public getItemsInsideByZoneId = (zoneId: string, addClasses?: boolean) =>
416
- this.DropZones.getItemsInsideById(zoneId, addClasses)
417
- }
418
-
419
- DragSelect.isCollision = isCollision
420
- export default DragSelect
421
- export * from './types'
422
- export type DSPubCallback<
423
- T extends keyof DSPublicPublish<E>,
424
- E extends DSInputElement = DSInputElement,
425
- > = DSCallback<DSPublishMappings<E>[T]>
@@ -1,51 +0,0 @@
1
- export type AddModificationObservers<T> = {
2
- /** Adds modification listeners to DOMNode(s) */
3
- (
4
- nodes: Node[],
5
- cb: T
6
- ): {
7
- observer: MutationObserver
8
- callback: T
9
- /** Removes event-listeners from the DOMNode(s) */
10
- cleanup: () => void
11
- }
12
- }
13
-
14
- export type MutationCallbackEvent =
15
- | UIEvent
16
- | Event
17
- | MutationRecord[]
18
- | ResizeObserverEntry[]
19
- type ModificationListenerCallback = (event: MutationCallbackEvent) => any
20
-
21
- export const addModificationObservers: AddModificationObservers<
22
- ModificationListenerCallback
23
- > = (nodes, cb) => {
24
- const callback = cb
25
-
26
- window.addEventListener('resize', callback)
27
- window.addEventListener('scroll', callback)
28
-
29
- const observer = new MutationObserver(callback)
30
- const resizeObserver = new ResizeObserver(callback)
31
-
32
- nodes.forEach((el, i) => {
33
- observer.observe(el, {
34
- childList: i !== 0,
35
- attributes: true,
36
- })
37
- if (el instanceof Element) resizeObserver.observe(el)
38
- })
39
-
40
- /**
41
- * Removes all observers
42
- */
43
- const cleanup = () => {
44
- window.removeEventListener('resize', callback)
45
- window.removeEventListener('scroll', callback)
46
- observer.disconnect()
47
- resizeObserver.disconnect()
48
- }
49
-
50
- return { observer, resizeObserver, callback, cleanup }
51
- }
@@ -1,19 +0,0 @@
1
- import { DSArea } from '../types'
2
- import { getCurrentScroll } from './getCurrentScroll'
3
-
4
- /** Checks whether the area can scroll or not */
5
- export type CanScroll = {
6
- (area: DSArea): boolean
7
- }
8
-
9
- export const canScroll: CanScroll = area => {
10
- const scroll = getCurrentScroll(area)
11
- if (scroll.x || scroll.y) return true
12
-
13
- if (area instanceof Document) {
14
- if (area.body) return Boolean(area.body.scrollTop = 1)
15
- return Boolean(area.documentElement.scrollTop = 1)
16
- }
17
-
18
- return Boolean(area.scrollTop = 1)
19
- }
@@ -1,8 +0,0 @@
1
- export const createSelectorAreaElement = () => {
2
- const node = document.createElement('div')
3
- node.style.position = 'fixed'
4
- node.style.overflow = 'hidden'
5
- node.style.pointerEvents = 'none'
6
- node.style.zIndex = '999999999999999999'
7
- return node
8
- }
@@ -1,13 +0,0 @@
1
- export const createSelectorElement = (customStyles: boolean) => {
2
- const selector = document.createElement('div')
3
-
4
- selector.style.position = 'absolute'
5
- if (!customStyles) {
6
- selector.style.background = 'rgba(0, 175, 255, 0.2)'
7
- selector.style.border = '1px solid rgba(0, 175, 255, 0.8)'
8
- selector.style.display = 'none'
9
- selector.style.pointerEvents = 'none' // fix for issue #8 (ie11+)
10
- }
11
-
12
- return selector
13
- }
@@ -1,31 +0,0 @@
1
- /**
2
- * Returns a function, that, as long as it continues to be invoked, will not
3
- * be triggered. The function will be called after it stops being called for
4
- * `wait` milliseconds. All credits to [Trey Huffine]{@link https://levelup.gitconnected.com/debounce-in-javascript-improve-your-applications-performance-5b01855e086}
5
- */
6
- export const debounce = (func: any, wait: number) => {
7
- let timeout: number | undefined
8
-
9
- // This is the function that is returned and will be executed many times
10
- // We spread (...args) to capture any number of parameters we want to pass
11
- return (...args: any[]) => {
12
- // The callback function to be executed after
13
- // the debounce time has elapsed
14
- const later = () => {
15
- // null timeout to indicate the debounce ended
16
- timeout = undefined
17
-
18
- // Execute the callback
19
- func(...args)
20
- }
21
- // This will reset the waiting every function execution.
22
- // This is the step that prevents the function from
23
- // being executed because it will never reach the
24
- // inside of the previous setTimeout
25
- clearTimeout(timeout)
26
-
27
- // Restart the debounce waiting period.
28
- // setTimeout returns a truthy value (it differs in web vs Node)
29
- timeout = setTimeout(later, wait) as any as number
30
- }
31
- }
@@ -1,13 +0,0 @@
1
- type EnsureArray = {
2
- /**
3
- * Transforms any list or single dom node to an array so user doesn’t have to care. Also removes duplicates.
4
- * @param items a single item, a Node-list or any element group
5
- */
6
- <T>(items?: T | T[] | [T]): T[]
7
- }
8
-
9
- export const ensureArray: EnsureArray = input => {
10
- if (!input) return []
11
- if (!Array.isArray(input) && typeof (input as any)[Symbol.iterator] !== 'function') return [input]
12
- return [...new Set([...(input as any)])]
13
- }
@@ -1,15 +0,0 @@
1
- import { DSArea, DSInputElement } from "../types"
2
-
3
- export const getAllParentNodes = <E extends DSInputElement>(node: E|DSArea) => {
4
- const traverse = (toWatch: ParentNode[], index = 0): ParentNode[] => {
5
- const parent = toWatch[index]?.parentNode
6
- if (parent) {
7
- toWatch.push(parent)
8
- index++
9
- return traverse(toWatch, index)
10
- }
11
- return toWatch
12
- }
13
-
14
- return traverse([node])
15
- }
@@ -1,27 +0,0 @@
1
- import { DSArea, DSBoundingRect } from '../types'
2
- /**
3
- * Returns the top/left/bottom/right/width/height
4
- * values of an area. If area is document then everything
5
- * except the sizes will be nulled.
6
- */
7
- export const getAreaRect = (area: DSArea, zoom: number): DSBoundingRect => {
8
- if (area instanceof Document)
9
- return {
10
- top: 0,
11
- left: 0,
12
- bottom: 0,
13
- right: 0,
14
- width: window.innerWidth,
15
- height: window.innerHeight,
16
- }
17
-
18
- const rect = area.getBoundingClientRect()
19
- return {
20
- top: rect.top,
21
- left: rect.left,
22
- bottom: rect.bottom,
23
- right: rect.right,
24
- width: (area.clientWidth || rect.width) * zoom,
25
- height: (area.clientHeight || rect.height) * zoom,
26
- }
27
- }
@@ -1,14 +0,0 @@
1
- import { DSArea, Vect2 } from '../types'
2
- import { getDocumentScroll } from './getDocumentScroll'
3
-
4
- export type GetCurrentScroll = {
5
- (area: DSArea): Vect2
6
- }
7
-
8
- export const getCurrentScroll: GetCurrentScroll = area => {
9
- if (!area || area instanceof Document) return getDocumentScroll()
10
- return {
11
- x: area.scrollLeft >= 0 ? area.scrollLeft : getDocumentScroll().x,
12
- y: area.scrollTop >= 0 ? area.scrollTop : getDocumentScroll().y,
13
- }
14
- }
@@ -1,5 +0,0 @@
1
-
2
- export const getDocumentScroll = () => ({
3
- y: document.body?.scrollTop || document.documentElement?.scrollTop || 0,
4
- x: document.body?.scrollLeft || document.documentElement?.scrollLeft || 0,
5
- })