dockview-react 1.14.2 → 1.15.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-react
3
- * @version 1.14.2
3
+ * @version 1.15.0
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(() => {
@@ -3213,6 +3281,9 @@
3213
3281
  get onDidRemovePanel() {
3214
3282
  return this.component.onDidRemovePanel;
3215
3283
  }
3284
+ get onDidMovePanel() {
3285
+ return this.component.onDidMovePanel;
3286
+ }
3216
3287
  /**
3217
3288
  * Invoked after a layout is deserialzied using the `fromJSON` method.
3218
3289
  */
@@ -3353,8 +3424,8 @@
3353
3424
  /**
3354
3425
  * Add a floating group
3355
3426
  */
3356
- addFloatingGroup(item, coord) {
3357
- return this.component.addFloatingGroup(item, coord);
3427
+ addFloatingGroup(item, options) {
3428
+ return this.component.addFloatingGroup(item, options);
3358
3429
  }
3359
3430
  /**
3360
3431
  * Create a component from a serialized object.
@@ -3404,6 +3475,9 @@
3404
3475
  addPopoutGroup(item, options) {
3405
3476
  return this.component.addPopoutGroup(item, options);
3406
3477
  }
3478
+ setGap(gap) {
3479
+ this.component.updateOptions({ gap });
3480
+ }
3407
3481
  }
3408
3482
 
3409
3483
  class DragHandler extends CompositeDisposable {
@@ -4773,7 +4847,8 @@
4773
4847
  this.accessor.addFloatingGroup(this.group, {
4774
4848
  x: left - rootLeft + 20,
4775
4849
  y: top - rootTop + 20,
4776
- }, { inDragMode: true });
4850
+ inDragMode: true,
4851
+ });
4777
4852
  }
4778
4853
  }), addDisposableListener(this.tabContainer, 'mousedown', (event) => {
4779
4854
  if (event.defaultPrevented) {
@@ -4842,7 +4917,8 @@
4842
4917
  this.accessor.addFloatingGroup(panel, {
4843
4918
  x: left - rootLeft,
4844
4919
  y: top - rootTop,
4845
- }, { inDragMode: true });
4920
+ inDragMode: true,
4921
+ });
4846
4922
  return;
4847
4923
  }
4848
4924
  const isLeftClick = event.button === 0;
@@ -4915,6 +4991,7 @@
4915
4991
  rootOverlayModel: undefined,
4916
4992
  locked: undefined,
4917
4993
  disableDnd: undefined,
4994
+ gap: undefined,
4918
4995
  };
4919
4996
  return Object.keys(properties);
4920
4997
  })();
@@ -5645,6 +5722,9 @@
5645
5722
  get isActive() {
5646
5723
  return this.api.isActive;
5647
5724
  }
5725
+ get isVisible() {
5726
+ return this.api.isVisible;
5727
+ }
5648
5728
  constructor(id, component, options, api) {
5649
5729
  super(id, component, api !== null && api !== void 0 ? api : new GridviewPanelApiImpl(id, component));
5650
5730
  this._evaluatedMinimumWidth = 0;
@@ -6407,12 +6487,7 @@
6407
6487
  this._element.appendChild(this.options.content);
6408
6488
  this.options.container.appendChild(this._element);
6409
6489
  // 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
- });
6490
+ 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
6491
  }
6417
6492
  setBounds(bounds = {}) {
6418
6493
  if (typeof bounds.height === 'number') {
@@ -6421,11 +6496,25 @@
6421
6496
  if (typeof bounds.width === 'number') {
6422
6497
  this._element.style.width = `${bounds.width}px`;
6423
6498
  }
6424
- if (typeof bounds.top === 'number') {
6499
+ if ('top' in bounds && typeof bounds.top === 'number') {
6425
6500
  this._element.style.top = `${bounds.top}px`;
6501
+ this._element.style.bottom = 'auto';
6502
+ this.verticalAlignment = 'top';
6503
+ }
6504
+ if ('bottom' in bounds && typeof bounds.bottom === 'number') {
6505
+ this._element.style.bottom = `${bounds.bottom}px`;
6506
+ this._element.style.top = 'auto';
6507
+ this.verticalAlignment = 'bottom';
6426
6508
  }
6427
- if (typeof bounds.left === 'number') {
6509
+ if ('left' in bounds && typeof bounds.left === 'number') {
6428
6510
  this._element.style.left = `${bounds.left}px`;
6511
+ this._element.style.right = 'auto';
6512
+ this.horiziontalAlignment = 'left';
6513
+ }
6514
+ if ('right' in bounds && typeof bounds.right === 'number') {
6515
+ this._element.style.right = `${bounds.right}px`;
6516
+ this._element.style.left = 'auto';
6517
+ this.horiziontalAlignment = 'right';
6429
6518
  }
6430
6519
  const containerRect = this.options.container.getBoundingClientRect();
6431
6520
  const overlayRect = this._element.getBoundingClientRect();
@@ -6433,24 +6522,54 @@
6433
6522
  // a minimum width of minimumViewportWidth must be inside the viewport
6434
6523
  const xOffset = Math.max(0, this.getMinimumWidth(overlayRect.width));
6435
6524
  // 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`;
6525
+ const yOffset = Math.max(0, this.getMinimumHeight(overlayRect.height));
6526
+ if (this.verticalAlignment === 'top') {
6527
+ const top = clamp(overlayRect.top - containerRect.top, -yOffset, Math.max(0, containerRect.height - overlayRect.height + yOffset));
6528
+ this._element.style.top = `${top}px`;
6529
+ this._element.style.bottom = 'auto';
6530
+ }
6531
+ if (this.verticalAlignment === 'bottom') {
6532
+ const bottom = clamp(containerRect.bottom - overlayRect.bottom, -yOffset, Math.max(0, containerRect.height - overlayRect.height + yOffset));
6533
+ this._element.style.bottom = `${bottom}px`;
6534
+ this._element.style.top = 'auto';
6535
+ }
6536
+ if (this.horiziontalAlignment === 'left') {
6537
+ const left = clamp(overlayRect.left - containerRect.left, -xOffset, Math.max(0, containerRect.width - overlayRect.width + xOffset));
6538
+ this._element.style.left = `${left}px`;
6539
+ this._element.style.right = 'auto';
6540
+ }
6541
+ if (this.horiziontalAlignment === 'right') {
6542
+ const right = clamp(containerRect.right - overlayRect.right, -xOffset, Math.max(0, containerRect.width - overlayRect.width + xOffset));
6543
+ this._element.style.right = `${right}px`;
6544
+ this._element.style.left = 'auto';
6545
+ }
6443
6546
  this._onDidChange.fire();
6444
6547
  }
6445
6548
  toJSON() {
6446
6549
  const container = this.options.container.getBoundingClientRect();
6447
6550
  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
- };
6551
+ const result = {};
6552
+ if (this.verticalAlignment === 'top') {
6553
+ result.top = parseFloat(this._element.style.top);
6554
+ }
6555
+ else if (this.verticalAlignment === 'bottom') {
6556
+ result.bottom = parseFloat(this._element.style.bottom);
6557
+ }
6558
+ else {
6559
+ result.top = element.top - container.top;
6560
+ }
6561
+ if (this.horiziontalAlignment === 'left') {
6562
+ result.left = parseFloat(this._element.style.left);
6563
+ }
6564
+ else if (this.horiziontalAlignment === 'right') {
6565
+ result.right = parseFloat(this._element.style.right);
6566
+ }
6567
+ else {
6568
+ result.left = element.left - container.left;
6569
+ }
6570
+ result.width = element.width;
6571
+ result.height = element.height;
6572
+ return result;
6454
6573
  }
6455
6574
  setupDrag(dragTarget, options = { inDragMode: false }) {
6456
6575
  const move = new MutableDisposable();
@@ -6482,12 +6601,30 @@
6482
6601
  };
6483
6602
  }
6484
6603
  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));
6604
+ const yOffset = Math.max(0, this.getMinimumHeight(overlayRect.height));
6489
6605
  const top = clamp(y - offset.y, -yOffset, Math.max(0, containerRect.height - overlayRect.height + yOffset));
6490
- this.setBounds({ top, left });
6606
+ const bottom = clamp(offset.y -
6607
+ y +
6608
+ containerRect.height -
6609
+ overlayRect.height, -yOffset, Math.max(0, containerRect.height - overlayRect.height + yOffset));
6610
+ const left = clamp(x - offset.x, -xOffset, Math.max(0, containerRect.width - overlayRect.width + xOffset));
6611
+ const right = clamp(offset.x - x + containerRect.width - overlayRect.width, -xOffset, Math.max(0, containerRect.width - overlayRect.width + xOffset));
6612
+ const bounds = {};
6613
+ // Anchor to top or to bottom depending on which one is closer
6614
+ if (top <= bottom) {
6615
+ bounds.top = top;
6616
+ }
6617
+ else {
6618
+ bounds.bottom = bottom;
6619
+ }
6620
+ // Anchor to left or to right depending on which one is closer
6621
+ if (left <= right) {
6622
+ bounds.left = left;
6623
+ }
6624
+ else {
6625
+ bounds.right = right;
6626
+ }
6627
+ this.setBounds(bounds);
6491
6628
  }), addDisposableWindowListener(window, 'mouseup', () => {
6492
6629
  toggleClass(this._element, 'dv-resize-container-dragging', false);
6493
6630
  move.dispose();
@@ -6555,8 +6692,10 @@
6555
6692
  };
6556
6693
  }
6557
6694
  let top = undefined;
6695
+ let bottom = undefined;
6558
6696
  let height = undefined;
6559
6697
  let left = undefined;
6698
+ let right = undefined;
6560
6699
  let width = undefined;
6561
6700
  const moveTop = () => {
6562
6701
  top = clamp(y, -Number.MAX_VALUE, startPosition.originalY +
@@ -6570,6 +6709,7 @@
6570
6709
  startPosition.originalY +
6571
6710
  startPosition.originalHeight -
6572
6711
  top;
6712
+ bottom = containerRect.height - top - height;
6573
6713
  };
6574
6714
  const moveBottom = () => {
6575
6715
  top =
@@ -6581,6 +6721,7 @@
6581
6721
  ? -top +
6582
6722
  this.options.minimumInViewportHeight
6583
6723
  : Overlay.MINIMUM_HEIGHT, Number.MAX_VALUE);
6724
+ bottom = containerRect.height - top - height;
6584
6725
  };
6585
6726
  const moveLeft = () => {
6586
6727
  left = clamp(x, -Number.MAX_VALUE, startPosition.originalX +
@@ -6594,6 +6735,7 @@
6594
6735
  startPosition.originalX +
6595
6736
  startPosition.originalWidth -
6596
6737
  left;
6738
+ right = containerRect.width - left - width;
6597
6739
  };
6598
6740
  const moveRight = () => {
6599
6741
  left =
@@ -6605,6 +6747,7 @@
6605
6747
  ? -left +
6606
6748
  this.options.minimumInViewportWidth
6607
6749
  : Overlay.MINIMUM_WIDTH, Number.MAX_VALUE);
6750
+ right = containerRect.width - left - width;
6608
6751
  };
6609
6752
  switch (direction) {
6610
6753
  case 'top':
@@ -6636,7 +6779,24 @@
6636
6779
  moveRight();
6637
6780
  break;
6638
6781
  }
6639
- this.setBounds({ height, width, top, left });
6782
+ const bounds = {};
6783
+ // Anchor to top or to bottom depending on which one is closer
6784
+ if (top <= bottom) {
6785
+ bounds.top = top;
6786
+ }
6787
+ else {
6788
+ bounds.bottom = bottom;
6789
+ }
6790
+ // Anchor to left or to right depending on which one is closer
6791
+ if (left <= right) {
6792
+ bounds.left = left;
6793
+ }
6794
+ else {
6795
+ bounds.right = right;
6796
+ }
6797
+ bounds.height = height;
6798
+ bounds.width = width;
6799
+ this.setBounds(bounds);
6640
6800
  }), {
6641
6801
  dispose: () => {
6642
6802
  for (const iframe of iframes) {
@@ -6659,7 +6819,7 @@
6659
6819
  if (typeof this.options.minimumInViewportHeight === 'number') {
6660
6820
  return height - this.options.minimumInViewportHeight;
6661
6821
  }
6662
- return height;
6822
+ return 0;
6663
6823
  }
6664
6824
  dispose() {
6665
6825
  this._element.remove();
@@ -6682,7 +6842,7 @@
6682
6842
  }
6683
6843
 
6684
6844
  const DEFAULT_FLOATING_GROUP_OVERFLOW_SIZE = 100;
6685
- const DEFAULT_FLOATING_GROUP_POSITION = { left: 100, top: 100 };
6845
+ const DEFAULT_FLOATING_GROUP_POSITION = { left: 100, top: 100, width: 300, height: 300 };
6686
6846
 
6687
6847
  function createFocusableElement() {
6688
6848
  const element = document.createElement('div');
@@ -7025,6 +7185,7 @@
7025
7185
  parentElement: options.parentElement,
7026
7186
  disableAutoResizing: options.disableAutoResizing,
7027
7187
  locked: options.locked,
7188
+ margin: options.gap,
7028
7189
  });
7029
7190
  this.nextGroupId = sequentialNumberGenerator();
7030
7191
  this._deserializer = new DefaultDockviewDeserialzier(this);
@@ -7050,9 +7211,9 @@
7050
7211
  this._onDidActivePanelChange = new Emitter();
7051
7212
  this.onDidActivePanelChange = this._onDidActivePanelChange.event;
7052
7213
  this._onDidMovePanel = new Emitter();
7214
+ this.onDidMovePanel = this._onDidMovePanel.event;
7053
7215
  this._floatingGroups = [];
7054
7216
  this._popoutGroups = [];
7055
- this._ignoreEvents = 0;
7056
7217
  this._onDidRemoveGroup = new Emitter();
7057
7218
  this.onDidRemoveGroup = this._onDidRemoveGroup.event;
7058
7219
  this._onDidAddGroup = new Emitter();
@@ -7066,7 +7227,9 @@
7066
7227
  this.overlayRenderContainer = new OverlayRenderContainer(gready);
7067
7228
  toggleClass(this.gridview.element, 'dv-dockview', true);
7068
7229
  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) => {
7230
+ 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(() => {
7231
+ this.updateWatermark();
7232
+ }), this.onDidAdd((event) => {
7070
7233
  if (!this._moving) {
7071
7234
  this._onDidAddGroup.fire(event);
7072
7235
  }
@@ -7080,7 +7243,7 @@
7080
7243
  }
7081
7244
  }), exports.DockviewEvent.any(this.onDidAdd, this.onDidRemove)(() => {
7082
7245
  this.updateWatermark();
7083
- }), exports.DockviewEvent.any(this.onDidAddPanel, this.onDidRemovePanel, this.onDidActivePanelChange)(() => {
7246
+ }), exports.DockviewEvent.any(this.onDidAddPanel, this.onDidRemovePanel, this.onDidAddGroup, this.onDidRemove, this.onDidMovePanel, this.onDidActivePanelChange)(() => {
7084
7247
  this._bufferOnDidLayoutChange.fire();
7085
7248
  }), exports.DockviewDisposable.from(() => {
7086
7249
  // iterate over a copy of the array since .dispose() mutates the original array
@@ -7331,8 +7494,8 @@
7331
7494
  console.error('dockview: failed to create popout window', err);
7332
7495
  });
7333
7496
  }
7334
- addFloatingGroup(item, coord, options) {
7335
- var _a, _b, _c, _d, _e, _f, _g;
7497
+ addFloatingGroup(item, options) {
7498
+ var _a, _b, _c, _d, _e;
7336
7499
  let group;
7337
7500
  if (item instanceof DockviewPanel) {
7338
7501
  group = this.createGroup();
@@ -7377,26 +7540,62 @@
7377
7540
  }
7378
7541
  }
7379
7542
  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'
7543
+ function getAnchoredBox() {
7544
+ if (options === null || options === void 0 ? void 0 : options.position) {
7545
+ const result = {};
7546
+ if ('left' in options.position) {
7547
+ result.left = Math.max(options.position.left, 0);
7548
+ }
7549
+ else if ('right' in options.position) {
7550
+ result.right = Math.max(options.position.right, 0);
7551
+ }
7552
+ else {
7553
+ result.left = DEFAULT_FLOATING_GROUP_POSITION.left;
7554
+ }
7555
+ if ('top' in options.position) {
7556
+ result.top = Math.max(options.position.top, 0);
7557
+ }
7558
+ else if ('bottom' in options.position) {
7559
+ result.bottom = Math.max(options.position.bottom, 0);
7560
+ }
7561
+ else {
7562
+ result.top = DEFAULT_FLOATING_GROUP_POSITION.top;
7563
+ }
7564
+ if ('width' in options.position) {
7565
+ result.width = Math.max(options.position.width, 0);
7566
+ }
7567
+ else {
7568
+ result.width = DEFAULT_FLOATING_GROUP_POSITION.width;
7569
+ }
7570
+ if ('height' in options.position) {
7571
+ result.height = Math.max(options.position.height, 0);
7572
+ }
7573
+ else {
7574
+ result.height = DEFAULT_FLOATING_GROUP_POSITION.height;
7575
+ }
7576
+ return result;
7577
+ }
7578
+ return {
7579
+ left: typeof (options === null || options === void 0 ? void 0 : options.x) === 'number'
7580
+ ? Math.max(options.x, 0)
7581
+ : DEFAULT_FLOATING_GROUP_POSITION.left,
7582
+ top: typeof (options === null || options === void 0 ? void 0 : options.y) === 'number'
7583
+ ? Math.max(options.y, 0)
7584
+ : DEFAULT_FLOATING_GROUP_POSITION.top,
7585
+ width: typeof (options === null || options === void 0 ? void 0 : options.width) === 'number'
7586
+ ? Math.max(options.width, 0)
7587
+ : DEFAULT_FLOATING_GROUP_POSITION.width,
7588
+ height: typeof (options === null || options === void 0 ? void 0 : options.height) === 'number'
7589
+ ? Math.max(options.height, 0)
7590
+ : DEFAULT_FLOATING_GROUP_POSITION.height,
7591
+ };
7592
+ }
7593
+ const anchoredBox = getAnchoredBox();
7594
+ const overlay = new Overlay(Object.assign(Object.assign({ container: this.gridview.element, content: group.element }, anchoredBox), { minimumInViewportWidth: this.options.floatingGroupBounds === 'boundedWithinViewport'
7394
7595
  ? 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'
7596
+ : (_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
7597
  ? 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
- });
7598
+ : (_e = (_d = this.options.floatingGroupBounds) === null || _d === void 0 ? void 0 : _d.minimumHeightWithinViewport) !== null && _e !== void 0 ? _e : DEFAULT_FLOATING_GROUP_OVERFLOW_SIZE }));
7400
7599
  const el = group.element.querySelector('.void-container');
7401
7600
  if (!el) {
7402
7601
  throw new Error('failed to find drag handle');
@@ -7494,12 +7693,18 @@
7494
7693
  group.overlay.minimumInViewportWidth =
7495
7694
  (_b = this.options.floatingGroupBounds) === null || _b === void 0 ? void 0 : _b.minimumWidthWithinViewport;
7496
7695
  }
7497
- group.overlay.setBounds({});
7696
+ group.overlay.setBounds();
7498
7697
  }
7499
7698
  }
7500
7699
  if (changed_rootOverlayOptions) {
7501
7700
  this._rootDropTarget.setOverlayModel(options.rootOverlayModel);
7502
7701
  }
7702
+ if (this.gridview.margin !== 0 && options.gap === undefined) {
7703
+ this.gridview.margin = 0;
7704
+ }
7705
+ if (typeof options.gap === 'number') {
7706
+ this.gridview.margin = options.gap;
7707
+ }
7503
7708
  this.layout(this.gridview.width, this.gridview.height, true);
7504
7709
  }
7505
7710
  layout(width, height, forceResize) {
@@ -7661,11 +7866,10 @@
7661
7866
  const { data, position } = serializedFloatingGroup;
7662
7867
  const group = createGroupFromSerializedState(data);
7663
7868
  this.addFloatingGroup(group, {
7664
- x: position.left,
7665
- y: position.top,
7666
- height: position.height,
7667
- width: position.width,
7668
- }, { skipRemoveGroup: true, inDragMode: false });
7869
+ position: position,
7870
+ skipRemoveGroup: true,
7871
+ inDragMode: false,
7872
+ });
7669
7873
  }
7670
7874
  const serializedPopoutGroups = (_b = data.popoutGroups) !== null && _b !== void 0 ? _b : [];
7671
7875
  for (const serializedPopoutGroup of serializedPopoutGroups) {
@@ -7800,11 +8004,7 @@
7800
8004
  options.floating !== null
7801
8005
  ? options.floating
7802
8006
  : {};
7803
- this.addFloatingGroup(group, o, {
7804
- inDragMode: false,
7805
- skipRemoveGroup: true,
7806
- skipActiveGroup: true,
7807
- });
8007
+ this.addFloatingGroup(group, Object.assign(Object.assign({}, o), { inDragMode: false, skipRemoveGroup: true, skipActiveGroup: true }));
7808
8008
  panel = this.createPanel(options, group);
7809
8009
  group.model.openPanel(panel, {
7810
8010
  skipSetActive: options.inactive,
@@ -7843,11 +8043,7 @@
7843
8043
  options.floating !== null
7844
8044
  ? options.floating
7845
8045
  : {};
7846
- this.addFloatingGroup(group, coordinates, {
7847
- inDragMode: false,
7848
- skipRemoveGroup: true,
7849
- skipActiveGroup: true,
7850
- });
8046
+ this.addFloatingGroup(group, Object.assign(Object.assign({}, coordinates), { inDragMode: false, skipRemoveGroup: true, skipActiveGroup: true }));
7851
8047
  panel = this.createPanel(options, group);
7852
8048
  group.model.openPanel(panel, {
7853
8049
  skipSetActive: options.inactive,
@@ -7902,6 +8098,7 @@
7902
8098
  });
7903
8099
  const watermarkContainer = document.createElement('div');
7904
8100
  watermarkContainer.className = 'dv-watermark-container';
8101
+ addTestId(watermarkContainer, 'watermark-component');
7905
8102
  watermarkContainer.appendChild(this.watermark.element);
7906
8103
  this.gridview.element.appendChild(watermarkContainer);
7907
8104
  }
@@ -8090,6 +8287,7 @@
8090
8287
  this.doSetGroupAndPanelActive(destinationGroup);
8091
8288
  this._onDidMovePanel.fire({
8092
8289
  panel: removedPanel,
8290
+ from: sourceGroup,
8093
8291
  });
8094
8292
  }
8095
8293
  else {
@@ -8113,6 +8311,10 @@
8113
8311
  // if a group has one tab - we are essentially moving the 'group'
8114
8312
  // which is equivalent to swapping two views in this case
8115
8313
  this.gridview.moveView(sourceParentLocation, from, to);
8314
+ this._onDidMovePanel.fire({
8315
+ panel: this.getGroupPanel(sourceItemId),
8316
+ from: sourceGroup,
8317
+ });
8116
8318
  return;
8117
8319
  }
8118
8320
  }
@@ -8126,6 +8328,10 @@
8126
8328
  const location = getRelativeLocation(this.gridview.orientation, updatedReferenceLocation, destinationTarget);
8127
8329
  this.movingLock(() => this.doAddGroup(targetGroup, location));
8128
8330
  this.doSetGroupAndPanelActive(targetGroup);
8331
+ this._onDidMovePanel.fire({
8332
+ panel: this.getGroupPanel(sourceItemId),
8333
+ from: sourceGroup,
8334
+ });
8129
8335
  }
8130
8336
  else {
8131
8337
  /**
@@ -8145,6 +8351,10 @@
8145
8351
  skipSetGroupActive: true,
8146
8352
  }));
8147
8353
  this.doSetGroupAndPanelActive(group);
8354
+ this._onDidMovePanel.fire({
8355
+ panel: removedPanel,
8356
+ from: sourceGroup,
8357
+ });
8148
8358
  }
8149
8359
  }
8150
8360
  }
@@ -8169,9 +8379,6 @@
8169
8379
  }
8170
8380
  });
8171
8381
  this.doSetGroupAndPanelActive(to);
8172
- panels.forEach((panel) => {
8173
- this._onDidMovePanel.fire({ panel });
8174
- });
8175
8382
  }
8176
8383
  else {
8177
8384
  switch (from.api.location.type) {
@@ -8197,10 +8404,10 @@
8197
8404
  const referenceLocation = getGridLocation(to.element);
8198
8405
  const dropLocation = getRelativeLocation(this.gridview.orientation, referenceLocation, target);
8199
8406
  this.gridview.addView(from, exports.Sizing.Distribute, dropLocation);
8200
- from.panels.forEach((panel) => {
8201
- this._onDidMovePanel.fire({ panel });
8202
- });
8203
8407
  }
8408
+ from.panels.forEach((panel) => {
8409
+ this._onDidMovePanel.fire({ panel, from });
8410
+ });
8204
8411
  }
8205
8412
  doSetGroupActive(group) {
8206
8413
  super.doSetGroupActive(group);