dragselect 2.3.1 → 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 +7 -0
  2. package/README.md +45 -23
  3. package/deploying.md +7 -4
  4. package/dist/DragSelect.d.ts +10 -18
  5. package/dist/DragSelect.es6m.js +412 -579
  6. package/dist/DragSelect.js +412 -579
  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 -31
  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 +3 -3
  27. package/src/DragSelect.js +22 -175
  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 +14 -45
  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/src/DragSelect.js CHANGED
@@ -54,7 +54,7 @@ import {
54
54
  Selector,
55
55
  SelectorArea,
56
56
  } from './modules'
57
- import { PointerStore, ScrollStore, KeyStore } from './stores'
57
+ import { PointerStore, ScrollStore, KeyStore, SettingsStore } from './stores'
58
58
  import { toArray, vect2, subscriberAliases } from './methods'
59
59
 
60
60
  // Setup
@@ -71,115 +71,29 @@ class DragSelect {
71
71
  * @constructor DragSelect
72
72
  * @param {Settings} settings
73
73
  */
74
- constructor({
75
- area = document,
76
- selectables = [],
77
- autoScrollSpeed = 5,
78
- overflowTolerance = { x: 25, y: 25 },
79
- zoom = 1,
80
- customStyles = false,
81
- multiSelectMode = false,
82
- multiSelectToggling = true,
83
- multiSelectKeys = ['Control', 'Shift', 'Meta'],
84
- selector = undefined,
85
- draggability = true,
86
- immediateDrag = true,
87
- keyboardDrag = true,
88
- dragKeys,
89
- keyboardDragSpeed = 10,
90
- useTransform = true,
91
- hoverClass = 'ds-hover',
92
- selectableClass = 'ds-selectable',
93
- selectedClass = 'ds-selected',
94
- selectorClass = 'ds-selector',
95
- selectorAreaClass = 'ds-selector-area',
96
- callback,
97
- onDragMove,
98
- onDragStartBegin,
99
- onDragStart,
100
- onElementSelect,
101
- onElementUnselect,
102
- }) {
74
+ constructor(settings) {
103
75
  this.PubSub = new PubSub({ DS: this })
104
76
  this.subscribe = this.PubSub.subscribe
105
77
  this.unsubscribe = this.PubSub.unsubscribe
106
78
  this.publish = this.PubSub.publish
107
- this._callbacksTemp({
108
- callback,
109
- onDragMove,
110
- onDragStart,
111
- onDragStartBegin,
112
- onElementSelect,
113
- onElementUnselect,
114
- })
115
-
116
- this.stores = {
117
- PointerStore: new PointerStore({ DS: this }),
118
- ScrollStore: new ScrollStore({ DS: this, areaElement: area, zoom }),
119
- KeyStore: new KeyStore({ DS: this, multiSelectKeys, multiSelectMode }),
120
- }
121
79
 
122
- this.Area = new Area({ area, PS: this.PubSub, zoom })
80
+ this.stores = /** @type {{ SettingsStore:SettingsStore, PointerStore:PointerStore, ScrollStore:ScrollStore, KeyStore:KeyStore }} */ ({})
81
+ this.stores.SettingsStore = new SettingsStore({ DS: this, settings })
82
+ this.stores.PointerStore = new PointerStore({ DS: this })
83
+ this.stores.ScrollStore = new ScrollStore({ DS: this })
84
+ this.stores.KeyStore = new KeyStore({ DS: this })
123
85
 
124
- this.Selector = new Selector({
125
- DS: this,
126
- selector,
127
- selectorClass,
128
- customStyles,
129
- })
86
+ this.Area = new Area({ DS: this })
87
+ this.Selector = new Selector({ DS: this })
88
+ this.SelectorArea = new SelectorArea({ DS: this })
130
89
 
131
- this.SelectorArea = new SelectorArea({
132
- DS: this,
133
- selectorAreaClass,
134
- autoScrollSpeed,
135
- overflowTolerance,
136
- })
90
+ this.SelectableSet = new SelectableSet({ DS: this })
91
+ this.SelectedSet = new SelectedSet({ DS: this })
92
+ this.Selection = new Selection({ DS: this })
137
93
 
138
- this.SelectableSet = new SelectableSet({
139
- elements: selectables,
140
- DS: this,
141
- className: selectableClass,
142
- hoverClassName: hoverClass,
143
- useTransform,
144
- draggability,
145
- })
94
+ this.Drag = new Drag({ DS: this })
146
95
 
147
- this.SelectedSet = new SelectedSet({
148
- DS: this,
149
- className: selectedClass,
150
- })
151
-
152
- this.Selection = new Selection({
153
- DS: this,
154
- hoverClassName: hoverClass,
155
- multiSelectToggling,
156
- })
157
-
158
- this.Drag = new Drag({
159
- DS: this,
160
- draggability,
161
- useTransform,
162
- keyboardDrag,
163
- dragKeys: Object.assign(
164
- {
165
- up: ['ArrowUp'],
166
- down: ['ArrowDown'],
167
- left: ['ArrowLeft'],
168
- right: ['ArrowRight'],
169
- },
170
- dragKeys
171
- ),
172
- zoom,
173
- keyboardDragSpeed,
174
- })
175
-
176
- this.Interaction = new Interaction({
177
- areaElement: area,
178
- DS: this,
179
- draggability,
180
- immediateDrag,
181
- selectableClass,
182
- })
96
+ this.Interaction = new Interaction({ DS: this })
183
97
 
184
98
  // Subscriber Aliases
185
99
  subscriberAliases({
@@ -194,54 +108,6 @@ class DragSelect {
194
108
  this.start()
195
109
  }
196
110
 
197
- // @TODO: remove after deprecation
198
- _callbacksTemp({
199
- callback,
200
- onDragMove,
201
- onDragStart,
202
- onDragStartBegin,
203
- onElementSelect,
204
- onElementUnselect,
205
- }) {
206
- const warnMessage = (name, newName) =>
207
- console.warn(
208
- `[DragSelect] ${name} is deprecated. Use DragSelect.subscribe("${newName}", (callbackObject) => {}) instead. Act Now! See docs for more info`
209
- )
210
- if (callback) {
211
- warnMessage('callback', 'callback')
212
- this.subscribe('callback', ({ items, item, event }) =>
213
- callback(items, event)
214
- )
215
- }
216
- if (onDragMove) {
217
- warnMessage('onDragMove', 'dragmove')
218
- this.subscribe('dragmove', ({ items, item, event }) => onDragMove(event))
219
- }
220
- if (onDragStart) {
221
- warnMessage('onDragStart', 'dragstart')
222
- this.subscribe('dragstart', ({ items, item, event }) =>
223
- onDragStart(event)
224
- )
225
- }
226
- if (onDragStartBegin) {
227
- warnMessage('onDragStartBegin', 'dragstart')
228
- this.subscribe('dragstart', ({ items, item, event }) =>
229
- onDragStartBegin(event)
230
- )
231
- }
232
- if (onElementSelect) {
233
- warnMessage('onElementSelect', 'elementselect')
234
- this.subscribe('elementselect', ({ items, item, event }) =>
235
- onElementSelect(item, event)
236
- )
237
- }
238
- if (onElementUnselect) {
239
- warnMessage('onElementUnselect', 'elementunselect')
240
- this.subscribe('elementunselect', ({ items, item, event }) =>
241
- onElementUnselect(item, event)
242
- )
243
- }
244
- }
245
111
  // Useful methods for the user
246
112
  //////////////////////////////////////////////////////////////////////////////////////
247
113
  /**
@@ -403,6 +269,7 @@ class DragSelect {
403
269
  removeFromSelection = false,
404
270
  addToSelection = false
405
271
  ) {
272
+ console.warn('[DragSelect] DEPRECATION ".setSelectables" is deprecated and will be removed soon. Please use "ds.setSettings({ selectables: << new dom elements >> })" instead (see docs)')
406
273
  this.removeSelectables(elements, removeFromSelection)
407
274
  return this.addSelectables(elements, addToSelection)
408
275
  }
@@ -435,37 +302,17 @@ class DragSelect {
435
302
  * @return {boolean}
436
303
  */
437
304
  isMultiSelect = (event) => this.stores.KeyStore.isMultiSelectKeyPressed(event)
438
- /**
439
- * Utility method that returns the cursor position difference between start and now
440
- * @param {boolean} [usePreviousCursorDifference] if true, it will output the cursor position difference between the previous selection and now
441
- * @param {boolean} [useAreaPositions] if true, it will use cursor positions relative to the area
442
- * @return {Vect2}
443
- * @deprecated
444
- */
445
- getCursorPositionDifference(
446
- usePreviousCursorDifference = false,
447
- useAreaPositions = false
448
- ) {
449
- console.warn(
450
- '[DragSelect] Using .getCursorPositionDifference is deprecated. Calculate yourself instead. i.e. `.getCurrentCursorPosition().x - .getInitialCursorPosition().x`'
451
- )
452
- const posA = useAreaPositions
453
- ? this.getCurrentCursorPositionArea()
454
- : this.getCurrentCursorPosition()
455
- const posB = usePreviousCursorDifference
456
- ? useAreaPositions
457
- ? this.getPreviousCursorPositionArea()
458
- : this.getPreviousCursorPosition()
459
- : useAreaPositions
460
- ? this.getInitialCursorPositionArea()
461
- : this.getInitialCursorPosition()
462
- return vect2.calc(posA, '-', posB)
463
- }
464
305
  /**
465
306
  * Whether the user is currently drag n dropping elements (instead of selection)
466
307
  * @return {boolean}
467
308
  */
468
309
  isDragging = () => this.Interaction.isDragging
310
+ /**
311
+ * Update any setting dynamically
312
+ * @param {Settings} settings
313
+ * @return {void}
314
+ */
315
+ setSettings = (settings) => this.stores.SettingsStore.update({ settings })
469
316
  }
470
317
 
471
318
  export default DragSelect
@@ -3,15 +3,13 @@ import '../types'
3
3
 
4
4
  /**
5
5
  * Creates the SelectorArea
6
- * @param {string} selectorAreaClass
7
6
  * @return {HTMLDivElement}
8
7
  */
9
- export default (selectorAreaClass) => {
8
+ export default () => {
10
9
  const node = document.createElement('div')
11
10
  node.style.position = 'fixed'
12
11
  node.style.overflow = 'hidden'
13
12
  node.style.pointerEvents = 'none'
14
13
  node.style.zIndex = '999999999999999999'
15
- node.classList.add(selectorAreaClass)
16
14
  return node
17
15
  }
@@ -0,0 +1,109 @@
1
+ /**
2
+ * @param {string} key
3
+ * @param {string} type
4
+ * @param {*} fallback
5
+ * @returns {void}
6
+ */
7
+ const wrongTypeWarn = (key, type, fallback) =>
8
+ console.warn(`[DragSelect] TypeIssue: setting "${key}" is not of type "${type}".`)
9
+
10
+ /**
11
+ * @param {string} key
12
+ * @param {*} value
13
+ * @param {boolean} withFallback
14
+ * @param {*} fallback
15
+ * @returns {object}
16
+ */
17
+ const hydrateHelper = (key, value, withFallback, fallback) => {
18
+ // no value available
19
+ if (value === undefined)
20
+ return withFallback ? { [key]: fallback } : {}
21
+ // force unsetting of a value
22
+ if (value === null) return { [key]: null }
23
+
24
+ // TypeCheck [GENERIC]
25
+ let isAvailable = true // if it’s not undefined, it was set voluntarily
26
+ let forceFallback = false
27
+
28
+ // TypeCheck [String]
29
+ const expectedString = typeof fallback === 'string'
30
+ if (expectedString) isAvailable = typeof value === 'string' || value instanceof String
31
+ if (expectedString && !isAvailable) {
32
+ forceFallback = true
33
+ wrongTypeWarn(key, 'string', fallback)
34
+ }
35
+
36
+ // TypeCheck [Number]
37
+ const expectedNumber = !isNaN(fallback) && typeof fallback === 'number'
38
+ if (expectedNumber) isAvailable = !isNaN(value) && typeof value === 'number'
39
+ if (expectedNumber && !isAvailable) {
40
+ forceFallback = true
41
+ wrongTypeWarn(key, 'number', fallback)
42
+ }
43
+
44
+ // TypeCheck [Object]
45
+ const expectedObject = Object.prototype.toString.call(fallback) === "[object Object]"
46
+ if (expectedObject) isAvailable = Object.prototype.toString.call(value) === "[object Object]"
47
+ if (expectedObject && !isAvailable) {
48
+ forceFallback = true
49
+ wrongTypeWarn(key, 'object', fallback)
50
+ }
51
+
52
+ // TypeCheck [Boolean]
53
+ const expectedBoolean = typeof fallback === "boolean"
54
+ if (expectedBoolean) isAvailable = typeof value === "boolean"
55
+ if (expectedBoolean && !isAvailable) {
56
+ forceFallback = true
57
+ wrongTypeWarn(key, 'boolean', fallback)
58
+ }
59
+
60
+ // TypeCheck [Array]
61
+ const expectedArray = Array.isArray(fallback)
62
+ if (expectedArray) isAvailable = Array.isArray(value)
63
+ if (expectedArray && !isAvailable) {
64
+ forceFallback = true
65
+ wrongTypeWarn(key, 'array', fallback)
66
+ }
67
+
68
+ const isFallback = forceFallback || withFallback
69
+
70
+ // Special rule for [dragKeys]
71
+ if (key === 'dragKeys' && isAvailable) return { [key]: Object.assign(fallback, value) }
72
+ else if(key === 'dragKeys' && !isAvailable) return isFallback ? { [key]: fallback } : {}
73
+
74
+ return isAvailable ? { [key]: value } : isFallback ? { [key]: fallback } : {}
75
+ }
76
+
77
+ /**
78
+ * This helper method creates the setting object,
79
+ * - if the settings provided are of wrong type, the fallback value will be used
80
+ * - - except for if settings are undefined or explicitly marked as "null"
81
+ * - if "withfallback" is true, it will return the object with all settings:
82
+ * - - if not provided from the settings object (or wrong type), the fallback will be used
83
+ * (the fallback value for each setting is the last prop of the hydrateHelper)
84
+ * @param {Settings} settings
85
+ * @param {boolean} withFallback
86
+ */
87
+ export default (settings, withFallback) => ({
88
+ ...hydrateHelper('area', settings.area, withFallback, document),
89
+ ...hydrateHelper('selectables', settings.selectables, withFallback, null),
90
+ ...hydrateHelper('autoScrollSpeed', settings.autoScrollSpeed, withFallback, 5),
91
+ ...hydrateHelper('overflowTolerance', settings.overflowTolerance, withFallback, { x: 25, y: 25 }),
92
+ ...hydrateHelper('zoom', settings.zoom, withFallback, 1),
93
+ ...hydrateHelper('customStyles', settings.customStyles, withFallback, false),
94
+ ...hydrateHelper('multiSelectMode', settings.multiSelectMode, withFallback, false),
95
+ ...hydrateHelper('multiSelectToggling', settings.multiSelectToggling, withFallback, true),
96
+ ...hydrateHelper('multiSelectKeys', settings.multiSelectKeys, withFallback, ['Control', 'Shift', 'Meta']),
97
+ ...hydrateHelper('selector', settings.selector, withFallback, null),
98
+ ...hydrateHelper('draggability', settings.draggability, withFallback, true),
99
+ ...hydrateHelper('immediateDrag', settings.immediateDrag, withFallback, true),
100
+ ...hydrateHelper('keyboardDrag', settings.keyboardDrag, withFallback, true),
101
+ ...hydrateHelper('dragKeys', settings.dragKeys, withFallback, { up: ['ArrowUp'], down: ['ArrowDown'], left: ['ArrowLeft'], right: ['ArrowRight'] }),
102
+ ...hydrateHelper('keyboardDragSpeed', settings.keyboardDragSpeed, withFallback, 10),
103
+ ...hydrateHelper('useTransform', settings.useTransform, withFallback, true),
104
+ ...hydrateHelper('hoverClass', settings.hoverClass, withFallback, 'ds-hover'),
105
+ ...hydrateHelper('selectableClass', settings.selectableClass, withFallback, 'ds-selectable'),
106
+ ...hydrateHelper('selectedClass', settings.selectedClass, withFallback, 'ds-selected'),
107
+ ...hydrateHelper('selectorClass', settings.selectorClass, withFallback, 'ds-selector'),
108
+ ...hydrateHelper('selectorAreaClass', settings.selectorAreaClass, withFallback, 'ds-selector-area'),
109
+ })
@@ -16,6 +16,7 @@ export { default as handleElementPositionAttribute } from './handleElementPositi
16
16
  export { default as handleKeyboardDragPosDifference } from './handleKeyboardDragPosDifference'
17
17
  export { default as handleSelection } from './handleSelection'
18
18
  export { default as handleUnSelection } from './handleUnSelection'
19
+ export { default as hydrateSettings } from './hydrateSettings'
19
20
  export { default as isCollision } from './isCollision'
20
21
  export { default as moveElement } from './moveElement'
21
22
  export { default as removeModificationObservers } from './removeModificationObservers'
@@ -1,7 +1,7 @@
1
1
  // @ts-check
2
2
  import '../types.js'
3
+ import DragSelect from '../DragSelect'
3
4
 
4
- import { PubSub } from './'
5
5
  import {
6
6
  addModificationObservers,
7
7
  debounce,
@@ -11,14 +11,12 @@ import {
11
11
  handleElementPositionAttribute,
12
12
  } from '../methods'
13
13
 
14
- /**
15
- * @typedef {Object} AreaProps
16
- * @property {DSArea} area
17
- * @property {PubSub} PS
18
- * @property {number} zoom
19
- */
20
-
21
14
  export default class Area {
15
+ /**
16
+ * @type {DragSelect}
17
+ * @private
18
+ */
19
+ DS
22
20
  /**
23
21
  * @type {DSModificationCallback}
24
22
  * @private
@@ -62,25 +60,29 @@ export default class Area {
62
60
 
63
61
  /**
64
62
  * @constructor Area
65
- * @param {AreaProps} settings
63
+ * @param {{DS:DragSelect}} p
66
64
  * @ignore
67
65
  */
68
- constructor({ area, PS, zoom }) {
69
- this._zoom = zoom
70
- this.PubSub = PS
71
- this.setArea(area)
66
+ constructor({ DS }) {
67
+ this.DS = DS
68
+
69
+ this.setArea(this.DS.stores.SettingsStore.s.area)
70
+ // @ts-ignore: @todo: update to typescript
71
+ this.DS.PubSub.subscribe('Settings:updated:area', ({ settings }) =>
72
+ this.setArea(settings.area)
73
+ )
72
74
 
73
75
  this._modificationCallback = debounce((event) => {
74
- this.PubSub.publish('Area:modified:pre', { event, item: this })
76
+ this.DS.PubSub.publish('Area:modified:pre', { event, item: this })
75
77
  this.reset()
76
- this.PubSub.publish('Area:modified', { event, item: this })
78
+ this.DS.PubSub.publish('Area:modified', { event, item: this })
77
79
  }, 60)
78
80
  this._modificationObserver = new MutationObserver(
79
81
  this._modificationCallback
80
82
  )
81
83
 
82
- this.PubSub.subscribe('Interaction:init', this.start)
83
- this.PubSub.subscribe('Interaction:end', this.reset)
84
+ this.DS.PubSub.subscribe('Interaction:init', this.start)
85
+ this.DS.PubSub.subscribe('Interaction:end', this.reset)
84
86
  }
85
87
 
86
88
  /** @param {DSArea} area */
@@ -93,9 +95,9 @@ export default class Area {
93
95
 
94
96
  // first immediate debounce to update values after dom-update
95
97
  setTimeout(() => {
96
- this.PubSub.publish('Area:modified:pre', { item: this })
98
+ this.DS.PubSub.publish('Area:modified:pre', { item: this })
97
99
  this.reset()
98
- this.PubSub.publish('Area:modified', { item: this })
100
+ this.DS.PubSub.publish('Area:modified', { item: this })
99
101
  })
100
102
  }
101
103
 
@@ -135,9 +137,9 @@ export default class Area {
135
137
  scroll_directions: directions,
136
138
  scroll_multiplier: multiplier,
137
139
  }
138
- this.PubSub.publish('Area:scroll:pre', data)
140
+ this.DS.PubSub.publish('Area:scroll:pre', data)
139
141
  scrollElement(this._node, directions, multiplier)
140
- this.PubSub.publish('Area:scroll', data)
142
+ this.DS.PubSub.publish('Area:scroll', data)
141
143
  }
142
144
 
143
145
  //////////////////////////////////////////////////////////////////////////////////////
@@ -180,7 +182,7 @@ export default class Area {
180
182
  */
181
183
  get rect() {
182
184
  if (this._rect) return this._rect
183
- return (this._rect = getAreaRect(this.HTMLNode, this._zoom))
185
+ return (this._rect = getAreaRect(this.HTMLNode, this.DS.stores.SettingsStore.s.zoom))
184
186
  }
185
187
 
186
188
  get parentNodes() {
@@ -5,11 +5,6 @@ import DragSelect from '../DragSelect'
5
5
  import { vect2, moveElement, handleKeyboardDragPosDifference } from '../methods'
6
6
 
7
7
  export default class Drag {
8
- /**
9
- * @type {boolean}
10
- * @private
11
- */
12
- _useTransform
13
8
  /**
14
9
  * @type {Vect2}
15
10
  * @private
@@ -25,11 +20,6 @@ export default class Drag {
25
20
  * @private
26
21
  */
27
22
  _elements = []
28
- /**
29
- * @type {boolean}
30
- * @private
31
- */
32
- _draggability
33
23
  /**
34
24
  * @type {DSDragKeys}
35
25
  * @private
@@ -39,55 +29,32 @@ export default class Drag {
39
29
  * @type {string[]}
40
30
  * @private
41
31
  */
42
- _dragKeysFlat
43
- /**
44
- * @type {boolean}
45
- * @private
46
- */
47
- _keyboardDrag
48
- /**
49
- * @type {number}
50
- * @private
51
- */
52
- _keyboardDragSpeed
53
- /**
54
- * @type {number}
55
- * @private
56
- */
57
- _zoom
32
+ _dragKeysFlat = []
58
33
 
59
34
  /**
60
- * @param {Object} p
61
- * @param {DragSelect} p.DS
62
- * @param {boolean} p.draggability
63
- * @param {boolean} p.useTransform
64
- * @param {DSDragKeys} p.dragKeys
65
- * @param {boolean} p.keyboardDrag
66
- * @param {number} p.keyboardDragSpeed
67
- * @param {number} p.zoom
35
+ * @constructor Drag
36
+ * @param {{DS:DragSelect}} obj
68
37
  * @ignore
69
38
  */
70
- constructor({
71
- DS,
72
- dragKeys,
73
- draggability,
74
- keyboardDrag,
75
- keyboardDragSpeed,
76
- useTransform,
77
- zoom,
78
- }) {
39
+ constructor({ DS }) {
79
40
  this.DS = DS
80
- this._useTransform = useTransform
81
- this._keyboardDragSpeed = keyboardDragSpeed
82
- this._keyboardDrag = keyboardDrag
83
- this._zoom = zoom
84
- this._draggability = draggability
85
41
 
42
+ // @ts-ignore: @todo: update to typescript
43
+ this.DS.subscribe('Settings:updated:dragKeys', this.assignDragkeys)
44
+ this.assignDragkeys()
45
+ this.DS.subscribe('Interaction:start', this.start)
46
+ this.DS.subscribe('Interaction:end', this.stop)
47
+ this.DS.subscribe('Interaction:update', this.update)
48
+ this.DS.subscribe('KeyStore:down', this.keyboardDrag)
49
+ this.DS.subscribe('KeyStore:up', this.keyboardEnd)
50
+ }
51
+
52
+ assignDragkeys = () => {
86
53
  this._dragKeys = {
87
- up: dragKeys.up.map((k) => k.toLowerCase()),
88
- down: dragKeys.down.map((k) => k.toLowerCase()),
89
- left: dragKeys.left.map((k) => k.toLowerCase()),
90
- right: dragKeys.right.map((k) => k.toLowerCase()),
54
+ up: this.DS.stores.SettingsStore.s.dragKeys.up.map((k) => k.toLowerCase()),
55
+ down: this.DS.stores.SettingsStore.s.dragKeys.down.map((k) => k.toLowerCase()),
56
+ left: this.DS.stores.SettingsStore.s.dragKeys.left.map((k) => k.toLowerCase()),
57
+ right: this.DS.stores.SettingsStore.s.dragKeys.right.map((k) => k.toLowerCase()),
91
58
  }
92
59
  this._dragKeysFlat = [
93
60
  ...this._dragKeys.up,
@@ -95,20 +62,15 @@ export default class Drag {
95
62
  ...this._dragKeys.left,
96
63
  ...this._dragKeys.right,
97
64
  ]
98
-
99
- this.DS.subscribe('Interaction:start', this.start)
100
- this.DS.subscribe('Interaction:end', this.stop)
101
- this.DS.subscribe('Interaction:update', this.update)
102
- this.DS.subscribe('KeyStore:down', this.keyboardDrag)
103
- this.DS.subscribe('KeyStore:up', this.keyboardEnd)
104
65
  }
105
66
 
106
67
  keyboardDrag = ({ event, key }) => {
68
+ const _key = key.toLowerCase()
107
69
  if (
108
- !this._keyboardDrag ||
109
- !this._dragKeysFlat.includes(key) ||
70
+ !this.DS.stores.SettingsStore.s.keyboardDrag ||
71
+ !this._dragKeysFlat.includes(_key) ||
110
72
  !this.DS.SelectedSet.size ||
111
- !this._draggability ||
73
+ !this.DS.stores.SettingsStore.s.draggability ||
112
74
  this.DS.continue
113
75
  )
114
76
  return
@@ -125,9 +87,9 @@ export default class Drag {
125
87
 
126
88
  const posDirection = handleKeyboardDragPosDifference({
127
89
  shiftKey: this.DS.stores.KeyStore.currentValues.includes('shift'),
128
- keyboardDragSpeed: this._keyboardDragSpeed,
129
- zoom: this._zoom,
130
- key,
90
+ keyboardDragSpeed: this.DS.stores.SettingsStore.s.keyboardDragSpeed,
91
+ zoom: this.DS.stores.SettingsStore.s.zoom,
92
+ key: _key,
131
93
  scrollCallback: this.DS.Area.scroll,
132
94
  scrollDiff: this._scrollDiff,
133
95
  canScroll: this.DS.stores.ScrollStore.canScroll,
@@ -139,24 +101,28 @@ export default class Drag {
139
101
  element,
140
102
  posDirection,
141
103
  containerRect: this.DS.SelectorArea.rect,
142
- useTransform: this._useTransform,
104
+ useTransform: this.DS.stores.SettingsStore.s.useTransform,
143
105
  })
144
106
  )
145
107
 
146
- this.DS.publish(['Interaction:update:pre', 'Interaction:update'], publishData)
108
+ this.DS.publish(
109
+ ['Interaction:update:pre', 'Interaction:update'],
110
+ publishData
111
+ )
147
112
  }
148
113
 
149
114
  keyboardEnd = ({ event, key }) => {
115
+ const _key = key.toLowerCase()
150
116
  if (
151
- !this._keyboardDrag ||
152
- !this._dragKeysFlat.includes(key) ||
117
+ !this.DS.stores.SettingsStore.s.keyboardDrag ||
118
+ !this._dragKeysFlat.includes(_key) ||
153
119
  !this.DS.SelectedSet.size ||
154
- !this._draggability
120
+ !this.DS.stores.SettingsStore.s.draggability
155
121
  )
156
122
  return
157
123
  const publishData = {
158
124
  event,
159
- isDragging: this._draggability,
125
+ isDragging: this.DS.stores.SettingsStore.s.draggability,
160
126
  isDraggingKeyboard: true,
161
127
  }
162
128
  this.DS.publish(['Interaction:end:pre', 'Interaction:end'], publishData)
@@ -194,7 +160,7 @@ export default class Drag {
194
160
  element,
195
161
  posDirection,
196
162
  containerRect: this.DS.SelectorArea.rect,
197
- useTransform: this._useTransform,
163
+ useTransform: this.DS.stores.SettingsStore.s.useTransform,
198
164
  })
199
165
  )
200
166
  }