@checksub_team/peaks_timeline 1.9.2 → 1.9.3

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": "@checksub_team/peaks_timeline",
3
- "version": "1.9.2",
3
+ "version": "1.9.3",
4
4
  "description": "JavaScript UI component for displaying audio waveforms",
5
5
  "main": "./peaks.js",
6
6
  "types": "./peaks.js.d.ts",
package/peaks.js CHANGED
@@ -15743,15 +15743,17 @@ module.exports = function (Utils, Source, SourceGroup, Konva) {
15743
15743
  const sources = [];
15744
15744
  const segments = [];
15745
15745
  const self = this;
15746
- this.deselectAll(true);
15746
+ this.deselectDifference(elements, true);
15747
15747
  elements.forEach(function (element) {
15748
- self._selectedElements[element.id] = element;
15749
- element.setSelected(true);
15750
- if (notify) {
15751
- if (element instanceof Source) {
15752
- sources.push(element);
15753
- } else {
15754
- segments.push(element);
15748
+ if (!self._selectedElements[element.id]) {
15749
+ self._selectedElements[element.id] = element;
15750
+ element.setSelected(true);
15751
+ if (notify) {
15752
+ if (element instanceof Source) {
15753
+ sources.push(element);
15754
+ } else {
15755
+ segments.push(element);
15756
+ }
15755
15757
  }
15756
15758
  }
15757
15759
  });
@@ -15764,10 +15766,14 @@ module.exports = function (Utils, Source, SourceGroup, Konva) {
15764
15766
  }
15765
15767
  }
15766
15768
  };
15767
- ModeLayer.prototype.deselectAll = function (notify) {
15769
+ ModeLayer.prototype.deselectDifference = function (newElements, notify) {
15768
15770
  const sources = [];
15769
15771
  const segments = [];
15770
- for (var id in this._selectedElements) {
15772
+ const selectedElementsToDeselect = Object.assign({}, this._selectedElements);
15773
+ newElements.forEach(function (element) {
15774
+ delete selectedElementsToDeselect[element.id];
15775
+ });
15776
+ for (var id in selectedElementsToDeselect) {
15771
15777
  if (Utils.objectHasProperty(this._selectedElements, id)) {
15772
15778
  const element = this._selectedElements[id];
15773
15779
  element.setSelected(false);
@@ -15850,7 +15856,7 @@ module.exports = function (Utils, Source, SourceGroup, Konva) {
15850
15856
  this.selectElements([hoveredKonvaElement.getSegment()], true);
15851
15857
  }
15852
15858
  } else {
15853
- this.deselectAll(true);
15859
+ this.deselectDifference([], true);
15854
15860
  this._view.drawSourcesLayer();
15855
15861
  }
15856
15862
  };
@@ -15858,7 +15864,7 @@ module.exports = function (Utils, Source, SourceGroup, Konva) {
15858
15864
  const selectedElements = Object.values(this._selectedElements);
15859
15865
  if (selectedElements.length) {
15860
15866
  var selectedElement = selectedElements[0];
15861
- this.deselectAll(true);
15867
+ this.deselectDifference([], true);
15862
15868
  if (selectedElement instanceof Source) {
15863
15869
  if (selectedElement.isDeletable()) {
15864
15870
  this._peaks.destroySource(selectedElement.id);
@@ -16004,7 +16010,7 @@ module.exports = function (Utils, Source, SourceGroup, Konva) {
16004
16010
  this._peaks.off('keyboard.delete', this._onKeyboardDelete);
16005
16011
  break;
16006
16012
  }
16007
- this.deselectAll(true);
16013
+ this.deselectDifference([], true);
16008
16014
  switch (mode) {
16009
16015
  case 'cut':
16010
16016
  this._stage.on('mouseover', this._onMouseEnterInCutMode);
@@ -20230,7 +20236,7 @@ module.exports = function (MouseDragHandler, PlayheadLayer, SourcesLayer, ModeLa
20230
20236
  }
20231
20237
  };
20232
20238
  TimelineZoomView.prototype.deselectAll = function () {
20233
- this._modeLayer.deselectAll(false);
20239
+ this._modeLayer.deselectDifference([], false);
20234
20240
  };
20235
20241
  TimelineZoomView.prototype.isListening = function () {
20236
20242
  return this._stage.listening();
package/src/mode-layer.js CHANGED
@@ -72,17 +72,19 @@ define([
72
72
  const segments = [];
73
73
  const self = this;
74
74
 
75
- this.deselectAll(true);
75
+ this.deselectDifference(elements, true);
76
76
 
77
77
  elements.forEach(function(element) {
78
- self._selectedElements[element.id] = element;
79
- element.setSelected(true);
80
- if (notify) {
81
- if (element instanceof Source) {
82
- sources.push(element);
83
- }
84
- else {
85
- segments.push(element);
78
+ if (!self._selectedElements[element.id]) {
79
+ self._selectedElements[element.id] = element;
80
+ element.setSelected(true);
81
+ if (notify) {
82
+ if (element instanceof Source) {
83
+ sources.push(element);
84
+ }
85
+ else {
86
+ segments.push(element);
87
+ }
86
88
  }
87
89
  }
88
90
  });
@@ -97,11 +99,16 @@ define([
97
99
  }
98
100
  };
99
101
 
100
- ModeLayer.prototype.deselectAll = function(notify) {
102
+ ModeLayer.prototype.deselectDifference = function(newElements, notify) {
101
103
  const sources = [];
102
104
  const segments = [];
105
+ const selectedElementsToDeselect = Object.assign({}, this._selectedElements);
106
+
107
+ newElements.forEach(function(element) {
108
+ delete selectedElementsToDeselect[element.id];
109
+ });
103
110
 
104
- for (var id in this._selectedElements) {
111
+ for (var id in selectedElementsToDeselect) {
105
112
  if (Utils.objectHasProperty(this._selectedElements, id)) {
106
113
  const element = this._selectedElements[id];
107
114
 
@@ -198,7 +205,7 @@ define([
198
205
  }
199
206
  }
200
207
  else {
201
- this.deselectAll(true);
208
+ this.deselectDifference([], true);
202
209
  this._view.drawSourcesLayer(); // Redraw sources layer to remove selection
203
210
  }
204
211
  };
@@ -210,7 +217,7 @@ define([
210
217
  if (selectedElements.length) {
211
218
  var selectedElement = selectedElements[0];
212
219
 
213
- this.deselectAll(true);
220
+ this.deselectDifference([], true);
214
221
 
215
222
  if (selectedElement instanceof Source) {
216
223
  if (selectedElement.isDeletable()) {
@@ -426,7 +433,7 @@ define([
426
433
  break;
427
434
  }
428
435
 
429
- this.deselectAll(true);
436
+ this.deselectDifference([], true);
430
437
 
431
438
  // Set new mode
432
439
  switch (mode) {
@@ -401,7 +401,7 @@ define([
401
401
  };
402
402
 
403
403
  TimelineZoomView.prototype.deselectAll = function() {
404
- this._modeLayer.deselectAll(false);
404
+ this._modeLayer.deselectDifference([], false);
405
405
  };
406
406
 
407
407
  TimelineZoomView.prototype.isListening = function() {