@ckeditor/ckeditor5-utils 40.0.0 → 40.2.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/CHANGELOG.md +26 -26
- package/LICENSE.md +3 -3
- package/package.json +1 -1
- package/src/abortabledebounce.d.ts +17 -0
- package/src/abortabledebounce.js +22 -0
- package/src/areconnectedthroughproperties.d.ts +11 -11
- package/src/areconnectedthroughproperties.js +73 -73
- package/src/ckeditorerror.d.ts +123 -123
- package/src/ckeditorerror.js +176 -176
- package/src/collection.d.ts +433 -427
- package/src/collection.js +583 -575
- package/src/comparearrays.d.ts +30 -30
- package/src/comparearrays.js +47 -47
- package/src/config.d.ts +163 -163
- package/src/config.js +163 -162
- package/src/count.d.ts +18 -18
- package/src/count.js +24 -24
- package/src/delay.d.ts +19 -19
- package/src/delay.js +26 -26
- package/src/diff.d.ts +31 -31
- package/src/diff.js +115 -115
- package/src/difftochanges.d.ts +59 -59
- package/src/difftochanges.js +79 -79
- package/src/dom/createelement.d.ts +57 -57
- package/src/dom/createelement.js +40 -40
- package/src/dom/emittermixin.d.ts +142 -142
- package/src/dom/emittermixin.js +239 -239
- package/src/dom/findclosestscrollableancestor.d.ts +11 -11
- package/src/dom/findclosestscrollableancestor.js +31 -31
- package/src/dom/getancestors.d.ts +17 -17
- package/src/dom/getancestors.js +27 -27
- package/src/dom/getborderwidths.d.ts +24 -24
- package/src/dom/getborderwidths.js +24 -24
- package/src/dom/getcommonancestor.d.ts +12 -12
- package/src/dom/getcommonancestor.js +25 -25
- package/src/dom/getdatafromelement.d.ts +14 -14
- package/src/dom/getdatafromelement.js +20 -20
- package/src/dom/getpositionedancestor.d.ts +10 -10
- package/src/dom/getpositionedancestor.js +22 -22
- package/src/dom/global.d.ts +32 -32
- package/src/dom/global.js +35 -35
- package/src/dom/indexof.d.ts +14 -14
- package/src/dom/indexof.js +21 -21
- package/src/dom/insertat.d.ts +15 -15
- package/src/dom/insertat.js +17 -17
- package/src/dom/iscomment.d.ts +11 -11
- package/src/dom/iscomment.js +14 -14
- package/src/dom/isnode.d.ts +11 -11
- package/src/dom/isnode.js +21 -21
- package/src/dom/isrange.d.ts +11 -11
- package/src/dom/isrange.js +13 -13
- package/src/dom/istext.d.ts +11 -11
- package/src/dom/istext.js +13 -13
- package/src/dom/isvalidattributename.d.ts +10 -10
- package/src/dom/isvalidattributename.js +22 -22
- package/src/dom/isvisible.d.ts +18 -18
- package/src/dom/isvisible.js +20 -20
- package/src/dom/iswindow.d.ts +11 -11
- package/src/dom/iswindow.js +22 -22
- package/src/dom/position.d.ts +211 -211
- package/src/dom/position.js +313 -313
- package/src/dom/rect.d.ts +195 -195
- package/src/dom/rect.js +474 -474
- package/src/dom/remove.d.ts +13 -13
- package/src/dom/remove.js +18 -18
- package/src/dom/resizeobserver.d.ts +74 -74
- package/src/dom/resizeobserver.js +126 -126
- package/src/dom/scroll.d.ts +73 -73
- package/src/dom/scroll.js +383 -383
- package/src/dom/setdatainelement.d.ts +14 -14
- package/src/dom/setdatainelement.js +20 -20
- package/src/dom/tounit.d.ts +22 -22
- package/src/dom/tounit.js +16 -16
- package/src/elementreplacer.d.ts +31 -31
- package/src/elementreplacer.js +43 -43
- package/src/emittermixin.d.ts +312 -312
- package/src/emittermixin.js +453 -453
- package/src/env.d.ts +117 -117
- package/src/env.js +122 -122
- package/src/eventinfo.d.ts +58 -58
- package/src/eventinfo.js +26 -26
- package/src/fastdiff.d.ts +112 -112
- package/src/fastdiff.js +248 -248
- package/src/first.d.ts +11 -11
- package/src/first.js +17 -17
- package/src/focustracker.d.ts +75 -75
- package/src/focustracker.js +95 -95
- package/src/index.d.ts +64 -61
- package/src/index.js +63 -60
- package/src/inserttopriorityarray.d.ts +30 -30
- package/src/inserttopriorityarray.js +21 -21
- package/src/isiterable.d.ts +14 -14
- package/src/isiterable.js +16 -16
- package/src/keyboard.d.ts +126 -126
- package/src/keyboard.js +221 -221
- package/src/keystrokehandler.d.ts +87 -87
- package/src/keystrokehandler.js +122 -122
- package/src/language.d.ts +17 -17
- package/src/language.js +19 -19
- package/src/locale.d.ts +120 -120
- package/src/locale.js +76 -76
- package/src/mapsequal.d.ts +15 -15
- package/src/mapsequal.js +27 -27
- package/src/mix.d.ts +85 -85
- package/src/mix.js +50 -50
- package/src/nth.d.ts +16 -16
- package/src/nth.js +24 -24
- package/src/objecttomap.d.ts +23 -23
- package/src/objecttomap.js +27 -27
- package/src/observablemixin.d.ts +560 -560
- package/src/observablemixin.js +580 -580
- package/src/priorities.d.ts +33 -33
- package/src/priorities.js +23 -23
- package/src/retry.d.ts +33 -0
- package/src/retry.js +47 -0
- package/src/splicearray.d.ts +26 -26
- package/src/splicearray.js +40 -40
- package/src/spy.d.ts +21 -21
- package/src/spy.js +22 -22
- package/src/toarray.d.ts +25 -25
- package/src/toarray.js +7 -7
- package/src/tomap.d.ts +19 -19
- package/src/tomap.js +29 -29
- package/src/translation-service.d.ts +168 -168
- package/src/translation-service.js +198 -198
- package/src/uid.d.ts +15 -15
- package/src/uid.js +57 -57
- package/src/unicode.d.ts +54 -54
- package/src/unicode.js +85 -85
- package/src/verifylicense.d.ts +15 -15
- package/src/verifylicense.js +87 -87
- package/src/version.d.ts +10 -10
- package/src/version.js +153 -153
- package/src/wait.d.ts +16 -0
- package/src/wait.js +29 -0
package/src/fastdiff.d.ts
CHANGED
|
@@ -1,112 +1,112 @@
|
|
|
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
|
-
import type { DiffResult } from './diff';
|
|
6
|
-
import type { Change } from './difftochanges';
|
|
7
|
-
/**
|
|
8
|
-
* @module utils/fastdiff
|
|
9
|
-
*/
|
|
10
|
-
/**
|
|
11
|
-
* Finds positions of the first and last change in the given string/array and generates a set of changes:
|
|
12
|
-
*
|
|
13
|
-
* ```ts
|
|
14
|
-
* fastDiff( '12a', '12xyza' );
|
|
15
|
-
* // [ { index: 2, type: 'insert', values: [ 'x', 'y', 'z' ] } ]
|
|
16
|
-
*
|
|
17
|
-
* fastDiff( '12a', '12aa' );
|
|
18
|
-
* // [ { index: 3, type: 'insert', values: [ 'a' ] } ]
|
|
19
|
-
*
|
|
20
|
-
* fastDiff( '12xyza', '12a' );
|
|
21
|
-
* // [ { index: 2, type: 'delete', howMany: 3 } ]
|
|
22
|
-
*
|
|
23
|
-
* fastDiff( [ '1', '2', 'a', 'a' ], [ '1', '2', 'a' ] );
|
|
24
|
-
* // [ { index: 3, type: 'delete', howMany: 1 } ]
|
|
25
|
-
*
|
|
26
|
-
* fastDiff( [ '1', '2', 'a', 'b', 'c', '3' ], [ '2', 'a', 'b' ] );
|
|
27
|
-
* // [ { index: 0, type: 'insert', values: [ '2', 'a', 'b' ] }, { index: 3, type: 'delete', howMany: 6 } ]
|
|
28
|
-
* ```
|
|
29
|
-
*
|
|
30
|
-
* Passed arrays can contain any type of data, however to compare them correctly custom comparator function
|
|
31
|
-
* should be passed as a third parameter:
|
|
32
|
-
*
|
|
33
|
-
* ```ts
|
|
34
|
-
* fastDiff( [ { value: 1 }, { value: 2 } ], [ { value: 1 }, { value: 3 } ], ( a, b ) => {
|
|
35
|
-
* return a.value === b.value;
|
|
36
|
-
* } );
|
|
37
|
-
* // [ { index: 1, type: 'insert', values: [ { value: 3 } ] }, { index: 2, type: 'delete', howMany: 1 } ]
|
|
38
|
-
* ```
|
|
39
|
-
*
|
|
40
|
-
* The resulted set of changes can be applied to the input in order to transform it into the output, for example:
|
|
41
|
-
*
|
|
42
|
-
* ```ts
|
|
43
|
-
* let input = '12abc3';
|
|
44
|
-
* const output = '2ab';
|
|
45
|
-
* const changes = fastDiff( input, output );
|
|
46
|
-
*
|
|
47
|
-
* changes.forEach( change => {
|
|
48
|
-
* if ( change.type == 'insert' ) {
|
|
49
|
-
* input = input.substring( 0, change.index ) + change.values.join( '' ) + input.substring( change.index );
|
|
50
|
-
* } else if ( change.type == 'delete' ) {
|
|
51
|
-
* input = input.substring( 0, change.index ) + input.substring( change.index + change.howMany );
|
|
52
|
-
* }
|
|
53
|
-
* } );
|
|
54
|
-
*
|
|
55
|
-
* // input equals output now
|
|
56
|
-
* ```
|
|
57
|
-
*
|
|
58
|
-
* or in case of arrays:
|
|
59
|
-
*
|
|
60
|
-
* ```ts
|
|
61
|
-
* let input = [ '1', '2', 'a', 'b', 'c', '3' ];
|
|
62
|
-
* const output = [ '2', 'a', 'b' ];
|
|
63
|
-
* const changes = fastDiff( input, output );
|
|
64
|
-
*
|
|
65
|
-
* changes.forEach( change => {
|
|
66
|
-
* if ( change.type == 'insert' ) {
|
|
67
|
-
* input = input.slice( 0, change.index ).concat( change.values, input.slice( change.index ) );
|
|
68
|
-
* } else if ( change.type == 'delete' ) {
|
|
69
|
-
* input = input.slice( 0, change.index ).concat( input.slice( change.index + change.howMany ) );
|
|
70
|
-
* }
|
|
71
|
-
* } );
|
|
72
|
-
*
|
|
73
|
-
* // input equals output now
|
|
74
|
-
* ```
|
|
75
|
-
*
|
|
76
|
-
* By passing `true` as the fourth parameter (`atomicChanges`) the output of this function will become compatible with
|
|
77
|
-
* the {@link module:utils/diff~diff `diff()`} function:
|
|
78
|
-
*
|
|
79
|
-
* ```ts
|
|
80
|
-
* fastDiff( '12a', '12xyza', undefined, true );
|
|
81
|
-
* // [ 'equal', 'equal', 'insert', 'insert', 'insert', 'equal' ]
|
|
82
|
-
* ```
|
|
83
|
-
*
|
|
84
|
-
* The default output format of this function is compatible with the output format of
|
|
85
|
-
* {@link module:utils/difftochanges~diffToChanges `diffToChanges()`}. The `diffToChanges()` input format is, in turn,
|
|
86
|
-
* compatible with the output of {@link module:utils/diff~diff `diff()`}:
|
|
87
|
-
*
|
|
88
|
-
* ```ts
|
|
89
|
-
* const a = '1234';
|
|
90
|
-
* const b = '12xyz34';
|
|
91
|
-
*
|
|
92
|
-
* // Both calls will return the same results (grouped changes format).
|
|
93
|
-
* fastDiff( a, b );
|
|
94
|
-
* diffToChanges( diff( a, b ) );
|
|
95
|
-
*
|
|
96
|
-
* // Again, both calls will return the same results (atomic changes format).
|
|
97
|
-
* fastDiff( a, b, undefined, true );
|
|
98
|
-
* diff( a, b );
|
|
99
|
-
* ```
|
|
100
|
-
*
|
|
101
|
-
* @typeParam T The type of array elements.
|
|
102
|
-
* @typeParam AtomicChanges The type of `atomicChanges` parameter (selects the result type).
|
|
103
|
-
* @param a Input array or string.
|
|
104
|
-
* @param b Input array or string.
|
|
105
|
-
* @param cmp Optional function used to compare array values, by default `===` (strict equal operator) is used.
|
|
106
|
-
* @param atomicChanges Whether an array of `inset|delete|equal` operations should
|
|
107
|
-
* be returned instead of changes set. This makes this function compatible with {@link module:utils/diff~diff `diff()`}.
|
|
108
|
-
* Defaults to `false`.
|
|
109
|
-
* @returns Array of changes. The elements are either {@link module:utils/diff~DiffResult} or {@link module:utils/difftochanges~Change},
|
|
110
|
-
* depending on `atomicChanges` parameter.
|
|
111
|
-
*/
|
|
112
|
-
export default function fastDiff<T, AtomicChanges extends boolean = false>(a: ArrayLike<T>, b: ArrayLike<T>, cmp?: (a: T, b: T) => boolean, atomicChanges?: AtomicChanges): Array<AtomicChanges extends true ? DiffResult : Change<T>>;
|
|
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
|
+
import type { DiffResult } from './diff';
|
|
6
|
+
import type { Change } from './difftochanges';
|
|
7
|
+
/**
|
|
8
|
+
* @module utils/fastdiff
|
|
9
|
+
*/
|
|
10
|
+
/**
|
|
11
|
+
* Finds positions of the first and last change in the given string/array and generates a set of changes:
|
|
12
|
+
*
|
|
13
|
+
* ```ts
|
|
14
|
+
* fastDiff( '12a', '12xyza' );
|
|
15
|
+
* // [ { index: 2, type: 'insert', values: [ 'x', 'y', 'z' ] } ]
|
|
16
|
+
*
|
|
17
|
+
* fastDiff( '12a', '12aa' );
|
|
18
|
+
* // [ { index: 3, type: 'insert', values: [ 'a' ] } ]
|
|
19
|
+
*
|
|
20
|
+
* fastDiff( '12xyza', '12a' );
|
|
21
|
+
* // [ { index: 2, type: 'delete', howMany: 3 } ]
|
|
22
|
+
*
|
|
23
|
+
* fastDiff( [ '1', '2', 'a', 'a' ], [ '1', '2', 'a' ] );
|
|
24
|
+
* // [ { index: 3, type: 'delete', howMany: 1 } ]
|
|
25
|
+
*
|
|
26
|
+
* fastDiff( [ '1', '2', 'a', 'b', 'c', '3' ], [ '2', 'a', 'b' ] );
|
|
27
|
+
* // [ { index: 0, type: 'insert', values: [ '2', 'a', 'b' ] }, { index: 3, type: 'delete', howMany: 6 } ]
|
|
28
|
+
* ```
|
|
29
|
+
*
|
|
30
|
+
* Passed arrays can contain any type of data, however to compare them correctly custom comparator function
|
|
31
|
+
* should be passed as a third parameter:
|
|
32
|
+
*
|
|
33
|
+
* ```ts
|
|
34
|
+
* fastDiff( [ { value: 1 }, { value: 2 } ], [ { value: 1 }, { value: 3 } ], ( a, b ) => {
|
|
35
|
+
* return a.value === b.value;
|
|
36
|
+
* } );
|
|
37
|
+
* // [ { index: 1, type: 'insert', values: [ { value: 3 } ] }, { index: 2, type: 'delete', howMany: 1 } ]
|
|
38
|
+
* ```
|
|
39
|
+
*
|
|
40
|
+
* The resulted set of changes can be applied to the input in order to transform it into the output, for example:
|
|
41
|
+
*
|
|
42
|
+
* ```ts
|
|
43
|
+
* let input = '12abc3';
|
|
44
|
+
* const output = '2ab';
|
|
45
|
+
* const changes = fastDiff( input, output );
|
|
46
|
+
*
|
|
47
|
+
* changes.forEach( change => {
|
|
48
|
+
* if ( change.type == 'insert' ) {
|
|
49
|
+
* input = input.substring( 0, change.index ) + change.values.join( '' ) + input.substring( change.index );
|
|
50
|
+
* } else if ( change.type == 'delete' ) {
|
|
51
|
+
* input = input.substring( 0, change.index ) + input.substring( change.index + change.howMany );
|
|
52
|
+
* }
|
|
53
|
+
* } );
|
|
54
|
+
*
|
|
55
|
+
* // input equals output now
|
|
56
|
+
* ```
|
|
57
|
+
*
|
|
58
|
+
* or in case of arrays:
|
|
59
|
+
*
|
|
60
|
+
* ```ts
|
|
61
|
+
* let input = [ '1', '2', 'a', 'b', 'c', '3' ];
|
|
62
|
+
* const output = [ '2', 'a', 'b' ];
|
|
63
|
+
* const changes = fastDiff( input, output );
|
|
64
|
+
*
|
|
65
|
+
* changes.forEach( change => {
|
|
66
|
+
* if ( change.type == 'insert' ) {
|
|
67
|
+
* input = input.slice( 0, change.index ).concat( change.values, input.slice( change.index ) );
|
|
68
|
+
* } else if ( change.type == 'delete' ) {
|
|
69
|
+
* input = input.slice( 0, change.index ).concat( input.slice( change.index + change.howMany ) );
|
|
70
|
+
* }
|
|
71
|
+
* } );
|
|
72
|
+
*
|
|
73
|
+
* // input equals output now
|
|
74
|
+
* ```
|
|
75
|
+
*
|
|
76
|
+
* By passing `true` as the fourth parameter (`atomicChanges`) the output of this function will become compatible with
|
|
77
|
+
* the {@link module:utils/diff~diff `diff()`} function:
|
|
78
|
+
*
|
|
79
|
+
* ```ts
|
|
80
|
+
* fastDiff( '12a', '12xyza', undefined, true );
|
|
81
|
+
* // [ 'equal', 'equal', 'insert', 'insert', 'insert', 'equal' ]
|
|
82
|
+
* ```
|
|
83
|
+
*
|
|
84
|
+
* The default output format of this function is compatible with the output format of
|
|
85
|
+
* {@link module:utils/difftochanges~diffToChanges `diffToChanges()`}. The `diffToChanges()` input format is, in turn,
|
|
86
|
+
* compatible with the output of {@link module:utils/diff~diff `diff()`}:
|
|
87
|
+
*
|
|
88
|
+
* ```ts
|
|
89
|
+
* const a = '1234';
|
|
90
|
+
* const b = '12xyz34';
|
|
91
|
+
*
|
|
92
|
+
* // Both calls will return the same results (grouped changes format).
|
|
93
|
+
* fastDiff( a, b );
|
|
94
|
+
* diffToChanges( diff( a, b ) );
|
|
95
|
+
*
|
|
96
|
+
* // Again, both calls will return the same results (atomic changes format).
|
|
97
|
+
* fastDiff( a, b, undefined, true );
|
|
98
|
+
* diff( a, b );
|
|
99
|
+
* ```
|
|
100
|
+
*
|
|
101
|
+
* @typeParam T The type of array elements.
|
|
102
|
+
* @typeParam AtomicChanges The type of `atomicChanges` parameter (selects the result type).
|
|
103
|
+
* @param a Input array or string.
|
|
104
|
+
* @param b Input array or string.
|
|
105
|
+
* @param cmp Optional function used to compare array values, by default `===` (strict equal operator) is used.
|
|
106
|
+
* @param atomicChanges Whether an array of `inset|delete|equal` operations should
|
|
107
|
+
* be returned instead of changes set. This makes this function compatible with {@link module:utils/diff~diff `diff()`}.
|
|
108
|
+
* Defaults to `false`.
|
|
109
|
+
* @returns Array of changes. The elements are either {@link module:utils/diff~DiffResult} or {@link module:utils/difftochanges~Change},
|
|
110
|
+
* depending on `atomicChanges` parameter.
|
|
111
|
+
*/
|
|
112
|
+
export default function fastDiff<T, AtomicChanges extends boolean = false>(a: ArrayLike<T>, b: ArrayLike<T>, cmp?: (a: T, b: T) => boolean, atomicChanges?: AtomicChanges): Array<AtomicChanges extends true ? DiffResult : Change<T>>;
|