dockview-core 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.
Files changed (76) hide show
  1. package/dist/cjs/api/component.api.d.ts +4 -5
  2. package/dist/cjs/api/component.api.js +12 -2
  3. package/dist/cjs/constants.d.ts +2 -0
  4. package/dist/cjs/constants.js +1 -1
  5. package/dist/cjs/dnd/overlay.d.ts +6 -4
  6. package/dist/cjs/dnd/overlay.js +119 -28
  7. package/dist/cjs/dockview/components/titlebar/tabsContainer.js +4 -2
  8. package/dist/cjs/dockview/dockviewComponent.d.ts +20 -17
  9. package/dist/cjs/dockview/dockviewComponent.js +92 -45
  10. package/dist/cjs/dockview/dockviewFloatingGroupPanel.d.ts +3 -12
  11. package/dist/cjs/dockview/options.d.ts +10 -6
  12. package/dist/cjs/dockview/options.js +1 -0
  13. package/dist/cjs/dom.d.ts +1 -0
  14. package/dist/cjs/dom.js +5 -1
  15. package/dist/cjs/gridview/baseComponentGridview.d.ts +3 -0
  16. package/dist/cjs/gridview/baseComponentGridview.js +8 -2
  17. package/dist/cjs/gridview/branchNode.d.ts +7 -3
  18. package/dist/cjs/gridview/branchNode.js +24 -29
  19. package/dist/cjs/gridview/gridview.d.ts +7 -1
  20. package/dist/cjs/gridview/gridview.js +31 -8
  21. package/dist/cjs/gridview/gridviewPanel.d.ts +1 -0
  22. package/dist/cjs/gridview/gridviewPanel.js +7 -0
  23. package/dist/cjs/math.js +5 -1
  24. package/dist/cjs/splitview/splitview.d.ts +13 -0
  25. package/dist/cjs/splitview/splitview.js +42 -12
  26. package/dist/cjs/types.d.ts +23 -0
  27. package/dist/dockview-core.amd.js +317 -110
  28. package/dist/dockview-core.amd.js.map +1 -1
  29. package/dist/dockview-core.amd.min.js +2 -2
  30. package/dist/dockview-core.amd.min.js.map +1 -1
  31. package/dist/dockview-core.amd.min.noStyle.js +2 -2
  32. package/dist/dockview-core.amd.min.noStyle.js.map +1 -1
  33. package/dist/dockview-core.amd.noStyle.js +316 -109
  34. package/dist/dockview-core.amd.noStyle.js.map +1 -1
  35. package/dist/dockview-core.cjs.js +317 -110
  36. package/dist/dockview-core.cjs.js.map +1 -1
  37. package/dist/dockview-core.esm.js +317 -110
  38. package/dist/dockview-core.esm.js.map +1 -1
  39. package/dist/dockview-core.esm.min.js +2 -2
  40. package/dist/dockview-core.esm.min.js.map +1 -1
  41. package/dist/dockview-core.js +317 -110
  42. package/dist/dockview-core.js.map +1 -1
  43. package/dist/dockview-core.min.js +2 -2
  44. package/dist/dockview-core.min.js.map +1 -1
  45. package/dist/dockview-core.min.noStyle.js +2 -2
  46. package/dist/dockview-core.min.noStyle.js.map +1 -1
  47. package/dist/dockview-core.noStyle.js +316 -109
  48. package/dist/dockview-core.noStyle.js.map +1 -1
  49. package/dist/esm/api/component.api.d.ts +4 -5
  50. package/dist/esm/api/component.api.js +8 -2
  51. package/dist/esm/constants.d.ts +2 -0
  52. package/dist/esm/constants.js +1 -1
  53. package/dist/esm/dnd/overlay.d.ts +6 -4
  54. package/dist/esm/dnd/overlay.js +108 -28
  55. package/dist/esm/dockview/components/titlebar/tabsContainer.js +4 -2
  56. package/dist/esm/dockview/dockviewComponent.d.ts +20 -17
  57. package/dist/esm/dockview/dockviewComponent.js +93 -46
  58. package/dist/esm/dockview/dockviewFloatingGroupPanel.d.ts +3 -12
  59. package/dist/esm/dockview/options.d.ts +10 -6
  60. package/dist/esm/dockview/options.js +1 -0
  61. package/dist/esm/dom.d.ts +1 -0
  62. package/dist/esm/dom.js +3 -0
  63. package/dist/esm/gridview/baseComponentGridview.d.ts +3 -0
  64. package/dist/esm/gridview/baseComponentGridview.js +6 -2
  65. package/dist/esm/gridview/branchNode.d.ts +7 -3
  66. package/dist/esm/gridview/branchNode.js +19 -7
  67. package/dist/esm/gridview/gridview.d.ts +7 -1
  68. package/dist/esm/gridview/gridview.js +27 -8
  69. package/dist/esm/gridview/gridviewPanel.d.ts +1 -0
  70. package/dist/esm/gridview/gridviewPanel.js +3 -0
  71. package/dist/esm/math.js +5 -1
  72. package/dist/esm/splitview/splitview.d.ts +13 -0
  73. package/dist/esm/splitview/splitview.js +38 -12
  74. package/dist/esm/types.d.ts +23 -0
  75. package/dist/styles/dockview.css +0 -13
  76. package/package.json +1 -1
