@ckeditor/ckeditor5-utils 0.0.0-internal-20241017.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 +4 -0
- package/LICENSE.md +21 -0
- package/README.md +22 -0
- package/dist/abortabledebounce.d.ts +21 -0
- package/dist/areconnectedthroughproperties.d.ts +15 -0
- package/dist/ckeditorerror.d.ts +127 -0
- package/dist/collection.d.ts +437 -0
- package/dist/comparearrays.d.ts +34 -0
- package/dist/config.d.ts +167 -0
- package/dist/count.d.ts +22 -0
- package/dist/crc32.d.ts +30 -0
- package/dist/delay.d.ts +23 -0
- package/dist/diff.d.ts +35 -0
- package/dist/difftochanges.d.ts +63 -0
- package/dist/dom/createelement.d.ts +61 -0
- package/dist/dom/emittermixin.d.ts +146 -0
- package/dist/dom/findclosestscrollableancestor.d.ts +15 -0
- package/dist/dom/getancestors.d.ts +21 -0
- package/dist/dom/getborderwidths.d.ts +28 -0
- package/dist/dom/getcommonancestor.d.ts +16 -0
- package/dist/dom/getdatafromelement.d.ts +18 -0
- package/dist/dom/getpositionedancestor.d.ts +14 -0
- package/dist/dom/getrangefrommouseevent.d.ts +21 -0
- package/dist/dom/global.d.ts +36 -0
- package/dist/dom/indexof.d.ts +18 -0
- package/dist/dom/insertat.d.ts +19 -0
- package/dist/dom/iscomment.d.ts +15 -0
- package/dist/dom/isnode.d.ts +15 -0
- package/dist/dom/isrange.d.ts +15 -0
- package/dist/dom/istext.d.ts +15 -0
- package/dist/dom/isvalidattributename.d.ts +14 -0
- package/dist/dom/isvisible.d.ts +19 -0
- package/dist/dom/iswindow.d.ts +15 -0
- package/dist/dom/position.d.ts +215 -0
- package/dist/dom/rect.d.ts +199 -0
- package/dist/dom/remove.d.ts +17 -0
- package/dist/dom/resizeobserver.d.ts +78 -0
- package/dist/dom/scroll.d.ts +77 -0
- package/dist/dom/setdatainelement.d.ts +18 -0
- package/dist/dom/tounit.d.ts +26 -0
- package/dist/elementreplacer.d.ts +35 -0
- package/dist/emittermixin.d.ts +316 -0
- package/dist/env.d.ts +144 -0
- package/dist/eventinfo.d.ts +62 -0
- package/dist/fastdiff.d.ts +116 -0
- package/dist/first.d.ts +15 -0
- package/dist/focustracker.d.ts +83 -0
- package/dist/index-content.css +4 -0
- package/dist/index-editor.css +4 -0
- package/dist/index.css +4 -0
- package/dist/index.d.ts +70 -0
- package/dist/index.js +5871 -0
- package/dist/index.js.map +1 -0
- package/dist/inserttopriorityarray.d.ts +34 -0
- package/dist/isiterable.d.ts +18 -0
- package/dist/keyboard.d.ts +130 -0
- package/dist/keystrokehandler.d.ts +101 -0
- package/dist/language.d.ts +21 -0
- package/dist/locale.d.ts +145 -0
- package/dist/mapsequal.d.ts +19 -0
- package/dist/mix.d.ts +89 -0
- package/dist/nth.d.ts +20 -0
- package/dist/objecttomap.d.ts +27 -0
- package/dist/observablemixin.d.ts +564 -0
- package/dist/parsebase64encodedobject.d.ts +15 -0
- package/dist/priorities.d.ts +37 -0
- package/dist/retry.d.ts +37 -0
- package/dist/splicearray.d.ts +30 -0
- package/dist/spy.d.ts +25 -0
- package/dist/toarray.d.ts +29 -0
- package/dist/tomap.d.ts +23 -0
- package/dist/translation-service.d.ts +178 -0
- package/dist/uid.d.ts +19 -0
- package/dist/unicode.d.ts +58 -0
- package/dist/version.d.ts +14 -0
- package/dist/wait.d.ts +20 -0
- package/package.json +36 -0
- package/src/abortabledebounce.d.ts +17 -0
- package/src/abortabledebounce.js +22 -0
- package/src/areconnectedthroughproperties.d.ts +11 -0
- package/src/areconnectedthroughproperties.js +73 -0
- package/src/ckeditorerror.d.ts +123 -0
- package/src/ckeditorerror.js +176 -0
- package/src/collection.d.ts +433 -0
- package/src/collection.js +583 -0
- package/src/comparearrays.d.ts +30 -0
- package/src/comparearrays.js +47 -0
- package/src/config.d.ts +163 -0
- package/src/config.js +163 -0
- package/src/count.d.ts +18 -0
- package/src/count.js +25 -0
- package/src/crc32.d.ts +26 -0
- package/src/crc32.js +61 -0
- package/src/delay.d.ts +19 -0
- package/src/delay.js +26 -0
- package/src/diff.d.ts +31 -0
- package/src/diff.js +115 -0
- package/src/difftochanges.d.ts +59 -0
- package/src/difftochanges.js +79 -0
- package/src/dom/createelement.d.ts +57 -0
- package/src/dom/createelement.js +40 -0
- package/src/dom/emittermixin.d.ts +142 -0
- package/src/dom/emittermixin.js +239 -0
- package/src/dom/findclosestscrollableancestor.d.ts +11 -0
- package/src/dom/findclosestscrollableancestor.js +31 -0
- package/src/dom/getancestors.d.ts +17 -0
- package/src/dom/getancestors.js +27 -0
- package/src/dom/getborderwidths.d.ts +24 -0
- package/src/dom/getborderwidths.js +24 -0
- package/src/dom/getcommonancestor.d.ts +12 -0
- package/src/dom/getcommonancestor.js +25 -0
- package/src/dom/getdatafromelement.d.ts +14 -0
- package/src/dom/getdatafromelement.js +20 -0
- package/src/dom/getpositionedancestor.d.ts +10 -0
- package/src/dom/getpositionedancestor.js +22 -0
- package/src/dom/getrangefrommouseevent.d.ts +17 -0
- package/src/dom/getrangefrommouseevent.js +33 -0
- package/src/dom/global.d.ts +32 -0
- package/src/dom/global.js +35 -0
- package/src/dom/indexof.d.ts +14 -0
- package/src/dom/indexof.js +21 -0
- package/src/dom/insertat.d.ts +15 -0
- package/src/dom/insertat.js +17 -0
- package/src/dom/iscomment.d.ts +11 -0
- package/src/dom/iscomment.js +14 -0
- package/src/dom/isnode.d.ts +11 -0
- package/src/dom/isnode.js +21 -0
- package/src/dom/isrange.d.ts +11 -0
- package/src/dom/isrange.js +13 -0
- package/src/dom/istext.d.ts +11 -0
- package/src/dom/istext.js +13 -0
- package/src/dom/isvalidattributename.d.ts +10 -0
- package/src/dom/isvalidattributename.js +22 -0
- package/src/dom/isvisible.d.ts +15 -0
- package/src/dom/isvisible.js +30 -0
- package/src/dom/iswindow.d.ts +11 -0
- package/src/dom/iswindow.js +22 -0
- package/src/dom/position.d.ts +211 -0
- package/src/dom/position.js +313 -0
- package/src/dom/rect.d.ts +195 -0
- package/src/dom/rect.js +474 -0
- package/src/dom/remove.d.ts +13 -0
- package/src/dom/remove.js +18 -0
- package/src/dom/resizeobserver.d.ts +74 -0
- package/src/dom/resizeobserver.js +127 -0
- package/src/dom/scroll.d.ts +73 -0
- package/src/dom/scroll.js +383 -0
- package/src/dom/setdatainelement.d.ts +14 -0
- package/src/dom/setdatainelement.js +20 -0
- package/src/dom/tounit.d.ts +22 -0
- package/src/dom/tounit.js +16 -0
- package/src/elementreplacer.d.ts +31 -0
- package/src/elementreplacer.js +43 -0
- package/src/emittermixin.d.ts +312 -0
- package/src/emittermixin.js +453 -0
- package/src/env.d.ts +140 -0
- package/src/env.js +145 -0
- package/src/eventinfo.d.ts +58 -0
- package/src/eventinfo.js +26 -0
- package/src/fastdiff.d.ts +112 -0
- package/src/fastdiff.js +248 -0
- package/src/first.d.ts +11 -0
- package/src/first.js +17 -0
- package/src/focustracker.d.ts +79 -0
- package/src/focustracker.js +101 -0
- package/src/index.d.ts +66 -0
- package/src/index.js +65 -0
- package/src/inserttopriorityarray.d.ts +30 -0
- package/src/inserttopriorityarray.js +21 -0
- package/src/isiterable.d.ts +14 -0
- package/src/isiterable.js +16 -0
- package/src/keyboard.d.ts +126 -0
- package/src/keyboard.js +252 -0
- package/src/keystrokehandler.d.ts +97 -0
- package/src/keystrokehandler.js +122 -0
- package/src/language.d.ts +17 -0
- package/src/language.js +20 -0
- package/src/locale.d.ts +141 -0
- package/src/locale.js +78 -0
- package/src/mapsequal.d.ts +15 -0
- package/src/mapsequal.js +27 -0
- package/src/mix.d.ts +85 -0
- package/src/mix.js +50 -0
- package/src/nth.d.ts +16 -0
- package/src/nth.js +24 -0
- package/src/objecttomap.d.ts +23 -0
- package/src/objecttomap.js +27 -0
- package/src/observablemixin.d.ts +560 -0
- package/src/observablemixin.js +580 -0
- package/src/parsebase64encodedobject.d.ts +11 -0
- package/src/parsebase64encodedobject.js +22 -0
- package/src/priorities.d.ts +33 -0
- package/src/priorities.js +23 -0
- package/src/retry.d.ts +33 -0
- package/src/retry.js +47 -0
- package/src/splicearray.d.ts +26 -0
- package/src/splicearray.js +40 -0
- package/src/spy.d.ts +21 -0
- package/src/spy.js +22 -0
- package/src/toarray.d.ts +25 -0
- package/src/toarray.js +7 -0
- package/src/tomap.d.ts +19 -0
- package/src/tomap.js +29 -0
- package/src/translation-service.d.ts +174 -0
- package/src/translation-service.js +209 -0
- package/src/uid.d.ts +15 -0
- package/src/uid.js +45 -0
- package/src/unicode.d.ts +54 -0
- package/src/unicode.js +85 -0
- package/src/version.d.ts +10 -0
- package/src/version.js +179 -0
- package/src/wait.d.ts +16 -0
- package/src/wait.js +29 -0
|
@@ -0,0 +1,59 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* @license Copyright (c) 2003-2024, 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
|
+
import type { DiffResult } from './diff.js';
|
|
6
|
+
/**
|
|
7
|
+
* @module utils/difftochanges
|
|
8
|
+
*/
|
|
9
|
+
/**
|
|
10
|
+
* Creates a set of changes which need to be applied to the input in order to transform
|
|
11
|
+
* it into the output. This function can be used with strings or arrays.
|
|
12
|
+
*
|
|
13
|
+
* ```ts
|
|
14
|
+
* const input = Array.from( 'abc' );
|
|
15
|
+
* const output = Array.from( 'xaby' );
|
|
16
|
+
* const changes = diffToChanges( diff( input, output ), output );
|
|
17
|
+
*
|
|
18
|
+
* changes.forEach( change => {
|
|
19
|
+
* if ( change.type == 'insert' ) {
|
|
20
|
+
* input.splice( change.index, 0, ...change.values );
|
|
21
|
+
* } else if ( change.type == 'delete' ) {
|
|
22
|
+
* input.splice( change.index, change.howMany );
|
|
23
|
+
* }
|
|
24
|
+
* } );
|
|
25
|
+
*
|
|
26
|
+
* input.join( '' ) == output.join( '' ); // -> true
|
|
27
|
+
* ```
|
|
28
|
+
*
|
|
29
|
+
* @typeParam T The type of output array element.
|
|
30
|
+
* @param diff Result of {@link module:utils/diff~diff}.
|
|
31
|
+
* @param output The string or array which was passed as diff's output.
|
|
32
|
+
* @returns Set of changes (insert or delete) which need to be applied to the input
|
|
33
|
+
* in order to transform it into the output.
|
|
34
|
+
*/
|
|
35
|
+
export default function diffToChanges<T>(diff: ReadonlyArray<DiffResult>, output: ArrayLike<T>): Array<Change<T>>;
|
|
36
|
+
/**
|
|
37
|
+
* An object describing insertion change.
|
|
38
|
+
*
|
|
39
|
+
* @typeParam T The type of output array element.
|
|
40
|
+
*/
|
|
41
|
+
export interface InsertChange<T> {
|
|
42
|
+
type: 'insert';
|
|
43
|
+
index: number;
|
|
44
|
+
values: Array<T>;
|
|
45
|
+
}
|
|
46
|
+
/**
|
|
47
|
+
* An object describing deletion change.
|
|
48
|
+
*/
|
|
49
|
+
export interface DeleteChange {
|
|
50
|
+
type: 'delete';
|
|
51
|
+
index: number;
|
|
52
|
+
howMany: number;
|
|
53
|
+
}
|
|
54
|
+
/**
|
|
55
|
+
* The element of the result of {@link module:utils/difftochanges~diffToChanges} function.
|
|
56
|
+
*
|
|
57
|
+
* @typeParam T The type of output array element.
|
|
58
|
+
*/
|
|
59
|
+
export type Change<T> = InsertChange<T> | DeleteChange;
|
|
@@ -0,0 +1,79 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* @license Copyright (c) 2003-2024, 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/difftochanges
|
|
7
|
+
*/
|
|
8
|
+
/**
|
|
9
|
+
* Creates a set of changes which need to be applied to the input in order to transform
|
|
10
|
+
* it into the output. This function can be used with strings or arrays.
|
|
11
|
+
*
|
|
12
|
+
* ```ts
|
|
13
|
+
* const input = Array.from( 'abc' );
|
|
14
|
+
* const output = Array.from( 'xaby' );
|
|
15
|
+
* const changes = diffToChanges( diff( input, output ), output );
|
|
16
|
+
*
|
|
17
|
+
* changes.forEach( change => {
|
|
18
|
+
* if ( change.type == 'insert' ) {
|
|
19
|
+
* input.splice( change.index, 0, ...change.values );
|
|
20
|
+
* } else if ( change.type == 'delete' ) {
|
|
21
|
+
* input.splice( change.index, change.howMany );
|
|
22
|
+
* }
|
|
23
|
+
* } );
|
|
24
|
+
*
|
|
25
|
+
* input.join( '' ) == output.join( '' ); // -> true
|
|
26
|
+
* ```
|
|
27
|
+
*
|
|
28
|
+
* @typeParam T The type of output array element.
|
|
29
|
+
* @param diff Result of {@link module:utils/diff~diff}.
|
|
30
|
+
* @param output The string or array which was passed as diff's output.
|
|
31
|
+
* @returns Set of changes (insert or delete) which need to be applied to the input
|
|
32
|
+
* in order to transform it into the output.
|
|
33
|
+
*/
|
|
34
|
+
export default function diffToChanges(diff, output) {
|
|
35
|
+
const changes = [];
|
|
36
|
+
let index = 0;
|
|
37
|
+
let lastOperation = null;
|
|
38
|
+
diff.forEach(change => {
|
|
39
|
+
if (change == 'equal') {
|
|
40
|
+
pushLast();
|
|
41
|
+
index++;
|
|
42
|
+
}
|
|
43
|
+
else if (change == 'insert') {
|
|
44
|
+
if (lastOperation && lastOperation.type == 'insert') {
|
|
45
|
+
lastOperation.values.push(output[index]);
|
|
46
|
+
}
|
|
47
|
+
else {
|
|
48
|
+
pushLast();
|
|
49
|
+
lastOperation = {
|
|
50
|
+
type: 'insert',
|
|
51
|
+
index,
|
|
52
|
+
values: [output[index]]
|
|
53
|
+
};
|
|
54
|
+
}
|
|
55
|
+
index++;
|
|
56
|
+
}
|
|
57
|
+
else /* if ( change == 'delete' ) */ {
|
|
58
|
+
if (lastOperation && lastOperation.type == 'delete') {
|
|
59
|
+
lastOperation.howMany++;
|
|
60
|
+
}
|
|
61
|
+
else {
|
|
62
|
+
pushLast();
|
|
63
|
+
lastOperation = {
|
|
64
|
+
type: 'delete',
|
|
65
|
+
index,
|
|
66
|
+
howMany: 1
|
|
67
|
+
};
|
|
68
|
+
}
|
|
69
|
+
}
|
|
70
|
+
});
|
|
71
|
+
pushLast();
|
|
72
|
+
return changes;
|
|
73
|
+
function pushLast() {
|
|
74
|
+
if (lastOperation) {
|
|
75
|
+
changes.push(lastOperation);
|
|
76
|
+
lastOperation = null;
|
|
77
|
+
}
|
|
78
|
+
}
|
|
79
|
+
}
|
|
@@ -0,0 +1,57 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* @license Copyright (c) 2003-2024, 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
|
+
* Attributes to be applied to the HTML element.
|
|
7
|
+
*/
|
|
8
|
+
type HTMLElementAttributes = {
|
|
9
|
+
readonly [key: string]: string;
|
|
10
|
+
};
|
|
11
|
+
/**
|
|
12
|
+
* Attributes to be applied to the SVG element.
|
|
13
|
+
*/
|
|
14
|
+
type SVGElementAttributes = HTMLElementAttributes & {
|
|
15
|
+
xmlns: string;
|
|
16
|
+
};
|
|
17
|
+
/**
|
|
18
|
+
* Element or elements that will be added to the created element as children. Strings will be automatically turned into Text nodes.
|
|
19
|
+
*/
|
|
20
|
+
type ChildrenElements = Node | string | Iterable<Node | string>;
|
|
21
|
+
/**
|
|
22
|
+
* Creates an SVG element with attributes and children elements.
|
|
23
|
+
*
|
|
24
|
+
* ```ts
|
|
25
|
+
* createElement( document, 'mask', { xmlns: 'http://www.w3.org/2000/svg' } ); // <mask>
|
|
26
|
+
* createElement( document, 'mask', { xmlns: 'http://www.w3.org/2000/svg', id: 'foo' } ); // <mask id="foo">
|
|
27
|
+
* createElement( document, 'mask', { xmlns: 'http://www.w3.org/2000/svg' }, 'foo' ); // <mask>foo</mask>
|
|
28
|
+
* createElement( document, 'mask', { xmlns: 'http://www.w3.org/2000/svg' }, [ createElement(...) ] ); // <mask><...></mask>
|
|
29
|
+
* ```
|
|
30
|
+
*
|
|
31
|
+
* @label SVG_ELEMENT
|
|
32
|
+
* @param doc Document used to create the element.
|
|
33
|
+
* @param name Name of the SVG element.
|
|
34
|
+
* @param attributes Object where keys represent attribute keys and values represent attribute values.
|
|
35
|
+
* @param children Child or any iterable of children. Strings will be automatically turned into Text nodes.
|
|
36
|
+
* @returns SVG element.
|
|
37
|
+
*/
|
|
38
|
+
export default function createElement<T extends keyof SVGElementTagNameMap>(doc: Document, name: T, attributes: SVGElementAttributes, children?: ChildrenElements): SVGElementTagNameMap[T];
|
|
39
|
+
/**
|
|
40
|
+
* Creates an HTML element with attributes and children elements.
|
|
41
|
+
*
|
|
42
|
+
* ```ts
|
|
43
|
+
* createElement( document, 'p' ); // <p>
|
|
44
|
+
* createElement( document, 'p', { class: 'foo' } ); // <p class="foo">
|
|
45
|
+
* createElement( document, 'p', null, 'foo' ); // <p>foo</p>
|
|
46
|
+
* createElement( document, 'p', null, [ createElement(...) ] ); // <p><...></p>
|
|
47
|
+
* ```
|
|
48
|
+
*
|
|
49
|
+
* @label HTML_ELEMENT
|
|
50
|
+
* @param doc Document used to create the element.
|
|
51
|
+
* @param name Name of the HTML element.
|
|
52
|
+
* @param attributes Object where keys represent attribute keys and values represent attribute values.
|
|
53
|
+
* @param children Child or any iterable of children. Strings will be automatically turned into Text nodes.
|
|
54
|
+
* @returns HTML element.
|
|
55
|
+
*/
|
|
56
|
+
export default function createElement<T extends keyof HTMLElementTagNameMap>(doc: Document, name: T, attributes?: HTMLElementAttributes, children?: ChildrenElements): HTMLElementTagNameMap[T];
|
|
57
|
+
export {};
|
|
@@ -0,0 +1,40 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* @license Copyright (c) 2003-2024, 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/createelement
|
|
7
|
+
*/
|
|
8
|
+
import isIterable from '../isiterable.js';
|
|
9
|
+
import { isString } from 'lodash-es';
|
|
10
|
+
/**
|
|
11
|
+
* Creates an HTML or SVG element with attributes and children elements.
|
|
12
|
+
*
|
|
13
|
+
* ```ts
|
|
14
|
+
* createElement( document, 'p' ); // <p>
|
|
15
|
+
* createElement( document, 'mask', { xmlns: 'http://www.w3.org/2000/svg' } ); // <mask>
|
|
16
|
+
* ```
|
|
17
|
+
*
|
|
18
|
+
* @param doc Document used to create the element.
|
|
19
|
+
* @param name Name of the element.
|
|
20
|
+
* @param attributes Object where keys represent attribute keys and values represent attribute values.
|
|
21
|
+
* @param children Child or any iterable of children. Strings will be automatically turned into Text nodes.
|
|
22
|
+
* @returns HTML or SVG element.
|
|
23
|
+
*/
|
|
24
|
+
export default function createElement(doc, name, attributes = {}, children = []) {
|
|
25
|
+
const namespace = attributes && attributes.xmlns;
|
|
26
|
+
const element = namespace ? doc.createElementNS(namespace, name) : doc.createElement(name);
|
|
27
|
+
for (const key in attributes) {
|
|
28
|
+
element.setAttribute(key, attributes[key]);
|
|
29
|
+
}
|
|
30
|
+
if (isString(children) || !isIterable(children)) {
|
|
31
|
+
children = [children];
|
|
32
|
+
}
|
|
33
|
+
for (let child of children) {
|
|
34
|
+
if (isString(child)) {
|
|
35
|
+
child = doc.createTextNode(child);
|
|
36
|
+
}
|
|
37
|
+
element.appendChild(child);
|
|
38
|
+
}
|
|
39
|
+
return element;
|
|
40
|
+
}
|
|
@@ -0,0 +1,142 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* @license Copyright (c) 2003-2024, 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/emittermixin
|
|
7
|
+
*/
|
|
8
|
+
import { type Emitter, type CallbackOptions, type BaseEvent, type GetCallback } from '../emittermixin.js';
|
|
9
|
+
import type EventInfo from '../eventinfo.js';
|
|
10
|
+
import type { Constructor, Mixed } from '../mix.js';
|
|
11
|
+
/**
|
|
12
|
+
* Mixin that injects the DOM events API into its host. It provides the API
|
|
13
|
+
* compatible with {@link module:utils/emittermixin~Emitter}.
|
|
14
|
+
*
|
|
15
|
+
* This function creates a class that inherits from the provided `base` and implements `Emitter` interface.
|
|
16
|
+
*
|
|
17
|
+
* DOM emitter mixin is by default available in the {@link module:ui/view~View} class,
|
|
18
|
+
* but it can also be mixed into any other class:
|
|
19
|
+
*
|
|
20
|
+
* ```ts
|
|
21
|
+
* import DomEmitterMixin from '../utils/dom/emittermixin.js';
|
|
22
|
+
*
|
|
23
|
+
* class BaseClass { ... }
|
|
24
|
+
*
|
|
25
|
+
* class SomeView extends DomEmitterMixin( BaseClass ) {}
|
|
26
|
+
*
|
|
27
|
+
* const view = new SomeView();
|
|
28
|
+
* view.listenTo( domElement, ( evt, domEvt ) => {
|
|
29
|
+
* console.log( evt, domEvt );
|
|
30
|
+
* } );
|
|
31
|
+
* ```
|
|
32
|
+
*
|
|
33
|
+
* @label EXTENDS
|
|
34
|
+
*/
|
|
35
|
+
export default function DomEmitterMixin<Base extends Constructor<Emitter>>(base: Base): Mixed<Base, DomEmitter>;
|
|
36
|
+
/**
|
|
37
|
+
* Mixin that injects the DOM events API into its host. It provides the API
|
|
38
|
+
* compatible with {@link module:utils/emittermixin~Emitter}.
|
|
39
|
+
*
|
|
40
|
+
* This function creates a class that implements `Emitter` interface.
|
|
41
|
+
*
|
|
42
|
+
* DOM emitter mixin is by default available in the {@link module:ui/view~View} class,
|
|
43
|
+
* but it can also be mixed into any other class:
|
|
44
|
+
*
|
|
45
|
+
* ```ts
|
|
46
|
+
* import DomEmitterMixin from '../utils/dom/emittermixin.js';
|
|
47
|
+
*
|
|
48
|
+
* class SomeView extends DomEmitterMixin() {}
|
|
49
|
+
*
|
|
50
|
+
* const view = new SomeView();
|
|
51
|
+
* view.listenTo( domElement, ( evt, domEvt ) => {
|
|
52
|
+
* console.log( evt, domEvt );
|
|
53
|
+
* } );
|
|
54
|
+
* ```
|
|
55
|
+
*
|
|
56
|
+
* @label NO_ARGUMENTS
|
|
57
|
+
*/
|
|
58
|
+
export default function DomEmitterMixin(): {
|
|
59
|
+
new (): DomEmitter;
|
|
60
|
+
prototype: DomEmitter;
|
|
61
|
+
};
|
|
62
|
+
export interface DomEventMap extends HTMLElementEventMap, WindowEventMap {
|
|
63
|
+
}
|
|
64
|
+
/**
|
|
65
|
+
* Interface representing classes which mix in {@link module:utils/dom/emittermixin~DomEmitterMixin}.
|
|
66
|
+
*
|
|
67
|
+
* Can be easily implemented by a class by mixing the {@link module:utils/dom/emittermixin~DomEmitterMixin} mixin.
|
|
68
|
+
*
|
|
69
|
+
* ```ts
|
|
70
|
+
* class MyClass extends DomEmitterMixin( OtherBaseClass ) {
|
|
71
|
+
* // This class now implements the `Emitter` interface.
|
|
72
|
+
* }
|
|
73
|
+
* ```
|
|
74
|
+
*/
|
|
75
|
+
export interface DomEmitter extends Emitter {
|
|
76
|
+
/**
|
|
77
|
+
* Registers a callback function to be executed when an event is fired in a specific Emitter or DOM Node.
|
|
78
|
+
* It is backwards compatible with {@link module:utils/emittermixin~Emitter#listenTo}.
|
|
79
|
+
*
|
|
80
|
+
* @label HTML_EMITTER
|
|
81
|
+
* @param emitter The object that fires the event.
|
|
82
|
+
* @param event The name of the event.
|
|
83
|
+
* @param callback The function to be called on event.
|
|
84
|
+
* @param options Additional options.
|
|
85
|
+
* @param options.useCapture Indicates that events of this type will be dispatched to the registered
|
|
86
|
+
* listener before being dispatched to any EventTarget beneath it in the DOM tree.
|
|
87
|
+
* @param options.usePassive Indicates that the function specified by listener will never call preventDefault()
|
|
88
|
+
* and prevents blocking browser's main thread by this event handler.
|
|
89
|
+
*/
|
|
90
|
+
listenTo<K extends keyof DomEventMap>(emitter: Node | Window, event: K, callback: (this: this, ev: EventInfo, event: DomEventMap[K]) => void, options?: CallbackOptions & {
|
|
91
|
+
readonly useCapture?: boolean;
|
|
92
|
+
readonly usePassive?: boolean;
|
|
93
|
+
}): void;
|
|
94
|
+
/**
|
|
95
|
+
* Registers a callback function to be executed when an event is fired in a specific (emitter) object.
|
|
96
|
+
*
|
|
97
|
+
* Events can be grouped in namespaces using `:`.
|
|
98
|
+
* When namespaced event is fired, it additionally fires all callbacks for that namespace.
|
|
99
|
+
*
|
|
100
|
+
* ```ts
|
|
101
|
+
* // myEmitter.on( ... ) is a shorthand for myEmitter.listenTo( myEmitter, ... ).
|
|
102
|
+
* myEmitter.on( 'myGroup', genericCallback );
|
|
103
|
+
* myEmitter.on( 'myGroup:myEvent', specificCallback );
|
|
104
|
+
*
|
|
105
|
+
* // genericCallback is fired.
|
|
106
|
+
* myEmitter.fire( 'myGroup' );
|
|
107
|
+
* // both genericCallback and specificCallback are fired.
|
|
108
|
+
* myEmitter.fire( 'myGroup:myEvent' );
|
|
109
|
+
* // genericCallback is fired even though there are no callbacks for "foo".
|
|
110
|
+
* myEmitter.fire( 'myGroup:foo' );
|
|
111
|
+
* ```
|
|
112
|
+
*
|
|
113
|
+
* An event callback can {@link module:utils/eventinfo~EventInfo#stop stop the event} and
|
|
114
|
+
* set the {@link module:utils/eventinfo~EventInfo#return return value} of the {@link #fire} method.
|
|
115
|
+
*
|
|
116
|
+
* @label DOM_EMITTER
|
|
117
|
+
* @typeParam TEvent The type describing the event. See {@link module:utils/emittermixin~BaseEvent}.
|
|
118
|
+
* @param emitter The object that fires the event.
|
|
119
|
+
* @param event The name of the event.
|
|
120
|
+
* @param callback The function to be called on event.
|
|
121
|
+
* @param options Additional options.
|
|
122
|
+
*/
|
|
123
|
+
listenTo<TEvent extends BaseEvent>(emitter: Emitter, event: TEvent['name'], callback: GetCallback<TEvent>, options?: CallbackOptions): void;
|
|
124
|
+
/**
|
|
125
|
+
* Stops listening for events. It can be used at different levels:
|
|
126
|
+
* It is backwards compatible with {@link module:utils/emittermixin~Emitter#listenTo}.
|
|
127
|
+
*
|
|
128
|
+
* * To stop listening to a specific callback.
|
|
129
|
+
* * To stop listening to a specific event.
|
|
130
|
+
* * To stop listening to all events fired by a specific object.
|
|
131
|
+
* * To stop listening to all events fired by all objects.
|
|
132
|
+
*
|
|
133
|
+
* @label DOM_STOP
|
|
134
|
+
* @param emitter The object to stop listening to.
|
|
135
|
+
* If omitted, stops it for all objects.
|
|
136
|
+
* @param event (Requires the `emitter`) The name of the event to stop listening to. If omitted, stops it
|
|
137
|
+
* for all events from `emitter`.
|
|
138
|
+
* @param callback (Requires the `event`) The function to be removed from the call list for the given
|
|
139
|
+
* `event`.
|
|
140
|
+
*/
|
|
141
|
+
stopListening(emitter?: Emitter | Node | Window, event?: string, callback?: Function): void;
|
|
142
|
+
}
|
|
@@ -0,0 +1,239 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* @license Copyright (c) 2003-2024, 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/emittermixin
|
|
7
|
+
*/
|
|
8
|
+
import EmitterMixin, { _getEmitterListenedTo, _setEmitterId } from '../emittermixin.js';
|
|
9
|
+
import uid from '../uid.js';
|
|
10
|
+
import isNode from './isnode.js';
|
|
11
|
+
import isWindow from './iswindow.js';
|
|
12
|
+
const defaultEmitterClass = /* #__PURE__ */ DomEmitterMixin(/* #__PURE__ */ EmitterMixin());
|
|
13
|
+
export default function DomEmitterMixin(base) {
|
|
14
|
+
if (!base) {
|
|
15
|
+
return defaultEmitterClass;
|
|
16
|
+
}
|
|
17
|
+
class Mixin extends base {
|
|
18
|
+
listenTo(emitter, event, callback, options = {}) {
|
|
19
|
+
// Check if emitter is an instance of DOM Node. If so, use corresponding ProxyEmitter (or create one if not existing).
|
|
20
|
+
if (isNode(emitter) || isWindow(emitter)) {
|
|
21
|
+
const proxyOptions = {
|
|
22
|
+
capture: !!options.useCapture,
|
|
23
|
+
passive: !!options.usePassive
|
|
24
|
+
};
|
|
25
|
+
const proxyEmitter = this._getProxyEmitter(emitter, proxyOptions) || new ProxyEmitter(emitter, proxyOptions);
|
|
26
|
+
this.listenTo(proxyEmitter, event, callback, options);
|
|
27
|
+
}
|
|
28
|
+
else {
|
|
29
|
+
// Execute parent class method with Emitter (or ProxyEmitter) instance.
|
|
30
|
+
super.listenTo(emitter, event, callback, options);
|
|
31
|
+
}
|
|
32
|
+
}
|
|
33
|
+
stopListening(emitter, event, callback) {
|
|
34
|
+
// Check if the emitter is an instance of DOM Node. If so, forward the call to the corresponding ProxyEmitters.
|
|
35
|
+
if (isNode(emitter) || isWindow(emitter)) {
|
|
36
|
+
const proxyEmitters = this._getAllProxyEmitters(emitter);
|
|
37
|
+
for (const proxy of proxyEmitters) {
|
|
38
|
+
this.stopListening(proxy, event, callback);
|
|
39
|
+
}
|
|
40
|
+
}
|
|
41
|
+
else {
|
|
42
|
+
// Execute parent class method with Emitter (or ProxyEmitter) instance.
|
|
43
|
+
super.stopListening(emitter, event, callback);
|
|
44
|
+
}
|
|
45
|
+
}
|
|
46
|
+
/**
|
|
47
|
+
* Retrieves ProxyEmitter instance for given DOM Node residing in this Host and given options.
|
|
48
|
+
*
|
|
49
|
+
* @param node DOM Node of the ProxyEmitter.
|
|
50
|
+
* @param options Additional options.
|
|
51
|
+
* @param options.useCapture Indicates that events of this type will be dispatched to the registered
|
|
52
|
+
* listener before being dispatched to any EventTarget beneath it in the DOM tree.
|
|
53
|
+
* @param options.usePassive Indicates that the function specified by listener will never call preventDefault()
|
|
54
|
+
* and prevents blocking browser's main thread by this event handler.
|
|
55
|
+
* @returns ProxyEmitter instance bound to the DOM Node.
|
|
56
|
+
*/
|
|
57
|
+
_getProxyEmitter(node, options) {
|
|
58
|
+
return _getEmitterListenedTo(this, getProxyEmitterId(node, options));
|
|
59
|
+
}
|
|
60
|
+
/**
|
|
61
|
+
* Retrieves all the ProxyEmitter instances for given DOM Node residing in this Host.
|
|
62
|
+
*
|
|
63
|
+
* @param node DOM Node of the ProxyEmitter.
|
|
64
|
+
*/
|
|
65
|
+
_getAllProxyEmitters(node) {
|
|
66
|
+
return [
|
|
67
|
+
{ capture: false, passive: false },
|
|
68
|
+
{ capture: false, passive: true },
|
|
69
|
+
{ capture: true, passive: false },
|
|
70
|
+
{ capture: true, passive: true }
|
|
71
|
+
].map(options => this._getProxyEmitter(node, options)).filter(proxy => !!proxy);
|
|
72
|
+
}
|
|
73
|
+
}
|
|
74
|
+
return Mixin;
|
|
75
|
+
}
|
|
76
|
+
// Backward compatibility with `mix`
|
|
77
|
+
([
|
|
78
|
+
'_getProxyEmitter', '_getAllProxyEmitters',
|
|
79
|
+
'on', 'once', 'off', 'listenTo',
|
|
80
|
+
'stopListening', 'fire', 'delegate', 'stopDelegating',
|
|
81
|
+
'_addEventListener', '_removeEventListener'
|
|
82
|
+
]).forEach(key => {
|
|
83
|
+
DomEmitterMixin[key] = defaultEmitterClass.prototype[key];
|
|
84
|
+
});
|
|
85
|
+
/**
|
|
86
|
+
* Creates a ProxyEmitter instance. Such an instance is a bridge between a DOM Node firing events
|
|
87
|
+
* and any Host listening to them. It is backwards compatible with {@link module:utils/emittermixin~Emitter#on}.
|
|
88
|
+
* There is a separate instance for each combination of modes (useCapture & usePassive). The mode is concatenated with
|
|
89
|
+
* UID stored in HTMLElement to give each instance unique identifier.
|
|
90
|
+
*
|
|
91
|
+
* listenTo( click, ... )
|
|
92
|
+
* +-----------------------------------------+
|
|
93
|
+
* | stopListening( ... ) |
|
|
94
|
+
* +----------------------------+ | addEventListener( click, ... )
|
|
95
|
+
* | Host | | +---------------------------------------------+
|
|
96
|
+
* +----------------------------+ | | removeEventListener( click, ... ) |
|
|
97
|
+
* | _listeningTo: { | +----------v-------------+ |
|
|
98
|
+
* | UID+mode: { | | ProxyEmitter | |
|
|
99
|
+
* | emitter: ProxyEmitter, | +------------------------+ +------------v----------+
|
|
100
|
+
* | callbacks: { | | events: { | | Node (HTMLElement) |
|
|
101
|
+
* | click: [ callbacks ] | | click: [ callbacks ] | +-----------------------+
|
|
102
|
+
* | } | | }, | | data-ck-expando: UID |
|
|
103
|
+
* | } | | _domNode: Node, | +-----------------------+
|
|
104
|
+
* | } | | _domListeners: {}, | |
|
|
105
|
+
* | +------------------------+ | | _emitterId: UID+mode | |
|
|
106
|
+
* | | DomEmitterMixin | | +--------------^---------+ |
|
|
107
|
+
* | +------------------------+ | | | |
|
|
108
|
+
* +--------------^-------------+ | +---------------------------------------------+
|
|
109
|
+
* | | click (DOM Event)
|
|
110
|
+
* +-----------------------------------------+
|
|
111
|
+
* fire( click, DOM Event )
|
|
112
|
+
*/
|
|
113
|
+
class ProxyEmitter extends /* #__PURE__ */ EmitterMixin() {
|
|
114
|
+
/**
|
|
115
|
+
* @param node DOM Node that fires events.
|
|
116
|
+
* @param options Additional options.
|
|
117
|
+
* @param options.useCapture Indicates that events of this type will be dispatched to the registered
|
|
118
|
+
* listener before being dispatched to any EventTarget beneath it in the DOM tree.
|
|
119
|
+
* @param options.usePassive Indicates that the function specified by listener will never call preventDefault()
|
|
120
|
+
* and prevents blocking browser's main thread by this event handler.
|
|
121
|
+
*/
|
|
122
|
+
constructor(node, options) {
|
|
123
|
+
super();
|
|
124
|
+
// Set emitter ID to match DOM Node "expando" property.
|
|
125
|
+
_setEmitterId(this, getProxyEmitterId(node, options));
|
|
126
|
+
// Remember the DOM Node this ProxyEmitter is bound to.
|
|
127
|
+
this._domNode = node;
|
|
128
|
+
// And given options.
|
|
129
|
+
this._options = options;
|
|
130
|
+
}
|
|
131
|
+
/**
|
|
132
|
+
* Registers a callback function to be executed when an event is fired.
|
|
133
|
+
*
|
|
134
|
+
* It attaches a native DOM listener to the DOM Node. When fired,
|
|
135
|
+
* a corresponding Emitter event will also fire with DOM Event object as an argument.
|
|
136
|
+
*
|
|
137
|
+
* **Note**: This is automatically called by the
|
|
138
|
+
* {@link module:utils/emittermixin~Emitter#listenTo `Emitter#listenTo()`}.
|
|
139
|
+
*
|
|
140
|
+
* @param event The name of the event.
|
|
141
|
+
*/
|
|
142
|
+
attach(event) {
|
|
143
|
+
// If the DOM Listener for given event already exist it is pointless
|
|
144
|
+
// to attach another one.
|
|
145
|
+
if (this._domListeners && this._domListeners[event]) {
|
|
146
|
+
return;
|
|
147
|
+
}
|
|
148
|
+
const domListener = this._createDomListener(event);
|
|
149
|
+
// Attach the native DOM listener to DOM Node.
|
|
150
|
+
this._domNode.addEventListener(event, domListener, this._options);
|
|
151
|
+
if (!this._domListeners) {
|
|
152
|
+
this._domListeners = {};
|
|
153
|
+
}
|
|
154
|
+
// Store the native DOM listener in this ProxyEmitter. It will be helpful
|
|
155
|
+
// when stopping listening to the event.
|
|
156
|
+
this._domListeners[event] = domListener;
|
|
157
|
+
}
|
|
158
|
+
/**
|
|
159
|
+
* Stops executing the callback on the given event.
|
|
160
|
+
*
|
|
161
|
+
* **Note**: This is automatically called by the
|
|
162
|
+
* {@link module:utils/emittermixin~Emitter#stopListening `Emitter#stopListening()`}.
|
|
163
|
+
*
|
|
164
|
+
* @param event The name of the event.
|
|
165
|
+
*/
|
|
166
|
+
detach(event) {
|
|
167
|
+
let events;
|
|
168
|
+
// Remove native DOM listeners which are orphans. If no callbacks
|
|
169
|
+
// are awaiting given event, detach native DOM listener from DOM Node.
|
|
170
|
+
// See: {@link attach}.
|
|
171
|
+
if (this._domListeners[event] && (!(events = this._events[event]) || !events.callbacks.length)) {
|
|
172
|
+
this._domListeners[event].removeListener();
|
|
173
|
+
}
|
|
174
|
+
}
|
|
175
|
+
/**
|
|
176
|
+
* Adds callback to emitter for given event.
|
|
177
|
+
*
|
|
178
|
+
* @internal
|
|
179
|
+
* @param event The name of the event.
|
|
180
|
+
* @param callback The function to be called on event.
|
|
181
|
+
* @param options Additional options.
|
|
182
|
+
*/
|
|
183
|
+
_addEventListener(event, callback, options) {
|
|
184
|
+
this.attach(event);
|
|
185
|
+
EmitterMixin().prototype._addEventListener.call(this, event, callback, options);
|
|
186
|
+
}
|
|
187
|
+
/**
|
|
188
|
+
* Removes callback from emitter for given event.
|
|
189
|
+
*
|
|
190
|
+
* @internal
|
|
191
|
+
* @param event The name of the event.
|
|
192
|
+
* @param callback The function to stop being called.
|
|
193
|
+
*/
|
|
194
|
+
_removeEventListener(event, callback) {
|
|
195
|
+
EmitterMixin().prototype._removeEventListener.call(this, event, callback);
|
|
196
|
+
this.detach(event);
|
|
197
|
+
}
|
|
198
|
+
/**
|
|
199
|
+
* Creates a native DOM listener callback. When the native DOM event
|
|
200
|
+
* is fired it will fire corresponding event on this ProxyEmitter.
|
|
201
|
+
* Note: A native DOM Event is passed as an argument.
|
|
202
|
+
*
|
|
203
|
+
* @param event The name of the event.
|
|
204
|
+
* @returns The DOM listener callback.
|
|
205
|
+
*/
|
|
206
|
+
_createDomListener(event) {
|
|
207
|
+
const domListener = (domEvt) => {
|
|
208
|
+
this.fire(event, domEvt);
|
|
209
|
+
};
|
|
210
|
+
// Supply the DOM listener callback with a function that will help
|
|
211
|
+
// detach it from the DOM Node, when it is no longer necessary.
|
|
212
|
+
// See: {@link detach}.
|
|
213
|
+
domListener.removeListener = () => {
|
|
214
|
+
this._domNode.removeEventListener(event, domListener, this._options);
|
|
215
|
+
delete this._domListeners[event];
|
|
216
|
+
};
|
|
217
|
+
return domListener;
|
|
218
|
+
}
|
|
219
|
+
}
|
|
220
|
+
/**
|
|
221
|
+
* Gets an unique DOM Node identifier. The identifier will be set if not defined.
|
|
222
|
+
*
|
|
223
|
+
* @returns UID for given DOM Node.
|
|
224
|
+
*/
|
|
225
|
+
function getNodeUID(node) {
|
|
226
|
+
return node['data-ck-expando'] || (node['data-ck-expando'] = uid());
|
|
227
|
+
}
|
|
228
|
+
/**
|
|
229
|
+
* Gets id of the ProxyEmitter for the given node.
|
|
230
|
+
*/
|
|
231
|
+
function getProxyEmitterId(node, options) {
|
|
232
|
+
let id = getNodeUID(node);
|
|
233
|
+
for (const option of Object.keys(options).sort()) {
|
|
234
|
+
if (options[option]) {
|
|
235
|
+
id += '-' + option;
|
|
236
|
+
}
|
|
237
|
+
}
|
|
238
|
+
return id;
|
|
239
|
+
}
|
|
@@ -0,0 +1,11 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* @license Copyright (c) 2003-2024, 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
|
+
* Returns the closest scrollable ancestor of a DOM element.
|
|
7
|
+
*
|
|
8
|
+
* @param domElement DOM element.
|
|
9
|
+
* @returns First ancestor of `domElement` that is scrollable or null if such ancestor doesn't exist.
|
|
10
|
+
*/
|
|
11
|
+
export default function findClosestScrollableAncestor(domElement: HTMLElement): HTMLElement | null;
|
|
@@ -0,0 +1,31 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* @license Copyright (c) 2003-2024, 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/findclosestscrollableancestor
|
|
7
|
+
*/
|
|
8
|
+
import global from './global.js';
|
|
9
|
+
/**
|
|
10
|
+
* Returns the closest scrollable ancestor of a DOM element.
|
|
11
|
+
*
|
|
12
|
+
* @param domElement DOM element.
|
|
13
|
+
* @returns First ancestor of `domElement` that is scrollable or null if such ancestor doesn't exist.
|
|
14
|
+
*/
|
|
15
|
+
export default function findClosestScrollableAncestor(domElement) {
|
|
16
|
+
let element = domElement.parentElement;
|
|
17
|
+
if (!element) {
|
|
18
|
+
return null;
|
|
19
|
+
}
|
|
20
|
+
while (element.tagName != 'BODY') {
|
|
21
|
+
const overflow = element.style.overflowY || global.window.getComputedStyle(element).overflowY;
|
|
22
|
+
if (overflow === 'auto' || overflow === 'scroll') {
|
|
23
|
+
break;
|
|
24
|
+
}
|
|
25
|
+
element = element.parentElement;
|
|
26
|
+
if (!element) {
|
|
27
|
+
return null;
|
|
28
|
+
}
|
|
29
|
+
}
|
|
30
|
+
return element;
|
|
31
|
+
}
|
|
@@ -0,0 +1,17 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* @license Copyright (c) 2003-2024, 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/getancestors
|
|
7
|
+
*/
|
|
8
|
+
/**
|
|
9
|
+
* Returns all ancestors of given DOM node, starting from the top-most (root). Includes the given node itself. If the
|
|
10
|
+
* node is a part of `DocumentFragment` that `DocumentFragment` will be returned. In contrary, if the node is
|
|
11
|
+
* appended to a `Document`, that `Document` will not be returned (algorithms operating on DOM tree care for `Document#documentElement`
|
|
12
|
+
* at most, which will be returned).
|
|
13
|
+
*
|
|
14
|
+
* @param node DOM node.
|
|
15
|
+
* @returns Array of given `node` parents.
|
|
16
|
+
*/
|
|
17
|
+
export default function getAncestors(node: Node): Array<Node>;
|