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
  */
@@ -159,7 +159,7 @@
159
159
  this.value = value;
160
160
  }
161
161
  print() {
162
- console.warn(this.value);
162
+ console.warn('dockview: stacktrace', this.value);
163
163
  }
164
164
  }
165
165
  class Listener {
@@ -224,7 +224,7 @@
224
224
  var _a;
225
225
  // don't check until stack of execution is completed to allow for out-of-order disposals within the same execution block
226
226
  for (const listener of this._listeners) {
227
- console.warn((_a = listener.stacktrace) === null || _a === void 0 ? void 0 : _a.print());
227
+ console.warn('dockview: stacktrace', (_a = listener.stacktrace) === null || _a === void 0 ? void 0 : _a.print());
228
228
  }
229
229
  });
230
230
  }
@@ -254,18 +254,49 @@
254
254
  },
255
255
  };
256
256
  }
257
- class TickDelayedEvent {
257
+ /**
258
+ *
259
+ * Event Emitter that fires events from a Microtask callback, only one event will fire per event-loop cycle.
260
+ *
261
+ * It's kind of like using an `asapScheduler` in RxJs with additional logic to only fire once per event-loop cycle.
262
+ * This implementation exists to avoid external dependencies.
263
+ *
264
+ * @see https://developer.mozilla.org/en-US/docs/Web/API/queueMicrotask
265
+ * @see https://rxjs.dev/api/index/const/asapScheduler
266
+ */
267
+ class AsapEvent {
258
268
  constructor() {
259
269
  this._onFired = new Emitter();
260
- this.onEvent = this._onFired.event;
270
+ this._currentFireCount = 0;
271
+ this._queued = false;
272
+ this.onEvent = (e) => {
273
+ /**
274
+ * when the event is first subscribed to take note of the current fire count
275
+ */
276
+ const fireCountAtTimeOfEventSubscription = this._currentFireCount;
277
+ return this._onFired.event(() => {
278
+ /**
279
+ * if the current fire count is greater than the fire count at event subscription
280
+ * then the event has been fired since we subscribed and it's ok to "on_next" the event.
281
+ *
282
+ * if the count is not greater then what we are recieving is an event from the microtask
283
+ * queue that was triggered before we actually subscribed and therfore we should ignore it.
284
+ */
285
+ if (this._currentFireCount > fireCountAtTimeOfEventSubscription) {
286
+ e();
287
+ }
288
+ });
289
+ };
261
290
  }
262
291
  fire() {
263
- if (this.timer) {
264
- clearTimeout(this.timer);
292
+ this._currentFireCount++;
293
+ if (this._queued) {
294
+ return;
265
295
  }
266
- this.timer = setTimeout(() => {
296
+ this._queued = true;
297
+ queueMicrotask(() => {
298
+ this._queued = false;
267
299
  this._onFired.fire();
268
- clearTimeout(this.timer);
269
300
  });
270
301
  }
271
302
  dispose() {
@@ -2583,15 +2614,14 @@
2583
2614
  super(document.createElement('div'), options.disableAutoResizing);
2584
2615
  this._id = nextLayoutId$1.next();
2585
2616
  this._groups = new Map();
2586
- this._onDidLayoutChange = new Emitter();
2587
- this.onDidLayoutChange = this._onDidLayoutChange.event;
2588
2617
  this._onDidRemove = new Emitter();
2589
2618
  this.onDidRemove = this._onDidRemove.event;
2590
2619
  this._onDidAdd = new Emitter();
2591
2620
  this.onDidAdd = this._onDidAdd.event;
2592
2621
  this._onDidActiveChange = new Emitter();
2593
2622
  this.onDidActiveChange = this._onDidActiveChange.event;
2594
- this._bufferOnDidLayoutChange = new TickDelayedEvent();
2623
+ this._bufferOnDidLayoutChange = new AsapEvent();
2624
+ this.onDidLayoutChange = this._bufferOnDidLayoutChange.onEvent;
2595
2625
  this.element.style.height = '100%';
2596
2626
  this.element.style.width = '100%';
2597
2627
  options.parentElement.appendChild(this.element);
@@ -2606,13 +2636,11 @@
2606
2636
  this._bufferOnDidLayoutChange.fire();
2607
2637
  }), exports.DockviewEvent.any(this.onDidAdd, this.onDidRemove, this.onDidActiveChange)(() => {
2608
2638
  this._bufferOnDidLayoutChange.fire();
2609
- }), this._bufferOnDidLayoutChange.onEvent(() => {
2610
- this._onDidLayoutChange.fire();
2611
2639
  }), this._bufferOnDidLayoutChange);
2612
2640
  }
2613
2641
  setVisible(panel, visible) {
2614
2642
  this.gridview.setViewVisible(getGridLocation(panel.element), visible);
2615
- this._onDidLayoutChange.fire();
2643
+ this._bufferOnDidLayoutChange.fire();
2616
2644
  }
2617
2645
  isVisible(panel) {
2618
2646
  return this.gridview.isViewVisible(getGridLocation(panel.element));
@@ -2718,7 +2746,6 @@
2718
2746
  this._onDidActiveChange.dispose();
2719
2747
  this._onDidAdd.dispose();
2720
2748
  this._onDidRemove.dispose();
2721
- this._onDidLayoutChange.dispose();
2722
2749
  for (const group of this.groups) {
2723
2750
  group.dispose();
2724
2751
  }
@@ -5747,8 +5774,7 @@
5747
5774
  }
5748
5775
  }
5749
5776
 
5750
- // TODO find a better way to initialize and avoid needing null checks
5751
- const NOT_INITIALIZED_MESSAGE = 'DockviewGroupPanelApiImpl not initialized';
5777
+ const NOT_INITIALIZED_MESSAGE = 'dockview: DockviewGroupPanelApiImpl not initialized';
5752
5778
  class DockviewGroupPanelApiImpl extends GridviewPanelApiImpl {
5753
5779
  get location() {
5754
5780
  if (!this._group) {
@@ -5821,14 +5847,14 @@
5821
5847
  }
5822
5848
  }
5823
5849
  initialize(group) {
5824
- this._group = group;
5825
5850
  /**
5826
- * TODO: Annoying initialization order caveat
5851
+ * TODO: Annoying initialization order caveat, find a better way to initialize and avoid needing null checks
5827
5852
  *
5828
5853
  * Due to the order on initialization we know that the model isn't defined until later in the same stack-frame of setup.
5829
5854
  * By queuing a microtask we can ensure the setup is completed within the same stack-frame, but after everything else has
5830
5855
  * finished ensuring the `model` is defined.
5831
5856
  */
5857
+ this._group = group;
5832
5858
  queueMicrotask(() => {
5833
5859
  this._mutableDisposable.value =
5834
5860
  this._group.model.onDidActivePanelChange((event) => {
@@ -5982,12 +6008,10 @@
5982
6008
  var _a;
5983
6009
  let _trackGroupActive = (_a = previousGroup === null || previousGroup === void 0 ? void 0 : previousGroup.isActive) !== null && _a !== void 0 ? _a : false; // prevent duplicate events with same state
5984
6010
  this.groupEventsDisposable.value = new CompositeDisposable(this.group.api.onDidVisibilityChange((event) => {
5985
- if (!event.isVisible && this.isVisible) {
5986
- this._onDidVisibilityChange.fire(event);
5987
- }
5988
- else if (event.isVisible &&
5989
- !this.isVisible &&
5990
- this.group.model.isPanelActive(this.panel)) {
6011
+ const hasBecomeHidden = !event.isVisible && this.isVisible;
6012
+ const hasBecomeVisible = event.isVisible && !this.isVisible;
6013
+ const isActivePanel = this.group.model.isPanelActive(this.panel);
6014
+ if (hasBecomeHidden || (hasBecomeVisible && isActivePanel)) {
5991
6015
  this._onDidVisibilityChange.fire(event);
5992
6016
  }
5993
6017
  }), this.group.api.onDidLocationChange((event) => {
@@ -6073,12 +6097,6 @@
6073
6097
  const didTitleChange = title !== this.title;
6074
6098
  if (didTitleChange) {
6075
6099
  this._title = title;
6076
- this.view.update({
6077
- params: {
6078
- params: this._params,
6079
- title: this.title,
6080
- },
6081
- });
6082
6100
  this.api._onDidTitleChange.fire({ title });
6083
6101
  }
6084
6102
  }
@@ -6106,10 +6124,7 @@
6106
6124
  }
6107
6125
  // update the view with the updated props
6108
6126
  this.view.update({
6109
- params: {
6110
- params: this._params,
6111
- title: this.title,
6112
- },
6127
+ params: this._params,
6113
6128
  });
6114
6129
  }
6115
6130
  updateParentGroup(group, options) {
@@ -7247,7 +7262,7 @@
7247
7262
  return element.getBoundingClientRect();
7248
7263
  }
7249
7264
  const box = getBox();
7250
- 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;
7265
+ 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();
7251
7266
  if (itemToPopout.api.location.type === 'grid') {
7252
7267
  itemToPopout.api.setVisible(false);
7253
7268
  }
@@ -7363,24 +7378,22 @@
7363
7378
  });
7364
7379
  }
7365
7380
  }
7366
- else {
7367
- if (this.getPanel(group.id)) {
7368
- const removedGroup = this.doRemoveGroup(group, {
7369
- skipDispose: true,
7370
- skipActive: true,
7371
- });
7372
- removedGroup.model.renderContainer =
7373
- this.overlayRenderContainer;
7374
- removedGroup.model.location = { type: 'grid' };
7375
- returnedGroup = removedGroup;
7376
- }
7381
+ else if (this.getPanel(group.id)) {
7382
+ const removedGroup = this.doRemoveGroup(group, {
7383
+ skipDispose: true,
7384
+ skipActive: true,
7385
+ });
7386
+ removedGroup.model.renderContainer =
7387
+ this.overlayRenderContainer;
7388
+ removedGroup.model.location = { type: 'grid' };
7389
+ returnedGroup = removedGroup;
7377
7390
  }
7378
7391
  }));
7379
7392
  this._popoutGroups.push(value);
7380
7393
  this.updateWatermark();
7381
7394
  })
