dragselect 2.4.3 → 2.5.0

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 (52) hide show
  1. package/CHANGELOG.md +10 -0
  2. package/README.md +103 -27
  3. package/deploying.md +1 -1
  4. package/dist/DragSelect.d.ts +26 -4
  5. package/dist/DragSelect.es6m.js +882 -792
  6. package/dist/DragSelect.js +882 -792
  7. package/dist/ds.es6m.min.js +1 -1
  8. package/dist/ds.min.js +1 -1
  9. package/dist/methods/addModificationObservers.d.ts +9 -1
  10. package/dist/methods/getAllParentNodes.d.ts +3 -0
  11. package/dist/methods/getPointerPos.d.ts +1 -1
  12. package/dist/methods/index.d.ts +1 -0
  13. package/dist/methods/isCollision.d.ts +1 -1
  14. package/dist/methods/subscriberAliases.d.ts +3 -1
  15. package/dist/modules/Area.d.ts +2 -12
  16. package/dist/modules/DropZone.d.ts +88 -0
  17. package/dist/modules/DropZones.d.ts +76 -0
  18. package/dist/modules/Interaction.d.ts +1 -0
  19. package/dist/modules/SelectableSet.d.ts +12 -0
  20. package/dist/modules/Selection.d.ts +1 -0
  21. package/dist/modules/Selector.d.ts +1 -1
  22. package/dist/modules/SelectorArea.d.ts +1 -1
  23. package/dist/modules/index.d.ts +1 -0
  24. package/dist/stores/KeyStore.d.ts +2 -2
  25. package/dist/stores/PointerStore.d.ts +2 -1
  26. package/dist/types.d.ts +78 -4
  27. package/jest-puppeteer.config.js +1 -0
  28. package/package.json +10 -9
  29. package/rollup.config.js +1 -1
  30. package/src/DragSelect.js +29 -5
  31. package/src/methods/addModificationObservers.js +26 -5
  32. package/src/methods/canScroll.js +1 -1
  33. package/src/methods/getAllParentNodes.js +18 -0
  34. package/src/methods/getPointerPos.js +1 -1
  35. package/src/methods/handleElementPositionAttribute.js +1 -1
  36. package/src/methods/hydrateSettings.js +17 -0
  37. package/src/methods/index.js +1 -0
  38. package/src/methods/isCollision.js +24 -5
  39. package/src/methods/scrollElement.js +1 -1
  40. package/src/methods/subscriberAliases.js +16 -5
  41. package/src/methods/toArray.js +3 -2
  42. package/src/modules/Area.js +12 -44
  43. package/src/modules/DropZone.js +224 -0
  44. package/src/modules/DropZones.js +153 -0
  45. package/src/modules/Interaction.js +32 -7
  46. package/src/modules/SelectableSet.js +45 -8
  47. package/src/modules/Selection.js +9 -11
  48. package/src/modules/index.js +1 -0
  49. package/src/stores/KeyStore.js +1 -1
  50. package/src/stores/PointerStore.js +17 -3
  51. package/src/stores/SettingsStore.js +0 -1
  52. package/src/types.js +33 -4
