@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.
- package/LICENSE.md +1 -1
- package/package.json +5 -5
- package/src/areconnectedthroughproperties.js +7 -9
- package/src/ckeditorerror.js +52 -71
- package/src/collection.js +108 -150
- package/src/comparearrays.js +11 -9
- package/src/config.js +30 -84
- package/src/count.js +6 -4
- package/src/diff.js +8 -6
- package/src/difftochanges.js +18 -15
- package/src/dom/createelement.js +12 -10
- package/src/dom/emittermixin.js +44 -85
- package/src/dom/findclosestscrollableancestor.js +30 -0
- package/src/dom/getancestors.js +3 -3
- package/src/dom/getborderwidths.js +3 -3
- package/src/dom/getcommonancestor.js +4 -4
- package/src/dom/getdatafromelement.js +3 -3
- package/src/dom/getpositionedancestor.js +2 -3
- package/src/dom/global.js +13 -15
- package/src/dom/indexof.js +3 -3
- package/src/dom/insertat.js +4 -4
- package/src/dom/iscomment.js +1 -4
- package/src/dom/isnode.js +1 -4
- package/src/dom/isrange.js +1 -4
- package/src/dom/istext.js +1 -4
- package/src/dom/isvisible.js +1 -4
- package/src/dom/iswindow.js +1 -4
- package/src/dom/position.js +111 -134
- package/src/dom/rect.js +43 -53
- package/src/dom/remove.js +2 -2
- package/src/dom/resizeobserver.js +11 -36
- package/src/dom/scroll.js +86 -92
- package/src/dom/setdatainelement.js +3 -3
- package/src/dom/tounit.js +2 -11
- package/src/elementreplacer.js +3 -3
- package/src/emittermixin.js +49 -49
- package/src/env.js +15 -76
- package/src/eventinfo.js +3 -3
- package/src/fastdiff.js +116 -97
- package/src/first.js +1 -4
- package/src/focustracker.js +12 -20
- package/src/index.js +19 -1
- package/src/inserttopriorityarray.js +3 -3
- package/src/isiterable.js +3 -3
- package/src/keyboard.js +21 -22
- package/src/keystrokehandler.js +27 -25
- package/src/language.js +2 -3
- package/src/locale.js +12 -15
- package/src/mapsequal.js +5 -5
- package/src/mix.js +16 -14
- package/src/nth.js +1 -5
- package/src/objecttomap.js +7 -5
- package/src/observablemixin.js +127 -151
- package/src/priorities.js +1 -10
- package/src/splicearray.js +13 -12
- package/src/spy.js +2 -2
- package/src/toarray.js +1 -1
- package/src/tomap.js +8 -6
- package/src/translation-service.js +71 -53
- package/src/uid.js +6 -4
- package/src/unicode.js +10 -16
- 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-
|
|
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": "
|
|
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": "^
|
|
18
|
-
"@ckeditor/ckeditor5-editor-classic": "^
|
|
19
|
-
"@ckeditor/ckeditor5-core": "^
|
|
20
|
-
"@ckeditor/ckeditor5-engine": "^
|
|
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-
|
|
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/
|
|
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
|
-
|
|
30
|
-
|
|
31
|
-
|
|
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.
|
package/src/ckeditorerror.js
CHANGED
|
@@ -1,5 +1,5 @@
|
|
|
1
1
|
/**
|
|
2
|
-
* @license Copyright (c) 2003-
|
|
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
|
-
*
|
|
29
|
-
*
|
|
30
|
-
*
|
|
31
|
-
*
|
|
32
|
-
*
|
|
33
|
-
*
|
|
34
|
-
*
|
|
35
|
-
*
|
|
36
|
-
*
|
|
37
|
-
*
|
|
38
|
-
*
|
|
39
|
-
*
|
|
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
|
|
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
|
|
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
|
|
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
|
-
* @
|
|
88
|
-
* @param
|
|
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
|
-
*
|
|
118
|
-
*
|
|
119
|
-
*
|
|
120
|
-
*
|
|
121
|
-
*
|
|
122
|
-
*
|
|
123
|
-
*
|
|
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
|
|
129
|
-
* @param
|
|
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
|
-
*
|
|
140
|
-
*
|
|
141
|
-
*
|
|
142
|
-
*
|
|
143
|
-
*
|
|
144
|
-
*
|
|
145
|
-
*
|
|
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
|
|
152
|
-
* @param
|
|
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
|
-
|
|
158
|
-
|
|
159
|
-
|
|
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
|
-
|
|
166
|
-
|
|
167
|
-
|
|
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
|
-
|
|
187
|
-
|
|
188
|
-
|
|
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];
|