7382
7395
  .catch((err) => {
7383
- console.error(err);
7396
+ console.error('dockview: failed to create popout window', err);
7384
7397
  });
7385
7398
  }
7386
7399
  addFloatingGroup(item, coord, options) {
@@ -7423,7 +7436,7 @@
7423
7436
  this.doRemoveGroup(item, {
7424
7437
  skipDispose: true,
7425
7438
  skipPopoutReturn: true,
7426
- skipPopoutAssociated: !!popoutReferenceGroup,
7439
+ skipPopoutAssociated: false,
7427
7440
  });
7428
7441
  }
7429
7442
  }
@@ -7783,7 +7796,6 @@
7783
7796
  clear() {
7784
7797
  const groups = Array.from(this._groups.values()).map((_) => _.value);
7785
7798
  const hasActiveGroup = !!this.activeGroup;
7786
- !!this.activePanel;
7787
7799
  for (const group of groups) {
7788
7800
  // remove the group will automatically remove the panels
7789
7801
  this.removeGroup(group, { skipActive: true });
@@ -7967,7 +7979,6 @@
7967
7979
  }
7968
7980
  addGroup(options) {
7969
7981
  var _a;
7970
- const group = this.createGroup(options);
7971
7982
  if (options) {
7972
7983
  let referenceGroup;
7973
7984
  if (isGroupOptionsWithPanel(options)) {
@@ -8001,6 +8012,7 @@
8001
8012
  const target = toTarget(options.direction || 'within');
8002
8013
  const location = getGridLocation(referenceGroup.element);
8003
8014
  const relativeLocation = getRelativeLocation(this.gridview.orientation, location, target);
8015
+ const group = this.createGroup(options);
8004
8016
  this.doAddGroup(group, relativeLocation);
8005
8017
  if (!options.skipSetActive) {
8006
8018
  this.doSetGroupAndPanelActive(group);
@@ -8008,6 +8020,7 @@
8008
8020
  return group;
8009
8021
  }
8010
8022
  else {
8023
+ const group = this.createGroup(options);
8011
8024
  this.doAddGroup(group);
8012
8025
  this.doSetGroupAndPanelActive(group);
8013
8026
  return group;
@@ -8288,7 +8301,7 @@
8288
8301
  }
8289
8302
  let id = options === null || options === void 0 ? void 0 : options.id;
8290
8303
  if (id && this._groups.has(options.id)) {
8291
- console.warn(`Duplicate group id ${options === null || options === void 0 ? void 0 : options.id}. reassigning group id to avoid errors`);
8304
+ console.warn(`dockview: Duplicate group id ${options === null || options === void 0 ? void 0 : options.id}. reassigning group id to avoid errors`);
8292
8305
  id = undefined;
8293
8306
  }
8294
8307
  if (!id) {