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
  */
@@ -129,7 +129,7 @@
129
129
  this.value = value;
130
130
  }
131
131
  print() {
132
- console.warn(this.value);
132
+ console.warn('dockview: stacktrace', this.value);
133
133
  }
134
134
  }
135
135
  class Listener {
@@ -194,7 +194,7 @@
194
194
  var _a;
195
195
  // don't check until stack of execution is completed to allow for out-of-order disposals within the same execution block
196
196
  for (const listener of this._listeners) {
197
- console.warn((_a = listener.stacktrace) === null || _a === void 0 ? void 0 : _a.print());
197
+ console.warn('dockview: stacktrace', (_a = listener.stacktrace) === null || _a === void 0 ? void 0 : _a.print());
198
198
  }
199
199
  });
200
200
  }
@@ -224,18 +224,49 @@
224
224
  },
225
225
  };
226
226
  }
227
- class TickDelayedEvent {
227
+ /**
228
+ *
229
+ * Event Emitter that fires events from a Microtask callback, only one event will fire per event-loop cycle.
230
+ *
231
+ * It's kind of like using an `asapScheduler` in RxJs with additional logic to only fire once per event-loop cycle.
232
+ * This implementation exists to avoid external dependencies.
233
+ *
234
+ * @see https://developer.mozilla.org/en-US/docs/Web/API/queueMicrotask
235
+ * @see https://rxjs.dev/api/index/const/asapScheduler
236
+ */
237
+ class AsapEvent {
228
238
  constructor() {
229
239
  this._onFired = new Emitter();
230
- this.onEvent = this._onFired.event;
240
+ this._currentFireCount = 0;
241
+ this._queued = false;
242
+ this.onEvent = (e) => {
243
+ /**
244
+ * when the event is first subscribed to take note of the current fire count
245
+ */
246
+ const fireCountAtTimeOfEventSubscription = this._currentFireCount;
247
+ return this._onFired.event(() => {
248
+ /**
249
+ * if the current fire count is greater than the fire count at event subscription
250
+ * then the event has been fired since we subscribed and it's ok to "on_next" the event.
251
+ *
252
+ * if the count is not greater then what we are recieving is an event from the microtask
253
+ * queue that was triggered before we actually subscribed and therfore we should ignore it.
254
+ */
255
+ if (this._currentFireCount > fireCountAtTimeOfEventSubscription) {
256
+ e();
257
+ }
258
+ });
259
+ };
231
260
  }
232
261
  fire() {
233
- if (this.timer) {
234
- clearTimeout(this.timer);
262
+ this._currentFireCount++;
263
+ if (this._queued) {
264
+ return;
235
265
  }
236
- this.timer = setTimeout(() => {
266
+ this._queued = true;
267
+ queueMicrotask(() => {
268
+ this._queued = false;
237
269
  this._onFired.fire();
238
- clearTimeout(this.timer);
239
270
  });
240
271
  }
241
272
  dispose() {
@@ -2553,15 +2584,14 @@
2553
2584
  super(document.createElement('div'), options.disableAutoResizing);
2554
2585
  this._id = nextLayoutId$1.next();
2555
2586
  this._groups = new Map();
2556
- this._onDidLayoutChange = new Emitter();
2557
- this.onDidLayoutChange = this._onDidLayoutChange.event;
2558
2587
  this._onDidRemove = new Emitter();
2559
2588
  this.onDidRemove = this._onDidRemove.event;
2560
2589
  this._onDidAdd = new Emitter();
2561
2590
  this.onDidAdd = this._onDidAdd.event;
2562
2591
  this._onDidActiveChange = new Emitter();
2563
2592
  this.onDidActiveChange = this._onDidActiveChange.event;
2564
- this._bufferOnDidLayoutChange = new TickDelayedEvent();
2593
+ this._bufferOnDidLayoutChange = new AsapEvent();
2594
+ this.onDidLayoutChange = this._bufferOnDidLayoutChange.onEvent;
2565
2595
  this.element.style.height = '100%';
2566
2596
  this.element.style.width = '100%';
2567
2597
  options.parentElement.appendChild(this.element);
@@ -2576,13 +2606,11 @@
2576
2606
  this._bufferOnDidLayoutChange.fire();
2577
2607
  }), exports.DockviewEvent.any(this.onDidAdd, this.onDidRemove, this.onDidActiveChange)(() => {
2578
2608
  this._bufferOnDidLayoutChange.fire();
2579
- }), this._bufferOnDidLayoutChange.onEvent(() => {
2580
- this._onDidLayoutChange.fire();
2581
2609
  }), this._bufferOnDidLayoutChange);
2582
2610
  }
2583
2611
  setVisible(panel, visible) {
2584
2612
  this.gridview.setViewVisible(getGridLocation(panel.element), visible);
2585
- this._onDidLayoutChange.fire();
2613
+ this._bufferOnDidLayoutChange.fire();
2586
2614
  }
2587
2615
  isVisible(panel) {
2588
2616
  return this.gridview.isViewVisible(getGridLocation(panel.element));
@@ -2688,7 +2716,6 @@
2688
2716
  this._onDidActiveChange.dispose();
2689
2717
  this._onDidAdd.dispose();
2690
2718
  this._onDidRemove.dispose();
2691
- this._onDidLayoutChange.dispose();
2692
2719
  for (const group of this.groups) {
2693
2720
  group.dispose();
2694
2721
  }
@@ -5717,8 +5744,7 @@
5717
5744
  }
5718
5745
  }
5719
5746
 
5720
- // TODO find a better way to initialize and avoid needing null checks
5721
- const NOT_INITIALIZED_MESSAGE = 'DockviewGroupPanelApiImpl not initialized';
5747
+ const NOT_INITIALIZED_MESSAGE = 'dockview: DockviewGroupPanelApiImpl not initialized';
5722
5748
  class DockviewGroupPanelApiImpl extends GridviewPanelApiImpl {
5723
5749
  get location() {
5724
5750
  if (!this._group) {
@@ -5791,14 +5817,14 @@
5791
5817
  }
5792
5818
  }
5793
5819
  initialize(group) {
5794
- this._group = group;
5795
5820
  /**
5796
- * TODO: Annoying initialization order caveat
5821
+ * TODO: Annoying initialization order caveat, find a better way to initialize and avoid needing null checks
5797
5822
  *
5798
5823
  * Due to the order on initialization we know that the model isn't defined until later in the same stack-frame of setup.
5799
5824
  * By queuing a microtask we can ensure the setup is completed within the same stack-frame, but after everything else has
5800
5825
  * finished ensuring the `model` is defined.
5801
5826
  */
5827
+ this._group = group;
5802
5828
  queueMicrotask(() => {
5803
5829
  this._mutableDisposable.value =
5804
5830
  this._group.model.onDidActivePanelChange((event) => {
@@ -5952,12 +5978,10 @@
5952
5978
  var _a;
5953
5979
  let _trackGroupActive = (_a = previousGroup === null || previousGroup === void 0 ? void 0 : previousGroup.isActive) !== null && _a !== void 0 ? _a : false; // prevent duplicate events with same state
5954
5980
  this.groupEventsDisposable.value = new CompositeDisposable(this.group.api.onDidVisibilityChange((event) => {
5955
- if (!event.isVisible && this.isVisible) {
5956
- this._onDidVisibilityChange.fire(event);
5957
- }
5958
- else if (event.isVisible &&
5959
- !this.isVisible &&
5960
- this.group.model.isPanelActive(this.panel)) {
5981
+ const hasBecomeHidden = !event.isVisible && this.isVisible;
5982
+ const hasBecomeVisible = event.isVisible && !this.isVisible;
5983
+ const isActivePanel = this.group.model.isPanelActive(this.panel);
5984
+ if (hasBecomeHidden || (hasBecomeVisible && isActivePanel)) {
5961
5985
  this._onDidVisibilityChange.fire(event);
5962
5986
  }
5963
5987
  }), this.group.api.onDidLocationChange((event) => {
@@ -6043,12 +6067,6 @@
6043
6067
  const didTitleChange = title !== this.title;
6044
6068
  if (didTitleChange) {
6045
6069
  this._title = title;
6046
- this.view.update({
6047
- params: {
6048
- params: this._params,
6049
- title: this.title,
6050
- },
6051
- });
6052
6070
  this.api._onDidTitleChange.fire({ title });
6053
6071
  }
6054
6072
  }
@@ -6076,10 +6094,7 @@
6076
6094
  }
6077
6095
  // update the view with the updated props
6078
6096
  this.view.update({
6079
- params: {
6080
- params: this._params,
6081
- title: this.title,
6082
- },
6097
+ params: this._params,
6083
6098
  });
6084
6099
  }
6085
6100
  updateParentGroup(group, options) {
@@ -7217,7 +7232,7 @@
7217
7232
  return element.getBoundingClientRect();
7218
7233
  }
7219
7234
  const box = getBox();
7220
- 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;
7235
+ 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();
7221
7236
  if (itemToPopout.api.location.type === 'grid') {
7222
7237
  itemToPopout.api.setVisible(false);
7223
7238
  }
@@ -7333,24 +7348,22 @@
7333
7348
  });
7334
7349
  }
7335
7350
  }
7336
- else {
7337
- if (this.getPanel(group.id)) {
7338
- const removedGroup = this.doRemoveGroup(group, {
7339
- skipDispose: true,
7340
- skipActive: true,
7341
- });
7342
- removedGroup.model.renderContainer =
7343
- this.overlayRenderContainer;
7344
- removedGroup.model.location = { type: 'grid' };
7345
- returnedGroup = removedGroup;
7346
- }
7351
+ else if (this.getPanel(group.id)) {
7352
+ const removedGroup = this.doRemoveGroup(group, {
7353
+ skipDispose: true,
7354
+ skipActive: true,
7355
+ });
7356
+ removedGroup.model.renderContainer =
7357
+ this.overlayRenderContainer;
7358
+ removedGroup.model.location = { type: 'grid' };
7359
+ returnedGroup = removedGroup;
7347
7360
  }
7348
7361
  }));
7349
7362
  this._popoutGroups.push(value);
7350
7363
  this.updateWatermark();
7351
7364
  })
