@ckeditor/ckeditor5-utils 38.2.0-alpha.0 → 39.0.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/README.md CHANGED
@@ -4,7 +4,6 @@ CKEditor 5 utilities
4
4
  [![npm version](https://badge.fury.io/js/%40ckeditor%2Fckeditor5-utils.svg)](https://www.npmjs.com/package/@ckeditor/ckeditor5-utils)
5
5
  [![Coverage Status](https://coveralls.io/repos/github/ckeditor/ckeditor5/badge.svg?branch=master)](https://coveralls.io/github/ckeditor/ckeditor5?branch=master)
6
6
  [![Build Status](https://travis-ci.com/ckeditor/ckeditor5.svg?branch=master)](https://app.travis-ci.com/github/ckeditor/ckeditor5)
7
- ![Dependency Status](https://img.shields.io/librariesio/release/npm/@ckeditor/ckeditor5-utils)
8
7
 
9
8
  Various utilities used by CKEditor 5 and its features. This is a sort of CKEditor 5's standard library.
10
9
 
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@ckeditor/ckeditor5-utils",
3
- "version": "38.2.0-alpha.0",
3
+ "version": "39.0.0",
4
4
  "description": "Miscellaneous utilities used by CKEditor 5.",
5
5
  "keywords": [
6
6
  "ckeditor",
@@ -10,9 +10,8 @@
10
10
  "ckeditor5-dll"
11
11
  ],
12
12
  "main": "src/index.js",
13
- "type": "module",
14
13
  "dependencies": {
15
- "lodash-es": "^4.17.15"
14
+ "lodash-es": "4.17.21"
16
15
  },
17
16
  "engines": {
18
17
  "node": ">=16.0.0",
@@ -0,0 +1,17 @@
1
+ /**
2
+ * @license Copyright (c) 2003-2023, CKSource Holding sp. z o.o. All rights reserved.
3
+ * For licensing, see LICENSE.md or https://ckeditor.com/legal/ckeditor-oss-license
4
+ */
5
+ /**
6
+ * @module utils/dom/getelementsintersectionrect
7
+ */
8
+ import Rect from './rect';
9
+ /**
10
+ * Calculates the intersection `Rect` of a given set of elements (and/or a `document`).
11
+ * Also, takes into account the viewport top offset configuration.
12
+ *
13
+ * @internal
14
+ * @param elements
15
+ * @param viewportTopOffset
16
+ */
17
+ export default function getElementsIntersectionRect(elements: Array<HTMLElement | Document>, viewportTopOffset?: number): Rect | null;
@@ -0,0 +1,42 @@
1
+ /**
2
+ * @license Copyright (c) 2003-2023, CKSource Holding sp. z o.o. All rights reserved.
3
+ * For licensing, see LICENSE.md or https://ckeditor.com/legal/ckeditor-oss-license
4
+ */
5
+ /**
6
+ * @module utils/dom/getelementsintersectionrect
7
+ */
8
+ import Rect from './rect';
9
+ /**
10
+ * Calculates the intersection `Rect` of a given set of elements (and/or a `document`).
11
+ * Also, takes into account the viewport top offset configuration.
12
+ *
13
+ * @internal
14
+ * @param elements
15
+ * @param viewportTopOffset
16
+ */
17
+ export default function getElementsIntersectionRect(elements, viewportTopOffset = 0) {
18
+ const elementRects = elements.map(element => {
19
+ // The document (window) is yet another "element", but cropped by the top offset.
20
+ if (element instanceof Document) {
21
+ const windowRect = new Rect(global.window);
22
+ windowRect.top += viewportTopOffset;
23
+ windowRect.height -= viewportTopOffset;
24
+ return windowRect;
25
+ }
26
+ else {
27
+ return new Rect(element);
28
+ }
29
+ });
30
+ let intersectionRect = elementRects[0];
31
+ // @if CK_DEBUG_GETELEMENTSINTERSECTIONRECT // for ( const rect of elementRects ) {
32
+ // @if CK_DEBUG_GETELEMENTSINTERSECTIONRECT // RectDrawer.draw( rect, {
33
+ // @if CK_DEBUG_GETELEMENTSINTERSECTIONRECT // outlineWidth: '1px', opacity: '.7', outlineStyle: 'dashed'
34
+ // @if CK_DEBUG_GETELEMENTSINTERSECTIONRECT // }, 'Scrollable element' );
35
+ // @if CK_DEBUG_GETELEMENTSINTERSECTIONRECT // }
36
+ for (const rect of elementRects.slice(1)) {
37
+ if (intersectionRect) {
38
+ intersectionRect = intersectionRect.getIntersection(rect);
39
+ }
40
+ }
41
+ return intersectionRect;
42
+ }
@@ -0,0 +1,14 @@
1
+ /**
2
+ * @license Copyright (c) 2003-2023, CKSource Holding sp. z o.o. All rights reserved.
3
+ * For licensing, see LICENSE.md or https://ckeditor.com/legal/ckeditor-oss-license
4
+ */
5
+ /**
6
+ * Loops over the given element's ancestors to find all the scrollable elements.
7
+ *
8
+ * **Note**: The `document` is always included in the returned array.
9
+ *
10
+ * @internal
11
+ * @param element
12
+ * @returns An array of scrollable element's ancestors (including the `document`).
13
+ */
14
+ export default function getScrollableAncestors(element: HTMLElement): Array<HTMLElement | Document>;
@@ -0,0 +1,28 @@
1
+ /**
2
+ * @license Copyright (c) 2003-2023, CKSource Holding sp. z o.o. All rights reserved.
3
+ * For licensing, see LICENSE.md or https://ckeditor.com/legal/ckeditor-oss-license
4
+ */
5
+ /**
6
+ * @module utils/dom/getscrollableancestors
7
+ */
8
+ import global from './global';
9
+ import findClosestScrollableAncestor from './findclosestscrollableancestor';
10
+ /**
11
+ * Loops over the given element's ancestors to find all the scrollable elements.
12
+ *
13
+ * **Note**: The `document` is always included in the returned array.
14
+ *
15
+ * @internal
16
+ * @param element
17
+ * @returns An array of scrollable element's ancestors (including the `document`).
18
+ */
19
+ export default function getScrollableAncestors(element) {
20
+ const scrollableAncestors = [];
21
+ let scrollableAncestor = findClosestScrollableAncestor(element);
22
+ while (scrollableAncestor && scrollableAncestor !== global.document.body) {
23
+ scrollableAncestors.push(scrollableAncestor);
24
+ scrollableAncestor = findClosestScrollableAncestor(scrollableAncestor);
25
+ }
26
+ scrollableAncestors.push(global.document);
27
+ return scrollableAncestors;
28
+ }
@@ -66,6 +66,8 @@ export declare function scrollViewportToShowTarget<T extends boolean, U extends
66
66
  * @param target A target, which supposed to become visible to the user.
67
67
  * @param ancestorOffset An offset between the target and the boundary of scrollable ancestors
68
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.
69
71
  */
70
- export declare function scrollAncestorsToShowTarget(target: HTMLElement | Range, ancestorOffset?: number): void;
72
+ export declare function scrollAncestorsToShowTarget(target: HTMLElement | Range, ancestorOffset?: number, limiterElement?: HTMLElement): void;
71
73
  export {};
package/src/dom/scroll.js CHANGED
@@ -124,13 +124,16 @@ export function scrollViewportToShowTarget({ target, viewportOffset = 0, ancesto
124
124
  * @param target A target, which supposed to become visible to the user.
125
125
  * @param ancestorOffset An offset between the target and the boundary of scrollable ancestors
126
126
  * to be maintained while scrolling.
127
+ * @param limiterElement The outermost ancestor that should be scrolled. If specified, it can prevent
128
+ * scrolling the whole page.
127
129
  */
128
- export function scrollAncestorsToShowTarget(target, ancestorOffset) {
130
+ export function scrollAncestorsToShowTarget(target, ancestorOffset, limiterElement) {
129
131
  const targetParent = getParentElement(target);
130
132
  scrollAncestorsToShowRect({
131
133
  parent: targetParent,
132
134
  getRect: () => new Rect(target),
133
- ancestorOffset
135
+ ancestorOffset,
136
+ limiterElement
134
137
  });
135
138
  }
136
139
  /**
@@ -246,12 +249,14 @@ function scrollWindowToShowRect({ window, rect, alignToTop, forceScroll, viewpor
246
249
  * anyway.
247
250
  * @param options.forceScroll When set `true`, the `rect` will be aligned to the top of scrollable ancestors
248
251
  * whether it is already visible or not. This option will only work when `alignToTop` is `true`
252
+ * @param options.limiterElement The outermost ancestor that should be scrolled. Defaults to the `<body>` element.
249
253
  */
250
- function scrollAncestorsToShowRect({ parent, getRect, alignToTop, forceScroll, ancestorOffset = 0 }) {
254
+ function scrollAncestorsToShowRect({ parent, getRect, alignToTop, forceScroll, ancestorOffset = 0, limiterElement }) {
251
255
  const parentWindow = getWindow(parent);
252
256
  const forceScrollToTop = alignToTop && forceScroll;
253
257
  let parentRect, targetRect, targetFitsInTarget;
254
- while (parent != parentWindow.document.body) {
258
+ const limiter = limiterElement || parentWindow.document.body;
259
+ while (parent != limiter) {
255
260
  targetRect = getRect();
256
261
  parentRect = new Rect(parent).excludeScrollbarsAndBorders();
257
262
  targetFitsInTarget = parentRect.contains(targetRect);
@@ -39,8 +39,10 @@ export default class FocusTracker extends FocusTracker_base {
39
39
  focusedElement: Element | null;
40
40
  /**
41
41
  * List of registered elements.
42
+ *
43
+ * @internal
42
44
  */
43
- private _elements;
45
+ _elements: Set<Element>;
44
46
  /**
45
47
  * Event loop timeout.
46
48
  */
@@ -26,6 +26,8 @@ export default class FocusTracker extends DomEmitterMixin(ObservableMixin()) {
26
26
  super();
27
27
  /**
28
28
  * List of registered elements.
29
+ *
30
+ * @internal
29
31
  */
30
32
  this._elements = new Set();
31
33
  /**
package/src/index.d.ts CHANGED
@@ -25,6 +25,8 @@ export { default as DomEmitterMixin, type DomEmitter } from './dom/emittermixin'
25
25
  export { default as findClosestScrollableAncestor } from './dom/findclosestscrollableancestor';
26
26
  export { default as global } from './dom/global';
27
27
  export { default as getAncestors } from './dom/getancestors';
28
+ export { default as getElementsIntersectionRect } from './dom/getelementsintersectionrect';
29
+ export { default as getScrollableAncestors } from './dom/getscrollableancestors';
28
30
  export { default as getDataFromElement } from './dom/getdatafromelement';
29
31
  export { default as isText } from './dom/istext';
30
32
  export { default as Rect, type RectSource } from './dom/rect';
@@ -38,7 +40,7 @@ export { default as isNode } from './dom/isnode';
38
40
  export { default as isRange } from './dom/isrange';
39
41
  export { default as isValidAttributeName } from './dom/isvalidattributename';
40
42
  export { default as isVisible } from './dom/isvisible';
41
- export { getOptimalPosition, type Options as PositionOptions, type PositioningFunction } from './dom/position';
43
+ export { getOptimalPosition, type Options as PositionOptions, type PositioningFunction, type Position } from './dom/position';
42
44
  export { default as remove } from './dom/remove';
43
45
  export * from './dom/scroll';
44
46
  export * from './keyboard';
package/src/index.js CHANGED
@@ -24,6 +24,8 @@ export { default as DomEmitterMixin } from './dom/emittermixin';
24
24
  export { default as findClosestScrollableAncestor } from './dom/findclosestscrollableancestor';
25
25
  export { default as global } from './dom/global';
26
26
  export { default as getAncestors } from './dom/getancestors';
27
+ export { default as getElementsIntersectionRect } from './dom/getelementsintersectionrect';
28
+ export { default as getScrollableAncestors } from './dom/getscrollableancestors';
27
29
  export { default as getDataFromElement } from './dom/getdatafromelement';
28
30
  export { default as isText } from './dom/istext';
29
31
  export { default as Rect } from './dom/rect';
@@ -531,6 +531,8 @@ interface SingleBindChain<TKey extends string, TVal> {
531
531
  to<O1 extends Observable, K1 extends keyof O1, O2 extends Observable, K2 extends keyof O2, O3 extends Observable, K3 extends keyof O3>(observable1: O1, key1: K1, observable2: O2, key2: K2, observable3: O3, key3: K3, callback: (value1: O1[K1], value2: O2[K2], value3: O3[K3]) => TVal): void;
532
532
  to<O1 extends ObservableWithProperty<TKey>, O2 extends ObservableWithProperty<TKey>, O3 extends ObservableWithProperty<TKey>, O4 extends ObservableWithProperty<TKey>>(observable1: O1, observable2: O2, observable3: O3, observable4: O4, callback: (value1: O1[TKey], value2: O2[TKey], value3: O3[TKey], value4: O4[TKey]) => TVal): void;
533
533
  to<O1 extends Observable, K1 extends keyof O1, O2 extends Observable, K2 extends keyof O2, O3 extends Observable, K3 extends keyof O3, O4 extends Observable, K4 extends keyof O4>(observable1: O1, key1: K1, observable2: O2, key2: K2, observable3: O3, key3: K3, observable4: O4, key4: K4, callback: (value1: O1[K1], value2: O2[K2], value3: O3[K3], value4: O4[K4]) => TVal): void;
534
+ to<O1 extends ObservableWithProperty<TKey>, O2 extends ObservableWithProperty<TKey>, O3 extends ObservableWithProperty<TKey>, O4 extends ObservableWithProperty<TKey>, O5 extends ObservableWithProperty<TKey>>(observable1: O1, observable2: O2, observable3: O3, observable4: O4, observable5: O5, callback: (value1: O1[TKey], value2: O2[TKey], value3: O3[TKey], value4: O4[TKey], value5: O5[TKey]) => TVal): void;
535
+ to<O1 extends Observable, K1 extends keyof O1, O2 extends Observable, K2 extends keyof O2, O3 extends Observable, K3 extends keyof O3, O4 extends Observable, K4 extends keyof O4, O5 extends Observable, K5 extends keyof O5>(observable1: O1, key1: K1, observable2: O2, key2: K2, observable3: O3, key3: K3, observable4: O4, key4: K4, observable5: O5, key5: K5, callback: (value1: O1[K1], value2: O2[K2], value3: O3[K3], value4: O4[K4], value5: O5[K5]) => TVal): void;
534
536
  }
535
537
  /**
536
538
  * A helper type that can be used as a constraint, ensuring the type is both observable and have the given property.
package/src/version.d.ts CHANGED
@@ -2,7 +2,7 @@
2
2
  * @license Copyright (c) 2003-2023, CKSource Holding sp. z o.o. All rights reserved.
3
3
  * For licensing, see LICENSE.md or https://ckeditor.com/legal/ckeditor-oss-license
4
4
  */
5
- declare const version = "38.2.0-alpha.0";
5
+ declare const version = "39.0.0";
6
6
  export default version;
7
7
  export declare const releaseDate: Date;
8
8
  declare global {
package/src/version.js CHANGED
@@ -7,10 +7,10 @@
7
7
  */
8
8
  /* globals window, global */
9
9
  import CKEditorError from './ckeditorerror';
10
- const version = '38.2.0-alpha.0';
10
+ const version = '39.0.0';
11
11
  export default version;
12
12
  // The second argument is not a month. It is `monthIndex` and starts from `0`.
13
- export const releaseDate = new Date(2023, 5, 29);
13
+ export const releaseDate = new Date(2023, 7, 2);
14
14
  /* istanbul ignore next -- @preserve */
15
15
  const windowOrGlobal = typeof window === 'object' ? window : global;
16
16
  /* istanbul ignore next -- @preserve */