@mui/x-data-grid 7.12.1 → 7.14.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 (157) hide show
  1. package/CHANGELOG.md +162 -1
  2. package/DataGrid/DataGrid.js +10 -1
  3. package/components/GridColumnHeaders.js +1 -1
  4. package/components/GridConfigurationContext.d.ts +2 -0
  5. package/components/GridConfigurationContext.js +5 -0
  6. package/components/GridHeaders.js +1 -1
  7. package/components/GridRow.js +6 -8
  8. package/components/GridScrollArea.js +1 -1
  9. package/components/GridSkeletonLoadingOverlay.js +1 -1
  10. package/components/cell/GridCell.js +12 -13
  11. package/components/cell/GridEditSingleSelectCell.js +2 -3
  12. package/components/cell/GridSkeletonCell.js +2 -2
  13. package/components/columnHeaders/GridColumnHeaderItem.js +1 -1
  14. package/components/containers/GridRootStyles.js +9 -2
  15. package/components/menu/columnMenu/GridColumnMenuContainer.js +2 -2
  16. package/components/panel/GridPanel.js +1 -2
  17. package/components/panel/filterPanel/GridFilterForm.js +9 -4
  18. package/components/toolbar/GridToolbarDensitySelector.js +2 -2
  19. package/components/toolbar/GridToolbarExportContainer.js +2 -2
  20. package/components/toolbar/GridToolbarQuickFilter.js +5 -3
  21. package/components/virtualization/GridMainContainer.js +3 -2
  22. package/components/virtualization/GridVirtualScrollerFiller.js +1 -1
  23. package/context/GridContextProvider.d.ts +3 -1
  24. package/context/GridContextProvider.js +12 -7
  25. package/hooks/core/useGridStateInitialization.js +1 -3
  26. package/hooks/features/dimensions/useGridDimensions.js +1 -1
  27. package/hooks/features/export/serializers/csvSerializer.js +4 -3
  28. package/hooks/features/filter/gridFilterSelector.d.ts +20 -7
  29. package/hooks/features/filter/gridFilterSelector.js +34 -0
  30. package/hooks/features/filter/gridFilterState.d.ts +6 -0
  31. package/hooks/features/filter/index.d.ts +2 -1
  32. package/hooks/features/filter/index.js +1 -1
  33. package/hooks/features/filter/useGridFilter.js +3 -0
  34. package/hooks/features/rowSelection/useGridRowSelection.js +4 -1
  35. package/hooks/features/rows/useGridParamsApi.js +2 -1
  36. package/hooks/features/rows/useGridRowAriaAttributes.d.ts +2 -0
  37. package/hooks/features/rows/useGridRowAriaAttributes.js +19 -0
  38. package/hooks/utils/useGridAriaAttributes.d.ts +2 -6
  39. package/hooks/utils/useGridAriaAttributes.js +5 -8
  40. package/hooks/utils/useGridConfiguration.d.ts +2 -0
  41. package/hooks/utils/useGridConfiguration.js +9 -0
  42. package/hooks/utils/useGridSelector.d.ts +5 -2
  43. package/hooks/utils/useGridSelector.js +39 -1
  44. package/index.js +1 -1
  45. package/internals/index.d.ts +5 -2
  46. package/internals/index.js +5 -2
  47. package/locales/csCZ.js +4 -5
  48. package/locales/heIL.js +4 -5
  49. package/locales/viVN.js +4 -5
  50. package/models/configuration/gridConfiguration.d.ts +10 -0
  51. package/models/configuration/gridConfiguration.js +1 -0
  52. package/models/configuration/gridRowConfiguration.d.ts +12 -0
  53. package/models/configuration/gridRowConfiguration.js +1 -0
  54. package/models/gridDataSource.d.ts +8 -7
  55. package/models/gridRows.d.ts +2 -2
  56. package/models/params/gridCellParams.d.ts +4 -0
  57. package/models/props/DataGridProps.d.ts +1 -1
  58. package/modern/DataGrid/DataGrid.js +10 -1
  59. package/modern/components/GridColumnHeaders.js +1 -1
  60. package/modern/components/GridConfigurationContext.js +5 -0
  61. package/modern/components/GridHeaders.js +1 -1
  62. package/modern/components/GridRow.js +6 -8
  63. package/modern/components/GridScrollArea.js +1 -1
  64. package/modern/components/GridSkeletonLoadingOverlay.js +1 -1
  65. package/modern/components/cell/GridCell.js +12 -13
  66. package/modern/components/cell/GridEditSingleSelectCell.js +2 -3
  67. package/modern/components/cell/GridSkeletonCell.js +2 -2
  68. package/modern/components/columnHeaders/GridColumnHeaderItem.js +1 -1
  69. package/modern/components/containers/GridRootStyles.js +9 -2
  70. package/modern/components/menu/columnMenu/GridColumnMenuContainer.js +2 -2
  71. package/modern/components/panel/GridPanel.js +1 -2
  72. package/modern/components/panel/filterPanel/GridFilterForm.js +9 -4
  73. package/modern/components/toolbar/GridToolbarDensitySelector.js +2 -2
  74. package/modern/components/toolbar/GridToolbarExportContainer.js +2 -2
  75. package/modern/components/toolbar/GridToolbarQuickFilter.js +5 -3
  76. package/modern/components/virtualization/GridMainContainer.js +3 -2
  77. package/modern/components/virtualization/GridVirtualScrollerFiller.js +1 -1
  78. package/modern/context/GridContextProvider.js +12 -7
  79. package/modern/hooks/core/useGridStateInitialization.js +1 -3
  80. package/modern/hooks/features/dimensions/useGridDimensions.js +1 -1
  81. package/modern/hooks/features/export/serializers/csvSerializer.js +4 -3
  82. package/modern/hooks/features/filter/gridFilterSelector.js +34 -0
  83. package/modern/hooks/features/filter/index.js +1 -1
  84. package/modern/hooks/features/filter/useGridFilter.js +3 -0
  85. package/modern/hooks/features/rowSelection/useGridRowSelection.js +4 -1
  86. package/modern/hooks/features/rows/useGridParamsApi.js +2 -1
  87. package/modern/hooks/features/rows/useGridRowAriaAttributes.js +19 -0
  88. package/modern/hooks/utils/useGridAriaAttributes.js +5 -8
  89. package/modern/hooks/utils/useGridConfiguration.js +9 -0
  90. package/modern/hooks/utils/useGridSelector.js +39 -1
  91. package/modern/index.js +1 -1
  92. package/modern/internals/index.js +5 -2
  93. package/modern/locales/csCZ.js +4 -5
  94. package/modern/locales/heIL.js +4 -5
  95. package/modern/locales/viVN.js +4 -5
  96. package/modern/models/configuration/gridConfiguration.js +1 -0
  97. package/modern/models/configuration/gridRowConfiguration.js +1 -0
  98. package/modern/utils/createSelector.js +116 -0
  99. package/modern/utils/keyboardUtils.js +1 -11
  100. package/node/DataGrid/DataGrid.js +10 -1
  101. package/node/components/GridColumnHeaders.js +1 -1
  102. package/node/{utils/fastMemo.js → components/GridConfigurationContext.js} +4 -4
  103. package/node/components/GridHeaders.js +1 -1
  104. package/node/components/GridRow.js +6 -8
  105. package/node/components/GridScrollArea.js +1 -1
  106. package/node/components/GridSkeletonLoadingOverlay.js +1 -1
  107. package/node/components/cell/GridCell.js +12 -13
  108. package/node/components/cell/GridEditSingleSelectCell.js +2 -3
  109. package/node/components/cell/GridSkeletonCell.js +2 -2
  110. package/node/components/columnHeaders/GridColumnHeaderItem.js +1 -1
  111. package/node/components/containers/GridRootStyles.js +9 -2
  112. package/node/components/menu/columnMenu/GridColumnMenuContainer.js +1 -1
  113. package/node/components/panel/GridPanel.js +1 -2
  114. package/node/components/panel/filterPanel/GridFilterForm.js +9 -4
  115. package/node/components/toolbar/GridToolbarDensitySelector.js +1 -1
  116. package/node/components/toolbar/GridToolbarExportContainer.js +1 -1
  117. package/node/components/toolbar/GridToolbarQuickFilter.js +5 -3
  118. package/node/components/virtualization/GridMainContainer.js +3 -2
  119. package/node/components/virtualization/GridVirtualScrollerFiller.js +1 -1
  120. package/node/context/GridContextProvider.js +12 -7
  121. package/node/hooks/core/useGridStateInitialization.js +1 -3
  122. package/node/hooks/features/dimensions/useGridDimensions.js +1 -1
  123. package/node/hooks/features/export/serializers/csvSerializer.js +4 -3
  124. package/node/hooks/features/filter/gridFilterSelector.js +35 -1
  125. package/node/hooks/features/filter/index.js +97 -15
  126. package/node/hooks/features/filter/useGridFilter.js +3 -0
  127. package/node/hooks/features/rowSelection/useGridRowSelection.js +4 -1
  128. package/node/hooks/features/rows/useGridParamsApi.js +2 -1
  129. package/node/hooks/features/rows/useGridRowAriaAttributes.js +28 -0
  130. package/node/hooks/utils/useGridAriaAttributes.js +4 -7
  131. package/node/hooks/utils/useGridConfiguration.js +18 -0
  132. package/node/hooks/utils/useGridSelector.js +42 -3
  133. package/node/index.js +1 -1
  134. package/node/internals/index.js +53 -12
  135. package/node/locales/csCZ.js +4 -5
  136. package/node/locales/heIL.js +4 -5
  137. package/node/locales/viVN.js +4 -5
  138. package/node/models/configuration/gridConfiguration.js +5 -0
  139. package/node/models/configuration/gridRowConfiguration.js +5 -0
  140. package/node/utils/createSelector.js +119 -2
  141. package/node/utils/keyboardUtils.js +2 -15
  142. package/package.json +4 -4
  143. package/utils/createSelector.d.ts +19 -0
  144. package/utils/createSelector.js +116 -0
  145. package/utils/keyboardUtils.d.ts +1 -9
  146. package/utils/keyboardUtils.js +1 -11
  147. package/modern/utils/fastMemo.js +0 -5
  148. package/modern/utils/fastObjectShallowCompare.js +0 -28
  149. package/modern/utils/throttle.js +0 -19
  150. package/node/utils/fastObjectShallowCompare.js +0 -34
  151. package/node/utils/throttle.js +0 -25
  152. package/utils/fastMemo.d.ts +0 -1
  153. package/utils/fastMemo.js +0 -5
  154. package/utils/fastObjectShallowCompare.d.ts +0 -1
  155. package/utils/fastObjectShallowCompare.js +0 -28
  156. package/utils/throttle.d.ts +0 -4
  157. package/utils/throttle.js +0 -19
