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
  */
@@ -253,18 +253,49 @@ function addDisposableListener(element, type, listener, options) {
253
253
  },
254
254
  };
255
255
  }
256
- class TickDelayedEvent {
256
+ /**
257
+ *
258
+ * Event Emitter that fires events from a Microtask callback, only one event will fire per event-loop cycle.
259
+ *
260
+ * It's kind of like using an `asapScheduler` in RxJs with additional logic to only fire once per event-loop cycle.
261
+ * This implementation exists to avoid external dependencies.
262
+ *
263
+ * @see https://developer.mozilla.org/en-US/docs/Web/API/queueMicrotask
264
+ * @see https://rxjs.dev/api/index/const/asapScheduler
265
+ */
266
+ class AsapEvent {
257
267
  constructor() {
258
268
  this._onFired = new Emitter();
259
- this.onEvent = this._onFired.event;
269
+ this._currentFireCount = 0;
270
+ this._queued = false;
271
+ this.onEvent = (e) => {
272
+ /**
273
+ * when the event is first subscribed to take note of the current fire count
274
+ */
275
+ const fireCountAtTimeOfEventSubscription = this._currentFireCount;
276
+ return this._onFired.event(() => {
277
+ /**
278
+ * if the current fire count is greater than the fire count at event subscription
279
+ * then the event has been fired since we subscribed and it's ok to "on_next" the event.
280
+ *
281
+ * if the count is not greater then what we are recieving is an event from the microtask
282
+ * queue that was triggered before we actually subscribed and therfore we should ignore it.
283
+ */
284
+ if (this._currentFireCount > fireCountAtTimeOfEventSubscription) {
285
+ e();
286
+ }
287
+ });
288
+ };
260
289
  }
261
290
  fire() {
262
- if (this.timer) {
263
- clearTimeout(this.timer);
291
+ this._currentFireCount++;
292
+ if (this._queued) {
293
+ return;
264
294
  }
265
- this.timer = setTimeout(() => {
295
+ this._queued = true;
296
+ queueMicrotask(() => {
297
+ this._queued = false;
266
298
  this._onFired.fire();
267
- clearTimeout(this.timer);
268
299
  });
269
300
  }
270
301
  dispose() {
@@ -2582,15 +2613,14 @@ class BaseGrid extends Resizable {
2582
2613
  super(document.createElement('div'), options.disableAutoResizing);
2583
2614
  this._id = nextLayoutId$1.next();
2584
2615
  this._groups = new Map();
2585
- this._onDidLayoutChange = new Emitter();
2586
- this.onDidLayoutChange = this._onDidLayoutChange.event;
2587
2616
  this._onDidRemove = new Emitter();
2588
2617
  this.onDidRemove = this._onDidRemove.event;
2589
2618
  this._onDidAdd = new Emitter();
2590
2619
  this.onDidAdd = this._onDidAdd.event;
2591
2620
  this._onDidActiveChange = new Emitter();
2592
2621
  this.onDidActiveChange = this._onDidActiveChange.event;
2593
- this._bufferOnDidLayoutChange = new TickDelayedEvent();
2622
+ this._bufferOnDidLayoutChange = new AsapEvent();
2623
+ this.onDidLayoutChange = this._bufferOnDidLayoutChange.onEvent;
2594
2624
  this.element.style.height = '100%';
2595
2625
  this.element.style.width = '100%';
2596
2626
  options.parentElement.appendChild(this.element);
@@ -2605,13 +2635,11 @@ class BaseGrid extends Resizable {
2605
2635
  this._bufferOnDidLayoutChange.fire();
2606
2636
  }), exports.DockviewEvent.any(this.onDidAdd, this.onDidRemove, this.onDidActiveChange)(() => {
2607
2637
  this._bufferOnDidLayoutChange.fire();
2608
- }), this._bufferOnDidLayoutChange.onEvent(() => {
2609
- this._onDidLayoutChange.fire();
2610
2638
  }), this._bufferOnDidLayoutChange);
2611
2639
  }
2612
2640
  setVisible(panel, visible) {
2613
2641
  this.gridview.setViewVisible(getGridLocation(panel.element), visible);
2614
- this._onDidLayoutChange.fire();
2642
+ this._bufferOnDidLayoutChange.fire();
2615
2643
  }
2616
2644
  isVisible(panel) {
2617
2645
  return this.gridview.isViewVisible(getGridLocation(panel.element));
@@ -2717,7 +2745,6 @@ class BaseGrid extends Resizable {
2717
2745
  this._onDidActiveChange.dispose();
2718
2746
  this._onDidAdd.dispose();
2719
2747
  this._onDidRemove.dispose();
2720
- this._onDidLayoutChange.dispose();
2721
2748
  for (const group of this.groups) {
2722
2749
  group.dispose();
2723
2750
  }
@@ -7943,7 +7970,6 @@ class DockviewComponent extends BaseGrid {
7943
7970
  }
7944
7971
  addGroup(options) {
7945
7972
  var _a;
7946
- const group = this.createGroup(options);
7947
7973
  if (options) {
7948
7974
  let referenceGroup;
7949
7975
  if (isGroupOptionsWithPanel(options)) {
@@ -7977,6 +8003,7 @@ class DockviewComponent extends BaseGrid {
7977
8003
  const target = toTarget(options.direction || 'within');
7978
8004
  const location = getGridLocation(referenceGroup.element);
7979
8005
  const relativeLocation = getRelativeLocation(this.gridview.orientation, location, target);
8006
+ const group = this.createGroup(options);
7980
8007
  this.doAddGroup(group, relativeLocation);
7981
8008
  if (!options.skipSetActive) {
7982
8009
  this.doSetGroupAndPanelActive(group);
@@ -7984,6 +8011,7 @@ class DockviewComponent extends BaseGrid {
7984
8011
  return group;
7985
8012
  }
7986
8013
  else {
8014
+ const group = this.createGroup(options);
7987
8015
  this.doAddGroup(group);
7988
8016
  this.doSetGroupAndPanelActive(group);
7989
8017
  return group;