@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
|
@@ -2,27 +2,22 @@
|
|
|
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/dom/getpositionedancestor
|
|
8
7
|
*/
|
|
9
|
-
|
|
10
8
|
import global from './global';
|
|
11
|
-
|
|
12
9
|
/**
|
|
13
10
|
* For a given element, returns the nearest ancestor element which CSS position is not "static".
|
|
14
11
|
*
|
|
15
|
-
* @param {HTMLElement} element The native DOM element to be checked.
|
|
12
|
+
* @param {HTMLElement} [element] The native DOM element to be checked.
|
|
16
13
|
* @returns {HTMLElement|null}
|
|
17
14
|
*/
|
|
18
|
-
export default function getPositionedAncestor(
|
|
19
|
-
|
|
20
|
-
|
|
21
|
-
|
|
22
|
-
|
|
23
|
-
|
|
24
|
-
|
|
25
|
-
|
|
26
|
-
|
|
27
|
-
return element.offsetParent;
|
|
15
|
+
export default function getPositionedAncestor(element) {
|
|
16
|
+
if (!element || !element.parentNode) {
|
|
17
|
+
return null;
|
|
18
|
+
}
|
|
19
|
+
if (element.offsetParent === global.document.body) {
|
|
20
|
+
return null;
|
|
21
|
+
}
|
|
22
|
+
return element.offsetParent;
|
|
28
23
|
}
|
package/src/dom/global.js
CHANGED
|
@@ -2,13 +2,10 @@
|
|
|
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
|
/* globals window, document */
|
|
7
|
-
|
|
8
6
|
/**
|
|
9
7
|
* @module utils/dom/global
|
|
10
8
|
*/
|
|
11
|
-
|
|
12
9
|
/**
|
|
13
10
|
* A helper (module) giving an access to the global DOM objects such as `window` and
|
|
14
11
|
* `document`. Accessing these objects using this helper allows easy and bulletproof
|
|
@@ -23,4 +20,18 @@
|
|
|
23
20
|
*
|
|
24
21
|
* console.log( global.window.innerWidth );
|
|
25
22
|
*/
|
|
26
|
-
|
|
23
|
+
let global;
|
|
24
|
+
// In some environments window and document API might not be available.
|
|
25
|
+
try {
|
|
26
|
+
global = { window, document };
|
|
27
|
+
}
|
|
28
|
+
catch (e) {
|
|
29
|
+
// It's not possible to mock a window object to simulate lack of a window object without writing extremely convoluted code.
|
|
30
|
+
/* istanbul ignore next */
|
|
31
|
+
// Let's cast it to not change module's API.
|
|
32
|
+
// We only handle this so loading editor in environments without window and document doesn't fail.
|
|
33
|
+
// For better DX we shouldn't introduce mixed types and require developers to check the type manually.
|
|
34
|
+
// This module should not be used on purpose in any environment outside browser.
|
|
35
|
+
global = { window: {}, document: {} };
|
|
36
|
+
}
|
|
37
|
+
export default global;
|
package/src/dom/indexof.js
CHANGED
|
@@ -2,24 +2,20 @@
|
|
|
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/dom/indexof
|
|
8
7
|
*/
|
|
9
|
-
|
|
10
8
|
/**
|
|
11
9
|
* Returns index of the node in the parent element.
|
|
12
10
|
*
|
|
13
11
|
* @param {Node} node Node which index is tested.
|
|
14
12
|
* @returns {Number} Index of the node in the parent element. Returns 0 if node has no parent.
|
|
15
13
|
*/
|
|
16
|
-
export default function indexOf(
|
|
17
|
-
|
|
18
|
-
|
|
19
|
-
|
|
20
|
-
|
|
21
|
-
|
|
22
|
-
|
|
23
|
-
|
|
24
|
-
return index;
|
|
14
|
+
export default function indexOf(node) {
|
|
15
|
+
let index = 0;
|
|
16
|
+
while (node.previousSibling) {
|
|
17
|
+
node = node.previousSibling;
|
|
18
|
+
index++;
|
|
19
|
+
}
|
|
20
|
+
return index;
|
|
25
21
|
}
|
package/src/dom/insertat.js
CHANGED
|
@@ -2,11 +2,9 @@
|
|
|
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/dom/insertat
|
|
8
7
|
*/
|
|
9
|
-
|
|
10
8
|
/**
|
|
11
9
|
* Inserts node to the parent at given index.
|
|
12
10
|
*
|
|
@@ -14,6 +12,6 @@
|
|
|
14
12
|
* @param {Number} index Insertions index.
|
|
15
13
|
* @param {Node} nodeToInsert Node to insert.
|
|
16
14
|
*/
|
|
17
|
-
export default function insertAt(
|
|
18
|
-
|
|
15
|
+
export default function insertAt(parentElement, index, nodeToInsert) {
|
|
16
|
+
parentElement.insertBefore(nodeToInsert, parentElement.childNodes[index] || null);
|
|
19
17
|
}
|
package/src/dom/iscomment.js
CHANGED
|
@@ -2,19 +2,16 @@
|
|
|
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
|
/* globals Node */
|
|
7
|
-
|
|
8
6
|
/**
|
|
9
7
|
* @module utils/dom/iscomment
|
|
10
8
|
*/
|
|
11
|
-
|
|
12
9
|
/**
|
|
13
10
|
* Checks whether the object is a native DOM Comment node.
|
|
14
11
|
*
|
|
15
12
|
* @param {*} obj
|
|
16
13
|
* @returns {Boolean}
|
|
17
14
|
*/
|
|
18
|
-
export default function isComment(
|
|
19
|
-
|
|
15
|
+
export default function isComment(obj) {
|
|
16
|
+
return obj && obj.nodeType === Node.COMMENT_NODE;
|
|
20
17
|
}
|
package/src/dom/isnode.js
CHANGED
|
@@ -2,25 +2,23 @@
|
|
|
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/dom/isnode
|
|
8
7
|
*/
|
|
9
|
-
|
|
10
8
|
/**
|
|
11
9
|
* Checks if the object is a native DOM Node.
|
|
12
10
|
*
|
|
13
11
|
* @param {*} obj
|
|
14
12
|
* @returns {Boolean}
|
|
15
13
|
*/
|
|
16
|
-
export default function isNode(
|
|
17
|
-
|
|
18
|
-
|
|
19
|
-
|
|
20
|
-
|
|
21
|
-
|
|
22
|
-
|
|
23
|
-
|
|
24
|
-
|
|
25
|
-
|
|
14
|
+
export default function isNode(obj) {
|
|
15
|
+
if (obj) {
|
|
16
|
+
if (obj.defaultView) {
|
|
17
|
+
return obj instanceof obj.defaultView.Document;
|
|
18
|
+
}
|
|
19
|
+
else if (obj.ownerDocument && obj.ownerDocument.defaultView) {
|
|
20
|
+
return obj instanceof obj.ownerDocument.defaultView.Node;
|
|
21
|
+
}
|
|
22
|
+
}
|
|
23
|
+
return false;
|
|
26
24
|
}
|
package/src/dom/isrange.js
CHANGED
|
@@ -2,17 +2,15 @@
|
|
|
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/dom/isrange
|
|
8
7
|
*/
|
|
9
|
-
|
|
10
8
|
/**
|
|
11
9
|
* Checks if the object is a native DOM Range.
|
|
12
10
|
*
|
|
13
11
|
* @param {*} obj
|
|
14
12
|
* @returns {Boolean}
|
|
15
13
|
*/
|
|
16
|
-
export default function isRange(
|
|
17
|
-
|
|
14
|
+
export default function isRange(obj) {
|
|
15
|
+
return Object.prototype.toString.apply(obj) == '[object Range]';
|
|
18
16
|
}
|
package/src/dom/istext.js
CHANGED
|
@@ -2,17 +2,15 @@
|
|
|
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/dom/istext
|
|
8
7
|
*/
|
|
9
|
-
|
|
10
8
|
/**
|
|
11
9
|
* Checks if the object is a native DOM Text node.
|
|
12
10
|
*
|
|
13
11
|
* @param {*} obj
|
|
14
12
|
* @returns {Boolean}
|
|
15
13
|
*/
|
|
16
|
-
export default function isText(
|
|
17
|
-
|
|
14
|
+
export default function isText(obj) {
|
|
15
|
+
return Object.prototype.toString.call(obj) == '[object Text]';
|
|
18
16
|
}
|
package/src/dom/isvisible.js
CHANGED
|
@@ -2,11 +2,9 @@
|
|
|
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/dom/isvisible
|
|
8
7
|
*/
|
|
9
|
-
|
|
10
8
|
/**
|
|
11
9
|
* Checks whether the element is visible to the user in DOM:
|
|
12
10
|
*
|
|
@@ -20,6 +18,6 @@
|
|
|
20
18
|
* @param {HTMLElement|null|undefined} element
|
|
21
19
|
* @returns {Boolean}
|
|
22
20
|
*/
|
|
23
|
-
export default function isVisible(
|
|
24
|
-
|
|
21
|
+
export default function isVisible(element) {
|
|
22
|
+
return !!(element && element.getClientRects && element.getClientRects().length);
|
|
25
23
|
}
|
package/src/dom/iswindow.js
CHANGED
|
@@ -2,29 +2,24 @@
|
|
|
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/dom/iswindow
|
|
8
7
|
*/
|
|
9
|
-
|
|
10
8
|
/**
|
|
11
9
|
* Checks if the object is a native DOM Window.
|
|
12
10
|
*
|
|
13
11
|
* @param {*} obj
|
|
14
12
|
* @returns {Boolean}
|
|
15
13
|
*/
|
|
16
|
-
export default function isWindow(
|
|
17
|
-
|
|
18
|
-
|
|
19
|
-
|
|
20
|
-
|
|
21
|
-
|
|
22
|
-
|
|
23
|
-
|
|
24
|
-
|
|
25
|
-
|
|
26
|
-
|
|
27
|
-
}
|
|
28
|
-
|
|
29
|
-
return false;
|
|
14
|
+
export default function isWindow(obj) {
|
|
15
|
+
const stringifiedObject = Object.prototype.toString.apply(obj);
|
|
16
|
+
// Returns `true` for the `window` object in browser environments.
|
|
17
|
+
if (stringifiedObject == '[object Window]') {
|
|
18
|
+
return true;
|
|
19
|
+
}
|
|
20
|
+
// Returns `true` for the `window` object in the Electron environment.
|
|
21
|
+
if (stringifiedObject == '[object global]') {
|
|
22
|
+
return true;
|
|
23
|
+
}
|
|
24
|
+
return false;
|
|
30
25
|
}
|