@ckeditor/ckeditor5-utils 40.0.0 → 40.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/LICENSE.md +3 -3
- package/package.json +1 -1
- package/src/areconnectedthroughproperties.d.ts +11 -11
- package/src/areconnectedthroughproperties.js +73 -73
- package/src/ckeditorerror.d.ts +123 -123
- package/src/ckeditorerror.js +176 -176
- package/src/collection.d.ts +433 -427
- package/src/collection.js +583 -575
- package/src/comparearrays.d.ts +30 -30
- package/src/comparearrays.js +47 -47
- package/src/config.d.ts +163 -163
- package/src/config.js +163 -162
- package/src/count.d.ts +18 -18
- package/src/count.js +24 -24
- package/src/delay.d.ts +19 -19
- package/src/delay.js +26 -26
- package/src/diff.d.ts +31 -31
- package/src/diff.js +115 -115
- package/src/difftochanges.d.ts +59 -59
- package/src/difftochanges.js +79 -79
- package/src/dom/createelement.d.ts +57 -57
- package/src/dom/createelement.js +40 -40
- package/src/dom/emittermixin.d.ts +142 -142
- package/src/dom/emittermixin.js +239 -239
- package/src/dom/findclosestscrollableancestor.d.ts +11 -11
- package/src/dom/findclosestscrollableancestor.js +31 -31
- package/src/dom/getancestors.d.ts +17 -17
- package/src/dom/getancestors.js +27 -27
- package/src/dom/getborderwidths.d.ts +24 -24
- package/src/dom/getborderwidths.js +24 -24
- package/src/dom/getcommonancestor.d.ts +12 -12
- package/src/dom/getcommonancestor.js +25 -25
- package/src/dom/getdatafromelement.d.ts +14 -14
- package/src/dom/getdatafromelement.js +20 -20
- package/src/dom/getpositionedancestor.d.ts +10 -10
- package/src/dom/getpositionedancestor.js +22 -22
- package/src/dom/global.d.ts +32 -32
- package/src/dom/global.js +35 -35
- package/src/dom/indexof.d.ts +14 -14
- package/src/dom/indexof.js +21 -21
- package/src/dom/insertat.d.ts +15 -15
- package/src/dom/insertat.js +17 -17
- package/src/dom/iscomment.d.ts +11 -11
- package/src/dom/iscomment.js +14 -14
- package/src/dom/isnode.d.ts +11 -11
- package/src/dom/isnode.js +21 -21
- package/src/dom/isrange.d.ts +11 -11
- package/src/dom/isrange.js +13 -13
- package/src/dom/istext.d.ts +11 -11
- package/src/dom/istext.js +13 -13
- package/src/dom/isvalidattributename.d.ts +10 -10
- package/src/dom/isvalidattributename.js +22 -22
- package/src/dom/isvisible.d.ts +18 -18
- package/src/dom/isvisible.js +20 -20
- package/src/dom/iswindow.d.ts +11 -11
- package/src/dom/iswindow.js +22 -22
- package/src/dom/position.d.ts +211 -211
- package/src/dom/position.js +313 -313
- package/src/dom/rect.d.ts +195 -195
- package/src/dom/rect.js +474 -474
- package/src/dom/remove.d.ts +13 -13
- package/src/dom/remove.js +18 -18
- package/src/dom/resizeobserver.d.ts +74 -74
- package/src/dom/resizeobserver.js +126 -126
- package/src/dom/scroll.d.ts +73 -73
- package/src/dom/scroll.js +383 -383
- package/src/dom/setdatainelement.d.ts +14 -14
- package/src/dom/setdatainelement.js +20 -20
- package/src/dom/tounit.d.ts +22 -22
- package/src/dom/tounit.js +16 -16
- package/src/elementreplacer.d.ts +31 -31
- package/src/elementreplacer.js +43 -43
- package/src/emittermixin.d.ts +312 -312
- package/src/emittermixin.js +453 -453
- package/src/env.d.ts +117 -117
- package/src/env.js +122 -122
- package/src/eventinfo.d.ts +58 -58
- package/src/eventinfo.js +26 -26
- package/src/fastdiff.d.ts +112 -112
- package/src/fastdiff.js +248 -248
- package/src/first.d.ts +11 -11
- package/src/first.js +17 -17
- package/src/focustracker.d.ts +75 -75
- package/src/focustracker.js +95 -95
- package/src/index.d.ts +61 -61
- package/src/index.js +60 -60
- package/src/inserttopriorityarray.d.ts +30 -30
- package/src/inserttopriorityarray.js +21 -21
- package/src/isiterable.d.ts +14 -14
- package/src/isiterable.js +16 -16
- package/src/keyboard.d.ts +126 -126
- package/src/keyboard.js +221 -221
- package/src/keystrokehandler.d.ts +87 -87
- package/src/keystrokehandler.js +122 -122
- package/src/language.d.ts +17 -17
- package/src/language.js +19 -19
- package/src/locale.d.ts +120 -120
- package/src/locale.js +76 -76
- package/src/mapsequal.d.ts +15 -15
- package/src/mapsequal.js +27 -27
- package/src/mix.d.ts +85 -85
- package/src/mix.js +50 -50
- package/src/nth.d.ts +16 -16
- package/src/nth.js +24 -24
- package/src/objecttomap.d.ts +23 -23
- package/src/objecttomap.js +27 -27
- package/src/observablemixin.d.ts +560 -560
- package/src/observablemixin.js +580 -580
- package/src/priorities.d.ts +33 -33
- package/src/priorities.js +23 -23
- package/src/splicearray.d.ts +26 -26
- package/src/splicearray.js +40 -40
- package/src/spy.d.ts +21 -21
- package/src/spy.js +22 -22
- package/src/toarray.d.ts +25 -25
- package/src/toarray.js +7 -7
- package/src/tomap.d.ts +19 -19
- package/src/tomap.js +29 -29
- package/src/translation-service.d.ts +168 -168
- package/src/translation-service.js +198 -198
- package/src/uid.d.ts +15 -15
- package/src/uid.js +57 -57
- package/src/unicode.d.ts +54 -54
- package/src/unicode.js +85 -85
- package/src/verifylicense.d.ts +15 -15
- package/src/verifylicense.js +87 -87
- package/src/version.d.ts +10 -10
- package/src/version.js +153 -153
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
|
|
|
@@ -13,9 +13,9 @@ Where not otherwise indicated, all CKEditor content is authored by CKSource engi
|
|
|
13
13
|
|
|
14
14
|
The following libraries are included in CKEditor under the [MIT license](https://opensource.org/licenses/MIT):
|
|
15
15
|
|
|
16
|
-
*
|
|
16
|
+
* Lodash - Copyright (c) JS Foundation and other contributors https://js.foundation/. Based on Underscore.js, copyright Jeremy Ashkenas, DocumentCloud and Investigative Reporters & Editors http://underscorejs.org/.
|
|
17
17
|
|
|
18
18
|
Trademarks
|
|
19
19
|
----------
|
|
20
20
|
|
|
21
|
-
**CKEditor** is a trademark of [CKSource Holding sp. z o.o.](https://cksource.com) All other brand and product names are trademarks, registered trademarks or service marks of their respective holders.
|
|
21
|
+
**CKEditor** is a trademark of [CKSource Holding sp. z o.o.](https://cksource.com) All other brand and product names are trademarks, registered trademarks, or service marks of their respective holders.
|
package/package.json
CHANGED
|
@@ -1,11 +1,11 @@
|
|
|
1
|
-
/**
|
|
2
|
-
* @license Copyright (c) 2003-2023, 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
|
-
* @module utils/areconnectedthroughproperties
|
|
7
|
-
*/
|
|
8
|
-
/**
|
|
9
|
-
* Traverses both structures to find out whether there is a reference that is shared between both structures.
|
|
10
|
-
*/
|
|
11
|
-
export default function areConnectedThroughProperties(obj1: object, obj2: object): boolean;
|
|
1
|
+
/**
|
|
2
|
+
* @license Copyright (c) 2003-2023, 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
|
+
* @module utils/areconnectedthroughproperties
|
|
7
|
+
*/
|
|
8
|
+
/**
|
|
9
|
+
* Traverses both structures to find out whether there is a reference that is shared between both structures.
|
|
10
|
+
*/
|
|
11
|
+
export default function areConnectedThroughProperties(obj1: object, obj2: object): boolean;
|
|
@@ -1,73 +1,73 @@
|
|
|
1
|
-
/**
|
|
2
|
-
* @license Copyright (c) 2003-2023, 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
|
-
* @module utils/areconnectedthroughproperties
|
|
7
|
-
*/
|
|
8
|
-
/* globals EventTarget, Event */
|
|
9
|
-
/**
|
|
10
|
-
* Traverses both structures to find out whether there is a reference that is shared between both structures.
|
|
11
|
-
*/
|
|
12
|
-
export default function areConnectedThroughProperties(obj1, obj2) {
|
|
13
|
-
if (obj1 === obj2 && isObject(obj1)) {
|
|
14
|
-
return true;
|
|
15
|
-
}
|
|
16
|
-
const subNodes1 = getSubNodes(obj1);
|
|
17
|
-
const subNodes2 = getSubNodes(obj2);
|
|
18
|
-
for (const node of subNodes1) {
|
|
19
|
-
if (subNodes2.has(node)) {
|
|
20
|
-
return true;
|
|
21
|
-
}
|
|
22
|
-
}
|
|
23
|
-
return false;
|
|
24
|
-
}
|
|
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
|
-
*/
|
|
30
|
-
function getSubNodes(head) {
|
|
31
|
-
const nodes = [head];
|
|
32
|
-
// Nodes are stored to prevent infinite looping.
|
|
33
|
-
const subNodes = new Set();
|
|
34
|
-
while (nodes.length > 0) {
|
|
35
|
-
const node = nodes.shift();
|
|
36
|
-
if (subNodes.has(node) || shouldNodeBeSkipped(node)) {
|
|
37
|
-
continue;
|
|
38
|
-
}
|
|
39
|
-
subNodes.add(node);
|
|
40
|
-
// Handle arrays, maps, sets, custom collections that implements `[ Symbol.iterator ]()`, etc.
|
|
41
|
-
if (node[Symbol.iterator]) {
|
|
42
|
-
// The custom editor iterators might cause some problems if the editor is crashed.
|
|
43
|
-
try {
|
|
44
|
-
nodes.push(...node);
|
|
45
|
-
}
|
|
46
|
-
catch (err) {
|
|
47
|
-
// eslint-disable-line no-empty
|
|
48
|
-
}
|
|
49
|
-
}
|
|
50
|
-
else {
|
|
51
|
-
nodes.push(...Object.values(node));
|
|
52
|
-
}
|
|
53
|
-
}
|
|
54
|
-
return subNodes;
|
|
55
|
-
}
|
|
56
|
-
function shouldNodeBeSkipped(node) {
|
|
57
|
-
const type = Object.prototype.toString.call(node);
|
|
58
|
-
return (type === '[object Number]' ||
|
|
59
|
-
type === '[object Boolean]' ||
|
|
60
|
-
type === '[object String]' ||
|
|
61
|
-
type === '[object Symbol]' ||
|
|
62
|
-
type === '[object Function]' ||
|
|
63
|
-
type === '[object Date]' ||
|
|
64
|
-
type === '[object RegExp]' ||
|
|
65
|
-
node === undefined ||
|
|
66
|
-
node === null ||
|
|
67
|
-
// Skip native DOM objects, e.g. Window, nodes, events, etc.
|
|
68
|
-
node instanceof EventTarget ||
|
|
69
|
-
node instanceof Event);
|
|
70
|
-
}
|
|
71
|
-
function isObject(structure) {
|
|
72
|
-
return typeof structure === 'object' && structure !== null;
|
|
73
|
-
}
|
|
1
|
+
/**
|
|
2
|
+
* @license Copyright (c) 2003-2023, 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
|
+
* @module utils/areconnectedthroughproperties
|
|
7
|
+
*/
|
|
8
|
+
/* globals EventTarget, Event */
|
|
9
|
+
/**
|
|
10
|
+
* Traverses both structures to find out whether there is a reference that is shared between both structures.
|
|
11
|
+
*/
|
|
12
|
+
export default function areConnectedThroughProperties(obj1, obj2) {
|
|
13
|
+
if (obj1 === obj2 && isObject(obj1)) {
|
|
14
|
+
return true;
|
|
15
|
+
}
|
|
16
|
+
const subNodes1 = getSubNodes(obj1);
|
|
17
|
+
const subNodes2 = getSubNodes(obj2);
|
|
18
|
+
for (const node of subNodes1) {
|
|
19
|
+
if (subNodes2.has(node)) {
|
|
20
|
+
return true;
|
|
21
|
+
}
|
|
22
|
+
}
|
|
23
|
+
return false;
|
|
24
|
+
}
|
|
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
|
+
*/
|
|
30
|
+
function getSubNodes(head) {
|
|
31
|
+
const nodes = [head];
|
|
32
|
+
// Nodes are stored to prevent infinite looping.
|
|
33
|
+
const subNodes = new Set();
|
|
34
|
+
while (nodes.length > 0) {
|
|
35
|
+
const node = nodes.shift();
|
|
36
|
+
if (subNodes.has(node) || shouldNodeBeSkipped(node)) {
|
|
37
|
+
continue;
|
|
38
|
+
}
|
|
39
|
+
subNodes.add(node);
|
|
40
|
+
// Handle arrays, maps, sets, custom collections that implements `[ Symbol.iterator ]()`, etc.
|
|
41
|
+
if (node[Symbol.iterator]) {
|
|
42
|
+
// The custom editor iterators might cause some problems if the editor is crashed.
|
|
43
|
+
try {
|
|
44
|
+
nodes.push(...node);
|
|
45
|
+
}
|
|
46
|
+
catch (err) {
|
|
47
|
+
// eslint-disable-line no-empty
|
|
48
|
+
}
|
|
49
|
+
}
|
|
50
|
+
else {
|
|
51
|
+
nodes.push(...Object.values(node));
|
|
52
|
+
}
|
|
53
|
+
}
|
|
54
|
+
return subNodes;
|
|
55
|
+
}
|
|
56
|
+
function shouldNodeBeSkipped(node) {
|
|
57
|
+
const type = Object.prototype.toString.call(node);
|
|
58
|
+
return (type === '[object Number]' ||
|
|
59
|
+
type === '[object Boolean]' ||
|
|
60
|
+
type === '[object String]' ||
|
|
61
|
+
type === '[object Symbol]' ||
|
|
62
|
+
type === '[object Function]' ||
|
|
63
|
+
type === '[object Date]' ||
|
|
64
|
+
type === '[object RegExp]' ||
|
|
65
|
+
node === undefined ||
|
|
66
|
+
node === null ||
|
|
67
|
+
// Skip native DOM objects, e.g. Window, nodes, events, etc.
|
|
68
|
+
node instanceof EventTarget ||
|
|
69
|
+
node instanceof Event);
|
|
70
|
+
}
|
|
71
|
+
function isObject(structure) {
|
|
72
|
+
return typeof structure === 'object' && structure !== null;
|
|
73
|
+
}
|
package/src/ckeditorerror.d.ts
CHANGED
|
@@ -1,123 +1,123 @@
|
|
|
1
|
-
/**
|
|
2
|
-
* @license Copyright (c) 2003-2023, 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
|
-
* @module utils/ckeditorerror
|
|
7
|
-
*/
|
|
8
|
-
/**
|
|
9
|
-
* URL to the documentation with error codes.
|
|
10
|
-
*/
|
|
11
|
-
export declare const DOCUMENTATION_URL = "https://ckeditor.com/docs/ckeditor5/latest/support/error-codes.html";
|
|
12
|
-
/**
|
|
13
|
-
* The CKEditor error class.
|
|
14
|
-
*
|
|
15
|
-
* You should throw `CKEditorError` when:
|
|
16
|
-
*
|
|
17
|
-
* * An unexpected situation occurred and the editor (most probably) will not work properly. Such exception will be handled
|
|
18
|
-
* by the {@link module:watchdog/watchdog~Watchdog watchdog} (if it is integrated),
|
|
19
|
-
* * If the editor is incorrectly integrated or the editor API is used in the wrong way. This way you will give
|
|
20
|
-
* feedback to the developer as soon as possible. Keep in mind that for common integration issues which should not
|
|
21
|
-
* stop editor initialization (like missing upload adapter, wrong name of a toolbar component) we use
|
|
22
|
-
* {@link module:utils/ckeditorerror~logWarning `logWarning()`} and
|
|
23
|
-
* {@link module:utils/ckeditorerror~logError `logError()`}
|
|
24
|
-
* to improve developers experience and let them see the a working editor as soon as possible.
|
|
25
|
-
*
|
|
26
|
-
* ```ts
|
|
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
|
-
*/
|
|
40
|
-
export default class CKEditorError extends Error {
|
|
41
|
-
/**
|
|
42
|
-
* A context of the error by which the Watchdog is able to determine which editor crashed.
|
|
43
|
-
*/
|
|
44
|
-
readonly context: object | null | undefined;
|
|
45
|
-
/**
|
|
46
|
-
* The additional error data passed to the constructor. Undefined if none was passed.
|
|
47
|
-
*/
|
|
48
|
-
readonly data?: object;
|
|
49
|
-
/**
|
|
50
|
-
* Creates an instance of the CKEditorError class.
|
|
51
|
-
*
|
|
52
|
-
* @param errorName The error id in an `error-name` format. A link to this error documentation page will be added
|
|
53
|
-
* to the thrown error's `message`.
|
|
54
|
-
* @param context A context of the error by which the {@link module:watchdog/watchdog~Watchdog watchdog}
|
|
55
|
-
* is able to determine which editor crashed. It should be an editor instance or a property connected to it. It can be also
|
|
56
|
-
* a `null` value if the editor should not be restarted in case of the error (e.g. during the editor initialization).
|
|
57
|
-
* The error context should be checked using the `areConnectedThroughProperties( editor, context )` utility
|
|
58
|
-
* to check if the object works as the context.
|
|
59
|
-
* @param data Additional data describing the error. A stringified version of this object
|
|
60
|
-
* will be appended to the error message, so the data are quickly visible in the console. The original
|
|
61
|
-
* data object will also be later available under the {@link #data} property.
|
|
62
|
-
*/
|
|
63
|
-
constructor(errorName: string, context?: object | null, data?: object);
|
|
64
|
-
/**
|
|
65
|
-
* Checks if the error is of the `CKEditorError` type.
|
|
66
|
-
*/
|
|
67
|
-
is(type: string): boolean;
|
|
68
|
-
/**
|
|
69
|
-
* A utility that ensures that the thrown error is a {@link module:utils/ckeditorerror~CKEditorError} one.
|
|
70
|
-
* It is useful when combined with the {@link module:watchdog/watchdog~Watchdog} feature, which can restart the editor in case
|
|
71
|
-
* of a {@link module:utils/ckeditorerror~CKEditorError} error.
|
|
72
|
-
*
|
|
73
|
-
* @param err The error to rethrow.
|
|
74
|
-
* @param context An object connected through properties with the editor instance. This context will be used
|
|
75
|
-
* by the watchdog to verify which editor should be restarted.
|
|
76
|
-
*/
|
|
77
|
-
static rethrowUnexpectedError(err: Error, context: object): never;
|
|
78
|
-
}
|
|
79
|
-
/**
|
|
80
|
-
* Logs a warning to the console with a properly formatted message and adds a link to the documentation.
|
|
81
|
-
* Use whenever you want to log a warning to the console.
|
|
82
|
-
*
|
|
83
|
-
* ```ts
|
|
84
|
-
* /**
|
|
85
|
-
* * There was a problem processing the configuration of the toolbar. The item with the given
|
|
86
|
-
* * name does not exist, so it was omitted when rendering the toolbar.
|
|
87
|
-
* *
|
|
88
|
-
* * @error toolbarview-item-unavailable
|
|
89
|
-
* * @param {String} name The name of the component.
|
|
90
|
-
* *\/
|
|
91
|
-
* logWarning( 'toolbarview-item-unavailable', { name } );
|
|
92
|
-
* ```
|
|
93
|
-
*
|
|
94
|
-
* See also {@link module:utils/ckeditorerror~CKEditorError} for an explanation when to throw an error and when to log
|
|
95
|
-
* a warning or an error to the console.
|
|
96
|
-
*
|
|
97
|
-
* @param errorName The error name to be logged.
|
|
98
|
-
* @param data Additional data to be logged.
|
|
99
|
-
*/
|
|
100
|
-
export declare function logWarning(errorName: string, data?: object): void;
|
|
101
|
-
/**
|
|
102
|
-
* Logs an error to the console with a properly formatted message and adds a link to the documentation.
|
|
103
|
-
* Use whenever you want to log an error to the console.
|
|
104
|
-
*
|
|
105
|
-
* ```ts
|
|
106
|
-
* /**
|
|
107
|
-
* * There was a problem processing the configuration of the toolbar. The item with the given
|
|
108
|
-
* * name does not exist, so it was omitted when rendering the toolbar.
|
|
109
|
-
* *
|
|
110
|
-
* * @error toolbarview-item-unavailable
|
|
111
|
-
* * @param {String} name The name of the component.
|
|
112
|
-
* *\/
|
|
113
|
-
* logError( 'toolbarview-item-unavailable', { name } );
|
|
114
|
-
* ```
|
|
115
|
-
*
|
|
116
|
-
* **Note**: In most cases logging a warning using {@link module:utils/ckeditorerror~logWarning} is enough.
|
|
117
|
-
*
|
|
118
|
-
* See also {@link module:utils/ckeditorerror~CKEditorError} for an explanation when to use each method.
|
|
119
|
-
*
|
|
120
|
-
* @param errorName The error name to be logged.
|
|
121
|
-
* @param data Additional data to be logged.
|
|
122
|
-
*/
|
|
123
|
-
export declare function logError(errorName: string, data?: object): void;
|
|
1
|
+
/**
|
|
2
|
+
* @license Copyright (c) 2003-2023, 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
|
+
* @module utils/ckeditorerror
|
|
7
|
+
*/
|
|
8
|
+
/**
|
|
9
|
+
* URL to the documentation with error codes.
|
|
10
|
+
*/
|
|
11
|
+
export declare const DOCUMENTATION_URL = "https://ckeditor.com/docs/ckeditor5/latest/support/error-codes.html";
|
|
12
|
+
/**
|
|
13
|
+
* The CKEditor error class.
|
|
14
|
+
*
|
|
15
|
+
* You should throw `CKEditorError` when:
|
|
16
|
+
*
|
|
17
|
+
* * An unexpected situation occurred and the editor (most probably) will not work properly. Such exception will be handled
|
|
18
|
+
* by the {@link module:watchdog/watchdog~Watchdog watchdog} (if it is integrated),
|
|
19
|
+
* * If the editor is incorrectly integrated or the editor API is used in the wrong way. This way you will give
|
|
20
|
+
* feedback to the developer as soon as possible. Keep in mind that for common integration issues which should not
|
|
21
|
+
* stop editor initialization (like missing upload adapter, wrong name of a toolbar component) we use
|
|
22
|
+
* {@link module:utils/ckeditorerror~logWarning `logWarning()`} and
|
|
23
|
+
* {@link module:utils/ckeditorerror~logError `logError()`}
|
|
24
|
+
* to improve developers experience and let them see the a working editor as soon as possible.
|
|
25
|
+
*
|
|
26
|
+
* ```ts
|
|
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
|
+
*/
|
|
40
|
+
export default class CKEditorError extends Error {
|
|
41
|
+
/**
|
|
42
|
+
* A context of the error by which the Watchdog is able to determine which editor crashed.
|
|
43
|
+
*/
|
|
44
|
+
readonly context: object | null | undefined;
|
|
45
|
+
/**
|
|
46
|
+
* The additional error data passed to the constructor. Undefined if none was passed.
|
|
47
|
+
*/
|
|
48
|
+
readonly data?: object;
|
|
49
|
+
/**
|
|
50
|
+
* Creates an instance of the CKEditorError class.
|
|
51
|
+
*
|
|
52
|
+
* @param errorName The error id in an `error-name` format. A link to this error documentation page will be added
|
|
53
|
+
* to the thrown error's `message`.
|
|
54
|
+
* @param context A context of the error by which the {@link module:watchdog/watchdog~Watchdog watchdog}
|
|
55
|
+
* is able to determine which editor crashed. It should be an editor instance or a property connected to it. It can be also
|
|
56
|
+
* a `null` value if the editor should not be restarted in case of the error (e.g. during the editor initialization).
|
|
57
|
+
* The error context should be checked using the `areConnectedThroughProperties( editor, context )` utility
|
|
58
|
+
* to check if the object works as the context.
|
|
59
|
+
* @param data Additional data describing the error. A stringified version of this object
|
|
60
|
+
* will be appended to the error message, so the data are quickly visible in the console. The original
|
|
61
|
+
* data object will also be later available under the {@link #data} property.
|
|
62
|
+
*/
|
|
63
|
+
constructor(errorName: string, context?: object | null, data?: object);
|
|
64
|
+
/**
|
|
65
|
+
* Checks if the error is of the `CKEditorError` type.
|
|
66
|
+
*/
|
|
67
|
+
is(type: string): boolean;
|
|
68
|
+
/**
|
|
69
|
+
* A utility that ensures that the thrown error is a {@link module:utils/ckeditorerror~CKEditorError} one.
|
|
70
|
+
* It is useful when combined with the {@link module:watchdog/watchdog~Watchdog} feature, which can restart the editor in case
|
|
71
|
+
* of a {@link module:utils/ckeditorerror~CKEditorError} error.
|
|
72
|
+
*
|
|
73
|
+
* @param err The error to rethrow.
|
|
74
|
+
* @param context An object connected through properties with the editor instance. This context will be used
|
|
75
|
+
* by the watchdog to verify which editor should be restarted.
|
|
76
|
+
*/
|
|
77
|
+
static rethrowUnexpectedError(err: Error, context: object): never;
|
|
78
|
+
}
|
|
79
|
+
/**
|
|
80
|
+
* Logs a warning to the console with a properly formatted message and adds a link to the documentation.
|
|
81
|
+
* Use whenever you want to log a warning to the console.
|
|
82
|
+
*
|
|
83
|
+
* ```ts
|
|
84
|
+
* /**
|
|
85
|
+
* * There was a problem processing the configuration of the toolbar. The item with the given
|
|
86
|
+
* * name does not exist, so it was omitted when rendering the toolbar.
|
|
87
|
+
* *
|
|
88
|
+
* * @error toolbarview-item-unavailable
|
|
89
|
+
* * @param {String} name The name of the component.
|
|
90
|
+
* *\/
|
|
91
|
+
* logWarning( 'toolbarview-item-unavailable', { name } );
|
|
92
|
+
* ```
|
|
93
|
+
*
|
|
94
|
+
* See also {@link module:utils/ckeditorerror~CKEditorError} for an explanation when to throw an error and when to log
|
|
95
|
+
* a warning or an error to the console.
|
|
96
|
+
*
|
|
97
|
+
* @param errorName The error name to be logged.
|
|
98
|
+
* @param data Additional data to be logged.
|
|
99
|
+
*/
|
|
100
|
+
export declare function logWarning(errorName: string, data?: object): void;
|
|
101
|
+
/**
|
|
102
|
+
* Logs an error to the console with a properly formatted message and adds a link to the documentation.
|
|
103
|
+
* Use whenever you want to log an error to the console.
|
|
104
|
+
*
|
|
105
|
+
* ```ts
|
|
106
|
+
* /**
|
|
107
|
+
* * There was a problem processing the configuration of the toolbar. The item with the given
|
|
108
|
+
* * name does not exist, so it was omitted when rendering the toolbar.
|
|
109
|
+
* *
|
|
110
|
+
* * @error toolbarview-item-unavailable
|
|
111
|
+
* * @param {String} name The name of the component.
|
|
112
|
+
* *\/
|
|
113
|
+
* logError( 'toolbarview-item-unavailable', { name } );
|
|
114
|
+
* ```
|
|
115
|
+
*
|
|
116
|
+
* **Note**: In most cases logging a warning using {@link module:utils/ckeditorerror~logWarning} is enough.
|
|
117
|
+
*
|
|
118
|
+
* See also {@link module:utils/ckeditorerror~CKEditorError} for an explanation when to use each method.
|
|
119
|
+
*
|
|
120
|
+
* @param errorName The error name to be logged.
|
|
121
|
+
* @param data Additional data to be logged.
|
|
122
|
+
*/
|
|
123
|
+
export declare function logError(errorName: string, data?: object): void;
|