dragselect 2.5.3 → 2.5.5

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/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "dragselect",
3
- "version": "2.5.3",
3
+ "version": "2.5.5",
4
4
  "description": "easy javascript drag select & drop functionality for your projects",
5
5
  "main": "./dist/DragSelect.js",
6
6
  "types": "./dist/DragSelect.d.ts",
@@ -12,13 +12,12 @@
12
12
  "\n# TESTING:": "",
13
13
  "checkjs": "tsc --lib es2019,dom -t es5 --allowJs --skipLibCheck --checkJs --noEmit src/*.js",
14
14
  "checkjs:watch": "npm run checkjs -- -w",
15
- "postcheckjs": "npm run docs && rm -rf docs",
16
15
  "pretest": "npm run build",
17
16
  "test": "npm run checkjs && jest --detectOpenHandles",
18
17
  "test:watch": "npm run test -- --watch",
19
18
  "\n# BUILDING:": "",
20
19
  "build": "npm run rollup",
21
- "docs": "jsdoc -c jsdoc.json",
20
+ "docs": "cd www && yarn && yarn build && cd ..",
22
21
  "premedia": "rm -r docs/media &",
23
22
  "media": "cp -R .media docs/media",
24
23
  "prerollup": "npm run types",
@@ -27,7 +26,7 @@
27
26
  "rollup:watch": "npm run rollup -- -w",
28
27
  "types": "tsc src/DragSelect.js --lib es2019,dom -t es5 --declaration --allowJs --emitDeclarationOnly --skipLibCheck --outDir dist",
29
28
  "\n## PROD:": "",
30
- "ci:build": "npm run rollup:ci && npm run media && npm run docs",
29
+ "ci:build": "npm run docs && npm run rollup:ci && npm run media",
31
30
  "ci:test": "npm run test"
32
31
  },
33
32
  "devDependencies": {
@@ -62,13 +61,12 @@
62
61
  "glob": "^7.1.7",
63
62
  "jest": "^26.6.3",
64
63
  "jest-puppeteer": "^6.1.1",
65
- "jsdoc": "^3.6.11",
66
64
  "minami": "^1.2.3",
67
65
  "prettier": "^2.2.1",
68
66
  "puppeteer": "18.1.0",
69
67
  "rollup": "^2.36.1",
70
68
  "rollup-plugin-terser": "^7.0.2",
71
- "typescript": "^4.8.0"
69
+ "typescript": "^4.9.3"
72
70
  },
