@mui/utils 6.1.2 → 6.1.4

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.
@@ -12,7 +12,7 @@ var _formatMuiErrorMessage2 = _interopRequireDefault(require("@mui/utils/formatM
12
12
  // We only handle the first word.
13
13
  function capitalize(string) {
14
14
  if (typeof string !== 'string') {
15
- throw new Error(process.env.NODE_ENV !== "production" ? `MUI: \`capitalize(string)\` expects a string argument.` : (0, _formatMuiErrorMessage2.default)(7));
15
+ throw new Error(process.env.NODE_ENV !== "production" ? 'MUI: `capitalize(string)` expects a string argument.' : (0, _formatMuiErrorMessage2.default)(7));
16
16
  }
17
17
  return string.charAt(0).toUpperCase() + string.slice(1);
18
18
  }
@@ -5,7 +5,7 @@ import _formatMuiErrorMessage from "@mui/utils/formatMuiErrorMessage";
5
5
  // We only handle the first word.
6
6
  export default function capitalize(string) {
7
7
  if (typeof string !== 'string') {
8
- throw new Error(process.env.NODE_ENV !== "production" ? `MUI: \`capitalize(string)\` expects a string argument.` : _formatMuiErrorMessage(7));
8
+ throw new Error(process.env.NODE_ENV !== "production" ? 'MUI: `capitalize(string)` expects a string argument.' : _formatMuiErrorMessage(7));
9
9
  }
10
10
  return string.charAt(0).toUpperCase() + string.slice(1);
11
11
  }
@@ -1,19 +1,15 @@
1
1
  /**
2
- * WARNING: Don't import this directly.
3
- * Use `MuiError` from `@mui/internal-babel-macros/MuiError.macro` instead.
2
+ * WARNING: Don't import this directly. It's imported by the code generated by
3
+ * `@mui/interal-babel-plugin-minify-errors`. Make sure to always use string literals in `Error`
4
+ * constructors to ensure the plugin works as expected. Supported patterns include:
5
+ * throw new Error('My message');
6
+ * throw new Error(`My message: ${foo}`);
7
+ * throw new Error(`My message: ${foo}` + 'another string');
8
+ * ...
4
9
  * @param {number} code
5
10
  */
6
- export default function formatMuiErrorMessage(code) {
7
- // Apply babel-plugin-transform-template-literals in loose mode
8
- // loose mode is safe if we're concatenating primitives
9
- // see https://babeljs.io/docs/en/babel-plugin-transform-template-literals#loose
10
- /* eslint-disable prefer-template */
11
- let url = 'https://mui.com/production-error/?code=' + code;
12
- for (let i = 1; i < arguments.length; i += 1) {
13
- // rest params over-transpile for this case
14
- // eslint-disable-next-line prefer-rest-params
15
- url += '&args[]=' + encodeURIComponent(arguments[i]);
16
- }
17
- return 'Minified MUI error #' + code + '; visit ' + url + ' for the full message.';
18
- /* eslint-enable prefer-template */
11
+ export default function formatMuiErrorMessage(code, ...args) {
12
+ const url = new URL(`https://mui.com/production-error/?code=${code}`);
13
+ args.forEach(arg => url.searchParams.append('args[]', arg));
14
+ return `Minified MUI error #${code}; visit ${url} for the full message.`;
19
15
  }
@@ -5,14 +5,14 @@ import * as React from 'react';
5
5
  * It will throw runtime error if the element is not a valid React element.
6
6
  *
7
7
  * @param element React.ReactElement
8
- * @returns React.Ref<any> | null | undefined
8
+ * @returns React.Ref<any> | null
9
9
  */
10
10
  export default function getReactElementRef(element) {
11
11
  // 'ref' is passed as prop in React 19, whereas 'ref' is directly attached to children in older versions
12
12
  if (parseInt(React.version, 10) >= 19) {
13
- return element.props?.ref;
13
+ return element?.props?.ref || null;
14
14
  }
15
15
  // @ts-expect-error element.ref is not included in the ReactElement type
16
16
  // https://github.com/DefinitelyTyped/DefinitelyTyped/discussions/70189
17
- return element?.ref;
17
+ return element?.ref || null;
18
18
  }
@@ -28,20 +28,20 @@ function emitCurrentTabStorageChange(key) {
28
28
  listeners.forEach(listener => listener());
29
29
  }
30
30
  }
31
- function subscribe(area, key, callbark) {
31
+ function subscribe(area, key, callback) {
32
32
  if (!key) {
33
33
  return () => {};
34
34
  }
35
35
  const storageHandler = event => {
36
36
  if (event.storageArea === area && event.key === key) {
37
- callbark();
37
+ callback();
38
38
  }
39
39
  };
40
40
  window.addEventListener('storage', storageHandler);
41
- onCurrentTabStorageChange(key, callbark);
41
+ onCurrentTabStorageChange(key, callback);
42
42
  return () => {
43
43
  window.removeEventListener('storage', storageHandler);
44
- offCurrentTabStorageChange(key, callbark);
44
+ offCurrentTabStorageChange(key, callback);
45
45
  };
46
46
  }
47
47
  function getSnapshot(area, key) {
@@ -89,7 +89,7 @@ function useLocalStorageStateServer() {
89
89
  function useLocalStorageStateBrowser(key, initializer = null) {
90
90
  const [initialValue] = React.useState(initializer);
91
91
  const area = window.localStorage;
92
- const subscribeKey = React.useCallback(callbark => subscribe(area, key, callbark), [area, key]);
92
+ const subscribeKey = React.useCallback(callback => subscribe(area, key, callback), [area, key]);
93
93
  const getKeySnapshot = React.useCallback(() => getSnapshot(area, key) ?? initialValue, [area, initialValue, key]);
94
94
 
95
95
  // Start with null for the hydration, and then switch to the actual value.
@@ -1,6 +1,11 @@
1
1
  /**
2
- * WARNING: Don't import this directly.
3
- * Use `MuiError` from `@mui/internal-babel-macros/MuiError.macro` instead.
2
+ * WARNING: Don't import this directly. It's imported by the code generated by
3
+ * `@mui/interal-babel-plugin-minify-errors`. Make sure to always use string literals in `Error`
4
+ * constructors to ensure the plugin works as expected. Supported patterns include:
5
+ * throw new Error('My message');
6
+ * throw new Error(`My message: ${foo}`);
7
+ * throw new Error(`My message: ${foo}` + 'another string');
8
+ * ...
4
9
  * @param {number} code
5
10
  */
6
- export default function formatMuiErrorMessage(code: number): string;
11
+ export default function formatMuiErrorMessage(code: number, ...args: string[]): string;
@@ -5,21 +5,17 @@ Object.defineProperty(exports, "__esModule", {
5
5
  });
6
6
  exports.default = formatMuiErrorMessage;
7
7
  /**
8
- * WARNING: Don't import this directly.
9
- * Use `MuiError` from `@mui/internal-babel-macros/MuiError.macro` instead.
8
+ * WARNING: Don't import this directly. It's imported by the code generated by
9
+ * `@mui/interal-babel-plugin-minify-errors`. Make sure to always use string literals in `Error`
10
+ * constructors to ensure the plugin works as expected. Supported patterns include:
11
+ * throw new Error('My message');
12
+ * throw new Error(`My message: ${foo}`);
13
+ * throw new Error(`My message: ${foo}` + 'another string');
14
+ * ...
10
15
  * @param {number} code
11
16
  */
12
- function formatMuiErrorMessage(code) {
13
- // Apply babel-plugin-transform-template-literals in loose mode
14
- // loose mode is safe if we're concatenating primitives
15
- // see https://babeljs.io/docs/en/babel-plugin-transform-template-literals#loose
16
- /* eslint-disable prefer-template */
17
- let url = 'https://mui.com/production-error/?code=' + code;
18
- for (let i = 1; i < arguments.length; i += 1) {
19
- // rest params over-transpile for this case
20
- // eslint-disable-next-line prefer-rest-params
21
- url += '&args[]=' + encodeURIComponent(arguments[i]);
22
- }
23
- return 'Minified MUI error #' + code + '; visit ' + url + ' for the full message.';
24
- /* eslint-enable prefer-template */
17
+ function formatMuiErrorMessage(code, ...args) {
18
+ const url = new URL(`https://mui.com/production-error/?code=${code}`);
19
+ args.forEach(arg => url.searchParams.append('args[]', arg));
20
+ return `Minified MUI error #${code}; visit ${url} for the full message.`;
25
21
  }
@@ -4,6 +4,6 @@ import * as React from 'react';
4
4
  * It will throw runtime error if the element is not a valid React element.
5
5
  *
6
6
  * @param element React.ReactElement
7
- * @returns React.Ref<any> | null | undefined
7
+ * @returns React.Ref<any> | null
8
8
  */
9
- export default function getReactElementRef(element: React.ReactElement): React.Ref<any> | null | undefined;
9
+ export default function getReactElementRef(element: React.ReactElement): React.Ref<any> | null;
@@ -11,14 +11,14 @@ var React = _interopRequireWildcard(require("react"));
11
11
  * It will throw runtime error if the element is not a valid React element.
12
12
  *
13
13
  * @param element React.ReactElement
14
- * @returns React.Ref<any> | null | undefined
14
+ * @returns React.Ref<any> | null
15
15
  */
16
16
  function getReactElementRef(element) {
17
17
  // 'ref' is passed as prop in React 19, whereas 'ref' is directly attached to children in older versions
18
18
  if (parseInt(React.version, 10) >= 19) {
19
- return element.props?.ref;
19
+ return element?.props?.ref || null;
20
20
  }
21
21
  // @ts-expect-error element.ref is not included in the ReactElement type
22
22
  // https://github.com/DefinitelyTyped/DefinitelyTyped/discussions/70189
23
- return element?.ref;
23
+ return element?.ref || null;
24
24
  }
@@ -5,4 +5,4 @@ import * as React from 'react';
5
5
  *
6
6
  * @param children the children
7
7
  */
8
- export default function getValidReactChildren(children: React.ReactNode): React.ReactElement<any>[];
8
+ export default function getValidReactChildren(children: React.ReactNode): React.ReactElement<unknown>[];
package/index.js CHANGED
@@ -1,5 +1,5 @@
1
1
  /**
2
- * @mui/utils v6.1.2
2
+ * @mui/utils v6.1.4
3
3
  *
4
4
  * @license MIT
5
5
  * This source code is licensed under the MIT license found in the
@@ -5,7 +5,7 @@ import _formatMuiErrorMessage from "@mui/utils/formatMuiErrorMessage";
5
5
  // We only handle the first word.
6
6
  export default function capitalize(string) {
7
7
  if (typeof string !== 'string') {
8
- throw new Error(process.env.NODE_ENV !== "production" ? `MUI: \`capitalize(string)\` expects a string argument.` : _formatMuiErrorMessage(7));
8
+ throw new Error(process.env.NODE_ENV !== "production" ? 'MUI: `capitalize(string)` expects a string argument.' : _formatMuiErrorMessage(7));
9
9
  }
10
10
  return string.charAt(0).toUpperCase() + string.slice(1);
11
11
  }
@@ -1,19 +1,15 @@
1
1
  /**
2
- * WARNING: Don't import this directly.
3
- * Use `MuiError` from `@mui/internal-babel-macros/MuiError.macro` instead.
2
+ * WARNING: Don't import this directly. It's imported by the code generated by
3
+ * `@mui/interal-babel-plugin-minify-errors`. Make sure to always use string literals in `Error`
4
+ * constructors to ensure the plugin works as expected. Supported patterns include:
5
+ * throw new Error('My message');
6
+ * throw new Error(`My message: ${foo}`);
7
+ * throw new Error(`My message: ${foo}` + 'another string');
8
+ * ...
4
9
  * @param {number} code
5
10
  */
6
- export default function formatMuiErrorMessage(code) {
7
- // Apply babel-plugin-transform-template-literals in loose mode
8
- // loose mode is safe if we're concatenating primitives
9
- // see https://babeljs.io/docs/en/babel-plugin-transform-template-literals#loose
10
- /* eslint-disable prefer-template */
11
- let url = 'https://mui.com/production-error/?code=' + code;
12
- for (let i = 1; i < arguments.length; i += 1) {
13
- // rest params over-transpile for this case
14
- // eslint-disable-next-line prefer-rest-params
15
- url += '&args[]=' + encodeURIComponent(arguments[i]);
16
- }
17
- return 'Minified MUI error #' + code + '; visit ' + url + ' for the full message.';
18
- /* eslint-enable prefer-template */
11
+ export default function formatMuiErrorMessage(code, ...args) {
12
+ const url = new URL(`https://mui.com/production-error/?code=${code}`);
13
+ args.forEach(arg => url.searchParams.append('args[]', arg));
14
+ return `Minified MUI error #${code}; visit ${url} for the full message.`;
19
15
  }
@@ -5,14 +5,14 @@ import * as React from 'react';
5
5
  * It will throw runtime error if the element is not a valid React element.
6
6
  *
7
7
  * @param element React.ReactElement
8
- * @returns React.Ref<any> | null | undefined
8
+ * @returns React.Ref<any> | null
9
9
  */
10
10
  export default function getReactElementRef(element) {
11
11
  // 'ref' is passed as prop in React 19, whereas 'ref' is directly attached to children in older versions
12
12
  if (parseInt(React.version, 10) >= 19) {
13
- return element.props?.ref;
13
+ return element?.props?.ref || null;
14
14
  }
15
15
  // @ts-expect-error element.ref is not included in the ReactElement type
16
16
  // https://github.com/DefinitelyTyped/DefinitelyTyped/discussions/70189
17
- return element?.ref;
17
+ return element?.ref || null;
18
18
  }
package/modern/index.js CHANGED
@@ -1,5 +1,5 @@
1
1
  /**
2
- * @mui/utils v6.1.2
2
+ * @mui/utils v6.1.4
3
3
  *
4
4
  * @license MIT
5
5
  * This source code is licensed under the MIT license found in the
@@ -28,20 +28,20 @@ function emitCurrentTabStorageChange(key) {
28
28
  listeners.forEach(listener => listener());
29
29
  }
30
30
  }
31
- function subscribe(area, key, callbark) {
31
+ function subscribe(area, key, callback) {
32
32
  if (!key) {
33
33
  return () => {};
34
34
  }
35
35
  const storageHandler = event => {
36
36
  if (event.storageArea === area && event.key === key) {
37
- callbark();
37
+ callback();
38
38
  }
39
39
  };
40
40
  window.addEventListener('storage', storageHandler);
41
- onCurrentTabStorageChange(key, callbark);
41
+ onCurrentTabStorageChange(key, callback);
42
42
  return () => {
43
43
  window.removeEventListener('storage', storageHandler);
44
- offCurrentTabStorageChange(key, callbark);
44
+ offCurrentTabStorageChange(key, callback);
45
45
  };
46
46
  }
47
47
  function getSnapshot(area, key) {
@@ -89,7 +89,7 @@ function useLocalStorageStateServer() {
89
89
  function useLocalStorageStateBrowser(key, initializer = null) {
90
90
  const [initialValue] = React.useState(initializer);
91
91
  const area = window.localStorage;
92
- const subscribeKey = React.useCallback(callbark => subscribe(area, key, callbark), [area, key]);
92
+ const subscribeKey = React.useCallback(callback => subscribe(area, key, callback), [area, key]);
93
93
  const getKeySnapshot = React.useCallback(() => getSnapshot(area, key) ?? initialValue, [area, initialValue, key]);
94
94
 
95
95
  // Start with null for the hydration, and then switch to the actual value.
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@mui/utils",
3
- "version": "6.1.2",
3
+ "version": "6.1.4",
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.25.6",
29
+ "@babel/runtime": "^7.25.7",
30
30
  "@types/prop-types": "^15.7.13",
31
31
  "clsx": "^2.1.1",
32
32
  "prop-types": "^15.8.1",
33
33
  "react-is": "^18.3.1",
34
- "@mui/types": "^7.2.17"
34
+ "@mui/types": "^7.2.18"
35
35
  },
36
36
  "peerDependencies": {
37
37
  "@types/react": "^17.0.0 || ^18.0.0 || ^19.0.0",
@@ -33,20 +33,20 @@ function emitCurrentTabStorageChange(key) {
33
33
  listeners.forEach(listener => listener());
34
34
  }
35
35
  }
36
- function subscribe(area, key, callbark) {
36
+ function subscribe(area, key, callback) {
37
37
  if (!key) {
38
38
  return () => {};
39
39
  }
40
40
  const storageHandler = event => {
41
41
  if (event.storageArea === area && event.key === key) {
42
- callbark();
42
+ callback();
43
43
  }
44
44
  };
45
45
  window.addEventListener('storage', storageHandler);
46
- onCurrentTabStorageChange(key, callbark);
46
+ onCurrentTabStorageChange(key, callback);
47
47
  return () => {
48
48
  window.removeEventListener('storage', storageHandler);
49
- offCurrentTabStorageChange(key, callbark);
49
+ offCurrentTabStorageChange(key, callback);
50
50
  };
51
51
  }
52
52
  function getSnapshot(area, key) {
@@ -94,7 +94,7 @@ function useLocalStorageStateServer() {
94
94
  function useLocalStorageStateBrowser(key, initializer = null) {
95
95
  const [initialValue] = React.useState(initializer);
96
96
  const area = window.localStorage;
97
- const subscribeKey = React.useCallback(callbark => subscribe(area, key, callbark), [area, key]);
97
+ const subscribeKey = React.useCallback(callback => subscribe(area, key, callback), [area, key]);
98
98
  const getKeySnapshot = React.useCallback(() => getSnapshot(area, key) ?? initialValue, [area, initialValue, key]);
99
99
 
100
100
  // Start with null for the hydration, and then switch to the actual value.