@ckeditor/ckeditor5-utils 35.3.2 → 36.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.
Files changed (62) hide show
  1. package/LICENSE.md +1 -1
  2. package/package.json +5 -5
  3. package/src/areconnectedthroughproperties.js +7 -9
  4. package/src/ckeditorerror.js +52 -71
  5. package/src/collection.js +108 -150
  6. package/src/comparearrays.js +11 -9
  7. package/src/config.js +30 -84
  8. package/src/count.js +6 -4
  9. package/src/diff.js +8 -6
  10. package/src/difftochanges.js +18 -15
  11. package/src/dom/createelement.js +12 -10
  12. package/src/dom/emittermixin.js +44 -85
  13. package/src/dom/findclosestscrollableancestor.js +30 -0
  14. package/src/dom/getancestors.js +3 -3
  15. package/src/dom/getborderwidths.js +3 -3
  16. package/src/dom/getcommonancestor.js +4 -4
  17. package/src/dom/getdatafromelement.js +3 -3
  18. package/src/dom/getpositionedancestor.js +2 -3
  19. package/src/dom/global.js +13 -15
  20. package/src/dom/indexof.js +3 -3
  21. package/src/dom/insertat.js +4 -4
  22. package/src/dom/iscomment.js +1 -4
  23. package/src/dom/isnode.js +1 -4
  24. package/src/dom/isrange.js +1 -4
  25. package/src/dom/istext.js +1 -4
  26. package/src/dom/isvisible.js +1 -4
  27. package/src/dom/iswindow.js +1 -4
  28. package/src/dom/position.js +111 -134
  29. package/src/dom/rect.js +43 -53
  30. package/src/dom/remove.js +2 -2
  31. package/src/dom/resizeobserver.js +11 -36
  32. package/src/dom/scroll.js +86 -92
  33. package/src/dom/setdatainelement.js +3 -3
  34. package/src/dom/tounit.js +2 -11
  35. package/src/elementreplacer.js +3 -3
  36. package/src/emittermixin.js +49 -49
  37. package/src/env.js +15 -76
  38. package/src/eventinfo.js +3 -3
  39. package/src/fastdiff.js +116 -97
  40. package/src/first.js +1 -4
  41. package/src/focustracker.js +12 -20
  42. package/src/index.js +19 -1
  43. package/src/inserttopriorityarray.js +3 -3
  44. package/src/isiterable.js +3 -3
  45. package/src/keyboard.js +21 -22
  46. package/src/keystrokehandler.js +27 -25
  47. package/src/language.js +2 -3
  48. package/src/locale.js +12 -15
  49. package/src/mapsequal.js +5 -5
  50. package/src/mix.js +16 -14
  51. package/src/nth.js +1 -5
  52. package/src/objecttomap.js +7 -5
  53. package/src/observablemixin.js +127 -151
  54. package/src/priorities.js +1 -10
  55. package/src/splicearray.js +13 -12
  56. package/src/spy.js +2 -2
  57. package/src/toarray.js +1 -1
  58. package/src/tomap.js +8 -6
  59. package/src/translation-service.js +71 -53
  60. package/src/uid.js +6 -4
  61. package/src/unicode.js +10 -16
  62. package/src/version.js +33 -27
package/src/env.js CHANGED
@@ -1,5 +1,5 @@
1
1
  /**
2
- * @license Copyright (c) 2003-2022, CKSource Holding sp. z o.o. All rights reserved.
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
5
  /* globals navigator:false */
@@ -9,8 +9,6 @@
9
9
  /**
10
10
  * Safely returns `userAgent` from browser's navigator API in a lower case.
11
11
  * If navigator API is not available it will return an empty string.
12
- *
13
- * @returns {String}
14
12
  */
