@ckeditor/ckeditor5-utils 34.0.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 +3 -3
  3. package/package.json +19 -8
  4. package/src/areconnectedthroughproperties.js +0 -92
  5. package/src/ckeditorerror.js +0 -218
  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
package/src/priorities.js DELETED
@@ -1,44 +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/priorities
8
- */
9
-
10
- /**
11
- * String representing a priority value.
12
- *
13
- * @typedef {'highest'|'high'|'normal'|'low'|'lowest'} module:utils/priorities~PriorityString
14
- */
15
-
16
- /**
17
- * Provides group of constants to use instead of hardcoding numeric priority values.
18
- *
19
- * @namespace
20
- */
21
- const priorities = {
22
- /**
23
- * Converts a string with priority name to it's numeric value. If `Number` is given, it just returns it.
24
- *
25
- * @static
26
- * @param {module:utils/priorities~PriorityString|Number} priority Priority to convert.
27
- * @returns {Number} Converted priority.
28
- */
29
- get( priority ) {
30
- if ( typeof priority != 'number' ) {
31
- return this[ priority ] || this.normal;
32
- } else {
33
- return priority;
34
- }
35
- },
36
-
37
- highest: 100000,
38
- high: 1000,
39
- normal: 0,
40
- low: -1000,
41
- lowest: -100000
42
- };
43
-
44
- export default priorities;
package/src/spy.js DELETED
@@ -1,25 +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/spy
8
- */
9
-
10
- /**
11
- * Creates a spy function (ala Sinon.js) that can be used to inspect call to it.
12
- *
13
- * The following are the present features:
14
- *
15
- * * spy.called: property set to `true` if the function has been called at least once.
16
- *
17
- * @returns {Function} The spy function.
18
- */
19
- function spy() {
20
- return function spy() {
21
- spy.called = true;
22
- };
23
- }
24
-
25
- export default spy;
package/src/toarray.js DELETED
@@ -1,18 +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/toarray
8
- */
9
-
10
- /**
11
- * Transforms any value to an array. If the provided value is already an array, it is returned unchanged.
12
- *
13
- * @param {*} data The value to transform to an array.
14
- * @returns {Array} An array created from data.
15
- */
16
- export default function toArray( data ) {
17
- return Array.isArray( data ) ? data : [ data ];
18
- }
package/src/tomap.js DELETED
@@ -1,29 +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/tomap
8
- */
9
-
10
- import objectToMap from './objecttomap';
11
- import isIterable from './isiterable';
12
-
13
- /**
14
- * Transforms object or iterable to map. Iterable needs to be in the format acceptable by the `Map` constructor.
15
- *
16
- * map = toMap( { 'foo': 1, 'bar': 2 } );
17
- * map = toMap( [ [ 'foo', 1 ], [ 'bar', 2 ] ] );
18
- * map = toMap( anotherMap );
19
- *
20
- * @param {Object|Iterable} data Object or iterable to transform.
21
- * @returns {Map} Map created from data.
22
- */
23
- export default function toMap( data ) {
24
- if ( isIterable( data ) ) {
25
- return new Map( data );
26
- } else {
27
- return objectToMap( data );
28
- }
29
- }
@@ -1,216 +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
- /* globals window */
7
-
8
- /**
9
- * @module utils/translation-service
10
- */
11
-
12
- import CKEditorError from './ckeditorerror';
13
-
14
- /* istanbul ignore else */
15
- if ( !window.CKEDITOR_TRANSLATIONS ) {
16
- window.CKEDITOR_TRANSLATIONS = {};
17
- }
18
-
19
- /**
20
- * Adds translations to existing ones or overrides the existing translations. These translations will later
21
- * be available for the {@link module:utils/locale~Locale#t `t()`} function.
22
- *
23
- * The `translations` is an object which consists of `messageId: translation` pairs. Note that the message ID can be
24
- * either constructed from the message string or from the message ID if it was passed
25
- * (this happens rarely and mostly for short messages or messages with placeholders).
26
- * Since the editor displays only the message string, the message ID can be found either in the source code or in the
27
- * built translations for another language.
28
- *
29
- * add( 'pl', {
30
- * 'Cancel': 'Anuluj',
31
- * 'IMAGE': 'obraz', // Note that the `IMAGE` comes from the message ID, while the string can be `image`.
32
- * } );
33
- *
34
- * If the message is supposed to support various plural forms, make sure to provide an array with the singular form and all plural forms:
35
- *
36
- * add( 'pl', {
37
- * 'Add space': [ 'Dodaj spację', 'Dodaj %0 spacje', 'Dodaj %0 spacji' ]
38
- * } );
39
- *
40
- * You should also specify the third argument (the `getPluralForm()` function) that will be used to determine the plural form if no
41
- * language file was loaded for that language. All language files coming from CKEditor 5 sources will have this option set, so
42
- * these plural form rules will be reused by other translations added to the registered languages. The `getPluralForm()` function
43
- * can return either a Boolean or a number.
44
- *
45
- * add( 'en', {
46
- * // ... Translations.
47
- * }, n => n !== 1 );
48
- * add( 'pl', {
49
- * // ... Translations.
50
- * }, n => n == 1 ? 0 : n % 10 >= 2 && n % 10 <= 4 && ( n % 100 < 10 || n % 100 >= 20 ) ? 1 : 2 );
51
- *
52
- * All translations extend the global `window.CKEDITOR_TRANSLATIONS` object. An example of this object can be found below:
53
- *
54
- * {
55
- * pl: {
56
- * dictionary: {
57
- * 'Cancel': 'Anuluj',
58
- * 'Add space': [ 'Dodaj spację', 'Dodaj %0 spacje', 'Dodaj %0 spacji' ]
59
- * },
60
- * // A function that returns the plural form index.
61
- * getPluralForm: n => n !==1
62
- * }
63
- * // Other languages.
64
- * }
65
- *
66
- * If you cannot import this function from this module (e.g. because you use a CKEditor 5 build), you can
67
- * still add translations by extending the global `window.CKEDITOR_TRANSLATIONS` object by using a function like
68
- * the one below:
69
- *
70
- * function addTranslations( language, translations, getPluralForm ) {
71
- * if ( !window.CKEDITOR_TRANSLATIONS ) {
72
- * window.CKEDITOR_TRANSLATIONS = {};
73
- * }
74
-
75
- * if ( !window.CKEDITOR_TRANSLATIONS[ language ] ) {
76
- * window.CKEDITOR_TRANSLATIONS[ language ] = {};
77
- * }
78
- *
79
- * const languageTranslations = window.CKEDITOR_TRANSLATIONS[ language ];
80
- *
81
- * languageTranslations.dictionary = languageTranslations.dictionary || {};
82
- * languageTranslations.getPluralForm = getPluralForm || languageTranslations.getPluralForm;
83
- *
84
- * // Extend the dictionary for the given language.
85
- * Object.assign( languageTranslations.dictionary, translations );
86
- * }
87
- *
88
- * @param {String} language Target language.
89
- * @param {Object.<String,*>} translations An object with translations which will be added to the dictionary.
90
- * For each message ID the value should be either a translation or an array of translations if the message
91
- * should support plural forms.
92
- * @param {Function} getPluralForm A function that returns the plural form index (a number).
93
- */
94
- export function add( language, translations, getPluralForm ) {
95
- if ( !window.CKEDITOR_TRANSLATIONS[ language ] ) {
96
- window.CKEDITOR_TRANSLATIONS[ language ] = {};
97
- }
98
-
99
- const languageTranslations = window.CKEDITOR_TRANSLATIONS[ language ];
100
-
101
- languageTranslations.dictionary = languageTranslations.dictionary || {};
102
- languageTranslations.getPluralForm = getPluralForm || languageTranslations.getPluralForm;
103
-
104
- Object.assign( languageTranslations.dictionary, translations );
105
- }
106
-
107
- /**
108
- * **Note:** This method is internal, use {@link module:utils/locale~Locale#t the `t()` function} instead to translate
109
- * the editor UI parts.
110
- *
111
- * This function is responsible for translating messages to the specified language. It uses translations added perviously
112
- * by {@link module:utils/translation-service~add} (a translations dictionary and the `getPluralForm()` function
113
- * to provide accurate translations of plural forms).
114
- *
115
- * When no translation is defined in the dictionary or the dictionary does not exist, this function returns
116
- * the original message string or the message plural depending on the number of elements.
117
- *
118
- * translate( 'pl', { string: 'Cancel' } ); // 'Cancel'
119
- *
120
- * The third optional argument is the number of elements, based on which the single form or one of the plural forms
121
- * should be picked when the message is supposed to support various plural forms.
122
- *
123
- * translate( 'en', { string: 'Add a space', plural: 'Add %0 spaces' }, 1 ); // 'Add a space'
124
- * translate( 'en', { string: 'Add a space', plural: 'Add %0 spaces' }, 3 ); // 'Add %0 spaces'
125
- *
126
- * The message should provide an ID using the `id` property when the message strings are not unique and their
127
- * translations should be different.
128
- *
129
- * translate( 'en', { string: 'image', id: 'ADD_IMAGE' } );
130
- * translate( 'en', { string: 'image', id: 'AN_IMAGE' } );
131
- *
132
- * @protected
133
- * @param {String} language Target language.
134
- * @param {module:utils/translation-service~Message} message A message that will be translated.
135
- * @param {Number} [quantity] The number of elements for which a plural form should be picked from the target language dictionary.
136
- * @returns {String} Translated sentence.
137
- */
138
- export function _translate( language, message, quantity = 1 ) {
139
- if ( typeof quantity !== 'number' ) {
140
- /**
141
- * An incorrect value was passed to the translation function. This was probably caused
142
- * by an incorrect message interpolation of a plural form. Note that for messages supporting plural forms
143
- * the second argument of the `t()` function should always be a number or an array with a number as the first element.
144
- *
145
- * @error translation-service-quantity-not-a-number
146
- */
147
- throw new CKEditorError( 'translation-service-quantity-not-a-number', null, { quantity } );
148
- }
149
-
150
- const numberOfLanguages = getNumberOfLanguages();
151
-
152
- if ( numberOfLanguages === 1 ) {
153
- // Override the language to the only supported one.
154
- // This can't be done in the `Locale` class, because the translations comes after the `Locale` class initialization.
155
- language = Object.keys( window.CKEDITOR_TRANSLATIONS )[ 0 ];
156
- }
157
-
158
- const messageId = message.id || message.string;
159
-
160
- if ( numberOfLanguages === 0 || !hasTranslation( language, messageId ) ) {
161
- if ( quantity !== 1 ) {
162
- // Return the default plural form that was passed in the `message.plural` parameter.
163
- return message.plural;
164
- }
165
-
166
- return message.string;
167
- }
168
-
169
- const dictionary = window.CKEDITOR_TRANSLATIONS[ language ].dictionary;
170
- const getPluralForm = window.CKEDITOR_TRANSLATIONS[ language ].getPluralForm || ( n => n === 1 ? 0 : 1 );
171
-
172
- if ( typeof dictionary[ messageId ] === 'string' ) {
173
- return dictionary[ messageId ];
174
- }
175
-
176
- const pluralFormIndex = Number( getPluralForm( quantity ) );
177
-
178
- // Note: The `translate` function is not responsible for replacing `%0, %1, ...` with values.
179
- return dictionary[ messageId ][ pluralFormIndex ];
180
- }
181
-
182
- /**
183
- * Clears dictionaries for test purposes.
184
- *
185
- * @protected
186
- */
187
- export function _clear() {
188
- window.CKEDITOR_TRANSLATIONS = {};
189
- }
190
-
191
- // Checks whether the dictionary exists and translation in that dictionary exists.
192
- function hasTranslation( language, messageId ) {
193
- return (
194
- !!window.CKEDITOR_TRANSLATIONS[ language ] &&
195
- !!window.CKEDITOR_TRANSLATIONS[ language ].dictionary[ messageId ]
196
- );
197
- }
198
-
199
- function getNumberOfLanguages() {
200
- return Object.keys( window.CKEDITOR_TRANSLATIONS ).length;
201
- }
202
-
203
- /**
204
- * The internationalization message interface. A message that implements this interface can be passed to the `t()` function
205
- * to be translated to the target UI language.
206
- *
207
- * @typedef {Object} module:utils/translation-service~Message
208
- *
209
- * @property {String} string The message string to translate. Acts as a default translation if the translation for a given language
210
- * is not defined. When the message is supposed to support plural forms, the string should be the English singular form of the message.
211
- * @property {String} [id] The message ID. If passed, the message ID is taken from this property instead of the `message.string`.
212
- * This property is useful when various messages share the same message string, for example, the `editor` string in `in the editor`
213
- * and `my editor` sentences.
214
- * @property {String} [plural] The plural form of the message. This property should be skipped when a message is not supposed
215
- * to support plural forms. Otherwise it should always be set to a string with the English plural form of the message.
216
- */
package/src/uid.js DELETED
@@ -1,59 +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/uid
8
- */
9
-
10
- // A hash table of hex numbers to avoid using toString() in uid() which is costly.
11
- // [ '00', '01', '02', ..., 'fe', 'ff' ]
12
- const HEX_NUMBERS = new Array( 256 ).fill()
13
- .map( ( val, index ) => ( '0' + ( index ).toString( 16 ) ).slice( -2 ) );
14
-
15
- /**
16
- * Returns a unique id. The id starts with an "e" character and a randomly generated string of
17
- * 32 alphanumeric characters.
18
- *
19
- * **Note**: The characters the unique id is built from correspond to the hex number notation
20
- * (from "0" to "9", from "a" to "f"). In other words, each id corresponds to an "e" followed
21
- * by 16 8-bit numbers next to each other.
22
- *
23
- * @returns {String} An unique id string.
24
- */
25
- export default function uid() {
26
- // Let's create some positive random 32bit integers first.
27
- //
28
- // 1. Math.random() is a float between 0 and 1.
29
- // 2. 0x100000000 is 2^32 = 4294967296.
30
- // 3. >>> 0 enforces integer (in JS all numbers are floating point).
31
- //
32
- // For instance:
33
- // Math.random() * 0x100000000 = 3366450031.853859
34
- // but
35
- // Math.random() * 0x100000000 >>> 0 = 3366450031.
36
- const r1 = Math.random() * 0x100000000 >>> 0;
37
- const r2 = Math.random() * 0x100000000 >>> 0;
38
- const r3 = Math.random() * 0x100000000 >>> 0;
39
- const r4 = Math.random() * 0x100000000 >>> 0;
40
-
41
- // Make sure that id does not start with number.
42
- return 'e' +
43
- HEX_NUMBERS[ r1 >> 0 & 0xFF ] +
44
- HEX_NUMBERS[ r1 >> 8 & 0xFF ] +
45
- HEX_NUMBERS[ r1 >> 16 & 0xFF ] +
46
- HEX_NUMBERS[ r1 >> 24 & 0xFF ] +
47
- HEX_NUMBERS[ r2 >> 0 & 0xFF ] +
48
- HEX_NUMBERS[ r2 >> 8 & 0xFF ] +
49
- HEX_NUMBERS[ r2 >> 16 & 0xFF ] +
50
- HEX_NUMBERS[ r2 >> 24 & 0xFF ] +
51
- HEX_NUMBERS[ r3 >> 0 & 0xFF ] +
52
- HEX_NUMBERS[ r3 >> 8 & 0xFF ] +
53
- HEX_NUMBERS[ r3 >> 16 & 0xFF ] +
54
- HEX_NUMBERS[ r3 >> 24 & 0xFF ] +
55
- HEX_NUMBERS[ r4 >> 0 & 0xFF ] +
56
- HEX_NUMBERS[ r4 >> 8 & 0xFF ] +
57
- HEX_NUMBERS[ r4 >> 16 & 0xFF ] +
58
- HEX_NUMBERS[ r4 >> 24 & 0xFF ];
59
- }
package/src/unicode.js DELETED
@@ -1,106 +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
- * Set of utils to handle unicode characters.
8
- *
9
- * @module utils/unicode
10
- */
11
-
12
- /**
13
- * Checks whether given `character` is a combining mark.
14
- *
15
- * @param {String} character Character to check.
16
- * @returns {Boolean}
17
- */
18
- export function isCombiningMark( character ) {
19
- // eslint-disable-next-line no-misleading-character-class
20
- return !!character && character.length == 1 && /[\u0300-\u036f\u1ab0-\u1aff\u1dc0-\u1dff\u20d0-\u20ff\ufe20-\ufe2f]/.test( character );
21
- }
22
-
23
- /**
24
- * Checks whether given `character` is a high half of surrogate pair.
25
- *
26
- * Using UTF-16 terminology, a surrogate pair denotes UTF-16 character using two UTF-8 characters. The surrogate pair
27
- * consist of high surrogate pair character followed by low surrogate pair character.
28
- *
29
- * @param {String} character Character to check.
30
- * @returns {Boolean}
31
- */
32
- export function isHighSurrogateHalf( character ) {
33
- return !!character && character.length == 1 && /[\ud800-\udbff]/.test( character );
34
- }
35
-
36
- /**
37
- * Checks whether given `character` is a low half of surrogate pair.
38
- *
39
- * Using UTF-16 terminology, a surrogate pair denotes UTF-16 character using two UTF-8 characters. The surrogate pair
40
- * consist of high surrogate pair character followed by low surrogate pair character.
41
- *
42
- * @param {String} character Character to check.
43
- * @returns {Boolean}
44
- */
45
- export function isLowSurrogateHalf( character ) {
46
- return !!character && character.length == 1 && /[\udc00-\udfff]/.test( character );
47
- }
48
-
49
- /**
50
- * Checks whether given offset in a string is inside a surrogate pair (between two surrogate halves).
51
- *
52
- * @param {String} string String to check.
53
- * @param {Number} offset Offset to check.
54
- * @returns {Boolean}
55
- */
56
- export function isInsideSurrogatePair( string, offset ) {
57
- return isHighSurrogateHalf( string.charAt( offset - 1 ) ) && isLowSurrogateHalf( string.charAt( offset ) );
58
- }
59
-
60
- /**
61
- * Checks whether given offset in a string is between base character and combining mark or between two combining marks.
62
- *
63
- * @param {String} string String to check.
64
- * @param {Number} offset Offset to check.
65
- * @returns {Boolean}
66
- */
67
- export function isInsideCombinedSymbol( string, offset ) {
68
- return isCombiningMark( string.charAt( offset ) );
69
- }
70
-
71
- const EMOJI_PATTERN = buildEmojiRegexp();
72
-
73
- /**
74
- * Checks whether given offset in a string is inside multi-character emoji sequence.
75
- *
76
- * @param {String} string String to check.
77
- * @param {Number} offset Offset to check.
78
- * @returns {Boolean}
79
- */
80
- export function isInsideEmojiSequence( string, offset ) {
81
- const matches = String( string ).matchAll( EMOJI_PATTERN );
82
-
83
- return Array.from( matches ).some( match => match.index < offset && offset < match.index + match[ 0 ].length );
84
- }
85
-
86
- function buildEmojiRegexp() {
87
- const parts = [
88
- // Emoji Tag Sequence (ETS)
89
- /\p{Emoji}[\u{E0020}-\u{E007E}]+\u{E007F}/u,
90
-
91
- // Emoji Keycap Sequence
92
- /\p{Emoji}\u{FE0F}?\u{20E3}/u,
93
-
94
- // Emoji Presentation Sequence
95
- /\p{Emoji}\u{FE0F}/u,
96
-
97
- // Single-Character Emoji / Emoji Modifier Sequence
98
- /(?=\p{General_Category=Other_Symbol})\p{Emoji}\p{Emoji_Modifier}*/u
99
- ];
100
-
101
- const flagSequence = /\p{Regional_Indicator}{2}/u.source;
102
- const emoji = '(?:' + parts.map( part => part.source ).join( '|' ) + ')';
103
- const sequence = `${ flagSequence }|${ emoji }(?:\u{200D}${ emoji })*`;
104
-
105
- return new RegExp( sequence, 'ug' );
106
- }
package/src/version.js DELETED
@@ -1,157 +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/version
8
- */
9
-
10
- /* globals window, global */
11
-
12
- import CKEditorError from './ckeditorerror';
13
-
14
- const version = '34.0.0';
15
-
16
- export default version;
17
-
18
- /* istanbul ignore next */
19
- const windowOrGlobal = typeof window === 'object' ? window : global;
20
-
21
- /* istanbul ignore next */
22
- if ( windowOrGlobal.CKEDITOR_VERSION ) {
23
- /**
24
- * This error is thrown when due to a mistake in how CKEditor 5 was installed or initialized, some
25
- * of its modules were duplicated (evaluated and executed twice). Module duplication leads to inevitable runtime
26
- * errors.
27
- *
28
- * There are many situations in which some modules can be loaded twice. In the worst case scenario,
29
- * you may need to check your project for each of these issues and fix them all.
30
- *
31
- * # Trying to add a plugin to an existing build
32
- *
33
- * If you import an existing CKEditor 5 build and a plugin like this:
34
- *
35
- * import ClassicEditor from '@ckeditor/ckeditor5-build-classic';
36
- * import Highlight from '@ckeditor/ckeditor5-highlight/src/highlight';
37
- *
38
- * Then your project loads some CKEditor 5 packages twice. How does it happen?
39
- *
40
- * The build package contains a file which is already compiled with webpack. This means
41
- * that it contains all the necessary code from e.g. `@ckeditor/ckeditor5-engine` and `@ckeditor/ckeditor5-utils`.
42
- *
43
- * However, the `Highlight` plugin imports some of the modules from these packages, too. If you ask webpack to
44
- * build such a project, you will end up with the modules being included (and run) twice &mdash; first, because they are
45
- * included inside the build package, and second, because they are required by the `Highlight` plugin.
46
- *
47
- * Therefore, **you must never add plugins to an existing build** unless your plugin has no dependencies.
48
- *
49
- * Adding plugins to a build is done by taking the source version of this build (so, before it was built with webpack)
50
- * and adding plugins there. In this situation, webpack will know that it only needs to load each plugin once.
51
- *
52
- * Read more in the {@glink installation/getting-started/installing-plugins "Installing plugins"} guide.
53
- *
54
- * # Confused an editor build with an editor implementation
55
- *
56
- * This scenario is very similar to the previous one, but has a different origin.
57
- *
58
- * Let's assume that you wanted to use CKEditor 5 from source, as explained in the
59
- * {@glink installation/advanced/alternative-setups/integrating-from-source "Building from source"} section
60
- * or in the {@glink framework/guides/quick-start "Quick start"} guide of CKEditor 5 Framework.
61
- *
62
- * The correct way to do so is to import an editor and plugins and run them together like this:
63
- *
64
- * import ClassicEditor from '@ckeditor/ckeditor5-editor-classic/src/classiceditor';
65
- * import Essentials from '@ckeditor/ckeditor5-essentials/src/essentials';
66
- * import Paragraph from '@ckeditor/ckeditor5-paragraph/src/paragraph';
67
- * import Bold from '@ckeditor/ckeditor5-basic-styles/src/bold';
68
- * import Italic from '@ckeditor/ckeditor5-basic-styles/src/italic';
69
- *
70
- * ClassicEditor
71
- * .create( document.querySelector( '#editor' ), {
72
- * plugins: [ Essentials, Paragraph, Bold, Italic ],
73
- * toolbar: [ 'bold', 'italic' ]
74
- * } )
75
- * .then( editor => {
76
- * console.log( 'Editor was initialized', editor );
77
- * } )
78
- * .catch( error => {
79
- * console.error( error.stack );
80
- * } );
81
- *
82
- * However, you might have mistakenly imported a build instead of the source `ClassicEditor`. In this case
83
- * your imports will look like this:
84
- *
85
- * import ClassicEditor from '@ckeditor/ckeditor5-build-classic';
86
- * import Essentials from '@ckeditor/ckeditor5-essentials/src/essentials';
87
- * import Paragraph from '@ckeditor/ckeditor5-paragraph/src/paragraph';
88
- * import Bold from '@ckeditor/ckeditor5-basic-styles/src/bold';
89
- * import Italic from '@ckeditor/ckeditor5-basic-styles/src/italic';
90
- *
91
- * This creates the same situation as in the previous section because you use a build together with source plugins.
92
- *
93
- * Remember: `@ckeditor/ckeditor5-build-*` packages contain editor builds and `@ckeditor/ckeditor5-editor-*` contain source editors.
94
- *
95
- * # Loading two or more builds on one page
96
- *
97
- * If you use CKEditor 5 builds, you might have loaded two (or more) `ckeditor.js` files on one web page.
98
- * Check your web page for duplicated `<script>` elements or make sure your page builder/bundler includes CKEditor only once.
99
- *
100
- * If you want to use two different types of editors at once, see the
101
- * {@glink installation/advanced/using-two-editors "Using two different editors"}
102
- * section.
103
- *
104
- * # Using outdated packages
105
- *
106
- * Building CKEditor 5 from source requires using multiple npm packages. These packages have their dependencies
107
- * to other packages. If you use the latest version of, for example, `@ckeditor/ckeditor5-editor-classic` with
108
- * an outdated version of `@ckeditor/ckeditor5-image`, npm or yarn will need to install two different versions of
109
- * `@ckeditor/ckeditor5-core` because `@ckeditor/ckeditor5-editor-classic` and `@ckeditor/ckeditor5-image` may require
110
- * different versions of the core package.
111
- *
112
- * The solution to this issue is to update all packages to their latest version. We recommend
113
- * using tools like [`npm-check-updates`](https://www.npmjs.com/package/npm-check-updates) which simplify this process.
114
- *
115
- * # Conflicting version of dependencies
116
- *
117
- * This is a special case of the previous scenario. If you use CKEditor 5 with some third-party plugins,
118
- * it may happen that even if you use the latest versions of the official packages and the latest version of
119
- * these third-party packages, there will be a conflict between some of their dependencies.
120
- *
121
- * Such a problem can be resolved by either downgrading CKEditor 5 packages (which we do not recommend) or
122
- * asking the author of the third-party package to upgrade its depdendencies (or forking their project and doing this yourself).
123
- *
124
- * **Note:** All official CKEditor 5 packages (excluding integrations and `ckeditor5-dev-*` packages) are released in the
125
- * 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
126
- * whether you use packages coming from the same CKEditor 5 version. You can read more about versioning in the
127
- * {@glink support/versioning-policy Versioning policy} guide.
128
- *
129
- * # Packages were duplicated in `node_modules`
130
- *
131
- * In some situations, especially when calling `npm install` multiple times, it may happen
132
- * that npm will not correctly "deduplicate" packages.
133
- *
134
- * Normally, npm deduplicates all packages so, for example, `@ckeditor/ckeditor5-core` is installed only once in `node_modules/`.
135
- * However, it is known to fail to do so from time to time.
136
- *
137
- * We recommend checking if any of the steps listed below help:
138
- *
139
- * * `rm -rf node_modules && npm install` to make sure you have a clean `node_modules/` directory. This step
140
- * is known to help in most cases.
141
- * * If you use `yarn.lock` or `package-lock.json`, remove it before `npm install`.
142
- * * Check whether all CKEditor 5 packages are up to date and reinstall them
143
- * if you changed anything (`rm -rf node_modules && npm install`).
144
- *
145
- * If all packages are correct and compatible with each other, the steps above are known to help. If not, you may
146
- * try to check with `npm ls` how many times packages like `@ckeditor/ckeditor5-core`, `@ckeditor/ckeditor5-engine` and
147
- *`@ckeditor/ckeditor5-utils` are installed. If more than once, verify which package causes that.
148
- *
149
- * @error ckeditor-duplicated-modules
150
- */
151
- throw new CKEditorError(
152
- 'ckeditor-duplicated-modules',
153
- null
154
- );
155
- } else {
156
- windowOrGlobal.CKEDITOR_VERSION = version;
157
- }