@mui/system 5.15.9 → 5.15.12

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 (105) hide show
  1. package/Box/Box.js +2 -2
  2. package/Box/boxClasses.js +3 -2
  3. package/CHANGELOG.md +375 -133
  4. package/Container/containerClasses.js +5 -3
  5. package/Container/createContainer.js +7 -5
  6. package/Stack/createStack.js +5 -3
  7. package/Stack/stackClasses.js +5 -3
  8. package/ThemeProvider/ThemeProvider.js +2 -2
  9. package/Unstable_Grid/createGrid.js +12 -7
  10. package/Unstable_Grid/gridClasses.js +5 -3
  11. package/breakpoints.js +2 -2
  12. package/colorManipulator.js +2 -2
  13. package/createStyled.js +8 -6
  14. package/createTheme/createSpacing.d.ts +1 -1
  15. package/createTheme/createTheme.js +3 -3
  16. package/cssVars/createCssVarsProvider.js +6 -3
  17. package/cssVars/createCssVarsTheme.d.ts +1 -0
  18. package/cssVars/prepareCssVars.d.ts +5 -2
  19. package/cssVars/prepareCssVars.js +21 -14
  20. package/esm/Box/Box.js +1 -1
  21. package/esm/Box/boxClasses.js +1 -1
  22. package/esm/Container/containerClasses.js +2 -1
  23. package/esm/Container/createContainer.js +3 -1
  24. package/esm/Stack/createStack.js +3 -1
  25. package/esm/Stack/stackClasses.js +2 -1
  26. package/esm/ThemeProvider/ThemeProvider.js +1 -1
  27. package/esm/Unstable_Grid/createGrid.js +10 -5
  28. package/esm/Unstable_Grid/gridClasses.js +2 -1
  29. package/esm/breakpoints.js +1 -1
  30. package/esm/colorManipulator.js +1 -1
  31. package/esm/createStyled.js +5 -3
  32. package/esm/createTheme/createTheme.js +1 -1
  33. package/esm/cssVars/createCssVarsProvider.js +4 -1
  34. package/esm/cssVars/prepareCssVars.js +19 -12
  35. package/esm/index.js +1 -0
  36. package/esm/merge.js +1 -1
  37. package/esm/propsToClassKey.js +1 -1
  38. package/esm/style.js +1 -1
  39. package/esm/styleFunctionSx/extendSxProp.js +1 -1
  40. package/esm/styleFunctionSx/styleFunctionSx.js +1 -1
  41. package/esm/useMediaQuery/index.js +2 -0
  42. package/esm/useMediaQuery/useMediaQuery.js +126 -0
  43. package/esm/useThemeProps/getThemeProps.js +1 -1
  44. package/index.d.ts +3 -0
  45. package/index.js +9 -1
  46. package/legacy/Box/Box.js +1 -1
  47. package/legacy/Box/boxClasses.js +1 -1
  48. package/legacy/Container/containerClasses.js +2 -1
  49. package/legacy/Container/createContainer.js +3 -1
  50. package/legacy/Stack/createStack.js +3 -1
  51. package/legacy/Stack/stackClasses.js +2 -1
  52. package/legacy/ThemeProvider/ThemeProvider.js +1 -1
  53. package/legacy/Unstable_Grid/createGrid.js +10 -5
  54. package/legacy/Unstable_Grid/gridClasses.js +2 -1
  55. package/legacy/breakpoints.js +1 -1
  56. package/legacy/colorManipulator.js +1 -1
  57. package/legacy/createStyled.js +5 -3
  58. package/legacy/createTheme/createTheme.js +1 -1
  59. package/legacy/cssVars/createCssVarsProvider.js +4 -1
  60. package/legacy/cssVars/prepareCssVars.js +21 -12
  61. package/legacy/index.js +2 -1
  62. package/legacy/merge.js +1 -1
  63. package/legacy/propsToClassKey.js +1 -1
  64. package/legacy/style.js +1 -1
  65. package/legacy/styleFunctionSx/extendSxProp.js +1 -1
  66. package/legacy/styleFunctionSx/styleFunctionSx.js +1 -1
  67. package/legacy/useMediaQuery/index.js +2 -0
  68. package/legacy/useMediaQuery/useMediaQuery.js +145 -0
  69. package/legacy/useThemeProps/getThemeProps.js +1 -1
  70. package/merge.js +3 -2
  71. package/modern/Box/Box.js +1 -1
  72. package/modern/Box/boxClasses.js +1 -1
  73. package/modern/Container/containerClasses.js +2 -1
  74. package/modern/Container/createContainer.js +3 -1
  75. package/modern/Stack/createStack.js +3 -1
  76. package/modern/Stack/stackClasses.js +2 -1
  77. package/modern/ThemeProvider/ThemeProvider.js +1 -1
  78. package/modern/Unstable_Grid/createGrid.js +10 -5
  79. package/modern/Unstable_Grid/gridClasses.js +2 -1
  80. package/modern/breakpoints.js +1 -1
  81. package/modern/colorManipulator.js +1 -1
  82. package/modern/createStyled.js +5 -3
  83. package/modern/createTheme/createTheme.js +1 -1
  84. package/modern/cssVars/createCssVarsProvider.js +4 -1
  85. package/modern/cssVars/prepareCssVars.js +17 -12
  86. package/modern/index.js +2 -1
  87. package/modern/merge.js +1 -1
  88. package/modern/propsToClassKey.js +1 -1
  89. package/modern/style.js +1 -1
  90. package/modern/styleFunctionSx/extendSxProp.js +1 -1
  91. package/modern/styleFunctionSx/styleFunctionSx.js +1 -1
  92. package/modern/useMediaQuery/index.js +2 -0
  93. package/modern/useMediaQuery/useMediaQuery.js +126 -0
  94. package/modern/useThemeProps/getThemeProps.js +1 -1
  95. package/package.json +4 -4
  96. package/propsToClassKey.js +3 -3
  97. package/style.js +2 -2
  98. package/styleFunctionSx/extendSxProp.js +2 -2
  99. package/styleFunctionSx/styleFunctionSx.js +2 -2
  100. package/useMediaQuery/index.d.ts +2 -0
  101. package/useMediaQuery/index.js +26 -0
  102. package/useMediaQuery/package.json +6 -0
  103. package/useMediaQuery/useMediaQuery.d.ts +46 -0
  104. package/useMediaQuery/useMediaQuery.js +133 -0
  105. package/useThemeProps/getThemeProps.js +3 -2
