@checksub_team/peaks_timeline 2.0.0-alpha.13 → 2.0.0-alpha.14

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.13",
3
+ "version": "2.0.0-alpha.14",
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
@@ -15502,11 +15502,18 @@ module.exports = function (SegmentsGroup, LineGroup, LineIndicator, Utils) {
15502
15502
  this._automaticLineCreationPosition = newLinePosition;
15503
15503
  this._automaticLineCreationTimeout = setTimeout(function () {
15504
15504
  this._automaticLineCreationTimeout = null;
15505
- var currentLine = this._lineGroupsByPosition[initialPosition];
15505
+ const currentLine = this._lineGroupsByPosition[initialPosition];
15506
15506
  sources = sources.filter(function (source) {
15507
15507
  return currentLine.hasSource(source.id);
15508
15508
  });
15509
- if (sources.length === 0 || sources.length === currentLine.countRemainingElements()) {
15509
+ if (sources.length === 0) {
15510
+ this.stopAutomaticLineCreation();
15511
+ return;
15512
+ }
15513
+ const posAround = this.getLinesAroundPos(currentLine.getPosition());
15514
+ const targetPosIsJustBefore = newLinePosition <= currentLine.getPosition() && newLinePosition > posAround[0];
15515
+ const targetPosIsJustAfter = newLinePosition >= currentLine.getPosition() && newLinePosition <= posAround[1];
15516
+ if (sources.length === currentLine.countRemainingElements() && (targetPosIsJustBefore || targetPosIsJustAfter)) {
15510
15517
  this.stopAutomaticLineCreation();
15511
15518
  return;
15512
15519
  }
@@ -15583,6 +15590,24 @@ module.exports = function (SegmentsGroup, LineGroup, LineIndicator, Utils) {
15583
15590
  }
15584
15591
  return pos;
15585
15592
  };
15593
+ LineGroups.prototype.getLinesAroundPos = function (pos) {
15594
+ var returnPos = [
15595
+ -1,
15596
+ this.getLastPosition() + 1
15597
+ ];
15598
+ for (var position in this._lineGroupsByPosition) {
15599
+ if (Utils.objectHasProperty(this._lineGroupsByPosition, position)) {
15600
+ var p = parseInt(position, 10);
15601
+ if (p < pos) {
15602
+ returnPos[0] = p;
15603
+ } else if (p > pos) {
15604
+ returnPos[1] = p;
15605
+ break;
15606
+ }
15607
+ }
15608
+ }
15609
+ return returnPos;
15610
+ };
15586
15611
  LineGroups.prototype._moveSourcesToPositionIfPossible = function (sources, targetPosition, targetTime, sourcesDuration) {
15587
15612
  const lineGroup = this._lineGroupsByPosition[targetPosition];
15588
15613
  if (!lineGroup || lineGroup.isSegmentsLine()) {
@@ -298,13 +298,25 @@ define([
298
298
  this._automaticLineCreationTimeout = setTimeout(function() {
299
299
  this._automaticLineCreationTimeout = null;
300
300
 
301
- var currentLine = this._lineGroupsByPosition[initialPosition];
301
+ const currentLine = this._lineGroupsByPosition[initialPosition];
302
302
 
303
303
  sources = sources.filter(function(source) {
304
304
  return currentLine.hasSource(source.id);
305
305
  });
306
306
 
307
- if (sources.length === 0 || sources.length === currentLine.countRemainingElements()) {
307
+ if (sources.length === 0) {
308
+ this.stopAutomaticLineCreation();
309
+ return;
310
+ }
311
+
312
+ const posAround = this.getLinesAroundPos(currentLine.getPosition());
313
+ const targetPosIsJustBefore = newLinePosition <= currentLine.getPosition() && newLinePosition > posAround[0];
314
+ const targetPosIsJustAfter = newLinePosition >= currentLine.getPosition() && newLinePosition <= posAround[1];
315
+
316
+ if (
317
+ sources.length === currentLine.countRemainingElements() &&
318
+ (targetPosIsJustBefore || targetPosIsJustAfter)
319
+ ) {
308
320
  this.stopAutomaticLineCreation();
309
321
  return;
310
322
  }
@@ -409,6 +421,26 @@ define([
409
421
  return pos;
410
422
  };
411
423
 
424
+ LineGroups.prototype.getLinesAroundPos = function(pos) {
425
+ var returnPos = [-1, this.getLastPosition() + 1];
426
+
427
+ for (var position in this._lineGroupsByPosition) {
428
+ if (Utils.objectHasProperty(this._lineGroupsByPosition, position)) {
429
+ var p = parseInt(position, 10);
430
+
431
+ if (p < pos) {
432
+ returnPos[0] = p;
433
+ }
434
+ else if (p > pos) {
435
+ returnPos[1] = p;
436
+ break;
437
+ }
438
+ }
439
+ }
440
+
441
+ return returnPos;
442
+ };
443
+
412
444
  LineGroups.prototype._moveSourcesToPositionIfPossible = function(sources, targetPosition, targetTime,
413
445
  sourcesDuration
414
446
  ) {