@ckeditor/ckeditor5-utils 45.1.0 → 45.2.0-alpha.1
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/dist/index.js +274 -15
- package/dist/index.js.map +1 -1
- package/package.json +2 -2
- package/src/areconnectedthroughproperties.js +2 -4
- package/src/ckeditorerror.js +0 -1
- package/src/delay.js +0 -1
- package/src/dom/getancestors.js +0 -1
- package/src/dom/getdatafromelement.js +0 -1
- package/src/dom/global.js +1 -1
- package/src/dom/iscomment.js +0 -1
- package/src/dom/isvalidattributename.js +1 -1
- package/src/dom/setdatainelement.js +0 -1
- package/src/env.js +2 -3
- package/src/focustracker.js +0 -1
- package/src/formathtml.d.ts +19 -0
- package/src/formathtml.js +164 -0
- package/src/index.d.ts +1 -0
- package/src/index.js +1 -0
- package/src/locale.js +0 -1
- package/src/parsebase64encodedobject.js +1 -1
- package/src/version.d.ts +1 -1
- package/src/version.js +2 -2
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@ckeditor/ckeditor5-utils",
|
|
3
|
-
"version": "45.
|
|
3
|
+
"version": "45.2.0-alpha.1",
|
|
4
4
|
"description": "Miscellaneous utilities used by CKEditor 5.",
|
|
5
5
|
"keywords": [
|
|
6
6
|
"ckeditor",
|
|
@@ -12,7 +12,7 @@
|
|
|
12
12
|
"type": "module",
|
|
13
13
|
"main": "src/index.js",
|
|
14
14
|
"dependencies": {
|
|
15
|
-
"@ckeditor/ckeditor5-ui": "45.
|
|
15
|
+
"@ckeditor/ckeditor5-ui": "45.2.0-alpha.1",
|
|
16
16
|
"es-toolkit": "1.32.0"
|
|
17
17
|
},
|
|
18
18
|
"author": "CKSource (http://cksource.com/)",
|
|
@@ -5,7 +5,6 @@
|
|
|
5
5
|
/**
|
|
6
6
|
* @module utils/areconnectedthroughproperties
|
|
7
7
|
*/
|
|
8
|
-
/* globals EventTarget, Event */
|
|
9
8
|
/**
|
|
10
9
|
* Traverses both structures to find out whether there is a reference that is shared between both structures.
|
|
11
10
|
*/
|
|
@@ -43,9 +42,8 @@ function getSubNodes(head) {
|
|
|
43
42
|
try {
|
|
44
43
|
nodes.push(...node);
|
|
45
44
|
}
|
|
46
|
-
|
|
47
|
-
|
|
48
|
-
}
|
|
45
|
+
// eslint-disable-next-line no-empty
|
|
46
|
+
catch { }
|
|
49
47
|
}
|
|
50
48
|
else {
|
|
51
49
|
nodes.push(...Object.values(node));
|
package/src/ckeditorerror.js
CHANGED
package/src/delay.js
CHANGED
|
@@ -5,7 +5,6 @@
|
|
|
5
5
|
/**
|
|
6
6
|
* @module utils/delay
|
|
7
7
|
*/
|
|
8
|
-
/* globals setTimeout, clearTimeout */
|
|
9
8
|
/**
|
|
10
9
|
* Returns a function wrapper that will trigger a function after a specified wait time.
|
|
11
10
|
* The timeout can be canceled by calling the cancel function on the returned wrapped function.
|
package/src/dom/getancestors.js
CHANGED
|
@@ -2,7 +2,6 @@
|
|
|
2
2
|
* @license Copyright (c) 2003-2025, CKSource Holding sp. z o.o. All rights reserved.
|
|
3
3
|
* For licensing, see LICENSE.md or https://ckeditor.com/legal/ckeditor-licensing-options
|
|
4
4
|
*/
|
|
5
|
-
/* globals HTMLTextAreaElement */
|
|
6
5
|
/**
|
|
7
6
|
* @module utils/dom/getdatafromelement
|
|
8
7
|
*/
|
package/src/dom/global.js
CHANGED
|
@@ -23,7 +23,7 @@ let globalVar; // named globalVar instead of global: https://github.com/ckeditor
|
|
|
23
23
|
try {
|
|
24
24
|
globalVar = { window, document };
|
|
25
25
|
}
|
|
26
|
-
catch
|
|
26
|
+
catch {
|
|
27
27
|
// It's not possible to mock a window object to simulate lack of a window object without writing extremely convoluted code.
|
|
28
28
|
/* istanbul ignore next -- @preserve */
|
|
29
29
|
// Let's cast it to not change module's API.
|
package/src/dom/iscomment.js
CHANGED
package/src/env.js
CHANGED
|
@@ -2,7 +2,6 @@
|
|
|
2
2
|
* @license Copyright (c) 2003-2025, CKSource Holding sp. z o.o. All rights reserved.
|
|
3
3
|
* For licensing, see LICENSE.md or https://ckeditor.com/legal/ckeditor-licensing-options
|
|
4
4
|
*/
|
|
5
|
-
/* globals navigator:false */
|
|
6
5
|
/**
|
|
7
6
|
* @module utils/env
|
|
8
7
|
*/
|
|
@@ -16,7 +15,7 @@ export function getUserAgent() {
|
|
|
16
15
|
try {
|
|
17
16
|
return navigator.userAgent.toLowerCase();
|
|
18
17
|
}
|
|
19
|
-
catch
|
|
18
|
+
catch {
|
|
20
19
|
return '';
|
|
21
20
|
}
|
|
22
21
|
}
|
|
@@ -122,7 +121,7 @@ export function isRegExpUnicodePropertySupported() {
|
|
|
122
121
|
// Usage of regular expression literal cause error during build (ckeditor/ckeditor5-dev#534).
|
|
123
122
|
isSupported = 'ć'.search(new RegExp('[\\p{L}]', 'u')) === 0;
|
|
124
123
|
}
|
|
125
|
-
catch
|
|
124
|
+
catch {
|
|
126
125
|
// Firefox throws a SyntaxError when the group is unsupported.
|
|
127
126
|
}
|
|
128
127
|
return isSupported;
|
package/src/focustracker.js
CHANGED
|
@@ -0,0 +1,19 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* @license Copyright (c) 2003-2025, CKSource Holding sp. z o.o. All rights reserved.
|
|
3
|
+
* For licensing, see LICENSE.md or https://ckeditor.com/legal/ckeditor-licensing-options
|
|
4
|
+
*/
|
|
5
|
+
/**
|
|
6
|
+
* @module utils/formathtml
|
|
7
|
+
*/
|
|
8
|
+
/**
|
|
9
|
+
* A simple (and naive) HTML code formatter that returns a formatted HTML markup that can be easily
|
|
10
|
+
* parsed by human eyes. It beautifies the HTML code by adding new lines between elements that behave like block elements
|
|
11
|
+
* (https://developer.mozilla.org/en-US/docs/Web/HTML/Block-level_elements
|
|
12
|
+
* and a few more like `tr`, `td`, and similar ones) and inserting indents for nested content.
|
|
13
|
+
*
|
|
14
|
+
* WARNING: This function works only on a text that does not contain any indentations or new lines.
|
|
15
|
+
* Calling this function on the already formatted text will damage the formatting.
|
|
16
|
+
*
|
|
17
|
+
* @param input An HTML string to format.
|
|
18
|
+
*/
|
|
19
|
+
export default function formatHtml(input: string): string;
|
|
@@ -0,0 +1,164 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* @license Copyright (c) 2003-2025, CKSource Holding sp. z o.o. All rights reserved.
|
|
3
|
+
* For licensing, see LICENSE.md or https://ckeditor.com/legal/ckeditor-licensing-options
|
|
4
|
+
*/
|
|
5
|
+
/**
|
|
6
|
+
* @module utils/formathtml
|
|
7
|
+
*/
|
|
8
|
+
/**
|
|
9
|
+
* A simple (and naive) HTML code formatter that returns a formatted HTML markup that can be easily
|
|
10
|
+
* parsed by human eyes. It beautifies the HTML code by adding new lines between elements that behave like block elements
|
|
11
|
+
* (https://developer.mozilla.org/en-US/docs/Web/HTML/Block-level_elements
|
|
12
|
+
* and a few more like `tr`, `td`, and similar ones) and inserting indents for nested content.
|
|
13
|
+
*
|
|
14
|
+
* WARNING: This function works only on a text that does not contain any indentations or new lines.
|
|
15
|
+
* Calling this function on the already formatted text will damage the formatting.
|
|
16
|
+
*
|
|
17
|
+
* @param input An HTML string to format.
|
|
18
|
+
*/
|
|
19
|
+
export default function formatHtml(input) {
|
|
20
|
+
// A list of block-like elements around which the new lines should be inserted, and within which
|
|
21
|
+
// the indentation of their children should be increased.
|
|
22
|
+
// The list is partially based on https://developer.mozilla.org/en-US/docs/Web/HTML/Block-level_elements that contains
|
|
23
|
+
// a full list of HTML block-level elements.
|
|
24
|
+
// A void element is an element that cannot have any child - https://html.spec.whatwg.org/multipage/syntax.html#void-elements.
|
|
25
|
+
// Note that <pre> element is not listed on this list to avoid breaking whitespace formatting.
|
|
26
|
+
// Note that <br> element is not listed and handled separately so no additional white spaces are injected.
|
|
27
|
+
const elementsToFormat = [
|
|
28
|
+
{ name: 'address', isVoid: false },
|
|
29
|
+
{ name: 'article', isVoid: false },
|
|
30
|
+
{ name: 'aside', isVoid: false },
|
|
31
|
+
{ name: 'blockquote', isVoid: false },
|
|
32
|
+
{ name: 'details', isVoid: false },
|
|
33
|
+
{ name: 'dialog', isVoid: false },
|
|
34
|
+
{ name: 'dd', isVoid: false },
|
|
35
|
+
{ name: 'div', isVoid: false },
|
|
36
|
+
{ name: 'dl', isVoid: false },
|
|
37
|
+
{ name: 'dt', isVoid: false },
|
|
38
|
+
{ name: 'fieldset', isVoid: false },
|
|
39
|
+
{ name: 'figcaption', isVoid: false },
|
|
40
|
+
{ name: 'figure', isVoid: false },
|
|
41
|
+
{ name: 'footer', isVoid: false },
|
|
42
|
+
{ name: 'form', isVoid: false },
|
|
43
|
+
{ name: 'h1', isVoid: false },
|
|
44
|
+
{ name: 'h2', isVoid: false },
|
|
45
|
+
{ name: 'h3', isVoid: false },
|
|
46
|
+
{ name: 'h4', isVoid: false },
|
|
47
|
+
{ name: 'h5', isVoid: false },
|
|
48
|
+
{ name: 'h6', isVoid: false },
|
|
49
|
+
{ name: 'header', isVoid: false },
|
|
50
|
+
{ name: 'hgroup', isVoid: false },
|
|
51
|
+
{ name: 'hr', isVoid: true },
|
|
52
|
+
{ name: 'li', isVoid: false },
|
|
53
|
+
{ name: 'main', isVoid: false },
|
|
54
|
+
{ name: 'nav', isVoid: false },
|
|
55
|
+
{ name: 'ol', isVoid: false },
|
|
56
|
+
{ name: 'p', isVoid: false },
|
|
57
|
+
{ name: 'section', isVoid: false },
|
|
58
|
+
{ name: 'table', isVoid: false },
|
|
59
|
+
{ name: 'tbody', isVoid: false },
|
|
60
|
+
{ name: 'td', isVoid: false },
|
|
61
|
+
{ name: 'th', isVoid: false },
|
|
62
|
+
{ name: 'thead', isVoid: false },
|
|
63
|
+
{ name: 'tr', isVoid: false },
|
|
64
|
+
{ name: 'ul', isVoid: false }
|
|
65
|
+
];
|
|
66
|
+
const elementNamesToFormat = elementsToFormat.map(element => element.name).join('|');
|
|
67
|
+
// It is not the fastest way to format the HTML markup but the performance should be good enough.
|
|
68
|
+
const lines = input
|
|
69
|
+
// Add new line before and after `<tag>` and `</tag>`.
|
|
70
|
+
// It may separate individual elements with two new lines, but this will be fixed below.
|
|
71
|
+
.replace(new RegExp(`</?(${elementNamesToFormat})( .*?)?>`, 'g'), '\n$&\n')
|
|
72
|
+
// Keep `<br>`s at the end of line to avoid adding additional whitespaces before `<br>`.
|
|
73
|
+
.replace(/<br[^>]*>/g, '$&\n')
|
|
74
|
+
// Divide input string into lines, which start with either an opening tag, a closing tag, or just a text.
|
|
75
|
+
.split('\n');
|
|
76
|
+
let indentCount = 0;
|
|
77
|
+
let isPreformattedLine = false;
|
|
78
|
+
return lines
|
|
79
|
+
.map(line => {
|
|
80
|
+
isPreformattedLine = isPreformattedBlockLine(line, isPreformattedLine);
|
|
81
|
+
// Ignore empty lines outside a <pre> block.
|
|
82
|
+
if (!line.length && !isPreformattedLine) {
|
|
83
|
+
return '';
|
|
84
|
+
}
|
|
85
|
+
if (isNonVoidOpeningTag(line, elementsToFormat)) {
|
|
86
|
+
return indentLine(line, indentCount++);
|
|
87
|
+
}
|
|
88
|
+
if (isClosingTag(line, elementsToFormat)) {
|
|
89
|
+
return indentLine(line, --indentCount);
|
|
90
|
+
}
|
|
91
|
+
if (isPreformattedLine === 'middle' || isPreformattedLine === 'last') {
|
|
92
|
+
return indentLine(line, 0);
|
|
93
|
+
}
|
|
94
|
+
return indentLine(line, indentCount);
|
|
95
|
+
})
|
|
96
|
+
.join('')
|
|
97
|
+
.trimEnd();
|
|
98
|
+
}
|
|
99
|
+
/**
|
|
100
|
+
* Checks, if an argument is an opening tag of a non-void element to be formatted.
|
|
101
|
+
*
|
|
102
|
+
* @param line String to check.
|
|
103
|
+
* @param elementsToFormat Elements to be formatted.
|
|
104
|
+
*/
|
|
105
|
+
function isNonVoidOpeningTag(line, elementsToFormat) {
|
|
106
|
+
return elementsToFormat.some(element => {
|
|
107
|
+
if (element.isVoid) {
|
|
108
|
+
return false;
|
|
109
|
+
}
|
|
110
|
+
if (!new RegExp(`<${element.name}( .*?)?>`).test(line)) {
|
|
111
|
+
return false;
|
|
112
|
+
}
|
|
113
|
+
return true;
|
|
114
|
+
});
|
|
115
|
+
}
|
|
116
|
+
/**
|
|
117
|
+
* Checks, if an argument is a closing tag.
|
|
118
|
+
*
|
|
119
|
+
* @param line String to check.
|
|
120
|
+
* @param elementsToFormat Elements to be formatted.
|
|
121
|
+
*/
|
|
122
|
+
function isClosingTag(line, elementsToFormat) {
|
|
123
|
+
return elementsToFormat.some(element => {
|
|
124
|
+
return new RegExp(`</${element.name}>`).test(line);
|
|
125
|
+
});
|
|
126
|
+
}
|
|
127
|
+
/**
|
|
128
|
+
* Indents a line by a specified number of characters.
|
|
129
|
+
*
|
|
130
|
+
* @param line Line to indent.
|
|
131
|
+
* @param indentCount Number of characters to use for indentation.
|
|
132
|
+
* @param indentChar Indentation character(s). 4 spaces by default.
|
|
133
|
+
*/
|
|
134
|
+
function indentLine(line, indentCount, indentChar = ' ') {
|
|
135
|
+
// More about Math.max() here in https://github.com/ckeditor/ckeditor5/issues/10698.
|
|
136
|
+
return `${indentChar.repeat(Math.max(0, indentCount))}${line}\n`;
|
|
137
|
+
}
|
|
138
|
+
/**
|
|
139
|
+
* Checks whether a line belongs to a preformatted (`<pre>`) block.
|
|
140
|
+
*
|
|
141
|
+
* @param line Line to check.
|
|
142
|
+
* @param isPreviousLinePreFormatted Information on whether the previous line was preformatted (and how).
|
|
143
|
+
*/
|
|
144
|
+
function isPreformattedBlockLine(line, isPreviousLinePreFormatted) {
|
|
145
|
+
const isPreOpen = /<pre( .*?)?>/.test(line);
|
|
146
|
+
const isPreClose = /<\/pre>/.test(line);
|
|
147
|
+
if (isPreOpen && isPreClose) {
|
|
148
|
+
// If both an opening and closing a <pre> tag, no special treatment needed.
|
|
149
|
+
return false;
|
|
150
|
+
}
|
|
151
|
+
else if (isPreOpen) {
|
|
152
|
+
return 'first';
|
|
153
|
+
}
|
|
154
|
+
else if (isPreClose) {
|
|
155
|
+
return 'last';
|
|
156
|
+
}
|
|
157
|
+
else if (isPreviousLinePreFormatted === 'first' || isPreviousLinePreFormatted === 'middle') {
|
|
158
|
+
// This line is just after a 'first' or 'middle' line of a multi-line pre-block.
|
|
159
|
+
return 'middle';
|
|
160
|
+
}
|
|
161
|
+
else {
|
|
162
|
+
return false;
|
|
163
|
+
}
|
|
164
|
+
}
|
package/src/index.d.ts
CHANGED
|
@@ -65,5 +65,6 @@ export { default as wait } from './wait.js';
|
|
|
65
65
|
export { default as parseBase64EncodedObject } from './parsebase64encodedobject.js';
|
|
66
66
|
export { default as crc32, type CRCData } from './crc32.js';
|
|
67
67
|
export { default as collectStylesheets } from './collectstylesheets.js';
|
|
68
|
+
export { default as formatHtml } from './formathtml.js';
|
|
68
69
|
export * from './unicode.js';
|
|
69
70
|
export { default as version, releaseDate } from './version.js';
|
package/src/index.js
CHANGED
|
@@ -64,5 +64,6 @@ export { default as wait } from './wait.js';
|
|
|
64
64
|
export { default as parseBase64EncodedObject } from './parsebase64encodedobject.js';
|
|
65
65
|
export { default as crc32 } from './crc32.js';
|
|
66
66
|
export { default as collectStylesheets } from './collectstylesheets.js';
|
|
67
|
+
export { default as formatHtml } from './formathtml.js';
|
|
67
68
|
export * from './unicode.js';
|
|
68
69
|
export { default as version, releaseDate } from './version.js';
|
package/src/locale.js
CHANGED
package/src/version.d.ts
CHANGED
|
@@ -2,7 +2,7 @@
|
|
|
2
2
|
* @license Copyright (c) 2003-2025, CKSource Holding sp. z o.o. All rights reserved.
|
|
3
3
|
* For licensing, see LICENSE.md or https://ckeditor.com/legal/ckeditor-licensing-options
|
|
4
4
|
*/
|
|
5
|
-
declare const version = "45.
|
|
5
|
+
declare const version = "45.2.0-alpha.1";
|
|
6
6
|
export default version;
|
|
7
7
|
export declare const releaseDate: Date;
|
|
8
8
|
declare global {
|
package/src/version.js
CHANGED
|
@@ -6,10 +6,10 @@
|
|
|
6
6
|
* @module utils/version
|
|
7
7
|
*/
|
|
8
8
|
import CKEditorError from './ckeditorerror.js';
|
|
9
|
-
const version = '45.
|
|
9
|
+
const version = '45.2.0-alpha.1';
|
|
10
10
|
export default version;
|
|
11
11
|
// The second argument is not a month. It is `monthIndex` and starts from `0`.
|
|
12
|
-
export const releaseDate = new Date(2025, 4,
|
|
12
|
+
export const releaseDate = new Date(2025, 4, 29);
|
|
13
13
|
/* istanbul ignore next -- @preserve */
|
|
14
14
|
if (globalThis.CKEDITOR_VERSION) {
|
|
15
15
|
/**
|