@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/rect.js
CHANGED
|
@@ -19,29 +19,31 @@ export default class Rect {
|
|
|
19
19
|
/**
|
|
20
20
|
* Creates an instance of rect.
|
|
21
21
|
*
|
|
22
|
-
*
|
|
23
|
-
*
|
|
22
|
+
* ```ts
|
|
23
|
+
* // Rect of an HTMLElement.
|
|
24
|
+
* const rectA = new Rect( document.body );
|
|
24
25
|
*
|
|
25
|
-
*
|
|
26
|
-
*
|
|
26
|
+
* // Rect of a DOM Range.
|
|
27
|
+
* const rectB = new Rect( document.getSelection().getRangeAt( 0 ) );
|
|
27
28
|
*
|
|
28
|
-
*
|
|
29
|
-
*
|
|
29
|
+
* // Rect of a window (web browser viewport).
|
|
30
|
+
* const rectC = new Rect( window );
|
|
30
31
|
*
|
|
31
|
-
*
|
|
32
|
-
*
|
|
32
|
+
* // Rect out of an object.
|
|
33
|
+
* const rectD = new Rect( { top: 0, right: 10, bottom: 10, left: 0, width: 10, height: 10 } );
|
|
33
34
|
*
|
|
34
|
-
*
|
|
35
|
-
*
|
|
35
|
+
* // Rect out of another Rect instance.
|
|
36
|
+
* const rectE = new Rect( rectD );
|
|
36
37
|
*
|
|
37
|
-
*
|
|
38
|
-
*
|
|
38
|
+
* // Rect out of a ClientRect.
|
|
39
|
+
* const rectF = new Rect( document.body.getClientRects().item( 0 ) );
|
|
40
|
+
* ```
|
|
39
41
|
*
|
|
40
42
|
* **Note**: By default a rect of an HTML element includes its CSS borders and scrollbars (if any)
|
|
41
43
|
* ant the rect of a `window` includes scrollbars too. Use {@link #excludeScrollbarsAndBorders}
|
|
42
44
|
* to get the inner part of the rect.
|
|
43
45
|
*
|
|
44
|
-
* @param
|
|
46
|
+
* @param source A source object to create the rect.
|
|
45
47
|
*/
|
|
46
48
|
constructor(source) {
|
|
47
49
|
const isSourceRange = isRange(source);
|
|
@@ -88,7 +90,7 @@ export default class Rect {
|
|
|
88
90
|
/**
|
|
89
91
|
* Returns a clone of the rect.
|
|
90
92
|
*
|
|
91
|
-
* @returns
|
|
93
|
+
* @returns A cloned rect.
|
|
92
94
|
*/
|
|
93
95
|
clone() {
|
|
94
96
|
return new Rect(this);
|
|
@@ -96,9 +98,9 @@ export default class Rect {
|
|
|
96
98
|
/**
|
|
97
99
|
* Moves the rect so that its upper–left corner lands in desired `[ x, y ]` location.
|
|
98
100
|
*
|
|
99
|
-
* @param
|
|
100
|
-
* @param
|
|
101
|
-
* @returns
|
|
101
|
+
* @param x Desired horizontal location.
|
|
102
|
+
* @param y Desired vertical location.
|
|
103
|
+
* @returns A rect which has been moved.
|
|
102
104
|
*/
|
|
103
105
|
moveTo(x, y) {
|
|
104
106
|
this.top = y;
|
|
@@ -110,9 +112,9 @@ export default class Rect {
|
|
|
110
112
|
/**
|
|
111
113
|
* Moves the rect in–place by a dedicated offset.
|
|
112
114
|
*
|
|
113
|
-
* @param
|
|
114
|
-
* @param
|
|
115
|
-
* @returns
|
|
115
|
+
* @param x A horizontal offset.
|
|
116
|
+
* @param y A vertical offset
|
|
117
|
+
* @returns A rect which has been moved.
|
|
116
118
|
*/
|
|
117
119
|
moveBy(x, y) {
|
|
118
120
|
this.top += y;
|
|
@@ -123,9 +125,6 @@ export default class Rect {
|
|
|
123
125
|
}
|
|
124
126
|
/**
|
|
125
127
|
* Returns a new rect a a result of intersection with another rect.
|
|
126
|
-
*
|
|
127
|
-
* @param {module:utils/dom/rect~Rect} anotherRect
|
|
128
|
-
* @returns {module:utils/dom/rect~Rect|null}
|
|
129
128
|
*/
|
|
130
129
|
getIntersection(anotherRect) {
|
|
131
130
|
const rect = {
|
|
@@ -148,8 +147,7 @@ export default class Rect {
|
|
|
148
147
|
/**
|
|
149
148
|
* Returns the area of intersection with another rect.
|
|
150
149
|
*
|
|
151
|
-
* @
|
|
152
|
-
* @returns {Number} Area of intersection.
|
|
150
|
+
* @returns Area of intersection.
|
|
153
151
|
*/
|
|
154
152
|
getIntersectionArea(anotherRect) {
|
|
155
153
|
const rect = this.getIntersection(anotherRect);
|
|
@@ -162,8 +160,6 @@ export default class Rect {
|
|
|
162
160
|
}
|
|
163
161
|
/**
|
|
164
162
|
* Returns the area of the rect.
|
|
165
|
-
*
|
|
166
|
-
* @returns {Number}
|
|
167
163
|
*/
|
|
168
164
|
getArea() {
|
|
169
165
|
return this.width * this.height;
|
|
@@ -176,7 +172,7 @@ export default class Rect {
|
|
|
176
172
|
* If there's no such visible rect, which is when the rect is limited by one or many of
|
|
177
173
|
* the ancestors, `null` is returned.
|
|
178
174
|
*
|
|
179
|
-
* @returns
|
|
175
|
+
* @returns A visible rect instance or `null`, if there's none.
|
|
180
176
|
*/
|
|
181
177
|
getVisible() {
|
|
182
178
|
const source = this._source;
|
|
@@ -208,8 +204,8 @@ export default class Rect {
|
|
|
208
204
|
* {@link #bottom}, {@link #width} and {@link #height}) are the equal in both rect
|
|
209
205
|
* instances.
|
|
210
206
|
*
|
|
211
|
-
* @param
|
|
212
|
-
* @returns
|
|
207
|
+
* @param anotherRect A rect instance to compare with.
|
|
208
|
+
* @returns `true` when Rects are equal. `false` otherwise.
|
|
213
209
|
*/
|
|
214
210
|
isEqual(anotherRect) {
|
|
215
211
|
for (const prop of rectProperties) {
|
|
@@ -222,8 +218,8 @@ export default class Rect {
|
|
|
222
218
|
/**
|
|
223
219
|
* Checks whether a rect fully contains another rect instance.
|
|
224
220
|
*
|
|
225
|
-
* @param
|
|
226
|
-
* @returns
|
|
221
|
+
* @param anotherRect
|
|
222
|
+
* @returns `true` if contains, `false` otherwise.
|
|
227
223
|
*/
|
|
228
224
|
contains(anotherRect) {
|
|
229
225
|
const intersectRect = this.getIntersection(anotherRect);
|
|
@@ -235,7 +231,7 @@ export default class Rect {
|
|
|
235
231
|
* * Borders are removed when {@link #_source} is an HTML element.
|
|
236
232
|
* * Scrollbars are excluded from HTML elements and the `window`.
|
|
237
233
|
*
|
|
238
|
-
* @returns
|
|
234
|
+
* @returns A rect which has been updated.
|
|
239
235
|
*/
|
|
240
236
|
excludeScrollbarsAndBorders() {
|
|
241
237
|
const source = this._source;
|
|
@@ -271,8 +267,8 @@ export default class Rect {
|
|
|
271
267
|
/**
|
|
272
268
|
* Returns an array of rects of the given native DOM Range.
|
|
273
269
|
*
|
|
274
|
-
* @param
|
|
275
|
-
* @returns
|
|
270
|
+
* @param range A native DOM range.
|
|
271
|
+
* @returns DOM Range rects.
|
|
276
272
|
*/
|
|
277
273
|
static getDomRangeRects(range) {
|
|
278
274
|
const rects = [];
|
|
@@ -302,8 +298,8 @@ export default class Rect {
|
|
|
302
298
|
/**
|
|
303
299
|
* Returns a bounding rectangle that contains all the given `rects`.
|
|
304
300
|
*
|
|
305
|
-
* @param
|
|
306
|
-
* @returns
|
|
301
|
+
* @param rects A list of rectangles that should be contained in the result rectangle.
|
|
302
|
+
* @returns Bounding rectangle or `null` if no `rects` were given.
|
|
307
303
|
*/
|
|
308
304
|
static getBoundingRect(rects) {
|
|
309
305
|
const boundingRectData = {
|
|
@@ -330,32 +326,26 @@ export default class Rect {
|
|
|
330
326
|
return new Rect(boundingRectData);
|
|
331
327
|
}
|
|
332
328
|
}
|
|
333
|
-
|
|
334
|
-
|
|
335
|
-
|
|
336
|
-
// @param {module:utils/dom/rect~Rect} rect
|
|
337
|
-
// @param {module:utils/dom/rect~RectLike} source
|
|
329
|
+
/**
|
|
330
|
+
* Acquires all the rect properties from the passed source.
|
|
331
|
+
*/
|
|
338
332
|
function copyRectProperties(rect, source) {
|
|
339
333
|
for (const p of rectProperties) {
|
|
340
334
|
rect[p] = source[p];
|
|
341
335
|
}
|
|
342
336
|
}
|
|
343
|
-
|
|
344
|
-
|
|
345
|
-
|
|
346
|
-
// @param {*} value
|
|
347
|
-
// @returns {Boolean}
|
|
337
|
+
/**
|
|
338
|
+
* Checks if provided object is a <body> HTML element.
|
|
339
|
+
*/
|
|
348
340
|
function isBody(value) {
|
|
349
341
|
if (!isDomElement(value)) {
|
|
350
342
|
return false;
|
|
351
343
|
}
|
|
352
344
|
return value === value.ownerDocument.body;
|
|
353
345
|
}
|
|
354
|
-
|
|
355
|
-
|
|
356
|
-
|
|
357
|
-
// @param {*} value
|
|
358
|
-
// @returns {Boolean}
|
|
346
|
+
/**
|
|
347
|
+
* Checks if provided object "looks like" a DOM Element and has API required by `Rect` class.
|
|
348
|
+
*/
|
|
359
349
|
function isDomElement(value) {
|
|
360
350
|
// Note: earlier we used `isElement()` from lodash library, however that function is less performant because
|
|
361
351
|
// it makes complicated checks to make sure that given value is a DOM element.
|
package/src/dom/remove.js
CHANGED
|
@@ -9,13 +9,15 @@ import global from './global';
|
|
|
9
9
|
/**
|
|
10
10
|
* A helper class which instances allow performing custom actions when native DOM elements are resized.
|
|
11
11
|
*
|
|
12
|
-
*
|
|
12
|
+
* ```ts
|
|
13
|
+
* const editableElement = editor.editing.view.getDomRoot();
|
|
13
14
|
*
|
|
14
|
-
*
|
|
15
|
-
*
|
|
16
|
-
*
|
|
17
|
-
*
|
|
18
|
-
*
|
|
15
|
+
* const observer = new ResizeObserver( editableElement, entry => {
|
|
16
|
+
* console.log( 'The editable element has been resized in DOM.' );
|
|
17
|
+
* console.log( entry.target ); // -> editableElement
|
|
18
|
+
* console.log( entry.contentRect.width ); // -> e.g. '423px'
|
|
19
|
+
* } );
|
|
20
|
+
* ```
|
|
19
21
|
*
|
|
20
22
|
* It uses the [native DOM resize observer](https://developer.mozilla.org/en-US/docs/Web/API/ResizeObserver)
|
|
21
23
|
* under the hood.
|
|
@@ -24,9 +26,9 @@ export default class ResizeObserver {
|
|
|
24
26
|
/**
|
|
25
27
|
* Creates an instance of the `ResizeObserver` class.
|
|
26
28
|
*
|
|
27
|
-
* @param
|
|
29
|
+
* @param element A DOM element that is to be observed for resizing. Note that
|
|
28
30
|
* the element must be visible (i.e. not detached from DOM) for the observer to work.
|
|
29
|
-
* @param
|
|
31
|
+
* @param callback A function called when the observed element was resized. It passes
|
|
30
32
|
* the [`ResizeObserverEntry`](https://developer.mozilla.org/en-US/docs/Web/API/ResizeObserverEntry)
|
|
31
33
|
* object with information about the resize event.
|
|
32
34
|
*/
|
|
@@ -49,11 +51,6 @@ export default class ResizeObserver {
|
|
|
49
51
|
}
|
|
50
52
|
/**
|
|
51
53
|
* Registers a new resize callback for the DOM element.
|
|
52
|
-
*
|
|
53
|
-
* @private
|
|
54
|
-
* @static
|
|
55
|
-
* @param {Element} element
|
|
56
|
-
* @param {Function} callback
|
|
57
54
|
*/
|
|
58
55
|
static _addElementCallback(element, callback) {
|
|
59
56
|
if (!ResizeObserver._elementCallbacks) {
|
|
@@ -69,11 +66,6 @@ export default class ResizeObserver {
|
|
|
69
66
|
/**
|
|
70
67
|
* Removes a resize callback from the DOM element. If no callbacks are left
|
|
71
68
|
* for the element, it removes the element from the native observer.
|
|
72
|
-
*
|
|
73
|
-
* @private
|
|
74
|
-
* @static
|
|
75
|
-
* @param {Element} element
|
|
76
|
-
* @param {Function} callback
|
|
77
69
|
*/
|
|
78
70
|
static _deleteElementCallback(element, callback) {
|
|
79
71
|
const callbacks = ResizeObserver._getElementCallbacks(element);
|
|
@@ -94,11 +86,6 @@ export default class ResizeObserver {
|
|
|
94
86
|
}
|
|
95
87
|
/**
|
|
96
88
|
* Returns are registered resize callbacks for the DOM element.
|
|
97
|
-
*
|
|
98
|
-
* @private
|
|
99
|
-
* @static
|
|
100
|
-
* @param {Element} element
|
|
101
|
-
* @returns {Set.<Function>|null|undefined}
|
|
102
89
|
*/
|
|
103
90
|
static _getElementCallbacks(element) {
|
|
104
91
|
if (!ResizeObserver._elementCallbacks) {
|
|
@@ -108,9 +95,6 @@ export default class ResizeObserver {
|
|
|
108
95
|
}
|
|
109
96
|
/**
|
|
110
97
|
* Creates the single native observer shared across all `ResizeObserver` instances.
|
|
111
|
-
*
|
|
112
|
-
* @private
|
|
113
|
-
* @static
|
|
114
98
|
*/
|
|
115
99
|
static _createObserver() {
|
|
116
100
|
ResizeObserver._observerInstance = new global.window.ResizeObserver(entries => {
|
|
@@ -127,19 +111,10 @@ export default class ResizeObserver {
|
|
|
127
111
|
}
|
|
128
112
|
/**
|
|
129
113
|
* The single native observer instance shared across all {@link module:utils/dom/resizeobserver~ResizeObserver} instances.
|
|
130
|
-
*
|
|
131
|
-
* @static
|
|
132
|
-
* @private
|
|
133
|
-
* @readonly
|
|
134
|
-
* @property {Object|null}
|
|
135
114
|
*/
|
|
136
115
|
ResizeObserver._observerInstance = null;
|
|
137
116
|
/**
|
|
138
117
|
* A mapping of native DOM elements and their callbacks shared across all
|
|
139
118
|
* {@link module:utils/dom/resizeobserver~ResizeObserver} instances.
|
|
140
|
-
*
|
|
141
|
-
* @static
|
|
142
|
-
* @private
|
|
143
|
-
* @property {Map.<Element,Set>|null}
|
|
144
119
|
*/
|
|
145
120
|
ResizeObserver._elementCallbacks = null;
|
package/src/dom/scroll.js
CHANGED
|
@@ -13,9 +13,9 @@ import isText from './istext';
|
|
|
13
13
|
* This helper will scroll all `target` ancestors and the web browser viewport to reveal the target to
|
|
14
14
|
* the user. If the `target` is already visible, nothing will happen.
|
|
15
15
|
*
|
|
16
|
-
* @param
|
|
17
|
-
* @param
|
|
18
|
-
* @param
|
|
16
|
+
* @param options
|
|
17
|
+
* @param options.target A target, which supposed to become visible to the user.
|
|
18
|
+
* @param options.viewportOffset An offset from the edge of the viewport (in pixels)
|
|
19
19
|
* the `target` will be moved by when the viewport is scrolled. It enhances the user experience
|
|
20
20
|
* by keeping the `target` some distance from the edge of the viewport and thus making it easier to
|
|
21
21
|
* read or edit by the user.
|
|
@@ -76,7 +76,7 @@ export function scrollViewportToShowTarget({ target, viewportOffset = 0 }) {
|
|
|
76
76
|
* Makes any page `HTMLElement` or `Range` (target) visible within its scrollable ancestors,
|
|
77
77
|
* e.g. if they have `overflow: scroll` CSS style.
|
|
78
78
|
*
|
|
79
|
-
* @param
|
|
79
|
+
* @param target A target, which supposed to become visible to the user.
|
|
80
80
|
*/
|
|
81
81
|
export function scrollAncestorsToShowTarget(target) {
|
|
82
82
|
const targetParent = getParentElement(target);
|
|
@@ -84,47 +84,56 @@ export function scrollAncestorsToShowTarget(target) {
|
|
|
84
84
|
return new Rect(target);
|
|
85
85
|
});
|
|
86
86
|
}
|
|
87
|
-
|
|
88
|
-
|
|
89
|
-
|
|
90
|
-
|
|
91
|
-
|
|
92
|
-
|
|
93
|
-
|
|
94
|
-
|
|
95
|
-
|
|
96
|
-
|
|
97
|
-
|
|
98
|
-
|
|
99
|
-
|
|
100
|
-
|
|
101
|
-
|
|
102
|
-
|
|
103
|
-
|
|
104
|
-
|
|
105
|
-
|
|
106
|
-
|
|
107
|
-
|
|
108
|
-
|
|
109
|
-
|
|
110
|
-
|
|
111
|
-
|
|
112
|
-
|
|
113
|
-
|
|
114
|
-
|
|
115
|
-
|
|
116
|
-
|
|
117
|
-
|
|
118
|
-
|
|
119
|
-
|
|
120
|
-
|
|
121
|
-
|
|
122
|
-
|
|
123
|
-
|
|
124
|
-
|
|
125
|
-
|
|
126
|
-
|
|
127
|
-
|
|
87
|
+
/**
|
|
88
|
+
* Makes a given rect visible within its parent window.
|
|
89
|
+
*
|
|
90
|
+
* Note: Avoid the situation where the caret is still in the viewport, but totally
|
|
91
|
+
* at the edge of it. In such situation, if it moved beyond the viewport in the next
|
|
92
|
+
* action e.g. after paste, the scrolling would move it to the viewportOffset level
|
|
93
|
+
* and it all would look like the caret visually moved up/down:
|
|
94
|
+
*
|
|
95
|
+
* 1.
|
|
96
|
+
* ```
|
|
97
|
+
* | foo[]
|
|
98
|
+
* | <--- N px of space below the caret
|
|
99
|
+
* +---------------------------------...
|
|
100
|
+
* ```
|
|
101
|
+
*
|
|
102
|
+
* 2. *paste*
|
|
103
|
+
* 3.
|
|
104
|
+
* ```
|
|
105
|
+
* |
|
|
106
|
+
* |
|
|
107
|
+
* +-foo-----------------------------...
|
|
108
|
+
* bar[] <--- caret below viewport, scrolling...
|
|
109
|
+
* ```
|
|
110
|
+
*
|
|
111
|
+
* 4. *scrolling*
|
|
112
|
+
* 5.
|
|
113
|
+
* ```
|
|
114
|
+
* |
|
|
115
|
+
* | foo
|
|
116
|
+
* | bar[] <--- caret precisely at the edge
|
|
117
|
+
* +---------------------------------...
|
|
118
|
+
* ```
|
|
119
|
+
*
|
|
120
|
+
* To prevent this, this method checks the rects moved by the viewportOffset to cover
|
|
121
|
+
* the upper/lower edge of the viewport. It makes sure if the action repeats, there's
|
|
122
|
+
* no twitching – it's a purely visual improvement:
|
|
123
|
+
*
|
|
124
|
+
* 5. (after fix)
|
|
125
|
+
* ```
|
|
126
|
+
* |
|
|
127
|
+
* | foo
|
|
128
|
+
* | bar[]
|
|
129
|
+
* | <--- N px of space below the caret
|
|
130
|
+
* +---------------------------------...
|
|
131
|
+
* ```
|
|
132
|
+
*
|
|
133
|
+
* @param window A window which is scrolled to reveal the rect.
|
|
134
|
+
* @param rect A rect which is to be revealed.
|
|
135
|
+
* @param viewportOffset See scrollViewportToShowTarget.
|
|
136
|
+
*/
|
|
128
137
|
function scrollWindowToShowRect(window, rect, viewportOffset) {
|
|
129
138
|
const targetShiftedDownRect = rect.clone().moveBy(0, viewportOffset);
|
|
130
139
|
const targetShiftedUpRect = rect.clone().moveBy(0, -viewportOffset);
|
|
@@ -149,11 +158,12 @@ function scrollWindowToShowRect(window, rect, viewportOffset) {
|
|
|
149
158
|
window.scrollTo(scrollX, scrollY);
|
|
150
159
|
}
|
|
151
160
|
}
|
|
152
|
-
|
|
153
|
-
|
|
154
|
-
|
|
155
|
-
|
|
156
|
-
|
|
161
|
+
/**
|
|
162
|
+
* Recursively scrolls element ancestors to visually reveal a rect.
|
|
163
|
+
*
|
|
164
|
+
* @param parent A parent The first ancestors to start scrolling.
|
|
165
|
+
* @param getRect A function which returns the Rect, which is to be revealed.
|
|
166
|
+
*/
|
|
157
167
|
function scrollAncestorsToShowRect(parent, getRect) {
|
|
158
168
|
const parentWindow = getWindow(parent);
|
|
159
169
|
let parentRect, targetRect;
|
|
@@ -177,47 +187,33 @@ function scrollAncestorsToShowRect(parent, getRect) {
|
|
|
177
187
|
parent = parent.parentNode;
|
|
178
188
|
}
|
|
179
189
|
}
|
|
180
|
-
|
|
181
|
-
|
|
182
|
-
|
|
183
|
-
// @param {module:utils/dom/rect~Rect} firstRect
|
|
184
|
-
// @param {module:utils/dom/rect~Rect} secondRect
|
|
185
|
-
// @returns {Boolean}
|
|
190
|
+
/**
|
|
191
|
+
* Determines if a given `Rect` extends beyond the bottom edge of the second `Rect`.
|
|
192
|
+
*/
|
|
186
193
|
function isBelow(firstRect, secondRect) {
|
|
187
194
|
return firstRect.bottom > secondRect.bottom;
|
|
188
195
|
}
|
|
189
|
-
|
|
190
|
-
|
|
191
|
-
|
|
192
|
-
// @param {module:utils/dom/rect~Rect} firstRect
|
|
193
|
-
// @param {module:utils/dom/rect~Rect} secondRect
|
|
194
|
-
// @returns {Boolean}
|
|
196
|
+
/**
|
|
197
|
+
* Determines if a given `Rect` extends beyond the top edge of the second `Rect`.
|
|
198
|
+
*/
|
|
195
199
|
function isAbove(firstRect, secondRect) {
|
|
196
200
|
return firstRect.top < secondRect.top;
|
|
197
201
|
}
|
|
198
|
-
|
|
199
|
-
|
|
200
|
-
|
|
201
|
-
// @param {module:utils/dom/rect~Rect} firstRect
|
|
202
|
-
// @param {module:utils/dom/rect~Rect} secondRect
|
|
203
|
-
// @returns {Boolean}
|
|
202
|
+
/**
|
|
203
|
+
* Determines if a given `Rect` extends beyond the left edge of the second `Rect`.
|
|
204
|
+
*/
|
|
204
205
|
function isLeftOf(firstRect, secondRect) {
|
|
205
206
|
return firstRect.left < secondRect.left;
|
|
206
207
|
}
|
|
207
|
-
|
|
208
|
-
|
|
209
|
-
|
|
210
|
-
// @param {module:utils/dom/rect~Rect} firstRect
|
|
211
|
-
// @param {module:utils/dom/rect~Rect} secondRect
|
|
212
|
-
// @returns {Boolean}
|
|
208
|
+
/**
|
|
209
|
+
* Determines if a given `Rect` extends beyond the right edge of the second `Rect`.
|
|
210
|
+
*/
|
|
213
211
|
function isRightOf(firstRect, secondRect) {
|
|
214
212
|
return firstRect.right > secondRect.right;
|
|
215
213
|
}
|
|
216
|
-
|
|
217
|
-
|
|
218
|
-
|
|
219
|
-
// @param {HTMLElement|Range} elementOrRange
|
|
220
|
-
// @returns {Window}
|
|
214
|
+
/**
|
|
215
|
+
* Returns the closest window of an element or range.
|
|
216
|
+
*/
|
|
221
217
|
function getWindow(elementOrRange) {
|
|
222
218
|
if (isRange(elementOrRange)) {
|
|
223
219
|
return elementOrRange.startContainer.ownerDocument.defaultView;
|
|
@@ -226,11 +222,9 @@ function getWindow(elementOrRange) {
|
|
|
226
222
|
return elementOrRange.ownerDocument.defaultView;
|
|
227
223
|
}
|
|
228
224
|
}
|
|
229
|
-
|
|
230
|
-
|
|
231
|
-
|
|
232
|
-
// @param {HTMLElement|Range} elementOrRange
|
|
233
|
-
// @returns {HTMLelement}
|
|
225
|
+
/**
|
|
226
|
+
* Returns the closest parent of an element or DOM range.
|
|
227
|
+
*/
|
|
234
228
|
function getParentElement(elementOrRange) {
|
|
235
229
|
if (isRange(elementOrRange)) {
|
|
236
230
|
let parent = elementOrRange.commonAncestorContainer;
|
|
@@ -244,13 +238,13 @@ function getParentElement(elementOrRange) {
|
|
|
244
238
|
return elementOrRange.parentNode;
|
|
245
239
|
}
|
|
246
240
|
}
|
|
247
|
-
|
|
248
|
-
|
|
249
|
-
|
|
250
|
-
|
|
251
|
-
|
|
252
|
-
|
|
253
|
-
|
|
241
|
+
/**
|
|
242
|
+
* Returns the rect of an element or range residing in an iframe.
|
|
243
|
+
* The result rect is relative to the geometry of the passed window instance.
|
|
244
|
+
*
|
|
245
|
+
* @param target Element or range which rect should be returned.
|
|
246
|
+
* @param relativeWindow A window the rect should be relative to.
|
|
247
|
+
*/
|
|
254
248
|
function getRectRelativeToWindow(target, relativeWindow) {
|
|
255
249
|
const targetWindow = getWindow(target);
|
|
256
250
|
const rect = new Rect(target);
|
|
@@ -9,8 +9,8 @@
|
|
|
9
9
|
/**
|
|
10
10
|
* Sets data in a given element.
|
|
11
11
|
*
|
|
12
|
-
* @param
|
|
13
|
-
* @param
|
|
12
|
+
* @param el The element in which the data will be set.
|
|
13
|
+
* @param data The data string.
|
|
14
14
|
*/
|
|
15
15
|
export default function setDataInElement(el, data) {
|
|
16
16
|
if (el instanceof HTMLTextAreaElement) {
|
package/src/dom/tounit.js
CHANGED
|
@@ -9,17 +9,8 @@
|
|
|
9
9
|
* Returns a helper function, which adds a desired trailing
|
|
10
10
|
* `unit` to the passed value.
|
|
11
11
|
*
|
|
12
|
-
* @param
|
|
13
|
-
* @returns {module:utils/dom/tounit~helper}
|
|
12
|
+
* @param unit An unit like "px" or "em".
|
|
14
13
|
*/
|
|
15
14
|
export default function toUnit(unit) {
|
|
16
|
-
/**
|
|
17
|
-
* A function, which adds a pre–defined trailing `unit`
|
|
18
|
-
* to the passed `value`.
|
|
19
|
-
*
|
|
20
|
-
* @function helper
|
|
21
|
-
* @param {String|Number} value A value to be given the unit.
|
|
22
|
-
* @returns {String} A value with the trailing unit.
|
|
23
|
-
*/
|
|
24
15
|
return value => value + unit;
|
|
25
16
|
}
|
package/src/elementreplacer.js
CHANGED
|
@@ -18,8 +18,8 @@ export default class ElementReplacer {
|
|
|
18
18
|
*
|
|
19
19
|
* The effect of this method can be reverted by {@link #restore}.
|
|
20
20
|
*
|
|
21
|
-
* @param
|
|
22
|
-
* @param
|
|
21
|
+
* @param element The element to replace.
|
|
22
|
+
* @param newElement The replacement element. If not passed, then the `element` will just be hidden.
|
|
23
23
|
*/
|
|
24
24
|
replace(element, newElement) {
|
|
25
25
|
this._replacedElements.push({ element, newElement });
|