@ckeditor/ckeditor5-utils 34.2.0 → 35.1.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.
Files changed (61) hide show
  1. package/CHANGELOG.md +324 -0
  2. package/LICENSE.md +1 -1
  3. package/package.json +19 -8
  4. package/src/areconnectedthroughproperties.js +54 -71
  5. package/src/ckeditorerror.js +92 -114
  6. package/src/collection.js +594 -762
  7. package/src/comparearrays.js +22 -28
  8. package/src/config.js +193 -223
  9. package/src/count.js +8 -12
  10. package/src/diff.js +85 -110
  11. package/src/difftochanges.js +47 -57
  12. package/src/dom/createelement.js +17 -25
  13. package/src/dom/emittermixin.js +202 -263
  14. package/src/dom/getancestors.js +9 -13
  15. package/src/dom/getborderwidths.js +10 -13
  16. package/src/dom/getcommonancestor.js +9 -15
  17. package/src/dom/getdatafromelement.js +5 -9
  18. package/src/dom/getpositionedancestor.js +9 -14
  19. package/src/dom/global.js +15 -4
  20. package/src/dom/indexof.js +7 -11
  21. package/src/dom/insertat.js +2 -4
  22. package/src/dom/iscomment.js +2 -5
  23. package/src/dom/isnode.js +10 -12
  24. package/src/dom/isrange.js +2 -4
  25. package/src/dom/istext.js +2 -4
  26. package/src/dom/isvisible.js +2 -4
  27. package/src/dom/iswindow.js +11 -16
  28. package/src/dom/position.js +220 -410
  29. package/src/dom/rect.js +335 -414
  30. package/src/dom/remove.js +5 -8
  31. package/src/dom/resizeobserver.js +109 -342
  32. package/src/dom/scroll.js +151 -183
  33. package/src/dom/setdatainelement.js +5 -9
  34. package/src/dom/tounit.js +10 -12
  35. package/src/elementreplacer.js +30 -44
  36. package/src/emittermixin.js +368 -634
  37. package/src/env.js +109 -116
  38. package/src/eventinfo.js +12 -65
  39. package/src/fastdiff.js +96 -128
  40. package/src/first.js +8 -12
  41. package/src/focustracker.js +77 -133
  42. package/src/index.js +0 -9
  43. package/src/inserttopriorityarray.js +9 -30
  44. package/src/isiterable.js +2 -4
  45. package/src/keyboard.js +117 -196
  46. package/src/keystrokehandler.js +72 -88
  47. package/src/language.js +9 -15
  48. package/src/locale.js +61 -158
  49. package/src/mapsequal.js +12 -17
  50. package/src/mix.js +17 -16
  51. package/src/nth.js +8 -11
  52. package/src/objecttomap.js +7 -11
  53. package/src/observablemixin.js +474 -778
  54. package/src/priorities.js +20 -32
  55. package/src/spy.js +3 -6
  56. package/src/toarray.js +2 -13
  57. package/src/tomap.js +8 -10
  58. package/src/translation-service.js +57 -93
  59. package/src/uid.js +34 -38
  60. package/src/unicode.js +28 -43
  61. package/src/version.js +134 -143
package/src/first.js CHANGED
@@ -2,23 +2,19 @@
2
2
  * @license Copyright (c) 2003-2022, 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
-
6
5
  /**
7
6
  * @module utils/first
8
7
  */
9
-
10
8
  /**
11
- * Returns first item of the given `iterable`.
9
+ * Returns first item of the given `iterator`.
12
10
  *
13
- * @param {Iterable.<*>} iterable
11
+ * @param {Iterator.<*>} iterator
14
12
  * @returns {*}
15
13
  */
