@ckeditor/ckeditor5-utils 35.3.2 → 35.4.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.
- package/package.json +5 -5
- package/src/areconnectedthroughproperties.js +5 -7
- package/src/ckeditorerror.js +51 -70
- package/src/collection.js +106 -148
- package/src/comparearrays.js +10 -8
- package/src/config.js +29 -83
- package/src/count.js +5 -3
- package/src/diff.js +7 -5
- package/src/difftochanges.js +17 -14
- package/src/dom/createelement.js +11 -9
- package/src/dom/emittermixin.js +43 -84
- package/src/dom/getancestors.js +2 -2
- package/src/dom/getborderwidths.js +2 -2
- package/src/dom/getcommonancestor.js +3 -3
- package/src/dom/getdatafromelement.js +2 -2
- package/src/dom/getpositionedancestor.js +1 -2
- package/src/dom/global.js +8 -10
- package/src/dom/indexof.js +2 -2
- package/src/dom/insertat.js +3 -3
- package/src/dom/iscomment.js +0 -3
- package/src/dom/isnode.js +0 -3
- package/src/dom/isrange.js +0 -3
- package/src/dom/istext.js +0 -3
- package/src/dom/isvisible.js +0 -3
- package/src/dom/iswindow.js +0 -3
- package/src/dom/position.js +110 -133
- package/src/dom/rect.js +42 -52
- package/src/dom/remove.js +1 -1
- package/src/dom/resizeobserver.js +10 -35
- package/src/dom/scroll.js +85 -91
- package/src/dom/setdatainelement.js +2 -2
- package/src/dom/tounit.js +1 -10
- package/src/elementreplacer.js +2 -2
- package/src/emittermixin.js +48 -48
- package/src/env.js +14 -75
- package/src/eventinfo.js +2 -2
- package/src/fastdiff.js +115 -96
- package/src/first.js +0 -3
- package/src/focustracker.js +10 -18
- package/src/index.js +17 -0
- package/src/inserttopriorityarray.js +2 -2
- package/src/isiterable.js +2 -2
- package/src/keyboard.js +20 -21
- package/src/keystrokehandler.js +26 -24
- package/src/language.js +1 -2
- package/src/locale.js +11 -14
- package/src/mapsequal.js +3 -3
- package/src/mix.js +15 -13
- package/src/nth.js +0 -4
- package/src/objecttomap.js +6 -4
- package/src/observablemixin.js +126 -150
- package/src/priorities.js +0 -9
- package/src/splicearray.js +12 -11
- package/src/spy.js +1 -1
- package/src/tomap.js +7 -5
- package/src/translation-service.js +70 -52
- package/src/uid.js +5 -3
- package/src/unicode.js +9 -15
- package/src/version.js +32 -26
package/src/dom/global.js
CHANGED
|
@@ -2,23 +2,21 @@
|
|
|
2
2
|
* @license Copyright (c) 2003-2022, CKSource Holding sp. z o.o. All rights reserved.
|
|
3
3
|
* For licensing, see LICENSE.md or https://ckeditor.com/legal/ckeditor-oss-license
|
|
4
4
|
*/
|
|
5
|
-
/* globals window, document */
|
|
6
|
-
/**
|
|
7
|
-
* @module utils/dom/global
|
|
8
|
-
*/
|
|
9
5
|
/**
|
|
10
6
|
* A helper (module) giving an access to the global DOM objects such as `window` and
|
|
11
7
|
* `document`. Accessing these objects using this helper allows easy and bulletproof
|
|
12
8
|
* testing, i.e. stubbing native properties:
|
|
13
9
|
*
|
|
14
|
-
*
|
|
10
|
+
* ```ts
|
|
11
|
+
* import { global } from 'ckeditor5/utils';
|
|
15
12
|
*
|
|
16
|
-
*
|
|
17
|
-
*
|
|
18
|
-
*
|
|
19
|
-
*
|
|
13
|
+
* // This stub will work for any code using global module.
|
|
14
|
+
* testUtils.sinon.stub( global, 'window', {
|
|
15
|
+
* innerWidth: 10000
|
|
16
|
+
* } );
|
|
20
17
|
*
|
|
21
|
-
*
|
|
18
|
+
* console.log( global.window.innerWidth );
|
|
19
|
+
* ```
|
|
22
20
|
*/
|
|
23
21
|
let global;
|
|
24
22
|
// In some environments window and document API might not be available.
|
package/src/dom/indexof.js
CHANGED
|
@@ -8,8 +8,8 @@
|
|
|
8
8
|
/**
|
|
9
9
|
* Returns index of the node in the parent element.
|
|
10
10
|
*
|
|
11
|
-
* @param
|
|
12
|
-
* @returns
|
|
11
|
+
* @param node Node which index is tested.
|
|
12
|
+
* @returns Index of the node in the parent element. Returns 0 if node has no parent.
|
|
13
13
|
*/
|
|
14
14
|
export default function indexOf(node) {
|
|
15
15
|
let index = 0;
|
package/src/dom/insertat.js
CHANGED
|
@@ -8,9 +8,9 @@
|
|
|
8
8
|
/**
|
|
9
9
|
* Inserts node to the parent at given index.
|
|
10
10
|
*
|
|
11
|
-
* @param
|
|
12
|
-
* @param
|
|
13
|
-
* @param
|
|
11
|
+
* @param parentElement Parent element.
|
|
12
|
+
* @param index Insertions index.
|
|
13
|
+
* @param nodeToInsert Node to insert.
|
|
14
14
|
*/
|
|
15
15
|
export default function insertAt(parentElement, index, nodeToInsert) {
|
|
16
16
|
parentElement.insertBefore(nodeToInsert, parentElement.childNodes[index] || null);
|
package/src/dom/iscomment.js
CHANGED
package/src/dom/isnode.js
CHANGED
package/src/dom/isrange.js
CHANGED
package/src/dom/istext.js
CHANGED
package/src/dom/isvisible.js
CHANGED
|
@@ -14,9 +14,6 @@
|
|
|
14
14
|
*
|
|
15
15
|
* **Note**: This helper does not check whether the element is hidden by cropping, overflow, etc..
|
|
16
16
|
* To check that, use {@link module:utils/dom/rect~Rect} instead.
|
|
17
|
-
*
|
|
18
|
-
* @param {HTMLElement|null|undefined} element
|
|
19
|
-
* @returns {Boolean}
|
|
20
17
|
*/
|
|
21
18
|
export default function isVisible(element) {
|
|
22
19
|
return !!(element && element.getClientRects && element.getClientRects().length);
|
package/src/dom/iswindow.js
CHANGED
package/src/dom/position.js
CHANGED
|
@@ -10,70 +10,71 @@ import Rect from './rect';
|
|
|
10
10
|
import getPositionedAncestor from './getpositionedancestor';
|
|
11
11
|
import getBorderWidths from './getborderwidths';
|
|
12
12
|
import { isFunction } from 'lodash-es';
|
|
13
|
-
// @if CK_DEBUG_POSITION //
|
|
13
|
+
// @if CK_DEBUG_POSITION // const { RectDrawer } = require( '@ckeditor/ckeditor5-minimap/src/utils' );
|
|
14
14
|
/**
|
|
15
15
|
* Calculates the `position: absolute` coordinates of a given element so it can be positioned with respect to the
|
|
16
16
|
* target in the visually most efficient way, taking various restrictions like viewport or limiter geometry
|
|
17
17
|
* into consideration.
|
|
18
18
|
*
|
|
19
|
-
*
|
|
20
|
-
*
|
|
19
|
+
* ```ts
|
|
20
|
+
* // The element which is to be positioned.
|
|
21
|
+
* const element = document.body.querySelector( '#toolbar' );
|
|
21
22
|
*
|
|
22
|
-
*
|
|
23
|
-
*
|
|
23
|
+
* // A target to which the element is positioned relatively.
|
|
24
|
+
* const target = document.body.querySelector( '#container' );
|
|
24
25
|
*
|
|
25
|
-
*
|
|
26
|
-
*
|
|
27
|
-
*
|
|
28
|
-
*
|
|
26
|
+
* // Finding the optimal coordinates for the positioning.
|
|
27
|
+
* const { left, top, name } = getOptimalPosition( {
|
|
28
|
+
* element: element,
|
|
29
|
+
* target: target,
|
|
29
30
|
*
|
|
30
|
-
*
|
|
31
|
-
*
|
|
32
|
-
*
|
|
33
|
-
*
|
|
34
|
-
*
|
|
35
|
-
*
|
|
36
|
-
*
|
|
37
|
-
*
|
|
38
|
-
*
|
|
39
|
-
*
|
|
40
|
-
*
|
|
41
|
-
*
|
|
42
|
-
*
|
|
43
|
-
*
|
|
44
|
-
*
|
|
31
|
+
* // The algorithm will chose among these positions to meet the requirements such
|
|
32
|
+
* // as "limiter" element or "fitInViewport", set below. The positions are considered
|
|
33
|
+
* // in the order of the array.
|
|
34
|
+
* positions: [
|
|
35
|
+
* //
|
|
36
|
+
* // [ Target ]
|
|
37
|
+
* // +-----------------+
|
|
38
|
+
* // | Element |
|
|
39
|
+
* // +-----------------+
|
|
40
|
+
* //
|
|
41
|
+
* targetRect => ( {
|
|
42
|
+
* top: targetRect.bottom,
|
|
43
|
+
* left: targetRect.left,
|
|
44
|
+
* name: 'mySouthEastPosition'
|
|
45
|
+
* } ),
|
|
45
46
|
*
|
|
46
|
-
*
|
|
47
|
-
*
|
|
48
|
-
*
|
|
49
|
-
*
|
|
50
|
-
*
|
|
51
|
-
*
|
|
52
|
-
*
|
|
53
|
-
*
|
|
54
|
-
*
|
|
55
|
-
*
|
|
56
|
-
*
|
|
57
|
-
*
|
|
47
|
+
* //
|
|
48
|
+
* // +-----------------+
|
|
49
|
+
* // | Element |
|
|
50
|
+
* // +-----------------+
|
|
51
|
+
* // [ Target ]
|
|
52
|
+
* //
|
|
53
|
+
* ( targetRect, elementRect ) => ( {
|
|
54
|
+
* top: targetRect.top - elementRect.height,
|
|
55
|
+
* left: targetRect.left,
|
|
56
|
+
* name: 'myNorthEastPosition'
|
|
57
|
+
* } )
|
|
58
|
+
* ],
|
|
58
59
|
*
|
|
59
|
-
*
|
|
60
|
-
*
|
|
60
|
+
* // Find a position such guarantees the element remains within visible boundaries of <body>.
|
|
61
|
+
* limiter: document.body,
|
|
61
62
|
*
|
|
62
|
-
*
|
|
63
|
-
*
|
|
64
|
-
*
|
|
63
|
+
* // Find a position such guarantees the element remains within visible boundaries of the browser viewport.
|
|
64
|
+
* fitInViewport: true
|
|
65
|
+
* } );
|
|
65
66
|
*
|
|
66
|
-
*
|
|
67
|
-
*
|
|
68
|
-
*
|
|
67
|
+
* // The best position which fits into document.body and the viewport. May be useful
|
|
68
|
+
* // to set proper class on the `element`.
|
|
69
|
+
* console.log( name ); // -> "myNorthEastPosition"
|
|
69
70
|
*
|
|
70
|
-
*
|
|
71
|
-
*
|
|
72
|
-
*
|
|
73
|
-
*
|
|
71
|
+
* // Using the absolute coordinates which has been found to position the element
|
|
72
|
+
* // as in the diagram depicting the "myNorthEastPosition" position.
|
|
73
|
+
* element.style.top = top;
|
|
74
|
+
* element.style.left = left;
|
|
75
|
+
* ```
|
|
74
76
|
*
|
|
75
|
-
* @param
|
|
76
|
-
* @returns {module:utils/dom/position~Position}
|
|
77
|
+
* @param options The input data and configuration of the helper.
|
|
77
78
|
*/
|
|
78
79
|
export function getOptimalPosition({ element, target, positions, limiter, fitInViewport, viewportOffsetConfig }) {
|
|
79
80
|
// If the {@link module:utils/dom/position~Options#target} is a function, use what it returns.
|
|
@@ -113,11 +114,9 @@ export function getOptimalPosition({ element, target, positions, limiter, fitInV
|
|
|
113
114
|
}
|
|
114
115
|
return bestPosition;
|
|
115
116
|
}
|
|
116
|
-
|
|
117
|
-
|
|
118
|
-
|
|
119
|
-
// @param {Object} An object containing viewportOffset config.
|
|
120
|
-
// @returns {module:utils/dom/rect~Rect} A shrunken rect of the viewport.
|
|
117
|
+
/**
|
|
118
|
+
* Returns a viewport `Rect` shrunk by the viewport offset config from all sides.
|
|
119
|
+
*/
|
|
121
120
|
function getConstrainedViewportRect(viewportOffsetConfig) {
|
|
122
121
|
viewportOffsetConfig = Object.assign({ top: 0, bottom: 0, left: 0, right: 0 }, viewportOffsetConfig);
|
|
123
122
|
const viewportRect = new Rect(global.window);
|
|
@@ -127,21 +126,10 @@ function getConstrainedViewportRect(viewportOffsetConfig) {
|
|
|
127
126
|
viewportRect.height -= viewportOffsetConfig.bottom;
|
|
128
127
|
return viewportRect;
|
|
129
128
|
}
|
|
130
|
-
|
|
131
|
-
|
|
132
|
-
|
|
133
|
-
|
|
134
|
-
//
|
|
135
|
-
// @param {module:utils/dom/position~Options#positions} positions Functions returning
|
|
136
|
-
// {@link module:utils/dom/position~Position}to be checked, in the order of preference.
|
|
137
|
-
// @param {Object} options
|
|
138
|
-
// @param {module:utils/dom/rect~Rect} options.elementRect The positioned element rect.
|
|
139
|
-
// @param {module:utils/dom/rect~Rect} options.targetRect The target element rect.
|
|
140
|
-
// @param {module:utils/dom/rect~Rect} options.viewportRect The viewport rect.
|
|
141
|
-
// @param {module:utils/dom/rect~Rect} [options.limiterRect] The limiter rect.
|
|
142
|
-
// @param {HTMLElement|null} [options.positionedElementAncestor] Nearest element ancestor element which CSS position is not "static".
|
|
143
|
-
//
|
|
144
|
-
// @returns {module:utils/dom/position~Position|null} An array containing the name of the position and it's rect.
|
|
129
|
+
/**
|
|
130
|
+
* For a given array of positioning functions, returns such that provides the best
|
|
131
|
+
* fit of the `elementRect` into the `limiterRect` and `viewportRect`.
|
|
132
|
+
*/
|
|
145
133
|
function getBestPosition(positions, options) {
|
|
146
134
|
const { elementRect } = options;
|
|
147
135
|
// This is when element is fully visible.
|
|
@@ -169,17 +157,14 @@ function getBestPosition(positions, options) {
|
|
|
169
157
|
}
|
|
170
158
|
return bestPosition;
|
|
171
159
|
}
|
|
172
|
-
|
|
173
|
-
|
|
174
|
-
|
|
175
|
-
|
|
176
|
-
|
|
177
|
-
|
|
178
|
-
|
|
179
|
-
|
|
180
|
-
//
|
|
181
|
-
// @param {module:utils/dom/rect~Rect} rect A rect with absolute rect coordinates.
|
|
182
|
-
// @param {HTMLElement} positionedElementAncestor An ancestor element that should be considered.
|
|
160
|
+
/**
|
|
161
|
+
* For a given absolute Rect coordinates object and a positioned element ancestor, it updates its
|
|
162
|
+
* coordinates that make up for the position and the scroll of the ancestor.
|
|
163
|
+
*
|
|
164
|
+
* This is necessary because while Rects (and DOMRects) are relative to the browser's viewport, their coordinates
|
|
165
|
+
* are used in real–life to position elements with `position: absolute`, which are scoped by any positioned
|
|
166
|
+
* (and scrollable) ancestors.
|
|
167
|
+
*/
|
|
183
168
|
function shiftRectToCompensatePositionedAncestor(rect, positionedElementAncestor) {
|
|
184
169
|
const ancestorPosition = getRectForAbsolutePositioning(new Rect(positionedElementAncestor));
|
|
185
170
|
const ancestorBorderWidths = getBorderWidths(positionedElementAncestor);
|
|
@@ -207,34 +192,34 @@ function shiftRectToCompensatePositionedAncestor(rect, positionedElementAncestor
|
|
|
207
192
|
moveY -= ancestorBorderWidths.top;
|
|
208
193
|
rect.moveBy(moveX, moveY);
|
|
209
194
|
}
|
|
210
|
-
|
|
211
|
-
|
|
212
|
-
|
|
213
|
-
|
|
214
|
-
// @param {module:utils/dom/rect~Rect} rect A rect to be converted.
|
|
215
|
-
// @returns {module:utils/dom/rect~Rect} Object containing `left` and `top` properties, in absolute coordinates.
|
|
195
|
+
/**
|
|
196
|
+
* DOMRect (also Rect) works in a scroll–independent geometry but `position: absolute` doesn't.
|
|
197
|
+
* This function converts Rect to `position: absolute` coordinates.
|
|
198
|
+
*/
|
|
216
199
|
function getRectForAbsolutePositioning(rect) {
|
|
217
200
|
const { scrollX, scrollY } = global.window;
|
|
218
201
|
return rect.clone().moveBy(scrollX, scrollY);
|
|
219
202
|
}
|
|
220
|
-
|
|
221
|
-
|
|
222
|
-
|
|
223
|
-
|
|
224
|
-
|
|
225
|
-
|
|
226
|
-
|
|
203
|
+
/**
|
|
204
|
+
* A position class which instances are created and used by the {@link module:utils/dom/position~getOptimalPosition} helper.
|
|
205
|
+
*
|
|
206
|
+
* {@link module:utils/dom/position~Position#top} and {@link module:utils/dom/position~Position#left} properties of the position instance
|
|
207
|
+
* translate directly to the `top` and `left` properties in CSS "`position: absolute` coordinate system". If set on the positioned element
|
|
208
|
+
* in DOM, they will make it display it in the right place in the viewport.
|
|
209
|
+
*/
|
|
227
210
|
class PositionObject {
|
|
228
|
-
|
|
229
|
-
|
|
230
|
-
|
|
231
|
-
|
|
232
|
-
|
|
233
|
-
|
|
234
|
-
|
|
235
|
-
|
|
236
|
-
|
|
237
|
-
|
|
211
|
+
/**
|
|
212
|
+
* Creates an instance of the {@link module:utils/dom/position~PositionObject} class.
|
|
213
|
+
*
|
|
214
|
+
* @param positioningFunction function The function that defines the expected
|
|
215
|
+
* coordinates the positioned element should move to.
|
|
216
|
+
* @param options options object.
|
|
217
|
+
* @param options.elementRect The positioned element rect.
|
|
218
|
+
* @param options.targetRect The target element rect.
|
|
219
|
+
* @param options.viewportRect The viewport rect.
|
|
220
|
+
* @param options.limiterRect The limiter rect.
|
|
221
|
+
* @param options.positionedElementAncestor Nearest element ancestor element which CSS position is not "static".
|
|
222
|
+
*/
|
|
238
223
|
constructor(positioningFunction, options) {
|
|
239
224
|
const positioningFunctionOutput = positioningFunction(options.targetRect, options.elementRect, options.viewportRect);
|
|
240
225
|
// Nameless position for a function that didn't participate.
|
|
@@ -247,26 +232,23 @@ class PositionObject {
|
|
|
247
232
|
this._positioningFunctionCorrdinates = { left, top };
|
|
248
233
|
this._options = options;
|
|
249
234
|
}
|
|
250
|
-
|
|
251
|
-
|
|
252
|
-
|
|
253
|
-
|
|
254
|
-
// @type {Number}
|
|
235
|
+
/**
|
|
236
|
+
* The left value in pixels in the CSS `position: absolute` coordinate system.
|
|
237
|
+
* Set it on the positioned element in DOM to move it to the position.
|
|
238
|
+
*/
|
|
255
239
|
get left() {
|
|
256
240
|
return this._absoluteRect.left;
|
|
257
241
|
}
|
|
258
|
-
|
|
259
|
-
|
|
260
|
-
|
|
261
|
-
|
|
262
|
-
// @type {Number}
|
|
242
|
+
/**
|
|
243
|
+
* The top value in pixels in the CSS `position: absolute` coordinate system.
|
|
244
|
+
* Set it on the positioned element in DOM to move it to the position.
|
|
245
|
+
*/
|
|
263
246
|
get top() {
|
|
264
247
|
return this._absoluteRect.top;
|
|
265
248
|
}
|
|
266
|
-
|
|
267
|
-
|
|
268
|
-
|
|
269
|
-
// @type {Number}
|
|
249
|
+
/**
|
|
250
|
+
* An intersection area between positioned element and limiter within viewport constraints.
|
|
251
|
+
*/
|
|
270
252
|
get limiterIntersectionArea() {
|
|
271
253
|
const limiterRect = this._options.limiterRect;
|
|
272
254
|
if (limiterRect) {
|
|
@@ -286,10 +268,9 @@ class PositionObject {
|
|
|
286
268
|
}
|
|
287
269
|
return 0;
|
|
288
270
|
}
|
|
289
|
-
|
|
290
|
-
|
|
291
|
-
|
|
292
|
-
// @type {Number}
|
|
271
|
+
/**
|
|
272
|
+
* An intersection area between positioned element and viewport.
|
|
273
|
+
*/
|
|
293
274
|
get viewportIntersectionArea() {
|
|
294
275
|
const viewportRect = this._options.viewportRect;
|
|
295
276
|
if (viewportRect) {
|
|
@@ -297,12 +278,10 @@ class PositionObject {
|
|
|
297
278
|
}
|
|
298
279
|
return 0;
|
|
299
280
|
}
|
|
300
|
-
|
|
301
|
-
|
|
302
|
-
|
|
303
|
-
|
|
304
|
-
// @readonly
|
|
305
|
-
// @type {module:utils/dom/rect~Rect}
|
|
281
|
+
/**
|
|
282
|
+
* An already positioned element rect. A clone of the element rect passed to the constructor
|
|
283
|
+
* but placed in the viewport according to the positioning function.
|
|
284
|
+
*/
|
|
306
285
|
get _rect() {
|
|
307
286
|
if (this._cachedRect) {
|
|
308
287
|
return this._cachedRect;
|
|
@@ -310,11 +289,9 @@ class PositionObject {
|
|
|
310
289
|
this._cachedRect = this._options.elementRect.clone().moveTo(this._positioningFunctionCorrdinates.left, this._positioningFunctionCorrdinates.top);
|
|
311
290
|
return this._cachedRect;
|
|
312
291
|
}
|
|
313
|
-
|
|
314
|
-
|
|
315
|
-
|
|
316
|
-
// @readonly
|
|
317
|
-
// @type {module:utils/dom/rect~Rect}
|
|
292
|
+
/**
|
|
293
|
+
* An already absolutely positioned element rect. See ({@link #_rect}).
|
|
294
|
+
*/
|
|
318
295
|
get _absoluteRect() {
|
|
319
296
|
if (this._cachedAbsoluteRect) {
|
|
320
297
|
return this._cachedAbsoluteRect;
|