dockview-core 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.
Files changed (76) hide show
  1. package/dist/cjs/api/component.api.d.ts +5 -5
  2. package/dist/cjs/api/component.api.js +19 -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 +24 -17
  9. package/dist/cjs/dockview/dockviewComponent.js +104 -47
  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 +328 -112
  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 +327 -111
  34. package/dist/dockview-core.amd.noStyle.js.map +1 -1
  35. package/dist/dockview-core.cjs.js +328 -112
  36. package/dist/dockview-core.cjs.js.map +1 -1
  37. package/dist/dockview-core.esm.js +328 -112
  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 +328 -112
  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 +327 -111
  48. package/dist/dockview-core.noStyle.js.map +1 -1
  49. package/dist/esm/api/component.api.d.ts +5 -5
  50. package/dist/esm/api/component.api.js +11 -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 +24 -17
  57. package/dist/esm/dockview/dockviewComponent.js +101 -48
  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
@@ -19,7 +19,7 @@ function findLeaf(candiateNode, last) {
19
19
  }
20
20
  function flipNode(node, size, orthogonalSize) {
21
21
  if (node instanceof BranchNode) {
22
- const result = new BranchNode(orthogonal(node.orientation), node.proportionalLayout, node.styles, size, orthogonalSize, node.disabled);
22
+ const result = new BranchNode(orthogonal(node.orientation), node.proportionalLayout, node.styles, size, orthogonalSize, node.disabled, node.margin);
23
23
  let totalSize = 0;
24
24
  for (let i = node.children.length - 1; i >= 0; i--) {
25
25
  const child = node.children[i];
@@ -174,6 +174,13 @@ export class Gridview {
174
174
  }
175
175
  }
176
176
  }
177
+ get margin() {
178
+ return this._margin;
179
+ }
180
+ set margin(value) {
181
+ this._margin = value;
182
+ this.root.margin = value;
183
+ }
177
184
  maximizedView() {
178
185
  var _a;
179
186
  return (_a = this._maximizedNode) === null || _a === void 0 ? void 0 : _a.leaf.view;
@@ -259,13 +266,14 @@ export class Gridview {
259
266
  this.disposable.dispose();
260
267
  this._onDidChange.dispose();
261
268
  this._onDidMaximizedNodeChange.dispose();
269
+ this._onDidViewVisibilityChange.dispose();
262
270
  this.root.dispose();
263
271
  this._maximizedNode = undefined;
264
272
  this.element.remove();
265
273
  }
266
274
  clear() {
267
275
  const orientation = this.root.orientation;
268
- this.root = new BranchNode(orientation, this.proportionalLayout, this.styles, this.root.size, this.root.orthogonalSize, this._locked);
276
+ this.root = new BranchNode(orientation, this.proportionalLayout, this.styles, this.root.size, this.root.orthogonalSize, this.locked, this.margin);
269
277
  }
270
278
  deserialize(json, deserializer) {
271
279
  const orientation = json.orientation;
@@ -276,6 +284,7 @@ export class Gridview {
276
284
  this.root = this._deserializeNode(root, orientation, deserializer, orthogonalSize);
277
285
  }
278
286
  _deserializeNode(node, orientation, deserializer, orthogonalSize) {
287
+ var _a;
279
288
  let result;
280
289
  if (node.type === 'branch') {
281
290
  const serializedChildren = node.data;
@@ -287,10 +296,14 @@ export class Gridview {
287
296
  });
288
297
  result = new BranchNode(orientation, this.proportionalLayout, this.styles, node.size, // <- orthogonal size - flips at each depth
289
298
  orthogonalSize, // <- size - flips at each depth,
290
- this._locked, children);
299
+ this.locked, this.margin, children);
291
300
  }
292
301
  else {
293
- result = new LeafNode(deserializer.fromJSON(node), orientation, orthogonalSize, node.size);
302
+ const view = deserializer.fromJSON(node);
303
+ if (typeof node.visible === 'boolean') {
304
+ (_a = view.setVisible) === null || _a === void 0 ? void 0 : _a.call(view, node.visible);
305
+ }
306
+ result = new LeafNode(view, orientation, orthogonalSize, node.size);
294
307
  }
295
308
  return result;
296
309
  }
@@ -320,7 +333,7 @@ export class Gridview {
320
333
  }
321
334
  const oldRoot = this.root;
322
335
  oldRoot.element.remove();
323
- this._root = new BranchNode(orthogonal(oldRoot.orientation), this.proportionalLayout, this.styles, this.root.orthogonalSize, this.root.size, this._locked);
336
+ this._root = new BranchNode(orthogonal(oldRoot.orientation), this.proportionalLayout, this.styles, this.root.orthogonalSize, this.root.size, this.locked, this.margin);
324
337
  if (oldRoot.children.length === 0) {
325
338
  // no data so no need to add anything back in
326
339
  }
@@ -387,19 +400,24 @@ export class Gridview {
387
400
  }
388
401
  return findLeaf(this.root, reverse);
389
402
  }
