@redsift/table 12.5.2-muiv7 → 12.5.3-alpha.0

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,1124 +1,5 @@
1
- import * as React from 'react';
2
- import { useState, useEffect } from 'react';
3
- import { P as PropTypes, R as RtlProvider, O as DefaultPropsProvider, T as THEME_ID, b as createTheme, Q as createTypography, a as styleFunctionSx } from './Portal.js';
4
- import { j as jsxRuntimeExports } from './jsx-runtime.js';
5
- import { n as useTheme$1, G as GlobalStyles, p as GlobalStyles$1 } from './ControlledPagination.js';
6
- import { ThemeContext as ThemeContext$2 } from '@emotion/react';
7
1
  import styled, { css } from 'styled-components';
8
-
9
- /**
10
- * A version of `React.useLayoutEffect` that does not show a warning when server-side rendering.
11
- * This is useful for effects that are only needed for client-side rendering but not for SSR.
12
- *
13
- * Before you use this hook, make sure to read https://gist.github.com/gaearon/e7d97cdf38a2907924ea12e4ebdf3c85
14
- * and confirm it doesn't apply to your use-case.
15
- */
16
- const useEnhancedEffect = typeof window !== 'undefined' ? React.useLayoutEffect : React.useEffect;
17
- var useEnhancedEffect$1 = useEnhancedEffect;
18
-
19
- // This module is based on https://github.com/airbnb/prop-types-exact repository.
20
- // However, in order to reduce the number of dependencies and to remove some extra safe checks
21
- // the module was forked.
22
-
23
- const specialProperty$1 = 'exact-prop: \u200b';
24
- function exactProp$1(propTypes) {
25
- if (process.env.NODE_ENV === 'production') {
26
- return propTypes;
27
- }
28
- return {
29
- ...propTypes,
30
- [specialProperty$1]: props => {
31
- const unsupportedProps = Object.keys(props).filter(prop => !propTypes.hasOwnProperty(prop));
32
- if (unsupportedProps.length > 0) {
33
- return new Error(`The following props are not supported: ${unsupportedProps.map(prop => `\`${prop}\``).join(', ')}. Please remove them.`);
34
- }
35
- return null;
36
- }
37
- };
38
- }
39
-
40
- const ThemeContext = /*#__PURE__*/React.createContext(null);
41
- if (process.env.NODE_ENV !== 'production') {
42
- ThemeContext.displayName = 'ThemeContext';
43
- }
44
- var ThemeContext$1 = ThemeContext;
45
-
46
- function useTheme() {
47
- const theme = React.useContext(ThemeContext$1);
48
- if (process.env.NODE_ENV !== 'production') {
49
- // TODO: uncomment once we enable eslint-plugin-react-compiler eslint-disable-next-line react-compiler/react-compiler
50
- // eslint-disable-next-line react-hooks/rules-of-hooks -- It's not required to run React.useDebugValue in production
51
- React.useDebugValue(theme);
52
- }
53
- return theme;
54
- }
55
-
56
- const hasSymbol = typeof Symbol === 'function' && Symbol.for;
57
- var nested = hasSymbol ? Symbol.for('mui.nested') : '__THEME_NESTED__';
58
-
59
- function mergeOuterLocalTheme(outerTheme, localTheme) {
60
- if (typeof localTheme === 'function') {
61
- const mergedTheme = localTheme(outerTheme);
62
- if (process.env.NODE_ENV !== 'production') {
63
- if (!mergedTheme) {
64
- console.error(['MUI: You should return an object from your theme function, i.e.', '<ThemeProvider theme={() => ({})} />'].join('\n'));
65
- }
66
- }
67
- return mergedTheme;
68
- }
69
- return {
70
- ...outerTheme,
71
- ...localTheme
72
- };
73
- }
74
-
75
- /**
76
- * This component takes a `theme` prop.
77
- * It makes the `theme` available down the React tree thanks to React context.
78
- * This component should preferably be used at **the root of your component tree**.
79
- */
80
- function ThemeProvider$2(props) {
81
- const {
82
- children,
83
- theme: localTheme
84
- } = props;
85
- const outerTheme = useTheme();
86
- if (process.env.NODE_ENV !== 'production') {
87
- if (outerTheme === null && typeof localTheme === 'function') {
88
- console.error(['MUI: You are providing a theme function prop to the ThemeProvider component:', '<ThemeProvider theme={outerTheme => outerTheme} />', '', 'However, no outer theme is present.', 'Make sure a theme is already injected higher in the React tree ' + 'or provide a theme object.'].join('\n'));
89
- }
90
- }
91
- const theme = React.useMemo(() => {
92
- const output = outerTheme === null ? {
93
- ...localTheme
94
- } : mergeOuterLocalTheme(outerTheme, localTheme);
95
- if (output != null) {
96
- output[nested] = outerTheme !== null;
97
- }
98
- return output;
99
- }, [localTheme, outerTheme]);
100
- return /*#__PURE__*/jsxRuntimeExports.jsx(ThemeContext$1.Provider, {
101
- value: theme,
102
- children: children
103
- });
104
- }
105
- process.env.NODE_ENV !== "production" ? ThemeProvider$2.propTypes = {
106
- /**
107
- * Your component tree.
108
- */
109
- children: PropTypes.node,
110
- /**
111
- * A theme object. You can provide a function to extend the outer theme.
112
- */
113
- theme: PropTypes.oneOfType([PropTypes.object, PropTypes.func]).isRequired
114
- } : void 0;
115
- if (process.env.NODE_ENV !== 'production') {
116
- process.env.NODE_ENV !== "production" ? ThemeProvider$2.propTypes = exactProp$1(ThemeProvider$2.propTypes) : void 0;
117
- }
118
-
119
- // This module is based on https://github.com/airbnb/prop-types-exact repository.
120
- // However, in order to reduce the number of dependencies and to remove some extra safe checks
121
- // the module was forked.
122
-
123
- const specialProperty = 'exact-prop: \u200b';
124
- function exactProp(propTypes) {
125
- if (process.env.NODE_ENV === 'production') {
126
- return propTypes;
127
- }
128
- return {
129
- ...propTypes,
130
- [specialProperty]: props => {
131
- const unsupportedProps = Object.keys(props).filter(prop => !propTypes.hasOwnProperty(prop));
132
- if (unsupportedProps.length > 0) {
133
- return new Error(`The following props are not supported: ${unsupportedProps.map(prop => `\`${prop}\``).join(', ')}. Please remove them.`);
134
- }
135
- return null;
136
- }
137
- };
138
- }
139
-
140
- let globalId = 0;
141
-
142
- // TODO React 17: Remove `useGlobalId` once React 17 support is removed
143
- function useGlobalId(idOverride) {
144
- const [defaultId, setDefaultId] = React.useState(idOverride);
145
- const id = idOverride || defaultId;
146
- React.useEffect(() => {
147
- if (defaultId == null) {
148
- // Fallback to this default id when possible.
149
- // Use the incrementing value for client-side rendering only.
150
- // We can't use it server-side.
151
- // If you want to use random values please consider the Birthday Problem: https://en.wikipedia.org/wiki/Birthday_problem
152
- globalId += 1;
153
- setDefaultId(`mui-${globalId}`);
154
- }
155
- }, [defaultId]);
156
- return id;
157
- }
158
-
159
- // See https://github.com/mui/material-ui/issues/41190#issuecomment-2040873379 for why
160
- const safeReact = {
161
- ...React
162
- };
163
- const maybeReactUseId = safeReact.useId;
164
-
165
- /**
166
- *
167
- * @example <div id={useId()} />
168
- * @param idOverride
169
- * @returns {string}
170
- */
171
- function useId(idOverride) {
172
- // React.useId() is only available from React 17.0.0.
173
- if (maybeReactUseId !== undefined) {
174
- const reactId = maybeReactUseId();
175
- return idOverride ?? reactId;
176
- }
177
-
178
- // TODO: uncomment once we enable eslint-plugin-react-compiler // eslint-disable-next-line react-compiler/react-compiler
179
- // eslint-disable-next-line react-hooks/rules-of-hooks -- `React.useId` is invariant at runtime.
180
- return useGlobalId(idOverride);
181
- }
182
-
183
- function useLayerOrder(theme) {
184
- const upperTheme = useTheme$1();
185
- const id = useId() || '';
186
- const {
187
- modularCssLayers
188
- } = theme;
189
- let layerOrder = 'mui.global, mui.components, mui.theme, mui.custom, mui.sx';
190
- if (!modularCssLayers || upperTheme !== null) {
191
- // skip this hook if upper theme exists.
192
- layerOrder = '';
193
- } else if (typeof modularCssLayers === 'string') {
194
- layerOrder = modularCssLayers.replace(/mui(?!\.)/g, layerOrder);
195
- } else {
196
- layerOrder = `@layer ${layerOrder};`;
197
- }
198
- useEnhancedEffect$1(() => {
199
- const head = document.querySelector('head');
200
- if (!head) {
201
- return;
202
- }
203
- const firstChild = head.firstChild;
204
- if (layerOrder) {
205
- // Only insert if first child doesn't have data-mui-layer-order attribute
206
- if (firstChild && firstChild.hasAttribute?.('data-mui-layer-order') && firstChild.getAttribute('data-mui-layer-order') === id) {
207
- return;
208
- }
209
- const styleElement = document.createElement('style');
210
- styleElement.setAttribute('data-mui-layer-order', id);
211
- styleElement.textContent = layerOrder;
212
- head.prepend(styleElement);
213
- } else {
214
- head.querySelector(`style[data-mui-layer-order="${id}"]`)?.remove();
215
- }
216
- }, [layerOrder, id]);
217
- if (!layerOrder) {
218
- return null;
219
- }
220
- return /*#__PURE__*/jsxRuntimeExports.jsx(GlobalStyles, {
221
- styles: layerOrder
222
- });
223
- }
224
-
225
- const EMPTY_THEME = {};
226
- function useThemeScoping(themeId, upperTheme, localTheme, isPrivate = false) {
227
- return React.useMemo(() => {
228
- const resolvedTheme = themeId ? upperTheme[themeId] || upperTheme : upperTheme;
229
- if (typeof localTheme === 'function') {
230
- const mergedTheme = localTheme(resolvedTheme);
231
- const result = themeId ? {
232
- ...upperTheme,
233
- [themeId]: mergedTheme
234
- } : mergedTheme;
235
- // must return a function for the private theme to NOT merge with the upper theme.
236
- // see the test case "use provided theme from a callback" in ThemeProvider.test.js
237
- if (isPrivate) {
238
- return () => result;
239
- }
240
- return result;
241
- }
242
- return themeId ? {
243
- ...upperTheme,
244
- [themeId]: localTheme
245
- } : {
246
- ...upperTheme,
247
- ...localTheme
248
- };
249
- }, [themeId, upperTheme, localTheme, isPrivate]);
250
- }
251
-
252
- /**
253
- * This component makes the `theme` available down the React tree.
254
- * It should preferably be used at **the root of your component tree**.
255
- *
256
- * <ThemeProvider theme={theme}> // existing use case
257
- * <ThemeProvider theme={{ id: theme }}> // theme scoping
258
- */
259
- function ThemeProvider$1(props) {
260
- const {
261
- children,
262
- theme: localTheme,
263
- themeId
264
- } = props;
265
- const upperTheme = useTheme$1(EMPTY_THEME);
266
- const upperPrivateTheme = useTheme() || EMPTY_THEME;
267
- if (process.env.NODE_ENV !== 'production') {
268
- if (upperTheme === null && typeof localTheme === 'function' || themeId && upperTheme && !upperTheme[themeId] && typeof localTheme === 'function') {
269
- console.error(['MUI: You are providing a theme function prop to the ThemeProvider component:', '<ThemeProvider theme={outerTheme => outerTheme} />', '', 'However, no outer theme is present.', 'Make sure a theme is already injected higher in the React tree ' + 'or provide a theme object.'].join('\n'));
270
- }
271
- }
272
- const engineTheme = useThemeScoping(themeId, upperTheme, localTheme);
273
- const privateTheme = useThemeScoping(themeId, upperPrivateTheme, localTheme, true);
274
- const rtlValue = (themeId ? engineTheme[themeId] : engineTheme).direction === 'rtl';
275
- const layerOrder = useLayerOrder(engineTheme);
276
- return /*#__PURE__*/jsxRuntimeExports.jsx(ThemeProvider$2, {
277
- theme: privateTheme,
278
- children: /*#__PURE__*/jsxRuntimeExports.jsx(ThemeContext$2.Provider, {
279
- value: engineTheme,
280
- children: /*#__PURE__*/jsxRuntimeExports.jsx(RtlProvider, {
281
- value: rtlValue,
282
- children: /*#__PURE__*/jsxRuntimeExports.jsxs(DefaultPropsProvider, {
283
- value: themeId ? engineTheme[themeId].components : engineTheme.components,
284
- children: [layerOrder, children]
285
- })
286
- })
287
- })
288
- });
289
- }
290
- process.env.NODE_ENV !== "production" ? ThemeProvider$1.propTypes /* remove-proptypes */ = {
291
- // ┌────────────────────────────── Warning ──────────────────────────────┐
292
- // │ These PropTypes are generated from the TypeScript type definitions. │
293
- // │ To update them, edit the d.ts file and run `pnpm proptypes`. │
294
- // └─────────────────────────────────────────────────────────────────────┘
295
- /**
296
- * Your component tree.
297
- */
298
- children: PropTypes.node,
299
- /**
300
- * A theme object. You can provide a function to extend the outer theme.
301
- */
302
- theme: PropTypes.oneOfType([PropTypes.func, PropTypes.object]).isRequired,
303
- /**
304
- * The design system's unique id for getting the corresponded theme when there are multiple design systems.
305
- */
306
- themeId: PropTypes.string
307
- } : void 0;
308
- if (process.env.NODE_ENV !== 'production') {
309
- process.env.NODE_ENV !== "production" ? ThemeProvider$1.propTypes = exactProp(ThemeProvider$1.propTypes) : void 0;
310
- }
311
-
312
- /**
313
- * Split this component for RSC import
314
- */
315
- const DEFAULT_MODE_STORAGE_KEY = 'mode';
316
- const DEFAULT_COLOR_SCHEME_STORAGE_KEY = 'color-scheme';
317
- const DEFAULT_ATTRIBUTE = 'data-color-scheme';
318
- function InitColorSchemeScript(options) {
319
- const {
320
- defaultMode = 'system',
321
- defaultLightColorScheme = 'light',
322
- defaultDarkColorScheme = 'dark',
323
- modeStorageKey = DEFAULT_MODE_STORAGE_KEY,
324
- colorSchemeStorageKey = DEFAULT_COLOR_SCHEME_STORAGE_KEY,
325
- attribute: initialAttribute = DEFAULT_ATTRIBUTE,
326
- colorSchemeNode = 'document.documentElement',
327
- nonce
328
- } = options || {};
329
- let setter = '';
330
- let attribute = initialAttribute;
331
- if (initialAttribute === 'class') {
332
- attribute = '.%s';
333
- }
334
- if (initialAttribute === 'data') {
335
- attribute = '[data-%s]';
336
- }
337
- if (attribute.startsWith('.')) {
338
- const selector = attribute.substring(1);
339
- setter += `${colorSchemeNode}.classList.remove('${selector}'.replace('%s', light), '${selector}'.replace('%s', dark));
340
- ${colorSchemeNode}.classList.add('${selector}'.replace('%s', colorScheme));`;
341
- }
342
- const matches = attribute.match(/\[([^\]]+)\]/); // case [data-color-scheme=%s] or [data-color-scheme]
343
- if (matches) {
344
- const [attr, value] = matches[1].split('=');
345
- if (!value) {
346
- setter += `${colorSchemeNode}.removeAttribute('${attr}'.replace('%s', light));
347
- ${colorSchemeNode}.removeAttribute('${attr}'.replace('%s', dark));`;
348
- }
349
- setter += `
350
- ${colorSchemeNode}.setAttribute('${attr}'.replace('%s', colorScheme), ${value ? `${value}.replace('%s', colorScheme)` : '""'});`;
351
- } else {
352
- setter += `${colorSchemeNode}.setAttribute('${attribute}', colorScheme);`;
353
- }
354
- return /*#__PURE__*/jsxRuntimeExports.jsx("script", {
355
- suppressHydrationWarning: true,
356
- nonce: typeof window === 'undefined' ? nonce : ''
357
- // eslint-disable-next-line react/no-danger
358
- ,
359
- dangerouslySetInnerHTML: {
360
- __html: `(function() {
361
- try {
362
- let colorScheme = '';
363
- const mode = localStorage.getItem('${modeStorageKey}') || '${defaultMode}';
364
- const dark = localStorage.getItem('${colorSchemeStorageKey}-dark') || '${defaultDarkColorScheme}';
365
- const light = localStorage.getItem('${colorSchemeStorageKey}-light') || '${defaultLightColorScheme}';
366
- if (mode === 'system') {
367
- // handle system mode
368
- const mql = window.matchMedia('(prefers-color-scheme: dark)');
369
- if (mql.matches) {
370
- colorScheme = dark
371
- } else {
372
- colorScheme = light
373
- }
374
- }
375
- if (mode === 'light') {
376
- colorScheme = light;
377
- }
378
- if (mode === 'dark') {
379
- colorScheme = dark;
380
- }
381
- if (colorScheme) {
382
- ${setter}
383
- }
384
- } catch(e){}})();`
385
- }
386
- }, "mui-color-scheme-init");
387
- }
388
-
389
- function noop$1() {}
390
- const localStorageManager = ({
391
- key,
392
- storageWindow
393
- }) => {
394
- if (!storageWindow && typeof window !== 'undefined') {
395
- storageWindow = window;
396
- }
397
- return {
398
- get(defaultValue) {
399
- if (typeof window === 'undefined') {
400
- return undefined;
401
- }
402
- if (!storageWindow) {
403
- return defaultValue;
404
- }
405
- let value;
406
- try {
407
- value = storageWindow.localStorage.getItem(key);
408
- } catch {
409
- // Unsupported
410
- }
411
- return value || defaultValue;
412
- },
413
- set: value => {
414
- if (storageWindow) {
415
- try {
416
- storageWindow.localStorage.setItem(key, value);
417
- } catch {
418
- // Unsupported
419
- }
420
- }
421
- },
422
- subscribe: handler => {
423
- if (!storageWindow) {
424
- return noop$1;
425
- }
426
- const listener = event => {
427
- const value = event.newValue;
428
- if (event.key === key) {
429
- handler(value);
430
- }
431
- };
432
- storageWindow.addEventListener('storage', listener);
433
- return () => {
434
- storageWindow.removeEventListener('storage', listener);
435
- };
436
- }
437
- };
438
- };
439
- var localStorageManager$1 = localStorageManager;
440
-
441
- function noop() {}
442
- function getSystemMode(mode) {
443
- if (typeof window !== 'undefined' && typeof window.matchMedia === 'function' && mode === 'system') {
444
- const mql = window.matchMedia('(prefers-color-scheme: dark)');
445
- if (mql.matches) {
446
- return 'dark';
447
- }
448
- return 'light';
449
- }
450
- return undefined;
451
- }
452
- function processState(state, callback) {
453
- if (state.mode === 'light' || state.mode === 'system' && state.systemMode === 'light') {
454
- return callback('light');
455
- }
456
- if (state.mode === 'dark' || state.mode === 'system' && state.systemMode === 'dark') {
457
- return callback('dark');
458
- }
459
- return undefined;
460
- }
461
- function getColorScheme(state) {
462
- return processState(state, mode => {
463
- if (mode === 'light') {
464
- return state.lightColorScheme;
465
- }
466
- if (mode === 'dark') {
467
- return state.darkColorScheme;
468
- }
469
- return undefined;
470
- });
471
- }
472
- function useCurrentColorScheme(options) {
473
- const {
474
- defaultMode = 'light',
475
- defaultLightColorScheme,
476
- defaultDarkColorScheme,
477
- supportedColorSchemes = [],
478
- modeStorageKey = DEFAULT_MODE_STORAGE_KEY,
479
- colorSchemeStorageKey = DEFAULT_COLOR_SCHEME_STORAGE_KEY,
480
- storageWindow = typeof window === 'undefined' ? undefined : window,
481
- storageManager = localStorageManager$1,
482
- noSsr = false
483
- } = options;
484
- const joinedColorSchemes = supportedColorSchemes.join(',');
485
- const isMultiSchemes = supportedColorSchemes.length > 1;
486
- const modeStorage = React.useMemo(() => storageManager?.({
487
- key: modeStorageKey,
488
- storageWindow
489
- }), [storageManager, modeStorageKey, storageWindow]);
490
- const lightStorage = React.useMemo(() => storageManager?.({
491
- key: `${colorSchemeStorageKey}-light`,
492
- storageWindow
493
- }), [storageManager, colorSchemeStorageKey, storageWindow]);
494
- const darkStorage = React.useMemo(() => storageManager?.({
495
- key: `${colorSchemeStorageKey}-dark`,
496
- storageWindow
497
- }), [storageManager, colorSchemeStorageKey, storageWindow]);
498
- const [state, setState] = React.useState(() => {
499
- const initialMode = modeStorage?.get(defaultMode) || defaultMode;
500
- const lightColorScheme = lightStorage?.get(defaultLightColorScheme) || defaultLightColorScheme;
501
- const darkColorScheme = darkStorage?.get(defaultDarkColorScheme) || defaultDarkColorScheme;
502
- return {
503
- mode: initialMode,
504
- systemMode: getSystemMode(initialMode),
505
- lightColorScheme,
506
- darkColorScheme
507
- };
508
- });
509
- const [isClient, setIsClient] = React.useState(noSsr || !isMultiSchemes);
510
- React.useEffect(() => {
511
- setIsClient(true); // to rerender the component after hydration
512
- }, []);
513
- const colorScheme = getColorScheme(state);
514
- const setMode = React.useCallback(mode => {
515
- setState(currentState => {
516
- if (mode === currentState.mode) {
517
- // do nothing if mode does not change
518
- return currentState;
519
- }
520
- const newMode = mode ?? defaultMode;
521
- modeStorage?.set(newMode);
522
- return {
523
- ...currentState,
524
- mode: newMode,
525
- systemMode: getSystemMode(newMode)
526
- };
527
- });
528
- }, [modeStorage, defaultMode]);
529
- const setColorScheme = React.useCallback(value => {
530
- if (!value) {
531
- setState(currentState => {
532
- lightStorage?.set(defaultLightColorScheme);
533
- darkStorage?.set(defaultDarkColorScheme);
534
- return {
535
- ...currentState,
536
- lightColorScheme: defaultLightColorScheme,
537
- darkColorScheme: defaultDarkColorScheme
538
- };
539
- });
540
- } else if (typeof value === 'string') {
541
- if (value && !joinedColorSchemes.includes(value)) {
542
- console.error(`\`${value}\` does not exist in \`theme.colorSchemes\`.`);
543
- } else {
544
- setState(currentState => {
545
- const newState = {
546
- ...currentState
547
- };
548
- processState(currentState, mode => {
549
- if (mode === 'light') {
550
- lightStorage?.set(value);
551
- newState.lightColorScheme = value;
552
- }
553
- if (mode === 'dark') {
554
- darkStorage?.set(value);
555
- newState.darkColorScheme = value;
556
- }
557
- });
558
- return newState;
559
- });
560
- }
561
- } else {
562
- setState(currentState => {
563
- const newState = {
564
- ...currentState
565
- };
566
- const newLightColorScheme = value.light === null ? defaultLightColorScheme : value.light;
567
- const newDarkColorScheme = value.dark === null ? defaultDarkColorScheme : value.dark;
568
- if (newLightColorScheme) {
569
- if (!joinedColorSchemes.includes(newLightColorScheme)) {
570
- console.error(`\`${newLightColorScheme}\` does not exist in \`theme.colorSchemes\`.`);
571
- } else {
572
- newState.lightColorScheme = newLightColorScheme;
573
- lightStorage?.set(newLightColorScheme);
574
- }
575
- }
576
- if (newDarkColorScheme) {
577
- if (!joinedColorSchemes.includes(newDarkColorScheme)) {
578
- console.error(`\`${newDarkColorScheme}\` does not exist in \`theme.colorSchemes\`.`);
579
- } else {
580
- newState.darkColorScheme = newDarkColorScheme;
581
- darkStorage?.set(newDarkColorScheme);
582
- }
583
- }
584
- return newState;
585
- });
586
- }
587
- }, [joinedColorSchemes, lightStorage, darkStorage, defaultLightColorScheme, defaultDarkColorScheme]);
588
- const handleMediaQuery = React.useCallback(event => {
589
- if (state.mode === 'system') {
590
- setState(currentState => {
591
- const systemMode = event?.matches ? 'dark' : 'light';
592
-
593
- // Early exit, nothing changed.
594
- if (currentState.systemMode === systemMode) {
595
- return currentState;
596
- }
597
- return {
598
- ...currentState,
599
- systemMode
600
- };
601
- });
602
- }
603
- }, [state.mode]);
604
-
605
- // Ref hack to avoid adding handleMediaQuery as a dep
606
- const mediaListener = React.useRef(handleMediaQuery);
607
- mediaListener.current = handleMediaQuery;
608
- React.useEffect(() => {
609
- if (typeof window.matchMedia !== 'function' || !isMultiSchemes) {
610
- return undefined;
611
- }
612
- const handler = (...args) => mediaListener.current(...args);
613
-
614
- // Always listen to System preference
615
- const media = window.matchMedia('(prefers-color-scheme: dark)');
616
-
617
- // Intentionally use deprecated listener methods to support iOS & old browsers
618
- media.addListener(handler);
619
- handler(media);
620
- return () => {
621
- media.removeListener(handler);
622
- };
623
- }, [isMultiSchemes]);
624
-
625
- // Handle when localStorage has changed
626
- React.useEffect(() => {
627
- if (isMultiSchemes) {
628
- const unsubscribeMode = modeStorage?.subscribe(value => {
629
- if (!value || ['light', 'dark', 'system'].includes(value)) {
630
- setMode(value || defaultMode);
631
- }
632
- }) || noop;
633
- const unsubscribeLight = lightStorage?.subscribe(value => {
634
- if (!value || joinedColorSchemes.match(value)) {
635
- setColorScheme({
636
- light: value
637
- });
638
- }
639
- }) || noop;
640
- const unsubscribeDark = darkStorage?.subscribe(value => {
641
- if (!value || joinedColorSchemes.match(value)) {
642
- setColorScheme({
643
- dark: value
644
- });
645
- }
646
- }) || noop;
647
- return () => {
648
- unsubscribeMode();
649
- unsubscribeLight();
650
- unsubscribeDark();
651
- };
652
- }
653
- return undefined;
654
- }, [setColorScheme, setMode, joinedColorSchemes, defaultMode, storageWindow, isMultiSchemes, modeStorage, lightStorage, darkStorage]);
655
- return {
656
- ...state,
657
- mode: isClient ? state.mode : undefined,
658
- systemMode: isClient ? state.systemMode : undefined,
659
- colorScheme: isClient ? colorScheme : undefined,
660
- setMode,
661
- setColorScheme
662
- };
663
- }
664
-
665
- const DISABLE_CSS_TRANSITION = '*{-webkit-transition:none!important;-moz-transition:none!important;-o-transition:none!important;-ms-transition:none!important;transition:none!important}';
666
- function createCssVarsProvider(options) {
667
- const {
668
- themeId,
669
- /**
670
- * This `theme` object needs to follow a certain structure to
671
- * be used correctly by the finel `CssVarsProvider`. It should have a
672
- * `colorSchemes` key with the light and dark (and any other) palette.
673
- * It should also ideally have a vars object created using `prepareCssVars`.
674
- */
675
- theme: defaultTheme = {},
676
- modeStorageKey: defaultModeStorageKey = DEFAULT_MODE_STORAGE_KEY,
677
- colorSchemeStorageKey: defaultColorSchemeStorageKey = DEFAULT_COLOR_SCHEME_STORAGE_KEY,
678
- disableTransitionOnChange: designSystemTransitionOnChange = false,
679
- defaultColorScheme,
680
- resolveTheme
681
- } = options;
682
- const defaultContext = {
683
- allColorSchemes: [],
684
- colorScheme: undefined,
685
- darkColorScheme: undefined,
686
- lightColorScheme: undefined,
687
- mode: undefined,
688
- setColorScheme: () => {},
689
- setMode: () => {},
690
- systemMode: undefined
691
- };
692
- const ColorSchemeContext = /*#__PURE__*/React.createContext(undefined);
693
- if (process.env.NODE_ENV !== 'production') {
694
- ColorSchemeContext.displayName = 'ColorSchemeContext';
695
- }
696
- const useColorScheme = () => React.useContext(ColorSchemeContext) || defaultContext;
697
- const defaultColorSchemes = {};
698
- const defaultComponents = {};
699
- function CssVarsProvider(props) {
700
- const {
701
- children,
702
- theme: themeProp,
703
- modeStorageKey = defaultModeStorageKey,
704
- colorSchemeStorageKey = defaultColorSchemeStorageKey,
705
- disableTransitionOnChange = designSystemTransitionOnChange,
706
- storageManager,
707
- storageWindow = typeof window === 'undefined' ? undefined : window,
708
- documentNode = typeof document === 'undefined' ? undefined : document,
709
- colorSchemeNode = typeof document === 'undefined' ? undefined : document.documentElement,
710
- disableNestedContext = false,
711
- disableStyleSheetGeneration = false,
712
- defaultMode: initialMode = 'system',
713
- noSsr
714
- } = props;
715
- const hasMounted = React.useRef(false);
716
- const upperTheme = useTheme();
717
- const ctx = React.useContext(ColorSchemeContext);
718
- const nested = !!ctx && !disableNestedContext;
719
- const initialTheme = React.useMemo(() => {
720
- if (themeProp) {
721
- return themeProp;
722
- }
723
- return typeof defaultTheme === 'function' ? defaultTheme() : defaultTheme;
724
- }, [themeProp]);
725
- const scopedTheme = initialTheme[themeId];
726
- const restThemeProp = scopedTheme || initialTheme;
727
- const {
728
- colorSchemes = defaultColorSchemes,
729
- components = defaultComponents,
730
- cssVarPrefix
731
- } = restThemeProp;
732
- const joinedColorSchemes = Object.keys(colorSchemes).filter(k => !!colorSchemes[k]).join(',');
733
- const allColorSchemes = React.useMemo(() => joinedColorSchemes.split(','), [joinedColorSchemes]);
734
- const defaultLightColorScheme = typeof defaultColorScheme === 'string' ? defaultColorScheme : defaultColorScheme.light;
735
- const defaultDarkColorScheme = typeof defaultColorScheme === 'string' ? defaultColorScheme : defaultColorScheme.dark;
736
- const defaultMode = colorSchemes[defaultLightColorScheme] && colorSchemes[defaultDarkColorScheme] ? initialMode : colorSchemes[restThemeProp.defaultColorScheme]?.palette?.mode || restThemeProp.palette?.mode;
737
-
738
- // 1. Get the data about the `mode`, `colorScheme`, and setter functions.
739
- const {
740
- mode: stateMode,
741
- setMode,
742
- systemMode,
743
- lightColorScheme,
744
- darkColorScheme,
745
- colorScheme: stateColorScheme,
746
- setColorScheme
747
- } = useCurrentColorScheme({
748
- supportedColorSchemes: allColorSchemes,
749
- defaultLightColorScheme,
750
- defaultDarkColorScheme,
751
- modeStorageKey,
752
- colorSchemeStorageKey,
753
- defaultMode,
754
- storageManager,
755
- storageWindow,
756
- noSsr
757
- });
758
- let mode = stateMode;
759
- let colorScheme = stateColorScheme;
760
- if (nested) {
761
- mode = ctx.mode;
762
- colorScheme = ctx.colorScheme;
763
- }
764
- const memoTheme = React.useMemo(() => {
765
- // `colorScheme` is undefined on the server and hydration phase
766
- const calculatedColorScheme = colorScheme || restThemeProp.defaultColorScheme;
767
-
768
- // 2. get the `vars` object that refers to the CSS custom properties
769
- const themeVars = restThemeProp.generateThemeVars?.() || restThemeProp.vars;
770
-
771
- // 3. Start composing the theme object
772
- const theme = {
773
- ...restThemeProp,
774
- components,
775
- colorSchemes,
776
- cssVarPrefix,
777
- vars: themeVars
778
- };
779
- if (typeof theme.generateSpacing === 'function') {
780
- theme.spacing = theme.generateSpacing();
781
- }
782
-
783
- // 4. Resolve the color scheme and merge it to the theme
784
- if (calculatedColorScheme) {
785
- const scheme = colorSchemes[calculatedColorScheme];
786
- if (scheme && typeof scheme === 'object') {
787
- // 4.1 Merge the selected color scheme to the theme
788
- Object.keys(scheme).forEach(schemeKey => {
789
- if (scheme[schemeKey] && typeof scheme[schemeKey] === 'object') {
790
- // shallow merge the 1st level structure of the theme.
791
- theme[schemeKey] = {
792
- ...theme[schemeKey],
793
- ...scheme[schemeKey]
794
- };
795
- } else {
796
- theme[schemeKey] = scheme[schemeKey];
797
- }
798
- });
799
- }
800
- }
801
- return resolveTheme ? resolveTheme(theme) : theme;
802
- }, [restThemeProp, colorScheme, components, colorSchemes, cssVarPrefix]);
803
-
804
- // 5. Declaring effects
805
- // 5.1 Updates the selector value to use the current color scheme which tells CSS to use the proper stylesheet.
806
- const colorSchemeSelector = restThemeProp.colorSchemeSelector;
807
- useEnhancedEffect$1(() => {
808
- if (colorScheme && colorSchemeNode && colorSchemeSelector && colorSchemeSelector !== 'media') {
809
- const selector = colorSchemeSelector;
810
- let rule = colorSchemeSelector;
811
- if (selector === 'class') {
812
- rule = `.%s`;
813
- }
814
- if (selector === 'data') {
815
- rule = `[data-%s]`;
816
- }
817
- if (selector?.startsWith('data-') && !selector.includes('%s')) {
818
- // 'data-mui-color-scheme' -> '[data-mui-color-scheme="%s"]'
819
- rule = `[${selector}="%s"]`;
820
- }
821
- if (rule.startsWith('.')) {
822
- colorSchemeNode.classList.remove(...allColorSchemes.map(scheme => rule.substring(1).replace('%s', scheme)));
823
- colorSchemeNode.classList.add(rule.substring(1).replace('%s', colorScheme));
824
- } else {
825
- const matches = rule.replace('%s', colorScheme).match(/\[([^\]]+)\]/);
826
- if (matches) {
827
- const [attr, value] = matches[1].split('=');
828
- if (!value) {
829
- // for attributes like `data-theme-dark`, `data-theme-light`
830
- // remove all the existing data attributes before setting the new one
831
- allColorSchemes.forEach(scheme => {
832
- colorSchemeNode.removeAttribute(attr.replace(colorScheme, scheme));
833
- });
834
- }
835
- colorSchemeNode.setAttribute(attr, value ? value.replace(/"|'/g, '') : '');
836
- } else {
837
- colorSchemeNode.setAttribute(rule, colorScheme);
838
- }
839
- }
840
- }
841
- }, [colorScheme, colorSchemeSelector, colorSchemeNode, allColorSchemes]);
842
-
843
- // 5.2 Remove the CSS transition when color scheme changes to create instant experience.
844
- // credit: https://github.com/pacocoursey/next-themes/blob/b5c2bad50de2d61ad7b52a9c5cdc801a78507d7a/index.tsx#L313
845
- React.useEffect(() => {
846
- let timer;
847
- if (disableTransitionOnChange && hasMounted.current && documentNode) {
848
- const css = documentNode.createElement('style');
849
- css.appendChild(documentNode.createTextNode(DISABLE_CSS_TRANSITION));
850
- documentNode.head.appendChild(css);
851
-
852
- // Force browser repaint
853
- (() => window.getComputedStyle(documentNode.body))();
854
- timer = setTimeout(() => {
855
- documentNode.head.removeChild(css);
856
- }, 1);
857
- }
858
- return () => {
859
- clearTimeout(timer);
860
- };
861
- }, [colorScheme, disableTransitionOnChange, documentNode]);
862
- React.useEffect(() => {
863
- hasMounted.current = true;
864
- return () => {
865
- hasMounted.current = false;
866
- };
867
- }, []);
868
- const contextValue = React.useMemo(() => ({
869
- allColorSchemes,
870
- colorScheme,
871
- darkColorScheme,
872
- lightColorScheme,
873
- mode,
874
- setColorScheme,
875
- setMode: process.env.NODE_ENV === 'production' ? setMode : newMode => {
876
- if (memoTheme.colorSchemeSelector === 'media') {
877
- console.error(['MUI: The `setMode` function has no effect if `colorSchemeSelector` is `media` (`media` is the default value).', 'To toggle the mode manually, please configure `colorSchemeSelector` to use a class or data attribute.', 'To learn more, visit https://mui.com/material-ui/customization/css-theme-variables/configuration/#toggling-dark-mode-manually'].join('\n'));
878
- }
879
- setMode(newMode);
880
- },
881
- systemMode
882
- }), [allColorSchemes, colorScheme, darkColorScheme, lightColorScheme, mode, setColorScheme, setMode, systemMode, memoTheme.colorSchemeSelector]);
883
- let shouldGenerateStyleSheet = true;
884
- if (disableStyleSheetGeneration || restThemeProp.cssVariables === false || nested && upperTheme?.cssVarPrefix === cssVarPrefix) {
885
- shouldGenerateStyleSheet = false;
886
- }
887
- const element = /*#__PURE__*/jsxRuntimeExports.jsxs(React.Fragment, {
888
- children: [/*#__PURE__*/jsxRuntimeExports.jsx(ThemeProvider$1, {
889
- themeId: scopedTheme ? themeId : undefined,
890
- theme: memoTheme,
891
- children: children
892
- }), shouldGenerateStyleSheet && /*#__PURE__*/jsxRuntimeExports.jsx(GlobalStyles$1, {
893
- styles: memoTheme.generateStyleSheets?.() || []
894
- })]
895
- });
896
- if (nested) {
897
- return element;
898
- }
899
- return /*#__PURE__*/jsxRuntimeExports.jsx(ColorSchemeContext.Provider, {
900
- value: contextValue,
901
- children: element
902
- });
903
- }
904
- process.env.NODE_ENV !== "production" ? CssVarsProvider.propTypes = {
905
- /**
906
- * The component tree.
907
- */
908
- children: PropTypes.node,
909
- /**
910
- * The node used to attach the color-scheme attribute
911
- */
912
- colorSchemeNode: PropTypes.any,
913
- /**
914
- * localStorage key used to store `colorScheme`
915
- */
916
- colorSchemeStorageKey: PropTypes.string,
917
- /**
918
- * The default mode when the storage is empty,
919
- * require the theme to have `colorSchemes` with light and dark.
920
- */
921
- defaultMode: PropTypes.string,
922
- /**
923
- * If `true`, the provider creates its own context and generate stylesheet as if it is a root `CssVarsProvider`.
924
- */
925
- disableNestedContext: PropTypes.bool,
926
- /**
927
- * If `true`, the style sheet won't be generated.
928
- *
929
- * This is useful for controlling nested CssVarsProvider behavior.
930
- */
931
- disableStyleSheetGeneration: PropTypes.bool,
932
- /**
933
- * Disable CSS transitions when switching between modes or color schemes.
934
- */
935
- disableTransitionOnChange: PropTypes.bool,
936
- /**
937
- * The document to attach the attribute to.
938
- */
939
- documentNode: PropTypes.any,
940
- /**
941
- * The key in the local storage used to store current color scheme.
942
- */
943
- modeStorageKey: PropTypes.string,
944
- /**
945
- * If `true`, the mode will be the same value as the storage without an extra rerendering after the hydration.
946
- * You should use this option in conjuction with `InitColorSchemeScript` component.
947
- */
948
- noSsr: PropTypes.bool,
949
- /**
950
- * The storage manager to be used for storing the mode and color scheme
951
- * @default using `window.localStorage`
952
- */
953
- storageManager: PropTypes.func,
954
- /**
955
- * The window that attaches the 'storage' event listener.
956
- * @default window
957
- */
958
- storageWindow: PropTypes.any,
959
- /**
960
- * The calculated theme object that will be passed through context.
961
- */
962
- theme: PropTypes.object
963
- } : void 0;
964
- const defaultLightColorScheme = typeof defaultColorScheme === 'string' ? defaultColorScheme : defaultColorScheme.light;
965
- const defaultDarkColorScheme = typeof defaultColorScheme === 'string' ? defaultColorScheme : defaultColorScheme.dark;
966
- const getInitColorSchemeScript = params => InitColorSchemeScript({
967
- colorSchemeStorageKey: defaultColorSchemeStorageKey,
968
- defaultLightColorScheme,
969
- defaultDarkColorScheme,
970
- modeStorageKey: defaultModeStorageKey,
971
- ...params
972
- });
973
- return {
974
- CssVarsProvider,
975
- useColorScheme,
976
- getInitColorSchemeScript
977
- };
978
- }
979
-
980
- function ThemeProviderNoVars({
981
- theme: themeInput,
982
- ...props
983
- }) {
984
- const scopedTheme = THEME_ID in themeInput ? themeInput[THEME_ID] : undefined;
985
- return /*#__PURE__*/jsxRuntimeExports.jsx(ThemeProvider$1, {
986
- ...props,
987
- themeId: scopedTheme ? THEME_ID : undefined,
988
- theme: scopedTheme || themeInput
989
- });
990
- }
991
-
992
- const defaultConfig = {
993
- attribute: 'data-mui-color-scheme',
994
- colorSchemeStorageKey: 'mui-color-scheme',
995
- defaultLightColorScheme: 'light',
996
- defaultDarkColorScheme: 'dark',
997
- modeStorageKey: 'mui-mode'
998
- };
999
-
1000
- const {
1001
- CssVarsProvider: InternalCssVarsProvider,
1002
- useColorScheme,
1003
- getInitColorSchemeScript: deprecatedGetInitColorSchemeScript
1004
- } = createCssVarsProvider({
1005
- themeId: THEME_ID,
1006
- // @ts-ignore ignore module augmentation tests
1007
- theme: () => createTheme({
1008
- cssVariables: true
1009
- }),
1010
- colorSchemeStorageKey: defaultConfig.colorSchemeStorageKey,
1011
- modeStorageKey: defaultConfig.modeStorageKey,
1012
- defaultColorScheme: {
1013
- light: defaultConfig.defaultLightColorScheme,
1014
- dark: defaultConfig.defaultDarkColorScheme
1015
- },
1016
- resolveTheme: theme => {
1017
- const newTheme = {
1018
- ...theme,
1019
- typography: createTypography(theme.palette, theme.typography)
1020
- };
1021
- newTheme.unstable_sx = function sx(props) {
1022
- return styleFunctionSx({
1023
- sx: props,
1024
- theme: this
1025
- });
1026
- };
1027
- return newTheme;
1028
- }
1029
- });
1030
-
1031
- /**
1032
- * TODO: remove this export in v7
1033
- * @deprecated
1034
- * The `CssVarsProvider` component has been deprecated and ported into `ThemeProvider`.
1035
- *
1036
- * You should use `ThemeProvider` and `createTheme()` instead:
1037
- *
1038
- * ```diff
1039
- * - import { CssVarsProvider, extendTheme } from '@mui/material/styles';
1040
- * + import { ThemeProvider, createTheme } from '@mui/material/styles';
1041
- *
1042
- * - const theme = extendTheme();
1043
- * + const theme = createTheme({
1044
- * + cssVariables: true,
1045
- * + colorSchemes: { light: true, dark: true },
1046
- * + });
1047
- *
1048
- * - <CssVarsProvider theme={theme}>
1049
- * + <ThemeProvider theme={theme}>
1050
- * ```
1051
- *
1052
- * To see the full documentation, check out https://mui.com/material-ui/customization/css-theme-variables/usage/.
1053
- */
1054
- const CssVarsProvider = InternalCssVarsProvider;
1055
-
1056
- function ThemeProvider({
1057
- theme,
1058
- ...props
1059
- }) {
1060
- const noVarsTheme = React.useMemo(() => {
1061
- if (typeof theme === 'function') {
1062
- return theme;
1063
- }
1064
- const muiTheme = THEME_ID in theme ? theme[THEME_ID] : theme;
1065
- if (!('colorSchemes' in muiTheme)) {
1066
- if (!('vars' in muiTheme)) {
1067
- // For non-CSS variables themes, set `vars` to null to prevent theme inheritance from the upper theme.
1068
- // The example use case is the docs demo that uses ThemeProvider to customize the theme while the upper theme is using CSS variables.
1069
- return {
1070
- ...theme,
1071
- vars: null
1072
- };
1073
- }
1074
- return theme;
1075
- }
1076
- return null;
1077
- }, [theme]);
1078
- if (noVarsTheme) {
1079
- return /*#__PURE__*/jsxRuntimeExports.jsx(ThemeProviderNoVars, {
1080
- theme: noVarsTheme,
1081
- ...props
1082
- });
1083
- }
1084
- return /*#__PURE__*/jsxRuntimeExports.jsx(CssVarsProvider, {
1085
- theme: theme,
1086
- ...props
1087
- });
1088
- }
1089
-
1090
- /* eslint-disable */
1091
- /**
1092
- * https://github.com/zloirock/core-js/issues/86#issuecomment-115759028
1093
- * @deprecated Use `globalThis` instead.
1094
- */
1095
- var ponyfillGlobal = typeof window != 'undefined' && window.Math == Math ? window : typeof self != 'undefined' && self.Math == Math ? self : Function('return this')();
1096
-
1097
- /**
1098
- * @ignore - do not document.
1099
- */
1100
-
1101
- // Store the license information in a global, so it can be shared
1102
- // when module duplication occurs. The duplication of the modules can happen
1103
- // if using multiple version of MUI X at the same time of the bundler
1104
- // decide to duplicate to improve the size of the chunks.
1105
- // eslint-disable-next-line no-underscore-dangle
1106
- ponyfillGlobal.__MUI_LICENSE_INFO__ = ponyfillGlobal.__MUI_LICENSE_INFO__ || {
1107
- key: undefined
1108
- };
1109
- class LicenseInfo {
1110
- static getLicenseInfo() {
1111
- // eslint-disable-next-line no-underscore-dangle
1112
- return ponyfillGlobal.__MUI_LICENSE_INFO__;
1113
- }
1114
- static getLicenseKey() {
1115
- return LicenseInfo.getLicenseInfo().key;
1116
- }
1117
- static setLicenseKey(key) {
1118
- const licenseInfo = LicenseInfo.getLicenseInfo();
1119
- licenseInfo.key = key;
1120
- }
1121
- }
2
+ import { useState, useEffect } from 'react';
1122
3
 
1123
4
  /**
1124
5
  * Component style.
@@ -1206,15 +87,15 @@ const useControlledDatagridState = _ref => {
1206
87
  propsPinnedColumns,
1207
88
  propsSortModel
1208
89
  } = _ref;
90
+ // Internal state is a fallback for uncontrolled usage only.
1209
91
  const [internalFilterModel, setInternalFilterModel] = useState(propsFilterModel);
1210
92
  useEffect(() => {
1211
93
  setInternalFilterModel(propsFilterModel);
1212
94
  }, [propsFilterModel]);
1213
95
 
1214
- // When the parent passes a filterModel prop (controlled mode), use it
1215
- // directly so the DataGrid sees it on the same render not one frame later
1216
- // via the useEffect above.
1217
- const filterModel = propsFilterModel !== undefined ? propsFilterModel : internalFilterModel;
96
+ // In controlled mode (propsFilterModel provided), use it directly to avoid
97
+ // a one-frame delay from the useState + useEffect buffer.
98
+ const filterModel = propsFilterModel !== null && propsFilterModel !== void 0 ? propsFilterModel : internalFilterModel;
1218
99
  const onFilterModelChange = (model, details) => {
1219
100
  if (propsOnFilterModelChange) {
1220
101
  propsOnFilterModelChange(model, details);
@@ -1285,5 +166,5 @@ const useControlledDatagridState = _ref => {
1285
166
  };
1286
167
  };
1287
168
 
1288
- export { LicenseInfo as L, StyledDataGrid as S, ThemeProvider as T, useControlledDatagridState as u };
169
+ export { StyledDataGrid as S, useControlledDatagridState as u };
1289
170
  //# sourceMappingURL=useControlledDatagridState.js.map