15
13
  export function getUserAgent() {
16
14
  // In some environments navigator API might not be available.
@@ -24,73 +22,16 @@ export function getUserAgent() {
24
22
  const userAgent = getUserAgent();
25
23
  /**
26
24
  * A namespace containing environment and browser information.
27
- *
28
- * @namespace
29
25
  */
30
26
  const env = {
31
- /**
32
- * Indicates that the application is running on Macintosh.
33
- *
34
- * @static
35
- * @type {Boolean}
36
- */
37
27
  isMac: isMac(userAgent),
38
- /**
39
- * Indicates that the application is running on Windows.
40
- *
41
- * @static
42
- * @type {Boolean}
43
- */
44
28
  isWindows: isWindows(userAgent),
45
- /**
46
- * Indicates that the application is running in Firefox (Gecko).
47
- *
48
- * @static
49
- * @type {Boolean}
50
- */
51
29
  isGecko: isGecko(userAgent),
52
- /**
53
- * Indicates that the application is running in Safari.
54
- *
55
- * @static
56
- * @type {Boolean}
57
- */
58
30
  isSafari: isSafari(userAgent),
59
- /**
60
- * Indicates the the application is running in iOS.
61
- *
62
- * @static
63
- * @type {Boolean}
64
- */
65
31
  isiOS: isiOS(userAgent),
66
- /**
67
- * Indicates that the application is running on Android mobile device.
68
- *
69
- * @static
70
- * @type {Boolean}
71
- */
72
32
  isAndroid: isAndroid(userAgent),
73
- /**
74
- * Indicates that the application is running in a browser using the Blink engine.
75
- *
76
- * @static
77
- * @type {Boolean}
78
- */
79
33
  isBlink: isBlink(userAgent),
80
- /**
81
- * Environment features information.
82
- *
83
- * @memberOf module:utils/env~env
84
- * @namespace
85
- */
86
34
  features: {
87
- /**
88
- * Indicates that the environment supports ES2018 Unicode property escapes — like `\p{P}` or `\p{L}`.
89
- * More information about unicode properties might be found
90
- * [in Unicode Standard Annex #44](https://www.unicode.org/reports/tr44/#GC_Values_Table).
91
- *
92
- * @type {Boolean}
93
- */
94
35
  isRegExpUnicodePropertySupported: isRegExpUnicodePropertySupported()
95
36
  }
96
37
  };
@@ -98,8 +39,8 @@ export default env;
98
39
  /**
99
40
  * Checks if User Agent represented by the string is running on Macintosh.
100
41
  *
101
- * @param {String} userAgent **Lowercase** `navigator.userAgent` string.
102
- * @returns {Boolean} Whether User Agent is running on Macintosh or not.
42
+ * @param userAgent **Lowercase** `navigator.userAgent` string.
43
+ * @returns Whether User Agent is running on Macintosh or not.
103
44
  */
104
45
  export function isMac(userAgent) {
105
46
  return userAgent.indexOf('macintosh') > -1;
@@ -107,8 +48,8 @@ export function isMac(userAgent) {
107
48
  /**
108
49
  * Checks if User Agent represented by the string is running on Windows.
109
50
  *
110
- * @param {String} userAgent **Lowercase** `navigator.userAgent` string.
111
- * @returns {Boolean} Whether User Agent is running on Windows or not.
51
+ * @param userAgent **Lowercase** `navigator.userAgent` string.
52
+ * @returns Whether User Agent is running on Windows or not.
112
53
  */
113
54
  export function isWindows(userAgent) {
114
55
  return userAgent.indexOf('windows') > -1;
@@ -116,8 +57,8 @@ export function isWindows(userAgent) {
116
57
  /**
117
58
  * Checks if User Agent represented by the string is Firefox (Gecko).
118
59
  *
119
- * @param {String} userAgent **Lowercase** `navigator.userAgent` string.
120
- * @returns {Boolean} Whether User Agent is Firefox or not.
60
+ * @param userAgent **Lowercase** `navigator.userAgent` string.
61
+ * @returns Whether User Agent is Firefox or not.
121
62
  */
122
63
  export function isGecko(userAgent) {
123
64
  return !!userAgent.match(/gecko\/\d+/);
@@ -125,8 +66,8 @@ export function isGecko(userAgent) {
125
66
  /**
126
67
  * Checks if User Agent represented by the string is Safari.
127
68
  *
128
- * @param {String} userAgent **Lowercase** `navigator.userAgent` string.
129
- * @returns {Boolean} Whether User Agent is Safari or not.
69
+ * @param userAgent **Lowercase** `navigator.userAgent` string.
70
+ * @returns Whether User Agent is Safari or not.
130
71
  */
131
72
  export function isSafari(userAgent) {
132
73
  return userAgent.indexOf(' applewebkit/') > -1 && userAgent.indexOf('chrome') === -1;
@@ -134,8 +75,8 @@ export function isSafari(userAgent) {
134
75
  /**
135
76
  * Checks if User Agent represented by the string is running in iOS.
136
77
  *
137
- * @param {String} userAgent **Lowercase** `navigator.userAgent` string.
138
- * @returns {Boolean} Whether User Agent is running in iOS or not.
78
+ * @param userAgent **Lowercase** `navigator.userAgent` string.
79
+ * @returns Whether User Agent is running in iOS or not.
139
80
  */
140
81
  export function isiOS(userAgent) {
141
82
  // "Request mobile site" || "Request desktop site".
@@ -144,8 +85,8 @@ export function isiOS(userAgent) {
144
85
  /**
145
86
  * Checks if User Agent represented by the string is Android mobile device.
146
87
  *
147
- * @param {String} userAgent **Lowercase** `navigator.userAgent` string.
148
- * @returns {Boolean} Whether User Agent is Safari or not.
88
+ * @param userAgent **Lowercase** `navigator.userAgent` string.
89
+ * @returns Whether User Agent is Safari or not.
149
90
  */
150
91
  export function isAndroid(userAgent) {
151
92
  return userAgent.indexOf('android') > -1;
@@ -153,8 +94,8 @@ export function isAndroid(userAgent) {
153
94
  /**
154
95
  * Checks if User Agent represented by the string is Blink engine.
155
96
  *
156
- * @param {String} userAgent **Lowercase** `navigator.userAgent` string.
157
- * @returns {Boolean} Whether User Agent is Blink engine or not.
97
+ * @param userAgent **Lowercase** `navigator.userAgent` string.
98
+ * @returns Whether User Agent is Blink engine or not.
158
99
  */
159
100
  export function isBlink(userAgent) {
160
101
  // The Edge browser before switching to the Blink engine used to report itself as Chrome (and "Edge/")
@@ -165,8 +106,6 @@ export function isBlink(userAgent) {
165
106
  * Checks if the current environment supports ES2018 Unicode properties like `\p{P}` or `\p{L}`.
166
107
  * More information about unicode properties might be found
167
108
  * [in Unicode Standard Annex #44](https://www.unicode.org/reports/tr44/#GC_Values_Table).
168
- *
169
- * @returns {Boolean}
170
109
  */
171
110
  export function isRegExpUnicodePropertySupported() {
172
111
  let isSupported = false;
package/src/eventinfo.js CHANGED
@@ -1,5 +1,5 @@
1
1
  /**
2
- * @license Copyright (c) 2003-2022, CKSource Holding sp. z o.o. All rights reserved.
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
5
  /**
@@ -12,8 +12,8 @@ import spy from './spy';
12
12
  */
13
13
  export default class EventInfo {
14
14
  /**
15
- * @param {Object} source The emitter.
16
- * @param {String} name The event name.
15
+ * @param source The emitter.
16
+ * @param name The event name.
17
17
  */
18
18
  constructor(source, name) {
19
19
  this.source = source;
package/src/fastdiff.js CHANGED
@@ -1,95 +1,113 @@
1
1
  /**
2
- * @license Copyright (c) 2003-2022, CKSource Holding sp. z o.o. All rights reserved.
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
+ /**
6
+ * @module utils/fastdiff
7
+ */
5
8
  /**
6
9
  * Finds positions of the first and last change in the given string/array and generates a set of changes:
7
10
  *
8
- * fastDiff( '12a', '12xyza' );
9
- * // [ { index: 2, type: 'insert', values: [ 'x', 'y', 'z' ] } ]
11
+ * ```ts
12
+ * fastDiff( '12a', '12xyza' );
13
+ * // [ { index: 2, type: 'insert', values: [ 'x', 'y', 'z' ] } ]
10
14
  *
11
- * fastDiff( '12a', '12aa' );
12
- * // [ { index: 3, type: 'insert', values: [ 'a' ] } ]
15
+ * fastDiff( '12a', '12aa' );
16
+ * // [ { index: 3, type: 'insert', values: [ 'a' ] } ]
13
17
  *
14
- * fastDiff( '12xyza', '12a' );
15
- * // [ { index: 2, type: 'delete', howMany: 3 } ]
18
+ * fastDiff( '12xyza', '12a' );
19
+ * // [ { index: 2, type: 'delete', howMany: 3 } ]
16
20
  *
17
- * fastDiff( [ '1', '2', 'a', 'a' ], [ '1', '2', 'a' ] );
18
- * // [ { index: 3, type: 'delete', howMany: 1 } ]
21
+ * fastDiff( [ '1', '2', 'a', 'a' ], [ '1', '2', 'a' ] );
22
+ * // [ { index: 3, type: 'delete', howMany: 1 } ]
19
23
  *
20
- * fastDiff( [ '1', '2', 'a', 'b', 'c', '3' ], [ '2', 'a', 'b' ] );
21
- * // [ { index: 0, type: 'insert', values: [ '2', 'a', 'b' ] }, { index: 3, type: 'delete', howMany: 6 } ]
24
+ * fastDiff( [ '1', '2', 'a', 'b', 'c', '3' ], [ '2', 'a', 'b' ] );
25
+ * // [ { index: 0, type: 'insert', values: [ '2', 'a', 'b' ] }, { index: 3, type: 'delete', howMany: 6 } ]
26
+ * ```
22
27
  *
23
28
  * Passed arrays can contain any type of data, however to compare them correctly custom comparator function
24
29
  * should be passed as a third parameter:
25
30
  *
26
- * fastDiff( [ { value: 1 }, { value: 2 } ], [ { value: 1 }, { value: 3 } ], ( a, b ) => {
27
- * return a.value === b.value;
28
- * } );
29
- * // [ { index: 1, type: 'insert', values: [ { value: 3 } ] }, { index: 2, type: 'delete', howMany: 1 } ]
31
+ * ```ts
32
+ * fastDiff( [ { value: 1 }, { value: 2 } ], [ { value: 1 }, { value: 3 } ], ( a, b ) => {
33
+ * return a.value === b.value;
34
+ * } );
35
+ * // [ { index: 1, type: 'insert', values: [ { value: 3 } ] }, { index: 2, type: 'delete', howMany: 1 } ]
36
+ * ```
30
37
  *
31
38
  * The resulted set of changes can be applied to the input in order to transform it into the output, for example:
32
39
  *
33
- * let input = '12abc3';
34
- * const output = '2ab';
35
- * const changes = fastDiff( input, output );
40
+ * ```ts
41
+ * let input = '12abc3';
42
+ * const output = '2ab';
43
+ * const changes = fastDiff( input, output );
36
44
  *
37
- * changes.forEach( change => {
38
- * if ( change.type == 'insert' ) {
39
- * input = input.substring( 0, change.index ) + change.values.join( '' ) + input.substring( change.index );
40
- * } else if ( change.type == 'delete' ) {
41
- * input = input.substring( 0, change.index ) + input.substring( change.index + change.howMany );
42
- * }
43
- * } );
45
+ * changes.forEach( change => {
46
+ * if ( change.type == 'insert' ) {
47
+ * input = input.substring( 0, change.index ) + change.values.join( '' ) + input.substring( change.index );
48
+ * } else if ( change.type == 'delete' ) {
49
+ * input = input.substring( 0, change.index ) + input.substring( change.index + change.howMany );
50
+ * }
51
+ * } );
44
52
  *
45
- * // input equals output now
53
+ * // input equals output now
54
+ * ```
46
55
  *
47
56
  * or in case of arrays:
48
57
  *
49
- * let input = [ '1', '2', 'a', 'b', 'c', '3' ];
50
- * const output = [ '2', 'a', 'b' ];
51
- * const changes = fastDiff( input, output );
58
+ * ```ts
59
+ * let input = [ '1', '2', 'a', 'b', 'c', '3' ];
60
+ * const output = [ '2', 'a', 'b' ];
61
+ * const changes = fastDiff( input, output );
52
62
  *
53
- * changes.forEach( change => {
54
- * if ( change.type == 'insert' ) {
55
- * input = input.slice( 0, change.index ).concat( change.values, input.slice( change.index ) );
56
- * } else if ( change.type == 'delete' ) {
57
- * input = input.slice( 0, change.index ).concat( input.slice( change.index + change.howMany ) );
58
- * }
59
- * } );
63
+ * changes.forEach( change => {
64
+ * if ( change.type == 'insert' ) {
65
+ * input = input.slice( 0, change.index ).concat( change.values, input.slice( change.index ) );
66
+ * } else if ( change.type == 'delete' ) {
67
+ * input = input.slice( 0, change.index ).concat( input.slice( change.index + change.howMany ) );
68
+ * }
69
+ * } );
60
70
  *
61
- * // input equals output now
71
+ * // input equals output now
72
+ * ```
62
73
  *
63
74
  * By passing `true` as the fourth parameter (`atomicChanges`) the output of this function will become compatible with
64
75
  * the {@link module:utils/diff~diff `diff()`} function:
65
76
  *
66
- * fastDiff( '12a', '12xyza' );
67
- * // [ 'equal', 'equal', 'insert', 'insert', 'insert', 'equal' ]
77
+ * ```ts
78
+ * fastDiff( '12a', '12xyza', undefined, true );
79
+ * // [ 'equal', 'equal', 'insert', 'insert', 'insert', 'equal' ]
80
+ * ```
68
81
  *
69
82
  * The default output format of this function is compatible with the output format of
70
83
  * {@link module:utils/difftochanges~diffToChanges `diffToChanges()`}. The `diffToChanges()` input format is, in turn,
71
84
  * compatible with the output of {@link module:utils/diff~diff `diff()`}:
72
85
  *
73
- * const a = '1234';
74
- * const b = '12xyz34';
75
- *
76
- * // Both calls will return the same results (grouped changes format).
77
- * fastDiff( a, b );
78
- * diffToChanges( diff( a, b ) );
79
- *
80
- * // Again, both calls will return the same results (atomic changes format).
81
- * fastDiff( a, b, null, true );
82
- * diff( a, b );
83
- *
84
- *
85
- * @param {Array|String} a Input array or string.
86
- * @param {Array|String} b Input array or string.
87
- * @param {Function} [cmp] Optional function used to compare array values, by default `===` (strict equal operator) is used.
88
- * @param {Boolean} [atomicChanges=false] Whether an array of `inset|delete|equal` operations should
86
+ * ```ts
87
+ * const a = '1234';
88
+ * const b = '12xyz34';
89
+ *
90
+ * // Both calls will return the same results (grouped changes format).
91
+ * fastDiff( a, b );
92
+ * diffToChanges( diff( a, b ) );
93
+ *
94
+ * // Again, both calls will return the same results (atomic changes format).
95
+ * fastDiff( a, b, undefined, true );
96
+ * diff( a, b );
97
+ * ```
98
+ *
99
+ * @typeParam T The type of array elements.
100
+ * @typeParam AtomicChanges The type of `atomicChanges` parameter (selects the result type).
101
+ * @param a Input array or string.
102
+ * @param b Input array or string.
103
+ * @param cmp Optional function used to compare array values, by default `===` (strict equal operator) is used.
104
+ * @param atomicChanges Whether an array of `inset|delete|equal` operations should
89
105
  * be returned instead of changes set. This makes this function compatible with {@link module:utils/diff~diff `diff()`}.
90
- * @returns {Array} Array of changes.
106
+ * Defaults to `false`.
107
+ * @returns Array of changes. The elements are either {@link module:utils/diff~DiffResult} or {@link module:utils/difftochanges~Change},
108
+ * depending on `atomicChanges` parameter.
91
109
  */
92
- export default function fastDiff(a, b, cmp, atomicChanges = false) {
110
+ export default function fastDiff(a, b, cmp, atomicChanges) {
93
111
  // Set the comparator function.
94
112
  cmp = cmp || function (a, b) {
95
113
  return a === b;
@@ -105,24 +123,23 @@ export default function fastDiff(a, b, cmp, atomicChanges = false) {
105
123
  // Find first and last change.
106
124
  const changeIndexes = findChangeBoundaryIndexes(arrayA, arrayB, cmp);
107
125
  // Transform into changes array.
108
- return atomicChanges ? changeIndexesToAtomicChanges(changeIndexes, arrayB.length) : changeIndexesToChanges(arrayB, changeIndexes);
126
+ const result = atomicChanges ?
127
+ changeIndexesToAtomicChanges(changeIndexes, arrayB.length) :
128
+ changeIndexesToChanges(arrayB, changeIndexes);
129
+ return result;
109
130
  }
110
- // Finds position of the first and last change in the given arrays. For example:
111
- //
112
- // const indexes = findChangeBoundaryIndexes( [ '1', '2', '3', '4' ], [ '1', '3', '4', '2', '4' ] );
113
- // console.log( indexes ); // { firstIndex: 1, lastIndexOld: 3, lastIndexNew: 4 }
114
- //
115
- // The above indexes means that in the first array the modified part is `1[23]4` and in the second array it is `1[342]4`.
116
- // Based on such indexes, array with `insert`/`delete` operations which allows transforming first value into the second one
117
- // can be generated.
118
- //
119
- // @param {Array} arr1
120
- // @param {Array} arr2
121
- // @param {Function} cmp Comparator function.
122
- // @returns {Object}
123
- // @returns {Number} return.firstIndex Index of the first change in both values (always the same for both).
124
- // @returns {Number} result.lastIndexOld Index of the last common value in `arr1`.
125
- // @returns {Number} result.lastIndexNew Index of the last common value in `arr2`.
131
+ /**
132
+ * Finds position of the first and last change in the given arrays. For example:
133
+ *
134
+ * ```ts
135
+ * const indexes = findChangeBoundaryIndexes( [ '1', '2', '3', '4' ], [ '1', '3', '4', '2', '4' ] );
136
+ * console.log( indexes ); // { firstIndex: 1, lastIndexOld: 3, lastIndexNew: 4 }
137
+ * ```
138
+ *
139
+ * The above indexes means that in the first array the modified part is `1[23]4` and in the second array it is `1[342]4`.
140
+ * Based on such indexes, array with `insert`/`delete` operations which allows transforming first value into the second one
141
+ * can be generated.
142
+ */
126
143
  function findChangeBoundaryIndexes(arr1, arr2, cmp) {
127
144
  // Find the first difference between passed values.
128
145
  const firstIndex = findFirstDifferenceIndex(arr1, arr2, cmp);
@@ -150,12 +167,9 @@ function findChangeBoundaryIndexes(arr1, arr2, cmp) {
150
167
  const lastIndexNew = arr2.length - lastIndex;
151
168
  return { firstIndex, lastIndexOld, lastIndexNew };
152
169
  }
153
- // Returns a first index on which given arrays differ. If both arrays are the same, -1 is returned.
154
- //
155
- // @param {Array} arr1
156
- // @param {Array} arr2
157
- // @param {Function} cmp Comparator function.
158
- // @returns {Number}
170
+ /**
171
+ * Returns a first index on which given arrays differ. If both arrays are the same, -1 is returned.
172
+ */
159
173
  function findFirstDifferenceIndex(arr1, arr2, cmp) {
160
174
  for (let i = 0; i < Math.max(arr1.length, arr2.length); i++) {
161
175
  if (arr1[i] === undefined || arr2[i] === undefined || !cmp(arr1[i], arr2[i])) {
@@ -164,21 +178,24 @@ function findFirstDifferenceIndex(arr1, arr2, cmp) {
164
178
  }
165
179
  return -1; // Return -1 if arrays are equal.
166
180
  }
167
- // Returns a copy of the given array with `howMany` elements removed starting from the beginning and in reversed order.
168
- //
169
- // @param {Array} arr Array to be processed.
170
- // @param {Number} howMany How many elements from array beginning to remove.
171
- // @returns {Array} Shortened and reversed array.
181
+ /**
182
+ * Returns a copy of the given array with `howMany` elements removed starting from the beginning and in reversed order.
183
+ *
184
+ * @param arr Array to be processed.
185
+ * @param howMany How many elements from array beginning to remove.
186
+ * @returns Shortened and reversed array.
187
+ */
172
188
  function cutAndReverse(arr, howMany) {
173
189
  return arr.slice(howMany).reverse();
174
190
  }
175
- // Generates changes array based on change indexes from `findChangeBoundaryIndexes` function. This function will
176
- // generate array with 0 (no changes), 1 (deletion or insertion) or 2 records (insertion and deletion).
177
- //
178
- // @param {Array} newArray New array for which change indexes were calculated.
179
- // @param {Object} changeIndexes Change indexes object from `findChangeBoundaryIndexes` function.
180
- // @returns {Array.<module:utils/difftochanges~Change>} Array of changes compatible with
181
- // {@link module:utils/difftochanges~diffToChanges} format.
191
+ /**
192
+ * Generates changes array based on change indexes from `findChangeBoundaryIndexes` function. This function will
193
+ * generate array with 0 (no changes), 1 (deletion or insertion) or 2 records (insertion and deletion).
194
+ *
195
+ * @param newArray New array for which change indexes were calculated.
196
+ * @param changeIndexes Change indexes object from `findChangeBoundaryIndexes` function.
197
+ * @returns Array of changes compatible with {@link module:utils/difftochanges~diffToChanges} format.
198
+ */
182
199
  function changeIndexesToChanges(newArray, changeIndexes) {
183
200
  const result = [];
184
201
  const { firstIndex, lastIndexOld, lastIndexNew } = changeIndexes;
@@ -201,11 +218,13 @@ function changeIndexesToChanges(newArray, changeIndexes) {
201
218
  }
202
219
  return result;
203
220
  }
204
- // Generates array with set `equal|insert|delete` operations based on change indexes from `findChangeBoundaryIndexes` function.
205
- //
206
- // @param {Object} changeIndexes Change indexes object from `findChangeBoundaryIndexes` function.
207
- // @param {Number} newLength Length of the new array on which `findChangeBoundaryIndexes` calculated change indexes.
208
- // @returns {Array.<module:utils/diff~DiffResult>} Array of changes compatible with {@link module:utils/diff~diff} format.
221
+ /**
222
+ * Generates array with set `equal|insert|delete` operations based on change indexes from `findChangeBoundaryIndexes` function.
223
+ *
224
+ * @param changeIndexes Change indexes object from `findChangeBoundaryIndexes` function.
225
+ * @param newLength Length of the new array on which `findChangeBoundaryIndexes` calculated change indexes.
226
+ * @returns Array of changes compatible with {@link module:utils/diff~diff} format.
227
+ */
209
228
  function changeIndexesToAtomicChanges(changeIndexes, newLength) {
210
229
  const { firstIndex, lastIndexOld, lastIndexNew } = changeIndexes;
211
230
  // No changes.
package/src/first.js CHANGED
@@ -1,5 +1,5 @@
1
1
  /**
2
- * @license Copyright (c) 2003-2022, CKSource Holding sp. z o.o. All rights reserved.
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
5
  /**
@@ -7,9 +7,6 @@
7
7
  */
8
8
  /**
9
9
  * Returns first item of the given `iterator`.
10
- *
11
- * @param {Iterator.<*>} iterator
12
- * @returns {*}
13
10
  */
14
11
  export default function first(iterator) {
15
12
  const iteratorItem = iterator.next();
@@ -1,14 +1,13 @@
1
1
  /**
2
- * @license Copyright (c) 2003-2022, CKSource Holding sp. z o.o. All rights reserved.
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
5
  /* global setTimeout, clearTimeout */
6
- /* eslint-disable new-cap */
7
6
  /**
8
7
  * @module utils/focustracker
9
8
  */
10
9
  import DomEmitterMixin from './dom/emittermixin';
11
- import { Observable } from './observablemixin';
10
+ import ObservableMixin from './observablemixin';
12
11
  import CKEditorError from './ckeditorerror';
13
12
  /**
14
13
  * Allows observing a group of `Element`s whether at least one of them is focused.
@@ -21,22 +20,23 @@ import CKEditorError from './ckeditorerror';
21
20
  * (have e.g. `tabindex="-1"`).
22
21
  *
23
22
  * Check out the {@glink framework/guides/deep-dive/ui/focus-tracking "Deep dive into focus tracking" guide} to learn more.
24
- *
25
- * @mixes module:utils/dom/emittermixin~EmitterMixin
26
- * @mixes module:utils/observablemixin~ObservableMixin
27
23
  */
28
- export default class FocusTracker extends DomEmitterMixin(Observable) {
24
+ export default class FocusTracker extends DomEmitterMixin(ObservableMixin()) {
29
25
  constructor() {
30
26
  super();
31
- this.set('isFocused', false);
32
- this.set('focusedElement', null);
27
+ /**
28
+ * List of registered elements.
29
+ */
33
30
  this._elements = new Set();
31
+ /**
32
+ * Event loop timeout.
33
+ */
34
34
  this._nextEventLoopTimeout = null;
35
+ this.set('isFocused', false);
36
+ this.set('focusedElement', null);
35
37
  }
36
38
  /**
37
39
  * Starts tracking the specified element.
38
- *
39
- * @param {Element} element
40
40
  */
41
41
  add(element) {
42
42
  if (this._elements.has(element)) {
@@ -53,8 +53,6 @@ export default class FocusTracker extends DomEmitterMixin(Observable) {
53
53
  }
54
54
  /**
55
55
  * Stops tracking the specified element and stops listening on this element.
56
- *
57
- * @param {Element} element
58
56
  */
59
57
  remove(element) {
60
58
  if (element === this.focusedElement) {
@@ -74,10 +72,7 @@ export default class FocusTracker extends DomEmitterMixin(Observable) {
74
72
  this.stopListening();
75
73
  }
76
74
  /**
77
- * Stores currently focused element and set {#isFocused} as `true`.
78
- *
79
- * @private
80
- * @param {Element} element Element which has been focused.
75
+ * Stores currently focused element and set {@link #isFocused} as `true`.
81
76
  */
82
77
  _focus(element) {
83
78
  clearTimeout(this._nextEventLoopTimeout);
@@ -87,9 +82,6 @@ export default class FocusTracker extends DomEmitterMixin(Observable) {
87
82
  /**
88
83
  * Clears currently focused element and set {@link #isFocused} as `false`.
89
84
  * This method uses `setTimeout` to change order of fires `blur` and `focus` events.
90
- *
91
- * @private
92
- * @fires blur
93
85
  */
94
86
  _blur() {
95
87
  clearTimeout(this._nextEventLoopTimeout);
package/src/index.js CHANGED
@@ -1,5 +1,5 @@
1
1
  /**
2
- * @license Copyright (c) 2003-2022, CKSource Holding sp. z o.o. All rights reserved.
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
5
  /**
@@ -7,20 +7,36 @@
7
7
  */
8
8
  export { default as env } from './env';
9
9
  export { default as diff } from './diff';
10
+ export { default as fastDiff } from './fastdiff';
10
11
  export { default as mix } from './mix';
11
12
  export { default as EmitterMixin } from './emittermixin';
13
+ export { default as EventInfo } from './eventinfo';
12
14
  export { default as ObservableMixin } from './observablemixin';
13
15
  export { default as CKEditorError, logError, logWarning } from './ckeditorerror';
14
16
  export { default as ElementReplacer } from './elementreplacer';
17
+ export { default as count } from './count';
18
+ export { default as compareArrays } from './comparearrays';
15
19
  export { default as createElement } from './dom/createelement';
20
+ export { default as Config } from './config';
21
+ export { default as isIterable } from './isiterable';
16
22
  export { default as DomEmitterMixin } from './dom/emittermixin';
23
+ export { default as findClosestScrollableAncestor } from './dom/findclosestscrollableancestor';
17
24
  export { default as global } from './dom/global';
25
+ export { default as getAncestors } from './dom/getancestors';
18
26
  export { default as getDataFromElement } from './dom/getdatafromelement';
27
+ export { default as isText } from './dom/istext';
19
28
  export { default as Rect } from './dom/rect';
20
29
  export { default as ResizeObserver } from './dom/resizeobserver';
21
30
  export { default as setDataInElement } from './dom/setdatainelement';
22
31
  export { default as toUnit } from './dom/tounit';
32
+ export { default as indexOf } from './dom/indexof';
33
+ export { default as insertAt } from './dom/insertat';
34
+ export { default as isComment } from './dom/iscomment';
35
+ export { default as isNode } from './dom/isnode';
36
+ export { default as isRange } from './dom/isrange';
23
37
  export { default as isVisible } from './dom/isvisible';
38
+ export { getOptimalPosition } from './dom/position';
39
+ export { default as remove } from './dom/remove';
24
40
  export * from './dom/scroll';
25
41
  export * from './keyboard';
26
42
  export * from './language';
@@ -33,5 +49,7 @@ export { default as toArray } from './toarray';
33
49
  export { default as toMap } from './tomap';
34
50
  export { default as priorities } from './priorities';
35
51
  export { default as insertToPriorityArray } from './inserttopriorityarray';
52
+ export { default as spliceArray } from './splicearray';
36
53
  export { default as uid } from './uid';
54
+ export * from './unicode';
37
55
  export { default as version } from './version';
@@ -1,13 +1,13 @@
1
1
  /**
2
- * @license Copyright (c) 2003-2022, CKSource Holding sp. z o.o. All rights reserved.
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
5
  import priorities from './priorities';
6
6
  /**
7
7
  * Inserts any object with priority at correct index by priority so registered objects are always sorted from highest to lowest priority.
8
8
  *
9
- * @param {Array.<module:utils/inserttopriorityarray~ObjectWithPriority>} objects Array of objects with priority to insert object to.
10
- * @param {module:utils/inserttopriorityarray~ObjectWithPriority} objectToInsert Object with `priority` property.
9
+ * @param objects Array of objects with priority to insert object to.
10
+ * @param objectToInsert Object with `priority` property.
11
11
  */
12
12
  export default function insertToPriorityArray(objects, objectToInsert) {
13
13
  const priority = priorities.get(objectToInsert.priority);