dockview-core 1.13.0 → 1.14.0

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.
Files changed (40) hide show
  1. package/dist/cjs/api/dockviewGroupPanelApi.js +4 -5
  2. package/dist/cjs/api/dockviewPanelApi.js +4 -6
  3. package/dist/cjs/dockview/dockviewComponent.js +15 -17
  4. package/dist/cjs/dockview/dockviewPanel.js +1 -10
  5. package/dist/cjs/events.d.ts +13 -2
  6. package/dist/cjs/events.js +47 -15
  7. package/dist/cjs/gridview/baseComponentGridview.d.ts +3 -4
  8. package/dist/cjs/gridview/baseComponentGridview.js +3 -7
  9. package/dist/dockview-core.amd.js +66 -53
  10. package/dist/dockview-core.amd.js.map +1 -1
  11. package/dist/dockview-core.amd.min.js +2 -2
  12. package/dist/dockview-core.amd.min.js.map +1 -1
  13. package/dist/dockview-core.amd.min.noStyle.js +2 -2
  14. package/dist/dockview-core.amd.min.noStyle.js.map +1 -1
  15. package/dist/dockview-core.amd.noStyle.js +66 -53
  16. package/dist/dockview-core.amd.noStyle.js.map +1 -1
  17. package/dist/dockview-core.cjs.js +66 -53
  18. package/dist/dockview-core.cjs.js.map +1 -1
  19. package/dist/dockview-core.esm.js +66 -53
  20. package/dist/dockview-core.esm.js.map +1 -1
  21. package/dist/dockview-core.esm.min.js +2 -2
  22. package/dist/dockview-core.esm.min.js.map +1 -1
  23. package/dist/dockview-core.js +66 -53
  24. package/dist/dockview-core.js.map +1 -1
  25. package/dist/dockview-core.min.js +2 -2
  26. package/dist/dockview-core.min.js.map +1 -1
  27. package/dist/dockview-core.min.noStyle.js +2 -2
  28. package/dist/dockview-core.min.noStyle.js.map +1 -1
  29. package/dist/dockview-core.noStyle.js +66 -53
  30. package/dist/dockview-core.noStyle.js.map +1 -1
  31. package/dist/esm/api/dockviewGroupPanelApi.js +3 -4
  32. package/dist/esm/api/dockviewPanelApi.js +4 -6
  33. package/dist/esm/dockview/components/titlebar/tabsContainer.js +1 -1
  34. package/dist/esm/dockview/dockviewComponent.js +15 -17
  35. package/dist/esm/dockview/dockviewPanel.js +1 -10
  36. package/dist/esm/events.d.ts +13 -2
  37. package/dist/esm/events.js +40 -9
  38. package/dist/esm/gridview/baseComponentGridview.d.ts +3 -4
  39. package/dist/esm/gridview/baseComponentGridview.js +4 -8
  40. package/package.json +1 -1
@@ -1,6 +1,6 @@
1
1
  /**
2
2
  * dockview-core
3
- * @version 1.13.0
3
+ * @version 1.14.0
4
4
  * @link https://github.com/mathuo/dockview
5
5
  * @license MIT
6
6
  */
@@ -153,7 +153,7 @@ class Stacktrace {
153
153
  this.value = value;
154
154
  }
155
155
  print() {
156
- console.warn(this.value);
156
+ console.warn('dockview: stacktrace', this.value);
157
157
  }
158
158
  }
159
159
  class Listener {
@@ -218,7 +218,7 @@ class Emitter {
218
218
  var _a;
219
219
  // don't check until stack of execution is completed to allow for out-of-order disposals within the same execution block
220
220
  for (const listener of this._listeners) {
221
- console.warn((_a = listener.stacktrace) === null || _a === void 0 ? void 0 : _a.print());
221
+ console.warn('dockview: stacktrace', (_a = listener.stacktrace) === null || _a === void 0 ? void 0 : _a.print());
222
222
  }
223
223
  });
224
224
  }
@@ -248,18 +248,49 @@ function addDisposableListener(element, type, listener, options) {
248
248
  },
249
249
  };
250
250
  }
