@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.
- package/LICENSE.md +1 -1
- package/package.json +5 -5
- package/src/areconnectedthroughproperties.js +7 -9
- package/src/ckeditorerror.js +52 -71
- package/src/collection.js +108 -150
- package/src/comparearrays.js +11 -9
- package/src/config.js +30 -84
- package/src/count.js +6 -4
- package/src/diff.js +8 -6
- package/src/difftochanges.js +18 -15
- package/src/dom/createelement.js +12 -10
- package/src/dom/emittermixin.js +44 -85
- package/src/dom/findclosestscrollableancestor.js +30 -0
- package/src/dom/getancestors.js +3 -3
- package/src/dom/getborderwidths.js +3 -3
- package/src/dom/getcommonancestor.js +4 -4
- package/src/dom/getdatafromelement.js +3 -3
- package/src/dom/getpositionedancestor.js +2 -3
- package/src/dom/global.js +13 -15
- package/src/dom/indexof.js +3 -3
- package/src/dom/insertat.js +4 -4
- package/src/dom/iscomment.js +1 -4
- package/src/dom/isnode.js +1 -4
- package/src/dom/isrange.js +1 -4
- package/src/dom/istext.js +1 -4
- package/src/dom/isvisible.js +1 -4
- package/src/dom/iswindow.js +1 -4
- package/src/dom/position.js +111 -134
- package/src/dom/rect.js +43 -53
- package/src/dom/remove.js +2 -2
- package/src/dom/resizeobserver.js +11 -36
- package/src/dom/scroll.js +86 -92
- package/src/dom/setdatainelement.js +3 -3
- package/src/dom/tounit.js +2 -11
- package/src/elementreplacer.js +3 -3
- package/src/emittermixin.js +49 -49
- package/src/env.js +15 -76
- package/src/eventinfo.js +3 -3
- package/src/fastdiff.js +116 -97
- package/src/first.js +1 -4
- package/src/focustracker.js +12 -20
- package/src/index.js +19 -1
- package/src/inserttopriorityarray.js +3 -3
- package/src/isiterable.js +3 -3
- package/src/keyboard.js +21 -22
- package/src/keystrokehandler.js +27 -25
- package/src/language.js +2 -3
- package/src/locale.js +12 -15
- package/src/mapsequal.js +5 -5
- package/src/mix.js +16 -14
- package/src/nth.js +1 -5
- package/src/objecttomap.js +7 -5
- package/src/observablemixin.js +127 -151
- package/src/priorities.js +1 -10
- package/src/splicearray.js +13 -12
- package/src/spy.js +2 -2
- package/src/toarray.js +1 -1
- package/src/tomap.js +8 -6
- package/src/translation-service.js +71 -53
- package/src/uid.js +6 -4
- package/src/unicode.js +10 -16
- package/src/version.js +33 -27
package/src/env.js
CHANGED
|
@@ -1,5 +1,5 @@
|
|
|
1
1
|
/**
|
|
2
|
-
* @license Copyright (c) 2003-
|
|
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
|
|
102
|
-
* @returns
|
|
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
|
|
111
|
-
* @returns
|
|
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
|
|
120
|
-
* @returns
|
|
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
|
|
129
|
-
* @returns
|
|
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
|
|
138
|
-
* @returns
|
|
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
|
|
148
|
-
* @returns
|
|
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
|
|
157
|
-
* @returns
|
|
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-
|
|
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
|
|
16
|
-
* @param
|
|
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-
|
|
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
|
-
*
|
|
9
|
-
*
|
|
11
|
+
* ```ts
|
|
12
|
+
* fastDiff( '12a', '12xyza' );
|
|
13
|
+
* // [ { index: 2, type: 'insert', values: [ 'x', 'y', 'z' ] } ]
|
|
10
14
|
*
|
|
11
|
-
*
|
|
12
|
-
*
|
|
15
|
+
* fastDiff( '12a', '12aa' );
|
|
16
|
+
* // [ { index: 3, type: 'insert', values: [ 'a' ] } ]
|
|
13
17
|
*
|
|
14
|
-
*
|
|
15
|
-
*
|
|
18
|
+
* fastDiff( '12xyza', '12a' );
|
|
19
|
+
* // [ { index: 2, type: 'delete', howMany: 3 } ]
|
|
16
20
|
*
|
|
17
|
-
*
|
|
18
|
-
*
|
|
21
|
+
* fastDiff( [ '1', '2', 'a', 'a' ], [ '1', '2', 'a' ] );
|
|
22
|
+
* // [ { index: 3, type: 'delete', howMany: 1 } ]
|
|
19
23
|
*
|
|
20
|
-
*
|
|
21
|
-
*
|
|
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
|
-
*
|
|
27
|
-
*
|
|
28
|
-
*
|
|
29
|
-
*
|
|
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
|
-
*
|
|
34
|
-
*
|
|
35
|
-
*
|
|
40
|
+
* ```ts
|
|
41
|
+
* let input = '12abc3';
|
|
42
|
+
* const output = '2ab';
|
|
43
|
+
* const changes = fastDiff( input, output );
|
|
36
44
|
*
|
|
37
|
-
*
|
|
38
|
-
*
|
|
39
|
-
*
|
|
40
|
-
*
|
|
41
|
-
*
|
|
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
|
-
*
|
|
53
|
+
* // input equals output now
|
|
54
|
+
* ```
|
|
46
55
|
*
|
|
47
56
|
* or in case of arrays:
|
|
48
57
|
*
|
|
49
|
-
*
|
|
50
|
-
*
|
|
51
|
-
*
|
|
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
|
-
*
|
|
54
|
-
*
|
|
55
|
-
*
|
|
56
|
-
*
|
|
57
|
-
*
|
|
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
|
-
*
|
|
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
|
-
*
|
|
67
|
-
*
|
|
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
|
-
*
|
|
74
|
-
*
|
|
75
|
-
*
|
|
76
|
-
*
|
|
77
|
-
*
|
|
78
|
-
*
|
|
79
|
-
*
|
|
80
|
-
*
|
|
81
|
-
*
|
|
82
|
-
*
|
|
83
|
-
*
|
|
84
|
-
*
|
|
85
|
-
*
|
|
86
|
-
* @
|
|
87
|
-
* @
|
|
88
|
-
* @param
|
|
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
|
-
*
|
|
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
|
|
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
|
-
|
|
126
|
+
const result = atomicChanges ?
|
|
127
|
+
changeIndexesToAtomicChanges(changeIndexes, arrayB.length) :
|
|
128
|
+
changeIndexesToChanges(arrayB, changeIndexes);
|
|
129
|
+
return result;
|
|
109
130
|
}
|
|
110
|
-
|
|
111
|
-
|
|
112
|
-
|
|
113
|
-
|
|
114
|
-
|
|
115
|
-
|
|
116
|
-
|
|
117
|
-
|
|
118
|
-
|
|
119
|
-
|
|
120
|
-
|
|
121
|
-
|
|
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
|
-
|
|
154
|
-
|
|
155
|
-
|
|
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
|
-
|
|
168
|
-
|
|
169
|
-
|
|
170
|
-
|
|
171
|
-
|
|
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
|
-
|
|
176
|
-
|
|
177
|
-
|
|
178
|
-
|
|
179
|
-
|
|
180
|
-
|
|
181
|
-
|
|
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
|
-
|
|
205
|
-
|
|
206
|
-
|
|
207
|
-
|
|
208
|
-
|
|
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-
|
|
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();
|
package/src/focustracker.js
CHANGED
|
@@ -1,14 +1,13 @@
|
|
|
1
1
|
/**
|
|
2
|
-
* @license Copyright (c) 2003-
|
|
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
|
|
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(
|
|
24
|
+
export default class FocusTracker extends DomEmitterMixin(ObservableMixin()) {
|
|
29
25
|
constructor() {
|
|
30
26
|
super();
|
|
31
|
-
|
|
32
|
-
|
|
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-
|
|
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-
|
|
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
|
|
10
|
-
* @param
|
|
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);
|