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