7352
7365
  .catch((err) => {
7353
- console.error(err);
7366
+ console.error('dockview: failed to create popout window', err);
7354
7367
  });
7355
7368
  }
7356
7369
  addFloatingGroup(item, coord, options) {
@@ -7393,7 +7406,7 @@
7393
7406
  this.doRemoveGroup(item, {
7394
7407
  skipDispose: true,
7395
7408
  skipPopoutReturn: true,
7396
- skipPopoutAssociated: !!popoutReferenceGroup,
7409
+ skipPopoutAssociated: false,
7397
7410
  });
7398
7411
  }
7399
7412
  }
@@ -7753,7 +7766,6 @@
7753
7766
  clear() {
7754
7767
  const groups = Array.from(this._groups.values()).map((_) => _.value);
7755
7768
  const hasActiveGroup = !!this.activeGroup;
7756
- !!this.activePanel;
7757
7769
  for (const group of groups) {
7758
7770
  // remove the group will automatically remove the panels
7759
7771
  this.removeGroup(group, { skipActive: true });
@@ -7937,7 +7949,6 @@
7937
7949
  }
7938
7950
  addGroup(options) {
7939
7951
  var _a;
7940
- const group = this.createGroup(options);
7941
7952
  if (options) {
7942
7953
  let referenceGroup;
7943
7954
  if (isGroupOptionsWithPanel(options)) {
@@ -7971,6 +7982,7 @@
7971
7982
  const target = toTarget(options.direction || 'within');
7972
7983
  const location = getGridLocation(referenceGroup.element);
7973
7984
  const relativeLocation = getRelativeLocation(this.gridview.orientation, location, target);
7985
+ const group = this.createGroup(options);
7974
7986
  this.doAddGroup(group, relativeLocation);
7975
7987
  if (!options.skipSetActive) {
7976
7988
  this.doSetGroupAndPanelActive(group);
@@ -7978,6 +7990,7 @@
7978
7990
  return group;
7979
7991
  }
7980
7992
  else {
7993
+ const group = this.createGroup(options);
7981
7994
  this.doAddGroup(group);
7982
7995
  this.doSetGroupAndPanelActive(group);
7983
7996
  return group;
@@ -8258,7 +8271,7 @@
8258
8271
  }
8259
8272
  let id = options === null || options === void 0 ? void 0 : options.id;
8260
8273
  if (id && this._groups.has(options.id)) {
8261
- console.warn(`Duplicate group id ${options === null || options === void 0 ? void 0 : options.id}. reassigning group id to avoid errors`);
8274
+ console.warn(`dockview: Duplicate group id ${options === null || options === void 0 ? void 0 : options.id}. reassigning group id to avoid errors`);
8262
8275
  id = undefined;
8263
8276
  }
8264
8277
  if (!id) {