@mui/utils 6.0.0-beta.5 → 6.0.0-beta.5-dev.20240809-114550-93cb3d65e7
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/esm/resolveProps/resolveProps.js +30 -27
- package/index.js +1 -1
- package/modern/index.js +1 -1
- package/modern/resolveProps/resolveProps.js +30 -27
- package/package.json +1 -1
- package/resolveProps/resolveProps.d.ts +3 -3
- package/resolveProps/resolveProps.js +30 -27
|
@@ -1,40 +1,43 @@
|
|
|
1
1
|
/**
|
|
2
2
|
* Add keys, values of `defaultProps` that does not exist in `props`
|
|
3
|
-
* @param
|
|
4
|
-
* @param
|
|
5
|
-
* @returns
|
|
3
|
+
* @param defaultProps
|
|
4
|
+
* @param props
|
|
5
|
+
* @returns resolved props
|
|
6
6
|
*/
|
|
7
7
|
export default function resolveProps(defaultProps, props) {
|
|
8
8
|
const output = {
|
|
9
9
|
...props
|
|
10
10
|
};
|
|
11
|
-
|
|
12
|
-
if (
|
|
13
|
-
|
|
14
|
-
|
|
15
|
-
...output[propName]
|
|
16
|
-
};
|
|
17
|
-
} else if (propName.toString().match(/^(componentsProps|slotProps)$/)) {
|
|
18
|
-
const defaultSlotProps = defaultProps[propName] || {};
|
|
19
|
-
const slotProps = props[propName];
|
|
20
|
-
output[propName] = {};
|
|
21
|
-
if (!slotProps || !Object.keys(slotProps)) {
|
|
22
|
-
// Reduce the iteration if the slot props is empty
|
|
23
|
-
output[propName] = defaultSlotProps;
|
|
24
|
-
} else if (!defaultSlotProps || !Object.keys(defaultSlotProps)) {
|
|
25
|
-
// Reduce the iteration if the default slot props is empty
|
|
26
|
-
output[propName] = slotProps;
|
|
27
|
-
} else {
|
|
11
|
+
for (const key in defaultProps) {
|
|
12
|
+
if (Object.prototype.hasOwnProperty.call(defaultProps, key)) {
|
|
13
|
+
const propName = key;
|
|
14
|
+
if (propName === 'components' || propName === 'slots') {
|
|
28
15
|
output[propName] = {
|
|
29
|
-
...
|
|
16
|
+
...defaultProps[propName],
|
|
17
|
+
...output[propName]
|
|
30
18
|
};
|
|
31
|
-
|
|
32
|
-
|
|
33
|
-
|
|
19
|
+
} else if (propName === 'componentsProps' || propName === 'slotProps') {
|
|
20
|
+
const defaultSlotProps = defaultProps[propName];
|
|
21
|
+
const slotProps = props[propName];
|
|
22
|
+
if (!slotProps) {
|
|
23
|
+
output[propName] = defaultSlotProps || {};
|
|
24
|
+
} else if (!defaultSlotProps) {
|
|
25
|
+
output[propName] = slotProps;
|
|
26
|
+
} else {
|
|
27
|
+
output[propName] = {
|
|
28
|
+
...slotProps
|
|
29
|
+
};
|
|
30
|
+
for (const slotKey in defaultSlotProps) {
|
|
31
|
+
if (Object.prototype.hasOwnProperty.call(defaultSlotProps, slotKey)) {
|
|
32
|
+
const slotPropName = slotKey;
|
|
33
|
+
output[propName][slotPropName] = resolveProps(defaultSlotProps[slotPropName], slotProps[slotPropName]);
|
|
34
|
+
}
|
|
35
|
+
}
|
|
36
|
+
}
|
|
37
|
+
} else if (output[propName] === undefined) {
|
|
38
|
+
output[propName] = defaultProps[propName];
|
|
34
39
|
}
|
|
35
|
-
} else if (output[propName] === undefined) {
|
|
36
|
-
output[propName] = defaultProps[propName];
|
|
37
40
|
}
|
|
38
|
-
}
|
|
41
|
+
}
|
|
39
42
|
return output;
|
|
40
43
|
}
|
package/index.js
CHANGED
package/modern/index.js
CHANGED
|
@@ -1,40 +1,43 @@
|
|
|
1
1
|
/**
|
|
2
2
|
* Add keys, values of `defaultProps` that does not exist in `props`
|
|
3
|
-
* @param
|
|
4
|
-
* @param
|
|
5
|
-
* @returns
|
|
3
|
+
* @param defaultProps
|
|
4
|
+
* @param props
|
|
5
|
+
* @returns resolved props
|
|
6
6
|
*/
|
|
7
7
|
export default function resolveProps(defaultProps, props) {
|
|
8
8
|
const output = {
|
|
9
9
|
...props
|
|
10
10
|
};
|
|
11
|
-
|
|
12
|
-
if (
|
|
13
|
-
|
|
14
|
-
|
|
15
|
-
...output[propName]
|
|
16
|
-
};
|
|
17
|
-
} else if (propName.toString().match(/^(componentsProps|slotProps)$/)) {
|
|
18
|
-
const defaultSlotProps = defaultProps[propName] || {};
|
|
19
|
-
const slotProps = props[propName];
|
|
20
|
-
output[propName] = {};
|
|
21
|
-
if (!slotProps || !Object.keys(slotProps)) {
|
|
22
|
-
// Reduce the iteration if the slot props is empty
|
|
23
|
-
output[propName] = defaultSlotProps;
|
|
24
|
-
} else if (!defaultSlotProps || !Object.keys(defaultSlotProps)) {
|
|
25
|
-
// Reduce the iteration if the default slot props is empty
|
|
26
|
-
output[propName] = slotProps;
|
|
27
|
-
} else {
|
|
11
|
+
for (const key in defaultProps) {
|
|
12
|
+
if (Object.prototype.hasOwnProperty.call(defaultProps, key)) {
|
|
13
|
+
const propName = key;
|
|
14
|
+
if (propName === 'components' || propName === 'slots') {
|
|
28
15
|
output[propName] = {
|
|
29
|
-
...
|
|
16
|
+
...defaultProps[propName],
|
|
17
|
+
...output[propName]
|
|
30
18
|
};
|
|
31
|
-
|
|
32
|
-
|
|
33
|
-
|
|
19
|
+
} else if (propName === 'componentsProps' || propName === 'slotProps') {
|
|
20
|
+
const defaultSlotProps = defaultProps[propName];
|
|
21
|
+
const slotProps = props[propName];
|
|
22
|
+
if (!slotProps) {
|
|
23
|
+
output[propName] = defaultSlotProps || {};
|
|
24
|
+
} else if (!defaultSlotProps) {
|
|
25
|
+
output[propName] = slotProps;
|
|
26
|
+
} else {
|
|
27
|
+
output[propName] = {
|
|
28
|
+
...slotProps
|
|
29
|
+
};
|
|
30
|
+
for (const slotKey in defaultSlotProps) {
|
|
31
|
+
if (Object.prototype.hasOwnProperty.call(defaultSlotProps, slotKey)) {
|
|
32
|
+
const slotPropName = slotKey;
|
|
33
|
+
output[propName][slotPropName] = resolveProps(defaultSlotProps[slotPropName], slotProps[slotPropName]);
|
|
34
|
+
}
|
|
35
|
+
}
|
|
36
|
+
}
|
|
37
|
+
} else if (output[propName] === undefined) {
|
|
38
|
+
output[propName] = defaultProps[propName];
|
|
34
39
|
}
|
|
35
|
-
} else if (output[propName] === undefined) {
|
|
36
|
-
output[propName] = defaultProps[propName];
|
|
37
40
|
}
|
|
38
|
-
}
|
|
41
|
+
}
|
|
39
42
|
return output;
|
|
40
43
|
}
|
package/package.json
CHANGED
|
@@ -1,8 +1,8 @@
|
|
|
1
1
|
/**
|
|
2
2
|
* Add keys, values of `defaultProps` that does not exist in `props`
|
|
3
|
-
* @param
|
|
4
|
-
* @param
|
|
5
|
-
* @returns
|
|
3
|
+
* @param defaultProps
|
|
4
|
+
* @param props
|
|
5
|
+
* @returns resolved props
|
|
6
6
|
*/
|
|
7
7
|
export default function resolveProps<T extends {
|
|
8
8
|
components?: Record<string, unknown>;
|
|
@@ -6,41 +6,44 @@ Object.defineProperty(exports, "__esModule", {
|
|
|
6
6
|
exports.default = resolveProps;
|
|
7
7
|
/**
|
|
8
8
|
* Add keys, values of `defaultProps` that does not exist in `props`
|
|
9
|
-
* @param
|
|
10
|
-
* @param
|
|
11
|
-
* @returns
|
|
9
|
+
* @param defaultProps
|
|
10
|
+
* @param props
|
|
11
|
+
* @returns resolved props
|
|
12
12
|
*/
|
|
13
13
|
function resolveProps(defaultProps, props) {
|
|
14
14
|
const output = {
|
|
15
15
|
...props
|
|
16
16
|
};
|
|
17
|
-
|
|
18
|
-
if (
|
|
19
|
-
|
|
20
|
-
|
|
21
|
-
...output[propName]
|
|
22
|
-
};
|
|
23
|
-
} else if (propName.toString().match(/^(componentsProps|slotProps)$/)) {
|
|
24
|
-
const defaultSlotProps = defaultProps[propName] || {};
|
|
25
|
-
const slotProps = props[propName];
|
|
26
|
-
output[propName] = {};
|
|
27
|
-
if (!slotProps || !Object.keys(slotProps)) {
|
|
28
|
-
// Reduce the iteration if the slot props is empty
|
|
29
|
-
output[propName] = defaultSlotProps;
|
|
30
|
-
} else if (!defaultSlotProps || !Object.keys(defaultSlotProps)) {
|
|
31
|
-
// Reduce the iteration if the default slot props is empty
|
|
32
|
-
output[propName] = slotProps;
|
|
33
|
-
} else {
|
|
17
|
+
for (const key in defaultProps) {
|
|
18
|
+
if (Object.prototype.hasOwnProperty.call(defaultProps, key)) {
|
|
19
|
+
const propName = key;
|
|
20
|
+
if (propName === 'components' || propName === 'slots') {
|
|
34
21
|
output[propName] = {
|
|
35
|
-
...
|
|
22
|
+
...defaultProps[propName],
|
|
23
|
+
...output[propName]
|
|
36
24
|
};
|
|
37
|
-
|
|
38
|
-
|
|
39
|
-
|
|
25
|
+
} else if (propName === 'componentsProps' || propName === 'slotProps') {
|
|
26
|
+
const defaultSlotProps = defaultProps[propName];
|
|
27
|
+
const slotProps = props[propName];
|
|
28
|
+
if (!slotProps) {
|
|
29
|
+
output[propName] = defaultSlotProps || {};
|
|
30
|
+
} else if (!defaultSlotProps) {
|
|
31
|
+
output[propName] = slotProps;
|
|
32
|
+
} else {
|
|
33
|
+
output[propName] = {
|
|
34
|
+
...slotProps
|
|
35
|
+
};
|
|
36
|
+
for (const slotKey in defaultSlotProps) {
|
|
37
|
+
if (Object.prototype.hasOwnProperty.call(defaultSlotProps, slotKey)) {
|
|
38
|
+
const slotPropName = slotKey;
|
|
39
|
+
output[propName][slotPropName] = resolveProps(defaultSlotProps[slotPropName], slotProps[slotPropName]);
|
|
40
|
+
}
|
|
41
|
+
}
|
|
42
|
+
}
|
|
43
|
+
} else if (output[propName] === undefined) {
|
|
44
|
+
output[propName] = defaultProps[propName];
|
|
40
45
|
}
|
|
41
|
-
} else if (output[propName] === undefined) {
|
|
42
|
-
output[propName] = defaultProps[propName];
|
|
43
46
|
}
|
|
44
|
-
}
|
|
47
|
+
}
|
|
45
48
|
return output;
|
|
46
49
|
}
|