@ckeditor/ckeditor5-utils 34.2.0 → 35.1.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/CHANGELOG.md +324 -0
- package/LICENSE.md +1 -1
- package/package.json +19 -8
- package/src/areconnectedthroughproperties.js +54 -71
- package/src/ckeditorerror.js +92 -114
- package/src/collection.js +594 -762
- package/src/comparearrays.js +22 -28
- package/src/config.js +193 -223
- package/src/count.js +8 -12
- package/src/diff.js +85 -110
- package/src/difftochanges.js +47 -57
- package/src/dom/createelement.js +17 -25
- package/src/dom/emittermixin.js +202 -263
- package/src/dom/getancestors.js +9 -13
- package/src/dom/getborderwidths.js +10 -13
- package/src/dom/getcommonancestor.js +9 -15
- package/src/dom/getdatafromelement.js +5 -9
- package/src/dom/getpositionedancestor.js +9 -14
- package/src/dom/global.js +15 -4
- package/src/dom/indexof.js +7 -11
- package/src/dom/insertat.js +2 -4
- package/src/dom/iscomment.js +2 -5
- package/src/dom/isnode.js +10 -12
- package/src/dom/isrange.js +2 -4
- package/src/dom/istext.js +2 -4
- package/src/dom/isvisible.js +2 -4
- package/src/dom/iswindow.js +11 -16
- package/src/dom/position.js +220 -410
- package/src/dom/rect.js +335 -414
- package/src/dom/remove.js +5 -8
- package/src/dom/resizeobserver.js +109 -342
- package/src/dom/scroll.js +151 -183
- package/src/dom/setdatainelement.js +5 -9
- package/src/dom/tounit.js +10 -12
- package/src/elementreplacer.js +30 -44
- package/src/emittermixin.js +368 -634
- package/src/env.js +109 -116
- package/src/eventinfo.js +12 -65
- package/src/fastdiff.js +96 -128
- package/src/first.js +8 -12
- package/src/focustracker.js +77 -133
- package/src/index.js +0 -9
- package/src/inserttopriorityarray.js +9 -30
- package/src/isiterable.js +2 -4
- package/src/keyboard.js +117 -196
- package/src/keystrokehandler.js +72 -88
- package/src/language.js +9 -15
- package/src/locale.js +61 -158
- package/src/mapsequal.js +12 -17
- package/src/mix.js +17 -16
- package/src/nth.js +8 -11
- package/src/objecttomap.js +7 -11
- package/src/observablemixin.js +474 -778
- package/src/priorities.js +20 -32
- package/src/spy.js +3 -6
- package/src/toarray.js +2 -13
- package/src/tomap.js +8 -10
- package/src/translation-service.js +57 -93
- package/src/uid.js +34 -38
- package/src/unicode.js +28 -43
- package/src/version.js +134 -143
package/src/ckeditorerror.js
CHANGED
|
@@ -2,18 +2,14 @@
|
|
|
2
2
|
* @license Copyright (c) 2003-2022, 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
|
-
|
|
6
5
|
/**
|
|
7
6
|
* @module utils/ckeditorerror
|
|
8
7
|
*/
|
|
9
|
-
|
|
10
8
|
/* globals console */
|
|
11
|
-
|
|
12
9
|
/**
|
|
13
10
|
* URL to the documentation with error codes.
|
|
14
11
|
*/
|
|
15
12
|
export const DOCUMENTATION_URL = 'https://ckeditor.com/docs/ckeditor5/latest/support/error-codes.html';
|
|
16
|
-
|
|
17
13
|
/**
|
|
18
14
|
* The CKEditor error class.
|
|
19
15
|
*
|
|
@@ -43,85 +39,76 @@ export const DOCUMENTATION_URL = 'https://ckeditor.com/docs/ckeditor5/latest/sup
|
|
|
43
39
|
* @extends Error
|
|
44
40
|
*/
|
|
45
41
|
export default class CKEditorError extends Error {
|
|
46
|
-
|
|
47
|
-
|
|
48
|
-
|
|
49
|
-
|
|
50
|
-
|
|
51
|
-
|
|
52
|
-
|
|
53
|
-
|
|
54
|
-
|
|
55
|
-
|
|
56
|
-
|
|
57
|
-
|
|
58
|
-
|
|
59
|
-
|
|
60
|
-
|
|
61
|
-
|
|
62
|
-
|
|
63
|
-
|
|
64
|
-
|
|
65
|
-
|
|
66
|
-
|
|
67
|
-
|
|
68
|
-
|
|
69
|
-
|
|
70
|
-
|
|
71
|
-
|
|
72
|
-
|
|
73
|
-
|
|
74
|
-
|
|
75
|
-
|
|
76
|
-
|
|
77
|
-
|
|
78
|
-
|
|
79
|
-
|
|
80
|
-
|
|
81
|
-
|
|
82
|
-
|
|
83
|
-
|
|
84
|
-
|
|
85
|
-
|
|
86
|
-
|
|
87
|
-
|
|
88
|
-
|
|
89
|
-
|
|
90
|
-
|
|
91
|
-
|
|
92
|
-
|
|
93
|
-
|
|
94
|
-
|
|
95
|
-
|
|
96
|
-
|
|
97
|
-
|
|
98
|
-
|
|
99
|
-
|
|
100
|
-
|
|
101
|
-
|
|
102
|
-
|
|
103
|
-
|
|
104
|
-
|
|
105
|
-
|
|
106
|
-
|
|
107
|
-
|
|
108
|
-
|
|
109
|
-
|
|
110
|
-
|
|
111
|
-
|
|
112
|
-
|
|
113
|
-
|
|
114
|
-
|
|
115
|
-
const error = new CKEditorError( err.message, context );
|
|
116
|
-
|
|
117
|
-
// Restore the original stack trace to make the error look like the original one.
|
|
118
|
-
// See https://github.com/ckeditor/ckeditor5/issues/5595 for more details.
|
|
119
|
-
error.stack = err.stack;
|
|
120
|
-
|
|
121
|
-
throw error;
|
|
122
|
-
}
|
|
42
|
+
/**
|
|
43
|
+
* Creates an instance of the CKEditorError class.
|
|
44
|
+
*
|
|
45
|
+
* @param {String} errorName The error id in an `error-name` format. A link to this error documentation page will be added
|
|
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}
|
|
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
|
+
* a `null` value if the editor should not be restarted in case of the error (e.g. during the editor initialization).
|
|
50
|
+
* The error context should be checked using the `areConnectedThroughProperties( editor, context )` utility
|
|
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
|
|
53
|
+
* will be appended to the error message, so the data are quickly visible in the console. The original
|
|
54
|
+
* data object will also be later available under the {@link #data} property.
|
|
55
|
+
*/
|
|
56
|
+
constructor(errorName, context, data) {
|
|
57
|
+
super(getErrorMessage(errorName, data));
|
|
58
|
+
/**
|
|
59
|
+
* @type {String}
|
|
60
|
+
*/
|
|
61
|
+
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
|
+
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
|
+
this.data = data;
|
|
74
|
+
}
|
|
75
|
+
/**
|
|
76
|
+
* Checks if the error is of the `CKEditorError` type.
|
|
77
|
+
* @returns {Boolean}
|
|
78
|
+
*/
|
|
79
|
+
is(type) {
|
|
80
|
+
return type === 'CKEditorError';
|
|
81
|
+
}
|
|
82
|
+
/**
|
|
83
|
+
* A utility that ensures that the thrown error is a {@link module:utils/ckeditorerror~CKEditorError} one.
|
|
84
|
+
* It is useful when combined with the {@link module:watchdog/watchdog~Watchdog} feature, which can restart the editor in case
|
|
85
|
+
* of a {@link module:utils/ckeditorerror~CKEditorError} error.
|
|
86
|
+
*
|
|
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
|
|
90
|
+
* by the watchdog to verify which editor should be restarted.
|
|
91
|
+
*/
|
|
92
|
+
static rethrowUnexpectedError(err, context) {
|
|
93
|
+
if (err.is && err.is('CKEditorError')) {
|
|
94
|
+
throw err;
|
|
95
|
+
}
|
|
96
|
+
/**
|
|
97
|
+
* An unexpected error occurred inside the CKEditor 5 codebase. This error will look like the original one
|
|
98
|
+
* to make the debugging easier.
|
|
99
|
+
*
|
|
100
|
+
* This error is only useful when the editor is initialized using the {@link module:watchdog/watchdog~Watchdog} feature.
|
|
101
|
+
* In case of such error (or any {@link module:utils/ckeditorerror~CKEditorError} error) the watchdog should restart the editor.
|
|
102
|
+
*
|
|
103
|
+
* @error unexpected-error
|
|
104
|
+
*/
|
|
105
|
+
const error = new CKEditorError(err.message, context);
|
|
106
|
+
// Restore the original stack trace to make the error look like the original one.
|
|
107
|
+
// See https://github.com/ckeditor/ckeditor5/issues/5595 for more details.
|
|
108
|
+
error.stack = err.stack;
|
|
109
|
+
throw error;
|
|
110
|
+
}
|
|
123
111
|
}
|
|
124
|
-
|
|
125
112
|
/**
|
|
126
113
|
* Logs a warning to the console with a properly formatted message and adds a link to the documentation.
|
|
127
114
|
* Use whenever you want to log a warning to the console.
|
|
@@ -141,10 +128,9 @@ export default class CKEditorError extends Error {
|
|
|
141
128
|
* @param {String} errorName The error name to be logged.
|
|
142
129
|
* @param {Object} [data] Additional data to be logged.
|
|
143
130
|
*/
|
|
144
|
-
export function logWarning(
|
|
145
|
-
|
|
131
|
+
export function logWarning(errorName, data) {
|
|
132
|
+
console.warn(...formatConsoleArguments(errorName, data));
|
|
146
133
|
}
|
|
147
|
-
|
|
148
134
|
/**
|
|
149
135
|
* Logs an error to the console with a properly formatted message and adds a link to the documentation.
|
|
150
136
|
* Use whenever you want to log an error to the console.
|
|
@@ -165,53 +151,45 @@ export function logWarning( errorName, data ) {
|
|
|
165
151
|
* @param {String} errorName The error name to be logged.
|
|
166
152
|
* @param {Object} [data] Additional data to be logged.
|
|
167
153
|
*/
|
|
168
|
-
export function logError(
|
|
169
|
-
|
|
154
|
+
export function logError(errorName, data) {
|
|
155
|
+
console.error(...formatConsoleArguments(errorName, data));
|
|
170
156
|
}
|
|
171
|
-
|
|
172
157
|
// Returns formatted link to documentation message.
|
|
173
158
|
//
|
|
174
159
|
// @private
|
|
175
160
|
// @param {String} errorName
|
|
176
161
|
// @returns {string}
|
|
177
|
-
function getLinkToDocumentationMessage(
|
|
178
|
-
|
|
162
|
+
function getLinkToDocumentationMessage(errorName) {
|
|
163
|
+
return `\nRead more: ${DOCUMENTATION_URL}#error-${errorName}`;
|
|
179
164
|
}
|
|
180
|
-
|
|
181
165
|
// Returns formatted error message.
|
|
182
166
|
//
|
|
183
167
|
// @private
|
|
184
168
|
// @param {String} errorName
|
|
185
169
|
// @param {Object} [data]
|
|
186
170
|
// @returns {string}
|
|
187
|
-
function getErrorMessage(
|
|
188
|
-
|
|
189
|
-
|
|
190
|
-
|
|
191
|
-
|
|
192
|
-
|
|
193
|
-
|
|
194
|
-
|
|
195
|
-
|
|
196
|
-
|
|
197
|
-
|
|
198
|
-
|
|
199
|
-
|
|
200
|
-
|
|
201
|
-
const stringifiedData = data ? ` ${ JSON.stringify( data, circularReferencesReplacer ) }` : '';
|
|
202
|
-
const documentationLink = getLinkToDocumentationMessage( errorName );
|
|
203
|
-
|
|
204
|
-
return errorName + stringifiedData + documentationLink;
|
|
171
|
+
function getErrorMessage(errorName, data) {
|
|
172
|
+
const processedObjects = new WeakSet();
|
|
173
|
+
const circularReferencesReplacer = (key, value) => {
|
|
174
|
+
if (typeof value === 'object' && value !== null) {
|
|
175
|
+
if (processedObjects.has(value)) {
|
|
176
|
+
return `[object ${value.constructor.name}]`;
|
|
177
|
+
}
|
|
178
|
+
processedObjects.add(value);
|
|
179
|
+
}
|
|
180
|
+
return value;
|
|
181
|
+
};
|
|
182
|
+
const stringifiedData = data ? ` ${JSON.stringify(data, circularReferencesReplacer)}` : '';
|
|
183
|
+
const documentationLink = getLinkToDocumentationMessage(errorName);
|
|
184
|
+
return errorName + stringifiedData + documentationLink;
|
|
205
185
|
}
|
|
206
|
-
|
|
207
186
|
// Returns formatted console error arguments.
|
|
208
187
|
//
|
|
209
188
|
// @private
|
|
210
189
|
// @param {String} errorName
|
|
211
190
|
// @param {Object} [data]
|
|
212
191
|
// @returns {Array}
|
|
213
|
-
function formatConsoleArguments(
|
|
214
|
-
|
|
215
|
-
|
|
216
|
-
return data ? [ errorName, data, documentationMessage ] : [ errorName, documentationMessage ];
|
|
192
|
+
function formatConsoleArguments(errorName, data) {
|
|
193
|
+
const documentationMessage = getLinkToDocumentationMessage(errorName);
|
|
194
|
+
return data ? [errorName, data, documentationMessage] : [errorName, documentationMessage];
|
|
217
195
|
}
|