dockview-react 4.0.1 → 4.1.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.
@@ -1,6 +1,6 @@
1
1
  /**
2
2
  * dockview-react
3
- * @version 4.0.1
3
+ * @version 4.1.0
4
4
  * @link https://github.com/mathuo/dockview
5
5
  * @license MIT
6
6
  */
@@ -249,14 +249,6 @@
249
249
  }
250
250
  Emitter.ENABLE_TRACKING = false;
251
251
  Emitter.MEMORY_LEAK_WATCHER = new LeakageMonitor();
252
- function addDisposableWindowListener(element, type, listener, options) {
253
- element.addEventListener(type, listener, options);
254
- return {
255
- dispose: () => {
256
- element.removeEventListener(type, listener, options);
257
- },
258
- };
259
- }
260
252
  function addDisposableListener(element, type, listener, options) {
261
253
  element.addEventListener(type, listener, options);
262
254
  return {
@@ -435,9 +427,6 @@
435
427
  }
436
428
  return false;
437
429
  }
438
- function getElementsByTagName(tag) {
439
- return Array.prototype.slice.call(document.getElementsByTagName(tag), 0);
440
- }
441
430
  function trackFocus(element) {
442
431
  return new FocusTracker(element);
443
432
  }
@@ -484,14 +473,8 @@
484
473
  }
485
474
  }
486
475
  };
487
- if (element instanceof HTMLElement) {
488
- this.addDisposables(addDisposableListener(element, 'focus', onFocus, true));
489
- this.addDisposables(addDisposableListener(element, 'blur', onBlur, true));
490
- }
491
- else {
492
- this.addDisposables(addDisposableWindowListener(element, 'focus', onFocus, true));
493
- this.addDisposables(addDisposableWindowListener(element, 'blur', onBlur, true));
494
- }
476
+ this.addDisposables(addDisposableListener(element, 'focus', onFocus, true));
477
+ this.addDisposables(addDisposableListener(element, 'blur', onBlur, true));
495
478
  }
496
479
  refreshState() {
497
480
  this._refreshStateHandler();
@@ -565,11 +548,30 @@
565
548
  function addTestId(element, id) {
566
549
  element.setAttribute('data-testid', id);
567
550
  }
568
- function disableIframePointEvents() {
569
- const iframes = [
570
- ...getElementsByTagName('iframe'),
571
- ...getElementsByTagName('webview'),
572
- ];
551
+ /**
552
+ * Should be more efficient than element.querySelectorAll("*") since there
553
+ * is no need to store every element in-memory using this approach
554
+ */
555
+ function allTagsNamesInclusiveOfShadowDoms(tagNames) {
556
+ const iframes = [];
557
+ function findIframesInNode(node) {
558
+ if (node.nodeType === Node.ELEMENT_NODE) {
559
+ if (tagNames.includes(node.tagName)) {
560
+ iframes.push(node);
561
+ }
562
+ if (node.shadowRoot) {
563
+ findIframesInNode(node.shadowRoot);
564
+ }
565
+ for (const child of node.children) {
566
+ findIframesInNode(child);
567
+ }
568
+ }
569
+ }
570
+ findIframesInNode(document.documentElement);
571
+ return iframes;
572
+ }
573
+ function disableIframePointEvents(rootNode = document) {
574
+ const iframes = allTagsNamesInclusiveOfShadowDoms(['IFRAME', 'WEBVIEW']);
573
575
  const original = new WeakMap(); // don't hold onto HTMLElement references longer than required
574
576
  for (const iframe of iframes) {
575
577
  original.set(iframe, iframe.style.pointerEvents);
@@ -621,6 +623,7 @@
621
623
  }
622
624
  }
623
625
  }
626
+ const DEBOUCE_DELAY = 100;
624
627
  function isChildEntirelyVisibleWithinParent(child, parent) {
625
628
  //
626
629
  const childPosition = getDomNodePagePosition(child);
@@ -634,6 +637,41 @@
634
637
  }
635
638
  return true;
636
639
  }
