@ckeditor/ckeditor5-utils 35.1.0 → 35.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/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@ckeditor/ckeditor5-utils",
3
- "version": "35.1.0",
3
+ "version": "35.2.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": "^35.1.0",
18
- "@ckeditor/ckeditor5-editor-classic": "^35.1.0",
19
- "@ckeditor/ckeditor5-core": "^35.1.0",
20
- "@ckeditor/ckeditor5-engine": "^35.1.0",
17
+ "@ckeditor/ckeditor5-build-classic": "^35.2.0",
18
+ "@ckeditor/ckeditor5-editor-classic": "^35.2.0",
19
+ "@ckeditor/ckeditor5-core": "^35.2.0",
20
+ "@ckeditor/ckeditor5-engine": "^35.2.0",
21
21
  "@types/lodash-es": "^4.17.6",
22
22
  "typescript": "^4.6.4"
23
23
  },
package/src/dom/rect.js CHANGED
@@ -9,7 +9,6 @@ import isRange from './isrange';
9
9
  import isWindow from './iswindow';
10
10
  import getBorderWidths from './getborderwidths';
11
11
  import isText from './istext';
12
- import { isElement } from 'lodash-es';
13
12
  const rectProperties = ['top', 'right', 'bottom', 'left', 'width', 'height'];
14
13
  /**
15
14
  * A helper class representing a `ClientRect` object, e.g. value returned by
@@ -352,13 +351,13 @@ function isBody(value) {
352
351
  }
353
352
  return value === value.ownerDocument.body;
354
353
  }
355
- // Checks if provided object is a DOM Element.
356
- //
357
- // It's just a wrapper for lodash `isElement` but with type guard.
354
+ // Checks if provided object "looks like" a DOM Element and has API required by `Rect` class.
358
355
  //
359
356
  // @private
360
357
  // @param {*} value
361
358
  // @returns {Boolean}
362
359
  function isDomElement(value) {
363
- return isElement(value);
360
+ // Note: earlier we used `isElement()` from lodash library, however that function is less performant because
361
+ // it makes complicated checks to make sure that given value is a DOM element.
362
+ return value !== null && typeof value === 'object' && value.nodeType === 1 && typeof value.getBoundingClientRect === 'function';
364
363
  }
@@ -71,7 +71,7 @@ export default class KeystrokeHandler {
71
71
  * the {@link module:utils/keyboard~parseKeystroke} function.
72
72
  * @param {Function} callback A function called with the
73
73
  * {@link module:engine/view/observer/keyobserver~KeyEventData key event data} object and
74
- * a helper funcion to call both `preventDefault()` and `stopPropagation()` on the underlying event.
74
+ * a helper function to call both `preventDefault()` and `stopPropagation()` on the underlying event.
75
75
  * @param {Object} [options={}] Additional options.
76
76
  * @param {module:utils/priorities~PriorityString|Number} [options.priority='normal'] The priority of the keystroke
77
77
  * callback. The higher the priority value the sooner the callback will be executed. Keystrokes having the same priority
@@ -0,0 +1,39 @@
1
+ /**
2
+ * @license Copyright (c) 2003-2022, 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/splicearray
7
+ */
8
+ const BIG_CHUNK_SIZE = 10000;
9
+ /**
10
+ * Splices one array into another. To be used instead of `Array.prototype.splice` as the latter may
11
+ * throw "Maximum call stack size exceeded" when passed huge number of items to insert.
12
+ *
13
+ * Note: in contrary to Array.splice, this function does not modify the original `target`.
14
+ *
15
+ * spliceArray( [ 1, 2 ], [ 3, 4 ], 0, 0 ); // [ 3, 4, 1, 2 ]
16
+ * spliceArray( [ 1, 2 ], [ 3, 4 ], 1, 1 ); // [ 1, 3, 4 ]
17
+ * spliceArray( [ 1, 2 ], [ 3, 4 ], 1, 0 ); // [ 1, 3, 4, 2 ]
18
+ * spliceArray( [ 1, 2 ], [ 3, 4 ], 2, 0 ); // [ 1, 2, 3, 4 ]
19
+ * spliceArray( [ 1, 2 ], [], 0, 1 ); // [ 2 ]
20
+ *
21
+ * @private
22
+ * @param {Array} target Array to be spliced.
23
+ * @param {Array} source Array of elements to be inserted to target.
24
+ * @param {Number} start Index at which nodes should be inserted/removed.
25
+ * @param {Number} count Number of items.
26
+ *
27
+ * @returns {Array} New spliced array.
28
+ */
29
+ export default function spliceArray(target, source, start, count) {
30
+ // In case of performance problems, see: https://github.com/ckeditor/ckeditor5/pull/12429/files#r965850568
31
+ if (Math.max(source.length, target.length) > BIG_CHUNK_SIZE) {
32
+ return target.slice(0, start).concat(source).concat(target.slice(start + count, target.length));
33
+ }
34
+ else {
35
+ const newTarget = Array.from(target);
36
+ newTarget.splice(start, count, ...source);
37
+ return newTarget;
38
+ }
39
+ }
package/src/version.js CHANGED
@@ -7,7 +7,7 @@
7
7
  */
8
8
  /* globals window, global */
9
9
  import CKEditorError from './ckeditorerror';
10
- const version = '35.1.0';
10
+ const version = '35.2.0';
11
11
  export default version;
12
12
  /* istanbul ignore next */
13
13
  const windowOrGlobal = typeof window === 'object' ? window : global;