@@ -9,6 +9,14 @@ export interface OutputSelector<State, Result> {
9
9
  (state: State, instanceId: GridCoreApi['instanceId']): Result;
10
10
  acceptsApiRef: boolean;
11
11
  }
12
+ export interface OutputSelectorV8<State, Args, Result> {
13
+ (apiRef: React.MutableRefObject<{
14
+ state: State;
15
+ instanceId: GridCoreApi['instanceId'];
16
+ }>, args: Args): Result;
17
+ (state: State, instanceId: GridCoreApi['instanceId']): Result;
18
+ acceptsApiRef: boolean;
19
+ }
12
20
  type StateFromSelector<T> = T extends (first: infer F, ...args: any[]) => any ? F extends {
13
21
  state: infer F2;
14
22
  } ? F2 : F : never;
@@ -17,7 +25,18 @@ type StateFromSelectorList<Selectors extends readonly any[]> = Selectors extends
17
25
  ...other: infer R
18
26
  ] ? StateFromSelector<F> extends StateFromSelectorList<R> ? StateFromSelector<F> : StateFromSelectorList<R> : {};
19
27
  type SelectorArgs<Selectors extends ReadonlyArray<Selector<any>>, Result> = [selectors: [...Selectors], combiner: (...args: SelectorResultArray<Selectors>) => Result] | [...Selectors, (...args: SelectorResultArray<Selectors>) => Result];