73
71
  "repository": {
74
72
  "type": "git",
package/rollup.config.js CHANGED
@@ -6,6 +6,7 @@ import resolve from '@rollup/plugin-node-resolve'
6
6
  import { terser } from 'rollup-plugin-terser'
7
7
 
8
8
  let typesDone = false
9
+ let copyDocsDone = false
9
10
  const banner = `/***
10
11
 
11
12
  ~~~ Version ${process.env.npm_package_version} ~~~
@@ -45,13 +46,13 @@ export default {
45
46
  file: 'dist/DragSelect.es6m.js',
46
47
  format: 'es',
47
48
  name: 'DragSelect',
48
- banner: banner,
49
+ banner,
49
50
  },
50
51
  {
51
52
  file: 'dist/DragSelect.js',
52
53
  format: 'umd',
53
54
  name: 'DragSelect',
54
- banner: banner,
55
+ banner,
55
56
  },
56
57
  {
57
58
  file: 'dist/ds.es6m.min.js',
@@ -75,18 +76,22 @@ export default {
75
76
  name: 'copy',
76
77
  writeBundle(options) {
77
78
  if (!process.argv.includes('--ci')) return
79
+
80
+ // v1
78
81
  if (!fs.existsSync('docs/')) fs.mkdirSync('docs')
79
82
  fs.copyFileSync(
80
83
  `.v1/${path.basename(options.file)}`,
81
84
  `docs/${path.basename(options.file)}`
82
85
  )
83
- console.log(
86
+ console.info(
84
87
  `.v1/${path.basename(options.file)}`,
85
88
  `docs/${path.basename(options.file)}`
86
89
  )
90
+
91
+ // v2
87
92
  if (!fs.existsSync('docs/v2')) fs.mkdirSync('docs/v2')
88
93
  fs.copyFileSync(options.file, `docs/v2/${path.basename(options.file)}`)
89
- console.log(options.file, `docs/v2/${path.basename(options.file)}`)
94
+ console.info(options.file, `docs/v2/${path.basename(options.file)}`)
90
95
  },
91
96
  },
92
97
  {
@@ -94,7 +99,7 @@ export default {
94
99
  writeBundle() {
95
100
  if (typesDone) return
96
101
  typesDone = true
97
- console.log(`Adding types to all ts files`)
102
+ console.info(`Adding types to all ts files`)
98
103
  glob('dist/**/*.d.ts', (er, files) => {
99
104
  if (er) throw er
100
105
  files.forEach((fileName) => {
@@ -108,6 +113,15 @@ export default {
108
113
  })
109
114
  },
110
115
  },
116
+ {
117
+ name: 'copy-www-docs',
118
+ writeBundle() {
119
+ if (!process.argv.includes('--ci') || copyDocsDone) return
120
+ copyDocsDone = true
121
+ console.info(`Adding www/build output to docs/ folder`)
122
+ fs.cpSync(`www/build`, `docs/`, { recursive: true })
123
+ },
124
+ },
111
125
  {
112
126
  name: 'disable-treeshaking',
113
127
  transform(code, id) {
package/src/DragSelect.js CHANGED
@@ -59,7 +59,7 @@ import { PointerStore, ScrollStore, KeyStore, SettingsStore } from './stores'
59
59
  import { toArray, subscriberAliases } from './methods'
60
60
 
61
61
  // Setup
62
- //////////////////////////////////////////////////////////////////////////////////////
62
+ /// ///////////////////////////////////////////////////////////////////////////////////
63
63
 
64
64
  class DragSelect {
65
65
  /**
@@ -67,6 +67,7 @@ class DragSelect {
67
67
  * @type {boolean}
68
68
  */
69
69
  continue = false
70
+
70
71
  /**
71
72
  * @class DragSelect
72
73
  * @constructor DragSelect
@@ -113,7 +114,7 @@ class DragSelect {
113
114
  }
114
115
 
115
116
  // Useful methods for the user
116
- //////////////////////////////////////////////////////////////////////////////////////
117
+ /// ///////////////////////////////////////////////////////////////////////////////////
117
118
  /**
118
119
  * Initializes the functionality. Automatically triggered when created.
119
120
  * Also, reset the functionality after a teardown
@@ -122,6 +123,7 @@ class DragSelect {
122
123
  this.stopped = false
123
124
  this.Interaction.init()
124
125
  }
126
+
125
127
  /**
126
128
  * Complete function teardown
127
129
  * Will teardown/stop the whole functionality
@@ -146,23 +148,27 @@ class DragSelect {
146
148
 
147
149
  this.stopped = true
148
150
  }
151
+
149
152
  /**
150
153
  * Utility to override DragSelect internal functionality:
151
154
  * Break will skip the selection or dragging functionality (until after the callback) but let everything continue to run.
152
155
  * Useful utility to write your own functionality/move/dragNdrop based on DragSelect pointer positions.
153
156
  */
154
157
  break = () => (this.continue = true)
158
+
155
159
  /**
156
160
  * Update any setting dynamically
157
161
  * @param {Settings} settings
158
162
  * @return {void}
159
163
  */
160
164
  setSettings = (settings) => this.stores.SettingsStore.update({ settings })
165
+
161
166
  /**
162
167
  * Returns the current selected nodes
163
168
  * @return {DSElements}
164
169
  */
165
170
  getSelection = () => this.SelectedSet.elements
171
+
166
172
  /**
167
173
  * Adds several elements to the selection list also adds the specific classes and take into account all calculations.
168
174
  * Does not clear the selection, in contrary to .setSelection. Can add multiple elements at once
@@ -182,6 +188,7 @@ class DragSelect {
182
188
  this.PubSub.publish('callback', { items: this.getSelection() })
183
189
  return this.getSelection()
184
190
  }
191
+
185
192
  /**
186
193
  * Removes specific elements from the selection
187
194
  * Multiple elements can be given at once, in contrary to unselect
@@ -201,25 +208,31 @@ class DragSelect {
201
208
  this.PubSub.publish('callback', { items: this.getSelection() })
202
209
  return this.getSelection()
203
210
  }
211
+
204
212
  /**
205
213
  * Toggles specific elements from the selection:
206
214
  * If element is not in selection it will be added, if it is already selected, it will be removed.
207
215
  * Multiple elements can be given at once.
208
216
  * @param {DSInputElements} elements one or multiple elements
209
217
  * @param {boolean} [triggerCallback] - if callback should be called
210
- * @param {boolean} [alsoSelectables] - if element should not be added/removed to the list of selectable elements accordingly
218
+ * @param {boolean} [removeFromSelectables] - if element should not be added/removed to the list of selectable elements accordingly
211
219
  * @return {DSElements} all selected elements
212
220
  */
213
- toggleSelection(elements, triggerCallback = false, alsoSelectables = false) {
221
+ toggleSelection(
222
+ elements,
223
+ triggerCallback = false,
224
+ removeFromSelectables = false
225
+ ) {
214
226
  toArray(elements).forEach((el) =>
215
227
  this.SelectedSet.has(el)
216
- ? this.removeSelection(elements, triggerCallback, alsoSelectables)
217
- : this.addSelection(elements, triggerCallback, alsoSelectables)
228
+ ? this.removeSelection(elements, triggerCallback, removeFromSelectables)
229
+ : this.addSelection(elements, triggerCallback, removeFromSelectables)
218
230
  )
219
231
  if (triggerCallback)
220
232
  this.PubSub.publish('callback', { items: this.getSelection() })
221
233
  return this.getSelection()
222
234
  }
235
+
223
236
  /**
224
237
  * Sets the current selected elements and optionally run the callback
225
238
  * By default, adds new elements also to the list of selectables
@@ -237,6 +250,7 @@ class DragSelect {
237
250
  this.addSelection(elements, triggerCallback, dontAddToSelectables)
238
251
  return this.getSelection()
239
252
  }
253
+
240
254
  /**
241
255
  * Unselect / Deselect all current selected Nodes
242
256
  * @param {boolean} [triggerCallback] - if callback should be called
@@ -248,6 +262,7 @@ class DragSelect {
248
262
  this.PubSub.publish('callback', { items: this.getSelection() })
249
263
  return this.getSelection()
250
264
  }
265
+
251
266
  /**
252
267
  * Add elements that can be selected. No node is added twice
253
268
  * @param {DSInputElements} elements dom element(s)
@@ -263,11 +278,13 @@ class DragSelect {
263
278
  this.PubSub.publish('callback', { items: this.getSelection() })
264
279
  return elements
265
280
  }
281
+
266
282
  /**
267
283
  * Gets all nodes that can potentially be selected
268
284
  * @return {DSElements} this.selectables
269
285
  */
270
286
  getSelectables = () => this.SelectableSet.elements
287
+
271
288
  /**
272
289
  * Sets all elements that can be selected.
273
290
  * Removes all current selectables (& their respective classes).
@@ -282,10 +299,13 @@ class DragSelect {
282
299
  removeFromSelection = false,
283
300
  addToSelection = false
284
301
  ) {
285
- console.warn('[DragSelect] DEPRECATION ".setSelectables" is deprecated and will be removed soon. Please use "ds.setSettings({ selectables: << new dom elements >> })" instead (see docs)')
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
+ )
286
305
  this.removeSelectables(elements, removeFromSelection)
287
306
  return this.addSelectables(elements, addToSelection)
288
307
  }
308
+
289
309
  /**
290
310
  * Remove elements from the elements that can be selected.
291
311
  * @param {DSInputElements} elements – dom element(s)
@@ -300,49 +320,63 @@ class DragSelect {
300
320
  this.PubSub.publish('callback', { items: this.getSelection() })
301
321
  return elements
302
322
  }
323
+
303
324
  /** The starting/initial position of the cursor/selector @return {Vect2} */
304
325
  getInitialCursorPosition = () => this.stores.PointerStore.initialVal
326
+
305
327
  /** The last seen position of the cursor/selector @return {Vect2} */
306
328
  getCurrentCursorPosition = () => this.stores.PointerStore.currentVal
329
+
307
330
  /** The previous position of the cursor/selector @return {Vect2} */
308
331
  getPreviousCursorPosition = () => this.stores.PointerStore.lastVal
332
+
309
333
  /** The starting/initial position of the cursor/selector @return {Vect2} */
310
334
  getInitialCursorPositionArea = () => this.stores.PointerStore.initialValArea
335
+
311
336
  /** The last seen position of the cursor/selector @return {Vect2} */
312
337
  getCurrentCursorPositionArea = () => this.stores.PointerStore.currentValArea
338
+
313
339
  /** The previous position of the cursor/selector @return {Vect2} */
314
340
  getPreviousCursorPositionArea = () => this.stores.PointerStore.lastValArea
341
+
315
342
  /**
316
343
  * Whether the multi-selection key was pressed
317
344
  * @param {DSEvent|KeyboardEvent} [event]
318
345
  * @return {boolean}
319
346
  */
320
347
  isMultiSelect = (event) => this.stores.KeyStore.isMultiSelectKeyPressed(event)
348
+
321
349
  /**
322
350
  * Whether the user is currently drag n dropping elements (instead of selection)
323
351
  * @return {boolean}
324
352
  */
325
353
  isDragging = () => this.Interaction.isDragging
354
+
326
355
  /**
327
356
  * Returns first DropsZone under coordinates,
328
357
  * if no coordinated provided current pointer coordinates are used
329
358
  * @param {Vect2} [coordinates]
330
359
  * @returns {DSDropZone | undefined}
331
360
  */
332
- getZoneByCoordinates = (coordinates) => this.DropZones.getTarget(coordinates)?.toObject()
361
+ getZoneByCoordinates = (coordinates) =>
362
+ this.DropZones.getTarget(coordinates)?.toObject()
363
+
333
364
  /**
334
365
  * Returns itemsDropped into zone by zone id
335
366
  * @param {string} zoneId
336
367
  * @returns {DSElements|void}
337
368
  */
338
- getItemsDroppedByZoneId = (zoneId) => this.DropZones.getItemsDroppedById(zoneId)
369
+ getItemsDroppedByZoneId = (zoneId) =>
370
+ this.DropZones.getItemsDroppedById(zoneId)
371
+
339
372
  /**
340
373
  * Returns itemsInside by zone id
341
374
  * @param {string} zoneId
342
375
  * @param {boolean} addClasses whether or not to add/remove the "inside" classes to the items
343
376
  * @returns {DSElements|void}
344
377
  */
345
- getItemsInsideByZoneId = (zoneId, addClasses) => this.DropZones.getItemsInsideById(zoneId, addClasses)
378
+ getItemsInsideByZoneId = (zoneId, addClasses) =>
379
+ this.DropZones.getItemsInsideById(zoneId, addClasses)
346
380
  }
347
381
 
348
382
  export default DragSelect
@@ -11,8 +11,8 @@ export default (customStyles) => {
11
11
 
12
12
  selector.style.position = 'absolute'
13
13
  if (!customStyles) {
14
- selector.style.background = 'rgba(0, 0, 255, 0.1)'
15
- selector.style.border = '1px solid rgba(0, 0, 255, 0.45)'
14
+ selector.style.background = 'rgba(0, 175, 255, 0.2)'
15
+ selector.style.border = '1px solid rgba(0, 175, 255, 0.8)'
16
16
  selector.style.display = 'none'
17
17
  selector.style.pointerEvents = 'none' // fix for issue #8 (ie11+)
18
18
  }
@@ -64,9 +64,9 @@ export default class Area {
64
64
 
65
65
  this.setArea(this.DS.stores.SettingsStore.s.area)
66
66
  // @ts-ignore: @todo: update to typescript
67
- this.DS.PubSub.subscribe('Settings:updated:area', ({ settings }) =>
67
+ this.DS.PubSub.subscribe('Settings:updated:area', ({ settings }) => {
68
68
  this.setArea(settings.area)
69
- )
69
+ })
70
70
 
71
71
  this.DS.PubSub.subscribe('Interaction:init', this.start)
72
72
  this.DS.PubSub.subscribe('Interaction:end', this.reset)
@@ -74,6 +74,7 @@ export default class Area {
74
74
 
75
75
  /** @param {DSArea} area */
76
76
  setArea = (area) => {
77
+ this.reset()
77
78
  this._node = area
78
79
  handleElementPositionAttribute({
79
80
  computedStyle: this.computedStyle,
@@ -18,7 +18,10 @@ export default class Interaction {
18
18
  this.DS = DS
19
19
  this.Settings = DS.stores.SettingsStore.s
20
20
  // @ts-ignore: @todo: update to typescript
21
- this.DS.subscribe('Settings:updated:area', this.init)
21
+ this.DS.subscribe('Settings:updated:area', ({ settings }) => {
22
+ this.stop(settings['area:pre'])
23
+ this.init()
24
+ })
22
25
  this.DS.subscribe('PointerStore:updated', this.update)
23
26
  this.DS.subscribe('Selectable:click', this.onClick)
24
27
  this.DS.subscribe('Selectable:pointer', ({ event }) => this.start(event))
@@ -156,24 +159,24 @@ export default class Interaction {
156
159
  this.reset() // simulate mouse-up (that does not exist on keyboard)
157
160
  }
158
161
 
159
- stop = () => {
162
+ stop = (area = this.DS.Area.HTMLNode) => {
160
163
  this.isInteracting = false
161
164
  this.isDragging = false
162
165
 
163
166
  // @TODO: fix pointer events mixing issue see [PR](https://github.com/ThibaultJanBeyer/DragSelect/pull/128#issuecomment-1154885289)
164
167
  if (this.Settings.usePointerEvents) {
165
- this.DS.Area.HTMLNode.removeEventListener('pointerdown', this.start, {
168
+ area.removeEventListener('pointerdown', this.start, {
166
169
  // @ts-ignore
167
170
  passive: false,
168
171
  })
169
172
  document.removeEventListener('pointerup', this.reset)
170
173
  document.removeEventListener('pointercancel', this.reset)
171
174
  } else {
172
- this.DS.Area.HTMLNode.removeEventListener('mousedown', this.start)
175
+ area.removeEventListener('mousedown', this.start)
173
176
  document.removeEventListener('mouseup', this.reset)
174
177
  }
175
178
 
176
- this.DS.Area.HTMLNode.removeEventListener('touchstart', this.start, {
179
+ area.removeEventListener('touchstart', this.start, {
177
180
  // @ts-ignore
178
181
  passive: false,
179
182
  })
@@ -31,6 +31,8 @@ export default class Selector {
31
31
  })
32
32
  // @ts-ignore: @todo: update to typescript
33
33
  this.DS.subscribe('Settings:updated:selector', this.attachSelector)
34
+ // @ts-ignore: @todo: update to typescript
35
+ this.DS.subscribe('Settings:updated:customStyles', this.attachSelector)
34
36
  this.attachSelector()
35
37
 
36
38
  this.DS.subscribe('Interaction:start', this.start)
package/jsdoc.json DELETED
@@ -1,18 +0,0 @@
1
- {
2
- "opts": {
3
- "template": "node_modules/minami",
4
- "destination": "./docs"
5
- },
6
- "source": {
7
- "include": ["./src", "./src/modules/PubSub.js", "./README.md"],
8
- "includePattern": "\\.(jsx|js|ts|tsx)$"
9
- },
10
- "plugins": [
11
- "node_modules/better-docs/typescript",
12
- "node_modules/better-docs/typedef-import"
13
- ],
14
- "tags": {
15
- "allowUnknownTags": ["optional"]
16
- },
17
- "sourceType": "module"
18
- }
package/todos.md DELETED
@@ -1,10 +0,0 @@
1
- # TODOs
2
- ### Zoom Drag
3
- - Dragging when the area is zoomed is wrong
4
- ## Drag and Drop
5
- #### Constrain direction
6
- - User can set in which direction the element can be dragged
7
- ### Add drop-zones
8
- A way to add zones in which elements can be dropped that also react on element changes
9
- ### Classes
10
- - Elements should get different classes based on their state