@ckeditor/ckeditor5-utils 40.0.0 → 40.2.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 +26 -26
- package/LICENSE.md +3 -3
- package/package.json +1 -1
- package/src/abortabledebounce.d.ts +17 -0
- package/src/abortabledebounce.js +22 -0
- package/src/areconnectedthroughproperties.d.ts +11 -11
- package/src/areconnectedthroughproperties.js +73 -73
- package/src/ckeditorerror.d.ts +123 -123
- package/src/ckeditorerror.js +176 -176
- package/src/collection.d.ts +433 -427
- package/src/collection.js +583 -575
- package/src/comparearrays.d.ts +30 -30
- package/src/comparearrays.js +47 -47
- package/src/config.d.ts +163 -163
- package/src/config.js +163 -162
- package/src/count.d.ts +18 -18
- package/src/count.js +24 -24
- package/src/delay.d.ts +19 -19
- package/src/delay.js +26 -26
- package/src/diff.d.ts +31 -31
- package/src/diff.js +115 -115
- package/src/difftochanges.d.ts +59 -59
- package/src/difftochanges.js +79 -79
- package/src/dom/createelement.d.ts +57 -57
- package/src/dom/createelement.js +40 -40
- package/src/dom/emittermixin.d.ts +142 -142
- package/src/dom/emittermixin.js +239 -239
- package/src/dom/findclosestscrollableancestor.d.ts +11 -11
- package/src/dom/findclosestscrollableancestor.js +31 -31
- package/src/dom/getancestors.d.ts +17 -17
- package/src/dom/getancestors.js +27 -27
- package/src/dom/getborderwidths.d.ts +24 -24
- package/src/dom/getborderwidths.js +24 -24
- package/src/dom/getcommonancestor.d.ts +12 -12
- package/src/dom/getcommonancestor.js +25 -25
- package/src/dom/getdatafromelement.d.ts +14 -14
- package/src/dom/getdatafromelement.js +20 -20
- package/src/dom/getpositionedancestor.d.ts +10 -10
- package/src/dom/getpositionedancestor.js +22 -22
- package/src/dom/global.d.ts +32 -32
- package/src/dom/global.js +35 -35
- package/src/dom/indexof.d.ts +14 -14
- package/src/dom/indexof.js +21 -21
- package/src/dom/insertat.d.ts +15 -15
- package/src/dom/insertat.js +17 -17
- package/src/dom/iscomment.d.ts +11 -11
- package/src/dom/iscomment.js +14 -14
- package/src/dom/isnode.d.ts +11 -11
- package/src/dom/isnode.js +21 -21
- package/src/dom/isrange.d.ts +11 -11
- package/src/dom/isrange.js +13 -13
- package/src/dom/istext.d.ts +11 -11
- package/src/dom/istext.js +13 -13
- package/src/dom/isvalidattributename.d.ts +10 -10
- package/src/dom/isvalidattributename.js +22 -22
- package/src/dom/isvisible.d.ts +18 -18
- package/src/dom/isvisible.js +20 -20
- package/src/dom/iswindow.d.ts +11 -11
- package/src/dom/iswindow.js +22 -22
- package/src/dom/position.d.ts +211 -211
- package/src/dom/position.js +313 -313
- package/src/dom/rect.d.ts +195 -195
- package/src/dom/rect.js +474 -474
- package/src/dom/remove.d.ts +13 -13
- package/src/dom/remove.js +18 -18
- package/src/dom/resizeobserver.d.ts +74 -74
- package/src/dom/resizeobserver.js +126 -126
- package/src/dom/scroll.d.ts +73 -73
- package/src/dom/scroll.js +383 -383
- package/src/dom/setdatainelement.d.ts +14 -14
- package/src/dom/setdatainelement.js +20 -20
- package/src/dom/tounit.d.ts +22 -22
- package/src/dom/tounit.js +16 -16
- package/src/elementreplacer.d.ts +31 -31
- package/src/elementreplacer.js +43 -43
- package/src/emittermixin.d.ts +312 -312
- package/src/emittermixin.js +453 -453
- package/src/env.d.ts +117 -117
- package/src/env.js +122 -122
- package/src/eventinfo.d.ts +58 -58
- package/src/eventinfo.js +26 -26
- package/src/fastdiff.d.ts +112 -112
- package/src/fastdiff.js +248 -248
- package/src/first.d.ts +11 -11
- package/src/first.js +17 -17
- package/src/focustracker.d.ts +75 -75
- package/src/focustracker.js +95 -95
- package/src/index.d.ts +64 -61
- package/src/index.js +63 -60
- package/src/inserttopriorityarray.d.ts +30 -30
- package/src/inserttopriorityarray.js +21 -21
- package/src/isiterable.d.ts +14 -14
- package/src/isiterable.js +16 -16
- package/src/keyboard.d.ts +126 -126
- package/src/keyboard.js +221 -221
- package/src/keystrokehandler.d.ts +87 -87
- package/src/keystrokehandler.js +122 -122
- package/src/language.d.ts +17 -17
- package/src/language.js +19 -19
- package/src/locale.d.ts +120 -120
- package/src/locale.js +76 -76
- package/src/mapsequal.d.ts +15 -15
- package/src/mapsequal.js +27 -27
- package/src/mix.d.ts +85 -85
- package/src/mix.js +50 -50
- package/src/nth.d.ts +16 -16
- package/src/nth.js +24 -24
- package/src/objecttomap.d.ts +23 -23
- package/src/objecttomap.js +27 -27
- package/src/observablemixin.d.ts +560 -560
- package/src/observablemixin.js +580 -580
- package/src/priorities.d.ts +33 -33
- package/src/priorities.js +23 -23
- package/src/retry.d.ts +33 -0
- package/src/retry.js +47 -0
- package/src/splicearray.d.ts +26 -26
- package/src/splicearray.js +40 -40
- package/src/spy.d.ts +21 -21
- package/src/spy.js +22 -22
- package/src/toarray.d.ts +25 -25
- package/src/toarray.js +7 -7
- package/src/tomap.d.ts +19 -19
- package/src/tomap.js +29 -29
- package/src/translation-service.d.ts +168 -168
- package/src/translation-service.js +198 -198
- package/src/uid.d.ts +15 -15
- package/src/uid.js +57 -57
- package/src/unicode.d.ts +54 -54
- package/src/unicode.js +85 -85
- package/src/verifylicense.d.ts +15 -15
- package/src/verifylicense.js +87 -87
- package/src/version.d.ts +10 -10
- package/src/version.js +153 -153
- package/src/wait.d.ts +16 -0
- package/src/wait.js +29 -0
package/src/dom/remove.d.ts
CHANGED
|
@@ -1,13 +1,13 @@
|
|
|
1
|
-
/**
|
|
2
|
-
* @license Copyright (c) 2003-2023, CKSource Holding sp. z o.o. All rights reserved.
|
|
3
|
-
* For licensing, see LICENSE.md or https://ckeditor.com/legal/ckeditor-oss-license
|
|
4
|
-
*/
|
|
5
|
-
/**
|
|
6
|
-
* @module utils/dom/remove
|
|
7
|
-
*/
|
|
8
|
-
/**
|
|
9
|
-
* Removes given node from parent.
|
|
10
|
-
*
|
|
11
|
-
* @param node Node to remove.
|
|
12
|
-
*/
|
|
13
|
-
export default function remove(node: Node): void;
|
|
1
|
+
/**
|
|
2
|
+
* @license Copyright (c) 2003-2023, CKSource Holding sp. z o.o. All rights reserved.
|
|
3
|
+
* For licensing, see LICENSE.md or https://ckeditor.com/legal/ckeditor-oss-license
|
|
4
|
+
*/
|
|
5
|
+
/**
|
|
6
|
+
* @module utils/dom/remove
|
|
7
|
+
*/
|
|
8
|
+
/**
|
|
9
|
+
* Removes given node from parent.
|
|
10
|
+
*
|
|
11
|
+
* @param node Node to remove.
|
|
12
|
+
*/
|
|
13
|
+
export default function remove(node: Node): void;
|
package/src/dom/remove.js
CHANGED
|
@@ -1,18 +1,18 @@
|
|
|
1
|
-
/**
|
|
2
|
-
* @license Copyright (c) 2003-2023, CKSource Holding sp. z o.o. All rights reserved.
|
|
3
|
-
* For licensing, see LICENSE.md or https://ckeditor.com/legal/ckeditor-oss-license
|
|
4
|
-
*/
|
|
5
|
-
/**
|
|
6
|
-
* @module utils/dom/remove
|
|
7
|
-
*/
|
|
8
|
-
/**
|
|
9
|
-
* Removes given node from parent.
|
|
10
|
-
*
|
|
11
|
-
* @param node Node to remove.
|
|
12
|
-
*/
|
|
13
|
-
export default function remove(node) {
|
|
14
|
-
const parent = node.parentNode;
|
|
15
|
-
if (parent) {
|
|
16
|
-
parent.removeChild(node);
|
|
17
|
-
}
|
|
18
|
-
}
|
|
1
|
+
/**
|
|
2
|
+
* @license Copyright (c) 2003-2023, CKSource Holding sp. z o.o. All rights reserved.
|
|
3
|
+
* For licensing, see LICENSE.md or https://ckeditor.com/legal/ckeditor-oss-license
|
|
4
|
+
*/
|
|
5
|
+
/**
|
|
6
|
+
* @module utils/dom/remove
|
|
7
|
+
*/
|
|
8
|
+
/**
|
|
9
|
+
* Removes given node from parent.
|
|
10
|
+
*
|
|
11
|
+
* @param node Node to remove.
|
|
12
|
+
*/
|
|
13
|
+
export default function remove(node) {
|
|
14
|
+
const parent = node.parentNode;
|
|
15
|
+
if (parent) {
|
|
16
|
+
parent.removeChild(node);
|
|
17
|
+
}
|
|
18
|
+
}
|
|
@@ -1,74 +1,74 @@
|
|
|
1
|
-
/**
|
|
2
|
-
* @license Copyright (c) 2003-2023, CKSource Holding sp. z o.o. All rights reserved.
|
|
3
|
-
* For licensing, see LICENSE.md or https://ckeditor.com/legal/ckeditor-oss-license
|
|
4
|
-
*/
|
|
5
|
-
/**
|
|
6
|
-
* A helper class which instances allow performing custom actions when native DOM elements are resized.
|
|
7
|
-
*
|
|
8
|
-
* ```ts
|
|
9
|
-
* const editableElement = editor.editing.view.getDomRoot();
|
|
10
|
-
*
|
|
11
|
-
* const observer = new ResizeObserver( editableElement, entry => {
|
|
12
|
-
* console.log( 'The editable element has been resized in DOM.' );
|
|
13
|
-
* console.log( entry.target ); // -> editableElement
|
|
14
|
-
* console.log( entry.contentRect.width ); // -> e.g. '423px'
|
|
15
|
-
* } );
|
|
16
|
-
* ```
|
|
17
|
-
*
|
|
18
|
-
* It uses the [native DOM resize observer](https://developer.mozilla.org/en-US/docs/Web/API/ResizeObserver)
|
|
19
|
-
* under the hood.
|
|
20
|
-
*/
|
|
21
|
-
export default class ResizeObserver {
|
|
22
|
-
/**
|
|
23
|
-
* The element observed by this observer.
|
|
24
|
-
*/
|
|
25
|
-
private readonly _element;
|
|
26
|
-
/**
|
|
27
|
-
* The callback executed each time {@link #_element} is resized.
|
|
28
|
-
*/
|
|
29
|
-
private readonly _callback;
|
|
30
|
-
/**
|
|
31
|
-
* The single native observer instance shared across all {@link module:utils/dom/resizeobserver~ResizeObserver} instances.
|
|
32
|
-
*/
|
|
33
|
-
private static _observerInstance;
|
|
34
|
-
/**
|
|
35
|
-
* A mapping of native DOM elements and their callbacks shared across all
|
|
36
|
-
* {@link module:utils/dom/resizeobserver~ResizeObserver} instances.
|
|
37
|
-
*/
|
|
38
|
-
private static _elementCallbacks;
|
|
39
|
-
/**
|
|
40
|
-
* Creates an instance of the `ResizeObserver` class.
|
|
41
|
-
*
|
|
42
|
-
* @param element A DOM element that is to be observed for resizing. Note that
|
|
43
|
-
* the element must be visible (i.e. not detached from DOM) for the observer to work.
|
|
44
|
-
* @param callback A function called when the observed element was resized. It passes
|
|
45
|
-
* the [`ResizeObserverEntry`](https://developer.mozilla.org/en-US/docs/Web/API/ResizeObserverEntry)
|
|
46
|
-
* object with information about the resize event.
|
|
47
|
-
*/
|
|
48
|
-
constructor(element: Element, callback: (entry: ResizeObserverEntry) => void);
|
|
49
|
-
/**
|
|
50
|
-
* The element observed by this observer.
|
|
51
|
-
*/
|
|
52
|
-
get element(): Element;
|
|
53
|
-
/**
|
|
54
|
-
* Destroys the observer which disables the `callback` passed to the {@link #constructor}.
|
|
55
|
-
*/
|
|
56
|
-
destroy(): void;
|
|
57
|
-
/**
|
|
58
|
-
* Registers a new resize callback for the DOM element.
|
|
59
|
-
*/
|
|
60
|
-
private static _addElementCallback;
|
|
61
|
-
/**
|
|
62
|
-
* Removes a resize callback from the DOM element. If no callbacks are left
|
|
63
|
-
* for the element, it removes the element from the native observer.
|
|
64
|
-
*/
|
|
65
|
-
private static _deleteElementCallback;
|
|
66
|
-
/**
|
|
67
|
-
* Returns are registered resize callbacks for the DOM element.
|
|
68
|
-
*/
|
|
69
|
-
private static _getElementCallbacks;
|
|
70
|
-
/**
|
|
71
|
-
* Creates the single native observer shared across all `ResizeObserver` instances.
|
|
72
|
-
*/
|
|
73
|
-
private static _createObserver;
|
|
74
|
-
}
|
|
1
|
+
/**
|
|
2
|
+
* @license Copyright (c) 2003-2023, CKSource Holding sp. z o.o. All rights reserved.
|
|
3
|
+
* For licensing, see LICENSE.md or https://ckeditor.com/legal/ckeditor-oss-license
|
|
4
|
+
*/
|
|
5
|
+
/**
|
|
6
|
+
* A helper class which instances allow performing custom actions when native DOM elements are resized.
|
|
7
|
+
*
|
|
8
|
+
* ```ts
|
|
9
|
+
* const editableElement = editor.editing.view.getDomRoot();
|
|
10
|
+
*
|
|
11
|
+
* const observer = new ResizeObserver( editableElement, entry => {
|
|
12
|
+
* console.log( 'The editable element has been resized in DOM.' );
|
|
13
|
+
* console.log( entry.target ); // -> editableElement
|
|
14
|
+
* console.log( entry.contentRect.width ); // -> e.g. '423px'
|
|
15
|
+
* } );
|
|
16
|
+
* ```
|
|
17
|
+
*
|
|
18
|
+
* It uses the [native DOM resize observer](https://developer.mozilla.org/en-US/docs/Web/API/ResizeObserver)
|
|
19
|
+
* under the hood.
|
|
20
|
+
*/
|
|
21
|
+
export default class ResizeObserver {
|
|
22
|
+
/**
|
|
23
|
+
* The element observed by this observer.
|
|
24
|
+
*/
|
|
25
|
+
private readonly _element;
|
|
26
|
+
/**
|
|
27
|
+
* The callback executed each time {@link #_element} is resized.
|
|
28
|
+
*/
|
|
29
|
+
private readonly _callback;
|
|
30
|
+
/**
|
|
31
|
+
* The single native observer instance shared across all {@link module:utils/dom/resizeobserver~ResizeObserver} instances.
|
|
32
|
+
*/
|
|
33
|
+
private static _observerInstance;
|
|
34
|
+
/**
|
|
35
|
+
* A mapping of native DOM elements and their callbacks shared across all
|
|
36
|
+
* {@link module:utils/dom/resizeobserver~ResizeObserver} instances.
|
|
37
|
+
*/
|
|
38
|
+
private static _elementCallbacks;
|
|
39
|
+
/**
|
|
40
|
+
* Creates an instance of the `ResizeObserver` class.
|
|
41
|
+
*
|
|
42
|
+
* @param element A DOM element that is to be observed for resizing. Note that
|
|
43
|
+
* the element must be visible (i.e. not detached from DOM) for the observer to work.
|
|
44
|
+
* @param callback A function called when the observed element was resized. It passes
|
|
45
|
+
* the [`ResizeObserverEntry`](https://developer.mozilla.org/en-US/docs/Web/API/ResizeObserverEntry)
|
|
46
|
+
* object with information about the resize event.
|
|
47
|
+
*/
|
|
48
|
+
constructor(element: Element, callback: (entry: ResizeObserverEntry) => void);
|
|
49
|
+
/**
|
|
50
|
+
* The element observed by this observer.
|
|
51
|
+
*/
|
|
52
|
+
get element(): Element;
|
|
53
|
+
/**
|
|
54
|
+
* Destroys the observer which disables the `callback` passed to the {@link #constructor}.
|
|
55
|
+
*/
|
|
56
|
+
destroy(): void;
|
|
57
|
+
/**
|
|
58
|
+
* Registers a new resize callback for the DOM element.
|
|
59
|
+
*/
|
|
60
|
+
private static _addElementCallback;
|
|
61
|
+
/**
|
|
62
|
+
* Removes a resize callback from the DOM element. If no callbacks are left
|
|
63
|
+
* for the element, it removes the element from the native observer.
|
|
64
|
+
*/
|
|
65
|
+
private static _deleteElementCallback;
|
|
66
|
+
/**
|
|
67
|
+
* Returns are registered resize callbacks for the DOM element.
|
|
68
|
+
*/
|
|
69
|
+
private static _getElementCallbacks;
|
|
70
|
+
/**
|
|
71
|
+
* Creates the single native observer shared across all `ResizeObserver` instances.
|
|
72
|
+
*/
|
|
73
|
+
private static _createObserver;
|
|
74
|
+
}
|
|
@@ -1,126 +1,126 @@
|
|
|
1
|
-
/**
|
|
2
|
-
* @license Copyright (c) 2003-2023, CKSource Holding sp. z o.o. All rights reserved.
|
|
3
|
-
* For licensing, see LICENSE.md or https://ckeditor.com/legal/ckeditor-oss-license
|
|
4
|
-
*/
|
|
5
|
-
/**
|
|
6
|
-
* @module utils/dom/resizeobserver
|
|
7
|
-
*/
|
|
8
|
-
import global from './global';
|
|
9
|
-
/**
|
|
10
|
-
* A helper class which instances allow performing custom actions when native DOM elements are resized.
|
|
11
|
-
*
|
|
12
|
-
* ```ts
|
|
13
|
-
* const editableElement = editor.editing.view.getDomRoot();
|
|
14
|
-
*
|
|
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
|
-
* ```
|
|
21
|
-
*
|
|
22
|
-
* It uses the [native DOM resize observer](https://developer.mozilla.org/en-US/docs/Web/API/ResizeObserver)
|
|
23
|
-
* under the hood.
|
|
24
|
-
*/
|
|
25
|
-
export default class ResizeObserver {
|
|
26
|
-
/**
|
|
27
|
-
* Creates an instance of the `ResizeObserver` class.
|
|
28
|
-
*
|
|
29
|
-
* @param element A DOM element that is to be observed for resizing. Note that
|
|
30
|
-
* the element must be visible (i.e. not detached from DOM) for the observer to work.
|
|
31
|
-
* @param callback A function called when the observed element was resized. It passes
|
|
32
|
-
* the [`ResizeObserverEntry`](https://developer.mozilla.org/en-US/docs/Web/API/ResizeObserverEntry)
|
|
33
|
-
* object with information about the resize event.
|
|
34
|
-
*/
|
|
35
|
-
constructor(element, callback) {
|
|
36
|
-
// **Note**: For the maximum performance, this class ensures only a single instance of the native
|
|
37
|
-
// observer is used no matter how many instances of this class were created.
|
|
38
|
-
if (!ResizeObserver._observerInstance) {
|
|
39
|
-
ResizeObserver._createObserver();
|
|
40
|
-
}
|
|
41
|
-
this._element = element;
|
|
42
|
-
this._callback = callback;
|
|
43
|
-
ResizeObserver._addElementCallback(element, callback);
|
|
44
|
-
ResizeObserver._observerInstance.observe(element);
|
|
45
|
-
}
|
|
46
|
-
/**
|
|
47
|
-
* The element observed by this observer.
|
|
48
|
-
*/
|
|
49
|
-
get element() {
|
|
50
|
-
return this._element;
|
|
51
|
-
}
|
|
52
|
-
/**
|
|
53
|
-
* Destroys the observer which disables the `callback` passed to the {@link #constructor}.
|
|
54
|
-
*/
|
|
55
|
-
destroy() {
|
|
56
|
-
ResizeObserver._deleteElementCallback(this._element, this._callback);
|
|
57
|
-
}
|
|
58
|
-
/**
|
|
59
|
-
* Registers a new resize callback for the DOM element.
|
|
60
|
-
*/
|
|
61
|
-
static _addElementCallback(element, callback) {
|
|
62
|
-
if (!ResizeObserver._elementCallbacks) {
|
|
63
|
-
ResizeObserver._elementCallbacks = new Map();
|
|
64
|
-
}
|
|
65
|
-
let callbacks = ResizeObserver._elementCallbacks.get(element);
|
|
66
|
-
if (!callbacks) {
|
|
67
|
-
callbacks = new Set();
|
|
68
|
-
ResizeObserver._elementCallbacks.set(element, callbacks);
|
|
69
|
-
}
|
|
70
|
-
callbacks.add(callback);
|
|
71
|
-
}
|
|
72
|
-
/**
|
|
73
|
-
* Removes a resize callback from the DOM element. If no callbacks are left
|
|
74
|
-
* for the element, it removes the element from the native observer.
|
|
75
|
-
*/
|
|
76
|
-
static _deleteElementCallback(element, callback) {
|
|
77
|
-
const callbacks = ResizeObserver._getElementCallbacks(element);
|
|
78
|
-
// Remove the element callback. Check if exist first in case someone
|
|
79
|
-
// called destroy() twice.
|
|
80
|
-
if (callbacks) {
|
|
81
|
-
callbacks.delete(callback);
|
|
82
|
-
// If no callbacks left for the element, also remove the element.
|
|
83
|
-
if (!callbacks.size) {
|
|
84
|
-
ResizeObserver._elementCallbacks.delete(element);
|
|
85
|
-
ResizeObserver._observerInstance.unobserve(element);
|
|
86
|
-
}
|
|
87
|
-
}
|
|
88
|
-
if (ResizeObserver._elementCallbacks && !ResizeObserver._elementCallbacks.size) {
|
|
89
|
-
ResizeObserver._observerInstance = null;
|
|
90
|
-
ResizeObserver._elementCallbacks = null;
|
|
91
|
-
}
|
|
92
|
-
}
|
|
93
|
-
/**
|
|
94
|
-
* Returns are registered resize callbacks for the DOM element.
|
|
95
|
-
*/
|
|
96
|
-
static _getElementCallbacks(element) {
|
|
97
|
-
if (!ResizeObserver._elementCallbacks) {
|
|
98
|
-
return null;
|
|
99
|
-
}
|
|
100
|
-
return ResizeObserver._elementCallbacks.get(element);
|
|
101
|
-
}
|
|
102
|
-
/**
|
|
103
|
-
* Creates the single native observer shared across all `ResizeObserver` instances.
|
|
104
|
-
*/
|
|
105
|
-
static _createObserver() {
|
|
106
|
-
ResizeObserver._observerInstance = new global.window.ResizeObserver(entries => {
|
|
107
|
-
for (const entry of entries) {
|
|
108
|
-
const callbacks = ResizeObserver._getElementCallbacks(entry.target);
|
|
109
|
-
if (callbacks) {
|
|
110
|
-
for (const callback of callbacks) {
|
|
111
|
-
callback(entry);
|
|
112
|
-
}
|
|
113
|
-
}
|
|
114
|
-
}
|
|
115
|
-
});
|
|
116
|
-
}
|
|
117
|
-
}
|
|
118
|
-
/**
|
|
119
|
-
* The single native observer instance shared across all {@link module:utils/dom/resizeobserver~ResizeObserver} instances.
|
|
120
|
-
*/
|
|
121
|
-
ResizeObserver._observerInstance = null;
|
|
122
|
-
/**
|
|
123
|
-
* A mapping of native DOM elements and their callbacks shared across all
|
|
124
|
-
* {@link module:utils/dom/resizeobserver~ResizeObserver} instances.
|
|
125
|
-
*/
|
|
126
|
-
ResizeObserver._elementCallbacks = null;
|
|
1
|
+
/**
|
|
2
|
+
* @license Copyright (c) 2003-2023, CKSource Holding sp. z o.o. All rights reserved.
|
|
3
|
+
* For licensing, see LICENSE.md or https://ckeditor.com/legal/ckeditor-oss-license
|
|
4
|
+
*/
|
|
5
|
+
/**
|
|
6
|
+
* @module utils/dom/resizeobserver
|
|
7
|
+
*/
|
|
8
|
+
import global from './global';
|
|
9
|
+
/**
|
|
10
|
+
* A helper class which instances allow performing custom actions when native DOM elements are resized.
|
|
11
|
+
*
|
|
12
|
+
* ```ts
|
|
13
|
+
* const editableElement = editor.editing.view.getDomRoot();
|
|
14
|
+
*
|
|
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
|
+
* ```
|
|
21
|
+
*
|
|
22
|
+
* It uses the [native DOM resize observer](https://developer.mozilla.org/en-US/docs/Web/API/ResizeObserver)
|
|
23
|
+
* under the hood.
|
|
24
|
+
*/
|
|
25
|
+
export default class ResizeObserver {
|
|
26
|
+
/**
|
|
27
|
+
* Creates an instance of the `ResizeObserver` class.
|
|
28
|
+
*
|
|
29
|
+
* @param element A DOM element that is to be observed for resizing. Note that
|
|
30
|
+
* the element must be visible (i.e. not detached from DOM) for the observer to work.
|
|
31
|
+
* @param callback A function called when the observed element was resized. It passes
|
|
32
|
+
* the [`ResizeObserverEntry`](https://developer.mozilla.org/en-US/docs/Web/API/ResizeObserverEntry)
|
|
33
|
+
* object with information about the resize event.
|
|
34
|
+
*/
|
|
35
|
+
constructor(element, callback) {
|
|
36
|
+
// **Note**: For the maximum performance, this class ensures only a single instance of the native
|
|
37
|
+
// observer is used no matter how many instances of this class were created.
|
|
38
|
+
if (!ResizeObserver._observerInstance) {
|
|
39
|
+
ResizeObserver._createObserver();
|
|
40
|
+
}
|
|
41
|
+
this._element = element;
|
|
42
|
+
this._callback = callback;
|
|
43
|
+
ResizeObserver._addElementCallback(element, callback);
|
|
44
|
+
ResizeObserver._observerInstance.observe(element);
|
|
45
|
+
}
|
|
46
|
+
/**
|
|
47
|
+
* The element observed by this observer.
|
|
48
|
+
*/
|
|
49
|
+
get element() {
|
|
50
|
+
return this._element;
|
|
51
|
+
}
|
|
52
|
+
/**
|
|
53
|
+
* Destroys the observer which disables the `callback` passed to the {@link #constructor}.
|
|
54
|
+
*/
|
|
55
|
+
destroy() {
|
|
56
|
+
ResizeObserver._deleteElementCallback(this._element, this._callback);
|
|
57
|
+
}
|
|
58
|
+
/**
|
|
59
|
+
* Registers a new resize callback for the DOM element.
|
|
60
|
+
*/
|
|
61
|
+
static _addElementCallback(element, callback) {
|
|
62
|
+
if (!ResizeObserver._elementCallbacks) {
|
|
63
|
+
ResizeObserver._elementCallbacks = new Map();
|
|
64
|
+
}
|
|
65
|
+
let callbacks = ResizeObserver._elementCallbacks.get(element);
|
|
66
|
+
if (!callbacks) {
|
|
67
|
+
callbacks = new Set();
|
|
68
|
+
ResizeObserver._elementCallbacks.set(element, callbacks);
|
|
69
|
+
}
|
|
70
|
+
callbacks.add(callback);
|
|
71
|
+
}
|
|
72
|
+
/**
|
|
73
|
+
* Removes a resize callback from the DOM element. If no callbacks are left
|
|
74
|
+
* for the element, it removes the element from the native observer.
|
|
75
|
+
*/
|
|
76
|
+
static _deleteElementCallback(element, callback) {
|
|
77
|
+
const callbacks = ResizeObserver._getElementCallbacks(element);
|
|
78
|
+
// Remove the element callback. Check if exist first in case someone
|
|
79
|
+
// called destroy() twice.
|
|
80
|
+
if (callbacks) {
|
|
81
|
+
callbacks.delete(callback);
|
|
82
|
+
// If no callbacks left for the element, also remove the element.
|
|
83
|
+
if (!callbacks.size) {
|
|
84
|
+
ResizeObserver._elementCallbacks.delete(element);
|
|
85
|
+
ResizeObserver._observerInstance.unobserve(element);
|
|
86
|
+
}
|
|
87
|
+
}
|
|
88
|
+
if (ResizeObserver._elementCallbacks && !ResizeObserver._elementCallbacks.size) {
|
|
89
|
+
ResizeObserver._observerInstance = null;
|
|
90
|
+
ResizeObserver._elementCallbacks = null;
|
|
91
|
+
}
|
|
92
|
+
}
|
|
93
|
+
/**
|
|
94
|
+
* Returns are registered resize callbacks for the DOM element.
|
|
95
|
+
*/
|
|
96
|
+
static _getElementCallbacks(element) {
|
|
97
|
+
if (!ResizeObserver._elementCallbacks) {
|
|
98
|
+
return null;
|
|
99
|
+
}
|
|
100
|
+
return ResizeObserver._elementCallbacks.get(element);
|
|
101
|
+
}
|
|
102
|
+
/**
|
|
103
|
+
* Creates the single native observer shared across all `ResizeObserver` instances.
|
|
104
|
+
*/
|
|
105
|
+
static _createObserver() {
|
|
106
|
+
ResizeObserver._observerInstance = new global.window.ResizeObserver(entries => {
|
|
107
|
+
for (const entry of entries) {
|
|
108
|
+
const callbacks = ResizeObserver._getElementCallbacks(entry.target);
|
|
109
|
+
if (callbacks) {
|
|
110
|
+
for (const callback of callbacks) {
|
|
111
|
+
callback(entry);
|
|
112
|
+
}
|
|
113
|
+
}
|
|
114
|
+
}
|
|
115
|
+
});
|
|
116
|
+
}
|
|
117
|
+
}
|
|
118
|
+
/**
|
|
119
|
+
* The single native observer instance shared across all {@link module:utils/dom/resizeobserver~ResizeObserver} instances.
|
|
120
|
+
*/
|
|
121
|
+
ResizeObserver._observerInstance = null;
|
|
122
|
+
/**
|
|
123
|
+
* A mapping of native DOM elements and their callbacks shared across all
|
|
124
|
+
* {@link module:utils/dom/resizeobserver~ResizeObserver} instances.
|
|
125
|
+
*/
|
|
126
|
+
ResizeObserver._elementCallbacks = null;
|
package/src/dom/scroll.d.ts
CHANGED
|
@@ -1,73 +1,73 @@
|
|
|
1
|
-
/**
|
|
2
|
-
* @license Copyright (c) 2003-2023, CKSource Holding sp. z o.o. All rights reserved.
|
|
3
|
-
* For licensing, see LICENSE.md or https://ckeditor.com/legal/ckeditor-oss-license
|
|
4
|
-
*/
|
|
5
|
-
type IfTrue<T> = T extends true ? true : never;
|
|
6
|
-
/**
|
|
7
|
-
* Makes any page `HTMLElement` or `Range` (`target`) visible inside the browser viewport.
|
|
8
|
-
* This helper will scroll all `target` ancestors and the web browser viewport to reveal the target to
|
|
9
|
-
* the user. If the `target` is already visible, nothing will happen.
|
|
10
|
-
*
|
|
11
|
-
* @param options Additional configuration of the scrolling behavior.
|
|
12
|
-
* @param options.target A target, which supposed to become visible to the user.
|
|
13
|
-
* @param options.viewportOffset An offset from the edge of the viewport (in pixels)
|
|
14
|
-
* the `target` will be moved by if the viewport is scrolled. It enhances the user experience
|
|
15
|
-
* by keeping the `target` some distance from the edge of the viewport and thus making it easier to
|
|
16
|
-
* read or edit by the user.
|
|
17
|
-
* @param options.ancestorOffset An offset from the boundary of scrollable ancestors (if any)
|
|
18
|
-
* the `target` will be moved by if the viewport is scrolled. It enhances the user experience
|
|
19
|
-
* by keeping the `target` some distance from the edge of the ancestors and thus making it easier to
|
|
20
|
-
* read or edit by the user.
|
|
21
|
-
* @param options.alignToTop When set `true`, the helper will make sure the `target` is scrolled up
|
|
22
|
-
* to the top boundary of the viewport and/or scrollable ancestors if scrolled up. When not set
|
|
23
|
-
* (default), the `target` will be revealed by scrolling as little as possible. This option will
|
|
24
|
-
* not affect `targets` that must be scrolled down because they will appear at the top of the boundary
|
|
25
|
-
* anyway.
|
|
26
|
-
*
|
|
27
|
-
* ```
|
|
28
|
-
* scrollViewportToShowTarget() with scrollViewportToShowTarget() with
|
|
29
|
-
* Initial state alignToTop unset (default) alignToTop = true
|
|
30
|
-
*
|
|
31
|
-
* ┌────────────────────────────────┬─┐ ┌────────────────────────────────┬─┐ ┌────────────────────────────────┬─┐
|
|
32
|
-
* │ │▲│ │ │▲│ │ [ Target to be revealed ] │▲│
|
|
33
|
-
* │ │ │ │ │ │ │ │ │
|
|
34
|
-
* │ │█│ │ │ │ │ │ │
|
|
35
|
-
* │ │█│ │ │ │ │ │ │
|
|
36
|
-
* │ │ │ │ │█│ │ │ │
|
|
37
|
-
* │ │ │ │ │█│ │ │█│
|
|
38
|
-
* │ │ │ │ │ │ │ │█│
|
|
39
|
-
* │ │▼│ │ [ Target to be revealed ] │▼│ │ │▼│
|
|
40
|
-
* └────────────────────────────────┴─┘ └────────────────────────────────┴─┘ └────────────────────────────────┴─┘
|
|
41
|
-
*
|
|
42
|
-
*
|
|
43
|
-
* [ Target to be revealed ]
|
|
44
|
-
*```
|
|
45
|
-
*
|
|
46
|
-
* @param options.forceScroll When set `true`, the `target` will be aligned to the top of the viewport
|
|
47
|
-
* and scrollable ancestors whether it is already visible or not. This option will only work when `alignToTop`
|
|
48
|
-
* is `true`
|
|
49
|
-
*/
|
|
50
|
-
export declare function scrollViewportToShowTarget<T extends boolean, U extends IfTrue<T>>({ target, viewportOffset, ancestorOffset, alignToTop, forceScroll }: {
|
|
51
|
-
readonly target: HTMLElement | Range;
|
|
52
|
-
readonly viewportOffset?: number | {
|
|
53
|
-
top: number;
|
|
54
|
-
bottom: number;
|
|
55
|
-
left: number;
|
|
56
|
-
right: number;
|
|
57
|
-
};
|
|
58
|
-
readonly ancestorOffset?: number;
|
|
59
|
-
readonly alignToTop?: T;
|
|
60
|
-
readonly forceScroll?: U;
|
|
61
|
-
}): void;
|
|
62
|
-
/**
|
|
63
|
-
* Makes any page `HTMLElement` or `Range` (target) visible within its scrollable ancestors,
|
|
64
|
-
* e.g. if they have `overflow: scroll` CSS style.
|
|
65
|
-
*
|
|
66
|
-
* @param target A target, which supposed to become visible to the user.
|
|
67
|
-
* @param ancestorOffset An offset between the target and the boundary of scrollable ancestors
|
|
68
|
-
* to be maintained while scrolling.
|
|
69
|
-
* @param limiterElement The outermost ancestor that should be scrolled. If specified, it can prevent
|
|
70
|
-
* scrolling the whole page.
|
|
71
|
-
*/
|
|
72
|
-
export declare function scrollAncestorsToShowTarget(target: HTMLElement | Range, ancestorOffset?: number, limiterElement?: HTMLElement): void;
|
|
73
|
-
export {};
|
|
1
|
+
/**
|
|
2
|
+
* @license Copyright (c) 2003-2023, CKSource Holding sp. z o.o. All rights reserved.
|
|
3
|
+
* For licensing, see LICENSE.md or https://ckeditor.com/legal/ckeditor-oss-license
|
|
4
|
+
*/
|
|
5
|
+
type IfTrue<T> = T extends true ? true : never;
|
|
6
|
+
/**
|
|
7
|
+
* Makes any page `HTMLElement` or `Range` (`target`) visible inside the browser viewport.
|
|
8
|
+
* This helper will scroll all `target` ancestors and the web browser viewport to reveal the target to
|
|
9
|
+
* the user. If the `target` is already visible, nothing will happen.
|
|
10
|
+
*
|
|
11
|
+
* @param options Additional configuration of the scrolling behavior.
|
|
12
|
+
* @param options.target A target, which supposed to become visible to the user.
|
|
13
|
+
* @param options.viewportOffset An offset from the edge of the viewport (in pixels)
|
|
14
|
+
* the `target` will be moved by if the viewport is scrolled. It enhances the user experience
|
|
15
|
+
* by keeping the `target` some distance from the edge of the viewport and thus making it easier to
|
|
16
|
+
* read or edit by the user.
|
|
17
|
+
* @param options.ancestorOffset An offset from the boundary of scrollable ancestors (if any)
|
|
18
|
+
* the `target` will be moved by if the viewport is scrolled. It enhances the user experience
|
|
19
|
+
* by keeping the `target` some distance from the edge of the ancestors and thus making it easier to
|
|
20
|
+
* read or edit by the user.
|
|
21
|
+
* @param options.alignToTop When set `true`, the helper will make sure the `target` is scrolled up
|
|
22
|
+
* to the top boundary of the viewport and/or scrollable ancestors if scrolled up. When not set
|
|
23
|
+
* (default), the `target` will be revealed by scrolling as little as possible. This option will
|
|
24
|
+
* not affect `targets` that must be scrolled down because they will appear at the top of the boundary
|
|
25
|
+
* anyway.
|
|
26
|
+
*
|
|
27
|
+
* ```
|
|
28
|
+
* scrollViewportToShowTarget() with scrollViewportToShowTarget() with
|
|
29
|
+
* Initial state alignToTop unset (default) alignToTop = true
|
|
30
|
+
*
|
|
31
|
+
* ┌────────────────────────────────┬─┐ ┌────────────────────────────────┬─┐ ┌────────────────────────────────┬─┐
|
|
32
|
+
* │ │▲│ │ │▲│ │ [ Target to be revealed ] │▲│
|
|
33
|
+
* │ │ │ │ │ │ │ │ │
|
|
34
|
+
* │ │█│ │ │ │ │ │ │
|
|
35
|
+
* │ │█│ │ │ │ │ │ │
|
|
36
|
+
* │ │ │ │ │█│ │ │ │
|
|
37
|
+
* │ │ │ │ │█│ │ │█│
|
|
38
|
+
* │ │ │ │ │ │ │ │█│
|
|
39
|
+
* │ │▼│ │ [ Target to be revealed ] │▼│ │ │▼│
|
|
40
|
+
* └────────────────────────────────┴─┘ └────────────────────────────────┴─┘ └────────────────────────────────┴─┘
|
|
41
|
+
*
|
|
42
|
+
*
|
|
43
|
+
* [ Target to be revealed ]
|
|
44
|
+
*```
|
|
45
|
+
*
|
|
46
|
+
* @param options.forceScroll When set `true`, the `target` will be aligned to the top of the viewport
|
|
47
|
+
* and scrollable ancestors whether it is already visible or not. This option will only work when `alignToTop`
|
|
48
|
+
* is `true`
|
|
49
|
+
*/
|
|
50
|
+
export declare function scrollViewportToShowTarget<T extends boolean, U extends IfTrue<T>>({ target, viewportOffset, ancestorOffset, alignToTop, forceScroll }: {
|
|
51
|
+
readonly target: HTMLElement | Range;
|
|
52
|
+
readonly viewportOffset?: number | {
|
|
53
|
+
top: number;
|
|
54
|
+
bottom: number;
|
|
55
|
+
left: number;
|
|
56
|
+
right: number;
|
|
57
|
+
};
|
|
58
|
+
readonly ancestorOffset?: number;
|
|
59
|
+
readonly alignToTop?: T;
|
|
60
|
+
readonly forceScroll?: U;
|
|
61
|
+
}): void;
|
|
62
|
+
/**
|
|
63
|
+
* Makes any page `HTMLElement` or `Range` (target) visible within its scrollable ancestors,
|
|
64
|
+
* e.g. if they have `overflow: scroll` CSS style.
|
|
65
|
+
*
|
|
66
|
+
* @param target A target, which supposed to become visible to the user.
|
|
67
|
+
* @param ancestorOffset An offset between the target and the boundary of scrollable ancestors
|
|
68
|
+
* to be maintained while scrolling.
|
|
69
|
+
* @param limiterElement The outermost ancestor that should be scrolled. If specified, it can prevent
|
|
70
|
+
* scrolling the whole page.
|
|
71
|
+
*/
|
|
72
|
+
export declare function scrollAncestorsToShowTarget(target: HTMLElement | Range, ancestorOffset?: number, limiterElement?: HTMLElement): void;
|
|
73
|
+
export {};
|