@ckeditor/ckeditor5-utils 41.2.0 → 41.3.0-alpha.1

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