@ckeditor/ckeditor5-utils 34.2.0 → 35.1.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/CHANGELOG.md +324 -0
- package/LICENSE.md +1 -1
- package/package.json +19 -8
- package/src/areconnectedthroughproperties.js +54 -71
- package/src/ckeditorerror.js +92 -114
- package/src/collection.js +594 -762
- package/src/comparearrays.js +22 -28
- package/src/config.js +193 -223
- package/src/count.js +8 -12
- package/src/diff.js +85 -110
- package/src/difftochanges.js +47 -57
- package/src/dom/createelement.js +17 -25
- package/src/dom/emittermixin.js +202 -263
- package/src/dom/getancestors.js +9 -13
- package/src/dom/getborderwidths.js +10 -13
- package/src/dom/getcommonancestor.js +9 -15
- package/src/dom/getdatafromelement.js +5 -9
- package/src/dom/getpositionedancestor.js +9 -14
- package/src/dom/global.js +15 -4
- package/src/dom/indexof.js +7 -11
- package/src/dom/insertat.js +2 -4
- package/src/dom/iscomment.js +2 -5
- package/src/dom/isnode.js +10 -12
- package/src/dom/isrange.js +2 -4
- package/src/dom/istext.js +2 -4
- package/src/dom/isvisible.js +2 -4
- package/src/dom/iswindow.js +11 -16
- package/src/dom/position.js +220 -410
- package/src/dom/rect.js +335 -414
- package/src/dom/remove.js +5 -8
- package/src/dom/resizeobserver.js +109 -342
- package/src/dom/scroll.js +151 -183
- package/src/dom/setdatainelement.js +5 -9
- package/src/dom/tounit.js +10 -12
- package/src/elementreplacer.js +30 -44
- package/src/emittermixin.js +368 -634
- package/src/env.js +109 -116
- package/src/eventinfo.js +12 -65
- package/src/fastdiff.js +96 -128
- package/src/first.js +8 -12
- package/src/focustracker.js +77 -133
- package/src/index.js +0 -9
- package/src/inserttopriorityarray.js +9 -30
- package/src/isiterable.js +2 -4
- package/src/keyboard.js +117 -196
- package/src/keystrokehandler.js +72 -88
- package/src/language.js +9 -15
- package/src/locale.js +61 -158
- package/src/mapsequal.js +12 -17
- package/src/mix.js +17 -16
- package/src/nth.js +8 -11
- package/src/objecttomap.js +7 -11
- package/src/observablemixin.js +474 -778
- package/src/priorities.js +20 -32
- package/src/spy.js +3 -6
- package/src/toarray.js +2 -13
- package/src/tomap.js +8 -10
- package/src/translation-service.js +57 -93
- package/src/uid.js +34 -38
- package/src/unicode.js +28 -43
- package/src/version.js +134 -143
package/src/dom/scroll.js
CHANGED
|
@@ -2,107 +2,88 @@
|
|
|
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
|
-
|
|
6
5
|
/**
|
|
7
6
|
* @module utils/dom/scroll
|
|
8
7
|
*/
|
|
9
|
-
|
|
10
8
|
import isRange from './isrange';
|
|
11
9
|
import Rect from './rect';
|
|
12
10
|
import isText from './istext';
|
|
13
|
-
|
|
14
|
-
const utils = {};
|
|
15
|
-
|
|
16
11
|
/**
|
|
17
12
|
* Makes any page `HTMLElement` or `Range` (`target`) visible inside the browser viewport.
|
|
18
13
|
* This helper will scroll all `target` ancestors and the web browser viewport to reveal the target to
|
|
19
14
|
* the user. If the `target` is already visible, nothing will happen.
|
|
20
15
|
*
|
|
16
|
+
* @param {Object} options
|
|
21
17
|
* @param {HTMLElement|Range} options.target A target, which supposed to become visible to the user.
|
|
22
18
|
* @param {Number} [options.viewportOffset] An offset from the edge of the viewport (in pixels)
|
|
23
19
|
* the `target` will be moved by when the viewport is scrolled. It enhances the user experience
|
|
24
20
|
* by keeping the `target` some distance from the edge of the viewport and thus making it easier to
|
|
25
21
|
* read or edit by the user.
|
|
26
22
|
*/
|
|
27
|
-
export function scrollViewportToShowTarget(
|
|
28
|
-
|
|
29
|
-
|
|
30
|
-
|
|
31
|
-
|
|
32
|
-
|
|
33
|
-
|
|
34
|
-
|
|
35
|
-
|
|
36
|
-
|
|
37
|
-
|
|
38
|
-
|
|
39
|
-
|
|
40
|
-
|
|
41
|
-
|
|
42
|
-
|
|
43
|
-
|
|
44
|
-
|
|
45
|
-
|
|
46
|
-
|
|
47
|
-
|
|
48
|
-
|
|
49
|
-
|
|
50
|
-
|
|
51
|
-
|
|
52
|
-
|
|
53
|
-
|
|
54
|
-
|
|
55
|
-
|
|
56
|
-
|
|
57
|
-
|
|
58
|
-
|
|
59
|
-
|
|
60
|
-
|
|
61
|
-
|
|
62
|
-
|
|
63
|
-
|
|
64
|
-
|
|
65
|
-
|
|
66
|
-
|
|
67
|
-
|
|
68
|
-
|
|
69
|
-
|
|
70
|
-
|
|
71
|
-
|
|
72
|
-
|
|
73
|
-
|
|
74
|
-
|
|
75
|
-
|
|
76
|
-
|
|
77
|
-
|
|
78
|
-
}
|
|
79
|
-
} else {
|
|
80
|
-
currentWindow = null;
|
|
81
|
-
}
|
|
82
|
-
}
|
|
23
|
+
export function scrollViewportToShowTarget({ target, viewportOffset = 0 }) {
|
|
24
|
+
const targetWindow = getWindow(target);
|
|
25
|
+
let currentWindow = targetWindow;
|
|
26
|
+
let currentFrame = null;
|
|
27
|
+
// Iterate over all windows, starting from target's parent window up to window#top.
|
|
28
|
+
while (currentWindow) {
|
|
29
|
+
let firstAncestorToScroll;
|
|
30
|
+
// Let's scroll target's ancestors first to reveal it. Then, once the ancestor scrolls
|
|
31
|
+
// settled down, the algorithm can eventually scroll the viewport of the current window.
|
|
32
|
+
//
|
|
33
|
+
// Note: If the current window is target's **original** window (e.g. the first one),
|
|
34
|
+
// start scrolling the closest parent of the target. If not, scroll the closest parent
|
|
35
|
+
// of an iframe that resides in the current window.
|
|
36
|
+
if (currentWindow == targetWindow) {
|
|
37
|
+
firstAncestorToScroll = getParentElement(target);
|
|
38
|
+
}
|
|
39
|
+
else {
|
|
40
|
+
firstAncestorToScroll = getParentElement(currentFrame);
|
|
41
|
+
}
|
|
42
|
+
// Scroll the target's ancestors first. Once done, scrolling the viewport is easy.
|
|
43
|
+
scrollAncestorsToShowRect(firstAncestorToScroll, () => {
|
|
44
|
+
// Note: If the target does not belong to the current window **directly**,
|
|
45
|
+
// i.e. it resides in an iframe belonging to the window, obtain the target's rect
|
|
46
|
+
// in the coordinates of the current window. By default, a Rect returns geometry
|
|
47
|
+
// relative to the current window's viewport. To make it work in a parent window,
|
|
48
|
+
// it must be shifted.
|
|
49
|
+
return getRectRelativeToWindow(target, currentWindow);
|
|
50
|
+
});
|
|
51
|
+
// Obtain the rect of the target after it has been scrolled within its ancestors.
|
|
52
|
+
// It's time to scroll the viewport.
|
|
53
|
+
const targetRect = getRectRelativeToWindow(target, currentWindow);
|
|
54
|
+
scrollWindowToShowRect(currentWindow, targetRect, viewportOffset);
|
|
55
|
+
if (currentWindow.parent != currentWindow) {
|
|
56
|
+
// Keep the reference to the <iframe> element the "previous current window" was
|
|
57
|
+
// rendered within. It will be useful to re–calculate the rect of the target
|
|
58
|
+
// in the parent window's relative geometry. The target's rect must be shifted
|
|
59
|
+
// by it's iframe's position.
|
|
60
|
+
currentFrame = currentWindow.frameElement;
|
|
61
|
+
currentWindow = currentWindow.parent;
|
|
62
|
+
// If the current window has some parent but frameElement is inaccessible, then they have
|
|
63
|
+
// different domains/ports and, due to security reasons, accessing and scrolling
|
|
64
|
+
// the parent window won't be possible.
|
|
65
|
+
// See https://github.com/ckeditor/ckeditor5/issues/930.
|
|
66
|
+
if (!currentFrame) {
|
|
67
|
+
return;
|
|
68
|
+
}
|
|
69
|
+
}
|
|
70
|
+
else {
|
|
71
|
+
currentWindow = null;
|
|
72
|
+
}
|
|
73
|
+
}
|
|
83
74
|
}
|
|
84
|
-
|
|
85
75
|
/**
|
|
86
76
|
* Makes any page `HTMLElement` or `Range` (target) visible within its scrollable ancestors,
|
|
87
77
|
* e.g. if they have `overflow: scroll` CSS style.
|
|
88
78
|
*
|
|
89
79
|
* @param {HTMLElement|Range} target A target, which supposed to become visible to the user.
|
|
90
80
|
*/
|
|
91
|
-
export function scrollAncestorsToShowTarget(
|
|
92
|
-
|
|
93
|
-
|
|
94
|
-
|
|
95
|
-
|
|
96
|
-
} );
|
|
81
|
+
export function scrollAncestorsToShowTarget(target) {
|
|
82
|
+
const targetParent = getParentElement(target);
|
|
83
|
+
scrollAncestorsToShowRect(targetParent, () => {
|
|
84
|
+
return new Rect(target);
|
|
85
|
+
});
|
|
97
86
|
}
|
|
98
|
-
|
|
99
|
-
// TODO: Using a property value shorthand in the top of the file
|
|
100
|
-
// causes JSDoc to throw errors. See https://github.com/cksource/docs-builder/issues/75.
|
|
101
|
-
Object.assign( utils, {
|
|
102
|
-
scrollViewportToShowTarget,
|
|
103
|
-
scrollAncestorsToShowTarget
|
|
104
|
-
} );
|
|
105
|
-
|
|
106
87
|
// Makes a given rect visible within its parent window.
|
|
107
88
|
//
|
|
108
89
|
// Note: Avoid the situation where the caret is still in the viewport, but totally
|
|
@@ -144,134 +125,125 @@ Object.assign( utils, {
|
|
|
144
125
|
// @param {Window} window A window which is scrolled to reveal the rect.
|
|
145
126
|
// @param {module:utils/dom/rect~Rect} rect A rect which is to be revealed.
|
|
146
127
|
// @param {Number} viewportOffset See scrollViewportToShowTarget.
|
|
147
|
-
function scrollWindowToShowRect(
|
|
148
|
-
|
|
149
|
-
|
|
150
|
-
|
|
151
|
-
|
|
152
|
-
|
|
153
|
-
|
|
154
|
-
|
|
155
|
-
|
|
156
|
-
|
|
157
|
-
|
|
158
|
-
|
|
159
|
-
|
|
160
|
-
|
|
161
|
-
|
|
162
|
-
|
|
163
|
-
|
|
164
|
-
|
|
165
|
-
|
|
166
|
-
|
|
167
|
-
|
|
168
|
-
|
|
169
|
-
|
|
170
|
-
|
|
171
|
-
window.scrollTo( scrollX, scrollY );
|
|
172
|
-
}
|
|
128
|
+
function scrollWindowToShowRect(window, rect, viewportOffset) {
|
|
129
|
+
const targetShiftedDownRect = rect.clone().moveBy(0, viewportOffset);
|
|
130
|
+
const targetShiftedUpRect = rect.clone().moveBy(0, -viewportOffset);
|
|
131
|
+
const viewportRect = new Rect(window).excludeScrollbarsAndBorders();
|
|
132
|
+
const rects = [targetShiftedUpRect, targetShiftedDownRect];
|
|
133
|
+
if (!rects.every(rect => viewportRect.contains(rect))) {
|
|
134
|
+
let { scrollX, scrollY } = window;
|
|
135
|
+
if (isAbove(targetShiftedUpRect, viewportRect)) {
|
|
136
|
+
scrollY -= viewportRect.top - rect.top + viewportOffset;
|
|
137
|
+
}
|
|
138
|
+
else if (isBelow(targetShiftedDownRect, viewportRect)) {
|
|
139
|
+
scrollY += rect.bottom - viewportRect.bottom + viewportOffset;
|
|
140
|
+
}
|
|
141
|
+
// TODO: Web browsers scroll natively to place the target in the middle
|
|
142
|
+
// of the viewport. It's not a very popular case, though.
|
|
143
|
+
if (isLeftOf(rect, viewportRect)) {
|
|
144
|
+
scrollX -= viewportRect.left - rect.left + viewportOffset;
|
|
145
|
+
}
|
|
146
|
+
else if (isRightOf(rect, viewportRect)) {
|
|
147
|
+
scrollX += rect.right - viewportRect.right + viewportOffset;
|
|
148
|
+
}
|
|
149
|
+
window.scrollTo(scrollX, scrollY);
|
|
150
|
+
}
|
|
173
151
|
}
|
|
174
|
-
|
|
175
152
|
// Recursively scrolls element ancestors to visually reveal a rect.
|
|
176
153
|
//
|
|
177
154
|
// @private
|
|
178
155
|
// @param {HTMLElement} A parent The first ancestors to start scrolling.
|
|
179
156
|
// @param {Function} getRect A function which returns the Rect, which is to be revealed.
|
|
180
|
-
function scrollAncestorsToShowRect(
|
|
181
|
-
|
|
182
|
-
|
|
183
|
-
|
|
184
|
-
|
|
185
|
-
|
|
186
|
-
|
|
187
|
-
|
|
188
|
-
|
|
189
|
-
|
|
190
|
-
|
|
191
|
-
|
|
192
|
-
|
|
193
|
-
|
|
194
|
-
|
|
195
|
-
|
|
196
|
-
|
|
197
|
-
|
|
198
|
-
|
|
199
|
-
|
|
200
|
-
|
|
201
|
-
|
|
202
|
-
parent = parent.parentNode;
|
|
203
|
-
}
|
|
157
|
+
function scrollAncestorsToShowRect(parent, getRect) {
|
|
158
|
+
const parentWindow = getWindow(parent);
|
|
159
|
+
let parentRect, targetRect;
|
|
160
|
+
while (parent != parentWindow.document.body) {
|
|
161
|
+
targetRect = getRect();
|
|
162
|
+
parentRect = new Rect(parent).excludeScrollbarsAndBorders();
|
|
163
|
+
if (!parentRect.contains(targetRect)) {
|
|
164
|
+
if (isAbove(targetRect, parentRect)) {
|
|
165
|
+
parent.scrollTop -= parentRect.top - targetRect.top;
|
|
166
|
+
}
|
|
167
|
+
else if (isBelow(targetRect, parentRect)) {
|
|
168
|
+
parent.scrollTop += targetRect.bottom - parentRect.bottom;
|
|
169
|
+
}
|
|
170
|
+
if (isLeftOf(targetRect, parentRect)) {
|
|
171
|
+
parent.scrollLeft -= parentRect.left - targetRect.left;
|
|
172
|
+
}
|
|
173
|
+
else if (isRightOf(targetRect, parentRect)) {
|
|
174
|
+
parent.scrollLeft += targetRect.right - parentRect.right;
|
|
175
|
+
}
|
|
176
|
+
}
|
|
177
|
+
parent = parent.parentNode;
|
|
178
|
+
}
|
|
204
179
|
}
|
|
205
|
-
|
|
206
180
|
// Determines if a given `Rect` extends beyond the bottom edge of the second `Rect`.
|
|
207
181
|
//
|
|
208
182
|
// @private
|
|
209
183
|
// @param {module:utils/dom/rect~Rect} firstRect
|
|
210
184
|
// @param {module:utils/dom/rect~Rect} secondRect
|
|
211
|
-
|
|
212
|
-
|
|
185
|
+
// @returns {Boolean}
|
|
186
|
+
function isBelow(firstRect, secondRect) {
|
|
187
|
+
return firstRect.bottom > secondRect.bottom;
|
|
213
188
|
}
|
|
214
|
-
|
|
215
189
|
// Determines if a given `Rect` extends beyond the top edge of the second `Rect`.
|
|
216
190
|
//
|
|
217
191
|
// @private
|
|
218
192
|
// @param {module:utils/dom/rect~Rect} firstRect
|
|
219
193
|
// @param {module:utils/dom/rect~Rect} secondRect
|
|
220
|
-
|
|
221
|
-
|
|
194
|
+
// @returns {Boolean}
|
|
195
|
+
function isAbove(firstRect, secondRect) {
|
|
196
|
+
return firstRect.top < secondRect.top;
|
|
222
197
|
}
|
|
223
|
-
|
|
224
198
|
// Determines if a given `Rect` extends beyond the left edge of the second `Rect`.
|
|
225
199
|
//
|
|
226
200
|
// @private
|
|
227
201
|
// @param {module:utils/dom/rect~Rect} firstRect
|
|
228
202
|
// @param {module:utils/dom/rect~Rect} secondRect
|
|
229
|
-
|
|
230
|
-
|
|
203
|
+
// @returns {Boolean}
|
|
204
|
+
function isLeftOf(firstRect, secondRect) {
|
|
205
|
+
return firstRect.left < secondRect.left;
|
|
231
206
|
}
|
|
232
|
-
|
|
233
207
|
// Determines if a given `Rect` extends beyond the right edge of the second `Rect`.
|
|
234
208
|
//
|
|
235
209
|
// @private
|
|
236
210
|
// @param {module:utils/dom/rect~Rect} firstRect
|
|
237
211
|
// @param {module:utils/dom/rect~Rect} secondRect
|
|
238
|
-
|
|
239
|
-
|
|
212
|
+
// @returns {Boolean}
|
|
213
|
+
function isRightOf(firstRect, secondRect) {
|
|
214
|
+
return firstRect.right > secondRect.right;
|
|
240
215
|
}
|
|
241
|
-
|
|
242
216
|
// Returns the closest window of an element or range.
|
|
243
217
|
//
|
|
244
218
|
// @private
|
|
245
|
-
// @param {HTMLElement|Range}
|
|
219
|
+
// @param {HTMLElement|Range} elementOrRange
|
|
246
220
|
// @returns {Window}
|
|
247
|
-
function getWindow(
|
|
248
|
-
|
|
249
|
-
|
|
250
|
-
|
|
251
|
-
|
|
252
|
-
|
|
221
|
+
function getWindow(elementOrRange) {
|
|
222
|
+
if (isRange(elementOrRange)) {
|
|
223
|
+
return elementOrRange.startContainer.ownerDocument.defaultView;
|
|
224
|
+
}
|
|
225
|
+
else {
|
|
226
|
+
return elementOrRange.ownerDocument.defaultView;
|
|
227
|
+
}
|
|
253
228
|
}
|
|
254
|
-
|
|
255
229
|
// Returns the closest parent of an element or DOM range.
|
|
256
230
|
//
|
|
257
231
|
// @private
|
|
258
|
-
// @param {HTMLElement|Range}
|
|
232
|
+
// @param {HTMLElement|Range} elementOrRange
|
|
259
233
|
// @returns {HTMLelement}
|
|
260
|
-
function getParentElement(
|
|
261
|
-
|
|
262
|
-
|
|
263
|
-
|
|
264
|
-
|
|
265
|
-
|
|
266
|
-
|
|
267
|
-
|
|
268
|
-
|
|
269
|
-
|
|
270
|
-
|
|
271
|
-
|
|
272
|
-
}
|
|
234
|
+
function getParentElement(elementOrRange) {
|
|
235
|
+
if (isRange(elementOrRange)) {
|
|
236
|
+
let parent = elementOrRange.commonAncestorContainer;
|
|
237
|
+
// If a Range is attached to the Text, use the closest element ancestor.
|
|
238
|
+
if (isText(parent)) {
|
|
239
|
+
parent = parent.parentNode;
|
|
240
|
+
}
|
|
241
|
+
return parent;
|
|
242
|
+
}
|
|
243
|
+
else {
|
|
244
|
+
return elementOrRange.parentNode;
|
|
245
|
+
}
|
|
273
246
|
}
|
|
274
|
-
|
|
275
247
|
// Returns the rect of an element or range residing in an iframe.
|
|
276
248
|
// The result rect is relative to the geometry of the passed window instance.
|
|
277
249
|
//
|
|
@@ -279,24 +251,20 @@ function getParentElement( elementOrRange ) {
|
|
|
279
251
|
// @param {HTMLElement|Range} target Element or range which rect should be returned.
|
|
280
252
|
// @param {Window} relativeWindow A window the rect should be relative to.
|
|
281
253
|
// @returns {module:utils/dom/rect~Rect}
|
|
282
|
-
function getRectRelativeToWindow(
|
|
283
|
-
|
|
284
|
-
|
|
285
|
-
|
|
286
|
-
|
|
287
|
-
|
|
288
|
-
|
|
289
|
-
|
|
290
|
-
|
|
291
|
-
|
|
292
|
-
|
|
293
|
-
|
|
294
|
-
|
|
295
|
-
|
|
296
|
-
|
|
297
|
-
|
|
298
|
-
}
|
|
299
|
-
}
|
|
300
|
-
|
|
301
|
-
return rect;
|
|
254
|
+
function getRectRelativeToWindow(target, relativeWindow) {
|
|
255
|
+
const targetWindow = getWindow(target);
|
|
256
|
+
const rect = new Rect(target);
|
|
257
|
+
if (targetWindow === relativeWindow) {
|
|
258
|
+
return rect;
|
|
259
|
+
}
|
|
260
|
+
else {
|
|
261
|
+
let currentWindow = targetWindow;
|
|
262
|
+
while (currentWindow != relativeWindow) {
|
|
263
|
+
const frame = currentWindow.frameElement;
|
|
264
|
+
const frameRect = new Rect(frame).excludeScrollbarsAndBorders();
|
|
265
|
+
rect.moveBy(frameRect.left, frameRect.top);
|
|
266
|
+
currentWindow = currentWindow.parent;
|
|
267
|
+
}
|
|
268
|
+
}
|
|
269
|
+
return rect;
|
|
302
270
|
}
|
|
@@ -2,23 +2,19 @@
|
|
|
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
|
-
|
|
6
5
|
/**
|
|
7
6
|
* @module utils/dom/setdatainelement
|
|
8
7
|
*/
|
|
9
|
-
|
|
10
8
|
/* globals HTMLTextAreaElement */
|
|
11
|
-
|
|
12
9
|
/**
|
|
13
10
|
* Sets data in a given element.
|
|
14
11
|
*
|
|
15
12
|
* @param {HTMLElement} el The element in which the data will be set.
|
|
16
13
|
* @param {String} data The data string.
|
|
17
14
|
*/
|
|
18
|
-
export default function setDataInElement(
|
|
19
|
-
|
|
20
|
-
|
|
21
|
-
|
|
22
|
-
|
|
23
|
-
el.innerHTML = data;
|
|
15
|
+
export default function setDataInElement(el, data) {
|
|
16
|
+
if (el instanceof HTMLTextAreaElement) {
|
|
17
|
+
el.value = data;
|
|
18
|
+
}
|
|
19
|
+
el.innerHTML = data;
|
|
24
20
|
}
|
package/src/dom/tounit.js
CHANGED
|
@@ -2,11 +2,9 @@
|
|
|
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
|
-
|
|
6
5
|
/**
|
|
7
6
|
* @module utils/dom/tounit
|
|
8
7
|
*/
|
|
9
|
-
|
|
10
8
|
/**
|
|
11
9
|
* Returns a helper function, which adds a desired trailing
|
|
12
10
|
* `unit` to the passed value.
|
|
@@ -14,14 +12,14 @@
|
|
|
14
12
|
* @param {String} unit An unit like "px" or "em".
|
|
15
13
|
* @returns {module:utils/dom/tounit~helper}
|
|
16
14
|
*/
|
|
17
|
-
export default function toUnit(
|
|
18
|
-
|
|
19
|
-
|
|
20
|
-
|
|
21
|
-
|
|
22
|
-
|
|
23
|
-
|
|
24
|
-
|
|
25
|
-
|
|
26
|
-
|
|
15
|
+
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
|
+
return value => value + unit;
|
|
27
25
|
}
|
package/src/elementreplacer.js
CHANGED
|
@@ -2,56 +2,42 @@
|
|
|
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
|
-
|
|
6
5
|
/**
|
|
7
6
|
* @module utils/elementreplacer
|
|
8
7
|
*/
|
|
9
|
-
|
|
10
8
|
/**
|
|
11
9
|
* Utility class allowing to hide existing HTML elements or replace them with given ones in a way that doesn't remove
|
|
12
10
|
* the original elements from the DOM.
|
|
13
11
|
*/
|
|
14
12
|
export default class ElementReplacer {
|
|
15
|
-
|
|
16
|
-
|
|
17
|
-
|
|
18
|
-
|
|
19
|
-
|
|
20
|
-
|
|
21
|
-
|
|
22
|
-
|
|
23
|
-
|
|
24
|
-
|
|
25
|
-
|
|
26
|
-
|
|
27
|
-
|
|
28
|
-
|
|
29
|
-
|
|
30
|
-
|
|
31
|
-
|
|
32
|
-
|
|
33
|
-
|
|
34
|
-
|
|
35
|
-
|
|
36
|
-
|
|
37
|
-
|
|
38
|
-
|
|
39
|
-
|
|
40
|
-
|
|
41
|
-
|
|
42
|
-
|
|
43
|
-
|
|
44
|
-
|
|
45
|
-
*/
|
|
46
|
-
restore() {
|
|
47
|
-
this._replacedElements.forEach( ( { element, newElement } ) => {
|
|
48
|
-
element.style.display = '';
|
|
49
|
-
|
|
50
|
-
if ( newElement ) {
|
|
51
|
-
newElement.remove();
|
|
52
|
-
}
|
|
53
|
-
} );
|
|
54
|
-
|
|
55
|
-
this._replacedElements = [];
|
|
56
|
-
}
|
|
13
|
+
constructor() {
|
|
14
|
+
this._replacedElements = [];
|
|
15
|
+
}
|
|
16
|
+
/**
|
|
17
|
+
* Hides the `element` and, if specified, inserts the the given element next to it.
|
|
18
|
+
*
|
|
19
|
+
* The effect of this method can be reverted by {@link #restore}.
|
|
20
|
+
*
|
|
21
|
+
* @param {HTMLElement} element The element to replace.
|
|
22
|
+
* @param {HTMLElement} [newElement] The replacement element. If not passed, then the `element` will just be hidden.
|
|
23
|
+
*/
|
|
24
|
+
replace(element, newElement) {
|
|
25
|
+
this._replacedElements.push({ element, newElement });
|
|
26
|
+
element.style.display = 'none';
|
|
27
|
+
if (newElement) {
|
|
28
|
+
element.parentNode.insertBefore(newElement, element.nextSibling);
|
|
29
|
+
}
|
|
30
|
+
}
|
|
31
|
+
/**
|
|
32
|
+
* Restores what {@link #replace} did.
|
|
33
|
+
*/
|
|
34
|
+
restore() {
|
|
35
|
+
this._replacedElements.forEach(({ element, newElement }) => {
|
|
36
|
+
element.style.display = '';
|
|
37
|
+
if (newElement) {
|
|
38
|
+
newElement.remove();
|
|
39
|
+
}
|
|
40
|
+
});
|
|
41
|
+
this._replacedElements = [];
|
|
42
|
+
}
|
|
57
43
|
}
|