@mui/utils 7.0.1 → 7.0.2

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.
Files changed (115) hide show
  1. package/CHANGELOG.md +60 -0
  2. package/esm/index.js +1 -1
  3. package/esm/useForkRef/useForkRef.d.ts +1 -2
  4. package/esm/useForkRef/useForkRef.js +32 -12
  5. package/index.js +1 -1
  6. package/modern/useForkRef/useForkRef.d.ts +1 -2
  7. package/package.json +4 -12
  8. package/useForkRef/useForkRef.d.ts +1 -2
  9. package/useForkRef/useForkRef.js +32 -13
  10. package/modern/ClassNameGenerator/ClassNameGenerator.js +0 -17
  11. package/modern/ClassNameGenerator/index.js +0 -1
  12. package/modern/HTMLElementType/HTMLElementType.js +0 -14
  13. package/modern/HTMLElementType/index.js +0 -1
  14. package/modern/appendOwnerState/appendOwnerState.js +0 -28
  15. package/modern/appendOwnerState/index.js +0 -1
  16. package/modern/capitalize/capitalize.js +0 -11
  17. package/modern/capitalize/index.js +0 -1
  18. package/modern/chainPropTypes/chainPropTypes.js +0 -8
  19. package/modern/chainPropTypes/index.js +0 -1
  20. package/modern/clamp/clamp.js +0 -4
  21. package/modern/clamp/index.js +0 -1
  22. package/modern/composeClasses/composeClasses.js +0 -53
  23. package/modern/composeClasses/index.js +0 -1
  24. package/modern/createChainedFunction/createChainedFunction.js +0 -17
  25. package/modern/createChainedFunction/index.js +0 -1
  26. package/modern/debounce/debounce.js +0 -17
  27. package/modern/debounce/index.js +0 -2
  28. package/modern/deepmerge/deepmerge.js +0 -64
  29. package/modern/deepmerge/index.js +0 -2
  30. package/modern/deprecatedPropType/deprecatedPropType.js +0 -13
  31. package/modern/deprecatedPropType/index.js +0 -1
  32. package/modern/elementAcceptingRef/elementAcceptingRef.js +0 -42
  33. package/modern/elementAcceptingRef/index.js +0 -1
  34. package/modern/elementTypeAcceptingRef/elementTypeAcceptingRef.js +0 -40
  35. package/modern/elementTypeAcceptingRef/index.js +0 -1
  36. package/modern/exactProp/exactProp.js +0 -20
  37. package/modern/exactProp/index.js +0 -1
  38. package/modern/extractEventHandlers/extractEventHandlers.js +0 -18
  39. package/modern/extractEventHandlers/index.js +0 -1
  40. package/modern/formatMuiErrorMessage/formatMuiErrorMessage.js +0 -15
  41. package/modern/formatMuiErrorMessage/index.js +0 -1
  42. package/modern/generateUtilityClass/generateUtilityClass.js +0 -22
  43. package/modern/generateUtilityClass/index.js +0 -2
  44. package/modern/generateUtilityClasses/generateUtilityClasses.js +0 -8
  45. package/modern/generateUtilityClasses/index.js +0 -1
  46. package/modern/getDisplayName/getDisplayName.js +0 -38
  47. package/modern/getDisplayName/index.js +0 -1
  48. package/modern/getReactElementRef/getReactElementRef.js +0 -18
  49. package/modern/getReactElementRef/index.js +0 -1
  50. package/modern/getReactNodeRef/getReactNodeRef.js +0 -23
  51. package/modern/getReactNodeRef/index.js +0 -1
  52. package/modern/getScrollbarSize/getScrollbarSize.js +0 -7
  53. package/modern/getScrollbarSize/index.js +0 -1
  54. package/modern/getValidReactChildren/getValidReactChildren.js +0 -11
  55. package/modern/getValidReactChildren/index.js +0 -1
  56. package/modern/index.js +0 -57
  57. package/modern/integerPropType/index.js +0 -2
  58. package/modern/integerPropType/integerPropType.js +0 -44
  59. package/modern/isFocusVisible/index.js +0 -1
  60. package/modern/isFocusVisible/isFocusVisible.js +0 -15
  61. package/modern/isHostComponent/index.js +0 -1
  62. package/modern/isHostComponent/isHostComponent.js +0 -7
  63. package/modern/isMuiElement/index.js +0 -1
  64. package/modern/isMuiElement/isMuiElement.js +0 -8
  65. package/modern/mergeSlotProps/index.js +0 -1
  66. package/modern/mergeSlotProps/mergeSlotProps.js +0 -90
  67. package/modern/omitEventHandlers/index.js +0 -1
  68. package/modern/omitEventHandlers/omitEventHandlers.js +0 -18
  69. package/modern/ownerDocument/index.js +0 -1
  70. package/modern/ownerDocument/ownerDocument.js +0 -3
  71. package/modern/ownerWindow/index.js +0 -1
  72. package/modern/ownerWindow/ownerWindow.js +0 -5
  73. package/modern/package.json +0 -1
  74. package/modern/ponyfillGlobal/index.js +0 -1
  75. package/modern/ponyfillGlobal/ponyfillGlobal.js +0 -6
  76. package/modern/refType/index.js +0 -1
  77. package/modern/refType/refType.js +0 -3
  78. package/modern/requirePropFactory/index.js +0 -1
  79. package/modern/requirePropFactory/requirePropFactory.js +0 -25
  80. package/modern/resolveComponentProps/index.js +0 -1
  81. package/modern/resolveComponentProps/resolveComponentProps.js +0 -11
  82. package/modern/resolveProps/index.js +0 -1
  83. package/modern/resolveProps/resolveProps.js +0 -43
  84. package/modern/setRef/index.js +0 -1
  85. package/modern/setRef/setRef.js +0 -20
  86. package/modern/types/index.js +0 -1
  87. package/modern/unsupportedProp/index.js +0 -1
  88. package/modern/unsupportedProp/unsupportedProp.js +0 -10
  89. package/modern/useControlled/index.js +0 -1
  90. package/modern/useControlled/useControlled.js +0 -41
  91. package/modern/useEnhancedEffect/index.js +0 -1
  92. package/modern/useEnhancedEffect/useEnhancedEffect.js +0 -13
  93. package/modern/useEventCallback/index.js +0 -1
  94. package/modern/useEventCallback/useEventCallback.js +0 -20
  95. package/modern/useForkRef/index.js +0 -1
  96. package/modern/useForkRef/useForkRef.js +0 -40
  97. package/modern/useId/index.js +0 -1
  98. package/modern/useId/useId.js +0 -45
  99. package/modern/useIsFocusVisible/index.js +0 -2
  100. package/modern/useIsFocusVisible/useIsFocusVisible.js +0 -163
  101. package/modern/useLazyRef/index.js +0 -1
  102. package/modern/useLazyRef/useLazyRef.js +0 -19
  103. package/modern/useLocalStorageState/index.js +0 -1
  104. package/modern/useLocalStorageState/useLocalStorageState.js +0 -108
  105. package/modern/useOnMount/index.js +0 -1
  106. package/modern/useOnMount/useOnMount.js +0 -14
  107. package/modern/usePreviousProps/index.js +0 -1
  108. package/modern/usePreviousProps/usePreviousProps.js +0 -11
  109. package/modern/useSlotProps/index.js +0 -1
  110. package/modern/useSlotProps/useSlotProps.js +0 -38
  111. package/modern/useTimeout/index.js +0 -2
  112. package/modern/useTimeout/useTimeout.js +0 -35
  113. package/modern/visuallyHidden/index.js +0 -1
  114. package/modern/visuallyHidden/visuallyHidden.js +0 -12
  115. package/tsconfig.build.tsbuildinfo +0 -1
