@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/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@ckeditor/ckeditor5-ui",
3
- "version": "45.0.0-alpha.6",
3
+ "version": "45.0.0-alpha.8",
4
4
  "description": "The UI framework and standard UI library of CKEditor 5.",
5
5
  "keywords": [
6
6
  "ckeditor",
@@ -17,11 +17,11 @@
17
17
  "type": "module",
18
18
  "main": "src/index.js",
19
19
  "dependencies": {
20
- "@ckeditor/ckeditor5-core": "45.0.0-alpha.6",
21
- "@ckeditor/ckeditor5-editor-multi-root": "45.0.0-alpha.6",
22
- "@ckeditor/ckeditor5-engine": "45.0.0-alpha.6",
23
- "@ckeditor/ckeditor5-icons": "45.0.0-alpha.6",
24
- "@ckeditor/ckeditor5-utils": "45.0.0-alpha.6",
20
+ "@ckeditor/ckeditor5-core": "45.0.0-alpha.8",
21
+ "@ckeditor/ckeditor5-editor-multi-root": "45.0.0-alpha.8",
22
+ "@ckeditor/ckeditor5-engine": "45.0.0-alpha.8",
23
+ "@ckeditor/ckeditor5-icons": "45.0.0-alpha.8",
24
+ "@ckeditor/ckeditor5-utils": "45.0.0-alpha.8",
25
25
  "@types/color-convert": "2.0.4",
26
26
  "color-convert": "2.0.1",
27
27
  "color-parse": "1.4.2",
@@ -153,4 +153,8 @@ export default class StickyPanelView extends View {
153
153
  * @private
154
154
  */
155
155
  private get _contentPanelRect();
156
+ /**
157
+ * Returns normalized visual viewport offsets (only for Safari and iOS).
158
+ */
159
+ private _getVisualViewportOffset;
156
160
  }
@@ -7,11 +7,7 @@
7
7
  */
8
8
  import View from '../../view.js';
9
9
  import Template from '../../template.js';
10
- import { global, toUnit, Rect } from '@ckeditor/ckeditor5-utils';
11
- // @if CK_DEBUG_STICKYPANEL // const {
12
- // @if CK_DEBUG_STICKYPANEL // default: RectDrawer,
13
- // @if CK_DEBUG_STICKYPANEL // diagonalStylesBlack
14
- // @if CK_DEBUG_STICKYPANEL // } = require( '@ckeditor/ckeditor5-utils/tests/_utils/rectdrawer' );
10
+ import { Rect, toUnit, global, env } from '@ckeditor/ckeditor5-utils';
15
11
  import '../../../theme/components/panel/stickypanel.css';
16
12
  const toPx = /* #__PURE__ */ toUnit('px');
17
13
  /**
@@ -113,73 +109,65 @@ export default class StickyPanelView extends View {
113
109
  this.listenTo(this, 'change:isActive', () => {
114
110
  this.checkIfShouldBeSticky();
115
111
  });
112
+ if ((env.isiOS || env.isSafari) && global.window.visualViewport) {
113
+ this.listenTo(global.window.visualViewport, 'scroll', () => {
114
+ this.checkIfShouldBeSticky();
115
+ });
116
+ this.listenTo(global.window.visualViewport, 'resize', () => {
117
+ this.checkIfShouldBeSticky();
118
+ });
119
+ }
116
120
  }
117
121
  /**
118
122
  * Analyzes the environment to decide whether the panel should be sticky or not.
119
123
  * Then handles the positioning of the panel.
120
124
  */
121
125
  checkIfShouldBeSticky() {
122
- // @if CK_DEBUG_STICKYPANEL // RectDrawer.clear();
123
126
  if (!this.limiterElement || !this.isActive) {
124
127
  this._unstick();
125
128
  return;
126
129
  }
130
+ const { left: visualViewportOffsetLeft, top: visualViewportOffsetTop } = this._getVisualViewportOffset();
127
131
  const limiterRect = new Rect(this.limiterElement);
128
132
  let visibleLimiterRect = limiterRect.getVisible();
129
133
  if (visibleLimiterRect) {
130
134
  const windowRect = new Rect(global.window);
131
- windowRect.top += this.viewportTopOffset;
132
- windowRect.height -= this.viewportTopOffset;
135
+ let viewportTopOffset = this.viewportTopOffset;
136
+ if (env.isiOS || env.isSafari) {
137
+ // Adjust the viewport top offset to height visible in the visual viewport.
138
+ viewportTopOffset = visualViewportOffsetTop > this.viewportTopOffset ? 0 : this.viewportTopOffset - visualViewportOffsetTop;
139
+ }
140
+ windowRect.top += viewportTopOffset;
141
+ windowRect.height -= viewportTopOffset;
133
142
  visibleLimiterRect = visibleLimiterRect.getIntersection(windowRect);
134
143
  }
135
- // @if CK_DEBUG_STICKYPANEL // if ( visibleLimiterRect ) {
136
- // @if CK_DEBUG_STICKYPANEL // RectDrawer.draw( visibleLimiterRect,
137
- // @if CK_DEBUG_STICKYPANEL // { outlineWidth: '3px', opacity: '.8', outlineColor: 'red', outlineOffset: '-3px' },
138
- // @if CK_DEBUG_STICKYPANEL // 'Visible anc'
139
- // @if CK_DEBUG_STICKYPANEL // );
140
- // @if CK_DEBUG_STICKYPANEL // }
141
- // @if CK_DEBUG_STICKYPANEL //
142
- // @if CK_DEBUG_STICKYPANEL // RectDrawer.draw( limiterRect,
143
- // @if CK_DEBUG_STICKYPANEL // { outlineWidth: '3px', opacity: '.8', outlineColor: 'green', outlineOffset: '-3px' },
144
- // @if CK_DEBUG_STICKYPANEL // 'Limiter'
145
- // @if CK_DEBUG_STICKYPANEL // );
144
+ limiterRect.moveBy(visualViewportOffsetLeft, visualViewportOffsetTop);
145
+ if (visibleLimiterRect) {
146
+ visibleLimiterRect.moveBy(visualViewportOffsetLeft, visualViewportOffsetTop);
147
+ }
146
148
  // Stick the panel only if
147
149
  // * the limiter's ancestors are intersecting with each other so that some of their rects are visible,
148
150
  // * and the limiter's top edge is above the visible ancestors' top edge.
149
151
  if (visibleLimiterRect && limiterRect.top < visibleLimiterRect.top) {
150
- // @if CK_DEBUG_STICKYPANEL // RectDrawer.draw( visibleLimiterRect,
151
- // @if CK_DEBUG_STICKYPANEL // { outlineWidth: '3px', opacity: '.8', outlineColor: 'fuchsia', outlineOffset: '-3px',
152
- // @if CK_DEBUG_STICKYPANEL // backgroundColor: 'rgba(255, 0, 255, .3)' },
153
- // @if CK_DEBUG_STICKYPANEL // 'Visible limiter'
154
- // @if CK_DEBUG_STICKYPANEL // );
155
152
  const visibleLimiterTop = visibleLimiterRect.top;
156
153
  // Check if there's a change the panel can be sticky to the bottom of the limiter.
157
154
  if (visibleLimiterTop + this._contentPanelRect.height + this.limiterBottomOffset > visibleLimiterRect.bottom) {
158
155
  const stickyBottomOffset = Math.max(limiterRect.bottom - visibleLimiterRect.bottom, 0) + this.limiterBottomOffset;
159
- // @if CK_DEBUG_STICKYPANEL // const stickyBottomOffsetRect = new Rect( {
160
- // @if CK_DEBUG_STICKYPANEL // top: limiterRect.bottom - stickyBottomOffset, left: 0, right: 2000,
161
- // @if CK_DEBUG_STICKYPANEL // bottom: limiterRect.bottom - stickyBottomOffset, width: 2000, height: 1
162
- // @if CK_DEBUG_STICKYPANEL // } );
163
- // @if CK_DEBUG_STICKYPANEL // RectDrawer.draw( stickyBottomOffsetRect,
164
- // @if CK_DEBUG_STICKYPANEL // { outlineWidth: '1px', opacity: '.8', outlineColor: 'black' },
165
- // @if CK_DEBUG_STICKYPANEL // 'Sticky bottom offset'
166
- // @if CK_DEBUG_STICKYPANEL // );
167
156
  // Check if sticking the panel to the bottom of the limiter does not cause it to suddenly
168
157
  // move upwards if there's not enough space for it.
169
- if (limiterRect.bottom - stickyBottomOffset > limiterRect.top + this._contentPanelRect.height) {
158
+ // Adding 1 avoids rounding problems and toolbar flickering when offset almost equals the height.
159
+ if (limiterRect.bottom - stickyBottomOffset > limiterRect.top + this._contentPanelRect.height + 1) {
170
160
  this._stickToBottomOfLimiter(stickyBottomOffset);
171
161
  }
172
162
  else {
173
163
  this._unstick();
174
164
  }
175
165
  }
166
+ else if (this._contentPanelRect.height + this.limiterBottomOffset < limiterRect.height) {
167
+ this._stickToTopOfAncestors(visibleLimiterTop);
168
+ }
176
169
  else {
177
- if (this._contentPanelRect.height + this.limiterBottomOffset < limiterRect.height) {
178
- this._stickToTopOfAncestors(visibleLimiterTop);
179
- }
180
- else {
181
- this._unstick();
182
- }
170
+ this._unstick();
183
171
  }
184
172
  }
185
173
  else {
@@ -190,14 +178,6 @@ export default class StickyPanelView extends View {
190
178
  // @if CK_DEBUG_STICKYPANEL // console.log( '_isStickyToTheBottomOfLimiter', this._isStickyToTheBottomOfLimiter );
191
179
  // @if CK_DEBUG_STICKYPANEL // console.log( '_stickyTopOffset', this._stickyTopOffset );
192
180
  // @if CK_DEBUG_STICKYPANEL // console.log( '_stickyBottomOffset', this._stickyBottomOffset );
193
- // @if CK_DEBUG_STICKYPANEL // if ( visibleLimiterRect ) {
194
- // @if CK_DEBUG_STICKYPANEL // RectDrawer.draw( visibleLimiterRect,
195
- // @if CK_DEBUG_STICKYPANEL // { ...diagonalStylesBlack,
196
- // @if CK_DEBUG_STICKYPANEL // outlineWidth: '3px', opacity: '.8', outlineColor: 'orange', outlineOffset: '-3px',
197
- // @if CK_DEBUG_STICKYPANEL // backgroundColor: 'rgba(0, 0, 255, .2)' },
198
- // @if CK_DEBUG_STICKYPANEL // 'visibleLimiterRect'
199
- // @if CK_DEBUG_STICKYPANEL // );
200
- // @if CK_DEBUG_STICKYPANEL // }
201
181
  }
202
182
  /**
203
183
  * Sticks the panel at the given CSS `top` offset.
@@ -210,7 +190,7 @@ export default class StickyPanelView extends View {
210
190
  this._isStickyToTheBottomOfLimiter = false;
211
191
  this._stickyTopOffset = topOffset;
212
192
  this._stickyBottomOffset = null;
213
- this._marginLeft = toPx(-global.window.scrollX);
193
+ this._marginLeft = toPx(-global.window.scrollX + this._getVisualViewportOffset().left);
214
194
  }
215
195
  /**
216
196
  * Sticks the panel at the bottom of the limiter with a given CSS `bottom` offset.
@@ -223,7 +203,7 @@ export default class StickyPanelView extends View {
223
203
  this._isStickyToTheBottomOfLimiter = true;
224
204
  this._stickyTopOffset = null;
225
205
  this._stickyBottomOffset = stickyBottomOffset;
226
- this._marginLeft = toPx(-global.window.scrollX);
206
+ this._marginLeft = toPx(-global.window.scrollX + this._getVisualViewportOffset().left);
227
207
  }
228
208
  /**
229
209
  * Unsticks the panel putting it back to its original position.
@@ -245,4 +225,16 @@ export default class StickyPanelView extends View {
245
225
  get _contentPanelRect() {
246
226
  return new Rect(this.contentPanelElement);
247
227
  }
228
+ /**
229
+ * Returns normalized visual viewport offsets (only for Safari and iOS).
230
+ */
231
+ _getVisualViewportOffset() {
232
+ const visualViewport = global.window.visualViewport;
233
+ if (!(env.isiOS || env.isSafari) || !visualViewport) {
234
+ return { left: 0, top: 0 };
235
+ }
236
+ const left = Math.max(Math.round(visualViewport.offsetLeft), 0);
237
+ const top = Math.max(Math.round(visualViewport.offsetTop), 0);
238
+ return { left, top };
239
+ }
248
240
  }