@checksub_team/peaks_timeline 1.8.3 → 1.9.2

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/peaks.js CHANGED
@@ -15064,6 +15064,23 @@ module.exports = function (Konva, Utils) {
15064
15064
  }
15065
15065
  return newXs;
15066
15066
  };
15067
+ Line.prototype.getSourcesAfter = function (time) {
15068
+ const sources = [];
15069
+ var currentId = this._firstSourceId;
15070
+ while (currentId) {
15071
+ var lineSource = this._sources[currentId];
15072
+ if (lineSource.source.startTime >= time) {
15073
+ while (currentId) {
15074
+ lineSource = this._sources[currentId];
15075
+ sources.push(lineSource.source);
15076
+ currentId = lineSource.nextSourceId;
15077
+ }
15078
+ break;
15079
+ }
15080
+ currentId = lineSource.nextSourceId;
15081
+ }
15082
+ return sources;
15083
+ };
15067
15084
  Line.prototype.updatePosition = function (pos) {
15068
15085
  for (var sourceId in this._sources) {
15069
15086
  if (Utils.objectHasProperty(this._sources, sourceId)) {
@@ -15210,6 +15227,9 @@ module.exports = function (SegmentsGroup, Line, LineIndicator, Utils) {
15210
15227
  }
15211
15228
  return positions;
15212
15229
  };
15230
+ Lines.prototype.getSourcesOnLineAfter = function (lineId, time) {
15231
+ return this._linesByPosition[lineId].getSourcesAfter(time);
15232
+ };
15213
15233
  Lines.prototype.getSegmentsGroups = function () {
15214
15234
  return this._segmentsGroups;
15215
15235
  };
@@ -15610,11 +15630,17 @@ module.exports = function (Colors, EventEmitter, TimelineSegments, TimelineSourc
15610
15630
  Peaks.prototype.allowInteractions = function (forSources, forSegments) {
15611
15631
  return this.view.allowInteractions(forSources, forSegments);
15612
15632
  };
15633
+ Peaks.prototype.getSelectedElements = function () {
15634
+ return this.view.getSelectedElements();
15635
+ };
15613
15636
  Peaks.prototype.selectSourceById = function (sourceId) {
15614
15637
  return this.view.selectSourceById(sourceId);
15615
15638
  };
15616
- Peaks.prototype.deselectSource = function () {
15617
- return this.view.deselectElement();
15639
+ Peaks.prototype.selectSourcesOnLineAfter = function (lineId, time) {
15640
+ return this.view.selectSourcesOnLineAfter(lineId, time);
15641
+ };
15642
+ Peaks.prototype.deselectAll = function () {
15643
+ return this.view.deselectAll();
15618
15644
  };
15619
15645
  Peaks.prototype._addWindowResizeHandler = function () {
15620
15646
  this._onResize = this._onResize.bind(this);
@@ -15687,7 +15713,7 @@ module.exports = function (DefaultSegmentMarker, Utils, Konva) {
15687
15713
  };
15688
15714
  }(_dereq_('./default-segment-marker'), _dereq_('./utils'), _dereq_('konva'));
15689
15715
  },{"./default-segment-marker":88,"./utils":112,"konva":43}],96:[function(_dereq_,module,exports){
15690
- module.exports = function (Utils, SourceGroup, Konva) {
15716
+ module.exports = function (Utils, Source, SourceGroup, Konva) {
15691
15717
  'use strict';
15692
15718
  var TIME_X_OFFSET = 20;
15693
15719
  var TIME_Y_OFFSET = 10;
@@ -15697,6 +15723,8 @@ module.exports = function (Utils, SourceGroup, Konva) {
15697
15723
  this._view = view;
15698
15724
  this._playheadLayer = playheadLayer;
15699
15725
  this._stage = stage;
15726
+ this._selectedElements = {};
15727
+ this._currentLine = null;
15700
15728
  this._layer = new Konva.Layer({ listening: this._mode !== 'default' });
15701
15729
  this._prepareDefaultMode();
15702
15730
  this._onMouseClickInDefaultMode = this._onMouseClickInDefaultMode.bind(this);
@@ -15711,33 +15739,60 @@ module.exports = function (Utils, SourceGroup, Konva) {
15711
15739
  ModeLayer.prototype.addToStage = function (stage) {
15712
15740
  stage.add(this._layer);
15713
15741
  };
15714
- ModeLayer.prototype.selectElement = function (element, notify) {
15715
- this.deselectElement(notify);
15716
- if (element) {
15717
- this._selectedElement = element;
15718
- this._selectedElement.setSelected(true);
15742
+ ModeLayer.prototype.selectElements = function (elements, notify) {
15743
+ const sources = [];
15744
+ const segments = [];
15745
+ const self = this;
15746
+ this.deselectAll(true);
15747
+ elements.forEach(function (element) {
15748
+ self._selectedElements[element.id] = element;
15749
+ element.setSelected(true);
15719
15750
  if (notify) {
15720
- if (element instanceof SourceGroup) {
15721
- this._peaks.emit('source.selected', this._selectedElement.getSource());
15751
+ if (element instanceof Source) {
15752
+ sources.push(element);
15722
15753
  } else {
15723
- this._peaks.emit('segment.selected', this._selectedElement.getSegment());
15754
+ segments.push(element);
15724
15755
  }
15725
15756
  }
15757
+ });
15758
+ if (notify) {
15759
+ if (sources.length) {
15760
+ this._peaks.emit('sources.selected', sources);
15761
+ }
15762
+ if (segments.length) {
15763
+ this._peaks.emit('segments.selected', segments);
15764
+ }
15726
15765
  }
15727
15766
  };
15728
- ModeLayer.prototype.deselectElement = function (notify) {
15729
- if (this._selectedElement) {
15730
- this._selectedElement.setSelected(false);
15731
- if (notify) {
15732
- if (this._selectedElement instanceof SourceGroup) {
15733
- this._peaks.emit('source.deselected', this._selectedElement.getSource());
15734
- } else {
15735
- this._peaks.emit('segment.deselected', this._selectedElement.getSegment());
15767
+ ModeLayer.prototype.deselectAll = function (notify) {
15768
+ const sources = [];
15769
+ const segments = [];
15770
+ for (var id in this._selectedElements) {
15771
+ if (Utils.objectHasProperty(this._selectedElements, id)) {
15772
+ const element = this._selectedElements[id];
15773
+ element.setSelected(false);
15774
+ if (notify) {
15775
+ if (element instanceof Source) {
15776
+ sources.push(element);
15777
+ } else {
15778
+ segments.push(element);
15779
+ }
15736
15780
  }
15781
+ delete this._selectedElements[id];
15782
+ }
15783
+ }
15784
+ if (notify) {
15785
+ if (sources.length) {
15786
+ this._peaks.emit('sources.deselected', sources);
15787
+ }
15788
+ if (segments.length) {
15789
+ this._peaks.emit('segments.deselected', segments);
15737
15790
  }
15738
- this._selectedElement = null;
15739
15791
  }
15740
15792
  };
15793
+ ModeLayer.prototype.getSelectedElements = function () {
15794
+ return this._selectedElements;
15795
+ };
15741
15796
  ModeLayer.prototype._prepareDefaultMode = function () {
15742
15797
  this._selectedElement = null;
15743
15798
  };
@@ -15787,24 +15842,30 @@ module.exports = function (Utils, SourceGroup, Konva) {
15787
15842
  this._layer.add(this._cutGroup);
15788
15843
  };
15789
15844
  ModeLayer.prototype._onMouseClickInDefaultMode = function () {
15790
- var hoveredElement = this._view.getHoveredElement();
15791
- if (hoveredElement) {
15792
- this.selectElement(hoveredElement, true);
15845
+ const hoveredKonvaElement = this._view.getHoveredElement();
15846
+ if (hoveredKonvaElement) {
15847
+ if (hoveredKonvaElement instanceof SourceGroup) {
15848
+ this.selectElements([hoveredKonvaElement.getSource()], true);
15849
+ } else {
15850
+ this.selectElements([hoveredKonvaElement.getSegment()], true);
15851
+ }
15793
15852
  } else {
15794
- this.deselectElement(true);
15853
+ this.deselectAll(true);
15854
+ this._view.drawSourcesLayer();
15795
15855
  }
15796
15856
  };
15797
15857
  ModeLayer.prototype._onKeyboardDelete = function () {
15798
- if (this._selectedElement) {
15799
- var selectedElement = this._selectedElement;
15800
- this.deselectElement(true);
15801
- if (selectedElement instanceof SourceGroup) {
15858
+ const selectedElements = Object.values(this._selectedElements);
15859
+ if (selectedElements.length) {
15860
+ var selectedElement = selectedElements[0];
15861
+ this.deselectAll(true);
15862
+ if (selectedElement instanceof Source) {
15802
15863
  if (selectedElement.isDeletable()) {
15803
- this._peaks.destroySource(selectedElement.getSource().id);
15864
+ this._peaks.destroySource(selectedElement.id);
15804
15865
  }
15805
15866
  } else {
15806
15867
  if (selectedElement.getSegment().allowDeletion) {
15807
- this._peaks.destroySegment(selectedElement.getSegment().id);
15868
+ this._peaks.destroySegment(selectedElement.id);
15808
15869
  }
15809
15870
  }
15810
15871
  }
@@ -15943,7 +16004,7 @@ module.exports = function (Utils, SourceGroup, Konva) {
15943
16004
  this._peaks.off('keyboard.delete', this._onKeyboardDelete);
15944
16005
  break;
15945
16006
  }
15946
- this.deselectElement(true);
16007
+ this.deselectAll(true);
15947
16008
  switch (mode) {
15948
16009
  case 'cut':
15949
16010
  this._stage.on('mouseover', this._onMouseEnterInCutMode);
@@ -15980,8 +16041,8 @@ module.exports = function (Utils, SourceGroup, Konva) {
15980
16041
  return this._mode;
15981
16042
  };
15982
16043
  return ModeLayer;
15983
- }(_dereq_('./utils'), _dereq_('./source-group'), _dereq_('konva'));
15984
- },{"./source-group":104,"./utils":112,"konva":43}],97:[function(_dereq_,module,exports){
16044
+ }(_dereq_('./utils'), _dereq_('./source'), _dereq_('./source-group'), _dereq_('konva'));
16045
+ },{"./source":105,"./source-group":104,"./utils":112,"konva":43}],97:[function(_dereq_,module,exports){
15985
16046
  module.exports = function (Konva) {
15986
16047
  'use strict';
15987
16048
  function getMarkerObject(obj) {
@@ -16184,15 +16245,15 @@ module.exports = function (Utils, Konva) {
16184
16245
  draggable: true,
16185
16246
  dragBoundFunc: function (pos) {
16186
16247
  var time = Math.max(0, self._view.pixelsToTime(pos.x + self._view.getFrameOffset()));
16187
- var autoPos = self._view.updateWithAutoScroll(this, function () {
16248
+ self._view.updateWithAutoScroll(function () {
16188
16249
  time = Math.max(0, self._view.pixelsToTime(self._view.getPointerPosition().x + self._view.getFrameOffset()));
16189
16250
  self._onPlayheadDrag(time);
16190
16251
  }, function () {
16191
16252
  self._onPlayheadDrag(time);
16192
16253
  });
16193
16254
  return {
16194
- x: autoPos.x,
16195
- y: autoPos.y
16255
+ x: Math.max(pos.x, 0),
16256
+ y: 0
16196
16257
  };
16197
16258
  }
16198
16259
  });
@@ -16210,7 +16271,6 @@ module.exports = function (Utils, Konva) {
16210
16271
  PlayheadLayer.prototype._onPlayheadDragStart = function () {
16211
16272
  this._view.enableAutoScroll(false);
16212
16273
  this._dragging = true;
16213
- this._scrollInterval = null;
16214
16274
  };
16215
16275
  PlayheadLayer.prototype._onPlayheadDragEnd = function () {
16216
16276
  this._view.enableAutoScroll(true);
@@ -16412,7 +16472,6 @@ module.exports = function (Konva, SegmentMarker, Utils) {
16412
16472
  this._endMarker = null;
16413
16473
  this._shapeGroup = null;
16414
16474
  this._rectangle = null;
16415
- this._isSelected = false;
16416
16475
  this._indicators = {};
16417
16476
  var self = this;
16418
16477
  this._segmentWidth = this._view.timeToPixels(this._segment.endTime - this._segment.startTime);
@@ -16448,14 +16507,7 @@ module.exports = function (Konva, SegmentMarker, Utils) {
16448
16507
  });
16449
16508
  this._shapeGroup.add(this._rectangle);
16450
16509
  this._shapeGroup.dragBoundFunc(function () {
16451
- var diff = self._view.getPointerPosition().x - self._mouseDownX;
16452
- self._group.updateSegment(self._segment, self._initialStartPixel + diff, self._initialEndPixel + diff);
16453
- self._startMarker.timeUpdated(self._segment.startTime);
16454
- self._endMarker.timeUpdated(self._segment.endTime);
16455
- return {
16456
- x: this.absolutePosition().x,
16457
- y: this.absolutePosition().y
16458
- };
16510
+ return self._onShapeGroupDrag(this);
16459
16511
  });
16460
16512
  this._shapeGroup.on('mouseenter', this._onMouseEnter.bind(this));
16461
16513
  this._shapeGroup.on('mouseleave', this._onMouseLeave.bind(this));
@@ -16480,6 +16532,16 @@ module.exports = function (Konva, SegmentMarker, Utils) {
16480
16532
  this._shapeGroup.add(this._indicatorsGroup);
16481
16533
  this.createIndicators();
16482
16534
  }
16535
+ SegmentShape.prototype._onShapeGroupDrag = function (draggedElement) {
16536
+ const diff = this._view.getPointerPosition().x - this._mouseDownX;
16537
+ this._group.updateSegment(this._segment, this._initialStartPixel + diff, this._initialEndPixel + diff);
16538
+ this._startMarker.timeUpdated(this._segment.startTime);
16539
+ this._endMarker.timeUpdated(this._segment.endTime);
16540
+ return {
16541
+ x: draggedElement.absolutePosition().x,
16542
+ y: draggedElement.absolutePosition().y
16543
+ };
16544
+ };
16483
16545
  SegmentShape.prototype._cornerRadius = function () {
16484
16546
  return this._segment.borderRadius !== undefined && this._segment.borderRadius !== null ? this._segment.borderRadius : SEGMENT_CORNER_RADIUS;
16485
16547
  };
@@ -16709,9 +16771,6 @@ module.exports = function (Konva, SegmentMarker, Utils) {
16709
16771
  var startMarker = segmentMarker.isStartMarker();
16710
16772
  this._peaks.emit('segments.dragend', this._segment, startMarker);
16711
16773
  };
16712
- SegmentShape.prototype.setSelected = function (isSelected) {
16713
- this._isSelected = isSelected;
16714
- };
16715
16774
  SegmentShape.prototype.fitToView = function () {
16716
16775
  if (this._startMarker) {
16717
16776
  this._startMarker.fitToView();
@@ -16845,6 +16904,7 @@ module.exports = function (Utils) {
16845
16904
  this._indicators = opts.indicators;
16846
16905
  this._minSize = peaks.options.minSegmentSize;
16847
16906
  this._relativeId = 0;
16907
+ this._selected = false;
16848
16908
  if (shouldNotifyUpdate) {
16849
16909
  peaks.emit('segments.updated', [this]);
16850
16910
  }
@@ -17024,6 +17084,9 @@ module.exports = function (Utils) {
17024
17084
  this._indicators = opts.indicators;
17025
17085
  this._peaks.emit('segment.updated', this);
17026
17086
  };
17087
+ Segment.prototype.setSelected = function (selected) {
17088
+ this._selected = selected;
17089
+ };
17027
17090
  Segment.prototype.isVisible = function (startTime, endTime) {
17028
17091
  return this.startTime < endTime && startTime < this.endTime;
17029
17092
  };
@@ -17583,15 +17646,14 @@ module.exports = function (WaveformBuilder, WaveformShape, Utils, Konva) {
17583
17646
  this._previewList = [];
17584
17647
  this._group = new Konva.Group({
17585
17648
  x: this._x,
17649
+ sourceId: this._source.id,
17586
17650
  draggable: this._source.draggable,
17587
17651
  dragBoundFunc: function () {
17588
- return {
17589
- x: this.absolutePosition().x,
17590
- y: this.absolutePosition().y
17591
- };
17652
+ return self._layer.onSourcesGroupDrag(this);
17592
17653
  }
17593
17654
  });
17594
- this._group.on('dragstart', this._onSourceGroupDragStart.bind(this));
17655
+ this._group.on('dragstart', this._layer.onSourcesGroupDragStart.bind(this._layer));
17656
+ this._group.on('dragend', this._layer.onSourcesGroupDragEnd.bind(this._layer));
17595
17657
  this._group.on('mouseover', function () {
17596
17658
  self._view.setHoveredElement(self);
17597
17659
  if (self._view.getCurrentMode() === 'cut') {
@@ -17606,7 +17668,6 @@ module.exports = function (WaveformBuilder, WaveformShape, Utils, Konva) {
17606
17668
  self.toggleResizing(true);
17607
17669
  }
17608
17670
  });
17609
- this._group.on('dragend', this._onSourceGroupDragEnd.bind(this));
17610
17671
  this._group.add(new Konva.Group());
17611
17672
  if (this._borderWidth) {
17612
17673
  this._border = new Konva.Shape({
@@ -17619,51 +17680,27 @@ module.exports = function (WaveformBuilder, WaveformShape, Utils, Konva) {
17619
17680
  }
17620
17681
  this._addHandles();
17621
17682
  this.setWrapping(source.wrapped);
17683
+ this._setSelected();
17622
17684
  this._indicatorsGroup = new Konva.Group();
17623
17685
  this._group.add(this._indicatorsGroup);
17624
17686
  this.createIndicators();
17625
17687
  }
17626
- SourceGroup.prototype._onSourceGroupDragStart = function () {
17627
- this._dragged = true;
17628
- this._mouseDownX = this._view.getPointerPosition().x;
17629
- this._initialStartTime = this._source.startTime;
17630
- this._initialStartPixel = this._view.timeToPixels(this._initialStartTime);
17631
- this._initialEndTime = this._source.endTime;
17632
- this._initialEndPixel = this._view.timeToPixels(this._initialEndTime);
17633
- this._initialFrameOffset = this._view.getFrameOffset();
17634
- };
17635
- SourceGroup.prototype._onSourceGroupDragEnd = function () {
17688
+ SourceGroup.prototype.prepareDragEnd = function () {
17636
17689
  var handleWidth = Math.min(this._peaks.options.sourceHandleWidth, this._width / 2);
17637
17690
  this._leftHandle.width(handleWidth);
17638
17691
  this._rightHandle.width(handleWidth);
17639
17692
  this._rightHandle.x(this._width - handleWidth);
17640
- this._view.drawSourcesLayer();
17641
- this._dragged = false;
17642
- this._view.updateTimelineLength();
17643
- this._peaks.emit('sources.updated', [this._source]);
17644
- };
17645
- SourceGroup.prototype._onSourceGroupDrag = function (draggedElement) {
17646
- var self = this;
17647
- var pos = this._view.updateWithAutoScroll(draggedElement, function () {
17648
- var mousePos = Math.min(self._view.getWidth() - self._peaks.options.autoScrollThreshold * self._view.getWidth(), Math.max(0, self._view.getPointerPosition().x));
17649
- var diff = mousePos - self._mouseDownX;
17650
- self._layer.updateSource(self._source, self._initialStartPixel + diff + (self._view.getFrameOffset() - self._initialFrameOffset), self._initialEndPixel + diff + (self._view.getFrameOffset() - self._initialFrameOffset), self._view.getPointerPosition().y);
17651
- self._view.setTimelineLength(self._view.timeToPixels(self._source.endTime) + self._view.getWidth());
17652
- });
17653
- return {
17654
- x: pos.x,
17655
- y: pos.y
17656
- };
17657
17693
  };
17658
17694
  SourceGroup.prototype._onSourceGroupHandleDrag = function (draggedElement, dragPos, leftHandle) {
17659
- var self = this;
17660
- var pos = this._view.updateWithAutoScroll(draggedElement, function () {
17661
- self._layer.updateSource(self._source, leftHandle ? dragPos.x + self._view.getFrameOffset() : null, leftHandle ? null : dragPos.x + draggedElement.width() + self._view.getFrameOffset());
17662
- });
17695
+ this._view.updateWithAutoScroll(function () {
17696
+ if (this._layer.updateSource(this._source, leftHandle ? dragPos.x + this._view.getFrameOffset() : null, leftHandle ? null : dragPos.x + draggedElement.width() + this._view.getFrameOffset())) {
17697
+ this._layer.draw();
17698
+ }
17699
+ }.bind(this));
17663
17700
  this._view.setTimelineLength(this._view.timeToPixels(this._source.endTime) + this._view.getWidth());
17664
17701
  return {
17665
- x: pos.x,
17666
- y: pos.y
17702
+ x: draggedElement.absolutePosition().x,
17703
+ y: draggedElement.absolutePosition().y
17667
17704
  };
17668
17705
  };
17669
17706
  SourceGroup.prototype.update = function () {
@@ -17717,12 +17754,6 @@ module.exports = function (WaveformBuilder, WaveformShape, Utils, Konva) {
17717
17754
  }
17718
17755
  });
17719
17756
  if (this._source.resizable) {
17720
- this._leftHandle.on('dragend', function () {
17721
- if (this._scrollingInterval) {
17722
- clearInterval(this._scrollingInterval);
17723
- this._scrollingInterval = null;
17724
- }
17725
- });
17726
17757
  this._leftHandle.on('mouseover', function () {
17727
17758
  self._view.setCursor('ew-resize');
17728
17759
  });
@@ -17743,12 +17774,6 @@ module.exports = function (WaveformBuilder, WaveformShape, Utils, Konva) {
17743
17774
  }
17744
17775
  });
17745
17776
  if (this._source.resizable) {
17746
- this._rightHandle.on('dragend', function () {
17747
- if (this._scrollingInterval) {
17748
- clearInterval(this._scrollingInterval);
17749
- this._scrollingInterval = null;
17750
- }
17751
- });
17752
17777
  this._rightHandle.on('mouseover', function () {
17753
17778
  self._view.setCursor('ew-resize');
17754
17779
  });
@@ -17819,13 +17844,6 @@ module.exports = function (WaveformBuilder, WaveformShape, Utils, Konva) {
17819
17844
  var unwrap = new Konva.Group({
17820
17845
  width: this._width,
17821
17846
  height: this._unwrappedHeight,
17822
- draggable: this._source.draggable,
17823
- dragBoundFunc: function () {
17824
- return {
17825
- x: this.absolutePosition().x,
17826
- y: this.absolutePosition().y
17827
- };
17828
- },
17829
17847
  clipFunc: function (ctx) {
17830
17848
  self.drawSourceShape(ctx, null, true);
17831
17849
  }
@@ -17837,25 +17855,12 @@ module.exports = function (WaveformBuilder, WaveformShape, Utils, Konva) {
17837
17855
  unwrap.on('mouseout', function () {
17838
17856
  self._view.setCursor('default');
17839
17857
  });
17840
- unwrap.on('dragstart', function () {
17841
- this._scrollInterval = null;
17842
- });
17843
- unwrap.on('dragend', function () {
17844
- if (this._scrollingInterval) {
17845
- clearInterval(this._scrollingInterval);
17846
- this._scrollingInterval = null;
17847
- }
17848
- });
17849
17858
  }
17850
17859
  var background = new Konva.Group();
17851
17860
  background.add(new Konva.Shape({
17852
17861
  fill: this._source.backgroundColor,
17853
17862
  sceneFunc: function (ctx, shape) {
17854
17863
  self.drawSourceShape(ctx, shape, true);
17855
- },
17856
- draggable: this._source.draggable,
17857
- dragBoundFunc: function () {
17858
- return self._onSourceGroupDrag(this);
17859
17864
  }
17860
17865
  }));
17861
17866
  unwrap.add(background);
@@ -17885,13 +17890,6 @@ module.exports = function (WaveformBuilder, WaveformShape, Utils, Konva) {
17885
17890
  var wrap = new Konva.Group({
17886
17891
  width: this._width,
17887
17892
  height: this._wrappedHeight,
17888
- draggable: this._source.draggable,
17889
- dragBoundFunc: function () {
17890
- return {
17891
- x: this.absolutePosition().x,
17892
- y: this.absolutePosition().y
17893
- };
17894
- },
17895
17893
  clipFunc: function (ctx) {
17896
17894
  self.drawSourceShape(ctx, null, true);
17897
17895
  }
@@ -17903,25 +17901,12 @@ module.exports = function (WaveformBuilder, WaveformShape, Utils, Konva) {
17903
17901
  wrap.on('mouseout', function () {
17904
17902
  self._view.setCursor('default');
17905
17903
  });
17906
- wrap.on('dragstart', function () {
17907
- this._scrollInterval = null;
17908
- });
17909
- wrap.on('dragend', function () {
17910
- if (this._scrollingInterval) {
17911
- clearInterval(this._scrollingInterval);
17912
- this._scrollingInterval = null;
17913
- }
17914
- });
17915
17904
  }
17916
17905
  var background = new Konva.Group();
17917
17906
  background.add(new Konva.Shape({
17918
17907
  fill: this._source.backgroundColor,
17919
17908
  sceneFunc: function (ctx, shape) {
17920
17909
  self.drawSourceShape(ctx, shape, true);
17921
- },
17922
- draggable: this._source.draggable,
17923
- dragBoundFunc: function () {
17924
- return self._onSourceGroupDrag(this);
17925
17910
  }
17926
17911
  }));
17927
17912
  wrap.add(background);
@@ -18158,9 +18143,9 @@ module.exports = function (WaveformBuilder, WaveformShape, Utils, Konva) {
18158
18143
  return preview.type === 'audio';
18159
18144
  });
18160
18145
  };
18161
- SourceGroup.prototype.setSelected = function (isSelected) {
18146
+ SourceGroup.prototype._setSelected = function () {
18162
18147
  if (this._border) {
18163
- if (isSelected) {
18148
+ if (this._source._selected) {
18164
18149
  this._border.fill(this._source.selectedColor);
18165
18150
  this._borderWidth = this._peaks.options.sourceSelectedBorderWidth;
18166
18151
  } else {
@@ -18173,7 +18158,7 @@ module.exports = function (WaveformBuilder, WaveformShape, Utils, Konva) {
18173
18158
  return node.getClassName() === 'Shape';
18174
18159
  });
18175
18160
  if (unwrap_background) {
18176
- if (isSelected) {
18161
+ if (this._source._selected) {
18177
18162
  unwrap_background.stroke(this._source.selectedColor);
18178
18163
  unwrap_background.strokeWidth(this._peaks.options.sourceSelectedBorderWidth);
18179
18164
  } else {
@@ -18186,7 +18171,7 @@ module.exports = function (WaveformBuilder, WaveformShape, Utils, Konva) {
18186
18171
  return node.getClassName() === 'Shape';
18187
18172
  });
18188
18173
  if (wrap_background) {
18189
- if (isSelected) {
18174
+ if (this._source._selected) {
18190
18175
  wrap_background.stroke(this._source.selectedColor);
18191
18176
  wrap_background.strokeWidth(this._peaks.options.sourceSelectedBorderWidth);
18192
18177
  } else {
@@ -18195,7 +18180,6 @@ module.exports = function (WaveformBuilder, WaveformShape, Utils, Konva) {
18195
18180
  }
18196
18181
  }
18197
18182
  }
18198
- this._view.drawSourcesLayer();
18199
18183
  };
18200
18184
  SourceGroup.prototype.updatePreviews = function () {
18201
18185
  var self = this;
@@ -18293,9 +18277,6 @@ module.exports = function (WaveformBuilder, WaveformShape, Utils, Konva) {
18293
18277
  SourceGroup.prototype.isVisible = function () {
18294
18278
  return this._group.visible();
18295
18279
  };
18296
- SourceGroup.prototype.isDragged = function () {
18297
- return this._dragged;
18298
- };
18299
18280
  SourceGroup.prototype.isCuttable = function () {
18300
18281
  return this._source.cuttable;
18301
18282
  };
@@ -18305,6 +18286,9 @@ module.exports = function (WaveformBuilder, WaveformShape, Utils, Konva) {
18305
18286
  SourceGroup.prototype.destroy = function () {
18306
18287
  this._group.destroy();
18307
18288
  };
18289
+ SourceGroup.prototype.getLine = function () {
18290
+ return this._source.position;
18291
+ };
18308
18292
  SourceGroup.prototype.createIndicators = function () {
18309
18293
  var newIndicatorsColors = this._source.indicators;
18310
18294
  var oldIndicators = this._indicators;
@@ -18602,6 +18586,7 @@ module.exports = function (Utils) {
18602
18586
  this._binaryHeight = opts.binaryHeight;
18603
18587
  this._indicators = opts.indicators;
18604
18588
  this._minSize = peaks.options.minSourceSize;
18589
+ this._selected = false;
18605
18590
  }
18606
18591
  Object.defineProperties(Source.prototype, {
18607
18592
  id: {
@@ -19053,6 +19038,10 @@ module.exports = function (Utils) {
19053
19038
  this._indicators = opts.indicators;
19054
19039
  this._peaks.emit('source.update', this);
19055
19040
  };
19041
+ Source.prototype.setSelected = function (selected) {
19042
+ this._selected = selected;
19043
+ this._peaks.emit('source.update', this);
19044
+ };
19056
19045
  Source.prototype.isVisible = function (startTime, endTime) {
19057
19046
  return this._startTime < endTime && startTime < this._endTime;
19058
19047
  };
@@ -19250,6 +19239,57 @@ module.exports = function (SourceGroup, Lines, DataRetriever, Utils, Invoker, Ko
19250
19239
  this._layer.draw();
19251
19240
  }
19252
19241
  };
19242
+ SourcesLayer.prototype.onSourcesGroupDragStart = function (element) {
19243
+ this._initialFrameOffset = this._view.getFrameOffset();
19244
+ this._mouseDownX = this._view.getPointerPosition().x;
19245
+ this._selectedElements = {};
19246
+ const draggedElementId = element.currentTarget.attrs.sourceId;
19247
+ const shouldDragSelectedElements = Object.keys(this._view.getSelectedElements()).includes(draggedElementId);
19248
+ this._nonSelectedElement = shouldDragSelectedElements ? null : [this._sourcesGroup[draggedElementId].getSource()];
19249
+ };
19250
+ SourcesLayer.prototype.onSourcesGroupDragEnd = function () {
19251
+ const updatedSources = (this._nonSelectedElement || Object.values(this._view.getSelectedElements())).map(function (source) {
19252
+ const sourceGroup = this._sourcesGroup[source.id];
19253
+ if (sourceGroup) {
19254
+ sourceGroup.prepareDragEnd();
19255
+ }
19256
+ return source;
19257
+ }.bind(this));
19258
+ this._view.drawSourcesLayer();
19259
+ this._view.updateTimelineLength();
19260
+ this._selectedElements = {};
19261
+ this._peaks.emit('sources.updated', updatedSources);
19262
+ };
19263
+ SourcesLayer.prototype.onSourcesGroupDrag = function (draggedElement) {
19264
+ this._view.updateWithAutoScroll(this._updateSourcesGroup.bind(this));
19265
+ return {
19266
+ x: draggedElement.absolutePosition().x,
19267
+ y: draggedElement.absolutePosition().y
19268
+ };
19269
+ };
19270
+ SourcesLayer.prototype._updateSourcesGroup = function () {
19271
+ var mousePos = Math.min(this._view.getWidth() - this._peaks.options.autoScrollThreshold * this._view.getWidth(), Math.max(0, this._view.getPointerPosition().x));
19272
+ const diff = mousePos - this._mouseDownX;
19273
+ const currentFrameOffset = this._view.getFrameOffset();
19274
+ const mousePosY = this._view.getPointerPosition().y;
19275
+ var newEnd = 0;
19276
+ var shouldRedraw = false;
19277
+ (this._nonSelectedElement || Object.values(this._view.getSelectedElements())).forEach(function (source) {
19278
+ if (!this._selectedElements[source.id]) {
19279
+ this._selectedElements[source.id] = {
19280
+ startX: this._view.timeToPixels(source.startTime),
19281
+ endX: this._view.timeToPixels(source.endTime)
19282
+ };
19283
+ }
19284
+ const {startX, endX} = this._selectedElements[source.id];
19285
+ newEnd = Math.max(newEnd, source.endTime);
19286
+ shouldRedraw = this.updateSource(source, startX + diff + (currentFrameOffset - this._initialFrameOffset), endX + diff + (currentFrameOffset - this._initialFrameOffset), mousePosY) || shouldRedraw;
19287
+ }.bind(this));
19288
+ if (shouldRedraw) {
19289
+ this.draw();
19290
+ }
19291
+ this._view.setTimelineLength(this._view.timeToPixels(newEnd) + this._view.getWidth());
19292
+ };
19253
19293
  SourcesLayer.prototype.findSources = function (startTime, endTime) {
19254
19294
  var sources = this._peaks.sources.find(startTime, endTime);
19255
19295
  var positions = this._lines.getVisibleLines();
@@ -19271,8 +19311,9 @@ module.exports = function (SourceGroup, Lines, DataRetriever, Utils, Invoker, Ko
19271
19311
  source.updateTimes(newXs.startX !== null ? this._view.pixelsToTime(newXs.startX) : null, newXs.endX !== null ? this._view.pixelsToTime(newXs.endX) : null);
19272
19312
  if (newXs) {
19273
19313
  this._updateSource(source, newXs.updateWidth);
19274
- this.draw();
19314
+ return true;
19275
19315
  }
19316
+ return false;
19276
19317
  };
19277
19318
  SourcesLayer.prototype.manageVerticalPosition = function (source, newY) {
19278
19319
  return this._lines.manageVerticalPosition(source, newY);
@@ -19299,7 +19340,7 @@ module.exports = function (SourceGroup, Lines, DataRetriever, Utils, Invoker, Ko
19299
19340
  for (var sourceId in this._sourcesGroup) {
19300
19341
  if (Utils.objectHasProperty(this._sourcesGroup, sourceId)) {
19301
19342
  var source = this._sourcesGroup[sourceId].getSource();
19302
- if (!this._isSourceVisible(source, startTime, endTime) && !this._sourcesGroup[sourceId].isDragged()) {
19343
+ if (!this._isSourceVisible(source, startTime, endTime)) {
19303
19344
  this._removeSource(source);
19304
19345
  count++;
19305
19346
  }
@@ -19366,6 +19407,9 @@ module.exports = function (SourceGroup, Lines, DataRetriever, Utils, Invoker, Ko
19366
19407
  SourcesLayer.prototype.getSourceGroupById = function (sourceId) {
19367
19408
  return this._sourcesGroup[sourceId];
19368
19409
  };
19410
+ SourcesLayer.prototype.getSourcesOnLineAfter = function (lineId, time) {
19411
+ return this._lines.getSourcesOnLineAfter(lineId, time);
19412
+ };
19369
19413
  SourcesLayer.prototype._sourcesOverlapped = function (source1, source2) {
19370
19414
  var endsLater = source1.startTime < source2.startTime && source1.endTime > source2.startTime;
19371
19415
  var startsEarlier = source1.startTime > source2.startTime && source1.startTime < source2.endTime;
@@ -19407,9 +19451,11 @@ module.exports = function (SourceGroup, Lines, DataRetriever, Utils, Invoker, Ko
19407
19451
  this._peaks.off('sources.destroy', this._onSourcesDestroy);
19408
19452
  this._peaks.off('sources.show', this._onSourcesShow);
19409
19453
  this._peaks.off('sources.hide', this._onSourcesHide);
19454
+ this._peaks.off('source.update', this._onSourceUpdate);
19410
19455
  this._peaks.off('data.retrieved', this._onDataRetrieved);
19411
19456
  this._peaks.off('sources.refresh', this._onSourcesRefresh);
19412
19457
  this._peaks.off('segments.show', this._onSegmentsShow);
19458
+ this._peaks.off('options.set.line_height', this._onOptionsLineHeightChange);
19413
19459
  this._peaks.off('source.setIndicators', this.setIndicators);
19414
19460
  };
19415
19461
  SourcesLayer.prototype.getHeight = function () {
@@ -20076,6 +20122,9 @@ module.exports = function (MouseDragHandler, PlayheadLayer, SourcesLayer, ModeLa
20076
20122
  });
20077
20123
  this._stage.on('wheel', function (e) {
20078
20124
  e.evt.preventDefault();
20125
+ if (self._mouseDragHandler.isDragging()) {
20126
+ return;
20127
+ }
20079
20128
  if (self._peaks.keyboardHandler.isCtrlCmdPressed()) {
20080
20129
  if (e.evt.deltaY > 0) {
20081
20130
  self.setZoom(self.getTimeToPixelsScale() + Math.floor(self.getTimeToPixelsScale() / 10) + 1);
@@ -20102,46 +20151,54 @@ module.exports = function (MouseDragHandler, PlayheadLayer, SourcesLayer, ModeLa
20102
20151
  }
20103
20152
  }
20104
20153
  });
20154
+ window.addEventListener('mouseup', this._mouseUp.bind(this), false);
20155
+ window.addEventListener('touchend', this._mouseUp.bind(this), false);
20156
+ window.addEventListener('blur', this._mouseUp.bind(this), false);
20105
20157
  }
20106
- TimelineZoomView.prototype.updateWithAutoScroll = function (obj, updateInInterval, updateOutInterval) {
20158
+ TimelineZoomView.prototype._mouseUp = function () {
20159
+ this.clearScrollingInterval();
20160
+ };
20161
+ TimelineZoomView.prototype.getSelectedElements = function () {
20162
+ return Object.values(this._modeLayer.getSelectedElements());
20163
+ };
20164
+ TimelineZoomView.prototype.updateWithAutoScroll = function (updateInInterval, updateOutInterval) {
20107
20165
  var self = this;
20108
20166
  var posX = this.getPointerPosition().x;
20109
20167
  var threshold = Math.round(this._peaks.options.autoScrollThreshold * this.getWidth());
20110
- obj._limited = 0;
20168
+ this._limited = 0;
20111
20169
  if (posX < threshold) {
20112
- obj._limited = Math.round(-30 * Math.min(1, (threshold - posX) / threshold));
20170
+ this._limited = Math.round(-30 * Math.min(1, (threshold - posX) / threshold));
20113
20171
  } else if (posX > this.getWidth() - threshold) {
20114
- obj._limited = Math.round(30 * Math.min(1, (posX - (this.getWidth() - threshold)) / threshold));
20172
+ this._limited = Math.round(30 * Math.min(1, (posX - (this.getWidth() - threshold)) / threshold));
20115
20173
  }
20116
- if (obj._limited && self.getFrameOffset() > 0 || obj._limited > 0) {
20117
- if (!obj._scrollingInterval) {
20118
- obj._scrollingInterval = setInterval(function () {
20119
- var newOffset = self.getFrameOffset() + obj._limited;
20174
+ if (this._limited && self.getFrameOffset() > 0 || this._limited > 0) {
20175
+ if (!this._scrollingInterval) {
20176
+ this._scrollingInterval = setInterval(function () {
20177
+ var newOffset = self.getFrameOffset() + self._limited;
20120
20178
  if (newOffset < 0) {
20121
20179
  self.updateTimeline(0, null, false);
20122
- clearInterval(obj._scrollingInterval);
20123
- obj._scrollingInterval = null;
20180
+ clearInterval(self._scrollingInterval);
20181
+ self._scrollingInterval = null;
20124
20182
  } else {
20125
- self.updateTimeline(self.getFrameOffset() + obj._limited, null, false);
20183
+ self.updateTimeline(self.getFrameOffset() + self._limited, null, false);
20126
20184
  }
20127
20185
  updateInInterval();
20128
20186
  }, 10);
20129
20187
  }
20130
20188
  } else {
20131
- if (obj._scrollingInterval) {
20132
- clearInterval(obj._scrollingInterval);
20133
- obj._scrollingInterval = null;
20134
- }
20189
+ this.clearScrollingInterval();
20135
20190
  if (updateOutInterval) {
20136
20191
  updateOutInterval();
20137
20192
  } else {
20138
20193
  updateInInterval();
20139
20194
  }
20140
20195
  }
20141
- return {
20142
- x: obj.absolutePosition().x,
20143
- y: obj.absolutePosition().y
20144
- };
20196
+ };
20197
+ TimelineZoomView.prototype.clearScrollingInterval = function () {
20198
+ if (this._scrollingInterval) {
20199
+ clearInterval(this._scrollingInterval);
20200
+ this._scrollingInterval = null;
20201
+ }
20145
20202
  };
20146
20203
  TimelineZoomView.prototype.getCurrentMode = function () {
20147
20204
  return this._modeLayer.getCurrentMode();
@@ -20157,14 +20214,23 @@ module.exports = function (MouseDragHandler, PlayheadLayer, SourcesLayer, ModeLa
20157
20214
  this._sourcesLayer.stopDrag();
20158
20215
  this._sourcesLayer.draw();
20159
20216
  };
20217
+ TimelineZoomView.prototype.getSelectedElements = function () {
20218
+ return this._modeLayer.getSelectedElements();
20219
+ };
20160
20220
  TimelineZoomView.prototype.selectSourceById = function (sourceId) {
20161
- var sourceGroup = this._sourcesLayer.getSourceGroupById(sourceId);
20221
+ const sourceGroup = this._sourcesLayer.getSourceGroupById(sourceId);
20162
20222
  if (sourceGroup) {
20163
- this._modeLayer.selectElement(sourceGroup, false);
20223
+ this._modeLayer.selectElements([sourceGroup.getSource()], false);
20224
+ }
20225
+ };
20226
+ TimelineZoomView.prototype.selectSourcesOnLineAfter = function (lineId, time) {
20227
+ const sources = this._sourcesLayer.getSourcesOnLineAfter(lineId, time);
20228
+ if (sources) {
20229
+ this._modeLayer.selectElements(sources, false);
20164
20230
  }
20165
20231
  };
20166
- TimelineZoomView.prototype.deselectElement = function () {
20167
- this._modeLayer.deselectElement(false);
20232
+ TimelineZoomView.prototype.deselectAll = function () {
20233
+ this._modeLayer.deselectAll(false);
20168
20234
  };
20169
20235
  TimelineZoomView.prototype.isListening = function () {
20170
20236
  return this._stage.listening();