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

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.15",
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
@@ -15325,6 +15325,7 @@ module.exports = function (SegmentsGroup, LineGroup, LineIndicator, Utils) {
15325
15325
  this._peaks.on('main.allowInteractions', this.allowInteractions.bind(this));
15326
15326
  this._peaks.on('line.heightChanged', this._onLineHeightChanged.bind(this));
15327
15327
  this._peaks.on('segments.dragend', this._onSegmentUpdated.bind(this));
15328
+ this._peaks.on('lineIndicator.drag', this._onIndicatorDrag.bind(this));
15328
15329
  }
15329
15330
  LineGroups.prototype.fitToView = function () {
15330
15331
  this._lineIndicator.fitToView();
@@ -15502,11 +15503,18 @@ module.exports = function (SegmentsGroup, LineGroup, LineIndicator, Utils) {
15502
15503
  this._automaticLineCreationPosition = newLinePosition;
15503
15504
  this._automaticLineCreationTimeout = setTimeout(function () {
15504
15505
  this._automaticLineCreationTimeout = null;
15505
- var currentLine = this._lineGroupsByPosition[initialPosition];
15506
+ const currentLine = this._lineGroupsByPosition[initialPosition];
15506
15507
  sources = sources.filter(function (source) {
15507
15508
  return currentLine.hasSource(source.id);
15508
15509
  });
15509
- if (sources.length === 0 || sources.length === currentLine.countRemainingElements()) {
15510
+ if (sources.length === 0) {
15511
+ this.stopAutomaticLineCreation();
15512
+ return;
15513
+ }
15514
+ const posAround = this.getLinesAroundPos(currentLine.getPosition());
15515
+ const targetPosIsJustBefore = newLinePosition <= currentLine.getPosition() && newLinePosition > posAround[0];
15516
+ const targetPosIsJustAfter = newLinePosition >= currentLine.getPosition() && newLinePosition <= posAround[1];
15517
+ if (sources.length === currentLine.countRemainingElements() && (targetPosIsJustBefore || targetPosIsJustAfter)) {
15510
15518
  this.stopAutomaticLineCreation();
15511
15519
  return;
15512
15520
  }
@@ -15583,6 +15591,24 @@ module.exports = function (SegmentsGroup, LineGroup, LineIndicator, Utils) {
15583
15591
  }
15584
15592
  return pos;
15585
15593
  };
15594
+ LineGroups.prototype.getLinesAroundPos = function (pos) {
15595
+ var returnPos = [
15596
+ -1,
15597
+ this.getLastPosition() + 1
15598
+ ];
15599
+ for (var position in this._lineGroupsByPosition) {
15600
+ if (Utils.objectHasProperty(this._lineGroupsByPosition, position)) {
15601
+ var p = parseInt(position, 10);
15602
+ if (p < pos) {
15603
+ returnPos[0] = p;
15604
+ } else if (p > pos) {
15605
+ returnPos[1] = p;
15606
+ break;
15607
+ }
15608
+ }
15609
+ }
15610
+ return returnPos;
15611
+ };
15586
15612
  LineGroups.prototype._moveSourcesToPositionIfPossible = function (sources, targetPosition, targetTime, sourcesDuration) {
15587
15613
  const lineGroup = this._lineGroupsByPosition[targetPosition];
15588
15614
  if (!lineGroup || lineGroup.isSegmentsLine()) {
@@ -15667,6 +15693,30 @@ module.exports = function (SegmentsGroup, LineGroup, LineIndicator, Utils) {
15667
15693
  this.refreshLineYs();
15668
15694
  return line.id;
15669
15695
  };
15696
+ LineGroups.prototype._onIndicatorDrag = function (lineId, y) {
15697
+ const lineGroup = this._lineGroupsById[lineId];
15698
+ if (!lineGroup) {
15699
+ return;
15700
+ }
15701
+ const positions = this.getLinesUnderY(y);
15702
+ if (positions[0] !== positions[1] || positions[0] === lineGroup.getPosition()) {
15703
+ return;
15704
+ }
15705
+ const targetPos = positions[0];
15706
+ const targetLineGroup = this._lineGroupsByPosition[targetPos];
15707
+ const targetCenterY = targetLineGroup.y() + targetLineGroup.lineHeight() / 2;
15708
+ const movingDown = targetPos > lineGroup.getPosition();
15709
+ if (movingDown && y < targetCenterY || !movingDown && y > targetCenterY) {
15710
+ return;
15711
+ }
15712
+ if (targetPos === lineGroup.getPosition() + 1) {
15713
+ this._setLinePosition(targetLineGroup.getId(), lineGroup.getPosition());
15714
+ } else {
15715
+ this._setLinePosition(lineId, targetPos);
15716
+ }
15717
+ this.refreshLineYs();
15718
+ this._peaks.emit('line.moved', lineGroup.getLine());
15719
+ };
15670
15720
  LineGroups.prototype.updateSegments = function (frameStartTime, frameEndTime) {
15671
15721
  for (var lineId in this._segmentsGroups) {
15672
15722
  if (Utils.objectHasProperty(this._segmentsGroups, lineId)) {
@@ -15751,6 +15801,11 @@ module.exports = function (Konva, SVGs, Utils) {
15751
15801
  });
15752
15802
  this._layer.add(this._separatingLine);
15753
15803
  this._layer.draw();
15804
+ this._isDragging = false;
15805
+ this._dragLineId = null;
15806
+ this._dragContainerRect = null;
15807
+ this._onWindowMove = this._onWindowMove.bind(this);
15808
+ this._onWindowUp = this._onWindowUp.bind(this);
15754
15809
  }
15755
15810
  LineIndicator.prototype.fitToView = function () {
15756
15811
  this._height = this._view.getHeight();
@@ -15838,11 +15893,22 @@ module.exports = function (Konva, SVGs, Utils) {
15838
15893
  child.fill(child.getAttr('defaultColor'));
15839
15894
  });
15840
15895
  self.draw();
15841
- self._stage.container().style.cursor = 'default';
15896
+ if (!self._isDragging) {
15897
+ self._stage.container().style.cursor = 'default';
15898
+ }
15842
15899
  });
15843
15900
  indicator.on('click', function (e) {
15844
15901
  self._peaks.emit('lineIndicator.click', self._indicators[lineGroup.getId()], e.evt);
15845
15902
  });
15903
+ indicator.on('mousedown touchstart', function () {
15904
+ self._dragLineId = lineGroup.getId();
15905
+ self._dragContainerRect = self._stage.getContainer().getBoundingClientRect();
15906
+ window.addEventListener('mousemove', self._onWindowMove, false);
15907
+ window.addEventListener('touchmove', self._onWindowMove, false);
15908
+ window.addEventListener('mouseup', self._onWindowUp, false);
15909
+ window.addEventListener('touchend', self._onWindowUp, false);
15910
+ window.addEventListener('blur', self._onWindowUp, false);
15911
+ });
15846
15912
  return indicator;
15847
15913
  };
15848
15914
  LineIndicator.prototype.addIndicator = function (lineGroup) {
@@ -15928,6 +15994,33 @@ module.exports = function (Konva, SVGs, Utils) {
15928
15994
  LineIndicator.prototype.draw = function () {
15929
15995
  this._layer.draw();
15930
15996
  };
15997
+ LineIndicator.prototype._onWindowMove = function (event) {
15998
+ if (!this._dragContainerRect) {
15999
+ return;
16000
+ }
16001
+ if (!this._isDragging) {
16002
+ this._stage.container().style.cursor = 'grabbing';
16003
+ }
16004
+ var clientY;
16005
+ if (event.type === 'touchmove') {
16006
+ clientY = Math.floor(event.changedTouches[0].clientY);
16007
+ } else {
16008
+ clientY = event.clientY;
16009
+ }
16010
+ const relY = clientY - this._dragContainerRect.top;
16011
+ this._peaks.emit('lineIndicator.drag', this._dragLineId, relY);
16012
+ };
16013
+ LineIndicator.prototype._onWindowUp = function () {
16014
+ window.removeEventListener('mousemove', this._onWindowMove, false);
16015
+ window.removeEventListener('touchmove', this._onWindowMove, false);
16016
+ window.removeEventListener('mouseup', this._onWindowUp, false);
16017
+ window.removeEventListener('touchend', this._onWindowUp, false);
16018
+ window.removeEventListener('blur', this._onWindowUp, false);
16019
+ this._isDragging = false;
16020
+ this._dragLineId = null;
16021
+ this._dragContainerRect = null;
16022
+ this._stage.container().style.cursor = 'pointer';
16023
+ };
15931
16024
  return LineIndicator;
15932
16025
  }(_dereq_('konva'), _dereq_('./svgs'), _dereq_('../utils'));
15933
16026
  },{"../utils":116,"./svgs":104,"konva":43}],94:[function(_dereq_,module,exports){
@@ -61,6 +61,8 @@ define([
61
61
  this._peaks.on('line.heightChanged', this._onLineHeightChanged.bind(this));
62
62
 
63
63
  this._peaks.on('segments.dragend', this._onSegmentUpdated.bind(this));
64
+
65
+ this._peaks.on('lineIndicator.drag', this._onIndicatorDrag.bind(this));
64
66
  }
65
67
 
66
68
  LineGroups.prototype.fitToView = function() {
@@ -298,13 +300,25 @@ define([
298
300
  this._automaticLineCreationTimeout = setTimeout(function() {
299
301
  this._automaticLineCreationTimeout = null;
300
302
 
301
- var currentLine = this._lineGroupsByPosition[initialPosition];
303
+ const currentLine = this._lineGroupsByPosition[initialPosition];
302
304
 
303
305
  sources = sources.filter(function(source) {
304
306
  return currentLine.hasSource(source.id);
305
307
  });
306
308
 
307
- if (sources.length === 0 || sources.length === currentLine.countRemainingElements()) {
309
+ if (sources.length === 0) {
310
+ this.stopAutomaticLineCreation();
311
+ return;
312
+ }
313
+
314
+ const posAround = this.getLinesAroundPos(currentLine.getPosition());
315
+ const targetPosIsJustBefore = newLinePosition <= currentLine.getPosition() && newLinePosition > posAround[0];
316
+ const targetPosIsJustAfter = newLinePosition >= currentLine.getPosition() && newLinePosition <= posAround[1];
317
+
318
+ if (
319
+ sources.length === currentLine.countRemainingElements() &&
320
+ (targetPosIsJustBefore || targetPosIsJustAfter)
321
+ ) {
308
322
  this.stopAutomaticLineCreation();
309
323
  return;
310
324
  }
@@ -409,6 +423,26 @@ define([
409
423
  return pos;
410
424
  };
411
425
 
426
+ LineGroups.prototype.getLinesAroundPos = function(pos) {
427
+ var returnPos = [-1, this.getLastPosition() + 1];
428
+
429
+ for (var position in this._lineGroupsByPosition) {
430
+ if (Utils.objectHasProperty(this._lineGroupsByPosition, position)) {
431
+ var p = parseInt(position, 10);
432
+
433
+ if (p < pos) {
434
+ returnPos[0] = p;
435
+ }
436
+ else if (p > pos) {
437
+ returnPos[1] = p;
438
+ break;
439
+ }
440
+ }
441
+ }
442
+
443
+ return returnPos;
444
+ };
445
+
412
446
  LineGroups.prototype._moveSourcesToPositionIfPossible = function(sources, targetPosition, targetTime,
413
447
  sourcesDuration
414
448
  ) {
@@ -531,6 +565,40 @@ define([
531
565
  return line.id;
532
566
  };
533
567
 
568
+ LineGroups.prototype._onIndicatorDrag = function(lineId, y) {
569
+ const lineGroup = this._lineGroupsById[lineId];
570
+
571
+ if (!lineGroup) {
572
+ return;
573
+ }
574
+
575
+ const positions = this.getLinesUnderY(y);
576
+
577
+ if (positions[0] !== positions[1] || positions[0] === lineGroup.getPosition()) {
578
+ return;
579
+ }
580
+
581
+ const targetPos = positions[0];
582
+ const targetLineGroup = this._lineGroupsByPosition[targetPos];
583
+ const targetCenterY = targetLineGroup.y() + (targetLineGroup.lineHeight() / 2);
584
+ const movingDown = targetPos > lineGroup.getPosition();
585
+
586
+ if ((movingDown && y < targetCenterY) || (!movingDown && y > targetCenterY)) {
587
+ return;
588
+ }
589
+
590
+ if (targetPos === lineGroup.getPosition() + 1) {
591
+ this._setLinePosition(targetLineGroup.getId(), lineGroup.getPosition());
592
+ }
593
+ else {
594
+ this._setLinePosition(lineId, targetPos);
595
+ }
596
+
597
+ this.refreshLineYs();
598
+
599
+ this._peaks.emit('line.moved', lineGroup.getLine());
600
+ };
601
+
534
602
  LineGroups.prototype.updateSegments = function(frameStartTime, frameEndTime) {
535
603
  for (var lineId in this._segmentsGroups) {
536
604
  if (Utils.objectHasProperty(this._segmentsGroups, lineId)) {
@@ -69,6 +69,13 @@ define([
69
69
  this._layer.add(this._separatingLine);
70
70
 
71
71
  this._layer.draw();
72
+
73
+ this._isDragging = false;
74
+ this._dragLineId = null;
75
+ this._dragContainerRect = null;
76
+
77
+ this._onWindowMove = this._onWindowMove.bind(this);
78
+ this._onWindowUp = this._onWindowUp.bind(this);
72
79
  }
73
80
 
74
81
  LineIndicator.prototype.fitToView = function() {
@@ -174,13 +181,26 @@ define([
174
181
  child.fill(child.getAttr('defaultColor'));
175
182
  });
176
183
  self.draw();
177
- self._stage.container().style.cursor = 'default';
184
+ if (!self._isDragging) {
185
+ self._stage.container().style.cursor = 'default';
186
+ }
178
187
  });
179
188
 
180
189
  indicator.on('click', function(e) {
181
190
  self._peaks.emit('lineIndicator.click', self._indicators[lineGroup.getId()], e.evt);
182
191
  });
183
192
 
193
+ indicator.on('mousedown touchstart', function() {
194
+ self._dragLineId = lineGroup.getId();
195
+ self._dragContainerRect = self._stage.getContainer().getBoundingClientRect();
196
+
197
+ window.addEventListener('mousemove', self._onWindowMove, false);
198
+ window.addEventListener('touchmove', self._onWindowMove, false);
199
+ window.addEventListener('mouseup', self._onWindowUp, false);
200
+ window.addEventListener('touchend', self._onWindowUp, false);
201
+ window.addEventListener('blur', self._onWindowUp, false);
202
+ });
203
+
184
204
  return indicator;
185
205
  };
186
206
 
@@ -309,5 +329,42 @@ define([
309
329
  this._layer.draw();
310
330
  };
311
331
 
332
+ LineIndicator.prototype._onWindowMove = function(event) {
333
+ if (!this._dragContainerRect) {
334
+ return;
335
+ }
336
+
337
+ if (!this._isDragging) {
338
+ this._stage.container().style.cursor = 'grabbing';
339
+ }
340
+
341
+ var clientY;
342
+
343
+ if (event.type === 'touchmove') {
344
+ clientY = Math.floor(event.changedTouches[0].clientY);
345
+ }
346
+ else {
347
+ clientY = event.clientY;
348
+ }
349
+
350
+ const relY = clientY - this._dragContainerRect.top;
351
+
352
+ this._peaks.emit('lineIndicator.drag', this._dragLineId, relY);
353
+ };
354
+
355
+ LineIndicator.prototype._onWindowUp = function() {
356
+ window.removeEventListener('mousemove', this._onWindowMove, false);
357
+ window.removeEventListener('touchmove', this._onWindowMove, false);
358
+ window.removeEventListener('mouseup', this._onWindowUp, false);
359
+ window.removeEventListener('touchend', this._onWindowUp, false);
360
+ window.removeEventListener('blur', this._onWindowUp, false);
361
+
362
+ this._isDragging = false;
363
+ this._dragLineId = null;
364
+ this._dragContainerRect = null;
365
+
366
+ this._stage.container().style.cursor = 'pointer';
367
+ };
368
+
312
369
  return LineIndicator;
313
370
  });