dockview-react 1.14.2 → 1.15.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-react
3
- * @version 1.14.2
3
+ * @version 1.15.1
4
4
  * @link https://github.com/mathuo/dockview
5
5
  * @license MIT
6
6
  */
@@ -532,6 +532,9 @@
532
532
  }
533
533
  return false;
534
534
  }
535
+ function addTestId(element, id) {
536
+ element.setAttribute('data-testid', id);
537
+ }
535
538
 
536
539
  function tail(arr) {
537
540
  if (arr.length === 0) {
@@ -593,7 +596,11 @@
593
596
 
594
597
  const clamp = (value, min, max) => {
595
598
  if (min > max) {
596
- throw new Error(`${min} > ${max} is an invalid condition`);
599
+ /**
600
+ * caveat: an error should be thrown here if this was a proper `clamp` function but we need to handle
601
+ * cases where `min` > `max` and in those cases return `min`.
602
+ */
603
+ return min;
597
604
  }
598
605
  return Math.min(max, Math.max(value, min));
599
606
  };
@@ -798,7 +805,14 @@
798
805
  this._disabled = value;
799
806
  toggleClass(this.element, 'dv-splitview-disabled', value);
800
807
  }
808
+ get margin() {
809
+ return this._margin;
810
+ }
811
+ set margin(value) {
812
+ this._margin = value;
813
+ }
801
814
  constructor(container, options) {
815
+ var _a;
802
816
  this.container = container;
803
817
  this.viewItems = [];
804
818
  this.sashes = [];
@@ -809,6 +823,7 @@
809
823
  this._startSnappingEnabled = true;
810
824
  this._endSnappingEnabled = true;
811
825
  this._disabled = false;
826
+ this._margin = 0;
812
827
  this._onDidSashEnd = new Emitter();
813
828
  this.onDidSashEnd = this._onDidSashEnd.event;
814
829
  this._onDidAddView = new Emitter();
@@ -897,6 +912,7 @@
897
912
  };
898
913
  this._orientation = options.orientation;
899
914
  this.element = this.createContainer();
915
+ this.margin = (_a = options.margin) !== null && _a !== void 0 ? _a : 0;
900
916
  this.proportionalLayout =
901
917
  options.proportionalLayout === undefined
902
918
  ? true
@@ -951,9 +967,7 @@
951
967
  if (index < 0 || index >= this.viewItems.length) {
952
968
  throw new Error('Index out of bounds');
953
969
  }
954
- toggleClass(this.container, 'visible', visible);
955
970
  const viewItem = this.viewItems[index];
956
- toggleClass(this.container, 'visible', visible);
957
971
  viewItem.setVisible(visible, viewItem.size);
958
972
  this.distributeEmptySpace(index);
959
973
  this.layoutViews();
@@ -1265,15 +1279,29 @@
1265
1279
  this._proportions = this.viewItems.map((i) => i.visible ? i.size / this._contentSize : undefined);
1266
1280
  }
1267
1281
  }
1282
+ /**
1283
+ * Margin explain:
1284
+ *
1285
+ * For `n` views in a splitview there will be `n-1` margins `m`.
1286
+ *
1287
+ * To fit the margins each view must reduce in size by `(m * (n - 1)) / n`.
1288
+ *
1289
+ * For each view `i` the offet must be adjusted by `m * i/(n - 1)`.
1290
+ */
1268
1291
  layoutViews() {
1269
1292
  this._contentSize = this.viewItems.reduce((r, i) => r + i.size, 0);
1270
- let sum = 0;
1271
- const x = [];
1272
1293
  this.updateSashEnablement();
1294
+ if (this.viewItems.length === 0) {
1295
+ return;
1296
+ }
1297
+ const sashCount = this.viewItems.length - 1;
1298
+ const marginReducedSize = (this.margin * sashCount) / this.viewItems.length;
1299
+ let totalLeftOffset = 0;
1300
+ const viewLeftOffsets = [];
1273
1301
  for (let i = 0; i < this.viewItems.length - 1; i++) {
1274
- sum += this.viewItems[i].size;
1275
- x.push(sum);
1276
- const offset = Math.min(Math.max(0, sum - 2), this.size - 4);
1302
+ totalLeftOffset += this.viewItems[i].size;
1303
+ viewLeftOffsets.push(totalLeftOffset);
1304
+ const offset = Math.min(Math.max(0, totalLeftOffset - 2), this.size - this.margin);
1277
1305
  if (this._orientation === exports.Orientation.HORIZONTAL) {
1278
1306
  this.sashes[i].container.style.left = `${offset}px`;
1279
1307
  this.sashes[i].container.style.top = `0px`;
@@ -1284,19 +1312,24 @@
1284
1312
  }
1285
1313
  }
1286
1314
  this.viewItems.forEach((view, i) => {
1315
+ const size = view.size - marginReducedSize;
1316
+ const offset = i === 0
1317
+ ? 0
1318
+ : viewLeftOffsets[i - 1] +
1319
+ (i / sashCount) * marginReducedSize;
1287
1320
  if (this._orientation === exports.Orientation.HORIZONTAL) {
1288
- view.container.style.width = `${view.size}px`;
1289
- view.container.style.left = i == 0 ? '0px' : `${x[i - 1]}px`;
1321
+ view.container.style.width = `${size}px`;
1322
+ view.container.style.left = `${offset}px`;
1290
1323
  view.container.style.top = '';
1291
1324
  view.container.style.height = '';
1292
1325
  }
1293
1326
  if (this._orientation === exports.Orientation.VERTICAL) {
1294
- view.container.style.height = `${view.size}px`;
1295
- view.container.style.top = i == 0 ? '0px' : `${x[i - 1]}px`;
1327
+ view.container.style.height = `${size}px`;
1328
+ view.container.style.top = `${offset}px`;
1296
1329
  view.container.style.width = '';
1297
1330
  view.container.style.left = '';
1298
1331
  }
1299
- view.view.layout(view.size, this._orthogonalSize);
1332
+ view.view.layout(view.size - marginReducedSize, this._orthogonalSize);
1300
1333
  });
1301
1334
  }
