@checksub_team/peaks_timeline 1.4.25 → 1.4.26

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@checksub_team/peaks_timeline",
3
- "version": "1.4.25",
3
+ "version": "1.4.26",
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
@@ -14754,6 +14754,35 @@ module.exports = function (Konva, Utils) {
14754
14754
  Line.prototype.lineHeight = function () {
14755
14755
  return this._height;
14756
14756
  };
14757
+ Line.prototype.changeHeight = function (from, to) {
14758
+ if (this._sourceHeights[from]) {
14759
+ var oldHeight = this._height;
14760
+ if (this._sourceHeights[to]) {
14761
+ this._sourceHeights[to] += this._sourceHeights[from];
14762
+ } else {
14763
+ this._sourceHeights[to] = this._sourceHeights[from];
14764
+ }
14765
+ if (to > this._height) {
14766
+ this._height = to;
14767
+ } else if (from === this._height) {
14768
+ this._height = 0;
14769
+ for (var height in this._sourceHeights) {
14770
+ if (Utils.objectHasProperty(this._sourceHeights, height)) {
14771
+ var parsedHeight = parseInt(height, 10);
14772
+ if (parsedHeight !== from) {
14773
+ if (parsedHeight > this._height) {
14774
+ this._height = parsedHeight;
14775
+ }
14776
+ }
14777
+ }
14778
+ }
14779
+ }
14780
+ if (this._height !== oldHeight) {
14781
+ this._peaks.emit('line.heightChanged', this._position);
14782
+ }
14783
+ delete this._sourceHeights[from];
14784
+ }
14785
+ };
14757
14786
  Line.prototype.updateLineHeight = function (sourceGroup, action) {
14758
14787
  var oldHeight = this._height;
14759
14788
  var sourceGroupHeight;
@@ -14782,7 +14811,7 @@ module.exports = function (Konva, Utils) {
14782
14811
  for (var height in this._sourceHeights) {
14783
14812
  if (Utils.objectHasProperty(this._sourceHeights, height)) {
14784
14813
  var parsedHeight = parseInt(height, 10);
14785
- if (parseInt(height, 10) > this._height) {
14814
+ if (parsedHeight > this._height) {
14786
14815
  this._height = parsedHeight;
14787
14816
  }
14788
14817
  }
@@ -15148,6 +15177,15 @@ module.exports = function (Line, LineIndicator, Utils) {
15148
15177
  var lineNewY = oldLine.getY();
15149
15178
  this._updateLinesPosition(position, lineNewY);
15150
15179
  };
15180
+ Lines.prototype.changeLineHeight = function (from, to) {
15181
+ for (var position in this._linesByPosition) {
15182
+ if (Utils.objectHasProperty(this._linesByPosition, position)) {
15183
+ if (!this._linesByPosition[position].isSegmentsLine()) {
15184
+ this._linesByPosition[position].changeHeight(from, to);
15185
+ }
15186
+ }
15187
+ }
15188
+ };
15151
15189
  Lines.prototype.addSourceGroup = function (sourceGroup, position) {
15152
15190
  if (!this._linesByPosition[position]) {
15153
15191
  this._createLine(position);
@@ -15572,6 +15610,11 @@ module.exports = function (Colors, EventEmitter, TimelineSegments, TimelineSourc
15572
15610
  Peaks.prototype._removeWindowResizeHandler = function () {
15573
15611
  window.removeEventListener('resize', this._onResize);
15574
15612
  };
15613
+ Peaks.prototype.setLineHeight = function (newLineHeight) {
15614
+ var oldHeight = this.options.lineHeight;
15615
+ this.options.lineHeight = newLineHeight;
15616
+ this.emit('options.set.line_height', oldHeight);
15617
+ };
15575
15618
  Peaks.prototype.destroy = function () {
15576
15619
  this._removeWindowResizeHandler();
15577
15620
  if (this.keyboardHandler) {
@@ -15697,12 +15740,15 @@ module.exports = function (Utils, SourceGroup, Konva) {
15697
15740
  if (hoveredElement) {
15698
15741
  if (this._selectedElement) {
15699
15742
  this._selectedElement.setSelected(false);
15743
+ this._peaks.emit('source.deselected', this._selectedElement.getSource());
15700
15744
  }
15701
15745
  this._selectedElement = hoveredElement;
15702
15746
  this._selectedElement.setSelected(true);
15747
+ this._peaks.emit('source.selected', this._selectedElement.getSource());
15703
15748
  } else {
15704
15749
  if (this._selectedElement) {
15705
15750
  this._selectedElement.setSelected(false);
15751
+ this._peaks.emit('source.deselected', this._selectedElement.getSource());
15706
15752
  this._selectedElement = null;
15707
15753
  }
15708
15754
  }
@@ -18516,6 +18562,7 @@ module.exports = function (SourceGroup, SegmentsGroup, Lines, DataRetriever, Uti
18516
18562
  this._peaks.on('data.retrieved', this._onDataRetrieved.bind(this));
18517
18563
  this._peaks.on('sources.refresh', this._onSourcesRefresh.bind(this));
18518
18564
  this._peaks.on('segments.show', this._onSegmentsShow.bind(this));
18565
+ this._peaks.on('options.set.line_height', this._onOptionsLineHeightChange.bind(this));
18519
18566
  }
18520
18567
  SourcesLayer.prototype.getLoadedData = function (id) {
18521
18568
  return this._loadedData[id];
@@ -18538,6 +18585,25 @@ module.exports = function (SourceGroup, SegmentsGroup, Lines, DataRetriever, Uti
18538
18585
  SourcesLayer.prototype.isEditingEnabled = function () {
18539
18586
  return this._allowEditing;
18540
18587
  };
18588
+ SourcesLayer.prototype._onOptionsLineHeightChange = function (oldHeight) {
18589
+ var positions = [];
18590
+ for (var sourceId in this._sourcesGroup) {
18591
+ if (Utils.objectHasProperty(this._sourcesGroup, sourceId)) {
18592
+ var source = this._sourcesGroup[sourceId].getSource();
18593
+ if (!positions.includes(source.position)) {
18594
+ this._lines.changeLineHeight(oldHeight, this._peaks.options.lineHeight);
18595
+ positions.push(source.position);
18596
+ }
18597
+ this._removeSource(source);
18598
+ this._addSourceGroup(source);
18599
+ }
18600
+ }
18601
+ if (positions) {
18602
+ var frameOffset = this._view.getFrameOffset();
18603
+ var width = this._view.getWidth();
18604
+ this.updateSources(this._view.pixelsToTime(frameOffset), this._view.pixelsToTime(frameOffset + width));
18605
+ }
18606
+ };
18541
18607
  SourcesLayer.prototype._onSourceUpdate = function (source) {
18542
18608
  var redraw = false;
18543
18609
  var sourceGroup = this._sourcesGroup[source.id];
package/src/line.js CHANGED
@@ -91,6 +91,43 @@ define([
91
91
  return this._height;
92
92
  };
93
93
 
94
+ Line.prototype.changeHeight = function(from, to) {
95
+ if (this._sourceHeights[from]) {
96
+ var oldHeight = this._height;
97
+
98
+ if (this._sourceHeights[to]) {
99
+ this._sourceHeights[to] += this._sourceHeights[from];
100
+ }
101
+ else {
102
+ this._sourceHeights[to] = this._sourceHeights[from];
103
+ }
104
+
105
+ if (to > this._height) {
106
+ this._height = to;
107
+ }
108
+ else if (from === this._height) {
109
+ this._height = 0;
110
+ for (var height in this._sourceHeights) {
111
+ if (Utils.objectHasProperty(this._sourceHeights, height)) {
112
+ var parsedHeight = parseInt(height, 10);
113
+
114
+ if (parsedHeight !== from) {
115
+ if (parsedHeight > this._height) {
116
+ this._height = parsedHeight;
117
+ }
118
+ }
119
+ }
120
+ }
121
+ }
122
+
123
+ if (this._height !== oldHeight) {
124
+ this._peaks.emit('line.heightChanged', this._position);
125
+ }
126
+
127
+ delete this._sourceHeights[from];
128
+ }
129
+ };
130
+
94
131
  Line.prototype.updateLineHeight = function(sourceGroup, action) {
95
132
  var oldHeight = this._height;
96
133
  var sourceGroupHeight;
@@ -127,7 +164,7 @@ define([
127
164
  if (Utils.objectHasProperty(this._sourceHeights, height)) {
128
165
  var parsedHeight = parseInt(height, 10);
129
166
 
130
- if (parseInt(height, 10) > this._height) {
167
+ if (parsedHeight > this._height) {
131
168
  this._height = parsedHeight;
132
169
  }
133
170
  }
package/src/lines.js CHANGED
@@ -57,6 +57,16 @@ define([
57
57
  this._updateLinesPosition(position, lineNewY);
58
58
  };
59
59
 
60
+ Lines.prototype.changeLineHeight = function(from, to) {
61
+ for (var position in this._linesByPosition) {
62
+ if (Utils.objectHasProperty(this._linesByPosition, position)) {
63
+ if (!this._linesByPosition[position].isSegmentsLine()) {
64
+ this._linesByPosition[position].changeHeight(from, to);
65
+ }
66
+ }
67
+ }
68
+ };
69
+
60
70
  Lines.prototype.addSourceGroup = function(sourceGroup, position) {
61
71
  if (!this._linesByPosition[position]) {
62
72
  this._createLine(position);
package/src/main.js CHANGED
@@ -233,7 +233,7 @@ define([
233
233
  lineHeight: 80,
234
234
 
235
235
  /**
236
- * Ratio by which lineHeight must be multiplied to obtain the segment's line height.
236
+ * Height of a segment, in pixels.
237
237
  */
238
238
  segmentHeight: 32,
239
239
 
@@ -641,6 +641,13 @@ define([
641
641
  window.removeEventListener('resize', this._onResize);
642
642
  };
643
643
 
644
+ Peaks.prototype.setLineHeight = function(newLineHeight) {
645
+ var oldHeight = this.options.lineHeight;
646
+
647
+ this.options.lineHeight = newLineHeight;
648
+ this.emit('options.set.line_height', oldHeight);
649
+ };
650
+
644
651
  /**
645
652
  * Cleans up a Peaks instance after use.
646
653
  */
package/src/mode-layer.js CHANGED
@@ -121,15 +121,19 @@ define([
121
121
  if (hoveredElement) {
122
122
  if (this._selectedElement) {
123
123
  this._selectedElement.setSelected(false);
124
+ this._peaks.emit('source.deselected', this._selectedElement.getSource());
124
125
  }
125
126
 
126
127
  this._selectedElement = hoveredElement;
127
128
 
128
129
  this._selectedElement.setSelected(true);
130
+
131
+ this._peaks.emit('source.selected', this._selectedElement.getSource());
129
132
  }
130
133
  else {
131
134
  if (this._selectedElement) {
132
135
  this._selectedElement.setSelected(false);
136
+ this._peaks.emit('source.deselected', this._selectedElement.getSource());
133
137
  this._selectedElement = null;
134
138
  }
135
139
  }
@@ -61,6 +61,7 @@ define([
61
61
  this._peaks.on('data.retrieved', this._onDataRetrieved.bind(this));
62
62
  this._peaks.on('sources.refresh', this._onSourcesRefresh.bind(this));
63
63
  this._peaks.on('segments.show', this._onSegmentsShow.bind(this));
64
+ this._peaks.on('options.set.line_height', this._onOptionsLineHeightChange.bind(this));
64
65
  }
65
66
 
66
67
  SourcesLayer.prototype.getLoadedData = function(id) {
@@ -97,6 +98,36 @@ define([
97
98
  return this._allowEditing;
98
99
  };
99
100
 
101
+ SourcesLayer.prototype._onOptionsLineHeightChange = function(oldHeight) {
102
+ var positions = [];
103
+
104
+ for (var sourceId in this._sourcesGroup) {
105
+ if (Utils.objectHasProperty(this._sourcesGroup, sourceId)) {
106
+ var source = this._sourcesGroup[sourceId].getSource();
107
+
108
+ if (!positions.includes(source.position)) {
109
+ this._lines.changeLineHeight(
110
+ oldHeight,
111
+ this._peaks.options.lineHeight
112
+ );
113
+ positions.push(source.position);
114
+ }
115
+ this._removeSource(source);
116
+ this._addSourceGroup(source);
117
+ }
118
+ }
119
+
120
+ if (positions) {
121
+ var frameOffset = this._view.getFrameOffset();
122
+ var width = this._view.getWidth();
123
+
124
+ this.updateSources(
125
+ this._view.pixelsToTime(frameOffset),
126
+ this._view.pixelsToTime(frameOffset + width)
127
+ );
128
+ }
129
+ };
130
+
100
131
  SourcesLayer.prototype._onSourceUpdate = function(source) {
101
132
  var redraw = false;
102
133
  var sourceGroup = this._sourcesGroup[source.id];