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
package/CHANGELOG.md CHANGED
@@ -1,3 +1,14 @@
1
+ # Next
2
+
3
+ - Change all Properties dynamically *anytime*. Solves #111 and #95. Very helpful for async libraries like react. You can do so using the `setSettings` method, you can pass any settings in the object and they will be updated. Example: update the drag area at any time by running: `ds.setSettings({ area: document.getElementById("new-area") })`.
4
+ - Remove deprecated keys `ctrlKey`, `shiftKey` and `metaKey`. Use `Control`, `Shift` and `Meta` respectively instead.
5
+ - Remove deprecated method `getCursorPositionDifference`. Calculate the difference on your own instead.
6
+ - Remove deprecated setting property callbacks. Use `DragSelect.subscribe("callback", (callbackObject) => {})` instead.
7
+
8
+ # 2.3.1
9
+
10
+ - Fix bug [#109](https://github.com/ThibaultJanBeyer/DragSelect/issues/109) where inner elements are ignored from normal drag behavior
11
+
1
12
  # 2.3.0
2
13
 
3
14
  - Fix bug with break not working. (still handling change)
@@ -5,6 +16,7 @@
5
16
  - **Caution**:
6
17
  - - This upgrade changes the order in which the callbacks are fired. The normal callbacks are fired in a FIFO order, first in, first out. The `pre` callbacks are fired in a LIFO order, last in first out.
7
18
  - - Pre Events are now really triggered *before* the whole action.
19
+ - Fixes issue [#110](https://github.com/ThibaultJanBeyer/DragSelect/issues/110) where teardown did not work properly
8
20
 
9
21
  # 2.2.2
10
22
 
package/README.md CHANGED
@@ -9,7 +9,7 @@
9
9
 
10
10
  [GitHub](https://github.com/ThibaultJanBeyer/DragSelect/) | [NPM](https://www.npmjs.com/package/dragselect) | [Project-Page](https://dragselect.com/)
11
11
 
12
- [![Build Status](https://travis-ci.com/ThibaultJanBeyer/DragSelect.svg?branch=master)](https://travis-ci.com/ThibaultJanBeyer/DragSelect) ![gzip size](https://img.badgesize.io/https://dragselect.com/v2/ds.min.js?compression=gzip) ![npm downloads count](https://img.shields.io/npm/dt/dragselect.svg) [![No Dependency](https://david-dm.org/ThibaultJanBeyer/DragSelect.svg)](https://david-dm.org/ThibaultJanBeyer/DragSelect)
12
+ [![Build Status](https://travis-ci.com/ThibaultJanBeyer/DragSelect.svg?branch=master)](https://travis-ci.com/ThibaultJanBeyer/DragSelect) ![gzip size](https://img.badgesize.io/https://dragselect.com/v2/ds.min.js?compression=gzip) ![npm downloads count](https://img.shields.io/npm/dt/dragselect.svg) [![No Dependency](https://img.shields.io/badge/dependencies-none-informational)](https://github.com/ThibaultJanBeyer/DragSelect/blob/master/package.json) [![Contributors Welcome](https://img.shields.io/badge/contributors-welcome-blueviolet)](https://github.com/ThibaultJanBeyer/DragSelect/blob/master/CONTRIBUTING.md) [![Sponsors Welcome](https://img.shields.io/badge/sponsors-welcome-blueviolet)](https://github.com/sponsors/ThibaultJanBeyer)
13
13
 
14
14
  # DragSelect ![GitHub package.json version](https://img.shields.io/github/package-json/v/ThibaultJanBeyer/DragSelect.svg)
15
15
  easily add a selection algorithm to your application/website.
@@ -25,10 +25,11 @@ easily add a selection algorithm to your application/website.
25
25
  - - [Simple](#simple)
26
26
  - - [Within a scroll-able Area](#within-a-scroll-able-area)
27
27
  - - [Extended](#extended)
28
- - - [Mobile/Touch usage](#mobile/touch-usage)
28
+ - - [Mobile Touch usage](#mobiletouch-usage)
29
29
  - - [Accessibility (a11y)](#accessibility-a11y)
30
30
  - - [Use your own Drag And Drop](#use-your-own-drag-and-drop)
31
- - [Constructor Properties](#constructor-properties)
31
+ - [Constructor Properties (Settings)](#constructor-properties-settings)
32
+ - - [Post initialization setting updates](#post-initialization-setting-updates)
32
33
  - [Event Callbacks](#event-callbacks)
33
34
  - - [Callback Object Keys](#callback-object-keys)
34
35
  - [Methods](#methods)
@@ -40,7 +41,7 @@ easily add a selection algorithm to your application/website.
40
41
 
41
42
  # Key-Features
42
43
 
43
- - **No dependencies** [![No Dependency](https://david-dm.org/ThibaultJanBeyer/DragSelect.svg)](https://david-dm.org/ThibaultJanBeyer/DragSelect)
44
+ - **No dependencies** [![No Dependency](https://img.shields.io/badge/dependencies-none-informational)](https://github.com/ThibaultJanBeyer/DragSelect/blob/master/package.json)
44
45
  - Hyper customizable
45
46
  - Replicates operating system drag-selection in the browser
46
47
  - Accessibility (a11y)
@@ -68,16 +69,23 @@ We use it currently in a professional rich interface application where we have a
68
69
 
69
70
  # Supporters
70
71
 
71
- Please donate to support the countless hours of hard work & support. Especially if your company makes money. Thank you :)
72
+ Please donate to support the countless hours of hard work & support. Especially if your company makes money, then there is no excuse. Thank you :)
72
73
 
73
- Thanks to:
74
+ If you're too poor or broke you can still support us with your time instead by [contributing to the code](https://github.com/ThibaultJanBeyer/DragSelect/blob/master/CONTRIBUTING.md)!
74
75
 
75
- | ![BrowserStack](https://dragselect.com/media/browserstack.jpg) | [You?](https://paypal.me/pools/c/8gF2a5szCP) |
76
+ ## Thanks to:
77
+
78
+ | ![BrowserStack](https://dragselect.com/media/browserstack.jpg) | [You?](https://github.com/sponsors/ThibaultJanBeyer) |
76
79
  |--- |--- |
77
- |[BrowserStack](https://www.browserstack.com/) is an amazing testing service which helps testing the tool on various browsers. They support this open source projects by providing a [free account for open source projects](https://www.browserstack.com/open-source) to use their service! | Thank and support us by making a [Direct Donation](https://paypal.me/pools/c/8gF2a5szCP) (Donations are distributed with all project contributors proportionally. We are grateful for any amount) or [Get in touch](mailto:thibault.beyer@gmail.com). We can display your logo here if you want, which will help you recruit great talent and boost your SEO. |
78
- BTC: [1LdweSpjgSeJC8XxX3swrohBMBLUzg6cmC](https://www.blockchain.com/btc/address/1LdweSpjgSeJC8XxX3swrohBMBLUzg6cmC) |
79
- Paypal: [https://paypal.me/pools/c/8gF2a5szCP](https://paypal.me/pools/c/8gF2a5szCP) |
80
- Other: [get in touch](mailto:thibault.beyer@gmail.com) |
80
+ |[BrowserStack](https://www.browserstack.com/) is a testing service which helps testing the tool on various browsers. They support this open source projects by providing us with a [free account](https://www.browserstack.com/open-source)! | Thank and support us by making a [Direct Donation to DragSelect](https://www.blockchain.com/btc/address/1LdweSpjgSeJC8XxX3swrohBMBLUzg6cmC) (via Bitcoin: `1LdweSpjgSeJC8XxX3swrohBMBLUzg6cmC`). Or sponsor via [GitHub Sponsors](https://github.com/sponsors/ThibaultJanBeyer) or [Get in touch](mailto:thibault.beyer@gmail.com). |
81
+ | Via BTC: | [1LdweSpjgSeJC8XxX3swrohBMBLUzg6cmC](https://www.blockchain.com/btc/address/1LdweSpjgSeJC8XxX3swrohBMBLUzg6cmC) (direct) |
82
+ | Via GitHub: | [GitHub Sponsors](https://github.com/sponsors/ThibaultJanBeyer) (monthly & one-time) |
83
+ | Other: | [get in touch](mailto:thibault.beyer@gmail.com) |
84
+
85
+ All donations are distributed with all project contributors proportionally to their involvement. We are grateful for any amount:
86
+ We have more than ![npm downloads count](https://img.shields.io/npm/dt/dragselect.svg), imagine how much we'd have if everyone would have had donated only 1$ 🤩 (unfortunately this did not happen)
87
+
88
+ If you donate, we can display your logo here if you want, which will give you fame, fortune and help you recruit great talent and boosting your SEO.
81
89
 
82
90
  # Installation
83
91
  ## NPM
@@ -146,26 +154,24 @@ All options are optional. You could also just initiate the Dragselect by `new Dr
146
154
  Find all possible properties and methods in **[the docs](https://dragselect.com/DragSelect.html)**
147
155
 
148
156
  ```javascript
157
+ // if you add the function to a variable like this, you have access to all its functions
149
158
  const ds = new DragSelect({
150
- // node/nodes that can be selected.
151
- // This is also optional, you could just add them later with .addSelectables().
159
+ // all settings are optional and can be added later
160
+ });
161
+
162
+ // this is how you add/update settings after initialization
163
+ ds.setSettings({
164
+ // node/nodes that can be selected. By default will never add elements twice:
152
165
  selectables: document.querySelectorAll('.selectable-nodes'),
153
166
  // area in which you can drag. If not provided it will be the whole document & body/documentElement.
154
167
  area: document.getElementById('area'),
155
168
  // and many more, see "properties" section in the docs
156
- });
157
-
158
- // if you add the function to a variable like we did, you have access to all its functions:
169
+ })
159
170
 
160
171
  // fired once the user releases the mouse. (items) = selected nodes:
161
172
  ds.subscribe('callback', ({ items, event }) => {})
162
-
163
173
  // returns all currently selected nodes:
164
174
  ds.getSelection();
165
-
166
- // adds elements that can be selected. Won't add elements twice:
167
- ds.addSelectables(document.getElementsByClassName('selectable-node'));
168
-
169
175
  // Teardown/stop the whole functionality:
170
176
  ds.stop();
171
177
  // Reset the functionality after a teardown:
@@ -253,9 +259,13 @@ ds.subscribe('predragmove', ({ isDragging, isDraggingKeyboard }) => {
253
259
  }
254
260
  ```
255
261
 
256
- # Constructor Properties:
262
+ # Constructor Properties (Settings):
257
263
 
258
- *DragSelect is hyper customizable*. Note, all properties are optional. See **[the docs](https://dragselect.com/DragSelect.html)** for more info. Here is the full list:
264
+ *DragSelect is hyper customizable*. Note, all properties are optional. See **[the docs](https://dragselect.com/DragSelect.html)** for more info.
265
+
266
+ Moreover any setting can also be updated or added after the initialization, see [post-initialization setting updates](#post-initialization-setting-updates).
267
+
268
+ Here is the full list:
259
269
 
260
270
  | property | type | usage | default |
261
271
  |--- |--- |--- |--- |
@@ -280,6 +290,18 @@ ds.subscribe('predragmove', ({ isDragging, isDraggingKeyboard }) => {
280
290
  |selectorClass |string |The class name assigned to the square selector helper. |[see classes](#classes)
281
291
  |selectableClass |string |The class name assigned to the elements that can be selected. |[see classes](#classes)
282
292
 
293
+ ## Post-Initialization Setting-Updates
294
+
295
+ Any setting can be updated/added after initialization by using the `setSettings` method. Here is an example updating the `area` and the `selectables`:
296
+
297
+ ```JavaScript
298
+ const ds = new DragSelect({})
299
+ ds.setSettings({
300
+ selectables: document.getElementsByClassName('selectable-nodes'),
301
+ area: document.getElementById('area')
302
+ })
303
+ ```
304
+
283
305
  # Event Callbacks
284
306
 
285
307
  Event Callbacks are used like this:
@@ -342,7 +364,7 @@ Also check **[the docs](https://dragselect.com/DragSelect.html)** for more info.
342
364
  |getCursorPositionDifference |Boolean (usePreviousCursorDifference) |Returns object with the x, y difference between the initial and the last cursor position. If the argument is set to true, it will instead return the x, y difference to the previous coordinates |
343
365
  |isMultiSelect |\[event:KeyboardEvent|MouseEvent|TouchEvent\] (optional) |Whether the multi-select key is currently pressed
344
366
  |isDragging |/ |Whether the user is currently drag n dropping elements (instead of selection)
345
- |break |/ |Utility to override DragSelect internal functionality. Read [docs](#writing-a-fully-custom-solution) for more info.
367
+ |break |/ |Utility to override DragSelect internal functionality. Breaks out of current flow. Read [docs](#writing-a-fully-custom-solution) for more info.
346
368
 
347
369
  # Classes
348
370
  | name | trigger |
@@ -359,7 +381,7 @@ Also check **[the docs](https://dragselect.com/DragSelect.html)** for more info.
359
381
 
360
382
  Creating and maintaining useful tools is a lot of work.
361
383
  So don’t forget to give this repository a star if you find it useful.
362
- Star this repo, tell all your friends and start contributing and/or [donating 1$](https://paypal.me/pools/c/8gF2a5szCP) to keep it running. Thank you :)
384
+ Star this repo, tell all your friends and start contributing and/or [donating 1$](https://github.com/sponsors/ThibaultJanBeyer) to keep it running. Thank you :)
363
385
 
364
386
  [![Typewriter Gif](https://dragselect.com/media/typewriter.gif)](https://thibaultjanbeyer.com/)
365
387
 
package/deploying.md CHANGED
@@ -11,21 +11,24 @@ if you are a regular contributor, see [contibuting](CONTRIBUTING.md) and make a
11
11
 
12
12
  ## Deploying
13
13
 
14
- Tipically you don’t have to do this, since you most likely are not the project owner.
14
+ Typically you don’t have to do this, since you most likely are not the project owner.
15
15
  But if you are the project owner:
16
16
 
17
- - Travis will take care of deployment to gh-pages when you push/merge to github (gh-pages will be build by travis)
17
+ - Travis will take care of deployment to gh-pages when you push/merge to github (gh-pages will be build by Travis)
18
18
 
19
19
  If this was successful, the next step is to publish the new version on `npm`:
20
20
 
21
21
  ```
22
22
  npm version patch
23
23
  npm run rollup
24
- npm publish
25
24
  ```
26
25
  Rollup is necessary for npm packages (since `dist` will be deployed to npm but is ignored in repo)
27
26
 
28
27
  versions are either `patch` wich changes 0.0.x, `minor` wich changes 0.x.0 or `major` for x.0.0.
29
28
  See [npm docs](https://docs.npmjs.com/getting-started/publishing-npm-packages)
30
29
 
31
- After that push again, just to make sure
30
+ After that push again, just to make sure and then publish
31
+
32
+ ```
33
+ npm publish
34
+ ```
@@ -5,7 +5,7 @@ declare class DragSelect {
5
5
  * @constructor DragSelect
6
6
  * @param {Settings} settings
7
7
  */
8
- constructor({ area, selectables, autoScrollSpeed, overflowTolerance, zoom, customStyles, multiSelectMode, multiSelectToggling, multiSelectKeys, selector, draggability, immediateDrag, keyboardDrag, dragKeys, keyboardDragSpeed, useTransform, hoverClass, selectableClass, selectedClass, selectorClass, selectorAreaClass, callback, onDragMove, onDragStartBegin, onDragStart, onElementSelect, onElementUnselect, }: Settings);
8
+ constructor(settings: Settings);
9
9
  /**
10
10
  * used to skip all current Selection and dragNdrop functionality
11
11
  * @type {boolean}
@@ -14,8 +14,9 @@ declare class DragSelect {
14
14
  PubSub: PubSub;
15
15
  subscribe: (eventName: DSCallbackNames, callback: Function) => number;
16
16
  unsubscribe: (eventName: DSCallbackNames, callback?: Function, id?: number) => void;
17
- publish: (eventName: "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" | DSCallbackNames[], data: CallbackObject) => void;
17
+ publish: (eventName: DSCallbackNames | DSCallbackNames[], data: CallbackObject) => void;
18
18
  stores: {
19
+ SettingsStore: SettingsStore;
19
20
  PointerStore: PointerStore;
20
21
  ScrollStore: ScrollStore;
21
22
  KeyStore: KeyStore;
@@ -28,14 +29,6 @@ declare class DragSelect {
28
29
  Selection: Selection;
29
30
  Drag: Drag;
30
31
  Interaction: Interaction;
31
- _callbacksTemp({ callback, onDragMove, onDragStart, onDragStartBegin, onElementSelect, onElementUnselect, }: {
32
- callback: any;
33
- onDragMove: any;
34
- onDragStart: any;
35
- onDragStartBegin: any;
36
- onElementSelect: any;
37
- onElementUnselect: any;
38
- }): void;
39
32
  /**
40
33
  * Initializes the functionality. Automatically triggered when created.
41
34
  * Also, reset the functionality after a teardown
@@ -151,21 +144,20 @@ declare class DragSelect {
151
144
  * @return {boolean}
152
145
  */
153
146
  isMultiSelect: (event?: DSEvent | KeyboardEvent) => boolean;
154
- /**
155
- * Utility method that returns the cursor position difference between start and now
156
- * @param {boolean} [usePreviousCursorDifference] if true, it will output the cursor position difference between the previous selection and now
157
- * @param {boolean} [useAreaPositions] if true, it will use cursor positions relative to the area
158
- * @return {Vect2}
159
- * @deprecated
160
- */
161
- getCursorPositionDifference(usePreviousCursorDifference?: boolean, useAreaPositions?: boolean): Vect2;
162
147
  /**
163
148
  * Whether the user is currently drag n dropping elements (instead of selection)
164
149
  * @return {boolean}
165
150
  */
166
151
  isDragging: () => boolean;
152
+ /**
153
+ * Update any setting dynamically
154
+ * @param {Settings} settings
155
+ * @return {void}
156
+ */
157
+ setSettings: (settings: Settings) => void;
167
158
  }
168
159
  import { PubSub } from "./modules";
160
+ import { SettingsStore } from "./stores";
169
161
  import { PointerStore } from "./stores";
170
162
  import { ScrollStore } from "./stores";
171
163
  import { KeyStore } from "./stores";