1302
1335
  findFirstSnapIndex(indexes) {
@@ -1745,7 +1778,18 @@
1745
1778
  set disabled(value) {
1746
1779
  this.splitview.disabled = value;
1747
1780
  }
1748
- constructor(orientation, proportionalLayout, styles, size, orthogonalSize, disabled, childDescriptors) {
1781
+ get margin() {
1782
+ return this.splitview.margin;
1783
+ }
1784
+ set margin(value) {
1785
+ this.splitview.margin = value;
1786
+ this.children.forEach((child) => {
1787
+ if (child instanceof BranchNode) {
1788
+ child.margin = value;
1789
+ }
1790
+ });
1791
+ }
1792
+ constructor(orientation, proportionalLayout, styles, size, orthogonalSize, disabled, margin, childDescriptors) {
1749
1793
  super();
1750
1794
  this.orientation = orientation;
1751
1795
  this.proportionalLayout = proportionalLayout;
@@ -1765,6 +1809,7 @@
1765
1809
  orientation: this.orientation,
1766
1810
  proportionalLayout,
1767
1811
  styles,
1812
+ margin,
1768
1813
  });
1769
1814
  this.splitview.layout(this.size, this.orthogonalSize);
1770
1815
  }
@@ -1788,6 +1833,7 @@
1788
1833
  descriptor,
1789
1834
  proportionalLayout,
1790
1835
  styles,
1836
+ margin,
1791
1837
  });
1792
1838
  }
1793
1839
  this.disabled = disabled;
@@ -1796,10 +1842,8 @@
1796
1842
  }));
1797
1843
  this.setupChildrenEvents();
1798
1844
  }
1799
- setVisible(visible) {
1800
- for (const child of this.children) {
1801
- child.setVisible(visible);
1802
- }
1845
+ setVisible(_visible) {
1846
+ // noop
1803
1847
  }
1804
1848
  isChildVisible(index) {
1805
1849
  if (index < 0 || index >= this.children.length) {
@@ -1816,12 +1860,13 @@
1816
1860
  }
1817
1861
  const wereAllChildrenHidden = this.splitview.contentSize === 0;
1818
1862
  this.splitview.setViewVisible(index, visible);
1863
+ // }
1819
1864
  const areAllChildrenHidden = this.splitview.contentSize === 0;
1820
1865
  // If all children are hidden then the parent should hide the entire splitview
1821
1866
  // If the entire splitview is hidden then the parent should show the splitview when a child is shown
1822
1867
  if ((visible && wereAllChildrenHidden) ||
1823
1868
  (!visible && areAllChildrenHidden)) {
1824
- this._onDidVisibilityChange.fire(visible);
1869
+ this._onDidVisibilityChange.fire({ visible });
1825
1870
  }
1826
1871
  }
1827
1872
  moveChild(from, to) {
@@ -1894,7 +1939,7 @@
1894
1939
  this._onDidChange.fire({ size: e.orthogonalSize });
1895
1940
  }), ...this.children.map((c, i) => {
1896
1941
  if (c instanceof BranchNode) {
1897
- return c.onDidVisibilityChange((visible) => {
1942
+ return c.onDidVisibilityChange(({ visible }) => {
1898
1943
  this.setChildVisible(i, visible);
1899
1944
  });
1900
1945
  }
@@ -1924,7 +1969,7 @@
1924
1969
  }
1925
1970
  function flipNode(node, size, orthogonalSize) {
1926
1971
  if (node instanceof BranchNode) {
1927
- const result = new BranchNode(orthogonal(node.orientation), node.proportionalLayout, node.styles, size, orthogonalSize, node.disabled);
1972
+ const result = new BranchNode(orthogonal(node.orientation), node.proportionalLayout, node.styles, size, orthogonalSize, node.disabled, node.margin);
1928
1973
  let totalSize = 0;
1929
1974
  for (let i = node.children.length - 1; i >= 0; i--) {
1930
1975
  const child = node.children[i];
@@ -2079,6 +2124,13 @@
2079
2124
  }
2080
2125
  }
2081
2126
  }
2127
+ get margin() {
2128
+ return this._margin;
2129
+ }
2130
+ set margin(value) {
2131
+ this._margin = value;
2132
+ this.root.margin = value;
2133
+ }
2082
2134
  maximizedView() {
2083
2135
  var _a;
2084
2136
  return (_a = this._maximizedNode) === null || _a === void 0 ? void 0 : _a.leaf.view;
@@ -2164,13 +2216,14 @@
2164
2216
  this.disposable.dispose();
2165
2217
  this._onDidChange.dispose();
2166
2218
  this._onDidMaximizedNodeChange.dispose();
2219
+ this._onDidViewVisibilityChange.dispose();
2167
2220
  this.root.dispose();
2168
2221
  this._maximizedNode = undefined;
2169
2222
  this.element.remove();
2170
2223
  }
2171
2224
  clear() {
2172
2225
  const orientation = this.root.orientation;
2173
- this.root = new BranchNode(orientation, this.proportionalLayout, this.styles, this.root.size, this.root.orthogonalSize, this._locked);
2226
+ this.root = new BranchNode(orientation, this.proportionalLayout, this.styles, this.root.size, this.root.orthogonalSize, this.locked, this.margin);
2174
2227
  }
2175
2228
  deserialize(json, deserializer) {
2176
2229
  const orientation = json.orientation;
@@ -2181,6 +2234,7 @@
2181
2234
  this.root = this._deserializeNode(root, orientation, deserializer, orthogonalSize);
2182
2235
  }
2183
2236
  _deserializeNode(node, orientation, deserializer, orthogonalSize) {
2237
+ var _a;
2184
2238
  let result;
2185
2239
  if (node.type === 'branch') {
2186
2240
  const serializedChildren = node.data;
@@ -2192,10 +2246,14 @@
2192
2246
  });
2193
2247
  result = new BranchNode(orientation, this.proportionalLayout, this.styles, node.size, // <- orthogonal size - flips at each depth
2194
2248
  orthogonalSize, // <- size - flips at each depth,
2195
- this._locked, children);
2249
+ this.locked, this.margin, children);
2196
2250
  }
2197
2251
  else {
2198
- result = new LeafNode(deserializer.fromJSON(node), orientation, orthogonalSize, node.size);
2252
+ const view = deserializer.fromJSON(node);
2253
+ if (typeof node.visible === 'boolean') {
2254
+ (_a = view.setVisible) === null || _a === void 0 ? void 0 : _a.call(view, node.visible);
2255
+ }
2256
+ result = new LeafNode(view, orientation, orthogonalSize, node.size);
2199
2257
  }
2200
2258
  return result;
2201
2259
  }
