dragselect 2.3.0 → 2.4.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 (43) hide show
  1. package/CHANGELOG.md +12 -0
  2. package/README.md +47 -25
  3. package/deploying.md +7 -4
  4. package/dist/DragSelect.d.ts +10 -18
  5. package/dist/DragSelect.es6m.js +417 -570
  6. package/dist/DragSelect.js +417 -570
  7. package/dist/ds.es6m.min.js +1 -1
  8. package/dist/ds.min.js +1 -1
  9. package/dist/methods/createSelectorAreaElement.d.ts +1 -1
  10. package/dist/methods/getOverflowEdges.d.ts +1 -1
  11. package/dist/methods/hydrateSettings.d.ts +3 -0
  12. package/dist/methods/index.d.ts +1 -0
  13. package/dist/modules/Area.d.ts +10 -15
  14. package/dist/modules/Drag.d.ts +4 -40
  15. package/dist/modules/Interaction.d.ts +2 -24
  16. package/dist/modules/SelectableSet.d.ts +6 -38
  17. package/dist/modules/SelectedSet.d.ts +6 -10
  18. package/dist/modules/Selection.d.ts +2 -14
  19. package/dist/modules/Selector.d.ts +5 -11
  20. package/dist/modules/SelectorArea.d.ts +4 -17
  21. package/dist/stores/KeyStore.d.ts +2 -14
  22. package/dist/stores/ScrollStore.d.ts +2 -9
  23. package/dist/stores/SettingsStore.d.ts +39 -0
  24. package/dist/stores/index.d.ts +1 -0
  25. package/dist/types.d.ts +13 -32
  26. package/package.json +4 -3
  27. package/src/DragSelect.js +22 -174
  28. package/src/methods/createSelectorAreaElement.js +1 -3
  29. package/src/methods/hydrateSettings.js +109 -0
  30. package/src/methods/index.js +1 -0
  31. package/src/modules/Area.js +24 -22
  32. package/src/modules/Drag.js +37 -71
  33. package/src/modules/Interaction.js +31 -38
  34. package/src/modules/SelectableSet.js +29 -54
  35. package/src/modules/SelectedSet.js +4 -13
  36. package/src/modules/Selection.js +6 -19
  37. package/src/modules/Selector.js +21 -8
  38. package/src/modules/SelectorArea.js +12 -17
  39. package/src/stores/KeyStore.js +11 -37
  40. package/src/stores/ScrollStore.js +17 -17
  41. package/src/stores/SettingsStore.js +67 -0
  42. package/src/stores/index.js +1 -0
  43. package/src/types.js +4 -7
