@ckeditor/ckeditor5-utils 41.3.1 → 41.4.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/dist/index-content.css +4 -0
- package/dist/index-editor.css +4 -0
- package/dist/index.css +4 -0
- package/dist/index.js +5491 -0
- package/dist/index.js.map +1 -0
- package/dist/types/abortabledebounce.d.ts +21 -0
- package/dist/types/areconnectedthroughproperties.d.ts +15 -0
- package/dist/types/ckeditorerror.d.ts +127 -0
- package/dist/types/collection.d.ts +437 -0
- package/dist/types/comparearrays.d.ts +34 -0
- package/dist/types/config.d.ts +167 -0
- package/dist/types/count.d.ts +22 -0
- package/dist/types/delay.d.ts +23 -0
- package/dist/types/diff.d.ts +35 -0
- package/dist/types/difftochanges.d.ts +63 -0
- package/dist/types/dom/createelement.d.ts +61 -0
- package/dist/types/dom/emittermixin.d.ts +146 -0
- package/dist/types/dom/findclosestscrollableancestor.d.ts +15 -0
- package/dist/types/dom/getancestors.d.ts +21 -0
- package/dist/types/dom/getborderwidths.d.ts +28 -0
- package/dist/types/dom/getcommonancestor.d.ts +16 -0
- package/dist/types/dom/getdatafromelement.d.ts +18 -0
- package/dist/types/dom/getpositionedancestor.d.ts +14 -0
- package/dist/types/dom/global.d.ts +36 -0
- package/dist/types/dom/indexof.d.ts +18 -0
- package/dist/types/dom/insertat.d.ts +19 -0
- package/dist/types/dom/iscomment.d.ts +15 -0
- package/dist/types/dom/isnode.d.ts +15 -0
- package/dist/types/dom/isrange.d.ts +15 -0
- package/dist/types/dom/istext.d.ts +15 -0
- package/dist/types/dom/isvalidattributename.d.ts +14 -0
- package/dist/types/dom/isvisible.d.ts +22 -0
- package/dist/types/dom/iswindow.d.ts +15 -0
- package/dist/types/dom/position.d.ts +215 -0
- package/dist/types/dom/rect.d.ts +199 -0
- package/dist/types/dom/remove.d.ts +17 -0
- package/dist/types/dom/resizeobserver.d.ts +78 -0
- package/dist/types/dom/scroll.d.ts +77 -0
- package/dist/types/dom/setdatainelement.d.ts +18 -0
- package/dist/types/dom/tounit.d.ts +26 -0
- package/dist/types/elementreplacer.d.ts +35 -0
- package/dist/types/emittermixin.d.ts +316 -0
- package/dist/types/env.d.ts +137 -0
- package/dist/types/eventinfo.d.ts +62 -0
- package/dist/types/fastdiff.d.ts +116 -0
- package/dist/types/first.d.ts +15 -0
- package/dist/types/focustracker.d.ts +79 -0
- package/dist/types/index.d.ts +68 -0
- package/dist/types/inserttopriorityarray.d.ts +34 -0
- package/dist/types/isiterable.d.ts +18 -0
- package/dist/types/keyboard.d.ts +130 -0
- package/dist/types/keystrokehandler.d.ts +91 -0
- package/dist/types/language.d.ts +21 -0
- package/dist/types/locale.d.ts +145 -0
- package/dist/types/mapsequal.d.ts +19 -0
- package/dist/types/mix.d.ts +89 -0
- package/dist/types/nth.d.ts +20 -0
- package/dist/types/objecttomap.d.ts +27 -0
- package/dist/types/observablemixin.d.ts +564 -0
- package/dist/types/priorities.d.ts +37 -0
- package/dist/types/retry.d.ts +37 -0
- package/dist/types/splicearray.d.ts +30 -0
- package/dist/types/spy.d.ts +25 -0
- package/dist/types/toarray.d.ts +29 -0
- package/dist/types/tomap.d.ts +23 -0
- package/dist/types/translation-service.d.ts +178 -0
- package/dist/types/uid.d.ts +19 -0
- package/dist/types/unicode.d.ts +58 -0
- package/dist/types/verifylicense.d.ts +19 -0
- package/dist/types/version.d.ts +14 -0
- package/dist/types/wait.d.ts +20 -0
- package/package.json +2 -1
- package/src/env.d.ts +16 -0
- package/src/env.js +16 -0
- package/src/locale.d.ts +1 -1
- package/src/version.d.ts +1 -1
- package/src/version.js +2 -2
|
@@ -0,0 +1,18 @@
|
|
|
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
|
+
* @license Copyright (c) 2003-2024, CKSource Holding sp. z o.o. All rights reserved.
|
|
7
|
+
* For licensing, see LICENSE.md or https://ckeditor.com/legal/ckeditor-oss-license
|
|
8
|
+
*/
|
|
9
|
+
/**
|
|
10
|
+
* @module utils/dom/indexof
|
|
11
|
+
*/
|
|
12
|
+
/**
|
|
13
|
+
* Returns index of the node in the parent element.
|
|
14
|
+
*
|
|
15
|
+
* @param node Node which index is tested.
|
|
16
|
+
* @returns Index of the node in the parent element. Returns 0 if node has no parent.
|
|
17
|
+
*/
|
|
18
|
+
export default function indexOf(node: Node): number;
|
|
@@ -0,0 +1,19 @@
|
|
|
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
|
+
* @license Copyright (c) 2003-2024, CKSource Holding sp. z o.o. All rights reserved.
|
|
7
|
+
* For licensing, see LICENSE.md or https://ckeditor.com/legal/ckeditor-oss-license
|
|
8
|
+
*/
|
|
9
|
+
/**
|
|
10
|
+
* @module utils/dom/insertat
|
|
11
|
+
*/
|
|
12
|
+
/**
|
|
13
|
+
* Inserts node to the parent at given index.
|
|
14
|
+
*
|
|
15
|
+
* @param parentElement Parent element.
|
|
16
|
+
* @param index Insertions index.
|
|
17
|
+
* @param nodeToInsert Node to insert.
|
|
18
|
+
*/
|
|
19
|
+
export default function insertAt(parentElement: Element, index: number, nodeToInsert: Node): void;
|
|
@@ -0,0 +1,15 @@
|
|
|
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
|
+
* @license Copyright (c) 2003-2024, CKSource Holding sp. z o.o. All rights reserved.
|
|
7
|
+
* For licensing, see LICENSE.md or https://ckeditor.com/legal/ckeditor-oss-license
|
|
8
|
+
*/
|
|
9
|
+
/**
|
|
10
|
+
* @module utils/dom/iscomment
|
|
11
|
+
*/
|
|
12
|
+
/**
|
|
13
|
+
* Checks whether the object is a native DOM Comment node.
|
|
14
|
+
*/
|
|
15
|
+
export default function isComment(obj: any): obj is Comment;
|
|
@@ -0,0 +1,15 @@
|
|
|
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
|
+
* @license Copyright (c) 2003-2024, CKSource Holding sp. z o.o. All rights reserved.
|
|
7
|
+
* For licensing, see LICENSE.md or https://ckeditor.com/legal/ckeditor-oss-license
|
|
8
|
+
*/
|
|
9
|
+
/**
|
|
10
|
+
* @module utils/dom/isnode
|
|
11
|
+
*/
|
|
12
|
+
/**
|
|
13
|
+
* Checks if the object is a native DOM Node.
|
|
14
|
+
*/
|
|
15
|
+
export default function isNode(obj: any): obj is Node;
|
|
@@ -0,0 +1,15 @@
|
|
|
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
|
+
* @license Copyright (c) 2003-2024, CKSource Holding sp. z o.o. All rights reserved.
|
|
7
|
+
* For licensing, see LICENSE.md or https://ckeditor.com/legal/ckeditor-oss-license
|
|
8
|
+
*/
|
|
9
|
+
/**
|
|
10
|
+
* @module utils/dom/isrange
|
|
11
|
+
*/
|
|
12
|
+
/**
|
|
13
|
+
* Checks if the object is a native DOM Range.
|
|
14
|
+
*/
|
|
15
|
+
export default function isRange(obj: unknown): obj is Range;
|
|
@@ -0,0 +1,15 @@
|
|
|
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
|
+
* @license Copyright (c) 2003-2024, CKSource Holding sp. z o.o. All rights reserved.
|
|
7
|
+
* For licensing, see LICENSE.md or https://ckeditor.com/legal/ckeditor-oss-license
|
|
8
|
+
*/
|
|
9
|
+
/**
|
|
10
|
+
* @module utils/dom/istext
|
|
11
|
+
*/
|
|
12
|
+
/**
|
|
13
|
+
* Checks if the object is a native DOM Text node.
|
|
14
|
+
*/
|
|
15
|
+
export default function isText(obj: unknown): obj is Text;
|
|
@@ -0,0 +1,14 @@
|
|
|
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
|
+
* @license Copyright (c) 2003-2024, CKSource Holding sp. z o.o. All rights reserved.
|
|
7
|
+
* For licensing, see LICENSE.md or https://ckeditor.com/legal/ckeditor-oss-license
|
|
8
|
+
*/
|
|
9
|
+
/**
|
|
10
|
+
* Checks if the given attribute name is valid in terms of HTML.
|
|
11
|
+
*
|
|
12
|
+
* @param name Attribute name.
|
|
13
|
+
*/
|
|
14
|
+
export default function isValidAttributeName(name: string): boolean;
|
|
@@ -0,0 +1,22 @@
|
|
|
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
|
+
* @license Copyright (c) 2003-2024, CKSource Holding sp. z o.o. All rights reserved.
|
|
7
|
+
* For licensing, see LICENSE.md or https://ckeditor.com/legal/ckeditor-oss-license
|
|
8
|
+
*/
|
|
9
|
+
/**
|
|
10
|
+
* @module utils/dom/isvisible
|
|
11
|
+
*/
|
|
12
|
+
/**
|
|
13
|
+
* Checks whether the element is visible to the user in DOM:
|
|
14
|
+
*
|
|
15
|
+
* * connected to the root of the document,
|
|
16
|
+
* * has no `display: none`,
|
|
17
|
+
* * has no ancestors with `display: none`.
|
|
18
|
+
*
|
|
19
|
+
* **Note**: This helper does not check whether the element is hidden by cropping, overflow, etc..
|
|
20
|
+
* To check that, use {@link module:utils/dom/rect~Rect} instead.
|
|
21
|
+
*/
|
|
22
|
+
export default function isVisible(element: HTMLElement | null | undefined): boolean;
|
|
@@ -0,0 +1,15 @@
|
|
|
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
|
+
* @license Copyright (c) 2003-2024, CKSource Holding sp. z o.o. All rights reserved.
|
|
7
|
+
* For licensing, see LICENSE.md or https://ckeditor.com/legal/ckeditor-oss-license
|
|
8
|
+
*/
|
|
9
|
+
/**
|
|
10
|
+
* @module utils/dom/iswindow
|
|
11
|
+
*/
|
|
12
|
+
/**
|
|
13
|
+
* Checks if the object is a native DOM Window.
|
|
14
|
+
*/
|
|
15
|
+
export default function isWindow(obj: unknown): obj is Window;
|
|
@@ -0,0 +1,215 @@
|
|
|
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
|
+
* @license Copyright (c) 2003-2024, CKSource Holding sp. z o.o. All rights reserved.
|
|
7
|
+
* For licensing, see LICENSE.md or https://ckeditor.com/legal/ckeditor-oss-license
|
|
8
|
+
*/
|
|
9
|
+
import Rect, { type RectSource } from './rect.js';
|
|
10
|
+
/**
|
|
11
|
+
* Calculates the `position: absolute` coordinates of a given element so it can be positioned with respect to the
|
|
12
|
+
* target in the visually most efficient way, taking various restrictions like viewport or limiter geometry
|
|
13
|
+
* into consideration.
|
|
14
|
+
*
|
|
15
|
+
* **Note**: If there are no position coordinates found that meet the requirements (arguments of this helper),
|
|
16
|
+
* `null` is returned.
|
|
17
|
+
*
|
|
18
|
+
* ```ts
|
|
19
|
+
* // The element which is to be positioned.
|
|
20
|
+
* const element = document.body.querySelector( '#toolbar' );
|
|
21
|
+
*
|
|
22
|
+
* // A target to which the element is positioned relatively.
|
|
23
|
+
* const target = document.body.querySelector( '#container' );
|
|
24
|
+
*
|
|
25
|
+
* // Finding the optimal coordinates for the positioning.
|
|
26
|
+
* const { left, top, name } = getOptimalPosition( {
|
|
27
|
+
* element: element,
|
|
28
|
+
* target: target,
|
|
29
|
+
*
|
|
30
|
+
* // The algorithm will chose among these positions to meet the requirements such
|
|
31
|
+
* // as "limiter" element or "fitInViewport", set below. The positions are considered
|
|
32
|
+
* // in the order of the array.
|
|
33
|
+
* positions: [
|
|
34
|
+
* //
|
|
35
|
+
* // [ Target ]
|
|
36
|
+
* // +-----------------+
|
|
37
|
+
* // | Element |
|
|
38
|
+
* // +-----------------+
|
|
39
|
+
* //
|
|
40
|
+
* targetRect => ( {
|
|
41
|
+
* top: targetRect.bottom,
|
|
42
|
+
* left: targetRect.left,
|
|
43
|
+
* name: 'mySouthEastPosition'
|
|
44
|
+
* } ),
|
|
45
|
+
*
|
|
46
|
+
* //
|
|
47
|
+
* // +-----------------+
|
|
48
|
+
* // | Element |
|
|
49
|
+
* // +-----------------+
|
|
50
|
+
* // [ Target ]
|
|
51
|
+
* //
|
|
52
|
+
* ( targetRect, elementRect ) => ( {
|
|
53
|
+
* top: targetRect.top - elementRect.height,
|
|
54
|
+
* left: targetRect.left,
|
|
55
|
+
* name: 'myNorthEastPosition'
|
|
56
|
+
* } )
|
|
57
|
+
* ],
|
|
58
|
+
*
|
|
59
|
+
* // Find a position such guarantees the element remains within visible boundaries of <body>.
|
|
60
|
+
* limiter: document.body,
|
|
61
|
+
*
|
|
62
|
+
* // Find a position such guarantees the element remains within visible boundaries of the browser viewport.
|
|
63
|
+
* fitInViewport: true
|
|
64
|
+
* } );
|
|
65
|
+
*
|
|
66
|
+
* // The best position which fits into document.body and the viewport. May be useful
|
|
67
|
+
* // to set proper class on the `element`.
|
|
68
|
+
* console.log( name ); // -> "myNorthEastPosition"
|
|
69
|
+
*
|
|
70
|
+
* // Using the absolute coordinates which has been found to position the element
|
|
71
|
+
* // as in the diagram depicting the "myNorthEastPosition" position.
|
|
72
|
+
* element.style.top = top;
|
|
73
|
+
* element.style.left = left;
|
|
74
|
+
* ```
|
|
75
|
+
*
|
|
76
|
+
* @param options The input data and configuration of the helper.
|
|
77
|
+
*/
|
|
78
|
+
export declare function getOptimalPosition({ element, target, positions, limiter, fitInViewport, viewportOffsetConfig }: Options): DomPoint | null;
|
|
79
|
+
/**
|
|
80
|
+
* A position object which instances are created and used by the {@link module:utils/dom/position~getOptimalPosition} helper.
|
|
81
|
+
*
|
|
82
|
+
* {@link module:utils/dom/position~DomPoint#top} and {@link module:utils/dom/position~DomPoint#left} properties of the position instance
|
|
83
|
+
* translate directly to the `top` and `left` properties in CSS "`position: absolute` coordinate system". If set on the positioned element
|
|
84
|
+
* in DOM, they will make it display it in the right place in the viewport.
|
|
85
|
+
*/
|
|
86
|
+
export interface DomPoint {
|
|
87
|
+
/**
|
|
88
|
+
* Position name.
|
|
89
|
+
*/
|
|
90
|
+
readonly name?: string;
|
|
91
|
+
/**
|
|
92
|
+
* Additional position configuration, as passed from the {@link module:utils/dom/position~PositioningFunction positioning function}.
|
|
93
|
+
*
|
|
94
|
+
* This object can be use, for instance, to pass through presentation options used by the consumer of the
|
|
95
|
+
* {@link module:utils/dom/position~getOptimalPosition} helper.
|
|
96
|
+
*/
|
|
97
|
+
readonly config?: object;
|
|
98
|
+
/**
|
|
99
|
+
* The left value in pixels in the CSS `position: absolute` coordinate system.
|
|
100
|
+
* Set it on the positioned element in DOM to move it to the position.
|
|
101
|
+
*/
|
|
102
|
+
readonly left: number;
|
|
103
|
+
/**
|
|
104
|
+
* The top value in pixels in the CSS `position: absolute` coordinate system.
|
|
105
|
+
* Set it on the positioned element in DOM to move it to the position.
|
|
106
|
+
*/
|
|
107
|
+
readonly top: number;
|
|
108
|
+
}
|
|
109
|
+
/**
|
|
110
|
+
* The `getOptimalPosition()` helper options.
|
|
111
|
+
*/
|
|
112
|
+
export interface Options {
|
|
113
|
+
/**
|
|
114
|
+
* Element that is to be positioned.
|
|
115
|
+
*/
|
|
116
|
+
readonly element: HTMLElement;
|
|
117
|
+
/**
|
|
118
|
+
* Target with respect to which the `element` is to be positioned.
|
|
119
|
+
*/
|
|
120
|
+
readonly target: RectSource | (() => RectSource);
|
|
121
|
+
/**
|
|
122
|
+
* An array of positioning functions.
|
|
123
|
+
*
|
|
124
|
+
* **Note**: Positioning functions are processed in the order of preference. The first function that works
|
|
125
|
+
* in the current environment (e.g. offers the complete fit in the viewport geometry) will be picked by
|
|
126
|
+
* `getOptimalPosition()`.
|
|
127
|
+
*
|
|
128
|
+
* **Note**: Any positioning function returning `null` is ignored.
|
|
129
|
+
*/
|
|
130
|
+
readonly positions: ReadonlyArray<PositioningFunction>;
|
|
131
|
+
/**
|
|
132
|
+
* When set, the algorithm will chose position which fits the most in the
|
|
133
|
+
* limiter's bounding rect.
|
|
134
|
+
*/
|
|
135
|
+
readonly limiter?: RectSource | (() => (RectSource | null)) | null;
|
|
136
|
+
/**
|
|
137
|
+
* When set, the algorithm will chose such a position which fits `element`
|
|
138
|
+
* the most inside visible viewport.
|
|
139
|
+
*/
|
|
140
|
+
readonly fitInViewport?: boolean;
|
|
141
|
+
/**
|
|
142
|
+
* Viewport offset config object. It restricts the visible viewport available to the `getOptimalPosition()` from each side.
|
|
143
|
+
*
|
|
144
|
+
* ```ts
|
|
145
|
+
* {
|
|
146
|
+
* top: 50,
|
|
147
|
+
* right: 50,
|
|
148
|
+
* bottom: 50,
|
|
149
|
+
* left: 50
|
|
150
|
+
* }
|
|
151
|
+
* ```
|
|
152
|
+
*/
|
|
153
|
+
readonly viewportOffsetConfig?: {
|
|
154
|
+
readonly top?: number;
|
|
155
|
+
readonly right?: number;
|
|
156
|
+
readonly bottom?: number;
|
|
157
|
+
readonly left?: number;
|
|
158
|
+
};
|
|
159
|
+
}
|
|
160
|
+
/**
|
|
161
|
+
* A positioning function which, based on positioned element and target {@link module:utils/dom/rect~Rect Rects}, returns rect coordinates
|
|
162
|
+
* representing the geometrical relation between them. Used by the {@link module:utils/dom/position~getOptimalPosition} helper.
|
|
163
|
+
*
|
|
164
|
+
* ```ts
|
|
165
|
+
* // This simple position will place the element directly under the target, in the middle:
|
|
166
|
+
* //
|
|
167
|
+
* // [ Target ]
|
|
168
|
+
* // +-----------------+
|
|
169
|
+
* // | Element |
|
|
170
|
+
* // +-----------------+
|
|
171
|
+
* //
|
|
172
|
+
* const position = ( targetRect, elementRect, [ viewportRect ] ) => ( {
|
|
173
|
+
* top: targetRect.bottom,
|
|
174
|
+
* left: targetRect.left + targetRect.width / 2 - elementRect.width / 2,
|
|
175
|
+
* name: 'bottomMiddle',
|
|
176
|
+
*
|
|
177
|
+
* // Note: The config is optional.
|
|
178
|
+
* config: {
|
|
179
|
+
* zIndex: '999'
|
|
180
|
+
* }
|
|
181
|
+
* } );
|
|
182
|
+
* ```
|
|
183
|
+
*
|
|
184
|
+
* @param elementRect The rect of the element to be positioned.
|
|
185
|
+
* @param targetRect The rect of the target the element (its rect) is relatively positioned to.
|
|
186
|
+
* @param viewportRect The rect of the visual browser viewport.
|
|
187
|
+
* @returns When the function returns `null`, it will not be considered by {@link module:utils/dom/position~getOptimalPosition}.
|
|
188
|
+
*/
|
|
189
|
+
export type PositioningFunction = (elementRect: Rect, targetRect: Rect, viewportRect: Rect, limiterRect?: Rect) => PositioningFunctionResult | null;
|
|
190
|
+
/**
|
|
191
|
+
* The result of {@link module:utils/dom/position~PositioningFunction}.
|
|
192
|
+
*/
|
|
193
|
+
export interface PositioningFunctionResult {
|
|
194
|
+
/**
|
|
195
|
+
* The `top` value of the element rect that would represent the position.
|
|
196
|
+
*/
|
|
197
|
+
top: number;
|
|
198
|
+
/**
|
|
199
|
+
* The `left` value of the element rect that would represent the position.
|
|
200
|
+
*/
|
|
201
|
+
left: number;
|
|
202
|
+
/**
|
|
203
|
+
* The name of the position. It helps the user of the {@link module:utils/dom/position~getOptimalPosition}
|
|
204
|
+
* helper to recognize different positioning function results. It will pass through to the {@link module:utils/dom/position~DomPoint}
|
|
205
|
+
* returned by the helper.
|
|
206
|
+
*/
|
|
207
|
+
name?: string;
|
|
208
|
+
/**
|
|
209
|
+
* An optional configuration that will pass-through the {@link module:utils/dom/position~getOptimalPosition} helper
|
|
210
|
+
* to the {@link module:utils/dom/position~DomPoint} returned by this helper.
|
|
211
|
+
* This configuration may, for instance, let the user of {@link module:utils/dom/position~getOptimalPosition} know that this particular
|
|
212
|
+
* position comes with a certain presentation.
|
|
213
|
+
*/
|
|
214
|
+
config?: object;
|
|
215
|
+
}
|
|
@@ -0,0 +1,199 @@
|
|
|
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
|
+
* @license Copyright (c) 2003-2024, CKSource Holding sp. z o.o. All rights reserved.
|
|
7
|
+
* For licensing, see LICENSE.md or https://ckeditor.com/legal/ckeditor-oss-license
|
|
8
|
+
*/
|
|
9
|
+
/**
|
|
10
|
+
* A helper class representing a `ClientRect` object, e.g. value returned by
|
|
11
|
+
* the native `object.getBoundingClientRect()` method. Provides a set of methods
|
|
12
|
+
* to manipulate the rect and compare it against other rect instances.
|
|
13
|
+
*/
|
|
14
|
+
export default class Rect {
|
|
15
|
+
/**
|
|
16
|
+
* The "top" value of the rect.
|
|
17
|
+
*
|
|
18
|
+
* @readonly
|
|
19
|
+
*/
|
|
20
|
+
top: number;
|
|
21
|
+
/**
|
|
22
|
+
* The "right" value of the rect.
|
|
23
|
+
*
|
|
24
|
+
* @readonly
|
|
25
|
+
*/
|
|
26
|
+
right: number;
|
|
27
|
+
/**
|
|
28
|
+
* The "bottom" value of the rect.
|
|
29
|
+
*
|
|
30
|
+
* @readonly
|
|
31
|
+
*/
|
|
32
|
+
bottom: number;
|
|
33
|
+
/**
|
|
34
|
+
* The "left" value of the rect.
|
|
35
|
+
*
|
|
36
|
+
* @readonly
|
|
37
|
+
*/
|
|
38
|
+
left: number;
|
|
39
|
+
/**
|
|
40
|
+
* The "width" value of the rect.
|
|
41
|
+
*
|
|
42
|
+
* @readonly
|
|
43
|
+
*/
|
|
44
|
+
width: number;
|
|
45
|
+
/**
|
|
46
|
+
* The "height" value of the rect.
|
|
47
|
+
*
|
|
48
|
+
* @readonly
|
|
49
|
+
*/
|
|
50
|
+
height: number;
|
|
51
|
+
/**
|
|
52
|
+
* The object this rect is for.
|
|
53
|
+
*
|
|
54
|
+
* @readonly
|
|
55
|
+
*/
|
|
56
|
+
private _source;
|
|
57
|
+
/**
|
|
58
|
+
* Creates an instance of rect.
|
|
59
|
+
*
|
|
60
|
+
* ```ts
|
|
61
|
+
* // Rect of an HTMLElement.
|
|
62
|
+
* const rectA = new Rect( document.body );
|
|
63
|
+
*
|
|
64
|
+
* // Rect of a DOM Range.
|
|
65
|
+
* const rectB = new Rect( document.getSelection().getRangeAt( 0 ) );
|
|
66
|
+
*
|
|
67
|
+
* // Rect of a window (web browser viewport).
|
|
68
|
+
* const rectC = new Rect( window );
|
|
69
|
+
*
|
|
70
|
+
* // Rect out of an object.
|
|
71
|
+
* const rectD = new Rect( { top: 0, right: 10, bottom: 10, left: 0, width: 10, height: 10 } );
|
|
72
|
+
*
|
|
73
|
+
* // Rect out of another Rect instance.
|
|
74
|
+
* const rectE = new Rect( rectD );
|
|
75
|
+
*
|
|
76
|
+
* // Rect out of a ClientRect.
|
|
77
|
+
* const rectF = new Rect( document.body.getClientRects().item( 0 ) );
|
|
78
|
+
* ```
|
|
79
|
+
*
|
|
80
|
+
* **Note**: By default a rect of an HTML element includes its CSS borders and scrollbars (if any)
|
|
81
|
+
* ant the rect of a `window` includes scrollbars too. Use {@link #excludeScrollbarsAndBorders}
|
|
82
|
+
* to get the inner part of the rect.
|
|
83
|
+
*
|
|
84
|
+
* @param source A source object to create the rect.
|
|
85
|
+
*/
|
|
86
|
+
constructor(source: RectSource);
|
|
87
|
+
/**
|
|
88
|
+
* Returns a clone of the rect.
|
|
89
|
+
*
|
|
90
|
+
* @returns A cloned rect.
|
|
91
|
+
*/
|
|
92
|
+
clone(): Rect;
|
|
93
|
+
/**
|
|
94
|
+
* Moves the rect so that its upper–left corner lands in desired `[ x, y ]` location.
|
|
95
|
+
*
|
|
96
|
+
* @param x Desired horizontal location.
|
|
97
|
+
* @param y Desired vertical location.
|
|
98
|
+
* @returns A rect which has been moved.
|
|
99
|
+
*/
|
|
100
|
+
moveTo(x: number, y: number): this;
|
|
101
|
+
/**
|
|
102
|
+
* Moves the rect in–place by a dedicated offset.
|
|
103
|
+
*
|
|
104
|
+
* @param x A horizontal offset.
|
|
105
|
+
* @param y A vertical offset
|
|
106
|
+
* @returns A rect which has been moved.
|
|
107
|
+
*/
|
|
108
|
+
moveBy(x: number, y: number): this;
|
|
109
|
+
/**
|
|
110
|
+
* Returns a new rect a a result of intersection with another rect.
|
|
111
|
+
*/
|
|
112
|
+
getIntersection(anotherRect: Rect): Rect | null;
|
|
113
|
+
/**
|
|
114
|
+
* Returns the area of intersection with another rect.
|
|
115
|
+
*
|
|
116
|
+
* @returns Area of intersection.
|
|
117
|
+
*/
|
|
118
|
+
getIntersectionArea(anotherRect: Rect): number;
|
|
119
|
+
/**
|
|
120
|
+
* Returns the area of the rect.
|
|
121
|
+
*/
|
|
122
|
+
getArea(): number;
|
|
123
|
+
/**
|
|
124
|
+
* Returns a new rect, a part of the original rect, which is actually visible to the user and is relative to the,`body`,
|
|
125
|
+
* e.g. an original rect cropped by parent element rects which have `overflow` set in CSS
|
|
126
|
+
* other than `"visible"`.
|
|
127
|
+
*
|
|
128
|
+
* If there's no such visible rect, which is when the rect is limited by one or many of
|
|
129
|
+
* the ancestors, `null` is returned.
|
|
130
|
+
*
|
|
131
|
+
* **Note**: This method does not consider the boundaries of the viewport (window).
|
|
132
|
+
* To get a rect cropped by all ancestors and the viewport, use an intersection such as:
|
|
133
|
+
*
|
|
134
|
+
* ```ts
|
|
135
|
+
* const visibleInViewportRect = new Rect( window ).getIntersection( new Rect( source ).getVisible() );
|
|
136
|
+
* ```
|
|
137
|
+
*
|
|
138
|
+
* @returns A visible rect instance or `null`, if there's none.
|
|
139
|
+
*/
|
|
140
|
+
getVisible(): Rect | null;
|
|
141
|
+
/**
|
|
142
|
+
* Checks if all property values ({@link #top}, {@link #left}, {@link #right},
|
|
143
|
+
* {@link #bottom}, {@link #width} and {@link #height}) are the equal in both rect
|
|
144
|
+
* instances.
|
|
145
|
+
*
|
|
146
|
+
* @param anotherRect A rect instance to compare with.
|
|
147
|
+
* @returns `true` when Rects are equal. `false` otherwise.
|
|
148
|
+
*/
|
|
149
|
+
isEqual(anotherRect: Rect): boolean;
|
|
150
|
+
/**
|
|
151
|
+
* Checks whether a rect fully contains another rect instance.
|
|
152
|
+
*
|
|
153
|
+
* @param anotherRect
|
|
154
|
+
* @returns `true` if contains, `false` otherwise.
|
|
155
|
+
*/
|
|
156
|
+
contains(anotherRect: Rect): boolean;
|
|
157
|
+
/**
|
|
158
|
+
* Recalculates screen coordinates to coordinates relative to the positioned ancestor offset.
|
|
159
|
+
*/
|
|
160
|
+
toAbsoluteRect(): Rect;
|
|
161
|
+
/**
|
|
162
|
+
* Excludes scrollbars and CSS borders from the rect.
|
|
163
|
+
*
|
|
164
|
+
* * Borders are removed when {@link #_source} is an HTML element.
|
|
165
|
+
* * Scrollbars are excluded from HTML elements and the `window`.
|
|
166
|
+
*
|
|
167
|
+
* @returns A rect which has been updated.
|
|
168
|
+
*/
|
|
169
|
+
excludeScrollbarsAndBorders(): this;
|
|
170
|
+
/**
|
|
171
|
+
* Returns an array of rects of the given native DOM Range.
|
|
172
|
+
*
|
|
173
|
+
* @param range A native DOM range.
|
|
174
|
+
* @returns DOM Range rects.
|
|
175
|
+
*/
|
|
176
|
+
static getDomRangeRects(range: Range): Array<Rect>;
|
|
177
|
+
/**
|
|
178
|
+
* Returns a bounding rectangle that contains all the given `rects`.
|
|
179
|
+
*
|
|
180
|
+
* @param rects A list of rectangles that should be contained in the result rectangle.
|
|
181
|
+
* @returns Bounding rectangle or `null` if no `rects` were given.
|
|
182
|
+
*/
|
|
183
|
+
static getBoundingRect(rects: Iterable<Rect>): Rect | null;
|
|
184
|
+
}
|
|
185
|
+
/**
|
|
186
|
+
* A source of {@link module:utils/dom/rect~Rect}.
|
|
187
|
+
*/
|
|
188
|
+
export type RectSource = HTMLElement | Range | Window | RectLike;
|
|
189
|
+
/**
|
|
190
|
+
* An object that describes properties of `ClientRect` object.
|
|
191
|
+
*/
|
|
192
|
+
export interface RectLike {
|
|
193
|
+
readonly top: number;
|
|
194
|
+
readonly right: number;
|
|
195
|
+
readonly bottom: number;
|
|
196
|
+
readonly left: number;
|
|
197
|
+
readonly width: number;
|
|
198
|
+
readonly height: number;
|
|
199
|
+
}
|
|
@@ -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
|
+
* @license Copyright (c) 2003-2024, CKSource Holding sp. z o.o. All rights reserved.
|
|
7
|
+
* For licensing, see LICENSE.md or https://ckeditor.com/legal/ckeditor-oss-license
|
|
8
|
+
*/
|
|
9
|
+
/**
|
|
10
|
+
* @module utils/dom/remove
|
|
11
|
+
*/
|
|
12
|
+
/**
|
|
13
|
+
* Removes given node from parent.
|
|
14
|
+
*
|
|
15
|
+
* @param node Node to remove.
|
|
16
|
+
*/
|
|
17
|
+
export default function remove(node: Node): void;
|
|
@@ -0,0 +1,78 @@
|
|
|
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
|
+
* @license Copyright (c) 2003-2024, CKSource Holding sp. z o.o. All rights reserved.
|
|
7
|
+
* For licensing, see LICENSE.md or https://ckeditor.com/legal/ckeditor-oss-license
|
|
8
|
+
*/
|
|
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
|
+
* The element observed by this observer.
|
|
28
|
+
*/
|
|
29
|
+
private readonly _element;
|
|
30
|
+
/**
|
|
31
|
+
* The callback executed each time {@link #_element} is resized.
|
|
32
|
+
*/
|
|
33
|
+
private readonly _callback;
|
|
34
|
+
/**
|
|
35
|
+
* The single native observer instance shared across all {@link module:utils/dom/resizeobserver~ResizeObserver} instances.
|
|
36
|
+
*/
|
|
37
|
+
private static _observerInstance;
|
|
38
|
+
/**
|
|
39
|
+
* A mapping of native DOM elements and their callbacks shared across all
|
|
40
|
+
* {@link module:utils/dom/resizeobserver~ResizeObserver} instances.
|
|
41
|
+
*/
|
|
42
|
+
private static _elementCallbacks;
|
|
43
|
+
/**
|
|
44
|
+
* Creates an instance of the `ResizeObserver` class.
|
|
45
|
+
*
|
|
46
|
+
* @param element A DOM element that is to be observed for resizing. Note that
|
|
47
|
+
* the element must be visible (i.e. not detached from DOM) for the observer to work.
|
|
48
|
+
* @param callback A function called when the observed element was resized. It passes
|
|
49
|
+
* the [`ResizeObserverEntry`](https://developer.mozilla.org/en-US/docs/Web/API/ResizeObserverEntry)
|
|
50
|
+
* object with information about the resize event.
|
|
51
|
+
*/
|
|
52
|
+
constructor(element: Element, callback: (entry: ResizeObserverEntry) => void);
|
|
53
|
+
/**
|
|
54
|
+
* The element observed by this observer.
|
|
55
|
+
*/
|
|
56
|
+
get element(): Element;
|
|
57
|
+
/**
|
|
58
|
+
* Destroys the observer which disables the `callback` passed to the {@link #constructor}.
|
|
59
|
+
*/
|
|
60
|
+
destroy(): void;
|
|
61
|
+
/**
|
|
62
|
+
* Registers a new resize callback for the DOM element.
|
|
63
|
+
*/
|
|
64
|
+
private static _addElementCallback;
|
|
65
|
+
/**
|
|
66
|
+
* Removes a resize callback from the DOM element. If no callbacks are left
|
|
67
|
+
* for the element, it removes the element from the native observer.
|
|
68
|
+
*/
|
|
69
|
+
private static _deleteElementCallback;
|
|
70
|
+
/**
|
|
71
|
+
* Returns are registered resize callbacks for the DOM element.
|
|
72
|
+
*/
|
|
73
|
+
private static _getElementCallbacks;
|
|
74
|
+
/**
|
|
75
|
+
* Creates the single native observer shared across all `ResizeObserver` instances.
|
|
76
|
+
*/
|
|
77
|
+
private static _createObserver;
|
|
78
|
+
}
|