@ckeditor/ckeditor5-utils 43.1.0 → 43.2.0-alpha.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/dist/index.js CHANGED
@@ -953,143 +953,167 @@ diff.fastDiff = fastDiff;
953
953
  ];
954
954
  }
955
955
 
956
- const version = '43.1.0';
956
+ const version = '43.2.0-alpha.0';
957
957
  // The second argument is not a month. It is `monthIndex` and starts from `0`.
958
- const releaseDate = new Date(2024, 8, 5);
958
+ const releaseDate = new Date(2024, 8, 25);
959
959
  /* istanbul ignore next -- @preserve */ if (globalThis.CKEDITOR_VERSION) {
960
960
  /**
961
- * The best solution to avoid this error is migrating your CKEditor 5 instance to
962
- * {@glink updating/nim-migration/migration-to-new-installation-methods new installation methods}.
963
- *
964
- * Mentioned below are predefined builds, which are a deprecated installation method. The solutions
965
- * provided are kept here for legacy support only.
966
- *
967
- * This error is thrown when due to a mistake in how CKEditor 5 was installed or initialized, some
968
- * of its modules were duplicated (evaluated and executed twice). Module duplication leads to inevitable runtime
969
- * errors.
970
- *
971
- * There are many situations in which some modules can be loaded twice. In the worst case scenario,
972
- * you may need to check your project for each of these issues and fix them all.
973
- *
974
- * # Trying to add a plugin to an existing build
975
- *
976
- * If you import an existing CKEditor 5 build and a plugin like this:
977
- *
978
- * ```ts
979
- * import ClassicEditor from '@ckeditor/ckeditor5-build-classic';
980
- * import Highlight from '@ckeditor/ckeditor5-highlight/src/highlight';
961
+ * This error is thrown when, due to a mistake in the way CKEditor 5 was installed,
962
+ * imported, or initialized, some of its modules were evaluated and executed twice.
963
+ * Duplicate modules inevitably lead to runtime errors and increased bundle size.
964
+ *
965
+ * # Check dependency versions
966
+ *
967
+ * First, make sure that you use the latest version of all CKEditor 5 dependencies.
968
+ * Depending on the installation method, you should check the versions of the `ckeditor5`,
969
+ * `ckeditor5-premium-features`, or `@ckeditor/ckeditor5-<NAME>` packages. If you cannot update
970
+ * to the latest version, ensure that all the CKEditor&nbsp;5 packages are
971
+ * in the same version.
972
+ *
973
+ * If you use third-party plugins, make sure to update them, too. If they are incompatible
974
+ * with the version of CKEditor&nbsp;5 you use, you may need to downgrade the CKEditor&nbsp;5 packages
975
+ * (which we do not recommend). Ask the plugin's author to upgrade the dependencies,
976
+ * or fork their project and update it yourself.
977
+ *
978
+ * # Check imports
979
+ *
980
+ * The next step is to look at how you import CKEditor&nbsp;5 into your project.
981
+ *
982
+ * **The {@glink updating/nim-migration/migration-to-new-installation-methods new installation methods}
983
+ * are designed to prevent module duplication, so if you are not using them yet, you should consider
984
+ * updating your project**. However, several legacy installation methods are still supported for backward
985
+ * compatibility, and mixing them may result in module duplication.
986
+ *
987
+ * These are the most common import methods of the CKEditor&nbsp;5 packages.
988
+ *
989
+ * - **New installation methods (NIM)** &ndash; Imports from the `ckeditor5` and `ckeditor5-premium-features` packages.
990
+ * - **Optimized build** for the new installation methods &ndash; Imports from the `@ckeditor/ckeditor5-<NAME>/dist/index.js`.
991
+ * - **Predefined builds** (legacy) &ndash; Imports from the `@ckeditor/ckeditor5-build-<NAME>` packages.
992
+ * - **Default imports** (legacy) &ndash; Imports from the `@ckeditor/ckeditor5-<NAME>` packages (default export).
993
+ * - **`src`** (legacy) &ndash; Imports from the `@ckeditor/ckeditor5-<NAME>/src/*`.
994
+ * - **DLL builds** (legacy) &ndash; Imports from the `ckeditor5/build/<NAME>` and `@ckeditor/ckeditor5-<NAME>/build/*`.
995
+ *
996
+ * The best way to avoid duplicate modules is to avoid mixing these installation methods. For example, if you use imports
997
+ * specific to the optimized build, you should use them for all CKEditor&nbsp;5 packages. In addition, since
998
+ * the Predefined and DLL builds already include the core of the editor, they cannot be used with other types of imports.
999
+ *
1000
+ * Here is a matrix showing which installation methods are compatible with each other:
1001
+ *
1002
+ * | | NIM | Optimized build | Predefined builds | Default imports | `src` | DLL builds |
1003
+ * |------------------|-----|-----------------|-------------------|-----------------|-------|------------|
1004
+ * | NIM | ✅ | ✅ | ❌ | ❌ | ❌ | ❌ |
1005
+ * | Optimized builds | ✅ | ✅ | ❌ | ❌ | ❌ | ❌ |
1006
+ * | Predefined build | ❌ | ❌ | ✅ | ❌ | ❌ | ❌ |
1007
+ * | Default imports | ❌ | ❌ | ❌ | ✅ | ✅ | ❌ |
1008
+ * | `src` | ❌ | ❌ | ❌ | ✅ | ✅ | ❌ |
1009
+ * | DLL builds | ❌ | ❌ | ❌ | ❌ | ❌ | ✅ |
1010
+ *
1011
+ * If you use any third-party plugins, make sure the way you import them is compatible with
1012
+ * the way you import CKEditor&nbsp;5.
1013
+ *
1014
+ * <details>
1015
+ * <summary>New installation methods and optimized builds</summary>
1016
+ *
1017
+ * If you use the {@glink updating/nim-migration/migration-to-new-installation-methods new installation methods},
1018
+ * you should only import code from the `ckeditor5` and `ckeditor5-premium-features` packages.
1019
+ * Do not import code from the `@ckeditor/ckeditor5-<NAME>` packages unless you follow
1020
+ * the {@glink getting-started/setup/optimizing-build-size Optimizing build size} guide and the imports from
1021
+ * the `@ckeditor/ckeditor5-<NAME>` packages end with `/dist/index.js`.
1022
+ *
1023
+ * If you use a CDN, ensure that some files are not included twice in your project.
1024
+ *
1025
+ * Examples of valid and invalid import paths:
1026
+ *
1027
+ * ```js
1028
+ * import { ClassicEditor, Highlight } from 'ckeditor5'; // ✅
1029
+ * import { Highlight } from '@ckeditor/ckeditor5-highlight/dist/index.js'; // ✅
1030
+ * import Highlight from '@ckeditor/ckeditor5-highlight/src/highlight.js'; // ❌
1031
+ * import { Highlight } from '@ckeditor/ckeditor5-highlight'; // ❌
1032
+ * import '@ckeditor/ckeditor5-highlight/build/highlight.js'; // ❌
981
1033
  * ```
1034
+ * </details>
982
1035
  *
983
- * Then your project loads some CKEditor 5 packages twice. How does it happen?
1036
+ * <details>
1037
+ * <summary>(Legacy) Predefined builds</summary>
984
1038
  *
985
- * The build package contains a file which is already compiled with webpack. This means
986
- * that it contains all the necessary code from e.g. `@ckeditor/ckeditor5-engine` and `@ckeditor/ckeditor5-utils`.
1039
+ * If you use the {@glink getting-started/legacy/installation-methods/predefined-builds Predefined builds},
1040
+ * you cannot import any additional plugins. These builds already include the editor's core
1041
+ * and selected plugins and importing additional ones will cause some modules to be bundled and loaded twice.
987
1042
  *
988
- * However, the `Highlight` plugin imports some of the modules from these packages, too. If you ask webpack to
989
- * build such a project, you will end up with the modules being included (and run) twice &ndash; first, because they are
990
- * included inside the build package, and second, because they are required by the `Highlight` plugin.
1043
+ * Examples of valid and invalid import paths:
991
1044
  *
992
- * Therefore, **you must never add plugins to an existing build** unless your plugin has no dependencies.
993
- *
994
- * Adding plugins to a build is done by taking the source version of this build (so, before it was built with webpack)
995
- * and adding plugins there. In this situation, webpack will know that it only needs to load each plugin once.
996
- *
997
- * # Confused an editor build with an editor implementation
998
- *
999
- * This scenario is very similar to the previous one, but has a different origin.
1000
- *
1001
- * Let's assume that you wanted to use CKEditor 5 from source.
1002
- *
1003
- * The correct way to do so is to import an editor and plugins and run them together like this:
1004
- *
1005
- * ```ts
1006
- * import ClassicEditor from '@ckeditor/ckeditor5-editor-classic/src/classiceditor';
1007
- * import Essentials from '@ckeditor/ckeditor5-essentials/src/essentials';
1008
- * import Paragraph from '@ckeditor/ckeditor5-paragraph/src/paragraph';
1009
- * import Bold from '@ckeditor/ckeditor5-basic-styles/src/bold';
1010
- * import Italic from '@ckeditor/ckeditor5-basic-styles/src/italic';
1011
- *
1012
- * ClassicEditor
1013
- * .create( document.querySelector( '#editor' ), {
1014
- * plugins: [ Essentials, Paragraph, Bold, Italic ],
1015
- * toolbar: [ 'bold', 'italic' ]
1016
- * } )
1017
- * .then( editor => {
1018
- * console.log( 'Editor was initialized', editor );
1019
- * } )
1020
- * .catch( error => {
1021
- * console.error( error.stack );
1022
- * } );
1045
+ * ```js
1046
+ * import ClassicEditor from '@ckeditor/ckeditor5-build-classic'; // ✅
1047
+ * import { Highlight } from 'ckeditor5'; //
1048
+ * import { Highlight } from '@ckeditor/ckeditor5-highlight/dist/index.js'; //
1049
+ * import { Highlight } from '@ckeditor/ckeditor5-highlight'; // ❌
1050
+ * import Highlight from '@ckeditor/ckeditor5-highlight/src/highlight'; //
1051
+ * import '@ckeditor/ckeditor5-highlight/build/highlight'; // ❌
1023
1052
  * ```
1024
1053
  *
1025
- * However, you might have mistakenly imported a build instead of the source `ClassicEditor`. In this case
1026
- * your imports will look like this:
1027
- *
1028
- * ```ts
1029
- * import ClassicEditor from '@ckeditor/ckeditor5-build-classic';
1030
- * import Essentials from '@ckeditor/ckeditor5-essentials/src/essentials';
1031
- * import Paragraph from '@ckeditor/ckeditor5-paragraph/src/paragraph';
1032
- * import Bold from '@ckeditor/ckeditor5-basic-styles/src/bold';
1033
- * import Italic from '@ckeditor/ckeditor5-basic-styles/src/italic';
1054
+ * If you are missing some features from the
1055
+ * {@glink getting-started/legacy/installation-methods/predefined-builds#plugins-included-in-the-predefined-builds list of plugins},
1056
+ * you should switch to the {@glink updating/nim-migration/migration-to-new-installation-methods new installation methods}
1057
+ * which do not have this limitation.
1058
+ * If you cannot migrate to the new installation methods, try the
1059
+ * {@glink getting-started/legacy/installation-methods/predefined-builds#superbuild superbuild} instead.
1060
+ * This build contains all the editor features.
1061
+ * </details>
1062
+ *
1063
+ * <details>
1064
+ * <summary>(Legacy) Default imports and `src` imports</summary>
1065
+ *
1066
+ * If you use the {@glink getting-started/legacy/installation-methods/quick-start-other legacy customized installation}
1067
+ * method, you should only import code from the `@ckeditor/ckeditor5-<NAME>` packages. While you can import code from
1068
+ * the `@ckeditor/ckeditor5-<NAME>/src/*` files, it is not recommended as it can make migration to the new installation
1069
+ * methods more difficult.
1070
+ *
1071
+ * If you use this installation method, you should not import code from the `ckeditor5`, `ckeditor5-premium-features`,
1072
+ * or `@ckeditor/ckeditor5-build-<NAME>` packages.
1073
+ *
1074
+ * Examples of valid and invalid import paths:
1075
+ *
1076
+ * ```js
1077
+ * import { ClassicEditor } from '@ckeditor/ckeditor5-editor-classic'; // ✅
1078
+ * import { Highlight } from '@ckeditor/ckeditor5-highlight'; // ✅
1079
+ * import Highlight from '@ckeditor/ckeditor5-highlight/src/highlight.js'; // ✅ (not recommended)
1080
+ * import { Highlight } from 'ckeditor5'; // ❌
1081
+ * import { Highlight } from '@ckeditor/ckeditor5-highlight/dist/index.js'; // ❌
1082
+ * import '@ckeditor/ckeditor5-highlight/build/highlight'; // ❌
1034
1083
  * ```
1084
+ * </details>
1035
1085
  *
1036
- * This creates the same situation as in the previous section because you use a build together with source plugins.
1037
- *
1038
- * Remember: `@ckeditor/ckeditor5-build-*` packages contain editor builds and `@ckeditor/ckeditor5-editor-*` contain source editors.
1039
- *
1040
- * # Loading two or more builds on one page
1041
- *
1042
- * If you use CKEditor 5 builds, you might have loaded two (or more) `ckeditor.js` files on one web page.
1043
- * Check your web page for duplicated `<script>` elements or make sure your page builder/bundler includes CKEditor only once.
1044
- *
1045
- * If you want to use two different types of editors at once, see the
1046
- * {@glink getting-started/legacy/advanced/using-two-editors "Using two different editors"}
1047
- * section.
1048
- *
1049
- * # Using outdated packages
1086
+ * <details>
1087
+ * <summary>(Legacy) DLL builds</summary>
1050
1088
  *
1051
- * Building CKEditor 5 from source requires using multiple npm packages. These packages have their dependencies
1052
- * to other packages. If you use the latest version of, for example, `@ckeditor/ckeditor5-editor-classic` with
1053
- * an outdated version of `@ckeditor/ckeditor5-image`, npm or yarn will need to install two different versions of
1054
- * `@ckeditor/ckeditor5-core` because `@ckeditor/ckeditor5-editor-classic` and `@ckeditor/ckeditor5-image` may require
1055
- * different versions of the core package.
1089
+ * If you are using the {@glink getting-started/legacy/advanced/alternative-setups/dll-builds legacy DLL builds},
1090
+ * you should not import any non-DLL modules.
1056
1091
  *
1057
- * The solution to this issue is to update all packages to their latest version. We recommend
1058
- * using tools like [`npm-check-updates`](https://www.npmjs.com/package/npm-check-updates) which simplify this process.
1092
+ * Examples of valid and invalid import paths:
1059
1093
  *
1060
- * # Conflicting version of dependencies
1061
- *
1062
- * This is a special case of the previous scenario. If you use CKEditor 5 with some third-party plugins,
1063
- * it may happen that even if you use the latest versions of the official packages and the latest version of
1064
- * these third-party packages, there will be a conflict between some of their dependencies.
1065
- *
1066
- * Such a problem can be resolved by either downgrading CKEditor 5 packages (which we do not recommend) or
1067
- * asking the author of the third-party package to upgrade its depdendencies (or forking their project and doing this yourself).
1068
- *
1069
- * **Note:** All official CKEditor 5 packages (excluding integrations and `ckeditor5-dev-*` packages) are released in the
1070
- * same major version. This means that in the `x.y.z` version, the `x` is the same for all packages. This is the simplest way to check
1071
- * whether you use packages coming from the same CKEditor 5 version. You can read more about versioning in the
1072
- * {@glink updating/versioning-policy Versioning policy} guide.
1073
- *
1074
- * # Packages were duplicated in `node_modules`
1075
- *
1076
- * In some situations, especially when calling `npm install` multiple times, it may happen
1077
- * that npm will not correctly "deduplicate" packages.
1094
+ * ```js
1095
+ * import 'ckeditor5/build/ckeditor5-dll.js';// ✅
1096
+ * import '@ckeditor/ckeditor5-editor-classic/build/editor-classic.js';//
1097
+ * import '@ckeditor/ckeditor5-highlight/build/highlight.js';//
1098
+ * import { Highlight } from 'ckeditor5'; //
1099
+ * import { Highlight } from '@ckeditor/ckeditor5-highlight/dist/index.js'; // ❌
1100
+ * import { Highlight } from '@ckeditor/ckeditor5-highlight'; //
1101
+ * import Highlight from '@ckeditor/ckeditor5-highlight/src/highlight.js'; //
1102
+ * ```
1103
+ * </details>
1078
1104
  *
1079
- * Normally, npm deduplicates all packages so, for example, `@ckeditor/ckeditor5-core` is installed only once in `node_modules/`.
1080
- * However, it is known to fail to do so from time to time.
1105
+ * # Reinstall `node_modules`
1081
1106
  *
1082
- * We recommend checking if any of the steps listed below help:
1107
+ * Usually, npm and other package managers deduplicate all packages - for example, `ckeditor5` is only installed once
1108
+ * in `node_modules/`. However, it is known to fail to do so occasionally.
1083
1109
  *
1084
- * * `rm -rf node_modules && npm install` to make sure you have a clean `node_modules/` directory. This step
1085
- * is known to help in most cases.
1086
- * * If you use `yarn.lock` or `package-lock.json`, remove it before `npm install`.
1087
- * * Check whether all CKEditor 5 packages are up to date and reinstall them
1088
- * if you changed anything (`rm -rf node_modules && npm install`).
1110
+ * To rule out this possibility, you can try the following:
1089
1111
  *
1090
- * If all packages are correct and compatible with each other, the steps above are known to help. If not, you may
1091
- * try to check with `npm ls` how many times packages like `@ckeditor/ckeditor5-core`, `@ckeditor/ckeditor5-engine` and
1092
- *`@ckeditor/ckeditor5-utils` are installed. If more than once, verify which package causes that.
1112
+ * 1. Remove the `node_modules` directory.
1113
+ * 2. Remove the `package-lock.json`, `yarn.lock`, or `pnpm-lock.yaml` files (depending on the package manager used).
1114
+ * 3. Run `npm install` to reinstall all packages.
1115
+ * 4. Run `npm ls` to check how many times packages like `@ckeditor/ckeditor5-core` are installed.
1116
+ * If they are installed more than once, verify which package causes that.
1093
1117
  *
1094
1118
  * @error ckeditor-duplicated-modules
1095
1119
  */ throw new CKEditorError('ckeditor-duplicated-modules', null);
@@ -2181,6 +2205,7 @@ function initObservable(observable) {
2181
2205
  * @returns Number of items returned by that iterable.
2182
2206
  */ function count(iterable) {
2183
2207
  let count = 0;
2208
+ // eslint-disable-next-line @typescript-eslint/no-unused-vars
2184
2209
  for (const _ of iterable){
2185
2210
  count++;
2186
2211
  }
@@ -2291,7 +2316,7 @@ function initObservable(observable) {
2291
2316
  * @param configurations The initial configurations to be set. Usually, provided by the user.
2292
2317
  * @param defaultConfigurations The default configurations. Usually, provided by the system.
2293
2318
  */ constructor(configurations, defaultConfigurations){
2294
- this._config = {};
2319
+ this._config = Object.create(null);
2295
2320
  // Set default configuration.
2296
2321
  if (defaultConfigurations) {
2297
2322
  // Clone the configuration to make sure that the properties will not be shared
@@ -2357,7 +2382,7 @@ function initObservable(observable) {
2357
2382
  for (const part of parts){
2358
2383
  // If there is no object for specified part then create one.
2359
2384
  if (!isPlainObject(target[part])) {
2360
- target[part] = {};
2385
+ target[part] = Object.create(null);
2361
2386
  }
2362
2387
  // Nested object becomes a target.
2363
2388
  target = target[part];
@@ -2366,7 +2391,7 @@ function initObservable(observable) {
2366
2391
  if (isPlainObject(value)) {
2367
2392
  // We take care of proper config structure.
2368
2393
  if (!isPlainObject(target[name])) {
2369
- target[name] = {};
2394
+ target[name] = Object.create(null);
2370
2395
  }
2371
2396
  target = target[name];
2372
2397
  // And iterate through this object calling `_setToTarget` again for each property.