@vaadin/component-base 23.6.4 → 23.6.5

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": "@vaadin/component-base",
3
- "version": "23.6.4",
3
+ "version": "23.6.5",
4
4
  "publishConfig": {
5
5
  "access": "public"
6
6
  },
@@ -42,5 +42,5 @@
42
42
  "@vaadin/testing-helpers": "^0.3.2",
43
43
  "sinon": "^13.0.2"
44
44
  },
45
- "gitHead": "5b6742f8777f6ad4e8ad833d4023a84cc55b7be7"
45
+ "gitHead": "d55853f02f62ce8a506a3ffd4f4a91dfb5cc66a2"
46
46
  }
@@ -44,7 +44,7 @@ const registered = new Set();
44
44
  export const ElementMixin = (superClass) =>
45
45
  class VaadinElementMixin extends DirMixin(superClass) {
46
46
  static get version() {
47
- return '23.6.4';
47
+ return '23.6.5';
48
48
  }
49
49
 
50
50
  /** @protected */
@@ -0,0 +1,44 @@
1
+ /**
2
+ * @license
3
+ * Copyright (c) 2000 - 2024 Vaadin Ltd.
4
+ *
5
+ * This program is available under Vaadin Commercial License and Service Terms.
6
+ *
7
+ *
8
+ * See https://vaadin.com/commercial-license-and-service-terms for the full
9
+ * license.
10
+ */
11
+
12
+ /**
13
+ * Recursively copies own properties of `source` into `target` and returns
14
+ * `target`. Plain objects are merged, other values are assigned as they are.
15
+ * An object is plain when it inherits from `Object.prototype` or from nothing,
16
+ * so values such as a `Date` or a class instance are assigned, not merged.
17
+ *
18
+ * Merges a single source. Use `deepMergePartials()` to merge several objects,
19
+ * or to merge objects that only provide some of the properties.
20
+ *
21
+ * Both arguments are expected to be plain objects. When either of them is not,
22
+ * `target` is returned without changes. A property of the target that is not a
23
+ * plain object is replaced with the merged object, unlike the arguments.
24
+ *
25
+ * Keys that would modify `Object.prototype`, such as `__proto__`, are ignored.
26
+ */
27
+ export function deepMerge<T extends object>(target: T, source: object): T;
28
+
29
+ /**
30
+ * Recursively merges partial objects into `target` in order and returns
31
+ * `target`, so that a later source overrides an earlier one.
32
+ *
33
+ * Values that are `null` or `undefined` are skipped, so a source that only
34
+ * provides some of the properties does not remove the others. For the same
35
+ * reason, a property that the target already has is not replaced with an
36
+ * object when the source has one for the same key. Arrays are copied one level
37
+ * deep, so that the result does not share an array with any of the sources.
38
+ *
39
+ * Sources that are not plain objects are ignored. When `target` is not a plain
40
+ * object, it is returned without changes.
41
+ *
42
+ * Keys that would modify `Object.prototype`, such as `__proto__`, are ignored.
43
+ */
44
+ export function deepMergePartials<T extends object>(target: T, ...sources: object[]): T;
@@ -0,0 +1,116 @@
1
+ /**
2
+ * @license
3
+ * Copyright (c) 2000 - 2024 Vaadin Ltd.
4
+ *
5
+ * This program is available under Vaadin Commercial License and Service Terms.
6
+ *
7
+ *
8
+ * See https://vaadin.com/commercial-license-and-service-terms for the full
9
+ * license.
10
+ */
11
+
12
+ /**
13
+ * Keys that are not copied while merging, as assigning them would modify
14
+ * `Object.prototype` instead of the merge target, and so affect every
15
+ * object in the application.
16
+ */
17
+ const IGNORED_KEYS = ['__proto__', 'constructor', 'prototype'];
18
+
19
+ const { hasOwnProperty } = Object.prototype;
20
+
21
+ const isPlainObject = (value) => {
22
+ if (!value || typeof value !== 'object') {
23
+ return false;
24
+ }
25
+ const prototype = Object.getPrototypeOf(value);
26
+ return prototype === Object.prototype || prototype === null;
27
+ };
28
+
29
+ /**
30
+ * Merges `source` into `target`. With `partial`, the source is treated as an
31
+ * object that may provide only some of the properties: nullish values are
32
+ * skipped and arrays are copied instead of shared.
33
+ */
34
+ function merge(target, source, partial) {
35
+ if (!isPlainObject(target) || !isPlainObject(source)) {
36
+ return target;
37
+ }
38
+
39
+ Object.keys(source).forEach((key) => {
40
+ if (IGNORED_KEYS.includes(key)) {
41
+ return;
42
+ }
43
+
44
+ const value = source[key];
45
+
46
+ if (isPlainObject(value)) {
47
+ // Only merge into an own plain object, so that the merge can never
48
+ // continue into an object inherited from the prototype chain.
49
+ if (!hasOwnProperty.call(target, key) || !isPlainObject(target[key])) {
50
+ // With `partial`, a value that the target already has is kept, so that
51
+ // a source property of an unexpected type does not remove a default.
52
+ if (partial && hasOwnProperty.call(target, key) && target[key]) {
53
+ return;
54
+ }
55
+
56
+ target[key] = {};
57
+ }
58
+
59
+ merge(target[key], value, partial);
60
+ } else if (partial && Array.isArray(value)) {
61
+ target[key] = [...value];
62
+ } else if (!partial || (value !== undefined && value !== null)) {
63
+ target[key] = value;
64
+ }
65
+ });
66
+
67
+ return target;
68
+ }
69
+
70
+ /**
71
+ * Recursively copies own properties of `source` into `target` and returns
72
+ * `target`. Plain objects are merged, other values are assigned as they are.
73
+ * An object is plain when it inherits from `Object.prototype` or from nothing,
74
+ * so values such as a `Date` or a class instance are assigned, not merged.
75
+ *
76
+ * Merges a single source. Use `deepMergePartials()` to merge several objects,
77
+ * or to merge objects that only provide some of the properties.
78
+ *
79
+ * Both arguments are expected to be plain objects. When either of them is not,
80
+ * `target` is returned without changes. A property of the target that is not a
81
+ * plain object is replaced with the merged object, unlike the arguments.
82
+ *
83
+ * Keys that would modify `Object.prototype`, such as `__proto__`, are ignored.
84
+ *
85
+ * @param {object} target the object to merge into, modified in place
86
+ * @param {object} source the object to copy the properties from
87
+ * @return {object} the `target` object
88
+ */
89
+ export function deepMerge(target, source) {
90
+ return merge(target, source, false);
91
+ }
92
+
93
+ /**
94
+ * Recursively merges partial objects into `target` in order and returns
95
+ * `target`, so that a later source overrides an earlier one.
96
+ *
97
+ * Values that are `null` or `undefined` are skipped, so a source that only
98
+ * provides some of the properties does not remove the others. For the same
99
+ * reason, a property that the target already has is not replaced with an
100
+ * object when the source has one for the same key. Arrays are copied one level
101
+ * deep, so that the result does not share an array with any of the sources.
102
+ *
103
+ * Sources that are not plain objects are ignored. When `target` is not a plain
104
+ * object, it is returned without changes.
105
+ *
106
+ * Keys that would modify `Object.prototype`, such as `__proto__`, are ignored.
107
+ *
108
+ * @param {object} target the object to merge into, modified in place
109
+ * @param {...object} sources the objects to copy the properties from
110
+ * @return {object} the `target` object
111
+ */
112
+ export function deepMergePartials(target, ...sources) {
113
+ sources.forEach((source) => merge(target, source, true));
114
+
115
+ return target;
116
+ }