@ckeditor/ckeditor5-utils 37.0.1 → 38.0.0-rc.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/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@ckeditor/ckeditor5-utils",
3
- "version": "37.0.1",
3
+ "version": "38.0.0-rc.0",
4
4
  "description": "Miscellaneous utilities used by CKEditor 5.",
5
5
  "keywords": [
6
6
  "ckeditor",
@@ -14,10 +14,10 @@
14
14
  "lodash-es": "^4.17.15"
15
15
  },
16
16
  "devDependencies": {
17
- "@ckeditor/ckeditor5-build-classic": "^37.0.1",
18
- "@ckeditor/ckeditor5-editor-classic": "^37.0.1",
19
- "@ckeditor/ckeditor5-core": "^37.0.1",
20
- "@ckeditor/ckeditor5-engine": "^37.0.1",
17
+ "@ckeditor/ckeditor5-build-classic": "^38.0.0-rc.0",
18
+ "@ckeditor/ckeditor5-editor-classic": "^38.0.0-rc.0",
19
+ "@ckeditor/ckeditor5-core": "^38.0.0-rc.0",
20
+ "@ckeditor/ckeditor5-engine": "^38.0.0-rc.0",
21
21
  "@types/lodash-es": "^4.17.6",
22
22
  "typescript": "^4.8.4"
23
23
  },
package/src/delay.d.ts ADDED
@@ -0,0 +1,19 @@
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/delay
7
+ */
8
+ /**
9
+ * Returns a function wrapper that will trigger a function after a specified wait time.
10
+ * The timeout can be canceled by calling the cancel function on the returned wrapped function.
11
+ *
12
+ * @param func The function to wrap.
13
+ * @param wait The timeout in ms.
14
+ */
15
+ export default function delay<T extends (...args: Array<any>) => any>(func: T, wait: number): DelayedFunc<T>;
16
+ export interface DelayedFunc<T extends (...args: Array<any>) => any> {
17
+ (...args: Parameters<T>): void;
18
+ cancel(): void;
19
+ }
package/src/delay.js ADDED
@@ -0,0 +1,26 @@
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/delay
7
+ */
8
+ /* globals setTimeout, clearTimeout */
9
+ /**
10
+ * Returns a function wrapper that will trigger a function after a specified wait time.
11
+ * The timeout can be canceled by calling the cancel function on the returned wrapped function.
12
+ *
13
+ * @param func The function to wrap.
14
+ * @param wait The timeout in ms.
15
+ */
16
+ export default function delay(func, wait) {
17
+ let timer;
18
+ function delayed(...args) {
19
+ delayed.cancel();
20
+ timer = setTimeout(() => func(...args), wait);
21
+ }
22
+ delayed.cancel = () => {
23
+ clearTimeout(timer);
24
+ };
25
+ return delayed;
26
+ }
package/src/dom/global.js CHANGED
@@ -25,7 +25,7 @@ try {
25
25
  }
26
26
  catch (e) {
27
27
  // It's not possible to mock a window object to simulate lack of a window object without writing extremely convoluted code.
28
- /* istanbul ignore next */
28
+ /* istanbul ignore next -- @preserve */
29
29
  // Let's cast it to not change module's API.
30
30
  // We only handle this so loading editor in environments without window and document doesn't fail.
31
31
  // For better DX we shouldn't introduce mixed types and require developers to check the type manually.
@@ -0,0 +1,10 @@
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
+ * Checks if the given attribute name is valid in terms of HTML.
7
+ *
8
+ * @param name Attribute name.
9
+ */
10
+ export default function isValidAttributeName(name: string): boolean;
@@ -0,0 +1,22 @@
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/dom/isvalidattributename
7
+ */
8
+ import global from './global';
9
+ /**
10
+ * Checks if the given attribute name is valid in terms of HTML.
11
+ *
12
+ * @param name Attribute name.
13
+ */
14
+ export default function isValidAttributeName(name) {
15
+ try {
16
+ global.document.createAttribute(name);
17
+ }
18
+ catch (error) {
19
+ return false;
20
+ }
21
+ return true;
22
+ }
@@ -172,7 +172,7 @@ export default function EmitterMixin(base) {
172
172
  }
173
173
  catch (err) {
174
174
  // @if CK_DEBUG // throw err;
175
- /* istanbul ignore next */
175
+ /* istanbul ignore next -- @preserve */
176
176
  CKEditorError.rethrowUnexpectedError(err, this);
177
177
  }
178
178
  }
