@checksub_team/peaks_timeline 2.1.1 → 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 CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@checksub_team/peaks_timeline",
3
- "version": "2.1.1",
3
+ "version": "2.1.2",
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
@@ -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];
@@ -22379,7 +22382,8 @@ module.exports = function (MouseDragHandler, PlayheadLayer, SourcesLayer, ModeLa
22379
22382
  self._timelineLength = 0;
22380
22383
  self._timeToPixelsScale = self._options.initialZoomLevel;
22381
22384
  self._timeToPixelsMinScale = self._options.minScale;
22382
- self._isFocused = false;
22385
+ self._focusedByHover = false;
22386
+ self._focusedByClick = false;
22383
22387
  self._isClickable = true;
22384
22388
  self._width = container.clientWidth;
22385
22389
  self._height = container.clientHeight || self._options.height;
@@ -22455,13 +22459,13 @@ module.exports = function (MouseDragHandler, PlayheadLayer, SourcesLayer, ModeLa
22455
22459
  }
22456
22460
  });
22457
22461
  this._stage.on('mouseover', function () {
22458
- self._isFocused = true;
22462
+ self._focusedByHover = true;
22459
22463
  });
22460
22464
  this._stage.on('mouseout', function () {
22461
- self._isFocused = false;
22465
+ self._focusedByHover = false;
22462
22466
  });
22463
22467
  this._stage.on('click', function (event) {
22464
- self._isFocused = true;
22468
+ self._focusedByClick = true;
22465
22469
  if (!self._isClickable) {
22466
22470
  return;
22467
22471
  }
@@ -22517,11 +22521,18 @@ module.exports = function (MouseDragHandler, PlayheadLayer, SourcesLayer, ModeLa
22517
22521
  window.addEventListener('mouseup', this._mouseUp.bind(this), false);
22518
22522
  window.addEventListener('touchend', this._mouseUp.bind(this), false);
22519
22523
  window.addEventListener('blur', this._mouseUp.bind(this), false);
22524
+ this._onWindowClick = this._onWindowClick.bind(this);
22525
+ window.addEventListener('click', this._onWindowClick, false);
22520
22526
  }
22521
22527
  View.prototype._mouseUp = function () {
22522
22528
  this.clearScrollingInterval();
22523
22529
  this._peaks.emit('handler.view.mouseup');
22524
22530
  };
22531
+ View.prototype._onWindowClick = function (event) {
22532
+ if (!this._container.contains(event.target)) {
22533
+ this._focusedByClick = false;
22534
+ }
22535
+ };
22525
22536
  View.prototype.setClickable = function (clickable) {
22526
22537
  this._isClickable = clickable;
22527
22538
  };
@@ -22606,8 +22617,14 @@ module.exports = function (MouseDragHandler, PlayheadLayer, SourcesLayer, ModeLa
22606
22617
  View.prototype.isListening = function () {
22607
22618
  return this._stage.listening();
22608
22619
  };
22620
+ View.prototype.isFocusedByHover = function () {
22621
+ return this._focusedByHover;
22622
+ };
22623
+ View.prototype.isFocusedByClick = function () {
22624
+ return this._focusedByClick;
22625
+ };
22609
22626
  View.prototype.isFocused = function () {
22610
- return this._isFocused;
22627
+ return this._focusedByHover || this._focusedByClick;
22611
22628
  };
22612
22629
  View.prototype.batchDrawSourcesLayer = function () {
22613
22630
  this._sourcesLayer.batchDraw();
@@ -22907,6 +22924,7 @@ module.exports = function (MouseDragHandler, PlayheadLayer, SourcesLayer, ModeLa
22907
22924
  this._peaks.off('handler.keyboard.shiftright', this._onKeyboardShiftRight);
22908
22925
  this._peaks.off('handler.view.defaultmode', this._onDefaultMode);
22909
22926
  this._peaks.off('handler.view.cutmode', this._onCutMode);
22927
+ window.removeEventListener('click', this._onWindowClick, false);
22910
22928
  if (this._stage) {
22911
22929
  this._stage.destroy();
22912
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
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._isFocused = false;
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._isFocused = true;
209
+ self._focusedByHover = true;
209
210
  });
210
211
 
211
212
  this._stage.on('mouseout', function() {
212
- self._isFocused = false;
213
+ self._focusedByHover = false;
213
214
  });
214
215
 
215
216
  this._stage.on('click', function(event) {
216
- self._isFocused = true;
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._isFocused;
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;