@@ -1,34 +1,12 @@
1
1
  export default class Interaction {
2
2
  /**
3
3
  * @constructor Interaction
4
- * @param {Object} obj
5
- * @param {DSArea} obj.areaElement
6
- * @param {boolean} obj.draggability
7
- * @param {boolean} obj.immediateDrag
8
- * @param {DragSelect} obj.DS
4
+ * @param {{DS:DragSelect}} obj
9
5
  * @ignore
10
6
  */
11
- constructor({ areaElement, DS, draggability, immediateDrag }: {
12
- areaElement: DSArea;
13
- draggability: boolean;
14
- immediateDrag: boolean;
7
+ constructor({ DS }: {
15
8
  DS: DragSelect;
16
9
  });
17
- /**
18
- * @type {DSArea}
19
- * @private
20
- * */
21
- private _areaElement;
22
- /**
23
- * @type {boolean}
24
- * @private
25
- * */
26
- private _draggability;
27
- /**
28
- * @type {boolean}
29
- * @private
30
- * */
31
- private _immediateDrag;
32
10
  /** @type {boolean} */
33
11
  isInteracting: boolean;
34
12
  /** @type {boolean} */
@@ -1,50 +1,18 @@
1
1
  export default class SelectableSet extends Set<any> {
2
2
  /**
3
3
  * @constructor SelectableSet
4
- * @param {Object} p
5
- * @param {DSInputElements} p.elements
6
- * @param {DragSelect} p.DS
7
- * @param {string} p.className
8
- * @param {string} p.hoverClassName
9
- * @param {boolean} p.useTransform
10
- * @param {boolean} p.draggability
4
+ * @param {{DS:DragSelect}} obj
11
5
  * @ignore
12
6
  */
13
- constructor({ elements, className, hoverClassName, draggability, useTransform, DS, }: {
14
- elements: DSInputElements;
7
+ constructor({ DS }: {
15
8
  DS: DragSelect;
16
- className: string;
17
- hoverClassName: string;
18
- useTransform: boolean;
19
- draggability: boolean;
20
9
  });
21
- /**
22
- * @type {DSElements}
23
- * @private
24
- * */
25
- private _initElements;
26
- /**
27
- * @type {string}
28
- * @private
29
- * */
30
- private _className;
31
- /**
32
- * @type {string}
33
- * @private
34
- * */
35
- private _hoverClassName;
36
- /**
37
- * @type {boolean}
38
- * @private
39
- * */
40
- private _useTransform;
41
- /**
42
- * @type {boolean}
43
- * @private
44
- * */
45
- private _draggability;
46
10
  DS: DragSelect;
47
11
  init: () => void;
12
+ /** @param {DSElement} element */
13
+ add(element: DSElement): SelectableSet;
14
+ /** @param {DSElement} element */
15
+ delete(element: DSElement): boolean;
48
16
  _onClick: (event: any) => void;
49
17
  _onPointer: (event: any) => void;
50
18
  /** @param {DSElements} elements */
@@ -1,21 +1,17 @@
1
1
  export default class SelectedSet extends Set<any> {
2
2
  /**
3
3
  * @constructor SelectableSet
4
- * @param {Object} p
5
- * @param {DragSelect} p.DS
6
- * @param {string} p.className
4
+ * @param {{DS:DragSelect}} obj
7
5
  * @ignore
8
6
  */
9
- constructor({ className, DS }: {
7
+ constructor({ DS }: {
10
8
  DS: DragSelect;
11
- className: string;
12
9
  });
13
- /**
14
- * @type {string}
15
- * @private
16
- * */
17
- private _className;
18
10
  DS: DragSelect;
11
+ /** @param {DSElement} element */
12
+ add(element: DSElement): SelectedSet;
13
+ /** @param {DSElement} element */
14
+ delete(element: DSElement): boolean;
19
15
  /**
20
16
  * Adds/Removes an element. If it is already selected = remove, if not = add.
21
17
  * @param {DSElement} element
@@ -1,29 +1,17 @@
1
1
  export default class Selection {
2
2
  /**
3
3
  * @constructor Selection
4
- * @param {{ DS:DragSelect, hoverClassName:string, multiSelectToggling:boolean }} p
4
+ * @param {{ DS:DragSelect }} p
5
5
  * @ignore
6
6
  */
7
- constructor({ DS, hoverClassName, multiSelectToggling }: {
7
+ constructor({ DS }: {
8
8
  DS: DragSelect;
9
- hoverClassName: string;
10
- multiSelectToggling: boolean;
11
9
  });
12
10
  /**
13
11
  * @type {Set}
14
12
  * @private
15
13
  * */
16
14
  private _prevSelectedSet;
17
- /**
18
- * @type {string}
19
- * @private
20
- * */
21
- private _hoverClassName;
22
- /**
23
- * @type {boolean}
24
- * @private
25
- * */
26
- private _multiSelectToggling;
27
15
  DS: DragSelect;
28
16
  /**
29
17
  * Stores the previous selection (solves #9)
@@ -1,18 +1,11 @@
1
1
  export default class Selector {
2
2
  /**
3
3
  * @constructor Selector
4
- * @param {Object} p
5
- * @param {DragSelect} p.DS
6
- * @param {HTMLElement} p.selector
7
- * @param {string} p.selectorClass
8
- * @param {boolean} p.customStyles
4
+ * @param {{ DS:DragSelect }} p
9
5
  * @ignore
10
6
  */
11
- constructor({ DS, selector, selectorClass, customStyles }: {
7
+ constructor({ DS }: {
12
8
  DS: DragSelect;
13
- selector: HTMLElement;
14
- selectorClass: string;
15
- customStyles: boolean;
16
9
  });
17
10
  /**
18
11
  * @type {DSBoundingRect}
@@ -20,6 +13,7 @@ export default class Selector {
20
13
  */
21
14
  private _rect;
22
15
  DS: DragSelect;
16
+ attachSelector: () => void;
23
17
  HTMLNode: HTMLElement;
24
18
  start: ({ isDragging }: {
25
19
  isDragging: any;
@@ -29,7 +23,7 @@ export default class Selector {
29
23
  update: ({ isDragging }: {
30
24
  isDragging: any;
31
25
  }) => void;
32
- get rect(): DSBoundingRect;
26
+ get rect(): DOMRect | DSBoundingRect;
33
27
  }
34
- import DragSelect from "../DragSelect.js";
28
+ import DragSelect from "../DragSelect";
35
29
  import "../types"
@@ -2,20 +2,12 @@ export default class SelectorArea {
2
2
  /**
3
3
  * @class SelectorArea
4
4
  * @constructor SelectorArea
5
- * @param {{ DS:DragSelect, selectorAreaClass:string, autoScrollSpeed:number, overflowTolerance:Vect2}} obj
5
+ * @param {{ DS:DragSelect }} obj
6
6
  * @ignore
7
7
  */
8
- constructor({ DS, selectorAreaClass, autoScrollSpeed, overflowTolerance }: {
8
+ constructor({ DS }: {
9
9
  DS: DragSelect;
10
- selectorAreaClass: string;
11
- autoScrollSpeed: number;
12
- overflowTolerance: Vect2;
13
10
  });
14
- /**
15
- * @type {number}
16
- * @private
17
- * */
18
- private _autoScrollSpeed;
19
11
  /**
20
12
  * @type {*}
21
13
  * @private
@@ -31,11 +23,6 @@ export default class SelectorArea {
31
23
  * @private
32
24
  */
33
25
  private currentEdges;
34
- /**
35
- * @type {Vect2}
36
- * @private
37
- */
38
- private _overflowTolerance;
39
26
  DS: DragSelect;
40
27
  HTMLNode: HTMLDivElement;
41
28
  start: () => void;
@@ -65,7 +52,7 @@ export default class SelectorArea {
65
52
  * @returns {boolean}
66
53
  */
67
54
  isClicked(event?: DSEvent): boolean;
68
- get rect(): DSBoundingRect;
55
+ get rect(): DOMRect | DSBoundingRect;
69
56
  }
70
- import DragSelect from "../DragSelect.js";
57
+ import DragSelect from "../DragSelect";
71
58
  import "../types"
@@ -2,24 +2,12 @@ export default class KeyStore {
2
2
  /**
3
3
  * @class KeyStore
4
4
  * @constructor KeyStore
5
- * @param {{DS:DragSelect,multiSelectKeys:DSMultiSelectKeys,multiSelectMode:boolean}} p
5
+ * @param {{DS:DragSelect}} p
6
6
  * @ignore
7
7
  */
8
- constructor({ DS, multiSelectKeys, multiSelectMode }: {
8
+ constructor({ DS }: {
9
9
  DS: DragSelect;
10
- multiSelectKeys: DSMultiSelectKeys;
11
- multiSelectMode: boolean;
12
10
  });
13
- /**
14
- * @type {boolean}
15
- * @private
16
- * */
17
- private _multiSelectMode;
18
- /**
19
- * @type {DSMultiSelectKeys}
20
- * @private
21
- * */
22
- private _multiSelectKeys;
23
11
  /**
24
12
  * @type {Set<string>}
25
13
  * @private
@@ -2,13 +2,11 @@ export default class ScrollStore {
2
2
  /**
3
3
  * @class ScrollStore
4
4
  * @constructor ScrollStore
5
- * @param {{ DS:DragSelect, areaElement: DSArea, zoom:number }} p
5
+ * @param {{ DS:DragSelect }} p
6
6
  * @ignore
7
7
  */
8
- constructor({ DS, areaElement, zoom }: {
8
+ constructor({ DS }: {
9
9
  DS: DragSelect;
10
- areaElement: DSArea;
11
- zoom: number;
12
10
  });
13
11
  /**
14
12
  * @type {Vect2}
@@ -18,16 +16,11 @@ export default class ScrollStore {
18
16
  * @type {Vect2}
19
17
  * @private */
20
18
  private _currentVal;
21
- /**
22
- * @type {DSArea}
23
- * @private */
24
- private _areaElement;
25
19
  /**
26
20
  * @type {boolean}
27
21
  * @private */
28
22
  private _canScroll;
29
23
  DS: DragSelect;
30
- zoom: number;
31
24
  init: () => void;
32
25
  start: () => void;
33
26
  update: () => Vect2;
@@ -0,0 +1,39 @@
1
+ export default class SettingsStore {
2
+ /**
3
+ * @class ScrollStore
4
+ * @constructor ScrollStore
5
+ * @param {{ DS:DragSelect, settings:Settings }} p
6
+ * @ignore
7
+ */
8
+ constructor({ DS, settings }: {
9
+ DS: DragSelect;
10
+ settings: Settings;
11
+ });
12
+ /**
13
+ * @type {Settings}
14
+ * @private
15
+ * */
16
+ private _settings;
17
+ /**
18
+ * Holds the settings and their previous value `:pre`
19
+ * @example {
20
+ * autoScrollSpeed: 3,
21
+ * 'autoScrollSpeed:pre': 5
22
+ * }
23
+ * @type {Settings}
24
+ * */
25
+ s: Settings;
26
+ DS: DragSelect;
27
+ /** @param {{settings: Settings, init?: boolean}} props */
28
+ update: ({ settings, init }: {
29
+ settings: Settings;
30
+ init?: boolean;
31
+ }) => void;
32
+ /** @param {{settings: Settings, init: boolean}} props */
33
+ _update: ({ settings, init }: {
34
+ settings: Settings;
35
+ init: boolean;
36
+ }) => void;
37
+ }
38
+ import DragSelect from "../DragSelect";
39
+ import "../types"
@@ -1,4 +1,5 @@
1
1
  export { default as KeyStore } from "./KeyStore";
2
2
  export { default as PointerStore } from "./PointerStore";
3
3
  export { default as ScrollStore } from "./ScrollStore";
4
+ export { default as SettingsStore } from "./SettingsStore";
4
5
  import "../types"
package/dist/types.d.ts CHANGED
@@ -86,30 +86,6 @@ type Settings = {
86
86
  * the class assigned to the square in which the selector resides. By default it's invisible
87
87
  */
88
88
  selectorAreaClass?: string;
89
- /**
90
- * Deprecated: please use DragSelect.subscribe('callback', callback) instead
91
- */
92
- callback?: DSCallback;
93
- /**
94
- * Deprecated: please use DragSelect.subscribe('onDragMove', onDragMove) instead
95
- */
96
- onDragMove?: DSCallback;
97
- /**
98
- * Deprecated: please use DragSelect.subscribe('onDragStartBegin', onDragStartBegin) instead
99
- */
100
- onDragStartBegin?: DSCallback;
101
- /**
102
- * Deprecated: please use DragSelect.subscribe('onDragStart', onDragStart) instead
103
- */
104
- onDragStart?: DSCallback;
105
- /**
106
- * Deprecated: please use DragSelect.subscribe('onElementSelect', onElementSelect) instead
107
- */
108
- onElementSelect?: DSCallback;
109
- /**
110
- * Deprecated: please use DragSelect.subscribe('onElementUnselect', onElementUnselect) instead
111
- */
112
- onElementUnselect?: DSCallback;
113
89
  };
114
90
  /**
115
91
  * The Object that is passed back to any callback method
@@ -139,6 +115,10 @@ type CallbackObject = {
139
115
  * Pressed key (lowercase)
140
116
  */
141
117
  key?: string;
118
+ /**
119
+ * the settings being updates/manipulated/passed, also holds the previous value. i.e. updating selectorClass will publish { settings: { selectorClass: 'newVal', 'selectorClass:pre': 'oldVal' } }
120
+ */
121
+ settings?: Settings;
142
122
  scroll_directions?: Array<'top' | 'bottom' | 'left' | 'right' | undefined>;
143
123
  scroll_multiplier?: number;
144
124
  };
@@ -155,7 +135,7 @@ type DSElementPos = {
155
135
  r: number;
156
136
  b: number;
157
137
  };
158
- type DSEdges = ("left" | "right" | "bottom" | "top")[];
138
+ type DSEdges = Array<'top' | 'bottom' | 'left' | 'right' | undefined>;
159
139
  /**
160
140
  * area within which you can drag
161
141
  */
@@ -167,11 +147,11 @@ type DSSelectorArea = HTMLElement;
167
147
  /**
168
148
  * the elements that can be selected
169
149
  */
170
- type DSInputElements = HTMLElement | SVGElement | (HTMLElement | SVGElement)[];
150
+ type DSInputElements = Array<HTMLElement | SVGElement> | HTMLElement | SVGElement;
171
151
  /**
172
152
  * the elements that can be selected
173
153
  */
174
- type DSElements = (HTMLElement | SVGElement)[];
154
+ type DSElements = Array<HTMLElement | SVGElement>;
175
155
  /**
176
156
  * a single element that can be selected
177
157
  */
@@ -183,14 +163,15 @@ type DSEvent = MouseEvent | TouchEvent;
183
163
  /**
184
164
  * An array of keys that allows switching to the multi-select mode
185
165
  */
186
- type DSMultiSelectKeys = string[];
187
- type DSEventNames = "dragstart" | "dragmove" | "autoscroll" | "elementselect" | "elementunselect" | "callback";
188
- type DSInternalEventNames = "Interaction:init" | "Interaction:start" | "Interaction:end" | "Interaction:update" | "Area:modified" | "Area:scroll" | "PointerStore:updated" | "Selected:added" | "Selected:removed" | "Selectable:click" | "Selectable:pointer" | "KeyStore:down" | "KeyStore:up";
189
- type DSInternalEventNamesPre = "Interaction:init:pre" | "Interaction:start:pre" | "Interaction:end:pre" | "Interaction:update:pre" | "Area:modified:pre" | "Area:scroll:pre" | "PointerStore:updated:pre" | "Selected:added:pre" | "Selected:removed:pre" | "Selectable:click:pre" | "Selectable:pointer:pre" | "KeyStore:down:pre" | "KeyStore:up:pre";
166
+ type DSMultiSelectKeys = Array<'Shift' | 'Control' | 'Meta' | string>;
167
+ type DSEventNames = 'dragmove' | 'autoscroll' | 'dragstart' | 'elementselect' | 'elementunselect' | 'callback';
168
+ type DSInternalEventNames = 'Interaction:init' | 'Interaction:start' | 'Interaction:end' | 'Interaction:update' | 'Area:modified' | 'Area:scroll' | 'PointerStore:updated' | 'Selected:added' | 'Selected:removed' | 'Selectable:click' | 'Selectable:pointer' | 'KeyStore:down' | 'KeyStore:up';
169
+ type DSInternalEventNamesPre = 'Interaction:init:pre' | 'Interaction:start:pre' | 'Interaction:end:pre' | 'Interaction:update:pre' | 'Area:modified:pre' | 'Area:scroll:pre' | 'PointerStore:updated:pre' | 'Selected:added:pre' | 'Selected:removed:pre' | 'Selectable:click:pre' | 'Selectable:pointer:pre' | 'KeyStore:down:pre' | 'KeyStore:up:pre';
170
+ type DSInternalSettingEvents = 'Settings:updated' | 'Settings:updated:pre' | 'Settings:updated:*' | 'Settings:updated:*:pre';
190
171
  /**
191
172
  * the name of the callback
192
173
  */
193
- type DSCallbackNames = "dragstart" | "dragmove" | "autoscroll" | "elementselect" | "elementunselect" | "callback" | "Interaction:init" | "Interaction:start" | "Interaction:end" | "Interaction:update" | "Area:modified" | "Area:scroll" | "PointerStore:updated" | "Selected:added" | "Selected:removed" | "Selectable:click" | "Selectable:pointer" | "KeyStore:down" | "KeyStore:up" | "Interaction:init:pre" | "Interaction:start:pre" | "Interaction:end:pre" | "Interaction:update:pre" | "Area:modified:pre" | "Area:scroll:pre" | "PointerStore:updated:pre" | "Selected:added:pre" | "Selected:removed:pre" | "Selectable:click:pre" | "Selectable:pointer:pre" | "KeyStore:down:pre" | "KeyStore:up:pre";
174
+ type DSCallbackNames = DSEventNames | DSInternalEventNames | DSInternalEventNamesPre | DSInternalSettingEvents;
194
175
  type DSBoundingRect = {
195
176
  top: number;
196
177
  left: number;
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "dragselect",
3
- "version": "2.3.0",
3
+ "version": "2.4.0",
4
4
  "description": "easy javascript drag select functionality for your projects",
5
5
  "main": "./dist/DragSelect.js",
6
6
  "types": "./dist/DragSelect.d.ts",
@@ -13,6 +13,7 @@
13
13
  "checkjs": "tsc --lib es2019,dom -t es5 --allowJs --checkJs --noEmit src/*.js",
14
14
  "checkjs:watch": "npm run checkjs -- -w",
15
15
  "postcheckjs": "npm run docs && rm -rf docs",
16
+ "pretest": "npm run build",
16
17
  "test": "npm run checkjs && jest --detectOpenHandles",
17
18
  "test:watch": "npm run test -- --watch",
18
19
  "\n# BUILDING:": "",
@@ -60,13 +61,13 @@
60
61
  "glob": "^7.1.7",
61
62
  "jest": "^26.6.3",
62
63
  "jest-puppeteer": "^4.4.0",
63
- "jsdoc": "^3.6.6",
64
+ "jsdoc": "^3.6.11",
64
65
  "minami": "^1.2.3",
65
66
  "prettier": "^2.2.1",
66
67
  "puppeteer": "^5.5.0",
67
68
  "rollup": "^2.36.1",
68
69
  "rollup-plugin-terser": "^7.0.2",
69
- "typescript": "^4.1.3"
70
+ "typescript": "^4.8.0"
70
71
  },
71
72
  "repository": {
72
73
  "type": "git",