@mui/system 5.15.7 → 5.15.9

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.
@@ -1,11 +1,12 @@
1
- import _objectWithoutPropertiesLoose from "@babel/runtime/helpers/esm/objectWithoutPropertiesLoose";
2
1
  import _extends from "@babel/runtime/helpers/esm/extends";
3
- const _excluded = ["name", "slot", "skipVariantsResolver", "skipSx", "overridesResolver"];
2
+ import _objectWithoutPropertiesLoose from "@babel/runtime/helpers/esm/objectWithoutPropertiesLoose";
3
+ const _excluded = ["ownerState"],
4
+ _excluded2 = ["variants"],
5
+ _excluded3 = ["name", "slot", "skipVariantsResolver", "skipSx", "overridesResolver"];
4
6
  /* eslint-disable no-underscore-dangle */
5
7
  import styledEngineStyled, { internal_processStyles as processStyles } from '@mui/styled-engine';
6
- import { getDisplayName, unstable_capitalize as capitalize, isPlainObject, deepmerge } from '@mui/utils';
8
+ import { getDisplayName, unstable_capitalize as capitalize, isPlainObject } from '@mui/utils';
7
9
  import createTheme from './createTheme';
8
- import propsToClassKey from './propsToClassKey';
9
10
  import styleFunctionSx from './styleFunctionSx';
