@checksub_team/peaks_timeline 2.1.0 → 2.1.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/package.json +1 -1
- package/peaks.js +38 -14
- package/src/components/mode-layer.js +4 -0
- package/src/components/playhead-layer.js +18 -13
- package/src/view.js +27 -5
package/package.json
CHANGED
package/peaks.js
CHANGED
|
@@ -16326,6 +16326,9 @@ module.exports = function (SourceGroup, Source, Utils, Konva) {
|
|
|
16326
16326
|
}
|
|
16327
16327
|
};
|
|
16328
16328
|
ModeLayer.prototype._onKeyboardDelete = function () {
|
|
16329
|
+
if (!this._view.isFocusedByClick()) {
|
|
16330
|
+
return;
|
|
16331
|
+
}
|
|
16329
16332
|
const selectedElements = Object.values(this._selectedElements);
|
|
16330
16333
|
if (selectedElements.length === 1) {
|
|
16331
16334
|
var selectedElement = selectedElements[0];
|
|
@@ -16723,7 +16726,7 @@ module.exports = function (Utils, Konva) {
|
|
|
16723
16726
|
PlayheadLayer.prototype._createPlayheadText = function (color) {
|
|
16724
16727
|
this._playheadText = new Konva.Text({
|
|
16725
16728
|
x: 13,
|
|
16726
|
-
y:
|
|
16729
|
+
y: 10,
|
|
16727
16730
|
text: '00:00:00',
|
|
16728
16731
|
fontSize: 11,
|
|
16729
16732
|
fontFamily: 'sans-serif',
|
|
@@ -16737,21 +16740,28 @@ module.exports = function (Utils, Konva) {
|
|
|
16737
16740
|
this._syncPlayhead(time);
|
|
16738
16741
|
};
|
|
16739
16742
|
PlayheadLayer.prototype._syncPlayhead = function (time) {
|
|
16740
|
-
|
|
16741
|
-
|
|
16743
|
+
const pixelHasChanged = this._updatePlayheadPixel(time);
|
|
16744
|
+
const timeHasChanged = this._time !== time;
|
|
16745
|
+
if (timeHasChanged) {
|
|
16746
|
+
this._updateActiveSegmentsAndSources(time);
|
|
16747
|
+
this._updatePlayheadText(time);
|
|
16742
16748
|
}
|
|
16743
16749
|
this._time = time;
|
|
16744
|
-
|
|
16745
|
-
|
|
16746
|
-
|
|
16747
|
-
this._playheadLayer.batchDraw();
|
|
16750
|
+
if (pixelHasChanged || timeHasChanged) {
|
|
16751
|
+
this._playheadLayer.batchDraw();
|
|
16752
|
+
}
|
|
16748
16753
|
};
|
|
16749
16754
|
PlayheadLayer.prototype._updatePlayheadPixel = function (time) {
|
|
16750
16755
|
const pixelIndex = this._view.timeToPixels(time);
|
|
16751
16756
|
const frameOffset = this._view.timeToPixels(this._view.getTimeOffset());
|
|
16752
16757
|
this._playheadPixel = pixelIndex;
|
|
16753
16758
|
const playheadX = this._playheadPixel - frameOffset;
|
|
16754
|
-
this._playheadGroup.
|
|
16759
|
+
const oldX = this._playheadGroup.getAttr('x');
|
|
16760
|
+
const shouldUpdateX = oldX !== playheadX;
|
|
16761
|
+
if (shouldUpdateX) {
|
|
16762
|
+
this._playheadGroup.setAttr('x', playheadX);
|
|
16763
|
+
}
|
|
16764
|
+
return shouldUpdateX;
|
|
16755
16765
|
};
|
|
16756
16766
|
PlayheadLayer.prototype._updateActiveSegmentsAndSources = function (time) {
|
|
16757
16767
|
const lineGroups = this._lines.getLineGroupsById();
|
|
@@ -16795,7 +16805,6 @@ module.exports = function (Utils, Konva) {
|
|
|
16795
16805
|
PlayheadLayer.prototype._updatePlayheadText = function (time) {
|
|
16796
16806
|
var text = Utils.formatTime(time, false);
|
|
16797
16807
|
this._playheadText.setText(text);
|
|
16798
|
-
this._peaks.emit('playhead.moved', this._playheadText.getAbsolutePosition().x, this._playheadText.width());
|
|
16799
16808
|
};
|
|
16800
16809
|
PlayheadLayer.prototype.getPlayheadOffset = function () {
|
|
16801
16810
|
return this._playheadPixel - this._view.getFrameOffset();
|
|
@@ -22373,7 +22382,8 @@ module.exports = function (MouseDragHandler, PlayheadLayer, SourcesLayer, ModeLa
|
|
|
22373
22382
|
self._timelineLength = 0;
|
|
22374
22383
|
self._timeToPixelsScale = self._options.initialZoomLevel;
|
|
22375
22384
|
self._timeToPixelsMinScale = self._options.minScale;
|
|
22376
|
-
self.
|
|
22385
|
+
self._focusedByHover = false;
|
|
22386
|
+
self._focusedByClick = false;
|
|
22377
22387
|
self._isClickable = true;
|
|
22378
22388
|
self._width = container.clientWidth;
|
|
22379
22389
|
self._height = container.clientHeight || self._options.height;
|
|
@@ -22449,13 +22459,13 @@ module.exports = function (MouseDragHandler, PlayheadLayer, SourcesLayer, ModeLa
|
|
|
22449
22459
|
}
|
|
22450
22460
|
});
|
|
22451
22461
|
this._stage.on('mouseover', function () {
|
|
22452
|
-
self.
|
|
22462
|
+
self._focusedByHover = true;
|
|
22453
22463
|
});
|
|
22454
22464
|
this._stage.on('mouseout', function () {
|
|
22455
|
-
self.
|
|
22465
|
+
self._focusedByHover = false;
|
|
22456
22466
|
});
|
|
22457
22467
|
this._stage.on('click', function (event) {
|
|
22458
|
-
self.
|
|
22468
|
+
self._focusedByClick = true;
|
|
22459
22469
|
if (!self._isClickable) {
|
|
22460
22470
|
return;
|
|
22461
22471
|
}
|
|
@@ -22511,11 +22521,18 @@ module.exports = function (MouseDragHandler, PlayheadLayer, SourcesLayer, ModeLa
|
|
|
22511
22521
|
window.addEventListener('mouseup', this._mouseUp.bind(this), false);
|
|
22512
22522
|
window.addEventListener('touchend', this._mouseUp.bind(this), false);
|
|
22513
22523
|
window.addEventListener('blur', this._mouseUp.bind(this), false);
|
|
22524
|
+
this._onWindowClick = this._onWindowClick.bind(this);
|
|
22525
|
+
window.addEventListener('click', this._onWindowClick, false);
|
|
22514
22526
|
}
|
|
22515
22527
|
View.prototype._mouseUp = function () {
|
|
22516
22528
|
this.clearScrollingInterval();
|
|
22517
22529
|
this._peaks.emit('handler.view.mouseup');
|
|
22518
22530
|
};
|
|
22531
|
+
View.prototype._onWindowClick = function (event) {
|
|
22532
|
+
if (!this._container.contains(event.target)) {
|
|
22533
|
+
this._focusedByClick = false;
|
|
22534
|
+
}
|
|
22535
|
+
};
|
|
22519
22536
|
View.prototype.setClickable = function (clickable) {
|
|
22520
22537
|
this._isClickable = clickable;
|
|
22521
22538
|
};
|
|
@@ -22600,8 +22617,14 @@ module.exports = function (MouseDragHandler, PlayheadLayer, SourcesLayer, ModeLa
|
|
|
22600
22617
|
View.prototype.isListening = function () {
|
|
22601
22618
|
return this._stage.listening();
|
|
22602
22619
|
};
|
|
22620
|
+
View.prototype.isFocusedByHover = function () {
|
|
22621
|
+
return this._focusedByHover;
|
|
22622
|
+
};
|
|
22623
|
+
View.prototype.isFocusedByClick = function () {
|
|
22624
|
+
return this._focusedByClick;
|
|
22625
|
+
};
|
|
22603
22626
|
View.prototype.isFocused = function () {
|
|
22604
|
-
return this.
|
|
22627
|
+
return this._focusedByHover || this._focusedByClick;
|
|
22605
22628
|
};
|
|
22606
22629
|
View.prototype.batchDrawSourcesLayer = function () {
|
|
22607
22630
|
this._sourcesLayer.batchDraw();
|
|
@@ -22901,6 +22924,7 @@ module.exports = function (MouseDragHandler, PlayheadLayer, SourcesLayer, ModeLa
|
|
|
22901
22924
|
this._peaks.off('handler.keyboard.shiftright', this._onKeyboardShiftRight);
|
|
22902
22925
|
this._peaks.off('handler.view.defaultmode', this._onDefaultMode);
|
|
22903
22926
|
this._peaks.off('handler.view.cutmode', this._onCutMode);
|
|
22927
|
+
window.removeEventListener('click', this._onWindowClick, false);
|
|
22904
22928
|
if (this._stage) {
|
|
22905
22929
|
this._stage.destroy();
|
|
22906
22930
|
this._stage = null;
|
|
@@ -234,6 +234,10 @@ define([
|
|
|
234
234
|
};
|
|
235
235
|
|
|
236
236
|
ModeLayer.prototype._onKeyboardDelete = function() {
|
|
237
|
+
if (!this._view.isFocusedByClick()) {
|
|
238
|
+
return;
|
|
239
|
+
}
|
|
240
|
+
|
|
237
241
|
const selectedElements = Object.values(this._selectedElements);
|
|
238
242
|
|
|
239
243
|
// We allow deletion if there is ONLY 1 element selected
|
|
@@ -196,7 +196,7 @@ define([
|
|
|
196
196
|
// Create with default y, the real value is set in fitToView().
|
|
197
197
|
this._playheadText = new Konva.Text({
|
|
198
198
|
x: 13,
|
|
199
|
-
y:
|
|
199
|
+
y: 10,
|
|
200
200
|
text: '00:00:00',
|
|
201
201
|
fontSize: 11,
|
|
202
202
|
fontFamily: 'sans-serif',
|
|
@@ -226,15 +226,18 @@ define([
|
|
|
226
226
|
*/
|
|
227
227
|
|
|
228
228
|
PlayheadLayer.prototype._syncPlayhead = function(time) {
|
|
229
|
-
|
|
230
|
-
|
|
229
|
+
const pixelHasChanged = this._updatePlayheadPixel(time);
|
|
230
|
+
const timeHasChanged = this._time !== time;
|
|
231
|
+
|
|
232
|
+
if (timeHasChanged) {
|
|
233
|
+
this._updateActiveSegmentsAndSources(time);
|
|
234
|
+
this._updatePlayheadText(time);
|
|
231
235
|
}
|
|
232
236
|
|
|
233
237
|
this._time = time;
|
|
234
|
-
|
|
235
|
-
|
|
236
|
-
|
|
237
|
-
this._playheadLayer.batchDraw();
|
|
238
|
+
if (pixelHasChanged || timeHasChanged) {
|
|
239
|
+
this._playheadLayer.batchDraw();
|
|
240
|
+
}
|
|
238
241
|
};
|
|
239
242
|
|
|
240
243
|
/**
|
|
@@ -249,8 +252,15 @@ define([
|
|
|
249
252
|
|
|
250
253
|
this._playheadPixel = pixelIndex;
|
|
251
254
|
const playheadX = this._playheadPixel - frameOffset;
|
|
255
|
+
const oldX = this._playheadGroup.getAttr('x');
|
|
256
|
+
|
|
257
|
+
const shouldUpdateX = oldX !== playheadX;
|
|
258
|
+
|
|
259
|
+
if (shouldUpdateX) {
|
|
260
|
+
this._playheadGroup.setAttr('x', playheadX);
|
|
261
|
+
}
|
|
252
262
|
|
|
253
|
-
|
|
263
|
+
return shouldUpdateX;
|
|
254
264
|
};
|
|
255
265
|
|
|
256
266
|
/**
|
|
@@ -328,11 +338,6 @@ define([
|
|
|
328
338
|
var text = Utils.formatTime(time, false);
|
|
329
339
|
|
|
330
340
|
this._playheadText.setText(text);
|
|
331
|
-
this._peaks.emit(
|
|
332
|
-
'playhead.moved',
|
|
333
|
-
this._playheadText.getAbsolutePosition().x,
|
|
334
|
-
this._playheadText.width()
|
|
335
|
-
);
|
|
336
341
|
};
|
|
337
342
|
|
|
338
343
|
/**
|
package/src/view.js
CHANGED
|
@@ -79,7 +79,8 @@ define([
|
|
|
79
79
|
self._timeToPixelsScale = self._options.initialZoomLevel;
|
|
80
80
|
self._timeToPixelsMinScale = self._options.minScale;
|
|
81
81
|
|
|
82
|
-
self.
|
|
82
|
+
self._focusedByHover = false;
|
|
83
|
+
self._focusedByClick = false; // Track if focus was set by click
|
|
83
84
|
self._isClickable = true;
|
|
84
85
|
|
|
85
86
|
self._width = container.clientWidth;
|
|
@@ -205,15 +206,15 @@ define([
|
|
|
205
206
|
});
|
|
206
207
|
|
|
207
208
|
this._stage.on('mouseover', function() {
|
|
208
|
-
self.
|
|
209
|
+
self._focusedByHover = true;
|
|
209
210
|
});
|
|
210
211
|
|
|
211
212
|
this._stage.on('mouseout', function() {
|
|
212
|
-
self.
|
|
213
|
+
self._focusedByHover = false;
|
|
213
214
|
});
|
|
214
215
|
|
|
215
216
|
this._stage.on('click', function(event) {
|
|
216
|
-
self.
|
|
217
|
+
self._focusedByClick = true;
|
|
217
218
|
|
|
218
219
|
if (!self._isClickable) {
|
|
219
220
|
return;
|
|
@@ -307,6 +308,10 @@ define([
|
|
|
307
308
|
window.addEventListener('mouseup', this._mouseUp.bind(this), false);
|
|
308
309
|
window.addEventListener('touchend', this._mouseUp.bind(this), false);
|
|
309
310
|
window.addEventListener('blur', this._mouseUp.bind(this), false);
|
|
311
|
+
|
|
312
|
+
// Handle clicks outside the timeline to remove focus
|
|
313
|
+
this._onWindowClick = this._onWindowClick.bind(this);
|
|
314
|
+
window.addEventListener('click', this._onWindowClick, false);
|
|
310
315
|
}
|
|
311
316
|
|
|
312
317
|
View.prototype._mouseUp = function() {
|
|
@@ -314,6 +319,12 @@ define([
|
|
|
314
319
|
this._peaks.emit('handler.view.mouseup');
|
|
315
320
|
};
|
|
316
321
|
|
|
322
|
+
View.prototype._onWindowClick = function(event) {
|
|
323
|
+
if (!this._container.contains(event.target)) {
|
|
324
|
+
this._focusedByClick = false;
|
|
325
|
+
}
|
|
326
|
+
};
|
|
327
|
+
|
|
317
328
|
View.prototype.setClickable = function(clickable) {
|
|
318
329
|
this._isClickable = clickable;
|
|
319
330
|
};
|
|
@@ -430,8 +441,16 @@ define([
|
|
|
430
441
|
return this._stage.listening();
|
|
431
442
|
};
|
|
432
443
|
|
|
444
|
+
View.prototype.isFocusedByHover = function() {
|
|
445
|
+
return this._focusedByHover;
|
|
446
|
+
};
|
|
447
|
+
|
|
448
|
+
View.prototype.isFocusedByClick = function() {
|
|
449
|
+
return this._focusedByClick;
|
|
450
|
+
};
|
|
451
|
+
|
|
433
452
|
View.prototype.isFocused = function() {
|
|
434
|
-
return this.
|
|
453
|
+
return this._focusedByHover || this._focusedByClick;
|
|
435
454
|
};
|
|
436
455
|
|
|
437
456
|
View.prototype.batchDrawSourcesLayer = function() {
|
|
@@ -900,6 +919,9 @@ define([
|
|
|
900
919
|
this._peaks.off('handler.view.defaultmode', this._onDefaultMode);
|
|
901
920
|
this._peaks.off('handler.view.cutmode', this._onCutMode);
|
|
902
921
|
|
|
922
|
+
// Remove window click listener
|
|
923
|
+
window.removeEventListener('click', this._onWindowClick, false);
|
|
924
|
+
|
|
903
925
|
if (this._stage) {
|
|
904
926
|
this._stage.destroy();
|
|
905
927
|
this._stage = null;
|