@@ -0,0 +1,88 @@
1
+ export default class DropZone {
2
+ /**
3
+ * @constructor Drag
4
+ * @param {Object} obj
5
+ * @param {DragSelect} obj.DS
6
+ * @param {string} obj.id
7
+ * @param {DSElement} obj.element
8
+ * @param {DSInputElements} obj.droppables
9
+ * @ignore
10
+ */
11
+ constructor({ DS, id, element, droppables }: {
12
+ DS: DragSelect;
13
+ id: string;
14
+ element: DSElement;
15
+ droppables: DSInputElements;
16
+ });
17
+ /**
18
+ * @type {string}
19
+ */
20
+ id: string;
21
+ /**
22
+ * @type {DSElement}
23
+ */
24
+ element: DSElement;
25
+ /**
26
+ * @type {DSElements}
27
+ */
28
+ droppables: DSElements;
29
+ /**
30
+ * @type {DOMRect}
31
+ * @private
32
+ */
33
+ private _rect;
34
+ /**
35
+ * @type {{cleanup:()=>void}}
36
+ * @private
37
+ */
38
+ private _observers;
39
+ /**
40
+ * @type {NodeJS.Timeout}
41
+ * @private
42
+ */
43
+ private _timeout;
44
+ /**
45
+ * @type {DSElements}
46
+ * @private
47
+ */
48
+ private _itemsDropped;
49
+ /**
50
+ * @type {DSElements}
51
+ * @private
52
+ */
53
+ private _itemsInside;
54
+ DS: DragSelect;
55
+ Settings: Settings;
56
+ /**
57
+ * @param {'add'|'remove'} action
58
+ */
59
+ setReadyClasses: (action: 'add' | 'remove') => void;
60
+ /**
61
+ * This zone is NOT the target of a drop
62
+ */
63
+ handleNoDrop: () => void;
64
+ /**
65
+ * This zone IS the target of a drop
66
+ */
67
+ handleDrop: () => void;
68
+ handleItemsInsideClasses: () => void;
69
+ start: ({ isDragging }: {
70
+ isDragging: any;
71
+ }) => void;
72
+ stop: ({ isDragging }: {
73
+ isDragging: any;
74
+ }) => void;
75
+ destroy(): void;
76
+ isDestroyed: boolean;
77
+ /**
78
+ * @returns {DSDropZone}
79
+ */
80
+ toObject: () => DSDropZone;
81
+ get rect(): DOMRect;
82
+ get itemsDropped(): DSElements;
83
+ get itemsInside(): DSElements;
84
+ get parentNodes(): DSElements;
85
+ _parentNodes: DSElements;
86
+ }
87
+ import DragSelect from "../DragSelect";
88
+ import "../types"
@@ -0,0 +1,76 @@
1
+ export default class DropZones {
2
+ /**
3
+ * @constructor Drag
4
+ * @param {{DS:DragSelect}} obj
5
+ * @ignore
6
+ */
7
+ constructor({ DS }: {
8
+ DS: DragSelect;
9
+ });
10
+ /**
11
+ * Get the drop zone by the zone element
12
+ * @type {Map<DSElement, DropZone>}
13
+ * @private
14
+ */
15
+ private _zoneByElement;
16
+ /**
17
+ * Get the drop zone by the zone id
18
+ * @type {Map<string, DropZone>}
19
+ * @private
20
+ */
21
+ private _zoneById;
22
+ /**
23
+ * Get the drop zones by one zone item
24
+ * @type {Map<DSElement,DropZone[]>}
25
+ * @private
26
+ */
27
+ private _zonesByDroppable;
28
+ /**
29
+ * Get the drop zones by one zone item
30
+ * @type {DropZone[]}
31
+ * @private
32
+ */
33
+ private _zones;
34
+ DS: DragSelect;
35
+ Settings: Settings;
36
+ /**
37
+ * @param {Object} obj
38
+ * @param {DSDropZone[]} [obj.dropZones]
39
+ */
40
+ setDropZones: ({ dropZones }: {
41
+ dropZones?: DSDropZone[];
42
+ }) => void;
43
+ _handleDrop: (target: any) => void;
44
+ /**
45
+ * @param {DSElements} elements
46
+ * @param {Vect2} point
47
+ * @returns {DropZone|undefined}
48
+ */
49
+ _getZoneByElementsFromPoint: (elements: DSElements, { x, y }: Vect2) => DropZone | undefined;
50
+ start: ({ isDragging }: {
51
+ isDragging: any;
52
+ }) => void;
53
+ stop: ({ isDragging }: {
54
+ isDragging: any;
55
+ }) => void;
56
+ /**
57
+ * @param {string} zoneId
58
+ * @returns {DSElements|void}
59
+ */
60
+ getItemsDroppedById: (zoneId: string) => DSElements | void;
61
+ /**
62
+ * @param {string} zoneId
63
+ * @param {boolean} addClasses
64
+ * @returns {DSElements|void}
65
+ */
66
+ getItemsInsideById: (zoneId: string, addClasses: boolean) => DSElements | void;
67
+ /**
68
+ * Returns first DropsZone under current pointer
69
+ * @param {Vect2} [coordinates]
70
+ * @returns {DropZone | undefined}
71
+ */
72
+ getTarget: (coordinates?: Vect2) => DropZone | undefined;
73
+ }
74
+ import DragSelect from "../DragSelect";
75
+ import DropZone from "./DropZone";
76
+ import "../types"
@@ -12,6 +12,7 @@ export default class Interaction {
12
12
  /** @type {boolean} */
13
13
  isDragging: boolean;
14
14
  DS: DragSelect;
15
+ Settings: Settings;
15
16
  init: () => void;
16
17
  _init: () => void;
17
18
  /**
@@ -7,7 +7,18 @@ export default class SelectableSet extends Set<any> {
7
7
  constructor({ DS }: {
8
8
  DS: DragSelect;
9
9
  });
10
+ /**
11
+ * @type {Map<DSElement,DSBoundingRect>}
12
+ * @private
13
+ */
14
+ private _rects;
15
+ /**
16
+ * @type {NodeJS.Timeout}
17
+ * @private
18
+ */
19
+ private _timeout;
10
20
  DS: DragSelect;
21
+ Settings: Settings;
11
22
  init: () => void;
12
23
  /** @param {DSElement} element */
13
24
  add(element: DSElement): SelectableSet;
@@ -21,6 +32,7 @@ export default class SelectableSet extends Set<any> {
21
32
  deleteAll: (elements: DSElements) => void;
22
33
  /** @return {DSElements} */
23
34
  get elements(): DSElements;
35
+ get rects(): Map<DSElement, DSBoundingRect>;
24
36
  }
25
37
  import DragSelect from "../DragSelect";
26
38
  import "../types"
@@ -13,6 +13,7 @@ export default class Selection {
13
13
  * */
14
14
  private _prevSelectedSet;
15
15
  DS: DragSelect;
16
+ Settings: Settings;
16
17
  /**
17
18
  * Stores the previous selection (solves #9)
18
19
  * @param {DSEvent} event
@@ -23,7 +23,7 @@ export default class Selector {
23
23
  update: ({ isDragging }: {
24
24
  isDragging: any;
25
25
  }) => void;
26
- get rect(): DOMRect | DSBoundingRect;
26
+ get rect(): DSBoundingRect | DOMRect;
27
27
  }
28
28
  import DragSelect from "../DragSelect";
29
29
  import "../types"
@@ -52,7 +52,7 @@ export default class SelectorArea {
52
52
  * @returns {boolean}
53
53
  */
54
54
  isClicked(event?: DSEvent): boolean;
55
- get rect(): DOMRect | DSBoundingRect;
55
+ get rect(): DSBoundingRect | DOMRect;
56
56
  }
57
57
  import DragSelect from "../DragSelect";
58
58
  import "../types"
@@ -1,5 +1,6 @@
1
1
  export { default as Area } from "./Area";
2
2
  export { default as Drag } from "./Drag";
3
+ export { default as DropZones } from "./DropZones";
3
4
  export { default as Interaction } from "./Interaction";
4
5
  export { default as PubSub } from "./PubSub";
5
6
  export { default as SelectableSet } from "./SelectableSet";
@@ -26,8 +26,8 @@ export default class KeyStore {
26
26
  keyup: (event: KeyboardEvent) => void;
27
27
  stop: () => void;
28
28
  reset: () => void;
29
- /** @param {KeyboardEvent|MouseEvent|TouchEvent} [event] */
30
- isMultiSelectKeyPressed(event?: KeyboardEvent | MouseEvent | TouchEvent): boolean;
29
+ /** @param {KeyboardEvent|MouseEvent|PointerEvent|TouchEvent} [event] */
30
+ isMultiSelectKeyPressed(event?: KeyboardEvent | MouseEvent | PointerEvent | TouchEvent): boolean;
31
31
  get currentValues(): string[];
32
32
  }
33
33
  import DragSelect from "../DragSelect";
@@ -46,6 +46,7 @@ export default class PointerStore {
46
46
  * */
47
47
  private _lastTouch;
48
48
  DS: DragSelect;
49
+ Settings: Settings;
49
50
  init: () => void;
50
51
  /** @param {DSEvent} [event] */
51
52
  start(event?: DSEvent): void;
@@ -67,7 +68,7 @@ export default class PointerStore {
67
68
  get lastVal(): Vect2;
68
69
  /**
69
70
  * @param {DSEvent} event
70
- * @return {MouseEvent|Touch}
71
+ * @return {MouseEvent|PointerEvent|Touch}
71
72
  * @private
72
73
  */
73
74
  private _normalizedEvent;
package/dist/types.d.ts CHANGED
@@ -5,7 +5,7 @@ type Settings = {
5
5
  /**
6
6
  * area in which you can drag. If not provided it will be the whole document
7
7
  */
8
- area?: HTMLElement | SVGElement | HTMLDocument;
8
+ area?: HTMLElement | SVGElement | Document;
9
9
  /**
10
10
  * the elements that can be selected
11
11
  */
@@ -42,6 +42,10 @@ type Settings = {
42
42
  * the square that will draw the selection
43
43
  */
44
44
  selector?: HTMLElement;
45
+ /**
46
+ * how much % of the element has to be selected to be considered selected (0 = just touching, 1 = inside the selection)
47
+ */
48
+ selectionThreshold?: number;
45
49
  /**
46
50
  * When a user is dragging on an already selected element, the selection is dragged.
47
51
  */
@@ -66,6 +70,26 @@ type Settings = {
66
70
  * Whether to use hardware accelerated css transforms when dragging or top/left instead
67
71
  */
68
72
  useTransform?: boolean;
73
+ /**
74
+ * Refresh rate on memoization, higher numbers mean better performance but more lag if elements are moving, lower numbers mean less lag but worse performance. If none of your DOMNodes are moving, you can set it to a very high number to increase performance. Value in milliseconds.
75
+ */
76
+ refreshMemoryRate?: number;
77
+ /**
78
+ * one or more drop-elements: where the selectables can be dropped into
79
+ */
80
+ dropZones?: DSInputDropZone[];
81
+ /**
82
+ * how much % of the item has to be inside the dropzone to be considered inside (0 = barely touching, 1 = completely inside)
83
+ */
84
+ dropInsideThreshold?: number;
85
+ /**
86
+ * how much % of the zone does the pointer has to be in to be considered a target (0 = anywhere in the zone, max: 0.5 = has to point at the center of the zone)
87
+ */
88
+ dropTargetThreshold?: number;
89
+ /**
90
+ * Whether to use Pointer Events to replace traditional Mouse or Touch Events. Useful for tools like Google Blockly.
91
+ */
92
+ usePointerEvents?: boolean;
69
93
  /**
70
94
  * the class assigned to the mouse hovered items
71
95
  */
@@ -86,6 +110,34 @@ type Settings = {
86
110
  * the class assigned to the square in which the selector resides. By default it's invisible
87
111
  */
88
112
  selectorAreaClass?: string;
113
+ /**
114
+ * on an item corresponding the target dropzone. This is also the prefix for ds-dropped-target-${zone.id}
115
+ */
116
+ droppedTargetClass?: string;
117
+ /**
118
+ * on an item that is within its dropzone bounds after a drop. This is also the prefix for ds-dropped-inside-${zone.id}
119
+ */
120
+ droppedInsideClass?: string;
121
+ /**
122
+ * on element that can be dropped into at least one container. This is also the prefix for ds-droppable-${zone.id}
123
+ */
124
+ droppableClass?: string;
125
+ /**
126
+ * on each dropZone
127
+ */
128
+ dropZoneClass?: string;
129
+ /**
130
+ * on corresponding dropZone when element is dragged
131
+ */
132
+ dropZoneReadyClass?: string;
133
+ /**
134
+ * on dropZone that has elements from any successful target drop
135
+ */
136
+ dropZoneTargetClass?: string;
137
+ /**
138
+ * on dropZone that has elements inside after any drop
139
+ */
140
+ dropZoneInsideClass?: string;
89
141
  };
90
142
  /**
91
143
  * The Object that is passed back to any callback method
@@ -98,7 +150,7 @@ type CallbackObject = {
98
150
  /**
99
151
  * The respective event object
100
152
  */
101
- event?: MouseEvent | TouchEvent | KeyboardEvent | Event;
153
+ event?: MouseEvent | TouchEvent | PointerEvent | KeyboardEvent | Event;
102
154
  /**
103
155
  * The single item currently interacted with
104
156
  */
@@ -121,8 +173,30 @@ type CallbackObject = {
121
173
  settings?: Settings;
122
174
  scroll_directions?: Array<'top' | 'bottom' | 'left' | 'right' | undefined>;
123
175
  scroll_multiplier?: number;
176
+ /**
177
+ * The dropZone element that the element was dropped into (or the mouse is currently hovering over)
178
+ */
179
+ dropTarget?: DSDropZone;
124
180
  };
125
181
  type DSCallback = Function;
182
+ type DSInputDropZone = {
183
+ id: string;
184
+ element: DSElement;
185
+ droppables: DSInputElements;
186
+ };
187
+ type DSDropZone = {
188
+ id: string;
189
+ element: DSElement;
190
+ droppables: DSElements;
191
+ /**
192
+ * the items related to the target zone
193
+ */
194
+ itemsDropped?: DSElements;
195
+ /**
196
+ * the items that are within the targets bounds
197
+ */
198
+ itemsInside?: DSElements;
199
+ };
126
200
  type Vect2 = {
127
201
  x: number;
128
202
  y: number;
@@ -139,7 +213,7 @@ type DSEdges = Array<'top' | 'bottom' | 'left' | 'right' | undefined>;
139
213
  /**
140
214
  * area within which you can drag
141
215
  */
142
- type DSArea = HTMLElement | SVGElement | HTMLDocument;
216
+ type DSArea = HTMLElement | SVGElement | Document;
143
217
  /**
144
218
  * area in which you can drag
145
219
  */
@@ -159,7 +233,7 @@ type DSElement = HTMLElement | SVGElement;
159
233
  /**
160
234
  * en event from a touch or mouse interaction
161
235
  */
162
- type DSEvent = MouseEvent | TouchEvent;
236
+ type DSEvent = MouseEvent | TouchEvent | PointerEvent;
163
237
  /**
164
238
  * An array of keys that allows switching to the multi-select mode
165
239
  */
@@ -1,5 +1,6 @@
1
1
  module.exports = {
2
2
  launch: {
3
3
  headless: true,
4
+ args: ['--no-sandbox', '--disable-setuid-sandbox']
4
5
  },
5
6
  }
package/package.json CHANGED
@@ -1,7 +1,7 @@
1
1
  {
2
2
  "name": "dragselect",
3
- "version": "2.4.3",
4
- "description": "easy javascript drag select functionality for your projects",
3
+ "version": "2.5.0",
4
+ "description": "easy javascript drag select & drop functionality for your projects",
5
5
  "main": "./dist/DragSelect.js",
6
6
  "types": "./dist/DragSelect.d.ts",
7
7
  "scripts": {
@@ -10,7 +10,7 @@
10
10
  "start": "npm run open & npm run watch",
11
11
  "watch": "concurrently --kill-others \"npm run checkjs:watch\" \"npm run rollup:watch\" \"npm run test:watch\"",
12
12
  "\n# TESTING:": "",
13
- "checkjs": "tsc --lib es2019,dom -t es5 --allowJs --checkJs --noEmit src/*.js",
13
+ "checkjs": "tsc --lib es2019,dom -t es5 --allowJs --skipLibCheck --checkJs --noEmit src/*.js",
14
14
  "checkjs:watch": "npm run checkjs -- -w",
15
15
  "postcheckjs": "npm run docs && rm -rf docs",
16
16
  "pretest": "npm run build",
@@ -23,12 +23,12 @@
23
23
  "media": "cp -R .media docs/media",
24
24
  "prerollup": "npm run types",
25
25
  "rollup": "rollup -c",
26
- "rollup:travis": "npm run rollup -- --travis",
26
+ "rollup:ci": "npm run rollup -- --ci",
27
27
  "rollup:watch": "npm run rollup -- -w",
28
- "types": "tsc src/DragSelect.js --lib es2019,dom -t es5 --declaration --allowJs --emitDeclarationOnly --outDir dist",
28
+ "types": "tsc src/DragSelect.js --lib es2019,dom -t es5 --declaration --allowJs --emitDeclarationOnly --skipLibCheck --outDir dist",
29
29
  "\n## PROD:": "",
30
- "travis:build": "npm run rollup:travis && npm run media && npm run docs",
31
- "travis:test": "npm run rollup && npm run test"
30
+ "ci:build": "npm run rollup:ci && npm run media && npm run docs",
31
+ "ci:test": "npm run test"
32
32
  },
33
33
  "devDependencies": {
34
34
  "@babel/cli": "^7.12.10",
@@ -41,6 +41,7 @@
41
41
  "@rollup/plugin-babel": "^5.2.2",
42
42
  "@rollup/plugin-node-resolve": "^11.0.1",
43
43
  "@typescript-eslint/eslint-plugin-tslint": "^4.12.0",
44
+ "@typescript-eslint/parser": "^5.41.0",
44
45
  "babel-jest": "^26.6.3",
45
46
  "babel-loader": "^8.2.2",
46
47
  "babel-polyfill": "^6.26.0",
@@ -60,11 +61,11 @@
60
61
  "eslint-plugin-standard": "^5.0.0",
61
62
  "glob": "^7.1.7",
62
63
  "jest": "^26.6.3",
63
- "jest-puppeteer": "^4.4.0",
64
+ "jest-puppeteer": "^6.1.1",
64
65
  "jsdoc": "^3.6.11",
65
66
  "minami": "^1.2.3",
66
67
  "prettier": "^2.2.1",
67
- "puppeteer": "^5.5.0",
68
+ "puppeteer": "18.1.0",
68
69
  "rollup": "^2.36.1",
69
70
  "rollup-plugin-terser": "^7.0.2",
70
71
  "typescript": "^4.8.0"
package/rollup.config.js CHANGED
@@ -74,7 +74,7 @@ export default {
74
74
  {
75
75
  name: 'copy',
76
76
  writeBundle(options) {
77
- if (!process.argv.includes('--travis')) return
77
+ if (!process.argv.includes('--ci')) return
78
78
  if (!fs.existsSync('docs/')) fs.mkdirSync('docs')
79
79
  fs.copyFileSync(
80
80
  `.v1/${path.basename(options.file)}`,
package/src/DragSelect.js CHANGED
@@ -46,6 +46,7 @@ import './types'
46
46
  import {
47
47
  Area,
48
48
  Drag,
49
+ DropZones,
49
50
  Interaction,
50
51
  PubSub,
51
52
  SelectableSet,
@@ -55,7 +56,7 @@ import {
55
56
  SelectorArea,
56
57
  } from './modules'
57
58
  import { PointerStore, ScrollStore, KeyStore, SettingsStore } from './stores'
58
- import { toArray, vect2, subscriberAliases } from './methods'
59
+ import { toArray, subscriberAliases } from './methods'
59
60
 
60
61
  // Setup
61
62
  //////////////////////////////////////////////////////////////////////////////////////
@@ -93,6 +94,8 @@ class DragSelect {
93
94
 
94
95
  this.Drag = new Drag({ DS: this })
95
96
 
97
+ this.DropZones = new DropZones({ DS: this })
98
+
96
99
  this.Interaction = new Interaction({ DS: this })
97
100
 
98
101
  // Subscriber Aliases
@@ -101,6 +104,7 @@ class DragSelect {
101
104
  publish: this.publish,
102
105
  SelectedSet: this.SelectedSet,
103
106
  Interaction: this.Interaction,
107
+ DropZones: this.DropZones,
104
108
  })
105
109
 
106
110
  this.subscribe('Interaction:end', () => (this.continue = false))
@@ -148,6 +152,12 @@ class DragSelect {
148
152
  * Useful utility to write your own functionality/move/dragNdrop based on DragSelect pointer positions.
149
153
  */
150
154
  break = () => (this.continue = true)
155
+ /**
156
+ * Update any setting dynamically
157
+ * @param {Settings} settings
158
+ * @return {void}
159
+ */
160
+ setSettings = (settings) => this.stores.SettingsStore.update({ settings })
151
161
  /**
152
162
  * Returns the current selected nodes
153
163
  * @return {DSElements}
@@ -314,11 +324,25 @@ class DragSelect {
314
324
  */
315
325
  isDragging = () => this.Interaction.isDragging
316
326
  /**
317
- * Update any setting dynamically
318
- * @param {Settings} settings
319
- * @return {void}
327
+ * Returns first DropsZone under coordinates,
328
+ * if no coordinated provided current pointer coordinates are used
329
+ * @param {Vect2} [coordinates]
330
+ * @returns {DSDropZone | undefined}
320
331
  */
321
- setSettings = (settings) => this.stores.SettingsStore.update({ settings })
332
+ getZoneByCoordinates = (coordinates) => this.DropZones.getTarget(coordinates)?.toObject()
333
+ /**
334
+ * Returns itemsDropped into zone by zone id
335
+ * @param {string} zoneId
336
+ * @returns {DSElements|void}
337
+ */
338
+ getItemsDroppedByZoneId = (zoneId) => this.DropZones.getItemsDroppedById(zoneId)
339
+ /**
340
+ * Returns itemsInside by zone id
341
+ * @param {string} zoneId
342
+ * @param {boolean} addClasses whether or not to add/remove the "inside" classes to the items
343
+ * @returns {DSElements|void}
344
+ */
345
+ getItemsInsideByZoneId = (zoneId, addClasses) => this.DropZones.getItemsInsideById(zoneId, addClasses)
322
346
  }
323
347
 
324
348
  export default DragSelect
@@ -1,20 +1,41 @@
1
1
  // @ts-check
2
2
  import '../types'
3
3
 
4
+ import { removeModificationObservers } from './'
5
+
6
+ /**
7
+ * Removes event-listeners from the DOMNode
8
+ * @typedef {()=>void} DSCleanup
9
+ */
10
+
4
11
  /**
5
- * Adds event-listeners to the selectorArea
12
+ * Adds event-listeners to a DOMNode
6
13
  * @param {DSArea[]} nodes
7
- * @param {DSModificationCallback} callback
8
- * @param {MutationObserver} modificationObserver
14
+ * @param {DSModificationCallback} cb
15
+ * @return {{observer:MutationObserver,callback:DSModificationCallback,cleanup:DSCleanup}}
9
16
  */
10
- export default (nodes, callback, modificationObserver) => {
17
+ export default (nodes, cb) => {
18
+ const callback = cb
19
+
11
20
  window.addEventListener('resize', callback)
12
21
  window.addEventListener('scroll', callback)
13
22
 
23
+ const observer = new MutationObserver(callback)
24
+
14
25
  nodes.forEach((el, i) => {
15
- modificationObserver.observe(el, {
26
+ observer.observe(el, {
16
27
  childList: i !== 0,
17
28
  attributes: true,
18
29
  })
19
30
  })
31
+
32
+ /**
33
+ * Removes all observers
34
+ */
35
+ const cleanup = () => removeModificationObservers(
36
+ observer,
37
+ callback,
38
+ )
39
+
40
+ return { observer, callback, cleanup }
20
41
  }
@@ -11,7 +11,7 @@ export default (area) => {
11
11
  let scroll = getCurrentScroll(area)
12
12
  if (scroll.x || scroll.y) return true
13
13
 
14
- if (area instanceof HTMLDocument) {
14
+ if (area instanceof Document) {
15
15
  if (area.body) return !!(area.body.scrollTop = 1)
16
16
  else return !!(area.documentElement.scrollTop = 1)
17
17
  }
@@ -0,0 +1,18 @@
1
+ /**
2
+ * @param {DSElement|DSArea} node
3
+ * @returns {DSElements}
4
+ */
5
+ export default (node) => {
6
+ const traverse = (toWatch, index = 0) => {
7
+ const parent = toWatch[index]?.parentNode
8
+ if (parent) {
9
+ toWatch.push(parent)
10
+ index++
11
+ return traverse(toWatch, index)
12
+ } else {
13
+ return toWatch
14
+ }
15
+ }
16
+
17
+ return traverse([node])
18
+ }
@@ -4,7 +4,7 @@ import '../types'
4
4
  /**
5
5
  * Returns cursor x, y position based on event object
6
6
  * @param {Object} p
7
- * @param {MouseEvent|Touch} p.event
7
+ * @param {MouseEvent|Touch|PointerEvent} p.event
8
8
  * @return {Vect2} cursor X/Y position
9
9
  */
10
10
  export default ({ event }) => ({
@@ -11,6 +11,6 @@ export default ({ computedStyle, node }) => {
11
11
  const position = computedStyle.position
12
12
  const isPositioned =
13
13
  position === 'absolute' || position === 'relative' || position === 'fixed'
14
- if (!(node instanceof HTMLDocument) && !isPositioned)
14
+ if (!(node instanceof Document) && !isPositioned)
15
15
  node.style.position = 'relative'
16
16
  }