@ckeditor/ckeditor5-utils 34.2.0 → 35.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 (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 +0 -92
  5. package/src/ckeditorerror.js +0 -217
  6. package/src/collection.js +0 -785
  7. package/src/comparearrays.js +0 -51
  8. package/src/config.js +0 -246
  9. package/src/count.js +0 -26
  10. package/src/diff.js +0 -138
  11. package/src/difftochanges.js +0 -86
  12. package/src/dom/createelement.js +0 -49
  13. package/src/dom/emittermixin.js +0 -341
  14. package/src/dom/getancestors.js +0 -31
  15. package/src/dom/getborderwidths.js +0 -27
  16. package/src/dom/getcommonancestor.js +0 -31
  17. package/src/dom/getdatafromelement.js +0 -24
  18. package/src/dom/getpositionedancestor.js +0 -28
  19. package/src/dom/global.js +0 -26
  20. package/src/dom/indexof.js +0 -25
  21. package/src/dom/insertat.js +0 -19
  22. package/src/dom/iscomment.js +0 -20
  23. package/src/dom/isnode.js +0 -26
  24. package/src/dom/isrange.js +0 -18
  25. package/src/dom/istext.js +0 -18
  26. package/src/dom/isvisible.js +0 -25
  27. package/src/dom/iswindow.js +0 -30
  28. package/src/dom/position.js +0 -518
  29. package/src/dom/rect.js +0 -443
  30. package/src/dom/remove.js +0 -21
  31. package/src/dom/resizeobserver.js +0 -378
  32. package/src/dom/scroll.js +0 -302
  33. package/src/dom/setdatainelement.js +0 -24
  34. package/src/dom/tounit.js +0 -27
  35. package/src/elementreplacer.js +0 -57
  36. package/src/emittermixin.js +0 -719
  37. package/src/env.js +0 -190
  38. package/src/eventinfo.js +0 -79
  39. package/src/fastdiff.js +0 -261
  40. package/src/first.js +0 -24
  41. package/src/focustracker.js +0 -157
  42. package/src/index.js +0 -45
  43. package/src/inserttopriorityarray.js +0 -42
  44. package/src/isiterable.js +0 -18
  45. package/src/keyboard.js +0 -301
  46. package/src/keystrokehandler.js +0 -130
  47. package/src/language.js +0 -26
  48. package/src/locale.js +0 -176
  49. package/src/mapsequal.js +0 -32
  50. package/src/mix.js +0 -47
  51. package/src/nth.js +0 -31
  52. package/src/objecttomap.js +0 -29
  53. package/src/observablemixin.js +0 -908
  54. package/src/priorities.js +0 -44
  55. package/src/spy.js +0 -25
  56. package/src/toarray.js +0 -18
  57. package/src/tomap.js +0 -29
  58. package/src/translation-service.js +0 -216
  59. package/src/uid.js +0 -59
  60. package/src/unicode.js +0 -106
  61. package/src/version.js +0 -157
@@ -1,51 +0,0 @@
1
- /**
2
- * @license Copyright (c) 2003-2022, CKSource Holding sp. z o.o. All rights reserved.
3
- * For licensing, see LICENSE.md or https://ckeditor.com/legal/ckeditor-oss-license
4
- */
5
-
6
- /**
7
- * @module utils/comparearrays
8
- */
9
-
10
- /**
11
- * Compares how given arrays relate to each other. One array can be: same as another array, prefix of another array
12
- * or completely different. If arrays are different, first index at which they differ is returned. Otherwise,
13
- * a flag specifying the relation is returned. Flags are negative numbers, so whenever a number >= 0 is returned
14
- * it means that arrays differ.
15
- *
16
- * compareArrays( [ 0, 2 ], [ 0, 2 ] ); // 'same'
17
- * compareArrays( [ 0, 2 ], [ 0, 2, 1 ] ); // 'prefix'
18
- * compareArrays( [ 0, 2 ], [ 0 ] ); // 'extension'
19
- * compareArrays( [ 0, 2 ], [ 1, 2 ] ); // 0
20
- * compareArrays( [ 0, 2 ], [ 0, 1 ] ); // 1
21
- *
22
- * @param {Array} a Array that is compared.
23
- * @param {Array} b Array to compare with.
24
- * @returns {module:utils/comparearrays~ArrayRelation} How array `a` is related to `b`.
25
- */
26
- export default function compareArrays( a, b ) {
27
- const minLen = Math.min( a.length, b.length );
28
-
29
- for ( let i = 0; i < minLen; i++ ) {
30
- if ( a[ i ] != b[ i ] ) {
31
- // The arrays are different.
32
- return i;
33
- }
34
- }
35
-
36
- // Both arrays were same at all points.
37
- if ( a.length == b.length ) {
38
- // If their length is also same, they are the same.
39
- return 'same';
40
- } else if ( a.length < b.length ) {
41
- // Compared array is shorter so it is a prefix of the other array.
42
- return 'prefix';
43
- } else {
44
- // Compared array is longer so it is an extension of the other array.
45
- return 'extension';
46
- }
47
- }
48
-
49
- /**
50
- * @typedef {'extension'|'same'|'prefix'} module:utils/comparearrays~ArrayRelation
51
- */
package/src/config.js DELETED
@@ -1,246 +0,0 @@
1
- /**
2
- * @license Copyright (c) 2003-2022, CKSource Holding sp. z o.o. All rights reserved.
3
- * For licensing, see LICENSE.md or https://ckeditor.com/legal/ckeditor-oss-license
4
- */
5
-
6
- /**
7
- * @module utils/config
8
- */
9
-
10
- import { isPlainObject, isElement, cloneDeepWith } from 'lodash-es';
11
-
12
- /**
13
- * Handles a configuration dictionary.
14
- */
15
- export default class Config {
16
- /**
17
- * Creates an instance of the {@link ~Config} class.
18
- *
19
- * @param {Object} [configurations] The initial configurations to be set. Usually, provided by the user.
20
- * @param {Object} [defaultConfigurations] The default configurations. Usually, provided by the system.
21
- */
22
- constructor( configurations, defaultConfigurations ) {
23
- /**
24
- * Store for the whole configuration.
25
- *
26
- * @private
27
- * @member {Object}
28
- */
29
- this._config = {};
30
-
31
- // Set default configuration.
32
- if ( defaultConfigurations ) {
33
- // Clone the configuration to make sure that the properties will not be shared
34
- // between editors and make the watchdog feature work correctly.
35
- this.define( cloneConfig( defaultConfigurations ) );
36
- }
37
-
38
- // Set initial configuration.
39
- if ( configurations ) {
40
- this._setObjectToTarget( this._config, configurations );
41
- }
42
- }
43
-
44
- /**
45
- * Set configuration values.
46
- *
47
- * It accepts both a name/value pair or an object, which properties and values will be used to set
48
- * configurations.
49
- *
50
- * It also accepts setting a "deep configuration" by using dots in the name. For example, `'resize.width'` sets
51
- * the value for the `width` configuration in the `resize` subset.
52
- *
53
- * config.set( 'width', 500 );
54
- * config.set( 'toolbar.collapsed', true );
55
- *
56
- * // Equivalent to:
57
- * config.set( {
58
- * width: 500
59
- * toolbar: {
60
- * collapsed: true
61
- * }
62
- * } );
63
- *
64
- * Passing an object as the value will amend the configuration, not replace it.
65
- *
66
- * config.set( 'toolbar', {
67
- * collapsed: true,
68
- * } );
69
- *
70
- * config.set( 'toolbar', {
71
- * color: 'red',
72
- * } );
73
- *
74
- * config.get( 'toolbar.collapsed' ); // true
75
- * config.get( 'toolbar.color' ); // 'red'
76
- *
77
- * @param {String|Object} name The configuration name or an object from which take properties as
78
- * configuration entries. Configuration names are case-sensitive.
79
- * @param {*} value The configuration value. Used if a name is passed.
80
- */
81
- set( name, value ) {
82
- this._setToTarget( this._config, name, value );
83
- }
84
-
85
- /**
86
- * Does exactly the same as {@link #set} with one exception – passed configuration extends
87
- * existing one, but does not overwrite already defined values.
88
- *
89
- * This method is supposed to be called by plugin developers to setup plugin's configurations. It would be
90
- * rarely used for other needs.
91
- *
92
- * @param {String|Object} name The configuration name or an object from which take properties as
93
- * configuration entries. Configuration names are case-sensitive.
94
- * @param {*} value The configuration value. Used if a name is passed.
95
- */
96
- define( name, value ) {
97
- const isDefine = true;
98
-
99
- this._setToTarget( this._config, name, value, isDefine );
100
- }
101
-
102
- /**
103
- * Gets the value for a configuration entry.
104
- *
105
- * config.get( 'name' );
106
- *
107
- * Deep configurations can be retrieved by separating each part with a dot.
108
- *
109
- * config.get( 'toolbar.collapsed' );
110
- *
111
- * @param {String} name The configuration name. Configuration names are case-sensitive.
112
- * @returns {*} The configuration value or `undefined` if the configuration entry was not found.
113
- */
114
- get( name ) {
115
- return this._getFromSource( this._config, name );
116
- }
117
-
118
- /**
119
- * Iterates over all top level configuration names.
120
- *
121
- * @returns {Iterable.<String>}
122
- */
123
- * names() {
124
- for ( const name of Object.keys( this._config ) ) {
125
- yield name;
126
- }
127
- }
128
-
129
- /**
130
- * Saves passed configuration to the specified target (nested object).
131
- *
132
- * @private
133
- * @param {Object} target Nested config object.
134
- * @param {String|Object} name The configuration name or an object from which take properties as
135
- * configuration entries. Configuration names are case-sensitive.
136
- * @param {*} value The configuration value. Used if a name is passed.
137
- * @param {Boolean} [isDefine=false] Define if passed configuration should overwrite existing one.
138
- */
139
- _setToTarget( target, name, value, isDefine = false ) {
140
- // In case of an object, iterate through it and call `_setToTarget` again for each property.
141
- if ( isPlainObject( name ) ) {
142
- this._setObjectToTarget( target, name, isDefine );
143
-
144
- return;
145
- }
146
-
147
- // The configuration name should be split into parts if it has dots. E.g. `resize.width` -> [`resize`, `width`].
148
- const parts = name.split( '.' );
149
-
150
- // Take the name of the configuration out of the parts. E.g. `resize.width` -> `width`.
151
- name = parts.pop();
152
-
153
- // Iterate over parts to check if currently stored configuration has proper structure.
154
- for ( const part of parts ) {
155
- // If there is no object for specified part then create one.
156
- if ( !isPlainObject( target[ part ] ) ) {
157
- target[ part ] = {};
158
- }
159
-
160
- // Nested object becomes a target.
161
- target = target[ part ];
162
- }
163
-
164
- // In case of value is an object.
165
- if ( isPlainObject( value ) ) {
166
- // We take care of proper config structure.
167
- if ( !isPlainObject( target[ name ] ) ) {
168
- target[ name ] = {};
169
- }
170
-
171
- target = target[ name ];
172
-
173
- // And iterate through this object calling `_setToTarget` again for each property.
174
- this._setObjectToTarget( target, value, isDefine );
175
-
176
- return;
177
- }
178
-
179
- // Do nothing if we are defining configuration for non empty name.
180
- if ( isDefine && typeof target[ name ] != 'undefined' ) {
181
- return;
182
- }
183
-
184
- target[ name ] = value;
185
- }
186
-
187
- /**
188
- * Get specified configuration from specified source (nested object).
189
- *
190
- * @private
191
- * @param {Object} source level of nested object.
192
- * @param {String} name The configuration name. Configuration names are case-sensitive.
193
- * @returns {*} The configuration value or `undefined` if the configuration entry was not found.
194
- */
195
- _getFromSource( source, name ) {
196
- // The configuration name should be split into parts if it has dots. E.g. `resize.width` -> [`resize`, `width`].
197
- const parts = name.split( '.' );
198
-
199
- // Take the name of the configuration out of the parts. E.g. `resize.width` -> `width`.
200
- name = parts.pop();
201
-
202
- // Iterate over parts to check if currently stored configuration has proper structure.
203
- for ( const part of parts ) {
204
- if ( !isPlainObject( source[ part ] ) ) {
205
- source = null;
206
- break;
207
- }
208
-
209
- // Nested object becomes a source.
210
- source = source[ part ];
211
- }
212
-
213
- // Always returns undefined for non existing configuration.
214
- return source ? cloneConfig( source[ name ] ) : undefined;
215
- }
216
-
217
- /**
218
- * Iterates through passed object and calls {@link #_setToTarget} method with object key and value for each property.
219
- *
220
- * @private
221
- * @param {Object} target Nested config object.
222
- * @param {Object} configuration Configuration data set
223
- * @param {Boolean} [isDefine] Defines if passed configuration is default configuration or not.
224
- */
225
- _setObjectToTarget( target, configuration, isDefine ) {
226
- Object.keys( configuration ).forEach( key => {
227
- this._setToTarget( target, key, configuration[ key ], isDefine );
228
- } );
229
- }
230
- }
231
-
232
- // Clones configuration object or value.
233
- // @param {*} source Source configuration
234
- // @returns {*} Cloned configuration value.
235
- function cloneConfig( source ) {
236
- return cloneDeepWith( source, leaveDOMReferences );
237
- }
238
-
239
- // A customized function for cloneDeepWith.
240
- // It will leave references to DOM Elements instead of cloning them.
241
- //
242
- // @param {*} value
243
- // @returns {Element|undefined}
244
- function leaveDOMReferences( value ) {
245
- return isElement( value ) ? value : undefined;
246
- }
package/src/count.js DELETED
@@ -1,26 +0,0 @@
1
- /**
2
- * @license Copyright (c) 2003-2022, CKSource Holding sp. z o.o. All rights reserved.
3
- * For licensing, see LICENSE.md or https://ckeditor.com/legal/ckeditor-oss-license
4
- */
5
-
6
- /**
7
- * @module utils/count
8
- */
9
-
10
- /**
11
- * Returns the number of items return by the iterator.
12
- *
13
- * count( [ 1, 2, 3, 4, 5 ] ); // 5;
14
- *
15
- * @param {Iterable.<*>} iterator Any iterator.
16
- * @returns {Number} Number of items returned by that iterator.
17
- */
18
- export default function count( iterator ) {
19
- let count = 0;
20
-
21
- for ( const _ of iterator ) { // eslint-disable-line no-unused-vars
22
- count++;
23
- }
24
-
25
- return count;
26
- }
package/src/diff.js DELETED
@@ -1,138 +0,0 @@
1
- /**
2
- * @license Copyright (c) 2003-2022, CKSource Holding sp. z o.o. All rights reserved.
3
- * For licensing, see LICENSE.md or https://ckeditor.com/legal/ckeditor-oss-license
4
- */
5
-
6
- /**
7
- * @module utils/diff
8
- */
9
-
10
- import fastDiff from '../src/fastdiff';
11
-
12
- // The following code is based on the "O(NP) Sequence Comparison Algorithm"
13
- // by Sun Wu, Udi Manber, Gene Myers, Webb Miller.
14
-
15
- /**
16
- * Calculates the difference between two arrays or strings producing an array containing a list of changes
17
- * necessary to transform input into output.
18
- *
19
- * diff( 'aba', 'acca' ); // [ 'equal', 'insert', 'insert', 'delete', 'equal' ]
20
- *
21
- * This function is based on the "O(NP) Sequence Comparison Algorithm" by Sun Wu, Udi Manber, Gene Myers, Webb Miller.
22
- * Unfortunately, while it gives the most precise results, its to complex for longer strings/arrow (above 200 items).
23
- * Therefore, `diff()` automatically switches to {@link module:utils/fastdiff~fastDiff `fastDiff()`} when detecting
24
- * such a scenario. The return formats of both functions are identical.
25
- *
26
- * @param {Array|String} a Input array or string.
27
- * @param {Array|String} b Output array or string.
28
- * @param {Function} [cmp] Optional function used to compare array values, by default === is used.
29
- * @returns {Array} Array of changes.
30
- */
31
- export default function diff( a, b, cmp ) {
32
- // Set the comparator function.
33
- cmp = cmp || function( a, b ) {
34
- return a === b;
35
- };
36
-
37
- const aLength = a.length;
38
- const bLength = b.length;
39
-
40
- // Perform `fastDiff` for longer strings/arrays (see #269).
41
- if ( aLength > 200 || bLength > 200 || aLength + bLength > 300 ) {
42
- return diff.fastDiff( a, b, cmp, true );
43
- }
44
-
45
- // Temporary action type statics.
46
- let _insert, _delete;
47
-
48
- // Swapped the arrays to use the shorter one as the first one.
49
- if ( bLength < aLength ) {
50
- const tmp = a;
51
-
52
- a = b;
53
- b = tmp;
54
-
55
- // We swap the action types as well.
56
- _insert = 'delete';
57
- _delete = 'insert';
58
- } else {
59
- _insert = 'insert';
60
- _delete = 'delete';
61
- }
62
-
63
- const m = a.length;
64
- const n = b.length;
65
- const delta = n - m;
66
-
67
- // Edit scripts, for each diagonal.
68
- const es = {};
69
- // Furthest points, the furthest y we can get on each diagonal.
70
- const fp = {};
71
-
72
- function snake( k ) {
73
- // We use -1 as an alternative below to handle initial values ( instead of filling the fp with -1 first ).
74
- // Furthest points (y) on the diagonal below k.
75
- const y1 = ( fp[ k - 1 ] !== undefined ? fp[ k - 1 ] : -1 ) + 1;
76
- // Furthest points (y) on the diagonal above k.
77
- const y2 = fp[ k + 1 ] !== undefined ? fp[ k + 1 ] : -1;
78
- // The way we should go to get further.
79
- const dir = y1 > y2 ? -1 : 1;
80
-
81
- // Clone previous changes array (if any).
82
- if ( es[ k + dir ] ) {
83
- es[ k ] = es[ k + dir ].slice( 0 );
84
- }
85
-
86
- // Create changes array.
87
- if ( !es[ k ] ) {
88
- es[ k ] = [];
89
- }
90
-
91
- // Push the action.
92
- es[ k ].push( y1 > y2 ? _insert : _delete );
93
-
94
- // Set the beginning coordinates.
95
- let y = Math.max( y1, y2 );
96
- let x = y - k;
97
-
98
- // Traverse the diagonal as long as the values match.
99
- while ( x < m && y < n && cmp( a[ x ], b[ y ] ) ) {
100
- x++;
101
- y++;
102
- // Push no change action.
103
- es[ k ].push( 'equal' );
104
- }
105
-
106
- return y;
107
- }
108
-
109
- let p = 0;
110
- let k;
111
-
112
- // Traverse the graph until we reach the end of the longer string.
113
- do {
114
- // Updates furthest points and edit scripts for diagonals below delta.
115
- for ( k = -p; k < delta; k++ ) {
116
- fp[ k ] = snake( k );
117
- }
118
-
119
- // Updates furthest points and edit scripts for diagonals above delta.
120
- for ( k = delta + p; k > delta; k-- ) {
121
- fp[ k ] = snake( k );
122
- }
123
-
124
- // Updates furthest point and edit script for the delta diagonal.
125
- // note that the delta diagonal is the one which goes through the sink (m, n).
126
- fp[ delta ] = snake( delta );
127
-
128
- p++;
129
- } while ( fp[ delta ] !== n );
130
-
131
- // Return the final list of edit changes.
132
- // We remove the first item that represents the action for the injected nulls.
133
- return es[ delta ].slice( 1 );
134
- }
135
-
136
- // Store the API in static property to easily overwrite it in tests.
137
- // Too bad dependency injection does not work in Webpack + ES 6 (const) + Babel.
138
- diff.fastDiff = fastDiff;
@@ -1,86 +0,0 @@
1
- /**
2
- * @license Copyright (c) 2003-2022, CKSource Holding sp. z o.o. All rights reserved.
3
- * For licensing, see LICENSE.md or https://ckeditor.com/legal/ckeditor-oss-license
4
- */
5
-
6
- /**
7
- * @module utils/difftochanges
8
- */
9
-
10
- /**
11
- * Creates a set of changes which need to be applied to the input in order to transform
12
- * it into the output. This function can be used with strings or arrays.
13
- *
14
- * const input = Array.from( 'abc' );
15
- * const output = Array.from( 'xaby' );
16
- * const changes = diffToChanges( diff( input, output ), output );
17
- *
18
- * changes.forEach( change => {
19
- * if ( change.type == 'insert' ) {
20
- * input.splice( change.index, 0, ...change.values );
21
- * } else if ( change.type == 'delete' ) {
22
- * input.splice( change.index, change.howMany );
23
- * }
24
- * } );
25
- *
26
- * input.join( '' ) == output.join( '' ); // -> true
27
- *
28
- * @param {Array.<'equal'|'insert'|'delete'>} diff Result of {@link module:utils/diff~diff}.
29
- * @param {String|Array} output The string or array which was passed as diff's output.
30
- * @returns {Array.<Object>} Set of changes (insert or delete) which need to be applied to the input
31
- * in order to transform it into the output.
32
- */
33
- export default function diffToChanges( diff, output ) {
34
- const changes = [];
35
- let index = 0;
36
- let lastOperation;
37
-
38
- diff.forEach( change => {
39
- if ( change == 'equal' ) {
40
- pushLast();
41
-
42
- index++;
43
- } else if ( change == 'insert' ) {
44
- if ( isContinuationOf( 'insert' ) ) {
45
- lastOperation.values.push( output[ index ] );
46
- } else {
47
- pushLast();
48
-
49
- lastOperation = {
50
- type: 'insert',
51
- index,
52
- values: [ output[ index ] ]
53
- };
54
- }
55
-
56
- index++;
57
- } else /* if ( change == 'delete' ) */ {
58
- if ( isContinuationOf( 'delete' ) ) {
59
- lastOperation.howMany++;
60
- } else {
61
- pushLast();
62
-
63
- lastOperation = {
64
- type: 'delete',
65
- index,
66
- howMany: 1
67
- };
68
- }
69
- }
70
- } );
71
-
72
- pushLast();
73
-
74
- return changes;
75
-
76
- function pushLast() {
77
- if ( lastOperation ) {
78
- changes.push( lastOperation );
79
- lastOperation = null;
80
- }
81
- }
82
-
83
- function isContinuationOf( expected ) {
84
- return lastOperation && lastOperation.type == expected;
85
- }
86
- }
@@ -1,49 +0,0 @@
1
- /**
2
- * @license Copyright (c) 2003-2022, CKSource Holding sp. z o.o. All rights reserved.
3
- * For licensing, see LICENSE.md or https://ckeditor.com/legal/ckeditor-oss-license
4
- */
5
-
6
- /**
7
- * @module utils/dom/createelement
8
- */
9
-
10
- import isIterable from '../isiterable';
11
- import { isString } from 'lodash-es';
12
-
13
- /**
14
- * Creates element with attributes and children.
15
- *
16
- * createElement( document, 'p' ); // <p>
17
- * createElement( document, 'p', { class: 'foo' } ); // <p class="foo">
18
- * createElement( document, 'p', null, 'foo' ); // <p>foo</p>
19
- * createElement( document, 'p', null, [ 'foo', createElement( document, 'img' ) ] ); // <p>foo<img></p>
20
- *
21
- * @param {Document} doc Document used to create element.
22
- * @param {String} name Name of the element.
23
- * @param {Object} [attributes] Object keys will become attributes keys and object values will became attributes values.
24
- * @param {Node|String|Array.<Node|String>} [children] Child or array of children. Strings will be automatically turned
25
- * into Text nodes.
26
- * @returns {Element} Created element.
27
- */
28
- export default function createElement( doc, name, attributes = {}, children = [] ) {
29
- const namespace = attributes && attributes.xmlns;
30
- const element = namespace ? doc.createElementNS( namespace, name ) : doc.createElement( name );
31
-
32
- for ( const key in attributes ) {
33
- element.setAttribute( key, attributes[ key ] );
34
- }
35
-
36
- if ( isString( children ) || !isIterable( children ) ) {
37
- children = [ children ];
38
- }
39
-
40
- for ( let child of children ) {
41
- if ( isString( child ) ) {
42
- child = doc.createTextNode( child );
43
- }
44
-
45
- element.appendChild( child );
46
- }
47
-
48
- return element;
49
- }