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