dockview 1.13.0 → 1.13.1

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.
@@ -1,6 +1,6 @@
1
1
  /**
2
2
  * dockview
3
- * @version 1.13.0
3
+ * @version 1.13.1
4
4
  * @link https://github.com/mathuo/dockview
5
5
  * @license MIT
6
6
  */
@@ -220,18 +220,49 @@ define(['exports', 'react', 'react-dom'], (function (exports, React, ReactDOM) {
220
220
  },
221
221
  };
222
222
  }
223
- class TickDelayedEvent {
223
+ /**
224
+ *
225
+ * Event Emitter that fires events from a Microtask callback, only one event will fire per event-loop cycle.
226
+ *
227
+ * It's kind of like using an `asapScheduler` in RxJs with additional logic to only fire once per event-loop cycle.
228
+ * This implementation exists to avoid external dependencies.
229
+ *
230
+ * @see https://developer.mozilla.org/en-US/docs/Web/API/queueMicrotask
231
+ * @see https://rxjs.dev/api/index/const/asapScheduler
232
+ */
233
+ class AsapEvent {
224
234
  constructor() {
225
235
  this._onFired = new Emitter();
226
- this.onEvent = this._onFired.event;
236
+ this._currentFireCount = 0;
237
+ this._queued = false;
238
+ this.onEvent = (e) => {
239
+ /**
240
+ * when the event is first subscribed to take note of the current fire count
241
+ */
242
+ const fireCountAtTimeOfEventSubscription = this._currentFireCount;
243
+ return this._onFired.event(() => {
244
+ /**
245
+ * if the current fire count is greater than the fire count at event subscription
246
+ * then the event has been fired since we subscribed and it's ok to "on_next" the event.
247
+ *
248
+ * if the count is not greater then what we are recieving is an event from the microtask
249
+ * queue that was triggered before we actually subscribed and therfore we should ignore it.
250
+ */
251
+ if (this._currentFireCount > fireCountAtTimeOfEventSubscription) {
252
+ e();
253
+ }
254
+ });
255
+ };
227
256
  }
228
257
  fire() {
229
- if (this.timer) {
230
- clearTimeout(this.timer);
258
+ this._currentFireCount++;
259
+ if (this._queued) {
260
+ return;
231
261
  }
232
- this.timer = setTimeout(() => {
262
+ this._queued = true;
263
+ queueMicrotask(() => {
264
+ this._queued = false;
233
265
  this._onFired.fire();
234
- clearTimeout(this.timer);
235
266
  });
236
267
  }
237
268
  dispose() {
@@ -2549,15 +2580,14 @@ define(['exports', 'react', 'react-dom'], (function (exports, React, ReactDOM) {
2549
2580
  super(document.createElement('div'), options.disableAutoResizing);
2550
2581
  this._id = nextLayoutId$1.next();
2551
2582
  this._groups = new Map();
2552
- this._onDidLayoutChange = new Emitter();
2553
- this.onDidLayoutChange = this._onDidLayoutChange.event;
2554
2583
  this._onDidRemove = new Emitter();
2555
2584
  this.onDidRemove = this._onDidRemove.event;
2556
2585
  this._onDidAdd = new Emitter();
2557
2586
  this.onDidAdd = this._onDidAdd.event;
2558
2587
  this._onDidActiveChange = new Emitter();
2559
2588
  this.onDidActiveChange = this._onDidActiveChange.event;
2560
- this._bufferOnDidLayoutChange = new TickDelayedEvent();
2589
+ this._bufferOnDidLayoutChange = new AsapEvent();
2590
+ this.onDidLayoutChange = this._bufferOnDidLayoutChange.onEvent;
2561
2591
  this.element.style.height = '100%';
2562
2592
  this.element.style.width = '100%';
2563
2593
  options.parentElement.appendChild(this.element);
@@ -2572,13 +2602,11 @@ define(['exports', 'react', 'react-dom'], (function (exports, React, ReactDOM) {
2572
2602
  this._bufferOnDidLayoutChange.fire();
2573
2603
  }), exports.DockviewEvent.any(this.onDidAdd, this.onDidRemove, this.onDidActiveChange)(() => {
2574
2604
  this._bufferOnDidLayoutChange.fire();
2575
- }), this._bufferOnDidLayoutChange.onEvent(() => {
2576
- this._onDidLayoutChange.fire();
2577
2605
  }), this._bufferOnDidLayoutChange);
2578
2606
  }
2579
2607
  setVisible(panel, visible) {
2580
2608
  this.gridview.setViewVisible(getGridLocation(panel.element), visible);
2581
- this._onDidLayoutChange.fire();
2609
+ this._bufferOnDidLayoutChange.fire();
2582
2610
  }
2583
2611
  isVisible(panel) {
2584
2612
  return this.gridview.isViewVisible(getGridLocation(panel.element));
@@ -2684,7 +2712,6 @@ define(['exports', 'react', 'react-dom'], (function (exports, React, ReactDOM) {
2684
2712
  this._onDidActiveChange.dispose();
2685
2713
  this._onDidAdd.dispose();
2686
2714
  this._onDidRemove.dispose();
2687
- this._onDidLayoutChange.dispose();
2688
2715
  for (const group of this.groups) {
2689
2716
  group.dispose();
2690
2717
  }
@@ -7910,7 +7937,6 @@ define(['exports', 'react', 'react-dom'], (function (exports, React, ReactDOM) {
7910
7937
  }
7911
7938
  addGroup(options) {
7912
7939
  var _a;
7913
- const group = this.createGroup(options);
7914
7940
  if (options) {
7915
7941
  let referenceGroup;
7916
7942
  if (isGroupOptionsWithPanel(options)) {
@@ -7944,6 +7970,7 @@ define(['exports', 'react', 'react-dom'], (function (exports, React, ReactDOM) {
7944
7970
  const target = toTarget(options.direction || 'within');
7945
7971
  const location = getGridLocation(referenceGroup.element);
7946
7972
  const relativeLocation = getRelativeLocation(this.gridview.orientation, location, target);
7973
+ const group = this.createGroup(options);
7947
7974
  this.doAddGroup(group, relativeLocation);
7948
7975
  if (!options.skipSetActive) {
7949
7976
  this.doSetGroupAndPanelActive(group);
@@ -7951,6 +7978,7 @@ define(['exports', 'react', 'react-dom'], (function (exports, React, ReactDOM) {
7951
7978
  return group;
7952
7979
  }
7953
7980
  else {
7981
+ const group = this.createGroup(options);
7954
7982
  this.doAddGroup(group);
7955
7983
  this.doSetGroupAndPanelActive(group);
7956
7984
  return group;