10
11
  function isEmpty(obj) {
11
12
  return Object.keys(obj).length === 0;
@@ -19,73 +20,6 @@ function isStringTag(tag) {
19
20
  // it's a lowercase character
20
21
  tag.charCodeAt(0) > 96;
21
22
  }
22
- const getStyleOverrides = (name, theme) => {
23
- if (theme.components && theme.components[name] && theme.components[name].styleOverrides) {
24
- return theme.components[name].styleOverrides;
25
- }
26
- return null;
27
- };
28
- const transformVariants = variants => {
29
- let numOfCallbacks = 0;
30
- const variantsStyles = {};
31
- if (variants) {
32
- variants.forEach(definition => {
33
- let key = '';
34
- if (typeof definition.props === 'function') {
35
- key = `callback${numOfCallbacks}`;
36
- numOfCallbacks += 1;
37
- } else {
38
- key = propsToClassKey(definition.props);
39
- }
40
- variantsStyles[key] = definition.style;
41
- });
42
- }
43
- return variantsStyles;
44
- };
45
- const getVariantStyles = (name, theme) => {
46
- let variants = [];
47
- if (theme && theme.components && theme.components[name] && theme.components[name].variants) {
48
- variants = theme.components[name].variants;
49
- }
50
- return transformVariants(variants);
51
- };
52
- const variantsResolver = (props, styles, variants) => {
53
- const {
54
- ownerState = {}
55
- } = props;
56
- const variantsStyles = [];
57
- let numOfCallbacks = 0;
58
- if (variants) {
59
- variants.forEach(variant => {
60
- let isMatch = true;
61
- if (typeof variant.props === 'function') {
62
- const propsToCheck = _extends({}, props, ownerState);
63
- isMatch = variant.props(propsToCheck);
64
- } else {
65
- Object.keys(variant.props).forEach(key => {
66
- if (ownerState[key] !== variant.props[key] && props[key] !== variant.props[key]) {
67
- isMatch = false;
68
- }
69
- });
70
- }
71
- if (isMatch) {
72
- if (typeof variant.props === 'function') {
73
- variantsStyles.push(styles[`callback${numOfCallbacks}`]);
74
- } else {
75
- variantsStyles.push(styles[propsToClassKey(variant.props)]);
76
- }
77
- }
78
- if (typeof variant.props === 'function') {
79
- numOfCallbacks += 1;
80
- }
81
- });
82
- }
83
- return variantsStyles;
84
- };
85
- const themeVariantsResolver = (props, styles, theme, name) => {
86
- const themeVariants = theme?.components?.[name]?.variants;
87
- return variantsResolver(props, styles, themeVariants);
88
- };
89
23
 
90
24
  // Update /system/styled/#api in case if this changes
91
25
  export function shouldForwardProp(prop) {
@@ -111,29 +45,51 @@ function defaultOverridesResolver(slot) {
111
45
  }
112
46
  return (props, styles) => styles[slot];
113
47
  }
114
- const muiStyledFunctionResolver = ({
115
- styledArg,
116
- props,
117
- defaultTheme,
118
- themeId
119
- }) => {
120
- const resolvedStyles = styledArg(_extends({}, props, {
121
- theme: resolveTheme(_extends({}, props, {
122
- defaultTheme,
123
- themeId
124
- }))
125
- }));
126
- let optionalVariants;
127
- if (resolvedStyles && resolvedStyles.variants) {
128
- optionalVariants = resolvedStyles.variants;
129
- delete resolvedStyles.variants;
48
+ function processStyleArg(callableStyle, _ref) {
49
+ let {
50
+ ownerState
51
+ } = _ref,
52
+ props = _objectWithoutPropertiesLoose(_ref, _excluded);
53
+ const resolvedStylesArg = typeof callableStyle === 'function' ? callableStyle(_extends({
54
+ ownerState
55
+ }, props)) : callableStyle;
56
+ if (Array.isArray(resolvedStylesArg)) {
57
+ return resolvedStylesArg.flatMap(resolvedStyle => processStyleArg(resolvedStyle, _extends({
58
+ ownerState
59
+ }, props)));
130
60
  }
131
- if (optionalVariants) {
132
- const variantsStyles = variantsResolver(props, transformVariants(optionalVariants), optionalVariants);
133
- return [resolvedStyles, ...variantsStyles];
61
+ if (!!resolvedStylesArg && typeof resolvedStylesArg === 'object' && Array.isArray(resolvedStylesArg.variants)) {
62
+ const {
63
+ variants = []
64
+ } = resolvedStylesArg,
65
+ otherStyles = _objectWithoutPropertiesLoose(resolvedStylesArg, _excluded2);
66
+ let result = otherStyles;
67
+ variants.forEach(variant => {
68
+ let isMatch = true;
69
+ if (typeof variant.props === 'function') {
70
+ isMatch = variant.props(_extends({
71
+ ownerState
72
+ }, props));
73
+ } else {
74
+ Object.keys(variant.props).forEach(key => {
75
+ if (ownerState?.[key] !== variant.props[key] && props[key] !== variant.props[key]) {
76
+ isMatch = false;
77
+ }
78
+ });
79
+ }
80
+ if (isMatch) {
81
+ if (!Array.isArray(result)) {
82
+ result = [result];
83
+ }
84
+ result.push(typeof variant.style === 'function' ? variant.style(_extends({
85
+ ownerState
86
+ }, props)) : variant.style);
87
+ }
88
+ });
89
+ return result;
134
90
  }
135
- return resolvedStyles;
136
- };
91
+ return resolvedStylesArg;
92
+ }
137
93
  export default function createStyled(input = {}) {
138
94
  const {
139
95
  themeId,
@@ -162,7 +118,7 @@ export default function createStyled(input = {}) {
162
118
  // For more details: https://github.com/mui/material-ui/pull/37908
163
119
  overridesResolver = defaultOverridesResolver(lowercaseFirstLetter(componentSlot))
164
120
  } = inputOptions,
165
- options = _objectWithoutPropertiesLoose(inputOptions, _excluded);
121
+ options = _objectWithoutPropertiesLoose(inputOptions, _excluded3);
166
122
 
167
123
  // if skipVariantsResolver option is defined, take the value, otherwise, true for root and false for other slots.
168
124
  const skipVariantsResolver = inputSkipVariantsResolver !== undefined ? inputSkipVariantsResolver :
@@ -195,83 +151,42 @@ export default function createStyled(input = {}) {
195
151
  shouldForwardProp: shouldForwardPropOption,
196
152
  label
197
153
  }, options));
198
- const muiStyledResolver = (styleArg, ...expressions) => {
199
- const expressionsWithDefaultTheme = expressions ? expressions.map(stylesArg => {
200
- // On the server Emotion doesn't use React.forwardRef for creating components, so the created
201
- // component stays as a function. This condition makes sure that we do not interpolate functions
202
- // which are basically components used as a selectors.
203
- if (typeof stylesArg === 'function' && stylesArg.__emotion_real !== stylesArg) {
204
- return props => muiStyledFunctionResolver({
205
- styledArg: stylesArg,
206
- props,
207
- defaultTheme,
208
- themeId
209
- });
210
- }
211
- if (isPlainObject(stylesArg)) {
212
- let transformedStylesArg = stylesArg;
213
- let styledArgVariants;
214
- if (stylesArg && stylesArg.variants) {
215
- styledArgVariants = stylesArg.variants;
216
- delete transformedStylesArg.variants;
217
- transformedStylesArg = props => {
218
- let result = stylesArg;
219
- const variantStyles = variantsResolver(props, transformVariants(styledArgVariants), styledArgVariants);
220
- variantStyles.forEach(variantStyle => {
221
- result = deepmerge(result, variantStyle);
222
- });
223
- return result;
224
- };
225
- }
226
- return transformedStylesArg;
227
- }
228
- return stylesArg;
229
- }) : [];
230
- let transformedStyleArg = styleArg;
231
- if (isPlainObject(styleArg)) {
232
- let styledArgVariants;
233
- if (styleArg && styleArg.variants) {
234
- styledArgVariants = styleArg.variants;
235
- delete transformedStyleArg.variants;
236
- transformedStyleArg = props => {
237
- let result = styleArg;
238
- const variantStyles = variantsResolver(props, transformVariants(styledArgVariants), styledArgVariants);
239
- variantStyles.forEach(variantStyle => {
240
- result = deepmerge(result, variantStyle);
241
- });
242
- return result;
243
- };
244
- }
245
- } else if (typeof styleArg === 'function' &&
154
+ const transformStyleArg = stylesArg => {
246
155
  // On the server Emotion doesn't use React.forwardRef for creating components, so the created
247
156
  // component stays as a function. This condition makes sure that we do not interpolate functions
248
157
  // which are basically components used as a selectors.
249
- styleArg.__emotion_real !== styleArg) {
250
- // If the type is function, we need to define the default theme.
251
- transformedStyleArg = props => muiStyledFunctionResolver({
252
- styledArg: styleArg,
253
- props,
254
- defaultTheme,
255
- themeId
256
- });
158
+ if (typeof stylesArg === 'function' && stylesArg.__emotion_real !== stylesArg || isPlainObject(stylesArg)) {
159
+ return props => processStyleArg(stylesArg, _extends({}, props, {
160
+ theme: resolveTheme({
161
+ theme: props.theme,
162
+ defaultTheme,
163
+ themeId
164
+ })
165
+ }));
257
166
  }
167
+ return stylesArg;
168
+ };
169
+ const muiStyledResolver = (styleArg, ...expressions) => {
170
+ let transformedStyleArg = transformStyleArg(styleArg);
171
+ const expressionsWithDefaultTheme = expressions ? expressions.map(transformStyleArg) : [];
258
172
  if (componentName && overridesResolver) {
259
173
  expressionsWithDefaultTheme.push(props => {
260
174
  const theme = resolveTheme(_extends({}, props, {
261
175
  defaultTheme,
262
176
  themeId
263
177
  }));
264
- const styleOverrides = getStyleOverrides(componentName, theme);
265
- if (styleOverrides) {
266
- const resolvedStyleOverrides = {};
267
- Object.entries(styleOverrides).forEach(([slotKey, slotStyle]) => {
268
- resolvedStyleOverrides[slotKey] = typeof slotStyle === 'function' ? slotStyle(_extends({}, props, {
269
- theme
270
- })) : slotStyle;
271
- });
272
- return overridesResolver(props, resolvedStyleOverrides);
178
+ if (!theme.components || !theme.components[componentName] || !theme.components[componentName].styleOverrides) {
179
+ return null;
273
180
  }
274
- return null;
181
+ const styleOverrides = theme.components[componentName].styleOverrides;
182
+ const resolvedStyleOverrides = {};
183
+ // TODO: v7 remove iteration and use `resolveStyleArg(styleOverrides[slot])` directly
184
+ Object.entries(styleOverrides).forEach(([slotKey, slotStyle]) => {
185
+ resolvedStyleOverrides[slotKey] = processStyleArg(slotStyle, _extends({}, props, {
186
+ theme
187
+ }));
188
+ });
189
+ return overridesResolver(props, resolvedStyleOverrides);
275
190
  });
276
191
  }
277
192
  if (componentName && !skipVariantsResolver) {
@@ -280,7 +195,12 @@ export default function createStyled(input = {}) {
280
195
  defaultTheme,
281
196
  themeId
282
197
  }));
283
- return themeVariantsResolver(props, getVariantStyles(componentName, theme), theme, componentName);
198
+ const themeVariants = theme?.components?.[componentName]?.variants;
199
+ return processStyleArg({
200
+ variants: themeVariants
201
+ }, _extends({}, props, {
202
+ theme
203
+ }));
284
204
  });
285
205
  }
286
206
  if (!skipSx) {
package/modern/index.js CHANGED
@@ -1,5 +1,5 @@
1
1
  /**
2
- * @mui/system v5.15.7
2
+ * @mui/system v5.15.9
3
3
  *
4
4
  * @license MIT
5
5
  * This source code is licensed under the MIT license found in the
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@mui/system",
3
- "version": "5.15.7",
3
+ "version": "5.15.9",
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.",
@@ -28,12 +28,12 @@
28
28
  "dependencies": {
29
29
  "@babel/runtime": "^7.23.9",
30
30
  "clsx": "^2.1.0",
31
- "csstype": "^3.1.2",
31
+ "csstype": "^3.1.3",
32
32
  "prop-types": "^15.8.1",
33
+ "@mui/private-theming": "^5.15.9",
33
34
  "@mui/types": "^7.2.13",
34
- "@mui/styled-engine": "^5.15.7",
35
- "@mui/utils": "^5.15.7",
36
- "@mui/private-theming": "^5.15.7"
35
+ "@mui/styled-engine": "^5.15.9",
36
+ "@mui/utils": "^5.15.9"
37
37
  },
38
38
  "peerDependencies": {
39
39
  "@emotion/react": "^11.5.0",
package/spacing.d.ts CHANGED
@@ -5,11 +5,11 @@ export type SpacingProps = PropsFor<typeof spacing>;
5
5
  export function createUnarySpacing<Spacing>(theme: { spacing: Spacing }): Spacing extends number
6
6
  ? (abs: number | string) => number | number
7
7
  : Spacing extends any[]
8
- ? <Index extends number>(abs: Index | string) => Spacing[Index] | string
9
- : Spacing extends (...args: unknown[]) => unknown
10
- ? Spacing
11
- : // warns in Dev
12
- () => undefined;
8
+ ? <Index extends number>(abs: Index | string) => Spacing[Index] | string
9
+ : Spacing extends (...args: unknown[]) => unknown
10
+ ? Spacing
11
+ : // warns in Dev
12
+ () => undefined;
13
13
 
14
14
  export function createUnaryUnit<Spacing>(
15
15
  theme: { spacing: Spacing },
@@ -19,11 +19,11 @@ export function createUnaryUnit<Spacing>(
19
19
  ): Spacing extends number
20
20
  ? (abs: SpacingValueType) => number | number
21
21
  : Spacing extends any[]
22
- ? <Index extends number>(abs: Index | string) => Spacing[Index] | string
23
- : Spacing extends (...args: unknown[]) => unknown
24
- ? Spacing
25
- : // warns in Dev
26
- () => undefined;
22
+ ? <Index extends number>(abs: Index | string) => Spacing[Index] | string
23
+ : Spacing extends (...args: unknown[]) => unknown
24
+ ? Spacing
25
+ : // warns in Dev
26
+ () => undefined;
27
27
 
28
28
  export const margin: SimpleStyleFunction<
29
29
  | 'm'
@@ -9,7 +9,7 @@ import { OverwriteCSSProperties } from './OverwriteCSSProperties';
9
9
  * Note that this extends to non-theme values also. For example `display=['none', 'block']`
10
10
  * will also works.
11
11
  */
12
- export type ResponsiveStyleValue<T> = T | Array<T | null> | { [key: string]: T | null };
12
+ export type ResponsiveStyleValue<T> = T | ReadonlyArray<T | null> | { [key: string]: T | null };
13
13
 
14
14
  /**
15
15
  * Map of all CSS pseudo selectors (`:hover`, `:focus`, ...).