@mui/x-internals 7.12.0 → 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.
package/CHANGELOG.md CHANGED
@@ -3,6 +3,235 @@
3
3
  All notable changes to this project will be documented in this file.
4
4
  See [Conventional Commits](https://conventionalcommits.org) for commit guidelines.
5
5
 
6
+ ## 7.14.0
7
+
8
+ _Aug 23, 2024_
9
+
10
+ We'd like to offer a big thanks to the 14 contributors who made this release possible. Here are some highlights ✨:
11
+
12
+ - 💫 Allow [filtering the axis on zoom](https://mui.com/x/react-charts/zoom-and-pan/#zoom-filtering), making the axis adapt by removing values outside the view.
13
+
14
+ <img width="600" src="https://github.com/user-attachments/assets/e65bbd00-d2a8-4136-81cd-3598f1373c16" alt="filtering the axis on zoom" />
15
+
16
+ - 📊 Improve bar chart performances
17
+ - 🌍 Improve Czech (cs-CZ) and Hebrew (he-IL) locales on the Data Grid
18
+ - 🌍 Improve Chinese (zh-HK), Hebrew (he-IL), and Vietnamese (vi-VN) locales on the Date and Time Pickers
19
+ - 🐞 Bugfixes
20
+
21
+ <!--/ HIGHLIGHT_ABOVE_SEPARATOR /-->
22
+
23
+ ### Data Grid
24
+
25
+ #### `@mui/x-data-grid@7.14.0`
26
+
27
+ - [DataGrid] Use readonly array result for `getTreeDataPath` (#11743) @pcorpet
28
+ - [DataGrid] Use `event.key` for `Tab` and `Escape` keys (#14170) @k-rajat19
29
+ - [DataGrid] Introduce selectors with arguments (#14236) @MBilalShafi
30
+ - [DataGrid] include `api` in `gridCellParams` interface (#14201) @k-rajat19
31
+ - [l10n] Improve Czech (cs-CZ) locale (#14135) @chirimiri22
32
+ - [l10n] Improve Hebrew (he-IL) locale (#14287) @rotembarsela
33
+
34
+ #### `@mui/x-data-grid-pro@7.14.0` [![pro](https://mui.com/r/x-pro-svg)](https://mui.com/r/x-pro-svg-link 'Pro plan')
35
+
36
+ Same changes as in `@mui/x-data-grid@7.14.0`.
37
+
38
+ #### `@mui/x-data-grid-premium@7.14.0` [![premium](https://mui.com/r/x-premium-svg)](https://mui.com/r/x-premium-svg-link 'Premium plan')
39
+
40
+ Same changes as in `@mui/x-data-grid-pro@7.14.0`, plus:
41
+
42
+ - [DataGridPremium] Fix clipboard paste not working for a single cell on non-first page (#14261) @arminmeh
43
+ - [DataGridPremium] Fix `onCellSelectionModelChange` not triggered when additional cell range is selected (#14199) @arminmeh
44
+
45
+ ### Date and Time Pickers
46
+
47
+ #### `@mui/x-date-pickers@7.14.0`
48
+
49
+ - [l10n] Improve Chinese (zh-HK) locale (#13289) @yeeharn
50
+ - [l10n] Improve Hebrew (he-IL) locale (#14287) @rotembarsela
51
+ - [l10n] Improve Vietnamese (vi-VN) locale (#14238) @locnbk2002
52
+ - [TimePicker] Handle `Space` and `Enter` on the `TimeClock` component @arthurbalduini
53
+
54
+ #### `@mui/x-date-pickers-pro@7.14.0` [![pro](https://mui.com/r/x-pro-svg)](https://mui.com/r/x-pro-svg-link 'Pro plan')
55
+
56
+ Same changes as in `@mui/x-date-pickers@7.14.0`.
57
+
58
+ ### Charts
59
+
60
+ #### `@mui/x-charts@7.14.0`
61
+
62
+ - [charts] Fix grid overflow with zooming (#14280) @alexfauquette
63
+ - [charts] Improve bar chart performances (#14278) @alexfauquette
64
+ - [charts] Test pointer events (#14042) @alexfauquette
65
+ - [charts] Use `isPointInside` function for both graphs and axis (#14222) @JCQuintas
66
+
67
+ #### `@mui/x-charts-pro@7.0.0-alpha.2` [![pro](https://mui.com/r/x-pro-svg)](https://mui.com/r/x-pro-svg-link 'Pro plan')
68
+
69
+ Same changes as in `@mui/x-charts@7.14.0`, plus:
70
+
71
+ - [charts-pro] Zoom axis filtering (#14121) @JCQuintas
72
+
73
+ ### Docs
74
+
75
+ - [docs] Consistent use of UTC and timezones (#14250) @oliviertassinari
76
+ - [docs] Fix missing leading slashes in URLs (#14249) @oliviertassinari
77
+ - [docs] Dash usage revision on pickers pages (#14260) @arthurbalduini
78
+
79
+ ### Core
80
+
81
+ - [core] Follow JSDocs convention @oliviertassinari
82
+ - [core] Prepare for material v6 (#14143) @LukasTy
83
+ - [code-infra] Set up `eslint-plugin-testing-library` (#14232) @LukasTy
84
+ - [infra] Updated mui-x roadmap links with new project URL (#14271) @michelengelen
85
+
86
+ ## 7.13.0
87
+
88
+ _Aug 16, 2024_
89
+
90
+ We'd like to offer a big thanks to the 12 contributors who made this release possible. Here are some highlights ✨:
91
+
92
+ - 💫 Allow to [edit the label](https://mui.com/x/react-tree-view/rich-tree-view/editing/) of Tree View's items.
93
+
94
+ <img width="344" src="https://github.com/user-attachments/assets/1a6cf765-2dc8-4906-bd93-139086eed148" alt="Item label editing" />
95
+
96
+ - 🔧 Improve rows accessibility on the Data Grid features "Tree Data" and "Row Grouping". Certain "Row Grouping" accessibility updates will only be applied if experimental feature flag is enabled. See the [documentation](https://mui.com/x/react-data-grid/row-grouping/#accessibility-changes-in-v8) for more information.
97
+ - 🌍 Improve Vietnamese (vi-VN) locale on the Data Grid
98
+ - 🐞 Bugfixes
99
+
100
+ <!--/ HIGHLIGHT_ABOVE_SEPARATOR /-->
101
+
102
+ ### Data Grid
103
+
104
+ #### `@mui/x-data-grid@7.13.0`
105
+
106
+ - [DataGrid] Fix CSV export for `null` and `undefined` values (#14166) @k-rajat19
107
+ - [DataGrid] Fix error logged during skeleton loading with nested data grid (#14186) @KenanYusuf
108
+ - [DataGrid] Remove needless check in `useGridStateInitialization` (#14181) @k-rajat19
109
+ - [DataGrid] Add recipe for persisting filters in local storage (#14208) @cherniavskii
110
+ - [l10n] Improve Vietnamese (vi-VN) locale (#14216) @hungnd-casso
111
+
112
+ #### `@mui/x-data-grid-pro@7.13.0` [![pro](https://mui.com/r/x-pro-svg)](https://mui.com/r/x-pro-svg-link 'Pro plan')
113
+
114
+ Same changes as in `@mui/x-data-grid@7.13.0`, plus:
115
+
116
+ - [DataGridPro] Fix Tree Data and Row Grouping rows accessibility (#13623) @arminmeh
117
+
118
+ #### `@mui/x-data-grid-premium@7.13.0` [![premium](https://mui.com/r/x-premium-svg)](https://mui.com/r/x-premium-svg-link 'Premium plan')
119
+
120
+ Same changes as in `@mui/x-data-grid-pro@7.13.0`.
121
+
122
+ ### Date and Time Pickers
123
+
124
+ #### `@mui/x-date-pickers@7.13.0`
125
+
126
+ - [pickers] Fix date and time merging to retain milliseconds (#14173) @LukasTy
127
+
128
+ #### `@mui/x-date-pickers-pro@7.13.0` [![pro](https://mui.com/r/x-pro-svg)](https://mui.com/r/x-pro-svg-link 'Pro plan')
129
+
130
+ Same changes as in `@mui/x-date-pickers@7.13.0`.
131
+
132
+ ### Charts
133
+
134
+ #### `@mui/x-charts@7.13.0`
135
+
136
+ - [charts] Add `baseline` property to the `LineChart` `series` (#14153) @JCQuintas
137
+ - [charts] Fix issue where tooltip would disappear on mouse click (#14187) @alexfauquette
138
+ - [charts] Rename `CartesianContextProvider` to `CartesianProvider` (#14102) @JCQuintas
139
+ - [charts] Support axis with the same value for all data points (#14191) @alexfauquette
140
+
141
+ #### `@mui/x-charts-pro@7.0.0-alpha.1` [![pro](https://mui.com/r/x-pro-svg)](https://mui.com/r/x-pro-svg-link 'Pro plan')
142
+
143
+ Same changes as in `@mui/x-charts@7.13.0`.
144
+
145
+ ### Tree View
146
+
147
+ #### `@mui/x-tree-view@7.13.0`
148
+
149
+ - [TreeView] Add label editing feature (#13388) @noraleonte
150
+ - [TreeView] Fix the parameters passed for the `canMoveItemToNewPosition` prop (#14176) @flaviendelangle
151
+
152
+ ### Docs
153
+
154
+ - [docs] Extract dataset in the Line chart docs (#14034) @alexfauquette
155
+ - [docs] Remove redundant encoding in the mock data source server (#14185) @MBilalShafi
156
+ - [docs] Use Netflix financial results to document bar charts (#13991) @alexfauquette
157
+ - [docs] Remove relience of abbreviations (#14226) @oliviertassinari
158
+
159
+ ### Core
160
+
161
+ - [core] Bump monorepo (#14141) @Janpot
162
+ - [core] Fix ESLint issue (#14207) @LukasTy
163
+ - [core] Fix Netlify build cache issue (#14182) @cherniavskii
164
+ - [code-infra] Refactor Netlify `cache-docs` plugin setup (#14105) @LukasTy
165
+ - [internals] Move utils needed for tree view virtualization to shared package (#14202) @flaviendelangle
166
+
167
+ ## 7.12.1
168
+
169
+ _Aug 8, 2024_
170
+
171
+ We'd like to offer a big thanks to the 9 contributors who made this release possible. Here are some highlights ✨:
172
+
173
+ - 🎨 Charts get a new component to display color mapping in the legend
174
+ - 🚀 The `@mui/x-charts-pro` is released in alpha version 🧪. This new package introduces two main features:
175
+ - The Heatmap component
176
+ - The zoom interaction on the bar, line, and scatter charts
177
+ - 🌍 Improve Dutch (nl-NL) locale on the Date and Time Pickers
178
+ - 🐞 Bugfixes
179
+
180
+ <!--/ HIGHLIGHT_ABOVE_SEPARATOR /-->
181
+
182
+ ### Data Grid
183
+
184
+ #### `@mui/x-data-grid@7.12.1`
185
+
186
+ - [DataGrid] Fix `checkboxSelectionVisibleOnly` behavior with server-side pagination (#14083) @MBilalShafi
187
+ - [DataGrid] Fix `columnHeadersContainerRef` being `undefined` before mount (#14051) @samwato
188
+ - [DataGrid] Support Yarn PnP (#14126) @cherniavskii
189
+
190
+ #### `@mui/x-data-grid-pro@7.12.1` [![pro](https://mui.com/r/x-pro-svg)](https://mui.com/r/x-pro-svg-link 'Pro plan')
191
+
192
+ Same changes as in `@mui/x-data-grid@7.12.1`.
193
+
194
+ #### `@mui/x-data-grid-premium@7.12.1` [![premium](https://mui.com/r/x-premium-svg)](https://mui.com/r/x-premium-svg-link 'Premium plan')
195
+
196
+ Same changes as in `@mui/x-data-grid-pro@7.12.1`.
197
+
198
+ ### Date and Time Pickers
199
+
200
+ #### `@mui/x-date-pickers@7.12.1`
201
+
202
+ - [l10n] Improve Dutch (nlNL) locale (pickers) (#14036) @Robin1896
203
+
204
+ #### `@mui/x-date-pickers-pro@7.12.1` [![pro](https://mui.com/r/x-pro-svg)](https://mui.com/r/x-pro-svg-link 'Pro plan')
205
+
206
+ Same changes as in `@mui/x-date-pickers@7.12.1`.
207
+
208
+ ### Charts
209
+
210
+ #### `@mui/x-charts@7.12.1`
211
+
212
+ - [charts] Fix charts vendor publish config (#14073) @JCQuintas
213
+ - [charts] Move `plugins` to `PluginProvider` (#14056) @JCQuintas
214
+
215
+ #### `@mui/x-charts-pro@7.0.0-alpha.0` [![pro](https://mui.com/r/x-pro-svg)](https://mui.com/r/x-pro-svg-link 'Pro plan')
216
+
217
+ Same changes as in `@mui/x-charts@7.12.1`, plus:
218
+
219
+ - [charts-pro] Release the pro package in alpha (#13859) @alexfauquette
220
+
221
+ ### Tree View
222
+
223
+ #### `@mui/x-tree-view@7.12.1`
224
+
225
+ ### Docs
226
+
227
+ - [docs] Add a warning to promote the usage of `updateRows` (#14027) @MBilalShafi
228
+ - [docs] Disable ad in `Rich Tree View-Ordering` page (#14123) @oliviertassinari
229
+ - [docs] Redesign Date and Time Pickers overview page (#13241) @noraleonte
230
+
231
+ - [CHANGELOG] Polish details @oliviertassinari
232
+ - [code-infra] Use concurrency 1 in CircleCI (#14110) @JCQuintas
233
+ - [infra] Re-added the removal of `Latest Version` section (#14132) @michelengelen
234
+
6
235
  ## 7.12.0
7
236
 
8
237
  _Aug 1, 2024_
@@ -24,9 +253,9 @@ We'd like to offer a big thanks to the 12 contributors who made this release pos
24
253
 
25
254
  - 🎁 Introduce [item reordering using drag and drop](https://mui.com/x/react-tree-view/rich-tree-view/ordering/) on the `RichTreeViewPro` component
26
255
 
27
- <img width="384" src="https://github.com/user-attachments/assets/78bd83c5-7ce4-4ed7-acf9-be70b2dbce54" alt="Item reordering using drag and drop" />
256
+ <img width="287" src="https://github.com/user-attachments/assets/78bd83c5-7ce4-4ed7-acf9-be70b2dbce54" alt="Item reordering using drag and drop" />
28
257
 
29
- - 📦 Support Common JS bundle out of the box on `@mui/x-charts` by adding vendored D3 dependencies.
258
+ - 📦 Support CommonJS bundle out of the box on `@mui/x-charts` by adding vendored D3 dependencies.
30
259
 
31
260
  - This modifies how the package imports D3.js. It will impact you if you use `d3` packages installed by `@mui/x-charts` and don't have them in your `package.json`. You shouldn't be affected otherwise.
32
261
  - For more context, the initial issue is caused by D3 only exporting ESM.
@@ -0,0 +1 @@
1
+ export declare function fastMemo<T>(component: T): T;
@@ -0,0 +1,5 @@
1
+ import * as React from 'react';
2
+ import { fastObjectShallowCompare } from '../fastObjectShallowCompare';
3
+ export function fastMemo(component) {
4
+ return /*#__PURE__*/React.memo(component, fastObjectShallowCompare);
5
+ }
@@ -0,0 +1 @@
1
+ export { fastMemo } from './fastMemo';
@@ -0,0 +1 @@
1
+ export { fastMemo } from './fastMemo';
@@ -0,0 +1,6 @@
1
+ {
2
+ "sideEffects": false,
3
+ "module": "./index.js",
4
+ "main": "../node/fastMemo/index.js",
5
+ "types": "./index.d.ts"
6
+ }
@@ -0,0 +1 @@
1
+ export declare function fastObjectShallowCompare<T extends Record<string, any> | null>(a: T, b: T): boolean;
@@ -0,0 +1,28 @@
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
+ }
@@ -0,0 +1 @@
1
+ export { fastObjectShallowCompare } from './fastObjectShallowCompare';
@@ -0,0 +1 @@
1
+ export { fastObjectShallowCompare } from './fastObjectShallowCompare';
@@ -0,0 +1,6 @@
1
+ {
2
+ "sideEffects": false,
3
+ "module": "./index.js",
4
+ "main": "../node/fastObjectShallowCompare/index.js",
5
+ "types": "./index.d.ts"
6
+ }
@@ -0,0 +1,5 @@
1
+ import * as React from 'react';
2
+ import { fastObjectShallowCompare } from '../fastObjectShallowCompare';
3
+ export function fastMemo(component) {
4
+ return /*#__PURE__*/React.memo(component, fastObjectShallowCompare);
5
+ }
@@ -0,0 +1 @@
1
+ export { fastMemo } from './fastMemo';
@@ -0,0 +1,28 @@
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
+ }
@@ -0,0 +1 @@
1
+ export { fastObjectShallowCompare } from './fastObjectShallowCompare';
@@ -0,0 +1 @@
1
+ export { throttle } from './throttle';
@@ -0,0 +1,19 @@
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
+ }
@@ -0,0 +1,13 @@
1
+ "use strict";
2
+
3
+ Object.defineProperty(exports, "__esModule", {
4
+ value: true
5
+ });
6
+ exports.fastMemo = fastMemo;
7
+ var React = _interopRequireWildcard(require("react"));
8
+ var _fastObjectShallowCompare = require("../fastObjectShallowCompare");
9
+ function _getRequireWildcardCache(e) { if ("function" != typeof WeakMap) return null; var r = new WeakMap(), t = new WeakMap(); return (_getRequireWildcardCache = function (e) { return e ? t : r; })(e); }
10
+ function _interopRequireWildcard(e, r) { if (!r && e && e.__esModule) return e; if (null === e || "object" != typeof e && "function" != typeof e) return { default: e }; var t = _getRequireWildcardCache(r); if (t && t.has(e)) return t.get(e); var n = { __proto__: null }, a = Object.defineProperty && Object.getOwnPropertyDescriptor; for (var u in e) if ("default" !== u && {}.hasOwnProperty.call(e, u)) { var i = a ? Object.getOwnPropertyDescriptor(e, u) : null; i && (i.get || i.set) ? Object.defineProperty(n, u, i) : n[u] = e[u]; } return n.default = e, t && t.set(e, n), n; }
11
+ function fastMemo(component) {
12
+ return /*#__PURE__*/React.memo(component, _fastObjectShallowCompare.fastObjectShallowCompare);
13
+ }
@@ -0,0 +1,12 @@
1
+ "use strict";
2
+
3
+ Object.defineProperty(exports, "__esModule", {
4
+ value: true
5
+ });
6
+ Object.defineProperty(exports, "fastMemo", {
7
+ enumerable: true,
8
+ get: function () {
9
+ return _fastMemo.fastMemo;
10
+ }
11
+ });
12
+ var _fastMemo = require("./fastMemo");
@@ -0,0 +1,34 @@
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
+ }
@@ -0,0 +1,12 @@
1
+ "use strict";
2
+
3
+ Object.defineProperty(exports, "__esModule", {
4
+ value: true
5
+ });
6
+ Object.defineProperty(exports, "fastObjectShallowCompare", {
7
+ enumerable: true,
8
+ get: function () {
9
+ return _fastObjectShallowCompare.fastObjectShallowCompare;
10
+ }
11
+ });
12
+ var _fastObjectShallowCompare = require("./fastObjectShallowCompare");
@@ -0,0 +1,12 @@
1
+ "use strict";
2
+
3
+ Object.defineProperty(exports, "__esModule", {
4
+ value: true
5
+ });
6
+ Object.defineProperty(exports, "throttle", {
7
+ enumerable: true,
8
+ get: function () {
9
+ return _throttle.throttle;
10
+ }
11
+ });
12
+ var _throttle = require("./throttle");
@@ -0,0 +1,25 @@
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
+ }
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@mui/x-internals",
3
- "version": "7.12.0",
3
+ "version": "7.14.0",
4
4
  "description": "Utility functions for the MUI X packages (internal use only).",
5
5
  "author": "MUI Team",
6
6
  "license": "MIT",
@@ -32,7 +32,7 @@
32
32
  },
33
33
  "dependencies": {
34
34
  "@babel/runtime": "^7.25.0",
35
- "@mui/utils": "^5.16.5"
35
+ "@mui/utils": "^5.16.6"
36
36
  },
37
37
  "peerDependencies": {
38
38
  "react": "^17.0.0 || ^18.0.0"
@@ -0,0 +1 @@
1
+ export { throttle } from './throttle';
@@ -0,0 +1 @@
1
+ export { throttle } from './throttle';
@@ -0,0 +1,6 @@
1
+ {
2
+ "sideEffects": false,
3
+ "module": "./index.js",
4
+ "main": "../node/throttle/index.js",
5
+ "types": "./index.d.ts"
6
+ }
@@ -0,0 +1,4 @@
1
+ export interface Cancelable {
2
+ clear(): void;
3
+ }
4
+ export declare function throttle<T extends (...args: any[]) => any>(func: T, wait?: number): T & Cancelable;
@@ -0,0 +1,19 @@
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
+ }