@@ -47,7 +47,7 @@ function findLeaf(candiateNode, last) {
47
47
  }
48
48
  function flipNode(node, size, orthogonalSize) {
49
49
  if (node instanceof branchNode_1.BranchNode) {
50
- var result = new branchNode_1.BranchNode((0, exports.orthogonal)(node.orientation), node.proportionalLayout, node.styles, size, orthogonalSize, node.disabled);
50
+ var result = new branchNode_1.BranchNode((0, exports.orthogonal)(node.orientation), node.proportionalLayout, node.styles, size, orthogonalSize, node.disabled, node.margin);
51
51
  var totalSize = 0;
52
52
  for (var i = node.children.length - 1; i >= 0; i--) {
53
53
  var child = node.children[i];
@@ -162,19 +162,24 @@ var serializeBranchNode = function (node, orientation) {
162
162
  };
163
163
  };
164
164
  var Gridview = /** @class */ (function () {
165
- function Gridview(proportionalLayout, styles, orientation) {
165
+ function Gridview(proportionalLayout, styles, orientation, locked, margin) {
166
166
  this.proportionalLayout = proportionalLayout;
167
167
  this.styles = styles;
168
168
  this._locked = false;
169
+ this._margin = 0;
169
170
  this._maximizedNode = undefined;
170
171
  this.disposable = new lifecycle_1.MutableDisposable();
171
172
  this._onDidChange = new events_1.Emitter();
172
173
  this.onDidChange = this._onDidChange.event;
174
+ this._onDidViewVisibilityChange = new events_1.Emitter();
175
+ this.onDidViewVisibilityChange = this._onDidViewVisibilityChange.event;
173
176
  this._onDidMaximizedNodeChange = new events_1.Emitter();
174
177
  this.onDidMaximizedNodeChange = this._onDidMaximizedNodeChange.event;
175
178
  this.element = document.createElement('div');
176
179
  this.element.className = 'grid-view';
177
- this.root = new branchNode_1.BranchNode(orientation, proportionalLayout, styles, 0, 0, this._locked);
180
+ this._locked = locked !== null && locked !== void 0 ? locked : false;
181
+ this._margin = margin !== null && margin !== void 0 ? margin : 0;
182
+ this.root = new branchNode_1.BranchNode(orientation, proportionalLayout, styles, 0, 0, this.locked, this.margin);
178
183
  }
179
184
  Object.defineProperty(Gridview.prototype, "length", {
180
185
  get: function () {
@@ -263,6 +268,17 @@ var Gridview = /** @class */ (function () {
263
268
  enumerable: false,
264
269
  configurable: true
265
270
  });
271
+ Object.defineProperty(Gridview.prototype, "margin", {
272
+ get: function () {
273
+ return this._margin;
274
+ },
275
+ set: function (value) {
276
+ this._margin = value;
277
+ this.root.margin = value;
278
+ },
279
+ enumerable: false,
280
+ configurable: true
281
+ });
266
282
  Gridview.prototype.maximizedView = function () {
267
283
  var _a;
268
284
  return (_a = this._maximizedNode) === null || _a === void 0 ? void 0 : _a.leaf.view;
@@ -348,13 +364,14 @@ var Gridview = /** @class */ (function () {
348
364
  this.disposable.dispose();
349
365
  this._onDidChange.dispose();
350
366
  this._onDidMaximizedNodeChange.dispose();
367
+ this._onDidViewVisibilityChange.dispose();
351
368
  this.root.dispose();
352
369
  this._maximizedNode = undefined;
353
370
  this.element.remove();
354
371
  };
355
372
  Gridview.prototype.clear = function () {
356
373
  var orientation = this.root.orientation;
357
- this.root = new branchNode_1.BranchNode(orientation, this.proportionalLayout, this.styles, this.root.size, this.root.orthogonalSize, this._locked);
374
+ this.root = new branchNode_1.BranchNode(orientation, this.proportionalLayout, this.styles, this.root.size, this.root.orthogonalSize, this.locked, this.margin);
358
375
  };
359
376
  Gridview.prototype.deserialize = function (json, deserializer) {
360
377
  var orientation = json.orientation;
@@ -366,6 +383,7 @@ var Gridview = /** @class */ (function () {
366
383
  };
367
384
  Gridview.prototype._deserializeNode = function (node, orientation, deserializer, orthogonalSize) {
368
385
  var _this = this;
386
+ var _a;
369
387
  var result;
370
388
  if (node.type === 'branch') {
371
389
  var serializedChildren = node.data;
@@ -377,10 +395,14 @@ var Gridview = /** @class */ (function () {
377
395
  });
378
396
  result = new branchNode_1.BranchNode(orientation, this.proportionalLayout, this.styles, node.size, // <- orthogonal size - flips at each depth
379
397
  orthogonalSize, // <- size - flips at each depth,
380
- this._locked, children);
398
+ this.locked, this.margin, children);
381
399
  }
382
400
  else {
383
- result = new leafNode_1.LeafNode(deserializer.fromJSON(node), orientation, orthogonalSize, node.size);
401
+ var view = deserializer.fromJSON(node);
402
+ if (typeof node.visible === 'boolean') {
403
+ (_a = view.setVisible) === null || _a === void 0 ? void 0 : _a.call(view, node.visible);
404
+ }
405
+ result = new leafNode_1.LeafNode(view, orientation, orthogonalSize, node.size);
384
406
  }
385
407
  return result;
386
408
  };
@@ -416,7 +438,7 @@ var Gridview = /** @class */ (function () {
416
438
  }
417
439
  var oldRoot = this.root;
418
440
  oldRoot.element.remove();
419
- this._root = new branchNode_1.BranchNode((0, exports.orthogonal)(oldRoot.orientation), this.proportionalLayout, this.styles, this.root.orthogonalSize, this.root.size, this._locked);
441
+ this._root = new branchNode_1.BranchNode((0, exports.orthogonal)(oldRoot.orientation), this.proportionalLayout, this.styles, this.root.orthogonalSize, this.root.size, this.locked, this.margin);
420
442
  if (oldRoot.children.length === 0) {
421
443
  // no data so no need to add anything back in
422
444
  }
@@ -501,6 +523,7 @@ var Gridview = /** @class */ (function () {
501
523
  if (!(parent instanceof branchNode_1.BranchNode)) {
502
524
  throw new Error('Invalid from location');
503
525
  }
526
+ this._onDidViewVisibilityChange.fire();
504
527
  parent.setChildVisible(index, visible);
505
528
  };
506
529
  Gridview.prototype.moveView = function (parentLocation, from, to) {
@@ -533,7 +556,7 @@ var Gridview = /** @class */ (function () {
533
556
  }
534
557
  var child = grandParent.removeChild(parentIndex);
535
558
  child.dispose();
536
- var newParent = new branchNode_1.BranchNode(parent.orientation, this.proportionalLayout, this.styles, parent.size, parent.orthogonalSize, this._locked);
559
+ var newParent = new branchNode_1.BranchNode(parent.orientation, this.proportionalLayout, this.styles, parent.size, parent.orthogonalSize, this.locked, this.margin);
537
560
  grandParent.addChild(newParent, parent.size, parentIndex);
538
561
  var newSibling = new leafNode_1.LeafNode(parent.view, grandParent.orientation, parent.size);
539
562
  newParent.addChild(newSibling, newSiblingSize, 0);
@@ -44,6 +44,7 @@ export declare abstract class GridviewPanel<T extends GridviewPanelApiImpl = Gri
44
44
  get maximumHeight(): number;
45
45
  get maximumWidth(): number;
46
46
  get isActive(): boolean;
47
+ get isVisible(): boolean;
47
48
  constructor(id: string, component: string, options?: {
48
49
  minimumWidth?: number;
49
50
  maximumWidth?: number;
@@ -167,6 +167,13 @@ var GridviewPanel = /** @class */ (function (_super) {
167
167
  enumerable: false,
168
168
  configurable: true
169
169
  });
170
+ Object.defineProperty(GridviewPanel.prototype, "isVisible", {
171
+ get: function () {
172
+ return this.api.isVisible;
173
+ },
174
+ enumerable: false,
175
+ configurable: true
176
+ });
170
177
  GridviewPanel.prototype.setVisible = function (isVisible) {
171
178
  this.api._onDidVisibilityChange.fire({ isVisible: isVisible });
172
179
  };
package/dist/cjs/math.js CHANGED
@@ -3,7 +3,11 @@ Object.defineProperty(exports, "__esModule", { value: true });
3
3
  exports.range = exports.sequentialNumberGenerator = exports.clamp = void 0;
4
4
  var clamp = function (value, min, max) {
5
5
  if (min > max) {
6
- throw new Error("".concat(min, " > ").concat(max, " is an invalid condition"));
6
+ /**
7
+ * caveat: an error should be thrown here if this was a proper `clamp` function but we need to handle
8
+ * cases where `min` > `max` and in those cases return `min`.
9
+ */
10
+ return min;
7
11
  }
8
12
  return Math.min(max, Math.max(value, min));
9
13
  };
@@ -18,6 +18,7 @@ export interface SplitViewOptions {
18
18
  readonly descriptor?: ISplitViewDescriptor;
19
19
  readonly proportionalLayout?: boolean;
20
20
  readonly styles?: ISplitviewStyles;
21
+ readonly margin?: number;
21
22
  }
22
23
  export declare enum LayoutPriority {
23
24
  Low = "low",// view is offered space last
@@ -80,6 +81,7 @@ export declare class Splitview {
80
81
  private _startSnappingEnabled;
81
82
  private _endSnappingEnabled;
82
83
  private _disabled;
84
+ private _margin;
83
85
  private readonly _onDidSashEnd;
84
86
  readonly onDidSashEnd: Event<void>;
85
87
  private readonly _onDidAddView;
@@ -103,6 +105,8 @@ export declare class Splitview {
103
105
  set endSnappingEnabled(endSnappingEnabled: boolean);
104
106
  get disabled(): boolean;
105
107
  set disabled(value: boolean);
108
+ get margin(): number;
109
+ set margin(value: number);
106
110
  constructor(container: HTMLElement, options: SplitViewOptions);
107
111
  style(styles?: ISplitviewStyles): void;
108
112
  isViewVisible(index: number): boolean;
@@ -120,6 +124,15 @@ export declare class Splitview {
120
124
  private relayout;
121
125
  private distributeEmptySpace;
122
126
  private saveProportions;
127
+ /**
128
+ * Margin explain:
129
+ *
130
+ * For `n` views in a splitview there will be `n-1` margins `m`.
131
+ *
132
+ * To fit the margins each view must reduce in size by `(m * (n - 1)) / n`.
133
+ *
134
+ * For each view `i` the offet must be adjusted by `m * i/(n - 1)`.
135
+ */
123
136
  private layoutViews;
124
137
  private findFirstSnapIndex;
125
138
  private updateSashEnablement;
@@ -79,6 +79,7 @@ var Sizing;
79
79
  var Splitview = /** @class */ (function () {
80
80
  function Splitview(container, options) {
81
81
  var _this = this;
82
+ var _a;
82
83
  this.container = container;
83
84
  this.viewItems = [];
84
85
  this.sashes = [];
@@ -89,6 +90,7 @@ var Splitview = /** @class */ (function () {
89
90
  this._startSnappingEnabled = true;
90
91
  this._endSnappingEnabled = true;
91
92
  this._disabled = false;
93
+ this._margin = 0;
92
94
  this._onDidSashEnd = new events_1.Emitter();
93
95
  this.onDidSashEnd = this._onDidSashEnd.event;
94
96
  this._onDidAddView = new events_1.Emitter();
@@ -201,6 +203,7 @@ var Splitview = /** @class */ (function () {
201
203
  };
202
204
  this._orientation = options.orientation;
203
205
  this.element = this.createContainer();
206
+ this.margin = (_a = options.margin) !== null && _a !== void 0 ? _a : 0;
204
207
  this.proportionalLayout =
205
208
  options.proportionalLayout === undefined
206
209
  ? true
@@ -345,6 +348,16 @@ var Splitview = /** @class */ (function () {
345
348
  enumerable: false,
346
349
  configurable: true
347
350
  });
351
+ Object.defineProperty(Splitview.prototype, "margin", {
352
+ get: function () {
353
+ return this._margin;
354
+ },
355
+ set: function (value) {
356
+ this._margin = value;
357
+ },
358
+ enumerable: false,
359
+ configurable: true
360
+ });
348
361
  Splitview.prototype.style = function (styles) {
349
362
  if ((styles === null || styles === void 0 ? void 0 : styles.separatorBorder) === 'transparent') {
350
363
  (0, dom_1.removeClasses)(this.element, 'separator-border');
@@ -368,9 +381,7 @@ var Splitview = /** @class */ (function () {
368
381
  if (index < 0 || index >= this.viewItems.length) {
369
382
  throw new Error('Index out of bounds');
370
383
  }
371
- (0, dom_1.toggleClass)(this.container, 'visible', visible);
372
384
  var viewItem = this.viewItems[index];
373
- (0, dom_1.toggleClass)(this.container, 'visible', visible);
374
385
  viewItem.setVisible(visible, viewItem.size);
375
386
  this.distributeEmptySpace(index);
376
387
  this.layoutViews();
@@ -781,16 +792,30 @@ var Splitview = /** @class */ (function () {
781
792
  });
782
793
  }
783
794
  };
795
+ /**
796
+ * Margin explain:
797
+ *
798
+ * For `n` views in a splitview there will be `n-1` margins `m`.
799
+ *
800
+ * To fit the margins each view must reduce in size by `(m * (n - 1)) / n`.
801
+ *
802
+ * For each view `i` the offet must be adjusted by `m * i/(n - 1)`.
803
+ */
784
804
  Splitview.prototype.layoutViews = function () {
785
805
  var _this = this;
786
806
  this._contentSize = this.viewItems.reduce(function (r, i) { return r + i.size; }, 0);
787
- var sum = 0;
788
- var x = [];
789
807
  this.updateSashEnablement();
808
+ if (this.viewItems.length === 0) {
809
+ return;
810
+ }
811
+ var sashCount = this.viewItems.length - 1;
812
+ var marginReducedSize = (this.margin * sashCount) / this.viewItems.length;
813
+ var totalLeftOffset = 0;
814
+ var viewLeftOffsets = [];
790
815
  for (var i = 0; i < this.viewItems.length - 1; i++) {
791
- sum += this.viewItems[i].size;
792
- x.push(sum);
793
- var offset = Math.min(Math.max(0, sum - 2), this.size - 4);
816
+ totalLeftOffset += this.viewItems[i].size;
817
+ viewLeftOffsets.push(totalLeftOffset);
818
+ var offset = Math.min(Math.max(0, totalLeftOffset - 2), this.size - this.margin);
794
819
  if (this._orientation === Orientation.HORIZONTAL) {
795
820
  this.sashes[i].container.style.left = "".concat(offset, "px");
796
821
  this.sashes[i].container.style.top = "0px";
@@ -801,19 +826,24 @@ var Splitview = /** @class */ (function () {
801
826
  }
802
827
  }
803
828
  this.viewItems.forEach(function (view, i) {
829
+ var size = view.size - marginReducedSize;
830
+ var offset = i === 0
831
+ ? 0
832
+ : viewLeftOffsets[i - 1] +
833
+ (i / sashCount) * marginReducedSize;
804
834
  if (_this._orientation === Orientation.HORIZONTAL) {
805
- view.container.style.width = "".concat(view.size, "px");
806
- view.container.style.left = i == 0 ? '0px' : "".concat(x[i - 1], "px");
835
+ view.container.style.width = "".concat(size, "px");
836
+ view.container.style.left = "".concat(offset, "px");
807
837
  view.container.style.top = '';
808
838
  view.container.style.height = '';
809
839
  }
810
840
  if (_this._orientation === Orientation.VERTICAL) {
811
- view.container.style.height = "".concat(view.size, "px");
812
- view.container.style.top = i == 0 ? '0px' : "".concat(x[i - 1], "px");
841
+ view.container.style.height = "".concat(size, "px");
842
+ view.container.style.top = "".concat(offset, "px");
813
843
  view.container.style.width = '';
814
844
  view.container.style.left = '';
815
845
  }
816
- view.view.layout(view.size, _this._orthogonalSize);
846
+ view.view.layout(view.size - marginReducedSize, _this._orthogonalSize);
817
847
  });
818
848
  };
819
849
  Splitview.prototype.findFirstSnapIndex = function (indexes) {
@@ -6,3 +6,26 @@ export interface Box {
6
6
  height: number;
7
7
  width: number;
8
8
  }
9
+ type TopLeft = {
10
+ top: number;
11
+ left: number;
12
+ };
13
+ type TopRight = {
14
+ top: number;
15
+ right: number;
16
+ };
17
+ type BottomLeft = {
18
+ bottom: number;
19
+ left: number;
20
+ };
21
+ type BottomRight = {
22
+ bottom: number;
23
+ right: number;
24
+ };
25
+ type AnchorPosition = TopLeft | TopRight | BottomLeft | BottomRight;
26
+ type Size = {
27
+ width: number;
28
+ height: number;
29
+ };
30
+ export type AnchoredBox = Size & AnchorPosition;
31
+ export {};