@redsift/table 12.5.5 → 12.5.6-muiv7

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