@ckeditor/ckeditor5-ui 45.0.0-alpha.7 → 45.0.0-alpha.9

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