@ckeditor/ckeditor5-ui 45.0.0-alpha.6 → 45.0.0-alpha.8

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.
package/dist/index.js CHANGED
@@ -15660,69 +15660,61 @@ const toPx$3 = /* #__PURE__ */ toUnit('px');
15660
15660
  this.listenTo(this, 'change:isActive', ()=>{
15661
15661
  this.checkIfShouldBeSticky();
15662
15662
  });
15663
+ if ((env.isiOS || env.isSafari) && global.window.visualViewport) {
15664
+ this.listenTo(global.window.visualViewport, 'scroll', ()=>{
15665
+ this.checkIfShouldBeSticky();
15666
+ });
15667
+ this.listenTo(global.window.visualViewport, 'resize', ()=>{
15668
+ this.checkIfShouldBeSticky();
15669
+ });
15670
+ }
15663
15671
  }
15664
15672
  /**
15665
15673
  * Analyzes the environment to decide whether the panel should be sticky or not.
15666
15674
  * Then handles the positioning of the panel.
15667
15675
  */ checkIfShouldBeSticky() {
15668
- // @if CK_DEBUG_STICKYPANEL // RectDrawer.clear();
15669
15676
  if (!this.limiterElement || !this.isActive) {
15670
15677
  this._unstick();
15671
15678
  return;
15672
15679
  }
15680
+ const { left: visualViewportOffsetLeft, top: visualViewportOffsetTop } = this._getVisualViewportOffset();
15673
15681
  const limiterRect = new Rect(this.limiterElement);
15674
15682
  let visibleLimiterRect = limiterRect.getVisible();
15675
15683
  if (visibleLimiterRect) {
15676
15684
  const windowRect = new Rect(global.window);
15677
- windowRect.top += this.viewportTopOffset;
15678
- windowRect.height -= this.viewportTopOffset;
15685
+ let viewportTopOffset = this.viewportTopOffset;
15686
+ if (env.isiOS || env.isSafari) {
15687
+ // Adjust the viewport top offset to height visible in the visual viewport.
15688
+ viewportTopOffset = visualViewportOffsetTop > this.viewportTopOffset ? 0 : this.viewportTopOffset - visualViewportOffsetTop;
15689
+ }
15690
+ windowRect.top += viewportTopOffset;
15691
+ windowRect.height -= viewportTopOffset;
15679
15692
  visibleLimiterRect = visibleLimiterRect.getIntersection(windowRect);
15680
15693
  }
15681
- // @if CK_DEBUG_STICKYPANEL // if ( visibleLimiterRect ) {
15682
- // @if CK_DEBUG_STICKYPANEL // RectDrawer.draw( visibleLimiterRect,
15683
- // @if CK_DEBUG_STICKYPANEL // { outlineWidth: '3px', opacity: '.8', outlineColor: 'red', outlineOffset: '-3px' },
15684
- // @if CK_DEBUG_STICKYPANEL // 'Visible anc'
15685
- // @if CK_DEBUG_STICKYPANEL // );
15686
- // @if CK_DEBUG_STICKYPANEL // }
15687
- // @if CK_DEBUG_STICKYPANEL //
15688
- // @if CK_DEBUG_STICKYPANEL // RectDrawer.draw( limiterRect,
15689
- // @if CK_DEBUG_STICKYPANEL // { outlineWidth: '3px', opacity: '.8', outlineColor: 'green', outlineOffset: '-3px' },
15690
- // @if CK_DEBUG_STICKYPANEL // 'Limiter'
15691
- // @if CK_DEBUG_STICKYPANEL // );
15694
+ limiterRect.moveBy(visualViewportOffsetLeft, visualViewportOffsetTop);
15695
+ if (visibleLimiterRect) {
15696
+ visibleLimiterRect.moveBy(visualViewportOffsetLeft, visualViewportOffsetTop);
15697
+ }
15692
15698
  // Stick the panel only if
15693
15699
  // * the limiter's ancestors are intersecting with each other so that some of their rects are visible,
15694
15700
  // * and the limiter's top edge is above the visible ancestors' top edge.
15695
15701
  if (visibleLimiterRect && limiterRect.top < visibleLimiterRect.top) {
15696
- // @if CK_DEBUG_STICKYPANEL // RectDrawer.draw( visibleLimiterRect,
15697
- // @if CK_DEBUG_STICKYPANEL // { outlineWidth: '3px', opacity: '.8', outlineColor: 'fuchsia', outlineOffset: '-3px',
15698
- // @if CK_DEBUG_STICKYPANEL // backgroundColor: 'rgba(255, 0, 255, .3)' },
15699
- // @if CK_DEBUG_STICKYPANEL // 'Visible limiter'
15700
- // @if CK_DEBUG_STICKYPANEL // );
15701
15702
  const visibleLimiterTop = visibleLimiterRect.top;
15702
15703
  // Check if there's a change the panel can be sticky to the bottom of the limiter.
15703
15704
  if (visibleLimiterTop + this._contentPanelRect.height + this.limiterBottomOffset > visibleLimiterRect.bottom) {
15704
15705
  const stickyBottomOffset = Math.max(limiterRect.bottom - visibleLimiterRect.bottom, 0) + this.limiterBottomOffset;
15705
- // @if CK_DEBUG_STICKYPANEL // const stickyBottomOffsetRect = new Rect( {
15706
- // @if CK_DEBUG_STICKYPANEL // top: limiterRect.bottom - stickyBottomOffset, left: 0, right: 2000,
15707
- // @if CK_DEBUG_STICKYPANEL // bottom: limiterRect.bottom - stickyBottomOffset, width: 2000, height: 1
15708
- // @if CK_DEBUG_STICKYPANEL // } );
15709
- // @if CK_DEBUG_STICKYPANEL // RectDrawer.draw( stickyBottomOffsetRect,
15710
- // @if CK_DEBUG_STICKYPANEL // { outlineWidth: '1px', opacity: '.8', outlineColor: 'black' },
15711
- // @if CK_DEBUG_STICKYPANEL // 'Sticky bottom offset'
15712
- // @if CK_DEBUG_STICKYPANEL // );
15713
15706
  // Check if sticking the panel to the bottom of the limiter does not cause it to suddenly
15714
15707
  // move upwards if there's not enough space for it.
15715
- if (limiterRect.bottom - stickyBottomOffset > limiterRect.top + this._contentPanelRect.height) {
15708
+ // Adding 1 avoids rounding problems and toolbar flickering when offset almost equals the height.
15709
+ if (limiterRect.bottom - stickyBottomOffset > limiterRect.top + this._contentPanelRect.height + 1) {
15716
15710
  this._stickToBottomOfLimiter(stickyBottomOffset);
15717
15711
  } else {
15718
15712
  this._unstick();
15719
15713
  }
15714
+ } else if (this._contentPanelRect.height + this.limiterBottomOffset < limiterRect.height) {
15715
+ this._stickToTopOfAncestors(visibleLimiterTop);
15720
15716
  } else {
15721
- if (this._contentPanelRect.height + this.limiterBottomOffset < limiterRect.height) {
15722
- this._stickToTopOfAncestors(visibleLimiterTop);
15723
- } else {
15724
- this._unstick();
15725
- }
15717
+ this._unstick();
15726
15718
  }
15727
15719
  } else {
15728
15720
  this._unstick();
@@ -15732,14 +15724,6 @@ const toPx$3 = /* #__PURE__ */ toUnit('px');
15732
15724
  // @if CK_DEBUG_STICKYPANEL // console.log( '_isStickyToTheBottomOfLimiter', this._isStickyToTheBottomOfLimiter );
15733
15725
  // @if CK_DEBUG_STICKYPANEL // console.log( '_stickyTopOffset', this._stickyTopOffset );
15734
15726
  // @if CK_DEBUG_STICKYPANEL // console.log( '_stickyBottomOffset', this._stickyBottomOffset );
15735
- // @if CK_DEBUG_STICKYPANEL // if ( visibleLimiterRect ) {
15736
- // @if CK_DEBUG_STICKYPANEL // RectDrawer.draw( visibleLimiterRect,
15737
- // @if CK_DEBUG_STICKYPANEL // { ...diagonalStylesBlack,
15738
- // @if CK_DEBUG_STICKYPANEL // outlineWidth: '3px', opacity: '.8', outlineColor: 'orange', outlineOffset: '-3px',
15739
- // @if CK_DEBUG_STICKYPANEL // backgroundColor: 'rgba(0, 0, 255, .2)' },
15740
- // @if CK_DEBUG_STICKYPANEL // 'visibleLimiterRect'
15741
- // @if CK_DEBUG_STICKYPANEL // );
15742
- // @if CK_DEBUG_STICKYPANEL // }
15743
15727
  }
15744
15728
  /**
15745
15729
  * Sticks the panel at the given CSS `top` offset.
@@ -15751,7 +15735,7 @@ const toPx$3 = /* #__PURE__ */ toUnit('px');
15751
15735
  this._isStickyToTheBottomOfLimiter = false;
15752
15736
  this._stickyTopOffset = topOffset;
15753
15737
  this._stickyBottomOffset = null;
15754
- this._marginLeft = toPx$3(-global.window.scrollX);
15738
+ this._marginLeft = toPx$3(-global.window.scrollX + this._getVisualViewportOffset().left);
15755
15739
  }
15756
15740
  /**
15757
15741
  * Sticks the panel at the bottom of the limiter with a given CSS `bottom` offset.
@@ -15763,7 +15747,7 @@ const toPx$3 = /* #__PURE__ */ toUnit('px');
15763
15747
  this._isStickyToTheBottomOfLimiter = true;
15764
15748
  this._stickyTopOffset = null;
15765
15749
  this._stickyBottomOffset = stickyBottomOffset;
15766
- this._marginLeft = toPx$3(-global.window.scrollX);
15750
+ this._marginLeft = toPx$3(-global.window.scrollX + this._getVisualViewportOffset().left);
15767
15751
  }
15768
15752
  /**
15769
15753
  * Unsticks the panel putting it back to its original position.
@@ -15783,6 +15767,23 @@ const toPx$3 = /* #__PURE__ */ toUnit('px');
15783
15767
  */ get _contentPanelRect() {
15784
15768
  return new Rect(this.contentPanelElement);
15785
15769
  }
15770
+ /**
15771
+ * Returns normalized visual viewport offsets (only for Safari and iOS).
15772
+ */ _getVisualViewportOffset() {
15773
+ const visualViewport = global.window.visualViewport;
15774
+ if (!(env.isiOS || env.isSafari) || !visualViewport) {
15775
+ return {
15776
+ left: 0,
15777
+ top: 0
15778
+ };
15779
+ }
15780
+ const left = Math.max(Math.round(visualViewport.offsetLeft), 0);
15781
+ const top = Math.max(Math.round(visualViewport.offsetTop), 0);
15782
+ return {
15783
+ left,
15784
+ top
15785
+ };
15786
+ }
15786
15787
  }
15787
15788
 
15788
15789
  /**