28
+ type SelectorResultArrayWithArgs<Selectors extends ReadonlyArray<Selector<any>>, Args> = [
29
+ ...SelectorResultArray<Selectors>,
30
+ Args
31
+ ];
32
+ type SelectorArgsV8<Selectors extends ReadonlyArray<Selector<any>>, Args, Result> = [
33
+ selectors: [...Selectors],
34
+ combiner: (...args: SelectorResultArrayWithArgs<Selectors, Args>) => Result
35
+ ] | [...Selectors, (...args: SelectorResultArrayWithArgs<Selectors, Args>) => Result];
20
36
  type CreateSelectorFunction = <Selectors extends ReadonlyArray<Selector<any>>, Result>(...items: SelectorArgs<Selectors, Result>) => OutputSelector<StateFromSelectorList<Selectors>, Result>;
37
+ type CreateSelectorFunctionV8 = <Selectors extends ReadonlyArray<Selector<any>>, Args, Result>(...items: SelectorArgsV8<Selectors, Args, Result>) => OutputSelectorV8<StateFromSelectorList<Selectors>, Args, Result>;
21
38
  export declare const createSelector: CreateSelectorFunction;
39
+ export declare const createSelectorV8: CreateSelectorFunctionV8;
22
40
  export declare const createSelectorMemoized: CreateSelectorFunction;
