dockview-core 1.12.0 → 1.13.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 (65) hide show
  1. package/dist/cjs/api/component.api.d.ts +2 -1
  2. package/dist/cjs/api/component.api.js +7 -0
  3. package/dist/cjs/api/dockviewGroupPanelApi.d.ts +5 -1
  4. package/dist/cjs/api/dockviewGroupPanelApi.js +19 -1
  5. package/dist/cjs/dnd/droptarget.d.ts +1 -1
  6. package/dist/cjs/dnd/droptarget.js +4 -10
  7. package/dist/cjs/dockview/components/panel/content.js +0 -8
  8. package/dist/cjs/dockview/dockviewComponent.d.ts +6 -4
  9. package/dist/cjs/dockview/dockviewComponent.js +71 -67
  10. package/dist/cjs/dockview/dockviewGroupPanelModel.d.ts +3 -0
  11. package/dist/cjs/dockview/dockviewGroupPanelModel.js +18 -19
  12. package/dist/cjs/dockview/dockviewPanelModel.js +21 -24
  13. package/dist/cjs/dockview/framework.d.ts +38 -0
  14. package/dist/cjs/dockview/framework.js +2 -0
  15. package/dist/cjs/dockview/options.d.ts +68 -46
  16. package/dist/cjs/dockview/options.js +43 -1
  17. package/dist/cjs/dockview/types.d.ts +4 -10
  18. package/dist/cjs/framwork.d.ts +4 -0
  19. package/dist/cjs/framwork.js +2 -0
  20. package/dist/cjs/index.d.ts +2 -1
  21. package/dist/cjs/index.js +1 -1
  22. package/dist/dockview-core.amd.js +1973 -1920
  23. package/dist/dockview-core.amd.js.map +1 -1
  24. package/dist/dockview-core.amd.min.js +2 -2
  25. package/dist/dockview-core.amd.min.js.map +1 -1
  26. package/dist/dockview-core.amd.min.noStyle.js +2 -2
  27. package/dist/dockview-core.amd.min.noStyle.js.map +1 -1
  28. package/dist/dockview-core.amd.noStyle.js +1973 -1920
  29. package/dist/dockview-core.amd.noStyle.js.map +1 -1
  30. package/dist/dockview-core.cjs.js +1973 -1920
  31. package/dist/dockview-core.cjs.js.map +1 -1
  32. package/dist/dockview-core.esm.js +1972 -1921
  33. package/dist/dockview-core.esm.js.map +1 -1
  34. package/dist/dockview-core.esm.min.js +2 -2
  35. package/dist/dockview-core.esm.min.js.map +1 -1
  36. package/dist/dockview-core.js +1973 -1920
  37. package/dist/dockview-core.js.map +1 -1
  38. package/dist/dockview-core.min.js +2 -2
  39. package/dist/dockview-core.min.js.map +1 -1
  40. package/dist/dockview-core.min.noStyle.js +2 -2
  41. package/dist/dockview-core.min.noStyle.js.map +1 -1
  42. package/dist/dockview-core.noStyle.js +1973 -1920
  43. package/dist/dockview-core.noStyle.js.map +1 -1
  44. package/dist/esm/api/component.api.d.ts +2 -1
  45. package/dist/esm/api/component.api.js +3 -0
  46. package/dist/esm/api/dockviewGroupPanelApi.d.ts +5 -1
  47. package/dist/esm/api/dockviewGroupPanelApi.js +18 -1
  48. package/dist/esm/dnd/droptarget.d.ts +1 -1
  49. package/dist/esm/dnd/droptarget.js +4 -10
  50. package/dist/esm/dockview/components/panel/content.js +0 -8
  51. package/dist/esm/dockview/dockviewComponent.d.ts +6 -4
  52. package/dist/esm/dockview/dockviewComponent.js +70 -68
  53. package/dist/esm/dockview/dockviewGroupPanelModel.d.ts +3 -0
  54. package/dist/esm/dockview/dockviewGroupPanelModel.js +18 -19
  55. package/dist/esm/dockview/dockviewPanelModel.js +21 -13
  56. package/dist/esm/dockview/framework.d.ts +38 -0
  57. package/dist/esm/dockview/framework.js +1 -0
  58. package/dist/esm/dockview/options.d.ts +68 -46
  59. package/dist/esm/dockview/options.js +36 -0
  60. package/dist/esm/dockview/types.d.ts +4 -10
  61. package/dist/esm/framwork.d.ts +4 -0
  62. package/dist/esm/framwork.js +1 -0
  63. package/dist/esm/index.d.ts +2 -1
  64. package/dist/esm/index.js +1 -1
  65. package/package.json +2 -2
@@ -1,6 +1,6 @@
1
1
  /**
2
2
  * dockview-core
3
- * @version 1.12.0
3
+ * @version 1.13.0
4
4
  * @link https://github.com/mathuo/dockview
5
5
  * @license MIT
6
6
  */
@@ -2468,6 +2468,261 @@ class Gridview {
2468
2468
  }
2469
2469
  }
2470
2470
 
2471
+ class Resizable extends CompositeDisposable {
2472
+ get element() {
2473
+ return this._element;
2474
+ }
2475
+ get disableResizing() {
2476
+ return this._disableResizing;
2477
+ }
2478
+ set disableResizing(value) {
2479
+ this._disableResizing = value;
2480
+ }
2481
+ constructor(parentElement, disableResizing = false) {
2482
+ super();
2483
+ this._disableResizing = disableResizing;
2484
+ this._element = parentElement;
2485
+ this.addDisposables(watchElementResize(this._element, (entry) => {
2486
+ if (this.isDisposed) {
2487
+ /**
2488
+ * resize is delayed through requestAnimationFrame so there is a small chance
2489
+ * the component has already been disposed of
2490
+ */
2491
+ return;
2492
+ }
2493
+ if (this.disableResizing) {
2494
+ return;
2495
+ }
2496
+ if (!this._element.offsetParent) {
2497
+ /**
2498
+ * offsetParent === null is equivalent to display: none being set on the element or one
2499
+ * of it's parents. In the display: none case the size will become (0, 0) which we do
2500
+ * not want to propagate.
2501
+ *
2502
+ * @see https://developer.mozilla.org/en-US/docs/Web/API/HTMLElement/offsetParent
2503
+ *
2504
+ * You could use checkVisibility() but at the time of writing it's not supported across
2505
+ * all Browsers
2506
+ *
2507
+ * @see https://developer.mozilla.org/en-US/docs/Web/API/Element/checkVisibility
2508
+ */
2509
+ return;
2510
+ }
2511
+ if (!isInDocument(this._element)) {
2512
+ /**
2513
+ * since the event is dispatched through requestAnimationFrame there is a small chance
2514
+ * the component is no longer attached to the DOM, if that is the case the dimensions
2515
+ * are mostly likely all zero and meaningless. we should skip this case.
2516
+ */
2517
+ return;
2518
+ }
2519
+ const { width, height } = entry.contentRect;
2520
+ this.layout(width, height);
2521
+ }));
2522
+ }
2523
+ }
2524
+
2525
+ const nextLayoutId$1 = sequentialNumberGenerator();
2526
+ function toTarget(direction) {
2527
+ switch (direction) {
2528
+ case 'left':
2529
+ return 'left';
2530
+ case 'right':
2531
+ return 'right';
2532
+ case 'above':
2533
+ return 'top';
2534
+ case 'below':
2535
+ return 'bottom';
2536
+ case 'within':
2537
+ default:
2538
+ return 'center';
2539
+ }
2540
+ }
2541
+ class BaseGrid extends Resizable {
2542
+ get id() {
2543
+ return this._id;
2544
+ }
2545
+ get size() {
2546
+ return this._groups.size;
2547
+ }
2548
+ get groups() {
2549
+ return Array.from(this._groups.values()).map((_) => _.value);
2550
+ }
2551
+ get width() {
2552
+ return this.gridview.width;
2553
+ }
2554
+ get height() {
2555
+ return this.gridview.height;
2556
+ }
2557
+ get minimumHeight() {
2558
+ return this.gridview.minimumHeight;
2559
+ }
2560
+ get maximumHeight() {
2561
+ return this.gridview.maximumHeight;
2562
+ }
2563
+ get minimumWidth() {
2564
+ return this.gridview.minimumWidth;
2565
+ }
2566
+ get maximumWidth() {
2567
+ return this.gridview.maximumWidth;
2568
+ }
2569
+ get activeGroup() {
2570
+ return this._activeGroup;
2571
+ }
2572
+ get locked() {
2573
+ return this.gridview.locked;
2574
+ }
2575
+ set locked(value) {
2576
+ this.gridview.locked = value;
2577
+ }
2578
+ constructor(options) {
2579
+ super(document.createElement('div'), options.disableAutoResizing);
2580
+ this._id = nextLayoutId$1.next();
2581
+ this._groups = new Map();
2582
+ this._onDidLayoutChange = new Emitter();
2583
+ this.onDidLayoutChange = this._onDidLayoutChange.event;
2584
+ this._onDidRemove = new Emitter();
2585
+ this.onDidRemove = this._onDidRemove.event;
2586
+ this._onDidAdd = new Emitter();
2587
+ this.onDidAdd = this._onDidAdd.event;
2588
+ this._onDidActiveChange = new Emitter();
2589
+ this.onDidActiveChange = this._onDidActiveChange.event;
2590
+ this._bufferOnDidLayoutChange = new TickDelayedEvent();
2591
+ this.element.style.height = '100%';
2592
+ this.element.style.width = '100%';
2593
+ options.parentElement.appendChild(this.element);
2594
+ this.gridview = new Gridview(!!options.proportionalLayout, options.styles, options.orientation);
2595
+ this.gridview.locked = !!options.locked;
2596
+ this.element.appendChild(this.gridview.element);
2597
+ this.layout(0, 0, true); // set some elements height/widths
2598
+ this.addDisposables(Disposable.from(() => {
2599
+ var _a;
2600
+ (_a = this.element.parentElement) === null || _a === void 0 ? void 0 : _a.removeChild(this.element);
2601
+ }), this.gridview.onDidChange(() => {
2602
+ this._bufferOnDidLayoutChange.fire();
2603
+ }), exports.DockviewEvent.any(this.onDidAdd, this.onDidRemove, this.onDidActiveChange)(() => {
2604
+ this._bufferOnDidLayoutChange.fire();
2605
+ }), this._bufferOnDidLayoutChange.onEvent(() => {
2606
+ this._onDidLayoutChange.fire();
2607
+ }), this._bufferOnDidLayoutChange);
2608
+ }
2609
+ setVisible(panel, visible) {
2610
+ this.gridview.setViewVisible(getGridLocation(panel.element), visible);
2611
+ this._onDidLayoutChange.fire();
2612
+ }
2613
+ isVisible(panel) {
2614
+ return this.gridview.isViewVisible(getGridLocation(panel.element));
2615
+ }
2616
+ maximizeGroup(panel) {
2617
+ this.gridview.maximizeView(panel);
2618
+ this.doSetGroupActive(panel);
2619
+ }
2620
+ isMaximizedGroup(panel) {
2621
+ return this.gridview.maximizedView() === panel;
2622
+ }
2623
+ exitMaximizedGroup() {
2624
+ this.gridview.exitMaximizedView();
2625
+ }
2626
+ hasMaximizedGroup() {
2627
+ return this.gridview.hasMaximizedView();
2628
+ }
2629
+ get onDidMaximizedGroupChange() {
2630
+ return this.gridview.onDidMaximizedNodeChange;
2631
+ }
2632
+ doAddGroup(group, location = [0], size) {
2633
+ this.gridview.addView(group, size !== null && size !== void 0 ? size : exports.Sizing.Distribute, location);
2634
+ this._onDidAdd.fire(group);
2635
+ }
2636
+ doRemoveGroup(group, options) {
2637
+ if (!this._groups.has(group.id)) {
2638
+ throw new Error('invalid operation');
2639
+ }
2640
+ const item = this._groups.get(group.id);
2641
+ const view = this.gridview.remove(group, exports.Sizing.Distribute);
2642
+ if (item && !(options === null || options === void 0 ? void 0 : options.skipDispose)) {
2643
+ item.disposable.dispose();
2644
+ item.value.dispose();
2645
+ this._groups.delete(group.id);
2646
+ this._onDidRemove.fire(group);
2647
+ }
2648
+ if (!(options === null || options === void 0 ? void 0 : options.skipActive) && this._activeGroup === group) {
2649
+ const groups = Array.from(this._groups.values());
2650
+ this.doSetGroupActive(groups.length > 0 ? groups[0].value : undefined);
2651
+ }
2652
+ return view;
2653
+ }
2654
+ getPanel(id) {
2655
+ var _a;
2656
+ return (_a = this._groups.get(id)) === null || _a === void 0 ? void 0 : _a.value;
2657
+ }
2658
+ doSetGroupActive(group) {
2659
+ if (this._activeGroup === group) {
2660
+ return;
2661
+ }
2662
+ if (this._activeGroup) {
2663
+ this._activeGroup.setActive(false);
2664
+ }
2665
+ if (group) {
2666
+ group.setActive(true);
2667
+ }
2668
+ this._activeGroup = group;
2669
+ this._onDidActiveChange.fire(group);
2670
+ }
2671
+ removeGroup(group) {
2672
+ this.doRemoveGroup(group);
2673
+ }
2674
+ moveToNext(options) {
2675
+ var _a;
2676
+ if (!options) {
2677
+ options = {};
2678
+ }
2679
+ if (!options.group) {
2680
+ if (!this.activeGroup) {
2681
+ return;
2682
+ }
2683
+ options.group = this.activeGroup;
2684
+ }
2685
+ const location = getGridLocation(options.group.element);
2686
+ const next = (_a = this.gridview.next(location)) === null || _a === void 0 ? void 0 : _a.view;
2687
+ this.doSetGroupActive(next);
2688
+ }
2689
+ moveToPrevious(options) {
2690
+ var _a;
2691
+ if (!options) {
2692
+ options = {};
2693
+ }
2694
+ if (!options.group) {
2695
+ if (!this.activeGroup) {
2696
+ return;
2697
+ }
2698
+ options.group = this.activeGroup;
2699
+ }
2700
+ const location = getGridLocation(options.group.element);
2701
+ const next = (_a = this.gridview.previous(location)) === null || _a === void 0 ? void 0 : _a.view;
2702
+ this.doSetGroupActive(next);
2703
+ }
2704
+ layout(width, height, forceResize) {
2705
+ const different = forceResize !== null && forceResize !== void 0 ? forceResize : (width !== this.width || height !== this.height);
2706
+ if (!different) {
2707
+ return;
2708
+ }
2709
+ this.gridview.element.style.height = `${height}px`;
2710
+ this.gridview.element.style.width = `${width}px`;
2711
+ this.gridview.layout(width, height);
2712
+ }
2713
+ dispose() {
2714
+ this._onDidActiveChange.dispose();
2715
+ this._onDidAdd.dispose();
2716
+ this._onDidRemove.dispose();
2717
+ this._onDidLayoutChange.dispose();
2718
+ for (const group of this.groups) {
2719
+ group.dispose();
2720
+ }
2721
+ this.gridview.dispose();
2722
+ super.dispose();
2723
+ }
2724
+ }
2725
+
2471
2726
  class SplitviewApi {
2472
2727
  /**
2473
2728
  * The minimum size the component can reach where size is measured in the direction of orientation provided.
@@ -3010,6 +3265,9 @@ class DockviewApi {
3010
3265
  get onWillDragPanel() {
3011
3266
  return this.component.onWillDragPanel;
3012
3267
  }
3268
+ get onUnhandledDragOverEvent() {
3269
+ return this.component.onUnhandledDragOverEvent;
3270
+ }
3013
3271
  /**
3014
3272
  * All panel objects.
3015
3273
  */
@@ -3147,6 +3405,67 @@ class DockviewApi {
3147
3405
  }
3148
3406
  }
3149
3407
 