16
- export default function first( iterable ) {
17
- const iteratorItem = iterable.next();
18
-
19
- if ( iteratorItem.done ) {
20
- return null;
21
- }
22
-
23
- return iteratorItem.value;
14
+ export default function first(iterator) {
15
+ const iteratorItem = iterator.next();
16
+ if (iteratorItem.done) {
17
+ return null;
18
+ }
19
+ return iteratorItem.value;
24
20
  }
@@ -2,25 +2,21 @@
2
2
  * @license Copyright (c) 2003-2022, 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
-
6
5
  /* global setTimeout, clearTimeout */
7
-
6
+ /* eslint-disable new-cap */
8
7
  /**
9
8
  * @module utils/focustracker
10
9
  */
11
-
12
10
  import DomEmitterMixin from './dom/emittermixin';
13
- import ObservableMixin from './observablemixin';
11
+ import { Observable } from './observablemixin';
14
12
  import CKEditorError from './ckeditorerror';
15
- import mix from './mix';
16
-
17
13
  /**
18
- * Allows observing a group of `HTMLElement`s whether at least one of them is focused.
14
+ * Allows observing a group of `Element`s whether at least one of them is focused.
19
15
  *
20
16
  * Used by the {@link module:core/editor/editor~Editor} in order to track whether the focus is still within the application,
21
17
  * or were used outside of its UI.
22
18
  *
23
- * **Note** `focus` and `blur` listeners use event capturing, so it is only needed to register wrapper `HTMLElement`
19
+ * **Note** `focus` and `blur` listeners use event capturing, so it is only needed to register wrapper `Element`
24
20
  * which contain other `focusable` elements. But note that this wrapper element has to be focusable too
25
21
  * (have e.g. `tabindex="-1"`).
26
22
  *
@@ -29,129 +25,77 @@ import mix from './mix';
29
25
  * @mixes module:utils/dom/emittermixin~EmitterMixin
30
26
  * @mixes module:utils/observablemixin~ObservableMixin
31
27
  */
32
- export default class FocusTracker {
33
- constructor() {
34
- /**
35
- * True when one of the registered elements is focused.
36
- *
37
- * @readonly
38
- * @observable
39
- * @member {Boolean} #isFocused
40
- */
41
- this.set( 'isFocused', false );
42
-
43
- /**
44
- * The currently focused element.
45
- *
46
- * While {@link #isFocused `isFocused`} remains `true`, the focus can
47
- * move between different UI elements. This property tracks those
48
- * elements and tells which one is currently focused.
49
- *
50
- * @readonly
51
- * @observable
52
- * @member {HTMLElement|null} #focusedElement
53
- */
54
- this.set( 'focusedElement', null );
55
-
56
- /**
57
- * List of registered elements.
58
- *
59
- * @private
60
- * @member {Set.<HTMLElement>}
61
- */
62
- this._elements = new Set();
63
-
64
- /**
65
- * Event loop timeout.
66
- *
67
- * @private
68
- * @member {Number}
69
- */
70
- this._nextEventLoopTimeout = null;
71
- }
72
-
73
- /**
74
- * Starts tracking the specified element.
75
- *
76
- * @param {HTMLElement} element
77
- */
78
- add( element ) {
79
- if ( this._elements.has( element ) ) {
80
- /**
81
- * This element is already tracked by {@link module:utils/focustracker~FocusTracker}.
82
- *
83
- * @error focustracker-add-element-already-exist
84
- */
85
- throw new CKEditorError( 'focustracker-add-element-already-exist', this );
86
- }
87
-
88
- this.listenTo( element, 'focus', () => this._focus( element ), { useCapture: true } );
89
- this.listenTo( element, 'blur', () => this._blur(), { useCapture: true } );
90
- this._elements.add( element );
91
- }
92
-
93
- /**
94
- * Stops tracking the specified element and stops listening on this element.
95
- *
96
- * @param {HTMLElement} element
97
- */
98
- remove( element ) {
99
- if ( element === this.focusedElement ) {
100
- this._blur( element );
101
- }
102
-
103
- if ( this._elements.has( element ) ) {
104
- this.stopListening( element );
105
- this._elements.delete( element );
106
- }
107
- }
108
-
109
- /**
110
- * Destroys the focus tracker by:
111
- * - Disabling all event listeners attached to tracked elements.
112
- * - Removing all tracked elements that were previously added.
113
- */
114
- destroy() {
115
- this.stopListening();
116
- }
117
-
118
- /**
119
- * Stores currently focused element and set {#isFocused} as `true`.
120
- *
121
- * @private
122
- * @param {HTMLElement} element Element which has been focused.
123
- */
124
- _focus( element ) {
125
- clearTimeout( this._nextEventLoopTimeout );
126
-
127
- this.focusedElement = element;
128
- this.isFocused = true;
129
- }
130
-
131
- /**
132
- * Clears currently focused element and set {@link #isFocused} as `false`.
133
- * This method uses `setTimeout` to change order of fires `blur` and `focus` events.
134
- *
135
- * @private
136
- * @fires blur
137
- */
138
- _blur() {
139
- clearTimeout( this._nextEventLoopTimeout );
140
-
141
- this._nextEventLoopTimeout = setTimeout( () => {
142
- this.focusedElement = null;
143
- this.isFocused = false;
144
- }, 0 );
145
- }
146
-
147
- /**
148
- * @event focus
149
- */
150
-
151
- /**
152
- * @event blur
153
- */
28
+ export default class FocusTracker extends DomEmitterMixin(Observable) {
29
+ constructor() {
30
+ super();
31
+ this.set('isFocused', false);
32
+ this.set('focusedElement', null);
33
+ this._elements = new Set();
34
+ this._nextEventLoopTimeout = null;
35
+ }
36
+ /**
37
+ * Starts tracking the specified element.
38
+ *
39
+ * @param {Element} element
40
+ */
41
+ add(element) {
42
+ if (this._elements.has(element)) {
43
+ /**
44
+ * This element is already tracked by {@link module:utils/focustracker~FocusTracker}.
45
+ *
46
+ * @error focustracker-add-element-already-exist
47
+ */
48
+ throw new CKEditorError('focustracker-add-element-already-exist', this);
49
+ }
50
+ this.listenTo(element, 'focus', () => this._focus(element), { useCapture: true });
51
+ this.listenTo(element, 'blur', () => this._blur(), { useCapture: true });
52
+ this._elements.add(element);
53
+ }
54
+ /**
55
+ * Stops tracking the specified element and stops listening on this element.
56
+ *
57
+ * @param {Element} element
58
+ */
59
+ remove(element) {
60
+ if (element === this.focusedElement) {
61
+ this._blur();
62
+ }
63
+ if (this._elements.has(element)) {
64
+ this.stopListening(element);
65
+ this._elements.delete(element);
66
+ }
67
+ }
68
+ /**
69
+ * Destroys the focus tracker by:
70
+ * - Disabling all event listeners attached to tracked elements.
71
+ * - Removing all tracked elements that were previously added.
72
+ */
73
+ destroy() {
74
+ this.stopListening();
75
+ }
76
+ /**
77
+ * Stores currently focused element and set {#isFocused} as `true`.
78
+ *
79
+ * @private
80
+ * @param {Element} element Element which has been focused.
81
+ */
82
+ _focus(element) {
83
+ clearTimeout(this._nextEventLoopTimeout);
84
+ this.focusedElement = element;
85
+ this.isFocused = true;
86
+ }
87
+ /**
88
+ * Clears currently focused element and set {@link #isFocused} as `false`.
89
+ * This method uses `setTimeout` to change order of fires `blur` and `focus` events.
90
+ *
91
+ * @private
92
+ * @fires blur
93
+ */
94
+ _blur() {
95
+ clearTimeout(this._nextEventLoopTimeout);
96
+ this._nextEventLoopTimeout = setTimeout(() => {
97
+ this.focusedElement = null;
98
+ this.isFocused = false;
99
+ }, 0);
100
+ }
154
101
  }
155
-
156
- mix( FocusTracker, DomEmitterMixin );
157
- mix( FocusTracker, ObservableMixin );
package/src/index.js CHANGED
@@ -2,22 +2,16 @@
2
2
  * @license Copyright (c) 2003-2022, 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
-
6
5
  /**
7
6
  * @module utils
8
7
  */
9
-
10
8
  export { default as env } from './env';
11
9
  export { default as diff } from './diff';
12
-
13
10
  export { default as mix } from './mix';
14
11
  export { default as EmitterMixin } from './emittermixin';
15
12
  export { default as ObservableMixin } from './observablemixin';
16
-
17
13
  export { default as CKEditorError, logError, logWarning } from './ckeditorerror';
18
-
19
14
  export { default as ElementReplacer } from './elementreplacer';
20
-
21
15
  export { default as createElement } from './dom/createelement';
22
16
  export { default as DomEmitterMixin } from './dom/emittermixin';
23
17
  export { default as global } from './dom/global';
@@ -28,7 +22,6 @@ export { default as setDataInElement } from './dom/setdatainelement';
28
22
  export { default as toUnit } from './dom/tounit';
29
23
  export { default as isVisible } from './dom/isvisible';
30
24
  export * from './dom/scroll';
31
-
32
25
  export * from './keyboard';
33
26
  export * from './language';
34
27
  export { default as Locale } from './locale';
@@ -39,7 +32,5 @@ export { default as KeystrokeHandler } from './keystrokehandler';
39
32
  export { default as toArray } from './toarray';
40
33
  export { default as toMap } from './tomap';
41
34
  export { default as priorities } from './priorities';
42
-
43
35
  export { default as uid } from './uid';
44
-
45
36
  export { default as version } from './version';
@@ -2,41 +2,20 @@
2
2
  * @license Copyright (c) 2003-2022, 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
-
6
5
  import priorities from './priorities';
7
-
8
- /**
9
- * @module utils/inserttopriorityarray
10
- */
11
-
12
- /**
13
- * The priority object descriptor.
14
- *
15
- * const objectWithPriority = {
16
- * priority: 'high'
17
- * }
18
- *
19
- * @typedef {Object} module:utils/inserttopriorityarray~ObjectWithPriority
20
- *
21
- * @property {module:utils/priorities~PriorityString|Number} priority Priority of the object.
22
- */
23
-
24
6
  /**
25
7
  * Inserts any object with priority at correct index by priority so registered objects are always sorted from highest to lowest priority.
26
8
  *
27
9
  * @param {Array.<module:utils/inserttopriorityarray~ObjectWithPriority>} objects Array of objects with priority to insert object to.
28
10
  * @param {module:utils/inserttopriorityarray~ObjectWithPriority} objectToInsert Object with `priority` property.
29
11
  */
30
- export default function insertToPriorityArray( objects, objectToInsert ) {
31
- const priority = priorities.get( objectToInsert.priority );
32
-
33
- for ( let i = 0; i < objects.length; i++ ) {
34
- if ( priorities.get( objects[ i ].priority ) < priority ) {
35
- objects.splice( i, 0, objectToInsert );
36
-
37
- return;
38
- }
39
- }
40
-
41
- objects.push( objectToInsert );
12
+ export default function insertToPriorityArray(objects, objectToInsert) {
13
+ const priority = priorities.get(objectToInsert.priority);
14
+ for (let i = 0; i < objects.length; i++) {
15
+ if (priorities.get(objects[i].priority) < priority) {
16
+ objects.splice(i, 0, objectToInsert);
17
+ return;
18
+ }
19
+ }
20
+ objects.push(objectToInsert);
42
21
  }
package/src/isiterable.js CHANGED
@@ -2,17 +2,15 @@
2
2
  * @license Copyright (c) 2003-2022, 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
-
6
5
  /**
7
6
  * @module utils/isiterable
8
7
  */
9
-
10
8
  /**
11
9
  * Checks if value implements iterator interface.
12
10
  *
13
11
  * @param {*} value The value to check.
14
12
  * @returns {Boolean} True if value implements iterator interface.
15
13
  */
16
- export default function isIterable( value ) {
17
- return !!( value && value[ Symbol.iterator ] );
14
+ export default function isIterable(value) {
15
+ return !!(value && value[Symbol.iterator]);
18
16
  }