@checksub_team/peaks_timeline 1.4.46 → 1.4.48

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.
Files changed (3) hide show
  1. package/package.json +1 -1
  2. package/peaks.js +11 -2
  3. package/src/segment.js +14 -6
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@checksub_team/peaks_timeline",
3
- "version": "1.4.46",
3
+ "version": "1.4.48",
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
@@ -16693,21 +16693,26 @@ module.exports = function (Konva, SegmentMarker, Utils) {
16693
16693
  module.exports = function (Utils) {
16694
16694
  'use strict';
16695
16695
  function validateSegment(peaks, options, context) {
16696
+ var shouldNotifyUpdate = false;
16696
16697
  if (!Utils.isValidTime(options.startTime)) {
16697
16698
  throw new TypeError('peaks.segments.' + context + ': startTime should be a valid number');
16698
16699
  }
16699
16700
  if (!Utils.isValidTime(options.endTime)) {
16700
- throw new TypeError('peaks.segments.' + context + ': endTime should be a valid number');
16701
+ options.endTime = options.startTime;
16702
+ shouldNotifyUpdate = true;
16701
16703
  }
16702
16704
  options.startTime = Utils.roundTime(options.startTime);
16703
16705
  options.endTime = Utils.roundTime(options.endTime);
16704
16706
  if (options.startTime < 0) {
16705
16707
  options.startTime = 0;
16708
+ shouldNotifyUpdate = true;
16706
16709
  }
16707
16710
  if (options.endTime < 0) {
16708
16711
  options.endTime = 0;
16712
+ shouldNotifyUpdate = true;
16709
16713
  } else if (options.endTime - options.startTime < peaks.options.minSegmentSize) {
16710
16714
  options.endTime = options.startTime + peaks.options.minSegmentSize;
16715
+ shouldNotifyUpdate = true;
16711
16716
  }
16712
16717
  options.startTime = Utils.roundTime(options.startTime);
16713
16718
  options.endTime = Utils.roundTime(options.endTime);
@@ -16732,6 +16737,7 @@ module.exports = function (Utils) {
16732
16737
  } else if (!Utils.isValidColor(options.hoverColor)) {
16733
16738
  throw new TypeError('peaks.segments.' + context + ': hoverColor must be a boolean');
16734
16739
  }
16740
+ return shouldNotifyUpdate;
16735
16741
  }
16736
16742
  function Segment(peaks, id, startTime, endTime, labelText, color, textColor, handleTextColor, hoverColor, opacity, editable, allowDeletion, line, indicators) {
16737
16743
  var opts = {
@@ -16748,7 +16754,7 @@ module.exports = function (Utils) {
16748
16754
  line: line,
16749
16755
  indicators: indicators
16750
16756
  };
16751
- validateSegment(peaks, opts, 'add()');
16757
+ var shouldNotifyUpdate = validateSegment(peaks, opts, 'add()');
16752
16758
  this._peaks = peaks;
16753
16759
  this._id = id;
16754
16760
  this._startTime = opts.startTime;
@@ -16764,6 +16770,9 @@ module.exports = function (Utils) {
16764
16770
  this._line = opts.line;
16765
16771
  this._indicators = opts.indicators;
16766
16772
  this._minSize = peaks.options.minSegmentSize;
16773
+ if (shouldNotifyUpdate) {
16774
+ peaks.emit('segments.updated', [this]);
16775
+ }
16767
16776
  }
16768
16777
  Object.defineProperties(Segment.prototype, {
16769
16778
  id: {
package/src/segment.js CHANGED
@@ -12,39 +12,41 @@ define([
12
12
  'use strict';
13
13
 
14
14
  function validateSegment(peaks, options, context) {
15
+ var shouldNotifyUpdate = false;
16
+
15
17
  if (!Utils.isValidTime(options.startTime)) {
16
- // eslint-disable-next-line max-len
17
18
  throw new TypeError('peaks.segments.' + context + ': startTime should be a valid number');
18
19
  }
19
20
 
20
21
  if (!Utils.isValidTime(options.endTime)) {
21
- // eslint-disable-next-line max-len
22
- throw new TypeError('peaks.segments.' + context + ': endTime should be a valid number');
22
+ options.endTime = options.startTime;
23
+ shouldNotifyUpdate = true;
23
24
  }
24
25
 
25
26
  options.startTime = Utils.roundTime(options.startTime);
26
27
  options.endTime = Utils.roundTime(options.endTime);
27
28
  if (options.startTime < 0) {
28
29
  options.startTime = 0;
30
+ shouldNotifyUpdate = true;
29
31
  }
30
32
 
31
33
  if (options.endTime < 0) {
32
34
  options.endTime = 0;
35
+ shouldNotifyUpdate = true;
33
36
  }
34
37
  else if (options.endTime - options.startTime < peaks.options.minSegmentSize) {
35
38
  options.endTime = options.startTime + peaks.options.minSegmentSize;
39
+ shouldNotifyUpdate = true;
36
40
  }
37
41
 
38
42
  options.startTime = Utils.roundTime(options.startTime);
39
43
  options.endTime = Utils.roundTime(options.endTime);
40
44
 
41
45
  if (options.opacity < 0 || options.opacity > 1) {
42
- // eslint-disable-next-line max-len
43
46
  throw new RangeError('peaks.segments.' + context + ': opacity should be between 0 and 1');
44
47
  }
45
48
 
46
49
  if (Utils.isNullOrUndefined(options.labelText)) {
47
- // Set default label text
48
50
  options.labelText = '';
49
51
  }
50
52
  else if (!Utils.isString(options.labelText)) {
@@ -68,6 +70,8 @@ define([
68
70
  else if (!Utils.isValidColor(options.hoverColor)) {
69
71
  throw new TypeError('peaks.segments.' + context + ': hoverColor must be a boolean');
70
72
  }
73
+
74
+ return shouldNotifyUpdate;
71
75
  }
72
76
 
73
77
  /**
@@ -110,7 +114,7 @@ define([
110
114
  indicators: indicators
111
115
  };
112
116
 
113
- validateSegment(peaks, opts, 'add()');
117
+ var shouldNotifyUpdate = validateSegment(peaks, opts, 'add()');
114
118
 
115
119
  this._peaks = peaks;
116
120
  this._id = id;
@@ -127,6 +131,10 @@ define([
127
131
  this._line = opts.line;
128
132
  this._indicators = opts.indicators;
129
133
  this._minSize = peaks.options.minSegmentSize;
134
+
135
+ if (shouldNotifyUpdate) {
136
+ peaks.emit('segments.updated', [this]);
137
+ }
130
138
  }
131
139
 
132
140
  Object.defineProperties(Segment.prototype, {