@ckeditor/ckeditor5-ui 45.0.0-alpha.7 → 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.7",
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.7",
21
- "@ckeditor/ckeditor5-editor-multi-root": "45.0.0-alpha.7",
22
- "@ckeditor/ckeditor5-engine": "45.0.0-alpha.7",
23
- "@ckeditor/ckeditor5-icons": "45.0.0-alpha.7",
24
- "@ckeditor/ckeditor5-utils": "45.0.0-alpha.7",
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",
@@ -154,7 +154,7 @@ export default class StickyPanelView extends View {
154
154
  */
155
155
  private get _contentPanelRect();
156
156
  /**
157
- * Sets custom CSS properties to the panel element to make it aware of the visual viewport offset.
157
+ * Returns normalized visual viewport offsets (only for Safari and iOS).
158
158
  */
159
- private _updateVisualViewport;
159
+ private _getVisualViewportOffset;
160
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,10 +109,13 @@ export default class StickyPanelView extends View {
113
109
  this.listenTo(this, 'change:isActive', () => {
114
110
  this.checkIfShouldBeSticky();
115
111
  });
116
- if (global.window.visualViewport) {
117
- this.listenTo(global.window.visualViewport, 'scroll', () => this._updateVisualViewport());
118
- this.listenTo(global.window.visualViewport, 'resize', () => this._updateVisualViewport());
119
- this._updateVisualViewport();
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
+ });
120
119
  }
121
120
  }
122
121
  /**
@@ -124,51 +123,36 @@ export default class StickyPanelView extends View {
124
123
  * Then handles the positioning of the panel.
125
124
  */