640
+ function onDidWindowMoveEnd(window) {
641
+ const emitter = new Emitter();
642
+ let previousScreenX = window.screenX;
643
+ let previousScreenY = window.screenY;
644
+ let timeout;
645
+ const checkMovement = () => {
646
+ if (window.closed) {
647
+ return;
648
+ }
649
+ const currentScreenX = window.screenX;
650
+ const currentScreenY = window.screenY;
651
+ if (currentScreenX !== previousScreenX ||
652
+ currentScreenY !== previousScreenY) {
653
+ clearTimeout(timeout);
654
+ timeout = setTimeout(() => {
655
+ emitter.fire();
656
+ }, DEBOUCE_DELAY);
657
+ previousScreenX = currentScreenX;
658
+ previousScreenY = currentScreenY;
659
+ }
660
+ requestAnimationFrame(checkMovement);
661
+ };
662
+ checkMovement();
663
+ return emitter;
664
+ }
665
+ function onDidWindowResizeEnd(element, cb) {
666
+ let resizeTimeout;
667
+ const disposable = new CompositeDisposable(addDisposableListener(element, 'resize', () => {
668
+ clearTimeout(resizeTimeout);
669
+ resizeTimeout = setTimeout(() => {
670
+ cb();
671
+ }, DEBOUCE_DELAY);
672
+ }));
673
+ return disposable;
674
+ }
637
675
 
