@ckeditor/ckeditor5-utils 35.3.2 → 35.4.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/package.json +5 -5
- package/src/areconnectedthroughproperties.js +5 -7
- package/src/ckeditorerror.js +51 -70
- package/src/collection.js +106 -148
- package/src/comparearrays.js +10 -8
- package/src/config.js +29 -83
- package/src/count.js +5 -3
- package/src/diff.js +7 -5
- package/src/difftochanges.js +17 -14
- package/src/dom/createelement.js +11 -9
- package/src/dom/emittermixin.js +43 -84
- package/src/dom/getancestors.js +2 -2
- package/src/dom/getborderwidths.js +2 -2
- package/src/dom/getcommonancestor.js +3 -3
- package/src/dom/getdatafromelement.js +2 -2
- package/src/dom/getpositionedancestor.js +1 -2
- package/src/dom/global.js +8 -10
- package/src/dom/indexof.js +2 -2
- package/src/dom/insertat.js +3 -3
- package/src/dom/iscomment.js +0 -3
- package/src/dom/isnode.js +0 -3
- package/src/dom/isrange.js +0 -3
- package/src/dom/istext.js +0 -3
- package/src/dom/isvisible.js +0 -3
- package/src/dom/iswindow.js +0 -3
- package/src/dom/position.js +110 -133
- package/src/dom/rect.js +42 -52
- package/src/dom/remove.js +1 -1
- package/src/dom/resizeobserver.js +10 -35
- package/src/dom/scroll.js +85 -91
- package/src/dom/setdatainelement.js +2 -2
- package/src/dom/tounit.js +1 -10
- package/src/elementreplacer.js +2 -2
- package/src/emittermixin.js +48 -48
- package/src/env.js +14 -75
- package/src/eventinfo.js +2 -2
- package/src/fastdiff.js +115 -96
- package/src/first.js +0 -3
- package/src/focustracker.js +10 -18
- package/src/index.js +17 -0
- package/src/inserttopriorityarray.js +2 -2
- package/src/isiterable.js +2 -2
- package/src/keyboard.js +20 -21
- package/src/keystrokehandler.js +26 -24
- package/src/language.js +1 -2
- package/src/locale.js +11 -14
- package/src/mapsequal.js +3 -3
- package/src/mix.js +15 -13
- package/src/nth.js +0 -4
- package/src/objecttomap.js +6 -4
- package/src/observablemixin.js +126 -150
- package/src/priorities.js +0 -9
- package/src/splicearray.js +12 -11
- package/src/spy.js +1 -1
- package/src/tomap.js +7 -5
- package/src/translation-service.js +70 -52
- package/src/uid.js +5 -3
- package/src/unicode.js +9 -15
- package/src/version.js +32 -26
|
@@ -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
|
-
*
|
|
26
|
-
*
|
|
27
|
-
*
|
|
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
|
-
*
|
|
33
|
-
*
|
|
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
|
-
*
|
|
42
|
-
*
|
|
43
|
-
*
|
|
44
|
-
*
|
|
45
|
-
*
|
|
46
|
-
*
|
|
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
|
-
*
|
|
52
|
-
*
|
|
53
|
-
*
|
|
54
|
-
*
|
|
55
|
-
*
|
|
56
|
-
*
|
|
57
|
-
*
|
|
58
|
-
*
|
|
59
|
-
*
|
|
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
|
-
*
|
|
67
|
-
*
|
|
68
|
-
*
|
|
69
|
-
*
|
|
74
|
+
* ```ts
|
|
75
|
+
* function addTranslations( language, translations, getPluralForm ) {
|
|
76
|
+
* if ( !global.window.CKEDITOR_TRANSLATIONS ) {
|
|
77
|
+
* global.window.CKEDITOR_TRANSLATIONS = {};
|
|
78
|
+
* }
|
|
70
79
|
|
|
71
|
-
*
|
|
72
|
-
*
|
|
73
|
-
*
|
|
80
|
+
* if ( !global.window.CKEDITOR_TRANSLATIONS[ language ] ) {
|
|
81
|
+
* global.window.CKEDITOR_TRANSLATIONS[ language ] = {};
|
|
82
|
+
* }
|
|
74
83
|
*
|
|
75
|
-
*
|
|
84
|
+
* const languageTranslations = global.window.CKEDITOR_TRANSLATIONS[ language ];
|
|
76
85
|
*
|
|
77
|
-
*
|
|
78
|
-
*
|
|
86
|
+
* languageTranslations.dictionary = languageTranslations.dictionary || {};
|
|
87
|
+
* languageTranslations.getPluralForm = getPluralForm || languageTranslations.getPluralForm;
|
|
79
88
|
*
|
|
80
|
-
*
|
|
81
|
-
*
|
|
82
|
-
*
|
|
89
|
+
* // Extend the dictionary for the given language.
|
|
90
|
+
* Object.assign( languageTranslations.dictionary, translations );
|
|
91
|
+
* }
|
|
92
|
+
* ```
|
|
83
93
|
*
|
|
84
|
-
* @param
|
|
85
|
-
* @param
|
|
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
|
|
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
|
-
*
|
|
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
|
-
*
|
|
116
|
-
*
|
|
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
|
-
*
|
|
122
|
-
*
|
|
135
|
+
* ```ts
|
|
136
|
+
* translate( 'en', { string: 'image', id: 'ADD_IMAGE' } );
|
|
137
|
+
* translate( 'en', { string: 'image', id: 'AN_IMAGE' } );
|
|
138
|
+
* ```
|
|
123
139
|
*
|
|
124
|
-
* @
|
|
125
|
-
* @param
|
|
126
|
-
* @param
|
|
127
|
-
* @param
|
|
128
|
-
* @returns
|
|
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
|
-
* @
|
|
184
|
+
* @internal
|
|
169
185
|
*/
|
|
170
186
|
export function _clear() {
|
|
171
187
|
global.window.CKEDITOR_TRANSLATIONS = {};
|
|
172
188
|
}
|
|
173
|
-
|
|
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
|
@@ -5,8 +5,10 @@
|
|
|
5
5
|
/**
|
|
6
6
|
* @module utils/uid
|
|
7
7
|
*/
|
|
8
|
-
|
|
9
|
-
|
|
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
|
|
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
|
@@ -10,8 +10,7 @@
|
|
|
10
10
|
/**
|
|
11
11
|
* Checks whether given `character` is a combining mark.
|
|
12
12
|
*
|
|
13
|
-
* @param
|
|
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
|
|
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
|
|
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
|
|
48
|
-
* @param
|
|
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
|
|
58
|
-
* @param
|
|
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
|
|
69
|
-
* @param
|
|
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
|
@@ -7,7 +7,7 @@
|
|
|
7
7
|
*/
|
|
8
8
|
/* globals window, global */
|
|
9
9
|
import CKEditorError from './ckeditorerror';
|
|
10
|
-
const version = '35.
|
|
10
|
+
const version = '35.4.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
|
-
*
|
|
29
|
-
*
|
|
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
|
-
*
|
|
58
|
-
*
|
|
59
|
-
*
|
|
60
|
-
*
|
|
61
|
-
*
|
|
62
|
-
*
|
|
63
|
-
*
|
|
64
|
-
*
|
|
65
|
-
*
|
|
66
|
-
*
|
|
67
|
-
*
|
|
68
|
-
*
|
|
69
|
-
*
|
|
70
|
-
*
|
|
71
|
-
*
|
|
72
|
-
*
|
|
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
|
-
*
|
|
79
|
-
*
|
|
80
|
-
*
|
|
81
|
-
*
|
|
82
|
-
*
|
|
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 — 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
|
|
126
|
+
* {@glink updating/versioning-policy Versioning policy} guide.
|
|
121
127
|
*
|
|
122
128
|
* # Packages were duplicated in `node_modules`
|
|
123
129
|
*
|