126
125
  checkIfShouldBeSticky() {
127
- // @if CK_DEBUG_STICKYPANEL // RectDrawer.clear();
128
126
  if (!this.limiterElement || !this.isActive) {
129
127
  this._unstick();
130
128
  return;
131
129
  }
130
+ const { left: visualViewportOffsetLeft, top: visualViewportOffsetTop } = this._getVisualViewportOffset();
132
131
  const limiterRect = new Rect(this.limiterElement);
133
132
  let visibleLimiterRect = limiterRect.getVisible();
134
133
  if (visibleLimiterRect) {
135
134
  const windowRect = new Rect(global.window);
136
- windowRect.top += this.viewportTopOffset;
137
- 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;
138
142
  visibleLimiterRect = visibleLimiterRect.getIntersection(windowRect);
139
143
  }
140
- // @if CK_DEBUG_STICKYPANEL // if ( visibleLimiterRect ) {
141
- // @if CK_DEBUG_STICKYPANEL // RectDrawer.draw( visibleLimiterRect,
142
- // @if CK_DEBUG_STICKYPANEL // { outlineWidth: '3px', opacity: '.8', outlineColor: 'red', outlineOffset: '-3px' },
143
- // @if CK_DEBUG_STICKYPANEL // 'Visible anc'
144
- // @if CK_DEBUG_STICKYPANEL // );
145
- // @if CK_DEBUG_STICKYPANEL // }
146
- // @if CK_DEBUG_STICKYPANEL //
147
- // @if CK_DEBUG_STICKYPANEL // RectDrawer.draw( limiterRect,
148
- // @if CK_DEBUG_STICKYPANEL // { outlineWidth: '3px', opacity: '.8', outlineColor: 'green', outlineOffset: '-3px' },
149
- // @if CK_DEBUG_STICKYPANEL // 'Limiter'
150
- // @if CK_DEBUG_STICKYPANEL // );
144
+ limiterRect.moveBy(visualViewportOffsetLeft, visualViewportOffsetTop);
145
+ if (visibleLimiterRect) {
146
+ visibleLimiterRect.moveBy(visualViewportOffsetLeft, visualViewportOffsetTop);
147
+ }
151
148
  // Stick the panel only if
152
149
  // * the limiter's ancestors are intersecting with each other so that some of their rects are visible,
153
150
  // * and the limiter's top edge is above the visible ancestors' top edge.
154
151
  if (visibleLimiterRect && limiterRect.top < visibleLimiterRect.top) {
155
- // @if CK_DEBUG_STICKYPANEL // RectDrawer.draw( visibleLimiterRect,
156
- // @if CK_DEBUG_STICKYPANEL // { outlineWidth: '3px', opacity: '.8', outlineColor: 'fuchsia', outlineOffset: '-3px',
157
- // @if CK_DEBUG_STICKYPANEL // backgroundColor: 'rgba(255, 0, 255, .3)' },
158
- // @if CK_DEBUG_STICKYPANEL // 'Visible limiter'
159
- // @if CK_DEBUG_STICKYPANEL // );
160
152
  const visibleLimiterTop = visibleLimiterRect.top;
161
153
  // Check if there's a change the panel can be sticky to the bottom of the limiter.
162
154
  if (visibleLimiterTop + this._contentPanelRect.height + this.limiterBottomOffset > visibleLimiterRect.bottom) {
163
155
  const stickyBottomOffset = Math.max(limiterRect.bottom - visibleLimiterRect.bottom, 0) + this.limiterBottomOffset;
164
- // @if CK_DEBUG_STICKYPANEL // const stickyBottomOffsetRect = new Rect( {
165
- // @if CK_DEBUG_STICKYPANEL // top: limiterRect.bottom - stickyBottomOffset, left: 0, right: 2000,
166
- // @if CK_DEBUG_STICKYPANEL // bottom: limiterRect.bottom - stickyBottomOffset, width: 2000, height: 1
167
- // @if CK_DEBUG_STICKYPANEL // } );
168
- // @if CK_DEBUG_STICKYPANEL // RectDrawer.draw( stickyBottomOffsetRect,
169
- // @if CK_DEBUG_STICKYPANEL // { outlineWidth: '1px', opacity: '.8', outlineColor: 'black' },
170
- // @if CK_DEBUG_STICKYPANEL // 'Sticky bottom offset'
171
- // @if CK_DEBUG_STICKYPANEL // );
172
156
  // Check if sticking the panel to the bottom of the limiter does not cause it to suddenly
173
157
  // move upwards if there's not enough space for it.
174
158
  // Adding 1 avoids rounding problems and toolbar flickering when offset almost equals the height.
@@ -179,13 +163,11 @@ export default class StickyPanelView extends View {
179
163
  this._unstick();
180
164
  }
181
165
  }
166
+ else if (this._contentPanelRect.height + this.limiterBottomOffset < limiterRect.height) {
167
+ this._stickToTopOfAncestors(visibleLimiterTop);
168
+ }
182
169
  else {
183
- if (this._contentPanelRect.height + this.limiterBottomOffset < limiterRect.height) {
184
- this._stickToTopOfAncestors(visibleLimiterTop);
185
- }
186
- else {
187
- this._unstick();
188
- }
170
+ this._unstick();
189
171
  }
190
172
  }
191
173
  else {
@@ -196,14 +178,6 @@ export default class StickyPanelView extends View {
196
178
  // @if CK_DEBUG_STICKYPANEL // console.log( '_isStickyToTheBottomOfLimiter', this._isStickyToTheBottomOfLimiter );
197
179
  // @if CK_DEBUG_STICKYPANEL // console.log( '_stickyTopOffset', this._stickyTopOffset );
198
180
  // @if CK_DEBUG_STICKYPANEL // console.log( '_stickyBottomOffset', this._stickyBottomOffset );
199
- // @if CK_DEBUG_STICKYPANEL // if ( visibleLimiterRect ) {
200
- // @if CK_DEBUG_STICKYPANEL // RectDrawer.draw( visibleLimiterRect,
201
- // @if CK_DEBUG_STICKYPANEL // { ...diagonalStylesBlack,
202
- // @if CK_DEBUG_STICKYPANEL // outlineWidth: '3px', opacity: '.8', outlineColor: 'orange', outlineOffset: '-3px',
203
- // @if CK_DEBUG_STICKYPANEL // backgroundColor: 'rgba(0, 0, 255, .2)' },
204
- // @if CK_DEBUG_STICKYPANEL // 'visibleLimiterRect'
205
- // @if CK_DEBUG_STICKYPANEL // );
206
- // @if CK_DEBUG_STICKYPANEL // }
207
181
  }
208
182
  /**
209
183
  * Sticks the panel at the given CSS `top` offset.
@@ -216,7 +190,7 @@ export default class StickyPanelView extends View {
216
190
  this._isStickyToTheBottomOfLimiter = false;
217
191
  this._stickyTopOffset = topOffset;
218
192
  this._stickyBottomOffset = null;
219
- this._marginLeft = toPx(-global.window.scrollX);
193
+ this._marginLeft = toPx(-global.window.scrollX + this._getVisualViewportOffset().left);
220
194
  }
221
195
  /**
222
196
  * Sticks the panel at the bottom of the limiter with a given CSS `bottom` offset.
@@ -229,7 +203,7 @@ export default class StickyPanelView extends View {
229
203
  this._isStickyToTheBottomOfLimiter = true;
230
204
  this._stickyTopOffset = null;
231
205
  this._stickyBottomOffset = stickyBottomOffset;
232
- this._marginLeft = toPx(-global.window.scrollX);
206
+ this._marginLeft = toPx(-global.window.scrollX + this._getVisualViewportOffset().left);
233
207
  }
234
208
  /**
235
209
  * Unsticks the panel putting it back to its original position.
@@ -252,10 +226,15 @@ export default class StickyPanelView extends View {
252
226
  return new Rect(this.contentPanelElement);
253
227
  }
254
228
  /**
255
- * Sets custom CSS properties to the panel element to make it aware of the visual viewport offset.
229
+ * Returns normalized visual viewport offsets (only for Safari and iOS).
256
230
  */
257
- _updateVisualViewport() {
258
- this.element.style.setProperty('--ck-visual-viewport-left', `${global.window.visualViewport.offsetLeft}px`);
259
- this.element.style.setProperty('--ck-visual-viewport-top', `${global.window.visualViewport.offsetTop}px`);
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 };
260
239
  }
261
240
  }
@@ -3,22 +3,15 @@
3
3
  * For licensing, see LICENSE.md or https://ckeditor.com/legal/ckeditor-licensing-options
4
4
  */
5
5
 
6
- :root {
7
- --ck-visual-viewport-left: 0px;
8
- --ck-visual-viewport-top: 0px;
9
- }
10
-
11
6
  .ck.ck-sticky-panel {
12
7
  & .ck-sticky-panel__content_sticky {
13
8
  z-index: var(--ck-z-panel); /* #315 */
14
9
  position: fixed;
15
10
  top: 0;
16
- transform: translate(var(--ck-visual-viewport-left, 0px), var(--ck-visual-viewport-top, 0px));
17
11
  }
18
12
 
19
13
  & .ck-sticky-panel__content_sticky_bottom-limit {
20
14
  top: auto;
21
15
  position: absolute;
22
- transform: none;
23
16
  }
24
17
  }