@checksub_team/peaks_timeline 2.4.0 → 2.5.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
@@ -15410,6 +15410,12 @@ module.exports = function (SourceGroup, Utils, Konva) {
15410
15410
  }
15411
15411
  return sources;
15412
15412
  };
15413
+ LineGroup.prototype.getSegmentsAfter = function (time) {
15414
+ if (!this.isSegmentsLine()) {
15415
+ return [];
15416
+ }
15417
+ return this._segmentsGroup.getSegmentsAfter(time);
15418
+ };
15413
15419
  LineGroup.prototype.getSourcesAround = function (time) {
15414
15420
  var left = null;
15415
15421
  var right = null;
@@ -15571,8 +15577,12 @@ module.exports = function (SegmentsGroup, LineGroup, LineIndicator, Utils) {
15571
15577
  LineGroups.prototype._onSegmentsUpdate = function (segment) {
15572
15578
  this._segmentsGroups[segment.line].onSegmentsUpdate(segment);
15573
15579
  };
15574
- LineGroups.prototype._onSegmentUpdated = function (segment) {
15575
- this._segmentsGroups[segment.line].onSegmentUpdated();
15580
+ LineGroups.prototype._onSegmentUpdated = function () {
15581
+ for (var lineId in this._segmentsGroups) {
15582
+ if (Utils.objectHasProperty(this._segmentsGroups, lineId) && this._segmentsGroups[lineId].hasUpdatedSegments()) {
15583
+ this._segmentsGroups[lineId].onSegmentUpdated();
15584
+ }
15585
+ }
15576
15586
  };
15577
15587
  LineGroups.prototype._onSegmentsRemove = function (segments) {
15578
15588
  var self = this;
@@ -15654,6 +15664,13 @@ module.exports = function (SegmentsGroup, LineGroup, LineIndicator, Utils) {
15654
15664
  LineGroups.prototype.getSourcesOnLineAfter = function (lineId, time) {
15655
15665
  return this._lineGroupsById[lineId].getSourcesAfter(time);
15656
15666
  };
15667
+ LineGroups.prototype.getSegmentsOnLineAfter = function (lineId, time) {
15668
+ const lineGroup = this._lineGroupsById[lineId] || this._segmentsGroupToLine[lineId];
15669
+ if (!lineGroup) {
15670
+ return [];
15671
+ }
15672
+ return lineGroup.getSegmentsAfter(time);
15673
+ };
15657
15674
  LineGroups.prototype.getSegmentsGroups = function () {
15658
15675
  return this._segmentsGroups;
15659
15676
  };
@@ -16587,11 +16604,8 @@ module.exports = function (SourceGroup, Invoker, Source, Utils, Konva) {
16587
16604
  ModeLayer.prototype._onMouseClickInDefaultMode = function () {
16588
16605
  const hoveredKonvaElement = this._view.getHoveredElement();
16589
16606
  if (hoveredKonvaElement) {
16590
- if (hoveredKonvaElement instanceof SourceGroup) {
16591
- this.selectElements([hoveredKonvaElement.getSource()], true);
16592
- } else {
16593
- this.selectElements([hoveredKonvaElement.getSegment()], true);
16594
- }
16607
+ const element = hoveredKonvaElement instanceof SourceGroup ? hoveredKonvaElement.getSource() : hoveredKonvaElement.getSegment();
16608
+ this.selectElements([element], true);
16595
16609
  } else {
16596
16610
  this.deselectDifference([], true);
16597
16611
  this._view.batchDrawSourcesLayer();
@@ -17175,28 +17189,8 @@ module.exports = function (Konva) {
17175
17189
  });
17176
17190
  }
17177
17191
  };
17178
- SegmentMarker.prototype._dragBoundFunc = function (pos) {
17179
- if (this._startMarker) {
17180
- var newStartX;
17181
- if (this._segment.duration) {
17182
- newStartX = Math.max(pos.x + this._view.getFrameOffset(), this._view.timeToPixels(this._segment.endTime - this._segment.duration));
17183
- } else {
17184
- newStartX = pos.x + this._view.getFrameOffset();
17185
- }
17186
- this._segmentShape.getSegmentsGroup().updateSegment(this._segment, newStartX, null);
17187
- } else {
17188
- var newEndX;
17189
- if (this._segment.duration) {
17190
- newEndX = Math.min(pos.x + this._view.getFrameOffset() + this._marker.getHandleWidth(), this._view.timeToPixels(this._segment.startTime + this._segment.duration));
17191
- } else {
17192
- newEndX = pos.x + this._view.getFrameOffset() + this._marker.getHandleWidth();
17193
- }
17194
- this._segmentShape.getSegmentsGroup().updateSegment(this._segment, null, newEndX);
17195
- }
17196
- return {
17197
- x: this._group.getAbsolutePosition().x,
17198
- y: this._group.getAbsolutePosition().y
17199
- };
17192
+ SegmentMarker.prototype._dragBoundFunc = function () {
17193
+ return this._view._sourcesLayer.onSegmentHandleDrag(this);
17200
17194
  };
17201
17195
  SegmentMarker.prototype.moveTo = function (group) {
17202
17196
  this._group.moveTo(group);
@@ -17207,6 +17201,9 @@ module.exports = function (Konva) {
17207
17201
  SegmentMarker.prototype.getX = function () {
17208
17202
  return this._group.getX();
17209
17203
  };
17204
+ SegmentMarker.prototype.getAbsolutePosition = function () {
17205
+ return this._group.getAbsolutePosition();
17206
+ };
17210
17207
  SegmentMarker.prototype.getWidth = function () {
17211
17208
  return this._group.getWidth();
17212
17209
  };
@@ -17222,6 +17219,9 @@ module.exports = function (Konva) {
17222
17219
  SegmentMarker.prototype.setX = function (x) {
17223
17220
  this._group.setX(x);
17224
17221
  };
17222
+ SegmentMarker.prototype.stopDrag = function () {
17223
+ this._group.stopDrag();
17224
+ };
17225
17225
  SegmentMarker.prototype.timeUpdated = function (time) {
17226
17226
  if (this._marker.timeUpdated) {
17227
17227
  this._marker.timeUpdated(time);
@@ -17297,37 +17297,68 @@ module.exports = function (Konva, SegmentMarker, Utils) {
17297
17297
  this._onSegmentHandleDrag = this._onSegmentHandleDrag.bind(this);
17298
17298
  this._onSegmentHandleDragStart = this._onSegmentHandleDragStart.bind(this);
17299
17299
  this._onSegmentHandleDragEnd = this._onSegmentHandleDragEnd.bind(this);
17300
- this._label = this._peaks.options.createSegmentLabel({
17301
- x: this._view.timeToPixels(segment.startTime),
17302
- y: this._segmentY,
17303
- width: this._view.timeToPixels(this._segment.endTime - this._segment.startTime),
17304
- height: this._segmentHeight,
17305
- segment: segment,
17306
- view: this._view.getName(),
17307
- group: this._group,
17308
- fontSize: 12
17309
- });
17300
+ this._createLabel();
17310
17301
  this._createMarkers();
17311
17302
  this._indicatorsGroup = new Konva.Group();
17312
17303
  this._shapeGroup.add(this._indicatorsGroup);
17313
17304
  this.createIndicators();
17314
17305
  }
17315
17306
  SegmentShape.prototype._onShapeGroupDrag = function (draggedElement) {
17316
- const diff = this._view.getPointerPosition().x - this._mouseDownX;
17317
- this._group.updateSegment(this._segment, this._initialStartPixel + diff, this._initialEndPixel + diff);
17318
- this._startMarker.timeUpdated(this._segment.startTime);
17319
- this._endMarker.timeUpdated(this._segment.endTime);
17320
- return {
17321
- x: draggedElement.absolutePosition().x,
17322
- y: draggedElement.absolutePosition().y
17323
- };
17307
+ return this._view._sourcesLayer.onSegmentDrag(draggedElement);
17324
17308
  };
17325
17309
  SegmentShape.prototype._cornerRadius = function () {
17326
17310
  return !Utils.isNullOrUndefined(this._segment.borderRadius) ? this._segment.borderRadius : SEGMENT_CORNER_RADIUS;
17327
17311
  };
17312
+ SegmentShape.prototype._createLabel = function () {
17313
+ this._label = this._peaks.options.createSegmentLabel({
17314
+ x: this._view.timeToPixels(this._segment.startTime),
17315
+ y: this._segmentY,
17316
+ width: this._view.timeToPixels(this._segment.endTime - this._segment.startTime),
17317
+ height: this._segmentHeight,
17318
+ segment: this._segment,
17319
+ view: this._view.getName(),
17320
+ group: this._group,
17321
+ fontSize: 12
17322
+ });
17323
+ };
17324
+ SegmentShape.prototype._rebuildSelectionDependentNodes = function () {
17325
+ var group = this._shapeGroup.getParent();
17326
+ if (this._label) {
17327
+ this._label.destroy();
17328
+ this._label = null;
17329
+ }
17330
+ if (this._startMarker) {
17331
+ this._startMarker.destroy();
17332
+ this._startMarker = null;
17333
+ }
17334
+ if (this._endMarker) {
17335
+ this._endMarker.destroy();
17336
+ this._endMarker = null;
17337
+ }
17338
+ this._createLabel();
17339
+ this._createMarkers();
17340
+ if (group) {
17341
+ if (this._label) {
17342
+ this._label.moveTo(group);
17343
+ }
17344
+ if (this._startMarker) {
17345
+ this._startMarker.moveTo(group);
17346
+ }
17347
+ if (this._endMarker) {
17348
+ this._endMarker.moveTo(group);
17349
+ }
17350
+ }
17351
+ };
17328
17352
  SegmentShape.prototype.update = function () {
17329
- var startPixel = this._view.timeToPixels(this._segment.startTime);
17330
- var endPixel = this._view.timeToPixels(this._segment.endTime);
17353
+ this._applyDisplayTimes(this._segment.startTime, this._segment.endTime);
17354
+ };
17355
+ SegmentShape.prototype.setSelected = function () {
17356
+ this._rebuildSelectionDependentNodes();
17357
+ this.update();
17358
+ };
17359
+ SegmentShape.prototype._applyDisplayTimes = function (startTime, endTime) {
17360
+ var startPixel = this._view.timeToPixels(startTime);
17361
+ var endPixel = this._view.timeToPixels(endTime);
17331
17362
  var frameOffset = this._view.timeToPixels(this._view.getTimeOffset());
17332
17363
  this._shapeGroup.x(startPixel - frameOffset);
17333
17364
  this._segmentWidth = endPixel - startPixel;
@@ -17351,11 +17382,11 @@ module.exports = function (Konva, SegmentMarker, Utils) {
17351
17382
  }
17352
17383
  if (this._startMarker) {
17353
17384
  this._startMarker.setX(startPixel - frameOffset);
17354
- this._startMarker.timeUpdated(this._segment.startTime);
17385
+ this._startMarker.timeUpdated(startTime);
17355
17386
  }
17356
17387
  if (this._endMarker) {
17357
17388
  this._endMarker.setX(endPixel - this._endMarker.getHandleWidth() - frameOffset);
17358
- this._endMarker.timeUpdated(this._segment.endTime);
17389
+ this._endMarker.timeUpdated(endTime);
17359
17390
  }
17360
17391
  if (this._label) {
17361
17392
  this._label.setX(startPixel - frameOffset);
@@ -17380,6 +17411,9 @@ module.exports = function (Konva, SegmentMarker, Utils) {
17380
17411
  SegmentShape.prototype.getEndMarker = function () {
17381
17412
  return this._endMarker;
17382
17413
  };
17414
+ SegmentShape.prototype.stopDrag = function () {
17415
+ this._shapeGroup.stopDrag();
17416
+ };
17383
17417
  SegmentShape.prototype.moveTo = function (group, segmentsGroup) {
17384
17418
  if (segmentsGroup) {
17385
17419
  this._segmentsGroup = segmentsGroup;
@@ -17529,27 +17563,20 @@ module.exports = function (Konva, SegmentMarker, Utils) {
17529
17563
  };
17530
17564
  SegmentShape.prototype._onSegmentDragStart = function () {
17531
17565
  this._view.setCursor('grab');
17532
- this._mouseDownX = this._view.getPointerPosition().x;
17533
- this._initialStartTime = this._segment.startTime;
17534
- this._initialStartPixel = this._view.timeToPixels(this._initialStartTime);
17535
- this._initialEndTime = this._segment.endTime;
17536
- this._initialEndPixel = this._view.timeToPixels(this._initialEndTime);
17537
- this._peaks.emit('segments.dragstart', this._segment);
17566
+ this._view._sourcesLayer.onSegmentDragStart(this);
17538
17567
  };
17539
17568
  SegmentShape.prototype._onSegmentDragEnd = function () {
17540
17569
  this._view.setCursor('pointer');
17541
- this._peaks.emit('segments.dragend', this._segment);
17570
+ this._view._sourcesLayer.onSegmentDragEnd(this);
17542
17571
  };
17543
17572
  SegmentShape.prototype._onSegmentHandleDrag = function () {
17544
17573
  this._peaks.emit('segments.dragged');
17545
17574
  };
17546
17575
  SegmentShape.prototype._onSegmentHandleDragStart = function (segmentMarker) {
17547
- var startMarker = segmentMarker.isStartMarker();
17548
- this._peaks.emit('segments.dragstart', this._segment, startMarker);
17576
+ this._view._sourcesLayer.onSegmentHandleDragStart(segmentMarker);
17549
17577
  };
17550
17578
  SegmentShape.prototype._onSegmentHandleDragEnd = function (segmentMarker) {
17551
- var startMarker = segmentMarker.isStartMarker();
17552
- this._peaks.emit('segments.dragend', this._segment, startMarker);
17579
+ this._view._sourcesLayer.onSegmentHandleDragEnd(segmentMarker);
17553
17580
  };
17554
17581
  SegmentShape.prototype.fitToView = function () {
17555
17582
  if (this._startMarker) {
@@ -17835,6 +17862,23 @@ module.exports = function (SegmentShape, Utils, Konva) {
17835
17862
  }
17836
17863
  return visibleSegments;
17837
17864
  };
17865
+ SegmentsGroup.prototype.getSegmentsAfter = function (time) {
17866
+ const segments = [];
17867
+ var currentId = this._firstSegmentId;
17868
+ while (currentId) {
17869
+ var segmentData = this._segments[currentId];
17870
+ if (segmentData.segment.startTime >= time) {
17871
+ while (currentId) {
17872
+ segmentData = this._segments[currentId];
17873
+ segments.push(segmentData.segment);
17874
+ currentId = segmentData.nextSegmentId;
17875
+ }
17876
+ break;
17877
+ }
17878
+ currentId = segmentData.nextSegmentId;
17879
+ }
17880
+ return segments;
17881
+ };
17838
17882
  SegmentsGroup.prototype._draw = function () {
17839
17883
  this._view.batchDrawSourcesLayer();
17840
17884
  };
@@ -17904,6 +17948,9 @@ module.exports = function (SegmentShape, Utils, Konva) {
17904
17948
  SegmentsGroup.prototype.isMagnetized = function () {
17905
17949
  return this._isMagnetized;
17906
17950
  };
17951
+ SegmentsGroup.prototype.markSegmentsUpdated = function (segments) {
17952
+ segments.forEach(this.addToUpdatedSegments.bind(this));
17953
+ };
17907
17954
  SegmentsGroup.prototype.setIndicators = function (segment) {
17908
17955
  var segmentShape = this._segmentShapes[segment.id];
17909
17956
  if (segmentShape) {
@@ -17911,23 +17958,98 @@ module.exports = function (SegmentShape, Utils, Konva) {
17911
17958
  this._draw();
17912
17959
  }
17913
17960
  };
17961
+ SegmentsGroup.prototype.setSelected = function (segment) {
17962
+ var segmentShape = this._segmentShapes[segment.id];
17963
+ if (segmentShape) {
17964
+ segmentShape.setSelected();
17965
+ this._draw();
17966
+ }
17967
+ };
17914
17968
  SegmentsGroup.prototype.addToUpdatedSegments = function (segment) {
17915
17969
  if (this._updatedSegments.indexOf(segment) === -1) {
17916
17970
  this._updatedSegments.push(segment);
17917
17971
  }
17918
17972
  };
17919
- SegmentsGroup.prototype.updateSegment = function (segment, newStartX, newEndX) {
17973
+ SegmentsGroup.prototype.hasUpdatedSegments = function () {
17974
+ return this._updatedSegments.length > 0;
17975
+ };
17976
+ SegmentsGroup.prototype.getSegmentsDragTimeLimits = function (segments, initialPositions) {
17977
+ var selectedIds = {};
17978
+ var minTimeOffset = -Infinity;
17979
+ var maxTimeOffset = Infinity;
17980
+ segments.forEach(function (segment) {
17981
+ selectedIds[segment.id] = true;
17982
+ });
17983
+ segments.forEach(function (segment) {
17984
+ var segmentData = this._segments[segment.id];
17985
+ var initialPosition = initialPositions[segment.id];
17986
+ var previousSegmentId = segmentData.prevSegmentId;
17987
+ var nextSegmentId = segmentData.nextSegmentId;
17988
+ while (previousSegmentId && selectedIds[previousSegmentId]) {
17989
+ previousSegmentId = this._segments[previousSegmentId].prevSegmentId;
17990
+ }
17991
+ while (nextSegmentId && selectedIds[nextSegmentId]) {
17992
+ nextSegmentId = this._segments[nextSegmentId].nextSegmentId;
17993
+ }
17994
+ if (previousSegmentId) {
17995
+ minTimeOffset = Math.max(minTimeOffset, this._segments[previousSegmentId].segment.endTime - initialPosition.startTime);
17996
+ } else {
17997
+ minTimeOffset = Math.max(minTimeOffset, -initialPosition.startTime);
17998
+ }
17999
+ if (nextSegmentId) {
18000
+ maxTimeOffset = Math.min(maxTimeOffset, this._segments[nextSegmentId].segment.startTime - initialPosition.endTime);
18001
+ }
18002
+ }.bind(this));
18003
+ return {
18004
+ minTimeOffset: minTimeOffset,
18005
+ maxTimeOffset: maxTimeOffset
18006
+ };
18007
+ };
18008
+ SegmentsGroup.prototype.dragSegmentsByTimeOffset = function (segments, initialPositions, timeOffset) {
18009
+ var hasChanges = false;
18010
+ segments.forEach(function (segment) {
18011
+ var initialPosition = initialPositions[segment.id];
18012
+ var newStartTime = Utils.roundTime(initialPosition.startTime + timeOffset);
18013
+ var newEndTime = Utils.roundTime(initialPosition.endTime + timeOffset);
18014
+ if (segment.startTime !== newStartTime || segment.endTime !== newEndTime) {
18015
+ segment.updateTimes(newStartTime, newEndTime);
18016
+ hasChanges = true;
18017
+ }
18018
+ });
18019
+ if (hasChanges) {
18020
+ this._updateVisibleSegmentsInView();
18021
+ }
18022
+ };
18023
+ SegmentsGroup.prototype._getVisibleTimeRange = function () {
18024
+ var frameOffset = this._view.getFrameOffset();
18025
+ var width = this._view.getWidth();
18026
+ return {
18027
+ startTime: this._view.pixelsToTime(frameOffset),
18028
+ endTime: this._view.pixelsToTime(frameOffset + width)
18029
+ };
18030
+ };
18031
+ SegmentsGroup.prototype._updateVisibleSegmentsInView = function () {
18032
+ var visibleTimeRange = this._getVisibleTimeRange();
18033
+ this.find(visibleTimeRange.startTime, visibleTimeRange.endTime).forEach(this._updateSegment.bind(this));
18034
+ this._removeInvisibleSegments(visibleTimeRange.startTime, visibleTimeRange.endTime);
18035
+ };
18036
+ SegmentsGroup.prototype.updateSegment = function (segment, newStartX, newEndX, shouldDraw) {
17920
18037
  var newXs = this.manageCollision(segment, newStartX, newEndX);
18038
+ if (Utils.isNullOrUndefined(shouldDraw)) {
18039
+ shouldDraw = true;
18040
+ }
17921
18041
  if (!Utils.isNullOrUndefined(newXs.startX)) {
17922
- segment.startTime = this._view.pixelsToTime(newXs.startX);
18042
+ segment.updateTimes(this._view.pixelsToTime(newXs.startX), null);
17923
18043
  }
17924
18044
  if (!Utils.isNullOrUndefined(newXs.endX)) {
17925
- segment.endTime = this._view.pixelsToTime(newXs.endX);
18045
+ segment.updateTimes(null, this._view.pixelsToTime(newXs.endX));
17926
18046
  }
17927
18047
  if (newXs) {
17928
18048
  this._updateSegment(segment);
17929
18049
  this.addToUpdatedSegments(segment);
17930
- this._draw();
18050
+ if (shouldDraw) {
18051
+ this._draw();
18052
+ }
17931
18053
  }
17932
18054
  };
17933
18055
  SegmentsGroup.prototype.manageCollision = function (segment, newStartX, newEndX) {
@@ -18303,20 +18425,7 @@ module.exports = function (WaveformBuilder, WaveformShape, Loader, Invoker, Util
18303
18425
  this._rightHandle.x(this._width - handleWidth);
18304
18426
  };
18305
18427
  SourceGroup.prototype._onSourceGroupHandleDrag = function (draggedElement, leftHandle) {
18306
- const {start, end} = this._initialTimes;
18307
- this._view.updateWithAutoScroll(function () {
18308
- var pointer = this._view.getPointerPosition();
18309
- var pointerX = pointer ? pointer.x : this._mouseDownX;
18310
- const diff = this._view.pixelsToTime(pointerX - this._mouseDownX);
18311
- const timeOffsetDiff = this._view.getTimeOffset() - this._initialTimeOffset;
18312
- if (this._layer.manageSourceMovements([this._source], leftHandle ? start + diff + timeOffsetDiff : null, leftHandle ? null : end + diff + timeOffsetDiff)) {
18313
- this._layer.batchDraw();
18314
- }
18315
- }.bind(this), null, false);
18316
- return {
18317
- x: draggedElement.absolutePosition().x,
18318
- y: draggedElement.absolutePosition().y
18319
- };
18428
+ return this._layer.onSourceHandleDrag(draggedElement, leftHandle);
18320
18429
  };
18321
18430
  SourceGroup.prototype.update = function () {
18322
18431
  const startPixel = this._view.timeToPixels(this._source.startTime);
@@ -18376,20 +18485,15 @@ module.exports = function (WaveformBuilder, WaveformShape, Loader, Invoker, Util
18376
18485
  this._rightHandle.height(this._unwrappedHeight);
18377
18486
  }
18378
18487
  };
18379
- SourceGroup.prototype._onHandleDragStart = function () {
18380
- this._initialTimeOffset = this._view.getTimeOffset();
18381
- this._mouseDownX = this._view.getPointerPosition().x;
18382
- this._initialTimes = {
18383
- start: this._source.startTime,
18384
- end: this._source.endTime
18385
- };
18488
+ SourceGroup.prototype._onHandleDragStart = function (leftHandle) {
18386
18489
  this._isHandleDragged = true;
18387
18490
  this._hideButtons();
18491
+ this._layer.onSourceHandleDragStart(this, leftHandle);
18388
18492
  };
18389
18493
  SourceGroup.prototype._onHandleDragEnd = function () {
18390
18494
  this._isHandleDragged = false;
18391
18495
  this._showButtons();
18392
- this._layer.processSourceUpdates([this._source]);
18496
+ this._layer.onSourceHandleDragEnd(this);
18393
18497
  };
18394
18498
  SourceGroup.prototype._addHandles = function (forceCreate) {
18395
18499
  var self = this;
@@ -18407,7 +18511,7 @@ module.exports = function (WaveformBuilder, WaveformShape, Loader, Invoker, Util
18407
18511
  });
18408
18512
  this._leftHandle.on('dragstart', function (event) {
18409
18513
  event.cancelBubble = true;
18410
- self._onHandleDragStart(event);
18514
+ self._onHandleDragStart(true);
18411
18515
  });
18412
18516
  this._leftHandle.on('dragend', function (event) {
18413
18517
  event.cancelBubble = true;
@@ -18435,7 +18539,7 @@ module.exports = function (WaveformBuilder, WaveformShape, Loader, Invoker, Util
18435
18539
  });
18436
18540
  this._rightHandle.on('dragstart', function (event) {
18437
18541
  event.cancelBubble = true;
18438
- self._onHandleDragStart(event);
18542
+ self._onHandleDragStart(false);
18439
18543
  });
18440
18544
  this._rightHandle.on('dragend', function (event) {
18441
18545
  event.cancelBubble = true;
@@ -19877,11 +19981,14 @@ module.exports = function (SourceGroup, LineGroups, DataRetriever, Invoker, Util
19877
19981
  this._throttledBatchDraw = this._invoker.throttleTrailing(this._layer.batchDraw.bind(this._layer));
19878
19982
  this._drawPending = false;
19879
19983
  this._suppressDragLifecycleForSourceId = null;
19984
+ this._sourceHandleDragSession = null;
19985
+ this._segmentDragSession = null;
19880
19986
  this._peaks.on('handler.sources.add', this._onSourcesAdd.bind(this));
19881
19987
  this._peaks.on('handler.sources.destroy', this._onSourcesDestroy.bind(this));
19882
19988
  this._peaks.on('handler.sources.show', this._onSourcesShow.bind(this));
19883
19989
  this._peaks.on('handler.sources.hide', this._onSourcesHide.bind(this));
19884
19990
  this._peaks.on('sources.setSelected', this._onSourcesSetSelected.bind(this));
19991
+ this._peaks.on('segments.setSelected', this._onSegmentsSetSelected.bind(this));
19885
19992
  this._peaks.on('model.source.update', this._onSourceUpdate.bind(this));
19886
19993
  this._peaks.on('data.retrieved', this._onDataRetrieved.bind(this));
19887
19994
  this._peaks.on('handler.segments.show', this._onSegmentsShow.bind(this));
@@ -19899,6 +20006,9 @@ module.exports = function (SourceGroup, LineGroups, DataRetriever, Invoker, Util
19899
20006
  if (draggedSourceGroup) {
19900
20007
  draggedSourceGroup.stopDrag();
19901
20008
  }
20009
+ if (this._segmentDragSession && this._segmentDragSession.draggedNode) {
20010
+ this._segmentDragSession.draggedNode.stopDrag();
20011
+ }
19902
20012
  };
19903
20013
  SourcesLayer.prototype.fitToView = function () {
19904
20014
  this._lineGroups.fitToView();
@@ -19912,6 +20022,9 @@ module.exports = function (SourceGroup, LineGroups, DataRetriever, Invoker, Util
19912
20022
  SourcesLayer.prototype.getSegmentsGroups = function () {
19913
20023
  return this._lineGroups.getSegmentsGroups();
19914
20024
  };
20025
+ SourcesLayer.prototype.getSegmentsOnLineAfter = function (lineId, time) {
20026
+ return this._lineGroups.getSegmentsOnLineAfter(lineId, time);
20027
+ };
19915
20028
  SourcesLayer.prototype.add = function (element) {
19916
20029
  this._layer.add(element);
19917
20030
  if (this._dragGroup) {
@@ -19996,12 +20109,23 @@ module.exports = function (SourceGroup, LineGroups, DataRetriever, Invoker, Util
19996
20109
  }
19997
20110
  };
19998
20111
  SourcesLayer.prototype._onSourcesSetSelected = function (sources) {
20112
+ var sourcesGroups = this._lineGroups.getSourcesGroups();
19999
20113
  sources.forEach(function (source) {
20000
- const sourceGroup = this._sourcesGroup[source.id];
20114
+ const sourceGroup = sourcesGroups[source.id];
20001
20115
  if (sourceGroup) {
20002
20116
  sourceGroup.setSelected();
20003
20117
  }
20004
- }.bind(this));
20118
+ });
20119
+ this.batchDraw();
20120
+ };
20121
+ SourcesLayer.prototype._onSegmentsSetSelected = function (segments) {
20122
+ var segmentsGroups = this._lineGroups.getSegmentsGroups();
20123
+ segments.forEach(function (segment) {
20124
+ var segmentsGroup = segmentsGroups[segment.line];
20125
+ if (segmentsGroup) {
20126
+ segmentsGroup.setSelected(segment);
20127
+ }
20128
+ });
20005
20129
  this.batchDraw();
20006
20130
  };
20007
20131
  SourcesLayer.prototype._onSourcesAdd = function (sources) {
@@ -20112,6 +20236,244 @@ module.exports = function (SourceGroup, LineGroups, DataRetriever, Invoker, Util
20112
20236
  this._draggedElementId = null;
20113
20237
  this._draggedElementsData = null;
20114
20238
  };
20239
+ SourcesLayer.prototype.cleanupAfterSourceHandleDrag = function () {
20240
+ this._sourceHandleDragSession = null;
20241
+ };
20242
+ SourcesLayer.prototype.onSourceHandleDragStart = function (sourceGroup, leftHandle) {
20243
+ var source = sourceGroup.getSource();
20244
+ this._sourceHandleDragSession = {
20245
+ source: source,
20246
+ leftHandle: leftHandle,
20247
+ mouseDownX: this._view.getPointerPosition().x,
20248
+ initialTimeOffset: this._view.getTimeOffset(),
20249
+ initialStartTime: source.startTime,
20250
+ initialEndTime: source.endTime
20251
+ };
20252
+ };
20253
+ SourcesLayer.prototype.onSourceHandleDrag = function (draggedElement) {
20254
+ this._view.updateWithAutoScroll(this._dragSourceHandle.bind(this), null, false);
20255
+ return {
20256
+ x: draggedElement.absolutePosition().x,
20257
+ y: draggedElement.absolutePosition().y
20258
+ };
20259
+ };
20260
+ SourcesLayer.prototype._dragSourceHandle = function () {
20261
+ var session = this._sourceHandleDragSession;
20262
+ var pointer = this._view.getPointerPosition();
20263
+ var pointerX;
20264
+ var diff;
20265
+ var timeOffsetDiff;
20266
+ var shouldRedraw;
20267
+ if (!session) {
20268
+ return;
20269
+ }
20270
+ pointerX = pointer ? pointer.x : session.mouseDownX;
20271
+ diff = this._view.pixelsToTime(pointerX - session.mouseDownX);
20272
+ timeOffsetDiff = this._view.getTimeOffset() - session.initialTimeOffset;
20273
+ shouldRedraw = this.manageSourceMovements([session.source], session.leftHandle ? session.initialStartTime + diff + timeOffsetDiff : null, session.leftHandle ? null : session.initialEndTime + diff + timeOffsetDiff);
20274
+ if (shouldRedraw) {
20275
+ this.batchDraw();
20276
+ }
20277
+ };
20278
+ SourcesLayer.prototype.onSourceHandleDragEnd = function (sourceGroup) {
20279
+ this.cleanupAfterSourceHandleDrag();
20280
+ this.processSourceUpdates([sourceGroup.getSource()]);
20281
+ };
20282
+ SourcesLayer.prototype.isSegmentDragInProgress = function () {
20283
+ return Boolean(this._segmentDragSession);
20284
+ };
20285
+ SourcesLayer.prototype.cleanupAfterSegmentDrag = function () {
20286
+ this._segmentDragSession = null;
20287
+ };
20288
+ SourcesLayer.prototype._getSelectedSegmentsForDrag = function (draggedSegment) {
20289
+ var selectedElements = this._view.getSelectedElements();
20290
+ var selectedSegments;
20291
+ var draggedSegmentIsSelected;
20292
+ if (!Array.isArray(selectedElements)) {
20293
+ selectedElements = Object.values(selectedElements);
20294
+ }
20295
+ selectedSegments = selectedElements.filter(function (element) {
20296
+ return !Utils.isNullOrUndefined(element.line) && Utils.isNullOrUndefined(element.lineId);
20297
+ });
20298
+ draggedSegmentIsSelected = selectedSegments.some(function (segment) {
20299
+ return segment.id === draggedSegment.id;
20300
+ });
20301
+ if (!draggedSegmentIsSelected) {
20302
+ selectedSegments = [draggedSegment];
20303
+ this._view.deselectAll();
20304
+ }
20305
+ return selectedSegments;
20306
+ };
20307
+ SourcesLayer.prototype._buildSegmentDragGroups = function (segments) {
20308
+ var segmentsGroups = this._lineGroups.getSegmentsGroups();
20309
+ var groupsByLine = {};
20310
+ segments.forEach(function (segment) {
20311
+ var groupContext = groupsByLine[segment.line];
20312
+ if (!groupContext) {
20313
+ groupContext = {
20314
+ group: segmentsGroups[segment.line],
20315
+ segments: [],
20316
+ initialPositions: {}
20317
+ };
20318
+ groupsByLine[segment.line] = groupContext;
20319
+ }
20320
+ groupContext.segments.push(segment);
20321
+ groupContext.initialPositions[segment.id] = {
20322
+ startTime: segment.startTime,
20323
+ endTime: segment.endTime
20324
+ };
20325
+ });
20326
+ return Object.keys(groupsByLine).map(function (lineId) {
20327
+ groupsByLine[lineId].segments.sort(function (a, b) {
20328
+ return a.startTime - b.startTime;
20329
+ });
20330
+ return groupsByLine[lineId];
20331
+ });
20332
+ };
20333
+ SourcesLayer.prototype.onSegmentDragStart = function (segmentShape) {
20334
+ var segment = segmentShape.getSegment();
20335
+ var selectedSegments = this._getSelectedSegmentsForDrag(segment);
20336
+ var groups = this._buildSegmentDragGroups(selectedSegments);
20337
+ var minTimeOffset = -Infinity;
20338
+ var maxTimeOffset = Infinity;
20339
+ var draggable = true;
20340
+ var shouldClampToAdjacentGroups = !(groups.length === 1 && groups[0].segments.length === 1);
20341
+ groups.forEach(function (groupContext) {
20342
+ if (shouldClampToAdjacentGroups) {
20343
+ var limits = groupContext.group.getSegmentsDragTimeLimits(groupContext.segments, groupContext.initialPositions);
20344
+ minTimeOffset = Math.max(minTimeOffset, limits.minTimeOffset);
20345
+ maxTimeOffset = Math.min(maxTimeOffset, limits.maxTimeOffset);
20346
+ }
20347
+ draggable = draggable && groupContext.segments.every(function (draggedSegment) {
20348
+ return draggedSegment.editable;
20349
+ });
20350
+ });
20351
+ this._segmentDragSession = {
20352
+ kind: 'move',
20353
+ draggedNode: segmentShape,
20354
+ draggedSegment: segment,
20355
+ mouseDownX: this._view.getPointerPosition().x,
20356
+ initialTimeOffset: this._view.getTimeOffset(),
20357
+ groups: groups,
20358
+ minTimeOffset: minTimeOffset,
20359
+ maxTimeOffset: maxTimeOffset,
20360
+ appliedTimeOffset: 0,
20361
+ draggable: draggable
20362
+ };
20363
+ this._peaks.emit('segments.dragstart', segment);
20364
+ };
20365
+ SourcesLayer.prototype.onSegmentDrag = function (draggedElement) {
20366
+ this._view.updateWithAutoScroll(this._dragSegments.bind(this), null, false);
20367
+ return {
20368
+ x: draggedElement.absolutePosition().x,
20369
+ y: draggedElement.absolutePosition().y
20370
+ };
20371
+ };
20372
+ SourcesLayer.prototype._dragSegments = function () {
20373
+ var session = this._segmentDragSession;
20374
+ var pointerPos;
20375
+ var mousePos;
20376
+ var timeDiff;
20377
+ var timeOffsetDiff;
20378
+ var requestedTimeOffset;
20379
+ var appliedTimeOffset;
20380
+ var groupContext;
20381
+ var segment;
20382
+ var initialPosition;
20383
+ if (!session || session.kind !== 'move' || !session.draggable) {
20384
+ return;
20385
+ }
20386
+ pointerPos = this._view.getPointerPosition();
20387
+ mousePos = Math.min(this._view.getWidth() - this._peaks.options.autoScrollThreshold * this._view.getWidth(), Math.max(0, pointerPos ? pointerPos.x : session.mouseDownX));
20388
+ timeDiff = this._view.pixelsToTime(mousePos - session.mouseDownX);
20389
+ timeOffsetDiff = this._view.getTimeOffset() - session.initialTimeOffset;
20390
+ requestedTimeOffset = Utils.roundTime(timeDiff + timeOffsetDiff);
20391
+ appliedTimeOffset = Utils.clamp(requestedTimeOffset, session.minTimeOffset, session.maxTimeOffset);
20392
+ if (appliedTimeOffset === session.appliedTimeOffset) {
20393
+ return;
20394
+ }
20395
+ if (session.groups.length === 1 && session.groups[0].segments.length === 1) {
20396
+ groupContext = session.groups[0];
20397
+ segment = groupContext.segments[0];
20398
+ initialPosition = groupContext.initialPositions[segment.id];
20399
+ groupContext.group.updateSegment(segment, this._view.timeToPixels(initialPosition.startTime + appliedTimeOffset), this._view.timeToPixels(initialPosition.endTime + appliedTimeOffset), false);
20400
+ } else {
20401
+ session.groups.forEach(function (groupContext) {
20402
+ groupContext.group.dragSegmentsByTimeOffset(groupContext.segments, groupContext.initialPositions, appliedTimeOffset);
20403
+ });
20404
+ }
20405
+ session.appliedTimeOffset = appliedTimeOffset;
20406
+ this._view.updateTimelineLength();
20407
+ this.batchDraw();
20408
+ };
20409
+ SourcesLayer.prototype.onSegmentDragEnd = function (segmentShape) {
20410
+ var session = this._segmentDragSession;
20411
+ if (session && session.kind === 'move' && session.appliedTimeOffset !== 0) {
20412
+ session.groups.forEach(function (groupContext) {
20413
+ groupContext.group.markSegmentsUpdated(groupContext.segments);
20414
+ });
20415
+ this._view.updateTimelineLength();
20416
+ }
20417
+ this.cleanupAfterSegmentDrag();
20418
+ this._peaks.emit('segments.dragend', segmentShape.getSegment());
20419
+ };
20420
+ SourcesLayer.prototype.onSegmentHandleDragStart = function (segmentMarker) {
20421
+ this._segmentDragSession = {
20422
+ kind: segmentMarker.isStartMarker() ? 'resize-start' : 'resize-end',
20423
+ draggedNode: segmentMarker,
20424
+ segment: segmentMarker.getSegment(),
20425
+ group: this._lineGroups.getSegmentsGroups()[segmentMarker.getSegment().line],
20426
+ mouseDownX: this._view.getPointerPosition().x,
20427
+ initialTimeOffset: this._view.getTimeOffset(),
20428
+ initialStartTime: segmentMarker.getSegment().startTime,
20429
+ initialEndTime: segmentMarker.getSegment().endTime,
20430
+ startMarker: segmentMarker.isStartMarker()
20431
+ };
20432
+ this._peaks.emit('segments.dragstart', segmentMarker.getSegment(), segmentMarker.isStartMarker());
20433
+ };
20434
+ SourcesLayer.prototype.onSegmentHandleDrag = function (segmentMarker) {
20435
+ this._view.updateWithAutoScroll(this._dragSegmentHandle.bind(this), null, false);
20436
+ return {
20437
+ x: segmentMarker.getAbsolutePosition().x,
20438
+ y: segmentMarker.getAbsolutePosition().y
20439
+ };
20440
+ };
20441
+ SourcesLayer.prototype._dragSegmentHandle = function () {
20442
+ var session = this._segmentDragSession;
20443
+ var pointerPos;
20444
+ var pointerX;
20445
+ var timeDiff;
20446
+ var timeOffsetDiff;
20447
+ var newStartTime;
20448
+ var newEndTime;
20449
+ if (!session || session.kind !== 'resize-start' && session.kind !== 'resize-end') {
20450
+ return;
20451
+ }
20452
+ pointerPos = this._view.getPointerPosition();
20453
+ pointerX = pointerPos ? pointerPos.x : session.mouseDownX;
20454
+ timeDiff = this._view.pixelsToTime(pointerX - session.mouseDownX);
20455
+ timeOffsetDiff = this._view.getTimeOffset() - session.initialTimeOffset;
20456
+ if (session.startMarker) {
20457
+ newStartTime = Utils.roundTime(session.initialStartTime + timeDiff + timeOffsetDiff);
20458
+ if (session.segment.duration) {
20459
+ newStartTime = Math.max(newStartTime, Utils.roundTime(session.segment.endTime - session.segment.duration));
20460
+ }
20461
+ session.group.updateSegment(session.segment, this._view.timeToPixels(newStartTime), null, false);
20462
+ } else {
20463
+ newEndTime = Utils.roundTime(session.initialEndTime + timeDiff + timeOffsetDiff);
20464
+ if (session.segment.duration) {
20465
+ newEndTime = Math.min(newEndTime, Utils.roundTime(session.segment.startTime + session.segment.duration));
20466
+ }
20467
+ session.group.updateSegment(session.segment, null, this._view.timeToPixels(newEndTime), false);
20468
+ }
20469
+ this._view.updateTimelineLength();
20470
+ this.batchDraw();
20471
+ };
20472
+ SourcesLayer.prototype.onSegmentHandleDragEnd = function (segmentMarker) {
20473
+ this._view.updateTimelineLength();
20474
+ this.cleanupAfterSegmentDrag();
20475
+ this._peaks.emit('segments.dragend', segmentMarker.getSegment(), segmentMarker.isStartMarker());
20476
+ };
20115
20477
  SourcesLayer.prototype.onSourcesGroupDragStart = function (element) {
20116
20478
  if (this._suppressDragLifecycleForSourceId && element && element.currentTarget && element.currentTarget.attrs && element.currentTarget.attrs.sourceId === this._suppressDragLifecycleForSourceId) {
20117
20479
  return;
@@ -21330,6 +21692,12 @@ module.exports = function (Colors, EventEmitter, SegmentHandler, SourceHandler,
21330
21692
  Peaks.prototype.selectSourcesOnLineAfter = function (lineId, time) {
21331
21693
  return this.view.selectSourcesOnLineAfter(lineId, time);
21332
21694
  };
21695
+ Peaks.prototype.selectSegmentById = function (segmentId) {
21696
+ return this.view.selectSegmentById(segmentId);
21697
+ };
21698
+ Peaks.prototype.selectSegmentsOnLineAfter = function (lineId, time) {
21699
+ return this.view.selectSegmentsOnLineAfter(lineId, time);
21700
+ };
21333
21701
  Peaks.prototype.deselectAll = function (notify) {
21334
21702
  return this.view.deselectAll(notify);
21335
21703
  };
@@ -21774,9 +22142,13 @@ module.exports = function (Utils) {
21774
22142
  this._indicators = opts.indicators;
21775
22143
  this._peaks.emit('model.segment.updated', this);
21776
22144
  };
21777
- Segment.prototype.setSelected = function (selected) {
21778
- this._selected = selected;
21779
- this._peaks.emit('model.segment.selected', this);
22145
+ Segment.prototype.updateTimes = function (newStartTime, newEndTime) {
22146
+ if (!Utils.isNullOrUndefined(newStartTime)) {
22147
+ this._startTime = Utils.roundTime(newStartTime);
22148
+ }
22149
+ if (!Utils.isNullOrUndefined(newEndTime)) {
22150
+ this._endTime = Utils.roundTime(newEndTime);
22151
+ }
21780
22152
  };
21781
22153
  Segment.prototype.isVisible = function (startTime, endTime) {
21782
22154
  return this.startTime < endTime && startTime < this.endTime;
@@ -23877,13 +24249,25 @@ module.exports = function (MouseDragHandler, PlayheadLayer, SourcesLayer, ModeLa
23877
24249
  View.prototype.selectSourceById = function (sourceId) {
23878
24250
  const sourceGroup = this._sourcesLayer.getSourceGroupById(sourceId);
23879
24251
  if (sourceGroup) {
23880
- this._modeLayer.selectElements([sourceGroup.getSource()], false);
24252
+ this._modeLayer.selectElements([sourceGroup.getSource()], true);
23881
24253
  }
23882
24254
  };
23883
24255
  View.prototype.selectSourcesOnLineAfter = function (lineId, time) {
23884
24256
  const sources = this._sourcesLayer.getSourcesOnLineAfter(lineId, time);
23885
- if (sources) {
23886
- this._modeLayer.selectElements(sources, false);
24257
+ if (sources.length) {
24258
+ this._modeLayer.selectElements(sources, true);
24259
+ }
24260
+ };
24261
+ View.prototype.selectSegmentById = function (segmentId) {
24262
+ const segment = this._peaks.segmentHandler.getSegment(segmentId);
24263
+ if (segment) {
24264
+ this._modeLayer.selectElements([segment], true);
24265
+ }
24266
+ };
24267
+ View.prototype.selectSegmentsOnLineAfter = function (lineId, time) {
24268
+ const segments = this._sourcesLayer.getSegmentsOnLineAfter(lineId, time);
24269
+ if (segments.length) {
24270
+ this._modeLayer.selectElements(segments, true);
23887
24271
  }
23888
24272
  };
23889
24273
  View.prototype.deselectAll = function (notify) {