package/src/index.d.ts CHANGED
@@ -36,6 +36,7 @@ export { default as insertAt } from './dom/insertat';
36
36
  export { default as isComment } from './dom/iscomment';
37
37
  export { default as isNode } from './dom/isnode';
38
38
  export { default as isRange } from './dom/isrange';
39
+ export { default as isValidAttributeName } from './dom/isvalidattributename';
39
40
  export { default as isVisible } from './dom/isvisible';
40
41
  export { getOptimalPosition, type Options as PositionOptions, type PositioningFunction } from './dom/position';
41
42
  export { default as remove } from './dom/remove';
@@ -53,5 +54,7 @@ export { default as priorities, type PriorityString } from './priorities';
53
54
  export { default as insertToPriorityArray } from './inserttopriorityarray';
54
55
  export { default as spliceArray } from './splicearray';
55
56
  export { default as uid } from './uid';
57
+ export { default as delay, type DelayedFunc } from './delay';
58
+ export { default as verifyLicense } from './verifylicense';
56
59
  export * from './unicode';
57
- export { default as version } from './version';
60
+ export { default as version, releaseDate } from './version';
package/src/index.js CHANGED
@@ -35,6 +35,7 @@ export { default as insertAt } from './dom/insertat';
35
35
  export { default as isComment } from './dom/iscomment';
36
36
  export { default as isNode } from './dom/isnode';
37
37
  export { default as isRange } from './dom/isrange';
38
+ export { default as isValidAttributeName } from './dom/isvalidattributename';
38
39
  export { default as isVisible } from './dom/isvisible';
39
40
  export { getOptimalPosition } from './dom/position';
40
41
  export { default as remove } from './dom/remove';
@@ -52,5 +53,7 @@ export { default as priorities } from './priorities';
52
53
  export { default as insertToPriorityArray } from './inserttopriorityarray';
53
54
  export { default as spliceArray } from './splicearray';
54
55
  export { default as uid } from './uid';
56
+ export { default as delay } from './delay';
57
+ export { default as verifyLicense } from './verifylicense';
55
58
  export * from './unicode';
56
- export { default as version } from './version';
59
+ export { default as version, releaseDate } from './version';
package/src/mix.d.ts CHANGED
@@ -78,8 +78,8 @@ export type Constructor<Instance = object> = abstract new (...args: Array<any>)
78
78
  * @typeParam Mixin An interface representing mixin.
79
79
  */
80
80
  export type Mixed<Base extends Constructor, Mixin extends object> = {
81
- new (...args: ConstructorParameters<Base>): InstanceType<Base> & Mixin;
82
- prototype: InstanceType<Base> & Mixin;
81
+ new (...args: ConstructorParameters<Base>): Mixin & InstanceType<Base>;
82
+ prototype: Mixin & InstanceType<Base>;
83
83
  } & {
84
84
  [K in keyof Base]: Base[K];
85
85
  };
@@ -8,7 +8,7 @@
8
8
  */
9
9
  import CKEditorError from './ckeditorerror';
10
10
  import global from './dom/global';
11
- /* istanbul ignore else */
11
+ /* istanbul ignore else -- @preserve */
12
12
  if (!global.window.CKEDITOR_TRANSLATIONS) {
13
13
  global.window.CKEDITOR_TRANSLATIONS = {};
14
14
  }
