@redsift/table 11.5.0-muiv5 → 11.6.0-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.
Files changed (46) hide show
  1. package/_internal/BaseComponents.js +3 -0
  2. package/_internal/BaseComponents.js.map +1 -0
  3. package/_internal/BasePopper.js +2448 -0
  4. package/_internal/BasePopper.js.map +1 -0
  5. package/_internal/BaseTextField.js +26 -0
  6. package/_internal/BaseTextField.js.map +1 -0
  7. package/_internal/ControlledPagination.js +10492 -0
  8. package/_internal/ControlledPagination.js.map +1 -0
  9. package/_internal/DataGrid.js +2 -0
  10. package/_internal/DataGrid.js.map +1 -0
  11. package/_internal/DataGrid2.js +316 -0
  12. package/_internal/DataGrid2.js.map +1 -0
  13. package/_internal/GridToolbarFilterSemanticField.js +2 -0
  14. package/_internal/GridToolbarFilterSemanticField.js.map +1 -0
  15. package/_internal/GridToolbarFilterSemanticField2.js +5581 -0
  16. package/_internal/GridToolbarFilterSemanticField2.js.map +1 -0
  17. package/_internal/Pagination.js +2 -0
  18. package/_internal/Pagination.js.map +1 -0
  19. package/_internal/Portal.js +4363 -0
  20. package/_internal/Portal.js.map +1 -0
  21. package/_internal/StatefulDataGrid.js +2 -0
  22. package/_internal/StatefulDataGrid.js.map +1 -0
  23. package/_internal/StatefulDataGrid2.js +3088 -0
  24. package/_internal/StatefulDataGrid2.js.map +1 -0
  25. package/_internal/TextCell.js +2 -0
  26. package/_internal/TextCell.js.map +1 -0
  27. package/_internal/TextCell2.js +66 -0
  28. package/_internal/TextCell2.js.map +1 -0
  29. package/_internal/Toolbar.js +2 -0
  30. package/_internal/Toolbar.js.map +1 -0
  31. package/_internal/Toolbar2.js +85 -0
  32. package/_internal/Toolbar2.js.map +1 -0
  33. package/_internal/ToolbarWrapper.js +2 -0
  34. package/_internal/ToolbarWrapper.js.map +1 -0
  35. package/_internal/ToolbarWrapper2.js +53 -0
  36. package/_internal/ToolbarWrapper2.js.map +1 -0
  37. package/_internal/_rollupPluginBabelHelpers.js +93 -0
  38. package/_internal/_rollupPluginBabelHelpers.js.map +1 -0
  39. package/_internal/jsx-runtime.js +1342 -0
  40. package/_internal/jsx-runtime.js.map +1 -0
  41. package/_internal/useControlledDatagridState.js +368 -0
  42. package/_internal/useControlledDatagridState.js.map +1 -0
  43. package/index.d.ts +54 -54
  44. package/index.js +37 -28350
  45. package/index.js.map +1 -1
  46. package/package.json +6 -6
