@checksub_team/peaks_timeline 2.0.0-alpha.0 → 2.0.0-alpha.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/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@checksub_team/peaks_timeline",
3
- "version": "2.0.0-alpha.0",
3
+ "version": "2.0.0-alpha.2",
4
4
  "description": "JavaScript UI component for displaying audio waveforms",
5
5
  "main": "./peaks.js",
6
6
  "types": "./peaks.js.d.ts",
package/peaks.js CHANGED
@@ -15397,12 +15397,11 @@ module.exports = function (SegmentsGroup, LineGroup, LineIndicator, Utils) {
15397
15397
  }
15398
15398
  lineGroup.addSource(source, sourceGroup, sourcesAround);
15399
15399
  };
15400
- LineGroups.prototype.addSegments = function (lineId, lineOptions) {
15401
- this._peaks.addLine(lineOptions, true);
15402
- const lineGroup = this._lineGroupsByPosition[lineOptions.position];
15400
+ LineGroups.prototype.addSegments = function (segmentsGroupId, lineId) {
15401
+ const lineGroup = this._lineGroupsById[lineId];
15403
15402
  lineGroup.allowInteractions(this._areSegmentInteractionsAllowed);
15404
- lineGroup.addSegments(this._segmentsGroups[lineId]);
15405
- this._segmentsGroupToLine[lineId] = lineGroup;
15403
+ lineGroup.addSegments(this._segmentsGroups[segmentsGroupId]);
15404
+ this._segmentsGroupToLine[segmentsGroupId] = lineGroup;
15406
15405
  this._setInteractions(lineGroup.getId());
15407
15406
  this.refreshLineYs();
15408
15407
  };
@@ -15690,8 +15689,9 @@ module.exports = function (SegmentsGroup, LineGroup, LineIndicator, Utils) {
15690
15689
  }
15691
15690
  };
