@mui/x-internals 8.18.0 → 8.21.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 +287 -0
- package/esm/export/loadStyleSheets.js +11 -6
- package/esm/store/Store.d.ts +3 -0
- package/esm/store/Store.js +4 -0
- package/esm/store/useStore.js +15 -2
- package/esm/store/useStoreEffect.js +5 -2
- package/export/loadStyleSheets.js +11 -6
- package/package.json +1 -1
- package/store/Store.d.ts +3 -0
- package/store/Store.js +4 -0
- package/store/useStore.js +17 -2
- package/store/useStoreEffect.js +5 -2
package/CHANGELOG.md
CHANGED
|
@@ -5,6 +5,293 @@
|
|
|
5
5
|
All notable changes to this project will be documented in this file.
|
|
6
6
|
See [Conventional Commits](https://conventionalcommits.org) for commit guidelines.
|
|
7
7
|
|
|
8
|
+
## 8.21.0
|
|
9
|
+
|
|
10
|
+
_Dec 3, 2025_
|
|
11
|
+
|
|
12
|
+
We'd like to extend a big thank you to the 8 contributors who made this release possible. Here are some highlights ✨:
|
|
13
|
+
|
|
14
|
+
- ✨ Add [tick spacing property](https://mui.com/x/react-charts/axis/#tick-spacing) to charts axis to control the distance between ticks.
|
|
15
|
+
|
|
16
|
+
The following team members contributed to this release:
|
|
17
|
+
@alexfauquette, @bernardobelchior, @ElliottMiller, @Janpot, @JCQuintas, @romgrk, @sai6855, @siriwatknp
|
|
18
|
+
|
|
19
|
+
### Data Grid
|
|
20
|
+
|
|
21
|
+
#### `@mui/x-data-grid@8.21.0`
|
|
22
|
+
|
|
23
|
+
- [DataGrid] Fix autosizing header width calculation (#20323) @siriwatknp
|
|
24
|
+
- [DataGrid] Virtualizer refactor (#19465) @romgrk
|
|
25
|
+
|
|
26
|
+
#### `@mui/x-data-grid-pro@8.21.0` [](https://mui.com/r/x-pro-svg-link 'Pro plan')
|
|
27
|
+
|
|
28
|
+
Same changes as in `@mui/x-data-grid@8.21.0`.
|
|
29
|
+
|
|
30
|
+
#### `@mui/x-data-grid-premium@8.21.0` [](https://mui.com/r/x-premium-svg-link 'Premium plan')
|
|
31
|
+
|
|
32
|
+
Same changes as in `@mui/x-data-grid-pro@8.21.0`, plus:
|
|
33
|
+
|
|
34
|
+
- [DataGridPremium] Prevent pasting to non-editable cells (#20333) @ElliottMiller
|
|
35
|
+
|
|
36
|
+
### Date and Time Pickers
|
|
37
|
+
|
|
38
|
+
#### `@mui/x-date-pickers@8.21.0`
|
|
39
|
+
|
|
40
|
+
Internal changes.
|
|
41
|
+
|
|
42
|
+
#### `@mui/x-date-pickers-pro@8.21.0` [](https://mui.com/r/x-pro-svg-link 'Pro plan')
|
|
43
|
+
|
|
44
|
+
Same changes as in `@mui/x-date-pickers@8.21.0`.
|
|
45
|
+
|
|
46
|
+
### Charts
|
|
47
|
+
|
|
48
|
+
#### `@mui/x-charts@8.21.0`
|
|
49
|
+
|
|
50
|
+
- [charts] Fix string measuring types (#20454) @bernardobelchior
|
|
51
|
+
- [charts] Fix typo in performance note for CustomLineMarks demo (#20529) @sai6855
|
|
52
|
+
- [charts] Introduce the notion of series with positions (#20461) @alexfauquette
|
|
53
|
+
- [charts] Migrate from sinon to Vitest mocking utilities for x-charts\* packages (#20444) @Copilot
|
|
54
|
+
- [charts] Move series-level values to series computed data in bar plot (#20467) @bernardobelchior
|
|
55
|
+
- [charts] Refactor bar chart components in preparation for range bar chart (#20521) @bernardobelchior
|
|
56
|
+
- [charts] Remove unnecessary `any` types (#20527) @sai6855
|
|
57
|
+
- [charts] Remove unused `drawingArea` from `findClosestPoints` (#20471) @bernardobelchior
|
|
58
|
+
- [charts] Revert `useIsHydrated` to default=false (#20511) @JCQuintas
|
|
59
|
+
- [charts] Support tooltip anchor position for radar (#20422) @alexfauquette
|
|
60
|
+
- [charts] Add tick spacing property (#20282) @bernardobelchior
|
|
61
|
+
- [charts] Fix Vitest lint error (#20550) @bernardobelchior
|
|
62
|
+
- [charts] Fix infinite loop when highlighting pie slices or scatter points (#20549) @bernardobelchior
|
|
63
|
+
|
|
64
|
+
#### `@mui/x-charts-pro@8.21.0` [](https://mui.com/r/x-pro-svg-link 'Pro plan')
|
|
65
|
+
|
|
66
|
+
Same changes as in `@mui/x-charts@8.21.0`, plus:
|
|
67
|
+
|
|
68
|
+
- [charts-pro] Add support for `anchor="node"` on Sankey tooltip (#20462) @alexfauquette
|
|
69
|
+
|
|
70
|
+
#### `@mui/x-charts-premium@8.21.0` [](https://mui.com/r/x-premium-svg-link 'Premium plan')
|
|
71
|
+
|
|
72
|
+
Same changes as in `@mui/x-charts-pro@8.21.0`.
|
|
73
|
+
|
|
74
|
+
### Tree View
|
|
75
|
+
|
|
76
|
+
#### `@mui/x-tree-view@8.21.0`
|
|
77
|
+
|
|
78
|
+
Internal changes.
|
|
79
|
+
|
|
80
|
+
#### `@mui/x-tree-view-pro@8.21.0` [](https://mui.com/r/x-pro-svg-link 'Pro plan')
|
|
81
|
+
|
|
82
|
+
Same changes as in `@mui/x-tree-view@8.21.0`.
|
|
83
|
+
|
|
84
|
+
### Codemod
|
|
85
|
+
|
|
86
|
+
#### `@mui/x-codemod@8.21.0`
|
|
87
|
+
|
|
88
|
+
Internal changes.
|
|
89
|
+
|
|
90
|
+
### Docs
|
|
91
|
+
|
|
92
|
+
- [docs] Migrate to `next/font` for fonts loading (#20407) @Copilot
|
|
93
|
+
|
|
94
|
+
### Core
|
|
95
|
+
|
|
96
|
+
- [code-infra] Enable vitest eslint plugin (#20530) @Janpot
|
|
97
|
+
- [code-infra] Fix missing font loading for local fonts (#20480) @Janpot
|
|
98
|
+
- [internal] Performance: use raw `useSyncExternalStore` (#20447) @romgrk
|
|
99
|
+
- [code-infra] Enable `vitest/expect-expect` and `vitest/no-standalone-expect` rules for x-charts packages (#20535) @Copilot
|
|
100
|
+
|
|
101
|
+
### Miscellaneous
|
|
102
|
+
|
|
103
|
+
- Bump @types/d3-sankey to ^0.12.5 (#20489) @renovate[bot]
|
|
104
|
+
- Bump @types/react to 19.2.7 (#20490) @renovate[bot]
|
|
105
|
+
- Bump @types/yargs to ^17.0.35 (#20491) @renovate[bot]
|
|
106
|
+
- Bump Vite & Vitest to ^4.0.14 (#20500) @renovate[bot]
|
|
107
|
+
- Bump csstype to ^3.2.3 (#20493) @renovate[bot]
|
|
108
|
+
- Bump es-toolkit to ^1.42.0 (#20494) @renovate[bot]
|
|
109
|
+
- Bump eslint to ^8.48.0 (#20495) @renovate[bot]
|
|
110
|
+
- Bump lerna to ^9.0.3 (#20496) @renovate[bot]
|
|
111
|
+
- Bump lucide-react to ^0.555.0 (#20502) @renovate[bot]
|
|
112
|
+
- Bump playwright monorepo (#20503) @renovate[bot]
|
|
113
|
+
- Bump pnpm to 10.24.0 (#20504) @renovate[bot]
|
|
114
|
+
- Bump react monorepo (#20340) @renovate[bot]
|
|
115
|
+
- Bump react-hook-form to ^7.66.1 (#20497) @renovate[bot]
|
|
116
|
+
- Bump rimraf to ^6.1.2 (#20498) @renovate[bot]
|
|
117
|
+
- Bump webpack-bundle-analyzer to ^5.0.1 (#20508) @renovate[bot]
|
|
118
|
+
- Bump next to ^15.5.6 [SECURITY] (#20555) @renovate[bot]
|
|
119
|
+
|
|
120
|
+
## 8.20.0
|
|
121
|
+
|
|
122
|
+
_Nov 26, 2025_
|
|
123
|
+
|
|
124
|
+
We'd like to extend a big thank you to the 8 contributors who made this release possible. Here are some highlights ✨:
|
|
125
|
+
|
|
126
|
+
- 🔃 Data Grid tree data now supports row reordering. See the [Drag-and-drop tree data reordering](https://mui.com/x/react-data-grid/tree-data/#drag-and-drop-tree-data-reordering) section for more details.
|
|
127
|
+
- 🐞 Bugfixes
|
|
128
|
+
|
|
129
|
+
The following team members contributed to this release:
|
|
130
|
+
@alexfauquette, @arminmeh, @bernardobelchior, @cherniavskii, @siriwatknp, @JCQuintas, @MBilalShafi, @prakhargupta1
|
|
131
|
+
|
|
132
|
+
### Data Grid
|
|
133
|
+
|
|
134
|
+
#### `@mui/x-data-grid@8.20.0`
|
|
135
|
+
|
|
136
|
+
- [DataGrid] Fix RTL virtualization to display columns when viewport width is larger than the grid (#20409) @siriwatknp
|
|
137
|
+
- [DataGrid] Fix row range selection (#20442) @arminmeh
|
|
138
|
+
- [DataGrid] Initialize data grid core packages (#20276) @cherniavskii
|
|
139
|
+
- [DataGrid] Improve accessibility of the sort icon (#20430) @arminmeh
|
|
140
|
+
- [DataGrid] Use `viewport` as a boundary for the `BasePopper` flip (#20311) @arminmeh
|
|
141
|
+
|
|
142
|
+
#### `@mui/x-data-grid-pro@8.20.0` [](https://mui.com/r/x-pro-svg-link 'Pro plan')
|
|
143
|
+
|
|
144
|
+
Same changes as in `@mui/x-data-grid@8.20.0`, plus:
|
|
145
|
+
|
|
146
|
+
- [DataGridPro] Avoid automatic scroll back to the focused header filter after it leaves the viewport (#20416) @arminmeh
|
|
147
|
+
- [DataGridPro] Tree data row reordering (#19401) @MBilalShafi
|
|
148
|
+
|
|
149
|
+
#### `@mui/x-data-grid-premium@8.20.0` [](https://mui.com/r/x-premium-svg-link 'Premium plan')
|
|
150
|
+
|
|
151
|
+
Same changes as in `@mui/x-data-grid-pro@8.20.0`.
|
|
152
|
+
|
|
153
|
+
### Charts
|
|
154
|
+
|
|
155
|
+
#### `@mui/x-charts@8.20.0`
|
|
156
|
+
|
|
157
|
+
- [charts] Fix item tooltip position with node anchor (#20421) @alexfauquette
|
|
158
|
+
- [charts] Fix radar item tooltip closing bug (#20429) @alexfauquette
|
|
159
|
+
- [charts] Move series processing to selector (#20388) @JCQuintas
|
|
160
|
+
- [charts] Prevent pointer out from removing controlled highlight (#20385) @alexfauquette
|
|
161
|
+
|
|
162
|
+
#### `@mui/x-charts-pro@8.20.0` [](https://mui.com/r/x-pro-svg-link 'Pro plan')
|
|
163
|
+
|
|
164
|
+
Same changes as in `@mui/x-charts@8.20.0`, plus:
|
|
165
|
+
|
|
166
|
+
- [charts-pro] Fix Content-Security-Policy nonce not being correctly set on export (#20395) @bernardobelchior
|
|
167
|
+
- [charts-pro] Improve vertical zoom slider thumb on mobile (#20439) @bernardobelchior
|
|
168
|
+
- [charts-pro] Provide arguments to the `AreaPlotRoot` styled component (#20414) @arminmeh
|
|
169
|
+
- [charts-pro] Remove grid outside the drawing area (#20412) @alexfauquette
|
|
170
|
+
|
|
171
|
+
#### `@mui/x-charts-premium@8.20.0` [](https://mui.com/r/x-premium-svg-link 'Premium plan')
|
|
172
|
+
|
|
173
|
+
Same changes as in `@mui/x-charts-pro@8.20.0`, plus:
|
|
174
|
+
|
|
175
|
+
- [charts-premium] Add explicit return type to `ChartsRenderer` for better compatibility with React 18 (#20413) @arminmeh
|
|
176
|
+
|
|
177
|
+
### Docs
|
|
178
|
+
|
|
179
|
+
- [docs] Add `llms.txt` link to the sidebar (#20312) @siriwatknp
|
|
180
|
+
- [docs] Add a line chart demo for the Overview section (#20239) @prakhargupta1
|
|
181
|
+
|
|
182
|
+
## 8.19.0
|
|
183
|
+
|
|
184
|
+
_Nov 20, 2025_
|
|
185
|
+
|
|
186
|
+
We'd like to extend a big thank you to the 15 contributors who made this release possible. Here are some highlights ✨:
|
|
187
|
+
|
|
188
|
+
- 🔎 Add pan on `wheel` to the charts zoom
|
|
189
|
+
- ⌨️ Allow opt-in to [tab navigation](https://mui.com/x/react-data-grid/accessibility/#tab-navigation) inside the Data Grid.
|
|
190
|
+
- ⚙️ New way of defining [action columns](https://mui.com/x/react-data-grid/column-definition/#ActionsWithModalGrid.tsx) in the Data Grid that makes it easier to keep `columns` prop stable.
|
|
191
|
+
- 🐞 Bugfixes
|
|
192
|
+
- 📚 Documentation improvements
|
|
193
|
+
|
|
194
|
+
Special thanks go out to these community members for their valuable contributions:
|
|
195
|
+
@lauri865, @noobyogi0010, @sai6855
|
|
196
|
+
|
|
197
|
+
The following team members contributed to this release:
|
|
198
|
+
@alexfauquette, @arminmeh, @bernardobelchior, @cherniavskii, @flaviendelangle, @Janpot, @JCQuintas, @mj12albert, @noraleonte, @rita-codes, @siriwatknp, @ZeeshanTamboli
|
|
199
|
+
|
|
200
|
+
### Data Grid
|
|
201
|
+
|
|
202
|
+
#### `@mui/x-data-grid@8.19.0`
|
|
203
|
+
|
|
204
|
+
- [DataGrid] Add `tabNavigation` prop to control tab navigation in the grid (#20286) @arminmeh
|
|
205
|
+
- [DataGrid] Allow to focus disabled checkbox cells (#19959) @mj12albert
|
|
206
|
+
- [DataGrid] Alternative actions column definition API (#15041) @cherniavskii
|
|
207
|
+
- [DataGrid] Fix failing tests (#20332) @cherniavskii
|
|
208
|
+
- [DataGrid] Prevent Safari 26 error in the event handler (#20369) @arminmeh
|
|
209
|
+
- [DataGrid] Undeprecate the `autoHeight` prop (#20363) @cherniavskii
|
|
210
|
+
- [DataGrid] Fix print export grid dimensions with dynamic row height and print styles (#19835) @cherniavskii
|
|
211
|
+
|
|
212
|
+
#### `@mui/x-data-grid-pro@8.19.0` [](https://mui.com/r/x-pro-svg-link 'Pro plan')
|
|
213
|
+
|
|
214
|
+
Same changes as in `@mui/x-data-grid@8.19.0`.
|
|
215
|
+
|
|
216
|
+
#### `@mui/x-data-grid-premium@8.19.0` [](https://mui.com/r/x-premium-svg-link 'Premium plan')
|
|
217
|
+
|
|
218
|
+
Same changes as in `@mui/x-data-grid-pro@8.19.0`, plus:
|
|
219
|
+
|
|
220
|
+
- [DataGridPremium] Fix aggregation with sorting (#19892) @lauri865
|
|
221
|
+
- [DataGridPremium] Lock `ExcelJS` version (#20329) @cherniavskii
|
|
222
|
+
|
|
223
|
+
### Date and Time Pickers
|
|
224
|
+
|
|
225
|
+
#### `@mui/x-date-pickers@8.19.0`
|
|
226
|
+
|
|
227
|
+
- [pickers] Do not loose `slotProps.field.slotProps` (#20322) @flaviendelangle
|
|
228
|
+
|
|
229
|
+
#### `@mui/x-date-pickers-pro@8.19.0` [](https://mui.com/r/x-pro-svg-link 'Pro plan')
|
|
230
|
+
|
|
231
|
+
Same changes as in `@mui/x-date-pickers@8.19.0`.
|
|
232
|
+
|
|
233
|
+
### Charts
|
|
234
|
+
|
|
235
|
+
#### `@mui/x-charts@8.19.0`
|
|
236
|
+
|
|
237
|
+
- [charts] Expose `niceDomain` utility (#20250) @bernardobelchior
|
|
238
|
+
- [charts] Fix benchmark regression by downgrading to JSDOM v26 (#20405) @bernardobelchior
|
|
239
|
+
- [charts] Fix Pie Chart keyboard focus highlight (#20358) @JCQuintas
|
|
240
|
+
- [charts] Memoize series selectors (#20326) @JCQuintas
|
|
241
|
+
- [charts] Relax dataset type (#20294) @bernardobelchior
|
|
242
|
+
- [charts] Remove `touch-action: pan-y` when zoom is disabled (#20204) @bernardobelchior
|
|
243
|
+
- [charts] Use `getBBox()` for correct SVG sizes in firefox (#20309) @JCQuintas
|
|
244
|
+
- [charts] Use directly selector from `@mui/x-internals` (#20365) @alexfauquette
|
|
245
|
+
- [charts] Fix unnecessary errors in dev mode (#20380) @JCQuintas
|
|
246
|
+
|
|
247
|
+
#### `@mui/x-charts-pro@8.19.0` [](https://mui.com/r/x-pro-svg-link 'Pro plan')
|
|
248
|
+
|
|
249
|
+
Same changes as in `@mui/x-charts@8.19.0`, plus:
|
|
250
|
+
|
|
251
|
+
- [charts-pro] Add pan on `wheel` to zoom (#19998) @JCQuintas
|
|
252
|
+
- [charts-pro] Fix zoom slider preview having an opaque background in dark mode (#20367) @bernardobelchior
|
|
253
|
+
|
|
254
|
+
#### `@mui/x-charts-premium@8.19.0` [](https://mui.com/r/x-premium-svg-link 'Premium plan')
|
|
255
|
+
|
|
256
|
+
Same changes as in `@mui/x-charts-pro@8.19.0`.
|
|
257
|
+
|
|
258
|
+
### Tree View
|
|
259
|
+
|
|
260
|
+
#### `@mui/x-tree-view@8.19.0`
|
|
261
|
+
|
|
262
|
+
- [tree view] Enable lazy load when children count is not know in tree view (#18680) @noobyogi0010
|
|
263
|
+
- [tree view] Fix unwanted behaviors on the item re-ordering (#20368) @flaviendelangle
|
|
264
|
+
|
|
265
|
+
#### `@mui/x-tree-view-pro@8.19.0` [](https://mui.com/r/x-pro-svg-link 'Pro plan')
|
|
266
|
+
|
|
267
|
+
Same changes as in `@mui/x-tree-view@8.19.0`.
|
|
268
|
+
|
|
269
|
+
### Codemod
|
|
270
|
+
|
|
271
|
+
#### `@mui/x-codemod@8.19.0`
|
|
272
|
+
|
|
273
|
+
Internal changes.
|
|
274
|
+
|
|
275
|
+
### Docs
|
|
276
|
+
|
|
277
|
+
- [docs] Add minimum Typescript version to migration guide (#20320) @siriwatknp
|
|
278
|
+
- [docs] Fix Autosizing documentation (#20348) @siriwatknp
|
|
279
|
+
- [docs] Fix separator opacity in demo (#20293) @sai6855
|
|
280
|
+
- [docs] Replace deprecated `LoadingButton` with `Button` component (#20208) @Janpot
|
|
281
|
+
|
|
282
|
+
### Core
|
|
283
|
+
|
|
284
|
+
- [code-infra] Add new broken links checker (#20120) @Janpot
|
|
285
|
+
- [code-infra] Disable Codspeed pipeline (#20370) @JCQuintas
|
|
286
|
+
- [code-infra] Optimize `checkMaterialVersion` (#20307) @Janpot
|
|
287
|
+
- [code-infra] Use utils from code-infra for changelog and PR creation (#20406) @brijeshb42
|
|
288
|
+
- [docs-infra] Revert `@docsearch/react` (#20313) @Janpot
|
|
289
|
+
|
|
290
|
+
### Miscellaneous
|
|
291
|
+
|
|
292
|
+
- [test] Fix browser tests skipping some projects (#20318) @cherniavskii
|
|
293
|
+
- [test] Update `use-react-version` pnpm script (#20319) @cherniavskii
|
|
294
|
+
|
|
8
295
|
## 8.18.0
|
|
9
296
|
|
|
10
297
|
<!-- generated comparing v8.17.0..master -->
|
|
@@ -10,7 +10,7 @@ export function loadStyleSheets(document, root, nonce) {
|
|
|
10
10
|
const headStyleElements = root.querySelectorAll("style, link[rel='stylesheet']");
|
|
11
11
|
for (let i = 0; i < headStyleElements.length; i += 1) {
|
|
12
12
|
const node = headStyleElements[i];
|
|
13
|
-
const
|
|
13
|
+
const newHeadStyleElement = document.createElement(node.tagName);
|
|
14
14
|
if (node.tagName === 'STYLE') {
|
|
15
15
|
const sheet = node.sheet;
|
|
16
16
|
if (sheet) {
|
|
@@ -20,23 +20,28 @@ export function loadStyleSheets(document, root, nonce) {
|
|
|
20
20
|
styleCSS += `${sheet.cssRules[j].cssText}\r\n`;
|
|
21
21
|
}
|
|
22
22
|
}
|
|
23
|
-
|
|
23
|
+
newHeadStyleElement.appendChild(document.createTextNode(styleCSS));
|
|
24
24
|
}
|
|
25
25
|
} else if (node.getAttribute('href')) {
|
|
26
26
|
for (let j = 0; j < node.attributes.length; j += 1) {
|
|
27
27
|
const attr = node.attributes[j];
|
|
28
28
|
if (attr) {
|
|
29
|
-
|
|
29
|
+
newHeadStyleElement.setAttribute(attr.nodeName, attr.nodeValue || '');
|
|
30
30
|
}
|
|
31
31
|
}
|
|
32
32
|
stylesheetLoadPromises.push(new Promise(resolve => {
|
|
33
|
-
|
|
33
|
+
newHeadStyleElement.addEventListener('load', () => resolve());
|
|
34
34
|
}));
|
|
35
35
|
}
|
|
36
36
|
if (nonce) {
|
|
37
|
-
|
|
37
|
+
newHeadStyleElement.setAttribute('nonce', nonce);
|
|
38
|
+
}
|
|
39
|
+
document.head.appendChild(newHeadStyleElement);
|
|
40
|
+
if (nonce) {
|
|
41
|
+
// I don't understand why we need to set the nonce again after appending the element, but I've tested it, and it's
|
|
42
|
+
// the only way I could find to fix Chrome's warning about a CSP violation.
|
|
43
|
+
newHeadStyleElement.setAttribute('nonce', nonce);
|
|
38
44
|
}
|
|
39
|
-
document.head.appendChild(newHeadStyleElements);
|
|
40
45
|
}
|
|
41
46
|
return stylesheetLoadPromises;
|
|
42
47
|
}
|
package/esm/store/Store.d.ts
CHANGED
|
@@ -10,6 +10,9 @@ export declare class Store<State> {
|
|
|
10
10
|
setState(newState: State): void;
|
|
11
11
|
update(changes: Partial<State>): void;
|
|
12
12
|
set<Key extends keyof State, T extends State[Key]>(key: Key, value: T): void;
|
|
13
|
+
use: <F extends (...args: any) => any>(selector: F, ...args: SelectorArgs<F>) => ReturnType<F>;
|
|
13
14
|
}
|
|
14
15
|
export type ReadonlyStore<State> = Pick<Store<State>, 'getSnapshot' | 'subscribe' | 'state'>;
|
|
16
|
+
type SelectorArgs<Selector> = Selector extends ((...params: infer Params) => any) ? Tail<Params> : never;
|
|
17
|
+
type Tail<T extends readonly any[]> = T extends readonly [any, ...infer Rest] ? Rest : [];
|
|
15
18
|
export {};
|
package/esm/store/Store.js
CHANGED
|
@@ -1,4 +1,5 @@
|
|
|
1
1
|
import _extends from "@babel/runtime/helpers/esm/extends";
|
|
2
|
+
import { useStore } from "./useStore.js";
|
|
2
3
|
/* eslint-disable no-cond-assign */
|
|
3
4
|
|
|
4
5
|
export class Store {
|
|
@@ -54,4 +55,7 @@ export class Store {
|
|
|
54
55
|
}));
|
|
55
56
|
}
|
|
56
57
|
}
|
|
58
|
+
use = (() => (selector, a1, a2, a3) => {
|
|
59
|
+
return useStore(this, selector, a1, a2, a3);
|
|
60
|
+
})();
|
|
57
61
|
}
|
package/esm/store/useStore.js
CHANGED
|
@@ -1,7 +1,20 @@
|
|
|
1
|
+
import * as React from 'react';
|
|
1
2
|
/* We need to import the shim because React 17 does not support the `useSyncExternalStore` API.
|
|
2
3
|
* More info: https://github.com/mui/mui-x/issues/18303#issuecomment-2958392341 */
|
|
4
|
+
import { useSyncExternalStore } from 'use-sync-external-store/shim';
|
|
3
5
|
import { useSyncExternalStoreWithSelector } from 'use-sync-external-store/shim/with-selector';
|
|
6
|
+
import reactMajor from "../reactMajor/index.js";
|
|
7
|
+
/* Some tests fail in R18 with the raw useSyncExternalStore. It may be possible to make it work
|
|
8
|
+
* but for now we only enable it for R19+. */
|
|
9
|
+
const canUseRawUseSyncExternalStore = reactMajor >= 19;
|
|
10
|
+
const useStoreImplementation = canUseRawUseSyncExternalStore ? useStoreR19 : useStoreLegacy;
|
|
4
11
|
export function useStore(store, selector, a1, a2, a3) {
|
|
5
|
-
|
|
6
|
-
|
|
12
|
+
return useStoreImplementation(store, selector, a1, a2, a3);
|
|
13
|
+
}
|
|
14
|
+
function useStoreR19(store, selector, a1, a2, a3) {
|
|
15
|
+
const getSelection = React.useCallback(() => selector(store.getSnapshot(), a1, a2, a3), [store, selector, a1, a2, a3]);
|
|
16
|
+
return useSyncExternalStore(store.subscribe, getSelection, getSelection);
|
|
17
|
+
}
|
|
18
|
+
function useStoreLegacy(store, selector, a1, a2, a3) {
|
|
19
|
+
return useSyncExternalStoreWithSelector(store.subscribe, store.getSnapshot, store.getSnapshot, state => selector(state, a1, a2, a3));
|
|
7
20
|
}
|
|
@@ -31,8 +31,11 @@ function initialize(params) {
|
|
|
31
31
|
subscribe: () => {
|
|
32
32
|
instance.dispose ??= store.subscribe(state => {
|
|
33
33
|
const nextState = selector(state);
|
|
34
|
-
|
|
35
|
-
|
|
34
|
+
if (!Object.is(previousState, nextState)) {
|
|
35
|
+
const prev = previousState;
|
|
36
|
+
previousState = nextState;
|
|
37
|
+
instance.effect(prev, nextState);
|
|
38
|
+
}
|
|
36
39
|
});
|
|
37
40
|
},
|
|
38
41
|
onMount: () => {
|
|
@@ -16,7 +16,7 @@ function loadStyleSheets(document, root, nonce) {
|
|
|
16
16
|
const headStyleElements = root.querySelectorAll("style, link[rel='stylesheet']");
|
|
17
17
|
for (let i = 0; i < headStyleElements.length; i += 1) {
|
|
18
18
|
const node = headStyleElements[i];
|
|
19
|
-
const
|
|
19
|
+
const newHeadStyleElement = document.createElement(node.tagName);
|
|
20
20
|
if (node.tagName === 'STYLE') {
|
|
21
21
|
const sheet = node.sheet;
|
|
22
22
|
if (sheet) {
|
|
@@ -26,23 +26,28 @@ function loadStyleSheets(document, root, nonce) {
|
|
|
26
26
|
styleCSS += `${sheet.cssRules[j].cssText}\r\n`;
|
|
27
27
|
}
|
|
28
28
|
}
|
|
29
|
-
|
|
29
|
+
newHeadStyleElement.appendChild(document.createTextNode(styleCSS));
|
|
30
30
|
}
|
|
31
31
|
} else if (node.getAttribute('href')) {
|
|
32
32
|
for (let j = 0; j < node.attributes.length; j += 1) {
|
|
33
33
|
const attr = node.attributes[j];
|
|
34
34
|
if (attr) {
|
|
35
|
-
|
|
35
|
+
newHeadStyleElement.setAttribute(attr.nodeName, attr.nodeValue || '');
|
|
36
36
|
}
|
|
37
37
|
}
|
|
38
38
|
stylesheetLoadPromises.push(new Promise(resolve => {
|
|
39
|
-
|
|
39
|
+
newHeadStyleElement.addEventListener('load', () => resolve());
|
|
40
40
|
}));
|
|
41
41
|
}
|
|
42
42
|
if (nonce) {
|
|
43
|
-
|
|
43
|
+
newHeadStyleElement.setAttribute('nonce', nonce);
|
|
44
|
+
}
|
|
45
|
+
document.head.appendChild(newHeadStyleElement);
|
|
46
|
+
if (nonce) {
|
|
47
|
+
// I don't understand why we need to set the nonce again after appending the element, but I've tested it, and it's
|
|
48
|
+
// the only way I could find to fix Chrome's warning about a CSP violation.
|
|
49
|
+
newHeadStyleElement.setAttribute('nonce', nonce);
|
|
44
50
|
}
|
|
45
|
-
document.head.appendChild(newHeadStyleElements);
|
|
46
51
|
}
|
|
47
52
|
return stylesheetLoadPromises;
|
|
48
53
|
}
|
package/package.json
CHANGED
package/store/Store.d.ts
CHANGED
|
@@ -10,6 +10,9 @@ export declare class Store<State> {
|
|
|
10
10
|
setState(newState: State): void;
|
|
11
11
|
update(changes: Partial<State>): void;
|
|
12
12
|
set<Key extends keyof State, T extends State[Key]>(key: Key, value: T): void;
|
|
13
|
+
use: <F extends (...args: any) => any>(selector: F, ...args: SelectorArgs<F>) => ReturnType<F>;
|
|
13
14
|
}
|
|
14
15
|
export type ReadonlyStore<State> = Pick<Store<State>, 'getSnapshot' | 'subscribe' | 'state'>;
|
|
16
|
+
type SelectorArgs<Selector> = Selector extends ((...params: infer Params) => any) ? Tail<Params> : never;
|
|
17
|
+
type Tail<T extends readonly any[]> = T extends readonly [any, ...infer Rest] ? Rest : [];
|
|
15
18
|
export {};
|
package/store/Store.js
CHANGED
|
@@ -6,6 +6,7 @@ Object.defineProperty(exports, "__esModule", {
|
|
|
6
6
|
});
|
|
7
7
|
exports.Store = void 0;
|
|
8
8
|
var _extends2 = _interopRequireDefault(require("@babel/runtime/helpers/extends"));
|
|
9
|
+
var _useStore = require("./useStore");
|
|
9
10
|
/* eslint-disable no-cond-assign */
|
|
10
11
|
|
|
11
12
|
class Store {
|
|
@@ -61,5 +62,8 @@ class Store {
|
|
|
61
62
|
}));
|
|
62
63
|
}
|
|
63
64
|
}
|
|
65
|
+
use = (selector, a1, a2, a3) => {
|
|
66
|
+
return (0, _useStore.useStore)(this, selector, a1, a2, a3);
|
|
67
|
+
};
|
|
64
68
|
}
|
|
65
69
|
exports.Store = Store;
|
package/store/useStore.js
CHANGED
|
@@ -1,14 +1,29 @@
|
|
|
1
1
|
"use strict";
|
|
2
2
|
|
|
3
|
+
var _interopRequireDefault = require("@babel/runtime/helpers/interopRequireDefault").default;
|
|
4
|
+
var _interopRequireWildcard = require("@babel/runtime/helpers/interopRequireWildcard").default;
|
|
3
5
|
Object.defineProperty(exports, "__esModule", {
|
|
4
6
|
value: true
|
|
5
7
|
});
|
|
6
8
|
exports.useStore = useStore;
|
|
9
|
+
var React = _interopRequireWildcard(require("react"));
|
|
10
|
+
var _shim = require("use-sync-external-store/shim");
|
|
7
11
|
var _withSelector = require("use-sync-external-store/shim/with-selector");
|
|
12
|
+
var _reactMajor = _interopRequireDefault(require("../reactMajor"));
|
|
8
13
|
/* We need to import the shim because React 17 does not support the `useSyncExternalStore` API.
|
|
9
14
|
* More info: https://github.com/mui/mui-x/issues/18303#issuecomment-2958392341 */
|
|
10
15
|
|
|
16
|
+
/* Some tests fail in R18 with the raw useSyncExternalStore. It may be possible to make it work
|
|
17
|
+
* but for now we only enable it for R19+. */
|
|
18
|
+
const canUseRawUseSyncExternalStore = _reactMajor.default >= 19;
|
|
19
|
+
const useStoreImplementation = canUseRawUseSyncExternalStore ? useStoreR19 : useStoreLegacy;
|
|
11
20
|
function useStore(store, selector, a1, a2, a3) {
|
|
12
|
-
|
|
13
|
-
|
|
21
|
+
return useStoreImplementation(store, selector, a1, a2, a3);
|
|
22
|
+
}
|
|
23
|
+
function useStoreR19(store, selector, a1, a2, a3) {
|
|
24
|
+
const getSelection = React.useCallback(() => selector(store.getSnapshot(), a1, a2, a3), [store, selector, a1, a2, a3]);
|
|
25
|
+
return (0, _shim.useSyncExternalStore)(store.subscribe, getSelection, getSelection);
|
|
26
|
+
}
|
|
27
|
+
function useStoreLegacy(store, selector, a1, a2, a3) {
|
|
28
|
+
return (0, _withSelector.useSyncExternalStoreWithSelector)(store.subscribe, store.getSnapshot, store.getSnapshot, state => selector(state, a1, a2, a3));
|
|
14
29
|
}
|
package/store/useStoreEffect.js
CHANGED
|
@@ -38,8 +38,11 @@ function initialize(params) {
|
|
|
38
38
|
subscribe: () => {
|
|
39
39
|
instance.dispose ?? (instance.dispose = store.subscribe(state => {
|
|
40
40
|
const nextState = selector(state);
|
|
41
|
-
|
|
42
|
-
|
|
41
|
+
if (!Object.is(previousState, nextState)) {
|
|
42
|
+
const prev = previousState;
|
|
43
|
+
previousState = nextState;
|
|
44
|
+
instance.effect(prev, nextState);
|
|
45
|
+
}
|
|
43
46
|
}));
|
|
44
47
|
},
|
|
45
48
|
onMount: () => {
|