@@ -0,0 +1,3088 @@
1
+ import { _ as _objectSpread2, a as _objectWithoutProperties, b as _extends$1 } from './_rollupPluginBabelHelpers.js';
2
+ import * as React from 'react';
3
+ import React__default, { useCallback, useEffect, useMemo, forwardRef, useRef, useState } from 'react';
4
+ import classNames from 'classnames';
5
+ import { Icon, useTheme as useTheme$1, ThemeProvider, RedsiftColorBlueN, RedsiftColorNeutralXDarkGrey, RedsiftColorNeutralWhite } from '@redsift/design-system';
6
+ import { getGridNumericOperators as getGridNumericOperators$1, GridFilterInputValue, GridFilterInputSingleSelect, GridFilterInputMultipleValue, GridFilterInputMultipleSingleSelect, getGridStringOperators as getGridStringOperators$1, getGridBooleanOperators, getGridDateOperators, getGridSingleSelectOperators, GridLogicOperator, useGridApiRef, DataGridPro, gridPaginatedVisibleSortedGridRowEntriesSelector, gridPaginatedVisibleSortedGridRowIdsSelector, gridFilteredSortedRowEntriesSelector, gridFilteredSortedRowIdsSelector } from '@mui/x-data-grid-pro';
7
+ import { L as LicenseInfo, u as useControlledDatagridState, T as ThemeProvider$1, S as StyledDataGrid } from './useControlledDatagridState.js';
8
+ import { mdiSync } from '@redsift/icons';
9
+ import { _ as _objectWithoutPropertiesLoose, a as _extends, d as defaultSxConfig, i as isPlainObject, s as styled, b as styleFunctionSx, u as useTheme, c as clsx, e as createTheme, T as THEME_ID, C as ClassNameGenerator, P as PropTypes, g as generateUtilityClasses, f as generateUtilityClass, h as styled$1, j as useThemeProps, k as capitalize, l as composeClasses, r as rootShouldForwardProp, m as refType } from './Portal.js';
10
+ import { j as jsxRuntimeExports } from './jsx-runtime.js';
11
+ import { u as useFormControl, f as formControlState, i as isAdornedStart, a as isFilled, F as FormControlContext, b as useId, c as Select, I as Input, d as FilledInput, O as OutlinedInput, o as onServerSideSelectionStatusChange, S as ServerSideControlledPagination, C as ControlledPagination } from './ControlledPagination.js';
12
+ import { T as Toolbar } from './Toolbar2.js';
13
+ import { B as BaseButton, a as BaseCheckbox, c as BasePopper, b as BaseIcon } from './BasePopper.js';
14
+ import { T as ToolbarWrapper } from './ToolbarWrapper2.js';
15
+
16
+ function isMuiElement(element, muiNames) {
17
+ return /*#__PURE__*/React.isValidElement(element) && muiNames.indexOf(element.type.muiName) !== -1;
18
+ }
19
+
20
+ const _excluded$7 = ["sx"];
21
+ const splitProps = props => {
22
+ var _props$theme$unstable, _props$theme;
23
+ const result = {
24
+ systemProps: {},
25
+ otherProps: {}
26
+ };
27
+ const config = (_props$theme$unstable = props == null ? void 0 : (_props$theme = props.theme) == null ? void 0 : _props$theme.unstable_sxConfig) != null ? _props$theme$unstable : defaultSxConfig;
28
+ Object.keys(props).forEach(prop => {
29
+ if (config[prop]) {
30
+ result.systemProps[prop] = props[prop];
31
+ } else {
32
+ result.otherProps[prop] = props[prop];
33
+ }
34
+ });
35
+ return result;
36
+ };
37
+ function extendSxProp(props) {
38
+ const {
39
+ sx: inSx
40
+ } = props,
41
+ other = _objectWithoutPropertiesLoose(props, _excluded$7);
42
+ const {
43
+ systemProps,
44
+ otherProps
45
+ } = splitProps(other);
46
+ let finalSx;
47
+ if (Array.isArray(inSx)) {
48
+ finalSx = [systemProps, ...inSx];
49
+ } else if (typeof inSx === 'function') {
50
+ finalSx = (...args) => {
51
+ const result = inSx(...args);
52
+ if (!isPlainObject(result)) {
53
+ return systemProps;
54
+ }
55
+ return _extends({}, systemProps, result);
56
+ };
57
+ } else {
58
+ finalSx = _extends({}, systemProps, inSx);
59
+ }
60
+ return _extends({}, otherProps, {
61
+ sx: finalSx
62
+ });
63
+ }
64
+
65
+ const _excluded$6 = ["className", "component"];
66
+ function createBox(options = {}) {
67
+ const {
68
+ themeId,
69
+ defaultTheme,
70
+ defaultClassName = 'MuiBox-root',
71
+ generateClassName
72
+ } = options;
73
+ const BoxRoot = styled('div', {
74
+ shouldForwardProp: prop => prop !== 'theme' && prop !== 'sx' && prop !== 'as'
75
+ })(styleFunctionSx);
76
+ const Box = /*#__PURE__*/React.forwardRef(function Box(inProps, ref) {
77
+ const theme = useTheme(defaultTheme);
78
+ const _extendSxProp = extendSxProp(inProps),
79
+ {
80
+ className,
81
+ component = 'div'
82
+ } = _extendSxProp,
83
+ other = _objectWithoutPropertiesLoose(_extendSxProp, _excluded$6);
84
+ return /*#__PURE__*/jsxRuntimeExports.jsx(BoxRoot, _extends({
85
+ as: component,
86
+ ref: ref,
87
+ className: clsx(className, generateClassName ? generateClassName(defaultClassName) : defaultClassName),
88
+ theme: themeId ? theme[themeId] || theme : theme
89
+ }, other));
90
+ });
91
+ return Box;
92
+ }
93
+
94
+ const defaultTheme = createTheme();
95
+ const Box = createBox({
96
+ themeId: THEME_ID,
97
+ defaultTheme,
98
+ defaultClassName: 'MuiBox-root',
99
+ generateClassName: ClassNameGenerator.generate
100
+ });
101
+ process.env.NODE_ENV !== "production" ? Box.propTypes /* remove-proptypes */ = {
102
+ // ----------------------------- Warning --------------------------------
103
+ // | These PropTypes are generated from the TypeScript type definitions |
104
+ // | To update them edit the d.ts file and run "yarn proptypes" |
105
+ // ----------------------------------------------------------------------
106
+ /**
107
+ * @ignore
108
+ */
109
+ children: PropTypes.node,
110
+ /**
111
+ * The component used for the root node.
112
+ * Either a string to use a HTML element or a component.
113
+ */
114
+ component: PropTypes.elementType,
115
+ /**
116
+ * The system prop that allows defining system overrides as well as additional CSS styles.
117
+ */
118
+ sx: PropTypes.oneOfType([PropTypes.arrayOf(PropTypes.oneOfType([PropTypes.func, PropTypes.object, PropTypes.bool])), PropTypes.func, PropTypes.object])
119
+ } : void 0;
120
+ var Box$1 = Box;
121
+
122
+ function getFormLabelUtilityClasses(slot) {
123
+ return generateUtilityClass('MuiFormLabel', slot);
124
+ }
125
+ const formLabelClasses = generateUtilityClasses('MuiFormLabel', ['root', 'colorSecondary', 'focused', 'disabled', 'error', 'filled', 'required', 'asterisk']);
126
+ var formLabelClasses$1 = formLabelClasses;
127
+
128
+ const _excluded$5 = ["children", "className", "color", "component", "disabled", "error", "filled", "focused", "required"];
129
+ const useUtilityClasses$4 = ownerState => {
130
+ const {
131
+ classes,
132
+ color,
133
+ focused,
134
+ disabled,
135
+ error,
136
+ filled,
137
+ required
138
+ } = ownerState;
139
+ const slots = {
140
+ root: ['root', `color${capitalize(color)}`, disabled && 'disabled', error && 'error', filled && 'filled', focused && 'focused', required && 'required'],
141
+ asterisk: ['asterisk', error && 'error']
142
+ };
143
+ return composeClasses(slots, getFormLabelUtilityClasses, classes);
144
+ };
145
+ const FormLabelRoot = styled$1('label', {
146
+ name: 'MuiFormLabel',
147
+ slot: 'Root',
148
+ overridesResolver: ({
149
+ ownerState
150
+ }, styles) => {
151
+ return _extends({}, styles.root, ownerState.color === 'secondary' && styles.colorSecondary, ownerState.filled && styles.filled);
152
+ }
153
+ })(({
154
+ theme,
155
+ ownerState
156
+ }) => _extends({
157
+ color: (theme.vars || theme).palette.text.secondary
158
+ }, theme.typography.body1, {
159
+ lineHeight: '1.4375em',
160
+ padding: 0,
161
+ position: 'relative',
162
+ [`&.${formLabelClasses$1.focused}`]: {
163
+ color: (theme.vars || theme).palette[ownerState.color].main
164
+ },
165
+ [`&.${formLabelClasses$1.disabled}`]: {
166
+ color: (theme.vars || theme).palette.text.disabled
167
+ },
168
+ [`&.${formLabelClasses$1.error}`]: {
169
+ color: (theme.vars || theme).palette.error.main
170
+ }
171
+ }));
172
+ const AsteriskComponent = styled$1('span', {
173
+ name: 'MuiFormLabel',
174
+ slot: 'Asterisk',
175
+ overridesResolver: (props, styles) => styles.asterisk
176
+ })(({
177
+ theme
178
+ }) => ({
179
+ [`&.${formLabelClasses$1.error}`]: {
180
+ color: (theme.vars || theme).palette.error.main
181
+ }
182
+ }));
183
+ const FormLabel = /*#__PURE__*/React.forwardRef(function FormLabel(inProps, ref) {
184
+ const props = useThemeProps({
185
+ props: inProps,
186
+ name: 'MuiFormLabel'
187
+ });
188
+ const {
189
+ children,
190
+ className,
191
+ component = 'label'
192
+ } = props,
193
+ other = _objectWithoutPropertiesLoose(props, _excluded$5);
194
+ const muiFormControl = useFormControl();
195
+ const fcs = formControlState({
196
+ props,
197
+ muiFormControl,
198
+ states: ['color', 'required', 'focused', 'disabled', 'error', 'filled']
199
+ });
200
+ const ownerState = _extends({}, props, {
201
+ color: fcs.color || 'primary',
202
+ component,
203
+ disabled: fcs.disabled,
204
+ error: fcs.error,
205
+ filled: fcs.filled,
206
+ focused: fcs.focused,
207
+ required: fcs.required
208
+ });
209
+ const classes = useUtilityClasses$4(ownerState);
210
+ return /*#__PURE__*/jsxRuntimeExports.jsxs(FormLabelRoot, _extends({
211
+ as: component,
212
+ ownerState: ownerState,
213
+ className: clsx(classes.root, className),
214
+ ref: ref
215
+ }, other, {
216
+ children: [children, fcs.required && /*#__PURE__*/jsxRuntimeExports.jsxs(AsteriskComponent, {
217
+ ownerState: ownerState,
218
+ "aria-hidden": true,
219
+ className: classes.asterisk,
220
+ children: ["\u2009", '*']
221
+ })]
222
+ }));
223
+ });
224
+ process.env.NODE_ENV !== "production" ? FormLabel.propTypes /* remove-proptypes */ = {
225
+ // ----------------------------- Warning --------------------------------
226
+ // | These PropTypes are generated from the TypeScript type definitions |
227
+ // | To update them edit the d.ts file and run "yarn proptypes" |
228
+ // ----------------------------------------------------------------------
229
+ /**
230
+ * The content of the component.
231
+ */
232
+ children: PropTypes.node,
233
+ /**
234
+ * Override or extend the styles applied to the component.
235
+ */
236
+ classes: PropTypes.object,
237
+ /**
238
+ * @ignore
239
+ */
240
+ className: PropTypes.string,
241
+ /**
242
+ * The color of the component.
243
+ * It supports both default and custom theme colors, which can be added as shown in the
244
+ * [palette customization guide](https://mui.com/material-ui/customization/palette/#adding-new-colors).
245
+ */
246
+ color: PropTypes /* @typescript-to-proptypes-ignore */.oneOfType([PropTypes.oneOf(['error', 'info', 'primary', 'secondary', 'success', 'warning']), PropTypes.string]),
247
+ /**
248
+ * The component used for the root node.
249
+ * Either a string to use a HTML element or a component.
250
+ */
251
+ component: PropTypes.elementType,
252
+ /**
253
+ * If `true`, the label should be displayed in a disabled state.
254
+ */
255
+ disabled: PropTypes.bool,
256
+ /**
257
+ * If `true`, the label is displayed in an error state.
258
+ */
259
+ error: PropTypes.bool,
260
+ /**
261
+ * If `true`, the label should use filled classes key.
262
+ */
263
+ filled: PropTypes.bool,
264
+ /**
265
+ * If `true`, the input of this label is focused (used by `FormGroup` components).
266
+ */
267
+ focused: PropTypes.bool,
268
+ /**
269
+ * If `true`, the label will indicate that the `input` is required.
270
+ */
271
+ required: PropTypes.bool,
272
+ /**
273
+ * The system prop that allows defining system overrides as well as additional CSS styles.
274
+ */
275
+ sx: PropTypes.oneOfType([PropTypes.arrayOf(PropTypes.oneOfType([PropTypes.func, PropTypes.object, PropTypes.bool])), PropTypes.func, PropTypes.object])
276
+ } : void 0;
277
+ var FormLabel$1 = FormLabel;
278
+
279
+ function getInputLabelUtilityClasses(slot) {
280
+ return generateUtilityClass('MuiInputLabel', slot);
281
+ }
282
+ generateUtilityClasses('MuiInputLabel', ['root', 'focused', 'disabled', 'error', 'required', 'asterisk', 'formControl', 'sizeSmall', 'shrink', 'animated', 'standard', 'filled', 'outlined']);
283
+
284
+ const _excluded$4 = ["disableAnimation", "margin", "shrink", "variant", "className"];
285
+ const useUtilityClasses$3 = ownerState => {
286
+ const {
287
+ classes,
288
+ formControl,
289
+ size,
290
+ shrink,
291
+ disableAnimation,
292
+ variant,
293
+ required
294
+ } = ownerState;
295
+ const slots = {
296
+ root: ['root', formControl && 'formControl', !disableAnimation && 'animated', shrink && 'shrink', size === 'small' && 'sizeSmall', variant],
297
+ asterisk: [required && 'asterisk']
298
+ };
299
+ const composedClasses = composeClasses(slots, getInputLabelUtilityClasses, classes);
300
+ return _extends({}, classes, composedClasses);
301
+ };
302
+ const InputLabelRoot = styled$1(FormLabel$1, {
303
+ shouldForwardProp: prop => rootShouldForwardProp(prop) || prop === 'classes',
304
+ name: 'MuiInputLabel',
305
+ slot: 'Root',
306
+ overridesResolver: (props, styles) => {
307
+ const {
308
+ ownerState
309
+ } = props;
310
+ return [{
311
+ [`& .${formLabelClasses$1.asterisk}`]: styles.asterisk
312
+ }, styles.root, ownerState.formControl && styles.formControl, ownerState.size === 'small' && styles.sizeSmall, ownerState.shrink && styles.shrink, !ownerState.disableAnimation && styles.animated, styles[ownerState.variant]];
313
+ }
314
+ })(({
315
+ theme,
316
+ ownerState
317
+ }) => _extends({
318
+ display: 'block',
319
+ transformOrigin: 'top left',
320
+ whiteSpace: 'nowrap',
321
+ overflow: 'hidden',
322
+ textOverflow: 'ellipsis',
323
+ maxWidth: '100%'
324
+ }, ownerState.formControl && {
325
+ position: 'absolute',
326
+ left: 0,
327
+ top: 0,
328
+ // slight alteration to spec spacing to match visual spec result
329
+ transform: 'translate(0, 20px) scale(1)'
330
+ }, ownerState.size === 'small' && {
331
+ // Compensation for the `Input.inputSizeSmall` style.
332
+ transform: 'translate(0, 17px) scale(1)'
333
+ }, ownerState.shrink && {
334
+ transform: 'translate(0, -1.5px) scale(0.75)',
335
+ transformOrigin: 'top left',
336
+ maxWidth: '133%'
337
+ }, !ownerState.disableAnimation && {
338
+ transition: theme.transitions.create(['color', 'transform', 'max-width'], {
339
+ duration: theme.transitions.duration.shorter,
340
+ easing: theme.transitions.easing.easeOut
341
+ })
342
+ }, ownerState.variant === 'filled' && _extends({
343
+ // Chrome's autofill feature gives the input field a yellow background.
344
+ // Since the input field is behind the label in the HTML tree,
345
+ // the input field is drawn last and hides the label with an opaque background color.
346
+ // zIndex: 1 will raise the label above opaque background-colors of input.
347
+ zIndex: 1,
348
+ pointerEvents: 'none',
349
+ transform: 'translate(12px, 16px) scale(1)',
350
+ maxWidth: 'calc(100% - 24px)'
351
+ }, ownerState.size === 'small' && {
352
+ transform: 'translate(12px, 13px) scale(1)'
353
+ }, ownerState.shrink && _extends({
354
+ userSelect: 'none',
355
+ pointerEvents: 'auto',
356
+ transform: 'translate(12px, 7px) scale(0.75)',
357
+ maxWidth: 'calc(133% - 24px)'
358
+ }, ownerState.size === 'small' && {
359
+ transform: 'translate(12px, 4px) scale(0.75)'
360
+ })), ownerState.variant === 'outlined' && _extends({
361
+ // see comment above on filled.zIndex
362
+ zIndex: 1,
363
+ pointerEvents: 'none',
364
+ transform: 'translate(14px, 16px) scale(1)',
365
+ maxWidth: 'calc(100% - 24px)'
366
+ }, ownerState.size === 'small' && {
367
+ transform: 'translate(14px, 9px) scale(1)'
368
+ }, ownerState.shrink && {
369
+ userSelect: 'none',
370
+ pointerEvents: 'auto',
371
+ // Theoretically, we should have (8+5)*2/0.75 = 34px
372
+ // but it feels a better when it bleeds a bit on the left, so 32px.
373
+ maxWidth: 'calc(133% - 32px)',
374
+ transform: 'translate(14px, -9px) scale(0.75)'
375
+ })));
376
+ const InputLabel = /*#__PURE__*/React.forwardRef(function InputLabel(inProps, ref) {
377
+ const props = useThemeProps({
378
+ name: 'MuiInputLabel',
379
+ props: inProps
380
+ });
381
+ const {
382
+ disableAnimation = false,
383
+ shrink: shrinkProp,
384
+ className
385
+ } = props,
386
+ other = _objectWithoutPropertiesLoose(props, _excluded$4);
387
+ const muiFormControl = useFormControl();
388
+ let shrink = shrinkProp;
389
+ if (typeof shrink === 'undefined' && muiFormControl) {
390
+ shrink = muiFormControl.filled || muiFormControl.focused || muiFormControl.adornedStart;
391
+ }
392
+ const fcs = formControlState({
393
+ props,
394
+ muiFormControl,
395
+ states: ['size', 'variant', 'required']
396
+ });
397
+ const ownerState = _extends({}, props, {
398
+ disableAnimation,
399
+ formControl: muiFormControl,
400
+ shrink,
401
+ size: fcs.size,
402
+ variant: fcs.variant,
403
+ required: fcs.required
404
+ });
405
+ const classes = useUtilityClasses$3(ownerState);
406
+ return /*#__PURE__*/jsxRuntimeExports.jsx(InputLabelRoot, _extends({
407
+ "data-shrink": shrink,
408
+ ownerState: ownerState,
409
+ ref: ref,
410
+ className: clsx(classes.root, className)
411
+ }, other, {
412
+ classes: classes
413
+ }));
414
+ });
415
+ process.env.NODE_ENV !== "production" ? InputLabel.propTypes /* remove-proptypes */ = {
416
+ // ----------------------------- Warning --------------------------------
417
+ // | These PropTypes are generated from the TypeScript type definitions |
418
+ // | To update them edit the d.ts file and run "yarn proptypes" |
419
+ // ----------------------------------------------------------------------
420
+ /**
421
+ * The content of the component.
422
+ */
423
+ children: PropTypes.node,
424
+ /**
425
+ * Override or extend the styles applied to the component.
426
+ */
427
+ classes: PropTypes.object,
428
+ /**
429
+ * @ignore
430
+ */
431
+ className: PropTypes.string,
432
+ /**
433
+ * The color of the component.
434
+ * It supports both default and custom theme colors, which can be added as shown in the
435
+ * [palette customization guide](https://mui.com/material-ui/customization/palette/#adding-new-colors).
436
+ */
437
+ color: PropTypes /* @typescript-to-proptypes-ignore */.oneOfType([PropTypes.oneOf(['error', 'info', 'primary', 'secondary', 'success', 'warning']), PropTypes.string]),
438
+ /**
439
+ * If `true`, the transition animation is disabled.
440
+ * @default false
441
+ */
442
+ disableAnimation: PropTypes.bool,
443
+ /**
444
+ * If `true`, the component is disabled.
445
+ */
446
+ disabled: PropTypes.bool,
447
+ /**
448
+ * If `true`, the label is displayed in an error state.
449
+ */
450
+ error: PropTypes.bool,
451
+ /**
452
+ * If `true`, the `input` of this label is focused.
453
+ */
454
+ focused: PropTypes.bool,
455
+ /**
456
+ * If `dense`, will adjust vertical spacing. This is normally obtained via context from
457
+ * FormControl.
458
+ */
459
+ margin: PropTypes.oneOf(['dense']),
460
+ /**
461
+ * if `true`, the label will indicate that the `input` is required.
462
+ */
463
+ required: PropTypes.bool,
464
+ /**
465
+ * If `true`, the label is shrunk.
466
+ */
467
+ shrink: PropTypes.bool,
468
+ /**
469
+ * The size of the component.
470
+ * @default 'normal'
471
+ */
472
+ size: PropTypes /* @typescript-to-proptypes-ignore */.oneOfType([PropTypes.oneOf(['normal', 'small']), PropTypes.string]),
473
+ /**
474
+ * The system prop that allows defining system overrides as well as additional CSS styles.
475
+ */
476
+ sx: PropTypes.oneOfType([PropTypes.arrayOf(PropTypes.oneOfType([PropTypes.func, PropTypes.object, PropTypes.bool])), PropTypes.func, PropTypes.object]),
477
+ /**
478
+ * The variant to use.
479
+ */
480
+ variant: PropTypes.oneOf(['filled', 'outlined', 'standard'])
481
+ } : void 0;
482
+ var InputLabel$1 = InputLabel;
483
+
484
+ function getFormControlUtilityClasses(slot) {
485
+ return generateUtilityClass('MuiFormControl', slot);
486
+ }
487
+ generateUtilityClasses('MuiFormControl', ['root', 'marginNone', 'marginNormal', 'marginDense', 'fullWidth', 'disabled']);
488
+
489
+ const _excluded$3 = ["children", "className", "color", "component", "disabled", "error", "focused", "fullWidth", "hiddenLabel", "margin", "required", "size", "variant"];
490
+ const useUtilityClasses$2 = ownerState => {
491
+ const {
492
+ classes,
493
+ margin,
494
+ fullWidth
495
+ } = ownerState;
496
+ const slots = {
497
+ root: ['root', margin !== 'none' && `margin${capitalize(margin)}`, fullWidth && 'fullWidth']
498
+ };
499
+ return composeClasses(slots, getFormControlUtilityClasses, classes);
500
+ };
501
+ const FormControlRoot = styled$1('div', {
502
+ name: 'MuiFormControl',
503
+ slot: 'Root',
504
+ overridesResolver: ({
505
+ ownerState
506
+ }, styles) => {
507
+ return _extends({}, styles.root, styles[`margin${capitalize(ownerState.margin)}`], ownerState.fullWidth && styles.fullWidth);
508
+ }
509
+ })(({
510
+ ownerState
511
+ }) => _extends({
512
+ display: 'inline-flex',
513
+ flexDirection: 'column',
514
+ position: 'relative',
515
+ // Reset fieldset default style.
516
+ minWidth: 0,
517
+ padding: 0,
518
+ margin: 0,
519
+ border: 0,
520
+ verticalAlign: 'top'
521
+ }, ownerState.margin === 'normal' && {
522
+ marginTop: 16,
523
+ marginBottom: 8
524
+ }, ownerState.margin === 'dense' && {
525
+ marginTop: 8,
526
+ marginBottom: 4
527
+ }, ownerState.fullWidth && {
528
+ width: '100%'
529
+ }));
530
+
531
+ /**
532
+ * Provides context such as filled/focused/error/required for form inputs.
533
+ * Relying on the context provides high flexibility and ensures that the state always stays
534
+ * consistent across the children of the `FormControl`.
535
+ * This context is used by the following components:
536
+ *
537
+ * - FormLabel
538
+ * - FormHelperText
539
+ * - Input
540
+ * - InputLabel
541
+ *
542
+ * You can find one composition example below and more going to [the demos](/material-ui/react-text-field/#components).
543
+ *
544
+ * ```jsx
545
+ * <FormControl>
546
+ * <InputLabel htmlFor="my-input">Email address</InputLabel>
547
+ * <Input id="my-input" aria-describedby="my-helper-text" />
548
+ * <FormHelperText id="my-helper-text">We'll never share your email.</FormHelperText>
549
+ * </FormControl>
550
+ * ```
551
+ *
552
+ * ⚠️ Only one `InputBase` can be used within a FormControl because it creates visual inconsistencies.
553
+ * For instance, only one input can be focused at the same time, the state shouldn't be shared.
554
+ */
555
+ const FormControl = /*#__PURE__*/React.forwardRef(function FormControl(inProps, ref) {
556
+ const props = useThemeProps({
557
+ props: inProps,
558
+ name: 'MuiFormControl'
559
+ });
560
+ const {
561
+ children,
562
+ className,
563
+ color = 'primary',
564
+ component = 'div',
565
+ disabled = false,
566
+ error = false,
567
+ focused: visuallyFocused,
568
+ fullWidth = false,
569
+ hiddenLabel = false,
570
+ margin = 'none',
571
+ required = false,
572
+ size = 'medium',
573
+ variant = 'outlined'
574
+ } = props,
575
+ other = _objectWithoutPropertiesLoose(props, _excluded$3);
576
+ const ownerState = _extends({}, props, {
577
+ color,
578
+ component,
579
+ disabled,
580
+ error,
581
+ fullWidth,
582
+ hiddenLabel,
583
+ margin,
584
+ required,
585
+ size,
586
+ variant
587
+ });
588
+ const classes = useUtilityClasses$2(ownerState);
589
+ const [adornedStart, setAdornedStart] = React.useState(() => {
590
+ // We need to iterate through the children and find the Input in order
591
+ // to fully support server-side rendering.
592
+ let initialAdornedStart = false;
593
+ if (children) {
594
+ React.Children.forEach(children, child => {
595
+ if (!isMuiElement(child, ['Input', 'Select'])) {
596
+ return;
597
+ }
598
+ const input = isMuiElement(child, ['Select']) ? child.props.input : child;
599
+ if (input && isAdornedStart(input.props)) {
600
+ initialAdornedStart = true;
601
+ }
602
+ });
603
+ }
604
+ return initialAdornedStart;
605
+ });
606
+ const [filled, setFilled] = React.useState(() => {
607
+ // We need to iterate through the children and find the Input in order
608
+ // to fully support server-side rendering.
609
+ let initialFilled = false;
610
+ if (children) {
611
+ React.Children.forEach(children, child => {
612
+ if (!isMuiElement(child, ['Input', 'Select'])) {
613
+ return;
614
+ }
615
+ if (isFilled(child.props, true) || isFilled(child.props.inputProps, true)) {
616
+ initialFilled = true;
617
+ }
618
+ });
619
+ }
620
+ return initialFilled;
621
+ });
622
+ const [focusedState, setFocused] = React.useState(false);
623
+ if (disabled && focusedState) {
624
+ setFocused(false);
625
+ }
626
+ const focused = visuallyFocused !== undefined && !disabled ? visuallyFocused : focusedState;
627
+ let registerEffect;
628
+ if (process.env.NODE_ENV !== 'production') {
629
+ // eslint-disable-next-line react-hooks/rules-of-hooks
630
+ const registeredInput = React.useRef(false);
631
+ registerEffect = () => {
632
+ if (registeredInput.current) {
633
+ console.error(['MUI: There are multiple `InputBase` components inside a FormControl.', 'This creates visual inconsistencies, only use one `InputBase`.'].join('\n'));
634
+ }
635
+ registeredInput.current = true;
636
+ return () => {
637
+ registeredInput.current = false;
638
+ };
639
+ };
640
+ }
641
+ const childContext = React.useMemo(() => {
642
+ return {
643
+ adornedStart,
644
+ setAdornedStart,
645
+ color,
646
+ disabled,
647
+ error,
648
+ filled,
649
+ focused,
650
+ fullWidth,
651
+ hiddenLabel,
652
+ size,
653
+ onBlur: () => {
654
+ setFocused(false);
655
+ },
656
+ onEmpty: () => {
657
+ setFilled(false);
658
+ },
659
+ onFilled: () => {
660
+ setFilled(true);
661
+ },
662
+ onFocus: () => {
663
+ setFocused(true);
664
+ },
665
+ registerEffect,
666
+ required,
667
+ variant
668
+ };
669
+ }, [adornedStart, color, disabled, error, filled, focused, fullWidth, hiddenLabel, registerEffect, required, size, variant]);
670
+ return /*#__PURE__*/jsxRuntimeExports.jsx(FormControlContext.Provider, {
671
+ value: childContext,
672
+ children: /*#__PURE__*/jsxRuntimeExports.jsx(FormControlRoot, _extends({
673
+ as: component,
674
+ ownerState: ownerState,
675
+ className: clsx(classes.root, className),
676
+ ref: ref
677
+ }, other, {
678
+ children: children
679
+ }))
680
+ });
681
+ });
682
+ process.env.NODE_ENV !== "production" ? FormControl.propTypes /* remove-proptypes */ = {
683
+ // ----------------------------- Warning --------------------------------
684
+ // | These PropTypes are generated from the TypeScript type definitions |
685
+ // | To update them edit the d.ts file and run "yarn proptypes" |
686
+ // ----------------------------------------------------------------------
687
+ /**
688
+ * The content of the component.
689
+ */
690
+ children: PropTypes.node,
691
+ /**
692
+ * Override or extend the styles applied to the component.
693
+ */
694
+ classes: PropTypes.object,
695
+ /**
696
+ * @ignore
697
+ */
698
+ className: PropTypes.string,
699
+ /**
700
+ * The color of the component.
701
+ * It supports both default and custom theme colors, which can be added as shown in the
702
+ * [palette customization guide](https://mui.com/material-ui/customization/palette/#adding-new-colors).
703
+ * @default 'primary'
704
+ */
705
+ color: PropTypes /* @typescript-to-proptypes-ignore */.oneOfType([PropTypes.oneOf(['primary', 'secondary', 'error', 'info', 'success', 'warning']), PropTypes.string]),
706
+ /**
707
+ * The component used for the root node.
708
+ * Either a string to use a HTML element or a component.
709
+ */
710
+ component: PropTypes.elementType,
711
+ /**
712
+ * If `true`, the label, input and helper text should be displayed in a disabled state.
713
+ * @default false
714
+ */
715
+ disabled: PropTypes.bool,
716
+ /**
717
+ * If `true`, the label is displayed in an error state.
718
+ * @default false
719
+ */
720
+ error: PropTypes.bool,
721
+ /**
722
+ * If `true`, the component is displayed in focused state.
723
+ */
724
+ focused: PropTypes.bool,
725
+ /**
726
+ * If `true`, the component will take up the full width of its container.
727
+ * @default false
728
+ */
729
+ fullWidth: PropTypes.bool,
730
+ /**
731
+ * If `true`, the label is hidden.
732
+ * This is used to increase density for a `FilledInput`.
733
+ * Be sure to add `aria-label` to the `input` element.
734
+ * @default false
735
+ */
736
+ hiddenLabel: PropTypes.bool,
737
+ /**
738
+ * If `dense` or `normal`, will adjust vertical spacing of this and contained components.
739
+ * @default 'none'
740
+ */
741
+ margin: PropTypes.oneOf(['dense', 'none', 'normal']),
742
+ /**
743
+ * If `true`, the label will indicate that the `input` is required.
744
+ * @default false
745
+ */
746
+ required: PropTypes.bool,
747
+ /**
748
+ * The size of the component.
749
+ * @default 'medium'
750
+ */
751
+ size: PropTypes /* @typescript-to-proptypes-ignore */.oneOfType([PropTypes.oneOf(['medium', 'small']), PropTypes.string]),
752
+ /**
753
+ * The system prop that allows defining system overrides as well as additional CSS styles.
754
+ */
755
+ sx: PropTypes.oneOfType([PropTypes.arrayOf(PropTypes.oneOfType([PropTypes.func, PropTypes.object, PropTypes.bool])), PropTypes.func, PropTypes.object]),
756
+ /**
757
+ * The variant to use.
758
+ * @default 'outlined'
759
+ */
760
+ variant: PropTypes.oneOf(['filled', 'outlined', 'standard'])
761
+ } : void 0;
762
+ var FormControl$1 = FormControl;
763
+
764
+ function getFormHelperTextUtilityClasses(slot) {
765
+ return generateUtilityClass('MuiFormHelperText', slot);
766
+ }
767
+ const formHelperTextClasses = generateUtilityClasses('MuiFormHelperText', ['root', 'error', 'disabled', 'sizeSmall', 'sizeMedium', 'contained', 'focused', 'filled', 'required']);
768
+ var formHelperTextClasses$1 = formHelperTextClasses;
769
+
770
+ var _span;
771
+ const _excluded$2 = ["children", "className", "component", "disabled", "error", "filled", "focused", "margin", "required", "variant"];
772
+ const useUtilityClasses$1 = ownerState => {
773
+ const {
774
+ classes,
775
+ contained,
776
+ size,
777
+ disabled,
778
+ error,
779
+ filled,
780
+ focused,
781
+ required
782
+ } = ownerState;
783
+ const slots = {
784
+ root: ['root', disabled && 'disabled', error && 'error', size && `size${capitalize(size)}`, contained && 'contained', focused && 'focused', filled && 'filled', required && 'required']
785
+ };
786
+ return composeClasses(slots, getFormHelperTextUtilityClasses, classes);
787
+ };
788
+ const FormHelperTextRoot = styled$1('p', {
789
+ name: 'MuiFormHelperText',
790
+ slot: 'Root',
791
+ overridesResolver: (props, styles) => {
792
+ const {
793
+ ownerState
794
+ } = props;
795
+ return [styles.root, ownerState.size && styles[`size${capitalize(ownerState.size)}`], ownerState.contained && styles.contained, ownerState.filled && styles.filled];
796
+ }
797
+ })(({
798
+ theme,
799
+ ownerState
800
+ }) => _extends({
801
+ color: (theme.vars || theme).palette.text.secondary
802
+ }, theme.typography.caption, {
803
+ textAlign: 'left',
804
+ marginTop: 3,
805
+ marginRight: 0,
806
+ marginBottom: 0,
807
+ marginLeft: 0,
808
+ [`&.${formHelperTextClasses$1.disabled}`]: {
809
+ color: (theme.vars || theme).palette.text.disabled
810
+ },
811
+ [`&.${formHelperTextClasses$1.error}`]: {
812
+ color: (theme.vars || theme).palette.error.main
813
+ }
814
+ }, ownerState.size === 'small' && {
815
+ marginTop: 4
816
+ }, ownerState.contained && {
817
+ marginLeft: 14,
818
+ marginRight: 14
819
+ }));
820
+ const FormHelperText = /*#__PURE__*/React.forwardRef(function FormHelperText(inProps, ref) {
821
+ const props = useThemeProps({
822
+ props: inProps,
823
+ name: 'MuiFormHelperText'
824
+ });
825
+ const {
826
+ children,
827
+ className,
828
+ component = 'p'
829
+ } = props,
830
+ other = _objectWithoutPropertiesLoose(props, _excluded$2);
831
+ const muiFormControl = useFormControl();
832
+ const fcs = formControlState({
833
+ props,
834
+ muiFormControl,
835
+ states: ['variant', 'size', 'disabled', 'error', 'filled', 'focused', 'required']
836
+ });
837
+ const ownerState = _extends({}, props, {
838
+ component,
839
+ contained: fcs.variant === 'filled' || fcs.variant === 'outlined',
840
+ variant: fcs.variant,
841
+ size: fcs.size,
842
+ disabled: fcs.disabled,
843
+ error: fcs.error,
844
+ filled: fcs.filled,
845
+ focused: fcs.focused,
846
+ required: fcs.required
847
+ });
848
+ const classes = useUtilityClasses$1(ownerState);
849
+ return /*#__PURE__*/jsxRuntimeExports.jsx(FormHelperTextRoot, _extends({
850
+ as: component,
851
+ ownerState: ownerState,
852
+ className: clsx(classes.root, className),
853
+ ref: ref
854
+ }, other, {
855
+ children: children === ' ' ? // notranslate needed while Google Translate will not fix zero-width space issue
856
+ _span || (_span = /*#__PURE__*/jsxRuntimeExports.jsx("span", {
857
+ className: "notranslate",
858
+ children: "\u200B"
859
+ })) : children
860
+ }));
861
+ });
862
+ process.env.NODE_ENV !== "production" ? FormHelperText.propTypes /* remove-proptypes */ = {
863
+ // ----------------------------- Warning --------------------------------
864
+ // | These PropTypes are generated from the TypeScript type definitions |
865
+ // | To update them edit the d.ts file and run "yarn proptypes" |
866
+ // ----------------------------------------------------------------------
867
+ /**
868
+ * The content of the component.
869
+ *
870
+ * If `' '` is provided, the component reserves one line height for displaying a future message.
871
+ */
872
+ children: PropTypes.node,
873
+ /**
874
+ * Override or extend the styles applied to the component.
875
+ */
876
+ classes: PropTypes.object,
877
+ /**
878
+ * @ignore
879
+ */
880
+ className: PropTypes.string,
881
+ /**
882
+ * The component used for the root node.
883
+ * Either a string to use a HTML element or a component.
884
+ */
885
+ component: PropTypes.elementType,
886
+ /**
887
+ * If `true`, the helper text should be displayed in a disabled state.
888
+ */
889
+ disabled: PropTypes.bool,
890
+ /**
891
+ * If `true`, helper text should be displayed in an error state.
892
+ */
893
+ error: PropTypes.bool,
894
+ /**
895
+ * If `true`, the helper text should use filled classes key.
896
+ */
897
+ filled: PropTypes.bool,
898
+ /**
899
+ * If `true`, the helper text should use focused classes key.
900
+ */
901
+ focused: PropTypes.bool,
902
+ /**
903
+ * If `dense`, will adjust vertical spacing. This is normally obtained via context from
904
+ * FormControl.
905
+ */
906
+ margin: PropTypes.oneOf(['dense']),
907
+ /**
908
+ * If `true`, the helper text should use required classes key.
909
+ */
910
+ required: PropTypes.bool,
911
+ /**
912
+ * The system prop that allows defining system overrides as well as additional CSS styles.
913
+ */
914
+ sx: PropTypes.oneOfType([PropTypes.arrayOf(PropTypes.oneOfType([PropTypes.func, PropTypes.object, PropTypes.bool])), PropTypes.func, PropTypes.object]),
915
+ /**
916
+ * The variant to use.
917
+ */
918
+ variant: PropTypes /* @typescript-to-proptypes-ignore */.oneOfType([PropTypes.oneOf(['filled', 'outlined', 'standard']), PropTypes.string])
919
+ } : void 0;
920
+ var FormHelperText$1 = FormHelperText;
921
+
922
+ function getTextFieldUtilityClass(slot) {
923
+ return generateUtilityClass('MuiTextField', slot);
924
+ }
925
+ generateUtilityClasses('MuiTextField', ['root']);
926
+
927
+ const _excluded$1 = ["autoComplete", "autoFocus", "children", "className", "color", "defaultValue", "disabled", "error", "FormHelperTextProps", "fullWidth", "helperText", "id", "InputLabelProps", "inputProps", "InputProps", "inputRef", "label", "maxRows", "minRows", "multiline", "name", "onBlur", "onChange", "onClick", "onFocus", "placeholder", "required", "rows", "select", "SelectProps", "type", "value", "variant"];
928
+ const variantComponent = {
929
+ standard: Input,
930
+ filled: FilledInput,
931
+ outlined: OutlinedInput
932
+ };
933
+ const useUtilityClasses = ownerState => {
934
+ const {
935
+ classes
936
+ } = ownerState;
937
+ const slots = {
938
+ root: ['root']
939
+ };
940
+ return composeClasses(slots, getTextFieldUtilityClass, classes);
941
+ };
942
+ const TextFieldRoot = styled$1(FormControl$1, {
943
+ name: 'MuiTextField',
944
+ slot: 'Root',
945
+ overridesResolver: (props, styles) => styles.root
946
+ })({});
947
+
948
+ /**
949
+ * The `TextField` is a convenience wrapper for the most common cases (80%).
950
+ * It cannot be all things to all people, otherwise the API would grow out of control.
951
+ *
952
+ * ## Advanced Configuration
953
+ *
954
+ * It's important to understand that the text field is a simple abstraction
955
+ * on top of the following components:
956
+ *
957
+ * - [FormControl](/material-ui/api/form-control/)
958
+ * - [InputLabel](/material-ui/api/input-label/)
959
+ * - [FilledInput](/material-ui/api/filled-input/)
960
+ * - [OutlinedInput](/material-ui/api/outlined-input/)
961
+ * - [Input](/material-ui/api/input/)
962
+ * - [FormHelperText](/material-ui/api/form-helper-text/)
963
+ *
964
+ * If you wish to alter the props applied to the `input` element, you can do so as follows:
965
+ *
966
+ * ```jsx
967
+ * const inputProps = {
968
+ * step: 300,
969
+ * };
970
+ *
971
+ * return <TextField id="time" type="time" inputProps={inputProps} />;
972
+ * ```
973
+ *
974
+ * For advanced cases, please look at the source of TextField by clicking on the
975
+ * "Edit this page" button above. Consider either:
976
+ *
977
+ * - using the upper case props for passing values directly to the components
978
+ * - using the underlying components directly as shown in the demos
979
+ */
980
+ const TextField = /*#__PURE__*/React.forwardRef(function TextField(inProps, ref) {
981
+ const props = useThemeProps({
982
+ props: inProps,
983
+ name: 'MuiTextField'
984
+ });
985
+ const {
986
+ autoComplete,
987
+ autoFocus = false,
988
+ children,
989
+ className,
990
+ color = 'primary',
991
+ defaultValue,
992
+ disabled = false,
993
+ error = false,
994
+ FormHelperTextProps,
995
+ fullWidth = false,
996
+ helperText,
997
+ id: idOverride,
998
+ InputLabelProps,
999
+ inputProps,
1000
+ InputProps,
1001
+ inputRef,
1002
+ label,
1003
+ maxRows,
1004
+ minRows,
1005
+ multiline = false,
1006
+ name,
1007
+ onBlur,
1008
+ onChange,
1009
+ onClick,
1010
+ onFocus,
1011
+ placeholder,
1012
+ required = false,
1013
+ rows,
1014
+ select = false,
1015
+ SelectProps,
1016
+ type,
1017
+ value,
1018
+ variant = 'outlined'
1019
+ } = props,
1020
+ other = _objectWithoutPropertiesLoose(props, _excluded$1);
1021
+ const ownerState = _extends({}, props, {
1022
+ autoFocus,
1023
+ color,
1024
+ disabled,
1025
+ error,
1026
+ fullWidth,
1027
+ multiline,
1028
+ required,
1029
+ select,
1030
+ variant
1031
+ });
1032
+ const classes = useUtilityClasses(ownerState);
1033
+ if (process.env.NODE_ENV !== 'production') {
1034
+ if (select && !children) {
1035
+ console.error('MUI: `children` must be passed when using the `TextField` component with `select`.');
1036
+ }
1037
+ }
1038
+ const InputMore = {};
1039
+ if (variant === 'outlined') {
1040
+ if (InputLabelProps && typeof InputLabelProps.shrink !== 'undefined') {
1041
+ InputMore.notched = InputLabelProps.shrink;
1042
+ }
1043
+ InputMore.label = label;
1044
+ }
1045
+ if (select) {
1046
+ // unset defaults from textbox inputs
1047
+ if (!SelectProps || !SelectProps.native) {
1048
+ InputMore.id = undefined;
1049
+ }
1050
+ InputMore['aria-describedby'] = undefined;
1051
+ }
1052
+ const id = useId(idOverride);
1053
+ const helperTextId = helperText && id ? `${id}-helper-text` : undefined;
1054
+ const inputLabelId = label && id ? `${id}-label` : undefined;
1055
+ const InputComponent = variantComponent[variant];
1056
+ const InputElement = /*#__PURE__*/jsxRuntimeExports.jsx(InputComponent, _extends({
1057
+ "aria-describedby": helperTextId,
1058
+ autoComplete: autoComplete,
1059
+ autoFocus: autoFocus,
1060
+ defaultValue: defaultValue,
1061
+ fullWidth: fullWidth,
1062
+ multiline: multiline,
1063
+ name: name,
1064
+ rows: rows,
1065
+ maxRows: maxRows,
1066
+ minRows: minRows,
1067
+ type: type,
1068
+ value: value,
1069
+ id: id,
1070
+ inputRef: inputRef,
1071
+ onBlur: onBlur,
1072
+ onChange: onChange,
1073
+ onFocus: onFocus,
1074
+ onClick: onClick,
1075
+ placeholder: placeholder,
1076
+ inputProps: inputProps
1077
+ }, InputMore, InputProps));
1078
+ return /*#__PURE__*/jsxRuntimeExports.jsxs(TextFieldRoot, _extends({
1079
+ className: clsx(classes.root, className),
1080
+ disabled: disabled,
1081
+ error: error,
1082
+ fullWidth: fullWidth,
1083
+ ref: ref,
1084
+ required: required,
1085
+ color: color,
1086
+ variant: variant,
1087
+ ownerState: ownerState
1088
+ }, other, {
1089
+ children: [label != null && label !== '' && /*#__PURE__*/jsxRuntimeExports.jsx(InputLabel$1, _extends({
1090
+ htmlFor: id,
1091
+ id: inputLabelId
1092
+ }, InputLabelProps, {
1093
+ children: label
1094
+ })), select ? /*#__PURE__*/jsxRuntimeExports.jsx(Select, _extends({
1095
+ "aria-describedby": helperTextId,
1096
+ id: id,
1097
+ labelId: inputLabelId,
1098
+ value: value,
1099
+ input: InputElement
1100
+ }, SelectProps, {
1101
+ children: children
1102
+ })) : InputElement, helperText && /*#__PURE__*/jsxRuntimeExports.jsx(FormHelperText$1, _extends({
1103
+ id: helperTextId
1104
+ }, FormHelperTextProps, {
1105
+ children: helperText
1106
+ }))]
1107
+ }));
1108
+ });
1109
+ process.env.NODE_ENV !== "production" ? TextField.propTypes /* remove-proptypes */ = {
1110
+ // ----------------------------- Warning --------------------------------
1111
+ // | These PropTypes are generated from the TypeScript type definitions |
1112
+ // | To update them edit the d.ts file and run "yarn proptypes" |
1113
+ // ----------------------------------------------------------------------
1114
+ /**
1115
+ * This prop helps users to fill forms faster, especially on mobile devices.
1116
+ * The name can be confusing, as it's more like an autofill.
1117
+ * You can learn more about it [following the specification](https://html.spec.whatwg.org/multipage/form-control-infrastructure.html#autofill).
1118
+ */
1119
+ autoComplete: PropTypes.string,
1120
+ /**
1121
+ * If `true`, the `input` element is focused during the first mount.
1122
+ * @default false
1123
+ */
1124
+ autoFocus: PropTypes.bool,
1125
+ /**
1126
+ * @ignore
1127
+ */
1128
+ children: PropTypes.node,
1129
+ /**
1130
+ * Override or extend the styles applied to the component.
1131
+ */
1132
+ classes: PropTypes.object,
1133
+ /**
1134
+ * @ignore
1135
+ */
1136
+ className: PropTypes.string,
1137
+ /**
1138
+ * The color of the component.
1139
+ * It supports both default and custom theme colors, which can be added as shown in the
1140
+ * [palette customization guide](https://mui.com/material-ui/customization/palette/#adding-new-colors).
1141
+ * @default 'primary'
1142
+ */
1143
+ color: PropTypes /* @typescript-to-proptypes-ignore */.oneOfType([PropTypes.oneOf(['primary', 'secondary', 'error', 'info', 'success', 'warning']), PropTypes.string]),
1144
+ /**
1145
+ * The default value. Use when the component is not controlled.
1146
+ */
1147
+ defaultValue: PropTypes.any,
1148
+ /**
1149
+ * If `true`, the component is disabled.
1150
+ * @default false
1151
+ */
1152
+ disabled: PropTypes.bool,
1153
+ /**
1154
+ * If `true`, the label is displayed in an error state.
1155
+ * @default false
1156
+ */
1157
+ error: PropTypes.bool,
1158
+ /**
1159
+ * Props applied to the [`FormHelperText`](/material-ui/api/form-helper-text/) element.
1160
+ */
1161
+ FormHelperTextProps: PropTypes.object,
1162
+ /**
1163
+ * If `true`, the input will take up the full width of its container.
1164
+ * @default false
1165
+ */
1166
+ fullWidth: PropTypes.bool,
1167
+ /**
1168
+ * The helper text content.
1169
+ */
1170
+ helperText: PropTypes.node,
1171
+ /**
1172
+ * The id of the `input` element.
1173
+ * Use this prop to make `label` and `helperText` accessible for screen readers.
1174
+ */
1175
+ id: PropTypes.string,
1176
+ /**
1177
+ * Props applied to the [`InputLabel`](/material-ui/api/input-label/) element.
1178
+ * Pointer events like `onClick` are enabled if and only if `shrink` is `true`.
1179
+ */
1180
+ InputLabelProps: PropTypes.object,
1181
+ /**
1182
+ * [Attributes](https://developer.mozilla.org/en-US/docs/Web/HTML/Element/input#Attributes) applied to the `input` element.
1183
+ */
1184
+ inputProps: PropTypes.object,
1185
+ /**
1186
+ * Props applied to the Input element.
1187
+ * It will be a [`FilledInput`](/material-ui/api/filled-input/),
1188
+ * [`OutlinedInput`](/material-ui/api/outlined-input/) or [`Input`](/material-ui/api/input/)
1189
+ * component depending on the `variant` prop value.
1190
+ */
1191
+ InputProps: PropTypes.object,
1192
+ /**
1193
+ * Pass a ref to the `input` element.
1194
+ */
1195
+ inputRef: refType,
1196
+ /**
1197
+ * The label content.
1198
+ */
1199
+ label: PropTypes.node,
1200
+ /**
1201
+ * If `dense` or `normal`, will adjust vertical spacing of this and contained components.
1202
+ * @default 'none'
1203
+ */
1204
+ margin: PropTypes.oneOf(['dense', 'none', 'normal']),
1205
+ /**
1206
+ * Maximum number of rows to display when multiline option is set to true.
1207
+ */
1208
+ maxRows: PropTypes.oneOfType([PropTypes.number, PropTypes.string]),
1209
+ /**
1210
+ * Minimum number of rows to display when multiline option is set to true.
1211
+ */
1212
+ minRows: PropTypes.oneOfType([PropTypes.number, PropTypes.string]),
1213
+ /**
1214
+ * If `true`, a `textarea` element is rendered instead of an input.
1215
+ * @default false
1216
+ */
1217
+ multiline: PropTypes.bool,
1218
+ /**
1219
+ * Name attribute of the `input` element.
1220
+ */
1221
+ name: PropTypes.string,
1222
+ /**
1223
+ * @ignore
1224
+ */
1225
+ onBlur: PropTypes.func,
1226
+ /**
1227
+ * Callback fired when the value is changed.
1228
+ *
1229
+ * @param {object} event The event source of the callback.
1230
+ * You can pull out the new value by accessing `event.target.value` (string).
1231
+ */
1232
+ onChange: PropTypes.func,
1233
+ /**
1234
+ * @ignore
1235
+ */
1236
+ onClick: PropTypes.func,
1237
+ /**
1238
+ * @ignore
1239
+ */
1240
+ onFocus: PropTypes.func,
1241
+ /**
1242
+ * The short hint displayed in the `input` before the user enters a value.
1243
+ */
1244
+ placeholder: PropTypes.string,
1245
+ /**
1246
+ * If `true`, the label is displayed as required and the `input` element is required.
1247
+ * @default false
1248
+ */
1249
+ required: PropTypes.bool,
1250
+ /**
1251
+ * Number of rows to display when multiline option is set to true.
1252
+ */
1253
+ rows: PropTypes.oneOfType([PropTypes.number, PropTypes.string]),
1254
+ /**
1255
+ * Render a [`Select`](/material-ui/api/select/) element while passing the Input element to `Select` as `input` parameter.
1256
+ * If this option is set you must pass the options of the select as children.
1257
+ * @default false
1258
+ */
1259
+ select: PropTypes.bool,
1260
+ /**
1261
+ * Props applied to the [`Select`](/material-ui/api/select/) element.
1262
+ */
1263
+ SelectProps: PropTypes.object,
1264
+ /**
1265
+ * The size of the component.
1266
+ */
1267
+ size: PropTypes /* @typescript-to-proptypes-ignore */.oneOfType([PropTypes.oneOf(['medium', 'small']), PropTypes.string]),
1268
+ /**
1269
+ * The system prop that allows defining system overrides as well as additional CSS styles.
1270
+ */
1271
+ sx: PropTypes.oneOfType([PropTypes.arrayOf(PropTypes.oneOfType([PropTypes.func, PropTypes.object, PropTypes.bool])), PropTypes.func, PropTypes.object]),
1272
+ /**
1273
+ * Type of the `input` element. It should be [a valid HTML5 input type](https://developer.mozilla.org/en-US/docs/Web/HTML/Element/input#Form_%3Cinput%3E_types).
1274
+ */
1275
+ type: PropTypes /* @typescript-to-proptypes-ignore */.string,
1276
+ /**
1277
+ * The value of the `input` element, required for a controlled component.
1278
+ */
1279
+ value: PropTypes.any,
1280
+ /**
1281
+ * The variant to use.
1282
+ * @default 'outlined'
1283
+ */
1284
+ variant: PropTypes.oneOf(['filled', 'outlined', 'standard'])
1285
+ } : void 0;
1286
+ var TextField$1 = TextField;
1287
+
1288
+ const SUBMIT_FILTER_STROKE_TIME = 500;
1289
+ const InputNumberInterval = props => {
1290
+ var _item$value;
1291
+ const {
1292
+ item,
1293
+ applyValue,
1294
+ focusElementRef = null
1295
+ } = props;
1296
+ const filterTimeout = React.useRef();
1297
+ const [filterValueState, setFilterValueState] = React.useState((_item$value = item.value) !== null && _item$value !== void 0 ? _item$value : '');
1298
+ const [applying, setIsApplying] = React.useState(false);
1299
+ React.useEffect(() => {
1300
+ return () => {
1301
+ clearTimeout(filterTimeout.current);
1302
+ };
1303
+ }, []);
1304
+ React.useEffect(() => {
1305
+ var _item$value2;
1306
+ const itemValue = (_item$value2 = item.value) !== null && _item$value2 !== void 0 ? _item$value2 : [undefined, undefined];
1307
+ setFilterValueState(itemValue);
1308
+ }, [item.value]);
1309
+ const updateFilterValue = (lowerBound, upperBound) => {
1310
+ clearTimeout(filterTimeout.current);
1311
+ setFilterValueState([lowerBound, upperBound]);
1312
+ setIsApplying(true);
1313
+ filterTimeout.current = setTimeout(() => {
1314
+ setIsApplying(false);
1315
+ applyValue(_objectSpread2(_objectSpread2({}, item), {}, {
1316
+ value: [lowerBound, upperBound]
1317
+ }));
1318
+ }, SUBMIT_FILTER_STROKE_TIME);
1319
+ };
1320
+ const handleUpperFilterChange = event => {
1321
+ const newUpperBound = event.target.value;
1322
+ updateFilterValue(filterValueState[0], newUpperBound);
1323
+ };
1324
+ const handleLowerFilterChange = event => {
1325
+ const newLowerBound = event.target.value;
1326
+ updateFilterValue(newLowerBound, filterValueState[1]);
1327
+ };
1328
+ return /*#__PURE__*/React.createElement(Box$1, {
1329
+ sx: {
1330
+ display: 'inline-flex',
1331
+ flexDirection: 'row',
1332
+ alignItems: 'end',
1333
+ height: 48,
1334
+ pl: '20px'
1335
+ }
1336
+ }, /*#__PURE__*/React.createElement(TextField$1, {
1337
+ name: "lower-bound-input",
1338
+ placeholder: "From",
1339
+ label: "From",
1340
+ variant: "standard",
1341
+ value: Number(filterValueState[0]),
1342
+ onChange: handleLowerFilterChange,
1343
+ type: "number",
1344
+ inputRef: focusElementRef,
1345
+ sx: {
1346
+ mr: 2
1347
+ }
1348
+ }), /*#__PURE__*/React.createElement(TextField$1, {
1349
+ name: "upper-bound-input",
1350
+ placeholder: "To",
1351
+ label: "To",
1352
+ variant: "standard",
1353
+ value: Number(filterValueState[1]),
1354
+ onChange: handleUpperFilterChange,
1355
+ type: "number",
1356
+ InputProps: applying ? {
1357
+ endAdornment: /*#__PURE__*/React.createElement(Icon, {
1358
+ icon: mdiSync
1359
+ })
1360
+ } : {}
1361
+ }));
1362
+ };
1363
+
1364
+ const isBetweenOperator = {
1365
+ label: 'is between',
1366
+ value: 'isBetween',
1367
+ getApplyFilterFn: filterItem => {
1368
+ if (!filterItem.field || !filterItem.value || !filterItem.operator) {
1369
+ return null;
1370
+ }
1371
+ if (!Array.isArray(filterItem.value) || filterItem.value.length !== 2) {
1372
+ return null;
1373
+ }
1374
+ if (filterItem.value[0] == null || filterItem.value[1] == null) {
1375
+ return null;
1376
+ }
1377
+ if (typeof filterItem.value[0] !== 'number' || typeof filterItem.value[1] !== 'number') {
1378
+ return null;
1379
+ }
1380
+ return params => {
1381
+ return params.value !== null && params.value !== undefined && filterItem.value[0] <= params.value && params.value <= filterItem.value[1];
1382
+ };
1383
+ },
1384
+ InputComponent: InputNumberInterval
1385
+ };
1386
+ const IS_BETWEEN = isBetweenOperator;
1387
+
1388
+ const getGridNumericOperators = () => [...getGridNumericOperators$1(), IS_BETWEEN];
1389
+
1390
+ const doesNotContain = {
1391
+ label: 'does not contain',
1392
+ value: 'doesNotContain',
1393
+ getApplyFilterFn: filterItem => {
1394
+ if (!filterItem.field || !filterItem.value || !filterItem.operator) {
1395
+ return null;
1396
+ }
1397
+ return params => {
1398
+ if (filterItem.value.length === 0) {
1399
+ return true;
1400
+ }
1401
+ if (String(params.value).indexOf(filterItem.value) !== -1) {
1402
+ return false;
1403
+ }
1404
+ return true;
1405
+ };
1406
+ },
1407
+ InputComponent: GridFilterInputValue
1408
+ };
1409
+ const DOES_NOT_CONTAIN = doesNotContain;
1410
+
1411
+ const doesNotEqual = {
1412
+ label: 'does not equal',
1413
+ value: 'doesNotEqual',
1414
+ getApplyFilterFn: filterItem => {
1415
+ if (!filterItem.field || !filterItem.value || !filterItem.value) {
1416
+ return null;
1417
+ }
1418
+ return params => {
1419
+ if (filterItem.value.length === 0) {
1420
+ return true;
1421
+ }
1422
+ if (String(params.value) === filterItem.value) {
1423
+ return false;
1424
+ }
1425
+ return true;
1426
+ };
1427
+ },
1428
+ InputComponent: GridFilterInputValue
1429
+ };
1430
+ const DOES_NOT_EQUAL = doesNotEqual;
1431
+
1432
+ const doesNotHaveOperator = {
1433
+ label: "doesn't have",
1434
+ value: 'doesNotHave',
1435
+ getApplyFilterFn: filterItem => {
1436
+ if (!filterItem.field || !filterItem.value || !filterItem.operator) {
1437
+ return null;
1438
+ }
1439
+ return params => {
1440
+ const cellValues = Array.isArray(params.value) ? params.value : [params.value];
1441
+ return !cellValues.map(value => String(value)).includes(filterItem.value);
1442
+ };
1443
+ },
1444
+ InputComponent: GridFilterInputValue
1445
+ };
1446
+ const DOES_NOT_HAVE = doesNotHaveOperator;
1447
+ const DOES_NOT_HAVE_WITH_SELECT = _objectSpread2(_objectSpread2({}, DOES_NOT_HAVE), {}, {
1448
+ InputComponent: GridFilterInputSingleSelect
1449
+ });
1450
+
1451
+ const hasOperator = {
1452
+ label: 'has',
1453
+ value: 'has',
1454
+ getApplyFilterFn: filterItem => {
1455
+ if (!filterItem.field || !filterItem.value || !filterItem.operator) {
1456
+ return null;
1457
+ }
1458
+ return params => {
1459
+ const cellValues = Array.isArray(params.value) ? params.value : [params.value];
1460
+ return cellValues.map(value => String(value)).includes(filterItem.value);
1461
+ };
1462
+ },
1463
+ InputComponent: GridFilterInputValue
1464
+ };
1465
+ const HAS = hasOperator;
1466
+ const HAS_WITH_SELECT = _objectSpread2(_objectSpread2({}, HAS), {}, {
1467
+ InputComponent: GridFilterInputSingleSelect
1468
+ });
1469
+
1470
+ const hasOnlyOperator = {
1471
+ label: 'has only',
1472
+ value: 'hasOnly',
1473
+ getApplyFilterFn: filterItem => {
1474
+ if (!filterItem.field || !filterItem.value || !filterItem.operator) {
1475
+ return null;
1476
+ }
1477
+ return params => {
1478
+ const cellValues = Array.isArray(params.value) ? params.value : [params.value];
1479
+ return cellValues.length === 1 && String(cellValues[0]) === filterItem.value;
1480
+ };
1481
+ },
1482
+ InputComponent: GridFilterInputValue
1483
+ };
1484
+ const HAS_ONLY = hasOnlyOperator;
1485
+ const HAS_ONLY_WITH_SELECT = _objectSpread2(_objectSpread2({}, HAS_ONLY), {}, {
1486
+ InputComponent: GridFilterInputSingleSelect
1487
+ });
1488
+
1489
+ const isOperator = {
1490
+ label: 'is',
1491
+ value: 'is',
1492
+ getApplyFilterFn: filterItem => {
1493
+ if (!filterItem.field || !filterItem.value || !filterItem.operator) {
1494
+ return null;
1495
+ }
1496
+ return params => {
1497
+ if (Array.isArray(params.value)) {
1498
+ return false;
1499
+ }
1500
+ return String(params.value) === filterItem.value;
1501
+ };
1502
+ },
1503
+ InputComponent: GridFilterInputValue
1504
+ };
1505
+ const IS = isOperator;
1506
+ const IS_WITH_SELECT = _objectSpread2(_objectSpread2({}, IS), {}, {
1507
+ InputComponent: GridFilterInputSingleSelect
1508
+ });
1509
+
1510
+ const isNotOperator = {
1511
+ label: 'is not',
1512
+ value: 'isNot',
1513
+ getApplyFilterFn: filterItem => {
1514
+ if (!filterItem.field || !filterItem.value || !filterItem.operator) {
1515
+ return null;
1516
+ }
1517
+ return params => {
1518
+ if (Array.isArray(params.value)) {
1519
+ return true;
1520
+ }
1521
+ return String(params.value) !== filterItem.value;
1522
+ };
1523
+ },
1524
+ InputComponent: GridFilterInputValue
1525
+ };
1526
+ const IS_NOT = isNotOperator;
1527
+ const IS_NOT_WITH_SELECT = _objectSpread2(_objectSpread2({}, IS_NOT), {}, {
1528
+ InputComponent: GridFilterInputSingleSelect
1529
+ });
1530
+
1531
+ const containsAnyOfOperator = {
1532
+ label: 'contains any of',
1533
+ value: 'containsAnyOf',
1534
+ getApplyFilterFn: filterItem => {
1535
+ if (!filterItem.field || !filterItem.value || !filterItem.operator) {
1536
+ return null;
1537
+ }
1538
+ return params => {
1539
+ if (filterItem.value.length === 0) {
1540
+ return true;
1541
+ }
1542
+ const paramValues = Array.isArray(params.value) ? params.value : [params.value];
1543
+ let match = false;
1544
+ filterItem.value.forEach(filteredValue => {
1545
+ paramValues.forEach(paramValue => {
1546
+ if (String(paramValue).indexOf(filteredValue) !== -1) {
1547
+ match = true;
1548
+ }
1549
+ });
1550
+ });
1551
+ return match;
1552
+ };
1553
+ },
1554
+ InputComponent: GridFilterInputMultipleValue
1555
+ };
1556
+ const containsAnyOfCIOperator = {
1557
+ label: 'contains any of (case insensitive)',
1558
+ value: 'containsAnyOf',
1559
+ getApplyFilterFn: filterItem => {
1560
+ if (!filterItem.field || !filterItem.value || !filterItem.operator) {
1561
+ return null;
1562
+ }
1563
+ return params => {
1564
+ if (filterItem.value.length === 0) {
1565
+ return true;
1566
+ }
1567
+ const paramValues = Array.isArray(params.value) ? params.value : [params.value];
1568
+ const paramValuesLower = paramValues.map(item => String(item).toLowerCase());
1569
+ let match = false;
1570
+ filterItem.value.forEach(filteredValue => {
1571
+ if (paramValuesLower.indexOf(filteredValue.toLowerCase()) !== -1) {
1572
+ match = true;
1573
+ }
1574
+ });
1575
+ return match;
1576
+ };
1577
+ },
1578
+ InputComponent: GridFilterInputMultipleValue
1579
+ };
1580
+ const CONTAINS_ANY_OF = containsAnyOfOperator;
1581
+ const CONTAINS_ANY_OF_I = containsAnyOfCIOperator;
1582
+
1583
+ const endsWithAnyOfOperator = {
1584
+ label: 'ends with any of',
1585
+ value: 'endsWithAnyOf',
1586
+ getApplyFilterFn: filterItem => {
1587
+ if (!filterItem.field || !filterItem.value || !filterItem.operator) {
1588
+ return null;
1589
+ }
1590
+ return params => {
1591
+ if (filterItem.value.length === 0) {
1592
+ return true;
1593
+ }
1594
+ const paramValues = Array.isArray(params.value) ? params.value : [params.value];
1595
+ let match = false;
1596
+ filterItem.value.forEach(filteredValue => {
1597
+ paramValues.forEach(paramValue => {
1598
+ if (String(paramValue).endsWith(filteredValue)) {
1599
+ match = true;
1600
+ }
1601
+ });
1602
+ });
1603
+ return match;
1604
+ };
1605
+ },
1606
+ InputComponent: GridFilterInputMultipleValue
1607
+ };
1608
+ const ENDS_WITH_ANY_OF = endsWithAnyOfOperator;
1609
+
1610
+ const isAnyOfOperator = {
1611
+ label: 'is any of',
1612
+ value: 'isAnyOf',
1613
+ getApplyFilterFn: filterItem => {
1614
+ if (!filterItem.field || !filterItem.value || !filterItem.operator) {
1615
+ return null;
1616
+ }
1617
+ return params => {
1618
+ if (filterItem.value.length === 0) {
1619
+ return true;
1620
+ }
1621
+ const paramValues = Array.isArray(params.value) ? params.value : [params.value];
1622
+ for (const paramValue of paramValues) {
1623
+ if (filterItem.value.includes(String(paramValue))) {
1624
+ return true;
1625
+ }
1626
+ }
1627
+ return false;
1628
+ };
1629
+ },
1630
+ InputComponent: GridFilterInputMultipleValue
1631
+ };
1632
+ const IS_ANY_OF = isAnyOfOperator;
1633
+ const IS_ANY_OF_WITH_SELECT = _objectSpread2(_objectSpread2({}, IS_ANY_OF), {}, {
1634
+ InputComponent: GridFilterInputMultipleSingleSelect
1635
+ });
1636
+
1637
+ const hasAnyOfOperator = {
1638
+ label: 'has any of',
1639
+ value: 'hasAnyOf',
1640
+ getApplyFilterFn: filterItem => {
1641
+ if (!filterItem.field || !filterItem.value || !filterItem.operator) {
1642
+ return null;
1643
+ }
1644
+ return params => {
1645
+ if (filterItem.value.length === 0) {
1646
+ return true;
1647
+ }
1648
+ const cellValues = Array.isArray(params.value) ? params.value : [params.value];
1649
+ const filterItemValues = Array.isArray(filterItem.value) ? filterItem.value : [filterItem.value];
1650
+ return filterItemValues.some(v => cellValues.map(value => String(value)).includes(v));
1651
+ };
1652
+ },
1653
+ InputComponent: GridFilterInputMultipleValue
1654
+ };
1655
+ const HAS_ANY_OF = hasAnyOfOperator;
1656
+ const HAS_ANY_OF_WITH_SELECT = _objectSpread2(_objectSpread2({}, HAS_ANY_OF), {}, {
1657
+ InputComponent: GridFilterInputMultipleSingleSelect
1658
+ });
1659
+
1660
+ const isNotAnyOfOperator = {
1661
+ label: 'is not any of',
1662
+ value: 'isNotAnyOf',
1663
+ getApplyFilterFn: filterItem => {
1664
+ if (!filterItem.field || !filterItem.value || !filterItem.operator) {
1665
+ return null;
1666
+ }
1667
+ return params => {
1668
+ if (filterItem.value.length === 0) {
1669
+ return true;
1670
+ }
1671
+ const paramValues = Array.isArray(params.value) ? params.value : [params.value];
1672
+ for (const paramValue of paramValues) {
1673
+ if (filterItem.value.includes(String(paramValue))) {
1674
+ return false;
1675
+ }
1676
+ }
1677
+ return true;
1678
+ };
1679
+ },
1680
+ InputComponent: GridFilterInputMultipleValue
1681
+ };
1682
+ const IS_NOT_ANY_OF = isNotAnyOfOperator;
1683
+ const IS_NOT_ANY_OF_WITH_SELECT = _objectSpread2(_objectSpread2({}, IS_NOT_ANY_OF), {}, {
1684
+ InputComponent: GridFilterInputMultipleSingleSelect
1685
+ });
1686
+
1687
+ const startsWithAnyOfOperator = {
1688
+ label: 'starts with any of',
1689
+ value: 'startsWithAnyOf',
1690
+ getApplyFilterFn: filterItem => {
1691
+ if (!filterItem.field || !filterItem.value || !filterItem.operator) {
1692
+ return null;
1693
+ }
1694
+ return params => {
1695
+ if (filterItem.value.length === 0) {
1696
+ return true;
1697
+ }
1698
+ const paramValues = Array.isArray(params.value) ? params.value : [params.value];
1699
+ let match = false;
1700
+ filterItem.value.forEach(filteredValue => {
1701
+ paramValues.forEach(paramValue => {
1702
+ if (String(paramValue).startsWith(filteredValue)) {
1703
+ match = true;
1704
+ }
1705
+ });
1706
+ });
1707
+ return match;
1708
+ };
1709
+ },
1710
+ InputComponent: GridFilterInputMultipleValue
1711
+ };
1712
+ const STARTS_WITH_ANY_OF = startsWithAnyOfOperator;
1713
+
1714
+ const doesNotHaveAnyOf = {
1715
+ label: "doesn't have any of",
1716
+ value: 'doesNotHaveAnyOf',
1717
+ getApplyFilterFn: filterItem => {
1718
+ if (!filterItem.field || !filterItem.value || !Array.isArray(filterItem.value) || filterItem.value.length === 0) {
1719
+ return null;
1720
+ }
1721
+ return params => {
1722
+ const cellValues = Array.isArray(params.value) ? params.value : [params.value];
1723
+
1724
+ // Return true only if none of the filter values are in the cell values
1725
+ return filterItem.value.every(filterVal => !cellValues.map(value => String(value)).includes(filterVal));
1726
+ };
1727
+ },
1728
+ InputComponent: GridFilterInputMultipleValue
1729
+ };
1730
+ const DOES_NOT_HAVE_ANY_OF = doesNotHaveAnyOf;
1731
+ const DOES_NOT_HAVE_ANY_OF_WITH_SELECT = _objectSpread2(_objectSpread2({}, DOES_NOT_HAVE_ANY_OF), {}, {
1732
+ InputComponent: GridFilterInputMultipleSingleSelect
1733
+ });
1734
+
1735
+ const getGridStringArrayOperators = () => [CONTAINS_ANY_OF, ENDS_WITH_ANY_OF, IS_ANY_OF, IS_NOT_ANY_OF, STARTS_WITH_ANY_OF];
1736
+ const getGridStringArrayOperatorsWithSelect = () => [CONTAINS_ANY_OF, ENDS_WITH_ANY_OF, IS_ANY_OF_WITH_SELECT, IS_ANY_OF_WITH_SELECT, IS_NOT_WITH_SELECT, IS_WITH_SELECT, STARTS_WITH_ANY_OF];
1737
+ const getGridStringArrayOperatorsWithSelectOnStringArrayColumns = () => [HAS_WITH_SELECT, HAS_ANY_OF_WITH_SELECT, HAS_ONLY_WITH_SELECT, DOES_NOT_HAVE_WITH_SELECT, DOES_NOT_HAVE_ANY_OF_WITH_SELECT];
1738
+
1739
+ const getGridStringOperators = () => [...getGridStringOperators$1().filter(operator => !['isAnyOf'].includes(operator.value)), DOES_NOT_CONTAIN, DOES_NOT_EQUAL, ...getGridStringArrayOperators()];
1740
+
1741
+ // istanbul ignore file
1742
+ const operatorList = {
1743
+ // Default types
1744
+ string: getGridStringOperators$1(),
1745
+ number: getGridNumericOperators$1(),
1746
+ boolean: getGridBooleanOperators(),
1747
+ date: getGridDateOperators(),
1748
+ dateTime: getGridDateOperators(true),
1749
+ singleSelect: getGridSingleSelectOperators(),
1750
+ // Extended types
1751
+ rsString: getGridStringOperators(),
1752
+ rsNumber: getGridNumericOperators(),
1753
+ rsSingleSelect: [CONTAINS_ANY_OF, ENDS_WITH_ANY_OF, IS_ANY_OF_WITH_SELECT, IS_NOT_WITH_SELECT, IS_WITH_SELECT, STARTS_WITH_ANY_OF],
1754
+ rsSingleSelectWithShortOperatorList: [IS_WITH_SELECT, IS_NOT_WITH_SELECT, IS_ANY_OF_WITH_SELECT],
1755
+ rsMultipleSelect: [HAS_WITH_SELECT, HAS_ANY_OF_WITH_SELECT, HAS_ONLY_WITH_SELECT, DOES_NOT_HAVE_WITH_SELECT, DOES_NOT_HAVE_ANY_OF_WITH_SELECT],
1756
+ rsMultipleSelectWithShortOperatorList: [HAS_WITH_SELECT, DOES_NOT_HAVE_WITH_SELECT, HAS_ANY_OF_WITH_SELECT],
1757
+ // Custom types
1758
+ rsStringArray: getGridStringArrayOperators()
1759
+ };
1760
+
1761
+ const PAGINATION_MODEL_KEY = 'paginationModel';
1762
+ const FILTER_MODEL_KEY = 'filterModel';
1763
+ const SORT_MODEL_KEY = 'sortModel';
1764
+ const VISIBILITY_MODEL_KEY = 'visibilityModel';
1765
+ const PINNED_COLUMNS = 'pinnedColumns';
1766
+ const DIMENSION_MODEL_KEY = 'dimension';
1767
+ const FILTER_SEARCH_KEY = 'searchModel';
1768
+ const CATEGORIES = [PAGINATION_MODEL_KEY, FILTER_MODEL_KEY, SORT_MODEL_KEY, VISIBILITY_MODEL_KEY, DIMENSION_MODEL_KEY, FILTER_SEARCH_KEY, PINNED_COLUMNS];
1769
+ const buildStorageKey = _ref => {
1770
+ let {
1771
+ id,
1772
+ version,
1773
+ category
1774
+ } = _ref;
1775
+ return `${id}:${version}:${category}`;
1776
+ };
1777
+ const clearPreviousVersionStorage = (id, previousLocalStorageVersions) => {
1778
+ for (const version of previousLocalStorageVersions) {
1779
+ const keysToDelete = [buildStorageKey({
1780
+ id,
1781
+ version,
1782
+ category: PAGINATION_MODEL_KEY
1783
+ }), buildStorageKey({
1784
+ id,
1785
+ version,
1786
+ category: SORT_MODEL_KEY
1787
+ }), buildStorageKey({
1788
+ id,
1789
+ version,
1790
+ category: FILTER_MODEL_KEY
1791
+ }), buildStorageKey({
1792
+ id,
1793
+ version,
1794
+ category: VISIBILITY_MODEL_KEY
1795
+ }), buildStorageKey({
1796
+ id,
1797
+ version,
1798
+ category: PINNED_COLUMNS
1799
+ }), buildStorageKey({
1800
+ id,
1801
+ version,
1802
+ category: FILTER_SEARCH_KEY
1803
+ }), buildStorageKey({
1804
+ id,
1805
+ version,
1806
+ category: DIMENSION_MODEL_KEY
1807
+ })];
1808
+ for (const keyToDelete of keysToDelete) {
1809
+ try {
1810
+ window.localStorage.removeItem(keyToDelete);
1811
+ } catch (e) {
1812
+ // Ignore
1813
+ }
1814
+ }
1815
+ }
1816
+ };
1817
+
1818
+ // reference value: https://www.w3schools.com/tags/ref_urlencode.ASP
1819
+ const DECODER = {
1820
+ '%20': ' ',
1821
+ '%26': '&',
1822
+ '%3D': '=',
1823
+ '%3F': '?',
1824
+ '%5B': '[',
1825
+ '%5D': ']',
1826
+ '%2C': ',',
1827
+ '%3C': '<',
1828
+ '%3E': '>',
1829
+ '%21': '!',
1830
+ '%22': '"'
1831
+ };
1832
+ const ENCODER = {
1833
+ ' ': '%20',
1834
+ '&': '%26',
1835
+ '=': '%3D',
1836
+ '?': '%3F',
1837
+ '[': '%5B',
1838
+ ']': '%5D',
1839
+ ',': '%2C',
1840
+ '<': '%3C',
1841
+ '>': '%3E',
1842
+ '!': '%21',
1843
+ '"': '%22'
1844
+ };
1845
+ const decodeValue = value => {
1846
+ if (value === '') {
1847
+ return '';
1848
+ }
1849
+ const re = new RegExp(Object.keys(DECODER).reduce((acc, curr) => `${acc}|${curr}`), 'g');
1850
+ // decodeValue for lists:
1851
+ if (value.startsWith('list[')) {
1852
+ const arrayValues = value.split('[')[1].split(']')[0];
1853
+ const arrayList = arrayValues.split(',').map(v => v.replace(re, encoded => DECODER[encoded])).filter(item => item);
1854
+ return arrayList.length > 0 ? arrayList : [];
1855
+ }
1856
+ return value.replace(re, encoded => DECODER[encoded]);
1857
+ };
1858
+ const encodeValue = value => {
1859
+ if (!value) {
1860
+ return '';
1861
+ }
1862
+
1863
+ // Array encoding for value:
1864
+ // we are representing it as list[encoded], where encoded is the list comma separated
1865
+ if (Array.isArray(value)) {
1866
+ const encodedArray = value.map(entry => {
1867
+ return String(entry).replace(/\s|&|=|\?|\[|\]/g, encoded => ENCODER[encoded]);
1868
+ }).join(',');
1869
+ return `list[${encodedArray}]`;
1870
+ }
1871
+
1872
+ // we might also pass integers
1873
+ const castedValue = String(value);
1874
+ return castedValue.replace(/\s|&|=|\?|\[|\]/g, encoded => ENCODER[encoded]);
1875
+ };
1876
+ const urlSearchParamsToString = searchParams => {
1877
+ let searchString = '';
1878
+ for (const [key, value] of searchParams) {
1879
+ searchString = searchString + `${key}=${value}&`;
1880
+ }
1881
+ return searchString.slice(0, searchString.length - 1);
1882
+ };
1883
+ const numberOperatorEncoder = {
1884
+ '=': 'eq',
1885
+ '!=': 'ne',
1886
+ '>': 'gt',
1887
+ '>=': 'gte',
1888
+ '<': 'lt',
1889
+ '<=': 'lte'
1890
+ };
1891
+ const numberOperatorDecoder = {
1892
+ eq: '=',
1893
+ ne: '!=',
1894
+ gt: '>',
1895
+ gte: '>=',
1896
+ lt: '<',
1897
+ lte: '<='
1898
+ };
1899
+ const isOperatorValueValid = (field, operator, columns) => {
1900
+ const column = columns.find(column => column.field === field);
1901
+ if (!column) {
1902
+ return false;
1903
+ }
1904
+ const columnType = (column === null || column === void 0 ? void 0 : column.type) || 'string';
1905
+ const operators = column.filterOperators || operatorList[columnType];
1906
+ if (!operators) {
1907
+ return false;
1908
+ }
1909
+ return !!operators.find(op => columnType === 'number' && Object.keys(numberOperatorEncoder).includes(op.value) ? numberOperatorEncoder[op.value] === operator : op.value === operator);
1910
+ };
1911
+ const listOperators = ['containsAnyOf', 'doesNotContainAnyOf', 'endsWithAnyOf', 'doesNotEndWithAnyOf', 'hasAnyOf', 'doesNotHaveAnyOf', 'isAnyOf', 'isNotAnyOf', 'startsWithAnyOf', 'doesNotStartWithAnyOf'];
1912
+
1913
+ // Check if the value doesn't break
1914
+ const isValueValid = (value, field, columns, operator) => {
1915
+ var _column$type;
1916
+ // every field accepts undefined as value for default
1917
+ if (value === undefined || value === '') {
1918
+ return true;
1919
+ }
1920
+
1921
+ // xxxAnyOf accepts as value only lists, and we are declaring them in the
1922
+ // URL as `list=[...]`
1923
+ if (listOperators.includes(operator)) {
1924
+ return Array.isArray(value) || value === '';
1925
+ }
1926
+
1927
+ // We are accepting arrays only if they are of the 'xxxAnyOf' type
1928
+ if (Array.isArray(value) && !listOperators.includes(operator)) {
1929
+ return false;
1930
+ }
1931
+ const column = columns.find(column => column.field === field);
1932
+ if (!column) {
1933
+ return false;
1934
+ }
1935
+ const type = (_column$type = column['type']) !== null && _column$type !== void 0 ? _column$type : 'string';
1936
+
1937
+ // Only date and rating fail with 500s, other set themselves as undefined
1938
+ if (type !== 'date' && type !== 'rating') {
1939
+ return true;
1940
+ }
1941
+
1942
+ // just checking that rating is a number.
1943
+ if (type === 'rating') {
1944
+ return !isNaN(Number(value));
1945
+ }
1946
+
1947
+ // format: YYYY-MM-DD
1948
+ // just verifying that the 3 values are numbers to avoid 500s,
1949
+ // If the value is invalid the form will appear as undefined
1950
+ if (type === 'date') {
1951
+ const dateSplitted = value.split('-');
1952
+ if (dateSplitted.length !== 3) {
1953
+ return false;
1954
+ }
1955
+ const [YYYY, MM, DD] = dateSplitted;
1956
+ return !isNaN(parseInt(YYYY)) && !isNaN(parseInt(MM)) && !isNaN(parseInt(DD));
1957
+ }
1958
+ return false;
1959
+ };
1960
+
1961
+ /** FILTERS */
1962
+
1963
+ // example:
1964
+ // unicodeDomain[contains]=a&unicodeDomain[contains]=dsa&logicOperator=and&tab=ignored
1965
+ const getFilterModelFromString = (searchString, columns) => {
1966
+ if (!searchString) {
1967
+ return 'invalid';
1968
+ }
1969
+ let logicOperator = GridLogicOperator.And;
1970
+ let quickFilterValues = [];
1971
+ const searchParams = new URLSearchParams();
1972
+ for (const [key, value] of new URLSearchParams(searchString)) {
1973
+ if (key.startsWith('_') && !['_logicOperator', '_sortColumn', '_pinnedColumnsLeft', '_pinnedColumnsRight', '_columnVisibility', '_pagination', '_quickFilterValues'].includes(key)) {
1974
+ searchParams.set(key, value);
1975
+ }
1976
+ if (key === '_logicOperator') {
1977
+ logicOperator = value === GridLogicOperator.And || value === GridLogicOperator.Or ? value : GridLogicOperator.And;
1978
+ }
1979
+ if (key === '_quickFilterValues') {
1980
+ try {
1981
+ quickFilterValues = JSON.parse(decodeURIComponent(value));
1982
+ } catch {
1983
+ quickFilterValues = [];
1984
+ }
1985
+ }
1986
+ }
1987
+ let id = 5000;
1988
+ const fields = columns.map(column => column.field);
1989
+ let isInvalid = false;
1990
+ const items = [];
1991
+ searchParams.forEach((value, key) => {
1992
+ var _columns$find;
1993
+ if (isInvalid) {
1994
+ return;
1995
+ }
1996
+ const field = key.split('[')[0].slice(1);
1997
+ if (!fields.includes(field)) {
1998
+ return;
1999
+ }
2000
+ const columnType = (_columns$find = columns.find(column => column.field === field)) === null || _columns$find === void 0 ? void 0 : _columns$find.type;
2001
+ const left = key.split(']')[0];
2002
+ if (left.split('[').length < 2) {
2003
+ isInvalid = true;
2004
+ return;
2005
+ }
2006
+ const splitRight = key.split('[')[1].split(']')[0].split(',');
2007
+ const type = splitRight[1];
2008
+ if (type !== columnType) {
2009
+ isInvalid = true;
2010
+ return;
2011
+ }
2012
+ const operator = splitRight[0];
2013
+ if (!isOperatorValueValid(field, operator, columns) || Array.isArray(operator)) {
2014
+ isInvalid = true;
2015
+ return;
2016
+ }
2017
+ id += 1;
2018
+ const decodedValue = decodeValue(value);
2019
+ if (!isValueValid(decodedValue, field, columns, operator)) {
2020
+ isInvalid = true;
2021
+ return;
2022
+ }
2023
+ items.push({
2024
+ field,
2025
+ operator: columnType === 'number' && Object.keys(numberOperatorDecoder).includes(operator) ? numberOperatorDecoder[operator] : operator,
2026
+ id,
2027
+ value: listOperators.includes(operator) && decodedValue === '' ? [] : decodedValue,
2028
+ type
2029
+ });
2030
+ });
2031
+ if (isInvalid) {
2032
+ return 'invalid';
2033
+ }
2034
+ return {
2035
+ items,
2036
+ logicOperator,
2037
+ quickFilterValues
2038
+ };
2039
+ };
2040
+ const getSearchParamsFromFilterModel = filterModel => {
2041
+ var _filterModel$quickFil;
2042
+ const searchParams = new URLSearchParams();
2043
+ searchParams.set('_logicOperator', filterModel['logicOperator'] || '');
2044
+ filterModel['items'].forEach(item => {
2045
+ const {
2046
+ field,
2047
+ operator,
2048
+ value,
2049
+ type
2050
+ } = item;
2051
+ if (Object.keys(numberOperatorEncoder).includes(operator)) {
2052
+ searchParams.set(`_${field}[${numberOperatorEncoder[operator]},${encodeValue(type)}]`, encodeValue(value));
2053
+ } else {
2054
+ searchParams.set(`_${field}[${encodeValue(operator)},${encodeValue(type)}]`, encodeValue(value));
2055
+ }
2056
+ });
2057
+ if ((_filterModel$quickFil = filterModel.quickFilterValues) !== null && _filterModel$quickFil !== void 0 && _filterModel$quickFil.length) {
2058
+ searchParams.set('_quickFilterValues', encodeURIComponent(JSON.stringify(filterModel.quickFilterValues)));
2059
+ }
2060
+ return searchParams;
2061
+ };
2062
+
2063
+ // Rules:
2064
+ // - if we have something in the URL, use that info
2065
+ // - if we don't have that, use the localStorage and update the URL
2066
+ // - if we don't have that, return an empty FilterModel
2067
+ const getFilterModel = (search, columns, localStorageFilters, setLocalStorageFilters, initialState, isNewVersion) => {
2068
+ const defaultValue = initialState && initialState.filter && initialState.filter.filterModel ? initialState.filter.filterModel : {
2069
+ items: [],
2070
+ logicOperator: GridLogicOperator.And
2071
+ };
2072
+ if (isNewVersion) {
2073
+ return defaultValue;
2074
+ }
2075
+ const filterModelFromSearch = getFilterModelFromString(search, columns);
2076
+ if (filterModelFromSearch !== 'invalid') {
2077
+ const searchFromFilterModel = getSearchParamsFromFilterModel(filterModelFromSearch);
2078
+ const searchString = urlSearchParamsToString(searchFromFilterModel);
2079
+ if (searchString !== localStorageFilters) {
2080
+ setLocalStorageFilters(searchString);
2081
+ }
2082
+ return filterModelFromSearch;
2083
+ }
2084
+ const filterModelFromLocalStorage = getFilterModelFromString(localStorageFilters, columns);
2085
+ if (filterModelFromLocalStorage !== 'invalid') {
2086
+ return filterModelFromLocalStorage;
2087
+ }
2088
+ return defaultValue;
2089
+ };
2090
+
2091
+ /** SORT */
2092
+
2093
+ const getSortingFromString = (searchString, columns) => {
2094
+ if (!searchString) {
2095
+ return 'invalid';
2096
+ }
2097
+ const searchParams = new URLSearchParams(searchString);
2098
+ const value = searchParams.get('_sortColumn');
2099
+ if (value === '' || value === null || value === '[]') {
2100
+ return [];
2101
+ }
2102
+ const fields = columns.map(column => column.field);
2103
+ const [column, order] = value.slice(1, value.length - 1).split(',');
2104
+ if (fields.includes(column) && (order === 'asc' || order === 'desc')) {
2105
+ return [{
2106
+ field: column,
2107
+ sort: order
2108
+ }];
2109
+ }
2110
+ return 'invalid';
2111
+ };
2112
+ const getSearchParamsFromSorting = sorting => {
2113
+ const searchParams = new URLSearchParams();
2114
+ searchParams.set('_sortColumn', sorting.length > 0 && sorting[0].sort ? `[${encodeValue(sorting[0].field)},${encodeValue(sorting[0].sort)}]` : '[]');
2115
+ return searchParams;
2116
+ };
2117
+
2118
+ // Rules:
2119
+ // - if we have something in the URL, use that info
2120
+ // - if we don't have that, use the localStorage and update the URL
2121
+ // - if we don't have that, return an empty SortModel
2122
+ const getSortModel = (search, columns, localStorageSorting, setLocalStorageSorting, initialState, isNewVersion) => {
2123
+ var _initialState$sorting;
2124
+ const defaultValue = initialState !== null && initialState !== void 0 && (_initialState$sorting = initialState.sorting) !== null && _initialState$sorting !== void 0 && _initialState$sorting.sortModel ? initialState.sorting.sortModel : [];
2125
+ if (isNewVersion) {
2126
+ return defaultValue;
2127
+ }
2128
+ const sorting = getSortingFromString(search, columns);
2129
+ if (sorting !== 'invalid') {
2130
+ const searchFromSortModel = getSearchParamsFromSorting(sorting);
2131
+ const searchString = urlSearchParamsToString(searchFromSortModel);
2132
+ if (searchString !== localStorageSorting) {
2133
+ setLocalStorageSorting(searchString);
2134
+ }
2135
+ return sorting;
2136
+ }
2137
+ const sortModelFromLocalStorage = getSortingFromString(localStorageSorting, columns);
2138
+ if (sortModelFromLocalStorage !== 'invalid') {
2139
+ return sortModelFromLocalStorage;
2140
+ }
2141
+ return defaultValue;
2142
+ };
2143
+
2144
+ /** PAGINATION */
2145
+
2146
+ const getPaginationFromString = searchString => {
2147
+ if (!searchString) {
2148
+ return 'invalid';
2149
+ }
2150
+ const searchParams = new URLSearchParams(searchString);
2151
+ const value = searchParams.get('_pagination');
2152
+ if (value === '' || value === null || value === '[]') {
2153
+ return 'invalid';
2154
+ }
2155
+ const pagination = value.slice(1, value.length - 1).split(',');
2156
+ const page = parseFloat(pagination[0]);
2157
+ const pageSize = parseFloat(pagination[1]);
2158
+ const direction = pagination[2];
2159
+ if (!Number.isNaN(page) && !Number.isNaN(pageSize) && direction && ['next', 'back'].includes(direction)) {
2160
+ return {
2161
+ page,
2162
+ pageSize,
2163
+ direction: direction
2164
+ };
2165
+ }
2166
+ return 'invalid';
2167
+ };
2168
+ const getSearchParamsFromPagination = pagination => {
2169
+ const searchParams = new URLSearchParams();
2170
+ searchParams.set('_pagination', `[${pagination.page},${pagination.pageSize},${pagination.direction}]`);
2171
+ return searchParams;
2172
+ };
2173
+
2174
+ // Rules:
2175
+ // - if we have something in the URL, use that info
2176
+ // - if we don't have that, use the localStorage and update the URL
2177
+ // - if we don't have that, return an empty PaginationModel
2178
+ const getPaginationModel = (search, localStoragePagination, setLocalStoragePagination, initialState, isNewVersion) => {
2179
+ const defaultValue = initialState !== null && initialState !== void 0 && initialState.pagination ? _objectSpread2({
2180
+ page: 0,
2181
+ pageSize: 25,
2182
+ direction: 'next'
2183
+ }, initialState.pagination) : {
2184
+ page: 0,
2185
+ pageSize: 25,
2186
+ direction: 'next'
2187
+ };
2188
+ if (isNewVersion) {
2189
+ return defaultValue;
2190
+ }
2191
+ const pagination = getPaginationFromString(search);
2192
+ if (pagination !== 'invalid') {
2193
+ const searchFromPaginationModel = getSearchParamsFromPagination(pagination);
2194
+ const searchString = urlSearchParamsToString(searchFromPaginationModel);
2195
+ if (searchString !== localStoragePagination) {
2196
+ setLocalStoragePagination(searchString);
2197
+ }
2198
+ return pagination;
2199
+ }
2200
+ const paginationModelFromLocalStorage = getPaginationFromString(localStoragePagination);
2201
+ if (paginationModelFromLocalStorage !== 'invalid') {
2202
+ return paginationModelFromLocalStorage;
2203
+ }
2204
+ return defaultValue;
2205
+ };
2206
+
2207
+ /** COLUMN VISIBILITY */
2208
+
2209
+ const getColumnVisibilityFromString = (searchString, columns) => {
2210
+ if (!searchString) {
2211
+ return 'invalid';
2212
+ }
2213
+ const searchParams = new URLSearchParams(searchString);
2214
+ const value = searchParams.get('_columnVisibility');
2215
+ if (value === '' || value === null || value === '[]') {
2216
+ return 'invalid';
2217
+ }
2218
+ const parsedFields = value.slice(1, value.length - 1).split(',');
2219
+ const fields = columns.map(column => column.field);
2220
+ const visibility = {};
2221
+ for (const field of fields) {
2222
+ visibility[field] = false;
2223
+ }
2224
+ for (const parsedField of parsedFields) {
2225
+ if (fields.includes(parsedField)) {
2226
+ visibility[parsedField] = true;
2227
+ }
2228
+ }
2229
+ if (Object.values(visibility).filter(v => v === true).length === 0) {
2230
+ return 'invalid';
2231
+ }
2232
+ return visibility;
2233
+ };
2234
+ const getSearchParamsFromColumnVisibility = (columnVisibility, columns) => {
2235
+ const searchParams = new URLSearchParams();
2236
+ const fields = columns.map(column => column.field);
2237
+
2238
+ // if column visibility model is empty, show all columns
2239
+ if (Object.keys(columnVisibility).length == 0) {
2240
+ searchParams.set('_columnVisibility', `[${fields.join(',')}]`);
2241
+ return searchParams;
2242
+ }
2243
+ const finalColumnVisibility = columns.filter(c => {
2244
+ var _c$hideable;
2245
+ return !((_c$hideable = c === null || c === void 0 ? void 0 : c.hideable) !== null && _c$hideable !== void 0 ? _c$hideable : true);
2246
+ }).map(c => c.field).reduce((acc, colName) => {
2247
+ return _objectSpread2(_objectSpread2({}, acc), {}, {
2248
+ [colName]: true
2249
+ });
2250
+ }, columnVisibility);
2251
+ const visibleColumns = fields.filter(column => finalColumnVisibility[column] !== false);
2252
+ searchParams.set('_columnVisibility', `[${visibleColumns.join(',')}]`);
2253
+ return searchParams;
2254
+ };
2255
+
2256
+ // Rules:
2257
+ // - if we have something in the URL, use that info
2258
+ // - if we don't have that, use the localStorage and update the URL
2259
+ // - if we don't have that, return an empty ColumnVisibilityModel (which is all columns)
2260
+ // NOTE: the `defaultHidden` is a custom field and not standard DataGrid
2261
+ // The reason is the following bug: https://github.com/mui/mui-x/issues/8407
2262
+ const getColumnsVisibility = (search, columns, localStorageColumnsVisibility, setLocalStorageColumnsVisibility, initialState, isNewVersion) => {
2263
+ var _initialState$columns3;
2264
+ const defaultValue = {};
2265
+ for (const column of columns) {
2266
+ var _initialState$columns, _initialState$columns2;
2267
+ const field = column.field;
2268
+ if ((initialState === null || initialState === void 0 ? void 0 : (_initialState$columns = initialState.columns) === null || _initialState$columns === void 0 ? void 0 : (_initialState$columns2 = _initialState$columns.columnVisibilityModel) === null || _initialState$columns2 === void 0 ? void 0 : _initialState$columns2[field]) !== undefined) {
2269
+ defaultValue[field] = initialState.columns.columnVisibilityModel[field];
2270
+ } else {
2271
+ defaultValue[field] = column.defaultHidden !== true; // undefined will be true
2272
+ }
2273
+ }
2274
+
2275
+ if (isNewVersion) {
2276
+ return defaultValue;
2277
+ }
2278
+ const columnVisibility = getColumnVisibilityFromString(search, columns);
2279
+ if (columnVisibility !== 'invalid') {
2280
+ const searchColumnVisibility = getSearchParamsFromColumnVisibility(columnVisibility, columns);
2281
+ if (searchColumnVisibility.toString() !== localStorageColumnsVisibility) {
2282
+ setLocalStorageColumnsVisibility(searchColumnVisibility.toString());
2283
+ }
2284
+ return columnVisibility;
2285
+ }
2286
+ const columnVisibilityFromLocalStorage = getColumnVisibilityFromString(localStorageColumnsVisibility, columns);
2287
+ if (columnVisibilityFromLocalStorage !== 'invalid') {
2288
+ return columnVisibilityFromLocalStorage;
2289
+ }
2290
+ if (initialState !== null && initialState !== void 0 && (_initialState$columns3 = initialState.columns) !== null && _initialState$columns3 !== void 0 && _initialState$columns3.columnVisibilityModel) {
2291
+ return initialState.columns.columnVisibilityModel;
2292
+ }
2293
+ return defaultValue;
2294
+ };
2295
+ const getPinnedColumnsFromString = (notParsed, tableColumns) => {
2296
+ if (!notParsed || notParsed.length === 1 && notParsed[0] === '?') {
2297
+ return 'invalid';
2298
+ }
2299
+ // remove the initial ? if present
2300
+ const parsed = notParsed[0] === '?' ? notParsed.slice(1) : notParsed;
2301
+ const pinnedColumns = {};
2302
+ for (const item of parsed.split('&')) {
2303
+ const fieldURL = item.split('=')[0];
2304
+ if (fieldURL !== '_pinnedColumnsLeft' && fieldURL !== '_pinnedColumnsRight') {
2305
+ continue;
2306
+ }
2307
+ const left = item.split(']')[0];
2308
+ if (left.split('[').length < 2) {
2309
+ continue;
2310
+ }
2311
+ const encodedValues = item.split('[')[1].split(']')[0];
2312
+ if (typeof encodedValues !== 'string') {
2313
+ continue;
2314
+ }
2315
+ const fields = [...tableColumns.map(column => column.field), '__check__'];
2316
+ const columns = encodedValues.split(',').map(value => decodeValue(value)).filter(val => typeof val === 'string' && fields.includes(val));
2317
+ if (fieldURL === '_pinnedColumnsLeft') {
2318
+ pinnedColumns['left'] = columns;
2319
+ }
2320
+ if (fieldURL === '_pinnedColumnsRight') {
2321
+ pinnedColumns['right'] = columns;
2322
+ }
2323
+ }
2324
+ return pinnedColumns.left && pinnedColumns.left.length > 0 || pinnedColumns.right && pinnedColumns.right.length > 0 ? {
2325
+ left: pinnedColumns.left || [],
2326
+ right: pinnedColumns.right || []
2327
+ } : 'invalid';
2328
+ };
2329
+ const getSearchParamsFromPinnedColumns = pinnedColumns => {
2330
+ var _pinnedColumns$left, _pinnedColumns$right;
2331
+ const searchParams = new URLSearchParams();
2332
+ const pinnedColumnLeft = ((_pinnedColumns$left = pinnedColumns.left) === null || _pinnedColumns$left === void 0 ? void 0 : _pinnedColumns$left.map(val => encodeValue(val))) || [];
2333
+ const pinnedColumnRight = ((_pinnedColumns$right = pinnedColumns.right) === null || _pinnedColumns$right === void 0 ? void 0 : _pinnedColumns$right.map(val => encodeValue(val))) || [];
2334
+ searchParams.set('_pinnedColumnsLeft', `[${pinnedColumnLeft.join(',')}]`);
2335
+ searchParams.set('_pinnedColumnsRight', `[${pinnedColumnRight.join(',')}]`);
2336
+ return searchParams;
2337
+ };
2338
+
2339
+ // Rules:
2340
+ // - if we have something in the URL, use that info
2341
+ // - if we don't have that, use the localStorage and update the URL
2342
+ // - if we don't have that, return an empty ColumnVisibilityModel (which is all columns)
2343
+ const getPinnedColumns = (search, columns, localStoragePinnedColumns, setLocalStoragePinnedColumns, initialState, isNewVersion) => {
2344
+ const defaultValue = initialState !== null && initialState !== void 0 && initialState.pinnedColumns ? {
2345
+ left: (initialState === null || initialState === void 0 ? void 0 : initialState.pinnedColumns['left']) || [],
2346
+ right: (initialState === null || initialState === void 0 ? void 0 : initialState.pinnedColumns['right']) || []
2347
+ } : {
2348
+ left: [],
2349
+ right: []
2350
+ };
2351
+ if (isNewVersion) {
2352
+ return defaultValue;
2353
+ }
2354
+ const pinnedColumns = getPinnedColumnsFromString(search, columns);
2355
+ if (pinnedColumns !== 'invalid') {
2356
+ const searchPinnedColumns = getSearchParamsFromPinnedColumns(pinnedColumns);
2357
+ if (searchPinnedColumns.toString() !== localStoragePinnedColumns) {
2358
+ setLocalStoragePinnedColumns(searchPinnedColumns.toString());
2359
+ }
2360
+ return pinnedColumns;
2361
+ }
2362
+ const pinnedColumnsFromLocalStorage = getPinnedColumnsFromString(localStoragePinnedColumns, columns);
2363
+ if (pinnedColumnsFromLocalStorage !== 'invalid') {
2364
+ return pinnedColumnsFromLocalStorage;
2365
+ }
2366
+ return defaultValue;
2367
+ };
2368
+ const getSearchParamsFromTab = search => {
2369
+ const searchParams = new URLSearchParams();
2370
+ const openTab = new URLSearchParams(search).get('tab');
2371
+ if (openTab) {
2372
+ searchParams.set('tab', openTab);
2373
+ }
2374
+ return searchParams;
2375
+ };
2376
+ const getFinalSearch = _ref => {
2377
+ let {
2378
+ search,
2379
+ localStorageVersion,
2380
+ filterModel,
2381
+ sortModel,
2382
+ paginationModel,
2383
+ columnsVisibilityModel,
2384
+ pinnedColumnsModel,
2385
+ columns
2386
+ } = _ref;
2387
+ const filterModelSearch = getSearchParamsFromFilterModel(filterModel);
2388
+ const sortModelSearch = getSearchParamsFromSorting(sortModel);
2389
+ const paginationModelSearch = getSearchParamsFromPagination(paginationModel);
2390
+ const columnVisibilityModelSearch = getSearchParamsFromColumnVisibility(columnsVisibilityModel, columns);
2391
+ const pinnedColumnsModelSearch = getSearchParamsFromPinnedColumns(pinnedColumnsModel);
2392
+ const tabSearch = getSearchParamsFromTab(search);
2393
+ const searchParams = new URLSearchParams();
2394
+ for (const [key, value] of new URLSearchParams(search)) {
2395
+ if (!key.startsWith('_')) {
2396
+ searchParams.set(key, value);
2397
+ }
2398
+ }
2399
+ searchParams.set('v', `${localStorageVersion}`);
2400
+
2401
+ // Add quickFilterValues explicitly if present in filterModel
2402
+ if (filterModel.quickFilterValues && filterModel.quickFilterValues.length > 0) {
2403
+ // Encode array as JSON string to preserve all values in one param
2404
+ searchParams.set('_quickFilterValues', encodeURIComponent(JSON.stringify(filterModel.quickFilterValues)));
2405
+ }
2406
+ return new URLSearchParams([...searchParams, ...filterModelSearch, ...sortModelSearch, ...paginationModelSearch, ...tabSearch, ...pinnedColumnsModelSearch, ...columnVisibilityModelSearch]);
2407
+ };
2408
+ /** Return the state of the table given the URL and the local storage state */
2409
+ const getModelsParsedOrUpdateLocalStorage = (search, localStorageVersion, columns, historyReplace, initialState, localStorage) => {
2410
+ const currentVersion = new URLSearchParams(search).get('v');
2411
+ const isNewVersion = !currentVersion || Number(currentVersion) !== localStorageVersion;
2412
+ const {
2413
+ localStorageFilters,
2414
+ setLocalStorageFilters,
2415
+ localStorageSorting,
2416
+ setLocalStorageSorting,
2417
+ localStoragePagination,
2418
+ setLocalStoragePagination,
2419
+ localStorageColumnsVisibility,
2420
+ setLocalStorageColumnsVisibility,
2421
+ localStoragePinnedColumns,
2422
+ setLocalStoragePinnedColumns
2423
+ } = localStorage;
2424
+ const filterModel = getFilterModel(search, columns, localStorageFilters, setLocalStorageFilters, initialState, isNewVersion);
2425
+ const sortModel = getSortModel(search, columns, localStorageSorting, setLocalStorageSorting, initialState, isNewVersion);
2426
+ const paginationModel = getPaginationModel(search, localStoragePagination, setLocalStoragePagination, initialState, isNewVersion);
2427
+ const columnVisibilityModel = getColumnsVisibility(search, columns, localStorageColumnsVisibility, setLocalStorageColumnsVisibility, initialState, isNewVersion);
2428
+ const pinnedColumnsModel = getPinnedColumns(search, columns, localStoragePinnedColumns, setLocalStoragePinnedColumns, initialState, isNewVersion);
2429
+ const finalSearch = getFinalSearch({
2430
+ localStorageVersion,
2431
+ search,
2432
+ filterModel,
2433
+ sortModel,
2434
+ paginationModel,
2435
+ columnsVisibilityModel: columnVisibilityModel,
2436
+ pinnedColumnsModel,
2437
+ columns
2438
+ });
2439
+ const searchString = urlSearchParamsToString(finalSearch);
2440
+ if (searchString !== search) {
2441
+ historyReplace(searchString);
2442
+ }
2443
+ return {
2444
+ filterModel,
2445
+ sortModel,
2446
+ paginationModel,
2447
+ columnVisibilityModel,
2448
+ pinnedColumnsModel
2449
+ };
2450
+ };
2451
+ const updateUrl = (_ref2, search, localStorageVersion, historyReplace, columns) => {
2452
+ let {
2453
+ filterModel,
2454
+ sortModel,
2455
+ paginationModel,
2456
+ columnsModel: columnsVisibilityModel,
2457
+ pinnedColumnsModel
2458
+ } = _ref2;
2459
+ const newSearch = getFinalSearch({
2460
+ search,
2461
+ localStorageVersion,
2462
+ filterModel,
2463
+ sortModel,
2464
+ paginationModel,
2465
+ columnsVisibilityModel,
2466
+ pinnedColumnsModel,
2467
+ columns
2468
+ });
2469
+ const searchString = urlSearchParamsToString(newSearch);
2470
+ if (searchString !== search) {
2471
+ historyReplace(searchString);
2472
+ }
2473
+ };
2474
+
2475
+ // Note: this is a comparator to sort the filters, not pure comparison
2476
+ // do not use it for equivalence (e.g. with value `3` and undefined we
2477
+ // will get 0).
2478
+ const compareFilters = (firstFilter, secondFilter) => {
2479
+ if (firstFilter.field < secondFilter.field) {
2480
+ return -1;
2481
+ } else if (firstFilter.field > secondFilter.field) {
2482
+ return 1;
2483
+ }
2484
+ if (firstFilter.operator === undefined || secondFilter.operator === undefined) {
2485
+ return 0;
2486
+ }
2487
+ if (firstFilter.operator < secondFilter.operator) {
2488
+ return -1;
2489
+ } else if (firstFilter.operator > secondFilter.operator) {
2490
+ return 1;
2491
+ }
2492
+ if (firstFilter.value < secondFilter.value) {
2493
+ return -1;
2494
+ } else if (firstFilter.value > secondFilter.value) {
2495
+ return 1;
2496
+ }
2497
+ return 0;
2498
+ };
2499
+ const areFiltersEquivalent = (firstFilter, secondFilter) => {
2500
+ return firstFilter.field === secondFilter.field && firstFilter.operator === secondFilter.operator && firstFilter.value === secondFilter.value;
2501
+ };
2502
+ const areFilterModelsEquivalent = (filterModel, filterModelToMatch) => {
2503
+ const {
2504
+ items,
2505
+ logicOperator
2506
+ } = filterModel;
2507
+ const {
2508
+ items: itemsToMatch,
2509
+ logicOperator: logicOperatorToMatch
2510
+ } = filterModelToMatch;
2511
+ if (logicOperator !== logicOperatorToMatch) {
2512
+ return false;
2513
+ }
2514
+ if (items.length !== itemsToMatch.length) {
2515
+ return false;
2516
+ }
2517
+ items.sort(compareFilters);
2518
+ itemsToMatch.sort(compareFilters);
2519
+ for (let i = 0; i < items.length; i++) {
2520
+ const filter = items[i];
2521
+ const filterToCompare = itemsToMatch[i];
2522
+
2523
+ // compareFilters return 0 if and only if the filters have the same
2524
+ // field, operator, and value
2525
+ if (!areFiltersEquivalent(filter, filterToCompare)) {
2526
+ return false;
2527
+ }
2528
+ }
2529
+ return true;
2530
+ };
2531
+
2532
+ // Get and Set data from LocalStorage WITHOUT useState
2533
+ const useFetchState = (defaultValue, key) => {
2534
+ let stickyValue = null;
2535
+ try {
2536
+ stickyValue = window.localStorage.getItem(key);
2537
+ } catch (e) {
2538
+ console.error('StatefulDataGrid: error getting item from local storage: ', e);
2539
+ }
2540
+ const parsedValue = stickyValue !== null && stickyValue !== undefined && stickyValue !== 'undefined' ? JSON.parse(stickyValue) : defaultValue;
2541
+ const updateValue = useCallback(value => {
2542
+ try {
2543
+ window.localStorage.setItem(key, JSON.stringify(value));
2544
+ } catch (e) {
2545
+ console.error('StatefulDataGrid: error setting item into local storage: ', e);
2546
+ }
2547
+ }, [key]);
2548
+ return [parsedValue, updateValue];
2549
+ };
2550
+
2551
+ // import useLocalStorage from './useLocalStorage';
2552
+
2553
+ const useTableStates = (id, version) => {
2554
+ const [paginationModel, setPaginationModel] = useFetchState('', buildStorageKey({
2555
+ id,
2556
+ version,
2557
+ category: PAGINATION_MODEL_KEY
2558
+ }));
2559
+ const [sortModel, setSortModel] = useFetchState('', buildStorageKey({
2560
+ id,
2561
+ version,
2562
+ category: SORT_MODEL_KEY
2563
+ }));
2564
+ const [localStorageFilters, setLocalStorageFilters] = useFetchState('', buildStorageKey({
2565
+ id,
2566
+ version,
2567
+ category: FILTER_SEARCH_KEY
2568
+ }));
2569
+ const [visibilityModelLocalStorage, setVisibilityModelLocalStorage] = useFetchState('', buildStorageKey({
2570
+ id,
2571
+ version,
2572
+ category: VISIBILITY_MODEL_KEY
2573
+ }));
2574
+ const [pinnedColumns, setPinnedColumns] = useFetchState('_pinnedColumnsLeft=[]&_pinnedColumnsRight=[]', buildStorageKey({
2575
+ id,
2576
+ version,
2577
+ category: PINNED_COLUMNS
2578
+ }));
2579
+ const [dimensionModel, setDimensionModel] = useFetchState({}, buildStorageKey({
2580
+ id,
2581
+ version,
2582
+ category: DIMENSION_MODEL_KEY
2583
+ }));
2584
+ return {
2585
+ paginationModel,
2586
+ setPaginationModel,
2587
+ sortModel,
2588
+ setSortModel,
2589
+ localStorageFilters,
2590
+ setLocalStorageFilters,
2591
+ visibilityModelLocalStorage,
2592
+ setVisibilityModelLocalStorage,
2593
+ pinnedColumns,
2594
+ setPinnedColumns,
2595
+ dimensionModel,
2596
+ setDimensionModel
2597
+ };
2598
+ };
2599
+
2600
+ const useStatefulTable = props => {
2601
+ const {
2602
+ // density = 'standard',
2603
+ apiRef,
2604
+ initialState,
2605
+ columns: propsColumns,
2606
+ onColumnVisibilityModelChange: propsOnColumnVisibilityModelChange,
2607
+ onColumnWidthChange: propsOnColumnWidthChange,
2608
+ onFilterModelChange: propsOnFilterModelChange,
2609
+ onPaginationModelChange: propsOnPaginationModelChange,
2610
+ onPinnedColumnsChange: propsOnPinnedColumnsChange,
2611
+ onSortModelChange: propsOnSortModelChange,
2612
+ useRouter,
2613
+ localStorageVersion = 1,
2614
+ previousLocalStorageVersions = []
2615
+ } = props;
2616
+ const {
2617
+ search,
2618
+ pathname,
2619
+ historyReplace
2620
+ } = useRouter();
2621
+ const id = pathname;
2622
+
2623
+ // States and setters persisted in the local storage for this table
2624
+ const {
2625
+ paginationModel,
2626
+ setPaginationModel,
2627
+ sortModel,
2628
+ setSortModel,
2629
+ localStorageFilters,
2630
+ setLocalStorageFilters,
2631
+ visibilityModelLocalStorage,
2632
+ setVisibilityModelLocalStorage,
2633
+ pinnedColumns,
2634
+ setPinnedColumns,
2635
+ dimensionModel,
2636
+ setDimensionModel
2637
+ } = useTableStates(id, localStorageVersion);
2638
+
2639
+ // clearing up old version keys, triggering only on first render
2640
+ useEffect(() => clearPreviousVersionStorage(id, previousLocalStorageVersions), [id, previousLocalStorageVersions]);
2641
+ const onColumnDimensionChange = useCallback(_ref => {
2642
+ let {
2643
+ newWidth,
2644
+ field
2645
+ } = _ref;
2646
+ setDimensionModel(_objectSpread2(_objectSpread2({}, dimensionModel), {}, {
2647
+ [field]: newWidth
2648
+ }));
2649
+ }, [dimensionModel, setDimensionModel]);
2650
+ const {
2651
+ filterModel: filterParsed,
2652
+ sortModel: sortModelParsed,
2653
+ paginationModel: paginationModelParsed,
2654
+ columnVisibilityModel: visibilityModel,
2655
+ pinnedColumnsModel
2656
+ } = getModelsParsedOrUpdateLocalStorage(search || '', localStorageVersion, propsColumns, historyReplace, initialState, {
2657
+ localStorageFilters,
2658
+ setLocalStorageFilters,
2659
+ localStorageSorting: sortModel,
2660
+ setLocalStorageSorting: setSortModel,
2661
+ localStoragePagination: paginationModel,
2662
+ setLocalStoragePagination: setPaginationModel,
2663
+ localStorageColumnsVisibility: visibilityModelLocalStorage,
2664
+ setLocalStorageColumnsVisibility: setVisibilityModelLocalStorage,
2665
+ localStoragePinnedColumns: pinnedColumns,
2666
+ setLocalStoragePinnedColumns: setPinnedColumns
2667
+ });
2668
+ const columns = useMemo(() => propsColumns.map(column => {
2669
+ column.width = dimensionModel[column.field] || column.width || 100;
2670
+ return column;
2671
+ }), [propsColumns, dimensionModel]);
2672
+ /** Add resetPage method to apiRef. */
2673
+ apiRef.current.resetPage = () => {
2674
+ apiRef.current.setPage(0);
2675
+ };
2676
+ return {
2677
+ apiRef,
2678
+ columns,
2679
+ onFilterModelChange: (model, details) => {
2680
+ const filterModel = _objectSpread2(_objectSpread2({}, model), {}, {
2681
+ items: model.items.map(item => {
2682
+ const column = apiRef.current.getColumn(item.field);
2683
+ item.type = column.type || 'string';
2684
+ return item;
2685
+ }),
2686
+ quickFilterValues: model.quickFilterValues || []
2687
+ });
2688
+ propsOnFilterModelChange === null || propsOnFilterModelChange === void 0 ? void 0 : propsOnFilterModelChange(filterModel, details);
2689
+ updateUrl({
2690
+ filterModel: filterModel,
2691
+ sortModel: sortModelParsed,
2692
+ paginationModel: paginationModelParsed,
2693
+ columnsModel: apiRef.current.state.columns.columnVisibilityModel,
2694
+ pinnedColumnsModel: pinnedColumnsModel
2695
+ }, search, localStorageVersion, historyReplace, columns);
2696
+ },
2697
+ filterModel: filterParsed,
2698
+ onSortModelChange: (model, details) => {
2699
+ propsOnSortModelChange === null || propsOnSortModelChange === void 0 ? void 0 : propsOnSortModelChange(model, details);
2700
+ updateUrl({
2701
+ filterModel: filterParsed,
2702
+ sortModel: model,
2703
+ paginationModel: paginationModelParsed,
2704
+ columnsModel: apiRef.current.state.columns.columnVisibilityModel,
2705
+ pinnedColumnsModel: pinnedColumnsModel
2706
+ }, search, localStorageVersion, historyReplace, columns);
2707
+ },
2708
+ sortModel: sortModelParsed,
2709
+ onPinnedColumnsChange: (pinnedColumns, details) => {
2710
+ propsOnPinnedColumnsChange === null || propsOnPinnedColumnsChange === void 0 ? void 0 : propsOnPinnedColumnsChange(pinnedColumns, details);
2711
+ updateUrl({
2712
+ filterModel: filterParsed,
2713
+ sortModel: sortModelParsed,
2714
+ paginationModel: paginationModelParsed,
2715
+ columnsModel: apiRef.current.state.columns.columnVisibilityModel,
2716
+ pinnedColumnsModel: pinnedColumns
2717
+ }, search, localStorageVersion, historyReplace, columns);
2718
+ },
2719
+ pinnedColumns: pinnedColumnsModel,
2720
+ paginationModel: paginationModelParsed,
2721
+ onPaginationModelChange: (model, details) => {
2722
+ const paginationModel = _objectSpread2(_objectSpread2({}, model), {}, {
2723
+ direction: paginationModelParsed.page < model.page ? 'next' : 'back'
2724
+ });
2725
+ propsOnPaginationModelChange === null || propsOnPaginationModelChange === void 0 ? void 0 : propsOnPaginationModelChange(paginationModel, details);
2726
+ updateUrl({
2727
+ filterModel: filterParsed,
2728
+ sortModel: sortModelParsed,
2729
+ paginationModel: paginationModel,
2730
+ columnsModel: apiRef.current.state.columns.columnVisibilityModel,
2731
+ pinnedColumnsModel: pinnedColumnsModel
2732
+ }, search, localStorageVersion, historyReplace, columns);
2733
+ },
2734
+ columnVisibilityModel: visibilityModel,
2735
+ onColumnVisibilityModelChange: (columnsVisibilityModel, details) => {
2736
+ propsOnColumnVisibilityModelChange === null || propsOnColumnVisibilityModelChange === void 0 ? void 0 : propsOnColumnVisibilityModelChange(columnsVisibilityModel, details);
2737
+ updateUrl({
2738
+ filterModel: filterParsed,
2739
+ sortModel: sortModelParsed,
2740
+ paginationModel: paginationModelParsed,
2741
+ columnsModel: columnsVisibilityModel,
2742
+ pinnedColumnsModel: pinnedColumnsModel
2743
+ }, search, localStorageVersion, historyReplace, columns);
2744
+ },
2745
+ onColumnWidthChange: (params, event, details) => {
2746
+ propsOnColumnWidthChange === null || propsOnColumnWidthChange === void 0 ? void 0 : propsOnColumnWidthChange(params, event, details);
2747
+ onColumnDimensionChange({
2748
+ newWidth: params.width,
2749
+ field: params.colDef.field
2750
+ });
2751
+ }
2752
+ };
2753
+ };
2754
+
2755
+ const _excluded = ["apiRef", "autoHeight", "className", "columns", "slots", "slotProps", "filterModel", "columnVisibilityModel", "pinnedColumns", "sortModel", "paginationModel", "height", "hideToolbar", "initialState", "isRowSelectable", "license", "localStorageVersion", "previousLocalStorageVersions", "onFilterModelChange", "rowSelectionModel", "onColumnWidthChange", "onPaginationModelChange", "onRowSelectionModelChange", "onColumnVisibilityModelChange", "onPinnedColumnsChange", "onSortModelChange", "pagination", "paginationPlacement", "paginationProps", "rows", "pageSizeOptions", "sx", "theme", "useRouter", "paginationMode", "rowCount"];
2756
+ const COMPONENT_NAME = 'DataGrid';
2757
+ const CLASSNAME = 'redsift-datagrid';
2758
+ const StatefulDataGrid = /*#__PURE__*/forwardRef((props, ref) => {
2759
+ const datagridRef = ref || useRef();
2760
+ const {
2761
+ apiRef: propsApiRef,
2762
+ autoHeight,
2763
+ className,
2764
+ columns,
2765
+ slots,
2766
+ slotProps,
2767
+ filterModel: propsFilterModel,
2768
+ columnVisibilityModel: propsColumnVisibilityModel,
2769
+ pinnedColumns: propsPinnedColumns,
2770
+ sortModel: propsSortModel,
2771
+ paginationModel: propsPaginationModel,
2772
+ height: propsHeight,
2773
+ hideToolbar,
2774
+ initialState,
2775
+ isRowSelectable,
2776
+ license = process.env.MUI_LICENSE_KEY,
2777
+ localStorageVersion,
2778
+ previousLocalStorageVersions,
2779
+ onFilterModelChange: propsOnFilterModelChange,
2780
+ rowSelectionModel: propsRowSelectionModel,
2781
+ onColumnWidthChange: propsOnColumnWidthChange,
2782
+ onPaginationModelChange: propsOnPaginationModelChange,
2783
+ onRowSelectionModelChange: propsOnRowSelectionModelChange,
2784
+ onColumnVisibilityModelChange: propsOnColumnVisibilityModelChange,
2785
+ onPinnedColumnsChange: propsOnPinnedColumnsChange,
2786
+ onSortModelChange: propsOnSortModelChange,
2787
+ pagination,
2788
+ paginationPlacement = 'both',
2789
+ paginationProps,
2790
+ rows,
2791
+ pageSizeOptions,
2792
+ sx,
2793
+ theme: propsTheme,
2794
+ useRouter,
2795
+ paginationMode = 'client',
2796
+ rowCount
2797
+ } = props,
2798
+ forwardedProps = _objectWithoutProperties(props, _excluded);
2799
+ const theme = useTheme$1(propsTheme);
2800
+ const _apiRef = useGridApiRef();
2801
+ const apiRef = propsApiRef !== null && propsApiRef !== void 0 ? propsApiRef : _apiRef;
2802
+ const RenderedToolbar = slots !== null && slots !== void 0 && slots.toolbar ? slots.toolbar : Toolbar;
2803
+ LicenseInfo.setLicenseKey(license);
2804
+ const height = propsHeight !== null && propsHeight !== void 0 ? propsHeight : autoHeight ? undefined : '500px';
2805
+ const {
2806
+ onColumnVisibilityModelChange: controlledOnColumnVisibilityModelChange,
2807
+ onFilterModelChange: controlledOnFilterModelChange,
2808
+ onPaginationModelChange: controlledOnPaginationModelChange,
2809
+ onPinnedColumnsChange: controlledOnPinnedColumnsChange,
2810
+ onSortModelChange: controlledOnSortModelChange
2811
+ } = useControlledDatagridState({
2812
+ initialState,
2813
+ pageSizeOptions,
2814
+ propsColumnVisibilityModel,
2815
+ propsFilterModel,
2816
+ propsOnColumnVisibilityModelChange,
2817
+ propsOnFilterModelChange,
2818
+ propsOnPinnedColumnsChange,
2819
+ propsOnSortModelChange,
2820
+ propsPaginationModel,
2821
+ propsPinnedColumns,
2822
+ propsSortModel,
2823
+ propsOnPaginationModelChange
2824
+ });
2825
+ const {
2826
+ columnVisibilityModel,
2827
+ filterModel,
2828
+ onColumnVisibilityModelChange,
2829
+ onFilterModelChange,
2830
+ onPaginationModelChange,
2831
+ onPinnedColumnsChange,
2832
+ onSortModelChange,
2833
+ paginationModel,
2834
+ pinnedColumns,
2835
+ sortModel,
2836
+ onColumnWidthChange
2837
+ } = useStatefulTable({
2838
+ apiRef: apiRef,
2839
+ initialState,
2840
+ columns,
2841
+ onColumnVisibilityModelChange: controlledOnColumnVisibilityModelChange,
2842
+ onColumnWidthChange: propsOnColumnWidthChange,
2843
+ onFilterModelChange: controlledOnFilterModelChange,
2844
+ onPaginationModelChange: controlledOnPaginationModelChange,
2845
+ onPinnedColumnsChange: controlledOnPinnedColumnsChange,
2846
+ onSortModelChange: controlledOnSortModelChange,
2847
+ useRouter: useRouter,
2848
+ localStorageVersion,
2849
+ previousLocalStorageVersions
2850
+ });
2851
+ const [rowSelectionModel, setRowSelectionModel] = useState(propsRowSelectionModel !== null && propsRowSelectionModel !== void 0 ? propsRowSelectionModel : []);
2852
+ useEffect(() => {
2853
+ setRowSelectionModel(propsRowSelectionModel !== null && propsRowSelectionModel !== void 0 ? propsRowSelectionModel : []);
2854
+ }, [propsRowSelectionModel]);
2855
+ const onRowSelectionModelChange = (selectionModel, details) => {
2856
+ if (propsOnRowSelectionModelChange) {
2857
+ propsOnRowSelectionModelChange(selectionModel, details);
2858
+ } else {
2859
+ setRowSelectionModel(selectionModel);
2860
+ }
2861
+ };
2862
+ const selectionStatus = useRef({
2863
+ type: 'none',
2864
+ numberOfSelectedRows: 0,
2865
+ numberOfSelectedRowsInPage: 0,
2866
+ page: paginationModel.page,
2867
+ pageSize: paginationModel.pageSize
2868
+ });
2869
+
2870
+ // in server-side pagination we want to update the selection status
2871
+ // every time we navigate between pages, resize our page or select something
2872
+ useEffect(() => {
2873
+ if (paginationMode == 'server') {
2874
+ onServerSideSelectionStatusChange(Array.isArray(rowSelectionModel) ? rowSelectionModel : [rowSelectionModel], apiRef, selectionStatus, isRowSelectable, paginationModel.page, paginationModel.pageSize);
2875
+ }
2876
+ }, [rowSelectionModel, paginationModel.page, paginationModel.pageSize]);
2877
+ if (!Array.isArray(rows)) {
2878
+ return null;
2879
+ }
2880
+ const muiTheme = useMemo(() => createTheme({
2881
+ palette: {
2882
+ mode: theme,
2883
+ primary: {
2884
+ main: RedsiftColorBlueN
2885
+ },
2886
+ background: {
2887
+ default: theme === 'dark' ? RedsiftColorNeutralXDarkGrey : RedsiftColorNeutralWhite,
2888
+ paper: theme === 'dark' ? RedsiftColorNeutralXDarkGrey : RedsiftColorNeutralWhite
2889
+ }
2890
+ }
2891
+ }), [theme]);
2892
+ return /*#__PURE__*/React__default.createElement(ThemeProvider, {
2893
+ value: {
2894
+ theme
2895
+ }
2896
+ }, /*#__PURE__*/React__default.createElement(ThemeProvider$1, {
2897
+ theme: muiTheme
2898
+ }, /*#__PURE__*/React__default.createElement(StyledDataGrid, {
2899
+ ref: datagridRef,
2900
+ className: classNames(StatefulDataGrid.className, className),
2901
+ $height: height
2902
+ }, /*#__PURE__*/React__default.createElement(DataGridPro, _extends$1({}, forwardedProps, {
2903
+ apiRef: apiRef,
2904
+ columns: columns,
2905
+ columnVisibilityModel: columnVisibilityModel,
2906
+ filterModel: filterModel,
2907
+ onColumnVisibilityModelChange: onColumnVisibilityModelChange,
2908
+ onFilterModelChange: onFilterModelChange,
2909
+ onPaginationModelChange: onPaginationModelChange,
2910
+ onPinnedColumnsChange: onPinnedColumnsChange,
2911
+ onSortModelChange: onSortModelChange,
2912
+ paginationModel: paginationModel,
2913
+ pinnedColumns: pinnedColumns,
2914
+ sortModel: sortModel,
2915
+ pageSizeOptions: pageSizeOptions,
2916
+ onColumnWidthChange: onColumnWidthChange,
2917
+ initialState: initialState,
2918
+ isRowSelectable: isRowSelectable,
2919
+ pagination: pagination,
2920
+ paginationMode: paginationMode,
2921
+ keepNonExistentRowsSelected: paginationMode == 'server',
2922
+ rows: rows,
2923
+ rowCount: rowCount,
2924
+ autoHeight: autoHeight,
2925
+ checkboxSelectionVisibleOnly: Boolean(pagination),
2926
+ slots: _objectSpread2(_objectSpread2({
2927
+ baseButton: BaseButton,
2928
+ baseCheckbox: BaseCheckbox,
2929
+ // baseTextField,
2930
+ basePopper: BasePopper,
2931
+ columnFilteredIcon: props => /*#__PURE__*/React__default.createElement(BaseIcon, _extends$1({}, props, {
2932
+ displayName: "ColumnFilteredIcon"
2933
+ })),
2934
+ columnSelectorIcon: props => /*#__PURE__*/React__default.createElement(BaseIcon, _extends$1({}, props, {
2935
+ displayName: "ColumnSelectorIcon"
2936
+ })),
2937
+ columnSortedAscendingIcon: props => /*#__PURE__*/React__default.createElement(BaseIcon, _extends$1({}, props, {
2938
+ displayName: "ColumnSortedAscendingIcon"
2939
+ })),
2940
+ columnSortedDescendingIcon: props => /*#__PURE__*/React__default.createElement(BaseIcon, _extends$1({}, props, {
2941
+ displayName: "ColumnSortedDescendingIcon"
2942
+ })),
2943
+ densityCompactIcon: props => /*#__PURE__*/React__default.createElement(BaseIcon, _extends$1({}, props, {
2944
+ displayName: "DensityCompactIcon"
2945
+ })),
2946
+ densityStandardIcon: props => /*#__PURE__*/React__default.createElement(BaseIcon, _extends$1({}, props, {
2947
+ displayName: "DensityStandardIcon"
2948
+ })),
2949
+ densityComfortableIcon: props => /*#__PURE__*/React__default.createElement(BaseIcon, _extends$1({}, props, {
2950
+ displayName: "DensityComfortableIcon"
2951
+ })),
2952
+ detailPanelCollapseIcon: props => /*#__PURE__*/React__default.createElement(BaseIcon, _extends$1({}, props, {
2953
+ displayName: "DetailPanelCollapseIcon"
2954
+ })),
2955
+ detailPanelExpandIcon: props => /*#__PURE__*/React__default.createElement(BaseIcon, _extends$1({}, props, {
2956
+ displayName: "DetailPanelExpandIcon"
2957
+ })),
2958
+ exportIcon: props => /*#__PURE__*/React__default.createElement(BaseIcon, _extends$1({}, props, {
2959
+ displayName: "ExportIcon"
2960
+ })),
2961
+ openFilterButtonIcon: props => /*#__PURE__*/React__default.createElement(BaseIcon, _extends$1({
2962
+ displayName: "OpenFilterButtonIcon"
2963
+ }, props))
2964
+ }, slots), {}, {
2965
+ toolbar: ToolbarWrapper,
2966
+ pagination: props => {
2967
+ return pagination ? paginationMode == 'server' ? /*#__PURE__*/React__default.createElement(ServerSideControlledPagination, _extends$1({}, props, {
2968
+ displaySelection: false,
2969
+ displayRowsPerPage: ['bottom', 'both'].includes(paginationPlacement),
2970
+ displayPagination: ['bottom', 'both'].includes(paginationPlacement),
2971
+ selectionStatus: selectionStatus.current,
2972
+ paginationModel: paginationModel,
2973
+ onPaginationModelChange: onPaginationModelChange,
2974
+ pageSizeOptions: pageSizeOptions,
2975
+ paginationProps: paginationProps,
2976
+ paginationMode: paginationMode,
2977
+ rowCount: rowCount
2978
+ })) : /*#__PURE__*/React__default.createElement(ControlledPagination, _extends$1({}, props, {
2979
+ displaySelection: false,
2980
+ displayRowsPerPage: ['bottom', 'both'].includes(paginationPlacement),
2981
+ displayPagination: ['bottom', 'both'].includes(paginationPlacement),
2982
+ selectionStatus: selectionStatus.current,
2983
+ apiRef: apiRef,
2984
+ isRowSelectable: isRowSelectable,
2985
+ paginationModel: paginationModel,
2986
+ onPaginationModelChange: onPaginationModelChange,
2987
+ pageSizeOptions: pageSizeOptions,
2988
+ paginationProps: paginationProps,
2989
+ paginationMode: paginationMode
2990
+ })) : null;
2991
+ }
2992
+ }),
2993
+ slotProps: _objectSpread2(_objectSpread2({}, slotProps), {}, {
2994
+ toolbar: _objectSpread2({
2995
+ hideToolbar,
2996
+ RenderedToolbar,
2997
+ filterModel,
2998
+ onFilterModelChange,
2999
+ pagination,
3000
+ paginationPlacement,
3001
+ selectionStatus,
3002
+ apiRef,
3003
+ isRowSelectable,
3004
+ paginationModel,
3005
+ onPaginationModelChange,
3006
+ pageSizeOptions,
3007
+ paginationProps,
3008
+ paginationMode,
3009
+ rowCount
3010
+ }, slotProps === null || slotProps === void 0 ? void 0 : slotProps.toolbar)
3011
+ }),
3012
+ rowSelectionModel: rowSelectionModel,
3013
+ onRowSelectionModelChange: (newSelectionModel, details) => {
3014
+ if (pagination && paginationMode != 'server') {
3015
+ const selectableRowsInPage = isRowSelectable ? gridPaginatedVisibleSortedGridRowEntriesSelector(apiRef).filter(_ref => {
3016
+ let {
3017
+ model
3018
+ } = _ref;
3019
+ return isRowSelectable({
3020
+ row: model
3021
+ });
3022
+ }).map(_ref2 => {
3023
+ let {
3024
+ id
3025
+ } = _ref2;
3026
+ return id;
3027
+ }) : gridPaginatedVisibleSortedGridRowIdsSelector(apiRef);
3028
+ const numberOfSelectableRowsInPage = selectableRowsInPage.length;
3029
+ const selectableRowsInTable = isRowSelectable ? gridFilteredSortedRowEntriesSelector(apiRef).filter(_ref3 => {
3030
+ let {
3031
+ model
3032
+ } = _ref3;
3033
+ return isRowSelectable({
3034
+ row: model
3035
+ });
3036
+ }).map(_ref4 => {
3037
+ let {
3038
+ id
3039
+ } = _ref4;
3040
+ return id;
3041
+ }) : gridFilteredSortedRowIdsSelector(apiRef);
3042
+ const numberOfSelectableRowsInTable = selectableRowsInTable.length;
3043
+ const numberOfSelectedRows = newSelectionModel.length;
3044
+ if (selectionStatus.current.type === 'table' && numberOfSelectedRows === numberOfSelectableRowsInTable - numberOfSelectableRowsInPage || selectionStatus.current.type === 'table' && numberOfSelectedRows === numberOfSelectableRowsInTable || selectionStatus.current.type === 'page' && numberOfSelectedRows === numberOfSelectableRowsInPage) {
3045
+ setTimeout(() => {
3046
+ apiRef.current.selectRows([], true, true);
3047
+ }, 0);
3048
+ }
3049
+ if (numberOfSelectedRows === numberOfSelectableRowsInPage && numberOfSelectableRowsInPage < numberOfSelectableRowsInTable) {
3050
+ selectionStatus.current = {
3051
+ type: 'page',
3052
+ numberOfSelectedRows
3053
+ };
3054
+ } else if (numberOfSelectedRows === numberOfSelectableRowsInTable && numberOfSelectableRowsInPage < numberOfSelectableRowsInTable) {
3055
+ selectionStatus.current = {
3056
+ type: 'table',
3057
+ numberOfSelectedRows
3058
+ };
3059
+ } else if (numberOfSelectedRows > 0) {
3060
+ selectionStatus.current = {
3061
+ type: 'other',
3062
+ numberOfSelectedRows
3063
+ };
3064
+ } else {
3065
+ selectionStatus.current = {
3066
+ type: 'none',
3067
+ numberOfSelectedRows
3068
+ };
3069
+ }
3070
+ }
3071
+ onRowSelectionModelChange === null || onRowSelectionModelChange === void 0 ? void 0 : onRowSelectionModelChange(newSelectionModel, details);
3072
+ },
3073
+ sx: _objectSpread2(_objectSpread2({}, sx), {}, {
3074
+ '.MuiDataGrid-columnHeaders': {
3075
+ flexDirection: 'column',
3076
+ alignItems: 'normal'
3077
+ },
3078
+ '.MuiDataGrid-selectedRowCount': {
3079
+ margin: 'none'
3080
+ }
3081
+ })
3082
+ })))));
3083
+ });
3084
+ StatefulDataGrid.className = CLASSNAME;
3085
+ StatefulDataGrid.displayName = COMPONENT_NAME;
3086
+
3087
+ export { getSearchParamsFromColumnVisibility as $, FILTER_SEARCH_KEY as A, CATEGORIES as B, CONTAINS_ANY_OF as C, DOES_NOT_CONTAIN as D, ENDS_WITH_ANY_OF as E, FILTER_MODEL_KEY as F, buildStorageKey as G, HAS as H, IS_BETWEEN as I, clearPreviousVersionStorage as J, decodeValue as K, encodeValue as L, urlSearchParamsToString as M, numberOperatorEncoder as N, numberOperatorDecoder as O, PAGINATION_MODEL_KEY as P, isOperatorValueValid as Q, isValueValid as R, STARTS_WITH_ANY_OF as S, getFilterModelFromString as T, getSearchParamsFromFilterModel as U, VISIBILITY_MODEL_KEY as V, getSortingFromString as W, getSearchParamsFromSorting as X, getPaginationFromString as Y, getSearchParamsFromPagination as Z, getColumnVisibilityFromString as _, DOES_NOT_EQUAL as a, getPinnedColumnsFromString as a0, getSearchParamsFromPinnedColumns as a1, getSearchParamsFromTab as a2, getFinalSearch as a3, getModelsParsedOrUpdateLocalStorage as a4, updateUrl as a5, areFilterModelsEquivalent as a6, StatefulDataGrid as a7, DOES_NOT_HAVE as b, DOES_NOT_HAVE_WITH_SELECT as c, HAS_WITH_SELECT as d, HAS_ONLY as e, HAS_ONLY_WITH_SELECT as f, getGridNumericOperators as g, IS as h, IS_WITH_SELECT as i, IS_NOT as j, IS_NOT_WITH_SELECT as k, getGridStringOperators as l, CONTAINS_ANY_OF_I as m, IS_ANY_OF as n, operatorList as o, IS_ANY_OF_WITH_SELECT as p, HAS_ANY_OF as q, HAS_ANY_OF_WITH_SELECT as r, IS_NOT_ANY_OF as s, IS_NOT_ANY_OF_WITH_SELECT as t, getGridStringArrayOperators as u, getGridStringArrayOperatorsWithSelect as v, getGridStringArrayOperatorsWithSelectOnStringArrayColumns as w, SORT_MODEL_KEY as x, PINNED_COLUMNS as y, DIMENSION_MODEL_KEY as z };
3088
+ //# sourceMappingURL=StatefulDataGrid2.js.map