@@ -2225,7 +2283,7 @@
2225
2283
  }
2226
2284
  const oldRoot = this.root;
2227
2285
  oldRoot.element.remove();
2228
- this._root = new BranchNode(orthogonal(oldRoot.orientation), this.proportionalLayout, this.styles, this.root.orthogonalSize, this.root.size, this._locked);
2286
+ this._root = new BranchNode(orthogonal(oldRoot.orientation), this.proportionalLayout, this.styles, this.root.orthogonalSize, this.root.size, this.locked, this.margin);
2229
2287
  if (oldRoot.children.length === 0) ;
2230
2288
  else if (oldRoot.children.length === 1) {
2231
2289
  // can remove one level of redundant branching if there is only a single child
@@ -2290,19 +2348,24 @@
2290
2348
  }
2291
2349
  return findLeaf(this.root, reverse);
2292
2350
  }
2293
- constructor(proportionalLayout, styles, orientation) {
2351
+ constructor(proportionalLayout, styles, orientation, locked, margin) {
2294
2352
  this.proportionalLayout = proportionalLayout;
2295
2353
  this.styles = styles;
2296
2354
  this._locked = false;
2355
+ this._margin = 0;
2297
2356
  this._maximizedNode = undefined;
2298
2357
  this.disposable = new MutableDisposable();
2299
2358
  this._onDidChange = new Emitter();
2300
2359
  this.onDidChange = this._onDidChange.event;
2360
+ this._onDidViewVisibilityChange = new Emitter();
2361
+ this.onDidViewVisibilityChange = this._onDidViewVisibilityChange.event;
2301
2362
  this._onDidMaximizedNodeChange = new Emitter();
2302
2363
  this.onDidMaximizedNodeChange = this._onDidMaximizedNodeChange.event;
2303
2364
  this.element = document.createElement('div');
2304
2365
  this.element.className = 'grid-view';
2305
- this.root = new BranchNode(orientation, proportionalLayout, styles, 0, 0, this._locked);
2366
+ this._locked = locked !== null && locked !== void 0 ? locked : false;
2367
+ this._margin = margin !== null && margin !== void 0 ? margin : 0;
2368
+ this.root = new BranchNode(orientation, proportionalLayout, styles, 0, 0, this.locked, this.margin);
2306
2369
  }
2307
2370
  isViewVisible(location) {
2308
2371
  const [rest, index] = tail(location);
@@ -2321,6 +2384,7 @@
2321
2384
  if (!(parent instanceof BranchNode)) {
2322
2385
  throw new Error('Invalid from location');
2323
2386
  }
2387
+ this._onDidViewVisibilityChange.fire();
2324
2388
  parent.setChildVisible(index, visible);
2325
2389
  }
2326
2390
  moveView(parentLocation, from, to) {
@@ -2353,7 +2417,7 @@
2353
2417
  }
2354
2418
  const child = grandParent.removeChild(parentIndex);
2355
2419
  child.dispose();
2356
- const newParent = new BranchNode(parent.orientation, this.proportionalLayout, this.styles, parent.size, parent.orthogonalSize, this._locked);
2420
+ const newParent = new BranchNode(parent.orientation, this.proportionalLayout, this.styles, parent.size, parent.orthogonalSize, this.locked, this.margin);
2357
2421
  grandParent.addChild(newParent, parent.size, parentIndex);
2358
2422
  const newSibling = new LeafNode(parent.view, grandParent.orientation, parent.size);
2359
2423
  newParent.addChild(newSibling, newSiblingSize, 0);
@@ -2592,14 +2656,18 @@
2592
2656
  this.onDidActiveChange = this._onDidActiveChange.event;
2593
2657
  this._bufferOnDidLayoutChange = new AsapEvent();
2594
2658
  this.onDidLayoutChange = this._bufferOnDidLayoutChange.onEvent;
2659
+ this._onDidViewVisibilityChangeMicroTaskQueue = new AsapEvent();
2660
+ this.onDidViewVisibilityChangeMicroTaskQueue = this._onDidViewVisibilityChangeMicroTaskQueue.onEvent;
2595
2661
  this.element.style.height = '100%';
2596
2662
  this.element.style.width = '100%';
2597
2663
  options.parentElement.appendChild(this.element);
2598
- this.gridview = new Gridview(!!options.proportionalLayout, options.styles, options.orientation);
2664
+ this.gridview = new Gridview(!!options.proportionalLayout, options.styles, options.orientation, options.locked, options.margin);
2599
2665
  this.gridview.locked = !!options.locked;
2600
2666
  this.element.appendChild(this.gridview.element);
2601
2667
  this.layout(0, 0, true); // set some elements height/widths
2602
- this.addDisposables(exports.DockviewDisposable.from(() => {
2668
+ this.addDisposables(this.gridview.onDidViewVisibilityChange(() => this._onDidViewVisibilityChangeMicroTaskQueue.fire()), this.onDidViewVisibilityChangeMicroTaskQueue(() => {
2669
+ this.layout(this.width, this.height, true);
2670
+ }), exports.DockviewDisposable.from(() => {
2603
2671
  var _a;
2604
2672
  (_a = this.element.parentElement) === null || _a === void 0 ? void 0 : _a.removeChild(this.element);
2605
2673
  }), this.gridview.onDidChange(() => {
@@ -3177,6 +3245,9 @@
3177
3245
  get totalPanels() {
3178
3246
  return this.component.totalPanels;
3179
3247
  }
3248
+ get gap() {
3249
+ return this.component.gap;
3250
+ }
3180
3251
  /**
3181
3252
  * Invoked when the active group changes. May be undefined if no group is active.
3182
3253
  */
@@ -3213,6 +3284,9 @@
3213
3284
  get onDidRemovePanel() {
3214
3285
  return this.component.onDidRemovePanel;
3215
3286
  }
3287
+ get onDidMovePanel() {
3288
+ return this.component.onDidMovePanel;
3289
+ }
3216
3290
  /**
3217
3291
  * Invoked after a layout is deserialzied using the `fromJSON` method.
3218
3292
  */
@@ -3353,8 +3427,8 @@
3353
3427
  /**
3354
3428
  * Add a floating group
3355
3429
  */
3356
- addFloatingGroup(item, coord) {
3357
- return this.component.addFloatingGroup(item, coord);
3430
+ addFloatingGroup(item, options) {
3431
+ return this.component.addFloatingGroup(item, options);
3358
3432
  }
3359
3433
  /**
3360
3434
  * Create a component from a serialized object.
@@ -3404,6 +3478,9 @@
3404
3478
  addPopoutGroup(item, options) {
3405
3479
  return this.component.addPopoutGroup(item, options);
3406
3480
  }
3481
+ setGap(gap) {
3482
+ this.component.updateOptions({ gap });
3483
+ }
3407
3484
  }
3408
3485
 
3409
3486
  class DragHandler extends CompositeDisposable {
@@ -4773,7 +4850,8 @@
4773
4850
  this.accessor.addFloatingGroup(this.group, {
4774
4851
  x: left - rootLeft + 20,
4775
4852
  y: top - rootTop + 20,
4776
- }, { inDragMode: true });
4853
+ inDragMode: true,
4854
+ });
4777
4855
  }
4778
4856
  }), addDisposableListener(this.tabContainer, 'mousedown', (event) => {
4779
4857
  if (event.defaultPrevented) {
@@ -4842,7 +4920,8 @@
4842
4920
  this.accessor.addFloatingGroup(panel, {
4843
4921
  x: left - rootLeft,
4844
4922
  y: top - rootTop,
4845
- }, { inDragMode: true });
4923
+ inDragMode: true,
4924
+ });
4846
4925
  return;
4847
4926
  }
4848
4927
  const isLeftClick = event.button === 0;
@@ -4915,6 +4994,7 @@
4915
4994
  rootOverlayModel: undefined,
4916
4995
  locked: undefined,
4917
4996
  disableDnd: undefined,
4997
+ gap: undefined,
4918
4998
  };
4919
4999
  return Object.keys(properties);
4920
5000
  })();
@@ -5645,6 +5725,9 @@
5645
5725
  get isActive() {
5646
5726
  return this.api.isActive;
5647
5727
  }
5728
+ get isVisible() {
5729
+ return this.api.isVisible;
5730
+ }
5648
5731
  constructor(id, component, options, api) {
5649
5732
  super(id, component, api !== null && api !== void 0 ? api : new GridviewPanelApiImpl(id, component));
5650
5733
  this._evaluatedMinimumWidth = 0;
@@ -6407,12 +6490,7 @@
6407
6490
  this._element.appendChild(this.options.content);
6408
6491
  this.options.container.appendChild(this._element);
6409
6492
  // if input bad resize within acceptable boundaries
6410
- this.setBounds({
6411
- height: this.options.height,
6412
- width: this.options.width,
6413
- top: this.options.top,
6414
- left: this.options.left,
6415
- });
6493
+ this.setBounds(Object.assign(Object.assign(Object.assign(Object.assign({ height: this.options.height, width: this.options.width }, ('top' in this.options && { top: this.options.top })), ('bottom' in this.options && { bottom: this.options.bottom })), ('left' in this.options && { left: this.options.left })), ('right' in this.options && { right: this.options.right })));
6416
6494
  }
6417
6495
  setBounds(bounds = {}) {
6418
6496
  if (typeof bounds.height === 'number') {
@@ -6421,11 +6499,25 @@
6421
6499
  if (typeof bounds.width === 'number') {
6422
6500
  this._element.style.width = `${bounds.width}px`;
6423
6501
  }
6424
- if (typeof bounds.top === 'number') {
6502
+ if ('top' in bounds && typeof bounds.top === 'number') {
6425
6503
  this._element.style.top = `${bounds.top}px`;
6504
+ this._element.style.bottom = 'auto';
6505
+ this.verticalAlignment = 'top';
6506
+ }
6507
+ if ('bottom' in bounds && typeof bounds.bottom === 'number') {
6508
+ this._element.style.bottom = `${bounds.bottom}px`;
6509
+ this._element.style.top = 'auto';
6510
+ this.verticalAlignment = 'bottom';
6426
6511
  }
6427
- if (typeof bounds.left === 'number') {
6512
+ if ('left' in bounds && typeof bounds.left === 'number') {
6428
6513
  this._element.style.left = `${bounds.left}px`;
6514
+ this._element.style.right = 'auto';
6515
+ this.horiziontalAlignment = 'left';
6516
+ }
6517
+ if ('right' in bounds && typeof bounds.right === 'number') {
6518
+ this._element.style.right = `${bounds.right}px`;
6519
+ this._element.style.left = 'auto';
6520
+ this.horiziontalAlignment = 'right';
6429
6521
  }
6430
6522
  const containerRect = this.options.container.getBoundingClientRect();
6431
6523
  const overlayRect = this._element.getBoundingClientRect();
@@ -6433,24 +6525,54 @@
6433
6525
  // a minimum width of minimumViewportWidth must be inside the viewport
6434
6526
  const xOffset = Math.max(0, this.getMinimumWidth(overlayRect.width));
6435
6527
  // a minimum height of minimumViewportHeight must be inside the viewport
6436
- const yOffset = typeof this.options.minimumInViewportHeight === 'number'
6437
- ? Math.max(0, this.getMinimumHeight(overlayRect.height))
6438
- : 0;
6439
- const left = clamp(overlayRect.left - containerRect.left, -xOffset, Math.max(0, containerRect.width - overlayRect.width + xOffset));
6440
- const top = clamp(overlayRect.top - containerRect.top, -yOffset, Math.max(0, containerRect.height - overlayRect.height + yOffset));
6441
- this._element.style.left = `${left}px`;
6442
- this._element.style.top = `${top}px`;
6528
+ const yOffset = Math.max(0, this.getMinimumHeight(overlayRect.height));
6529
+ if (this.verticalAlignment === 'top') {
6530
+ const top = clamp(overlayRect.top - containerRect.top, -yOffset, Math.max(0, containerRect.height - overlayRect.height + yOffset));
6531
+ this._element.style.top = `${top}px`;
6532
+ this._element.style.bottom = 'auto';
6533
+ }
6534
+ if (this.verticalAlignment === 'bottom') {
6535
+ const bottom = clamp(containerRect.bottom - overlayRect.bottom, -yOffset, Math.max(0, containerRect.height - overlayRect.height + yOffset));
6536
+ this._element.style.bottom = `${bottom}px`;
6537
+ this._element.style.top = 'auto';
6538
+ }
6539
+ if (this.horiziontalAlignment === 'left') {
6540
+ const left = clamp(overlayRect.left - containerRect.left, -xOffset, Math.max(0, containerRect.width - overlayRect.width + xOffset));
6541
+ this._element.style.left = `${left}px`;
6542
+ this._element.style.right = 'auto';
6543
+ }
6544
+ if (this.horiziontalAlignment === 'right') {
6545
+ const right = clamp(containerRect.right - overlayRect.right, -xOffset, Math.max(0, containerRect.width - overlayRect.width + xOffset));
6546
+ this._element.style.right = `${right}px`;
6547
+ this._element.style.left = 'auto';
6548
+ }
6443
6549
  this._onDidChange.fire();
6444
6550
  }
6445
6551
  toJSON() {
6446
6552
  const container = this.options.container.getBoundingClientRect();
6447
6553
  const element = this._element.getBoundingClientRect();
6448
- return {
6449
- top: element.top - container.top,
6450
- left: element.left - container.left,
6451
- width: element.width,
6452
- height: element.height,
6453
- };
6554
+ const result = {};
6555
+ if (this.verticalAlignment === 'top') {
6556
+ result.top = parseFloat(this._element.style.top);
6557
+ }
6558
+ else if (this.verticalAlignment === 'bottom') {
6559
+ result.bottom = parseFloat(this._element.style.bottom);
6560
+ }
6561
+ else {
6562
+ result.top = element.top - container.top;
6563
+ }
6564
+ if (this.horiziontalAlignment === 'left') {
6565
+ result.left = parseFloat(this._element.style.left);
6566
+ }
6567
+ else if (this.horiziontalAlignment === 'right') {
6568
+ result.right = parseFloat(this._element.style.right);
6569
+ }
6570
+ else {
6571
+ result.left = element.left - container.left;
6572
+ }
6573
+ result.width = element.width;
6574
+ result.height = element.height;
6575
+ return result;
6454
6576
  }
6455
6577
  setupDrag(dragTarget, options = { inDragMode: false }) {
6456
6578
  const move = new MutableDisposable();
@@ -6482,12 +6604,30 @@
6482
6604
  };
6483
6605
  }
6484
6606
  const xOffset = Math.max(0, this.getMinimumWidth(overlayRect.width));
6485
- const yOffset = Math.max(0, this.options.minimumInViewportHeight
6486
- ? this.getMinimumHeight(overlayRect.height)
6487
- : 0);
6488
- const left = clamp(x - offset.x, -xOffset, Math.max(0, containerRect.width - overlayRect.width + xOffset));
6607
+ const yOffset = Math.max(0, this.getMinimumHeight(overlayRect.height));
6489
6608
  const top = clamp(y - offset.y, -yOffset, Math.max(0, containerRect.height - overlayRect.height + yOffset));
6490
- this.setBounds({ top, left });
6609
+ const bottom = clamp(offset.y -
6610
+ y +
6611
+ containerRect.height -
6612
+ overlayRect.height, -yOffset, Math.max(0, containerRect.height - overlayRect.height + yOffset));
6613
+ const left = clamp(x - offset.x, -xOffset, Math.max(0, containerRect.width - overlayRect.width + xOffset));
6614
+ const right = clamp(offset.x - x + containerRect.width - overlayRect.width, -xOffset, Math.max(0, containerRect.width - overlayRect.width + xOffset));
6615
+ const bounds = {};
6616
+ // Anchor to top or to bottom depending on which one is closer
6617
+ if (top <= bottom) {
6618
+ bounds.top = top;
6619
+ }
6620
+ else {
6621
+ bounds.bottom = bottom;
6622
+ }
6623
+ // Anchor to left or to right depending on which one is closer
6624
+ if (left <= right) {
6625
+ bounds.left = left;
6626
+ }
6627
+ else {
6628
+ bounds.right = right;
6629
+ }
6630
+ this.setBounds(bounds);
6491
6631
  }), addDisposableWindowListener(window, 'mouseup', () => {
6492
6632
  toggleClass(this._element, 'dv-resize-container-dragging', false);
6493
6633
  move.dispose();
@@ -6555,8 +6695,10 @@
6555
6695
  };
6556
6696
  }
6557
6697
  let top = undefined;
6698
+ let bottom = undefined;
6558
6699
  let height = undefined;
6559
6700
  let left = undefined;
6701
+ let right = undefined;
6560
6702
  let width = undefined;
6561
6703
  const moveTop = () => {
6562
6704
  top = clamp(y, -Number.MAX_VALUE, startPosition.originalY +
@@ -6570,6 +6712,7 @@
6570
6712
  startPosition.originalY +
6571
6713
  startPosition.originalHeight -
6572
6714
  top;
6715
+ bottom = containerRect.height - top - height;
6573
6716
  };
6574
6717
  const moveBottom = () => {
6575
6718
  top =
@@ -6581,6 +6724,7 @@
6581
6724
  ? -top +
6582
6725
  this.options.minimumInViewportHeight
6583
6726
  : Overlay.MINIMUM_HEIGHT, Number.MAX_VALUE);
6727
+ bottom = containerRect.height - top - height;
6584
6728
  };
6585
6729
  const moveLeft = () => {
6586
6730
  left = clamp(x, -Number.MAX_VALUE, startPosition.originalX +
@@ -6594,6 +6738,7 @@
6594
6738
  startPosition.originalX +
6595
6739
  startPosition.originalWidth -
6596
6740
  left;
6741
+ right = containerRect.width - left - width;
6597
6742
  };
6598
6743
  const moveRight = () => {
6599
6744
  left =
@@ -6605,6 +6750,7 @@
6605
6750
  ? -left +
6606
6751
  this.options.minimumInViewportWidth
6607
6752
  : Overlay.MINIMUM_WIDTH, Number.MAX_VALUE);
6753
+ right = containerRect.width - left - width;
6608
6754
  };
6609
6755
  switch (direction) {
6610
6756
  case 'top':
@@ -6636,7 +6782,24 @@
6636
6782
  moveRight();
6637
6783
  break;
6638
6784
  }
6639
- this.setBounds({ height, width, top, left });
6785
+ const bounds = {};
6786
+ // Anchor to top or to bottom depending on which one is closer
6787
+ if (top <= bottom) {
6788
+ bounds.top = top;
6789
+ }
6790
+ else {
6791
+ bounds.bottom = bottom;
6792
+ }
6793
+ // Anchor to left or to right depending on which one is closer
6794
+ if (left <= right) {
6795
+ bounds.left = left;
6796
+ }
6797
+ else {
6798
+ bounds.right = right;
6799
+ }
6800
+ bounds.height = height;
6801
+ bounds.width = width;
6802
+ this.setBounds(bounds);
6640
6803
  }), {
6641
6804
  dispose: () => {
6642
6805
  for (const iframe of iframes) {
@@ -6659,7 +6822,7 @@
6659
6822
  if (typeof this.options.minimumInViewportHeight === 'number') {
6660
6823
  return height - this.options.minimumInViewportHeight;
6661
6824
  }
6662
- return height;
6825
+ return 0;
6663
6826
  }
6664
6827
  dispose() {
6665
6828
  this._element.remove();
@@ -6682,7 +6845,7 @@
6682
6845
  }
6683
6846
 
6684
6847
  const DEFAULT_FLOATING_GROUP_OVERFLOW_SIZE = 100;
6685
- const DEFAULT_FLOATING_GROUP_POSITION = { left: 100, top: 100 };
6848
+ const DEFAULT_FLOATING_GROUP_POSITION = { left: 100, top: 100, width: 300, height: 300 };
6686
6849
 
6687
6850
  function createFocusableElement() {
6688
6851
  const element = document.createElement('div');
@@ -7014,6 +7177,9 @@
7014
7177
  get api() {
7015
7178
  return this._api;
7016
7179
  }
7180
+ get gap() {
7181
+ return this.gridview.margin;
7182
+ }
7017
7183
  constructor(options) {
7018
7184
  var _a;
7019
7185
  super({
@@ -7025,6 +7191,7 @@
7025
7191
  parentElement: options.parentElement,
7026
7192
  disableAutoResizing: options.disableAutoResizing,
7027
7193
  locked: options.locked,
7194
+ margin: options.gap,
7028
7195
  });
7029
7196
  this.nextGroupId = sequentialNumberGenerator();
7030
7197
  this._deserializer = new DefaultDockviewDeserialzier(this);
@@ -7050,9 +7217,9 @@
7050
7217
  this._onDidActivePanelChange = new Emitter();
7051
7218
  this.onDidActivePanelChange = this._onDidActivePanelChange.event;
7052
7219
  this._onDidMovePanel = new Emitter();
7220
+ this.onDidMovePanel = this._onDidMovePanel.event;
7053
7221
  this._floatingGroups = [];
7054
7222
  this._popoutGroups = [];
7055
- this._ignoreEvents = 0;
7056
7223
  this._onDidRemoveGroup = new Emitter();
7057
7224
  this.onDidRemoveGroup = this._onDidRemoveGroup.event;
7058
7225
  this._onDidAddGroup = new Emitter();
@@ -7066,7 +7233,9 @@
7066
7233
  this.overlayRenderContainer = new OverlayRenderContainer(gready);
7067
7234
  toggleClass(this.gridview.element, 'dv-dockview', true);
7068
7235
  toggleClass(this.element, 'dv-debug', !!options.debug);
7069
- this.addDisposables(this.overlayRenderContainer, this._onWillDragPanel, this._onWillDragGroup, this._onWillShowOverlay, this._onDidActivePanelChange, this._onDidAddPanel, this._onDidRemovePanel, this._onDidLayoutFromJSON, this._onDidDrop, this._onWillDrop, this._onDidMovePanel, this._onDidAddGroup, this._onDidRemoveGroup, this._onDidActiveGroupChange, this._onUnhandledDragOverEvent, this.onDidAdd((event) => {
7236
+ this.addDisposables(this.overlayRenderContainer, this._onWillDragPanel, this._onWillDragGroup, this._onWillShowOverlay, this._onDidActivePanelChange, this._onDidAddPanel, this._onDidRemovePanel, this._onDidLayoutFromJSON, this._onDidDrop, this._onWillDrop, this._onDidMovePanel, this._onDidAddGroup, this._onDidRemoveGroup, this._onDidActiveGroupChange, this._onUnhandledDragOverEvent, this.onDidViewVisibilityChangeMicroTaskQueue(() => {
7237
+ this.updateWatermark();
7238
+ }), this.onDidAdd((event) => {
7070
7239
  if (!this._moving) {
7071
7240
  this._onDidAddGroup.fire(event);
7072
7241
  }
@@ -7080,7 +7249,7 @@
7080
7249
  }
7081
7250
  }), exports.DockviewEvent.any(this.onDidAdd, this.onDidRemove)(() => {
7082
7251
  this.updateWatermark();
7083
- }), exports.DockviewEvent.any(this.onDidAddPanel, this.onDidRemovePanel, this.onDidActivePanelChange)(() => {
7252
+ }), exports.DockviewEvent.any(this.onDidAddPanel, this.onDidRemovePanel, this.onDidAddGroup, this.onDidRemove, this.onDidMovePanel, this.onDidActivePanelChange)(() => {
7084
7253
  this._bufferOnDidLayoutChange.fire();
7085
7254
  }), exports.DockviewDisposable.from(() => {
7086
7255
  // iterate over a copy of the array since .dispose() mutates the original array
@@ -7180,7 +7349,7 @@
7180
7349
  var _a, _b, _c;
7181
7350
  if (itemToPopout instanceof DockviewPanel &&
7182
7351
  itemToPopout.group.size === 1) {
7183
- return this.addPopoutGroup(itemToPopout.group);
7352
+ return this.addPopoutGroup(itemToPopout.group, options);
7184
7353
  }
7185
7354
  const theme = getDockviewTheme(this.gridview.element);
7186
7355
  const element = this.element;
@@ -7331,8 +7500,8 @@
7331
7500
  console.error('dockview: failed to create popout window', err);
7332
7501
  });
7333
7502
  }
7334
- addFloatingGroup(item, coord, options) {
7335
- var _a, _b, _c, _d, _e, _f, _g;
7503
+ addFloatingGroup(item, options) {
7504
+ var _a, _b, _c, _d, _e;
7336
7505
  let group;
7337
7506
  if (item instanceof DockviewPanel) {
7338
7507
  group = this.createGroup();
@@ -7377,26 +7546,62 @@
7377
7546
  }
7378
7547
  }
7379
7548
  group.model.location = { type: 'floating' };
7380
- const overlayLeft = typeof (coord === null || coord === void 0 ? void 0 : coord.x) === 'number'
7381
- ? Math.max(coord.x, 0)
7382
- : DEFAULT_FLOATING_GROUP_POSITION.left;
7383
- const overlayTop = typeof (coord === null || coord === void 0 ? void 0 : coord.y) === 'number'
7384
- ? Math.max(coord.y, 0)
7385
- : DEFAULT_FLOATING_GROUP_POSITION.top;
7386
- const overlay = new Overlay({
7387
- container: this.gridview.element,
7388
- content: group.element,
7389
- height: (_b = coord === null || coord === void 0 ? void 0 : coord.height) !== null && _b !== void 0 ? _b : 300,
7390
- width: (_c = coord === null || coord === void 0 ? void 0 : coord.width) !== null && _c !== void 0 ? _c : 300,
7391
- left: overlayLeft,
7392
- top: overlayTop,
7393
- minimumInViewportWidth: this.options.floatingGroupBounds === 'boundedWithinViewport'
7549
+ function getAnchoredBox() {
7550
+ if (options === null || options === void 0 ? void 0 : options.position) {
7551
+ const result = {};
7552
+ if ('left' in options.position) {
7553
+ result.left = Math.max(options.position.left, 0);
7554
+ }
7555
+ else if ('right' in options.position) {
7556
+ result.right = Math.max(options.position.right, 0);
7557
+ }
7558
+ else {
7559
+ result.left = DEFAULT_FLOATING_GROUP_POSITION.left;
7560
+ }
7561
+ if ('top' in options.position) {
7562
+ result.top = Math.max(options.position.top, 0);
7563
+ }
7564
+ else if ('bottom' in options.position) {
7565
+ result.bottom = Math.max(options.position.bottom, 0);
7566
+ }
7567
+ else {
7568
+ result.top = DEFAULT_FLOATING_GROUP_POSITION.top;
7569
+ }
7570
+ if (typeof options.width === 'number') {
7571
+ result.width = Math.max(options.width, 0);
7572
+ }
7573
+ else {
7574
+ result.width = DEFAULT_FLOATING_GROUP_POSITION.width;
7575
+ }
7576
+ if (typeof options.height === 'number') {
7577
+ result.height = Math.max(options.height, 0);
7578
+ }
7579
+ else {
7580
+ result.height = DEFAULT_FLOATING_GROUP_POSITION.height;
7581
+ }
7582
+ return result;
7583
+ }
7584
+ return {
7585
+ left: typeof (options === null || options === void 0 ? void 0 : options.x) === 'number'
7586
+ ? Math.max(options.x, 0)
7587
+ : DEFAULT_FLOATING_GROUP_POSITION.left,
7588
+ top: typeof (options === null || options === void 0 ? void 0 : options.y) === 'number'
7589
+ ? Math.max(options.y, 0)
7590
+ : DEFAULT_FLOATING_GROUP_POSITION.top,
7591
+ width: typeof (options === null || options === void 0 ? void 0 : options.width) === 'number'
7592
+ ? Math.max(options.width, 0)
7593
+ : DEFAULT_FLOATING_GROUP_POSITION.width,
7594
+ height: typeof (options === null || options === void 0 ? void 0 : options.height) === 'number'
7595
+ ? Math.max(options.height, 0)
7596
+ : DEFAULT_FLOATING_GROUP_POSITION.height,
7597
+ };
7598
+ }
7599
+ const anchoredBox = getAnchoredBox();
7600
+ const overlay = new Overlay(Object.assign(Object.assign({ container: this.gridview.element, content: group.element }, anchoredBox), { minimumInViewportWidth: this.options.floatingGroupBounds === 'boundedWithinViewport'
7394
7601
  ? undefined
7395
- : (_e = (_d = this.options.floatingGroupBounds) === null || _d === void 0 ? void 0 : _d.minimumWidthWithinViewport) !== null && _e !== void 0 ? _e : DEFAULT_FLOATING_GROUP_OVERFLOW_SIZE,
7396
- minimumInViewportHeight: this.options.floatingGroupBounds === 'boundedWithinViewport'
7602
+ : (_c = (_b = this.options.floatingGroupBounds) === null || _b === void 0 ? void 0 : _b.minimumWidthWithinViewport) !== null && _c !== void 0 ? _c : DEFAULT_FLOATING_GROUP_OVERFLOW_SIZE, minimumInViewportHeight: this.options.floatingGroupBounds === 'boundedWithinViewport'
7397
7603
  ? undefined
7398
- : (_g = (_f = this.options.floatingGroupBounds) === null || _f === void 0 ? void 0 : _f.minimumHeightWithinViewport) !== null && _g !== void 0 ? _g : DEFAULT_FLOATING_GROUP_OVERFLOW_SIZE,
7399
- });
7604
+ : (_e = (_d = this.options.floatingGroupBounds) === null || _d === void 0 ? void 0 : _d.minimumHeightWithinViewport) !== null && _e !== void 0 ? _e : DEFAULT_FLOATING_GROUP_OVERFLOW_SIZE }));
7400
7605
  const el = group.element.querySelector('.void-container');
7401
7606
  if (!el) {
7402
7607
  throw new Error('failed to find drag handle');
@@ -7494,12 +7699,21 @@
7494
7699
  group.overlay.minimumInViewportWidth =
7495
7700
  (_b = this.options.floatingGroupBounds) === null || _b === void 0 ? void 0 : _b.minimumWidthWithinViewport;
7496
7701
  }
7497
- group.overlay.setBounds({});
7702
+ group.overlay.setBounds();
7498
7703
  }
7499
7704
  }
7500
7705
  if (changed_rootOverlayOptions) {
7501
7706
  this._rootDropTarget.setOverlayModel(options.rootOverlayModel);
7502
7707
  }
7708
+ if (
7709
+ // if explicitly set as `undefined`
7710
+ 'gap' in options &&
7711
+ options.gap === undefined) {
7712
+ this.gridview.margin = 0;
7713
+ }
7714
+ if (typeof options.gap === 'number') {
7715
+ this.gridview.margin = options.gap;
7716
+ }
7503
7717
  this.layout(this.gridview.width, this.gridview.height, true);
7504
7718
  }
7505
7719
  layout(width, height, forceResize) {
@@ -7661,11 +7875,10 @@
7661
7875
  const { data, position } = serializedFloatingGroup;
7662
7876
  const group = createGroupFromSerializedState(data);
7663
7877
  this.addFloatingGroup(group, {
7664
- x: position.left,
7665
- y: position.top,
7666
- height: position.height,
7667
- width: position.width,
7668
- }, { skipRemoveGroup: true, inDragMode: false });
7878
+ position: position,
7879
+ skipRemoveGroup: true,
7880
+ inDragMode: false,
7881
+ });
7669
7882
  }
7670
7883
  const serializedPopoutGroups = (_b = data.popoutGroups) !== null && _b !== void 0 ? _b : [];
7671
7884
  for (const serializedPopoutGroup of serializedPopoutGroups) {
@@ -7796,15 +8009,11 @@
7796
8009
  if (options.floating) {
7797
8010
  const group = this.createGroup();
7798
8011
  this._onDidAddGroup.fire(group);
7799
- const o = typeof options.floating === 'object' &&
8012
+ const floatingGroupOptions = typeof options.floating === 'object' &&
7800
8013
  options.floating !== null
7801
8014
  ? options.floating
7802
8015
  : {};
7803
- this.addFloatingGroup(group, o, {
7804
- inDragMode: false,
7805
- skipRemoveGroup: true,
7806
- skipActiveGroup: true,
7807
- });
8016
+ this.addFloatingGroup(group, Object.assign(Object.assign({}, floatingGroupOptions), { inDragMode: false, skipRemoveGroup: true, skipActiveGroup: true }));
7808
8017
  panel = this.createPanel(options, group);
7809
8018
  group.model.openPanel(panel, {
7810
8019
  skipSetActive: options.inactive,
@@ -7843,11 +8052,7 @@
7843
8052
  options.floating !== null
7844
8053
  ? options.floating
7845
8054
  : {};
7846
- this.addFloatingGroup(group, coordinates, {
7847
- inDragMode: false,
7848
- skipRemoveGroup: true,
7849
- skipActiveGroup: true,
7850
- });
8055
+ this.addFloatingGroup(group, Object.assign(Object.assign({}, coordinates), { inDragMode: false, skipRemoveGroup: true, skipActiveGroup: true }));
7851
8056
  panel = this.createPanel(options, group);
7852
8057
  group.model.openPanel(panel, {
7853
8058
  skipSetActive: options.inactive,
@@ -7902,6 +8107,7 @@
7902
8107
  });
7903
8108
  const watermarkContainer = document.createElement('div');
7904
8109
  watermarkContainer.className = 'dv-watermark-container';
8110
+ addTestId(watermarkContainer, 'watermark-component');
7905
8111
  watermarkContainer.appendChild(this.watermark.element);
7906
8112
  this.gridview.element.appendChild(watermarkContainer);
7907
8113
  }
@@ -8090,6 +8296,7 @@
8090
8296
  this.doSetGroupAndPanelActive(destinationGroup);
8091
8297
  this._onDidMovePanel.fire({
8092
8298
  panel: removedPanel,
8299
+ from: sourceGroup,
8093
8300
  });
8094
8301
  }
8095
8302
  else {
@@ -8113,6 +8320,10 @@
8113
8320
  // if a group has one tab - we are essentially moving the 'group'
8114
8321
  // which is equivalent to swapping two views in this case
8115
8322
  this.gridview.moveView(sourceParentLocation, from, to);
8323
+ this._onDidMovePanel.fire({
8324
+ panel: this.getGroupPanel(sourceItemId),
8325
+ from: sourceGroup,
8326
+ });
8116
8327
  return;
8117
8328
  }
8118
8329
  }
@@ -8126,6 +8337,10 @@
8126
8337
  const location = getRelativeLocation(this.gridview.orientation, updatedReferenceLocation, destinationTarget);
8127
8338
  this.movingLock(() => this.doAddGroup(targetGroup, location));
8128
8339
  this.doSetGroupAndPanelActive(targetGroup);
8340
+ this._onDidMovePanel.fire({
8341
+ panel: this.getGroupPanel(sourceItemId),
8342
+ from: sourceGroup,
8343
+ });
8129
8344
  }
8130
8345
  else {
8131
8346
  /**
@@ -8145,6 +8360,10 @@
8145
8360
  skipSetGroupActive: true,
8146
8361
  }));
8147
8362
  this.doSetGroupAndPanelActive(group);
8363
+ this._onDidMovePanel.fire({
8364
+ panel: removedPanel,
8365
+ from: sourceGroup,
8366
+ });
8148
8367
  }
8149
8368
  }
8150
8369
  }
@@ -8169,9 +8388,6 @@
8169
8388
  }
8170
8389
  });
8171
8390
  this.doSetGroupAndPanelActive(to);
8172
- panels.forEach((panel) => {
8173
- this._onDidMovePanel.fire({ panel });
8174
- });
8175
8391
  }
8176
8392
  else {
8177
8393
  switch (from.api.location.type) {
@@ -8197,10 +8413,10 @@
8197
8413
  const referenceLocation = getGridLocation(to.element);
8198
8414
  const dropLocation = getRelativeLocation(this.gridview.orientation, referenceLocation, target);
8199
8415
  this.gridview.addView(from, exports.Sizing.Distribute, dropLocation);
8200
- from.panels.forEach((panel) => {
8201
- this._onDidMovePanel.fire({ panel });
8202
- });
8203
8416
  }
8417
+ from.panels.forEach((panel) => {
8418
+ this._onDidMovePanel.fire({ panel, from });
8419
+ });
8204
8420
  }
8205
8421
  doSetGroupActive(group) {
8206
8422
  super.doSetGroupActive(group);