@checksub_team/peaks_timeline 2.3.0-alpha.0 → 2.3.0-alpha.1

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
@@ -14418,44 +14418,47 @@ WaveformData.createFromAudio = _dereq_("./lib/builders/webaudio");
14418
14418
  module.exports = WaveformData;
14419
14419
 
14420
14420
  },{"./lib/builders/webaudio":81,"./lib/core":83}],86:[function(_dereq_,module,exports){
14421
- module.exports = function (Utils, Konva) {
14421
+ module.exports = function (Utils, Invoker, Konva) {
14422
14422
  'use strict';
14423
14423
  var LEFT_PADDING = 4;
14424
14424
  function Axis(peaks, view, options) {
14425
14425
  this._view = view;
14426
+ this._invoker = new Invoker();
14426
14427
  var self = this;
14427
14428
  peaks.on('playhead.moved', this._onPlayheadMoved.bind(this));
14428
14429
  peaks.on('playhead.hidden', this._onPlayheadHidden.bind(this));
14429
- self._axisGridlineColor = options.axisGridlineColor;
14430
- self._axisLabelColor = options.axisLabelColor;
14431
- self._backLayer = new Konva.Layer({ listening: false });
14432
- self._frontLayer = new Konva.Layer({ listening: false });
14433
- self._axisShape = new Konva.Shape({
14430
+ this._axisGridlineColor = options.axisGridlineColor;
14431
+ this._axisLabelColor = options.axisLabelColor;
14432
+ this._backLayer = new Konva.Layer({ listening: false });
14433
+ this._frontLayer = new Konva.Layer({ listening: false });
14434
+ this._axisShape = new Konva.Shape({
14434
14435
  sceneFunc: function (context) {
14435
14436
  self.drawAxis(context, view);
14436
14437
  }
14437
14438
  });
14438
- self._backLayer.add(self._axisShape);
14439
- self._timesShape = new Konva.Shape({
14439
+ this._backLayer.add(this._axisShape);
14440
+ this._timesShape = new Konva.Shape({
14440
14441
  sceneFunc: function (context) {
14441
14442
  self.drawTimes(context, view);
14442
14443
  }
14443
14444
  });
14444
- self._frontLayer.add(self._timesShape);
14445
+ this._frontLayer.add(this._timesShape);
14446
+ this._throttledBackDraw = this._invoker.throttleTrailing(this._backLayer.batchDraw.bind(this._backLayer));
14447
+ this._throttledFrontDraw = this._invoker.throttleTrailing(this._frontLayer.batchDraw.bind(this._frontLayer));
14445
14448
  }
14446
14449
  Axis.prototype._onPlayheadMoved = function (playheadX, playheadWidth) {
14447
14450
  this._maskStart = playheadX + this._view.getFrameOffset();
14448
14451
  this._maskEnd = playheadX + this._view.getFrameOffset() + playheadWidth;
14449
- this._frontLayer.batchDraw();
14452
+ this._throttledFrontDraw();
14450
14453
  };
14451
14454
  Axis.prototype._onPlayheadHidden = function () {
14452
14455
  this._maskStart = null;
14453
14456
  this._maskEnd = null;
14454
- this._frontLayer.batchDraw();
14457
+ this._throttledFrontDraw();
14455
14458
  };
14456
14459
  Axis.prototype.batchDraw = function () {
14457
- this._backLayer.batchDraw();
14458
- this._frontLayer.batchDraw();
14460
+ this._throttledBackDraw();
14461
+ this._throttledFrontDraw();
14459
14462
  };
14460
14463
  Axis.prototype.addBackToStage = function (stage) {
14461
14464
  stage.add(this._backLayer);
@@ -14559,8 +14562,8 @@ module.exports = function (Utils, Konva) {
14559
14562
  return false;
14560
14563
  };
14561
14564
  return Axis;
14562
- }(_dereq_('../utils'), _dereq_('konva'));
14563
- },{"../utils":116,"konva":43}],87:[function(_dereq_,module,exports){
14565
+ }(_dereq_('../utils'), _dereq_('./invoker'), _dereq_('konva'));
14566
+ },{"../utils":116,"./invoker":90,"konva":43}],87:[function(_dereq_,module,exports){
14564
14567
  module.exports = function (Data, Utils) {
14565
14568
  'use strict';
14566
14569
  function DataRetriever(peaks) {
@@ -15732,30 +15735,9 @@ module.exports = function (SegmentsGroup, LineGroup, LineIndicator, Utils) {
15732
15735
  }
15733
15736
  this._automaticallyCreatedLineId = automaticallyCreatedLineGroup.getId();
15734
15737
  this._moveSourcesToPositionIfPossible(sources, newLinePosition);
15735
- this._nudgeFrameOffsetYToLineCenter(newLinePosition, this._automaticLineCreationMouseY);
15736
15738
  this._peaks.emit('sources.delayedLineChange', sources);
15737
15739
  }.bind(this), this._peaks.options.automaticLineCreationDelay);
15738
15740
  };
15739
- LineGroups.prototype._nudgeFrameOffsetYToLineCenter = function (linePosition, mouseY) {
15740
- if (!this._peaks.options.enableVerticalScrolling) {
15741
- return;
15742
- }
15743
- if (Utils.isNullOrUndefined(mouseY)) {
15744
- return;
15745
- }
15746
- const lineGroup = this._lineGroupsByPosition[linePosition];
15747
- if (!lineGroup) {
15748
- return;
15749
- }
15750
- const targetCenterY = lineGroup.y() + lineGroup.lineHeight() / 2;
15751
- const deltaY = targetCenterY - mouseY;
15752
- if (deltaY === 0) {
15753
- return;
15754
- }
15755
- const maxOffsetY = Math.max(0, this._view.getFullHeight() - this._view.getHeight());
15756
- const nextOffsetY = Utils.clamp(this._view.getFrameOffsetY() + deltaY, 0, maxOffsetY);
15757
- this._view.updateTimeline(null, nextOffsetY);
15758
- };
15759
15741
  LineGroups.prototype.manageVerticalPosition = function (sources, startTime, endTime, mouseX, mouseY) {
15760
15742
  if (Utils.isNullOrUndefined(mouseX)) {
15761
15743
  return;
@@ -15983,12 +15965,13 @@ module.exports = function (SegmentsGroup, LineGroup, LineIndicator, Utils) {
15983
15965
  return LineGroups;
15984
15966
  }(_dereq_('./segments-group'), _dereq_('./line-group'), _dereq_('./line-indicator'), _dereq_('../utils'));
15985
15967
  },{"../utils":116,"./line-group":91,"./line-indicator":93,"./segments-group":101}],93:[function(_dereq_,module,exports){
15986
- module.exports = function (Konva, SVGs, Utils) {
15968
+ module.exports = function (Konva, SVGs, Invoker, Utils) {
15987
15969
  'use strict';
15988
15970
  function LineIndicator(peaks, view, container) {
15989
15971
  this._peaks = peaks;
15990
15972
  this._view = view;
15991
15973
  this._container = container;
15974
+ this._invoker = new Invoker();
15992
15975
  this._width = this._peaks.options.lineIndicatorWidth;
15993
15976
  this._height = this._view.getHeight();
15994
15977
  this._sizes = {
@@ -16012,6 +15995,7 @@ module.exports = function (Konva, SVGs, Utils) {
16012
15995
  });
16013
15996
  this._layer = new Konva.Layer();
16014
15997
  this._stage.add(this._layer);
15998
+ this._throttledBatchDraw = this._invoker.throttleTrailing(this._layer.batchDraw.bind(this._layer));
16015
15999
  this._indicators = {};
16016
16000
  this._separatingLine = new Konva.Line({
16017
16001
  points: [
@@ -16025,7 +16009,7 @@ module.exports = function (Konva, SVGs, Utils) {
16025
16009
  listening: false
16026
16010
  });
16027
16011
  this._layer.add(this._separatingLine);
16028
- this._layer.batchDraw();
16012
+ this.batchDraw();
16029
16013
  this._isDragging = false;
16030
16014
  this._dragLineId = null;
16031
16015
  this._dragContainerRect = null;
@@ -16301,7 +16285,7 @@ module.exports = function (Konva, SVGs, Utils) {
16301
16285
  return anyChange;
16302
16286
  };
16303
16287
  LineIndicator.prototype.batchDraw = function () {
16304
- this._layer.batchDraw();
16288
+ this._throttledBatchDraw();
16305
16289
  };
16306
16290
  LineIndicator.prototype._onWindowMove = function (event) {
16307
16291
  if (!this._dragContainerRect) {
@@ -16331,8 +16315,8 @@ module.exports = function (Konva, SVGs, Utils) {
16331
16315
  this._stage.container().style.cursor = 'pointer';
16332
16316
  };
16333
16317
  return LineIndicator;
16334
- }(_dereq_('konva'), _dereq_('./svgs'), _dereq_('../utils'));
16335
- },{"../utils":116,"./svgs":104,"konva":43}],94:[function(_dereq_,module,exports){
16318
+ }(_dereq_('konva'), _dereq_('./svgs'), _dereq_('./invoker'), _dereq_('../utils'));
16319
+ },{"../utils":116,"./invoker":90,"./svgs":104,"konva":43}],94:[function(_dereq_,module,exports){
16336
16320
  module.exports = function (Konva) {
16337
16321
  'use strict';
16338
16322
  var RADIUS = 5;
@@ -16414,7 +16398,7 @@ module.exports = function (DefaultSegmentMarker, Utils, Konva) {
16414
16398
  };
16415
16399
  }(_dereq_('./default-segment-marker'), _dereq_('../utils'), _dereq_('konva'));
16416
16400
  },{"../utils":116,"./default-segment-marker":89,"konva":43}],96:[function(_dereq_,module,exports){
16417
- module.exports = function (SourceGroup, Source, Utils, Konva) {
16401
+ module.exports = function (SourceGroup, Invoker, Source, Utils, Konva) {
16418
16402
  'use strict';
16419
16403
  var TIME_X_OFFSET = 20;
16420
16404
  var TIME_Y_OFFSET = 10;
@@ -16424,9 +16408,11 @@ module.exports = function (SourceGroup, Source, Utils, Konva) {
16424
16408
  this._view = view;
16425
16409
  this._playheadLayer = playheadLayer;
16426
16410
  this._stage = stage;
16411
+ this._invoker = new Invoker();
16427
16412
  this._selectedElements = {};
16428
16413
  this._currentLine = null;
16429
16414
  this._layer = new Konva.Layer({ listening: this._mode !== 'default' });
16415
+ this._throttledBatchDraw = this._invoker.throttleTrailing(this._layer.batchDraw.bind(this._layer));
16430
16416
  this._prepareDefaultMode();
16431
16417
  this._onMouseClickInDefaultMode = this._onMouseClickInDefaultMode.bind(this);
16432
16418
  this._onKeyboardDelete = this._onKeyboardDelete.bind(this);
@@ -16438,6 +16424,9 @@ module.exports = function (SourceGroup, Source, Utils, Konva) {
16438
16424
  this.setMode(initialMode);
16439
16425
  this._peaks.on('handler.sources.destroy', this._onSourcesDestroy.bind(this));
16440
16426
  }
16427
+ ModeLayer.prototype.batchDraw = function () {
16428
+ this._throttledBatchDraw();
16429
+ };
16441
16430
  ModeLayer.prototype._onSourcesDestroy = function (sources) {
16442
16431
  const selectedElementsToDeselect = {};
16443
16432
  sources.forEach(function (source) {
@@ -16599,7 +16588,7 @@ module.exports = function (SourceGroup, Source, Utils, Konva) {
16599
16588
  };
16600
16589
  ModeLayer.prototype._onMouseEnterInCutMode = function () {
16601
16590
  this._cutGroup.visible(true);
16602
- this._layer.batchDraw();
16591
+ this.batchDraw();
16603
16592
  };
16604
16593
  ModeLayer.prototype._updateCursorTime = function (position) {
16605
16594
  var hoveredElement = this._view.getHoveredElement();
@@ -16671,11 +16660,11 @@ module.exports = function (SourceGroup, Source, Utils, Konva) {
16671
16660
  }
16672
16661
  this._updateCursorTime(cuttingPosition);
16673
16662
  this._updateCuttingLine(cuttingPosition);
16674
- this._layer.batchDraw();
16663
+ this.batchDraw();
16675
16664
  };
16676
16665
  ModeLayer.prototype._onMouseLeaveInCutMode = function () {
16677
16666
  this._cutGroup.visible(false);
16678
- this._layer.batchDraw();
16667
+ this.batchDraw();
16679
16668
  };
16680
16669
  ModeLayer.prototype._onMouseClickInCutMode = function () {
16681
16670
  var mousePosition = this._stage.getPointerPosition();
@@ -16700,12 +16689,30 @@ module.exports = function (SourceGroup, Source, Utils, Konva) {
16700
16689
  }
16701
16690
  cuttingPixel -= hoveredElement.x();
16702
16691
  this._cuttingLine.visible(false);
16703
- this._peaks.cutSource(hoveredElement.getSource(), this._view.pixelsToTime(cuttingPixel));
16704
16692
  this._view.setHoveredElement(null);
16693
+ this._peaks.cutSource(hoveredElement.getSource(), this._view.pixelsToTime(cuttingPixel));
16694
+ this._syncHoveredElementFromPointer();
16705
16695
  this._updateCursorTime(cuttingPosition);
16706
16696
  this._updateCuttingLine(cuttingPosition);
16707
- this._layer.batchDraw();
16697
+ this.batchDraw();
16698
+ }
16699
+ }
16700
+ };
16701
+ ModeLayer.prototype._syncHoveredElementFromPointer = function () {
16702
+ var pointerPos = this._stage.getPointerPosition();
16703
+ if (!pointerPos) {
16704
+ return;
16705
+ }
16706
+ var node = this._stage.getIntersection(pointerPos);
16707
+ while (node) {
16708
+ if (node.attrs && node.attrs.sourceId) {
16709
+ var sourceGroup = this._view.getSourceGroupById(node.attrs.sourceId);
16710
+ if (sourceGroup && !sourceGroup.isHovered()) {
16711
+ sourceGroup.startHover();
16712
+ }
16713
+ return;
16708
16714
  }
16715
+ node = node.getParent ? node.getParent() : null;
16709
16716
  }
16710
16717
  };
16711
16718
  ModeLayer.prototype.setMode = function (mode) {
@@ -16761,15 +16768,15 @@ module.exports = function (SourceGroup, Source, Utils, Konva) {
16761
16768
  return;
16762
16769
  }
16763
16770
  this._mode = mode;
16764
- this._layer.batchDraw();
16771
+ this.batchDraw();
16765
16772
  this._view.batchDrawSourcesLayer();
16766
16773
  };
16767
16774
  ModeLayer.prototype.getCurrentMode = function () {
16768
16775
  return this._mode;
16769
16776
  };
16770
16777
  return ModeLayer;
16771
- }(_dereq_('./source-group'), _dereq_('../models/source'), _dereq_('../utils'), _dereq_('konva'));
16772
- },{"../models/source":112,"../utils":116,"./source-group":102,"konva":43}],97:[function(_dereq_,module,exports){
16778
+ }(_dereq_('./source-group'), _dereq_('./invoker'), _dereq_('../models/source'), _dereq_('../utils'), _dereq_('konva'));
16779
+ },{"../models/source":112,"../utils":116,"./invoker":90,"./source-group":102,"konva":43}],97:[function(_dereq_,module,exports){
16773
16780
  module.exports = function (Konva) {
16774
16781
  'use strict';
16775
16782
  function getMarkerObject(obj) {
@@ -16866,7 +16873,7 @@ module.exports = function (Konva) {
16866
16873
  return MouseDragHandler;
16867
16874
  }(_dereq_('konva'));
16868
16875
  },{"konva":43}],98:[function(_dereq_,module,exports){
16869
- module.exports = function (Utils, Konva) {
16876
+ module.exports = function (Utils, Invoker, Konva) {
16870
16877
  'use strict';
16871
16878
  var HANDLE_RADIUS = 10;
16872
16879
  function PlayheadLayer(peaks, view, lines, showTime) {
@@ -16879,6 +16886,8 @@ module.exports = function (Utils, Konva) {
16879
16886
  this._playheadTextColor = peaks.options.playheadTextColor;
16880
16887
  this._time = null;
16881
16888
  this._playheadLayer = new Konva.Layer();
16889
+ this._invoker = new Invoker();
16890
+ this._throttledBatchDraw = this._invoker.throttleTrailing(this._playheadLayer.batchDraw.bind(this._playheadLayer));
16882
16891
  this._activeSegments = {};
16883
16892
  this._activeSources = {};
16884
16893
  this._createPlayhead(this._playheadColor);
@@ -17001,9 +17010,12 @@ module.exports = function (Utils, Konva) {
17001
17010
  }
17002
17011
  this._time = time;
17003
17012
  if (pixelHasChanged || timeHasChanged) {
17004
- this._playheadLayer.batchDraw();
17013
+ this.batchDraw();
17005
17014
  }
17006
17015
  };
17016
+ PlayheadLayer.prototype.batchDraw = function () {
17017
+ this._throttledBatchDraw();
17018
+ };
17007
17019
  PlayheadLayer.prototype._updatePlayheadPixel = function (time) {
17008
17020
  const pixelIndex = this._view.timeToPixels(time);
17009
17021
  const frameOffset = this._view.timeToPixels(this._view.getTimeOffset());
@@ -17081,12 +17093,12 @@ module.exports = function (Utils, Konva) {
17081
17093
  }
17082
17094
  }
17083
17095
  if (updated) {
17084
- this._playheadLayer.batchDraw();
17096
+ this.batchDraw();
17085
17097
  }
17086
17098
  };
17087
17099
  return PlayheadLayer;
17088
- }(_dereq_('../utils'), _dereq_('konva'));
17089
- },{"../utils":116,"konva":43}],99:[function(_dereq_,module,exports){
17100
+ }(_dereq_('../utils'), _dereq_('./invoker'), _dereq_('konva'));
17101
+ },{"../utils":116,"./invoker":90,"konva":43}],99:[function(_dereq_,module,exports){
17090
17102
  module.exports = function (Konva) {
17091
17103
  'use strict';
17092
17104
  function SegmentMarker(options) {
@@ -18105,6 +18117,7 @@ module.exports = function (WaveformBuilder, WaveformShape, Loader, Invoker, Util
18105
18117
  this._isDragged = false;
18106
18118
  this._isHandleDragging = false;
18107
18119
  this._destroyed = false;
18120
+ this._dragGhost = null;
18108
18121
  this._drawScheduled = false;
18109
18122
  this._previewList = [];
18110
18123
  this._previewBuildQueue = new Set();
@@ -18171,10 +18184,42 @@ module.exports = function (WaveformBuilder, WaveformShape, Loader, Invoker, Util
18171
18184
  SourceGroup.prototype._onHoverEnd = function () {
18172
18185
  this._hovered = false;
18173
18186
  this._manualHover = false;
18187
+ this._disableManualHoverTracking();
18174
18188
  this._view.setHoveredElement(null);
18175
18189
  this._hideButtons();
18176
18190
  this._scheduleBatchDraw();
18177
18191
  };
18192
+ SourceGroup.prototype._enableManualHoverTracking = function () {
18193
+ if (this._manualHoverTrackingEnabled) {
18194
+ return;
18195
+ }
18196
+ if (!this._group || this._destroyed) {
18197
+ return;
18198
+ }
18199
+ var stage = this._group.getStage && this._group.getStage();
18200
+ if (!stage) {
18201
+ return;
18202
+ }
18203
+ this._manualHoverTrackingEnabled = true;
18204
+ this._manualHoverNamespace = '.manualHover.' + this._source.id;
18205
+ this._manualHoverMoveHandler = function () {
18206
+ this._manageManualHoverStop();
18207
+ }.bind(this);
18208
+ stage.on('mousemove' + this._manualHoverNamespace, this._manualHoverMoveHandler);
18209
+ stage.on('touchmove' + this._manualHoverNamespace, this._manualHoverMoveHandler);
18210
+ };
18211
+ SourceGroup.prototype._disableManualHoverTracking = function () {
18212
+ if (!this._manualHoverTrackingEnabled) {
18213
+ return;
18214
+ }
18215
+ var stage = this._group && this._group.getStage && this._group.getStage();
18216
+ if (stage && this._manualHoverNamespace) {
18217
+ stage.off(this._manualHoverNamespace);
18218
+ }
18219
+ this._manualHoverTrackingEnabled = false;
18220
+ this._manualHoverMoveHandler = null;
18221
+ this._manualHoverNamespace = null;
18222
+ };
18178
18223
  SourceGroup.prototype._onDragStart = function (element) {
18179
18224
  this._isDragged = true;
18180
18225
  this._layer.onSourcesGroupDragStart(element);
@@ -18226,7 +18271,7 @@ module.exports = function (WaveformBuilder, WaveformShape, Loader, Invoker, Util
18226
18271
  if (this._layer.manageSourceMovements([this._source], leftHandle ? start + diff + timeOffsetDiff : null, leftHandle ? null : end + diff + timeOffsetDiff)) {
18227
18272
  this._layer.batchDraw();
18228
18273
  }
18229
- }.bind(this));
18274
+ }.bind(this), null, false);
18230
18275
  return {
18231
18276
  x: draggedElement.absolutePosition().x,
18232
18277
  y: draggedElement.absolutePosition().y
@@ -18261,6 +18306,10 @@ module.exports = function (WaveformBuilder, WaveformShape, Loader, Invoker, Util
18261
18306
  this._updateLoadingOverlay();
18262
18307
  this.updatePreviews();
18263
18308
  }
18309
+ if (this._isDragged) {
18310
+ this.createDragGhost();
18311
+ this.updateDragGhost();
18312
+ }
18264
18313
  };
18265
18314
  SourceGroup.prototype.setWrapping = function (wrap, forceCreate, notify) {
18266
18315
  if (wrap) {
@@ -18610,6 +18659,7 @@ module.exports = function (WaveformBuilder, WaveformShape, Loader, Invoker, Util
18610
18659
  };
18611
18660
  SourceGroup.prototype.startHover = function () {
18612
18661
  this._manualHover = true;
18662
+ this._enableManualHoverTracking();
18613
18663
  this._group.fire('mouseenter', { evt: new MouseEvent('mouseenter') }, true);
18614
18664
  };
18615
18665
  SourceGroup.prototype.stopHover = function () {
@@ -18617,6 +18667,11 @@ module.exports = function (WaveformBuilder, WaveformShape, Loader, Invoker, Util
18617
18667
  };
18618
18668
  SourceGroup.prototype.setDragging = function (isDragging) {
18619
18669
  this._isDragged = isDragging;
18670
+ if (isDragging) {
18671
+ this.createDragGhost();
18672
+ } else {
18673
+ this.destroyDragGhost();
18674
+ }
18620
18675
  };
18621
18676
  SourceGroup.prototype.startDrag = function () {
18622
18677
  return this._group.startDrag();
@@ -18998,6 +19053,65 @@ module.exports = function (WaveformBuilder, WaveformShape, Loader, Invoker, Util
18998
19053
  SourceGroup.prototype.getCurrentHeight = function () {
18999
19054
  return this._height;
19000
19055
  };
19056
+ SourceGroup.prototype.createDragGhost = function () {
19057
+ if (this._dragGhost) {
19058
+ return this._dragGhost;
19059
+ }
19060
+ var frameOffset = this._view.getFrameOffset();
19061
+ var x = this._view.timeToPixels(this._source.startTime) - frameOffset;
19062
+ var width = this._view.timeToPixels(this._source.endTime - this._source.startTime);
19063
+ var height = this.getCurrentHeight();
19064
+ var y = this.getAbsoluteY();
19065
+ this._dragGhost = new Konva.Rect({
19066
+ x: x,
19067
+ y: y,
19068
+ width: width,
19069
+ height: height,
19070
+ fill: this._source.backgroundColor,
19071
+ opacity: 0.4,
19072
+ stroke: this._source.selectedBorderColor,
19073
+ strokeWidth: 2,
19074
+ dash: [
19075
+ 8,
19076
+ 4
19077
+ ],
19078
+ cornerRadius: 8,
19079
+ listening: false
19080
+ });
19081
+ this._layer.add(this._dragGhost);
19082
+ this._dragGhost.moveToBottom();
19083
+ this.updateDragGhost();
19084
+ return this._dragGhost;
19085
+ };
19086
+ SourceGroup.prototype.updateDragGhost = function (lineGroupsById) {
19087
+ if (!this._dragGhost) {
19088
+ return;
19089
+ }
19090
+ if (!lineGroupsById && this._layer && typeof this._layer.getLineGroups === 'function') {
19091
+ var lineGroups = this._layer.getLineGroups();
19092
+ if (lineGroups && typeof lineGroups.getLineGroupsById === 'function') {
19093
+ lineGroupsById = lineGroups.getLineGroupsById();
19094
+ }
19095
+ }
19096
+ var frameOffset = this._view.getFrameOffset();
19097
+ var x = this._view.timeToPixels(this._source.startTime) - frameOffset;
19098
+ var width = this._view.timeToPixels(this._source.endTime - this._source.startTime);
19099
+ this._dragGhost.x(x);
19100
+ this._dragGhost.width(width);
19101
+ this._dragGhost.height(this.getCurrentHeight());
19102
+ if (lineGroupsById) {
19103
+ var lineGroup = lineGroupsById[this._source.lineId];
19104
+ if (lineGroup) {
19105
+ this._dragGhost.y(lineGroup.y());
19106
+ }
19107
+ }
19108
+ };
19109
+ SourceGroup.prototype.destroyDragGhost = function () {
19110
+ if (this._dragGhost) {
19111
+ this._dragGhost.destroy();
19112
+ this._dragGhost = null;
19113
+ }
19114
+ };
19001
19115
  SourceGroup.prototype.getHeights = function () {
19002
19116
  return {
19003
19117
  unwrapped: this._unwrappedHeight,
@@ -19391,6 +19505,8 @@ module.exports = function (WaveformBuilder, WaveformShape, Loader, Invoker, Util
19391
19505
  return volumeGroup;
19392
19506
  };
19393
19507
  SourceGroup.prototype.destroy = function () {
19508
+ this.destroyDragGhost();
19509
+ this._disableManualHoverTracking();
19394
19510
  if (this._pendingIdleCallbacks) {
19395
19511
  this._pendingIdleCallbacks.forEach(function (id) {
19396
19512
  Utils.cancelIdle(id);
@@ -19432,10 +19548,11 @@ module.exports = function (SourceGroup, LineGroups, DataRetriever, Invoker, Util
19432
19548
  this._allowEditing = allowEditing;
19433
19549
  this._sourcesGroup = {};
19434
19550
  this._layer = new Konva.Layer();
19435
- this._dragLayer = new Konva.Layer();
19436
19551
  this._dataRetriever = new DataRetriever(peaks);
19437
19552
  this._lineGroups = new LineGroups(peaks, view, this);
19438
19553
  this._lineGroups.addToLayer(this);
19554
+ this._dragGroup = new Konva.Group({ listening: false });
19555
+ this._layer.add(this._dragGroup);
19439
19556
  this._loadedData = {};
19440
19557
  this._invoker = new Invoker();
19441
19558
  this._rescaleVersion = 0;
@@ -19454,7 +19571,7 @@ module.exports = function (SourceGroup, LineGroups, DataRetriever, Invoker, Util
19454
19571
  this._peaks.on('sources.delayedLineChange', this._onSourcesDelayedLineChanged.bind(this));
19455
19572
  }
19456
19573
  SourcesLayer.prototype._onSourcesDelayedLineChanged = function () {
19457
- if (this._dragGhosts && this._draggedElements && this._draggedElements.length > 0) {
19574
+ if (this._draggedElements && this._draggedElements.length > 0) {
19458
19575
  this._dragSourcesGroup();
19459
19576
  }
19460
19577
  };
@@ -19478,10 +19595,12 @@ module.exports = function (SourceGroup, LineGroups, DataRetriever, Invoker, Util
19478
19595
  };
19479
19596
  SourcesLayer.prototype.add = function (element) {
19480
19597
  this._layer.add(element);
19598
+ if (this._dragGroup) {
19599
+ this._dragGroup.moveToTop();
19600
+ }
19481
19601
  };
19482
19602
  SourcesLayer.prototype.addToStage = function (stage) {
19483
19603
  stage.add(this._layer);
19484
- stage.add(this._dragLayer);
19485
19604
  };
19486
19605
  SourcesLayer.prototype.enableEditing = function (enable) {
19487
19606
  this._allowEditing = enable;
@@ -19651,7 +19770,6 @@ module.exports = function (SourceGroup, LineGroups, DataRetriever, Invoker, Util
19651
19770
  draggable: true
19652
19771
  });
19653
19772
  var self = this;
19654
- this._dragGhosts = [];
19655
19773
  this._initialSourcePositions = {};
19656
19774
  this._draggedElements.forEach(function (source) {
19657
19775
  self._initialSourcePositions[source.id] = {
@@ -19663,29 +19781,16 @@ module.exports = function (SourceGroup, LineGroups, DataRetriever, Invoker, Util
19663
19781
  if (sourceGroup) {
19664
19782
  sourceGroup.setDragging(true);
19665
19783
  var absoluteY = sourceGroup.getAbsoluteY();
19666
- sourceGroup.moveTo(self._dragLayer);
19784
+ sourceGroup.moveTo(self._dragGroup);
19667
19785
  sourceGroup.y(absoluteY);
19668
- var ghost = self._createDragGhost(sourceGroup);
19669
- self._dragGhosts.push({
19670
- ghost: ghost,
19671
- sourceId: source.id
19672
- });
19673
19786
  }
19674
19787
  });
19675
19788
  };
19676
19789
  SourcesLayer.prototype.onSourcesGroupDragEnd = function () {
19677
- if (this._dragGhosts) {
19678
- this._dragGhosts.forEach(function (item) {
19679
- if (item.ghost) {
19680
- item.ghost.destroy();
19681
- }
19682
- });
19683
- this._dragGhosts = null;
19684
- }
19790
+ var self = this;
19685
19791
  this._initialSourcePositions = null;
19686
19792
  this._dragOffsetX = undefined;
19687
19793
  this._dragOffsetY = undefined;
19688
- var self = this;
19689
19794
  const updatedSources = this._draggedElements.map(function (source) {
19690
19795
  const sourceGroup = self._sourcesGroup[source.id];
19691
19796
  if (sourceGroup) {
@@ -19704,7 +19809,7 @@ module.exports = function (SourceGroup, LineGroups, DataRetriever, Invoker, Util
19704
19809
  };
19705
19810
  SourcesLayer.prototype.onSourcesGroupDrag = function (draggedElement) {
19706
19811
  var pointerPos = this._view.getPointerPosition();
19707
- this._view.updateWithAutoScroll(this._dragSourcesGroup.bind(this));
19812
+ this._view.updateWithAutoScroll(this._dragSourcesGroup.bind(this), null, true);
19708
19813
  var clickedSourceGroup = this._sourcesGroup[this._draggedElementId];
19709
19814
  if (clickedSourceGroup) {
19710
19815
  var mouseX = pointerPos.x;
@@ -19766,10 +19871,8 @@ module.exports = function (SourceGroup, LineGroups, DataRetriever, Invoker, Util
19766
19871
  var newStartTime = Utils.roundTime(initialStartTime + timeOffsetDiff + timeDiff);
19767
19872
  var newEndTime = Utils.roundTime(initialEndTime + timeOffsetDiff + timeDiff);
19768
19873
  const shouldRedraw = this.manageSourceMovements(this._draggedElements, newStartTime, newEndTime, orderable, mousePosX, mousePosY);
19769
- this._updateDragGhosts();
19770
19874
  if (shouldRedraw) {
19771
19875
  this.batchDraw();
19772
- this._dragLayer.batchDraw();
19773
19876
  }
19774
19877
  };
19775
19878
  SourcesLayer.prototype.findSources = function (startTime, endTime) {
@@ -19779,54 +19882,6 @@ module.exports = function (SourceGroup, LineGroups, DataRetriever, Invoker, Util
19779
19882
  return lineIds[source.lineId];
19780
19883
  });
19781
19884
  };
19782
- SourcesLayer.prototype._createDragGhost = function (sourceGroup) {
19783
- var source = sourceGroup.getSource();
19784
- var frameOffset = this._view.getFrameOffset();
19785
- var x = this._view.timeToPixels(source.startTime) - frameOffset;
19786
- var width = this._view.timeToPixels(source.endTime - source.startTime);
19787
- var height = sourceGroup.getCurrentHeight();
19788
- var y = sourceGroup.getAbsoluteY();
19789
- var ghost = new Konva.Rect({
19790
- x: x,
19791
- y: y,
19792
- width: width,
19793
- height: height,
19794
- fill: source.backgroundColor,
19795
- opacity: 0.4,
19796
- stroke: source.selectedBorderColor,
19797
- strokeWidth: 2,
19798
- dash: [
19799
- 8,
19800
- 4
19801
- ],
19802
- cornerRadius: 8,
19803
- listening: false
19804
- });
19805
- this._layer.add(ghost);
19806
- ghost.moveToBottom();
19807
- return ghost;
19808
- };
19809
- SourcesLayer.prototype._updateDragGhosts = function () {
19810
- if (!this._dragGhosts) {
19811
- return;
19812
- }
19813
- var self = this;
19814
- var frameOffset = this._view.getFrameOffset();
19815
- var lineGroupsById = this._lineGroups.getLineGroupsById();
19816
- this._dragGhosts.forEach(function (item) {
19817
- var sourceGroup = self._sourcesGroup[item.sourceId];
19818
- if (!sourceGroup || !item.ghost) {
19819
- return;
19820
- }
19821
- var sourceData = sourceGroup.getSource();
19822
- var x = self._view.timeToPixels(sourceData.startTime) - frameOffset;
19823
- item.ghost.x(x);
19824
- var lineGroup = lineGroupsById[sourceData.lineId];
19825
- if (lineGroup) {
19826
- item.ghost.y(lineGroup.y());
19827
- }
19828
- });
19829
- };
19830
19885
  SourcesLayer.prototype._updateSourceTimesDuringDrag = function (newStartTime) {
19831
19886
  if (!this._initialSourcePositions || !this._draggedElements) {
19832
19887
  return;
@@ -19919,13 +19974,8 @@ module.exports = function (SourceGroup, LineGroups, DataRetriever, Invoker, Util
19919
19974
  if (isDraggedSource) {
19920
19975
  sourceGroup.setDragging(true);
19921
19976
  var absoluteY = sourceGroup.getAbsoluteY();
19922
- sourceGroup.moveTo(this._dragLayer);
19977
+ sourceGroup.moveTo(this._dragGroup);
19923
19978
  sourceGroup.y(absoluteY);
19924
- var ghost = this._createDragGhost(sourceGroup);
19925
- this._dragGhosts.push({
19926
- ghost: ghost,
19927
- sourceId: source.id
19928
- });
19929
19979
  }
19930
19980
  }
19931
19981
  return sourceGroup;
@@ -23153,48 +23203,90 @@ module.exports = function (MouseDragHandler, PlayheadLayer, SourcesLayer, ModeLa
23153
23203
  View.prototype.getSelectedElements = function () {
23154
23204
  return Object.values(this._modeLayer.getSelectedElements());
23155
23205
  };
23156
- View.prototype.updateWithAutoScroll = function (updateWhileScrolling, updateWhileNotScrolling) {
23206
+ View.prototype.updateWithAutoScroll = function (updateWhileScrolling, updateWhileNotScrolling, enableVerticalAutoScroll) {
23157
23207
  var self = this;
23158
23208
  var pointer = this.getPointerPosition();
23159
23209
  var pointerX = pointer ? pointer.x : null;
23210
+ var pointerY = pointer ? pointer.y : null;
23160
23211
  var viewWidth = this.getWidth();
23212
+ var viewHeight = this.getHeight();
23161
23213
  var thresholdPx = Math.round(this._peaks.options.autoScrollThreshold * viewWidth);
23214
+ var thresholdPy = Math.round(this._peaks.options.autoScrollThreshold * viewHeight);
23162
23215
  var MAX_AUTO_SCROLL_PX_PER_FRAME = 30;
23163
23216
  var NOMINAL_FRAME_MS = 16.67;
23164
- function getAutoScrollVelocity(pointerXValue) {
23165
- if (typeof pointerXValue !== 'number' || thresholdPx <= 0) {
23217
+ function getAutoScrollVelocity(pointerValue, threshold, size) {
23218
+ if (typeof pointerValue !== 'number' || threshold <= 0 || size <= 0) {
23166
23219
  return 0;
23167
23220
  }
23168
- if (pointerXValue < thresholdPx) {
23169
- return Math.round(-MAX_AUTO_SCROLL_PX_PER_FRAME * Math.min(1, (thresholdPx - pointerXValue) / thresholdPx));
23221
+ if (pointerValue < threshold) {
23222
+ return Math.round(-MAX_AUTO_SCROLL_PX_PER_FRAME * Math.min(1, (threshold - pointerValue) / threshold));
23170
23223
  }
23171
- if (pointerXValue > viewWidth - thresholdPx) {
23172
- return Math.round(MAX_AUTO_SCROLL_PX_PER_FRAME * Math.min(1, (pointerXValue - (viewWidth - thresholdPx)) / thresholdPx));
23224
+ if (pointerValue > size - threshold) {
23225
+ return Math.round(MAX_AUTO_SCROLL_PX_PER_FRAME * Math.min(1, (pointerValue - (size - threshold)) / threshold));
23173
23226
  }
23174
23227
  return 0;
23175
23228
  }
23176
- var velocityPxPerFrame = getAutoScrollVelocity(pointerX);
23177
- var canScroll = velocityPxPerFrame > 0 || velocityPxPerFrame < 0 && self.getFrameOffset() > 0;
23178
- this._limited = velocityPxPerFrame;
23179
- if (velocityPxPerFrame !== 0 && canScroll) {
23229
+ var velocityXPerFrame = getAutoScrollVelocity(pointerX, thresholdPx, viewWidth);
23230
+ var verticalScrollingEnabled = Boolean(enableVerticalAutoScroll && this._peaks.options.enableVerticalScrolling);
23231
+ var maxFrameOffsetY = 0;
23232
+ if (verticalScrollingEnabled) {
23233
+ maxFrameOffsetY = this.getFullHeight() - viewHeight;
23234
+ if (!Number.isFinite(maxFrameOffsetY) || maxFrameOffsetY < 0) {
23235
+ maxFrameOffsetY = 0;
23236
+ }
23237
+ }
23238
+ var velocityYPerFrame = verticalScrollingEnabled && maxFrameOffsetY > 0 ? getAutoScrollVelocity(pointerY, thresholdPy, viewHeight) : 0;
23239
+ var canScrollX = velocityXPerFrame > 0 || velocityXPerFrame < 0 && self.getFrameOffset() > 0;
23240
+ var canScrollY = verticalScrollingEnabled && maxFrameOffsetY > 0 && (velocityYPerFrame > 0 && self.getFrameOffsetY() < maxFrameOffsetY || velocityYPerFrame < 0 && self.getFrameOffsetY() > 0);
23241
+ this._autoScrollVelocityX = velocityXPerFrame;
23242
+ this._autoScrollVelocityY = velocityYPerFrame;
23243
+ if (velocityXPerFrame !== 0 && canScrollX || velocityYPerFrame !== 0 && canScrollY) {
23180
23244
  if (!this._scrollingRafId) {
23181
23245
  var lastTime = performance.now();
23182
23246
  function scrollFrame(currentTime) {
23183
23247
  if (!self._scrollingRafId) {
23184
23248
  return;
23185
23249
  }
23250
+ var xVel = self._autoScrollVelocityX || 0;
23251
+ var yVel = self._autoScrollVelocityY || 0;
23252
+ var canContinueX = xVel > 0 || xVel < 0 && self.getFrameOffset() > 0;
23253
+ var maxY = 0;
23254
+ var canContinueY = false;
23255
+ if (verticalScrollingEnabled) {
23256
+ maxY = self.getFullHeight() - self.getHeight();
23257
+ if (!Number.isFinite(maxY) || maxY < 0) {
23258
+ maxY = 0;
23259
+ }
23260
+ canContinueY = maxY > 0 && (yVel > 0 && self.getFrameOffsetY() < maxY || yVel < 0 && self.getFrameOffsetY() > 0);
23261
+ }
23262
+ if ((xVel === 0 || !canContinueX) && (yVel === 0 || !canContinueY)) {
23263
+ self.stopAutoScroll();
23264
+ updateWhileScrolling();
23265
+ return;
23266
+ }
23186
23267
  var deltaTime = currentTime - lastTime;
23187
- var scrollAmount = Math.round(self._limited * deltaTime / NOMINAL_FRAME_MS);
23268
+ var scrollAmountX = Math.round(xVel * deltaTime / NOMINAL_FRAME_MS);
23269
+ var scrollAmountY = Math.round(yVel * deltaTime / NOMINAL_FRAME_MS);
23188
23270
  lastTime = currentTime;
23189
- var newOffset = self.getFrameOffset() + scrollAmount;
23190
- if (newOffset < 0) {
23191
- self.updateTimeline(0);
23192
- self._scrollingRafId = null;
23271
+ var newOffsetX = self.getFrameOffset() + scrollAmountX;
23272
+ var newOffsetY = self.getFrameOffsetY() + scrollAmountY;
23273
+ if (newOffsetX < 0) {
23274
+ newOffsetX = 0;
23275
+ }
23276
+ if (verticalScrollingEnabled) {
23277
+ if (newOffsetY < 0) {
23278
+ newOffsetY = 0;
23279
+ } else if (newOffsetY > maxY) {
23280
+ newOffsetY = maxY;
23281
+ }
23282
+ }
23283
+ if (!verticalScrollingEnabled) {
23284
+ self.updateTimeline(newOffsetX);
23193
23285
  } else {
23194
- self.updateTimeline(newOffset);
23195
- updateWhileScrolling();
23196
- self._scrollingRafId = requestAnimationFrame(scrollFrame);
23286
+ self.updateTimeline(newOffsetX, newOffsetY);
23197
23287
  }
23288
+ updateWhileScrolling();
23289
+ self._scrollingRafId = requestAnimationFrame(scrollFrame);
23198
23290
  }
23199
23291
  self._scrollingRafId = requestAnimationFrame(scrollFrame);
23200
23292
  }