3408
+ class DragHandler extends CompositeDisposable {
3409
+ constructor(el) {
3410
+ super();
3411
+ this.el = el;
3412
+ this.dataDisposable = new MutableDisposable();
3413
+ this.pointerEventsDisposable = new MutableDisposable();
3414
+ this._onDragStart = new Emitter();
3415
+ this.onDragStart = this._onDragStart.event;
3416
+ this.addDisposables(this._onDragStart, this.dataDisposable, this.pointerEventsDisposable);
3417
+ this.configure();
3418
+ }
3419
+ isCancelled(_event) {
3420
+ return false;
3421
+ }
3422
+ configure() {
3423
+ this.addDisposables(this._onDragStart, addDisposableListener(this.el, 'dragstart', (event) => {
3424
+ if (event.defaultPrevented || this.isCancelled(event)) {
3425
+ event.preventDefault();
3426
+ return;
3427
+ }
3428
+ const iframes = [
3429
+ ...getElementsByTagName('iframe'),
3430
+ ...getElementsByTagName('webview'),
3431
+ ];
3432
+ this.pointerEventsDisposable.value = {
3433
+ dispose: () => {
3434
+ for (const iframe of iframes) {
3435
+ iframe.style.pointerEvents = 'auto';
3436
+ }
3437
+ },
3438
+ };
3439
+ for (const iframe of iframes) {
3440
+ iframe.style.pointerEvents = 'none';
3441
+ }
3442
+ this.el.classList.add('dv-dragged');
3443
+ setTimeout(() => this.el.classList.remove('dv-dragged'), 0);
3444
+ this.dataDisposable.value = this.getData(event);
3445
+ this._onDragStart.fire(event);
3446
+ if (event.dataTransfer) {
3447
+ event.dataTransfer.effectAllowed = 'move';
3448
+ const hasData = event.dataTransfer.items.length > 0;
3449
+ if (!hasData) {
3450
+ /**
3451
+ * Although this is not used by dockview many third party dnd libraries will check
3452
+ * dataTransfer.types to determine valid drag events.
3453
+ *
3454
+ * For example: in react-dnd if dataTransfer.types is not set then the dragStart event will be cancelled
3455
+ * through .preventDefault(). Since this is applied globally to all drag events this would break dockviews
3456
+ * dnd logic. You can see the code at
3457
+ * https://github.com/react-dnd/react-dnd/blob/main/packages/backend-html5/src/HTML5BackendImpl.ts#L542
3458
+ */
3459
+ event.dataTransfer.setData('text/plain', '__dockview_internal_drag_event__');
3460
+ }
3461
+ }
3462
+ }), addDisposableListener(this.el, 'dragend', () => {
3463
+ this.pointerEventsDisposable.dispose();
3464
+ this.dataDisposable.dispose();
3465
+ }));
3466
+ }
3467
+ }
3468
+
3150
3469
  class DragAndDropObserver extends CompositeDisposable {
3151
3470
  constructor(element, callbacks) {
3152
3471
  super();
@@ -3291,6 +3610,10 @@ class Droptarget extends CompositeDisposable {
3291
3610
  this.removeDropTarget();
3292
3611
  return;
3293
3612
  }
3613
+ if (!this.options.canDisplayOverlay(e, quadrant)) {
3614
+ this.removeDropTarget();
3615
+ return;
3616
+ }
3294
3617
  const willShowOverlayEvent = new WillShowOverlayEvent({
3295
3618
  nativeEvent: e,
3296
3619
  position: quadrant,
@@ -3304,16 +3627,6 @@ class Droptarget extends CompositeDisposable {
3304
3627
  this.removeDropTarget();
3305
3628
  return;
3306
3629
  }
3307
- if (typeof this.options.canDisplayOverlay === 'boolean') {
3308
- if (!this.options.canDisplayOverlay) {
3309
- this.removeDropTarget();
3310
- return;
3311
- }
3312
- }
3313
- else if (!this.options.canDisplayOverlay(e, quadrant)) {
3314
- this.removeDropTarget();
3315
- return;
3316
- }
3317
3630
  this.markAsUsed(e);
3318
3631
  if (!this.targetElement) {
3319
3632
  this.targetElement = document.createElement('div');
@@ -3504,2023 +3817,1758 @@ function calculateQuadrantAsPixels(overlayType, x, y, width, height, threshold)
3504
3817
  return 'center';
3505
3818
  }
3506
3819
 
3507
- class ContentContainer extends CompositeDisposable {
3508
- get element() {
3509
- return this._element;
3510
- }
3511
- constructor(accessor, group) {
3820
+ class WillFocusEvent extends DockviewEvent {
3821
+ constructor() {
3512
3822
  super();
3513
- this.accessor = accessor;
3514
- this.group = group;
3515
- this.disposable = new MutableDisposable();
3516
- this._onDidFocus = new Emitter();
3517
- this.onDidFocus = this._onDidFocus.event;
3518
- this._onDidBlur = new Emitter();
3519
- this.onDidBlur = this._onDidBlur.event;
3520
- this._element = document.createElement('div');
3521
- this._element.className = 'content-container';
3522
- this._element.tabIndex = -1;
3523
- this.addDisposables(this._onDidFocus, this._onDidBlur);
3524
- this.dropTarget = new Droptarget(this.element, {
3525
- acceptedTargetZones: ['top', 'bottom', 'left', 'right', 'center'],
3526
- canDisplayOverlay: (event, position) => {
3527
- if (this.group.locked === 'no-drop-target' ||
3528
- (this.group.locked && position === 'center')) {
3529
- return false;
3530
- }
3531
- const data = getPanelData();
3532
- if (!data &&
3533
- event.shiftKey &&
3534
- this.group.location.type !== 'floating') {
3535
- return false;
3536
- }
3537
- if (data && data.viewId === this.accessor.id) {
3538
- if (data.groupId === this.group.id) {
3539
- if (position === 'center') {
3540
- // don't allow to drop on self for center position
3541
- return false;
3542
- }
3543
- if (data.panelId === null) {
3544
- // don't allow group move to drop anywhere on self
3545
- return false;
3546
- }
3547
- }
3548
- const groupHasOnePanelAndIsActiveDragElement = this.group.panels.length === 1 &&
3549
- data.groupId === this.group.id;
3550
- return !groupHasOnePanelAndIsActiveDragElement;
3551
- }
3552
- return this.group.canDisplayOverlay(event, position, 'content');
3553
- },
3554
- });
3555
- this.addDisposables(this.dropTarget);
3556
3823
  }
3557
- show() {
3558
- this.element.style.display = '';
3824
+ }
3825
+ /**
3826
+ * A core api implementation that should be used across all panel-like objects
3827
+ */
3828
+ class PanelApiImpl extends CompositeDisposable {
3829
+ get isFocused() {
3830
+ return this._isFocused;
3559
3831
  }
3560
- hide() {
3561
- this.element.style.display = 'none';
3832
+ get isActive() {
3833
+ return this._isActive;
3562
3834
  }
3563
- renderPanel(panel, options = { asActive: true }) {
3564
- const doRender = options.asActive ||
3565
- (this.panel && this.group.isPanelActive(this.panel));
3566
- if (this.panel &&
3567
- this.panel.view.content.element.parentElement === this._element) {
3568
- /**
3569
- * If the currently attached panel is mounted directly to the content then remove it
3570
- */
3571
- this._element.removeChild(this.panel.view.content.element);
3572
- }
3573
- this.panel = panel;
3574
- let container;
3575
- switch (panel.api.renderer) {
3576
- case 'onlyWhenVisible':
3577
- this.group.renderContainer.detatch(panel);
3578
- if (this.panel) {
3579
- if (doRender) {
3580
- this._element.appendChild(this.panel.view.content.element);
3581
- }
3582
- }
3583
- container = this._element;
3584
- break;
3585
- case 'always':
3586
- if (panel.view.content.element.parentElement === this._element) {
3587
- this._element.removeChild(panel.view.content.element);
3588
- }
3589
- container = this.group.renderContainer.attach({
3590
- panel,
3591
- referenceContainer: this,
3592
- });
3593
- break;
3594
- }
3595
- if (doRender) {
3596
- const _onDidFocus = panel.view.content.onDidFocus;
3597
- const _onDidBlur = panel.view.content.onDidBlur;
3598
- const focusTracker = trackFocus(container);
3599
- const disposable = new CompositeDisposable();
3600
- disposable.addDisposables(focusTracker, focusTracker.onDidFocus(() => this._onDidFocus.fire()), focusTracker.onDidBlur(() => this._onDidBlur.fire()));
3601
- if (_onDidFocus) {
3602
- disposable.addDisposables(_onDidFocus(() => this._onDidFocus.fire()));
3603
- }
3604
- if (_onDidBlur) {
3605
- disposable.addDisposables(_onDidBlur(() => this._onDidBlur.fire()));
3606
- }
3607
- this.disposable.value = disposable;
3608
- }
3835
+ get isVisible() {
3836
+ return this._isVisible;
3609
3837
  }
3610
- openPanel(panel) {
3611
- if (this.panel === panel) {
3612
- return;
3613
- }
3614
- this.renderPanel(panel);
3838
+ get width() {
3839
+ return this._width;
3615
3840
  }
3616
- layout(_width, _height) {
3617
- // noop
3841
+ get height() {
3842
+ return this._height;
3618
3843
  }
3619
- closePanel() {
3620
- var _a;
3621
- if (this.panel) {
3622
- if (this.panel.api.renderer === 'onlyWhenVisible') {
3623
- (_a = this.panel.view.content.element.parentElement) === null || _a === void 0 ? void 0 : _a.removeChild(this.panel.view.content.element);
3624
- }
3625
- }
3626
- this.panel = undefined;
3844
+ constructor(id, component) {
3845
+ super();
3846
+ this.id = id;
3847
+ this.component = component;
3848
+ this._isFocused = false;
3849
+ this._isActive = false;
3850
+ this._isVisible = true;
3851
+ this._width = 0;
3852
+ this._height = 0;
3853
+ this._parameters = {};
3854
+ this.panelUpdatesDisposable = new MutableDisposable();
3855
+ this._onDidDimensionChange = new Emitter();
3856
+ this.onDidDimensionsChange = this._onDidDimensionChange.event;
3857
+ this._onDidChangeFocus = new Emitter();
3858
+ this.onDidFocusChange = this._onDidChangeFocus.event;
3859
+ //
3860
+ this._onWillFocus = new Emitter();
3861
+ this.onWillFocus = this._onWillFocus.event;
3862
+ //
3863
+ this._onDidVisibilityChange = new Emitter();
3864
+ this.onDidVisibilityChange = this._onDidVisibilityChange.event;
3865
+ this._onWillVisibilityChange = new Emitter();
3866
+ this.onWillVisibilityChange = this._onWillVisibilityChange.event;
3867
+ this._onDidActiveChange = new Emitter();
3868
+ this.onDidActiveChange = this._onDidActiveChange.event;
3869
+ this._onActiveChange = new Emitter();
3870
+ this.onActiveChange = this._onActiveChange.event;
3871
+ this._onDidParametersChange = new Emitter();
3872
+ this.onDidParametersChange = this._onDidParametersChange.event;
3873
+ this.addDisposables(this.onDidFocusChange((event) => {
3874
+ this._isFocused = event.isFocused;
3875
+ }), this.onDidActiveChange((event) => {
3876
+ this._isActive = event.isActive;
3877
+ }), this.onDidVisibilityChange((event) => {
3878
+ this._isVisible = event.isVisible;
3879
+ }), this.onDidDimensionsChange((event) => {
3880
+ this._width = event.width;
3881
+ this._height = event.height;
3882
+ }), this.panelUpdatesDisposable, this._onDidDimensionChange, this._onDidChangeFocus, this._onDidVisibilityChange, this._onDidActiveChange, this._onWillFocus, this._onActiveChange, this._onWillFocus, this._onWillVisibilityChange, this._onDidParametersChange);
3627
3883
  }
3628
- dispose() {
3629
- this.disposable.dispose();
3630
- super.dispose();
3884
+ getParameters() {
3885
+ return this._parameters;
3886
+ }
3887
+ initialize(panel) {
3888
+ this.panelUpdatesDisposable.value = this._onDidParametersChange.event((parameters) => {
3889
+ this._parameters = parameters;
3890
+ panel.update({
3891
+ params: parameters,
3892
+ });
3893
+ });
3894
+ }
3895
+ setVisible(isVisible) {
3896
+ this._onWillVisibilityChange.fire({ isVisible });
3897
+ }
3898
+ setActive() {
3899
+ this._onActiveChange.fire();
3900
+ }
3901
+ updateParameters(parameters) {
3902
+ this._onDidParametersChange.fire(parameters);
3631
3903
  }
3632
3904
  }
3633
3905
 
3634
- class DragHandler extends CompositeDisposable {
3635
- constructor(el) {
3636
- super();
3637
- this.el = el;
3638
- this.dataDisposable = new MutableDisposable();
3639
- this.pointerEventsDisposable = new MutableDisposable();
3640
- this._onDragStart = new Emitter();
3641
- this.onDragStart = this._onDragStart.event;
3642
- this.addDisposables(this._onDragStart, this.dataDisposable, this.pointerEventsDisposable);
3643
- this.configure();
3906
+ class SplitviewPanelApiImpl extends PanelApiImpl {
3907
+ //
3908
+ constructor(id, component) {
3909
+ super(id, component);
3910
+ this._onDidConstraintsChangeInternal = new Emitter();
3911
+ this.onDidConstraintsChangeInternal = this._onDidConstraintsChangeInternal.event;
3912
+ //
3913
+ this._onDidConstraintsChange = new Emitter({
3914
+ replay: true,
3915
+ });
3916
+ this.onDidConstraintsChange = this._onDidConstraintsChange.event;
3917
+ //
3918
+ this._onDidSizeChange = new Emitter();
3919
+ this.onDidSizeChange = this._onDidSizeChange.event;
3920
+ this.addDisposables(this._onDidConstraintsChangeInternal, this._onDidConstraintsChange, this._onDidSizeChange);
3644
3921
  }
3645
- isCancelled(_event) {
3646
- return false;
3922
+ setConstraints(value) {
3923
+ this._onDidConstraintsChangeInternal.fire(value);
3647
3924
  }
3648
- configure() {
3649
- this.addDisposables(this._onDragStart, addDisposableListener(this.el, 'dragstart', (event) => {
3650
- if (event.defaultPrevented || this.isCancelled(event)) {
3651
- event.preventDefault();
3652
- return;
3653
- }
3654
- const iframes = [
3655
- ...getElementsByTagName('iframe'),
3656
- ...getElementsByTagName('webview'),
3657
- ];
3658
- this.pointerEventsDisposable.value = {
3659
- dispose: () => {
3660
- for (const iframe of iframes) {
3661
- iframe.style.pointerEvents = 'auto';
3662
- }
3663
- },
3664
- };
3665
- for (const iframe of iframes) {
3666
- iframe.style.pointerEvents = 'none';
3667
- }
3668
- this.el.classList.add('dv-dragged');
3669
- setTimeout(() => this.el.classList.remove('dv-dragged'), 0);
3670
- this.dataDisposable.value = this.getData(event);
3671
- this._onDragStart.fire(event);
3672
- if (event.dataTransfer) {
3673
- event.dataTransfer.effectAllowed = 'move';
3674
- const hasData = event.dataTransfer.items.length > 0;
3675
- if (!hasData) {
3676
- /**
3677
- * Although this is not used by dockview many third party dnd libraries will check
3678
- * dataTransfer.types to determine valid drag events.
3679
- *
3680
- * For example: in react-dnd if dataTransfer.types is not set then the dragStart event will be cancelled
3681
- * through .preventDefault(). Since this is applied globally to all drag events this would break dockviews
3682
- * dnd logic. You can see the code at
3683
- * https://github.com/react-dnd/react-dnd/blob/main/packages/backend-html5/src/HTML5BackendImpl.ts#L542
3684
- */
3685
- event.dataTransfer.setData('text/plain', '__dockview_internal_drag_event__');
3686
- }
3687
- }
3688
- }), addDisposableListener(this.el, 'dragend', () => {
3689
- this.pointerEventsDisposable.dispose();
3690
- this.dataDisposable.dispose();
3691
- }));
3925
+ setSize(event) {
3926
+ this._onDidSizeChange.fire(event);
3692
3927
  }
3693
3928
  }
3694
3929
 
3695
- class TabDragHandler extends DragHandler {
3696
- constructor(element, accessor, group, panel) {
3697
- super(element);
3698
- this.accessor = accessor;
3699
- this.group = group;
3700
- this.panel = panel;
3701
- this.panelTransfer = LocalSelectionTransfer.getInstance();
3930
+ class PaneviewPanelApiImpl extends SplitviewPanelApiImpl {
3931
+ set pane(pane) {
3932
+ this._pane = pane;
3702
3933
  }
3703
- getData(event) {
3704
- this.panelTransfer.setData([new PanelTransfer(this.accessor.id, this.group.id, this.panel.id)], PanelTransfer.prototype);
3705
- return {
3706
- dispose: () => {
3707
- this.panelTransfer.clearData(PanelTransfer.prototype);
3708
- },
3709
- };
3934
+ constructor(id, component) {
3935
+ super(id, component);
3936
+ this._onDidExpansionChange = new Emitter({
3937
+ replay: true,
3938
+ });
3939
+ this.onDidExpansionChange = this._onDidExpansionChange.event;
3940
+ this._onMouseEnter = new Emitter({});
3941
+ this.onMouseEnter = this._onMouseEnter.event;
3942
+ this._onMouseLeave = new Emitter({});
3943
+ this.onMouseLeave = this._onMouseLeave.event;
3944
+ this.addDisposables(this._onDidExpansionChange, this._onMouseEnter, this._onMouseLeave);
3945
+ }
3946
+ setExpanded(isExpanded) {
3947
+ var _a;
3948
+ (_a = this._pane) === null || _a === void 0 ? void 0 : _a.setExpanded(isExpanded);
3949
+ }
3950
+ get isExpanded() {
3951
+ var _a;
3952
+ return !!((_a = this._pane) === null || _a === void 0 ? void 0 : _a.isExpanded());
3710
3953
  }
3711
3954
  }
3712
- class Tab extends CompositeDisposable {
3955
+
3956
+ class BasePanelView extends CompositeDisposable {
3713
3957
  get element() {
3714
3958
  return this._element;
3715
3959
  }
3716
- constructor(panel, accessor, group) {
3960
+ get width() {
3961
+ return this._width;
3962
+ }
3963
+ get height() {
3964
+ return this._height;
3965
+ }
3966
+ get params() {
3967
+ var _a;
3968
+ return (_a = this._params) === null || _a === void 0 ? void 0 : _a.params;
3969
+ }
3970
+ constructor(id, component, api) {
3717
3971
  super();
3718
- this.panel = panel;
3719
- this.accessor = accessor;
3720
- this.group = group;
3721
- this.content = undefined;
3722
- this._onChanged = new Emitter();
3723
- this.onChanged = this._onChanged.event;
3724
- this._onDropped = new Emitter();
3725
- this.onDrop = this._onDropped.event;
3726
- this._onDragStart = new Emitter();
3727
- this.onDragStart = this._onDragStart.event;
3972
+ this.id = id;
3973
+ this.component = component;
3974
+ this.api = api;
3975
+ this._height = 0;
3976
+ this._width = 0;
3728
3977
  this._element = document.createElement('div');
3729
- this._element.className = 'tab';
3730
- this._element.tabIndex = 0;
3731
- this._element.draggable = true;
3732
- toggleClass(this.element, 'inactive-tab', true);
3733
- const dragHandler = new TabDragHandler(this._element, this.accessor, this.group, this.panel);
3734
- this.dropTarget = new Droptarget(this._element, {
3735
- acceptedTargetZones: ['center'],
3736
- canDisplayOverlay: (event, position) => {
3737
- if (this.group.locked) {
3738
- return false;
3739
- }
3740
- const data = getPanelData();
3741
- if (data && this.accessor.id === data.viewId) {
3742
- if (data.panelId === null &&
3743
- data.groupId === this.group.id) {
3744
- // don't allow group move to drop on self
3745
- return false;
3746
- }
3747
- return this.panel.id !== data.panelId;
3748
- }
3749
- return this.group.model.canDisplayOverlay(event, position, 'tab');
3750
- },
3751
- });
3752
- this.onWillShowOverlay = this.dropTarget.onWillShowOverlay;
3753
- this.addDisposables(this._onChanged, this._onDropped, this._onDragStart, dragHandler.onDragStart((event) => {
3754
- this._onDragStart.fire(event);
3755
- }), dragHandler, addDisposableListener(this._element, 'mousedown', (event) => {
3756
- if (event.defaultPrevented) {
3757
- return;
3978
+ this._element.tabIndex = -1;
3979
+ this._element.style.outline = 'none';
3980
+ this._element.style.height = '100%';
3981
+ this._element.style.width = '100%';
3982
+ this._element.style.overflow = 'hidden';
3983
+ const focusTracker = trackFocus(this._element);
3984
+ this.addDisposables(this.api, focusTracker.onDidFocus(() => {
3985
+ this.api._onDidChangeFocus.fire({ isFocused: true });
3986
+ }), focusTracker.onDidBlur(() => {
3987
+ this.api._onDidChangeFocus.fire({ isFocused: false });
3988
+ }), focusTracker);
3989
+ }
3990
+ focus() {
3991
+ const event = new WillFocusEvent();
3992
+ this.api._onWillFocus.fire(event);
3993
+ if (event.defaultPrevented) {
3994
+ return;
3995
+ }
3996
+ this._element.focus();
3997
+ }
3998
+ layout(width, height) {
3999
+ this._width = width;
4000
+ this._height = height;
4001
+ this.api._onDidDimensionChange.fire({ width, height });
4002
+ if (this.part) {
4003
+ if (this._params) {
4004
+ this.part.update(this._params.params);
3758
4005
  }
3759
- this._onChanged.fire(event);
3760
- }), this.dropTarget.onDrop((event) => {
3761
- this._onDropped.fire(event);
3762
- }), this.dropTarget);
4006
+ }
3763
4007
  }
3764
- setActive(isActive) {
3765
- toggleClass(this.element, 'active-tab', isActive);
3766
- toggleClass(this.element, 'inactive-tab', !isActive);
4008
+ init(parameters) {
4009
+ this._params = parameters;
4010
+ this.part = this.getComponent();
3767
4011
  }
3768
- setContent(part) {
3769
- if (this.content) {
3770
- this._element.removeChild(this.content.element);
4012
+ update(event) {
4013
+ var _a, _b;
4014
+ // merge the new parameters with the existing parameters
4015
+ this._params = Object.assign(Object.assign({}, this._params), { params: Object.assign(Object.assign({}, (_a = this._params) === null || _a === void 0 ? void 0 : _a.params), event.params) });
4016
+ /**
4017
+ * delete new keys that have a value of undefined,
4018
+ * allow values of null
4019
+ */
4020
+ for (const key of Object.keys(event.params)) {
4021
+ if (event.params[key] === undefined) {
4022
+ delete this._params.params[key];
4023
+ }
3771
4024
  }
3772
- this.content = part;
3773
- this._element.appendChild(this.content.element);
4025
+ // update the view with the updated props
4026
+ (_b = this.part) === null || _b === void 0 ? void 0 : _b.update({ params: this._params.params });
4027
+ }
4028
+ toJSON() {
4029
+ var _a, _b;
4030
+ const params = (_b = (_a = this._params) === null || _a === void 0 ? void 0 : _a.params) !== null && _b !== void 0 ? _b : {};
4031
+ return {
4032
+ id: this.id,
4033
+ component: this.component,
4034
+ params: Object.keys(params).length > 0 ? params : undefined,
4035
+ };
3774
4036
  }
3775
4037
  dispose() {
4038
+ var _a;
4039
+ this.api.dispose();
4040
+ (_a = this.part) === null || _a === void 0 ? void 0 : _a.dispose();
3776
4041
  super.dispose();
3777
4042
  }
3778
4043
  }
3779
4044
 
3780
- function addGhostImage(dataTransfer, ghostElement) {
3781
- // class dockview provides to force ghost image to be drawn on a different layer and prevent weird rendering issues
3782
- addClasses(ghostElement, 'dv-dragged');
3783
- document.body.appendChild(ghostElement);
3784
- dataTransfer.setDragImage(ghostElement, 0, 0);
3785
- setTimeout(() => {
3786
- removeClasses(ghostElement, 'dv-dragged');
3787
- ghostElement.remove();
3788
- }, 0);
3789
- }
3790
-
3791
- class GroupDragHandler extends DragHandler {
3792
- constructor(element, accessor, group) {
3793
- super(element);
3794
- this.accessor = accessor;
3795
- this.group = group;
3796
- this.panelTransfer = LocalSelectionTransfer.getInstance();
3797
- this.addDisposables(addDisposableListener(element, 'mousedown', (e) => {
3798
- if (e.shiftKey) {
3799
- /**
3800
- * You cannot call e.preventDefault() because that will prevent drag events from firing
3801
- * but we also need to stop any group overlay drag events from occuring
3802
- * Use a custom event marker that can be checked by the overlay drag events
3803
- */
3804
- quasiPreventDefault(e);
3805
- }
3806
- }, true));
4045
+ class PaneviewPanel extends BasePanelView {
4046
+ set orientation(value) {
4047
+ this._orientation = value;
3807
4048
  }
3808
- isCancelled(_event) {
3809
- if (this.group.api.location.type === 'floating' && !_event.shiftKey) {
3810
- return true;
3811
- }
3812
- return false;
4049
+ get orientation() {
4050
+ return this._orientation;
3813
4051
  }
3814
- getData(dragEvent) {
3815
- const dataTransfer = dragEvent.dataTransfer;
3816
- this.panelTransfer.setData([new PanelTransfer(this.accessor.id, this.group.id, null)], PanelTransfer.prototype);
3817
- const style = window.getComputedStyle(this.el);
3818
- const bgColor = style.getPropertyValue('--dv-activegroup-visiblepanel-tab-background-color');
3819
- const color = style.getPropertyValue('--dv-activegroup-visiblepanel-tab-color');
3820
- if (dataTransfer) {
3821
- const ghostElement = document.createElement('div');
3822
- ghostElement.style.backgroundColor = bgColor;
3823
- ghostElement.style.color = color;
3824
- ghostElement.style.padding = '2px 8px';
3825
- ghostElement.style.height = '24px';
3826
- ghostElement.style.fontSize = '11px';
3827
- ghostElement.style.lineHeight = '20px';
3828
- ghostElement.style.borderRadius = '12px';
3829
- ghostElement.style.position = 'absolute';
3830
- ghostElement.textContent = `Multiple Panels (${this.group.size})`;
3831
- addGhostImage(dataTransfer, ghostElement);
3832
- }
3833
- return {
3834
- dispose: () => {
3835
- this.panelTransfer.clearData(PanelTransfer.prototype);
3836
- },
3837
- };
4052
+ get minimumSize() {
4053
+ const headerSize = this.headerSize;
4054
+ const expanded = this.isExpanded();
4055
+ const minimumBodySize = expanded ? this._minimumBodySize : 0;
4056
+ return headerSize + minimumBodySize;
3838
4057
  }
3839
- }
3840
-
3841
- class VoidContainer extends CompositeDisposable {
3842
- get element() {
3843
- return this._element;
4058
+ get maximumSize() {
4059
+ const headerSize = this.headerSize;
4060
+ const expanded = this.isExpanded();
4061
+ const maximumBodySize = expanded ? this._maximumBodySize : 0;
4062
+ return headerSize + maximumBodySize;
3844
4063
  }
3845
- constructor(accessor, group) {
3846
- super();
3847
- this.accessor = accessor;
3848
- this.group = group;
3849
- this._onDrop = new Emitter();
3850
- this.onDrop = this._onDrop.event;
3851
- this._onDragStart = new Emitter();
3852
- this.onDragStart = this._onDragStart.event;
3853
- this._element = document.createElement('div');
3854
- this._element.className = 'void-container';
3855
- this._element.tabIndex = 0;
3856
- this._element.draggable = true;
3857
- this.addDisposables(this._onDrop, this._onDragStart, addDisposableListener(this._element, 'click', () => {
3858
- this.accessor.doSetGroupActive(this.group);
3859
- }));
3860
- const handler = new GroupDragHandler(this._element, accessor, group);
3861
- this.dropTraget = new Droptarget(this._element, {
3862
- acceptedTargetZones: ['center'],
3863
- canDisplayOverlay: (event, position) => {
3864
- var _a;
3865
- const data = getPanelData();
3866
- if (data && this.accessor.id === data.viewId) {
3867
- if (data.panelId === null &&
3868
- data.groupId === this.group.id) {
3869
- // don't allow group move to drop on self
3870
- return false;
3871
- }
3872
- // don't show the overlay if the tab being dragged is the last panel of this group
3873
- return ((_a = last(this.group.panels)) === null || _a === void 0 ? void 0 : _a.id) !== data.panelId;
3874
- }
3875
- return group.model.canDisplayOverlay(event, position, 'header_space');
3876
- },
3877
- });
3878
- this.onWillShowOverlay = this.dropTraget.onWillShowOverlay;
3879
- this.addDisposables(handler, handler.onDragStart((event) => {
3880
- this._onDragStart.fire(event);
3881
- }), this.dropTraget.onDrop((event) => {
3882
- this._onDrop.fire(event);
3883
- }), this.dropTraget);
4064
+ get size() {
4065
+ return this._size;
3884
4066
  }
3885
- }
3886
-
3887
- class TabsContainer extends CompositeDisposable {
3888
- get panels() {
3889
- return this.tabs.map((_) => _.value.panel.id);
4067
+ get orthogonalSize() {
4068
+ return this._orthogonalSize;
3890
4069
  }
3891
- get size() {
3892
- return this.tabs.length;
4070
+ set orthogonalSize(size) {
4071
+ this._orthogonalSize = size;
3893
4072
  }
3894
- get hidden() {
3895
- return this._hidden;
4073
+ get minimumBodySize() {
4074
+ return this._minimumBodySize;
3896
4075
  }
3897
- set hidden(value) {
3898
- this._hidden = value;
3899
- this.element.style.display = value ? 'none' : '';
4076
+ set minimumBodySize(value) {
4077
+ this._minimumBodySize = typeof value === 'number' ? value : 0;
3900
4078
  }
3901
- show() {
3902
- if (!this.hidden) {
3903
- this.element.style.display = '';
3904
- }
4079
+ get maximumBodySize() {
4080
+ return this._maximumBodySize;
3905
4081
  }
3906
- hide() {
3907
- this._element.style.display = 'none';
4082
+ set maximumBodySize(value) {
4083
+ this._maximumBodySize =
4084
+ typeof value === 'number' ? value : Number.POSITIVE_INFINITY;
3908
4085
  }
3909
- setRightActionsElement(element) {
3910
- if (this.rightActions === element) {
4086
+ get headerVisible() {
4087
+ return this._headerVisible;
4088
+ }
4089
+ set headerVisible(value) {
4090
+ this._headerVisible = value;
4091
+ this.header.style.display = value ? '' : 'none';
4092
+ }
4093
+ constructor(id, component, headerComponent, orientation, isExpanded, isHeaderVisible) {
4094
+ super(id, component, new PaneviewPanelApiImpl(id, component));
4095
+ this.headerComponent = headerComponent;
4096
+ this._onDidChangeExpansionState = new Emitter({ replay: true });
4097
+ this.onDidChangeExpansionState = this._onDidChangeExpansionState.event;
4098
+ this._onDidChange = new Emitter();
4099
+ this.onDidChange = this._onDidChange.event;
4100
+ this.headerSize = 22;
4101
+ this._orthogonalSize = 0;
4102
+ this._size = 0;
4103
+ this._minimumBodySize = 100;
4104
+ this._maximumBodySize = Number.POSITIVE_INFINITY;
4105
+ this._isExpanded = false;
4106
+ this.expandedSize = 0;
4107
+ this.api.pane = this; // TODO cannot use 'this' before 'super'
4108
+ this.api.initialize(this);
4109
+ this._isExpanded = isExpanded;
4110
+ this._headerVisible = isHeaderVisible;
4111
+ this._onDidChangeExpansionState.fire(this.isExpanded()); // initialize value
4112
+ this._orientation = orientation;
4113
+ this.element.classList.add('pane');
4114
+ this.addDisposables(this.api.onWillVisibilityChange((event) => {
4115
+ const { isVisible } = event;
4116
+ const { accessor } = this._params;
4117
+ accessor.setVisible(this, isVisible);
4118
+ }), this.api.onDidSizeChange((event) => {
4119
+ this._onDidChange.fire({ size: event.size });
4120
+ }), addDisposableListener(this.element, 'mouseenter', (ev) => {
4121
+ this.api._onMouseEnter.fire(ev);
4122
+ }), addDisposableListener(this.element, 'mouseleave', (ev) => {
4123
+ this.api._onMouseLeave.fire(ev);
4124
+ }));
4125
+ this.addDisposables(this._onDidChangeExpansionState, this.onDidChangeExpansionState((isPanelExpanded) => {
4126
+ this.api._onDidExpansionChange.fire({
4127
+ isExpanded: isPanelExpanded,
4128
+ });
4129
+ }), this.api.onDidFocusChange((e) => {
4130
+ if (!this.header) {
4131
+ return;
4132
+ }
4133
+ if (e.isFocused) {
4134
+ addClasses(this.header, 'focused');
4135
+ }
4136
+ else {
4137
+ removeClasses(this.header, 'focused');
4138
+ }
4139
+ }));
4140
+ this.renderOnce();
4141
+ }
4142
+ setVisible(isVisible) {
4143
+ this.api._onDidVisibilityChange.fire({ isVisible });
4144
+ }
4145
+ setActive(isActive) {
4146
+ this.api._onDidActiveChange.fire({ isActive });
4147
+ }
4148
+ isExpanded() {
4149
+ return this._isExpanded;
4150
+ }
4151
+ setExpanded(expanded) {
4152
+ if (this._isExpanded === expanded) {
3911
4153
  return;
3912
4154
  }
3913
- if (this.rightActions) {
3914
- this.rightActions.remove();
3915
- this.rightActions = undefined;
4155
+ this._isExpanded = expanded;
4156
+ if (expanded) {
4157
+ if (this.animationTimer) {
4158
+ clearTimeout(this.animationTimer);
4159
+ }
4160
+ if (this.body) {
4161
+ this.element.appendChild(this.body);
4162
+ }
3916
4163
  }
3917
- if (element) {
3918
- this.rightActionsContainer.appendChild(element);
3919
- this.rightActions = element;
4164
+ else {
4165
+ this.animationTimer = setTimeout(() => {
4166
+ var _a;
4167
+ (_a = this.body) === null || _a === void 0 ? void 0 : _a.remove();
4168
+ }, 200);
3920
4169
  }
4170
+ this._onDidChange.fire(expanded ? { size: this.width } : {});
4171
+ this._onDidChangeExpansionState.fire(expanded);
3921
4172
  }
3922
- setLeftActionsElement(element) {
3923
- if (this.leftActions === element) {
3924
- return;
3925
- }
3926
- if (this.leftActions) {
3927
- this.leftActions.remove();
3928
- this.leftActions = undefined;
3929
- }
3930
- if (element) {
3931
- this.leftActionsContainer.appendChild(element);
3932
- this.leftActions = element;
4173
+ layout(size, orthogonalSize) {
4174
+ this._size = size;
4175
+ this._orthogonalSize = orthogonalSize;
4176
+ const [width, height] = this.orientation === exports.Orientation.HORIZONTAL
4177
+ ? [size, orthogonalSize]
4178
+ : [orthogonalSize, size];
4179
+ if (this.isExpanded()) {
4180
+ this.expandedSize = width;
3933
4181
  }
4182
+ super.layout(width, height);
3934
4183
  }
3935
- setPrefixActionsElement(element) {
3936
- if (this.preActions === element) {
3937
- return;
4184
+ init(parameters) {
4185
+ var _a, _b;
4186
+ super.init(parameters);
4187
+ if (typeof parameters.minimumBodySize === 'number') {
4188
+ this.minimumBodySize = parameters.minimumBodySize;
3938
4189
  }
3939
- if (this.preActions) {
3940
- this.preActions.remove();
3941
- this.preActions = undefined;
4190
+ if (typeof parameters.maximumBodySize === 'number') {
4191
+ this.maximumBodySize = parameters.maximumBodySize;
3942
4192
  }
3943
- if (element) {
3944
- this.preActionsContainer.appendChild(element);
3945
- this.preActions = element;
4193
+ this.bodyPart = this.getBodyComponent();
4194
+ this.headerPart = this.getHeaderComponent();
4195
+ this.bodyPart.init(Object.assign(Object.assign({}, parameters), { api: this.api }));
4196
+ this.headerPart.init(Object.assign(Object.assign({}, parameters), { api: this.api }));
4197
+ (_a = this.body) === null || _a === void 0 ? void 0 : _a.append(this.bodyPart.element);
4198
+ (_b = this.header) === null || _b === void 0 ? void 0 : _b.append(this.headerPart.element);
4199
+ if (typeof parameters.isExpanded === 'boolean') {
4200
+ this.setExpanded(parameters.isExpanded);
3946
4201
  }
3947
4202
  }
3948
- get element() {
3949
- return this._element;
4203
+ toJSON() {
4204
+ const params = this._params;
4205
+ return Object.assign(Object.assign({}, super.toJSON()), { headerComponent: this.headerComponent, title: params.title });
3950
4206
  }
3951
- isActive(tab) {
3952
- return (this.selectedIndex > -1 &&
3953
- this.tabs[this.selectedIndex].value === tab);
4207
+ renderOnce() {
4208
+ this.header = document.createElement('div');
4209
+ this.header.tabIndex = 0;
4210
+ this.header.className = 'pane-header';
4211
+ this.header.style.height = `${this.headerSize}px`;
4212
+ this.header.style.lineHeight = `${this.headerSize}px`;
4213
+ this.header.style.minHeight = `${this.headerSize}px`;
4214
+ this.header.style.maxHeight = `${this.headerSize}px`;
4215
+ this.element.appendChild(this.header);
4216
+ this.body = document.createElement('div');
4217
+ this.body.className = 'pane-body';
4218
+ this.element.appendChild(this.body);
3954
4219
  }
3955
- indexOf(id) {
3956
- return this.tabs.findIndex((tab) => tab.value.panel.id === id);
4220
+ // TODO slightly hacky by-pass of the component to create a body and header component
4221
+ getComponent() {
4222
+ return {
4223
+ update: (params) => {
4224
+ var _a, _b;
4225
+ (_a = this.bodyPart) === null || _a === void 0 ? void 0 : _a.update({ params });
4226
+ (_b = this.headerPart) === null || _b === void 0 ? void 0 : _b.update({ params });
4227
+ },
4228
+ dispose: () => {
4229
+ var _a, _b;
4230
+ (_a = this.bodyPart) === null || _a === void 0 ? void 0 : _a.dispose();
4231
+ (_b = this.headerPart) === null || _b === void 0 ? void 0 : _b.dispose();
4232
+ },
4233
+ };
3957
4234
  }
3958
- constructor(accessor, group) {
3959
- super();
4235
+ }
4236
+
4237
+ class DraggablePaneviewPanel extends PaneviewPanel {
4238
+ constructor(accessor, id, component, headerComponent, orientation, isExpanded, disableDnd) {
4239
+ super(id, component, headerComponent, orientation, isExpanded, true);
3960
4240
  this.accessor = accessor;
3961
- this.group = group;
3962
- this.tabs = [];
3963
- this.selectedIndex = -1;
3964
- this._hidden = false;
3965
- this._onDrop = new Emitter();
3966
- this.onDrop = this._onDrop.event;
3967
- this._onTabDragStart = new Emitter();
3968
- this.onTabDragStart = this._onTabDragStart.event;
3969
- this._onGroupDragStart = new Emitter();
3970
- this.onGroupDragStart = this._onGroupDragStart.event;
3971
- this._onWillShowOverlay = new Emitter();
3972
- this.onWillShowOverlay = this._onWillShowOverlay.event;
3973
- this._element = document.createElement('div');
3974
- this._element.className = 'tabs-and-actions-container';
3975
- toggleClass(this._element, 'dv-full-width-single-tab', this.accessor.options.singleTabMode === 'fullwidth');
3976
- this.rightActionsContainer = document.createElement('div');
3977
- this.rightActionsContainer.className = 'right-actions-container';
3978
- this.leftActionsContainer = document.createElement('div');
3979
- this.leftActionsContainer.className = 'left-actions-container';
3980
- this.preActionsContainer = document.createElement('div');
3981
- this.preActionsContainer.className = 'pre-actions-container';
3982
- this.tabContainer = document.createElement('div');
3983
- this.tabContainer.className = 'tabs-container';
3984
- this.voidContainer = new VoidContainer(this.accessor, this.group);
3985
- this._element.appendChild(this.preActionsContainer);
3986
- this._element.appendChild(this.tabContainer);
3987
- this._element.appendChild(this.leftActionsContainer);
3988
- this._element.appendChild(this.voidContainer.element);
3989
- this._element.appendChild(this.rightActionsContainer);
3990
- this.addDisposables(this.accessor.onDidAddPanel((e) => {
3991
- if (e.api.group === this.group) {
3992
- toggleClass(this._element, 'dv-single-tab', this.size === 1);
3993
- }
3994
- }), this.accessor.onDidRemovePanel((e) => {
3995
- if (e.api.group === this.group) {
3996
- toggleClass(this._element, 'dv-single-tab', this.size === 1);
3997
- }
3998
- }), this._onWillShowOverlay, this._onDrop, this._onTabDragStart, this._onGroupDragStart, this.voidContainer, this.voidContainer.onDragStart((event) => {
3999
- this._onGroupDragStart.fire({
4000
- nativeEvent: event,
4001
- group: this.group,
4002
- });
4003
- }), this.voidContainer.onDrop((event) => {
4004
- this._onDrop.fire({
4005
- event: event.nativeEvent,
4006
- index: this.tabs.length,
4007
- });
4008
- }), this.voidContainer.onWillShowOverlay((event) => {
4009
- this._onWillShowOverlay.fire(new WillShowOverlayLocationEvent(event, {
4010
- kind: 'header_space',
4011
- panel: this.group.activePanel,
4012
- api: this.accessor.api,
4013
- group: this.group,
4014
- getData: getPanelData,
4015
- }));
4016
- }), addDisposableListener(this.voidContainer.element, 'mousedown', (event) => {
4017
- const isFloatingGroupsEnabled = !this.accessor.options.disableFloatingGroups;
4018
- if (isFloatingGroupsEnabled &&
4019
- event.shiftKey &&
4020
- this.group.api.location.type !== 'floating') {
4021
- event.preventDefault();
4022
- const { top, left } = this.element.getBoundingClientRect();
4023
- const { top: rootTop, left: rootLeft } = this.accessor.element.getBoundingClientRect();
4024
- this.accessor.addFloatingGroup(this.group, {
4025
- x: left - rootLeft + 20,
4026
- y: top - rootTop + 20,
4027
- }, { inDragMode: true });
4028
- }
4029
- }), addDisposableListener(this.tabContainer, 'mousedown', (event) => {
4030
- if (event.defaultPrevented) {
4031
- return;
4032
- }
4033
- const isLeftClick = event.button === 0;
4034
- if (isLeftClick) {
4035
- this.accessor.doSetGroupActive(this.group);
4036
- }
4037
- }));
4038
- }
4039
- setActive(_isGroupActive) {
4040
- // noop
4041
- }
4042
- addTab(tab, index = this.tabs.length) {
4043
- if (index < 0 || index > this.tabs.length) {
4044
- throw new Error('invalid location');
4045
- }
4046
- this.tabContainer.insertBefore(tab.value.element, this.tabContainer.children[index]);
4047
- this.tabs = [
4048
- ...this.tabs.slice(0, index),
4049
- tab,
4050
- ...this.tabs.slice(index),
4051
- ];
4052
- if (this.selectedIndex < 0) {
4053
- this.selectedIndex = index;
4241
+ this._onDidDrop = new Emitter();
4242
+ this.onDidDrop = this._onDidDrop.event;
4243
+ if (!disableDnd) {
4244
+ this.initDragFeatures();
4054
4245
  }
4055
4246
  }
4056
- delete(id) {
4057
- const index = this.tabs.findIndex((tab) => tab.value.panel.id === id);
4058
- const tabToRemove = this.tabs.splice(index, 1)[0];
4059
- const { value, disposable } = tabToRemove;
4060
- disposable.dispose();
4061
- value.dispose();
4062
- value.element.remove();
4063
- }
4064
- setActivePanel(panel) {
4065
- this.tabs.forEach((tab) => {
4066
- const isActivePanel = panel.id === tab.value.panel.id;
4067
- tab.value.setActive(isActivePanel);
4247
+ initDragFeatures() {
4248
+ if (!this.header) {
4249
+ return;
4250
+ }
4251
+ const id = this.id;
4252
+ const accessorId = this.accessor.id;
4253
+ this.header.draggable = true;
4254
+ this.handler = new (class PaneDragHandler extends DragHandler {
4255
+ getData() {
4256
+ LocalSelectionTransfer.getInstance().setData([new PaneTransfer(accessorId, id)], PaneTransfer.prototype);
4257
+ return {
4258
+ dispose: () => {
4259
+ LocalSelectionTransfer.getInstance().clearData(PaneTransfer.prototype);
4260
+ },
4261
+ };
4262
+ }
4263
+ })(this.header);
4264
+ this.target = new Droptarget(this.element, {
4265
+ acceptedTargetZones: ['top', 'bottom'],
4266
+ overlayModel: {
4267
+ activationSize: { type: 'percentage', value: 50 },
4268
+ },
4269
+ canDisplayOverlay: (event) => {
4270
+ const data = getPaneData();
4271
+ if (data) {
4272
+ if (data.paneId !== this.id &&
4273
+ data.viewId === this.accessor.id) {
4274
+ return true;
4275
+ }
4276
+ }
4277
+ if (this.accessor.options.showDndOverlay) {
4278
+ return this.accessor.options.showDndOverlay({
4279
+ nativeEvent: event,
4280
+ getData: getPaneData,
4281
+ panel: this,
4282
+ });
4283
+ }
4284
+ return false;
4285
+ },
4068
4286
  });
4287
+ this.addDisposables(this._onDidDrop, this.handler, this.target, this.target.onDrop((event) => {
4288
+ this.onDrop(event);
4289
+ }));
4069
4290
  }
4070
- openPanel(panel, index = this.tabs.length) {
4071
- var _a;
4072
- if (this.tabs.find((tab) => tab.value.panel.id === panel.id)) {
4291
+ onDrop(event) {
4292
+ const data = getPaneData();
4293
+ if (!data || data.viewId !== this.accessor.id) {
4294
+ // if there is no local drag event for this panel
4295
+ // or if the drag event was creating by another Paneview instance
4296
+ this._onDidDrop.fire(Object.assign(Object.assign({}, event), { panel: this, api: new PaneviewApi(this.accessor), getData: getPaneData }));
4073
4297
  return;
4074
4298
  }
4075
- const tab = new Tab(panel, this.accessor, this.group);
4076
- if (!((_a = panel.view) === null || _a === void 0 ? void 0 : _a.tab)) {
4077
- throw new Error('invalid header component');
4299
+ const containerApi = this._params
4300
+ .containerApi;
4301
+ const panelId = data.paneId;
4302
+ const existingPanel = containerApi.getPanel(panelId);
4303
+ if (!existingPanel) {
4304
+ // if the panel doesn't exist
4305
+ this._onDidDrop.fire(Object.assign(Object.assign({}, event), { panel: this, getData: getPaneData, api: new PaneviewApi(this.accessor) }));
4306
+ return;
4078
4307
  }
4079
- tab.setContent(panel.view.tab);
4080
- const disposable = new CompositeDisposable(tab.onDragStart((event) => {
4081
- this._onTabDragStart.fire({ nativeEvent: event, panel });
4082
- }), tab.onChanged((event) => {
4083
- const isFloatingGroupsEnabled = !this.accessor.options.disableFloatingGroups;
4084
- const isFloatingWithOnePanel = this.group.api.location.type === 'floating' &&
4085
- this.size === 1;
4086
- if (isFloatingGroupsEnabled &&
4087
- !isFloatingWithOnePanel &&
4088
- event.shiftKey) {
4089
- event.preventDefault();
4090
- const panel = this.accessor.getGroupPanel(tab.panel.id);
4091
- const { top, left } = tab.element.getBoundingClientRect();
4092
- const { top: rootTop, left: rootLeft } = this.accessor.element.getBoundingClientRect();
4093
- this.accessor.addFloatingGroup(panel, {
4094
- x: left - rootLeft,
4095
- y: top - rootTop,
4096
- }, { inDragMode: true });
4097
- return;
4098
- }
4099
- const isLeftClick = event.button === 0;
4100
- if (!isLeftClick || event.defaultPrevented) {
4101
- return;
4308
+ const allPanels = containerApi.panels;
4309
+ const fromIndex = allPanels.indexOf(existingPanel);
4310
+ let toIndex = containerApi.panels.indexOf(this);
4311
+ if (event.position === 'left' || event.position === 'top') {
4312
+ toIndex = Math.max(0, toIndex - 1);
4313
+ }
4314
+ if (event.position === 'right' || event.position === 'bottom') {
4315
+ if (fromIndex > toIndex) {
4316
+ toIndex++;
4102
4317
  }
4103
- if (this.group.activePanel !== panel) {
4104
- this.group.model.openPanel(panel);
4105
- }
4106
- }), tab.onDrop((event) => {
4107
- this._onDrop.fire({
4108
- event: event.nativeEvent,
4109
- index: this.tabs.findIndex((x) => x.value === tab),
4110
- });
4111
- }), tab.onWillShowOverlay((event) => {
4112
- this._onWillShowOverlay.fire(new WillShowOverlayLocationEvent(event, {
4113
- kind: 'tab',
4114
- panel: this.group.activePanel,
4115
- api: this.accessor.api,
4116
- group: this.group,
4117
- getData: getPanelData,
4118
- }));
4119
- }));
4120
- const value = { value: tab, disposable };
4121
- this.addTab(value, index);
4122
- }
4123
- closePanel(panel) {
4124
- this.delete(panel.id);
4125
- }
4126
- dispose() {
4127
- super.dispose();
4128
- for (const { value, disposable } of this.tabs) {
4129
- disposable.dispose();
4130
- value.dispose();
4318
+ toIndex = Math.min(allPanels.length - 1, toIndex);
4131
4319
  }
4132
- this.tabs = [];
4320
+ containerApi.movePanel(fromIndex, toIndex);
4133
4321
  }
4134
4322
  }
4135
4323
 
4136
- class DockviewDidDropEvent extends DockviewEvent {
4137
- get nativeEvent() {
4138
- return this.options.nativeEvent;
4324
+ class ContentContainer extends CompositeDisposable {
4325
+ get element() {
4326
+ return this._element;
4139
4327
  }
4140
- get position() {
4141
- return this.options.position;
4328
+ constructor(accessor, group) {
4329
+ super();
4330
+ this.accessor = accessor;
4331
+ this.group = group;
4332
+ this.disposable = new MutableDisposable();
4333
+ this._onDidFocus = new Emitter();
4334
+ this.onDidFocus = this._onDidFocus.event;
4335
+ this._onDidBlur = new Emitter();
4336
+ this.onDidBlur = this._onDidBlur.event;
4337
+ this._element = document.createElement('div');
4338
+ this._element.className = 'content-container';
4339
+ this._element.tabIndex = -1;
4340
+ this.addDisposables(this._onDidFocus, this._onDidBlur);
4341
+ this.dropTarget = new Droptarget(this.element, {
4342
+ acceptedTargetZones: ['top', 'bottom', 'left', 'right', 'center'],
4343
+ canDisplayOverlay: (event, position) => {
4344
+ if (this.group.locked === 'no-drop-target' ||
4345
+ (this.group.locked && position === 'center')) {
4346
+ return false;
4347
+ }
4348
+ const data = getPanelData();
4349
+ if (!data &&
4350
+ event.shiftKey &&
4351
+ this.group.location.type !== 'floating') {
4352
+ return false;
4353
+ }
4354
+ if (data && data.viewId === this.accessor.id) {
4355
+ if (data.groupId === this.group.id) {
4356
+ if (position === 'center') {
4357
+ // don't allow to drop on self for center position
4358
+ return false;
4359
+ }
4360
+ if (data.panelId === null) {
4361
+ // don't allow group move to drop anywhere on self
4362
+ return false;
4363
+ }
4364
+ }
4365
+ const groupHasOnePanelAndIsActiveDragElement = this.group.panels.length === 1 &&
4366
+ data.groupId === this.group.id;
4367
+ return !groupHasOnePanelAndIsActiveDragElement;
4368
+ }
4369
+ return this.group.canDisplayOverlay(event, position, 'content');
4370
+ },
4371
+ });
4372
+ this.addDisposables(this.dropTarget);
4142
4373
  }
4143
- get panel() {
4144
- return this.options.panel;
4374
+ show() {
4375
+ this.element.style.display = '';
4145
4376
  }
4146
- get group() {
4147
- return this.options.group;
4377
+ hide() {
4378
+ this.element.style.display = 'none';
4148
4379
  }
4149
- get api() {
4150
- return this.options.api;
4380
+ renderPanel(panel, options = { asActive: true }) {
4381
+ const doRender = options.asActive ||
4382
+ (this.panel && this.group.isPanelActive(this.panel));
4383
+ if (this.panel &&
4384
+ this.panel.view.content.element.parentElement === this._element) {
4385
+ /**
4386
+ * If the currently attached panel is mounted directly to the content then remove it
4387
+ */
4388
+ this._element.removeChild(this.panel.view.content.element);
4389
+ }
4390
+ this.panel = panel;
4391
+ let container;
4392
+ switch (panel.api.renderer) {
4393
+ case 'onlyWhenVisible':
4394
+ this.group.renderContainer.detatch(panel);
4395
+ if (this.panel) {
4396
+ if (doRender) {
4397
+ this._element.appendChild(this.panel.view.content.element);
4398
+ }
4399
+ }
4400
+ container = this._element;
4401
+ break;
4402
+ case 'always':
4403
+ if (panel.view.content.element.parentElement === this._element) {
4404
+ this._element.removeChild(panel.view.content.element);
4405
+ }
4406
+ container = this.group.renderContainer.attach({
4407
+ panel,
4408
+ referenceContainer: this,
4409
+ });
4410
+ break;
4411
+ }
4412
+ if (doRender) {
4413
+ const focusTracker = trackFocus(container);
4414
+ const disposable = new CompositeDisposable();
4415
+ disposable.addDisposables(focusTracker, focusTracker.onDidFocus(() => this._onDidFocus.fire()), focusTracker.onDidBlur(() => this._onDidBlur.fire()));
4416
+ this.disposable.value = disposable;
4417
+ }
4151
4418
  }
4152
- constructor(options) {
4153
- super();
4154
- this.options = options;
4419
+ openPanel(panel) {
4420
+ if (this.panel === panel) {
4421
+ return;
4422
+ }
4423
+ this.renderPanel(panel);
4155
4424
  }
4156
- getData() {
4157
- return this.options.getData();
4425
+ layout(_width, _height) {
4426
+ // noop
4158
4427
  }
4159
- }
4160
- class DockviewWillDropEvent extends DockviewDidDropEvent {
4161
- get kind() {
4162
- return this._kind;
4428
+ closePanel() {
4429
+ var _a;
4430
+ if (this.panel) {
4431
+ if (this.panel.api.renderer === 'onlyWhenVisible') {
4432
+ (_a = this.panel.view.content.element.parentElement) === null || _a === void 0 ? void 0 : _a.removeChild(this.panel.view.content.element);
4433
+ }
4434
+ }
4435
+ this.panel = undefined;
4163
4436
  }
4164
- constructor(options) {
4165
- super(options);
4166
- this._kind = options.kind;
4437
+ dispose() {
4438
+ this.disposable.dispose();
4439
+ super.dispose();
4167
4440
  }
4168
4441
  }
4169
- class WillShowOverlayLocationEvent {
4170
- get kind() {
4171
- return this.options.kind;
4172
- }
4173
- get nativeEvent() {
4174
- return this.event.nativeEvent;
4442
+
4443
+ class TabDragHandler extends DragHandler {
4444
+ constructor(element, accessor, group, panel) {
4445
+ super(element);
4446
+ this.accessor = accessor;
4447
+ this.group = group;
4448
+ this.panel = panel;
4449
+ this.panelTransfer = LocalSelectionTransfer.getInstance();
4175
4450
  }
4176
- get position() {
4177
- return this.event.position;
4451
+ getData(event) {
4452
+ this.panelTransfer.setData([new PanelTransfer(this.accessor.id, this.group.id, this.panel.id)], PanelTransfer.prototype);
4453
+ return {
4454
+ dispose: () => {
4455
+ this.panelTransfer.clearData(PanelTransfer.prototype);
4456
+ },
4457
+ };
4178
4458
  }
4179
- get defaultPrevented() {
4180
- return this.event.defaultPrevented;
4459
+ }
4460
+ class Tab extends CompositeDisposable {
4461
+ get element() {
4462
+ return this._element;
4181
4463
  }
4182
- get panel() {
4183
- return this.options.panel;
4464
+ constructor(panel, accessor, group) {
4465
+ super();
4466
+ this.panel = panel;
4467
+ this.accessor = accessor;
4468
+ this.group = group;
4469
+ this.content = undefined;
4470
+ this._onChanged = new Emitter();
4471
+ this.onChanged = this._onChanged.event;
4472
+ this._onDropped = new Emitter();
4473
+ this.onDrop = this._onDropped.event;
4474
+ this._onDragStart = new Emitter();
4475
+ this.onDragStart = this._onDragStart.event;
4476
+ this._element = document.createElement('div');
4477
+ this._element.className = 'tab';
4478
+ this._element.tabIndex = 0;
4479
+ this._element.draggable = true;
4480
+ toggleClass(this.element, 'inactive-tab', true);
4481
+ const dragHandler = new TabDragHandler(this._element, this.accessor, this.group, this.panel);
4482
+ this.dropTarget = new Droptarget(this._element, {
4483
+ acceptedTargetZones: ['center'],
4484
+ canDisplayOverlay: (event, position) => {
4485
+ if (this.group.locked) {
4486
+ return false;
4487
+ }
4488
+ const data = getPanelData();
4489
+ if (data && this.accessor.id === data.viewId) {
4490
+ if (data.panelId === null &&
4491
+ data.groupId === this.group.id) {
4492
+ // don't allow group move to drop on self
4493
+ return false;
4494
+ }
4495
+ return this.panel.id !== data.panelId;
4496
+ }
4497
+ return this.group.model.canDisplayOverlay(event, position, 'tab');
4498
+ },
4499
+ });
4500
+ this.onWillShowOverlay = this.dropTarget.onWillShowOverlay;
4501
+ this.addDisposables(this._onChanged, this._onDropped, this._onDragStart, dragHandler.onDragStart((event) => {
4502
+ this._onDragStart.fire(event);
4503
+ }), dragHandler, addDisposableListener(this._element, 'mousedown', (event) => {
4504
+ if (event.defaultPrevented) {
4505
+ return;
4506
+ }
4507
+ this._onChanged.fire(event);
4508
+ }), this.dropTarget.onDrop((event) => {
4509
+ this._onDropped.fire(event);
4510
+ }), this.dropTarget);
4184
4511
  }
4185
- get api() {
4186
- return this.options.api;
4512
+ setActive(isActive) {
4513
+ toggleClass(this.element, 'active-tab', isActive);
4514
+ toggleClass(this.element, 'inactive-tab', !isActive);
4187
4515
  }
4188
- get group() {
4189
- return this.options.group;
4516
+ setContent(part) {
4517
+ if (this.content) {
4518
+ this._element.removeChild(this.content.element);
4519
+ }
4520
+ this.content = part;
4521
+ this._element.appendChild(this.content.element);
4190
4522
  }
4191
- preventDefault() {
4192
- this.event.preventDefault();
4193
- }
4194
- getData() {
4195
- return this.options.getData();
4196
- }
4197
- constructor(event, options) {
4198
- this.event = event;
4199
- this.options = options;
4523
+ dispose() {
4524
+ super.dispose();
4200
4525
  }
4201
4526
  }
4202
- class DockviewGroupPanelModel extends CompositeDisposable {
4203
- get element() {
4204
- throw new Error('not supported');
4205
- }
4206
- get activePanel() {
4207
- return this._activePanel;
4208
- }
4209
- get locked() {
4210
- return this._locked;
4211
- }
4212
- set locked(value) {
4213
- this._locked = value;
4214
- toggleClass(this.container, 'locked-groupview', value === 'no-drop-target' || value);
4215
- }
4216
- get isActive() {
4217
- return this._isGroupActive;
4218
- }
4219
- get panels() {
4220
- return this._panels;
4221
- }
4222
- get size() {
4223
- return this._panels.length;
4224
- }
4225
- get isEmpty() {
4226
- return this._panels.length === 0;
4227
- }
4228
- get hasWatermark() {
4229
- return !!(this.watermark && this.container.contains(this.watermark.element));
4230
- }
4231
- get header() {
4232
- return this.tabsContainer;
4527
+
4528
+ function addGhostImage(dataTransfer, ghostElement) {
4529
+ // class dockview provides to force ghost image to be drawn on a different layer and prevent weird rendering issues
4530
+ addClasses(ghostElement, 'dv-dragged');
4531
+ document.body.appendChild(ghostElement);
4532
+ dataTransfer.setDragImage(ghostElement, 0, 0);
4533
+ setTimeout(() => {
4534
+ removeClasses(ghostElement, 'dv-dragged');
4535
+ ghostElement.remove();
4536
+ }, 0);
4537
+ }
4538
+
4539
+ class GroupDragHandler extends DragHandler {
4540
+ constructor(element, accessor, group) {
4541
+ super(element);
4542
+ this.accessor = accessor;
4543
+ this.group = group;
4544
+ this.panelTransfer = LocalSelectionTransfer.getInstance();
4545
+ this.addDisposables(addDisposableListener(element, 'mousedown', (e) => {
4546
+ if (e.shiftKey) {
4547
+ /**
4548
+ * You cannot call e.preventDefault() because that will prevent drag events from firing
4549
+ * but we also need to stop any group overlay drag events from occuring
4550
+ * Use a custom event marker that can be checked by the overlay drag events
4551
+ */
4552
+ quasiPreventDefault(e);
4553
+ }
4554
+ }, true));
4233
4555
  }
4234
- get isContentFocused() {
4235
- if (!document.activeElement) {
4236
- return false;
4556
+ isCancelled(_event) {
4557
+ if (this.group.api.location.type === 'floating' && !_event.shiftKey) {
4558
+ return true;
4237
4559
  }
4238
- return isAncestor(document.activeElement, this.contentContainer.element);
4239
- }
4240
- get location() {
4241
- return this._location;
4560
+ return false;
4242
4561
  }
4243
- set location(value) {
4244
- this._location = value;
4245
- toggleClass(this.container, 'dv-groupview-floating', false);
4246
- toggleClass(this.container, 'dv-groupview-popout', false);
4247
- switch (value.type) {
4248
- case 'grid':
4249
- this.contentContainer.dropTarget.setTargetZones([
4250
- 'top',
4251
- 'bottom',
4252
- 'left',
4253
- 'right',
4254
- 'center',
4255
- ]);
4256
- break;
4257
- case 'floating':
4258
- this.contentContainer.dropTarget.setTargetZones(['center']);
4259
- this.contentContainer.dropTarget.setTargetZones(value
4260
- ? ['center']
4261
- : ['top', 'bottom', 'left', 'right', 'center']);
4262
- toggleClass(this.container, 'dv-groupview-floating', true);
4263
- break;
4264
- case 'popout':
4265
- this.contentContainer.dropTarget.setTargetZones(['center']);
4266
- toggleClass(this.container, 'dv-groupview-popout', true);
4267
- break;
4562
+ getData(dragEvent) {
4563
+ const dataTransfer = dragEvent.dataTransfer;
4564
+ this.panelTransfer.setData([new PanelTransfer(this.accessor.id, this.group.id, null)], PanelTransfer.prototype);
4565
+ const style = window.getComputedStyle(this.el);
4566
+ const bgColor = style.getPropertyValue('--dv-activegroup-visiblepanel-tab-background-color');
4567
+ const color = style.getPropertyValue('--dv-activegroup-visiblepanel-tab-color');
4568
+ if (dataTransfer) {
4569
+ const ghostElement = document.createElement('div');
4570
+ ghostElement.style.backgroundColor = bgColor;
4571
+ ghostElement.style.color = color;
4572
+ ghostElement.style.padding = '2px 8px';
4573
+ ghostElement.style.height = '24px';
4574
+ ghostElement.style.fontSize = '11px';
4575
+ ghostElement.style.lineHeight = '20px';
4576
+ ghostElement.style.borderRadius = '12px';
4577
+ ghostElement.style.position = 'absolute';
4578
+ ghostElement.textContent = `Multiple Panels (${this.group.size})`;
4579
+ addGhostImage(dataTransfer, ghostElement);
4268
4580
  }
4269
- this.groupPanel.api._onDidLocationChange.fire({
4270
- location: this.location,
4271
- });
4581
+ return {
4582
+ dispose: () => {
4583
+ this.panelTransfer.clearData(PanelTransfer.prototype);
4584
+ },
4585
+ };
4272
4586
  }
4273
- constructor(container, accessor, id, options, groupPanel) {
4274
- var _a;
4587
+ }
4588
+
4589
+ class VoidContainer extends CompositeDisposable {
4590
+ get element() {
4591
+ return this._element;
4592
+ }
4593
+ constructor(accessor, group) {
4275
4594
  super();
4276
- this.container = container;
4277
4595
  this.accessor = accessor;
4278
- this.id = id;
4279
- this.options = options;
4280
- this.groupPanel = groupPanel;
4281
- this._isGroupActive = false;
4282
- this._locked = false;
4283
- this._location = { type: 'grid' };
4284
- this.mostRecentlyUsed = [];
4285
- this._onDidChange = new Emitter();
4286
- this.onDidChange = this._onDidChange.event;
4287
- this._width = 0;
4288
- this._height = 0;
4289
- this._panels = [];
4290
- this._panelDisposables = new Map();
4291
- this._onMove = new Emitter();
4292
- this.onMove = this._onMove.event;
4293
- this._onDidDrop = new Emitter();
4294
- this.onDidDrop = this._onDidDrop.event;
4295
- this._onWillDrop = new Emitter();
4296
- this.onWillDrop = this._onWillDrop.event;
4297
- this._onWillShowOverlay = new Emitter();
4298
- this.onWillShowOverlay = this._onWillShowOverlay.event;
4299
- this._onTabDragStart = new Emitter();
4300
- this.onTabDragStart = this._onTabDragStart.event;
4301
- this._onGroupDragStart = new Emitter();
4302
- this.onGroupDragStart = this._onGroupDragStart.event;
4303
- this._onDidAddPanel = new Emitter();
4304
- this.onDidAddPanel = this._onDidAddPanel.event;
4305
- this._onDidPanelTitleChange = new Emitter();
4306
- this.onDidPanelTitleChange = this._onDidPanelTitleChange.event;
4307
- this._onDidPanelParametersChange = new Emitter();
4308
- this.onDidPanelParametersChange = this._onDidPanelParametersChange.event;
4309
- this._onDidRemovePanel = new Emitter();
4310
- this.onDidRemovePanel = this._onDidRemovePanel.event;
4311
- this._onDidActivePanelChange = new Emitter();
4312
- this.onDidActivePanelChange = this._onDidActivePanelChange.event;
4313
- this._overwriteRenderContainer = null;
4314
- toggleClass(this.container, 'groupview', true);
4315
- this._api = new DockviewApi(this.accessor);
4316
- this.tabsContainer = new TabsContainer(this.accessor, this.groupPanel);
4317
- this.contentContainer = new ContentContainer(this.accessor, this);
4318
- container.append(this.tabsContainer.element, this.contentContainer.element);
4319
- this.header.hidden = !!options.hideHeader;
4320
- this.locked = (_a = options.locked) !== null && _a !== void 0 ? _a : false;
4321
- this.addDisposables(this._onTabDragStart, this._onGroupDragStart, this._onWillShowOverlay, this.tabsContainer.onTabDragStart((event) => {
4322
- this._onTabDragStart.fire(event);
4323
- }), this.tabsContainer.onGroupDragStart((event) => {
4324
- this._onGroupDragStart.fire(event);
4325
- }), this.tabsContainer.onDrop((event) => {
4326
- this.handleDropEvent('header', event.event, 'center', event.index);
4327
- }), this.contentContainer.onDidFocus(() => {
4328
- this.accessor.doSetGroupActive(this.groupPanel);
4329
- }), this.contentContainer.onDidBlur(() => {
4330
- // noop
4331
- }), this.contentContainer.dropTarget.onDrop((event) => {
4332
- this.handleDropEvent('content', event.nativeEvent, event.position);
4333
- }), this.tabsContainer.onWillShowOverlay((event) => {
4334
- this._onWillShowOverlay.fire(event);
4335
- }), this.contentContainer.dropTarget.onWillShowOverlay((event) => {
4336
- this._onWillShowOverlay.fire(new WillShowOverlayLocationEvent(event, {
4337
- kind: 'content',
4338
- panel: this.activePanel,
4339
- api: this._api,
4340
- group: this.groupPanel,
4341
- getData: getPanelData,
4342
- }));
4343
- }), this._onMove, this._onDidChange, this._onDidDrop, this._onWillDrop, this._onDidAddPanel, this._onDidRemovePanel, this._onDidActivePanelChange);
4344
- }
4345
- focusContent() {
4346
- this.contentContainer.element.focus();
4347
- }
4348
- set renderContainer(value) {
4349
- this.panels.forEach((panel) => {
4350
- this.renderContainer.detatch(panel);
4351
- });
4352
- this._overwriteRenderContainer = value;
4353
- this.panels.forEach((panel) => {
4354
- this.rerender(panel);
4596
+ this.group = group;
4597
+ this._onDrop = new Emitter();
4598
+ this.onDrop = this._onDrop.event;
4599
+ this._onDragStart = new Emitter();
4600
+ this.onDragStart = this._onDragStart.event;
4601
+ this._element = document.createElement('div');
4602
+ this._element.className = 'void-container';
4603
+ this._element.tabIndex = 0;
4604
+ this._element.draggable = true;
4605
+ this.addDisposables(this._onDrop, this._onDragStart, addDisposableListener(this._element, 'click', () => {
4606
+ this.accessor.doSetGroupActive(this.group);
4607
+ }));
4608
+ const handler = new GroupDragHandler(this._element, accessor, group);
4609
+ this.dropTraget = new Droptarget(this._element, {
4610
+ acceptedTargetZones: ['center'],
4611
+ canDisplayOverlay: (event, position) => {
4612
+ var _a;
4613
+ const data = getPanelData();
4614
+ if (data && this.accessor.id === data.viewId) {
4615
+ if (data.panelId === null &&
4616
+ data.groupId === this.group.id) {
4617
+ // don't allow group move to drop on self
4618
+ return false;
4619
+ }
4620
+ // don't show the overlay if the tab being dragged is the last panel of this group
4621
+ return ((_a = last(this.group.panels)) === null || _a === void 0 ? void 0 : _a.id) !== data.panelId;
4622
+ }
4623
+ return group.model.canDisplayOverlay(event, position, 'header_space');
4624
+ },
4355
4625
  });
4626
+ this.onWillShowOverlay = this.dropTraget.onWillShowOverlay;
4627
+ this.addDisposables(handler, handler.onDragStart((event) => {
4628
+ this._onDragStart.fire(event);
4629
+ }), this.dropTraget.onDrop((event) => {
4630
+ this._onDrop.fire(event);
4631
+ }), this.dropTraget);
4356
4632
  }
4357
- get renderContainer() {
4358
- var _a;
4359
- return ((_a = this._overwriteRenderContainer) !== null && _a !== void 0 ? _a : this.accessor.overlayRenderContainer);
4633
+ }
4634
+
4635
+ class TabsContainer extends CompositeDisposable {
4636
+ get panels() {
4637
+ return this.tabs.map((_) => _.value.panel.id);
4360
4638
  }
4361
- initialize() {
4362
- if (this.options.panels) {
4363
- this.options.panels.forEach((panel) => {
4364
- this.doAddPanel(panel);
4365
- });
4366
- }
4367
- if (this.options.activePanel) {
4368
- this.openPanel(this.options.activePanel);
4369
- }
4370
- // must be run after the constructor otherwise this.parent may not be
4371
- // correctly initialized
4372
- this.setActive(this.isActive, true);
4373
- this.updateContainer();
4374
- if (this.accessor.options.createRightHeaderActionsElement) {
4375
- this._rightHeaderActions =
4376
- this.accessor.options.createRightHeaderActionsElement(this.groupPanel);
4377
- this.addDisposables(this._rightHeaderActions);
4378
- this._rightHeaderActions.init({
4379
- containerApi: this._api,
4380
- api: this.groupPanel.api,
4381
- });
4382
- this.tabsContainer.setRightActionsElement(this._rightHeaderActions.element);
4383
- }
4384
- if (this.accessor.options.createLeftHeaderActionsElement) {
4385
- this._leftHeaderActions =
4386
- this.accessor.options.createLeftHeaderActionsElement(this.groupPanel);
4387
- this.addDisposables(this._leftHeaderActions);
4388
- this._leftHeaderActions.init({
4389
- containerApi: this._api,
4390
- api: this.groupPanel.api,
4391
- });
4392
- this.tabsContainer.setLeftActionsElement(this._leftHeaderActions.element);
4393
- }
4394
- if (this.accessor.options.createPrefixHeaderActionsElement) {
4395
- this._prefixHeaderActions =
4396
- this.accessor.options.createPrefixHeaderActionsElement(this.groupPanel);
4397
- this.addDisposables(this._prefixHeaderActions);
4398
- this._prefixHeaderActions.init({
4399
- containerApi: this._api,
4400
- api: this.groupPanel.api,
4401
- });
4402
- this.tabsContainer.setPrefixActionsElement(this._prefixHeaderActions.element);
4403
- }
4404
- }
4405
- rerender(panel) {
4406
- this.contentContainer.renderPanel(panel, { asActive: false });
4407
- }
4408
- indexOf(panel) {
4409
- return this.tabsContainer.indexOf(panel.id);
4410
- }
4411
- toJSON() {
4412
- var _a;
4413
- const result = {
4414
- views: this.tabsContainer.panels,
4415
- activeView: (_a = this._activePanel) === null || _a === void 0 ? void 0 : _a.id,
4416
- id: this.id,
4417
- };
4418
- if (this.locked !== false) {
4419
- result.locked = this.locked;
4420
- }
4421
- if (this.header.hidden) {
4422
- result.hideHeader = true;
4423
- }
4424
- return result;
4425
- }
4426
- moveToNext(options) {
4427
- if (!options) {
4428
- options = {};
4429
- }
4430
- if (!options.panel) {
4431
- options.panel = this.activePanel;
4432
- }
4433
- const index = options.panel ? this.panels.indexOf(options.panel) : -1;
4434
- let normalizedIndex;
4435
- if (index < this.panels.length - 1) {
4436
- normalizedIndex = index + 1;
4437
- }
4438
- else if (!options.suppressRoll) {
4439
- normalizedIndex = 0;
4440
- }
4441
- else {
4442
- return;
4443
- }
4444
- this.openPanel(this.panels[normalizedIndex]);
4445
- }
4446
- moveToPrevious(options) {
4447
- if (!options) {
4448
- options = {};
4449
- }
4450
- if (!options.panel) {
4451
- options.panel = this.activePanel;
4452
- }
4453
- if (!options.panel) {
4454
- return;
4455
- }
4456
- const index = this.panels.indexOf(options.panel);
4457
- let normalizedIndex;
4458
- if (index > 0) {
4459
- normalizedIndex = index - 1;
4460
- }
4461
- else if (!options.suppressRoll) {
4462
- normalizedIndex = this.panels.length - 1;
4463
- }
4464
- else {
4465
- return;
4466
- }
4467
- this.openPanel(this.panels[normalizedIndex]);
4468
- }
4469
- containsPanel(panel) {
4470
- return this.panels.includes(panel);
4471
- }
4472
- init(_params) {
4473
- //noop
4474
- }
4475
- update(_params) {
4476
- //noop
4477
- }
4478
- focus() {
4479
- var _a;
4480
- (_a = this._activePanel) === null || _a === void 0 ? void 0 : _a.focus();
4481
- }
4482
- openPanel(panel, options = {}) {
4483
- /**
4484
- * set the panel group
4485
- * add the panel
4486
- * check if group active
4487
- * check if panel active
4488
- */
4489
- if (typeof options.index !== 'number' ||
4490
- options.index > this.panels.length) {
4491
- options.index = this.panels.length;
4492
- }
4493
- const skipSetActive = !!options.skipSetActive;
4494
- // ensure the group is updated before we fire any events
4495
- panel.updateParentGroup(this.groupPanel, {
4496
- skipSetActive: options.skipSetActive,
4497
- });
4498
- this.doAddPanel(panel, options.index, {
4499
- skipSetActive: skipSetActive,
4500
- });
4501
- if (this._activePanel === panel) {
4502
- this.contentContainer.renderPanel(panel, { asActive: true });
4503
- return;
4504
- }
4505
- if (!skipSetActive) {
4506
- this.doSetActivePanel(panel);
4507
- }
4508
- if (!options.skipSetGroupActive) {
4509
- this.accessor.doSetGroupActive(this.groupPanel);
4510
- }
4511
- if (!options.skipSetActive) {
4512
- this.updateContainer();
4513
- }
4514
- }
4515
- removePanel(groupItemOrId, options = {
4516
- skipSetActive: false,
4517
- }) {
4518
- const id = typeof groupItemOrId === 'string'
4519
- ? groupItemOrId
4520
- : groupItemOrId.id;
4521
- const panelToRemove = this._panels.find((panel) => panel.id === id);
4522
- if (!panelToRemove) {
4523
- throw new Error('invalid operation');
4524
- }
4525
- return this._removePanel(panelToRemove, options);
4526
- }
4527
- closeAllPanels() {
4528
- if (this.panels.length > 0) {
4529
- // take a copy since we will be edting the array as we iterate through
4530
- const arrPanelCpy = [...this.panels];
4531
- for (const panel of arrPanelCpy) {
4532
- this.doClose(panel);
4533
- }
4534
- }
4535
- else {
4536
- this.accessor.removeGroup(this.groupPanel);
4537
- }
4538
- }
4539
- closePanel(panel) {
4540
- this.doClose(panel);
4541
- }
4542
- doClose(panel) {
4543
- this.accessor.removePanel(panel);
4544
- }
4545
- isPanelActive(panel) {
4546
- return this._activePanel === panel;
4547
- }
4548
- updateActions(element) {
4549
- this.tabsContainer.setRightActionsElement(element);
4550
- }
4551
- setActive(isGroupActive, force = false) {
4552
- if (!force && this.isActive === isGroupActive) {
4553
- return;
4554
- }
4555
- this._isGroupActive = isGroupActive;
4556
- toggleClass(this.container, 'active-group', isGroupActive);
4557
- toggleClass(this.container, 'inactive-group', !isGroupActive);
4558
- this.tabsContainer.setActive(this.isActive);
4559
- if (!this._activePanel && this.panels.length > 0) {
4560
- this.doSetActivePanel(this.panels[0]);
4561
- }
4562
- this.updateContainer();
4563
- }
4564
- layout(width, height) {
4565
- var _a;
4566
- this._width = width;
4567
- this._height = height;
4568
- this.contentContainer.layout(this._width, this._height);
4569
- if ((_a = this._activePanel) === null || _a === void 0 ? void 0 : _a.layout) {
4570
- this._activePanel.layout(this._width, this._height);
4571
- }
4572
- }
4573
- _removePanel(panel, options) {
4574
- const isActivePanel = this._activePanel === panel;
4575
- this.doRemovePanel(panel);
4576
- if (isActivePanel && this.panels.length > 0) {
4577
- const nextPanel = this.mostRecentlyUsed[0];
4578
- this.openPanel(nextPanel, {
4579
- skipSetActive: options.skipSetActive,
4580
- skipSetGroupActive: options.skipSetActiveGroup,
4581
- });
4582
- }
4583
- if (this._activePanel && this.panels.length === 0) {
4584
- this.doSetActivePanel(undefined);
4585
- }
4586
- if (!options.skipSetActive) {
4587
- this.updateContainer();
4588
- }
4589
- return panel;
4590
- }
4591
- doRemovePanel(panel) {
4592
- const index = this.panels.indexOf(panel);
4593
- if (this._activePanel === panel) {
4594
- this.contentContainer.closePanel();
4595
- }
4596
- this.tabsContainer.delete(panel.id);
4597
- this._panels.splice(index, 1);
4598
- if (this.mostRecentlyUsed.includes(panel)) {
4599
- this.mostRecentlyUsed.splice(this.mostRecentlyUsed.indexOf(panel), 1);
4600
- }
4601
- const disposable = this._panelDisposables.get(panel.id);
4602
- if (disposable) {
4603
- disposable.dispose();
4604
- this._panelDisposables.delete(panel.id);
4605
- }
4606
- this._onDidRemovePanel.fire({ panel });
4607
- }
4608
- doAddPanel(panel, index = this.panels.length, options = { skipSetActive: false }) {
4609
- const existingPanel = this._panels.indexOf(panel);
4610
- const hasExistingPanel = existingPanel > -1;
4611
- this.tabsContainer.show();
4612
- this.contentContainer.show();
4613
- this.tabsContainer.openPanel(panel, index);
4614
- if (!options.skipSetActive) {
4615
- this.contentContainer.openPanel(panel);
4616
- }
4617
- if (hasExistingPanel) {
4618
- // TODO - need to ensure ordering hasn't changed and if it has need to re-order this.panels
4619
- return;
4620
- }
4621
- this.updateMru(panel);
4622
- this.panels.splice(index, 0, panel);
4623
- this._panelDisposables.set(panel.id, new CompositeDisposable(panel.api.onDidTitleChange((event) => this._onDidPanelTitleChange.fire(event)), panel.api.onDidParametersChange((event) => this._onDidPanelParametersChange.fire(event))));
4624
- this._onDidAddPanel.fire({ panel });
4625
- }
4626
- doSetActivePanel(panel) {
4627
- if (this._activePanel === panel) {
4628
- return;
4629
- }
4630
- this._activePanel = panel;
4631
- if (panel) {
4632
- this.tabsContainer.setActivePanel(panel);
4633
- panel.layout(this._width, this._height);
4634
- this.updateMru(panel);
4635
- this._onDidActivePanelChange.fire({
4636
- panel,
4637
- });
4638
- }
4639
- }
4640
- updateMru(panel) {
4641
- if (this.mostRecentlyUsed.includes(panel)) {
4642
- this.mostRecentlyUsed.splice(this.mostRecentlyUsed.indexOf(panel), 1);
4643
- }
4644
- this.mostRecentlyUsed = [panel, ...this.mostRecentlyUsed];
4645
- }
4646
- updateContainer() {
4647
- var _a, _b;
4648
- toggleClass(this.container, 'empty', this.isEmpty);
4649
- this.panels.forEach((panel) => panel.runEvents());
4650
- if (this.isEmpty && !this.watermark) {
4651
- const watermark = this.accessor.createWatermarkComponent();
4652
- watermark.init({
4653
- containerApi: this._api,
4654
- group: this.groupPanel,
4655
- });
4656
- this.watermark = watermark;
4657
- addDisposableListener(this.watermark.element, 'click', () => {
4658
- if (!this.isActive) {
4659
- this.accessor.doSetGroupActive(this.groupPanel);
4660
- }
4661
- });
4662
- this.tabsContainer.hide();
4663
- this.contentContainer.element.appendChild(this.watermark.element);
4664
- this.watermark.updateParentGroup(this.groupPanel, true);
4665
- }
4666
- if (!this.isEmpty && this.watermark) {
4667
- this.watermark.element.remove();
4668
- (_b = (_a = this.watermark).dispose) === null || _b === void 0 ? void 0 : _b.call(_a);
4669
- this.watermark = undefined;
4670
- this.tabsContainer.show();
4671
- }
4639
+ get size() {
4640
+ return this.tabs.length;
4672
4641
  }
4673
- canDisplayOverlay(event, position, target) {
4674
- // custom overlay handler
4675
- if (this.accessor.options.showDndOverlay) {
4676
- return this.accessor.options.showDndOverlay({
4677
- nativeEvent: event,
4678
- target,
4679
- group: this.accessor.getPanel(this.id),
4680
- position,
4681
- getData: getPanelData,
4682
- });
4683
- }
4684
- return false;
4642
+ get hidden() {
4643
+ return this._hidden;
4685
4644
  }
4686
- handleDropEvent(type, event, position, index) {
4687
- if (this.locked === 'no-drop-target') {
4688
- return;
4689
- }
4690
- function getKind() {
4691
- switch (type) {
4692
- case 'header':
4693
- return typeof index === 'number' ? 'tab' : 'header_space';
4694
- case 'content':
4695
- return 'content';
4696
- }
4697
- }
4698
- const panel = typeof index === 'number' ? this.panels[index] : undefined;
4699
- const willDropEvent = new DockviewWillDropEvent({
4700
- nativeEvent: event,
4701
- position,
4702
- panel,
4703
- getData: () => getPanelData(),
4704
- kind: getKind(),
4705
- group: this.groupPanel,
4706
- api: this._api,
4707
- });
4708
- this._onWillDrop.fire(willDropEvent);
4709
- if (willDropEvent.defaultPrevented) {
4710
- return;
4711
- }
4712
- const data = getPanelData();
4713
- if (data && data.viewId === this.accessor.id) {
4714
- if (data.panelId === null) {
4715
- // this is a group move dnd event
4716
- const { groupId } = data;
4717
- this._onMove.fire({
4718
- target: position,
4719
- groupId: groupId,
4720
- index,
4721
- });
4722
- return;
4723
- }
4724
- const fromSameGroup = this.tabsContainer.indexOf(data.panelId) !== -1;
4725
- if (fromSameGroup && this.tabsContainer.size === 1) {
4726
- return;
4727
- }
4728
- const { groupId, panelId } = data;
4729
- const isSameGroup = this.id === groupId;
4730
- if (isSameGroup && !position) {
4731
- const oldIndex = this.tabsContainer.indexOf(panelId);
4732
- if (oldIndex === index) {
4733
- return;
4734
- }
4735
- }
4736
- this._onMove.fire({
4737
- target: position,
4738
- groupId: data.groupId,
4739
- itemId: data.panelId,
4740
- index,
4741
- });
4645
+ set hidden(value) {
4646
+ this._hidden = value;
4647
+ this.element.style.display = value ? 'none' : '';
4648
+ }
4649
+ show() {
4650
+ if (!this.hidden) {
4651
+ this.element.style.display = '';
4742
4652
  }
4743
- else {
4744
- this._onDidDrop.fire(new DockviewDidDropEvent({
4745
- nativeEvent: event,
4746
- position,
4747
- panel,
4748
- getData: () => getPanelData(),
4749
- group: this.groupPanel,
4750
- api: this._api,
4751
- }));
4653
+ }
4654
+ hide() {
4655
+ this._element.style.display = 'none';
4656
+ }
4657
+ setRightActionsElement(element) {
4658
+ if (this.rightActions === element) {
4659
+ return;
4660
+ }
4661
+ if (this.rightActions) {
4662
+ this.rightActions.remove();
4663
+ this.rightActions = undefined;
4664
+ }
4665
+ if (element) {
4666
+ this.rightActionsContainer.appendChild(element);
4667
+ this.rightActions = element;
4752
4668
  }
4753
4669
  }
4754
- dispose() {
4755
- var _a, _b, _c;
4756
- super.dispose();
4757
- (_a = this.watermark) === null || _a === void 0 ? void 0 : _a.element.remove();
4758
- (_c = (_b = this.watermark) === null || _b === void 0 ? void 0 : _b.dispose) === null || _c === void 0 ? void 0 : _c.call(_b);
4759
- this.watermark = undefined;
4760
- for (const panel of this.panels) {
4761
- panel.dispose();
4670
+ setLeftActionsElement(element) {
4671
+ if (this.leftActions === element) {
4672
+ return;
4673
+ }
4674
+ if (this.leftActions) {
4675
+ this.leftActions.remove();
4676
+ this.leftActions = undefined;
4677
+ }
4678
+ if (element) {
4679
+ this.leftActionsContainer.appendChild(element);
4680
+ this.leftActions = element;
4681
+ }
4682
+ }
4683
+ setPrefixActionsElement(element) {
4684
+ if (this.preActions === element) {
4685
+ return;
4686
+ }
4687
+ if (this.preActions) {
4688
+ this.preActions.remove();
4689
+ this.preActions = undefined;
4690
+ }
4691
+ if (element) {
4692
+ this.preActionsContainer.appendChild(element);
4693
+ this.preActions = element;
4762
4694
  }
4763
- this.tabsContainer.dispose();
4764
- this.contentContainer.dispose();
4765
4695
  }
4766
- }
4767
-
4768
- class Resizable extends CompositeDisposable {
4769
4696
  get element() {
4770
4697
  return this._element;
4771
4698
  }
4772
- get disableResizing() {
4773
- return this._disableResizing;
4699
+ isActive(tab) {
4700
+ return (this.selectedIndex > -1 &&
4701
+ this.tabs[this.selectedIndex].value === tab);
4774
4702
  }
4775
- set disableResizing(value) {
4776
- this._disableResizing = value;
4703
+ indexOf(id) {
4704
+ return this.tabs.findIndex((tab) => tab.value.panel.id === id);
4777
4705
  }
4778
- constructor(parentElement, disableResizing = false) {
4706
+ constructor(accessor, group) {
4779
4707
  super();
4780
- this._disableResizing = disableResizing;
4781
- this._element = parentElement;
4782
- this.addDisposables(watchElementResize(this._element, (entry) => {
4783
- if (this.isDisposed) {
4784
- /**
4785
- * resize is delayed through requestAnimationFrame so there is a small chance
4786
- * the component has already been disposed of
4787
- */
4788
- return;
4708
+ this.accessor = accessor;
4709
+ this.group = group;
4710
+ this.tabs = [];
4711
+ this.selectedIndex = -1;
4712
+ this._hidden = false;
4713
+ this._onDrop = new Emitter();
4714
+ this.onDrop = this._onDrop.event;
4715
+ this._onTabDragStart = new Emitter();
4716
+ this.onTabDragStart = this._onTabDragStart.event;
4717
+ this._onGroupDragStart = new Emitter();
4718
+ this.onGroupDragStart = this._onGroupDragStart.event;
4719
+ this._onWillShowOverlay = new Emitter();
4720
+ this.onWillShowOverlay = this._onWillShowOverlay.event;
4721
+ this._element = document.createElement('div');
4722
+ this._element.className = 'tabs-and-actions-container';
4723
+ toggleClass(this._element, 'dv-full-width-single-tab', this.accessor.options.singleTabMode === 'fullwidth');
4724
+ this.rightActionsContainer = document.createElement('div');
4725
+ this.rightActionsContainer.className = 'right-actions-container';
4726
+ this.leftActionsContainer = document.createElement('div');
4727
+ this.leftActionsContainer.className = 'left-actions-container';
4728
+ this.preActionsContainer = document.createElement('div');
4729
+ this.preActionsContainer.className = 'pre-actions-container';
4730
+ this.tabContainer = document.createElement('div');
4731
+ this.tabContainer.className = 'tabs-container';
4732
+ this.voidContainer = new VoidContainer(this.accessor, this.group);
4733
+ this._element.appendChild(this.preActionsContainer);
4734
+ this._element.appendChild(this.tabContainer);
4735
+ this._element.appendChild(this.leftActionsContainer);
4736
+ this._element.appendChild(this.voidContainer.element);
4737
+ this._element.appendChild(this.rightActionsContainer);
4738
+ this.addDisposables(this.accessor.onDidAddPanel((e) => {
4739
+ if (e.api.group === this.group) {
4740
+ toggleClass(this._element, 'dv-single-tab', this.size === 1);
4789
4741
  }
4790
- if (this.disableResizing) {
4742
+ }), this.accessor.onDidRemovePanel((e) => {
4743
+ if (e.api.group === this.group) {
4744
+ toggleClass(this._element, 'dv-single-tab', this.size === 1);
4745
+ }
4746
+ }), this._onWillShowOverlay, this._onDrop, this._onTabDragStart, this._onGroupDragStart, this.voidContainer, this.voidContainer.onDragStart((event) => {
4747
+ this._onGroupDragStart.fire({
4748
+ nativeEvent: event,
4749
+ group: this.group,
4750
+ });
4751
+ }), this.voidContainer.onDrop((event) => {
4752
+ this._onDrop.fire({
4753
+ event: event.nativeEvent,
4754
+ index: this.tabs.length,
4755
+ });
4756
+ }), this.voidContainer.onWillShowOverlay((event) => {
4757
+ this._onWillShowOverlay.fire(new WillShowOverlayLocationEvent(event, {
4758
+ kind: 'header_space',
4759
+ panel: this.group.activePanel,
4760
+ api: this.accessor.api,
4761
+ group: this.group,
4762
+ getData: getPanelData,
4763
+ }));
4764
+ }), addDisposableListener(this.voidContainer.element, 'mousedown', (event) => {
4765
+ const isFloatingGroupsEnabled = !this.accessor.options.disableFloatingGroups;
4766
+ if (isFloatingGroupsEnabled &&
4767
+ event.shiftKey &&
4768
+ this.group.api.location.type !== 'floating') {
4769
+ event.preventDefault();
4770
+ const { top, left } = this.element.getBoundingClientRect();
4771
+ const { top: rootTop, left: rootLeft } = this.accessor.element.getBoundingClientRect();
4772
+ this.accessor.addFloatingGroup(this.group, {
4773
+ x: left - rootLeft + 20,
4774
+ y: top - rootTop + 20,
4775
+ }, { inDragMode: true });
4776
+ }
4777
+ }), addDisposableListener(this.tabContainer, 'mousedown', (event) => {
4778
+ if (event.defaultPrevented) {
4791
4779
  return;
4792
4780
  }
4793
- if (!this._element.offsetParent) {
4794
- /**
4795
- * offsetParent === null is equivalent to display: none being set on the element or one
4796
- * of it's parents. In the display: none case the size will become (0, 0) which we do
4797
- * not want to propagate.
4798
- *
4799
- * @see https://developer.mozilla.org/en-US/docs/Web/API/HTMLElement/offsetParent
4800
- *
4801
- * You could use checkVisibility() but at the time of writing it's not supported across
4802
- * all Browsers
4803
- *
4804
- * @see https://developer.mozilla.org/en-US/docs/Web/API/Element/checkVisibility
4805
- */
4781
+ const isLeftClick = event.button === 0;
4782
+ if (isLeftClick) {
4783
+ this.accessor.doSetGroupActive(this.group);
4784
+ }
4785
+ }));
4786
+ }
4787
+ setActive(_isGroupActive) {
4788
+ // noop
4789
+ }
4790
+ addTab(tab, index = this.tabs.length) {
4791
+ if (index < 0 || index > this.tabs.length) {
4792
+ throw new Error('invalid location');
4793
+ }
4794
+ this.tabContainer.insertBefore(tab.value.element, this.tabContainer.children[index]);
4795
+ this.tabs = [
4796
+ ...this.tabs.slice(0, index),
4797
+ tab,
4798
+ ...this.tabs.slice(index),
4799
+ ];
4800
+ if (this.selectedIndex < 0) {
4801
+ this.selectedIndex = index;
4802
+ }
4803
+ }
4804
+ delete(id) {
4805
+ const index = this.tabs.findIndex((tab) => tab.value.panel.id === id);
4806
+ const tabToRemove = this.tabs.splice(index, 1)[0];
4807
+ const { value, disposable } = tabToRemove;
4808
+ disposable.dispose();
4809
+ value.dispose();
4810
+ value.element.remove();
4811
+ }
4812
+ setActivePanel(panel) {
4813
+ this.tabs.forEach((tab) => {
4814
+ const isActivePanel = panel.id === tab.value.panel.id;
4815
+ tab.value.setActive(isActivePanel);
4816
+ });
4817
+ }
4818
+ openPanel(panel, index = this.tabs.length) {
4819
+ var _a;
4820
+ if (this.tabs.find((tab) => tab.value.panel.id === panel.id)) {
4821
+ return;
4822
+ }
4823
+ const tab = new Tab(panel, this.accessor, this.group);
4824
+ if (!((_a = panel.view) === null || _a === void 0 ? void 0 : _a.tab)) {
4825
+ throw new Error('invalid header component');
4826
+ }
4827
+ tab.setContent(panel.view.tab);
4828
+ const disposable = new CompositeDisposable(tab.onDragStart((event) => {
4829
+ this._onTabDragStart.fire({ nativeEvent: event, panel });
4830
+ }), tab.onChanged((event) => {
4831
+ const isFloatingGroupsEnabled = !this.accessor.options.disableFloatingGroups;
4832
+ const isFloatingWithOnePanel = this.group.api.location.type === 'floating' &&
4833
+ this.size === 1;
4834
+ if (isFloatingGroupsEnabled &&
4835
+ !isFloatingWithOnePanel &&
4836
+ event.shiftKey) {
4837
+ event.preventDefault();
4838
+ const panel = this.accessor.getGroupPanel(tab.panel.id);
4839
+ const { top, left } = tab.element.getBoundingClientRect();
4840
+ const { top: rootTop, left: rootLeft } = this.accessor.element.getBoundingClientRect();
4841
+ this.accessor.addFloatingGroup(panel, {
4842
+ x: left - rootLeft,
4843
+ y: top - rootTop,
4844
+ }, { inDragMode: true });
4806
4845
  return;
4807
4846
  }
4808
- if (!isInDocument(this._element)) {
4809
- /**
4810
- * since the event is dispatched through requestAnimationFrame there is a small chance
4811
- * the component is no longer attached to the DOM, if that is the case the dimensions
4812
- * are mostly likely all zero and meaningless. we should skip this case.
4813
- */
4847
+ const isLeftClick = event.button === 0;
4848
+ if (!isLeftClick || event.defaultPrevented) {
4814
4849
  return;
4815
4850
  }
4816
- const { width, height } = entry.contentRect;
4817
- this.layout(width, height);
4851
+ if (this.group.activePanel !== panel) {
4852
+ this.group.model.openPanel(panel);
4853
+ }
4854
+ }), tab.onDrop((event) => {
4855
+ this._onDrop.fire({
4856
+ event: event.nativeEvent,
4857
+ index: this.tabs.findIndex((x) => x.value === tab),
4858
+ });
4859
+ }), tab.onWillShowOverlay((event) => {
4860
+ this._onWillShowOverlay.fire(new WillShowOverlayLocationEvent(event, {
4861
+ kind: 'tab',
4862
+ panel: this.group.activePanel,
4863
+ api: this.accessor.api,
4864
+ group: this.group,
4865
+ getData: getPanelData,
4866
+ }));
4818
4867
  }));
4868
+ const value = { value: tab, disposable };
4869
+ this.addTab(value, index);
4819
4870
  }
4820
- }
4821
-
4822
- const nextLayoutId$1 = sequentialNumberGenerator();
4823
- function toTarget(direction) {
4824
- switch (direction) {
4825
- case 'left':
4826
- return 'left';
4827
- case 'right':
4828
- return 'right';
4829
- case 'above':
4830
- return 'top';
4831
- case 'below':
4832
- return 'bottom';
4833
- case 'within':
4834
- default:
4835
- return 'center';
4871
+ closePanel(panel) {
4872
+ this.delete(panel.id);
4873
+ }
4874
+ dispose() {
4875
+ super.dispose();
4876
+ for (const { value, disposable } of this.tabs) {
4877
+ disposable.dispose();
4878
+ value.dispose();
4879
+ }
4880
+ this.tabs = [];
4836
4881
  }
4837
4882
  }
4838
- class BaseGrid extends Resizable {
4839
- get id() {
4840
- return this._id;
4883
+
4884
+ class DockviewUnhandledDragOverEvent {
4885
+ get isAccepted() {
4886
+ return this._isAccepted;
4841
4887
  }
4842
- get size() {
4843
- return this._groups.size;
4888
+ constructor(nativeEvent, target, position, getData, group) {
4889
+ this.nativeEvent = nativeEvent;
4890
+ this.target = target;
4891
+ this.position = position;
4892
+ this.getData = getData;
4893
+ this.group = group;
4894
+ this._isAccepted = false;
4844
4895
  }
4845
- get groups() {
4846
- return Array.from(this._groups.values()).map((_) => _.value);
4896
+ accept() {
4897
+ this._isAccepted = true;
4847
4898
  }
4848
- get width() {
4849
- return this.gridview.width;
4899
+ }
4900
+ const PROPERTY_KEYS = (() => {
4901
+ /**
4902
+ * by readong the keys from an empty value object TypeScript will error
4903
+ * when we add or remove new properties to `DockviewOptions`
4904
+ */
4905
+ const properties = {
4906
+ disableAutoResizing: undefined,
4907
+ hideBorders: undefined,
4908
+ singleTabMode: undefined,
4909
+ disableFloatingGroups: undefined,
4910
+ floatingGroupBounds: undefined,
4911
+ popoutUrl: undefined,
4912
+ defaultRenderer: undefined,
4913
+ debug: undefined,
4914
+ rootOverlayModel: undefined,
4915
+ locked: undefined,
4916
+ disableDnd: undefined,
4917
+ };
4918
+ return Object.keys(properties);
4919
+ })();
4920
+ function isPanelOptionsWithPanel(data) {
4921
+ if (data.referencePanel) {
4922
+ return true;
4850
4923
  }
4851
- get height() {
4852
- return this.gridview.height;
4924
+ return false;
4925
+ }
4926
+ function isPanelOptionsWithGroup(data) {
4927
+ if (data.referenceGroup) {
4928
+ return true;
4853
4929
  }
4854
- get minimumHeight() {
4855
- return this.gridview.minimumHeight;
4930
+ return false;
4931
+ }
4932
+ function isGroupOptionsWithPanel(data) {
4933
+ if (data.referencePanel) {
4934
+ return true;
4856
4935
  }
4857
- get maximumHeight() {
4858
- return this.gridview.maximumHeight;
4936
+ return false;
4937
+ }
4938
+ function isGroupOptionsWithGroup(data) {
4939
+ if (data.referenceGroup) {
4940
+ return true;
4859
4941
  }
4860
- get minimumWidth() {
4861
- return this.gridview.minimumWidth;
4942
+ return false;
4943
+ }
4944
+
4945
+ class DockviewDidDropEvent extends DockviewEvent {
4946
+ get nativeEvent() {
4947
+ return this.options.nativeEvent;
4862
4948
  }
4863
- get maximumWidth() {
4864
- return this.gridview.maximumWidth;
4949
+ get position() {
4950
+ return this.options.position;
4865
4951
  }
4866
- get activeGroup() {
4867
- return this._activeGroup;
4952
+ get panel() {
4953
+ return this.options.panel;
4868
4954
  }
4869
- get locked() {
4870
- return this.gridview.locked;
4955
+ get group() {
4956
+ return this.options.group;
4871
4957
  }
4872
- set locked(value) {
4873
- this.gridview.locked = value;
4958
+ get api() {
4959
+ return this.options.api;
4874
4960
  }
4875
4961
  constructor(options) {
4876
- super(document.createElement('div'), options.disableAutoResizing);
4877
- this._id = nextLayoutId$1.next();
4878
- this._groups = new Map();
4879
- this._onDidLayoutChange = new Emitter();
4880
- this.onDidLayoutChange = this._onDidLayoutChange.event;
4881
- this._onDidRemove = new Emitter();
4882
- this.onDidRemove = this._onDidRemove.event;
4883
- this._onDidAdd = new Emitter();
4884
- this.onDidAdd = this._onDidAdd.event;
4885
- this._onDidActiveChange = new Emitter();
4886
- this.onDidActiveChange = this._onDidActiveChange.event;
4887
- this._bufferOnDidLayoutChange = new TickDelayedEvent();
4888
- this.element.style.height = '100%';
4889
- this.element.style.width = '100%';
4890
- options.parentElement.appendChild(this.element);
4891
- this.gridview = new Gridview(!!options.proportionalLayout, options.styles, options.orientation);
4892
- this.gridview.locked = !!options.locked;
4893
- this.element.appendChild(this.gridview.element);
4894
- this.layout(0, 0, true); // set some elements height/widths
4895
- this.addDisposables(Disposable.from(() => {
4896
- var _a;
4897
- (_a = this.element.parentElement) === null || _a === void 0 ? void 0 : _a.removeChild(this.element);
4898
- }), this.gridview.onDidChange(() => {
4899
- this._bufferOnDidLayoutChange.fire();
4900
- }), exports.DockviewEvent.any(this.onDidAdd, this.onDidRemove, this.onDidActiveChange)(() => {
4901
- this._bufferOnDidLayoutChange.fire();
4902
- }), this._bufferOnDidLayoutChange.onEvent(() => {
4903
- this._onDidLayoutChange.fire();
4904
- }), this._bufferOnDidLayoutChange);
4905
- }
4906
- setVisible(panel, visible) {
4907
- this.gridview.setViewVisible(getGridLocation(panel.element), visible);
4908
- this._onDidLayoutChange.fire();
4909
- }
4910
- isVisible(panel) {
4911
- return this.gridview.isViewVisible(getGridLocation(panel.element));
4912
- }
4913
- maximizeGroup(panel) {
4914
- this.gridview.maximizeView(panel);
4915
- this.doSetGroupActive(panel);
4916
- }
4917
- isMaximizedGroup(panel) {
4918
- return this.gridview.maximizedView() === panel;
4919
- }
4920
- exitMaximizedGroup() {
4921
- this.gridview.exitMaximizedView();
4922
- }
4923
- hasMaximizedGroup() {
4924
- return this.gridview.hasMaximizedView();
4925
- }
4926
- get onDidMaximizedGroupChange() {
4927
- return this.gridview.onDidMaximizedNodeChange;
4962
+ super();
4963
+ this.options = options;
4928
4964
  }
4929
- doAddGroup(group, location = [0], size) {
4930
- this.gridview.addView(group, size !== null && size !== void 0 ? size : exports.Sizing.Distribute, location);
4931
- this._onDidAdd.fire(group);
4965
+ getData() {
4966
+ return this.options.getData();
4932
4967
  }
4933
- doRemoveGroup(group, options) {
4934
- if (!this._groups.has(group.id)) {
4935
- throw new Error('invalid operation');
4936
- }
4937
- const item = this._groups.get(group.id);
4938
- const view = this.gridview.remove(group, exports.Sizing.Distribute);
4939
- if (item && !(options === null || options === void 0 ? void 0 : options.skipDispose)) {
4940
- item.disposable.dispose();
4941
- item.value.dispose();
4942
- this._groups.delete(group.id);
4943
- this._onDidRemove.fire(group);
4944
- }
4945
- if (!(options === null || options === void 0 ? void 0 : options.skipActive) && this._activeGroup === group) {
4946
- const groups = Array.from(this._groups.values());
4947
- this.doSetGroupActive(groups.length > 0 ? groups[0].value : undefined);
4948
- }
4949
- return view;
4968
+ }
4969
+ class DockviewWillDropEvent extends DockviewDidDropEvent {
4970
+ get kind() {
4971
+ return this._kind;
4950
4972
  }
4951
- getPanel(id) {
4952
- var _a;
4953
- return (_a = this._groups.get(id)) === null || _a === void 0 ? void 0 : _a.value;
4973
+ constructor(options) {
4974
+ super(options);
4975
+ this._kind = options.kind;
4954
4976
  }
4955
- doSetGroupActive(group) {
4956
- if (this._activeGroup === group) {
4957
- return;
4958
- }
4959
- if (this._activeGroup) {
4960
- this._activeGroup.setActive(false);
4961
- }
4962
- if (group) {
4963
- group.setActive(true);
4964
- }
4965
- this._activeGroup = group;
4966
- this._onDidActiveChange.fire(group);
4977
+ }
4978
+ class WillShowOverlayLocationEvent {
4979
+ get kind() {
4980
+ return this.options.kind;
4967
4981
  }
4968
- removeGroup(group) {
4969
- this.doRemoveGroup(group);
4982
+ get nativeEvent() {
4983
+ return this.event.nativeEvent;
4970
4984
  }
4971
- moveToNext(options) {
4972
- var _a;
4973
- if (!options) {
4974
- options = {};
4975
- }
4976
- if (!options.group) {
4977
- if (!this.activeGroup) {
4978
- return;
4979
- }
4980
- options.group = this.activeGroup;
4981
- }
4982
- const location = getGridLocation(options.group.element);
4983
- const next = (_a = this.gridview.next(location)) === null || _a === void 0 ? void 0 : _a.view;
4984
- this.doSetGroupActive(next);
4985
+ get position() {
4986
+ return this.event.position;
4985
4987
  }
4986
- moveToPrevious(options) {
4987
- var _a;
4988
- if (!options) {
4989
- options = {};
4990
- }
4991
- if (!options.group) {
4992
- if (!this.activeGroup) {
4993
- return;
4994
- }
4995
- options.group = this.activeGroup;
4996
- }
4997
- const location = getGridLocation(options.group.element);
4998
- const next = (_a = this.gridview.previous(location)) === null || _a === void 0 ? void 0 : _a.view;
4999
- this.doSetGroupActive(next);
4988
+ get defaultPrevented() {
4989
+ return this.event.defaultPrevented;
5000
4990
  }
5001
- layout(width, height, forceResize) {
5002
- const different = forceResize !== null && forceResize !== void 0 ? forceResize : (width !== this.width || height !== this.height);
5003
- if (!different) {
5004
- return;
5005
- }
5006
- this.gridview.element.style.height = `${height}px`;
5007
- this.gridview.element.style.width = `${width}px`;
5008
- this.gridview.layout(width, height);
4991
+ get panel() {
4992
+ return this.options.panel;
5009
4993
  }
5010
- dispose() {
5011
- this._onDidActiveChange.dispose();
5012
- this._onDidAdd.dispose();
5013
- this._onDidRemove.dispose();
5014
- this._onDidLayoutChange.dispose();
5015
- for (const group of this.groups) {
5016
- group.dispose();
5017
- }
5018
- this.gridview.dispose();
5019
- super.dispose();
4994
+ get api() {
4995
+ return this.options.api;
5020
4996
  }
5021
- }
5022
-
5023
- class WillFocusEvent extends DockviewEvent {
5024
- constructor() {
5025
- super();
4997
+ get group() {
4998
+ return this.options.group;
5026
4999
  }
5027
- }
5028
- /**
5029
- * A core api implementation that should be used across all panel-like objects
5030
- */
5031
- class PanelApiImpl extends CompositeDisposable {
5032
- get isFocused() {
5033
- return this._isFocused;
5000
+ preventDefault() {
5001
+ this.event.preventDefault();
5034
5002
  }
5035
- get isActive() {
5036
- return this._isActive;
5003
+ getData() {
5004
+ return this.options.getData();
5037
5005
  }
5038
- get isVisible() {
5039
- return this._isVisible;
5006
+ constructor(event, options) {
5007
+ this.event = event;
5008
+ this.options = options;
5040
5009
  }
5041
- get width() {
5042
- return this._width;
5010
+ }
5011
+ class DockviewGroupPanelModel extends CompositeDisposable {
5012
+ get element() {
5013
+ throw new Error('not supported');
5043
5014
  }
5044
- get height() {
5045
- return this._height;
5015
+ get activePanel() {
5016
+ return this._activePanel;
5046
5017
  }
5047
- constructor(id, component) {
5048
- super();
5049
- this.id = id;
5050
- this.component = component;
5051
- this._isFocused = false;
5052
- this._isActive = false;
5053
- this._isVisible = true;
5054
- this._width = 0;
5055
- this._height = 0;
5056
- this._parameters = {};
5057
- this.panelUpdatesDisposable = new MutableDisposable();
5058
- this._onDidDimensionChange = new Emitter();
5059
- this.onDidDimensionsChange = this._onDidDimensionChange.event;
5060
- this._onDidChangeFocus = new Emitter();
5061
- this.onDidFocusChange = this._onDidChangeFocus.event;
5062
- //
5063
- this._onWillFocus = new Emitter();
5064
- this.onWillFocus = this._onWillFocus.event;
5065
- //
5066
- this._onDidVisibilityChange = new Emitter();
5067
- this.onDidVisibilityChange = this._onDidVisibilityChange.event;
5068
- this._onWillVisibilityChange = new Emitter();
5069
- this.onWillVisibilityChange = this._onWillVisibilityChange.event;
5070
- this._onDidActiveChange = new Emitter();
5071
- this.onDidActiveChange = this._onDidActiveChange.event;
5072
- this._onActiveChange = new Emitter();
5073
- this.onActiveChange = this._onActiveChange.event;
5074
- this._onDidParametersChange = new Emitter();
5075
- this.onDidParametersChange = this._onDidParametersChange.event;
5076
- this.addDisposables(this.onDidFocusChange((event) => {
5077
- this._isFocused = event.isFocused;
5078
- }), this.onDidActiveChange((event) => {
5079
- this._isActive = event.isActive;
5080
- }), this.onDidVisibilityChange((event) => {
5081
- this._isVisible = event.isVisible;
5082
- }), this.onDidDimensionsChange((event) => {
5083
- this._width = event.width;
5084
- this._height = event.height;
5085
- }), this.panelUpdatesDisposable, this._onDidDimensionChange, this._onDidChangeFocus, this._onDidVisibilityChange, this._onDidActiveChange, this._onWillFocus, this._onActiveChange, this._onWillFocus, this._onWillVisibilityChange, this._onDidParametersChange);
5018
+ get locked() {
5019
+ return this._locked;
5086
5020
  }
5087
- getParameters() {
5088
- return this._parameters;
5021
+ set locked(value) {
5022
+ this._locked = value;
5023
+ toggleClass(this.container, 'locked-groupview', value === 'no-drop-target' || value);
5089
5024
  }
5090
- initialize(panel) {
5091
- this.panelUpdatesDisposable.value = this._onDidParametersChange.event((parameters) => {
5092
- this._parameters = parameters;
5093
- panel.update({
5094
- params: parameters,
5095
- });
5096
- });
5025
+ get isActive() {
5026
+ return this._isGroupActive;
5097
5027
  }
5098
- setVisible(isVisible) {
5099
- this._onWillVisibilityChange.fire({ isVisible });
5028
+ get panels() {
5029
+ return this._panels;
5100
5030
  }
5101
- setActive() {
5102
- this._onActiveChange.fire();
5031
+ get size() {
5032
+ return this._panels.length;
5103
5033
  }
5104
- updateParameters(parameters) {
5105
- this._onDidParametersChange.fire(parameters);
5034
+ get isEmpty() {
5035
+ return this._panels.length === 0;
5106
5036
  }
5107
- }
5108
-
5109
- class SplitviewPanelApiImpl extends PanelApiImpl {
5110
- //
5111
- constructor(id, component) {
5112
- super(id, component);
5113
- this._onDidConstraintsChangeInternal = new Emitter();
5114
- this.onDidConstraintsChangeInternal = this._onDidConstraintsChangeInternal.event;
5115
- //
5116
- this._onDidConstraintsChange = new Emitter({
5117
- replay: true,
5118
- });
5119
- this.onDidConstraintsChange = this._onDidConstraintsChange.event;
5120
- //
5121
- this._onDidSizeChange = new Emitter();
5122
- this.onDidSizeChange = this._onDidSizeChange.event;
5123
- this.addDisposables(this._onDidConstraintsChangeInternal, this._onDidConstraintsChange, this._onDidSizeChange);
5037
+ get hasWatermark() {
5038
+ return !!(this.watermark && this.container.contains(this.watermark.element));
5124
5039
  }
5125
- setConstraints(value) {
5126
- this._onDidConstraintsChangeInternal.fire(value);
5040
+ get header() {
5041
+ return this.tabsContainer;
5127
5042
  }
5128
- setSize(event) {
5129
- this._onDidSizeChange.fire(event);
5043
+ get isContentFocused() {
5044
+ if (!document.activeElement) {
5045
+ return false;
5046
+ }
5047
+ return isAncestor(document.activeElement, this.contentContainer.element);
5130
5048
  }
5131
- }
5132
-
5133
- class PaneviewPanelApiImpl extends SplitviewPanelApiImpl {
5134
- set pane(pane) {
5135
- this._pane = pane;
5049
+ get location() {
5050
+ return this._location;
5136
5051
  }
5137
- constructor(id, component) {
5138
- super(id, component);
5139
- this._onDidExpansionChange = new Emitter({
5140
- replay: true,
5052
+ set location(value) {
5053
+ this._location = value;
5054
+ toggleClass(this.container, 'dv-groupview-floating', false);
5055
+ toggleClass(this.container, 'dv-groupview-popout', false);
5056
+ switch (value.type) {
5057
+ case 'grid':
5058
+ this.contentContainer.dropTarget.setTargetZones([
5059
+ 'top',
5060
+ 'bottom',
5061
+ 'left',
5062
+ 'right',
5063
+ 'center',
5064
+ ]);
5065
+ break;
5066
+ case 'floating':
5067
+ this.contentContainer.dropTarget.setTargetZones(['center']);
5068
+ this.contentContainer.dropTarget.setTargetZones(value
5069
+ ? ['center']
5070
+ : ['top', 'bottom', 'left', 'right', 'center']);
5071
+ toggleClass(this.container, 'dv-groupview-floating', true);
5072
+ break;
5073
+ case 'popout':
5074
+ this.contentContainer.dropTarget.setTargetZones(['center']);
5075
+ toggleClass(this.container, 'dv-groupview-popout', true);
5076
+ break;
5077
+ }
5078
+ this.groupPanel.api._onDidLocationChange.fire({
5079
+ location: this.location,
5141
5080
  });
5142
- this.onDidExpansionChange = this._onDidExpansionChange.event;
5143
- this._onMouseEnter = new Emitter({});
5144
- this.onMouseEnter = this._onMouseEnter.event;
5145
- this._onMouseLeave = new Emitter({});
5146
- this.onMouseLeave = this._onMouseLeave.event;
5147
- this.addDisposables(this._onDidExpansionChange, this._onMouseEnter, this._onMouseLeave);
5148
- }
5149
- setExpanded(isExpanded) {
5150
- var _a;
5151
- (_a = this._pane) === null || _a === void 0 ? void 0 : _a.setExpanded(isExpanded);
5152
5081
  }
5153
- get isExpanded() {
5082
+ constructor(container, accessor, id, options, groupPanel) {
5154
5083
  var _a;
5155
- return !!((_a = this._pane) === null || _a === void 0 ? void 0 : _a.isExpanded());
5156
- }
5157
- }
5158
-
5159
- class BasePanelView extends CompositeDisposable {
5160
- get element() {
5161
- return this._element;
5084
+ super();
5085
+ this.container = container;
5086
+ this.accessor = accessor;
5087
+ this.id = id;
5088
+ this.options = options;
5089
+ this.groupPanel = groupPanel;
5090
+ this._isGroupActive = false;
5091
+ this._locked = false;
5092
+ this._location = { type: 'grid' };
5093
+ this.mostRecentlyUsed = [];
5094
+ this._onDidChange = new Emitter();
5095
+ this.onDidChange = this._onDidChange.event;
5096
+ this._width = 0;
5097
+ this._height = 0;
5098
+ this._panels = [];
5099
+ this._panelDisposables = new Map();
5100
+ this._onMove = new Emitter();
5101
+ this.onMove = this._onMove.event;
5102
+ this._onDidDrop = new Emitter();
5103
+ this.onDidDrop = this._onDidDrop.event;
5104
+ this._onWillDrop = new Emitter();
5105
+ this.onWillDrop = this._onWillDrop.event;
5106
+ this._onWillShowOverlay = new Emitter();
5107
+ this.onWillShowOverlay = this._onWillShowOverlay.event;
5108
+ this._onTabDragStart = new Emitter();
5109
+ this.onTabDragStart = this._onTabDragStart.event;
5110
+ this._onGroupDragStart = new Emitter();
5111
+ this.onGroupDragStart = this._onGroupDragStart.event;
5112
+ this._onDidAddPanel = new Emitter();
5113
+ this.onDidAddPanel = this._onDidAddPanel.event;
5114
+ this._onDidPanelTitleChange = new Emitter();
5115
+ this.onDidPanelTitleChange = this._onDidPanelTitleChange.event;
5116
+ this._onDidPanelParametersChange = new Emitter();
5117
+ this.onDidPanelParametersChange = this._onDidPanelParametersChange.event;
5118
+ this._onDidRemovePanel = new Emitter();
5119
+ this.onDidRemovePanel = this._onDidRemovePanel.event;
5120
+ this._onDidActivePanelChange = new Emitter();
5121
+ this.onDidActivePanelChange = this._onDidActivePanelChange.event;
5122
+ this._onUnhandledDragOverEvent = new Emitter();
5123
+ this.onUnhandledDragOverEvent = this._onUnhandledDragOverEvent.event;
5124
+ this._overwriteRenderContainer = null;
5125
+ toggleClass(this.container, 'groupview', true);
5126
+ this._api = new DockviewApi(this.accessor);
5127
+ this.tabsContainer = new TabsContainer(this.accessor, this.groupPanel);
5128
+ this.contentContainer = new ContentContainer(this.accessor, this);
5129
+ container.append(this.tabsContainer.element, this.contentContainer.element);
5130
+ this.header.hidden = !!options.hideHeader;
5131
+ this.locked = (_a = options.locked) !== null && _a !== void 0 ? _a : false;
5132
+ this.addDisposables(this._onTabDragStart, this._onGroupDragStart, this._onWillShowOverlay, this.tabsContainer.onTabDragStart((event) => {
5133
+ this._onTabDragStart.fire(event);
5134
+ }), this.tabsContainer.onGroupDragStart((event) => {
5135
+ this._onGroupDragStart.fire(event);
5136
+ }), this.tabsContainer.onDrop((event) => {
5137
+ this.handleDropEvent('header', event.event, 'center', event.index);
5138
+ }), this.contentContainer.onDidFocus(() => {
5139
+ this.accessor.doSetGroupActive(this.groupPanel);
5140
+ }), this.contentContainer.onDidBlur(() => {
5141
+ // noop
5142
+ }), this.contentContainer.dropTarget.onDrop((event) => {
5143
+ this.handleDropEvent('content', event.nativeEvent, event.position);
5144
+ }), this.tabsContainer.onWillShowOverlay((event) => {
5145
+ this._onWillShowOverlay.fire(event);
5146
+ }), this.contentContainer.dropTarget.onWillShowOverlay((event) => {
5147
+ this._onWillShowOverlay.fire(new WillShowOverlayLocationEvent(event, {
5148
+ kind: 'content',
5149
+ panel: this.activePanel,
5150
+ api: this._api,
5151
+ group: this.groupPanel,
5152
+ getData: getPanelData,
5153
+ }));
5154
+ }), this._onMove, this._onDidChange, this._onDidDrop, this._onWillDrop, this._onDidAddPanel, this._onDidRemovePanel, this._onDidActivePanelChange, this._onUnhandledDragOverEvent);
5162
5155
  }
5163
- get width() {
5164
- return this._width;
5156
+ focusContent() {
5157
+ this.contentContainer.element.focus();
5165
5158
  }
5166
- get height() {
5167
- return this._height;
5159
+ set renderContainer(value) {
5160
+ this.panels.forEach((panel) => {
5161
+ this.renderContainer.detatch(panel);
5162
+ });
5163
+ this._overwriteRenderContainer = value;
5164
+ this.panels.forEach((panel) => {
5165
+ this.rerender(panel);
5166
+ });
5168
5167
  }
5169
- get params() {
5168
+ get renderContainer() {
5170
5169
  var _a;
5171
- return (_a = this._params) === null || _a === void 0 ? void 0 : _a.params;
5172
- }
5173
- constructor(id, component, api) {
5174
- super();
5175
- this.id = id;
5176
- this.component = component;
5177
- this.api = api;
5178
- this._height = 0;
5179
- this._width = 0;
5180
- this._element = document.createElement('div');
5181
- this._element.tabIndex = -1;
5182
- this._element.style.outline = 'none';
5183
- this._element.style.height = '100%';
5184
- this._element.style.width = '100%';
5185
- this._element.style.overflow = 'hidden';
5186
- const focusTracker = trackFocus(this._element);
5187
- this.addDisposables(this.api, focusTracker.onDidFocus(() => {
5188
- this.api._onDidChangeFocus.fire({ isFocused: true });
5189
- }), focusTracker.onDidBlur(() => {
5190
- this.api._onDidChangeFocus.fire({ isFocused: false });
5191
- }), focusTracker);
5170
+ return ((_a = this._overwriteRenderContainer) !== null && _a !== void 0 ? _a : this.accessor.overlayRenderContainer);
5192
5171
  }
5193
- focus() {
5194
- const event = new WillFocusEvent();
5195
- this.api._onWillFocus.fire(event);
5196
- if (event.defaultPrevented) {
5197
- return;
5172
+ initialize() {
5173
+ if (this.options.panels) {
5174
+ this.options.panels.forEach((panel) => {
5175
+ this.doAddPanel(panel);
5176
+ });
5198
5177
  }
5199
- this._element.focus();
5200
- }
5201
- layout(width, height) {
5202
- this._width = width;
5203
- this._height = height;
5204
- this.api._onDidDimensionChange.fire({ width, height });
5205
- if (this.part) {
5206
- if (this._params) {
5207
- this.part.update(this._params.params);
5208
- }
5178
+ if (this.options.activePanel) {
5179
+ this.openPanel(this.options.activePanel);
5180
+ }
5181
+ // must be run after the constructor otherwise this.parent may not be
5182
+ // correctly initialized
5183
+ this.setActive(this.isActive, true);
5184
+ this.updateContainer();
5185
+ if (this.accessor.options.createRightHeaderActionComponent) {
5186
+ this._rightHeaderActions =
5187
+ this.accessor.options.createRightHeaderActionComponent(this.groupPanel);
5188
+ this.addDisposables(this._rightHeaderActions);
5189
+ this._rightHeaderActions.init({
5190
+ containerApi: this._api,
5191
+ api: this.groupPanel.api,
5192
+ group: this.groupPanel,
5193
+ });
5194
+ this.tabsContainer.setRightActionsElement(this._rightHeaderActions.element);
5195
+ }
5196
+ if (this.accessor.options.createLeftHeaderActionComponent) {
5197
+ this._leftHeaderActions =
5198
+ this.accessor.options.createLeftHeaderActionComponent(this.groupPanel);
5199
+ this.addDisposables(this._leftHeaderActions);
5200
+ this._leftHeaderActions.init({
5201
+ containerApi: this._api,
5202
+ api: this.groupPanel.api,
5203
+ group: this.groupPanel,
5204
+ });
5205
+ this.tabsContainer.setLeftActionsElement(this._leftHeaderActions.element);
5206
+ }
5207
+ if (this.accessor.options.createPrefixHeaderActionComponent) {
5208
+ this._prefixHeaderActions =
5209
+ this.accessor.options.createPrefixHeaderActionComponent(this.groupPanel);
5210
+ this.addDisposables(this._prefixHeaderActions);
5211
+ this._prefixHeaderActions.init({
5212
+ containerApi: this._api,
5213
+ api: this.groupPanel.api,
5214
+ group: this.groupPanel,
5215
+ });
5216
+ this.tabsContainer.setPrefixActionsElement(this._prefixHeaderActions.element);
5209
5217
  }
5210
5218
  }
5211
- init(parameters) {
5212
- this._params = parameters;
5213
- this.part = this.getComponent();
5219
+ rerender(panel) {
5220
+ this.contentContainer.renderPanel(panel, { asActive: false });
5214
5221
  }
5215
- update(event) {
5216
- var _a, _b;
5217
- // merge the new parameters with the existing parameters
5218
- this._params = Object.assign(Object.assign({}, this._params), { params: Object.assign(Object.assign({}, (_a = this._params) === null || _a === void 0 ? void 0 : _a.params), event.params) });
5219
- /**
5220
- * delete new keys that have a value of undefined,
5221
- * allow values of null
5222
- */
5223
- for (const key of Object.keys(event.params)) {
5224
- if (event.params[key] === undefined) {
5225
- delete this._params.params[key];
5226
- }
5227
- }
5228
- // update the view with the updated props
5229
- (_b = this.part) === null || _b === void 0 ? void 0 : _b.update({ params: this._params.params });
5222
+ indexOf(panel) {
5223
+ return this.tabsContainer.indexOf(panel.id);
5230
5224
  }
5231
5225
  toJSON() {
5232
- var _a, _b;
5233
- const params = (_b = (_a = this._params) === null || _a === void 0 ? void 0 : _a.params) !== null && _b !== void 0 ? _b : {};
5234
- return {
5226
+ var _a;
5227
+ const result = {
5228
+ views: this.tabsContainer.panels,
5229
+ activeView: (_a = this._activePanel) === null || _a === void 0 ? void 0 : _a.id,
5235
5230
  id: this.id,
5236
- component: this.component,
5237
- params: Object.keys(params).length > 0 ? params : undefined,
5238
5231
  };
5232
+ if (this.locked !== false) {
5233
+ result.locked = this.locked;
5234
+ }
5235
+ if (this.header.hidden) {
5236
+ result.hideHeader = true;
5237
+ }
5238
+ return result;
5239
5239
  }
5240
- dispose() {
5241
- var _a;
5242
- this.api.dispose();
5243
- (_a = this.part) === null || _a === void 0 ? void 0 : _a.dispose();
5244
- super.dispose();
5245
- }
5246
- }
5247
-
5248
- class PaneviewPanel extends BasePanelView {
5249
- set orientation(value) {
5250
- this._orientation = value;
5251
- }
5252
- get orientation() {
5253
- return this._orientation;
5254
- }
5255
- get minimumSize() {
5256
- const headerSize = this.headerSize;
5257
- const expanded = this.isExpanded();
5258
- const minimumBodySize = expanded ? this._minimumBodySize : 0;
5259
- return headerSize + minimumBodySize;
5260
- }
5261
- get maximumSize() {
5262
- const headerSize = this.headerSize;
5263
- const expanded = this.isExpanded();
5264
- const maximumBodySize = expanded ? this._maximumBodySize : 0;
5265
- return headerSize + maximumBodySize;
5266
- }
5267
- get size() {
5268
- return this._size;
5269
- }
5270
- get orthogonalSize() {
5271
- return this._orthogonalSize;
5272
- }
5273
- set orthogonalSize(size) {
5274
- this._orthogonalSize = size;
5275
- }
5276
- get minimumBodySize() {
5277
- return this._minimumBodySize;
5278
- }
5279
- set minimumBodySize(value) {
5280
- this._minimumBodySize = typeof value === 'number' ? value : 0;
5281
- }
5282
- get maximumBodySize() {
5283
- return this._maximumBodySize;
5284
- }
5285
- set maximumBodySize(value) {
5286
- this._maximumBodySize =
5287
- typeof value === 'number' ? value : Number.POSITIVE_INFINITY;
5288
- }
5289
- get headerVisible() {
5290
- return this._headerVisible;
5291
- }
5292
- set headerVisible(value) {
5293
- this._headerVisible = value;
5294
- this.header.style.display = value ? '' : 'none';
5240
+ moveToNext(options) {
5241
+ if (!options) {
5242
+ options = {};
5243
+ }
5244
+ if (!options.panel) {
5245
+ options.panel = this.activePanel;
5246
+ }
5247
+ const index = options.panel ? this.panels.indexOf(options.panel) : -1;
5248
+ let normalizedIndex;
5249
+ if (index < this.panels.length - 1) {
5250
+ normalizedIndex = index + 1;
5251
+ }
5252
+ else if (!options.suppressRoll) {
5253
+ normalizedIndex = 0;
5254
+ }
5255
+ else {
5256
+ return;
5257
+ }
5258
+ this.openPanel(this.panels[normalizedIndex]);
5295
5259
  }
5296
- constructor(id, component, headerComponent, orientation, isExpanded, isHeaderVisible) {
5297
- super(id, component, new PaneviewPanelApiImpl(id, component));
5298
- this.headerComponent = headerComponent;
5299
- this._onDidChangeExpansionState = new Emitter({ replay: true });
5300
- this.onDidChangeExpansionState = this._onDidChangeExpansionState.event;
5301
- this._onDidChange = new Emitter();
5302
- this.onDidChange = this._onDidChange.event;
5303
- this.headerSize = 22;
5304
- this._orthogonalSize = 0;
5305
- this._size = 0;
5306
- this._minimumBodySize = 100;
5307
- this._maximumBodySize = Number.POSITIVE_INFINITY;
5308
- this._isExpanded = false;
5309
- this.expandedSize = 0;
5310
- this.api.pane = this; // TODO cannot use 'this' before 'super'
5311
- this.api.initialize(this);
5312
- this._isExpanded = isExpanded;
5313
- this._headerVisible = isHeaderVisible;
5314
- this._onDidChangeExpansionState.fire(this.isExpanded()); // initialize value
5315
- this._orientation = orientation;
5316
- this.element.classList.add('pane');
5317
- this.addDisposables(this.api.onWillVisibilityChange((event) => {
5318
- const { isVisible } = event;
5319
- const { accessor } = this._params;
5320
- accessor.setVisible(this, isVisible);
5321
- }), this.api.onDidSizeChange((event) => {
5322
- this._onDidChange.fire({ size: event.size });
5323
- }), addDisposableListener(this.element, 'mouseenter', (ev) => {
5324
- this.api._onMouseEnter.fire(ev);
5325
- }), addDisposableListener(this.element, 'mouseleave', (ev) => {
5326
- this.api._onMouseLeave.fire(ev);
5327
- }));
5328
- this.addDisposables(this._onDidChangeExpansionState, this.onDidChangeExpansionState((isPanelExpanded) => {
5329
- this.api._onDidExpansionChange.fire({
5330
- isExpanded: isPanelExpanded,
5331
- });
5332
- }), this.api.onDidFocusChange((e) => {
5333
- if (!this.header) {
5334
- return;
5335
- }
5336
- if (e.isFocused) {
5337
- addClasses(this.header, 'focused');
5338
- }
5339
- else {
5340
- removeClasses(this.header, 'focused');
5341
- }
5342
- }));
5343
- this.renderOnce();
5260
+ moveToPrevious(options) {
5261
+ if (!options) {
5262
+ options = {};
5263
+ }
5264
+ if (!options.panel) {
5265
+ options.panel = this.activePanel;
5266
+ }
5267
+ if (!options.panel) {
5268
+ return;
5269
+ }
5270
+ const index = this.panels.indexOf(options.panel);
5271
+ let normalizedIndex;
5272
+ if (index > 0) {
5273
+ normalizedIndex = index - 1;
5274
+ }
5275
+ else if (!options.suppressRoll) {
5276
+ normalizedIndex = this.panels.length - 1;
5277
+ }
5278
+ else {
5279
+ return;
5280
+ }
5281
+ this.openPanel(this.panels[normalizedIndex]);
5344
5282
  }
5345
- setVisible(isVisible) {
5346
- this.api._onDidVisibilityChange.fire({ isVisible });
5283
+ containsPanel(panel) {
5284
+ return this.panels.includes(panel);
5347
5285
  }
5348
- setActive(isActive) {
5349
- this.api._onDidActiveChange.fire({ isActive });
5286
+ init(_params) {
5287
+ //noop
5350
5288
  }
5351
- isExpanded() {
5352
- return this._isExpanded;
5289
+ update(_params) {
5290
+ //noop
5353
5291
  }
5354
- setExpanded(expanded) {
5355
- if (this._isExpanded === expanded) {
5292
+ focus() {
5293
+ var _a;
5294
+ (_a = this._activePanel) === null || _a === void 0 ? void 0 : _a.focus();
5295
+ }
5296
+ openPanel(panel, options = {}) {
5297
+ /**
5298
+ * set the panel group
5299
+ * add the panel
5300
+ * check if group active
5301
+ * check if panel active
5302
+ */
5303
+ if (typeof options.index !== 'number' ||
5304
+ options.index > this.panels.length) {
5305
+ options.index = this.panels.length;
5306
+ }
5307
+ const skipSetActive = !!options.skipSetActive;
5308
+ // ensure the group is updated before we fire any events
5309
+ panel.updateParentGroup(this.groupPanel, {
5310
+ skipSetActive: options.skipSetActive,
5311
+ });
5312
+ this.doAddPanel(panel, options.index, {
5313
+ skipSetActive: skipSetActive,
5314
+ });
5315
+ if (this._activePanel === panel) {
5316
+ this.contentContainer.renderPanel(panel, { asActive: true });
5356
5317
  return;
5357
5318
  }
5358
- this._isExpanded = expanded;
5359
- if (expanded) {
5360
- if (this.animationTimer) {
5361
- clearTimeout(this.animationTimer);
5362
- }
5363
- if (this.body) {
5364
- this.element.appendChild(this.body);
5319
+ if (!skipSetActive) {
5320
+ this.doSetActivePanel(panel);
5321
+ }
5322
+ if (!options.skipSetGroupActive) {
5323
+ this.accessor.doSetGroupActive(this.groupPanel);
5324
+ }
5325
+ if (!options.skipSetActive) {
5326
+ this.updateContainer();
5327
+ }
5328
+ }
5329
+ removePanel(groupItemOrId, options = {
5330
+ skipSetActive: false,
5331
+ }) {
5332
+ const id = typeof groupItemOrId === 'string'
5333
+ ? groupItemOrId
5334
+ : groupItemOrId.id;
5335
+ const panelToRemove = this._panels.find((panel) => panel.id === id);
5336
+ if (!panelToRemove) {
5337
+ throw new Error('invalid operation');
5338
+ }
5339
+ return this._removePanel(panelToRemove, options);
5340
+ }
5341
+ closeAllPanels() {
5342
+ if (this.panels.length > 0) {
5343
+ // take a copy since we will be edting the array as we iterate through
5344
+ const arrPanelCpy = [...this.panels];
5345
+ for (const panel of arrPanelCpy) {
5346
+ this.doClose(panel);
5365
5347
  }
5366
5348
  }
5367
5349
  else {
5368
- this.animationTimer = setTimeout(() => {
5369
- var _a;
5370
- (_a = this.body) === null || _a === void 0 ? void 0 : _a.remove();
5371
- }, 200);
5350
+ this.accessor.removeGroup(this.groupPanel);
5372
5351
  }
5373
- this._onDidChange.fire(expanded ? { size: this.width } : {});
5374
- this._onDidChangeExpansionState.fire(expanded);
5375
5352
  }
5376
- layout(size, orthogonalSize) {
5377
- this._size = size;
5378
- this._orthogonalSize = orthogonalSize;
5379
- const [width, height] = this.orientation === exports.Orientation.HORIZONTAL
5380
- ? [size, orthogonalSize]
5381
- : [orthogonalSize, size];
5382
- if (this.isExpanded()) {
5383
- this.expandedSize = width;
5353
+ closePanel(panel) {
5354
+ this.doClose(panel);
5355
+ }
5356
+ doClose(panel) {
5357
+ this.accessor.removePanel(panel);
5358
+ }
5359
+ isPanelActive(panel) {
5360
+ return this._activePanel === panel;
5361
+ }
5362
+ updateActions(element) {
5363
+ this.tabsContainer.setRightActionsElement(element);
5364
+ }
5365
+ setActive(isGroupActive, force = false) {
5366
+ if (!force && this.isActive === isGroupActive) {
5367
+ return;
5384
5368
  }
5385
- super.layout(width, height);
5369
+ this._isGroupActive = isGroupActive;
5370
+ toggleClass(this.container, 'active-group', isGroupActive);
5371
+ toggleClass(this.container, 'inactive-group', !isGroupActive);
5372
+ this.tabsContainer.setActive(this.isActive);
5373
+ if (!this._activePanel && this.panels.length > 0) {
5374
+ this.doSetActivePanel(this.panels[0]);
5375
+ }
5376
+ this.updateContainer();
5386
5377
  }
5387
- init(parameters) {
5388
- var _a, _b;
5389
- super.init(parameters);
5390
- if (typeof parameters.minimumBodySize === 'number') {
5391
- this.minimumBodySize = parameters.minimumBodySize;
5378
+ layout(width, height) {
5379
+ var _a;
5380
+ this._width = width;
5381
+ this._height = height;
5382
+ this.contentContainer.layout(this._width, this._height);
5383
+ if ((_a = this._activePanel) === null || _a === void 0 ? void 0 : _a.layout) {
5384
+ this._activePanel.layout(this._width, this._height);
5392
5385
  }
5393
- if (typeof parameters.maximumBodySize === 'number') {
5394
- this.maximumBodySize = parameters.maximumBodySize;
5386
+ }
5387
+ _removePanel(panel, options) {
5388
+ const isActivePanel = this._activePanel === panel;
5389
+ this.doRemovePanel(panel);
5390
+ if (isActivePanel && this.panels.length > 0) {
5391
+ const nextPanel = this.mostRecentlyUsed[0];
5392
+ this.openPanel(nextPanel, {
5393
+ skipSetActive: options.skipSetActive,
5394
+ skipSetGroupActive: options.skipSetActiveGroup,
5395
+ });
5395
5396
  }
5396
- this.bodyPart = this.getBodyComponent();
5397
- this.headerPart = this.getHeaderComponent();
5398
- this.bodyPart.init(Object.assign(Object.assign({}, parameters), { api: this.api }));
5399
- this.headerPart.init(Object.assign(Object.assign({}, parameters), { api: this.api }));
5400
- (_a = this.body) === null || _a === void 0 ? void 0 : _a.append(this.bodyPart.element);
5401
- (_b = this.header) === null || _b === void 0 ? void 0 : _b.append(this.headerPart.element);
5402
- if (typeof parameters.isExpanded === 'boolean') {
5403
- this.setExpanded(parameters.isExpanded);
5397
+ if (this._activePanel && this.panels.length === 0) {
5398
+ this.doSetActivePanel(undefined);
5399
+ }
5400
+ if (!options.skipSetActive) {
5401
+ this.updateContainer();
5404
5402
  }
5403
+ return panel;
5405
5404
  }
5406
- toJSON() {
5407
- const params = this._params;
5408
- return Object.assign(Object.assign({}, super.toJSON()), { headerComponent: this.headerComponent, title: params.title });
5405
+ doRemovePanel(panel) {
5406
+ const index = this.panels.indexOf(panel);
5407
+ if (this._activePanel === panel) {
5408
+ this.contentContainer.closePanel();
5409
+ }
5410
+ this.tabsContainer.delete(panel.id);
5411
+ this._panels.splice(index, 1);
5412
+ if (this.mostRecentlyUsed.includes(panel)) {
5413
+ const index = this.mostRecentlyUsed.indexOf(panel);
5414
+ this.mostRecentlyUsed.splice(index, 1);
5415
+ }
5416
+ const disposable = this._panelDisposables.get(panel.id);
5417
+ if (disposable) {
5418
+ disposable.dispose();
5419
+ this._panelDisposables.delete(panel.id);
5420
+ }
5421
+ this._onDidRemovePanel.fire({ panel });
5409
5422
  }
5410
- renderOnce() {
5411
- this.header = document.createElement('div');
5412
- this.header.tabIndex = 0;
5413
- this.header.className = 'pane-header';
5414
- this.header.style.height = `${this.headerSize}px`;
5415
- this.header.style.lineHeight = `${this.headerSize}px`;
5416
- this.header.style.minHeight = `${this.headerSize}px`;
5417
- this.header.style.maxHeight = `${this.headerSize}px`;
5418
- this.element.appendChild(this.header);
5419
- this.body = document.createElement('div');
5420
- this.body.className = 'pane-body';
5421
- this.element.appendChild(this.body);
5423
+ doAddPanel(panel, index = this.panels.length, options = { skipSetActive: false }) {
5424
+ const existingPanel = this._panels.indexOf(panel);
5425
+ const hasExistingPanel = existingPanel > -1;
5426
+ this.tabsContainer.show();
5427
+ this.contentContainer.show();
5428
+ this.tabsContainer.openPanel(panel, index);
5429
+ if (!options.skipSetActive) {
5430
+ this.contentContainer.openPanel(panel);
5431
+ }
5432
+ if (hasExistingPanel) {
5433
+ // TODO - need to ensure ordering hasn't changed and if it has need to re-order this.panels
5434
+ return;
5435
+ }
5436
+ this.updateMru(panel);
5437
+ this.panels.splice(index, 0, panel);
5438
+ this._panelDisposables.set(panel.id, new CompositeDisposable(panel.api.onDidTitleChange((event) => this._onDidPanelTitleChange.fire(event)), panel.api.onDidParametersChange((event) => this._onDidPanelParametersChange.fire(event))));
5439
+ this._onDidAddPanel.fire({ panel });
5422
5440
  }
5423
- // TODO slightly hacky by-pass of the component to create a body and header component
5424
- getComponent() {
5425
- return {
5426
- update: (params) => {
5427
- var _a, _b;
5428
- (_a = this.bodyPart) === null || _a === void 0 ? void 0 : _a.update({ params });
5429
- (_b = this.headerPart) === null || _b === void 0 ? void 0 : _b.update({ params });
5430
- },
5431
- dispose: () => {
5432
- var _a, _b;
5433
- (_a = this.bodyPart) === null || _a === void 0 ? void 0 : _a.dispose();
5434
- (_b = this.headerPart) === null || _b === void 0 ? void 0 : _b.dispose();
5435
- },
5436
- };
5441
+ doSetActivePanel(panel) {
5442
+ if (this._activePanel === panel) {
5443
+ return;
5444
+ }
5445
+ this._activePanel = panel;
5446
+ if (panel) {
5447
+ this.tabsContainer.setActivePanel(panel);
5448
+ panel.layout(this._width, this._height);
5449
+ this.updateMru(panel);
5450
+ this._onDidActivePanelChange.fire({
5451
+ panel,
5452
+ });
5453
+ }
5437
5454
  }
5438
- }
5439
-
5440
- class DraggablePaneviewPanel extends PaneviewPanel {
5441
- constructor(accessor, id, component, headerComponent, orientation, isExpanded, disableDnd) {
5442
- super(id, component, headerComponent, orientation, isExpanded, true);
5443
- this.accessor = accessor;
5444
- this._onDidDrop = new Emitter();
5445
- this.onDidDrop = this._onDidDrop.event;
5446
- if (!disableDnd) {
5447
- this.initDragFeatures();
5455
+ updateMru(panel) {
5456
+ if (this.mostRecentlyUsed.includes(panel)) {
5457
+ this.mostRecentlyUsed.splice(this.mostRecentlyUsed.indexOf(panel), 1);
5448
5458
  }
5459
+ this.mostRecentlyUsed = [panel, ...this.mostRecentlyUsed];
5449
5460
  }
5450
- initDragFeatures() {
5451
- if (!this.header) {
5461
+ updateContainer() {
5462
+ var _a, _b;
5463
+ toggleClass(this.container, 'empty', this.isEmpty);
5464
+ this.panels.forEach((panel) => panel.runEvents());
5465
+ if (this.isEmpty && !this.watermark) {
5466
+ const watermark = this.accessor.createWatermarkComponent();
5467
+ watermark.init({
5468
+ containerApi: this._api,
5469
+ group: this.groupPanel,
5470
+ });
5471
+ this.watermark = watermark;
5472
+ addDisposableListener(this.watermark.element, 'click', () => {
5473
+ if (!this.isActive) {
5474
+ this.accessor.doSetGroupActive(this.groupPanel);
5475
+ }
5476
+ });
5477
+ this.tabsContainer.hide();
5478
+ this.contentContainer.element.appendChild(this.watermark.element);
5479
+ this.watermark.updateParentGroup(this.groupPanel, true);
5480
+ }
5481
+ if (!this.isEmpty && this.watermark) {
5482
+ this.watermark.element.remove();
5483
+ (_b = (_a = this.watermark).dispose) === null || _b === void 0 ? void 0 : _b.call(_a);
5484
+ this.watermark = undefined;
5485
+ this.tabsContainer.show();
5486
+ }
5487
+ }
5488
+ canDisplayOverlay(event, position, target) {
5489
+ const firedEvent = new DockviewUnhandledDragOverEvent(event, target, position, getPanelData, this.accessor.getPanel(this.id));
5490
+ this._onUnhandledDragOverEvent.fire(firedEvent);
5491
+ return firedEvent.isAccepted;
5492
+ }
5493
+ handleDropEvent(type, event, position, index) {
5494
+ if (this.locked === 'no-drop-target') {
5452
5495
  return;
5453
5496
  }
5454
- const id = this.id;
5455
- const accessorId = this.accessor.id;
5456
- this.header.draggable = true;
5457
- this.handler = new (class PaneDragHandler extends DragHandler {
5458
- getData() {
5459
- LocalSelectionTransfer.getInstance().setData([new PaneTransfer(accessorId, id)], PaneTransfer.prototype);
5460
- return {
5461
- dispose: () => {
5462
- LocalSelectionTransfer.getInstance().clearData(PaneTransfer.prototype);
5463
- },
5464
- };
5497
+ function getKind() {
5498
+ switch (type) {
5499
+ case 'header':
5500
+ return typeof index === 'number' ? 'tab' : 'header_space';
5501
+ case 'content':
5502
+ return 'content';
5465
5503
  }
5466
- })(this.header);
5467
- this.target = new Droptarget(this.element, {
5468
- acceptedTargetZones: ['top', 'bottom'],
5469
- overlayModel: {
5470
- activationSize: { type: 'percentage', value: 50 },
5471
- },
5472
- canDisplayOverlay: (event) => {
5473
- const data = getPaneData();
5474
- if (data) {
5475
- if (data.paneId !== this.id &&
5476
- data.viewId === this.accessor.id) {
5477
- return true;
5478
- }
5479
- }
5480
- if (this.accessor.options.showDndOverlay) {
5481
- return this.accessor.options.showDndOverlay({
5482
- nativeEvent: event,
5483
- getData: getPaneData,
5484
- panel: this,
5485
- });
5486
- }
5487
- return false;
5488
- },
5504
+ }
5505
+ const panel = typeof index === 'number' ? this.panels[index] : undefined;
5506
+ const willDropEvent = new DockviewWillDropEvent({
5507
+ nativeEvent: event,
5508
+ position,
5509
+ panel,
5510
+ getData: () => getPanelData(),
5511
+ kind: getKind(),
5512
+ group: this.groupPanel,
5513
+ api: this._api,
5489
5514
  });
5490
- this.addDisposables(this._onDidDrop, this.handler, this.target, this.target.onDrop((event) => {
5491
- this.onDrop(event);
5492
- }));
5493
- }
5494
- onDrop(event) {
5495
- const data = getPaneData();
5496
- if (!data || data.viewId !== this.accessor.id) {
5497
- // if there is no local drag event for this panel
5498
- // or if the drag event was creating by another Paneview instance
5499
- this._onDidDrop.fire(Object.assign(Object.assign({}, event), { panel: this, api: new PaneviewApi(this.accessor), getData: getPaneData }));
5515
+ this._onWillDrop.fire(willDropEvent);
5516
+ if (willDropEvent.defaultPrevented) {
5500
5517
  return;
5501
5518
  }
5502
- const containerApi = this._params
5503
- .containerApi;
5504
- const panelId = data.paneId;
5505
- const existingPanel = containerApi.getPanel(panelId);
5506
- if (!existingPanel) {
5507
- // if the panel doesn't exist
5508
- this._onDidDrop.fire(Object.assign(Object.assign({}, event), { panel: this, getData: getPaneData, api: new PaneviewApi(this.accessor) }));
5509
- return;
5519
+ const data = getPanelData();
5520
+ if (data && data.viewId === this.accessor.id) {
5521
+ if (data.panelId === null) {
5522
+ // this is a group move dnd event
5523
+ const { groupId } = data;
5524
+ this._onMove.fire({
5525
+ target: position,
5526
+ groupId: groupId,
5527
+ index,
5528
+ });
5529
+ return;
5530
+ }
5531
+ const fromSameGroup = this.tabsContainer.indexOf(data.panelId) !== -1;
5532
+ if (fromSameGroup && this.tabsContainer.size === 1) {
5533
+ return;
5534
+ }
5535
+ const { groupId, panelId } = data;
5536
+ const isSameGroup = this.id === groupId;
5537
+ if (isSameGroup && !position) {
5538
+ const oldIndex = this.tabsContainer.indexOf(panelId);
5539
+ if (oldIndex === index) {
5540
+ return;
5541
+ }
5542
+ }
5543
+ this._onMove.fire({
5544
+ target: position,
5545
+ groupId: data.groupId,
5546
+ itemId: data.panelId,
5547
+ index,
5548
+ });
5510
5549
  }
5511
- const allPanels = containerApi.panels;
5512
- const fromIndex = allPanels.indexOf(existingPanel);
5513
- let toIndex = containerApi.panels.indexOf(this);
5514
- if (event.position === 'left' || event.position === 'top') {
5515
- toIndex = Math.max(0, toIndex - 1);
5550
+ else {
5551
+ this._onDidDrop.fire(new DockviewDidDropEvent({
5552
+ nativeEvent: event,
5553
+ position,
5554
+ panel,
5555
+ getData: () => getPanelData(),
5556
+ group: this.groupPanel,
5557
+ api: this._api,
5558
+ }));
5516
5559
  }
5517
- if (event.position === 'right' || event.position === 'bottom') {
5518
- if (fromIndex > toIndex) {
5519
- toIndex++;
5520
- }
5521
- toIndex = Math.min(allPanels.length - 1, toIndex);
5560
+ }
5561
+ dispose() {
5562
+ var _a, _b, _c;
5563
+ super.dispose();
5564
+ (_a = this.watermark) === null || _a === void 0 ? void 0 : _a.element.remove();
5565
+ (_c = (_b = this.watermark) === null || _b === void 0 ? void 0 : _b.dispose) === null || _c === void 0 ? void 0 : _c.call(_b);
5566
+ this.watermark = undefined;
5567
+ for (const panel of this.panels) {
5568
+ panel.dispose();
5522
5569
  }
5523
- containerApi.movePanel(fromIndex, toIndex);
5570
+ this.tabsContainer.dispose();
5571
+ this.contentContainer.dispose();
5524
5572
  }
5525
5573
  }
5526
5574
 
@@ -5707,9 +5755,12 @@ class DockviewGroupPanelApiImpl extends GridviewPanelApiImpl {
5707
5755
  constructor(id, accessor) {
5708
5756
  super(id, '__dockviewgroup__');
5709
5757
  this.accessor = accessor;
5758
+ this._mutableDisposable = new MutableDisposable();
5710
5759
  this._onDidLocationChange = new Emitter();
5711
5760
  this.onDidLocationChange = this._onDidLocationChange.event;
5712
- this.addDisposables(this._onDidLocationChange);
5761
+ this._onDidActivePanelChange = new Emitter();
5762
+ this.onDidActivePanelChange = this._onDidActivePanelChange.event;
5763
+ this.addDisposables(this._onDidLocationChange, this._onDidActivePanelChange, this._mutableDisposable);
5713
5764
  }
5714
5765
  close() {
5715
5766
  if (!this._group) {
@@ -5767,6 +5818,19 @@ class DockviewGroupPanelApiImpl extends GridviewPanelApiImpl {
5767
5818
  }
5768
5819
  initialize(group) {
5769
5820
  this._group = group;
5821
+ /**
5822
+ * TODO: Annoying initialization order caveat
5823
+ *
5824
+ * Due to the order on initialization we know that the model isn't defined until later in the same stack-frame of setup.
5825
+ * By queuing a microtask we can ensure the setup is completed within the same stack-frame, but after everything else has
5826
+ * finished ensuring the `model` is defined.
5827
+ */
5828
+ queueMicrotask(() => {
5829
+ this._mutableDisposable.value =
5830
+ this._group.model.onDidActivePanelChange((event) => {
5831
+ this._onDidActivePanelChange.fire(event);
5832
+ });
5833
+ });
5770
5834
  }
5771
5835
  }
5772
5836
 
@@ -5827,31 +5891,6 @@ class DockviewGroupPanel extends GridviewPanel {
5827
5891
  }
5828
5892
  }
5829
5893
 
5830
- function isPanelOptionsWithPanel(data) {
5831
- if (data.referencePanel) {
5832
- return true;
5833
- }
5834
- return false;
5835
- }
5836
- function isPanelOptionsWithGroup(data) {
5837
- if (data.referenceGroup) {
5838
- return true;
5839
- }
5840
- return false;
5841
- }
5842
- function isGroupOptionsWithPanel(data) {
5843
- if (data.referencePanel) {
5844
- return true;
5845
- }
5846
- return false;
5847
- }
5848
- function isGroupOptionsWithGroup(data) {
5849
- if (data.referenceGroup) {
5850
- return true;
5851
- }
5852
- return false;
5853
- }
5854
-
5855
5894
  class DockviewPanelApiImpl extends GridviewPanelApiImpl {
5856
5895
  get location() {
5857
5896
  return this.group.api.location;
@@ -6219,7 +6258,7 @@ class DockviewPanelModel {
6219
6258
  this._tab = this.createTabComponent(this.id, tabComponent);
6220
6259
  }
6221
6260
  init(params) {
6222
- this.content.init(Object.assign(Object.assign({}, params), { tab: this.tab }));
6261
+ this.content.init(params);
6223
6262
  this.tab.init(params);
6224
6263
  }
6225
6264
  updateParentGroup(_group, _isPanelVisible) {
@@ -6240,20 +6279,29 @@ class DockviewPanelModel {
6240
6279
  (_d = (_c = this.tab).dispose) === null || _d === void 0 ? void 0 : _d.call(_c);
6241
6280
  }
6242
6281
  createContentComponent(id, componentName) {
6243
- var _a, _b;
6244
- return createComponent(id, componentName, (_a = this.accessor.options.components) !== null && _a !== void 0 ? _a : {}, this.accessor.options.frameworkComponents, (_b = this.accessor.options.frameworkComponentFactory) === null || _b === void 0 ? void 0 : _b.content);
6282
+ return this.accessor.options.createComponent({
6283
+ id,
6284
+ name: componentName,
6285
+ });
6245
6286
  }
6246
6287
  createTabComponent(id, componentName) {
6247
- var _a, _b;
6248
- if (componentName) {
6249
- return createComponent(id, componentName, this.accessor.options.tabComponents, this.accessor.options.frameworkTabComponents, (_a = this.accessor.options.frameworkComponentFactory) === null || _a === void 0 ? void 0 : _a.tab, () => new DefaultTab());
6250
- }
6251
- else if (this.accessor.options.defaultTabComponent) {
6252
- return createComponent(id, this.accessor.options.defaultTabComponent, this.accessor.options.tabComponents, this.accessor.options.frameworkTabComponents, (_b = this.accessor.options.frameworkComponentFactory) === null || _b === void 0 ? void 0 : _b.tab, () => new DefaultTab());
6253
- }
6254
- else {
6255
- return new DefaultTab();
6288
+ const name = componentName !== null && componentName !== void 0 ? componentName : this.accessor.options.defaultTabComponent;
6289
+ if (name) {
6290
+ if (this.accessor.options.createTabComponent) {
6291
+ const component = this.accessor.options.createTabComponent({
6292
+ id,
6293
+ name,
6294
+ });
6295
+ if (component) {
6296
+ return component;
6297
+ }
6298
+ else {
6299
+ return new DefaultTab();
6300
+ }
6301
+ }
6302
+ console.warn(`dockview: tabComponent '${componentName}' was not found. falling back to the default tab.`);
6256
6303
  }
6304
+ return new DefaultTab();
6257
6305
  }
6258
6306
  }
6259
6307
 
@@ -7013,11 +7061,13 @@ class DockviewComponent extends BaseGrid {
7013
7061
  return this._api;
7014
7062
  }
7015
7063
  constructor(options) {
7016
- var _a, _b;
7064
+ var _a;
7017
7065
  super({
7018
7066
  proportionalLayout: true,
7019
- orientation: (_a = options.orientation) !== null && _a !== void 0 ? _a : exports.Orientation.HORIZONTAL,
7020
- styles: options.styles,
7067
+ orientation: exports.Orientation.HORIZONTAL,
7068
+ styles: options.hideBorders
7069
+ ? { separatorBorder: 'transparent' }
7070
+ : undefined,
7021
7071
  parentElement: options.parentElement,
7022
7072
  disableAutoResizing: options.disableAutoResizing,
7023
7073
  locked: options.locked,
@@ -7035,6 +7085,8 @@ class DockviewComponent extends BaseGrid {
7035
7085
  this.onWillDrop = this._onWillDrop.event;
7036
7086
  this._onWillShowOverlay = new Emitter();
7037
7087
  this.onWillShowOverlay = this._onWillShowOverlay.event;
7088
+ this._onUnhandledDragOverEvent = new Emitter();
7089
+ this.onUnhandledDragOverEvent = this._onUnhandledDragOverEvent.event;
7038
7090
  this._onDidRemovePanel = new Emitter();
7039
7091
  this.onDidRemovePanel = this._onDidRemovePanel.event;
7040
7092
  this._onDidAddPanel = new Emitter();
@@ -7060,7 +7112,7 @@ class DockviewComponent extends BaseGrid {
7060
7112
  this.overlayRenderContainer = new OverlayRenderContainer(gready);
7061
7113
  toggleClass(this.gridview.element, 'dv-dockview', true);
7062
7114
  toggleClass(this.element, 'dv-debug', !!options.debug);
7063
- 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.onDidAdd((event) => {
7115
+ 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) => {
7064
7116
  if (!this._moving) {
7065
7117
  this._onDidAddGroup.fire(event);
7066
7118
  }
@@ -7087,22 +7139,6 @@ class DockviewComponent extends BaseGrid {
7087
7139
  }
7088
7140
  }));
7089
7141
  this._options = options;
7090
- if (!this.options.components) {
7091
- this.options.components = {};
7092
- }
7093
- if (!this.options.frameworkComponents) {
7094
- this.options.frameworkComponents = {};
7095
- }
7096
- if (!this.options.frameworkTabComponents) {
7097
- this.options.frameworkTabComponents = {};
7098
- }
7099
- if (!this.options.tabComponents) {
7100
- this.options.tabComponents = {};
7101
- }
7102
- if (!this.options.watermarkComponent &&
7103
- !this.options.watermarkFrameworkComponent) {
7104
- this.options.watermarkComponent = Watermark;
7105
- }
7106
7142
  this._rootDropTarget = new Droptarget(this.element, {
7107
7143
  canDisplayOverlay: (event, position) => {
7108
7144
  const data = getPanelData();
@@ -7117,26 +7153,20 @@ class DockviewComponent extends BaseGrid {
7117
7153
  }
7118
7154
  return true;
7119
7155
  }
7120
- if (this.options.showDndOverlay) {
7121
- if (position === 'center' && this.gridview.length !== 0) {
7122
- /**
7123
- * for external events only show the four-corner drag overlays, disable
7124
- * the center position so that external drag events can fall through to the group
7125
- * and panel drop target handlers
7126
- */
7127
- return false;
7128
- }
7129
- return this.options.showDndOverlay({
7130
- nativeEvent: event,
7131
- position: position,
7132
- target: 'edge',
7133
- getData: getPanelData,
7134
- });
7156
+ if (position === 'center' && this.gridview.length !== 0) {
7157
+ /**
7158
+ * for external events only show the four-corner drag overlays, disable
7159
+ * the center position so that external drag events can fall through to the group
7160
+ * and panel drop target handlers
7161
+ */
7162
+ return false;
7135
7163
  }
7136
- return false;
7164
+ const firedEvent = new DockviewUnhandledDragOverEvent(event, 'edge', position, getPanelData);
7165
+ this._onUnhandledDragOverEvent.fire(firedEvent);
7166
+ return firedEvent.isAccepted;
7137
7167
  },
7138
7168
  acceptedTargetZones: ['top', 'bottom', 'left', 'right', 'center'],
7139
- overlayModel: (_b = this.options.rootOverlayModel) !== null && _b !== void 0 ? _b : DEFAULT_ROOT_OVERLAY_MODEL,
7169
+ overlayModel: (_a = this.options.rootOverlayModel) !== null && _a !== void 0 ? _a : DEFAULT_ROOT_OVERLAY_MODEL,
7140
7170
  });
7141
7171
  this.addDisposables(this._rootDropTarget, this._rootDropTarget.onWillShowOverlay((event) => {
7142
7172
  if (this.gridview.length > 0 && event.position === 'center') {
@@ -7360,7 +7390,7 @@ class DockviewComponent extends BaseGrid {
7360
7390
  skipDispose: true,
7361
7391
  skipSetActiveGroup: true,
7362
7392
  }));
7363
- group.model.openPanel(item, { skipSetGroupActive: true });
7393
+ this.movingLock(() => group.model.openPanel(item, { skipSetGroupActive: true }));
7364
7394
  }
7365
7395
  else {
7366
7396
  group = item;
@@ -7433,7 +7463,7 @@ class DockviewComponent extends BaseGrid {
7433
7463
  // this is either a resize or a move
7434
7464
  // to inform the panels .layout(...) the group with it's current size
7435
7465
  // don't care about resize since the above watcher handles that
7436
- group.layout(group.height, group.width);
7466
+ group.layout(group.width, group.height);
7437
7467
  }), overlay.onDidChangeEnd(() => {
7438
7468
  this._bufferOnDidLayoutChange.fire();
7439
7469
  }), group.onDidChange((event) => {
@@ -7488,16 +7518,11 @@ class DockviewComponent extends BaseGrid {
7488
7518
  }
7489
7519
  updateOptions(options) {
7490
7520
  var _a, _b;
7491
- const changed_orientation = typeof options.orientation === 'string' &&
7492
- this.gridview.orientation !== options.orientation;
7493
- const changed_floatingGroupBounds = options.floatingGroupBounds !== undefined &&
7521
+ const changed_floatingGroupBounds = 'floatingGroupBounds' in options &&
7494
7522
  options.floatingGroupBounds !== this.options.floatingGroupBounds;
7495
- const changed_rootOverlayOptions = options.rootOverlayModel !== undefined &&
7523
+ const changed_rootOverlayOptions = 'rootOverlayModel' in options &&
7496
7524
  options.rootOverlayModel !== this.options.rootOverlayModel;
7497
7525
  this._options = Object.assign(Object.assign({}, this.options), options);
7498
- if (changed_orientation) {
7499
- this.gridview.orientation = options.orientation;
7500
- }
7501
7526
  if (changed_floatingGroupBounds) {
7502
7527
  for (const group of this._floatingGroups) {
7503
7528
  switch (this.options.floatingGroupBounds) {
@@ -7785,7 +7810,7 @@ class DockviewComponent extends BaseGrid {
7785
7810
  ? this.getGroupPanel(options.position.referencePanel)
7786
7811
  : options.position.referencePanel;
7787
7812
  if (!referencePanel) {
7788
- throw new Error(`referencePanel ${options.position.referencePanel} does not exist`);
7813
+ throw new Error(`referencePanel '${options.position.referencePanel}' does not exist`);
7789
7814
  }
7790
7815
  referenceGroup = this.findGroup(referencePanel);
7791
7816
  }
@@ -7795,14 +7820,19 @@ class DockviewComponent extends BaseGrid {
7795
7820
  ? (_a = this._groups.get(options.position.referenceGroup)) === null || _a === void 0 ? void 0 : _a.value
7796
7821
  : options.position.referenceGroup;
7797
7822
  if (!referenceGroup) {
7798
- throw new Error(`referencePanel ${options.position.referenceGroup} does not exist`);
7823
+ throw new Error(`referenceGroup '${options.position.referenceGroup}' does not exist`);
7799
7824
  }
7800
7825
  }
7801
7826
  else {
7802
7827
  const group = this.orthogonalize(directionToPosition(options.position.direction));
7803
7828
  const panel = this.createPanel(options, group);
7804
- group.model.openPanel(panel);
7805
- this.doSetGroupAndPanelActive(group);
7829
+ group.model.openPanel(panel, {
7830
+ skipSetActive: options.inactive,
7831
+ skipSetGroupActive: options.inactive,
7832
+ });
7833
+ if (!options.inactive) {
7834
+ this.doSetGroupAndPanelActive(group);
7835
+ }
7806
7836
  return panel;
7807
7837
  }
7808
7838
  }
@@ -7825,43 +7855,64 @@ class DockviewComponent extends BaseGrid {
7825
7855
  skipActiveGroup: true,
7826
7856
  });
7827
7857
  panel = this.createPanel(options, group);
7828
- group.model.openPanel(panel);
7858
+ group.model.openPanel(panel, {
7859
+ skipSetActive: options.inactive,
7860
+ skipSetGroupActive: options.inactive,
7861
+ });
7829
7862
  }
7830
7863
  else if (referenceGroup.api.location.type === 'floating' ||
7831
7864
  target === 'center') {
7832
7865
  panel = this.createPanel(options, referenceGroup);
7833
- referenceGroup.model.openPanel(panel);
7834
- this.doSetGroupAndPanelActive(referenceGroup);
7866
+ referenceGroup.model.openPanel(panel, {
7867
+ skipSetActive: options.inactive,
7868
+ skipSetGroupActive: options.inactive,
7869
+ });
7870
+ if (!options.inactive) {
7871
+ this.doSetGroupAndPanelActive(referenceGroup);
7872
+ }
7835
7873
  }
7836
7874
  else {
7837
7875
  const location = getGridLocation(referenceGroup.element);
7838
7876
  const relativeLocation = getRelativeLocation(this.gridview.orientation, location, target);
7839
7877
  const group = this.createGroupAtLocation(relativeLocation);
7840
7878
  panel = this.createPanel(options, group);
7841
- group.model.openPanel(panel);
7842
- this.doSetGroupAndPanelActive(group);
7879
+ group.model.openPanel(panel, {
7880
+ skipSetActive: options.inactive,
7881
+ skipSetGroupActive: options.inactive,
7882
+ });
7883
+ if (!options.inactive) {
7884
+ this.doSetGroupAndPanelActive(group);
7885
+ }
7843
7886
  }
7844
7887
  }
7845
7888
  else if (options.floating) {
7846
7889
  const group = this.createGroup();
7847
7890
  this._onDidAddGroup.fire(group);
7848
- const o = typeof options.floating === 'object' &&
7891
+ const coordinates = typeof options.floating === 'object' &&
7849
7892
  options.floating !== null
7850
7893
  ? options.floating
7851
7894
  : {};
7852
- this.addFloatingGroup(group, o, {
7895
+ this.addFloatingGroup(group, coordinates, {
7853
7896
  inDragMode: false,
7854
7897
  skipRemoveGroup: true,
7855
7898
  skipActiveGroup: true,
7856
7899
  });
7857
7900
  panel = this.createPanel(options, group);
7858
- group.model.openPanel(panel);
7901
+ group.model.openPanel(panel, {
7902
+ skipSetActive: options.inactive,
7903
+ skipSetGroupActive: options.inactive,
7904
+ });
7859
7905
  }
7860
7906
  else {
7861
7907
  const group = this.createGroupAtLocation();
7862
7908
  panel = this.createPanel(options, group);
7863
- group.model.openPanel(panel);
7864
- this.doSetGroupAndPanelActive(group);
7909
+ group.model.openPanel(panel, {
7910
+ skipSetActive: options.inactive,
7911
+ skipSetGroupActive: options.inactive,
7912
+ });
7913
+ if (!options.inactive) {
7914
+ this.doSetGroupAndPanelActive(group);
7915
+ }
7865
7916
  }
7866
7917
  return panel;
7867
7918
  }
@@ -7885,12 +7936,10 @@ class DockviewComponent extends BaseGrid {
7885
7936
  }
7886
7937
  }
7887
7938
  createWatermarkComponent() {
7888
- var _a;
7889
- return createComponent('watermark-id', 'watermark-name', this.options.watermarkComponent
7890
- ? { 'watermark-name': this.options.watermarkComponent }
7891
- : {}, this.options.watermarkFrameworkComponent
7892
- ? { 'watermark-name': this.options.watermarkFrameworkComponent }
7893
- : {}, (_a = this.options.frameworkComponentFactory) === null || _a === void 0 ? void 0 : _a.watermark);
7939
+ if (this.options.createWatermarkComponent) {
7940
+ return this.options.createWatermarkComponent();
7941
+ }
7942
+ return new Watermark();
7894
7943
  }
7895
7944
  updateWatermark() {
7896
7945
  var _a, _b;
@@ -8271,6 +8320,8 @@ class DockviewComponent extends BaseGrid {
8271
8320
  return;
8272
8321
  }
8273
8322
  this._onWillShowOverlay.fire(event);
8323
+ }), view.model.onUnhandledDragOverEvent((event) => {
8324
+ this._onUnhandledDragOverEvent.fire(event);
8274
8325
  }), view.model.onDidAddPanel((event) => {
8275
8326
  if (this._moving) {
8276
8327
  return;
@@ -9304,6 +9355,7 @@ exports.DockviewGroupPanel = DockviewGroupPanel;
9304
9355
  exports.DockviewGroupPanelModel = DockviewGroupPanelModel;
9305
9356
  exports.DockviewMutableDisposable = MutableDisposable;
9306
9357
  exports.DockviewPanel = DockviewPanel;
9358
+ exports.DockviewUnhandledDragOverEvent = DockviewUnhandledDragOverEvent;
9307
9359
  exports.DockviewWillDropEvent = DockviewWillDropEvent;
9308
9360
  exports.DraggablePaneviewPanel = DraggablePaneviewPanel;
9309
9361
  exports.Gridview = Gridview;
@@ -9311,6 +9363,7 @@ exports.GridviewApi = GridviewApi;
9311
9363
  exports.GridviewComponent = GridviewComponent;
9312
9364
  exports.GridviewPanel = GridviewPanel;
9313
9365
  exports.LocalSelectionTransfer = LocalSelectionTransfer;
9366
+ exports.PROPERTY_KEYS = PROPERTY_KEYS;
9314
9367
  exports.PaneFramework = PaneFramework;
9315
9368
  exports.PaneTransfer = PaneTransfer;
9316
9369
  exports.PanelTransfer = PanelTransfer;