package/CHANGELOG.md CHANGED
@@ -1,5 +1,65 @@
1
1
  # [Versions](https://mui.com/versions/)
2
2
 
3
+ ## 7.0.2
4
+
5
+ _Apr 9, 2025_
6
+
7
+ A big thanks to the 12 contributors who made this release possible.
8
+
9
+ ### `@mui/material@7.0.2`
10
+
11
+ - [Autocomplete] Add ability to render custom single value (#45387) @ZeeshanTamboli
12
+ - [Autocomplete] Prevent shrink animation in controlled Autocomplete when initial `value` is provided (#45734) @imadx
13
+ - [AvatarGroup] Fix `spacing` prop ignoring value `0` (#45799) @Kartik-Murthy
14
+ - [Dialog] Deprecate composed classes (#45418) @sai6855
15
+
16
+ ### `@mui/material-nextjs@7.0.2`
17
+
18
+ - Fix nonce issues (#45794) @Janpot
19
+ - Add warnings to nextjs router integration (#45778) @Janpot
20
+
21
+ ### `@mui/styled-engine@7.0.2`
22
+
23
+ - Added caching to `StyledEngineProvider` to improve performance for running tests with Jest (#45846) @siriwatknp
24
+
25
+ ### Core
26
+
27
+ - [blog] Improve upvote video (0646444) @oliviertassinari
28
+ - [code-infra] Remove webpack aliases (#45841) @Janpot
29
+ - [code-infra] Remove .tsbuildinfo from build folder (#45727) @Janpot
30
+ - [code-infra] Stabilize theme viewer screenshot tests (#45768) @Janpot
31
+ - [code-infra] Remove modern bundles (#45808) @Janpot
32
+ - Update buildTypes script to optionally remove css imports (#45835) @brijeshb42
33
+ - Allow repo to be accepted as an argument for releaseTag (#45801) @brijeshb42
34
+ - Update scripts to support base-ui (#45784) @brijeshb42
35
+ - Sync scorecards.yml across codebase (4de5076) @oliviertassinari
36
+ - Remove baseUrl and skipLibCheck (#45806) @Janpot
37
+ - [docs-infra] Fix redirect styles pages (#45848) @siriwatknp
38
+ - [docs-infra] Remove false-positive Vale rules (#45843) @oliviertassinari
39
+ - [docs-infra] Make sure Next.js can find package.json through its aliases (#45840) @Janpot
40
+ - [docs-infra] Fix Next.js brand name coverage (6915f8d) @oliviertassinari
41
+ - [docs-infra] Fix layout shift between MIT and commercial pages (#45760) @oliviertassinari
42
+ - [docs-infra] Non breaking space for ESM (#45758) @oliviertassinari
43
+ - [support-infra] Remove dead 'workflow_call:' (#45736) @oliviertassinari
44
+ - [utils] Support cleanup callbacks in useForkRef (#45621) @DiegoAndai
45
+
46
+ ### Docs
47
+
48
+ - Fix pigment vite integration example (#44746) @brijeshb42
49
+ - Update migration instructions and codemod references for deprecated APIs (#45793) @sai6855
50
+ - Add TanStack Router routing example (#44930) @vetledv
51
+ - Fix layout shifting in icons page (#45779) @sai6855
52
+ - Fix migration instructions (#45762) @oliviertassinari
53
+ - Fix wrong TypeScript support version (#45761) @oliviertassinari
54
+ - Fix link to mui-joy/src/styles/components.d.ts (#45763) @oliviertassinari
55
+ - Fix 301 link (ae94c40) @oliviertassinari
56
+ - Fix 301 links (abd8f63) @oliviertassinari
57
+ - Fix 301 redirection (c7658de) @oliviertassinari
58
+ - [nextjs] Migrate from deprecated "legacyBehavior" prop (#44871) @oliviertassinari
59
+ - [nextjs] Document CSP for Next.js Pages Router (#45798) @Grohden
60
+
61
+ All contributors of this release in alphabetical order: @brijeshb42, @DiegoAndai, @Grohden, @imadx, @Janpot, @Kartik-Murthy, @oliviertassinari, @renovate[bot], @sai6855, @siriwatknp, @vetledv, @ZeeshanTamboli
62
+
3
63
  ## 7.0.1
4
64
 
5
65
  <!-- generated comparing v7.0.0..master -->
package/esm/index.js CHANGED
@@ -1,5 +1,5 @@
1
1
  /**
2
- * @mui/utils v7.0.1
2
+ * @mui/utils v7.0.2
3
3
  *
4
4
  * @license MIT
5
5
  * This source code is licensed under the MIT license found in the
@@ -1,7 +1,6 @@
1
1
  import * as React from 'react';
2
2
  /**
3
- * Takes an array of refs and returns a new ref which will apply any modification to all of the refs.
4
- * This is useful when you want to have the ref used in multiple places.
3
+ * Merges refs into a single memoized callback ref or `null`.
5
4
  *
6
5
  * ```tsx
7
6
  * const rootRef = React.useRef<Instance>(null);
@@ -1,11 +1,9 @@
1
1
  'use client';
2
2
 
3
3
  import * as React from 'react';
4
- import setRef from "../setRef/index.js";
5
4
 
6
5
  /**
7
- * Takes an array of refs and returns a new ref which will apply any modification to all of the refs.
8
- * This is useful when you want to have the ref used in multiple places.
6
+ * Merges refs into a single memoized callback ref or `null`.
9
7
  *
10
8
  * ```tsx
11
9
  * const rootRef = React.useRef<Instance>(null);
@@ -20,19 +18,41 @@ import setRef from "../setRef/index.js";
20
18
  * @returns {React.RefCallback<Instance> | null} The new ref callback.
21
19
  */
22
20
  export default function useForkRef(...refs) {
23
- /**
24
- * This will create a new function if the refs passed to this hook change and are all defined.
25
- * This means react will call the old forkRef with `null` and the new forkRef
26
- * with the ref. Cleanup naturally emerges from this behavior.
27
- */
21
+ const cleanupRef = React.useRef(undefined);
22
+ const refEffect = React.useCallback(instance => {
23
+ const cleanups = refs.map(ref => {
24
+ if (ref == null) {
25
+ return null;
26
+ }
27
+ if (typeof ref === 'function') {
28
+ const refCallback = ref;
29
+ const refCleanup = refCallback(instance);
30
+ return typeof refCleanup === 'function' ? refCleanup : () => {
31
+ refCallback(null);
32
+ };
33
+ }
34
+ ref.current = instance;
35
+ return () => {
36
+ ref.current = null;
37
+ };
38
+ });
39
+ return () => {
40
+ cleanups.forEach(refCleanup => refCleanup?.());
41
+ };
42
+ // eslint-disable-next-line react-hooks/exhaustive-deps
43
+ }, refs);
28
44
  return React.useMemo(() => {
29
45
  if (refs.every(ref => ref == null)) {
30
46
  return null;
31
47
  }
32
- return instance => {
33
- refs.forEach(ref => {
34
- setRef(ref, instance);
35
- });
48
+ return value => {
49
+ if (cleanupRef.current) {
50
+ cleanupRef.current();
51
+ cleanupRef.current = undefined;
52
+ }
53
+ if (value != null) {
54
+ cleanupRef.current = refEffect(value);
55
+ }
36
56
  };
37
57
  // TODO: uncomment once we enable eslint-plugin-react-compiler // eslint-disable-next-line react-compiler/react-compiler -- intentionally ignoring that the dependency array must be an array literal
38
58
  // eslint-disable-next-line react-hooks/exhaustive-deps
package/index.js CHANGED
@@ -1,5 +1,5 @@
1
1
  /**
2
- * @mui/utils v7.0.1
2
+ * @mui/utils v7.0.2
3
3
  *
4
4
  * @license MIT
5
5
  * This source code is licensed under the MIT license found in the
@@ -1,7 +1,6 @@
1
1
  import * as React from 'react';
2
2
  /**
3
- * Takes an array of refs and returns a new ref which will apply any modification to all of the refs.
4
- * This is useful when you want to have the ref used in multiple places.
3
+ * Merges refs into a single memoized callback ref or `null`.
5
4
  *
6
5
  * ```tsx
7
6
  * const rootRef = React.useRef<Instance>(null);
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@mui/utils",
3
- "version": "7.0.1",
3
+ "version": "7.0.2",
4
4
  "private": false,
5
5
  "author": "MUI Team",
6
6
  "description": "Utility functions for React components.",
@@ -26,12 +26,12 @@
26
26
  "url": "https://opencollective.com/mui-org"
27
27
  },
28
28
  "dependencies": {
29
- "@babel/runtime": "^7.26.10",
29
+ "@babel/runtime": "^7.27.0",
30
30
  "@types/prop-types": "^15.7.14",
31
31
  "clsx": "^2.1.1",
32
32
  "prop-types": "^15.8.1",
33
- "react-is": "^19.0.0",
34
- "@mui/types": "^7.4.0"
33
+ "react-is": "^19.1.0",
34
+ "@mui/types": "^7.4.1"
35
35
  },
36
36
  "peerDependencies": {
37
37
  "@types/react": "^17.0.0 || ^18.0.0 || ^19.0.0",
@@ -61,10 +61,6 @@
61
61
  "import": {
62
62
  "types": "./esm/index.d.ts",
63
63
  "default": "./esm/index.js"
64
- },
65
- "mui-modern": {
66
- "types": "./modern/index.d.ts",
67
- "default": "./modern/index.js"
68
64
  }
69
65
  },
70
66
  "./*": {
@@ -75,10 +71,6 @@
75
71
  "import": {
76
72
  "types": "./esm/*/index.d.ts",
77
73
  "default": "./esm/*/index.js"
78
- },
79
- "mui-modern": {
80
- "types": "./modern/*/index.d.ts",
81
- "default": "./modern/*/index.js"
82
74
  }
83
75
  },
84
76
  "./esm": null,
@@ -1,7 +1,6 @@
1
1
  import * as React from 'react';
2
2
  /**
3
- * Takes an array of refs and returns a new ref which will apply any modification to all of the refs.
4
- * This is useful when you want to have the ref used in multiple places.
3
+ * Merges refs into a single memoized callback ref or `null`.
5
4
  *
6
5
  * ```tsx
7
6
  * const rootRef = React.useRef<Instance>(null);
@@ -1,17 +1,14 @@
1
1
  "use strict";
2
2
  'use client';
3
3
 
4
- var _interopRequireDefault = require("@babel/runtime/helpers/interopRequireDefault").default;
5
4
  var _interopRequireWildcard = require("@babel/runtime/helpers/interopRequireWildcard").default;
6
5
  Object.defineProperty(exports, "__esModule", {
7
6
  value: true
8
7
  });
9
8
  exports.default = useForkRef;
10
9
  var React = _interopRequireWildcard(require("react"));
11
- var _setRef = _interopRequireDefault(require("../setRef"));
12
10
  /**
13
- * Takes an array of refs and returns a new ref which will apply any modification to all of the refs.
14
- * This is useful when you want to have the ref used in multiple places.
11
+ * Merges refs into a single memoized callback ref or `null`.
15
12
  *
16
13
  * ```tsx
17
14
  * const rootRef = React.useRef<Instance>(null);
@@ -26,19 +23,41 @@ var _setRef = _interopRequireDefault(require("../setRef"));
26
23
  * @returns {React.RefCallback<Instance> | null} The new ref callback.
27
24
  */
28
25
  function useForkRef(...refs) {
29
- /**
30
- * This will create a new function if the refs passed to this hook change and are all defined.
31
- * This means react will call the old forkRef with `null` and the new forkRef
32
- * with the ref. Cleanup naturally emerges from this behavior.
33
- */
26
+ const cleanupRef = React.useRef(undefined);
27
+ const refEffect = React.useCallback(instance => {
28
+ const cleanups = refs.map(ref => {
29
+ if (ref == null) {
30
+ return null;
31
+ }
32
+ if (typeof ref === 'function') {
33
+ const refCallback = ref;
34
+ const refCleanup = refCallback(instance);
35
+ return typeof refCleanup === 'function' ? refCleanup : () => {
36
+ refCallback(null);
37
+ };
38
+ }
39
+ ref.current = instance;
40
+ return () => {
41
+ ref.current = null;
42
+ };
43
+ });
44
+ return () => {
45
+ cleanups.forEach(refCleanup => refCleanup?.());
46
+ };
47
+ // eslint-disable-next-line react-hooks/exhaustive-deps
48
+ }, refs);
34
49
  return React.useMemo(() => {
35
50
  if (refs.every(ref => ref == null)) {
36
51
  return null;
37
52
  }
38
- return instance => {
39
- refs.forEach(ref => {
40
- (0, _setRef.default)(ref, instance);
41
- });
53
+ return value => {
54
+ if (cleanupRef.current) {
55
+ cleanupRef.current();
56
+ cleanupRef.current = undefined;
57
+ }
58
+ if (value != null) {
59
+ cleanupRef.current = refEffect(value);
60
+ }
42
61
  };
43
62
  // TODO: uncomment once we enable eslint-plugin-react-compiler // eslint-disable-next-line react-compiler/react-compiler -- intentionally ignoring that the dependency array must be an array literal
44
63
  // eslint-disable-next-line react-hooks/exhaustive-deps
@@ -1,17 +0,0 @@
1
- const defaultGenerator = componentName => componentName;
2
- const createClassNameGenerator = () => {
3
- let generate = defaultGenerator;
4
- return {
5
- configure(generator) {
6
- generate = generator;
7
- },
8
- generate(componentName) {
9
- return generate(componentName);
10
- },
11
- reset() {
12
- generate = defaultGenerator;
13
- }
14
- };
15
- };
16
- const ClassNameGenerator = createClassNameGenerator();
17
- export default ClassNameGenerator;
@@ -1 +0,0 @@
1
- export { default } from "./ClassNameGenerator.js";
@@ -1,14 +0,0 @@
1
- export default function HTMLElementType(props, propName, componentName, location, propFullName) {
2
- if (process.env.NODE_ENV === 'production') {
3
- return null;
4
- }
5
- const propValue = props[propName];
6
- const safePropName = propFullName || propName;
7
- if (propValue == null) {
8
- return null;
9
- }
10
- if (propValue && propValue.nodeType !== 1) {
11
- return new Error(`Invalid ${location} \`${safePropName}\` supplied to \`${componentName}\`. ` + `Expected an HTMLElement.`);
12
- }
13
- return null;
14
- }
@@ -1 +0,0 @@
1
- export { default } from "./HTMLElementType.js";
@@ -1,28 +0,0 @@
1
- import isHostComponent from "../isHostComponent/index.js";
2
-
3
- /**
4
- * Type of the ownerState based on the type of an element it applies to.
5
- * This resolves to the provided OwnerState for React components and `undefined` for host components.
6
- * Falls back to `OwnerState | undefined` when the exact type can't be determined in development time.
7
- */
8
-
9
- /**
10
- * Appends the ownerState object to the props, merging with the existing one if necessary.
11
- *
12
- * @param elementType Type of the element that owns the `existingProps`. If the element is a DOM node or undefined, `ownerState` is not applied.
13
- * @param otherProps Props of the element.
14
- * @param ownerState
15
- */
16
- function appendOwnerState(elementType, otherProps, ownerState) {
17
- if (elementType === undefined || isHostComponent(elementType)) {
18
- return otherProps;
19
- }
20
- return {
21
- ...otherProps,
22
- ownerState: {
23
- ...otherProps.ownerState,
24
- ...ownerState
25
- }
26
- };
27
- }
28
- export default appendOwnerState;
@@ -1 +0,0 @@
1
- export { default } from "./appendOwnerState.js";
@@ -1,11 +0,0 @@
1
- import _formatErrorMessage from "@mui/utils/formatMuiErrorMessage";
2
- // It should to be noted that this function isn't equivalent to `text-transform: capitalize`.
3
- //
4
- // A strict capitalization should uppercase the first letter of each word in the sentence.
5
- // We only handle the first word.
6
- export default function capitalize(string) {
7
- if (typeof string !== 'string') {
8
- throw new Error(process.env.NODE_ENV !== "production" ? 'MUI: `capitalize(string)` expects a string argument.' : _formatErrorMessage(7));
9
- }
10
- return string.charAt(0).toUpperCase() + string.slice(1);
11
- }
@@ -1 +0,0 @@
1
- export { default } from "./capitalize.js";
@@ -1,8 +0,0 @@
1
- export default function chainPropTypes(propType1, propType2) {
2
- if (process.env.NODE_ENV === 'production') {
3
- return () => null;
4
- }
5
- return function validate(...args) {
6
- return propType1(...args) || propType2(...args);
7
- };
8
- }
@@ -1 +0,0 @@
1
- export { default } from "./chainPropTypes.js";
@@ -1,4 +0,0 @@
1
- function clamp(val, min = Number.MIN_SAFE_INTEGER, max = Number.MAX_SAFE_INTEGER) {
2
- return Math.max(min, Math.min(val, max));
3
- }
4
- export default clamp;
@@ -1 +0,0 @@
1
- export { default } from "./clamp.js";
@@ -1,53 +0,0 @@
1
- /* eslint no-restricted-syntax: 0, prefer-template: 0, guard-for-in: 0
2
- ---
3
- These rules are preventing the performance optimizations below.
4
- */
5
-
6
- /**
7
- * Compose classes from multiple sources.
8
- *
9
- * @example
10
- * ```tsx
11
- * const slots = {
12
- * root: ['root', 'primary'],
13
- * label: ['label'],
14
- * };
15
- *
16
- * const getUtilityClass = (slot) => `MuiButton-${slot}`;
17
- *
18
- * const classes = {
19
- * root: 'my-root-class',
20
- * };
21
- *
22
- * const output = composeClasses(slots, getUtilityClass, classes);
23
- * // {
24
- * // root: 'MuiButton-root MuiButton-primary my-root-class',
25
- * // label: 'MuiButton-label',
26
- * // }
27
- * ```
28
- *
29
- * @param slots a list of classes for each possible slot
30
- * @param getUtilityClass a function to resolve the class based on the slot name
31
- * @param classes the input classes from props
32
- * @returns the resolved classes for all slots
33
- */
34
- export default function composeClasses(slots, getUtilityClass, classes = undefined) {
35
- const output = {};
36
- for (const slotName in slots) {
37
- const slot = slots[slotName];
38
- let buffer = '';
39
- let start = true;
40
- for (let i = 0; i < slot.length; i += 1) {
41
- const value = slot[i];
42
- if (value) {
43
- buffer += (start === true ? '' : ' ') + getUtilityClass(value);
44
- start = false;
45
- if (classes && classes[value]) {
46
- buffer += ' ' + classes[value];
47
- }
48
- }
49
- }
50
- output[slotName] = buffer;
51
- }
52
- return output;
53
- }
@@ -1 +0,0 @@
1
- export { default } from "./composeClasses.js";
@@ -1,17 +0,0 @@
1
- /**
2
- * Safe chained function.
3
- *
4
- * Will only create a new function if needed,
5
- * otherwise will pass back existing functions or null.
6
- */
7
- export default function createChainedFunction(...funcs) {
8
- return funcs.reduce((acc, func) => {
9
- if (func == null) {
10
- return acc;
11
- }
12
- return function chainedFunction(...args) {
13
- acc.apply(this, args);
14
- func.apply(this, args);
15
- };
16
- }, () => {});
17
- }
@@ -1 +0,0 @@
1
- export { default } from "./createChainedFunction.js";
@@ -1,17 +0,0 @@
1
- // Corresponds to 10 frames at 60 Hz.
2
- // A few bytes payload overhead when lodash/debounce is ~3 kB and debounce ~300 B.
3
- export default function debounce(func, wait = 166) {
4
- let timeout;
5
- function debounced(...args) {
6
- const later = () => {
7
- // @ts-ignore
8
- func.apply(this, args);
9
- };
10
- clearTimeout(timeout);
11
- timeout = setTimeout(later, wait);
12
- }
13
- debounced.clear = () => {
14
- clearTimeout(timeout);
15
- };
16
- return debounced;
17
- }
@@ -1,2 +0,0 @@
1
- export { default } from "./debounce.js";
2
- export * from "./debounce.js";
@@ -1,64 +0,0 @@
1
- import * as React from 'react';
2
- import { isValidElementType } from 'react-is';
3
-
4
- // https://github.com/sindresorhus/is-plain-obj/blob/main/index.js
5
- export function isPlainObject(item) {
6
- if (typeof item !== 'object' || item === null) {
7
- return false;
8
- }
9
- const prototype = Object.getPrototypeOf(item);
10
- return (prototype === null || prototype === Object.prototype || Object.getPrototypeOf(prototype) === null) && !(Symbol.toStringTag in item) && !(Symbol.iterator in item);
11
- }
12
- function deepClone(source) {
13
- if (/*#__PURE__*/React.isValidElement(source) || isValidElementType(source) || !isPlainObject(source)) {
14
- return source;
15
- }
16
- const output = {};
17
- Object.keys(source).forEach(key => {
18
- output[key] = deepClone(source[key]);
19
- });
20
- return output;
21
- }
22
-
23
- /**
24
- * Merge objects deeply.
25
- * It will shallow copy React elements.
26
- *
27
- * If `options.clone` is set to `false` the source object will be merged directly into the target object.
28
- *
29
- * @example
30
- * ```ts
31
- * deepmerge({ a: { b: 1 }, d: 2 }, { a: { c: 2 }, d: 4 });
32
- * // => { a: { b: 1, c: 2 }, d: 4 }
33
- * ````
34
- *
35
- * @param target The target object.
36
- * @param source The source object.
37
- * @param options The merge options.
38
- * @param options.clone Set to `false` to merge the source object directly into the target object.
39
- * @returns The merged object.
40
- */
41
- export default function deepmerge(target, source, options = {
42
- clone: true
43
- }) {
44
- const output = options.clone ? {
45
- ...target
46
- } : target;
47
- if (isPlainObject(target) && isPlainObject(source)) {
48
- Object.keys(source).forEach(key => {
49
- if (/*#__PURE__*/React.isValidElement(source[key]) || isValidElementType(source[key])) {
50
- output[key] = source[key];
51
- } else if (isPlainObject(source[key]) &&
52
- // Avoid prototype pollution
53
- Object.prototype.hasOwnProperty.call(target, key) && isPlainObject(target[key])) {
54
- // Since `output` is a clone of `target` and we have narrowed `target` in this block we can cast to the same type.
55
- output[key] = deepmerge(target[key], source[key], options);
56
- } else if (options.clone) {
57
- output[key] = isPlainObject(source[key]) ? deepClone(source[key]) : source[key];
58
- } else {
59
- output[key] = source[key];
60
- }
61
- });
62
- }
63
- return output;
64
- }
@@ -1,2 +0,0 @@
1
- export { default } from "./deepmerge.js";
2
- export * from "./deepmerge.js";
@@ -1,13 +0,0 @@
1
- export default function deprecatedPropType(validator, reason) {
2
- if (process.env.NODE_ENV === 'production') {
3
- return () => null;
4
- }
5
- return (props, propName, componentName, location, propFullName) => {
6
- const componentNameSafe = componentName || '<<anonymous>>';
7
- const propFullNameSafe = propFullName || propName;
8
- if (typeof props[propName] !== 'undefined') {
9
- return new Error(`The ${location} \`${propFullNameSafe}\` of ` + `\`${componentNameSafe}\` is deprecated. ${reason}`);
10
- }
11
- return null;
12
- };
13
- }
@@ -1 +0,0 @@
1
- export { default } from "./deprecatedPropType.js";
@@ -1,42 +0,0 @@
1
- import PropTypes from 'prop-types';
2
- import chainPropTypes from "../chainPropTypes/index.js";
3
- function isClassComponent(elementType) {
4
- // elementType.prototype?.isReactComponent
5
- const {
6
- prototype = {}
7
- } = elementType;
8
- return Boolean(prototype.isReactComponent);
9
- }
10
- function acceptingRef(props, propName, componentName, location, propFullName) {
11
- const element = props[propName];
12
- const safePropName = propFullName || propName;
13
- if (element == null ||
14
- // When server-side rendering React doesn't warn either.
15
- // This is not an accurate check for SSR.
16
- // This is only in place for Emotion compat.
17
- // TODO: Revisit once https://github.com/facebook/react/issues/20047 is resolved.
18
- typeof window === 'undefined') {
19
- return null;
20
- }
21
- let warningHint;
22
- const elementType = element.type;
23
- /**
24
- * Blacklisting instead of whitelisting
25
- *
26
- * Blacklisting will miss some components, such as React.Fragment. Those will at least
27
- * trigger a warning in React.
28
- * We can't whitelist because there is no safe way to detect React.forwardRef
29
- * or class components. "Safe" means there's no public API.
30
- *
31
- */
32
- if (typeof elementType === 'function' && !isClassComponent(elementType)) {
33
- warningHint = 'Did you accidentally use a plain function component for an element instead?';
34
- }
35
- if (warningHint !== undefined) {
36
- return new Error(`Invalid ${location} \`${safePropName}\` supplied to \`${componentName}\`. ` + `Expected an element that can hold a ref. ${warningHint} ` + 'For more information see https://mui.com/r/caveat-with-refs-guide');
37
- }
38
- return null;
39
- }
40
- const elementAcceptingRef = chainPropTypes(PropTypes.element, acceptingRef);
41
- elementAcceptingRef.isRequired = chainPropTypes(PropTypes.element.isRequired, acceptingRef);
42
- export default elementAcceptingRef;
@@ -1 +0,0 @@
1
- export { default } from "./elementAcceptingRef.js";