@checksub_team/peaks_timeline 1.16.0-alpha.0 → 1.16.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/peaks.js CHANGED
@@ -14809,12 +14809,6 @@ module.exports = function (Konva, Utils, SVGs) {
14809
14809
  this._indicators[lineId].text = text;
14810
14810
  this.draw();
14811
14811
  };
14812
- LineIndicator.prototype._showMenu = function (menu) {
14813
- menu.style.display = 'block';
14814
- var containerRect = this._stage.container().getBoundingClientRect();
14815
- menu.style.top = containerRect.top + this._stage.getPointerPosition().y - menu.offsetHeight + 'px';
14816
- menu.style.left = containerRect.left + this._stage.getPointerPosition().x + 6 + 'px';
14817
- };
14818
14812
  LineIndicator.prototype._createIndicator = function (line, type, text) {
14819
14813
  var indicator = new Konva.Group();
14820
14814
  var indicatorHeight = 0;
@@ -14949,7 +14943,7 @@ module.exports = function (Konva, Utils, SVGs) {
14949
14943
  return LineIndicator;
14950
14944
  }(_dereq_('konva'), _dereq_('./utils'), _dereq_('./svgs'));
14951
14945
  },{"./svgs":108,"./utils":113,"konva":43}],92:[function(_dereq_,module,exports){
14952
- module.exports = function (Konva, Utils) {
14946
+ module.exports = function (SourceGroup, Konva, Utils) {
14953
14947
  'use strict';
14954
14948
  function Line(peaks, view, y, id, position) {
14955
14949
  this._peaks = peaks;
@@ -14982,8 +14976,8 @@ module.exports = function (Konva, Utils) {
14982
14976
  Line.prototype.getId = function () {
14983
14977
  return this._id;
14984
14978
  };
14985
- Line.prototype.isEmpty = function () {
14986
- return this.isSegmentsLine() ? this._segmentsGroup.isEmpty() : Object.keys(this._sources).length === 0;
14979
+ Line.prototype.countRemainingElements = function () {
14980
+ return this.isSegmentsLine() ? this._segmentsGroup.countRemainingElements() : Object.keys(this._sources).length;
14987
14981
  };
14988
14982
  Line.prototype.isSegmentsLine = function () {
14989
14983
  return Boolean(this._segmentsGroup);
@@ -15011,71 +15005,53 @@ module.exports = function (Konva, Utils) {
15011
15005
  Line.prototype.lineHeight = function () {
15012
15006
  return this._height;
15013
15007
  };
15014
- Line.prototype.changeHeight = function (from, to) {
15015
- if (this._sourceHeights[from]) {
15016
- var oldHeight = this._height;
15017
- if (this._sourceHeights[to]) {
15018
- this._sourceHeights[to] += this._sourceHeights[from];
15019
- } else {
15020
- this._sourceHeights[to] = this._sourceHeights[from];
15008
+ Line.prototype._addHeight = function (height) {
15009
+ if (this._sourceHeights[height]) {
15010
+ this._sourceHeights[height]++;
15011
+ } else {
15012
+ this._sourceHeights[height] = 1;
15013
+ if (height > this._height) {
15014
+ this._height = height;
15021
15015
  }
15022
- if (to > this._height) {
15023
- this._height = to;
15024
- } else if (from === this._height) {
15016
+ }
15017
+ };
15018
+ Line.prototype._subtractHeight = function (height) {
15019
+ if (Object.keys(this._sources).length === 0) {
15020
+ this._height = this._peaks.options.emptyLineHeight;
15021
+ this._sourceHeights = {};
15022
+ } else {
15023
+ this._sourceHeights[height]--;
15024
+ if (this._sourceHeights[height] === 0 && height === this._height) {
15025
+ delete this._sourceHeights[height];
15025
15026
  this._height = 0;
15026
- for (var height in this._sourceHeights) {
15027
- if (Utils.objectHasProperty(this._sourceHeights, height)) {
15028
- var parsedHeight = parseInt(height, 10);
15029
- if (parsedHeight !== from) {
15030
- if (parsedHeight > this._height) {
15031
- this._height = parsedHeight;
15032
- }
15027
+ for (var sourceHeight in this._sourceHeights) {
15028
+ if (Utils.objectHasProperty(this._sourceHeights, sourceHeight)) {
15029
+ var parsedHeight = parseInt(sourceHeight, 10);
15030
+ if (parsedHeight > this._height) {
15031
+ this._height = parsedHeight;
15033
15032
  }
15034
15033
  }
15035
15034
  }
15036
15035
  }
15037
- if (this._height !== oldHeight) {
15038
- this._peaks.emit('line.heightChanged', this._position);
15039
- }
15040
- delete this._sourceHeights[from];
15041
15036
  }
15042
15037
  };
15043
- Line.prototype.updateLineHeight = function (sourceGroup, action) {
15038
+ Line.prototype.updateLineHeight = function (source, action) {
15044
15039
  var oldHeight = this._height;
15040
+ var sourceGroup = this._sourcesGroup[source.id];
15045
15041
  var sourceGroupHeight;
15046
15042
  switch (action) {
15047
15043
  case 'add':
15048
- sourceGroupHeight = sourceGroup.getCurrentHeight();
15049
- if (this._sourceHeights[sourceGroupHeight]) {
15050
- this._sourceHeights[sourceGroupHeight]++;
15051
- } else {
15052
- this._sourceHeights[sourceGroupHeight] = 1;
15053
- if (sourceGroupHeight > this._height) {
15054
- this._height = sourceGroupHeight;
15055
- }
15056
- }
15044
+ sourceGroupHeight = sourceGroup ? sourceGroup.getCurrentHeight() : SourceGroup.getHeights(source, this._peaks).current;
15045
+ this._addHeight(sourceGroupHeight);
15057
15046
  break;
15058
15047
  case 'remove':
15059
- if (Object.keys(this._sources).length === 0) {
15060
- this._height = this._peaks.options.emptyLineHeight;
15061
- this._sourceHeights = {};
15062
- } else {
15063
- sourceGroupHeight = sourceGroup.getCurrentHeight();
15064
- this._sourceHeights[sourceGroupHeight]--;
15065
- if (this._sourceHeights[sourceGroupHeight] === 0 && sourceGroupHeight === this._height) {
15066
- delete this._sourceHeights[sourceGroupHeight];
15067
- this._height = 0;
15068
- for (var height in this._sourceHeights) {
15069
- if (Utils.objectHasProperty(this._sourceHeights, height)) {
15070
- var parsedHeight = parseInt(height, 10);
15071
- if (parsedHeight > this._height) {
15072
- this._height = parsedHeight;
15073
- }
15074
- }
15075
- }
15076
- }
15077
- }
15048
+ sourceGroupHeight = sourceGroup ? sourceGroup.getCurrentHeight() : SourceGroup.getHeights(source, this._peaks).current;
15049
+ this._subtractHeight(sourceGroupHeight);
15078
15050
  break;
15051
+ default:
15052
+ var {unwrapped, wrapped} = sourceGroup ? sourceGroup.getHeights() : SourceGroup.getHeights(source, this._peaks);
15053
+ this._addHeight(source.wrapped ? wrapped : unwrapped);
15054
+ this._subtractHeight(source.wrapped ? unwrapped : wrapped);
15079
15055
  }
15080
15056
  if (this._height !== oldHeight) {
15081
15057
  this._peaks.emit('line.heightChanged', this._position);
@@ -15087,9 +15063,10 @@ module.exports = function (Konva, Utils) {
15087
15063
  Line.prototype.addToLayer = function (layer) {
15088
15064
  layer.add(this._group);
15089
15065
  };
15090
- Line.prototype.addSourceGroup = function (sourceGroup) {
15091
- var source = sourceGroup.getSource();
15092
- this._sourcesGroup[source.id] = sourceGroup;
15066
+ Line.prototype.addSourceGroup = function (source, sourceGroup) {
15067
+ if (sourceGroup) {
15068
+ this._sourcesGroup[source.id] = sourceGroup;
15069
+ }
15093
15070
  if (!this._sources[source.id]) {
15094
15071
  var newSource = {
15095
15072
  source: source,
@@ -15106,9 +15083,9 @@ module.exports = function (Konva, Utils) {
15106
15083
  }
15107
15084
  if (source.endTime <= currentSource.source.startTime) {
15108
15085
  var startLimit = currentSource.prevSourceId ? this._sources[currentSource.prevSourceId].source.endTime : 0;
15109
- var newTimes = this._canBePlacedBetween(source.startTime, source.endTime, startLimit, currentSource.source.startTime);
15110
- if (newTimes) {
15111
- source.updateTimes(newTimes.start, newTimes.end);
15086
+ const {newStartTime, newEndTime} = this._canBePlacedBetween(source.startTime, source.endTime, startLimit, currentSource.source.startTime);
15087
+ if (newStartTime !== null && newEndTime !== null) {
15088
+ source.updateTimes(newStartTime, newEndTime);
15112
15089
  if (currentSource.prevSourceId) {
15113
15090
  this._sources[currentSource.prevSourceId].nextSourceId = source.id;
15114
15091
  newSource.prevSourceId = currentSource.prevSourceId;
@@ -15135,9 +15112,9 @@ module.exports = function (Konva, Utils) {
15135
15112
  this._firstSourceId = source.id;
15136
15113
  this._sources[source.id] = newSource;
15137
15114
  }
15138
- this.updateLineHeight(sourceGroup, 'add');
15115
+ this.updateLineHeight(source, 'add');
15139
15116
  }
15140
- if (!sourceGroup.getParent() || !sourceGroup.isDescendantOf(this._group)) {
15117
+ if (sourceGroup && (!sourceGroup.getParent() || !sourceGroup.isDescendantOf(this._group))) {
15141
15118
  sourceGroup.addToGroup(this._group);
15142
15119
  }
15143
15120
  };
@@ -15157,26 +15134,23 @@ module.exports = function (Konva, Utils) {
15157
15134
  };
15158
15135
  Line.prototype._canBePlacedBetween = function (startTime, endTime, startLimit, endLimit) {
15159
15136
  var timeWidth = Utils.roundTime(endTime - startTime);
15160
- var newTimes = null;
15137
+ var newStartTime, newEndTime;
15161
15138
  if (!endLimit && startTime > startLimit || startTime > startLimit && endTime < endLimit) {
15162
- newTimes = {
15163
- start: startTime,
15164
- end: endTime
15165
- };
15139
+ newStartTime = startTime;
15140
+ newEndTime = endTime;
15166
15141
  } else if (Utils.roundTime(endLimit - startLimit) >= timeWidth) {
15167
15142
  if (startTime > startLimit) {
15168
- newTimes = {
15169
- start: Utils.roundTime(endLimit - timeWidth),
15170
- end: endLimit
15171
- };
15143
+ newStartTime = Utils.roundTime(endLimit - timeWidth);
15144
+ newEndTime = endLimit;
15172
15145
  } else {
15173
- newTimes = {
15174
- start: startLimit,
15175
- end: Utils.roundTime(startLimit + timeWidth)
15176
- };
15146
+ newStartTime = startLimit;
15147
+ newEndTime = Utils.roundTime(startLimit + timeWidth);
15177
15148
  }
15178
15149
  }
15179
- return newTimes;
15150
+ return {
15151
+ newStartTime,
15152
+ newEndTime
15153
+ };
15180
15154
  };
15181
15155
  Line.prototype.removeSourceGroup = function (source, isPermanent) {
15182
15156
  var sourceGroup = this._sourcesGroup[source.id];
@@ -15199,7 +15173,7 @@ module.exports = function (Konva, Utils) {
15199
15173
  if (this._firstSourceId === source.id) {
15200
15174
  this._firstSourceId = sourceData.nextSourceId;
15201
15175
  }
15202
- this.updateLineHeight(sourceGroup, 'remove');
15176
+ this.updateLineHeight(source, 'remove');
15203
15177
  }
15204
15178
  return sourceGroup;
15205
15179
  };
@@ -15222,83 +15196,85 @@ module.exports = function (Konva, Utils) {
15222
15196
  this._y += dy;
15223
15197
  this._group.y(this._group.y() + dy);
15224
15198
  };
15225
- Line.prototype.manageSourceOrder = function (source, newTimes) {
15226
- var cursorTime = this._view.pixelsToTime(this._view.getPointerPosition().x);
15199
+ Line.prototype.manageOrder = function (sources, startTime, endTime) {
15200
+ const firstSource = sources[0];
15201
+ const lastSource = sources[sources.length - 1];
15202
+ const cursorTime = this._view.pixelsToTime(this._view.getPointerPosition().x);
15203
+ var newStartTime = startTime;
15204
+ var newEndTime = endTime;
15227
15205
  var tmpTimes;
15228
- var sourceDuration = source.endTime - source.startTime;
15229
- if (newTimes.start !== null && newTimes.end !== null) {
15230
- if (this._sources[source.id].prevSourceId) {
15231
- var previousStartTime = this._sources[this._sources[source.id].prevSourceId].source.startTime;
15232
- if (cursorTime + this._view.getTimeOffset() < previousStartTime) {
15233
- tmpTimes = this._changeSourcePosition(source, sourceDuration, cursorTime + this._view.getTimeOffset());
15234
- if (tmpTimes) {
15235
- newTimes.start = tmpTimes.start;
15236
- newTimes.end = tmpTimes.end;
15206
+ var sourceDuration = Utils.roundTime(endTime - startTime);
15207
+ if (typeof newStartTime === 'number' && typeof newEndTime === 'number') {
15208
+ if (this._sources[firstSource.id].prevSourceId) {
15209
+ var previousStartTime = this._sources[this._sources[firstSource.id].prevSourceId].source.startTime;
15210
+ if (Utils.roundTime(cursorTime + this._view.getTimeOffset()) < previousStartTime) {
15211
+ tmpTimes = this._changeSourcesPosition(sources, sourceDuration, cursorTime + this._view.getTimeOffset());
15212
+ if (typeof tmpTimes.newStartTime === 'number' && typeof tmpTimes.newEndTime === 'number') {
15213
+ newStartTime = tmpTimes.newStartTime;
15214
+ newEndTime = tmpTimes.newEndTime;
15237
15215
  }
15238
15216
  }
15239
15217
  }
15240
- if (this._sources[source.id].nextSourceId) {
15241
- var nextEndTime = this._sources[this._sources[source.id].nextSourceId].source.endTime;
15242
- if (cursorTime + this._view.getTimeOffset() > nextEndTime) {
15243
- tmpTimes = this._changeSourcePosition(source, sourceDuration, cursorTime + this._view.getTimeOffset());
15244
- if (tmpTimes) {
15245
- newTimes.start = tmpTimes.start;
15246
- newTimes.end = tmpTimes.end;
15218
+ if (this._sources[lastSource.id].nextSourceId) {
15219
+ var nextEndTime = this._sources[this._sources[lastSource.id].nextSourceId].source.endTime;
15220
+ if (Utils.roundTime(cursorTime + this._view.getTimeOffset()) > nextEndTime) {
15221
+ tmpTimes = this._changeSourcesPosition(sources, sourceDuration, cursorTime + this._view.getTimeOffset());
15222
+ if (typeof tmpTimes.newStartTime === 'number' && typeof tmpTimes.newEndTime === 'number') {
15223
+ newStartTime = tmpTimes.newStartTime;
15224
+ newEndTime = tmpTimes.newEndTime;
15247
15225
  }
15248
15226
  }
15249
15227
  }
15250
15228
  }
15251
- if (newTimes.start) {
15252
- newTimes.start = Utils.roundTime(newTimes.start);
15253
- }
15254
- if (newTimes.end) {
15255
- newTimes.end = Utils.roundTime(newTimes.end);
15256
- }
15257
- return newTimes;
15229
+ return {
15230
+ newStartTime,
15231
+ newEndTime
15232
+ };
15258
15233
  };
15259
- Line.prototype._changeSourcePosition = function (source, sourceDuration, time) {
15260
- if (source.orderable && this._firstSourceId) {
15261
- var currentRange = {
15262
- start: null,
15263
- end: null
15264
- };
15265
- var startLimit = null;
15266
- var endLimit = null;
15267
- do {
15268
- if (!currentRange.end) {
15269
- currentRange.end = this._sources[this._firstSourceId];
15270
- } else {
15271
- currentRange.start = currentRange.end;
15272
- currentRange.end = this._sources[currentRange.start.nextSourceId];
15273
- }
15274
- if (currentRange.start) {
15275
- startLimit = currentRange.start.source.endTime;
15276
- } else {
15277
- startLimit = 0;
15278
- }
15279
- if (currentRange.end) {
15280
- endLimit = currentRange.end.source.startTime;
15281
- } else {
15282
- endLimit = null;
15283
- }
15284
- if (time > startLimit && (endLimit === null || time < endLimit)) {
15285
- var newTimes = this._canBePlacedBetween(time, time + sourceDuration, startLimit, endLimit);
15286
- if (newTimes) {
15287
- if (newTimes.start) {
15288
- newTimes.start = Utils.roundTime(newTimes.start);
15289
- }
15290
- if (newTimes.end) {
15291
- newTimes.end = Utils.roundTime(newTimes.end);
15292
- }
15293
- source.updateTimes(newTimes.start, newTimes.end);
15294
- var prevSourceId = currentRange.start ? currentRange.start.source.id : null;
15234
+ Line.prototype._changeSourcesPosition = function (sources, sourceDuration, time) {
15235
+ var currentRange = {
15236
+ start: null,
15237
+ end: null
15238
+ };
15239
+ var startLimit = null;
15240
+ var endLimit = null;
15241
+ let newStartTime, newEndTime;
15242
+ do {
15243
+ if (!currentRange.end) {
15244
+ currentRange.end = this._sources[this._firstSourceId];
15245
+ } else {
15246
+ currentRange.start = currentRange.end;
15247
+ currentRange.end = this._sources[currentRange.start.nextSourceId];
15248
+ }
15249
+ if (currentRange.start) {
15250
+ startLimit = currentRange.start.source.endTime;
15251
+ } else {
15252
+ startLimit = 0;
15253
+ }
15254
+ if (currentRange.end) {
15255
+ endLimit = currentRange.end.source.startTime;
15256
+ } else {
15257
+ endLimit = null;
15258
+ }
15259
+ if (time > startLimit && (endLimit === null || time < endLimit)) {
15260
+ ({newStartTime, newEndTime} = this._canBePlacedBetween(time, time + sourceDuration, startLimit, endLimit));
15261
+ if (typeof newStartTime === 'number' && typeof newEndTime === 'number') {
15262
+ let prevSourceId = currentRange.start ? currentRange.start.source.id : null;
15263
+ sources.forEach(function (source) {
15295
15264
  this._moveSource(this._sources[source.id].source, prevSourceId);
15296
- return newTimes;
15297
- }
15265
+ prevSourceId = source.id;
15266
+ }.bind(this));
15298
15267
  }
15299
- } while (currentRange.end);
15300
- }
15301
- return null;
15268
+ return {
15269
+ newStartTime,
15270
+ newEndTime
15271
+ };
15272
+ }
15273
+ } while (currentRange.end);
15274
+ return {
15275
+ newStartTime,
15276
+ newEndTime
15277
+ };
15302
15278
  };
15303
15279
  Line.prototype._moveSource = function (source, prevSourceId) {
15304
15280
  var sourceObj = this._sources[source.id];
@@ -15326,20 +15302,17 @@ module.exports = function (Konva, Utils) {
15326
15302
  }
15327
15303
  this._sources[source.id] = sourceObj;
15328
15304
  };
15329
- Line.prototype.manageCollision = function (source, newTimes) {
15330
- var originalStartTime = null;
15331
- var originalEndTime = null;
15332
- var newStartTime = null;
15333
- var newEndTime = null;
15305
+ Line.prototype.manageCollision = function (sources, newStartTime, newEndTime) {
15306
+ var originalStartTime = newStartTime;
15307
+ var originalEndTime = newEndTime;
15334
15308
  var startLimited = false;
15335
15309
  var endLimited = false;
15336
- newTimes.updateTimelineLength = false;
15337
- if (newTimes.start !== null) {
15338
- originalStartTime = newTimes.start;
15339
- newStartTime = originalStartTime;
15340
- if (source.startTime > newStartTime) {
15341
- if (this._sources[source.id].prevSourceId) {
15342
- var previousSource = this._sources[this._sources[source.id].prevSourceId].source;
15310
+ const firstSource = sources[0];
15311
+ const lastSource = sources[sources.length - 1];
15312
+ if (typeof newStartTime === 'number') {
15313
+ if (firstSource.startTime > newStartTime) {
15314
+ if (this._sources[firstSource.id].prevSourceId) {
15315
+ var previousSource = this._sources[this._sources[firstSource.id].prevSourceId].source;
15343
15316
  if (newStartTime < previousSource.endTime) {
15344
15317
  newStartTime = previousSource.endTime;
15345
15318
  startLimited = true;
@@ -15352,12 +15325,10 @@ module.exports = function (Konva, Utils) {
15352
15325
  }
15353
15326
  }
15354
15327
  }
15355
- if (newTimes.end !== null) {
15356
- originalEndTime = newTimes.end;
15357
- newEndTime = originalEndTime;
15358
- if (source.endTime < newEndTime) {
15359
- if (this._sources[source.id].nextSourceId) {
15360
- var nextSource = this._sources[this._sources[source.id].nextSourceId].source;
15328
+ if (typeof newEndTime === 'number') {
15329
+ if (lastSource.endTime < newEndTime) {
15330
+ if (this._sources[lastSource.id].nextSourceId) {
15331
+ var nextSource = this._sources[this._sources[lastSource.id].nextSourceId].source;
15361
15332
  if (newEndTime > nextSource.startTime) {
15362
15333
  newEndTime = nextSource.startTime;
15363
15334
  endLimited = true;
@@ -15365,7 +15336,7 @@ module.exports = function (Konva, Utils) {
15365
15336
  }
15366
15337
  }
15367
15338
  }
15368
- if (newStartTime !== null && newEndTime !== null) {
15339
+ if (typeof newStartTime === 'number' && typeof newEndTime === 'number') {
15369
15340
  var timeWidth = originalEndTime - originalStartTime;
15370
15341
  if (startLimited) {
15371
15342
  newEndTime = Utils.roundTime(newStartTime + timeWidth);
@@ -15374,34 +15345,28 @@ module.exports = function (Konva, Utils) {
15374
15345
  newStartTime = Utils.roundTime(newEndTime - timeWidth);
15375
15346
  }
15376
15347
  }
15377
- if (newStartTime !== null && newEndTime === null) {
15378
- if (Utils.roundTime(source.endTime - newStartTime) < source.minSize) {
15379
- newStartTime = Utils.roundTime(source.endTime - source.minSize);
15348
+ if (typeof newStartTime === 'number' && typeof newEndTime !== 'number') {
15349
+ if (Utils.roundTime(sources[0].endTime - newStartTime) < sources[0].minSize) {
15350
+ newStartTime = Utils.roundTime(sources[0].endTime - sources[0].minSize);
15380
15351
  }
15381
- } else if (newEndTime !== null && newStartTime === null) {
15382
- if (Utils.roundTime(newEndTime - source.startTime) < source.minSize) {
15383
- newEndTime = Utils.roundTime(source.startTime + source.minSize);
15352
+ } else if (typeof newEndTime === 'number' && typeof newStartTime !== 'number') {
15353
+ if (Utils.roundTime(newEndTime - sources[0].startTime) < sources[0].minSize) {
15354
+ newEndTime = Utils.roundTime(sources[0].startTime + sources[0].minSize);
15384
15355
  }
15385
15356
  } else {
15386
- if (Utils.roundTime(newEndTime - newStartTime) < source.minSize) {
15387
- if (source.endTime !== newEndTime) {
15388
- newEndTime = Utils.roundTime(newStartTime + source.minSize);
15357
+ if (Utils.roundTime(newEndTime - newStartTime) < sources[0].minSize) {
15358
+ if (sources[0].endTime !== newEndTime) {
15359
+ newEndTime = Utils.roundTime(newStartTime + sources[0].minSize);
15389
15360
  }
15390
- if (source.startTime !== newStartTime) {
15391
- newStartTime = Utils.roundTime(newEndTime - source.minSize);
15361
+ if (sources[0].startTime !== newStartTime) {
15362
+ newStartTime = Utils.roundTime(newEndTime - sources[0].minSize);
15392
15363
  }
15393
15364
  }
15394
15365
  }
15395
- if (newStartTime !== null && newStartTime !== originalStartTime) {
15396
- newTimes.start = newStartTime;
15397
- }
15398
- if (newEndTime !== null && newEndTime !== originalEndTime) {
15399
- newTimes.end = newEndTime;
15400
- if (this._sources[source.id].nextSourceId === null) {
15401
- newTimes.updateTimelineLength = true;
15402
- }
15403
- }
15404
- return newTimes;
15366
+ return {
15367
+ newStartTime,
15368
+ newEndTime
15369
+ };
15405
15370
  };
15406
15371
  Line.prototype.getSourcesAfter = function (time) {
15407
15372
  const sources = [];
@@ -15466,8 +15431,8 @@ module.exports = function (Konva, Utils) {
15466
15431
  this._group.listening(bool);
15467
15432
  };
15468
15433
  return Line;
15469
- }(_dereq_('konva'), _dereq_('./utils'));
15470
- },{"./utils":113,"konva":43}],93:[function(_dereq_,module,exports){
15434
+ }(_dereq_('./source-group'), _dereq_('konva'), _dereq_('./utils'));
15435
+ },{"./source-group":105,"./utils":113,"konva":43}],93:[function(_dereq_,module,exports){
15471
15436
  module.exports = function (SegmentsGroup, Line, LineIndicator, Utils) {
15472
15437
  'use strict';
15473
15438
  function Lines(peaks, view, layer) {
@@ -15486,8 +15451,9 @@ module.exports = function (SegmentsGroup, Line, LineIndicator, Utils) {
15486
15451
  this._lineId = 0;
15487
15452
  this._lineIndicator = new LineIndicator(peaks, view, document.getElementById('line-indicator-container'));
15488
15453
  this._peaks.on('line.heightChanged', this._onLineHeightChanged.bind(this));
15489
- this._peaks.on('line.add', this._onLineAdd.bind(this));
15490
15454
  this._peaks.on('line.remove', this._onLineRemove.bind(this));
15455
+ this._peaks.on('sources.show', this._onSourcesWrappingChanged.bind(this));
15456
+ this._peaks.on('sources.hide', this._onSourcesWrappingChanged.bind(this));
15491
15457
  this._peaks.on('segment.updated', this._onSegmentsUpdate.bind(this));
15492
15458
  this._peaks.on('segments.add', this._onSegmentsAdd.bind(this));
15493
15459
  this._peaks.on('segments.remove', this._onSegmentsRemove.bind(this));
@@ -15531,31 +15497,24 @@ module.exports = function (SegmentsGroup, Line, LineIndicator, Utils) {
15531
15497
  this._updateLinesPosition(position);
15532
15498
  this._view.updateTimeline();
15533
15499
  };
15534
- Lines.prototype._onLineAdd = function (position) {
15535
- this._createLine(position);
15536
- this._setInteractions(position);
15537
- this._updateLinesPosition(position);
15538
- };
15539
15500
  Lines.prototype._onLineRemove = function (position) {
15540
- this.removeLine(position);
15501
+ this._removeLine(position);
15541
15502
  this._updateLinesPosition(position);
15542
15503
  };
15543
- Lines.prototype.changeLineHeight = function (from, to) {
15544
- for (var position in this._linesByPosition) {
15545
- if (Utils.objectHasProperty(this._linesByPosition, position)) {
15546
- if (!this._linesByPosition[position].isSegmentsLine()) {
15547
- this._linesByPosition[position].changeHeight(from, to);
15548
- }
15504
+ Lines.prototype._onSourcesWrappingChanged = function (sources) {
15505
+ sources.forEach(function (source) {
15506
+ if (this._linesByPosition[source.position]) {
15507
+ this._linesByPosition[source.position].updateLineHeight(source, 'wrappingChanged');
15549
15508
  }
15550
- }
15509
+ }.bind(this));
15551
15510
  };
15552
- Lines.prototype.addSourceGroup = function (sourceGroup, position) {
15511
+ Lines.prototype.addSourceGroup = function (source, sourceGroup, position) {
15553
15512
  if (!this._linesByPosition[position] || this._linesByPosition[position].isSegmentsLine()) {
15554
15513
  this._createLine(position);
15555
15514
  this._setInteractions(position);
15556
15515
  }
15557
- sourceGroup.getSource().position = position;
15558
- this._linesByPosition[position].addSourceGroup(sourceGroup);
15516
+ source.position = position;
15517
+ this._linesByPosition[position].addSourceGroup(source, sourceGroup);
15559
15518
  };
15560
15519
  Lines.prototype.addSegments = function (lineId, position) {
15561
15520
  this._createLine(position);
@@ -15575,7 +15534,7 @@ module.exports = function (SegmentsGroup, Line, LineIndicator, Utils) {
15575
15534
  }
15576
15535
  return sourceGroup;
15577
15536
  };
15578
- Lines.prototype.removeLine = function (pos) {
15537
+ Lines.prototype._removeLine = function (pos) {
15579
15538
  var oldLine = this._linesByPosition[pos];
15580
15539
  var lineId = oldLine.getId();
15581
15540
  if (this._automaticallyCreatedLineId === lineId) {
@@ -15686,35 +15645,43 @@ module.exports = function (SegmentsGroup, Line, LineIndicator, Utils) {
15686
15645
  this._automaticLineCreationPosition = null;
15687
15646
  this._automaticallyCreatedLineId = null;
15688
15647
  };
15689
- Lines.prototype.manageAutomaticLineCreation = function (pos, source) {
15648
+ Lines.prototype.manageAutomaticLineCreation = function (newLinePosition, initialPosition, sources) {
15690
15649
  if (this._automaticallyCreatedLineId !== null) {
15691
15650
  return;
15692
- } else if (this._automaticLineCreationPosition !== null && this._automaticLineCreationPosition !== pos) {
15651
+ } else if (this._automaticLineCreationPosition !== null && this._automaticLineCreationPosition !== newLinePosition) {
15693
15652
  this.stopAutomaticLineCreation();
15694
- } else if (this._automaticLineCreationTimeout) {
15653
+ }
15654
+ if (this._automaticLineCreationTimeout) {
15695
15655
  return;
15696
15656
  }
15697
- this._automaticLineCreationPosition = pos;
15657
+ this._automaticLineCreationPosition = newLinePosition;
15698
15658
  this._automaticLineCreationTimeout = setTimeout(function () {
15699
15659
  this._automaticLineCreationTimeout = null;
15700
- this._automaticallyCreatedLineId = this._createLine(pos);
15701
- this._setInteractions(pos);
15702
- this.moveSourceToPosition(source, pos);
15660
+ var currentLine = this._linesByPosition[initialPosition];
15661
+ if (currentLine.countRemainingElements() === sources.length) {
15662
+ this.stopAutomaticLineCreation();
15663
+ return;
15664
+ }
15665
+ this._automaticallyCreatedLineId = this._createLine(newLinePosition);
15666
+ this._setInteractions(newLinePosition);
15667
+ this.moveSourcesToPosition(sources, currentLine.getPosition(), newLinePosition);
15703
15668
  }.bind(this), this._peaks.options.automaticLineCreationDelay);
15704
15669
  };
15705
- Lines.prototype.manageVerticalPosition = function (source, mouseX, mouseY) {
15706
- if (mouseY !== null && mouseY !== undefined) {
15707
- var linePos = this.getLinesUnderY(mouseY);
15708
- if (linePos[0] !== linePos[1]) {
15709
- this.manageAutomaticLineCreation(linePos[0] + 1, source);
15710
- } else {
15711
- this.stopAutomaticLineCreation();
15712
- if (mouseX !== null && mouseX !== undefined && linePos[0] !== source.position && !this._linesByPosition[linePos[0]].isSegmentsLine()) {
15713
- var mouseTime = this._view.pixelsToTime(mouseX + this._view.getFrameOffset());
15714
- var sourceDuration = Utils.roundTime(source.endTime - source.startTime);
15715
- if (this._hasSpaceForSourceAt(linePos[0], mouseTime, sourceDuration)) {
15716
- this.moveSourceToPosition(source, linePos[0]);
15717
- }
15670
+ Lines.prototype.manageVerticalPosition = function (sources, startTime, endTime, mouseX, mouseY) {
15671
+ if (mouseX === null || mouseX === undefined) {
15672
+ return;
15673
+ }
15674
+ const position = sources[0].position;
15675
+ const linePos = this.getLinesUnderY(mouseY);
15676
+ if (linePos[0] !== linePos[1]) {
15677
+ this.manageAutomaticLineCreation(linePos[0] + 1, position, sources);
15678
+ } else {
15679
+ this.stopAutomaticLineCreation();
15680
+ if (mouseX !== null && mouseX !== undefined && linePos[0] !== position && !this._linesByPosition[linePos[0]].isSegmentsLine()) {
15681
+ var mouseTime = this._view.pixelsToTime(mouseX + this._view.getFrameOffset());
15682
+ var sourceDuration = Utils.roundTime(endTime - startTime);
15683
+ if (this._hasSpaceForSourceAt(linePos[0], mouseTime, sourceDuration)) {
15684
+ this.moveSourcesToPosition(sources, position, linePos[0]);
15718
15685
  }
15719
15686
  }
15720
15687
  }
@@ -15761,11 +15728,15 @@ module.exports = function (SegmentsGroup, Line, LineIndicator, Utils) {
15761
15728
  }
15762
15729
  return pos;
15763
15730
  };
15764
- Lines.prototype.moveSourceToPosition = function (source, pos) {
15765
- var sourceGroup = this._linesByPosition[source.position].removeSourceGroup(source, true);
15766
- sourceGroup.moveTo(this._linesByPosition[pos].getKonvaGroup());
15767
- this._updateLinesPosition(source.position);
15768
- this.addSourceGroup(sourceGroup, pos);
15731
+ Lines.prototype.moveSourcesToPosition = function (sources, initialPosition, targetPosition) {
15732
+ sources.forEach(function (source) {
15733
+ var sourceGroup = this._linesByPosition[initialPosition].removeSourceGroup(source, true);
15734
+ if (sourceGroup) {
15735
+ sourceGroup.moveTo(this._linesByPosition[targetPosition].getKonvaGroup());
15736
+ }
15737
+ this.addSourceGroup(source, sourceGroup, targetPosition);
15738
+ }.bind(this));
15739
+ this._updateLinesPosition(initialPosition);
15769
15740
  };
15770
15741
  Lines.prototype._getNextLineId = function () {
15771
15742
  this._lineId++;
@@ -15808,11 +15779,11 @@ module.exports = function (SegmentsGroup, Line, LineIndicator, Utils) {
15808
15779
  }
15809
15780
  }
15810
15781
  };
15811
- Lines.prototype.manageCollision = function (source, newTimes) {
15812
- return this._linesByPosition[source.position].manageCollision(source, newTimes);
15782
+ Lines.prototype.manageCollision = function (sources, newStartTime, newEndTime) {
15783
+ return this._linesByPosition[sources[0].position].manageCollision(sources, newStartTime, newEndTime);
15813
15784
  };
15814
- Lines.prototype.manageSourceOrder = function (source, newTimes) {
15815
- return this._linesByPosition[source.position].manageSourceOrder(source, newTimes);
15785
+ Lines.prototype.manageOrder = function (sources, startTime, endTime) {
15786
+ return this._linesByPosition[sources[0].position].manageOrder(sources, startTime, endTime);
15816
15787
  };
15817
15788
  Lines.prototype._setInteractions = function (position) {
15818
15789
  var line = this._linesByPosition[position];
@@ -16144,11 +16115,6 @@ module.exports = function (Colors, EventEmitter, TimelineSegments, TimelineSourc
16144
16115
  Peaks.prototype._removeWindowResizeHandler = function () {
16145
16116
  window.removeEventListener('resize', this._onResize);
16146
16117
  };
16147
- Peaks.prototype.setLineHeight = function (newLineHeight) {
16148
- var oldHeight = this.options.lineHeight;
16149
- this.options.lineHeight = newLineHeight;
16150
- this.emit('options.set.line_height', oldHeight);
16151
- };
16152
16118
  Peaks.prototype.zoomIn = function () {
16153
16119
  this.view.setZoom(this.view.getTimeToPixelsScale() + Math.floor(this.view.getTimeToPixelsScale() / 10) + 1);
16154
16120
  };
@@ -17674,6 +17640,9 @@ module.exports = function (SegmentShape, Utils, Konva) {
17674
17640
  SegmentsGroup.prototype.isEmpty = function () {
17675
17641
  return Object.keys(this._segments).length === 0;
17676
17642
  };
17643
+ SegmentsGroup.prototype.countRemainingElements = function () {
17644
+ return Object.keys(this._segments).length;
17645
+ };
17677
17646
  SegmentsGroup.prototype.addToGroup = function (group) {
17678
17647
  group.add(this._group);
17679
17648
  };
@@ -18179,13 +18148,12 @@ module.exports = function (WaveformBuilder, WaveformShape, Utils, Loader, Konva)
18179
18148
  this._indicators = {};
18180
18149
  var self = this;
18181
18150
  this._x = this._view.timeToPixels(source.startTime);
18182
- this._roundedX = Math.round(this._x);
18183
18151
  this._width = this._view.timeToPixels(source.endTime - source.startTime);
18184
- this._roundedWidth = Math.round(this._width);
18185
- this._unwrappedHeight = source.binaryHeight && source.previewHeight ? source.binaryHeight + source.previewHeight : this._peaks.options.lineHeight;
18186
- this._wrappedHeight = this._peaks.options.wrappedLineHeight;
18152
+ var heights = SourceGroup.getHeights(source, peaks);
18153
+ this._unwrappedHeight = heights.unwrapped;
18154
+ this._wrappedHeight = heights.wrapped;
18155
+ this._height = heights.current;
18187
18156
  this._borderWidth = this._source.borderWidth || 0;
18188
- this._height = this._unwrappedHeight;
18189
18157
  this._currentTimeToPixelsScaleUsed = this._view.getTimeToPixelsScale();
18190
18158
  this._selected = this._source.selected;
18191
18159
  this._isDragged = false;
@@ -18278,11 +18246,10 @@ module.exports = function (WaveformBuilder, WaveformShape, Utils, Loader, Konva)
18278
18246
  const timeOffsetDiff = this._view.getTimeOffset() - this._initialTimeOffset;
18279
18247
  const {start, end} = this._initialTimes;
18280
18248
  this._view.updateWithAutoScroll(function () {
18281
- if (this._layer.updateSource(this._source, leftHandle ? start + diff + timeOffsetDiff : null, leftHandle ? null : end + diff + timeOffsetDiff)) {
18249
+ if (this._layer.manageSourceMovements([this._source], leftHandle ? start + diff + timeOffsetDiff : null, leftHandle ? null : end + diff + timeOffsetDiff)) {
18282
18250
  this._layer.draw();
18283
18251
  }
18284
18252
  }.bind(this));
18285
- this._view.setTimelineLength(this._view.timeToPixels(this._source.endTime) + this._view.getWidth());
18286
18253
  return {
18287
18254
  x: draggedElement.absolutePosition().x,
18288
18255
  y: draggedElement.absolutePosition().y
@@ -18295,11 +18262,9 @@ module.exports = function (WaveformBuilder, WaveformShape, Utils, Loader, Konva)
18295
18262
  const newTimeToPixelsScale = this._view.getTimeToPixelsScale();
18296
18263
  this._group.x(startPixel - frameOffset);
18297
18264
  this._x = startPixel;
18298
- this._roundedX = Math.round(this._x);
18299
18265
  const newWidth = endPixel - startPixel;
18300
18266
  if (newWidth !== this._width) {
18301
18267
  this._width = newWidth;
18302
- this._roundedWidth = Math.round(this._width);
18303
18268
  if (newTimeToPixelsScale !== this._currentTimeToPixelsScaleUsed) {
18304
18269
  this._currentTimeToPixelsScaleUsed = newTimeToPixelsScale;
18305
18270
  this._updateMarkers();
@@ -18350,9 +18315,11 @@ module.exports = function (WaveformBuilder, WaveformShape, Utils, Loader, Konva)
18350
18315
  start: this._source.startTime,
18351
18316
  end: this._source.endTime
18352
18317
  };
18318
+ this._isDragged = true;
18353
18319
  this._hideButtons();
18354
18320
  };
18355
18321
  SourceGroup.prototype._onHandleDragEnd = function () {
18322
+ this._isDragged = false;
18356
18323
  this._showButtons();
18357
18324
  };
18358
18325
  SourceGroup.prototype._addHandles = function (forceCreate) {
@@ -18434,43 +18401,45 @@ module.exports = function (WaveformBuilder, WaveformShape, Utils, Loader, Konva)
18434
18401
  };
18435
18402
  SourceGroup.prototype.drawSourceShape = function (ctx, shape, addBorderWidth, fill) {
18436
18403
  var offset = addBorderWidth ? this._borderWidth : 0;
18437
- var radius = this._source.borderRadius !== undefined && this._source.borderRadius !== null ? this._source.borderRadius : Math.max(1, Math.min(this._roundedWidth / 2, Math.min(CORNER_RADIUS, this._height / 2)));
18438
- var x = Math.max(0, this._view.getFrameOffset() - this._roundedX - radius);
18439
- var width = Math.min(this._roundedWidth - x, this._view.getWidth() + radius - Math.max(0, this._roundedX - this._view.getFrameOffset()));
18404
+ var radius = this._source.borderRadius !== undefined && this._source.borderRadius !== null ? this._source.borderRadius : Math.max(1, Math.min(this._width / 2, Math.min(CORNER_RADIUS, this._height / 2)));
18405
+ var x = Math.max(0, this._view.getFrameOffset() - this._x - 2 * radius);
18406
+ var width = Math.min(this._width - x, this._view.getWidth() + 4 * radius - Math.max(0, this._x - this._view.getFrameOffset()));
18440
18407
  var xWidth = x + width;
18441
- ctx.beginPath();
18442
- ctx.moveTo(x + radius, offset);
18443
- ctx.lineTo(xWidth - radius, offset);
18444
- ctx.quadraticCurveTo(xWidth - offset, offset, xWidth - offset, radius);
18445
- ctx.lineTo(xWidth - offset, this._height - radius);
18446
- ctx.quadraticCurveTo(xWidth - offset, this._height - offset, xWidth - radius, this._height - offset);
18447
- ctx.lineTo(x + radius, this._height - offset);
18448
- ctx.quadraticCurveTo(x + offset, this._height - offset, x + offset, this._height - radius);
18449
- ctx.lineTo(x + offset, radius);
18450
- ctx.quadraticCurveTo(x + offset, offset, x + radius, offset);
18451
- ctx.closePath();
18452
- if (fill) {
18453
- if (this._source.shouldShowWarning()) {
18454
- var gradient = ctx.createLinearGradient(0, 0, this._roundedWidth, 0);
18455
- if (this._source.mediaEndTime < this._source.duration) {
18456
- var rightStopPosition = Math.max(1 - this._source.warningWidth / this._roundedWidth, 0.5);
18457
- gradient.addColorStop(rightStopPosition, this._source.backgroundColor);
18458
- gradient.addColorStop(1, this._source.warningColor);
18459
- }
18460
- if (this._source.mediaStartTime > 0) {
18461
- var leftStopPosition = Math.min(this._source.warningWidth / this._roundedWidth, 0.5);
18462
- gradient.addColorStop(0, this._source.warningColor);
18463
- gradient.addColorStop(leftStopPosition, this._source.backgroundColor);
18408
+ if (width > 0) {
18409
+ ctx.beginPath();
18410
+ ctx.moveTo(x + radius, offset);
18411
+ ctx.lineTo(xWidth - radius, offset);
18412
+ ctx.quadraticCurveTo(xWidth - offset, offset, xWidth - offset, radius);
18413
+ ctx.lineTo(xWidth - offset, this._height - radius);
18414
+ ctx.quadraticCurveTo(xWidth - offset, this._height - offset, xWidth - radius, this._height - offset);
18415
+ ctx.lineTo(x + radius, this._height - offset);
18416
+ ctx.quadraticCurveTo(x + offset, this._height - offset, x + offset, this._height - radius);
18417
+ ctx.lineTo(x + offset, radius);
18418
+ ctx.quadraticCurveTo(x + offset, offset, x + radius, offset);
18419
+ ctx.closePath();
18420
+ if (fill) {
18421
+ if (this._source.shouldShowWarning()) {
18422
+ var gradient = ctx.createLinearGradient(0, 0, this._width, 0);
18423
+ if (this._source.mediaEndTime < this._source.duration) {
18424
+ var rightStopPosition = Math.max(1 - this._source.warningWidth / this._width, 0.5);
18425
+ gradient.addColorStop(rightStopPosition, this._source.backgroundColor);
18426
+ gradient.addColorStop(1, this._source.warningColor);
18427
+ }
18428
+ if (this._source.mediaStartTime > 0) {
18429
+ var leftStopPosition = Math.min(this._source.warningWidth / this._width, 0.5);
18430
+ gradient.addColorStop(0, this._source.warningColor);
18431
+ gradient.addColorStop(leftStopPosition, this._source.backgroundColor);
18432
+ }
18433
+ ctx.fillStyle = gradient;
18434
+ ctx.fill();
18435
+ } else {
18436
+ ctx.fillStyle = this._source.backgroundColor;
18437
+ ctx.fill();
18464
18438
  }
18465
- ctx.fillStyle = gradient;
18466
- ctx.fill();
18467
- } else {
18468
- ctx.fillStyle = this._source.backgroundColor;
18469
- ctx.fill();
18470
18439
  }
18471
- }
18472
- if (shape) {
18473
- ctx.fillStrokeShape(shape);
18440
+ if (shape) {
18441
+ ctx.fillStrokeShape(shape);
18442
+ }
18474
18443
  }
18475
18444
  };
18476
18445
  SourceGroup.prototype._addUnwrap = function (forceCreate) {
@@ -18984,6 +18953,13 @@ module.exports = function (WaveformBuilder, WaveformShape, Utils, Loader, Konva)
18984
18953
  SourceGroup.prototype.getCurrentHeight = function () {
18985
18954
  return this._height;
18986
18955
  };
18956
+ SourceGroup.prototype.getHeights = function () {
18957
+ return {
18958
+ unwrapped: this._unwrappedHeight,
18959
+ wrapped: this._wrappedHeight,
18960
+ current: this._height
18961
+ };
18962
+ };
18987
18963
  SourceGroup.prototype.setVisible = function (boolean) {
18988
18964
  this._group.visible(boolean);
18989
18965
  };
@@ -19366,6 +19342,16 @@ module.exports = function (WaveformBuilder, WaveformShape, Utils, Loader, Konva)
19366
19342
  }
19367
19343
  this._group.destroy();
19368
19344
  };
19345
+ SourceGroup.getHeights = function (source, peaks) {
19346
+ var unwrappedHeight = source.binaryHeight && source.previewHeight ? source.binaryHeight + source.previewHeight : peaks.options.lineHeight;
19347
+ var wrappedHeight = peaks.options.wrappedLineHeight;
19348
+ var height = source.wrapped ? wrappedHeight : unwrappedHeight;
19349
+ return {
19350
+ unwrapped: unwrappedHeight,
19351
+ wrapped: wrappedHeight,
19352
+ current: height
19353
+ };
19354
+ };
19369
19355
  return SourceGroup;
19370
19356
  }(_dereq_('./waveform-builder'), _dereq_('./waveform-shape'), _dereq_('./utils'), _dereq_('./loader'), _dereq_('konva'));
19371
19357
  },{"./loader":94,"./utils":113,"./waveform-builder":114,"./waveform-shape":115,"konva":43}],106:[function(_dereq_,module,exports){
@@ -20372,7 +20358,6 @@ module.exports = function (SourceGroup, Lines, DataRetriever, Utils, Invoker, Ko
20372
20358
  this._peaks.on('source.update', this._onSourceUpdate.bind(this));
20373
20359
  this._peaks.on('data.retrieved', this._onDataRetrieved.bind(this));
20374
20360
  this._peaks.on('segments.show', this._onSegmentsShow.bind(this));
20375
- this._peaks.on('options.set.line_height', this._onOptionsLineHeightChange.bind(this));
20376
20361
  this._peaks.on('source.setIndicators', this.setIndicators.bind(this));
20377
20362
  }
20378
20363
  SourcesLayer.prototype.fitToView = function () {
@@ -20399,23 +20384,6 @@ module.exports = function (SourceGroup, Lines, DataRetriever, Utils, Invoker, Ko
20399
20384
  SourcesLayer.prototype.isEditingEnabled = function () {
20400
20385
  return this._allowEditing;
20401
20386
  };
20402
- SourcesLayer.prototype._onOptionsLineHeightChange = function (oldHeight) {
20403
- var positions = [];
20404
- for (var sourceId in this._sourcesGroup) {
20405
- if (Utils.objectHasProperty(this._sourcesGroup, sourceId)) {
20406
- var source = this._sourcesGroup[sourceId].getSource();
20407
- if (!positions.includes(source.position)) {
20408
- this._lines.changeLineHeight(oldHeight, this._peaks.options.lineHeight);
20409
- positions.push(source.position);
20410
- }
20411
- this._removeSource(source);
20412
- this._addSourceGroup(source);
20413
- }
20414
- }
20415
- if (positions) {
20416
- this.refresh();
20417
- }
20418
- };
20419
20387
  SourcesLayer.prototype.refresh = function () {
20420
20388
  var frameOffset = this._view.getFrameOffset();
20421
20389
  var width = this._view.getWidth();
@@ -20449,13 +20417,6 @@ module.exports = function (SourceGroup, Lines, DataRetriever, Utils, Invoker, Ko
20449
20417
  }.bind(this));
20450
20418
  this.draw();
20451
20419
  };
20452
- SourcesLayer.prototype._onSourcesShow = function (sources) {
20453
- var self = this;
20454
- sources.forEach(function (source) {
20455
- self._sourcesGroup[source.id].setWrapping(false, true);
20456
- });
20457
- this._layer.draw();
20458
- };
20459
20420
  SourcesLayer.prototype._onSourcesAdd = function (sources) {
20460
20421
  var self = this;
20461
20422
  var frameOffset = self._view.getFrameOffset();
@@ -20525,7 +20486,7 @@ module.exports = function (SourceGroup, Lines, DataRetriever, Utils, Invoker, Ko
20525
20486
  SourcesLayer.prototype._addSourceGroup = function (source, startDataRetrieval = true) {
20526
20487
  var sourceGroup = this._createSourceGroup(source);
20527
20488
  this._sourcesGroup[source.id] = sourceGroup;
20528
- this._lines.addSourceGroup(sourceGroup, source.position);
20489
+ this._lines.addSourceGroup(source, sourceGroup, source.position);
20529
20490
  if (startDataRetrieval) {
20530
20491
  this._dataRetriever.retrieveData(source);
20531
20492
  }
@@ -20552,13 +20513,28 @@ module.exports = function (SourceGroup, Lines, DataRetriever, Utils, Invoker, Ko
20552
20513
  SourcesLayer.prototype.onSourcesGroupDragStart = function (element) {
20553
20514
  this._initialTimeOffset = this._view.getTimeOffset();
20554
20515
  this._mouseDownX = this._view.getPointerPosition().x;
20555
- this._activeElements = {};
20556
20516
  const draggedElementId = element.currentTarget.attrs.sourceId;
20557
- const shouldDragSelectedElements = Object.keys(this._view.getSelectedElements()).includes(draggedElementId);
20558
- this._nonSelectedElement = shouldDragSelectedElements ? null : [this._sourcesGroup[draggedElementId].getSource()];
20517
+ var selectedElements = this._view.getSelectedElements();
20518
+ const shouldDragSelectedElements = Object.keys(selectedElements).includes(draggedElementId);
20519
+ if (shouldDragSelectedElements) {
20520
+ this._draggedElements = Object.values(selectedElements).sort((a, b) => a.startTime - b.startTime);
20521
+ } else {
20522
+ this._draggedElements = [this._sourcesGroup[draggedElementId].getSource()];
20523
+ this._view.deselectAll();
20524
+ }
20525
+ this._draggedElementsData = this._draggedElements.reduce(function (bounds, source) {
20526
+ bounds.initialStartTime = Math.min(source.startTime, bounds.initialStartTime);
20527
+ bounds.initialEndTime = Math.max(source.endTime, bounds.initialEndTime);
20528
+ bounds.orderable = source.orderable && bounds.orderable;
20529
+ return bounds;
20530
+ }, {
20531
+ initialStartTime: Infinity,
20532
+ initialEndTime: -Infinity,
20533
+ orderable: true
20534
+ });
20559
20535
  };
20560
20536
  SourcesLayer.prototype.onSourcesGroupDragEnd = function () {
20561
- const updatedSources = (this._nonSelectedElement || Object.values(this._view.getSelectedElements())).map(function (source) {
20537
+ const updatedSources = this._draggedElements.map(function (source) {
20562
20538
  const sourceGroup = this._sourcesGroup[source.id];
20563
20539
  if (sourceGroup) {
20564
20540
  sourceGroup.prepareDragEnd();
@@ -20567,7 +20543,6 @@ module.exports = function (SourceGroup, Lines, DataRetriever, Utils, Invoker, Ko
20567
20543
  }.bind(this));
20568
20544
  this._view.drawSourcesLayer();
20569
20545
  this._view.updateTimelineLength();
20570
- this._activeElements = {};
20571
20546
  this._peaks.emit('sources.updated', updatedSources);
20572
20547
  };
20573
20548
  SourcesLayer.prototype.onSourcesGroupDrag = function (draggedElement) {
@@ -20579,27 +20554,15 @@ module.exports = function (SourceGroup, Lines, DataRetriever, Utils, Invoker, Ko
20579
20554
  };
20580
20555
  SourcesLayer.prototype._dragSourcesGroup = function () {
20581
20556
  var mousePos = Math.min(this._view.getWidth() - this._peaks.options.autoScrollThreshold * this._view.getWidth(), Math.max(0, this._view.getPointerPosition().x));
20582
- const diff = this._view.pixelsToTime(mousePos - this._mouseDownX);
20557
+ const timeDiff = this._view.pixelsToTime(mousePos - this._mouseDownX);
20583
20558
  const timeOffsetDiff = this._view.getTimeOffset() - this._initialTimeOffset;
20584
20559
  const mousePosX = this._view.getPointerPosition().x;
20585
20560
  const mousePosY = this._view.getPointerPosition().y;
20586
- var newEnd = 0;
20587
- var shouldRedraw = false;
20588
- (this._nonSelectedElement || Object.values(this._view.getSelectedElements())).forEach(function (source) {
20589
- if (!this._activeElements[source.id]) {
20590
- this._activeElements[source.id] = {
20591
- initialStartTime: source.startTime,
20592
- initialEndTime: source.endTime
20593
- };
20594
- }
20595
- const {initialStartTime, initialEndTime} = this._activeElements[source.id];
20596
- newEnd = Math.max(newEnd, source.endTime);
20597
- shouldRedraw = this.updateSource(source, initialStartTime + diff + timeOffsetDiff, initialEndTime + diff + timeOffsetDiff, mousePosX, mousePosY) || shouldRedraw;
20598
- }.bind(this));
20561
+ const {initialStartTime, initialEndTime, orderable} = this._draggedElementsData;
20562
+ const shouldRedraw = this.manageSourceMovements(this._draggedElements, initialStartTime + timeOffsetDiff + timeDiff, initialEndTime + timeOffsetDiff + timeDiff, orderable, mousePosX, mousePosY);
20599
20563
  if (shouldRedraw) {
20600
20564
  this.draw();
20601
20565
  }
20602
- this._view.setTimelineLength(this._view.timeToPixels(newEnd) + this._view.getWidth());
20603
20566
  };
20604
20567
  SourcesLayer.prototype.findSources = function (startTime, endTime) {
20605
20568
  var sources = this._peaks.sources.find(startTime, endTime);
@@ -20608,31 +20571,41 @@ module.exports = function (SourceGroup, Lines, DataRetriever, Utils, Invoker, Ko
20608
20571
  return positions[source.position];
20609
20572
  });
20610
20573
  };
20611
- SourcesLayer.prototype.updateSource = function (source, startTime, endTime, mouseX, mouseY) {
20612
- var newTimes = {
20613
- start: startTime,
20614
- end: endTime
20615
- };
20616
- if (this._peaks.options.canMoveSourcesBetweenLines) {
20617
- this.manageVerticalPosition(source, mouseX, mouseY);
20618
- }
20619
- newTimes = this.manageSourceOrder(source, newTimes);
20620
- newTimes = this.manageCollision(source, newTimes);
20621
- source.updateTimes(newTimes.start, newTimes.end);
20622
- if (newTimes) {
20623
- this._updateSource(source);
20624
- return true;
20574
+ SourcesLayer.prototype._applyTimeChangesToSources = function (sources, initialStartTime, newStartTime, newEndTime) {
20575
+ if (sources.length === 1) {
20576
+ sources[0].updateTimes(newStartTime, newEndTime);
20577
+ } else {
20578
+ const timeDiff = Utils.roundTime(newStartTime - initialStartTime);
20579
+ if (timeDiff !== 0) {
20580
+ sources.forEach(function (source) {
20581
+ source.updateTimes(Utils.roundTime(source.startTime + timeDiff), Utils.roundTime(source.endTime + timeDiff));
20582
+ });
20583
+ }
20625
20584
  }
20626
- return false;
20585
+ this.refresh();
20586
+ };
20587
+ SourcesLayer.prototype.manageSourceMovements = function (sources, newStartTime, newEndTime, orderable, mouseX, mouseY) {
20588
+ newStartTime = typeof newStartTime === 'number' ? Utils.roundTime(newStartTime) : newStartTime;
20589
+ newEndTime = typeof newEndTime === 'number' ? Utils.roundTime(newEndTime) : newEndTime;
20590
+ if (this._peaks.options.canMoveSourcesBetweenLines && typeof mouseY === 'number') {
20591
+ this.manageVerticalPosition(sources, newStartTime, newEndTime, mouseX, mouseY);
20592
+ }
20593
+ if (orderable) {
20594
+ ({newStartTime, newEndTime} = this.manageOrder(sources, newStartTime, newEndTime));
20595
+ }
20596
+ ({newStartTime, newEndTime} = this.manageCollision(sources, newStartTime, newEndTime));
20597
+ this._applyTimeChangesToSources(sources, sources[0].startTime, newStartTime, newEndTime);
20598
+ this._view.setTimelineLength(this._view.timeToPixels(sources[sources.length - 1].endTime) + this._view.getWidth());
20599
+ return true;
20627
20600
  };
20628
- SourcesLayer.prototype.manageVerticalPosition = function (source, mouseX, mouseY) {
20629
- return this._lines.manageVerticalPosition(source, mouseX, mouseY);
20601
+ SourcesLayer.prototype.manageVerticalPosition = function (sources, startTime, endTime, mouseX, mouseY) {
20602
+ return this._lines.manageVerticalPosition(sources, startTime, endTime, mouseX, mouseY);
20630
20603
  };
20631
- SourcesLayer.prototype.manageSourceOrder = function (source, newTimes) {
20632
- return this._lines.manageSourceOrder(source, newTimes);
20604
+ SourcesLayer.prototype.manageOrder = function (sources, startTime, endTime) {
20605
+ return this._lines.manageOrder(sources, startTime, endTime);
20633
20606
  };
20634
- SourcesLayer.prototype.manageCollision = function (source, newTimes) {
20635
- return this._lines.manageCollision(source, newTimes);
20607
+ SourcesLayer.prototype.manageCollision = function (sources, newStartTime, newEndTime) {
20608
+ return this._lines.manageCollision(sources, newStartTime, newEndTime);
20636
20609
  };
20637
20610
  SourcesLayer.prototype._updateSource = function (source) {
20638
20611
  var sourceGroup = this._findOrAddSourceGroup(source);
@@ -20767,7 +20740,6 @@ module.exports = function (SourceGroup, Lines, DataRetriever, Utils, Invoker, Ko
20767
20740
  this._peaks.off('source.update', this._onSourceUpdate);
20768
20741
  this._peaks.off('data.retrieved', this._onDataRetrieved);
20769
20742
  this._peaks.off('segments.show', this._onSegmentsShow);
20770
- this._peaks.off('options.set.line_height', this._onOptionsLineHeightChange);
20771
20743
  this._peaks.off('source.setIndicators', this.setIndicators);
20772
20744
  };
20773
20745
  SourcesLayer.prototype.getHeight = function () {
@@ -21324,10 +21296,16 @@ module.exports = function (Source, Utils) {
21324
21296
  }, shouldBlockEvent);
21325
21297
  };
21326
21298
  TimelineSources.prototype.showById = function (sourceId) {
21299
+ if (this._sourcesById[sourceId].wrapped === false) {
21300
+ return;
21301
+ }
21327
21302
  this._sourcesById[sourceId].wrapped = false;
21328
21303
  this._peaks.emit('sources.show', [this._sourcesById[sourceId]]);
21329
21304
  };
21330
21305
  TimelineSources.prototype.hideById = function (sourceId) {
21306
+ if (this._sourcesById[sourceId].wrapped === true) {
21307
+ return;
21308
+ }
21331
21309
  this._sourcesById[sourceId].wrapped = true;
21332
21310
  this._peaks.emit('sources.hide', [this._sourcesById[sourceId]]);
21333
21311
  };