638
676
  function tail(arr) {
639
677
  if (arr.length === 0) {
@@ -3573,6 +3611,12 @@
3573
3611
  get onUnhandledDragOverEvent() {
3574
3612
  return this.component.onUnhandledDragOverEvent;
3575
3613
  }
3614
+ get onDidPopoutGroupSizeChange() {
3615
+ return this.component.onDidPopoutGroupSizeChange;
3616
+ }
3617
+ get onDidPopoutGroupPositionChange() {
3618
+ return this.component.onDidPopoutGroupPositionChange;
3619
+ }
3576
3620
  /**
3577
3621
  * All panel objects.
3578
3622
  */
@@ -4538,26 +4582,25 @@
4538
4582
  this._headerVisible = value;
4539
4583
  this.header.style.display = value ? '' : 'none';
4540
4584
  }
4541
- constructor(id, component, headerComponent, orientation, isExpanded, isHeaderVisible) {
4542
- super(id, component, new PaneviewPanelApiImpl(id, component));
4543
- this.headerComponent = headerComponent;
4585
+ constructor(options) {
4586
+ super(options.id, options.component, new PaneviewPanelApiImpl(options.id, options.component));
4544
4587
  this._onDidChangeExpansionState = new Emitter({ replay: true });
4545
4588
  this.onDidChangeExpansionState = this._onDidChangeExpansionState.event;
4546
4589
  this._onDidChange = new Emitter();
4547
4590
  this.onDidChange = this._onDidChange.event;
4548
- this.headerSize = 22;
4549
4591
  this._orthogonalSize = 0;
4550
4592
  this._size = 0;
4551
- this._minimumBodySize = 100;
4552
- this._maximumBodySize = Number.POSITIVE_INFINITY;
4553
4593
  this._isExpanded = false;
4554
- this.expandedSize = 0;
4555
4594
  this.api.pane = this; // TODO cannot use 'this' before 'super'
4556
4595
  this.api.initialize(this);
4557
- this._isExpanded = isExpanded;
4558
- this._headerVisible = isHeaderVisible;
4596
+ this.headerSize = options.headerSize;
4597
+ this.headerComponent = options.headerComponent;
4598
+ this._minimumBodySize = options.minimumBodySize;
4599
+ this._maximumBodySize = options.maximumBodySize;
4600
+ this._isExpanded = options.isExpanded;
4601
+ this._headerVisible = options.isHeaderVisible;
4559
4602
  this._onDidChangeExpansionState.fire(this.isExpanded()); // initialize value
4560
- this._orientation = orientation;
4603
+ this._orientation = options.orientation;
4561
4604
  this.element.classList.add('dv-pane');
4562
4605
  this.addDisposables(this.api.onWillVisibilityChange((event) => {
4563
4606
  const { isVisible } = event;
@@ -4624,9 +4667,6 @@
4624
4667
  const [width, height] = this.orientation === exports.Orientation.HORIZONTAL
4625
4668
  ? [size, orthogonalSize]
4626
4669
  : [orthogonalSize, size];
4627
- if (this.isExpanded()) {
4628
- this.expandedSize = width;
4629
- }
4630
4670
  super.layout(width, height);
4631
4671
  }
4632
4672
  init(parameters) {
@@ -4683,15 +4723,25 @@
4683
4723
  }
4684
4724
 
4685
4725
  class DraggablePaneviewPanel extends PaneviewPanel {
4686
- constructor(accessor, id, component, headerComponent, orientation, isExpanded, disableDnd) {
4687
- super(id, component, headerComponent, orientation, isExpanded, true);
4688
- this.accessor = accessor;
4726
+ constructor(options) {
4727
+ super({
4728
+ id: options.id,
4729
+ component: options.component,
4730
+ headerComponent: options.headerComponent,
4731
+ orientation: options.orientation,
4732
+ isExpanded: options.isExpanded,
4733
+ isHeaderVisible: true,
4734
+ headerSize: options.headerSize,
4735
+ minimumBodySize: options.minimumBodySize,
4736
+ maximumBodySize: options.maximumBodySize,
4737
+ });
4689
4738
  this._onDidDrop = new Emitter();
4690
4739
  this.onDidDrop = this._onDidDrop.event;
4691
4740
  this._onUnhandledDragOverEvent = new Emitter();
4692
4741
  this.onUnhandledDragOverEvent = this._onUnhandledDragOverEvent.event;
4742
+ this.accessor = options.accessor;
4693
4743
  this.addDisposables(this._onDidDrop, this._onUnhandledDragOverEvent);
4694
- if (!disableDnd) {
4744
+ if (!options.disableDnd) {
4695
4745
  this.initDragFeatures();
4696
4746
  }
4697
4747
  }
@@ -7325,7 +7375,7 @@
7325
7375
  dispose: () => {
7326
7376
  iframes.release();
7327
7377
  },
7328
- }, addDisposableWindowListener(window, 'pointermove', (e) => {
7378
+ }, addDisposableListener(window, 'pointermove', (e) => {
7329
7379
  const containerRect = this.options.container.getBoundingClientRect();
7330
7380
  const x = e.clientX - containerRect.left;
7331
7381
  const y = e.clientY - containerRect.top;
@@ -7362,7 +7412,7 @@
7362
7412
  bounds.right = right;
7363
7413
  }
7364
7414
  this.setBounds(bounds);
7365
- }), addDisposableWindowListener(window, 'pointerup', () => {
7415
+ }), addDisposableListener(window, 'pointerup', () => {
7366
7416
  toggleClass(this._element, 'dv-resize-container-dragging', false);
7367
7417
  move.dispose();
7368
7418
  this._onDidChangeEnd.fire();
@@ -7407,7 +7457,7 @@
7407
7457
  e.preventDefault();
7408
7458
  let startPosition = null;
7409
7459
  const iframes = disableIframePointEvents();
7410
- move.value = new CompositeDisposable(addDisposableWindowListener(window, 'pointermove', (e) => {
7460
+ move.value = new CompositeDisposable(addDisposableListener(window, 'pointermove', (e) => {
7411
7461
  const containerRect = this.options.container.getBoundingClientRect();
7412
7462
  const overlayRect = this._element.getBoundingClientRect();
7413
7463
  const y = e.clientY - containerRect.top;
@@ -7531,7 +7581,7 @@
7531
7581
  dispose: () => {
7532
7582
  iframes.release();
7533
7583
  },
7534
- }, addDisposableWindowListener(window, 'pointerup', () => {
7584
+ }, addDisposableListener(window, 'pointerup', () => {
7535
7585
  move.dispose();
7536
7586
  this._onDidChangeEnd.fire();
7537
7587
  }));
@@ -7814,7 +7864,7 @@
7814
7864
  this._window = { value: externalWindow, disposable };
7815
7865
  disposable.addDisposables(exports.DockviewDisposable.from(() => {
7816
7866
  externalWindow.close();
7817
- }), addDisposableWindowListener(window, 'beforeunload', () => {
7867
+ }), addDisposableListener(window, 'beforeunload', () => {
7818
7868
  /**
7819
7869
  * before the main window closes we should close this popup too
7820
7870
  * to be good citizens
@@ -7849,7 +7899,7 @@
7849
7899
  * beforeunload must be registered after load for reasons I could not determine
7850
7900
  * otherwise the beforeunload event will not fire when the window is closed
7851
7901
  */
7852
- addDisposableWindowListener(externalWindow, 'beforeunload', () => {
7902
+ addDisposableListener(externalWindow, 'beforeunload', () => {
7853
7903
  /**
7854
7904
  * @see https://developer.mozilla.org/en-US/docs/Web/API/Window/beforeunload_event
7855
7905
  */
@@ -7946,7 +7996,7 @@
7946
7996
  wrapper.style.left = `${position.x - offsetX}px`;
7947
7997
  this._element.appendChild(wrapper);
7948
7998
  this._active = wrapper;
7949
- this._activeDisposable.value = new CompositeDisposable(addDisposableWindowListener(window, 'pointerdown', (event) => {
7999
+ this._activeDisposable.value = new CompositeDisposable(addDisposableListener(window, 'pointerdown', (event) => {
7950
8000
  var _a;
7951
8001
  const target = event.target;
7952
8002
  if (!(target instanceof HTMLElement)) {
@@ -8125,6 +8175,10 @@
8125
8175
  this.onDidRemovePanel = this._onDidRemovePanel.event;
8126
8176
  this._onDidAddPanel = new Emitter();
8127
8177
  this.onDidAddPanel = this._onDidAddPanel.event;
8178
+ this._onDidPopoutGroupSizeChange = new Emitter();
8179
+ this.onDidPopoutGroupSizeChange = this._onDidPopoutGroupSizeChange.event;
8180
+ this._onDidPopoutGroupPositionChange = new Emitter();
8181
+ this.onDidPopoutGroupPositionChange = this._onDidPopoutGroupPositionChange.event;
8128
8182
  this._onDidLayoutFromJSON = new Emitter();
8129
8183
  this.onDidLayoutFromJSON = this._onDidLayoutFromJSON.event;
8130
8184
  this._onDidActivePanelChange = new Emitter();
@@ -8154,7 +8208,7 @@
8154
8208
  if (options.debug) {
8155
8209
  this.addDisposables(new StrictEventsSequencing(this));
8156
8210
  }
8157
- this.addDisposables(this.rootDropTargetContainer, 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._onDidMaximizedGroupChange, this._onDidOptionsChange, this.onDidViewVisibilityChangeMicroTaskQueue(() => {
8211
+ this.addDisposables(this.rootDropTargetContainer, 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._onDidMaximizedGroupChange, this._onDidOptionsChange, this._onDidPopoutGroupSizeChange, this._onDidPopoutGroupPositionChange, this.onDidViewVisibilityChangeMicroTaskQueue(() => {
8158
8212
  this.updateWatermark();
8159
8213
  }), this.onDidAdd((event) => {
8160
8214
  if (!this._moving) {
@@ -8175,7 +8229,7 @@
8175
8229
  });
8176
8230
  }), exports.DockviewEvent.any(this.onDidAdd, this.onDidRemove)(() => {
8177
8231
  this.updateWatermark();
8178
- }), exports.DockviewEvent.any(this.onDidAddPanel, this.onDidRemovePanel, this.onDidAddGroup, this.onDidRemove, this.onDidMovePanel, this.onDidActivePanelChange)(() => {
8232
+ }), exports.DockviewEvent.any(this.onDidAddPanel, this.onDidRemovePanel, this.onDidAddGroup, this.onDidRemove, this.onDidMovePanel, this.onDidActivePanelChange, this.onDidPopoutGroupPositionChange, this.onDidPopoutGroupSizeChange)(() => {
8179
8233
  this._bufferOnDidLayoutChange.fire();
8180
8234
  }), exports.DockviewDisposable.from(() => {
8181
8235
  // iterate over a copy of the array since .dispose() mutates the original array
@@ -8436,13 +8490,26 @@
8436
8490
  },
8437
8491
  },
8438
8492
  };
8439
- popoutWindowDisposable.addDisposables(
8493
+ const _onDidWindowPositionChange = onDidWindowMoveEnd(_window.window);
8494
+ popoutWindowDisposable.addDisposables(_onDidWindowPositionChange, onDidWindowResizeEnd(_window.window, () => {
8495
+ this._onDidPopoutGroupSizeChange.fire({
8496
+ width: _window.window.innerWidth,
8497
+ height: _window.window.innerHeight,
8498
+ group,
8499
+ });
8500
+ }), _onDidWindowPositionChange.event(() => {
8501
+ this._onDidPopoutGroupPositionChange.fire({
8502
+ screenX: _window.window.screenX,
8503
+ screenY: _window.window.screenX,
8504
+ group,
8505
+ });
8506
+ }),
8440
8507
  /**
8441
8508
  * ResizeObserver seems slow here, I do not know why but we don't need it
8442
8509
  * since we can reply on the window resize event as we will occupy the full
8443
8510
  * window dimensions
8444
8511
  */
8445
- addDisposableWindowListener(_window.window, 'resize', () => {
8512
+ addDisposableListener(_window.window, 'resize', () => {
8446
8513
  group.layout(_window.window.innerWidth, _window.window.innerHeight);
8447
8514
  }), overlayRenderContainer, exports.DockviewDisposable.from(() => {
8448
8515
  if (this.isDisposed) {
@@ -8656,7 +8723,7 @@
8656
8723
  }
8657
8724
  this.updateWatermark();
8658
8725
  }
8659
- orthogonalize(position) {
8726
+ orthogonalize(position, options) {
8660
8727
  switch (position) {
8661
8728
  case 'top':
8662
8729
  case 'bottom':
@@ -8679,10 +8746,10 @@
8679
8746
  case 'top':
8680
8747
  case 'left':
8681
8748
  case 'center':
8682
- return this.createGroupAtLocation([0]); // insert into first position
8749
+ return this.createGroupAtLocation([0], undefined, options); // insert into first position
8683
8750
  case 'bottom':
8684
8751
  case 'right':
8685
- return this.createGroupAtLocation([this.gridview.length]); // insert into last position
8752
+ return this.createGroupAtLocation([this.gridview.length], undefined, options); // insert into last position
8686
8753
  default:
8687
8754
  throw new Error(`unsupported position ${position}`);
8688
8755
  }
@@ -9178,7 +9245,7 @@
9178
9245
  }
9179
9246
  }
9180
9247
  else {
9181
- const group = this.orthogonalize(directionToPosition(options.direction));
9248
+ const group = this.orthogonalize(directionToPosition(options.direction), options);
9182
9249
  if (!options.skipSetActive) {
9183
9250
  this.doSetGroupAndPanelActive(group);
9184
9251
  }
@@ -9620,8 +9687,8 @@
9620
9687
  });
9621
9688
  return panel;
9622
9689
  }
9623
- createGroupAtLocation(location, size) {
9624
- const group = this.createGroup();
9690
+ createGroupAtLocation(location, size, options) {
9691
+ const group = this.createGroup(options);
9625
9692
  this.doAddGroup(group, location, size);
9626
9693
  return group;
9627
9694
  }
@@ -9955,6 +10022,9 @@
9955
10022
  return this._splitview;
9956
10023
  }
9957
10024
  set splitview(value) {
10025
+ if (this._splitview) {
10026
+ this._splitview.dispose();
10027
+ }
9958
10028
  this._splitview = value;
9959
10029
  this._splitviewChangeDisposable.value = new CompositeDisposable(this._splitview.onDidSashEnd(() => {
9960
10030
  this._onDidLayoutChange.fire(undefined);
@@ -10258,9 +10328,23 @@
10258
10328
  }
10259
10329
 
10260
10330
  const nextLayoutId = sequentialNumberGenerator();
10331
+ const HEADER_SIZE = 22;
10332
+ const MINIMUM_BODY_SIZE = 0;
10333
+ const MAXIMUM_BODY_SIZE = Number.MAX_SAFE_INTEGER;
10261
10334
  class PaneFramework extends DraggablePaneviewPanel {
10262
10335
  constructor(options) {
10263
- super(options.accessor, options.id, options.component, options.headerComponent, options.orientation, options.isExpanded, options.disableDnd);
10336
+ super({
10337
+ accessor: options.accessor,
10338
+ id: options.id,
10339
+ component: options.component,
10340
+ headerComponent: options.headerComponent,
10341
+ orientation: options.orientation,
10342
+ isExpanded: options.isExpanded,
10343
+ disableDnd: options.disableDnd,
10344
+ headerSize: options.headerSize,
10345
+ minimumBodySize: options.minimumBodySize,
10346
+ maximumBodySize: options.maximumBodySize,
10347
+ });
10264
10348
  this.options = options;
10265
10349
  }
10266
10350
  getBodyComponent() {
@@ -10355,7 +10439,7 @@
10355
10439
  this._options = Object.assign(Object.assign({}, this.options), options);
10356
10440
  }
10357
10441
  addPanel(options) {
10358
- var _a;
10442
+ var _a, _b;
10359
10443
  const body = this.options.createComponent({
10360
10444
  id: options.id,
10361
10445
  name: options.component,
@@ -10380,12 +10464,15 @@
10380
10464
  isExpanded: !!options.isExpanded,
10381
10465
  disableDnd: !!this.options.disableDnd,
10382
10466
  accessor: this,
10467
+ headerSize: (_a = options.headerSize) !== null && _a !== void 0 ? _a : HEADER_SIZE,
10468
+ minimumBodySize: MINIMUM_BODY_SIZE,
10469
+ maximumBodySize: MAXIMUM_BODY_SIZE,
10383
10470
  });
10384
10471
  this.doAddPanel(view);
10385
10472
  const size = typeof options.size === 'number' ? options.size : exports.Sizing.Distribute;
10386
10473
  const index = typeof options.index === 'number' ? options.index : undefined;
10387
10474
  view.init({
10388
- params: (_a = options.params) !== null && _a !== void 0 ? _a : {},
10475
+ params: (_b = options.params) !== null && _b !== void 0 ? _b : {},
10389
10476
  minimumBodySize: options.minimumBodySize,
10390
10477
  maximumBodySize: options.maximumBodySize,
10391
10478
  isExpanded: options.isExpanded,
@@ -10430,6 +10517,7 @@
10430
10517
  data: view.toJSON(),
10431
10518
  minimumSize: minimum(view.minimumBodySize),
10432
10519
  maximumSize: maximum(view.maximumBodySize),
10520
+ headerSize: view.headerSize,
10433
10521
  expanded: view.isExpanded(),
10434
10522
  };
10435
10523
  });
@@ -10450,6 +10538,7 @@
10450
10538
  descriptor: {
10451
10539
  size,
10452
10540
  views: views.map((view) => {
10541
+ var _a, _b, _c;
10453
10542
  const data = view.data;
10454
10543
  const body = this.options.createComponent({
10455
10544
  id: data.id,
@@ -10476,6 +10565,9 @@
10476
10565
  isExpanded: !!view.expanded,
10477
10566
  disableDnd: !!this.options.disableDnd,
10478
10567
  accessor: this,
10568
+ headerSize: (_a = view.headerSize) !== null && _a !== void 0 ? _a : HEADER_SIZE,
10569
+ minimumBodySize: (_b = view.minimumSize) !== null && _b !== void 0 ? _b : MINIMUM_BODY_SIZE,
10570
+ maximumBodySize: (_c = view.maximumSize) !== null && _c !== void 0 ? _c : MAXIMUM_BODY_SIZE,
10479
10571
  });
10480
10572
  this.doAddPanel(panel);
10481
10573
  queue.push(() => {