@ckeditor/ckeditor5-utils 43.0.0 → 43.1.0-alpha.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.
@@ -0,0 +1,21 @@
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/getrangefrommouseevent
11
+ */
12
+ /**
13
+ * Returns a DOM range from a given point specified by a mouse event.
14
+ *
15
+ * @param domEvent The mouse event.
16
+ * @returns The DOM range.
17
+ */
18
+ export default function getRangeFromMouseEvent(domEvent: MouseEvent & {
19
+ rangeParent?: HTMLElement;
20
+ rangeOffset?: number;
21
+ }): Range | null;
@@ -6,9 +6,6 @@
6
6
  * @license Copyright (c) 2003-2024, CKSource Holding sp. z o.o. All rights reserved.
7
7
  * For licensing, see LICENSE.md or https://ckeditor.com/legal/ckeditor-oss-license
8
8
  */
9
- /**
10
- * @module utils/dom/isvisible
11
- */
12
9
  /**
13
10
  * Checks whether the element is visible to the user in DOM:
14
11
  *
@@ -19,4 +16,4 @@
19
16
  * **Note**: This helper does not check whether the element is hidden by cropping, overflow, etc..
20
17
  * To check that, use {@link module:utils/dom/rect~Rect} instead.
21
18
  */
22
- export default function isVisible(element: HTMLElement | null | undefined): boolean;
19
+ export default function isVisible(element: Text | HTMLElement | null | undefined): boolean;
@@ -52,6 +52,10 @@ export default class FocusTracker extends /* #__PURE__ */ FocusTracker_base {
52
52
  */
53
53
  private _nextEventLoopTimeout;
54
54
  constructor();
55
+ /**
56
+ * List of registered elements.
57
+ */
58
+ get elements(): Array<Element>;
55
59
  /**
56
60
  * Starts tracking the specified element.
57
61
  */
package/dist/index.d.ts CHANGED
@@ -32,6 +32,7 @@ export { default as global } from './dom/global.js';
32
32
  export { default as getAncestors } from './dom/getancestors.js';
33
33
  export { default as getDataFromElement } from './dom/getdatafromelement.js';
34
34
  export { default as getBorderWidths } from './dom/getborderwidths.js';
35
+ export { default as getRangeFromMouseEvent } from './dom/getrangefrommouseevent.js';
35
36
  export { default as isText } from './dom/istext.js';
36
37
  export { default as Rect, type RectSource } from './dom/rect.js';
37
38
  export { default as ResizeObserver } from './dom/resizeobserver.js';
package/dist/index.js CHANGED
@@ -732,19 +732,7 @@ diff.fastDiff = fastDiff;
732
732
  * @returns An unique id string.
733
733
  */ function uid() {
734
734
  // Let's create some positive random 32bit integers first.
735
- //
736
- // 1. Math.random() is a float between 0 and 1.
737
- // 2. 0x100000000 is 2^32 = 4294967296.
738
- // 3. >>> 0 enforces integer (in JS all numbers are floating point).
739
- //
740
- // For instance:
741
- // Math.random() * 0x100000000 = 3366450031.853859
742
- // but
743
- // Math.random() * 0x100000000 >>> 0 = 3366450031.
744
- const r1 = Math.random() * 0x100000000 >>> 0;
745
- const r2 = Math.random() * 0x100000000 >>> 0;
746
- const r3 = Math.random() * 0x100000000 >>> 0;
747
- const r4 = Math.random() * 0x100000000 >>> 0;
735
+ const [r1, r2, r3, r4] = crypto.getRandomValues(new Uint32Array(4));
748
736
  // Make sure that id does not start with number.
749
737
  return 'e' + HEX_NUMBERS[r1 >> 0 & 0xFF] + HEX_NUMBERS[r1 >> 8 & 0xFF] + HEX_NUMBERS[r1 >> 16 & 0xFF] + HEX_NUMBERS[r1 >> 24 & 0xFF] + HEX_NUMBERS[r2 >> 0 & 0xFF] + HEX_NUMBERS[r2 >> 8 & 0xFF] + HEX_NUMBERS[r2 >> 16 & 0xFF] + HEX_NUMBERS[r2 >> 24 & 0xFF] + HEX_NUMBERS[r3 >> 0 & 0xFF] + HEX_NUMBERS[r3 >> 8 & 0xFF] + HEX_NUMBERS[r3 >> 16 & 0xFF] + HEX_NUMBERS[r3 >> 24 & 0xFF] + HEX_NUMBERS[r4 >> 0 & 0xFF] + HEX_NUMBERS[r4 >> 8 & 0xFF] + HEX_NUMBERS[r4 >> 16 & 0xFF] + HEX_NUMBERS[r4 >> 24 & 0xFF];
750
738
  }
@@ -965,9 +953,9 @@ diff.fastDiff = fastDiff;
965
953
  ];