15692
15691
  LineGroups.prototype.allowInteractions = function (forSources, forSegments) {
15693
- this._areSourceInteractionsAllowed = typeof forSources !== 'undefined' ? forSources : this._areSourceInteractionsAllowed;
15694
- this._areSegmentInteractionsAllowed = typeof forSegments !== 'undefined' ? forSegments : this._areSegmentInteractionsAllowed;
15692
+ this._areSourceInteractionsAllowed = !Utils.isNullOrUndefined(forSources) ? forSources : this._areSourceInteractionsAllowed;
15693
+ this._areSegmentInteractionsAllowed = !Utils.isNullOrUndefined(forSegments) ? forSegments : this._areSegmentInteractionsAllowed;
15694
+ console.log('peaks.lines.allowInteractions(): ' + 'forSources: ' + this._areSourceInteractionsAllowed + ', forSegments: ' + this._areSegmentInteractionsAllowed);
15695
15695
  for (var id in this._lineGroupsById) {
15696
15696
  if (Utils.objectHasProperty(this._lineGroupsById, id)) {
15697
15697
  this._setInteractions(id);
@@ -17633,6 +17633,7 @@ module.exports = function (WaveformBuilder, WaveformShape, Loader, Utils, Konva)
17633
17633
  this._borderWidth = this._source.borderWidth || 0;
17634
17634
  this._currentTimeToPixelsScaleUsed = this._view.getTimeToPixelsScale();
17635
17635
  this._selected = this._source.selected;
17636
+ this._hovered = false;
17636
17637
  this._isDragged = false;
17637
17638
  this._previewList = [];
17638
17639
  this._markersGroup = this._createMarkers();
@@ -17651,12 +17652,14 @@ module.exports = function (WaveformBuilder, WaveformShape, Loader, Utils, Konva)
17651
17652
  this._group.on('dragend', this._onDragEnd.bind(this));
17652
17653
  this._cursor = null;
17653
17654
  this._group.on('mouseenter', function () {
17655
+ self._setHovered(true);
17654
17656
  self._view.setHoveredElement(self);
17655
17657
  if (!self._source.loading) {
17656
17658
  self._showButtons();
17657
17659
  }
17658
17660
  });
17659
17661
  this._group.on('mouseleave', function () {
17662
+ self._setHovered(false);
17660
17663
  self._view.setHoveredElement(null);
17661
17664
  self._hideButtons();
17662
17665
  });
@@ -17694,6 +17697,10 @@ module.exports = function (WaveformBuilder, WaveformShape, Loader, Utils, Konva)
17694
17697
  this.createIndicators();
17695
17698
  this.setLoadingState(this._source.loading);
17696
17699
  }
17700
+ SourceGroup.prototype._setHovered = function (newValue) {
17701
+ this._hovered = newValue;
17702
+ this._group.draw();
17703
+ };
17697
17704
  SourceGroup.prototype._onDragStart = function (element) {
17698
17705
  this._isDragged = true;
17699
17706
  this._layer.onSourcesGroupDragStart(element);
@@ -17895,22 +17902,30 @@ module.exports = function (WaveformBuilder, WaveformShape, Loader, Utils, Konva)
17895
17902
  ctx.quadraticCurveTo(x + offset, offset, x + radius, offset);
17896
17903
  ctx.closePath();
17897
17904
  if (fill) {
17905
+ var backgroundColor;
17906
+ if (this._selected) {
17907
+ backgroundColor = this._source.selectedBackgroundColor;
17908
+ } else if (this._hovered) {
17909
+ backgroundColor = this._source.hoverBackgroundColor;
17910
+ } else {
17911
+ backgroundColor = this._source.backgroundColor;
17912
+ }
17898
17913
  if (this._source.shouldShowWarning()) {
17899
17914
  var gradient = ctx.createLinearGradient(0, 0, this._width, 0);
17900
17915
  if (this._source.mediaEndTime < this._source.duration) {
17901
17916
  var rightStopPosition = Math.max(1 - this._source.warningWidth / this._width, 0.5);
17902
- gradient.addColorStop(rightStopPosition, this._source.backgroundColor);
17917
+ gradient.addColorStop(rightStopPosition, backgroundColor);
17903
17918
  gradient.addColorStop(1, this._source.warningColor);
17904
17919
  }
17905
17920
  if (this._source.mediaStartTime > 0) {
17906
17921
  var leftStopPosition = Math.min(this._source.warningWidth / this._width, 0.5);
17907
17922
  gradient.addColorStop(0, this._source.warningColor);
17908
- gradient.addColorStop(leftStopPosition, this._source.backgroundColor);
17923
+ gradient.addColorStop(leftStopPosition, backgroundColor);
17909
17924
  }
17910
17925
  ctx.fillStyle = gradient;
17911
17926
  ctx.fill();
17912
17927
  } else {
17913
- ctx.fillStyle = this._source.backgroundColor;
17928
+ ctx.fillStyle = backgroundColor;
17914
17929
  ctx.fill();
17915
17930
  }
17916
17931
  }
@@ -18249,7 +18264,7 @@ module.exports = function (WaveformBuilder, WaveformShape, Loader, Utils, Konva)
18249
18264
  this._selected = this._source.selected;
18250
18265
  if (this._border) {
18251
18266
  if (this._selected) {
18252
- this._border.fill(this._source.selectedColor);
18267
+ this._border.fill(this._source.selectedBorderColor);
18253
18268
  this._borderWidth = this._peaks.options.sourceSelectedBorderWidth;
18254
18269
  } else {
18255
18270
  this._border.fill(this._source.borderColor);
@@ -18262,7 +18277,7 @@ module.exports = function (WaveformBuilder, WaveformShape, Loader, Utils, Konva)
18262
18277
  })[0];
18263
18278
  if (unwrap_background) {
18264
18279
  if (this._selected) {
18265
- unwrap_background.stroke(this._source.selectedColor);
18280
+ unwrap_background.stroke(this._source.selectedBorderColor);
18266
18281
  unwrap_background.strokeWidth(this._peaks.options.sourceSelectedBorderWidth);
18267
18282
  } else {
18268
18283
  unwrap_background.strokeWidth(0);
@@ -18275,7 +18290,7 @@ module.exports = function (WaveformBuilder, WaveformShape, Loader, Utils, Konva)
18275
18290
  })[0];
18276
18291
  if (wrap_background) {
18277
18292
  if (this._selected) {
18278
- wrap_background.stroke(this._source.selectedColor);
18293
+ wrap_background.stroke(this._source.selectedBorderColor);
18279
18294
  wrap_background.strokeWidth(this._peaks.options.sourceSelectedBorderWidth);
18280
18295
  } else {
18281
18296
  wrap_background.strokeWidth(0);
@@ -18968,8 +18983,8 @@ module.exports = function (SourceGroup, LineGroups, DataRetriever, Invoker, Util
18968
18983
  }
18969
18984
  }
18970
18985
  };
18971
- SourcesLayer.prototype._onSegmentsShow = function (lineId, lineOptions) {
18972
- this._lineGroups.addSegments(lineId, lineOptions);
18986
+ SourcesLayer.prototype._onSegmentsShow = function (segmentsGroupId, lineId) {
18987
+ this._lineGroups.addSegments(segmentsGroupId, lineId);
18973
18988
  this._view.updateTimelineLength();
18974
18989
  this._layer.draw();
18975
18990
  };
@@ -19733,6 +19748,7 @@ module.exports = function (Colors, EventEmitter, SegmentHandler, SourceHandler,
19733
19748
  nudgeIncrement: 1,
19734
19749
  zoomWaveformColor: 'rgba(180, 180, 180, 1)',
19735
19750
  randomizeSegmentColor: true,
19751
+ blockUpdatingOnMouseClickWithCtrlKey: false,
19736
19752
  blockUpdatingOnMouseClickWithMetaKey: false,
19737
19753
  height: 200,
19738
19754
  segmentColor: Colors.orange,
@@ -19922,8 +19938,8 @@ module.exports = function (Colors, EventEmitter, SegmentHandler, SourceHandler,
19922
19938
  Peaks.prototype.moveLine = function (lineId, position) {
19923
19939
  this.lineHandler.moveById(lineId, position);
19924
19940
  };
19925
- Peaks.prototype.showSegments = function (lineId, lineOptions) {
19926
- this.segmentHandler.addSegmentsToPosition(lineId, lineOptions);
19941
+ Peaks.prototype.showSegments = function (segmentsGroupId, lineId) {
19942
+ this.segmentHandler.addSegmentsToLine(segmentsGroupId, lineId);
19927
19943
  };
19928
19944
  Peaks.prototype.destroySegment = function (segmentId) {
19929
19945
  this.segmentHandler.removeById(segmentId);
@@ -20507,13 +20523,25 @@ module.exports = function (Utils) {
20507
20523
  if (!Utils.isValidColor(options.backgroundColor)) {
20508
20524
  throw new TypeError('peaks.sources.' + context + ': backgroundColor should be a valid CSS color');
20509
20525
  }
20510
- if (!Utils.isValidColor(options.borderColor)) {
20526
+ if (Utils.isNullOrUndefined(options.selectedBackgroundColor)) {
20527
+ options.selectedBackgroundColor = options.backgroundColor;
20528
+ } else if (!Utils.isValidColor(options.selectedBackgroundColor)) {
20529
+ throw new TypeError('peaks.sources.' + context + ': selectedBackgroundColor should be a valid CSS color');
20530
+ }
20531
+ if (Utils.isNullOrUndefined(options.hoverBackgroundColor)) {
20532
+ options.hoverBackgroundColor = Utils.shadeColor(options.backgroundColor, 30);
20533
+ } else if (!Utils.isValidColor(options.hoverBackgroundColor)) {
20534
+ throw new TypeError('peaks.sources.' + context + ': hoverBackgroundColor should be a valid CSS color');
20535
+ }
20536
+ if (Utils.isNullOrUndefined(options.borderColor)) {
20511
20537
  options.borderColor = options.color;
20538
+ } else if (!Utils.isValidColor(options.borderColor)) {
20539
+ throw new TypeError('peaks.sources.' + context + ': borderColor should be a valid CSS color');
20512
20540
  }
20513
- if (Utils.isNullOrUndefined(options.selectedColor)) {
20514
- options.selectedColor = null;
20515
- } else if (!Utils.isValidColor(options.selectedColor)) {
20516
- throw new TypeError('peaks.sources.' + context + ': selectedColor should be a valid CSS color');
20541
+ if (Utils.isNullOrUndefined(options.selectedBorderColor)) {
20542
+ options.selectedBorderColor = Utils.shadeColor(options.borderColor, 30);
20543
+ } else if (!Utils.isValidColor(options.selectedBorderColor)) {
20544
+ throw new TypeError('peaks.sources.' + context + ': selectedBorderColor should be a valid CSS color');
20517
20545
  }
20518
20546
  if (Utils.isNullOrUndefined(options.warningColor)) {
20519
20547
  options.warningColor = null;
@@ -20662,7 +20690,7 @@ module.exports = function (Utils) {
20662
20690
  throw new TypeError('peaks.sources.' + context + ': loading must be a boolean');
20663
20691
  }
20664
20692
  }
20665
- function Source(peaks, id, lineId, originId, elementId, title, titleAlignments, url, previewUrl, binaryUrl, kind, subkind, duration, startTime, endTime, mediaStartTime, mediaEndTime, color, backgroundColor, borderColor, selectedColor, warningColor, warningWidth, volumeSliderColor, volumeSliderWidth, volumeSliderDraggingWidth, textFont, textFontSize, textColor, textBackgroundColor, textPosition, textAutoScroll, borderWidth, borderRadius, wrapped, draggable, orderable, resizable, cuttable, deletable, wrapping, previewHeight, binaryHeight, indicators, markers, buttons, markerColor, markerWidth, volume, volumeRange, loading, ...customParams) {
20693
+ function Source(peaks, id, lineId, originId, elementId, title, titleAlignments, url, previewUrl, binaryUrl, kind, subkind, duration, startTime, endTime, mediaStartTime, mediaEndTime, color, backgroundColor, hoverBackgroundColor, selectedBackgroundColor, borderColor, selectedBorderColor, warningColor, warningWidth, volumeSliderColor, volumeSliderWidth, volumeSliderDraggingWidth, textFont, textFontSize, textColor, textBackgroundColor, textPosition, textAutoScroll, borderWidth, borderRadius, wrapped, draggable, orderable, resizable, cuttable, deletable, wrapping, previewHeight, binaryHeight, indicators, markers, buttons, markerColor, markerWidth, volume, volumeRange, loading, ...customParams) {
20666
20694
  var opts = {
20667
20695
  title: title,
20668
20696
  titleAlignments: titleAlignments,
@@ -20678,8 +20706,10 @@ module.exports = function (Utils) {
20678
20706
  mediaEndTime: mediaEndTime,
20679
20707
  color: color,
20680
20708
  backgroundColor: backgroundColor,
20709
+ hoverBackgroundColor: hoverBackgroundColor,
20710
+ selectedBackgroundColor: selectedBackgroundColor,
20681
20711
  borderColor: borderColor,
20682
- selectedColor: selectedColor,
20712
+ selectedBorderColor: selectedBorderColor,
20683
20713
  warningColor: warningColor,
20684
20714
  warningWidth: warningWidth,
20685
20715
  textFont: textFont,
@@ -20731,8 +20761,10 @@ module.exports = function (Utils) {
20731
20761
  this._mediaEndTime = opts.mediaEndTime;
20732
20762
  this._color = opts.color;
20733
20763
  this._backgroundColor = opts.backgroundColor;
20764
+ this._hoverBackgroundColor = opts.hoverBackgroundColor;
20765
+ this._selectedBackgroundColor = opts.selectedBackgroundColor;
20734
20766
  this._borderColor = opts.borderColor;
20735
- this._selectedColor = opts.selectedColor || Utils.shadeColor(opts.backgroundColor, 30);
20767
+ this._selectedBorderColor = opts.selectedBorderColor;
20736
20768
  this._warningColor = opts.warningColor;
20737
20769
  this._warningWidth = opts.warningWidth;
20738
20770
  this._volumeSliderColor = opts.volumeSliderColor;
@@ -20906,6 +20938,24 @@ module.exports = function (Utils) {
20906
20938
  this._backgroundColor = backgroundColor;
20907
20939
  }
20908
20940
  },
20941
+ hoverBackgroundColor: {
20942
+ enumerable: true,
20943
+ get: function () {
20944
+ return this._hoverBackgroundColor;
20945
+ },
20946
+ set: function (hoverBackgroundColor) {
20947
+ this._hoverBackgroundColor = hoverBackgroundColor;
20948
+ }
20949
+ },
20950
+ selectedBackgroundColor: {
20951
+ enumerable: true,
20952
+ get: function () {
20953
+ return this._selectedBackgroundColor;
20954
+ },
20955
+ set: function (selectedBackgroundColor) {
20956
+ this._selectedBackgroundColor = selectedBackgroundColor;
20957
+ }
20958
+ },
20909
20959
  borderColor: {
20910
20960
  enumerable: true,
20911
20961
  get: function () {
@@ -20915,13 +20965,13 @@ module.exports = function (Utils) {
20915
20965
  this._borderColor = borderColor;
20916
20966
  }
20917
20967
  },
20918
- selectedColor: {
20968
+ selectedBorderColor: {
20919
20969
  enumerable: true,
20920
20970
  get: function () {
20921
- return this._selectedColor;
20971
+ return this._selectedBorderColor;
20922
20972
  },
20923
- set: function (selectedColor) {
20924
- this._selectedColor = selectedColor;
20973
+ set: function (selectedBorderColor) {
20974
+ this._selectedBorderColor = selectedBorderColor;
20925
20975
  }
20926
20976
  },
20927
20977
  warningColor: {
@@ -21271,8 +21321,10 @@ module.exports = function (Utils) {
21271
21321
  mediaEndTime: this.mediaEndTime,
21272
21322
  color: this.color,
21273
21323
  backgroundColor: this.backgroundColor,
21324
+ hoverBackgroundColor: this.hoverBackgroundColor,
21325
+ selectedBackgroundColor: this.selectedBackgroundColor,
21274
21326
  borderColor: this.borderColor,
21275
- selectedColor: this.selectedColor,
21327
+ selectedBorderColor: this.selectedBorderColor,
21276
21328
  warningColor: this.warningColor,
21277
21329
  warningWidth: this.warningWidth,
21278
21330
  volumeSliderColor: this.volumeSliderColor,
@@ -21321,7 +21373,7 @@ module.exports = function (Utils) {
21321
21373
  this._color = opts.color;
21322
21374
  this._backgroundColor = opts.backgroundColor;
21323
21375
  this._borderColor = opts.borderColor;
21324
- this._selectedColor = opts.selectedColor || Utils.shadeColor(opts.backgroundColor, 30);
21376
+ this._selectedBorderColor = opts.selectedBorderColor;
21325
21377
  this._warningColor = opts.warningColor;
21326
21378
  this._warningWidth = opts.warningWidth;
21327
21379
  this._volumeSliderColor = opts.volumeSliderColor;
@@ -21490,8 +21542,11 @@ module.exports = function (Colors, Segment, Utils) {
21490
21542
  return segment.toSerializable();
21491
21543
  });
21492
21544
  };
21493
- SegmentHandler.prototype.addSegmentsToPosition = function (lineId, lineOptions) {
21494
- this._peaks.emit('handler.segments.show', lineId, lineOptions);
21545
+ SegmentHandler.prototype.addSegmentsToLine = function (segmentsGroupId, lineId) {
21546
+ if (!Utils.isString(lineId) || Utils.isNullOrUndefined(this._peaks.lineHandler.getLine(lineId))) {
21547
+ throw new Error('peaks.segmentHandler.addSegmentsToLine(): line with id ' + lineId + ' does not exist');
21548
+ }
21549
+ this._peaks.emit('handler.segments.show', segmentsGroupId, lineId);
21495
21550
  };
21496
21551
  SegmentHandler.prototype.getSegment = function (id) {
21497
21552
  return this._segmentsById[id] || null;
@@ -21631,8 +21686,10 @@ module.exports = function (Source, Utils) {
21631
21686
  mediaEndTime: originalMediaEndTime,
21632
21687
  color: sourceToCut.color,
21633
21688
  backgroundColor: sourceToCut.backgroundColor,
21689
+ hoverBackgroundColor: sourceToCut.hoverBackgroundColor,
21690
+ selectedBackgroundColor: sourceToCut.selectedBackgroundColor,
21634
21691
  borderColor: sourceToCut.borderColor,
21635
- selectedColor: sourceToCut.selectedColor,
21692
+ selectedBorderColor: sourceToCut.selectedBorderColor,
21636
21693
  warningColor: sourceToCut.warningColor,
21637
21694
  warningWidth: sourceToCut.warningWidth,
21638
21695
  volumeSliderColor: sourceToCut.volumeSliderColor,
@@ -21680,8 +21737,10 @@ module.exports = function (Source, Utils) {
21680
21737
  SourceHandler.prototype._addSource = function (source) {
21681
21738
  this._sources.push(source);
21682
21739
  this._sourcesById[source.id] = source;
21683
- this._sourcesByLineId[source.lineId] = this._sourcesByLineId[source.lineId] || [];
21684
- this._sourcesByLineId[source.lineId].push(source);
21740
+ if (Utils.isNullOrUndefined(this._sourcesByLineId[source.lineId])) {
21741
+ this._sourcesByLineId[source.lineId] = {};
21742
+ }
21743
+ this._sourcesByLineId[source.lineId][source.id] = source;
21685
21744
  };
21686
21745
  SourceHandler.prototype._createSource = function (options) {
21687
21746
  if (!Utils.isObject(options)) {
@@ -21693,12 +21752,15 @@ module.exports = function (Source, Utils) {
21693
21752
  customParams.push(key, value);
21694
21753
  }
21695
21754
  });
21696
- var source = new Source(this._peaks, options.id || this._getNextSourceId(), options.lineId, options.originId, options.elementId, options.title, options.titleAlignments, options.url, options.previewUrl, options.binaryUrl, options.kind, options.subkind, options.duration, options.startTime, options.endTime, options.mediaStartTime, options.mediaEndTime, options.color, options.backgroundColor, options.borderColor, options.selectedColor, options.warningColor, options.warningWidth, options.volumeSliderColor, options.volumeSliderWidth, options.volumeSliderDraggingWidth, options.textFont, options.textFontSize, options.textColor, options.textBackgroundColor, options.textPosition, options.textAutoScroll, options.borderWidth, options.borderRadius, options.wrapped, options.draggable, options.orderable, options.resizable, options.cuttable, options.deletable, options.wrapping, options.previewHeight, options.binaryHeight, options.indicators, options.markers, options.buttons, options.markerColor, options.markerWidth, options.volume, options.volumeRange, options.loading, ...customParams);
21755
+ var source = new Source(this._peaks, options.id || this._getNextSourceId(), options.lineId, options.originId, options.elementId, options.title, options.titleAlignments, options.url, options.previewUrl, options.binaryUrl, options.kind, options.subkind, options.duration, options.startTime, options.endTime, options.mediaStartTime, options.mediaEndTime, options.color, options.backgroundColor, options.hoverBackgroundColor, options.selectedBackgroundColor, options.borderColor, options.selectedBorderColor, options.warningColor, options.warningWidth, options.volumeSliderColor, options.volumeSliderWidth, options.volumeSliderDraggingWidth, options.textFont, options.textFontSize, options.textColor, options.textBackgroundColor, options.textPosition, options.textAutoScroll, options.borderWidth, options.borderRadius, options.wrapped, options.draggable, options.orderable, options.resizable, options.cuttable, options.deletable, options.wrapping, options.previewHeight, options.binaryHeight, options.indicators, options.markers, options.buttons, options.markerColor, options.markerWidth, options.volume, options.volumeRange, options.loading, ...customParams);
21697
21756
  return source;
21698
21757
  };
21699
21758
  SourceHandler.prototype.getSources = function () {
21700
21759
  return this._sources;
21701
21760
  };
21761
+ SourceHandler.prototype.getSourcesByLineId = function (lineId) {
21762
+ return Utils.isNullOrUndefined(lineId) ? this._sourcesByLineId : this._sourcesByLineId[lineId];
21763
+ };
21702
21764
  SourceHandler.prototype.getSourcesSerialized = function () {
21703
21765
  return this._sources.map(function (source) {
21704
21766
  return source.toSerializable();
@@ -21755,6 +21817,7 @@ module.exports = function (Source, Utils) {
21755
21817
  var index = indexes[i] - destroyed.length;
21756
21818
  var itemDestroyed = this._sources.splice(index, 1)[0];
21757
21819
  delete this._sourcesById[itemDestroyed.id];
21820
+ delete this._sourcesByLineId[itemDestroyed.lineId][itemDestroyed.id];
21758
21821
  destroyed.push(itemDestroyed);
21759
21822
  }
21760
21823
  return destroyed;
@@ -159,15 +159,13 @@ define([
159
159
  lineGroup.addSource(source, sourceGroup, sourcesAround);
160
160
  };
161
161
 
162
- LineGroups.prototype.addSegments = function(lineId, lineOptions) {
163
- this._peaks.addLine(lineOptions, true);
164
-
165
- const lineGroup = this._lineGroupsByPosition[lineOptions.position];
162
+ LineGroups.prototype.addSegments = function(segmentsGroupId, lineId) {
163
+ const lineGroup = this._lineGroupsById[lineId];
166
164
 
167
165
  lineGroup.allowInteractions(this._areSegmentInteractionsAllowed);
168
- lineGroup.addSegments(this._segmentsGroups[lineId]);
166
+ lineGroup.addSegments(this._segmentsGroups[segmentsGroupId]);
169
167
 
170
- this._segmentsGroupToLine[lineId] = lineGroup;
168
+ this._segmentsGroupToLine[segmentsGroupId] = lineGroup;
171
169
 
172
170
  this._setInteractions(lineGroup.getId());
173
171
 
@@ -569,10 +567,13 @@ define([
569
567
  };
570
568
 
571
569
  LineGroups.prototype.allowInteractions = function(forSources, forSegments) {
572
- this._areSourceInteractionsAllowed = typeof forSources !== 'undefined' ?
570
+ this._areSourceInteractionsAllowed = !Utils.isNullOrUndefined(forSources) ?
573
571
  forSources : this._areSourceInteractionsAllowed;
574
- this._areSegmentInteractionsAllowed = typeof forSegments !== 'undefined' ?
572
+ this._areSegmentInteractionsAllowed = !Utils.isNullOrUndefined(forSegments) ?
575
573
  forSegments : this._areSegmentInteractionsAllowed;
574
+ console.log('peaks.lines.allowInteractions(): ' +
575
+ 'forSources: ' + this._areSourceInteractionsAllowed + ', forSegments: ' + this._areSegmentInteractionsAllowed
576
+ );
576
577
  for (var id in this._lineGroupsById) {
577
578
  if (Utils.objectHasProperty(this._lineGroupsById, id)) {
578
579
  this._setInteractions(id);
@@ -56,6 +56,7 @@ define([
56
56
  this._borderWidth = this._source.borderWidth || 0;
57
57
  this._currentTimeToPixelsScaleUsed = this._view.getTimeToPixelsScale();
58
58
  this._selected = this._source.selected;
59
+ this._hovered = false;
59
60
  this._isDragged = false;
60
61
 
61
62
  this._previewList = [];
@@ -79,6 +80,7 @@ define([
79
80
 
80
81
  this._cursor = null;
81
82
  this._group.on('mouseenter', function() {
83
+ self._setHovered(true);
82
84
  self._view.setHoveredElement(self);
83
85
  if (!self._source.loading) {
84
86
  self._showButtons();
@@ -86,6 +88,7 @@ define([
86
88
  });
87
89
 
88
90
  this._group.on('mouseleave', function() {
91
+ self._setHovered(false);
89
92
  self._view.setHoveredElement(null);
90
93
  self._hideButtons();
91
94
  });
@@ -133,6 +136,11 @@ define([
133
136
  this.setLoadingState(this._source.loading);
134
137
  }
135
138
 
139
+ SourceGroup.prototype._setHovered = function(newValue) {
140
+ this._hovered = newValue;
141
+ this._group.draw();
142
+ };
143
+
136
144
  SourceGroup.prototype._onDragStart = function(element) {
137
145
  this._isDragged = true;
138
146
  this._layer.onSourcesGroupDragStart(element);
@@ -419,13 +427,25 @@ define([
419
427
  ctx.closePath();
420
428
 
421
429
  if (fill) {
430
+ var backgroundColor;
431
+
432
+ if (this._selected) {
433
+ backgroundColor = this._source.selectedBackgroundColor;
434
+ }
435
+ else if (this._hovered) {
436
+ backgroundColor = this._source.hoverBackgroundColor;
437
+ }
438
+ else {
439
+ backgroundColor = this._source.backgroundColor;
440
+ }
441
+
422
442
  if (this._source.shouldShowWarning()) {
423
443
  var gradient = ctx.createLinearGradient(0, 0, this._width, 0);
424
444
 
425
445
  if (this._source.mediaEndTime < this._source.duration) {
426
446
  var rightStopPosition = Math.max(1 - (this._source.warningWidth / this._width), 0.5);
427
447
 
428
- gradient.addColorStop(rightStopPosition, this._source.backgroundColor);
448
+ gradient.addColorStop(rightStopPosition, backgroundColor);
429
449
  gradient.addColorStop(1, this._source.warningColor);
430
450
  }
431
451
 
@@ -433,14 +453,14 @@ define([
433
453
  var leftStopPosition = Math.min(this._source.warningWidth / this._width, 0.5);
434
454
 
435
455
  gradient.addColorStop(0, this._source.warningColor);
436
- gradient.addColorStop(leftStopPosition, this._source.backgroundColor);
456
+ gradient.addColorStop(leftStopPosition, backgroundColor);
437
457
  }
438
458
 
439
459
  ctx.fillStyle = gradient;
440
460
  ctx.fill();
441
461
  }
442
462
  else {
443
- ctx.fillStyle = this._source.backgroundColor;
463
+ ctx.fillStyle = backgroundColor;
444
464
  ctx.fill();
445
465
  }
446
466
  }
@@ -874,7 +894,7 @@ define([
874
894
  this._selected = this._source.selected;
875
895
  if (this._border) {
876
896
  if (this._selected) {
877
- this._border.fill(this._source.selectedColor);
897
+ this._border.fill(this._source.selectedBorderColor);
878
898
  this._borderWidth = this._peaks.options.sourceSelectedBorderWidth;
879
899
  }
880
900
  else {
@@ -891,7 +911,7 @@ define([
891
911
 
892
912
  if (unwrap_background) {
893
913
  if (this._selected) {
894
- unwrap_background.stroke(this._source.selectedColor);
914
+ unwrap_background.stroke(this._source.selectedBorderColor);
895
915
  unwrap_background.strokeWidth(this._peaks.options.sourceSelectedBorderWidth);
896
916
  }
897
917
  else {
@@ -908,7 +928,7 @@ define([
908
928
 
909
929
  if (wrap_background) {
910
930
  if (this._selected) {
911
- wrap_background.stroke(this._source.selectedColor);
931
+ wrap_background.stroke(this._source.selectedBorderColor);
912
932
  wrap_background.strokeWidth(this._peaks.options.sourceSelectedBorderWidth);
913
933
  }
914
934
  else {
@@ -220,8 +220,8 @@ define([
220
220
  }
221
221
  };
222
222
 
223
- SourcesLayer.prototype._onSegmentsShow = function(lineId, lineOptions) {
224
- this._lineGroups.addSegments(lineId, lineOptions);
223
+ SourcesLayer.prototype._onSegmentsShow = function(segmentsGroupId, lineId) {
224
+ this._lineGroups.addSegments(segmentsGroupId, lineId);
225
225
  this._view.updateTimelineLength();
226
226
  this._layer.draw();
227
227
  };
package/src/main.js CHANGED
@@ -135,6 +135,11 @@ define([
135
135
  */
136
136
  randomizeSegmentColor: true,
137
137
 
138
+ /**
139
+ * Block mouse clicks if a control key is pressed
140
+ */
141
+ blockUpdatingOnMouseClickWithCtrlKey: false,
142
+
138
143
  /**
139
144
  * Block mouse clicks if a meta key is pressed
140
145
  */
@@ -722,8 +727,8 @@ define([
722
727
  this.lineHandler.moveById(lineId, position);
723
728
  };
724
729
 
725
- Peaks.prototype.showSegments = function(lineId, lineOptions) {
726
- this.segmentHandler.addSegmentsToPosition(lineId, lineOptions);
730
+ Peaks.prototype.showSegments = function(segmentsGroupId, lineId) {
731
+ this.segmentHandler.addSegmentsToLine(segmentsGroupId, lineId);
727
732
  };
728
733
 
729
734
  /**
@@ -121,16 +121,39 @@ define([
121
121
  );
122
122
  }
123
123
 
124
- if (!Utils.isValidColor(options.borderColor)) {
124
+ if (Utils.isNullOrUndefined(options.selectedBackgroundColor)) {
125
+ options.selectedBackgroundColor = options.backgroundColor;
126
+ }
127
+ else if (!Utils.isValidColor(options.selectedBackgroundColor)) {
128
+ throw new TypeError(
129
+ 'peaks.sources.' + context + ': selectedBackgroundColor should be a valid CSS color'
130
+ );
131
+ }
132
+
133
+ if (Utils.isNullOrUndefined(options.hoverBackgroundColor)) {
134
+ options.hoverBackgroundColor = Utils.shadeColor(options.backgroundColor, 30);
135
+ }
136
+ else if (!Utils.isValidColor(options.hoverBackgroundColor)) {
137
+ throw new TypeError(
138
+ 'peaks.sources.' + context + ': hoverBackgroundColor should be a valid CSS color'
139
+ );
140
+ }
141
+
142
+ if (Utils.isNullOrUndefined(options.borderColor)) {
125
143
  options.borderColor = options.color;
126
144
  }
145
+ else if (!Utils.isValidColor(options.borderColor)) {
146
+ throw new TypeError(
147
+ 'peaks.sources.' + context + ': borderColor should be a valid CSS color'
148
+ );
149
+ }
127
150
 
128
- if (Utils.isNullOrUndefined(options.selectedColor)) {
129
- options.selectedColor = null;
151
+ if (Utils.isNullOrUndefined(options.selectedBorderColor)) {
152
+ options.selectedBorderColor = Utils.shadeColor(options.borderColor, 30);
130
153
  }
131
- else if (!Utils.isValidColor(options.selectedColor)) {
154
+ else if (!Utils.isValidColor(options.selectedBorderColor)) {
132
155
  throw new TypeError(
133
- 'peaks.sources.' + context + ': selectedColor should be a valid CSS color'
156
+ 'peaks.sources.' + context + ': selectedBorderColor should be a valid CSS color'
134
157
  );
135
158
  }
136
159
 
@@ -374,7 +397,7 @@ define([
374
397
  * @param {String} color Primary color of the source representation.
375
398
  * @param {String} backgroundColor Background color of the source.
376
399
  * @param {String} borderColor Border color of the source.
377
- * @param {String} selectedColor Color when the source is selected.
400
+ * @param {String} selectedBorderColor Color when the source is selected.
378
401
  * @param {String} warningColor Color used for warning states.
379
402
  * @param {String} volumeSliderColor Color of the volume slider.
380
403
  * @param {Number} volumeSliderWidth Width of the volume slider.
@@ -407,9 +430,9 @@ define([
407
430
  */
408
431
 
409
432
  function Source(peaks, id, lineId, originId, elementId, title, titleAlignments, url, previewUrl, binaryUrl, kind,
410
- subkind, duration, startTime, endTime, mediaStartTime, mediaEndTime, color, backgroundColor,
411
- borderColor, selectedColor, warningColor, warningWidth, volumeSliderColor, volumeSliderWidth,
412
- volumeSliderDraggingWidth, textFont, textFontSize, textColor, textBackgroundColor, textPosition,
433
+ subkind, duration, startTime, endTime, mediaStartTime, mediaEndTime, color, backgroundColor, hoverBackgroundColor,
434
+ selectedBackgroundColor, borderColor, selectedBorderColor, warningColor, warningWidth, volumeSliderColor,
435
+ volumeSliderWidth, volumeSliderDraggingWidth, textFont, textFontSize, textColor, textBackgroundColor, textPosition,
413
436
  textAutoScroll, borderWidth, borderRadius, wrapped, draggable, orderable, resizable,
414
437
  cuttable, deletable, wrapping, previewHeight, binaryHeight, indicators, markers, buttons, markerColor,
415
438
  markerWidth, volume, volumeRange, loading, ...customParams) {
@@ -428,8 +451,10 @@ define([
428
451
  mediaEndTime: mediaEndTime,
429
452
  color: color,
430
453
  backgroundColor: backgroundColor,
454
+ hoverBackgroundColor: hoverBackgroundColor,
455
+ selectedBackgroundColor: selectedBackgroundColor,
431
456
  borderColor: borderColor,
432
- selectedColor: selectedColor,
457
+ selectedBorderColor: selectedBorderColor,
433
458
  warningColor: warningColor,
434
459
  warningWidth: warningWidth,
435
460
  textFont: textFont,
@@ -483,8 +508,10 @@ define([
483
508
  this._mediaEndTime = opts.mediaEndTime;
484
509
  this._color = opts.color;
485
510
  this._backgroundColor = opts.backgroundColor;
511
+ this._hoverBackgroundColor = opts.hoverBackgroundColor;
512
+ this._selectedBackgroundColor = opts.selectedBackgroundColor;
486
513
  this._borderColor = opts.borderColor;
487
- this._selectedColor = opts.selectedColor || Utils.shadeColor(opts.backgroundColor, 30);
514
+ this._selectedBorderColor = opts.selectedBorderColor;
488
515
  this._warningColor = opts.warningColor;
489
516
  this._warningWidth = opts.warningWidth;
490
517
  this._volumeSliderColor = opts.volumeSliderColor;
@@ -669,6 +696,26 @@ define([
669
696
  this._backgroundColor = backgroundColor;
670
697
  }
671
698
  },
699
+ hoverBackgroundColor: {
700
+ enumerable: true,
701
+ get: function() {
702
+ return this._hoverBackgroundColor;
703
+ },
704
+
705
+ set: function(hoverBackgroundColor) {
706
+ this._hoverBackgroundColor = hoverBackgroundColor;
707
+ }
708
+ },
709
+ selectedBackgroundColor: {
710
+ enumerable: true,
711
+ get: function() {
712
+ return this._selectedBackgroundColor;
713
+ },
714
+
715
+ set: function(selectedBackgroundColor) {
716
+ this._selectedBackgroundColor = selectedBackgroundColor;
717
+ }
718
+ },
672
719
  borderColor: {
673
720
  enumerable: true,
674
721
  get: function() {
@@ -679,14 +726,14 @@ define([
679
726
  this._borderColor = borderColor;
680
727
  }
681
728
  },
682
- selectedColor: {
729
+ selectedBorderColor: {
683
730
  enumerable: true,
684
731
  get: function() {
685
- return this._selectedColor;
732
+ return this._selectedBorderColor;
686
733
  },
687
734
 
688
- set: function(selectedColor) {
689
- this._selectedColor = selectedColor;
735
+ set: function(selectedBorderColor) {
736
+ this._selectedBorderColor = selectedBorderColor;
690
737
  }
691
738
  },
692
739
  warningColor: {
@@ -1084,8 +1131,10 @@ define([
1084
1131
  mediaEndTime: this.mediaEndTime,
1085
1132
  color: this.color,
1086
1133
  backgroundColor: this.backgroundColor,
1134
+ hoverBackgroundColor: this.hoverBackgroundColor,
1135
+ selectedBackgroundColor: this.selectedBackgroundColor,
1087
1136
  borderColor: this.borderColor,
1088
- selectedColor: this.selectedColor,
1137
+ selectedBorderColor: this.selectedBorderColor,
1089
1138
  warningColor: this.warningColor,
1090
1139
  warningWidth: this.warningWidth,
1091
1140
  volumeSliderColor: this.volumeSliderColor,
@@ -1137,7 +1186,7 @@ define([
1137
1186
  this._color = opts.color;
1138
1187
  this._backgroundColor = opts.backgroundColor;
1139
1188
  this._borderColor = opts.borderColor;
1140
- this._selectedColor = opts.selectedColor || Utils.shadeColor(opts.backgroundColor, 30);
1189
+ this._selectedBorderColor = opts.selectedBorderColor;
1141
1190
  this._warningColor = opts.warningColor;
1142
1191
  this._warningWidth = opts.warningWidth;
1143
1192
  this._volumeSliderColor = opts.volumeSliderColor;
@@ -176,8 +176,16 @@ define([
176
176
  * Add segments to the given line so they can be displayed.
177
177
  */
178
178
 
179
- SegmentHandler.prototype.addSegmentsToPosition = function(lineId, lineOptions) {
180
- this._peaks.emit('handler.segments.show', lineId, lineOptions);
179
+ SegmentHandler.prototype.addSegmentsToLine = function(segmentsGroupId, lineId) {
180
+ if (
181
+ !Utils.isString(lineId) ||
182
+ Utils.isNullOrUndefined(this._peaks.lineHandler.getLine(lineId))
183
+ ) {
184
+ throw new Error('peaks.segmentHandler.addSegmentsToLine(): line with id ' + lineId +
185
+ ' does not exist');
186
+ }
187
+
188
+ this._peaks.emit('handler.segments.show', segmentsGroupId, lineId);
181
189
  };
182
190
 
183
191
  /**
@@ -78,8 +78,10 @@ define([
78
78
  mediaEndTime: originalMediaEndTime,
79
79
  color: sourceToCut.color,
80
80
  backgroundColor: sourceToCut.backgroundColor,
81
+ hoverBackgroundColor: sourceToCut.hoverBackgroundColor,
82
+ selectedBackgroundColor: sourceToCut.selectedBackgroundColor,
81
83
  borderColor: sourceToCut.borderColor,
82
- selectedColor: sourceToCut.selectedColor,
84
+ selectedBorderColor: sourceToCut.selectedBorderColor,
83
85
  warningColor: sourceToCut.warningColor,
84
86
  warningWidth: sourceToCut.warningWidth,
85
87
  volumeSliderColor: sourceToCut.volumeSliderColor,
@@ -143,8 +145,10 @@ define([
143
145
  SourceHandler.prototype._addSource = function(source) {
144
146
  this._sources.push(source);
145
147
  this._sourcesById[source.id] = source;
146
- this._sourcesByLineId[source.lineId] = this._sourcesByLineId[source.lineId] || [];
147
- this._sourcesByLineId[source.lineId].push(source);
148
+ if (Utils.isNullOrUndefined(this._sourcesByLineId[source.lineId])) {
149
+ this._sourcesByLineId[source.lineId] = {};
150
+ }
151
+ this._sourcesByLineId[source.lineId][source.id] = source;
148
152
  };
149
153
 
150
154
  /**
@@ -190,8 +194,10 @@ define([
190
194
  options.mediaEndTime,
191
195
  options.color,
192
196
  options.backgroundColor,
197
+ options.hoverBackgroundColor,
198
+ options.selectedBackgroundColor,
193
199
  options.borderColor,
194
- options.selectedColor,
200
+ options.selectedBorderColor,
195
201
  options.warningColor,
196
202
  options.warningWidth,
197
203
  options.volumeSliderColor,
@@ -238,6 +244,10 @@ define([
238
244
  return this._sources;
239
245
  };
240
246
 
247
+ SourceHandler.prototype.getSourcesByLineId = function(lineId) {
248
+ return Utils.isNullOrUndefined(lineId) ? this._sourcesByLineId : this._sourcesByLineId[lineId];
249
+ };
250
+
241
251
  /**
242
252
  * Returns all sources, serialized to a plain object.
243
253
  *
@@ -380,6 +390,7 @@ define([
380
390
  var itemDestroyed = this._sources.splice(index, 1)[0];
381
391
 
382
392
  delete this._sourcesById[itemDestroyed.id];
393
+ delete this._sourcesByLineId[itemDestroyed.lineId][itemDestroyed.id];
383
394
 
384
395
  destroyed.push(itemDestroyed);
385
396
  }