dockview 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.
@@ -1,6 +1,6 @@
1
1
  /**
2
2
  * dockview
3
- * @version 1.13.0
3
+ * @version 1.14.0
4
4
  * @link https://github.com/mathuo/dockview
5
5
  * @license MIT
6
6
  */
@@ -125,7 +125,7 @@ define(['exports', 'react', 'react-dom'], (function (exports, React, ReactDOM) {
125
125
  this.value = value;
126
126
  }
127
127
  print() {
128
- console.warn(this.value);
128
+ console.warn('dockview: stacktrace', this.value);
129
129
  }
130
130
  }
131
131
  class Listener {
@@ -190,7 +190,7 @@ define(['exports', 'react', 'react-dom'], (function (exports, React, ReactDOM) {
190
190
  var _a;
191
191
  // don't check until stack of execution is completed to allow for out-of-order disposals within the same execution block
192
192
  for (const listener of this._listeners) {
193
- console.warn((_a = listener.stacktrace) === null || _a === void 0 ? void 0 : _a.print());
193
+ console.warn('dockview: stacktrace', (_a = listener.stacktrace) === null || _a === void 0 ? void 0 : _a.print());
194
194
  }
195
195
  });
196
196
  }
@@ -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
  }
@@ -5713,8 +5740,7 @@ define(['exports', 'react', 'react-dom'], (function (exports, React, ReactDOM) {
5713
5740
  }
5714
5741
  }
5715
5742
 
5716
- // TODO find a better way to initialize and avoid needing null checks
5717
- const NOT_INITIALIZED_MESSAGE = 'DockviewGroupPanelApiImpl not initialized';
5743
+ const NOT_INITIALIZED_MESSAGE = 'dockview: DockviewGroupPanelApiImpl not initialized';
5718
5744
  class DockviewGroupPanelApiImpl extends GridviewPanelApiImpl {
5719
5745
  get location() {
5720
5746
  if (!this._group) {
@@ -5787,14 +5813,14 @@ define(['exports', 'react', 'react-dom'], (function (exports, React, ReactDOM) {
5787
5813
  }
5788
5814
  }
5789
5815
  initialize(group) {
5790
- this._group = group;
5791
5816
  /**
5792
- * TODO: Annoying initialization order caveat
5817
+ * TODO: Annoying initialization order caveat, find a better way to initialize and avoid needing null checks
5793
5818
  *
5794
5819
  * Due to the order on initialization we know that the model isn't defined until later in the same stack-frame of setup.
5795
5820
  * By queuing a microtask we can ensure the setup is completed within the same stack-frame, but after everything else has
5796
5821
  * finished ensuring the `model` is defined.
5797
5822
  */
5823
+ this._group = group;
5798
5824
  queueMicrotask(() => {
5799
5825
  this._mutableDisposable.value =
5800
5826
  this._group.model.onDidActivePanelChange((event) => {
@@ -5948,12 +5974,10 @@ define(['exports', 'react', 'react-dom'], (function (exports, React, ReactDOM) {
5948
5974
  var _a;
5949
5975
  let _trackGroupActive = (_a = previousGroup === null || previousGroup === void 0 ? void 0 : previousGroup.isActive) !== null && _a !== void 0 ? _a : false; // prevent duplicate events with same state
5950
5976
  this.groupEventsDisposable.value = new CompositeDisposable(this.group.api.onDidVisibilityChange((event) => {
5951
- if (!event.isVisible && this.isVisible) {
5952
- this._onDidVisibilityChange.fire(event);
5953
- }
5954
- else if (event.isVisible &&
5955
- !this.isVisible &&
5956
- this.group.model.isPanelActive(this.panel)) {
5977
+ const hasBecomeHidden = !event.isVisible && this.isVisible;
5978
+ const hasBecomeVisible = event.isVisible && !this.isVisible;
5979
+ const isActivePanel = this.group.model.isPanelActive(this.panel);
5980
+ if (hasBecomeHidden || (hasBecomeVisible && isActivePanel)) {
5957
5981
  this._onDidVisibilityChange.fire(event);
5958
5982
  }
5959
5983
  }), this.group.api.onDidLocationChange((event) => {
@@ -6039,12 +6063,6 @@ define(['exports', 'react', 'react-dom'], (function (exports, React, ReactDOM) {
6039
6063
  const didTitleChange = title !== this.title;
6040
6064
  if (didTitleChange) {
6041
6065
  this._title = title;
6042
- this.view.update({
6043
- params: {
6044
- params: this._params,
6045
- title: this.title,
6046
- },
6047
- });
6048
6066
  this.api._onDidTitleChange.fire({ title });
6049
6067
  }
6050
6068
  }
@@ -6072,10 +6090,7 @@ define(['exports', 'react', 'react-dom'], (function (exports, React, ReactDOM) {
6072
6090
  }
6073
6091
  // update the view with the updated props
6074
6092
  this.view.update({
6075
- params: {
6076
- params: this._params,
6077
- title: this.title,
6078
- },
6093
+ params: this._params,
6079
6094
  });
6080
6095
  }
6081
6096
  updateParentGroup(group, options) {
@@ -7190,7 +7205,7 @@ define(['exports', 'react', 'react-dom'], (function (exports, React, ReactDOM) {
7190
7205
  return element.getBoundingClientRect();
7191
7206
  }
7192
7207
  const box = getBox();
7193
- 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;
7208
+ 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();
7194
7209
  if (itemToPopout.api.location.type === 'grid') {
7195
7210
  itemToPopout.api.setVisible(false);
7196
7211
  }
@@ -7306,24 +7321,22 @@ define(['exports', 'react', 'react-dom'], (function (exports, React, ReactDOM) {
7306
7321
  });
7307
7322
  }
7308
7323
  }
7309
- else {
7310
- if (this.getPanel(group.id)) {
7311
- const removedGroup = this.doRemoveGroup(group, {
7312
- skipDispose: true,
7313
- skipActive: true,
7314
- });
7315
- removedGroup.model.renderContainer =
7316
- this.overlayRenderContainer;
7317
- removedGroup.model.location = { type: 'grid' };
7318
- returnedGroup = removedGroup;
7319
- }
7324
+ else if (this.getPanel(group.id)) {
7325
+ const removedGroup = this.doRemoveGroup(group, {
7326
+ skipDispose: true,
7327
+ skipActive: true,
7328
+ });
7329
+ removedGroup.model.renderContainer =
7330
+ this.overlayRenderContainer;
7331
+ removedGroup.model.location = { type: 'grid' };
7332
+ returnedGroup = removedGroup;
7320
7333
  }
7321
7334
  }));
7322
7335
  this._popoutGroups.push(value);
7323
7336
  this.updateWatermark();
7324
7337
  })
7325
7338
  .catch((err) => {
7326
- console.error(err);
7339
+ console.error('dockview: failed to create popout window', err);
7327
7340
  });
7328
7341
  }
7329
7342
  addFloatingGroup(item, coord, options) {
@@ -7366,7 +7379,7 @@ define(['exports', 'react', 'react-dom'], (function (exports, React, ReactDOM) {
7366
7379
  this.doRemoveGroup(item, {
7367
7380
  skipDispose: true,
7368
7381
  skipPopoutReturn: true,
7369
- skipPopoutAssociated: !!popoutReferenceGroup,
7382
+ skipPopoutAssociated: false,
7370
7383
  });
7371
7384
  }
7372
7385
  }
@@ -7726,7 +7739,6 @@ define(['exports', 'react', 'react-dom'], (function (exports, React, ReactDOM) {
7726
7739
  clear() {
7727
7740
  const groups = Array.from(this._groups.values()).map((_) => _.value);
7728
7741
  const hasActiveGroup = !!this.activeGroup;
7729
- !!this.activePanel;
7730
7742
  for (const group of groups) {
7731
7743
  // remove the group will automatically remove the panels
7732
7744
  this.removeGroup(group, { skipActive: true });
@@ -7910,7 +7922,6 @@ define(['exports', 'react', 'react-dom'], (function (exports, React, ReactDOM) {
7910
7922
  }
7911
7923
  addGroup(options) {
7912
7924
  var _a;
7913
- const group = this.createGroup(options);
7914
7925
  if (options) {
7915
7926
  let referenceGroup;
7916
7927
  if (isGroupOptionsWithPanel(options)) {
@@ -7944,6 +7955,7 @@ define(['exports', 'react', 'react-dom'], (function (exports, React, ReactDOM) {
7944
7955
  const target = toTarget(options.direction || 'within');
7945
7956
  const location = getGridLocation(referenceGroup.element);
7946
7957
  const relativeLocation = getRelativeLocation(this.gridview.orientation, location, target);
7958
+ const group = this.createGroup(options);
7947
7959
  this.doAddGroup(group, relativeLocation);
7948
7960
  if (!options.skipSetActive) {
7949
7961
  this.doSetGroupAndPanelActive(group);
@@ -7951,6 +7963,7 @@ define(['exports', 'react', 'react-dom'], (function (exports, React, ReactDOM) {
7951
7963
  return group;
7952
7964
  }
7953
7965
  else {
7966
+ const group = this.createGroup(options);
7954
7967
  this.doAddGroup(group);
7955
7968
  this.doSetGroupAndPanelActive(group);
7956
7969
  return group;
@@ -8231,7 +8244,7 @@ define(['exports', 'react', 'react-dom'], (function (exports, React, ReactDOM) {
8231
8244
  }
8232
8245
  let id = options === null || options === void 0 ? void 0 : options.id;
8233
8246
  if (id && this._groups.has(options.id)) {
8234
- console.warn(`Duplicate group id ${options === null || options === void 0 ? void 0 : options.id}. reassigning group id to avoid errors`);
8247
+ console.warn(`dockview: Duplicate group id ${options === null || options === void 0 ? void 0 : options.id}. reassigning group id to avoid errors`);
8235
8248
  id = undefined;
8236
8249
  }
8237
8250
  if (!id) {
@@ -9448,7 +9461,7 @@ define(['exports', 'react', 'react-dom'], (function (exports, React, ReactDOM) {
9448
9461
  }
9449
9462
  update(event) {
9450
9463
  var _a;
9451
- (_a = this.part) === null || _a === void 0 ? void 0 : _a.update(event.params);
9464
+ (_a = this.part) === null || _a === void 0 ? void 0 : _a.update({ params: event.params });
9452
9465
  }
9453
9466
  layout(_width, _height) {
9454
9467
  // noop
@@ -9486,7 +9499,7 @@ define(['exports', 'react', 'react-dom'], (function (exports, React, ReactDOM) {
9486
9499
  }
9487
9500
  update(event) {
9488
9501
  var _a;
9489
- (_a = this.part) === null || _a === void 0 ? void 0 : _a.update(event.params);
9502
+ (_a = this.part) === null || _a === void 0 ? void 0 : _a.update({ params: event.params });
9490
9503
  }
9491
9504
  layout(_width, _height) {
9492
9505
  // noop - retrieval from api