966
954
  }
967
955
 
968
- const version = '43.0.0';
956
+ const version = '43.1.0-alpha.0';
969
957
  // The second argument is not a month. It is `monthIndex` and starts from `0`.
970
- const releaseDate = new Date(2024, 7, 7);
958
+ const releaseDate = new Date(2024, 7, 28);
971
959
  /* istanbul ignore next -- @preserve */ if (globalThis.CKEDITOR_VERSION) {
972
960
  /**
973
961
  * The best solution to avoid this error is migrating your CKEditor&nbsp;5 instance to
@@ -2804,6 +2792,35 @@ function DomEmitterMixin(base) {
2804
2792
  };
2805
2793
  }
2806
2794
 
2795
+ /**
2796
+ * @license Copyright (c) 2003-2024, CKSource Holding sp. z o.o. All rights reserved.
2797
+ * For licensing, see LICENSE.md or https://ckeditor.com/legal/ckeditor-oss-license
2798
+ */ /**
2799
+ * @module utils/dom/getrangefrommouseevent
2800
+ */ /**
2801
+ * Returns a DOM range from a given point specified by a mouse event.
2802
+ *
2803
+ * @param domEvent The mouse event.
2804
+ * @returns The DOM range.
2805
+ */ function getRangeFromMouseEvent(domEvent) {
2806
+ if (!domEvent.target) {
2807
+ return null;
2808
+ }
2809
+ const domDoc = domEvent.target.ownerDocument;
2810
+ const x = domEvent.clientX;
2811
+ const y = domEvent.clientY;
2812
+ let domRange = null;
2813
+ // Webkit & Blink.
2814
+ if (domDoc.caretRangeFromPoint && domDoc.caretRangeFromPoint(x, y)) {
2815
+ domRange = domDoc.caretRangeFromPoint(x, y);
2816
+ } else if (domEvent.rangeParent) {
2817
+ domRange = domDoc.createRange();
2818
+ domRange.setStart(domEvent.rangeParent, domEvent.rangeOffset);
2819
+ domRange.collapse(true);
2820
+ }
2821
+ return domRange;
2822
+ }
2823
+
2807
2824
  /**
2808
2825
  * @license Copyright (c) 2003-2024, CKSource Holding sp. z o.o. All rights reserved.
2809
2826
  * For licensing, see LICENSE.md or https://ckeditor.com/legal/ckeditor-oss-license
@@ -3513,11 +3530,6 @@ const rectProperties = [
3513
3530
  }
3514
3531
 
3515
3532
  /**
3516
- * @license Copyright (c) 2003-2024, CKSource Holding sp. z o.o. All rights reserved.
3517
- * For licensing, see LICENSE.md or https://ckeditor.com/legal/ckeditor-oss-license
3518
- */ /**
3519
- * @module utils/dom/isvisible
3520
- */ /**
3521
3533
  * Checks whether the element is visible to the user in DOM:
3522
3534
  *
3523
3535
  * * connected to the root of the document,
@@ -3527,7 +3539,16 @@ const rectProperties = [
3527
3539
  * **Note**: This helper does not check whether the element is hidden by cropping, overflow, etc..
3528
3540
  * To check that, use {@link module:utils/dom/rect~Rect} instead.
3529
3541
  */ function isVisible(element) {
3530
- return !!(element && element.getClientRects && element.getClientRects().length);
3542
+ if (!element) {
3543
+ return false;
3544
+ }
3545
+ if (isText(element)) {
3546
+ return isVisible(element.parentElement);
3547
+ }
3548
+ if (element.getClientRects) {
3549
+ return !!element.getClientRects().length;
3550
+ }
3551
+ return false;
3531
3552
  }
3532
3553
 
3533
3554
  // @if CK_DEBUG_POSITION // const {
@@ -5321,6 +5342,11 @@ function getNumberOfLanguages(translations) {
5321
5342
  this.set('isFocused', false);
5322
5343
  this.set('focusedElement', null);
5323
5344
  }
5345
+ /**
5346
+ * List of registered elements.
5347
+ */ get elements() {
5348
+ return Array.from(this._elements.values());
5349
+ }
5324
5350
  /**
5325
5351
  * Starts tracking the specified element.
5326
5352
  */ add(element) {
@@ -5812,5 +5838,5 @@ function buildEmojiRegexp() {
5812
5838
  return new RegExp(sequence, 'ug');
5813
5839
  }
5814
5840
 
5815
- export { CKEditorError, Collection, Config, DomEmitterMixin, ElementReplacer, EmitterMixin, EventInfo, FocusTracker, KeystrokeHandler, Locale, ObservableMixin, Rect, ResizeObserver, abortableDebounce, compareArrays, count, createElement, delay, diff, diffToChanges, env, exponentialDelay, fastDiff, findClosestScrollableAncestor, first, getAncestors, getBorderWidths, getCode, getDataFromElement, getEnvKeystrokeText, getLanguageDirection, getLocalizedArrowKeyCodeDirection, getOptimalPosition, global, indexOf, insertAt, insertToPriorityArray, isArrowKeyCode, isCombiningMark, isComment, isForwardArrowKeyCode, isHighSurrogateHalf, isInsideCombinedSymbol, isInsideEmojiSequence, isInsideSurrogatePair, isIterable, isLowSurrogateHalf, isNode, isRange, isText, isValidAttributeName, isVisible, keyCodes, logError, logWarning, mix, parseKeystroke, priorities, releaseDate, remove, retry, scrollAncestorsToShowTarget, scrollViewportToShowTarget, setDataInElement, spliceArray, toArray, toMap, toUnit, uid, verifyLicense, version, wait };
5841
+ export { CKEditorError, Collection, Config, DomEmitterMixin, ElementReplacer, EmitterMixin, EventInfo, FocusTracker, KeystrokeHandler, Locale, ObservableMixin, Rect, ResizeObserver, abortableDebounce, compareArrays, count, createElement, delay, diff, diffToChanges, env, exponentialDelay, fastDiff, findClosestScrollableAncestor, first, getAncestors, getBorderWidths, getCode, getDataFromElement, getEnvKeystrokeText, getLanguageDirection, getLocalizedArrowKeyCodeDirection, getOptimalPosition, getRangeFromMouseEvent, global, indexOf, insertAt, insertToPriorityArray, isArrowKeyCode, isCombiningMark, isComment, isForwardArrowKeyCode, isHighSurrogateHalf, isInsideCombinedSymbol, isInsideEmojiSequence, isInsideSurrogatePair, isIterable, isLowSurrogateHalf, isNode, isRange, isText, isValidAttributeName, isVisible, keyCodes, logError, logWarning, mix, parseKeystroke, priorities, releaseDate, remove, retry, scrollAncestorsToShowTarget, scrollViewportToShowTarget, setDataInElement, spliceArray, toArray, toMap, toUnit, uid, verifyLicense, version, wait };
5816
5842
  //# sourceMappingURL=index.js.map