@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
package/LICENSE.md CHANGED
@@ -2,7 +2,7 @@ Software License Agreement
2
2
  ==========================
3
3
 
4
4
  **CKEditor 5 utilities** – https://github.com/ckeditor/ckeditor5-utils <br>
5
- Copyright (c) 2003-2022, [CKSource Holding sp. z o.o.](https://cksource.com) All rights reserved.
5
+ Copyright (c) 2003-2023, [CKSource Holding sp. z o.o.](https://cksource.com) All rights reserved.
6
6
 
7
7
  Licensed under the terms of [GNU General Public License Version 2 or later](http://www.gnu.org/licenses/gpl.html).
8
8
 
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@ckeditor/ckeditor5-utils",
3
- "version": "35.3.2",
3
+ "version": "36.0.0",
4
4
  "description": "Miscellaneous utilities used by CKEditor 5.",
5
5
  "keywords": [
6
6
  "ckeditor",
@@ -14,10 +14,10 @@
14
14
  "lodash-es": "^4.17.15"
15
15
  },
16
16
  "devDependencies": {
17
- "@ckeditor/ckeditor5-build-classic": "^35.3.2",
18
- "@ckeditor/ckeditor5-editor-classic": "^35.3.2",
19
- "@ckeditor/ckeditor5-core": "^35.3.2",
20
- "@ckeditor/ckeditor5-engine": "^35.3.2",
17
+ "@ckeditor/ckeditor5-build-classic": "^36.0.0",
18
+ "@ckeditor/ckeditor5-editor-classic": "^36.0.0",
19
+ "@ckeditor/ckeditor5-core": "^36.0.0",
20
+ "@ckeditor/ckeditor5-engine": "^36.0.0",
21
21
  "@types/lodash-es": "^4.17.6",
22
22
  "typescript": "^4.8.4"
23
23
  },
@@ -1,17 +1,13 @@
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
- * @module utils/arestructuresconnected
6
+ * @module utils/areconnectedthroughproperties
7
7
  */
8
8
  /* globals EventTarget, Event */
9
9
  /**
10
10
  * Traverses both structures to find out whether there is a reference that is shared between both structures.
11
- *
12
- * @param {Object|Array} obj1
13
- * @param {Object|Array} obj2
14
- * @returns {Boolean}
15
11
  */
16
12
  export default function areConnectedThroughProperties(obj1, obj2) {
17
13
  if (obj1 === obj2 && isObject(obj1)) {
@@ -26,9 +22,11 @@ export default function areConnectedThroughProperties(obj1, obj2) {
26
22
  }
27
23
  return false;
28
24
  }
29
- // Traverses JS structure and stores all sub-nodes, including the head node.
30
- // It walks into each iterable structures with the `try catch` block to omit errors that might be thrown during
31
- // tree walking. All primitives, functions and built-ins are skipped.
25
+ /**
26
+ * Traverses JS structure and stores all sub-nodes, including the head node.
27
+ * It walks into each iterable structures with the `try catch` block to omit errors that might be thrown during
28
+ * tree walking. All primitives, functions and built-ins are skipped.
29
+ */
32
30
  function getSubNodes(head) {
33
31
  const nodes = [head];
34
32
  // Nodes are stored to prevent infinite looping.
@@ -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
  /**
@@ -24,57 +24,43 @@ export const DOCUMENTATION_URL = 'https://ckeditor.com/docs/ckeditor5/latest/sup
24
24
  * {@link module:utils/ckeditorerror~logError `logError()`}
25
25
  * to improve developers experience and let them see the a working editor as soon as possible.
26
26
  *
27
- * /**
28
- * * Error thrown when a plugin cannot be loaded due to JavaScript errors, lack of plugins with a given name, etc.
29
- * *
30
- * * @error plugin-load
31
- * * @param pluginName The name of the plugin that could not be loaded.
32
- * * @param moduleName The name of the module which tried to load this plugin.
33
- * * /
34
- * throw new CKEditorError( 'plugin-load', {
35
- * pluginName: 'foo',
36
- * moduleName: 'bar'
37
- * } );
38
- *
39
- * @extends Error
27
+ * ```ts
28
+ * /**
29
+ * * Error thrown when a plugin cannot be loaded due to JavaScript errors, lack of plugins with a given name, etc.
30
+ * *
31
+ * * @error plugin-load
32
+ * * @param pluginName The name of the plugin that could not be loaded.
33
+ * * @param moduleName The name of the module which tried to load this plugin.
34
+ * *\/
35
+ * throw new CKEditorError( 'plugin-load', {
36
+ * pluginName: 'foo',
37
+ * moduleName: 'bar'
38
+ * } );
39
+ * ```
40
40
  */
41
41
  export default class CKEditorError extends Error {
42
42
  /**
43
43
  * Creates an instance of the CKEditorError class.
44
44
  *
45
- * @param {String} errorName The error id in an `error-name` format. A link to this error documentation page will be added
45
+ * @param errorName The error id in an `error-name` format. A link to this error documentation page will be added
46
46
  * to the thrown error's `message`.
47
- * @param {Object|null} context A context of the error by which the {@link module:watchdog/watchdog~Watchdog watchdog}
47
+ * @param context A context of the error by which the {@link module:watchdog/watchdog~Watchdog watchdog}
48
48
  * is able to determine which editor crashed. It should be an editor instance or a property connected to it. It can be also
49
49
  * a `null` value if the editor should not be restarted in case of the error (e.g. during the editor initialization).
50
50
  * The error context should be checked using the `areConnectedThroughProperties( editor, context )` utility
51
51
  * to check if the object works as the context.
52
- * @param {Object} [data] Additional data describing the error. A stringified version of this object
52
+ * @param data Additional data describing the error. A stringified version of this object
53
53
  * will be appended to the error message, so the data are quickly visible in the console. The original
54
54
  * data object will also be later available under the {@link #data} property.
55
55
  */
56
56
  constructor(errorName, context, data) {
57
57
  super(getErrorMessage(errorName, data));
58
- /**
59
- * @type {String}
60
- */
61
58
  this.name = 'CKEditorError';
62
- /**
63
- * A context of the error by which the Watchdog is able to determine which editor crashed.
64
- *
65
- * @type {Object|null}
66
- */
67
59
  this.context = context;
68
- /**
69
- * The additional error data passed to the constructor. Undefined if none was passed.
70
- *
71
- * @type {Object|undefined}
72
- */
73
60
  this.data = data;
74
61
  }
75
62
  /**
76
63
  * Checks if the error is of the `CKEditorError` type.
77
- * @returns {Boolean}
78
64
  */
79
65
  is(type) {
80
66
  return type === 'CKEditorError';
@@ -84,9 +70,8 @@ export default class CKEditorError extends Error {
84
70
  * It is useful when combined with the {@link module:watchdog/watchdog~Watchdog} feature, which can restart the editor in case
85
71
  * of a {@link module:utils/ckeditorerror~CKEditorError} error.
86
72
  *
87
- * @static
88
- * @param {Error} err The error to rethrow.
89
- * @param {Object} context An object connected through properties with the editor instance. This context will be used
73
+ * @param err The error to rethrow.
74
+ * @param context An object connected through properties with the editor instance. This context will be used
90
75
  * by the watchdog to verify which editor should be restarted.
91
76
  */
92
77
  static rethrowUnexpectedError(err, context) {
@@ -113,20 +98,22 @@ export default class CKEditorError extends Error {
113
98
  * Logs a warning to the console with a properly formatted message and adds a link to the documentation.
114
99
  * Use whenever you want to log a warning to the console.
115
100
  *
116
- * /**
117
- * * There was a problem processing the configuration of the toolbar. The item with the given
118
- * * name does not exist, so it was omitted when rendering the toolbar.
119
- * *
120
- * * @error toolbarview-item-unavailable
121
- * * @param {String} name The name of the component.
122
- * * /
123
- * logWarning( 'toolbarview-item-unavailable', { name } );
101
+ * ```ts
102
+ * /**
103
+ * * There was a problem processing the configuration of the toolbar. The item with the given
104
+ * * name does not exist, so it was omitted when rendering the toolbar.
105
+ * *
106
+ * * @error toolbarview-item-unavailable
107
+ * * @param {String} name The name of the component.
108
+ * *\/
109
+ * logWarning( 'toolbarview-item-unavailable', { name } );
110
+ * ```
124
111
  *
125
112
  * See also {@link module:utils/ckeditorerror~CKEditorError} for an explanation when to throw an error and when to log
126
113
  * a warning or an error to the console.
127
114
  *
128
- * @param {String} errorName The error name to be logged.
129
- * @param {Object} [data] Additional data to be logged.
115
+ * @param errorName The error name to be logged.
116
+ * @param data Additional data to be logged.
130
117
  */
131
118
  export function logWarning(errorName, data) {
132
119
  console.warn(...formatConsoleArguments(errorName, data));
@@ -135,39 +122,36 @@ export function logWarning(errorName, data) {
135
122
  * Logs an error to the console with a properly formatted message and adds a link to the documentation.
136
123
  * Use whenever you want to log an error to the console.
137
124
  *
138
- * /**
139
- * * There was a problem processing the configuration of the toolbar. The item with the given
140
- * * name does not exist, so it was omitted when rendering the toolbar.
141
- * *
142
- * * @error toolbarview-item-unavailable
143
- * * @param {String} name The name of the component.
144
- * * /
145
- * logError( 'toolbarview-item-unavailable', { name } );
125
+ * ```ts
126
+ * /**
127
+ * * There was a problem processing the configuration of the toolbar. The item with the given
128
+ * * name does not exist, so it was omitted when rendering the toolbar.
129
+ * *
130
+ * * @error toolbarview-item-unavailable
131
+ * * @param {String} name The name of the component.
132
+ * *\/
133
+ * logError( 'toolbarview-item-unavailable', { name } );
134
+ * ```
146
135
  *
147
136
  * **Note**: In most cases logging a warning using {@link module:utils/ckeditorerror~logWarning} is enough.
148
137
  *
149
138
  * See also {@link module:utils/ckeditorerror~CKEditorError} for an explanation when to use each method.
150
139
  *
151
- * @param {String} errorName The error name to be logged.
152
- * @param {Object} [data] Additional data to be logged.
140
+ * @param errorName The error name to be logged.
141
+ * @param data Additional data to be logged.
153
142
  */
154
143
  export function logError(errorName, data) {
155
144
  console.error(...formatConsoleArguments(errorName, data));
156
145
  }
157
- // Returns formatted link to documentation message.
158
- //
159
- // @private
160
- // @param {String} errorName
161
- // @returns {string}
146
+ /**
147
+ * Returns formatted link to documentation message.
148
+ */
162
149
  function getLinkToDocumentationMessage(errorName) {
163
150
  return `\nRead more: ${DOCUMENTATION_URL}#error-${errorName}`;
164
151
  }
165
- // Returns formatted error message.
166
- //
167
- // @private
168
- // @param {String} errorName
169
- // @param {Object} [data]
170
- // @returns {string}
152
+ /**
153
+ * Returns formatted error message.
154
+ */
171
155
  function getErrorMessage(errorName, data) {
172
156
  const processedObjects = new WeakSet();
173
157
  const circularReferencesReplacer = (key, value) => {
@@ -183,12 +167,9 @@ function getErrorMessage(errorName, data) {
183
167
  const documentationLink = getLinkToDocumentationMessage(errorName);
184
168
  return errorName + stringifiedData + documentationLink;
185
169
  }
186
- // Returns formatted console error arguments.
187
- //
188
- // @private
189
- // @param {String} errorName
190
- // @param {Object} [data]
191
- // @returns {Array}
170
+ /**
171
+ * Returns formatted console error arguments.
172
+ */
192
173
  function formatConsoleArguments(errorName, data) {
193
174
  const documentationMessage = getLinkToDocumentationMessage(errorName);
194
175
  return data ? [errorName, data, documentationMessage] : [errorName, documentationMessage];