@ckeditor/ckeditor5-watchdog 40.0.0 → 40.2.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/src/index.d.ts 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 watchdog
7
- */
8
- export { default as ContextWatchdog } from './contextwatchdog';
9
- export { default as EditorWatchdog } from './editorwatchdog';
10
- export { default as Watchdog } from './watchdog';
11
- import './augmentation';
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 watchdog
7
+ */
8
+ export { default as ContextWatchdog } from './contextwatchdog';
9
+ export { default as EditorWatchdog } from './editorwatchdog';
10
+ export { default as Watchdog } from './watchdog';
11
+ import './augmentation';
package/src/index.js 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 watchdog
7
- */
8
- export { default as ContextWatchdog } from './contextwatchdog';
9
- export { default as EditorWatchdog } from './editorwatchdog';
10
- export { default as Watchdog } from './watchdog';
11
- import './augmentation';
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 watchdog
7
+ */
8
+ export { default as ContextWatchdog } from './contextwatchdog';
9
+ export { default as EditorWatchdog } from './editorwatchdog';
10
+ export { default as Watchdog } from './watchdog';
11
+ import './augmentation';
@@ -1,8 +1,8 @@
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
- * Traverses both structures to find out whether there is a reference that is shared between both structures.
7
- */
8
- export default function areConnectedThroughProperties(target1: unknown, target2: unknown, excludedNodes?: Set<unknown>): 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
+ * Traverses both structures to find out whether there is a reference that is shared between both structures.
7
+ */
8
+ export default function areConnectedThroughProperties(target1: unknown, target2: unknown, excludedNodes?: Set<unknown>): boolean;
@@ -1,58 +1,58 @@
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 watchdog/utils/areconnectedthroughproperties
7
- */
8
- /* globals console */
9
- import getSubNodes from './getsubnodes';
10
- /**
11
- * Traverses both structures to find out whether there is a reference that is shared between both structures.
12
- */
13
- export default function areConnectedThroughProperties(target1, target2, excludedNodes = new Set()) {
14
- if (target1 === target2 && isObject(target1)) {
15
- return true;
16
- }
17
- // @if CK_DEBUG_WATCHDOG // return checkConnectionBetweenProps( target1, target2, excludedNodes );
18
- const subNodes1 = getSubNodes(target1, excludedNodes);
19
- const subNodes2 = getSubNodes(target2, excludedNodes);
20
- for (const node of subNodes1) {
21
- if (subNodes2.has(node)) {
22
- return true;
23
- }
24
- }
25
- return false;
26
- }
27
- /* istanbul ignore next -- @preserve */
28
- // eslint-disable-next-line
29
- function checkConnectionBetweenProps(target1, target2, excludedNodes) {
30
- const { subNodes: subNodes1, prevNodeMap: prevNodeMap1 } = getSubNodes(target1, excludedNodes.subNodes);
31
- const { subNodes: subNodes2, prevNodeMap: prevNodeMap2 } = getSubNodes(target2, excludedNodes.subNodes);
32
- for (const sharedNode of subNodes1) {
33
- if (subNodes2.has(sharedNode)) {
34
- const connection = [];
35
- connection.push(sharedNode);
36
- let node = prevNodeMap1.get(sharedNode);
37
- while (node && node !== target1) {
38
- connection.push(node);
39
- node = prevNodeMap1.get(node);
40
- }
41
- node = prevNodeMap2.get(sharedNode);
42
- while (node && node !== target2) {
43
- connection.unshift(node);
44
- node = prevNodeMap2.get(node);
45
- }
46
- console.log('--------');
47
- console.log({ target1 });
48
- console.log({ sharedNode });
49
- console.log({ target2 });
50
- console.log({ connection });
51
- return true;
52
- }
53
- }
54
- return false;
55
- }
56
- function isObject(structure) {
57
- return typeof structure === 'object' && structure !== null;
58
- }
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 watchdog/utils/areconnectedthroughproperties
7
+ */
8
+ /* globals console */
9
+ import getSubNodes from './getsubnodes';
10
+ /**
11
+ * Traverses both structures to find out whether there is a reference that is shared between both structures.
12
+ */
13
+ export default function areConnectedThroughProperties(target1, target2, excludedNodes = new Set()) {
14
+ if (target1 === target2 && isObject(target1)) {
15
+ return true;
16
+ }
17
+ // @if CK_DEBUG_WATCHDOG // return checkConnectionBetweenProps( target1, target2, excludedNodes );
18
+ const subNodes1 = getSubNodes(target1, excludedNodes);
19
+ const subNodes2 = getSubNodes(target2, excludedNodes);
20
+ for (const node of subNodes1) {
21
+ if (subNodes2.has(node)) {
22
+ return true;
23
+ }
24
+ }
25
+ return false;
26
+ }
27
+ /* istanbul ignore next -- @preserve */
28
+ // eslint-disable-next-line
29
+ function checkConnectionBetweenProps(target1, target2, excludedNodes) {
30
+ const { subNodes: subNodes1, prevNodeMap: prevNodeMap1 } = getSubNodes(target1, excludedNodes.subNodes);
31
+ const { subNodes: subNodes2, prevNodeMap: prevNodeMap2 } = getSubNodes(target2, excludedNodes.subNodes);
32
+ for (const sharedNode of subNodes1) {
33
+ if (subNodes2.has(sharedNode)) {
34
+ const connection = [];
35
+ connection.push(sharedNode);
36
+ let node = prevNodeMap1.get(sharedNode);
37
+ while (node && node !== target1) {
38
+ connection.push(node);
39
+ node = prevNodeMap1.get(node);
40
+ }
41
+ node = prevNodeMap2.get(sharedNode);
42
+ while (node && node !== target2) {
43
+ connection.unshift(node);
44
+ node = prevNodeMap2.get(node);
45
+ }
46
+ console.log('--------');
47
+ console.log({ target1 });
48
+ console.log({ sharedNode });
49
+ console.log({ target2 });
50
+ console.log({ connection });
51
+ return true;
52
+ }
53
+ }
54
+ return false;
55
+ }
56
+ function isObject(structure) {
57
+ return typeof structure === 'object' && structure !== null;
58
+ }
@@ -1,8 +1,8 @@
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 watchdog/utils/getsubnodes
7
- */
8
- export default function getSubNodes(head: unknown, excludedProperties?: Set<unknown>): Set<unknown>;
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 watchdog/utils/getsubnodes
7
+ */
8
+ export default function getSubNodes(head: unknown, excludedProperties?: Set<unknown>): Set<unknown>;
@@ -1,78 +1,78 @@
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 watchdog/utils/getsubnodes
7
- */
8
- /* globals EventTarget, Event */
9
- export default function getSubNodes(head, excludedProperties = new Set()) {
10
- const nodes = [head];
11
- // @if CK_DEBUG_WATCHDOG // const prevNodeMap = new Map();
12
- // Nodes are stored to prevent infinite looping.
13
- const subNodes = new Set();
14
- let nodeIndex = 0;
15
- while (nodes.length > nodeIndex) {
16
- // Incrementing the iterator is much faster than changing size of the array with Array.prototype.shift().
17
- const node = nodes[nodeIndex++];
18
- if (subNodes.has(node) || !shouldNodeBeIncluded(node) || excludedProperties.has(node)) {
19
- continue;
20
- }
21
- subNodes.add(node);
22
- // Handle arrays, maps, sets, custom collections that implements `[ Symbol.iterator ]()`, etc.
23
- if (Symbol.iterator in node) {
24
- // The custom editor iterators might cause some problems if the editor is crashed.
25
- try {
26
- for (const n of node) {
27
- nodes.push(n);
28
- // @if CK_DEBUG_WATCHDOG // if ( !prevNodeMap.has( n ) ) {
29
- // @if CK_DEBUG_WATCHDOG // prevNodeMap.set( n, node );
30
- // @if CK_DEBUG_WATCHDOG // }
31
- }
32
- }
33
- catch (err) {
34
- // Do not log errors for broken structures
35
- // since we are in the error handling process already.
36
- // eslint-disable-line no-empty
37
- }
38
- }
39
- else {
40
- for (const key in node) {
41
- // We share a reference via the protobuf library within the editors,
42
- // hence the shared value should be skipped. Although, it's not a perfect
43
- // solution since new places like that might occur in the future.
44
- if (key === 'defaultValue') {
45
- continue;
46
- }
47
- nodes.push(node[key]);
48
- // @if CK_DEBUG_WATCHDOG // if ( !prevNodeMap.has( node[ key ] ) ) {
49
- // @if CK_DEBUG_WATCHDOG // prevNodeMap.set( node[ key ], node );
50
- // @if CK_DEBUG_WATCHDOG // }
51
- }
52
- }
53
- }
54
- // @if CK_DEBUG_WATCHDOG // return { subNodes, prevNodeMap } as any;
55
- return subNodes;
56
- }
57
- function shouldNodeBeIncluded(node) {
58
- const type = Object.prototype.toString.call(node);
59
- const typeOfNode = typeof node;
60
- return !(typeOfNode === 'number' ||
61
- typeOfNode === 'boolean' ||
62
- typeOfNode === 'string' ||
63
- typeOfNode === 'symbol' ||
64
- typeOfNode === 'function' ||
65
- type === '[object Date]' ||
66
- type === '[object RegExp]' ||
67
- type === '[object Module]' ||
68
- node === undefined ||
69
- node === null ||
70
- // This flag is meant to exclude singletons shared across editor instances. So when an error is thrown in one editor,
71
- // the other editors connected through the reference to the same singleton are not restarted. This is a temporary workaround
72
- // until a better solution is found.
73
- // More in https://github.com/ckeditor/ckeditor5/issues/12292.
74
- node._watchdogExcluded ||
75
- // Skip native DOM objects, e.g. Window, nodes, events, etc.
76
- node instanceof EventTarget ||
77
- node instanceof Event);
78
- }
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 watchdog/utils/getsubnodes
7
+ */
8
+ /* globals EventTarget, Event */
9
+ export default function getSubNodes(head, excludedProperties = new Set()) {
10
+ const nodes = [head];
11
+ // @if CK_DEBUG_WATCHDOG // const prevNodeMap = new Map();
12
+ // Nodes are stored to prevent infinite looping.
13
+ const subNodes = new Set();
14
+ let nodeIndex = 0;
15
+ while (nodes.length > nodeIndex) {
16
+ // Incrementing the iterator is much faster than changing size of the array with Array.prototype.shift().
17
+ const node = nodes[nodeIndex++];
18
+ if (subNodes.has(node) || !shouldNodeBeIncluded(node) || excludedProperties.has(node)) {
19
+ continue;
20
+ }
21
+ subNodes.add(node);
22
+ // Handle arrays, maps, sets, custom collections that implements `[ Symbol.iterator ]()`, etc.
23
+ if (Symbol.iterator in node) {
24
+ // The custom editor iterators might cause some problems if the editor is crashed.
25
+ try {
26
+ for (const n of node) {
27
+ nodes.push(n);
28
+ // @if CK_DEBUG_WATCHDOG // if ( !prevNodeMap.has( n ) ) {
29
+ // @if CK_DEBUG_WATCHDOG // prevNodeMap.set( n, node );
30
+ // @if CK_DEBUG_WATCHDOG // }
31
+ }
32
+ }
33
+ catch (err) {
34
+ // Do not log errors for broken structures
35
+ // since we are in the error handling process already.
36
+ // eslint-disable-line no-empty
37
+ }
38
+ }
39
+ else {
40
+ for (const key in node) {
41
+ // We share a reference via the protobuf library within the editors,
42
+ // hence the shared value should be skipped. Although, it's not a perfect
43
+ // solution since new places like that might occur in the future.
44
+ if (key === 'defaultValue') {
45
+ continue;
46
+ }
47
+ nodes.push(node[key]);
48
+ // @if CK_DEBUG_WATCHDOG // if ( !prevNodeMap.has( node[ key ] ) ) {
49
+ // @if CK_DEBUG_WATCHDOG // prevNodeMap.set( node[ key ], node );
50
+ // @if CK_DEBUG_WATCHDOG // }
51
+ }
52
+ }
53
+ }
54
+ // @if CK_DEBUG_WATCHDOG // return { subNodes, prevNodeMap } as any;
55
+ return subNodes;
56
+ }
57
+ function shouldNodeBeIncluded(node) {
58
+ const type = Object.prototype.toString.call(node);
59
+ const typeOfNode = typeof node;
60
+ return !(typeOfNode === 'number' ||
61
+ typeOfNode === 'boolean' ||
62
+ typeOfNode === 'string' ||
63
+ typeOfNode === 'symbol' ||
64
+ typeOfNode === 'function' ||
65
+ type === '[object Date]' ||
66
+ type === '[object RegExp]' ||
67
+ type === '[object Module]' ||
68
+ node === undefined ||
69
+ node === null ||
70
+ // This flag is meant to exclude singletons shared across editor instances. So when an error is thrown in one editor,
71
+ // the other editors connected through the reference to the same singleton are not restarted. This is a temporary workaround
72
+ // until a better solution is found.
73
+ // More in https://github.com/ckeditor/ckeditor5/issues/12292.
74
+ node._watchdogExcluded ||
75
+ // Skip native DOM objects, e.g. Window, nodes, events, etc.
76
+ node instanceof EventTarget ||
77
+ node instanceof Event);
78
+ }