@@ -0,0 +1,15 @@
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
+ * Possible states of the key after verification.
7
+ */
8
+ export type VerifiedKeyStatus = 'VALID' | 'INVALID';
9
+ /**
10
+ * Checks whether the given string contains information that allows you to verify the license status.
11
+ *
12
+ * @param token The string to check.
13
+ * @returns String that represents the state of given `token` parameter.
14
+ */
15
+ export default function verifyLicense(token: string | undefined): VerifiedKeyStatus;
@@ -0,0 +1,83 @@
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/verifylicense
7
+ */
8
+ import { releaseDate } from './version';
9
+ /**
10
+ * Checks whether the given string contains information that allows you to verify the license status.
11
+ *
12
+ * @param token The string to check.
13
+ * @returns String that represents the state of given `token` parameter.
14
+ */
15
+ export default function verifyLicense(token) {
16
+ function oldTokenCheck(token) {
17
+ if (token.match(/^[a-zA-Z0-9+/=$]+$/g) && (token.length >= 40 && token.length <= 255)) {
18
+ return 'VALID';
19
+ }
20
+ else {
21
+ return 'INVALID';
22
+ }
23
+ }
24
+ // TODO: issue ci#3175
25
+ let decryptedData = '';
26
+ let decryptedSecondElement = '';
27
+ if (!token) {
28
+ return 'INVALID';
29
+ }
30
+ try {
31
+ decryptedData = atob(token);
32
+ }
33
+ catch (e) {
34
+ return 'INVALID';
35
+ }
36
+ const splittedDecryptedData = decryptedData.split('-');
37
+ const firstElement = splittedDecryptedData[0];
38
+ const secondElement = splittedDecryptedData[1];
39
+ if (!secondElement) {
40
+ return oldTokenCheck(token);
41
+ }
42
+ try {
43
+ atob(secondElement);
44
+ }
45
+ catch (e) {
46
+ try {
47
+ atob(firstElement);
48
+ if (!atob(firstElement).length) {
49
+ return oldTokenCheck(token);
50
+ }
51
+ }
52
+ catch (e) {
53
+ return oldTokenCheck(token);
54
+ }
55
+ }
56
+ if (firstElement.length < 40 || firstElement.length > 255) {
57
+ return 'INVALID';
58
+ }
59
+ try {
60
+ // Must be a valid format.
61
+ atob(firstElement);
62
+ }
63
+ catch (e) {
64
+ return 'INVALID';
65
+ }
66
+ try {
67
+ decryptedSecondElement = atob(secondElement);
68
+ }
69
+ catch (e) {
70
+ return 'INVALID';
71
+ }
72
+ if (decryptedSecondElement.length !== 8) {
73
+ return 'INVALID';
74
+ }
75
+ const year = Number(decryptedSecondElement.substring(0, 4));
76
+ const monthIndex = Number(decryptedSecondElement.substring(4, 6)) - 1;
77
+ const day = Number(decryptedSecondElement.substring(6, 8));
78
+ const date = new Date(year, monthIndex, day);
79
+ if (date < releaseDate || isNaN(Number(date))) {
80
+ return 'INVALID';
81
+ }
82
+ return 'VALID';
83
+ }
package/src/version.d.ts CHANGED
@@ -2,8 +2,9 @@
2
2
  * @license Copyright (c) 2003-2023, 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
- declare const version = "37.0.1";
5
+ declare const version = "38.0.0-rc.0";
6
6
  export default version;
7
+ export declare const releaseDate: Date;
7
8
  declare global {
8
9
  var CKEDITOR_VERSION: string;
9
10
  }
package/src/version.js CHANGED
@@ -7,11 +7,13 @@
7
7
  */
8
8
  /* globals window, global */
9
9
  import CKEditorError from './ckeditorerror';
10
- const version = '37.0.1';
10
+ const version = '38.0.0-rc.0';
11
11
  export default version;
12
- /* istanbul ignore next */
12
+ // The second argument is not a month. It is `monthIndex` and starts from `0`.
13
+ export const releaseDate = new Date(2023, 4, 15);
14
+ /* istanbul ignore next -- @preserve */
13
15
  const windowOrGlobal = typeof window === 'object' ? window : global;
14
- /* istanbul ignore next */
16
+ /* istanbul ignore next -- @preserve */
15
17
  if (windowOrGlobal.CKEDITOR_VERSION) {
16
18
  /**
17
19
  * This error is thrown when due to a mistake in how CKEditor 5 was installed or initialized, some