251
- class TickDelayedEvent {
251
+ /**
252
+ *
253
+ * Event Emitter that fires events from a Microtask callback, only one event will fire per event-loop cycle.
254
+ *
255
+ * It's kind of like using an `asapScheduler` in RxJs with additional logic to only fire once per event-loop cycle.
256
+ * This implementation exists to avoid external dependencies.
257
+ *
258
+ * @see https://developer.mozilla.org/en-US/docs/Web/API/queueMicrotask
259
+ * @see https://rxjs.dev/api/index/const/asapScheduler
260
+ */
261
+ class AsapEvent {
252
262
  constructor() {
253
263
  this._onFired = new Emitter();
254
- this.onEvent = this._onFired.event;
264
+ this._currentFireCount = 0;
265
+ this._queued = false;
266
+ this.onEvent = (e) => {
267
+ /**
268
+ * when the event is first subscribed to take note of the current fire count
269
+ */
270
+ const fireCountAtTimeOfEventSubscription = this._currentFireCount;
271
+ return this._onFired.event(() => {
272
+ /**
273
+ * if the current fire count is greater than the fire count at event subscription
274
+ * then the event has been fired since we subscribed and it's ok to "on_next" the event.
275
+ *
276
+ * if the count is not greater then what we are recieving is an event from the microtask
277
+ * queue that was triggered before we actually subscribed and therfore we should ignore it.
278
+ */
279
+ if (this._currentFireCount > fireCountAtTimeOfEventSubscription) {
280
+ e();
281
+ }
282
+ });
283
+ };
255
284
  }
256
285
  fire() {
257
- if (this.timer) {
258
- clearTimeout(this.timer);
286
+ this._currentFireCount++;
287
+ if (this._queued) {
288
+ return;
259
289
  }
260
- this.timer = setTimeout(() => {
290
+ this._queued = true;
291
+ queueMicrotask(() => {
292
+ this._queued = false;
261
293
  this._onFired.fire();
262
- clearTimeout(this.timer);
263
294
  });
264
295
  }
265
296
  dispose() {
@@ -2577,15 +2608,14 @@ class BaseGrid extends Resizable {
2577
2608
  super(document.createElement('div'), options.disableAutoResizing);
2578
2609
  this._id = nextLayoutId$1.next();
2579
2610
  this._groups = new Map();
2580
- this._onDidLayoutChange = new Emitter();
2581
- this.onDidLayoutChange = this._onDidLayoutChange.event;
2582
2611
  this._onDidRemove = new Emitter();
2583
2612
  this.onDidRemove = this._onDidRemove.event;
2584
2613
  this._onDidAdd = new Emitter();
2585
2614
  this.onDidAdd = this._onDidAdd.event;
2586
2615
  this._onDidActiveChange = new Emitter();
2587
2616
  this.onDidActiveChange = this._onDidActiveChange.event;
2588
- this._bufferOnDidLayoutChange = new TickDelayedEvent();
2617
+ this._bufferOnDidLayoutChange = new AsapEvent();
2618
+ this.onDidLayoutChange = this._bufferOnDidLayoutChange.onEvent;
2589
2619
  this.element.style.height = '100%';
2590
2620
  this.element.style.width = '100%';
2591
2621
  options.parentElement.appendChild(this.element);
@@ -2600,13 +2630,11 @@ class BaseGrid extends Resizable {
2600
2630
  this._bufferOnDidLayoutChange.fire();
2601
2631
  }), Event.any(this.onDidAdd, this.onDidRemove, this.onDidActiveChange)(() => {
2602
2632
  this._bufferOnDidLayoutChange.fire();
2603
- }), this._bufferOnDidLayoutChange.onEvent(() => {
2604
- this._onDidLayoutChange.fire();
2605
2633
  }), this._bufferOnDidLayoutChange);
2606
2634
  }
2607
2635
  setVisible(panel, visible) {
2608
2636
  this.gridview.setViewVisible(getGridLocation(panel.element), visible);
2609
- this._onDidLayoutChange.fire();
2637
+ this._bufferOnDidLayoutChange.fire();
2610
2638
  }
2611
2639
  isVisible(panel) {
2612
2640
  return this.gridview.isViewVisible(getGridLocation(panel.element));
@@ -2712,7 +2740,6 @@ class BaseGrid extends Resizable {
2712
2740
  this._onDidActiveChange.dispose();
2713
2741
  this._onDidAdd.dispose();
2714
2742
  this._onDidRemove.dispose();
2715
- this._onDidLayoutChange.dispose();
2716
2743
  for (const group of this.groups) {
2717
2744
  group.dispose();
2718
2745
  }
@@ -5741,8 +5768,7 @@ class GridviewPanel extends BasePanelView {
5741
5768
  }
5742
5769
  }
5743
5770
 
5744
- // TODO find a better way to initialize and avoid needing null checks
5745
- const NOT_INITIALIZED_MESSAGE = 'DockviewGroupPanelApiImpl not initialized';
5771
+ const NOT_INITIALIZED_MESSAGE = 'dockview: DockviewGroupPanelApiImpl not initialized';
5746
5772
  class DockviewGroupPanelApiImpl extends GridviewPanelApiImpl {
5747
5773
  get location() {
5748
5774
  if (!this._group) {
@@ -5815,14 +5841,14 @@ class DockviewGroupPanelApiImpl extends GridviewPanelApiImpl {
5815
5841
  }
5816
5842
  }
5817
5843
  initialize(group) {
5818
- this._group = group;
5819
5844
  /**
5820
- * TODO: Annoying initialization order caveat
5845
+ * TODO: Annoying initialization order caveat, find a better way to initialize and avoid needing null checks
5821
5846
  *
5822
5847
  * Due to the order on initialization we know that the model isn't defined until later in the same stack-frame of setup.
5823
5848
  * By queuing a microtask we can ensure the setup is completed within the same stack-frame, but after everything else has
5824
5849
  * finished ensuring the `model` is defined.
5825
5850
  */
5851
+ this._group = group;
5826
5852
  queueMicrotask(() => {
5827
5853
  this._mutableDisposable.value =
5828
5854
  this._group.model.onDidActivePanelChange((event) => {
@@ -5976,12 +6002,10 @@ class DockviewPanelApiImpl extends GridviewPanelApiImpl {
5976
6002
  var _a;
5977
6003
  let _trackGroupActive = (_a = previousGroup === null || previousGroup === void 0 ? void 0 : previousGroup.isActive) !== null && _a !== void 0 ? _a : false; // prevent duplicate events with same state
5978
6004
  this.groupEventsDisposable.value = new CompositeDisposable(this.group.api.onDidVisibilityChange((event) => {
5979
- if (!event.isVisible && this.isVisible) {
5980
- this._onDidVisibilityChange.fire(event);
5981
- }
5982
- else if (event.isVisible &&
5983
- !this.isVisible &&
5984
- this.group.model.isPanelActive(this.panel)) {
6005
+ const hasBecomeHidden = !event.isVisible && this.isVisible;
6006
+ const hasBecomeVisible = event.isVisible && !this.isVisible;
6007
+ const isActivePanel = this.group.model.isPanelActive(this.panel);
6008
+ if (hasBecomeHidden || (hasBecomeVisible && isActivePanel)) {
5985
6009
  this._onDidVisibilityChange.fire(event);
5986
6010
  }
5987
6011
  }), this.group.api.onDidLocationChange((event) => {
@@ -6067,12 +6091,6 @@ class DockviewPanel extends CompositeDisposable {
6067
6091
  const didTitleChange = title !== this.title;
6068
6092
  if (didTitleChange) {
6069
6093
  this._title = title;
6070
- this.view.update({
6071
- params: {
6072
- params: this._params,
6073
- title: this.title,
6074
- },
6075
- });
6076
6094
  this.api._onDidTitleChange.fire({ title });
6077
6095
  }
6078
6096
  }
@@ -6100,10 +6118,7 @@ class DockviewPanel extends CompositeDisposable {
6100
6118
  }
6101
6119
  // update the view with the updated props
6102
6120
  this.view.update({
6103
- params: {
6104
- params: this._params,
6105
- title: this.title,
6106
- },
6121
+ params: this._params,
6107
6122
  });
6108
6123
  }
6109
6124
  updateParentGroup(group, options) {
@@ -7241,7 +7256,7 @@ class DockviewComponent extends BaseGrid {
7241
7256
  return element.getBoundingClientRect();
7242
7257
  }
7243
7258
  const box = getBox();
7244
- const groupId = (_b = (_a = options === null || options === void 0 ? void 0 : options.overridePopoutGroup) === null || _a === void 0 ? void 0 : _a.id) !== null && _b !== void 0 ? _b : this.getNextGroupId(); //item.id;
7259
+ const groupId = (_b = (_a = options === null || options === void 0 ? void 0 : options.overridePopoutGroup) === null || _a === void 0 ? void 0 : _a.id) !== null && _b !== void 0 ? _b : this.getNextGroupId();
7245
7260
  if (itemToPopout.api.location.type === 'grid') {
7246
7261
  itemToPopout.api.setVisible(false);
7247
7262
  }
@@ -7357,24 +7372,22 @@ class DockviewComponent extends BaseGrid {
7357
7372
  });
7358
7373
  }
7359
7374
  }
7360
- else {
7361
- if (this.getPanel(group.id)) {
7362
- const removedGroup = this.doRemoveGroup(group, {
7363
- skipDispose: true,
7364
- skipActive: true,
7365
- });
7366
- removedGroup.model.renderContainer =
7367
- this.overlayRenderContainer;
7368
- removedGroup.model.location = { type: 'grid' };
7369
- returnedGroup = removedGroup;
7370
- }
7375
+ else if (this.getPanel(group.id)) {
7376
+ const removedGroup = this.doRemoveGroup(group, {
7377
+ skipDispose: true,
7378
+ skipActive: true,
7379
+ });
7380
+ removedGroup.model.renderContainer =
7381
+ this.overlayRenderContainer;
7382
+ removedGroup.model.location = { type: 'grid' };
7383
+ returnedGroup = removedGroup;
7371
7384
  }
7372
7385
  }));
7373
7386
  this._popoutGroups.push(value);
7374
7387
  this.updateWatermark();
7375
7388
  })
7376
7389
  .catch((err) => {
7377
- console.error(err);
7390
+ console.error('dockview: failed to create popout window', err);
7378
7391
  });
7379
7392
  }
7380
7393
  addFloatingGroup(item, coord, options) {
@@ -7417,7 +7430,7 @@ class DockviewComponent extends BaseGrid {
7417
7430
  this.doRemoveGroup(item, {
7418
7431
  skipDispose: true,
7419
7432
  skipPopoutReturn: true,
7420
- skipPopoutAssociated: !!popoutReferenceGroup,
7433
+ skipPopoutAssociated: false,
7421
7434
  });
7422
7435
  }
7423
7436
  }
@@ -7777,7 +7790,6 @@ class DockviewComponent extends BaseGrid {
7777
7790
  clear() {
7778
7791
  const groups = Array.from(this._groups.values()).map((_) => _.value);
7779
7792
  const hasActiveGroup = !!this.activeGroup;
7780
- !!this.activePanel;
7781
7793
  for (const group of groups) {
7782
7794
  // remove the group will automatically remove the panels
7783
7795
  this.removeGroup(group, { skipActive: true });
@@ -7961,7 +7973,6 @@ class DockviewComponent extends BaseGrid {
7961
7973
  }
7962
7974
  addGroup(options) {
7963
7975
  var _a;
7964
- const group = this.createGroup(options);
7965
7976
  if (options) {
7966
7977
  let referenceGroup;
7967
7978
  if (isGroupOptionsWithPanel(options)) {
@@ -7995,6 +8006,7 @@ class DockviewComponent extends BaseGrid {
7995
8006
  const target = toTarget(options.direction || 'within');
7996
8007
  const location = getGridLocation(referenceGroup.element);
7997
8008
  const relativeLocation = getRelativeLocation(this.gridview.orientation, location, target);
8009
+ const group = this.createGroup(options);
7998
8010
  this.doAddGroup(group, relativeLocation);
7999
8011
  if (!options.skipSetActive) {
8000
8012
  this.doSetGroupAndPanelActive(group);
@@ -8002,6 +8014,7 @@ class DockviewComponent extends BaseGrid {
8002
8014
  return group;
8003
8015
  }
8004
8016
  else {
8017
+ const group = this.createGroup(options);
8005
8018
  this.doAddGroup(group);
8006
8019
  this.doSetGroupAndPanelActive(group);
8007
8020
  return group;
@@ -8282,7 +8295,7 @@ class DockviewComponent extends BaseGrid {
8282
8295
  }
8283
8296
  let id = options === null || options === void 0 ? void 0 : options.id;
8284
8297
  if (id && this._groups.has(options.id)) {
8285
- console.warn(`Duplicate group id ${options === null || options === void 0 ? void 0 : options.id}. reassigning group id to avoid errors`);
8298
+ console.warn(`dockview: Duplicate group id ${options === null || options === void 0 ? void 0 : options.id}. reassigning group id to avoid errors`);
8286
8299
  id = undefined;
8287
8300
  }
8288
8301
  if (!id) {