390
- constructor(proportionalLayout, styles, orientation) {
403
+ constructor(proportionalLayout, styles, orientation, locked, margin) {
391
404
  this.proportionalLayout = proportionalLayout;
392
405
  this.styles = styles;
393
406
  this._locked = false;
407
+ this._margin = 0;
394
408
  this._maximizedNode = undefined;
395
409
  this.disposable = new MutableDisposable();
396
410
  this._onDidChange = new Emitter();
397
411
  this.onDidChange = this._onDidChange.event;
412
+ this._onDidViewVisibilityChange = new Emitter();
413
+ this.onDidViewVisibilityChange = this._onDidViewVisibilityChange.event;
398
414
  this._onDidMaximizedNodeChange = new Emitter();
399
415
  this.onDidMaximizedNodeChange = this._onDidMaximizedNodeChange.event;
400
416
  this.element = document.createElement('div');
401
417
  this.element.className = 'grid-view';
402
- this.root = new BranchNode(orientation, proportionalLayout, styles, 0, 0, this._locked);
418
+ this._locked = locked !== null && locked !== void 0 ? locked : false;
419
+ this._margin = margin !== null && margin !== void 0 ? margin : 0;
420
+ this.root = new BranchNode(orientation, proportionalLayout, styles, 0, 0, this.locked, this.margin);
403
421
  }
404
422
  isViewVisible(location) {
405
423
  const [rest, index] = tail(location);
@@ -418,6 +436,7 @@ export class Gridview {
418
436
  if (!(parent instanceof BranchNode)) {
419
437
  throw new Error('Invalid from location');
420
438
  }
439
+ this._onDidViewVisibilityChange.fire();
421
440
  parent.setChildVisible(index, visible);
422
441
  }
423
442
  moveView(parentLocation, from, to) {
@@ -450,7 +469,7 @@ export class Gridview {
450
469
  }
451
470
  const child = grandParent.removeChild(parentIndex);
452
471
  child.dispose();
453
- const newParent = new BranchNode(parent.orientation, this.proportionalLayout, this.styles, parent.size, parent.orthogonalSize, this._locked);
472
+ const newParent = new BranchNode(parent.orientation, this.proportionalLayout, this.styles, parent.size, parent.orthogonalSize, this.locked, this.margin);
454
473
  grandParent.addChild(newParent, parent.size, parentIndex);
455
474
  const newSibling = new LeafNode(parent.view, grandParent.orientation, parent.size);
456
475
  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;
@@ -51,6 +51,9 @@ export class GridviewPanel extends BasePanelView {
51
51
  get isActive() {
52
52
  return this.api.isActive;
53
53
  }
54
+ get isVisible() {
55
+ return this.api.isVisible;
56
+ }
54
57
  constructor(id, component, options, api) {
55
58
  super(id, component, api !== null && api !== void 0 ? api : new GridviewPanelApiImpl(id, component));
56
59
  this._evaluatedMinimumWidth = 0;
package/dist/esm/math.js CHANGED
@@ -1,6 +1,10 @@
1
1
  export const clamp = (value, min, max) => {
2
2
  if (min > max) {
3
- throw new Error(`${min} > ${max} is an invalid condition`);
3
+ /**
4
+ * caveat: an error should be thrown here if this was a proper `clamp` function but we need to handle
5
+ * cases where `min` > `max` and in those cases return `min`.
6
+ */
7
+ return min;
4
8
  }
5
9
  return Math.min(max, Math.max(value, min));
6
10
  };
@@ -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;
@@ -107,7 +107,14 @@ export class Splitview {
107
107
  this._disabled = value;
108
108
  toggleClass(this.element, 'dv-splitview-disabled', value);
109
109
  }
110
+ get margin() {
111
+ return this._margin;
112
+ }
113
+ set margin(value) {
114
+ this._margin = value;
115
+ }
110
116
  constructor(container, options) {
117
+ var _a;
111
118
  this.container = container;
112
119
  this.viewItems = [];
113
120
  this.sashes = [];
@@ -118,6 +125,7 @@ export class Splitview {
118
125
  this._startSnappingEnabled = true;
119
126
  this._endSnappingEnabled = true;
120
127
  this._disabled = false;
128
+ this._margin = 0;
121
129
  this._onDidSashEnd = new Emitter();
122
130
  this.onDidSashEnd = this._onDidSashEnd.event;
123
131
  this._onDidAddView = new Emitter();
@@ -206,6 +214,7 @@ export class Splitview {
206
214
  };
207
215
  this._orientation = options.orientation;
208
216
  this.element = this.createContainer();
217
+ this.margin = (_a = options.margin) !== null && _a !== void 0 ? _a : 0;
209
218
  this.proportionalLayout =
210
219
  options.proportionalLayout === undefined
211
220
  ? true
@@ -260,9 +269,7 @@ export class Splitview {
260
269
  if (index < 0 || index >= this.viewItems.length) {
261
270
  throw new Error('Index out of bounds');
262
271
  }
263
- toggleClass(this.container, 'visible', visible);
264
272
  const viewItem = this.viewItems[index];
265
- toggleClass(this.container, 'visible', visible);
266
273
  viewItem.setVisible(visible, viewItem.size);
267
274
  this.distributeEmptySpace(index);
268
275
  this.layoutViews();
@@ -574,15 +581,29 @@ export class Splitview {
574
581
  this._proportions = this.viewItems.map((i) => i.visible ? i.size / this._contentSize : undefined);
575
582
  }
576
583
  }
584
+ /**
585
+ * Margin explain:
586
+ *
587
+ * For `n` views in a splitview there will be `n-1` margins `m`.
588
+ *
589
+ * To fit the margins each view must reduce in size by `(m * (n - 1)) / n`.
590
+ *
591
+ * For each view `i` the offet must be adjusted by `m * i/(n - 1)`.
592
+ */
577
593
  layoutViews() {
578
594
  this._contentSize = this.viewItems.reduce((r, i) => r + i.size, 0);
579
- let sum = 0;
580
- const x = [];
581
595
  this.updateSashEnablement();
596
+ if (this.viewItems.length === 0) {
597
+ return;
598
+ }
599
+ const sashCount = this.viewItems.length - 1;
600
+ const marginReducedSize = (this.margin * sashCount) / this.viewItems.length;
601
+ let totalLeftOffset = 0;
602
+ const viewLeftOffsets = [];
582
603
  for (let i = 0; i < this.viewItems.length - 1; i++) {
583
- sum += this.viewItems[i].size;
584
- x.push(sum);
585
- const offset = Math.min(Math.max(0, sum - 2), this.size - 4);
604
+ totalLeftOffset += this.viewItems[i].size;
605
+ viewLeftOffsets.push(totalLeftOffset);
606
+ const offset = Math.min(Math.max(0, totalLeftOffset - 2), this.size - this.margin);
586
607
  if (this._orientation === Orientation.HORIZONTAL) {
587
608
  this.sashes[i].container.style.left = `${offset}px`;
588
609
  this.sashes[i].container.style.top = `0px`;
@@ -593,19 +614,24 @@ export class Splitview {
593
614
  }
594
615
  }
595
616
  this.viewItems.forEach((view, i) => {
617
+ const size = view.size - marginReducedSize;
618
+ const offset = i === 0
619
+ ? 0
620
+ : viewLeftOffsets[i - 1] +
621
+ (i / sashCount) * marginReducedSize;
596
622
  if (this._orientation === Orientation.HORIZONTAL) {
597
- view.container.style.width = `${view.size}px`;
598
- view.container.style.left = i == 0 ? '0px' : `${x[i - 1]}px`;
623
+ view.container.style.width = `${size}px`;
624
+ view.container.style.left = `${offset}px`;
599
625
  view.container.style.top = '';
600
626
  view.container.style.height = '';
601
627
  }
602
628
  if (this._orientation === Orientation.VERTICAL) {
603
- view.container.style.height = `${view.size}px`;
604
- view.container.style.top = i == 0 ? '0px' : `${x[i - 1]}px`;
629
+ view.container.style.height = `${size}px`;
630
+ view.container.style.top = `${offset}px`;
605
631
  view.container.style.width = '';
606
632
  view.container.style.left = '';
607
633
  }
608
- view.view.layout(view.size, this._orthogonalSize);
634
+ view.view.layout(view.size - marginReducedSize, this._orthogonalSize);
609
635
  });
610
636
  }
611
637
  findFirstSnapIndex(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
+ export type AnchorPosition = TopLeft | TopRight | BottomLeft | BottomRight;
26
+ type Size = {
27
+ width: number;
28
+ height: number;
29
+ };
30
+ export type AnchoredBox = Size & AnchorPosition;
31
+ export {};
@@ -210,7 +210,6 @@
210
210
  --dv-tabs-container-scrollbar-color: #888;
211
211
  --dv-icon-hover-background-color: rgba(90, 93, 94, 0.31);
212
212
  --dv-floating-box-shadow: 8px 8px 8px 0px rgba(83, 89, 93, 0.5);
213
- --dv-group-gap-size: 3px;
214
213
  --dv-group-view-background-color: #ebeced;
215
214
  --dv-tabs-and-actions-container-background-color: #fcfcfc;
216
215
  --dv-activegroup-visiblepanel-tab-background-color: #f0f1f2;
@@ -438,18 +437,6 @@
438
437
  .dv-dockview .dv-overlay-render-container {
439
438
  position: relative;
440
439
  }
441
- .dv-dockview .split-view-container.horizontal > .view-container > .view:not(:last-child) .groupview {
442
- border-right: var(--dv-group-gap-size) solid transparent;
443
- }
444
- .dv-dockview .split-view-container.horizontal > .view-container > .view:not(:first-child) .groupview {
445
- border-left: var(--dv-group-gap-size) solid transparent;
446
- }
447
- .dv-dockview .split-view-container.vertical > .view-container > .view:not(:last-child) .groupview {
448
- border-bottom: var(--dv-group-gap-size) solid transparent;
449
- }
450
- .dv-dockview .split-view-container.vertical > .view-container > .view:not(:first-child) .groupview {
451
- border-top: var(--dv-group-gap-size) solid transparent;
452
- }
453
440
 
454
441
  .groupview.active-group > .tabs-and-actions-container > .tabs-container > .tab.active-tab {
455
442
  background-color: var(--dv-activegroup-visiblepanel-tab-background-color);
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "dockview-core",
3
- "version": "1.14.2",
3
+ "version": "1.15.1",
4
4
  "description": "Zero dependency layout manager supporting tabs, grids and splitviews",
5
5
  "keywords": [
6
6
  "splitview",