41
+ export declare const createSelectorMemoizedV8: CreateSelectorFunctionV8;
23
42
  export {};
@@ -1,5 +1,18 @@
1
1
  import { createSelector as reselectCreateSelector } from 'reselect';
2
2
  import { warnOnce } from '../internals/utils/warning';
3
+
4
+ // TODO v8: Remove this type
5
+
6
+ // TODO v8: Rename this type to `OutputSelector`
7
+
8
+ // TODO v8: Remove this type
9
+
10
+ // TODO v8: Rename this type to `SelectorArgs`
11
+
12
+ // TODO v8: Remove this type
13
+
14
+ // TODO v8: Rename this type to `CreateSelectorFunction`
15
+
3
16
  const cache = new WeakMap();
4
17
  function checkIsAPIRef(value) {
5
18
  return 'current' in value && 'instanceId' in value.current;
@@ -7,6 +20,8 @@ function checkIsAPIRef(value) {
7
20
  const DEFAULT_INSTANCE_ID = {
8
21
  id: 'default'
9
22
  };
23
+
24
+ // TODO v8: Remove this function
10
25
  export const createSelector = (a, b, c, d, e, f, ...other) => {
11
26
  if (other.length > 0) {
12
27
  throw new Error('Unsupported number of selectors');
@@ -71,6 +86,74 @@ export const createSelector = (a, b, c, d, e, f, ...other) => {
71
86
  selector.acceptsApiRef = true;
72
87
  return selector;
73
88
  };
89
+
90
+ // TODO v8: Rename this function to `createSelector`
91
+ export const createSelectorV8 = (a, b, c, d, e, f, ...other) => {
92
+ if (other.length > 0) {
93
+ throw new Error('Unsupported number of selectors');
94
+ }
95
+ let selector;
96
+ if (a && b && c && d && e && f) {
97
+ selector = (stateOrApiRef, args, instanceIdParam) => {
98
+ const isAPIRef = checkIsAPIRef(stateOrApiRef);
99
+ const instanceId = instanceIdParam ?? (isAPIRef ? stateOrApiRef.current.instanceId : DEFAULT_INSTANCE_ID);
100
+ const state = isAPIRef ? stateOrApiRef.current.state : stateOrApiRef;
101
+ const va = a(state, args, instanceId);
102
+ const vb = b(state, args, instanceId);
103
+ const vc = c(state, args, instanceId);
104
+ const vd = d(state, args, instanceId);
105
+ const ve = e(state, args, instanceId);
106
+ return f(va, vb, vc, vd, ve, args);
107
+ };
108
+ } else if (a && b && c && d && e) {
109
+ selector = (stateOrApiRef, args, instanceIdParam) => {
110
+ const isAPIRef = checkIsAPIRef(stateOrApiRef);
111
+ const instanceId = instanceIdParam ?? (isAPIRef ? stateOrApiRef.current.instanceId : DEFAULT_INSTANCE_ID);
112
+ const state = isAPIRef ? stateOrApiRef.current.state : stateOrApiRef;
113
+ const va = a(state, args, instanceId);
114
+ const vb = b(state, args, instanceId);
115
+ const vc = c(state, args, instanceId);
116
+ const vd = d(state, args, instanceId);
117
+ return e(va, vb, vc, vd, args);
118
+ };
119
+ } else if (a && b && c && d) {
120
+ selector = (stateOrApiRef, args, instanceIdParam) => {
121
+ const isAPIRef = checkIsAPIRef(stateOrApiRef);
122
+ const instanceId = instanceIdParam ?? (isAPIRef ? stateOrApiRef.current.instanceId : DEFAULT_INSTANCE_ID);
123
+ const state = isAPIRef ? stateOrApiRef.current.state : stateOrApiRef;
124
+ const va = a(state, args, instanceId);
125
+ const vb = b(state, args, instanceId);
126
+ const vc = c(state, args, instanceId);
127
+ return d(va, vb, vc, args);
128
+ };
129
+ } else if (a && b && c) {
130
+ selector = (stateOrApiRef, args, instanceIdParam) => {
131
+ const isAPIRef = checkIsAPIRef(stateOrApiRef);
132
+ const instanceId = instanceIdParam ?? (isAPIRef ? stateOrApiRef.current.instanceId : DEFAULT_INSTANCE_ID);
133
+ const state = isAPIRef ? stateOrApiRef.current.state : stateOrApiRef;
134
+ const va = a(state, args, instanceId);
135
+ const vb = b(state, args, instanceId);
136
+ return c(va, vb, args);
137
+ };
138
+ } else if (a && b) {
139
+ selector = (stateOrApiRef, args, instanceIdParam) => {
140
+ const isAPIRef = checkIsAPIRef(stateOrApiRef);
141
+ const instanceId = instanceIdParam ?? (isAPIRef ? stateOrApiRef.current.instanceId : DEFAULT_INSTANCE_ID);
142
+ const state = isAPIRef ? stateOrApiRef.current.state : stateOrApiRef;
143
+ const va = a(state, args, instanceId);
144
+ return b(va, args);
145
+ };
146
+ } else {
147
+ throw new Error('Missing arguments');
148
+ }
149
+
150
+ // We use this property to detect if the selector was created with createSelector
151
+ // or it's only a simple function the receives the state and returns part of it.
152
+ selector.acceptsApiRef = true;
153
+ return selector;
154
+ };
155
+
156
+ // TODO v8: Remove this function
74
157
  export const createSelectorMemoized = (...args) => {
75
158
  const selector = (stateOrApiRef, instanceId) => {
76
159
  const isAPIRef = checkIsAPIRef(stateOrApiRef);
@@ -97,6 +180,39 @@ export const createSelectorMemoized = (...args) => {
97
180
  return fn(state, cacheKey);
98
181
  };
99
182
 
183
+ // We use this property to detect if the selector was created with createSelector
184
+ // or it's only a simple function the receives the state and returns part of it.
185
+ selector.acceptsApiRef = true;
186
+ return selector;
187
+ };
188
+
189
+ // TODO v8: Rename this function to `createSelectorMemoized`
190
+ export const createSelectorMemoizedV8 = (...args) => {
191
+ const selector = (stateOrApiRef, selectorArgs, instanceId) => {
192
+ const isAPIRef = checkIsAPIRef(stateOrApiRef);
193
+ const cacheKey = isAPIRef ? stateOrApiRef.current.instanceId : instanceId ?? DEFAULT_INSTANCE_ID;
194
+ const state = isAPIRef ? stateOrApiRef.current.state : stateOrApiRef;
195
+ if (process.env.NODE_ENV !== 'production') {
196
+ if (cacheKey.id === 'default') {
197
+ warnOnce(['MUI X: A selector was called without passing the instance ID, which may impact the performance of the grid.', 'To fix, call it with `apiRef`, for example `mySelector(apiRef)`, or pass the instance ID explicitly, for example `mySelector(state, apiRef.current.instanceId)`.']);
198
+ }
199
+ }
200
+ const cacheArgsInit = cache.get(cacheKey);
201
+ const cacheArgs = cacheArgsInit ?? new Map();
202
+ const cacheFn = cacheArgs?.get(args);
203
+ if (cacheArgs && cacheFn) {
204
+ // We pass the cache key because the called selector might have as
205
+ // dependency another selector created with this `createSelector`.
206
+ return cacheFn(state, selectorArgs, cacheKey);
207
+ }
208
+ const fn = reselectCreateSelector(...args);
209
+ if (!cacheArgsInit) {
210
+ cache.set(cacheKey, cacheArgs);
211
+ }
212
+ cacheArgs.set(args, fn);
213
+ return fn(state, selectorArgs, cacheKey);
214
+ };
215
+
100
216
  // We use this property to detect if the selector was created with createSelector
101
217
  // or it's only a simple function the receives the state and returns part of it.
102
218
  selector.acceptsApiRef = true;
@@ -1,12 +1,4 @@
1
1
  import * as React from 'react';
2
- /**
3
- * @deprecated there is no meaninfuly logic abstracted, use event.key directly.
4
- */
5
- export declare const isEscapeKey: (key: string) => boolean;
6
- /**
7
- * @deprecated there is no meaninfuly logic abstracted, use event.key directly.
8
- */
9
- export declare const isTabKey: (key: string) => boolean;
10
2
  export declare function isPrintableKey(event: React.KeyboardEvent<HTMLElement>): boolean;
11
3
  export declare const GRID_MULTIPLE_SELECTION_KEYS: string[];
12
4
  export declare const GRID_CELL_EXIT_EDIT_MODE_KEYS: string[];
@@ -17,5 +9,5 @@ export declare const isCellExitEditModeKeys: (key: string) => boolean;
17
9
  export declare const isCellEditCommitKeys: (key: string) => boolean;
18
10
  export declare const isNavigationKey: (key: string) => boolean;
19
11
  export declare const isKeyboardEvent: (event: any) => event is React.KeyboardEvent<HTMLElement>;
20
- export declare const isHideMenuKey: (key: React.KeyboardEvent["key"]) => boolean;
12
+ export declare const isHideMenuKey: (key: React.KeyboardEvent["key"]) => key is "Tab" | "Escape";
21
13
  export declare function isPasteShortcut(event: React.KeyboardEvent): boolean;
@@ -1,13 +1,3 @@
1
- /**
2
- * @deprecated there is no meaninfuly logic abstracted, use event.key directly.
3
- */
4
- export const isEscapeKey = key => key === 'Escape';
5
-
6
- /**
7
- * @deprecated there is no meaninfuly logic abstracted, use event.key directly.
8
- */
9
- export const isTabKey = key => key === 'Tab';
10
-
11
1
  // Non printable keys have a name, for example "ArrowRight", see the whole list:
12
2
  // https://developer.mozilla.org/en-US/docs/Web/API/UI_Events/Keyboard_event_key_values
13
3
  // So event.key.length === 1 is often enough.
@@ -27,7 +17,7 @@ export const isCellExitEditModeKeys = key => GRID_CELL_EXIT_EDIT_MODE_KEYS.index
27
17
  export const isCellEditCommitKeys = key => GRID_CELL_EDIT_COMMIT_KEYS.indexOf(key) > -1;
28
18
  export const isNavigationKey = key => key.indexOf('Arrow') === 0 || key.indexOf('Page') === 0 || key === ' ' || key === 'Home' || key === 'End';
29
19
  export const isKeyboardEvent = event => !!event.key;
30
- export const isHideMenuKey = key => isTabKey(key) || isEscapeKey(key);
20
+ export const isHideMenuKey = key => key === 'Tab' || key === 'Escape';
31
21
 
32
22
  // In theory, on macOS, ctrl + v doesn't trigger a paste, so the function should return false.
33
23
  // However, maybe it's overkill to fix, so let's be lazy.
@@ -1,5 +0,0 @@
1
- import * as React from 'react';
2
- import { fastObjectShallowCompare } from './fastObjectShallowCompare';
3
- export function fastMemo(component) {
4
- return /*#__PURE__*/React.memo(component, fastObjectShallowCompare);
5
- }
@@ -1,28 +0,0 @@
1
- const is = Object.is;
2
- export function fastObjectShallowCompare(a, b) {
3
- if (a === b) {
4
- return true;
5
- }
6
- if (!(a instanceof Object) || !(b instanceof Object)) {
7
- return false;
8
- }
9
- let aLength = 0;
10
- let bLength = 0;
11
-
12
- /* eslint-disable guard-for-in */
13
- for (const key in a) {
14
- aLength += 1;
15
- if (!is(a[key], b[key])) {
16
- return false;
17
- }
18
- if (!(key in b)) {
19
- return false;
20
- }
21
- }
22
-
23
- /* eslint-disable-next-line @typescript-eslint/naming-convention, @typescript-eslint/no-unused-vars */
24
- for (const _ in b) {
25
- bLength += 1;
26
- }
27
- return aLength === bLength;
28
- }
@@ -1,19 +0,0 @@
1
- export function throttle(func, wait = 166) {
2
- let timeout;
3
- let lastArgs;
4
- const later = () => {
5
- timeout = undefined;
6
- func(...lastArgs);
7
- };
8
- function throttled(...args) {
9
- lastArgs = args;
10
- if (timeout === undefined) {
11
- timeout = setTimeout(later, wait);
12
- }
13
- }
14
- throttled.clear = () => {
15
- clearTimeout(timeout);
16
- timeout = undefined;
17
- };
18
- return throttled;
19
- }
@@ -1,34 +0,0 @@
1
- "use strict";
2
-
3
- Object.defineProperty(exports, "__esModule", {
4
- value: true
5
- });
6
- exports.fastObjectShallowCompare = fastObjectShallowCompare;
7
- const is = Object.is;
8
- function fastObjectShallowCompare(a, b) {
9
- if (a === b) {
10
- return true;
11
- }
12
- if (!(a instanceof Object) || !(b instanceof Object)) {
13
- return false;
14
- }
15
- let aLength = 0;
16
- let bLength = 0;
17
-
18
- /* eslint-disable guard-for-in */
19
- for (const key in a) {
20
- aLength += 1;
21
- if (!is(a[key], b[key])) {
22
- return false;
23
- }
24
- if (!(key in b)) {
25
- return false;
26
- }
27
- }
28
-
29
- /* eslint-disable-next-line @typescript-eslint/naming-convention, @typescript-eslint/no-unused-vars */
30
- for (const _ in b) {
31
- bLength += 1;
32
- }
33
- return aLength === bLength;
34
- }
@@ -1,25 +0,0 @@
1
- "use strict";
2
-
3
- Object.defineProperty(exports, "__esModule", {
4
- value: true
5
- });
6
- exports.throttle = throttle;
7
- function throttle(func, wait = 166) {
8
- let timeout;
9
- let lastArgs;
10
- const later = () => {
11
- timeout = undefined;
12
- func(...lastArgs);
13
- };
14
- function throttled(...args) {
15
- lastArgs = args;
16
- if (timeout === undefined) {
17
- timeout = setTimeout(later, wait);
18
- }
19
- }
20
- throttled.clear = () => {
21
- clearTimeout(timeout);
22
- timeout = undefined;
23
- };
24
- return throttled;
25
- }
@@ -1 +0,0 @@
1
- export declare function fastMemo<T>(component: T): T;
package/utils/fastMemo.js DELETED
@@ -1,5 +0,0 @@
1
- import * as React from 'react';
2
- import { fastObjectShallowCompare } from './fastObjectShallowCompare';
3
- export function fastMemo(component) {
4
- return /*#__PURE__*/React.memo(component, fastObjectShallowCompare);
5
- }
@@ -1 +0,0 @@
1
- export declare function fastObjectShallowCompare<T extends Record<string, any> | null>(a: T, b: T): boolean;
@@ -1,28 +0,0 @@
1
- const is = Object.is;
2
- export function fastObjectShallowCompare(a, b) {
3
- if (a === b) {
4
- return true;
5
- }
6
- if (!(a instanceof Object) || !(b instanceof Object)) {
7
- return false;
8
- }
9
- let aLength = 0;
10
- let bLength = 0;
11
-
12
- /* eslint-disable guard-for-in */
13
- for (const key in a) {
14
- aLength += 1;
15
- if (!is(a[key], b[key])) {
16
- return false;
17
- }
18
- if (!(key in b)) {
19
- return false;
20
- }
21
- }
22
-
23
- /* eslint-disable-next-line @typescript-eslint/naming-convention, @typescript-eslint/no-unused-vars */
24
- for (const _ in b) {
25
- bLength += 1;
26
- }
27
- return aLength === bLength;
28
- }
@@ -1,4 +0,0 @@
1
- export interface Cancelable {
2
- clear(): void;
3
- }
4
- export declare function throttle<T extends (...args: any[]) => any>(func: T, wait?: number): T & Cancelable;
package/utils/throttle.js DELETED
@@ -1,19 +0,0 @@
1
- export function throttle(func, wait = 166) {
2
- let timeout;
3
- let lastArgs;
4
- const later = () => {
5
- timeout = undefined;
6
- func(...lastArgs);
7
- };
8
- function throttled(...args) {
9
- lastArgs = args;
10
- if (timeout === undefined) {
11
- timeout = setTimeout(later, wait);
12
- }
13
- }
14
- throttled.clear = () => {
15
- clearTimeout(timeout);
16
- timeout = undefined;
17
- };
18
- return throttled;
19
- }