@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
@@ -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
  /* eslint-disable no-var */
@@ -22,70 +22,80 @@ if (!global.window.CKEDITOR_TRANSLATIONS) {
22
22
  * Since the editor displays only the message string, the message ID can be found either in the source code or in the
23
23
  * built translations for another language.
24
24
  *
25
- * add( 'pl', {
26
- * 'Cancel': 'Anuluj',
27
- * 'IMAGE': 'obraz', // Note that the `IMAGE` comes from the message ID, while the string can be `image`.
28
- * } );
25
+ * ```ts
26
+ * add( 'pl', {
27
+ * 'Cancel': 'Anuluj',
28
+ * 'IMAGE': 'obraz', // Note that the `IMAGE` comes from the message ID, while the string can be `image`.
29
+ * } );
30
+ * ```
29
31
  *
30
32
  * If the message is supposed to support various plural forms, make sure to provide an array with the singular form and all plural forms:
31
33
  *
32
- * add( 'pl', {
33
- * 'Add space': [ 'Dodaj spację', 'Dodaj %0 spacje', 'Dodaj %0 spacji' ]
34
- * } );
34
+ * ```ts
35
+ * add( 'pl', {
36
+ * 'Add space': [ 'Dodaj spację', 'Dodaj %0 spacje', 'Dodaj %0 spacji' ]
37
+ * } );
38
+ * ```
35
39
  *
36
40
  * You should also specify the third argument (the `getPluralForm()` function) that will be used to determine the plural form if no
37
41
  * language file was loaded for that language. All language files coming from CKEditor 5 sources will have this option set, so
38
42
  * these plural form rules will be reused by other translations added to the registered languages. The `getPluralForm()` function
39
43
  * can return either a Boolean or a number.
40
44
  *
41
- * add( 'en', {
42
- * // ... Translations.
43
- * }, n => n !== 1 );
44
- * add( 'pl', {
45
- * // ... Translations.
46
- * }, n => n == 1 ? 0 : n % 10 >= 2 && n % 10 <= 4 && ( n % 100 < 10 || n % 100 >= 20 ) ? 1 : 2 );
45
+ * ```ts
46
+ * add( 'en', {
47
+ * // ... Translations.
48
+ * }, n => n !== 1 );
49
+ * add( 'pl', {
50
+ * // ... Translations.
51
+ * }, n => n == 1 ? 0 : n % 10 >= 2 && n % 10 <= 4 && ( n % 100 < 10 || n % 100 >= 20 ) ? 1 : 2 );
52
+ * ```
47
53
  *
48
54
  * All translations extend the global `window.CKEDITOR_TRANSLATIONS` object. An example of this object can be found below:
49
55
  *
50
- * {
51
- * pl: {
52
- * dictionary: {
53
- * 'Cancel': 'Anuluj',
54
- * 'Add space': [ 'Dodaj spację', 'Dodaj %0 spacje', 'Dodaj %0 spacji' ]
55
- * },
56
- * // A function that returns the plural form index.
57
- * getPluralForm: n => n !==1
58
- * }
59
- * // Other languages.
60
- * }
56
+ * ```ts
57
+ * {
58
+ * pl: {
59
+ * dictionary: {
60
+ * 'Cancel': 'Anuluj',
61
+ * 'Add space': [ 'Dodaj spację', 'Dodaj %0 spacje', 'Dodaj %0 spacji' ]
62
+ * },
63
+ * // A function that returns the plural form index.
64
+ * getPluralForm: n => n == 1 ? 0 : n % 10 >= 2 && n % 10 <= 4 && ( n % 100 < 10 || n % 100 >= 20 ) ? 1 : 2 );
65
+ * }
66
+ * // Other languages.
67
+ * }
68
+ * ```
61
69
  *
62
70
  * If you cannot import this function from this module (e.g. because you use a CKEditor 5 build), you can
63
71
  * still add translations by extending the global `window.CKEDITOR_TRANSLATIONS` object by using a function like
64
72
  * the one below:
65
73
  *
66
- * function addTranslations( language, translations, getPluralForm ) {
67
- * if ( !global.window.CKEDITOR_TRANSLATIONS ) {
68
- * global.window.CKEDITOR_TRANSLATIONS = {};
69
- * }
74
+ * ```ts
75
+ * function addTranslations( language, translations, getPluralForm ) {
76
+ * if ( !global.window.CKEDITOR_TRANSLATIONS ) {
77
+ * global.window.CKEDITOR_TRANSLATIONS = {};
78
+ * }
70
79
 
71
- * if ( !global.window.CKEDITOR_TRANSLATIONS[ language ] ) {
72
- * global.window.CKEDITOR_TRANSLATIONS[ language ] = {};
73
- * }
80
+ * if ( !global.window.CKEDITOR_TRANSLATIONS[ language ] ) {
81
+ * global.window.CKEDITOR_TRANSLATIONS[ language ] = {};
82
+ * }
74
83
  *
75
- * const languageTranslations = global.window.CKEDITOR_TRANSLATIONS[ language ];
84
+ * const languageTranslations = global.window.CKEDITOR_TRANSLATIONS[ language ];
76
85
  *
77
- * languageTranslations.dictionary = languageTranslations.dictionary || {};
78
- * languageTranslations.getPluralForm = getPluralForm || languageTranslations.getPluralForm;
86
+ * languageTranslations.dictionary = languageTranslations.dictionary || {};
87
+ * languageTranslations.getPluralForm = getPluralForm || languageTranslations.getPluralForm;
79
88
  *
80
- * // Extend the dictionary for the given language.
81
- * Object.assign( languageTranslations.dictionary, translations );
82
- * }
89
+ * // Extend the dictionary for the given language.
90
+ * Object.assign( languageTranslations.dictionary, translations );
91
+ * }
92
+ * ```
83
93
  *
84
- * @param {String} language Target language.
85
- * @param {Object.<String,*>} translations An object with translations which will be added to the dictionary.
94
+ * @param language Target language.
95
+ * @param translations An object with translations which will be added to the dictionary.
86
96
  * For each message ID the value should be either a translation or an array of translations if the message
87
97
  * should support plural forms.
88
- * @param {Function} [getPluralForm] A function that returns the plural form index (a number).
98
+ * @param getPluralForm A function that returns the plural form index (a number).
89
99
  */
90
100
  export function add(language, translations, getPluralForm) {
91
101
  if (!global.window.CKEDITOR_TRANSLATIONS[language]) {
@@ -107,25 +117,31 @@ export function add(language, translations, getPluralForm) {
107
117
  * When no translation is defined in the dictionary or the dictionary does not exist, this function returns
108
118
  * the original message string or the message plural depending on the number of elements.
109
119
  *
110
- * translate( 'pl', { string: 'Cancel' } ); // 'Cancel'
120
+ * ```ts
121
+ * translate( 'pl', { string: 'Cancel' } ); // 'Cancel'
122
+ * ```
111
123
  *
112
124
  * The third optional argument is the number of elements, based on which the single form or one of the plural forms
113
125
  * should be picked when the message is supposed to support various plural forms.
114
126
  *
115
- * translate( 'en', { string: 'Add a space', plural: 'Add %0 spaces' }, 1 ); // 'Add a space'
116
- * translate( 'en', { string: 'Add a space', plural: 'Add %0 spaces' }, 3 ); // 'Add %0 spaces'
127
+ * ```ts
128
+ * translate( 'en', { string: 'Add a space', plural: 'Add %0 spaces' }, 1 ); // 'Add a space'
129
+ * translate( 'en', { string: 'Add a space', plural: 'Add %0 spaces' }, 3 ); // 'Add %0 spaces'
130
+ * ```
117
131
  *
118
132
  * The message should provide an ID using the `id` property when the message strings are not unique and their
119
133
  * translations should be different.
120
134
  *
121
- * translate( 'en', { string: 'image', id: 'ADD_IMAGE' } );
122
- * translate( 'en', { string: 'image', id: 'AN_IMAGE' } );
135
+ * ```ts
136
+ * translate( 'en', { string: 'image', id: 'ADD_IMAGE' } );
137
+ * translate( 'en', { string: 'image', id: 'AN_IMAGE' } );
138
+ * ```
123
139
  *
124
- * @protected
125
- * @param {String} language Target language.
126
- * @param {module:utils/translation-service~Message} message A message that will be translated.
127
- * @param {Number} [quantity] The number of elements for which a plural form should be picked from the target language dictionary.
128
- * @returns {String} Translated sentence.
140
+ * @internal
141
+ * @param language Target language.
142
+ * @param message A message that will be translated.
143
+ * @param quantity The number of elements for which a plural form should be picked from the target language dictionary.
144
+ * @returns Translated sentence.
129
145
  */
130
146
  export function _translate(language, message, quantity = 1) {
131
147
  if (typeof quantity !== 'number') {
@@ -165,12 +181,14 @@ export function _translate(language, message, quantity = 1) {
165
181
  /**
166
182
  * Clears dictionaries for test purposes.
167
183
  *
168
- * @protected
184
+ * @internal
169
185
  */
170
186
  export function _clear() {
171
187
  global.window.CKEDITOR_TRANSLATIONS = {};
172
188
  }
173
- // Checks whether the dictionary exists and translation in that dictionary exists.
189
+ /**
190
+ * Checks whether the dictionary exists and translation in that dictionary exists.
191
+ */
174
192
  function hasTranslation(language, messageId) {
175
193
  return (!!global.window.CKEDITOR_TRANSLATIONS[language] &&
176
194
  !!global.window.CKEDITOR_TRANSLATIONS[language].dictionary[messageId]);
package/src/uid.js CHANGED
@@ -1,12 +1,14 @@
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
  /**
6
6
  * @module utils/uid
7
7
  */
8
- // A hash table of hex numbers to avoid using toString() in uid() which is costly.
9
- // [ '00', '01', '02', ..., 'fe', 'ff' ]
8
+ /**
9
+ * A hash table of hex numbers to avoid using toString() in uid() which is costly.
10
+ * [ '00', '01', '02', ..., 'fe', 'ff' ]
11
+ */
10
12
  const HEX_NUMBERS = new Array(256).fill('')
11
13
  .map((_, index) => ('0' + (index).toString(16)).slice(-2));
12
14
  /**
@@ -17,7 +19,7 @@ const HEX_NUMBERS = new Array(256).fill('')
17
19
  * (from "0" to "9", from "a" to "f"). In other words, each id corresponds to an "e" followed
18
20
  * by 16 8-bit numbers next to each other.
19
21
  *
20
- * @returns {String} An unique id string.
22
+ * @returns An unique id string.
21
23
  */
22
24
  export default function uid() {
23
25
  // Let's create some positive random 32bit integers first.
package/src/unicode.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
  /**
@@ -10,8 +10,7 @@
10
10
  /**
11
11
  * Checks whether given `character` is a combining mark.
12
12
  *
13
- * @param {String} character Character to check.
14
- * @returns {Boolean}
13
+ * @param character Character to check.
15
14
  */
16
15
  export function isCombiningMark(character) {
17
16
  // eslint-disable-next-line no-misleading-character-class
@@ -23,8 +22,7 @@ export function isCombiningMark(character) {
23
22
  * Using UTF-16 terminology, a surrogate pair denotes UTF-16 character using two UTF-8 characters. The surrogate pair
24
23
  * consist of high surrogate pair character followed by low surrogate pair character.
25
24
  *
26
- * @param {String} character Character to check.
27
- * @returns {Boolean}
25
+ * @param character Character to check.
28
26
  */
29
27
  export function isHighSurrogateHalf(character) {
30
28
  return !!character && character.length == 1 && /[\ud800-\udbff]/.test(character);
@@ -35,8 +33,7 @@ export function isHighSurrogateHalf(character) {
35
33
  * Using UTF-16 terminology, a surrogate pair denotes UTF-16 character using two UTF-8 characters. The surrogate pair
36
34
  * consist of high surrogate pair character followed by low surrogate pair character.
37
35
  *
38
- * @param {String} character Character to check.
39
- * @returns {Boolean}
36
+ * @param character Character to check.
40
37
  */
41
38
  export function isLowSurrogateHalf(character) {
42
39
  return !!character && character.length == 1 && /[\udc00-\udfff]/.test(character);
@@ -44,9 +41,8 @@ export function isLowSurrogateHalf(character) {
44
41
  /**
45
42
  * Checks whether given offset in a string is inside a surrogate pair (between two surrogate halves).
46
43
  *
47
- * @param {String} string String to check.
48
- * @param {Number} offset Offset to check.
49
- * @returns {Boolean}
44
+ * @param string String to check.
45
+ * @param offset Offset to check.
50
46
  */
51
47
  export function isInsideSurrogatePair(string, offset) {
52
48
  return isHighSurrogateHalf(string.charAt(offset - 1)) && isLowSurrogateHalf(string.charAt(offset));
@@ -54,9 +50,8 @@ export function isInsideSurrogatePair(string, offset) {
54
50
  /**
55
51
  * Checks whether given offset in a string is between base character and combining mark or between two combining marks.
56
52
  *
57
- * @param {String} string String to check.
58
- * @param {Number} offset Offset to check.
59
- * @returns {Boolean}
53
+ * @param string String to check.
54
+ * @param offset Offset to check.
60
55
  */
61
56
  export function isInsideCombinedSymbol(string, offset) {
62
57
  return isCombiningMark(string.charAt(offset));
@@ -65,9 +60,8 @@ const EMOJI_PATTERN = buildEmojiRegexp();
65
60
  /**
66
61
  * Checks whether given offset in a string is inside multi-character emoji sequence.
67
62
  *
68
- * @param {String} string String to check.
69
- * @param {Number} offset Offset to check.
70
- * @returns {Boolean}
63
+ * @param string String to check.
64
+ * @param offset Offset to check.
71
65
  */
72
66
  export function isInsideEmojiSequence(string, offset) {
73
67
  const matches = String(string).matchAll(EMOJI_PATTERN);
package/src/version.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,7 +7,7 @@
7
7
  */
8
8
  /* globals window, global */
9
9
  import CKEditorError from './ckeditorerror';
10
- const version = '35.3.2';
10
+ const version = '36.0.0';
11
11
  export default version;
12
12
  /* istanbul ignore next */
13
13
  const windowOrGlobal = typeof window === 'object' ? window : global;
@@ -25,8 +25,10 @@ if (windowOrGlobal.CKEDITOR_VERSION) {
25
25
  *
26
26
  * If you import an existing CKEditor 5 build and a plugin like this:
27
27
  *
28
- * import ClassicEditor from '@ckeditor/ckeditor5-build-classic';
29
- * import Highlight from '@ckeditor/ckeditor5-highlight/src/highlight';
28
+ * ```ts
29
+ * import ClassicEditor from '@ckeditor/ckeditor5-build-classic';
30
+ * import Highlight from '@ckeditor/ckeditor5-highlight/src/highlight';
31
+ * ```
30
32
  *
31
33
  * Then your project loads some CKEditor 5 packages twice. How does it happen?
32
34
  *
@@ -54,32 +56,36 @@ if (windowOrGlobal.CKEDITOR_VERSION) {
54
56
  *
55
57
  * The correct way to do so is to import an editor and plugins and run them together like this:
56
58
  *
57
- * import ClassicEditor from '@ckeditor/ckeditor5-editor-classic/src/classiceditor';
58
- * import Essentials from '@ckeditor/ckeditor5-essentials/src/essentials';
59
- * import Paragraph from '@ckeditor/ckeditor5-paragraph/src/paragraph';
60
- * import Bold from '@ckeditor/ckeditor5-basic-styles/src/bold';
61
- * import Italic from '@ckeditor/ckeditor5-basic-styles/src/italic';
62
- *
63
- * ClassicEditor
64
- * .create( document.querySelector( '#editor' ), {
65
- * plugins: [ Essentials, Paragraph, Bold, Italic ],
66
- * toolbar: [ 'bold', 'italic' ]
67
- * } )
68
- * .then( editor => {
69
- * console.log( 'Editor was initialized', editor );
70
- * } )
71
- * .catch( error => {
72
- * console.error( error.stack );
73
- * } );
59
+ * ```ts
60
+ * import ClassicEditor from '@ckeditor/ckeditor5-editor-classic/src/classiceditor';
61
+ * import Essentials from '@ckeditor/ckeditor5-essentials/src/essentials';
62
+ * import Paragraph from '@ckeditor/ckeditor5-paragraph/src/paragraph';
63
+ * import Bold from '@ckeditor/ckeditor5-basic-styles/src/bold';
64
+ * import Italic from '@ckeditor/ckeditor5-basic-styles/src/italic';
65
+ *
66
+ * ClassicEditor
67
+ * .create( document.querySelector( '#editor' ), {
68
+ * plugins: [ Essentials, Paragraph, Bold, Italic ],
69
+ * toolbar: [ 'bold', 'italic' ]
70
+ * } )
71
+ * .then( editor => {
72
+ * console.log( 'Editor was initialized', editor );
73
+ * } )
74
+ * .catch( error => {
75
+ * console.error( error.stack );
76
+ * } );
77
+ * ```
74
78
  *
75
79
  * However, you might have mistakenly imported a build instead of the source `ClassicEditor`. In this case
76
80
  * your imports will look like this:
77
81
  *
78
- * import ClassicEditor from '@ckeditor/ckeditor5-build-classic';
79
- * import Essentials from '@ckeditor/ckeditor5-essentials/src/essentials';
80
- * import Paragraph from '@ckeditor/ckeditor5-paragraph/src/paragraph';
81
- * import Bold from '@ckeditor/ckeditor5-basic-styles/src/bold';
82
- * import Italic from '@ckeditor/ckeditor5-basic-styles/src/italic';
82
+ * ```ts
83
+ * import ClassicEditor from '@ckeditor/ckeditor5-build-classic';
84
+ * import Essentials from '@ckeditor/ckeditor5-essentials/src/essentials';
85
+ * import Paragraph from '@ckeditor/ckeditor5-paragraph/src/paragraph';
86
+ * import Bold from '@ckeditor/ckeditor5-basic-styles/src/bold';
87
+ * import Italic from '@ckeditor/ckeditor5-basic-styles/src/italic';
88
+ * ```
83
89
  *
84
90
  * This creates the same situation as in the previous section because you use a build together with source plugins.
85
91
  *
@@ -117,7 +123,7 @@ if (windowOrGlobal.CKEDITOR_VERSION) {
117
123
  * **Note:** All official CKEditor 5 packages (excluding integrations and `ckeditor5-dev-*` packages) are released in the
118
124
  * same major version. This is &mdash; in the `x.y.z`, the `x` is the same for all packages. This is the simplest way to check
119
125
  * whether you use packages coming from the same CKEditor 5 version. You can read more about versioning in the
120
- * {@glink support/versioning-policy Versioning policy} guide.
126
+ * {@glink updating/versioning-policy Versioning policy} guide.
121
127
  *
122
128
  * # Packages were duplicated in `node_modules`
123
129
  *