@@ -0,0 +1,126 @@
1
+ 'use client';
2
+
3
+ import * as React from 'react';
4
+ import useEnhancedEffect from '@mui/utils/useEnhancedEffect';
5
+ import { getThemeProps } from '../useThemeProps';
6
+ import useTheme from '../useThemeWithoutDefault';
7
+
8
+ /**
9
+ * @deprecated Not used internally. Use `MediaQueryListEvent` from lib.dom.d.ts instead.
10
+ */
11
+
12
+ /**
13
+ * @deprecated Not used internally. Use `MediaQueryList` from lib.dom.d.ts instead.
14
+ */
15
+
16
+ /**
17
+ * @deprecated Not used internally. Use `(event: MediaQueryListEvent) => void` instead.
18
+ */
19
+
20
+ function useMediaQueryOld(query, defaultMatches, matchMedia, ssrMatchMedia, noSsr) {
21
+ const [match, setMatch] = React.useState(() => {
22
+ if (noSsr && matchMedia) {
23
+ return matchMedia(query).matches;
24
+ }
25
+ if (ssrMatchMedia) {
26
+ return ssrMatchMedia(query).matches;
27
+ }
28
+
29
+ // Once the component is mounted, we rely on the
30
+ // event listeners to return the correct matches value.
31
+ return defaultMatches;
32
+ });
33
+ useEnhancedEffect(() => {
34
+ let active = true;
35
+ if (!matchMedia) {
36
+ return undefined;
37
+ }
38
+ const queryList = matchMedia(query);
39
+ const updateMatch = () => {
40
+ // Workaround Safari wrong implementation of matchMedia
41
+ // TODO can we remove it?
42
+ // https://github.com/mui/material-ui/pull/17315#issuecomment-528286677
43
+ if (active) {
44
+ setMatch(queryList.matches);
45
+ }
46
+ };
47
+ updateMatch();
48
+ // TODO: Use `addEventListener` once support for Safari < 14 is dropped
49
+ queryList.addListener(updateMatch);
50
+ return () => {
51
+ active = false;
52
+ queryList.removeListener(updateMatch);
53
+ };
54
+ }, [query, matchMedia]);
55
+ return match;
56
+ }
57
+
58
+ // eslint-disable-next-line no-useless-concat -- Workaround for https://github.com/webpack/webpack/issues/14814
59
+ const maybeReactUseSyncExternalStore = React['useSyncExternalStore' + ''];
60
+ function useMediaQueryNew(query, defaultMatches, matchMedia, ssrMatchMedia, noSsr) {
61
+ const getDefaultSnapshot = React.useCallback(() => defaultMatches, [defaultMatches]);
62
+ const getServerSnapshot = React.useMemo(() => {
63
+ if (noSsr && matchMedia) {
64
+ return () => matchMedia(query).matches;
65
+ }
66
+ if (ssrMatchMedia !== null) {
67
+ const {
68
+ matches
69
+ } = ssrMatchMedia(query);
70
+ return () => matches;
71
+ }
72
+ return getDefaultSnapshot;
73
+ }, [getDefaultSnapshot, query, ssrMatchMedia, noSsr, matchMedia]);
74
+ const [getSnapshot, subscribe] = React.useMemo(() => {
75
+ if (matchMedia === null) {
76
+ return [getDefaultSnapshot, () => () => {}];
77
+ }
78
+ const mediaQueryList = matchMedia(query);
79
+ return [() => mediaQueryList.matches, notify => {
80
+ // TODO: Use `addEventListener` once support for Safari < 14 is dropped
81
+ mediaQueryList.addListener(notify);
82
+ return () => {
83
+ mediaQueryList.removeListener(notify);
84
+ };
85
+ }];
86
+ }, [getDefaultSnapshot, matchMedia, query]);
87
+ const match = maybeReactUseSyncExternalStore(subscribe, getSnapshot, getServerSnapshot);
88
+ return match;
89
+ }
90
+ export default function useMediaQuery(queryInput, options = {}) {
91
+ const theme = useTheme();
92
+ // Wait for jsdom to support the match media feature.
93
+ // All the browsers MUI support have this built-in.
94
+ // This defensive check is here for simplicity.
95
+ // Most of the time, the match media logic isn't central to people tests.
96
+ const supportMatchMedia = typeof window !== 'undefined' && typeof window.matchMedia !== 'undefined';
97
+ const {
98
+ defaultMatches = false,
99
+ matchMedia = supportMatchMedia ? window.matchMedia : null,
100
+ ssrMatchMedia = null,
101
+ noSsr = false
102
+ } = getThemeProps({
103
+ name: 'MuiUseMediaQuery',
104
+ props: options,
105
+ theme
106
+ });
107
+ if (process.env.NODE_ENV !== 'production') {
108
+ if (typeof queryInput === 'function' && theme === null) {
109
+ console.error(['MUI: The `query` argument provided is invalid.', 'You are providing a function without a theme in the context.', 'One of the parent elements needs to use a ThemeProvider.'].join('\n'));
110
+ }
111
+ }
112
+ let query = typeof queryInput === 'function' ? queryInput(theme) : queryInput;
113
+ query = query.replace(/^@media( ?)/m, '');
114
+
115
+ // TODO: Drop `useMediaQueryOld` and use `use-sync-external-store` shim in `useMediaQueryNew` once the package is stable
116
+ const useMediaQueryImplementation = maybeReactUseSyncExternalStore !== undefined ? useMediaQueryNew : useMediaQueryOld;
117
+ const match = useMediaQueryImplementation(query, defaultMatches, matchMedia, ssrMatchMedia, noSsr);
118
+ if (process.env.NODE_ENV !== 'production') {
119
+ // eslint-disable-next-line react-hooks/rules-of-hooks
120
+ React.useDebugValue({
121
+ query,
122
+ match
123
+ });
124
+ }
125
+ return match;
126
+ }
@@ -1,4 +1,4 @@
1
- import { internal_resolveProps as resolveProps } from '@mui/utils';
1
+ import resolveProps from '@mui/utils/resolveProps';
2
2
  export default function getThemeProps(params) {
3
3
  const {
4
4
  theme,
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@mui/system",
3
- "version": "5.15.9",
3
+ "version": "5.15.12",
4
4
  "private": false,
5
5
  "author": "MUI Team",
6
6
  "description": "MUI System is a set of CSS utilities to help you build custom designs more efficiently. It makes it possible to rapidly lay out custom designs.",
@@ -30,10 +30,10 @@
30
30
  "clsx": "^2.1.0",
31
31
  "csstype": "^3.1.3",
32
32
  "prop-types": "^15.8.1",
33
- "@mui/private-theming": "^5.15.9",
33
+ "@mui/utils": "^5.15.12",
34
+ "@mui/private-theming": "^5.15.12",
34
35
  "@mui/types": "^7.2.13",
35
- "@mui/styled-engine": "^5.15.9",
36
- "@mui/utils": "^5.15.9"
36
+ "@mui/styled-engine": "^5.15.11"
37
37
  },
38
38
  "peerDependencies": {
39
39
  "@emotion/react": "^11.5.0",
@@ -6,7 +6,7 @@ Object.defineProperty(exports, "__esModule", {
6
6
  });
7
7
  exports.default = propsToClassKey;
8
8
  var _objectWithoutPropertiesLoose2 = _interopRequireDefault(require("@babel/runtime/helpers/objectWithoutPropertiesLoose"));
9
- var _utils = require("@mui/utils");
9
+ var _capitalize = _interopRequireDefault(require("@mui/utils/capitalize"));
10
10
  const _excluded = ["variant"];
11
11
  function isEmpty(string) {
12
12
  return string.length === 0;
@@ -25,9 +25,9 @@ function propsToClassKey(props) {
25
25
  let classKey = variant || '';
26
26
  Object.keys(other).sort().forEach(key => {
27
27
  if (key === 'color') {
28
- classKey += isEmpty(classKey) ? props[key] : (0, _utils.unstable_capitalize)(props[key]);
28
+ classKey += isEmpty(classKey) ? props[key] : (0, _capitalize.default)(props[key]);
29
29
  } else {
30
- classKey += `${isEmpty(classKey) ? key : (0, _utils.unstable_capitalize)(key)}${(0, _utils.unstable_capitalize)(props[key].toString())}`;
30
+ classKey += `${isEmpty(classKey) ? key : (0, _capitalize.default)(key)}${(0, _capitalize.default)(props[key].toString())}`;
31
31
  }
32
32
  });
33
33
  return classKey;
package/style.js CHANGED
@@ -7,7 +7,7 @@ Object.defineProperty(exports, "__esModule", {
7
7
  exports.default = void 0;
8
8
  exports.getPath = getPath;
9
9
  exports.getStyleValue = getStyleValue;
10
- var _utils = require("@mui/utils");
10
+ var _capitalize = _interopRequireDefault(require("@mui/utils/capitalize"));
11
11
  var _responsivePropType = _interopRequireDefault(require("./responsivePropType"));
12
12
  var _breakpoints = require("./breakpoints");
13
13
  function getPath(obj, path, checkVars = true) {
@@ -64,7 +64,7 @@ function style(options) {
64
64
  let value = getStyleValue(themeMapping, transform, propValueFinal);
65
65
  if (propValueFinal === value && typeof propValueFinal === 'string') {
66
66
  // Haven't found value
67
- value = getStyleValue(themeMapping, transform, `${prop}${propValueFinal === 'default' ? '' : (0, _utils.unstable_capitalize)(propValueFinal)}`, propValueFinal);
67
+ value = getStyleValue(themeMapping, transform, `${prop}${propValueFinal === 'default' ? '' : (0, _capitalize.default)(propValueFinal)}`, propValueFinal);
68
68
  }
69
69
  if (cssProperty === false) {
70
70
  return value;
@@ -7,7 +7,7 @@ Object.defineProperty(exports, "__esModule", {
7
7
  exports.default = extendSxProp;
8
8
  var _extends2 = _interopRequireDefault(require("@babel/runtime/helpers/extends"));
9
9
  var _objectWithoutPropertiesLoose2 = _interopRequireDefault(require("@babel/runtime/helpers/objectWithoutPropertiesLoose"));
10
- var _utils = require("@mui/utils");
10
+ var _deepmerge = require("@mui/utils/deepmerge");
11
11
  var _defaultSxConfig = _interopRequireDefault(require("./defaultSxConfig"));
12
12
  const _excluded = ["sx"];
13
13
  const splitProps = props => {
@@ -41,7 +41,7 @@ function extendSxProp(props) {
41
41
  } else if (typeof inSx === 'function') {
42
42
  finalSx = (...args) => {
43
43
  const result = inSx(...args);
44
- if (!(0, _utils.isPlainObject)(result)) {
44
+ if (!(0, _deepmerge.isPlainObject)(result)) {
45
45
  return systemProps;
46
46
  }
47
47
  return (0, _extends2.default)({}, systemProps, result);
@@ -6,7 +6,7 @@ Object.defineProperty(exports, "__esModule", {
6
6
  });
7
7
  exports.default = void 0;
8
8
  exports.unstable_createStyleFunctionSx = unstable_createStyleFunctionSx;
9
- var _utils = require("@mui/utils");
9
+ var _capitalize = _interopRequireDefault(require("@mui/utils/capitalize"));
10
10
  var _merge = _interopRequireDefault(require("../merge"));
11
11
  var _style = require("../style");
12
12
  var _breakpoints = require("../breakpoints");
@@ -57,7 +57,7 @@ function unstable_createStyleFunctionSx() {
57
57
  let value = (0, _style.getStyleValue)(themeMapping, transform, propValueFinal);
58
58
  if (propValueFinal === value && typeof propValueFinal === 'string') {
59
59
  // Haven't found value
60
- value = (0, _style.getStyleValue)(themeMapping, transform, `${prop}${propValueFinal === 'default' ? '' : (0, _utils.unstable_capitalize)(propValueFinal)}`, propValueFinal);
60
+ value = (0, _style.getStyleValue)(themeMapping, transform, `${prop}${propValueFinal === 'default' ? '' : (0, _capitalize.default)(propValueFinal)}`, propValueFinal);
61
61
  }
62
62
  if (cssProperty === false) {
63
63
  return value;
@@ -0,0 +1,2 @@
1
+ export { default } from './useMediaQuery';
2
+ export * from './useMediaQuery';
@@ -0,0 +1,26 @@
1
+ "use strict";
2
+
3
+ Object.defineProperty(exports, "__esModule", {
4
+ value: true
5
+ });
6
+ var _exportNames = {};
7
+ Object.defineProperty(exports, "default", {
8
+ enumerable: true,
9
+ get: function () {
10
+ return _useMediaQuery.default;
11
+ }
12
+ });
13
+ var _useMediaQuery = _interopRequireWildcard(require("./useMediaQuery"));
14
+ Object.keys(_useMediaQuery).forEach(function (key) {
15
+ if (key === "default" || key === "__esModule") return;
16
+ if (Object.prototype.hasOwnProperty.call(_exportNames, key)) return;
17
+ if (key in exports && exports[key] === _useMediaQuery[key]) return;
18
+ Object.defineProperty(exports, key, {
19
+ enumerable: true,
20
+ get: function () {
21
+ return _useMediaQuery[key];
22
+ }
23
+ });
24
+ });
25
+ function _getRequireWildcardCache(e) { if ("function" != typeof WeakMap) return null; var r = new WeakMap(), t = new WeakMap(); return (_getRequireWildcardCache = function (e) { return e ? t : r; })(e); }
26
+ function _interopRequireWildcard(e, r) { if (!r && e && e.__esModule) return e; if (null === e || "object" != typeof e && "function" != typeof e) return { default: e }; var t = _getRequireWildcardCache(r); if (t && t.has(e)) return t.get(e); var n = { __proto__: null }, a = Object.defineProperty && Object.getOwnPropertyDescriptor; for (var u in e) if ("default" !== u && Object.prototype.hasOwnProperty.call(e, u)) { var i = a ? Object.getOwnPropertyDescriptor(e, u) : null; i && (i.get || i.set) ? Object.defineProperty(n, u, i) : n[u] = e[u]; } return n.default = e, t && t.set(e, n), n; }
@@ -0,0 +1,6 @@
1
+ {
2
+ "sideEffects": false,
3
+ "module": "../esm/useMediaQuery/index.js",
4
+ "main": "./index.js",
5
+ "types": "./index.d.ts"
6
+ }
@@ -0,0 +1,46 @@
1
+ /**
2
+ * @deprecated Not used internally. Use `MediaQueryListEvent` from lib.dom.d.ts instead.
3
+ */
4
+ export interface MuiMediaQueryListEvent {
5
+ matches: boolean;
6
+ }
7
+ /**
8
+ * @deprecated Not used internally. Use `MediaQueryList` from lib.dom.d.ts instead.
9
+ */
10
+ export interface MuiMediaQueryList {
11
+ matches: boolean;
12
+ addListener: (listener: MuiMediaQueryListListener) => void;
13
+ removeListener: (listener: MuiMediaQueryListListener) => void;
14
+ }
15
+ /**
16
+ * @deprecated Not used internally. Use `(event: MediaQueryListEvent) => void` instead.
17
+ */
18
+ export type MuiMediaQueryListListener = (event: MuiMediaQueryListEvent) => void;
19
+ export interface UseMediaQueryOptions {
20
+ /**
21
+ * As `window.matchMedia()` is unavailable on the server,
22
+ * it returns a default matches during the first mount.
23
+ * @default false
24
+ */
25
+ defaultMatches?: boolean;
26
+ /**
27
+ * You can provide your own implementation of matchMedia.
28
+ * This can be used for handling an iframe content window.
29
+ */
30
+ matchMedia?: typeof window.matchMedia;
31
+ /**
32
+ * To perform the server-side hydration, the hook needs to render twice.
33
+ * A first time with `defaultMatches`, the value of the server, and a second time with the resolved value.
34
+ * This double pass rendering cycle comes with a drawback: it's slower.
35
+ * You can set this option to `true` if you use the returned value **only** client-side.
36
+ * @default false
37
+ */
38
+ noSsr?: boolean;
39
+ /**
40
+ * You can provide your own implementation of `matchMedia`, it's used when rendering server-side.
41
+ */
42
+ ssrMatchMedia?: (query: string) => {
43
+ matches: boolean;
44
+ };
45
+ }
46
+ export default function useMediaQuery<Theme = unknown>(queryInput: string | ((theme: Theme) => string), options?: UseMediaQueryOptions): boolean;
@@ -0,0 +1,133 @@
1
+ "use strict";
2
+ 'use client';
3
+
4
+ var _interopRequireDefault = require("@babel/runtime/helpers/interopRequireDefault");
5
+ Object.defineProperty(exports, "__esModule", {
6
+ value: true
7
+ });
8
+ exports.default = useMediaQuery;
9
+ var React = _interopRequireWildcard(require("react"));
10
+ var _useEnhancedEffect = _interopRequireDefault(require("@mui/utils/useEnhancedEffect"));
11
+ var _useThemeProps = require("../useThemeProps");
12
+ var _useThemeWithoutDefault = _interopRequireDefault(require("../useThemeWithoutDefault"));
13
+ function _getRequireWildcardCache(e) { if ("function" != typeof WeakMap) return null; var r = new WeakMap(), t = new WeakMap(); return (_getRequireWildcardCache = function (e) { return e ? t : r; })(e); }
14
+ function _interopRequireWildcard(e, r) { if (!r && e && e.__esModule) return e; if (null === e || "object" != typeof e && "function" != typeof e) return { default: e }; var t = _getRequireWildcardCache(r); if (t && t.has(e)) return t.get(e); var n = { __proto__: null }, a = Object.defineProperty && Object.getOwnPropertyDescriptor; for (var u in e) if ("default" !== u && Object.prototype.hasOwnProperty.call(e, u)) { var i = a ? Object.getOwnPropertyDescriptor(e, u) : null; i && (i.get || i.set) ? Object.defineProperty(n, u, i) : n[u] = e[u]; } return n.default = e, t && t.set(e, n), n; }
15
+ /**
16
+ * @deprecated Not used internally. Use `MediaQueryListEvent` from lib.dom.d.ts instead.
17
+ */
18
+
19
+ /**
20
+ * @deprecated Not used internally. Use `MediaQueryList` from lib.dom.d.ts instead.
21
+ */
22
+
23
+ /**
24
+ * @deprecated Not used internally. Use `(event: MediaQueryListEvent) => void` instead.
25
+ */
26
+
27
+ function useMediaQueryOld(query, defaultMatches, matchMedia, ssrMatchMedia, noSsr) {
28
+ const [match, setMatch] = React.useState(() => {
29
+ if (noSsr && matchMedia) {
30
+ return matchMedia(query).matches;
31
+ }
32
+ if (ssrMatchMedia) {
33
+ return ssrMatchMedia(query).matches;
34
+ }
35
+
36
+ // Once the component is mounted, we rely on the
37
+ // event listeners to return the correct matches value.
38
+ return defaultMatches;
39
+ });
40
+ (0, _useEnhancedEffect.default)(() => {
41
+ let active = true;
42
+ if (!matchMedia) {
43
+ return undefined;
44
+ }
45
+ const queryList = matchMedia(query);
46
+ const updateMatch = () => {
47
+ // Workaround Safari wrong implementation of matchMedia
48
+ // TODO can we remove it?
49
+ // https://github.com/mui/material-ui/pull/17315#issuecomment-528286677
50
+ if (active) {
51
+ setMatch(queryList.matches);
52
+ }
53
+ };
54
+ updateMatch();
55
+ // TODO: Use `addEventListener` once support for Safari < 14 is dropped
56
+ queryList.addListener(updateMatch);
57
+ return () => {
58
+ active = false;
59
+ queryList.removeListener(updateMatch);
60
+ };
61
+ }, [query, matchMedia]);
62
+ return match;
63
+ }
64
+
65
+ // eslint-disable-next-line no-useless-concat -- Workaround for https://github.com/webpack/webpack/issues/14814
66
+ const maybeReactUseSyncExternalStore = React['useSyncExternalStore' + ''];
67
+ function useMediaQueryNew(query, defaultMatches, matchMedia, ssrMatchMedia, noSsr) {
68
+ const getDefaultSnapshot = React.useCallback(() => defaultMatches, [defaultMatches]);
69
+ const getServerSnapshot = React.useMemo(() => {
70
+ if (noSsr && matchMedia) {
71
+ return () => matchMedia(query).matches;
72
+ }
73
+ if (ssrMatchMedia !== null) {
74
+ const {
75
+ matches
76
+ } = ssrMatchMedia(query);
77
+ return () => matches;
78
+ }
79
+ return getDefaultSnapshot;
80
+ }, [getDefaultSnapshot, query, ssrMatchMedia, noSsr, matchMedia]);
81
+ const [getSnapshot, subscribe] = React.useMemo(() => {
82
+ if (matchMedia === null) {
83
+ return [getDefaultSnapshot, () => () => {}];
84
+ }
85
+ const mediaQueryList = matchMedia(query);
86
+ return [() => mediaQueryList.matches, notify => {
87
+ // TODO: Use `addEventListener` once support for Safari < 14 is dropped
88
+ mediaQueryList.addListener(notify);
89
+ return () => {
90
+ mediaQueryList.removeListener(notify);
91
+ };
92
+ }];
93
+ }, [getDefaultSnapshot, matchMedia, query]);
94
+ const match = maybeReactUseSyncExternalStore(subscribe, getSnapshot, getServerSnapshot);
95
+ return match;
96
+ }
97
+ function useMediaQuery(queryInput, options = {}) {
98
+ const theme = (0, _useThemeWithoutDefault.default)();
99
+ // Wait for jsdom to support the match media feature.
100
+ // All the browsers MUI support have this built-in.
101
+ // This defensive check is here for simplicity.
102
+ // Most of the time, the match media logic isn't central to people tests.
103
+ const supportMatchMedia = typeof window !== 'undefined' && typeof window.matchMedia !== 'undefined';
104
+ const {
105
+ defaultMatches = false,
106
+ matchMedia = supportMatchMedia ? window.matchMedia : null,
107
+ ssrMatchMedia = null,
108
+ noSsr = false
109
+ } = (0, _useThemeProps.getThemeProps)({
110
+ name: 'MuiUseMediaQuery',
111
+ props: options,
112
+ theme
113
+ });
114
+ if (process.env.NODE_ENV !== 'production') {
115
+ if (typeof queryInput === 'function' && theme === null) {
116
+ console.error(['MUI: The `query` argument provided is invalid.', 'You are providing a function without a theme in the context.', 'One of the parent elements needs to use a ThemeProvider.'].join('\n'));
117
+ }
118
+ }
119
+ let query = typeof queryInput === 'function' ? queryInput(theme) : queryInput;
120
+ query = query.replace(/^@media( ?)/m, '');
121
+
122
+ // TODO: Drop `useMediaQueryOld` and use `use-sync-external-store` shim in `useMediaQueryNew` once the package is stable
123
+ const useMediaQueryImplementation = maybeReactUseSyncExternalStore !== undefined ? useMediaQueryNew : useMediaQueryOld;
124
+ const match = useMediaQueryImplementation(query, defaultMatches, matchMedia, ssrMatchMedia, noSsr);
125
+ if (process.env.NODE_ENV !== 'production') {
126
+ // eslint-disable-next-line react-hooks/rules-of-hooks
127
+ React.useDebugValue({
128
+ query,
129
+ match
130
+ });
131
+ }
132
+ return match;
133
+ }
@@ -1,10 +1,11 @@
1
1
  "use strict";
2
2
 
3
+ var _interopRequireDefault = require("@babel/runtime/helpers/interopRequireDefault");
3
4
  Object.defineProperty(exports, "__esModule", {
4
5
  value: true
5
6
  });
6
7
  exports.default = getThemeProps;
7
- var _utils = require("@mui/utils");
8
+ var _resolveProps = _interopRequireDefault(require("@mui/utils/resolveProps"));
8
9
  function getThemeProps(params) {
9
10
  const {
10
11
  theme,
@@ -14,5 +15,5 @@ function getThemeProps(params) {
14
15
  if (!theme || !theme.components || !theme.components[name] || !theme.components[name].defaultProps) {
15
16
  return props;
16
17
  }
17
- return (0, _utils.internal_resolveProps)(theme.components[name].defaultProps, props);
18
+ return (0, _resolveProps.default)(theme.components[name].defaultProps, props);
18
19
  }