react-gridix 0.2.2 → 0.2.3
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/README.md +93 -5
- package/dist/index.d.ts +14 -1
- package/dist/react-gridix.cjs +2 -2
- package/dist/react-gridix.js +745 -736
- package/package.json +1 -1
- package/README.html +0 -1742
package/README.md
CHANGED
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
# react-gridix
|
|
1
|
+
# react-gridix Documentation
|
|
2
2
|
|
|
3
3
|
A React `DataGrid` with row selection, server-side mode, typed per-column filters, date columns, in-cell editing, resizing and pinning, virtualization, CSV export and 8 themes, plus the `Checkbox` it uses.
|
|
4
4
|
|
|
@@ -11,9 +11,8 @@ A React `DataGrid` with row selection, server-side mode, typed per-column filter
|
|
|
11
11
|
5. [Checkbox](#5-checkbox)
|
|
12
12
|
6. [DataGrid](#6-datagrid)
|
|
13
13
|
7. [Demos](#7-demos)
|
|
14
|
-
8. [
|
|
15
|
-
9. [
|
|
16
|
-
10. [Migrating from the earlier version](#10-migrating-from-the-earlier-version)
|
|
14
|
+
8. [Troubleshooting](#9-troubleshooting)
|
|
15
|
+
9. [Migrating from the earlier version](#10-migrating-from-the-earlier-version)
|
|
17
16
|
|
|
18
17
|
---
|
|
19
18
|
|
|
@@ -398,6 +397,7 @@ The grid is generic: `DataGrid<T>` infers `T` from `rows`, and `ColumnDef<T>` ch
|
|
|
398
397
|
| `filters` / `onFiltersChange` | `Record<string, FilterValue>` / `(f) => void` | | Controlled column filters |
|
|
399
398
|
| `pagination` | `boolean` | `false` | Split rows into pages and show the bar with the row count and page controls |
|
|
400
399
|
| `paginationPosition` | `"bottom" \| "top" \| "both"` | `"bottom"` | Where the bar goes |
|
|
400
|
+
| `showFooter` | `boolean` | `true` | Set `false` to remove the footer completely (both bars), even with `pagination` on. Rows are still paged, so control the page with `page` / `onPageChange`. See [removing the toolbar and footer](#removing-the-toolbar-and-footer) |
|
|
401
401
|
| `pageSize` | `number` | `10` | Rows per page (initial value) |
|
|
402
402
|
| `pageSizeOptions` | `number[]` | `[5, 10, 25, 50]` | Choices in the page size menu. The current size is added if missing |
|
|
403
403
|
| `page` / `onPageChange` | `number` / `(page) => void` | | Controlled page (zero-based) |
|
|
@@ -436,6 +436,7 @@ The grid is generic: `DataGrid<T>` infers `T` from `rows`, and `ColumnDef<T>` ch
|
|
|
436
436
|
| --- | --- | --- | --- |
|
|
437
437
|
| `theme` | `GridTheme \| string` | | Applies a theme. Nothing changes without it. See [Theming](#4-theming) |
|
|
438
438
|
| `toolbar` | `ReactNode` | | Extra content on the right of the toolbar |
|
|
439
|
+
| `showToolbar` | `boolean` | `true` | Set `false` to remove the toolbar row completely (search box, Columns, Export, selected count and your `toolbar`), even when those features are on |
|
|
439
440
|
| `emptyMessage` | `ReactNode` | `"No rows to show"` | Shown when no rows match |
|
|
440
441
|
| `striped` | `boolean` | `false` | Alternate row shading |
|
|
441
442
|
| `stripeColors` | `[string, string]` | | Two colours for the alternating rows. Implies `striped`. See [striped rows](#striped-rows) |
|
|
@@ -789,6 +790,7 @@ const columns: ColumnDef<Task>[] = [
|
|
|
789
790
|
|
|
790
791
|
- Click a day to save it at once. **Today** picks today and **Clear** saves an empty date (`null`).
|
|
791
792
|
- Or type the date as `YYYY-MM-DD`. The calendar follows what you type, and Enter (or a click elsewhere) saves it. Tab saves and moves on, Escape cancels.
|
|
793
|
+
- **Keys while the text box has focus:** Up / Down move the date a week, Ctrl (or Alt) + Left / Right move it a day, Page Up / Page Down move it a month. The text box and the calendar update together, and Enter saves. Plain Left / Right still move the text cursor. (Arrow-key movement *between cells* is a separate opt-in: `keyboardNavigation`.)
|
|
792
794
|
- The arrows change month (`‹ ›`) and year (`« »`). Days before `dateMin` or after `dateMax` are dimmed and cannot be picked.
|
|
793
795
|
- Text that is not a real date (such as `2026-02-31`) marks the editor invalid and is not saved. Clicking away from it throws it away.
|
|
794
796
|
- Typing letters does not start an editor on a date cell: use double-click, Enter or F2.
|
|
@@ -879,6 +881,41 @@ The toolbar row is drawn when at least one of `searchable`, `columnMenu`, `expor
|
|
|
879
881
|
toolbar={<button className="rg-grid__tool-btn" onClick={refetch}>Reload</button>}
|
|
880
882
|
```
|
|
881
883
|
|
|
884
|
+
#### Removing the toolbar and footer
|
|
885
|
+
|
|
886
|
+
Both bars are drawn automatically: the **toolbar** when `searchable`, `columnMenu`, `exportable` or `toolbar` is used, and the **footer** when `pagination` is on. To remove one completely, even though its feature is on, switch it off:
|
|
887
|
+
|
|
888
|
+
```tsx
|
|
889
|
+
<DataGrid showToolbar={false} showFooter={false} ... />
|
|
890
|
+
```
|
|
891
|
+
|
|
892
|
+
The features keep working, so you can drive them yourself:
|
|
893
|
+
|
|
894
|
+
```tsx
|
|
895
|
+
const api = useRef<DataGridApi<Person> | null>(null);
|
|
896
|
+
const [search, setSearch] = useState("");
|
|
897
|
+
const [page, setPage] = useState(0);
|
|
898
|
+
|
|
899
|
+
// your own search box and pager, with the grid's bars removed
|
|
900
|
+
<input value={search} onChange={(e) => setSearch(e.target.value)} placeholder="Search…" />
|
|
901
|
+
<button onClick={() => api.current?.exportCsv({ filename: "people" })}>Export</button>
|
|
902
|
+
<button disabled={page === 0} onClick={() => setPage(page - 1)}>Previous</button>
|
|
903
|
+
<button onClick={() => setPage(page + 1)}>Next</button>
|
|
904
|
+
|
|
905
|
+
<DataGrid
|
|
906
|
+
apiRef={api}
|
|
907
|
+
searchable showToolbar={false} // the search still filters, from `search`
|
|
908
|
+
pagination pageSize={10} showFooter={false} // still 10 rows per page, from `page`
|
|
909
|
+
search={search} onSearchChange={setSearch}
|
|
910
|
+
page={page} onPageChange={setPage}
|
|
911
|
+
exportable showToolbar={false}
|
|
912
|
+
columns={columns}
|
|
913
|
+
rows={rows}
|
|
914
|
+
/>
|
|
915
|
+
```
|
|
916
|
+
|
|
917
|
+
Remember the "N selected" count lives in the toolbar and the footer, so read the selection from `onSelectionChange` instead when both are removed. Each bar can be removed on its own: `showToolbar={false}` leaves the footer, `showFooter={false}` leaves the toolbar.
|
|
918
|
+
|
|
882
919
|
### 6.9 Editing
|
|
883
920
|
|
|
884
921
|
Turn editing on with `editable` on the grid, then lock or unlock columns:
|
|
@@ -1300,6 +1337,37 @@ With Tailwind, define the keyframes in your config and use the utility, for exam
|
|
|
1300
1337
|
- `animateRows={false}` turns every row animation off, custom or not. It is also skipped while `virtualize` is on.
|
|
1301
1338
|
- Reduced motion: the built-in animation stops for people who ask for it. Your own class is yours to handle: wrap it in `@media (prefers-reduced-motion: no-preference) { ... }`.
|
|
1302
1339
|
|
|
1340
|
+
#### What does `classNames={{ cell: "border border-teal-400 py-2" }}` do?
|
|
1341
|
+
|
|
1342
|
+
`classNames` adds your own CSS classes to named parts of the grid. The key is the part (a **slot**), and the value is the class string. `cell` is the slot for **every body cell** (`<td>`) in every column. So this:
|
|
1343
|
+
|
|
1344
|
+
```tsx
|
|
1345
|
+
<DataGrid classNames={{ cell: "border border-teal-400 py-2" }} ... />
|
|
1346
|
+
```
|
|
1347
|
+
|
|
1348
|
+
adds those three Tailwind classes to each body cell:
|
|
1349
|
+
|
|
1350
|
+
| Class | Effect |
|
|
1351
|
+
| --- | --- |
|
|
1352
|
+
| `border` | A 1px border on all four sides of every cell, drawn on top of the grid's normal line under each row (`border-collapse` merges neighbouring borders into a grid of lines) |
|
|
1353
|
+
| `border-teal-400` | Makes that border teal |
|
|
1354
|
+
| `py-2` | Vertical padding of 0.5rem (8px) top and bottom, replacing the default 9px. The horizontal padding (12px) is unchanged |
|
|
1355
|
+
|
|
1356
|
+
It works with no `!important` because the library's own CSS has zero specificity, so any class you add wins. The header cells are not affected (use `classNames.headerCell`), and neither is a single column (use that column's `cellClassName`, see below). The inline-style twin is `styles`: `styles={{ cell: { border: "1px solid #2dd4bf", paddingBlock: 8 } }}`.
|
|
1357
|
+
|
|
1358
|
+
Other slots work the same way: `root`, `toolbar`, `search`, `table`, `thead`, `headerRow`, `headerCell`, `tbody`, `row`, `cell`, `editor`, `empty`, `footer`, and so on (the full list is in the slot table below).
|
|
1359
|
+
|
|
1360
|
+
**Where each kind of class goes**
|
|
1361
|
+
|
|
1362
|
+
| You want to style | Use |
|
|
1363
|
+
| --- | --- |
|
|
1364
|
+
| Every body cell | `classNames.cell` / `styles.cell` |
|
|
1365
|
+
| Every header cell | `classNames.headerCell` / `styles.headerCell` |
|
|
1366
|
+
| Whole rows, or some rows | grid `rowClassName` / `rowStyle` (a string or a function of the row) |
|
|
1367
|
+
| One column (header and cells) | column `className` / `style` |
|
|
1368
|
+
| One column's body cells | column `cellClassName` / `cellStyle` (a string or a function of the cell) |
|
|
1369
|
+
| One column's header | column `headerClassName` / `headerStyle` |
|
|
1370
|
+
|
|
1303
1371
|
#### Width
|
|
1304
1372
|
|
|
1305
1373
|
The grid is `width: 100%` of its container by default (it never overflows it: `max-width: 100%; min-width: 0`). To make it narrower, give it a width through `className` (`max-w-3xl`) or `style` (`{ maxWidth: 900 }`).
|
|
@@ -2121,7 +2189,6 @@ Open the URL it prints (usually `http://localhost:5173`). Link straight to a dem
|
|
|
2121
2189
|
The Styling demo loads Tailwind from its CDN, so it needs an internet connection. The rest works offline.
|
|
2122
2190
|
|
|
2123
2191
|
---
|
|
2124
|
-
|
|
2125
2192
|
## 8. Troubleshooting
|
|
2126
2193
|
|
|
2127
2194
|
| Problem | Cause and fix |
|
|
@@ -2165,6 +2232,27 @@ The Styling demo loads Tailwind from its CDN, so it needs an internet connection
|
|
|
2165
2232
|
|
|
2166
2233
|
---
|
|
2167
2234
|
|
|
2235
|
+
## 9. Migrating from the earlier version
|
|
2236
|
+
|
|
2237
|
+
### Renamed: react-gridix
|
|
2238
|
+
|
|
2239
|
+
The library is now **`react-gridix`**, and every CSS prefix changed from `rk` to `rg`.
|
|
2240
|
+
|
|
2241
|
+
| Before | Now |
|
|
2242
|
+
| --- | --- |
|
|
2243
|
+
| `npm install react-ui-kit` | `npm install react-gridix` |
|
|
2244
|
+
| `import ... from "react-ui-kit"` | `import ... from "react-gridix"` |
|
|
2245
|
+
| `import "react-ui-kit/style.css"` | `import "react-gridix/style.css"` |
|
|
2246
|
+
| CSS variables `--rk-header-bg`, `--rk-primary`, ... | `--rg-header-bg`, `--rg-primary`, ... |
|
|
2247
|
+
| Classes `.rk-grid__row`, `.rk-checkbox`, ... | `.rg-grid__row`, `.rg-checkbox`, ... |
|
|
2248
|
+
| Theme selector `[data-rk-theme="brand"]` | `[data-rg-theme="brand"]` |
|
|
2249
|
+
|
|
2250
|
+
Search your project's CSS for `rk-` and replace it with `rg-`. A one-line fix in a Unix shell: `sed -i 's/\brk-/rg-/g' src/**/*.css`.
|
|
2251
|
+
|
|
2252
|
+
### Other changes
|
|
2253
|
+
|
|
2254
|
+
Also new in this release: `filterDebounce`, a smaller default checkbox (17px instead of 20px, with a tighter gap and a narrower selection column), a calendar for date cells and date filters, the `sequence` column type, `rowAnimationClassName`, and re-tuned theme colours (stronger header contrast, clearer inputs in the dark themes).
|
|
2255
|
+
|
|
2168
2256
|
### Changed defaults
|
|
2169
2257
|
|
|
2170
2258
|
Three defaults changed so that every feature is opt-in.
|
package/dist/index.d.ts
CHANGED
|
@@ -229,7 +229,7 @@ export declare interface ColumnDef<T = Record<string, any>> {
|
|
|
229
229
|
headerCheckbox?: boolean;
|
|
230
230
|
}
|
|
231
231
|
|
|
232
|
-
export declare function DataGrid<T extends AnyRow = AnyRow>({ columns, rows, getRowId, editable, enterMovesDown, onCellEdit, onRowsChange, rowSelection, selectedRowIds, defaultSelectedRowIds, onSelectionChange, isRowSelectable, sort: sortProp, defaultSort, onSortChange, multiSort, searchable, searchPlaceholder, search: searchProp, onSearchChange, filters: filtersProp, onFiltersChange, pagination, paginationPosition, pageSize: initialPageSize, pageSizeOptions, page: pageProp, onPageChange, onPageSizeChange, serverSide, rowCount, onQueryChange, queryDebounce, filterDebounce, loading: loadingProp, loadingRows, skeletonRow, errorMessage, columnMenu, onColumnVisibilityChange, keyboardNavigation, virtualize, rowHeight, overscan, exportable, apiRef, onRowClick, toolbar, emptyMessage, striped, stripeColors, checkboxVariant, animateRows, rowAnimationClassName, theme, maxHeight, className, style, classNames, styles, rowClassName, rowStyle, }: DataGridProps<T>): JSX_2.Element;
|
|
232
|
+
export declare function DataGrid<T extends AnyRow = AnyRow>({ columns, rows, getRowId, editable, enterMovesDown, onCellEdit, onRowsChange, rowSelection, selectedRowIds, defaultSelectedRowIds, onSelectionChange, isRowSelectable, sort: sortProp, defaultSort, onSortChange, multiSort, searchable, searchPlaceholder, search: searchProp, onSearchChange, filters: filtersProp, onFiltersChange, pagination, paginationPosition, showToolbar: allowToolbar, showFooter, pageSize: initialPageSize, pageSizeOptions, page: pageProp, onPageChange, onPageSizeChange, serverSide, rowCount, onQueryChange, queryDebounce, filterDebounce, loading: loadingProp, loadingRows, skeletonRow, errorMessage, columnMenu, onColumnVisibilityChange, keyboardNavigation, virtualize, rowHeight, overscan, exportable, apiRef, onRowClick, toolbar, emptyMessage, striped, stripeColors, checkboxVariant, animateRows, rowAnimationClassName, theme, maxHeight, className, style, classNames, styles, rowClassName, rowStyle, }: DataGridProps<T>): JSX_2.Element;
|
|
233
233
|
|
|
234
234
|
/** Methods you can call from outside by passing a ref as `apiRef`. */
|
|
235
235
|
export declare interface DataGridApi<T = Record<string, any>> {
|
|
@@ -295,6 +295,19 @@ export declare interface DataGridProps<T = Record<string, any>> {
|
|
|
295
295
|
/** Split rows into pages and show the row count and page controls. Default false. */
|
|
296
296
|
pagination?: boolean;
|
|
297
297
|
/** Where the row count and page controls go: "bottom" (default), "top" or "both". */
|
|
298
|
+
/**
|
|
299
|
+
* Set to `false` to remove the toolbar row completely (search box, Columns button, Export button,
|
|
300
|
+
* selected count and your `toolbar` content), even if those features are switched on. The features
|
|
301
|
+
* still work: drive them yourself with `search`, `apiRef.exportCsv()` and so on. Default `true`
|
|
302
|
+
* (the toolbar is drawn only when one of those features is used).
|
|
303
|
+
*/
|
|
304
|
+
showToolbar?: boolean;
|
|
305
|
+
/**
|
|
306
|
+
* Set to `false` to remove the footer completely (row count, page-size menu and page buttons), even
|
|
307
|
+
* when `pagination` is on. Rows are still split into pages, so control the page yourself with
|
|
308
|
+
* `page` / `onPageChange`. Default `true` (the footer is drawn when `pagination` is on).
|
|
309
|
+
*/
|
|
310
|
+
showFooter?: boolean;
|
|
298
311
|
paginationPosition?: PaginationPosition;
|
|
299
312
|
/** Initial rows per page. */
|
|
300
313
|
pageSize?: number;
|
package/dist/react-gridix.cjs
CHANGED
|
@@ -1,2 +1,2 @@
|
|
|
1
|
-
"use strict";Object.defineProperty(exports,Symbol.toStringTag,{value:"Module"});const i=require("react/jsx-runtime"),u=require("react"),Cn=require("react-dom"),Ie=(...r)=>r.filter(Boolean).join(" ");function Fn(){return i.jsx("svg",{viewBox:"0 0 16 16",width:"100%",height:"100%","aria-hidden":"true",focusable:"false",children:i.jsx("path",{d:"M3.5 8.5l3 3 6-7",fill:"none",stroke:"currentColor",strokeWidth:"2.2",strokeLinecap:"round",strokeLinejoin:"round"})})}function Tn(){return i.jsx("svg",{viewBox:"0 0 16 16",width:"100%",height:"100%","aria-hidden":"true",focusable:"false",children:i.jsx("path",{d:"M4 8h8",fill:"none",stroke:"currentColor",strokeWidth:"2.2",strokeLinecap:"round"})})}function xe({checked:r,onChange:n,indeterminate:d=!1,variant:c="native",disabled:h=!1,label:g,"aria-label":f,id:j,name:y,indicator:S,className:M,style:w,classNames:v={},styles:_={}}){const E=d?"indeterminate":r?"checked":"unchecked";return i.jsxs("label",{className:Ie("rg-checkbox",`rg-checkbox--${c}`,E==="checked"&&"rg-checkbox--checked",d&&"rg-checkbox--indeterminate",h&&"rg-checkbox--disabled",v.root,M),style:{..._.root,...w},"data-state":E,children:[c==="native"?i.jsx("input",{type:"checkbox",id:j,name:y,ref:I=>{I&&(I.indeterminate=d)},className:Ie("rg-checkbox__control",v.control),style:_.control,checked:r,disabled:h,"aria-label":f,"data-state":E,onChange:I=>n(I.target.checked)}):i.jsx("button",{type:"button",role:"checkbox",id:j,className:Ie("rg-checkbox__control",v.control),style:_.control,"aria-checked":d?"mixed":r,"aria-label":f,disabled:h,"data-state":E,onClick:()=>n(!r),children:i.jsx("span",{className:Ie("rg-checkbox__indicator",S!==void 0&&!d&&"rg-checkbox__indicator--custom",v.indicator),style:_.indicator,"data-state":E,"aria-hidden":"true",children:d?c==="tick"?i.jsx(Tn,{}):null:S!==void 0?S:c==="tick"?i.jsx(Fn,{}):null})}),g!=null&&g!==!1&&g!==""&&i.jsx("span",{className:Ie("rg-checkbox__label",v.label),style:_.label,children:g})]})}const Rn=/^(\d{4})-(\d{2})-(\d{2})$/,jr=r=>String(r).padStart(2,"0");function U(r){const n=Rn.exec(r);if(!n)return null;const[d,c,h]=[Number(n[1]),Number(n[2]),Number(n[3])],g=new Date(d,c-1,h);return g.getFullYear()===d&&g.getMonth()===c-1&&g.getDate()===h?g:null}function G(r){var n;if(r instanceof Date)return Number.isNaN(r.getTime())?null:`${r.getFullYear()}-${jr(r.getMonth()+1)}-${jr(r.getDate())}`;if(typeof r=="number")return Number.isFinite(r)?G(new Date(r)):null;if(typeof r=="string"){const d=r.trim();if(d==="")return null;const c=(n=/^\d{4}-\d{2}-\d{2}/.exec(d))==null?void 0:n[0];if(c)return U(c)?c:null;const h=Date.parse(d);return Number.isNaN(h)?null:G(new Date(h))}return null}function In(r,n,d){const c=G(r);return c?U(c).toLocaleDateString(n,d??{year:"numeric",month:"short",day:"numeric"}):r==null?"":String(r)}function Ln(r,n){var d;return r===""?null:n instanceof Date?U(r):typeof n=="number"?((d=U(r))==null?void 0:d.getTime())??null:r}const $=(...r)=>r.filter(Boolean).join(" "),ut=r=>r.headerName??(r.type==="boolean"?"":r.type==="sequence"?"#":r.field),be=r=>ut(r)||r.field,wr=r=>String(r).padStart(2,"0"),Pt=(r,n,d)=>`${r}-${wr(n+1)}-${wr(d)}`;function Dr(r,n,d,c){const h=[r,n==null?void 0:n.from,n==null?void 0:n.to].map(y=>y?U(y):null).find(Boolean);if(h)return new Date(h.getFullYear(),h.getMonth(),1);const g=new Date;let f=G(g);d&&f<d&&(f=d),c&&f>c&&(f=c);const j=U(f)??g;return new Date(j.getFullYear(),j.getMonth(),1)}function Fr({value:r,range:n,min:d,max:c,onPick:h,locale:g,weekStart:f=0,hideFooter:j,keepFocus:y,className:S}){var Ae;const[M,w]=u.useState(()=>Dr(r,n,d,c)),[v,_]=u.useState(null),E=u.useRef(null),I=u.useRef({value:r,from:n==null?void 0:n.from,to:n==null?void 0:n.to});u.useEffect(()=>{const x=I.current;I.current={value:r,from:n==null?void 0:n.from,to:n==null?void 0:n.to};const B=r!==x.value?r:(n==null?void 0:n.from)!==x.from?n==null?void 0:n.from:(n==null?void 0:n.to)!==x.to?n==null?void 0:n.to:void 0,T=B?U(B):null;T&&w(P=>P.getFullYear()===T.getFullYear()&&P.getMonth()===T.getMonth()?P:new Date(T.getFullYear(),T.getMonth(),1))},[r,n==null?void 0:n.from,n==null?void 0:n.to]);const C=G(new Date),D=M.getFullYear(),F=M.getMonth(),Z=u.useMemo(()=>{const x=new Intl.DateTimeFormat(g,{weekday:"short"});return Array.from({length:7},(B,T)=>x.format(new Date(2023,0,1+(T+f)%7)))},[g,f]),le=new Intl.DateTimeFormat(g,{month:"long",year:"numeric"}).format(M),z=u.useMemo(()=>{const x=(new Date(D,F,1).getDay()-f+7)%7;return Array.from({length:42},(B,T)=>{const P=new Date(D,F,1-x+T);return{iso:Pt(P.getFullYear(),P.getMonth(),P.getDate()),day:P.getDate(),outside:P.getMonth()!==F}})},[D,F,f]),W=x=>!!d&&x<d||!!c&&x>c,ie=x=>w(new Date(D,F+x,1)),Pe=x=>{const B=U(x);B&&((B.getFullYear()!==D||B.getMonth()!==F)&&w(new Date(B.getFullYear(),B.getMonth(),1)),_(x),requestAnimationFrame(()=>{var T,P;return(P=(T=E.current)==null?void 0:T.querySelector(`[data-iso="${x}"]`))==null?void 0:P.focus()}))},De=(x,B)=>{const T=U(B),P=ne=>{x.preventDefault(),Pe(Pt(T.getFullYear(),T.getMonth(),T.getDate()+ne))};switch(x.key){case"ArrowLeft":return P(-1);case"ArrowRight":return P(1);case"ArrowUp":return P(-7);case"ArrowDown":return P(7);case"Home":return P(-((T.getDay()-f+7)%7));case"End":return P(6-(T.getDay()-f+7)%7);case"PageUp":case"PageDown":{x.preventDefault();const ne=x.key==="PageUp"?-1:1,ae=new Date(T.getFullYear(),T.getMonth()+ne+1,0).getDate();Pe(Pt(T.getFullYear(),T.getMonth()+ne,Math.min(T.getDate(),ae)));return}}},ft=x=>!!x&&z.some(B=>B.iso===x&&!B.outside),gt=[v,r,C].find(x=>ft(x)&&!W(x))??((Ae=z.find(x=>!x.outside&&!W(x.iso)))==null?void 0:Ae.iso),ee=n==null?void 0:n.from,K=n==null?void 0:n.to;return i.jsxs("div",{className:$("rg-cal",S),onMouseDown:y?x=>x.preventDefault():void 0,role:"group","aria-label":`Calendar, ${le}`,children:[i.jsxs("div",{className:"rg-cal__head",children:[i.jsx("button",{type:"button",className:"rg-cal__nav","aria-label":"Previous year",onClick:()=>ie(-12),children:"«"}),i.jsx("button",{type:"button",className:"rg-cal__nav","aria-label":"Previous month",onClick:()=>ie(-1),children:"‹"}),i.jsx("span",{className:"rg-cal__title","aria-live":"polite",children:le}),i.jsx("button",{type:"button",className:"rg-cal__nav","aria-label":"Next month",onClick:()=>ie(1),children:"›"}),i.jsx("button",{type:"button",className:"rg-cal__nav","aria-label":"Next year",onClick:()=>ie(12),children:"»"})]}),i.jsxs("div",{className:"rg-cal__grid",ref:E,children:[Z.map(x=>i.jsx("span",{className:"rg-cal__dow","aria-hidden":"true",children:x.slice(0,2)},x)),z.map(({iso:x,day:B,outside:T})=>{const P=x===r,ne=x===ee,ae=x===K,ht=!!ee&&!!K&&x>ee&&x<K;return i.jsx("button",{type:"button","data-iso":x,tabIndex:x===gt?0:-1,disabled:W(x),"aria-pressed":P||ne||ae,"aria-label":new Intl.DateTimeFormat(g,{dateStyle:"full"}).format(U(x)),className:$("rg-cal__day",T&&"rg-cal__day--outside",x===C&&"rg-cal__day--today",(P||ne||ae)&&"rg-cal__day--selected",ht&&"rg-cal__day--in-range",ee&&K&&ne&&ee!==K&&"rg-cal__day--range-start",ee&&K&&ae&&ee!==K&&"rg-cal__day--range-end"),onClick:()=>h(x),onKeyDown:Oe=>De(Oe,x),onFocus:()=>_(x),children:B},x)})]}),!j&&i.jsxs("div",{className:"rg-cal__foot",children:[i.jsx("button",{type:"button",className:"rg-cal__link",disabled:W(C),onClick:()=>{w(Dr(C)),h(C)},children:"Today"}),i.jsx("button",{type:"button",className:"rg-cal__link",onClick:()=>h(""),children:"Clear"})]})]})}const Ot=typeof window<"u"?u.useLayoutEffect:u.useEffect;function Le(r,n,d){const[c,h]=u.useState(n),g=r!==void 0,f=g?r:c,j=u.useCallback(y=>{g||h(y),d==null||d(y)},[g,d]);return[f,j]}function Tr(r,n){const d=u.useRef(r);d.current=r;const c=u.useRef(void 0),h=u.useRef(null),g=u.useCallback(()=>{c.current!==void 0&&clearTimeout(c.current),c.current=void 0,h.current=null},[]),f=u.useCallback(()=>{c.current!==void 0&&clearTimeout(c.current),c.current=void 0;const y=h.current;h.current=null,y&&d.current(...y)},[]),j=u.useCallback((...y)=>{if(n<=0){g(),d.current(...y);return}h.current=y,c.current!==void 0&&clearTimeout(c.current),c.current=setTimeout(f,n)},[n,g,f]);return u.useEffect(()=>f,[f]),{call:j,flush:f,cancel:g}}function Yt({anchorRef:r,open:n,onClose:d,label:c,theme:h,className:g,style:f,keepFocus:j,children:y}){const S=u.useRef(null),[M,w]=u.useState({top:0,left:0}),v=u.useCallback(()=>{var D;const _=r.current;if(!_)return;const E=_.getBoundingClientRect(),I=((D=S.current)==null?void 0:D.offsetWidth)??260,C=Math.max(8,Math.min(E.left,window.innerWidth-I-8));w({top:E.bottom+6,left:C})},[r]);return Ot(()=>{n&&v()},[n,v]),u.useEffect(()=>{if(!n)return;const _=I=>{var D,F;const C=I.target;(D=S.current)!=null&&D.contains(C)||(F=r.current)!=null&&F.contains(C)||d()},E=I=>{var C;I.key==="Escape"&&(d(),(C=r.current)==null||C.focus())};return document.addEventListener("mousedown",_),document.addEventListener("keydown",E),window.addEventListener("resize",v),window.addEventListener("scroll",v,!0),()=>{document.removeEventListener("mousedown",_),document.removeEventListener("keydown",E),window.removeEventListener("resize",v),window.removeEventListener("scroll",v,!0)}},[n,d,v,r]),!n||typeof document>"u"?null:Cn.createPortal(i.jsx("div",{ref:S,role:"dialog",onMouseDown:j?_=>_.preventDefault():void 0,"aria-label":c,"data-rg-theme":h||void 0,className:$("rg-grid-popup",g),style:{position:"fixed",top:M.top,left:M.left,...f},children:y}),document.body)}function $n({value:r,onChange:n,onPick:d,onBlur:c,onKeyDown:h,min:g,max:f,locale:j,invalid:y,label:S,theme:M,className:w,style:v}){const _=u.useRef(null);return i.jsxs(i.Fragment,{children:[i.jsx("input",{ref:_,autoFocus:!0,type:"text",inputMode:"numeric",placeholder:"YYYY-MM-DD",autoComplete:"off",className:w,style:v,value:r,"aria-label":S,"aria-invalid":y||void 0,"aria-haspopup":"dialog","aria-expanded":!0,onChange:E=>n(E.target.value.trim()),onBlur:c,onKeyDown:h,onFocus:E=>E.currentTarget.setSelectionRange(E.currentTarget.value.length,E.currentTarget.value.length)}),i.jsx(Yt,{anchorRef:_,open:!0,onClose:()=>{},label:S,theme:M,className:"rg-date-popup",keepFocus:!0,children:i.jsx(Fr,{value:r,min:g,max:f,locale:j,onPick:d,keepFocus:!0})})]})}function Nr(r){return r.filterType?r.filterType:r.type==="number"?"number":r.type==="date"?"date":r.type==="boolean"?"select":"text"}const Pn=r=>typeof r=="object"&&r!==null&&!Array.isArray(r);function Rr(r){if(r==null)return!1;if(typeof r=="string")return r.trim()!=="";if(Array.isArray(r))return r.length>0;if(Pn(r)){const n=r;return typeof n.min=="number"||typeof n.max=="number"||!!n.from||!!n.to}return!1}function An(r,n,d,c){switch(r){case"text":return d.toLowerCase().includes(String(n).trim().toLowerCase());case"exact":return d.toLowerCase()===String(n).trim().toLowerCase();case"number":{const{min:h,max:g}=n,f=typeof c=="number"?c:c==null||c===""?NaN:Number(c);return Number.isNaN(f)?!1:(typeof h!="number"||f>=h)&&(typeof g!="number"||f<=g)}case"date":{const{from:h,to:g}=n,f=G(c);return f?(!h||f>=h)&&(!g||f<=g):!1}case"select":return n.includes(String(c??""))}}function On(r,n,d,c){if(r.filterOptions)return r.filterOptions.map(g=>typeof g=="string"?{value:g,label:g}:g);if(r.type==="boolean")return[{value:"true",label:"Yes"},{value:"false",label:"No"}];const h=new Map;for(const g of n){const f=d(g);if(f==null||f==="")continue;const j=String(f);h.has(j)||h.set(j,c(g))}return[...h].map(([g,f])=>({value:g,label:f})).sort((g,f)=>g.label.localeCompare(f.label,void 0,{numeric:!0}))}const Er=r=>{if(r.trim()==="")return;const n=Number(r);return Number.isFinite(n)?n:void 0},Ir=r=>typeof r=="object"&&r!==null&&!Array.isArray(r);function Kn({value:r,onChange:n,label:d,debounce:c,inputClassName:h,inputStyle:g}){const f=Ir(r)?r:{},[j,y]=u.useState(f.min===void 0?"":String(f.min)),[S,M]=u.useState(f.max===void 0?"":String(f.max)),w=u.useRef(f),v=Tr((_,E)=>{const I=Er(_),C=Er(E);w.current={min:I,max:C},n(I===void 0&&C===void 0?void 0:{min:I,max:C})},c);return u.useEffect(()=>{f.min===w.current.min&&f.max===w.current.max||(w.current=f,v.cancel(),y(f.min===void 0?"":String(f.min)),M(f.max===void 0?"":String(f.max)))},[f.min,f.max]),i.jsxs("div",{className:"rg-grid__filter-fields",children:[i.jsxs("label",{className:"rg-grid__filter-field",children:[i.jsx("span",{children:"Min"}),i.jsx("input",{autoFocus:!0,type:"number",className:$("rg-grid__filter-input",h),style:g,value:j,"aria-label":`Minimum ${d}`,onChange:_=>{y(_.target.value),v.call(_.target.value,S)},onKeyDown:_=>_.key==="Enter"&&v.flush()})]}),i.jsxs("label",{className:"rg-grid__filter-field",children:[i.jsx("span",{children:"Max"}),i.jsx("input",{type:"number",className:$("rg-grid__filter-input",h),style:g,value:S,"aria-label":`Maximum ${d}`,onChange:_=>{M(_.target.value),v.call(j,_.target.value)},onKeyDown:_=>_.key==="Enter"&&v.flush()})]})]})}function Bn({value:r,onChange:n,onEnter:d,label:c,kind:h,placeholder:g,debounce:f,inputClassName:j,inputStyle:y}){const[S,M]=u.useState(r),w=u.useRef(r),v=Tr(_=>{w.current=_,n(_||void 0)},f);return u.useEffect(()=>{r!==w.current&&(w.current=r,v.cancel(),M(r))},[r]),i.jsx("input",{autoFocus:!0,type:"text",className:$("rg-grid__filter-input",j),style:y,value:S,placeholder:g??(h==="exact"?"Exactly…":`Filter ${c}…`),"aria-label":`Filter text for ${c}`,onChange:_=>{M(_.target.value),v.call(_.target.value)},onKeyDown:_=>{_.key==="Enter"&&(_.preventDefault(),v.flush(),d())}})}function Yn({value:r,onChange:n,label:d,inputClassName:c,inputStyle:h,min:g,max:f,locale:j}){const y=Ir(r)?r:{},S=(D,F)=>n(!D&&!F?void 0:{from:D||void 0,to:F||void 0}),[M,w]=u.useState(y.from??""),[v,_]=u.useState(y.to??"");u.useEffect(()=>{(U(M)?M:"")!==(y.from??"")&&w(y.from??""),(U(v)?v:"")!==(y.to??"")&&_(y.to??"")},[y.from,y.to]);const E=(D,F)=>{if((D==="from"?w:_)(F),F!==""&&!U(F))return;const Z=F||void 0;D==="from"?S(Z,y.to):S(y.from,Z)},I=D=>{D&&(!y.from||y.to?S(D,void 0):D<y.from?S(D,y.from):S(y.from,D))},C=(D,F,Z)=>i.jsxs("label",{className:"rg-grid__filter-field",children:[i.jsx("span",{children:D==="from"?"From":"To"}),i.jsx("input",{autoFocus:Z,type:"text",inputMode:"numeric",placeholder:"YYYY-MM-DD",className:$("rg-grid__filter-input",F!==""&&!U(F)&&"rg-grid__filter-input--invalid",c),style:h,value:F,"aria-label":`${d} ${D}`,"aria-invalid":F!==""&&!U(F)||void 0,onChange:le=>E(D,le.target.value.trim())})]});return i.jsxs("div",{className:"rg-grid__filter-fields rg-grid__filter-fields--stack",children:[i.jsxs("div",{className:"rg-grid__filter-date-row",children:[C("from",M,!0),C("to",v,!1)]}),i.jsx(Fr,{range:y,min:g,max:f,locale:j,onPick:I,hideFooter:!0})]})}function Wn({value:r,onChange:n,options:d}){const c=Array.isArray(r)?r:[],h=(g,f)=>{const j=f?[...c,g]:c.filter(y=>y!==g);n(j.length?j:void 0)};return i.jsxs("div",{className:"rg-grid__filter-fields rg-grid__filter-options",role:"group",children:[d.length===0&&i.jsx("span",{className:"rg-grid__filter-empty",children:"No values"}),d.map(g=>i.jsx(xe,{checked:c.includes(g.value),onChange:f=>h(g.value,f),label:g.label??g.value},g.value))]})}function qn({column:r,label:n,kind:d,value:c,onChange:h,options:g,debounce:f=300,theme:j,indicatorClassName:y,indicatorStyle:S,popupClassName:M,popupStyle:w,inputClassName:v,inputStyle:_}){const[E,I]=u.useState(!1),C=u.useRef(null),D=Rr(c),F=u.useCallback(()=>I(!1),[]),Z=typeof c=="string"?c:"",le=()=>{if(r.filterRenderer)return u.createElement(r.filterRenderer,{column:r,value:Z,onChange:z=>h(z||void 0)});switch(d){case"number":return i.jsx(Kn,{value:c,onChange:h,label:n,debounce:f,inputClassName:v,inputStyle:_});case"date":return i.jsx(Yn,{value:c,onChange:h,label:n,min:r.dateMin,max:r.dateMax,locale:r.dateLocale,inputClassName:v,inputStyle:_});case"select":return i.jsx(Wn,{value:c,onChange:h,options:g});default:return i.jsx(Bn,{value:Z,onChange:h,onEnter:()=>{var z;I(!1),(z=C.current)==null||z.focus()},label:n,kind:d,placeholder:r.filterPlaceholder,debounce:f,inputClassName:v,inputStyle:_})}};return i.jsxs(i.Fragment,{children:[i.jsx("button",{ref:C,type:"button",className:$("rg-grid__filter-btn",D&&"rg-grid__filter-btn--active",E&&"rg-grid__filter-btn--open",y),style:S,"aria-label":`Filter ${n}`,"aria-haspopup":"dialog","aria-expanded":E,"data-active":D||void 0,onClick:z=>{z.stopPropagation(),I(W=>!W)},onKeyDown:z=>z.stopPropagation(),children:r.filterIndicator?u.createElement(r.filterIndicator,{column:r,active:D,open:E}):i.jsx("span",{className:"rg-grid__filter-dot","aria-hidden":"true"})}),i.jsxs(Yt,{anchorRef:C,open:E,onClose:F,label:`Filter ${n}`,theme:j,className:M,style:w,children:[le(),D&&i.jsx("button",{type:"button",className:"rg-grid__filter-clear",onClick:()=>h(void 0),children:"Clear"})]})]})}function Vn({columns:r,hidden:n,onToggle:d,theme:c,className:h,style:g}){const[f,j]=u.useState(!1),y=u.useRef(null),S=u.useCallback(()=>j(!1),[]),M=r.filter(w=>!n.has(w.field)).length;return i.jsxs(i.Fragment,{children:[i.jsx("button",{ref:y,type:"button",className:$("rg-grid__tool-btn",h),style:g,"aria-haspopup":"dialog","aria-expanded":f,onClick:()=>j(w=>!w),children:"Columns"}),i.jsx(Yt,{anchorRef:y,open:f,onClose:S,label:"Show or hide columns",theme:c,children:i.jsx("div",{className:"rg-grid__filter-fields rg-grid__filter-options",role:"group","aria-label":"Columns",children:r.filter(w=>w.hideable!==!1).map(w=>{const v=!n.has(w.field);return i.jsx(xe,{checked:v,disabled:v&&M<=1,onChange:_=>d(w.field,!_),label:be(w)},w.field)})})})]})}const Un=/^[=+\-@\t\r]/;function zn(r,n,d){if(r==null)return"";let c=String(r);return d&&typeof r=="string"&&Un.test(c)&&!Number.isFinite(Number(c))&&(c=`'${c}`),c.includes(n)||/["\r\n]/.test(c)?`"${c.replace(/"/g,'""')}"`:c}function Hn(r,n,d={}){const{delimiter:c=",",sanitize:h=!0}=d,g=f=>f.map(j=>zn(j,c,h)).join(c);return[g(r),...n.map(g)].join(`\r
|
|
2
|
-
`)}function Jn(r,n){if(typeof document>"u")return;const d=new Blob(["\uFEFF",r],{type:"text/csv;charset=utf-8"}),c=URL.createObjectURL(d),h=document.createElement("a");h.href=c,h.download=n,h.style.display="none",document.body.appendChild(h),h.click(),h.remove(),setTimeout(()=>URL.revokeObjectURL(c),1e3)}const Kt=new Set(["__proto__","prototype","constructor"]),Lr=(r,n)=>Object.prototype.hasOwnProperty.call(r,n);function Q(r,n){if(r===null||typeof r!="object")return;if(Lr(r,n))return r[n];let d=r;for(const c of n.split(".")){if(d==null||typeof d!="object"||Kt.has(c))return;d=d[c]}return d}function Sr(r,n,d){if(Array.isArray(r)){const c=[...r];return c[n]=d,c}return{...r,[n]:d}}function Bt(r,n,d){const c=r??{};if(Lr(c,n)||!n.includes("."))return Kt.has(n)?r:Sr(c,n,d);const[h,...g]=n.split(".");if(Kt.has(h))return r;const f=c[h];return Sr(c,h,Bt(f!==null&&typeof f=="object"?f:{},g.join("."),d))}const ge=38,Gn=150,Mr=10,At=(r,n)=>`${typeof r}:${r}\0${n}`;function $e(r,n){const d=Q(n,r.field);return r.valueFormatter?r.valueFormatter(d,n):r.type==="boolean"&&typeof d=="boolean"?d?"Yes":"No":r.type==="date"?In(d,r.dateLocale,r.dateFormat):d==null?"":d instanceof Date?d.toLocaleDateString():String(d)}function Xn(r,n,d){if(d.type==="date"){const c=G(r)??"",h=G(n)??"";return c<h?-1:c>h?1:0}return typeof r=="number"&&typeof n=="number"?r-n:r instanceof Date&&n instanceof Date?r.getTime()-n.getTime():typeof r=="boolean"&&typeof n=="boolean"?Number(r)-Number(n):String(r).localeCompare(String(n),void 0,{numeric:!0,sensitivity:"base"})}const Qn=r=>r?Array.isArray(r)?r:[r]:[],Cr=r=>r.type==="date"&&r.validity.badInput;function Zn({columns:r,rows:n,getRowId:d,editable:c=!1,enterMovesDown:h=!0,onCellEdit:g,onRowsChange:f,rowSelection:j=!1,selectedRowIds:y,defaultSelectedRowIds:S,onSelectionChange:M,isRowSelectable:w,sort:v,defaultSort:_=null,onSortChange:E,multiSort:I=!1,searchable:C=!1,searchPlaceholder:D="Search…",search:F,onSearchChange:Z,filters:le,onFiltersChange:z,pagination:W=!1,paginationPosition:ie="bottom",pageSize:Pe=10,pageSizeOptions:De=[5,10,25,50],page:ft,onPageChange:gt,onPageSizeChange:ee,serverSide:K=!1,rowCount:Ae,onQueryChange:x,queryDebounce:B=250,filterDebounce:T=300,loading:P,loadingRows:ne,skeletonRow:ae,errorMessage:ht="Could not load the data.",columnMenu:Oe=!1,onColumnVisibilityChange:pt,keyboardNavigation:mt=!1,virtualize:te=!1,rowHeight:se=40,overscan:Wt=6,exportable:Ke=!1,apiRef:Ne,onRowClick:bt,toolbar:qt,emptyMessage:$r="No rows to show",striped:Pr=!1,stripeColors:Be,checkboxVariant:xt="native",animateRows:Vt=!0,rowAnimationClassName:_t,theme:Ye,maxHeight:We,className:Ar,style:Or,classNames:A={},styles:R={},rowClassName:yt,rowStyle:vt}){const Y=(e,t)=>({className:$(t,A[e]),style:R[e]}),[qe,Ut]=u.useState(n),_e=u.useRef(n);u.useEffect(()=>{_e.current=n,Ut(n)},[n]);const zt=e=>{_e.current=e,Ut(e)},[Ee,Kr]=Le(F,"",Z),[ye,Br]=Le(le,{},z),[H,Yr]=Le(v,Qn(_),E),[kt,ve]=Le(ft,0,gt),[q,Wr]=u.useState(Pe),qr=e=>{Wr(e),ee==null||ee(e)},[Ve,Vr]=u.useState(()=>new Set(r.filter(e=>e.hidden).map(e=>e.field))),Ur=(e,t)=>{const o=new Set(Ve);t?o.add(e):o.delete(e),Vr(o),pt==null||pt([...o])},[jt,Ht]=u.useState({}),[Ue,zr]=u.useState({}),[eo,Hr]=u.useState(0),Se=u.useRef(new Map),[Me,he]=u.useState(null),ce=u.useRef(0),ze=u.useRef(null),He=u.useRef(new Map),[wt,Jt]=u.useState(null),Dt=u.useRef(null),Ce=u.useRef(null),[Nt,Gt]=u.useState({top:0,height:0}),N=u.useMemo(()=>{const e=r.filter(t=>!Ve.has(t.field)).map(t=>t.type==="sequence"?{...t,sortable:!1,filterable:!1,editable:!1,filterRenderer:void 0}:t);return[...e.filter(t=>t.pinned==="left"),...e.filter(t=>t.pinned!=="left"&&t.pinned!=="right"),...e.filter(t=>t.pinned==="right")]},[r,Ve]),Et=e=>e.sortable===!0,J=j==="single"?"single":j?"multiple":null,Fe=N.length+(J?1:0),ke=u.useMemo(()=>qe.map((e,t)=>({row:e,index:t,id:d?d(e,t):t})),[qe,d]),Xt=u.useRef(new Map);ke.forEach(e=>Xt.current.set(e.id,e.row));const Je=u.useMemo(()=>Object.entries(ye).filter(([e,t])=>{const o=N.find(a=>a.field===e);return!!o&&!!o.filterable&&Rr(t)}),[ye,N]),[Jr,Gr]=u.useState(Ee);u.useEffect(()=>{if(!K)return;const e=setTimeout(()=>Gr(Ee),B);return()=>clearTimeout(e)},[Ee,K,B]);const je=K?Jr:Ee,Qt=e=>e.filterRenderer?"text":Nr(e),de=u.useMemo(()=>{if(K)return ke;const e=je.trim().toLowerCase();let t=ke.filter(({row:a})=>e&&!N.some(s=>$e(s,a).toLowerCase().includes(e))?!1:Je.every(([s,l])=>{const b=N.find(m=>m.field===s);return An(Qt(b),l,$e(b,a),Q(a,s))}));const o=H.map(a=>({col:N.find(s=>s.field===a.field),dir:a.direction==="asc"?1:-1})).filter(a=>!!a.col);return o.length&&(t=[...t].sort((a,s)=>{for(const{col:l,dir:b}of o){const m=Q(a.row,l.field),k=Q(s.row,l.field),p=m==null||m==="",O=k==null||k==="";if(p||O){if(p!==O)return p?1:-1;continue}const X=l.comparator?l.comparator(m,k,a.row,s.row):Xn(m,k,l);if(X!==0)return X*b}return 0})),t},[ke,N,je,Je,H,K]),Ge=JSON.stringify([je,ye,H,q]),Zt=u.useRef(Ge);u.useEffect(()=>{Zt.current!==Ge&&(Zt.current=Ge,ve(0))},[Ge]);const we=K?Ae??ke.length:de.length,ue=W?Math.max(1,Math.ceil(we/q)):1,V=Math.min(kt,ue-1),L=W&&!K?de.slice(V*q,V*q+q):de,Xr=we===0?0:W?V*q+1:1,Qr=W?Math.min(we,(V+1)*q):we,St=u.useMemo(()=>({sort:H.filter(e=>{const t=r.find(o=>o.field===e.field);return!!t&&Et(t)}),filters:Object.fromEntries(Je),search:je.trim(),page:V,pageSize:q}),[H,r,Je,je,V,q]),Zr=JSON.stringify(St),Xe=u.useRef(St);Xe.current=St;const Qe=u.useRef(x);Qe.current=x;const[en,Ze]=u.useState(!1),[tn,Mt]=u.useState(!1),Ct=u.useRef(0),et=u.useCallback(e=>{var a;const t=++Ct.current,o=(a=Qe.current)==null?void 0:a.call(Qe,e);o&&typeof o.then=="function"?(Ze(!0),Mt(!1),o.then(()=>{t===Ct.current&&Ze(!1)},()=>{t===Ct.current&&(Ze(!1),Mt(!0))})):(Ze(!1),Mt(!1))},[]);u.useEffect(()=>{K&&et(Xe.current)},[K,Zr,et]),u.useEffect(()=>{K&&W&&kt>ue-1&&ve(ue-1)},[K,W,kt,ue]);const Ft=P??en,er=e=>e.map(t=>Xt.current.get(t)).filter(t=>t!==void 0),[oe,tt]=Le(y,S??[],e=>M==null?void 0:M({ids:e,rows:er(e)})),Tt=u.useMemo(()=>new Set(oe),[oe]),rt=e=>w?w(e):!0,nt=u.useRef(null),tr=u.useRef(!1),rn=(e,t)=>{if(!J||!rt(e.row))return;if(J==="single"){tt(t?[e.id]:[]),nt.current=e.id;return}const o=new Set(oe),a=tr.current&&nt.current!==null?L.findIndex(l=>l.id===nt.current):-1,s=L.findIndex(l=>l.id===e.id);if(a>=0&&s>=0)for(let l=Math.min(a,s);l<=Math.max(a,s);l++)rt(L[l].row)&&(t?o.add(L[l].id):o.delete(L[l].id));else t?o.add(e.id):o.delete(e.id);nt.current=e.id,tt([...o])},Te=u.useMemo(()=>de.filter(e=>rt(e.row)),[de,w]),rr=Te.filter(e=>Tt.has(e.id)).length,nr=Te.length>0&&rr===Te.length,or=e=>{const t=new Set(oe);Te.forEach(o=>e?t.add(o.id):t.delete(o.id)),tt([...t])},ot=(e,t,o)=>({value:Q(t,e.field),formattedValue:$e(e,t),row:t,rowIndex:o,field:e.field,column:e}),Rt=(e,t)=>{const o=e.editable??c;return typeof o=="function"?o(t):!!o},it=(e,t)=>Rt(e,t)&&!(e.type==="boolean"&&!e.cellEditor),nn=(e,t)=>{const o=ot(e,t.row,t.index),a=Rt(e,o);return{...o,editable:a,updateValue:s=>a&&sr(t,e,{value:s})}},ir=(e,t)=>{if(!Et(e))return;const o=H.find(l=>l.field===e.field),a=o?o.direction==="asc"?"desc":null:"asc";let s;t&&I?a?o?s=H.map(l=>l.field===e.field?{...l,direction:a}:l):s=[...H,{field:e.field,direction:a}]:s=H.filter(l=>l.field!==e.field):s=a?[{field:e.field,direction:a}]:[],Yr(s)},st=(e,t)=>{var o;return(o=He.current.get(At(e,t)))==null?void 0:o.focus()},fe=()=>{ce.current+=1,he(null)},on=e=>{for(const t of _e.current){const o=Q(t,e.field);if(o!=null&&o!=="")return o}},lt=(e,t,o={})=>{if(!it(t,ot(t,e.row,e.index)))return!1;const a=Q(e.row,t.field);let s;return t.cellEditor?s=a:t.type==="date"?s=G(a)??"":s=o.text??(a==null?"":String(a)),ze.current=s,ce.current+=1,he({id:e.id,field:t.field,draft:s,session:ce.current,select:o.select??"end",invalid:!1}),!0},sr=(e,t,o)=>{const a=_e.current[e.index]??e.row,s=Q(a,t.field);let l;if("value"in o)l=o.value;else if(t.valueParser)l=t.valueParser(o.text,a);else if(t.type==="date"){if(o.text!==""&&!U(o.text))return!1;l=Ln(o.text,s??on(t))}else if(t.type==="number")if(o.text.trim()==="")l=null;else{const k=Number(o.text);if(!Number.isFinite(k))return!1;l=k}else l=o.text;if(t.type==="date"){if(G(l)===G(s))return!0;const k=G(l);if(k&&(t.dateMin&&k<t.dateMin||t.dateMax&&k>t.dateMax))return!1}else if(Object.is(l,s))return!0;if(t.validate&&!t.validate(l,a))return!1;const b=Bt(a,t.field,l),m=_e.current.map((k,p)=>p===e.index?b:k);return zt(m),g==null||g({rowId:e.id,rowIndex:e.index,field:t.field,oldValue:s,newValue:l,row:b}),f==null||f(m),!0},lr=(e,t,o)=>{const a=L.findIndex(p=>p.id===e.id),s=N.findIndex(p=>p.field===t);if(a<0||s<0)return null;const l=(p,O)=>it(O,ot(O,p.row,p.index));if(o==="down"||o==="up"){const p=o==="down"?1:-1;for(let O=a+p;O>=0&&O<L.length;O+=p)if(l(L[O],N[s]))return{entry:L[O],col:N[s]};return null}const b=o==="right"?1:-1;let m=a,k=s+b;for(;m>=0&&m<L.length;){for(;k>=0&&k<N.length;){if(l(L[m],N[k]))return{entry:L[m],col:N[k]};k+=b}m+=b,k=b>0?0:N.length-1}return null},pe=(e,t,o,a={})=>{const{move:s="none",focus:l=!0}=a;if(!sr(e,t,o))return he(m=>m&&{...m,invalid:!0}),!1;const b=s==="none"?null:lr(e,t.field,s);return b?lt(b.entry,b.col,{select:"all"}):(fe(),l&&st(e.id,t.field)),!0},ar=(e,t,o)=>{if(e.nativeEvent.isComposing)return;const a=e.currentTarget.value,s=Cr(e.currentTarget);if(e.key==="Enter"){if(e.preventDefault(),s)return he(b=>b&&{...b,invalid:!0});const l=h?e.shiftKey?"up":"down":"none";pe(t,o,{text:a},{move:l})}else if(e.key==="Escape")e.preventDefault(),fe(),st(t.id,o.field);else if(e.key==="Tab"&&!s){const l=e.shiftKey?"left":"right";lr(t,o.field,l)&&(e.preventDefault(),pe(t,o,{text:a},{move:l}))}},sn=(e,t)=>{var l;const o=L[e],a=N[t];if(!o||!a)return;Jt({id:o.id,field:a.field}),Dt.current=At(o.id,a.field);const s=Ce.current;if(te&&s){const b=((l=s.querySelector("thead"))==null?void 0:l.clientHeight)??0,m=e*se;m<s.scrollTop?s.scrollTo({top:m,behavior:"auto"}):m+se>s.scrollTop+s.clientHeight-b&&s.scrollTo({top:m+se-s.clientHeight+b,behavior:"auto"})}};u.useEffect(()=>{const e=Dt.current;if(!e)return;const t=He.current.get(e);t&&(Dt.current=null,t.focus())});const ln=(e,t,o)=>{if(!mt)return!1;let a=L.findIndex(l=>l.id===t.id),s=N.findIndex(l=>l.field===o.field);if(a<0||s<0)return!1;switch(e.key){case"ArrowDown":a+=1;break;case"ArrowUp":a-=1;break;case"ArrowRight":s+=1;break;case"ArrowLeft":s-=1;break;case"PageDown":a+=Mr;break;case"PageUp":a-=Mr;break;case"Home":s=0,(e.ctrlKey||e.metaKey)&&(a=0);break;case"End":s=N.length-1,(e.ctrlKey||e.metaKey)&&(a=L.length-1);break;default:return!1}return e.preventDefault(),sn(Math.max(0,Math.min(L.length-1,a)),Math.max(0,Math.min(N.length-1,s))),!0},an=(e,t,o,a)=>{e.target===e.currentTarget&&(ln(e,t,o)||it(o,a)&&(e.key==="Enter"||e.key==="F2"?(e.preventDefault(),lt(t,o)):!o.cellEditor&&o.type!=="date"&&e.key.length===1&&!e.ctrlKey&&!e.metaKey&&!e.altKey&&(e.preventDefault(),lt(t,o,{text:e.key}))))};Ot(()=>{if(!te||!Ce.current)return;const e=Ce.current,t=()=>Gt(a=>a.height===e.clientHeight?a:{...a,height:e.clientHeight});if(t(),typeof ResizeObserver>"u")return;const o=new ResizeObserver(t);return o.observe(e),()=>o.disconnect()},[te]);const Re=te&&!Ft&&L.length>0,cn=Nt.height||(typeof We=="number"?We:400),at=Re?Math.max(0,Math.floor(Nt.top/se)-Wt):0,It=Re?Math.min(L.length,Math.ceil((Nt.top+cn)/se)+Wt):L.length,dn=Re?L.slice(at,It):L,cr=`${V}|${q}|${JSON.stringify(H)}|${je}|${JSON.stringify(ye)}`,dr=u.useRef(!0);u.useEffect(()=>{if(dr.current){dr.current=!1;return}const e=Ce.current;e&&typeof e.scrollTo=="function"&&e.scrollTop>0&&e.scrollTo({top:0,behavior:"smooth"})},[cr]);const Lt=Object.keys(jt).length>0,ct=e=>jt[e.field]??(typeof e.width=="number"?e.width:Gn),un=e=>Math.max(40,typeof e.minWidth=="number"?e.minWidth:60),fn=(e,t)=>{e.preventDefault(),e.stopPropagation();const o={...jt};Lt||N.forEach(p=>{var O;return o[p.field]=((O=Se.current.get(p.field))==null?void 0:O.offsetWidth)??ct(p)});const a=e.clientX,s=o[t.field]??ct(t),l=e.currentTarget;l.setPointerCapture(e.pointerId),Ht(o);const b=p=>Math.min(t.maxWidth??1/0,Math.max(un(t),Math.round(p))),m=p=>Ht(O=>({...O,[t.field]:b(s+p.clientX-a)})),k=()=>{l.removeEventListener("pointermove",m),l.removeEventListener("pointerup",k),l.removeEventListener("pointercancel",k)};l.addEventListener("pointermove",m),l.addEventListener("pointerup",k),l.addEventListener("pointercancel",k)};Ot(()=>{var s,l;const e={};let t=J&&N.some(b=>b.pinned==="left")?ge:0;for(const b of N)b.pinned==="left"&&(e[b.field]=t,t+=((s=Se.current.get(b.field))==null?void 0:s.offsetWidth)??0);let o=0;for(const b of[...N].reverse())b.pinned==="right"&&(e[b.field]=o,o+=((l=Se.current.get(b.field))==null?void 0:l.offsetWidth)??0);const a=Object.keys(e);(a.length!==Object.keys(Ue).length||a.some(b=>e[b]!==Ue[b]))&&zr(e)}),u.useEffect(()=>{const e=()=>Hr(t=>t+1);return window.addEventListener("resize",e),()=>window.removeEventListener("resize",e)},[]);const ur=N.map(e=>e.pinned).lastIndexOf("left"),gn=N.findIndex(e=>e.pinned==="right"),dt=ur>=0,fr=(e,t)=>({className:e.pinned?$("rg-grid__pinned",`rg-grid__pinned--${e.pinned}`,t===ur&&"rg-grid__pinned--edge",t===gn&&"rg-grid__pinned--edge"):void 0,style:e.pinned==="left"?{left:Ue[e.field]??0}:e.pinned==="right"?{right:Ue[e.field]??0}:void 0}),gr=typeof Ke=="object"?Ke:{},hr=(e={})=>{const t={...gr,...e},o=t.scope??"filtered",a=o==="page"?L:o==="selected"?ke.filter(m=>Tt.has(m.id)):de,s=t.includeHidden?r:N,l=s.map(m=>ut(m)||m.field),b=a.map(({row:m},k)=>s.map(p=>{if(p.type==="sequence")return _r(p,k,o==="page"&&W&&!p.sequenceRestartEachPage?V*q:0);const O=Q(m,p.field);return p.exportValue?p.exportValue(O,m):p.type==="date"?G(O)??"":$e(p,m)}));return Hn(l,b,{sanitize:t.sanitize})},pr=(e={})=>{const t={...gr,...e};Jn(hr(e),`${t.filename??"export"}.csv`)};u.useEffect(()=>{Ne&&(Ne.current={getCsv:hr,exportCsv:pr,getSelectedRows:()=>er(oe),getSelectedRowIds:()=>oe,selectAll:()=>or(!0),clearSelection:()=>tt([]),refresh:()=>{K&&et(Xe.current)}})}),u.useEffect(()=>()=>{Ne&&(Ne.current=null)},[Ne]);const mr=e=>{var o,a,s,l,b,m,k,p;const t=e.checkbox??{};return{variant:t.variant??xt,indicator:t.indicator,className:t.className,style:t.style,classNames:{root:$(A.checkbox,(o=t.classNames)==null?void 0:o.root),control:$(A.checkboxControl,(a=t.classNames)==null?void 0:a.control),indicator:$(A.checkboxIndicator,(s=t.classNames)==null?void 0:s.indicator),label:(l=t.classNames)==null?void 0:l.label},styles:{root:{...R.checkbox,...(b=t.styles)==null?void 0:b.root},control:{...R.checkboxControl,...(m=t.styles)==null?void 0:m.control},indicator:{...R.checkboxIndicator,...(k=t.styles)==null?void 0:k.indicator},label:(p=t.styles)==null?void 0:p.label}}},me=e=>e.stopPropagation(),hn=(e,t)=>i.jsx("span",{className:"rg-grid__checkbox-cell",onClick:me,onDoubleClick:me,children:i.jsx(xe,{...mr(e),checked:!!t.value,disabled:!t.editable,"aria-label":`Toggle ${be(e)}`,onChange:o=>t.updateValue(o)})}),br=e=>de.filter(t=>Rt(e,ot(e,t.row,t.index))),pn=(e,t)=>{const o=new Map(br(e).map(l=>[l.index,l])),a=[],s=_e.current.map((l,b)=>{const m=o.get(b);if(!m)return l;const k=Q(l,e.field);if(!!k===t||e.validate&&!e.validate(t,l))return l;const p=Bt(l,e.field,t);return a.push({rowId:m.id,rowIndex:b,field:e.field,oldValue:k,newValue:t,row:p}),p});a.length!==0&&(zt(s),a.forEach(l=>g==null?void 0:g(l)),f==null||f(s))},mn=e=>{const t=br(e),o=t.length>0?t:de,a=o.filter(l=>!!Q(l.row,e.field)).length,s=o.length>0&&a===o.length;return i.jsx("span",{className:"rg-grid__header-checkbox",onClick:me,onDoubleClick:me,children:i.jsx(xe,{...mr(e),checked:s,indeterminate:a>0&&!s,disabled:t.length===0,label:ut(e)||void 0,"aria-label":`Select all ${be(e)}`,onChange:l=>pn(e,l)})})},bn=(e,t,o)=>{if(t.cellEditor)return i.jsx("div",{className:"rg-grid__custom-editor",onBlur:s=>{s.currentTarget.contains(s.relatedTarget)||o.session===ce.current&&(pe(e,t,{value:ze.current},{focus:!1})||fe())},onKeyDown:s=>{s.key==="Escape"&&(s.preventDefault(),s.stopPropagation(),fe(),st(e.id,t.field))},children:u.createElement(t.cellEditor,{value:o.draft,row:e.row,rowIndex:e.index,field:t.field,column:t,onChange:s=>{ze.current=s,he(l=>l&&l.session===o.session?{...l,draft:s,invalid:!1}:l)},onCommit:(s,l="none")=>{o.session===ce.current&&pe(e,t,{value:s===void 0?ze.current:s},{move:l})},onCancel:()=>{fe(),st(e.id,t.field)}})});const a=t.type==="date";return a?i.jsx($n,{value:o.draft===null||o.draft===void 0?"":String(o.draft),label:`Edit ${be(t)}`,invalid:o.invalid,min:t.dateMin,max:t.dateMax,locale:t.dateLocale,theme:Ye,className:$("rg-grid__editor",o.invalid&&"rg-grid__editor--invalid",A.editor),style:{textAlign:t.align,...R.editor},onChange:s=>he(l=>l&&{...l,draft:s,invalid:!1}),onPick:s=>{o.session===ce.current&&pe(e,t,{text:s},{focus:!0})},onBlur:s=>{o.session===ce.current&&(pe(e,t,{text:s.currentTarget.value},{focus:!1})||fe())},onKeyDown:s=>ar(s,e,t)}):i.jsx("input",{autoFocus:!0,type:a?"date":"text",min:a?t.dateMin:void 0,max:a?t.dateMax:void 0,className:$("rg-grid__editor",o.invalid&&"rg-grid__editor--invalid",A.editor),style:{textAlign:t.align,...R.editor},value:o.draft===null||o.draft===void 0?"":String(o.draft),inputMode:t.type==="number"?"decimal":void 0,"aria-label":`Edit ${be(t)}`,"aria-invalid":o.invalid||void 0,onChange:s=>{const l=s.target.value;he(b=>b&&{...b,draft:l,invalid:!1})},onFocus:s=>{const l=s.currentTarget;a||(o.select==="all"?l.select():l.setSelectionRange(l.value.length,l.value.length))},onBlur:s=>{if(o.session===ce.current){if(Cr(s.currentTarget))return fe();pe(e,t,{text:s.currentTarget.value},{focus:!1})||fe()}},onKeyDown:s=>ar(s,e,t)})},xn=u.useMemo(()=>{const e=new Map;for(const t of N)t.filterable&&!t.filterRenderer&&Nr(t)==="select"&&e.set(t.field,On(t,qe,o=>Q(o,t.field),o=>$e(t,o)));return e},[N,qe]),_n=Pr||!!Be,yn=Be?{"--rg-stripe-a":Be[0],"--rg-stripe-b":Be[1]}:void 0,vn=W&&(ie==="top"||ie==="both"),kn=W&&(ie==="bottom"||ie==="both"),jn=C||!!qt||Oe||!!Ke,xr=e=>i.jsxs("div",{className:$("rg-grid__footer",e==="top"&&"rg-grid__footer--top",A.footer),style:R.footer,"data-position":e,children:[i.jsxs("span",{...Y("rowCount","rg-grid__count"),children:[we===0?"0 rows":`${Xr}–${Qr} of ${we}`,J&&oe.length>0?` · ${oe.length} selected`:""]}),i.jsxs("div",{...Y("pagination","rg-grid__pagination"),children:[i.jsxs("label",{className:"rg-grid__page-size-label",children:["Rows per page",i.jsx("select",{value:q,onChange:t=>qr(Number(t.target.value)),...Y("pageSize","rg-grid__page-size"),children:(De.includes(q)?De:[...De,q].sort((t,o)=>t-o)).map(t=>i.jsx("option",{value:t,children:t},t))})]}),i.jsx("button",{type:"button","aria-label":"First page",disabled:V===0,onClick:()=>ve(0),...Y("pageButton","rg-grid__page-btn"),children:"«"}),i.jsx("button",{type:"button","aria-label":"Previous page",disabled:V===0,onClick:()=>ve(V-1),...Y("pageButton","rg-grid__page-btn"),children:"‹"}),i.jsxs("span",{...Y("pageInfo","rg-grid__page-info"),children:["Page ",V+1," of ",ue]}),i.jsx("button",{type:"button","aria-label":"Next page",disabled:V>=ue-1,onClick:()=>ve(V+1),...Y("pageButton","rg-grid__page-btn"),children:"›"}),i.jsx("button",{type:"button","aria-label":"Last page",disabled:V>=ue-1,onClick:()=>ve(ue-1),...Y("pageButton","rg-grid__page-btn"),children:"»"})]})]}),wn=e=>i.jsx("tr",{className:"rg-grid__tr rg-grid__skeleton-row","aria-hidden":"true",style:te?{height:se}:void 0,children:ae?i.jsx("td",{colSpan:Fe,className:"rg-grid__td rg-grid__skeleton-cell",children:u.createElement(ae,{rowIndex:e,columns:N})}):i.jsxs(i.Fragment,{children:[J&&i.jsx("td",{className:"rg-grid__td",children:i.jsx("span",{...Y("skeleton","rg-grid__skeleton"),style:{...R.skeleton,width:18}})}),N.map((t,o)=>i.jsx("td",{className:"rg-grid__td",style:{textAlign:t.align},children:i.jsx("span",{...Y("skeleton","rg-grid__skeleton"),style:{...R.skeleton,width:`${55+(e*7+o*13)%35}%`}})},t.field))]})},`sk${e}`),_r=(e,t,o=W&&!e.sequenceRestartEachPage?V*q:0)=>(e.sequenceStart??1)+o+t,Dn=(e,t)=>{const{row:o,id:a,index:s}=e,l=typeof yt=="function"?yt(o,s):yt,b=typeof vt=="function"?vt(o,s):vt,m=Tt.has(a),k=typeof _t=="function"?_t(o,s):_t;return i.jsxs("tr",{onClick:bt?()=>bt(o,s):void 0,"aria-selected":J?m:void 0,className:$("rg-grid__tr","rg-grid__row",_n&&(t%2===0?"rg-grid__row--stripe-a":"rg-grid__row--stripe-b"),Vt&&!te&&(k||"rg-grid__row--enter"),m&&"rg-grid__row--selected",bt&&"rg-grid__row--clickable",A.row,l),style:{...Vt&&!te?{"--rg-i":Math.min(t,24)}:null,...te?{height:se}:null,...R.row,...b},children:[J&&i.jsx("td",{className:$("rg-grid__td rg-grid__select-cell",dt&&"rg-grid__pinned rg-grid__pinned--left"),style:{width:ge,minWidth:ge,maxWidth:ge,...dt?{left:0}:null},onClick:me,children:i.jsx("span",{className:"rg-grid__checkbox-cell",onClickCapture:p=>tr.current=p.shiftKey,children:i.jsx(xe,{variant:xt,checked:m,disabled:!rt(o),"aria-label":J==="single"?"Select row":`Select row ${s+1}`,onChange:p=>rn(e,p),classNames:{root:A.checkbox,control:A.checkboxControl,indicator:A.checkboxIndicator},styles:{root:R.checkbox,control:R.checkboxControl,indicator:R.checkboxIndicator}})})}),N.map((p,O)=>{let X=nn(p,e);if(p.type==="sequence"){const re=_r(p,t);X={...X,value:re,formattedValue:p.valueFormatter?p.valueFormatter(re,o):String(re),editable:!1}}const En=typeof p.cellClassName=="function"?p.cellClassName(X):p.cellClassName,Sn=typeof p.cellStyle=="function"?p.cellStyle(X):p.cellStyle,yr=Me!==null&&Me.id===a&&Me.field===p.field,$t=it(p,X),vr=fr(p,O),Mn=wt?wt.id===a&&wt.field===p.field:t===0&&O===0;return i.jsx("td",{ref:re=>{const kr=At(a,p.field);re?He.current.set(kr,re):He.current.delete(kr)},tabIndex:mt?Mn?0:-1:$t?0:void 0,onFocus:mt?re=>re.target===re.currentTarget&&Jt({id:a,field:p.field}):void 0,onDoubleClick:$t?()=>lt(e,p):void 0,onKeyDown:re=>an(re,e,p,X),className:$("rg-grid__td",$t&&"rg-grid__td--editable",yr&&"rg-grid__td--editing",vr.className,A.cell,p.className,En),style:{textAlign:p.align,...R.cell,...p.style,...Sn,...vr.style},children:yr&&Me?bn(e,p,Me):p.cellRenderer?u.createElement(p.cellRenderer,X):p.type==="boolean"&&!p.cellEditor?hn(p,X):X.formattedValue},p.field)})]},a)},Nn=ne??(W?Math.min(q,20):5);return i.jsxs("div",{className:$("rg-grid",te&&"rg-grid--virtual",A.root,Ar),style:{...yn,...R.root,...Or},"data-rg-theme":Ye||void 0,"aria-busy":Ft||void 0,children:[jn&&i.jsxs("div",{...Y("toolbar","rg-grid__toolbar"),children:[i.jsxs("div",{className:"rg-grid__toolbar-left",children:[C&&i.jsx("input",{type:"search",value:Ee,onChange:e=>Kr(e.target.value),placeholder:D,"aria-label":"Search all columns",...Y("search","rg-grid__search")}),J&&oe.length>0&&i.jsxs("span",{className:"rg-grid__selected-count",role:"status",children:[oe.length," selected"]})]}),i.jsxs("div",{className:"rg-grid__toolbar-actions",children:[qt,Oe&&i.jsx(Vn,{columns:r,hidden:Ve,onToggle:Ur,theme:Ye,className:A.toolButton,style:R.toolButton}),Ke&&i.jsx("button",{type:"button",onClick:()=>pr(),...Y("toolButton","rg-grid__tool-btn"),children:"Export CSV"})]})]}),vn&&xr("top"),i.jsx("div",{ref:Ce,...Y("scroll","rg-grid__scroll"),onScroll:te?e=>Gt({top:e.currentTarget.scrollTop,height:e.currentTarget.clientHeight}):void 0,style:{...R.scroll,...We!==void 0?{maxHeight:We}:te?{maxHeight:400}:null},children:i.jsxs("table",{...Y("table","rg-grid__table"),role:"grid",style:Lt?{...R.table,tableLayout:"fixed",width:N.reduce((e,t)=>e+ct(t),J?ge:0),minWidth:"100%"}:R.table,children:[i.jsx("thead",{...Y("thead","rg-grid__thead"),children:i.jsxs("tr",{...Y("headerRow","rg-grid__tr"),children:[J&&i.jsx("th",{scope:"col",className:$("rg-grid__th rg-grid__select-cell",dt&&"rg-grid__pinned rg-grid__pinned--left",A.headerCell),style:{width:ge,minWidth:ge,maxWidth:ge,...dt?{left:0}:null,...R.headerCell},children:J==="multiple"&&i.jsx("span",{className:"rg-grid__checkbox-cell",children:i.jsx(xe,{variant:xt,checked:nr,indeterminate:rr>0&&!nr,disabled:Te.length===0,"aria-label":"Select all rows",onChange:or,classNames:{root:A.checkbox,control:A.checkboxControl,indicator:A.checkboxIndicator},styles:{root:R.checkbox,control:R.checkboxControl,indicator:R.checkboxIndicator}})})}),N.map((e,t)=>{const o=H.findIndex(m=>m.field===e.field),a=o>=0?H[o].direction:null,s=Et(e),l=Qt(e),b=fr(e,t);return i.jsxs("th",{ref:m=>{m?Se.current.set(e.field,m):Se.current.delete(e.field)},scope:"col","aria-sort":a?a==="asc"?"ascending":"descending":s?"none":void 0,tabIndex:s?0:void 0,onClick:m=>ir(e,m.shiftKey),onKeyDown:m=>{s&&m.target===m.currentTarget&&(m.key==="Enter"||m.key===" ")&&(m.preventDefault(),ir(e,m.shiftKey))},className:$("rg-grid__th",s&&"rg-grid__th--sortable",b.className,A.headerCell,e.className,e.headerClassName),style:{width:Lt?ct(e):e.width,minWidth:e.minWidth,textAlign:e.align,...R.headerCell,...e.style,...e.headerStyle,...b.style},children:[i.jsxs("span",{className:"rg-grid__th-content",children:[e.headerRenderer?u.createElement(e.headerRenderer,{column:e,sortDirection:a}):e.headerCheckbox&&e.type==="boolean"?mn(e):ut(e),e.filterable&&i.jsx(qn,{column:e,label:be(e),kind:l,value:ye[e.field],onChange:m=>{const k={...ye};m===void 0?delete k[e.field]:k[e.field]=m,Br(k)},options:xn.get(e.field)??[],debounce:e.filterDebounce??T,theme:Ye,indicatorClassName:$(A.filterIndicator,e.filterIndicatorClassName),indicatorStyle:{...R.filterIndicator,...e.filterIndicatorStyle},popupClassName:$(A.filterPopup,e.filterPopupClassName),popupStyle:{...R.filterPopup,...e.filterPopupStyle},inputClassName:A.filterInput,inputStyle:R.filterInput}),s&&i.jsxs("span",{className:"rg-grid__sort","aria-hidden":"true",children:[a==="asc"?"▲":a==="desc"?"▼":"↕",a&&H.length>1&&i.jsx("sup",{className:"rg-grid__sort-order",children:o+1})]})]}),e.resizable&&i.jsx("span",{className:"rg-grid__resizer",role:"separator","aria-orientation":"vertical","aria-label":`Resize ${be(e)}`,onPointerDown:m=>fn(m,e),onClick:me,onDoubleClick:me})]},e.field)})]})}),i.jsx("tbody",{...Y("tbody","rg-grid__tbody"),children:Ft?Array.from({length:Nn},(e,t)=>wn(t)):tn?i.jsx("tr",{children:i.jsxs("td",{colSpan:Fe,...Y("empty","rg-grid__empty rg-grid__error"),role:"alert",children:[ht," ",i.jsx("button",{type:"button",className:"rg-grid__tool-btn",onClick:()=>et(Xe.current),children:"Retry"})]})}):L.length===0?i.jsx("tr",{children:i.jsx("td",{colSpan:Fe,...Y("empty","rg-grid__empty"),children:$r})}):i.jsxs(i.Fragment,{children:[Re&&at>0&&i.jsx("tr",{"aria-hidden":"true",className:"rg-grid__spacer",children:i.jsx("td",{colSpan:Fe,style:{height:at*se}})}),dn.map((e,t)=>Dn(e,at+t)),Re&&It<L.length&&i.jsx("tr",{"aria-hidden":"true",className:"rg-grid__spacer",children:i.jsx("td",{colSpan:Fe,style:{height:(L.length-It)*se}})})]})},cr)]})}),kn&&xr("bottom")]})}exports.Checkbox=xe;exports.DataGrid=Zn;
|
|
1
|
+
"use strict";Object.defineProperty(exports,Symbol.toStringTag,{value:"Module"});const i=require("react/jsx-runtime"),u=require("react"),Tn=require("react-dom"),Le=(...r)=>r.filter(Boolean).join(" ");function Rn(){return i.jsx("svg",{viewBox:"0 0 16 16",width:"100%",height:"100%","aria-hidden":"true",focusable:"false",children:i.jsx("path",{d:"M3.5 8.5l3 3 6-7",fill:"none",stroke:"currentColor",strokeWidth:"2.2",strokeLinecap:"round",strokeLinejoin:"round"})})}function In(){return i.jsx("svg",{viewBox:"0 0 16 16",width:"100%",height:"100%","aria-hidden":"true",focusable:"false",children:i.jsx("path",{d:"M4 8h8",fill:"none",stroke:"currentColor",strokeWidth:"2.2",strokeLinecap:"round"})})}function xe({checked:r,onChange:n,indeterminate:d=!1,variant:c="native",disabled:h=!1,label:g,"aria-label":f,id:j,name:y,indicator:C,className:F,style:D,classNames:k={},styles:_={}}){const R=d?"indeterminate":r?"checked":"unchecked";return i.jsxs("label",{className:Le("rg-checkbox",`rg-checkbox--${c}`,R==="checked"&&"rg-checkbox--checked",d&&"rg-checkbox--indeterminate",h&&"rg-checkbox--disabled",k.root,F),style:{..._.root,...D},"data-state":R,children:[c==="native"?i.jsx("input",{type:"checkbox",id:j,name:y,ref:v=>{v&&(v.indeterminate=d)},className:Le("rg-checkbox__control",k.control),style:_.control,checked:r,disabled:h,"aria-label":f,"data-state":R,onChange:v=>n(v.target.checked)}):i.jsx("button",{type:"button",role:"checkbox",id:j,className:Le("rg-checkbox__control",k.control),style:_.control,"aria-checked":d?"mixed":r,"aria-label":f,disabled:h,"data-state":R,onClick:()=>n(!r),children:i.jsx("span",{className:Le("rg-checkbox__indicator",C!==void 0&&!d&&"rg-checkbox__indicator--custom",k.indicator),style:_.indicator,"data-state":R,"aria-hidden":"true",children:d?c==="tick"?i.jsx(In,{}):null:C!==void 0?C:c==="tick"?i.jsx(Rn,{}):null})}),g!=null&&g!==!1&&g!==""&&i.jsx("span",{className:Le("rg-checkbox__label",k.label),style:_.label,children:g})]})}const Ln=/^(\d{4})-(\d{2})-(\d{2})$/,jr=r=>String(r).padStart(2,"0");function q(r){const n=Ln.exec(r);if(!n)return null;const[d,c,h]=[Number(n[1]),Number(n[2]),Number(n[3])],g=new Date(d,c-1,h);return g.getFullYear()===d&&g.getMonth()===c-1&&g.getDate()===h?g:null}function z(r){var n;if(r instanceof Date)return Number.isNaN(r.getTime())?null:`${r.getFullYear()}-${jr(r.getMonth()+1)}-${jr(r.getDate())}`;if(typeof r=="number")return Number.isFinite(r)?z(new Date(r)):null;if(typeof r=="string"){const d=r.trim();if(d==="")return null;const c=(n=/^\d{4}-\d{2}-\d{2}/.exec(d))==null?void 0:n[0];if(c)return q(c)?c:null;const h=Date.parse(d);return Number.isNaN(h)?null:z(new Date(h))}return null}function $n(r,n,d){const c=z(r);return c?q(c).toLocaleDateString(n,d??{year:"numeric",month:"short",day:"numeric"}):r==null?"":String(r)}function Pn(r,n){var d;return r===""?null:n instanceof Date?q(r):typeof n=="number"?((d=q(r))==null?void 0:d.getTime())??null:r}const P=(...r)=>r.filter(Boolean).join(" "),ft=r=>r.headerName??(r.type==="boolean"?"":r.type==="sequence"?"#":r.field),be=r=>ft(r)||r.field,Dr=r=>String(r).padStart(2,"0"),Pt=(r,n,d)=>`${r}-${Dr(n+1)}-${Dr(d)}`;function Nr(r,n,d,c){const h=[r,n==null?void 0:n.from,n==null?void 0:n.to].map(y=>y?q(y):null).find(Boolean);if(h)return new Date(h.getFullYear(),h.getMonth(),1);const g=new Date;let f=z(g);d&&f<d&&(f=d),c&&f>c&&(f=c);const j=q(f)??g;return new Date(j.getFullYear(),j.getMonth(),1)}function Tr({value:r,range:n,min:d,max:c,onPick:h,locale:g,weekStart:f=0,hideFooter:j,keepFocus:y,className:C}){var _e;const[F,D]=u.useState(()=>Nr(r,n,d,c)),[k,_]=u.useState(null),R=u.useRef(null),v=u.useRef({value:r,from:n==null?void 0:n.from,to:n==null?void 0:n.to});u.useEffect(()=>{const b=v.current;v.current={value:r,from:n==null?void 0:n.from,to:n==null?void 0:n.to};const Y=r!==b.value?r:(n==null?void 0:n.from)!==b.from?n==null?void 0:n.from:(n==null?void 0:n.to)!==b.to?n==null?void 0:n.to:void 0,T=Y?q(Y):null;T&&D(L=>L.getFullYear()===T.getFullYear()&&L.getMonth()===T.getMonth()?L:new Date(T.getFullYear(),T.getMonth(),1))},[r,n==null?void 0:n.from,n==null?void 0:n.to]);const S=z(new Date),N=F.getFullYear(),E=F.getMonth(),H=u.useMemo(()=>{const b=new Intl.DateTimeFormat(g,{weekday:"short"});return Array.from({length:7},(Y,T)=>b.format(new Date(2023,0,1+(T+f)%7)))},[g,f]),te=new Intl.DateTimeFormat(g,{month:"long",year:"numeric"}).format(F),O=u.useMemo(()=>{const b=(new Date(N,E,1).getDay()-f+7)%7;return Array.from({length:42},(Y,T)=>{const L=new Date(N,E,1-b+T);return{iso:Pt(L.getFullYear(),L.getMonth(),L.getDate()),day:L.getDate(),outside:L.getMonth()!==E}})},[N,E,f]),W=b=>!!d&&b<d||!!c&&b>c,oe=b=>D(new Date(N,E+b,1)),Ae=b=>{const Y=q(b);Y&&((Y.getFullYear()!==N||Y.getMonth()!==E)&&D(new Date(Y.getFullYear(),Y.getMonth(),1)),_(b),requestAnimationFrame(()=>{var T,L;return(L=(T=R.current)==null?void 0:T.querySelector(`[data-iso="${b}"]`))==null?void 0:L.focus()}))},Ke=(b,Y)=>{const T=q(Y),L=re=>{b.preventDefault(),Ae(Pt(T.getFullYear(),T.getMonth(),T.getDate()+re))};switch(b.key){case"ArrowLeft":return L(-1);case"ArrowRight":return L(1);case"ArrowUp":return L(-7);case"ArrowDown":return L(7);case"Home":return L(-((T.getDay()-f+7)%7));case"End":return L(6-(T.getDay()-f+7)%7);case"PageUp":case"PageDown":{b.preventDefault();const re=b.key==="PageUp"?-1:1,ge=new Date(T.getFullYear(),T.getMonth()+re+1,0).getDate();Ae(Pt(T.getFullYear(),T.getMonth()+re,Math.min(T.getDate(),ge)));return}}},gt=b=>!!b&&O.some(Y=>Y.iso===b&&!Y.outside),Ne=[k,r,S].find(b=>gt(b)&&!W(b))??((_e=O.find(b=>!b.outside&&!W(b.iso)))==null?void 0:_e.iso),ie=n==null?void 0:n.from,se=n==null?void 0:n.to;return i.jsxs("div",{className:P("rg-cal",C),onMouseDown:y?b=>b.preventDefault():void 0,role:"group","aria-label":`Calendar, ${te}`,children:[i.jsxs("div",{className:"rg-cal__head",children:[i.jsx("button",{type:"button",className:"rg-cal__nav","aria-label":"Previous year",onClick:()=>oe(-12),children:"«"}),i.jsx("button",{type:"button",className:"rg-cal__nav","aria-label":"Previous month",onClick:()=>oe(-1),children:"‹"}),i.jsx("span",{className:"rg-cal__title","aria-live":"polite",children:te}),i.jsx("button",{type:"button",className:"rg-cal__nav","aria-label":"Next month",onClick:()=>oe(1),children:"›"}),i.jsx("button",{type:"button",className:"rg-cal__nav","aria-label":"Next year",onClick:()=>oe(12),children:"»"})]}),i.jsxs("div",{className:"rg-cal__grid",ref:R,children:[H.map(b=>i.jsx("span",{className:"rg-cal__dow","aria-hidden":"true",children:b.slice(0,2)},b)),O.map(({iso:b,day:Y,outside:T})=>{const L=b===r,re=b===ie,ge=b===se,ht=!!ie&&!!se&&b>ie&&b<se;return i.jsx("button",{type:"button","data-iso":b,tabIndex:b===Ne?0:-1,disabled:W(b),"aria-pressed":L||re||ge,"aria-label":new Intl.DateTimeFormat(g,{dateStyle:"full"}).format(q(b)),className:P("rg-cal__day",T&&"rg-cal__day--outside",b===S&&"rg-cal__day--today",(L||re||ge)&&"rg-cal__day--selected",ht&&"rg-cal__day--in-range",ie&&se&&re&&ie!==se&&"rg-cal__day--range-start",ie&&se&&ge&&ie!==se&&"rg-cal__day--range-end"),onClick:()=>h(b),onKeyDown:Oe=>Ke(Oe,b),onFocus:()=>_(b),children:Y},b)})]}),!j&&i.jsxs("div",{className:"rg-cal__foot",children:[i.jsx("button",{type:"button",className:"rg-cal__link",disabled:W(S),onClick:()=>{D(Nr(S)),h(S)},children:"Today"}),i.jsx("button",{type:"button",className:"rg-cal__link",onClick:()=>h(""),children:"Clear"})]})]})}const Kt=typeof window<"u"?u.useLayoutEffect:u.useEffect;function $e(r,n,d){const[c,h]=u.useState(n),g=r!==void 0,f=g?r:c,j=u.useCallback(y=>{g||h(y),d==null||d(y)},[g,d]);return[f,j]}function Rr(r,n){const d=u.useRef(r);d.current=r;const c=u.useRef(void 0),h=u.useRef(null),g=u.useCallback(()=>{c.current!==void 0&&clearTimeout(c.current),c.current=void 0,h.current=null},[]),f=u.useCallback(()=>{c.current!==void 0&&clearTimeout(c.current),c.current=void 0;const y=h.current;h.current=null,y&&d.current(...y)},[]),j=u.useCallback((...y)=>{if(n<=0){g(),d.current(...y);return}h.current=y,c.current!==void 0&&clearTimeout(c.current),c.current=setTimeout(f,n)},[n,g,f]);return u.useEffect(()=>f,[f]),{call:j,flush:f,cancel:g}}function Yt({anchorRef:r,open:n,onClose:d,label:c,theme:h,className:g,style:f,keepFocus:j,children:y}){const C=u.useRef(null),[F,D]=u.useState({top:0,left:0}),k=u.useCallback(()=>{var N;const _=r.current;if(!_)return;const R=_.getBoundingClientRect(),v=((N=C.current)==null?void 0:N.offsetWidth)??260,S=Math.max(8,Math.min(R.left,window.innerWidth-v-8));D({top:R.bottom+6,left:S})},[r]);return Kt(()=>{n&&k()},[n,k]),u.useEffect(()=>{if(!n)return;const _=v=>{var N,E;const S=v.target;(N=C.current)!=null&&N.contains(S)||(E=r.current)!=null&&E.contains(S)||d()},R=v=>{var S;v.key==="Escape"&&(d(),(S=r.current)==null||S.focus())};return document.addEventListener("mousedown",_),document.addEventListener("keydown",R),window.addEventListener("resize",k),window.addEventListener("scroll",k,!0),()=>{document.removeEventListener("mousedown",_),document.removeEventListener("keydown",R),window.removeEventListener("resize",k),window.removeEventListener("scroll",k,!0)}},[n,d,k,r]),!n||typeof document>"u"?null:Tn.createPortal(i.jsx("div",{ref:C,role:"dialog",onMouseDown:j?_=>_.preventDefault():void 0,"aria-label":c,"data-rg-theme":h||void 0,className:P("rg-grid-popup",g),style:{position:"fixed",top:F.top,left:F.left,...f},children:y}),document.body)}function An({value:r,onChange:n,onPick:d,onBlur:c,onKeyDown:h,min:g,max:f,locale:j,invalid:y,label:C,theme:F,className:D,style:k}){const _=u.useRef(null),R=v=>{const S=v.ctrlKey||v.altKey||v.metaKey,N=v.key==="ArrowUp"?{days:-7,months:0}:v.key==="ArrowDown"?{days:7,months:0}:S&&v.key==="ArrowLeft"?{days:-1,months:0}:S&&v.key==="ArrowRight"?{days:1,months:0}:v.key==="PageUp"?{days:0,months:-1}:v.key==="PageDown"?{days:0,months:1}:null;if(!N||v.shiftKey)return h(v);v.preventDefault();const E=q(r)??new Date,H=new Date(E.getFullYear(),E.getMonth()+N.months+1,0).getDate(),te=new Date(E.getFullYear(),E.getMonth()+N.months,Math.min(E.getDate(),H)+N.days);let O=z(te);g&&O<g&&(O=g),f&&O>f&&(O=f),n(O)};return i.jsxs(i.Fragment,{children:[i.jsx("input",{ref:_,autoFocus:!0,type:"text",inputMode:"numeric",placeholder:"YYYY-MM-DD",autoComplete:"off",className:D,style:k,value:r,"aria-label":C,"aria-invalid":y||void 0,"aria-haspopup":"dialog","aria-expanded":!0,onChange:v=>n(v.target.value.trim()),onBlur:c,onKeyDown:R,onFocus:v=>v.currentTarget.setSelectionRange(v.currentTarget.value.length,v.currentTarget.value.length)}),i.jsx(Yt,{anchorRef:_,open:!0,onClose:()=>{},label:C,theme:F,className:"rg-date-popup",keepFocus:!0,children:i.jsx(Tr,{value:r,min:g,max:f,locale:j,onPick:d,keepFocus:!0})})]})}function Er(r){return r.filterType?r.filterType:r.type==="number"?"number":r.type==="date"?"date":r.type==="boolean"?"select":"text"}const Kn=r=>typeof r=="object"&&r!==null&&!Array.isArray(r);function Ir(r){if(r==null)return!1;if(typeof r=="string")return r.trim()!=="";if(Array.isArray(r))return r.length>0;if(Kn(r)){const n=r;return typeof n.min=="number"||typeof n.max=="number"||!!n.from||!!n.to}return!1}function On(r,n,d,c){switch(r){case"text":return d.toLowerCase().includes(String(n).trim().toLowerCase());case"exact":return d.toLowerCase()===String(n).trim().toLowerCase();case"number":{const{min:h,max:g}=n,f=typeof c=="number"?c:c==null||c===""?NaN:Number(c);return Number.isNaN(f)?!1:(typeof h!="number"||f>=h)&&(typeof g!="number"||f<=g)}case"date":{const{from:h,to:g}=n,f=z(c);return f?(!h||f>=h)&&(!g||f<=g):!1}case"select":return n.includes(String(c??""))}}function Bn(r,n,d,c){if(r.filterOptions)return r.filterOptions.map(g=>typeof g=="string"?{value:g,label:g}:g);if(r.type==="boolean")return[{value:"true",label:"Yes"},{value:"false",label:"No"}];const h=new Map;for(const g of n){const f=d(g);if(f==null||f==="")continue;const j=String(f);h.has(j)||h.set(j,c(g))}return[...h].map(([g,f])=>({value:g,label:f})).sort((g,f)=>g.label.localeCompare(f.label,void 0,{numeric:!0}))}const Mr=r=>{if(r.trim()==="")return;const n=Number(r);return Number.isFinite(n)?n:void 0},Lr=r=>typeof r=="object"&&r!==null&&!Array.isArray(r);function Yn({value:r,onChange:n,label:d,debounce:c,inputClassName:h,inputStyle:g}){const f=Lr(r)?r:{},[j,y]=u.useState(f.min===void 0?"":String(f.min)),[C,F]=u.useState(f.max===void 0?"":String(f.max)),D=u.useRef(f),k=Rr((_,R)=>{const v=Mr(_),S=Mr(R);D.current={min:v,max:S},n(v===void 0&&S===void 0?void 0:{min:v,max:S})},c);return u.useEffect(()=>{f.min===D.current.min&&f.max===D.current.max||(D.current=f,k.cancel(),y(f.min===void 0?"":String(f.min)),F(f.max===void 0?"":String(f.max)))},[f.min,f.max]),i.jsxs("div",{className:"rg-grid__filter-fields",children:[i.jsxs("label",{className:"rg-grid__filter-field",children:[i.jsx("span",{children:"Min"}),i.jsx("input",{autoFocus:!0,type:"number",className:P("rg-grid__filter-input",h),style:g,value:j,"aria-label":`Minimum ${d}`,onChange:_=>{y(_.target.value),k.call(_.target.value,C)},onKeyDown:_=>_.key==="Enter"&&k.flush()})]}),i.jsxs("label",{className:"rg-grid__filter-field",children:[i.jsx("span",{children:"Max"}),i.jsx("input",{type:"number",className:P("rg-grid__filter-input",h),style:g,value:C,"aria-label":`Maximum ${d}`,onChange:_=>{F(_.target.value),k.call(j,_.target.value)},onKeyDown:_=>_.key==="Enter"&&k.flush()})]})]})}function Wn({value:r,onChange:n,onEnter:d,label:c,kind:h,placeholder:g,debounce:f,inputClassName:j,inputStyle:y}){const[C,F]=u.useState(r),D=u.useRef(r),k=Rr(_=>{D.current=_,n(_||void 0)},f);return u.useEffect(()=>{r!==D.current&&(D.current=r,k.cancel(),F(r))},[r]),i.jsx("input",{autoFocus:!0,type:"text",className:P("rg-grid__filter-input",j),style:y,value:C,placeholder:g??(h==="exact"?"Exactly…":`Filter ${c}…`),"aria-label":`Filter text for ${c}`,onChange:_=>{F(_.target.value),k.call(_.target.value)},onKeyDown:_=>{_.key==="Enter"&&(_.preventDefault(),k.flush(),d())}})}function qn({value:r,onChange:n,label:d,inputClassName:c,inputStyle:h,min:g,max:f,locale:j}){const y=Lr(r)?r:{},C=(N,E)=>n(!N&&!E?void 0:{from:N||void 0,to:E||void 0}),[F,D]=u.useState(y.from??""),[k,_]=u.useState(y.to??"");u.useEffect(()=>{(q(F)?F:"")!==(y.from??"")&&D(y.from??""),(q(k)?k:"")!==(y.to??"")&&_(y.to??"")},[y.from,y.to]);const R=(N,E)=>{if((N==="from"?D:_)(E),E!==""&&!q(E))return;const H=E||void 0;N==="from"?C(H,y.to):C(y.from,H)},v=N=>{N&&(!y.from||y.to?C(N,void 0):N<y.from?C(N,y.from):C(y.from,N))},S=(N,E,H)=>i.jsxs("label",{className:"rg-grid__filter-field",children:[i.jsx("span",{children:N==="from"?"From":"To"}),i.jsx("input",{autoFocus:H,type:"text",inputMode:"numeric",placeholder:"YYYY-MM-DD",className:P("rg-grid__filter-input",E!==""&&!q(E)&&"rg-grid__filter-input--invalid",c),style:h,value:E,"aria-label":`${d} ${N}`,"aria-invalid":E!==""&&!q(E)||void 0,onChange:te=>R(N,te.target.value.trim())})]});return i.jsxs("div",{className:"rg-grid__filter-fields rg-grid__filter-fields--stack",children:[i.jsxs("div",{className:"rg-grid__filter-date-row",children:[S("from",F,!0),S("to",k,!1)]}),i.jsx(Tr,{range:y,min:g,max:f,locale:j,onPick:v,hideFooter:!0})]})}function Un({value:r,onChange:n,options:d}){const c=Array.isArray(r)?r:[],h=(g,f)=>{const j=f?[...c,g]:c.filter(y=>y!==g);n(j.length?j:void 0)};return i.jsxs("div",{className:"rg-grid__filter-fields rg-grid__filter-options",role:"group",children:[d.length===0&&i.jsx("span",{className:"rg-grid__filter-empty",children:"No values"}),d.map(g=>i.jsx(xe,{checked:c.includes(g.value),onChange:f=>h(g.value,f),label:g.label??g.value},g.value))]})}function Vn({column:r,label:n,kind:d,value:c,onChange:h,options:g,debounce:f=300,theme:j,indicatorClassName:y,indicatorStyle:C,popupClassName:F,popupStyle:D,inputClassName:k,inputStyle:_}){const[R,v]=u.useState(!1),S=u.useRef(null),N=Ir(c),E=u.useCallback(()=>v(!1),[]),H=typeof c=="string"?c:"",te=()=>{if(r.filterRenderer)return u.createElement(r.filterRenderer,{column:r,value:H,onChange:O=>h(O||void 0)});switch(d){case"number":return i.jsx(Yn,{value:c,onChange:h,label:n,debounce:f,inputClassName:k,inputStyle:_});case"date":return i.jsx(qn,{value:c,onChange:h,label:n,min:r.dateMin,max:r.dateMax,locale:r.dateLocale,inputClassName:k,inputStyle:_});case"select":return i.jsx(Un,{value:c,onChange:h,options:g});default:return i.jsx(Wn,{value:H,onChange:h,onEnter:()=>{var O;v(!1),(O=S.current)==null||O.focus()},label:n,kind:d,placeholder:r.filterPlaceholder,debounce:f,inputClassName:k,inputStyle:_})}};return i.jsxs(i.Fragment,{children:[i.jsx("button",{ref:S,type:"button",className:P("rg-grid__filter-btn",N&&"rg-grid__filter-btn--active",R&&"rg-grid__filter-btn--open",y),style:C,"aria-label":`Filter ${n}`,"aria-haspopup":"dialog","aria-expanded":R,"data-active":N||void 0,onClick:O=>{O.stopPropagation(),v(W=>!W)},onKeyDown:O=>O.stopPropagation(),children:r.filterIndicator?u.createElement(r.filterIndicator,{column:r,active:N,open:R}):i.jsx("span",{className:"rg-grid__filter-dot","aria-hidden":"true"})}),i.jsxs(Yt,{anchorRef:S,open:R,onClose:E,label:`Filter ${n}`,theme:j,className:F,style:D,children:[te(),N&&i.jsx("button",{type:"button",className:"rg-grid__filter-clear",onClick:()=>h(void 0),children:"Clear"})]})]})}function zn({columns:r,hidden:n,onToggle:d,theme:c,className:h,style:g}){const[f,j]=u.useState(!1),y=u.useRef(null),C=u.useCallback(()=>j(!1),[]),F=r.filter(D=>!n.has(D.field)).length;return i.jsxs(i.Fragment,{children:[i.jsx("button",{ref:y,type:"button",className:P("rg-grid__tool-btn",h),style:g,"aria-haspopup":"dialog","aria-expanded":f,onClick:()=>j(D=>!D),children:"Columns"}),i.jsx(Yt,{anchorRef:y,open:f,onClose:C,label:"Show or hide columns",theme:c,children:i.jsx("div",{className:"rg-grid__filter-fields rg-grid__filter-options",role:"group","aria-label":"Columns",children:r.filter(D=>D.hideable!==!1).map(D=>{const k=!n.has(D.field);return i.jsx(xe,{checked:k,disabled:k&&F<=1,onChange:_=>d(D.field,!_),label:be(D)},D.field)})})})]})}const Hn=/^[=+\-@\t\r]/;function Jn(r,n,d){if(r==null)return"";let c=String(r);return d&&typeof r=="string"&&Hn.test(c)&&!Number.isFinite(Number(c))&&(c=`'${c}`),c.includes(n)||/["\r\n]/.test(c)?`"${c.replace(/"/g,'""')}"`:c}function Gn(r,n,d={}){const{delimiter:c=",",sanitize:h=!0}=d,g=f=>f.map(j=>Jn(j,c,h)).join(c);return[g(r),...n.map(g)].join(`\r
|
|
2
|
+
`)}function Xn(r,n){if(typeof document>"u")return;const d=new Blob(["\uFEFF",r],{type:"text/csv;charset=utf-8"}),c=URL.createObjectURL(d),h=document.createElement("a");h.href=c,h.download=n,h.style.display="none",document.body.appendChild(h),h.click(),h.remove(),setTimeout(()=>URL.revokeObjectURL(c),1e3)}const Ot=new Set(["__proto__","prototype","constructor"]),$r=(r,n)=>Object.prototype.hasOwnProperty.call(r,n);function Q(r,n){if(r===null||typeof r!="object")return;if($r(r,n))return r[n];let d=r;for(const c of n.split(".")){if(d==null||typeof d!="object"||Ot.has(c))return;d=d[c]}return d}function Sr(r,n,d){if(Array.isArray(r)){const c=[...r];return c[n]=d,c}return{...r,[n]:d}}function Bt(r,n,d){const c=r??{};if($r(c,n)||!n.includes("."))return Ot.has(n)?r:Sr(c,n,d);const[h,...g]=n.split(".");if(Ot.has(h))return r;const f=c[h];return Sr(c,h,Bt(f!==null&&typeof f=="object"?f:{},g.join("."),d))}const fe=38,Qn=150,Cr=10,At=(r,n)=>`${typeof r}:${r}\0${n}`;function Pe(r,n){const d=Q(n,r.field);return r.valueFormatter?r.valueFormatter(d,n):r.type==="boolean"&&typeof d=="boolean"?d?"Yes":"No":r.type==="date"?$n(d,r.dateLocale,r.dateFormat):d==null?"":d instanceof Date?d.toLocaleDateString():String(d)}function Zn(r,n,d){if(d.type==="date"){const c=z(r)??"",h=z(n)??"";return c<h?-1:c>h?1:0}return typeof r=="number"&&typeof n=="number"?r-n:r instanceof Date&&n instanceof Date?r.getTime()-n.getTime():typeof r=="boolean"&&typeof n=="boolean"?Number(r)-Number(n):String(r).localeCompare(String(n),void 0,{numeric:!0,sensitivity:"base"})}const eo=r=>r?Array.isArray(r)?r:[r]:[],Fr=r=>r.type==="date"&&r.validity.badInput;function to({columns:r,rows:n,getRowId:d,editable:c=!1,enterMovesDown:h=!0,onCellEdit:g,onRowsChange:f,rowSelection:j=!1,selectedRowIds:y,defaultSelectedRowIds:C,onSelectionChange:F,isRowSelectable:D,sort:k,defaultSort:_=null,onSortChange:R,multiSort:v=!1,searchable:S=!1,searchPlaceholder:N="Search…",search:E,onSearchChange:H,filters:te,onFiltersChange:O,pagination:W=!1,paginationPosition:oe="bottom",showToolbar:Ae=!0,showFooter:Ke=!0,pageSize:gt=10,pageSizeOptions:Ne=[5,10,25,50],page:ie,onPageChange:se,onPageSizeChange:_e,serverSide:b=!1,rowCount:Y,onQueryChange:T,queryDebounce:L=250,filterDebounce:re=300,loading:ge,loadingRows:ht,skeletonRow:Oe,errorMessage:Pr="Could not load the data.",columnMenu:Wt=!1,onColumnVisibilityChange:pt,keyboardNavigation:mt=!1,virtualize:Z=!1,rowHeight:le=40,overscan:qt=6,exportable:Be=!1,apiRef:Ee,onRowClick:bt,toolbar:Ut,emptyMessage:Ar="No rows to show",striped:Kr=!1,stripeColors:Ye,checkboxVariant:xt="native",animateRows:Vt=!0,rowAnimationClassName:_t,theme:We,maxHeight:qe,className:Or,style:Br,classNames:A={},styles:I={},rowClassName:yt,rowStyle:vt}){const B=(e,t)=>({className:P(t,A[e]),style:I[e]}),[Ue,zt]=u.useState(n),ye=u.useRef(n);u.useEffect(()=>{ye.current=n,zt(n)},[n]);const Ht=e=>{ye.current=e,zt(e)},[Me,Yr]=$e(E,"",H),[ve,Wr]=$e(te,{},O),[J,qr]=$e(k,eo(_),R),[kt,ke]=$e(ie,0,se),[U,Ur]=u.useState(gt),Vr=e=>{Ur(e),_e==null||_e(e)},[Ve,zr]=u.useState(()=>new Set(r.filter(e=>e.hidden).map(e=>e.field))),Hr=(e,t)=>{const o=new Set(Ve);t?o.add(e):o.delete(e),zr(o),pt==null||pt([...o])},[wt,Jt]=u.useState({}),[ze,Jr]=u.useState({}),[ro,Gr]=u.useState(0),Se=u.useRef(new Map),[Ce,he]=u.useState(null),ae=u.useRef(0),He=u.useRef(null),Je=u.useRef(new Map),[jt,Gt]=u.useState(null),Dt=u.useRef(null),Fe=u.useRef(null),[Nt,Xt]=u.useState({top:0,height:0}),M=u.useMemo(()=>{const e=r.filter(t=>!Ve.has(t.field)).map(t=>t.type==="sequence"?{...t,sortable:!1,filterable:!1,editable:!1,filterRenderer:void 0}:t);return[...e.filter(t=>t.pinned==="left"),...e.filter(t=>t.pinned!=="left"&&t.pinned!=="right"),...e.filter(t=>t.pinned==="right")]},[r,Ve]),Et=e=>e.sortable===!0,G=j==="single"?"single":j?"multiple":null,Te=M.length+(G?1:0),we=u.useMemo(()=>Ue.map((e,t)=>({row:e,index:t,id:d?d(e,t):t})),[Ue,d]),Qt=u.useRef(new Map);we.forEach(e=>Qt.current.set(e.id,e.row));const Ge=u.useMemo(()=>Object.entries(ve).filter(([e,t])=>{const o=M.find(a=>a.field===e);return!!o&&!!o.filterable&&Ir(t)}),[ve,M]),[Xr,Qr]=u.useState(Me);u.useEffect(()=>{if(!b)return;const e=setTimeout(()=>Qr(Me),L);return()=>clearTimeout(e)},[Me,b,L]);const je=b?Xr:Me,Zt=e=>e.filterRenderer?"text":Er(e),ce=u.useMemo(()=>{if(b)return we;const e=je.trim().toLowerCase();let t=we.filter(({row:a})=>e&&!M.some(s=>Pe(s,a).toLowerCase().includes(e))?!1:Ge.every(([s,l])=>{const x=M.find(m=>m.field===s);return On(Zt(x),l,Pe(x,a),Q(a,s))}));const o=J.map(a=>({col:M.find(s=>s.field===a.field),dir:a.direction==="asc"?1:-1})).filter(a=>!!a.col);return o.length&&(t=[...t].sort((a,s)=>{for(const{col:l,dir:x}of o){const m=Q(a.row,l.field),w=Q(s.row,l.field),p=m==null||m==="",K=w==null||w==="";if(p||K){if(p!==K)return p?1:-1;continue}const X=l.comparator?l.comparator(m,w,a.row,s.row):Zn(m,w,l);if(X!==0)return X*x}return 0})),t},[we,M,je,Ge,J,b]),Xe=JSON.stringify([je,ve,J,U]),er=u.useRef(Xe);u.useEffect(()=>{er.current!==Xe&&(er.current=Xe,ke(0))},[Xe]);const De=b?Y??we.length:ce.length,de=W?Math.max(1,Math.ceil(De/U)):1,V=Math.min(kt,de-1),$=W&&!b?ce.slice(V*U,V*U+U):ce,Zr=De===0?0:W?V*U+1:1,en=W?Math.min(De,(V+1)*U):De,Mt=u.useMemo(()=>({sort:J.filter(e=>{const t=r.find(o=>o.field===e.field);return!!t&&Et(t)}),filters:Object.fromEntries(Ge),search:je.trim(),page:V,pageSize:U}),[J,r,Ge,je,V,U]),tn=JSON.stringify(Mt),Qe=u.useRef(Mt);Qe.current=Mt;const Ze=u.useRef(T);Ze.current=T;const[rn,et]=u.useState(!1),[nn,St]=u.useState(!1),Ct=u.useRef(0),tt=u.useCallback(e=>{var a;const t=++Ct.current,o=(a=Ze.current)==null?void 0:a.call(Ze,e);o&&typeof o.then=="function"?(et(!0),St(!1),o.then(()=>{t===Ct.current&&et(!1)},()=>{t===Ct.current&&(et(!1),St(!0))})):(et(!1),St(!1))},[]);u.useEffect(()=>{b&&tt(Qe.current)},[b,tn,tt]),u.useEffect(()=>{b&&W&&kt>de-1&&ke(de-1)},[b,W,kt,de]);const Ft=ge??rn,tr=e=>e.map(t=>Qt.current.get(t)).filter(t=>t!==void 0),[ne,rt]=$e(y,C??[],e=>F==null?void 0:F({ids:e,rows:tr(e)})),Tt=u.useMemo(()=>new Set(ne),[ne]),nt=e=>D?D(e):!0,ot=u.useRef(null),rr=u.useRef(!1),on=(e,t)=>{if(!G||!nt(e.row))return;if(G==="single"){rt(t?[e.id]:[]),ot.current=e.id;return}const o=new Set(ne),a=rr.current&&ot.current!==null?$.findIndex(l=>l.id===ot.current):-1,s=$.findIndex(l=>l.id===e.id);if(a>=0&&s>=0)for(let l=Math.min(a,s);l<=Math.max(a,s);l++)nt($[l].row)&&(t?o.add($[l].id):o.delete($[l].id));else t?o.add(e.id):o.delete(e.id);ot.current=e.id,rt([...o])},Re=u.useMemo(()=>ce.filter(e=>nt(e.row)),[ce,D]),nr=Re.filter(e=>Tt.has(e.id)).length,or=Re.length>0&&nr===Re.length,ir=e=>{const t=new Set(ne);Re.forEach(o=>e?t.add(o.id):t.delete(o.id)),rt([...t])},it=(e,t,o)=>({value:Q(t,e.field),formattedValue:Pe(e,t),row:t,rowIndex:o,field:e.field,column:e}),Rt=(e,t)=>{const o=e.editable??c;return typeof o=="function"?o(t):!!o},st=(e,t)=>Rt(e,t)&&!(e.type==="boolean"&&!e.cellEditor),sn=(e,t)=>{const o=it(e,t.row,t.index),a=Rt(e,o);return{...o,editable:a,updateValue:s=>a&&lr(t,e,{value:s})}},sr=(e,t)=>{if(!Et(e))return;const o=J.find(l=>l.field===e.field),a=o?o.direction==="asc"?"desc":null:"asc";let s;t&&v?a?o?s=J.map(l=>l.field===e.field?{...l,direction:a}:l):s=[...J,{field:e.field,direction:a}]:s=J.filter(l=>l.field!==e.field):s=a?[{field:e.field,direction:a}]:[],qr(s)},lt=(e,t)=>{var o;return(o=Je.current.get(At(e,t)))==null?void 0:o.focus()},ue=()=>{ae.current+=1,he(null)},ln=e=>{for(const t of ye.current){const o=Q(t,e.field);if(o!=null&&o!=="")return o}},at=(e,t,o={})=>{if(!st(t,it(t,e.row,e.index)))return!1;const a=Q(e.row,t.field);let s;return t.cellEditor?s=a:t.type==="date"?s=z(a)??"":s=o.text??(a==null?"":String(a)),He.current=s,ae.current+=1,he({id:e.id,field:t.field,draft:s,session:ae.current,select:o.select??"end",invalid:!1}),!0},lr=(e,t,o)=>{const a=ye.current[e.index]??e.row,s=Q(a,t.field);let l;if("value"in o)l=o.value;else if(t.valueParser)l=t.valueParser(o.text,a);else if(t.type==="date"){if(o.text!==""&&!q(o.text))return!1;l=Pn(o.text,s??ln(t))}else if(t.type==="number")if(o.text.trim()==="")l=null;else{const w=Number(o.text);if(!Number.isFinite(w))return!1;l=w}else l=o.text;if(t.type==="date"){if(z(l)===z(s))return!0;const w=z(l);if(w&&(t.dateMin&&w<t.dateMin||t.dateMax&&w>t.dateMax))return!1}else if(Object.is(l,s))return!0;if(t.validate&&!t.validate(l,a))return!1;const x=Bt(a,t.field,l),m=ye.current.map((w,p)=>p===e.index?x:w);return Ht(m),g==null||g({rowId:e.id,rowIndex:e.index,field:t.field,oldValue:s,newValue:l,row:x}),f==null||f(m),!0},ar=(e,t,o)=>{const a=$.findIndex(p=>p.id===e.id),s=M.findIndex(p=>p.field===t);if(a<0||s<0)return null;const l=(p,K)=>st(K,it(K,p.row,p.index));if(o==="down"||o==="up"){const p=o==="down"?1:-1;for(let K=a+p;K>=0&&K<$.length;K+=p)if(l($[K],M[s]))return{entry:$[K],col:M[s]};return null}const x=o==="right"?1:-1;let m=a,w=s+x;for(;m>=0&&m<$.length;){for(;w>=0&&w<M.length;){if(l($[m],M[w]))return{entry:$[m],col:M[w]};w+=x}m+=x,w=x>0?0:M.length-1}return null},pe=(e,t,o,a={})=>{const{move:s="none",focus:l=!0}=a;if(!lr(e,t,o))return he(m=>m&&{...m,invalid:!0}),!1;const x=s==="none"?null:ar(e,t.field,s);return x?at(x.entry,x.col,{select:"all"}):(ue(),l&<(e.id,t.field)),!0},cr=(e,t,o)=>{if(e.nativeEvent.isComposing)return;const a=e.currentTarget.value,s=Fr(e.currentTarget);if(e.key==="Enter"){if(e.preventDefault(),s)return he(x=>x&&{...x,invalid:!0});const l=h?e.shiftKey?"up":"down":"none";pe(t,o,{text:a},{move:l})}else if(e.key==="Escape")e.preventDefault(),ue(),lt(t.id,o.field);else if(e.key==="Tab"&&!s){const l=e.shiftKey?"left":"right";ar(t,o.field,l)&&(e.preventDefault(),pe(t,o,{text:a},{move:l}))}},an=(e,t)=>{var l;const o=$[e],a=M[t];if(!o||!a)return;Gt({id:o.id,field:a.field}),Dt.current=At(o.id,a.field);const s=Fe.current;if(Z&&s){const x=((l=s.querySelector("thead"))==null?void 0:l.clientHeight)??0,m=e*le;m<s.scrollTop?s.scrollTo({top:m,behavior:"auto"}):m+le>s.scrollTop+s.clientHeight-x&&s.scrollTo({top:m+le-s.clientHeight+x,behavior:"auto"})}};u.useEffect(()=>{const e=Dt.current;if(!e)return;const t=Je.current.get(e);t&&(Dt.current=null,t.focus())});const cn=(e,t,o)=>{if(!mt)return!1;let a=$.findIndex(l=>l.id===t.id),s=M.findIndex(l=>l.field===o.field);if(a<0||s<0)return!1;switch(e.key){case"ArrowDown":a+=1;break;case"ArrowUp":a-=1;break;case"ArrowRight":s+=1;break;case"ArrowLeft":s-=1;break;case"PageDown":a+=Cr;break;case"PageUp":a-=Cr;break;case"Home":s=0,(e.ctrlKey||e.metaKey)&&(a=0);break;case"End":s=M.length-1,(e.ctrlKey||e.metaKey)&&(a=$.length-1);break;default:return!1}return e.preventDefault(),an(Math.max(0,Math.min($.length-1,a)),Math.max(0,Math.min(M.length-1,s))),!0},dn=(e,t,o,a)=>{e.target===e.currentTarget&&(cn(e,t,o)||st(o,a)&&(e.key==="Enter"||e.key==="F2"?(e.preventDefault(),at(t,o)):!o.cellEditor&&o.type!=="date"&&e.key.length===1&&!e.ctrlKey&&!e.metaKey&&!e.altKey&&(e.preventDefault(),at(t,o,{text:e.key}))))};Kt(()=>{if(!Z||!Fe.current)return;const e=Fe.current,t=()=>Xt(a=>a.height===e.clientHeight?a:{...a,height:e.clientHeight});if(t(),typeof ResizeObserver>"u")return;const o=new ResizeObserver(t);return o.observe(e),()=>o.disconnect()},[Z]);const Ie=Z&&!Ft&&$.length>0,un=Nt.height||(typeof qe=="number"?qe:400),ct=Ie?Math.max(0,Math.floor(Nt.top/le)-qt):0,It=Ie?Math.min($.length,Math.ceil((Nt.top+un)/le)+qt):$.length,fn=Ie?$.slice(ct,It):$,dr=`${V}|${U}|${JSON.stringify(J)}|${je}|${JSON.stringify(ve)}`,ur=u.useRef(!0);u.useEffect(()=>{if(ur.current){ur.current=!1;return}const e=Fe.current;e&&typeof e.scrollTo=="function"&&e.scrollTop>0&&e.scrollTo({top:0,behavior:"smooth"})},[dr]);const Lt=Object.keys(wt).length>0,dt=e=>wt[e.field]??(typeof e.width=="number"?e.width:Qn),gn=e=>Math.max(40,typeof e.minWidth=="number"?e.minWidth:60),hn=(e,t)=>{e.preventDefault(),e.stopPropagation();const o={...wt};Lt||M.forEach(p=>{var K;return o[p.field]=((K=Se.current.get(p.field))==null?void 0:K.offsetWidth)??dt(p)});const a=e.clientX,s=o[t.field]??dt(t),l=e.currentTarget;l.setPointerCapture(e.pointerId),Jt(o);const x=p=>Math.min(t.maxWidth??1/0,Math.max(gn(t),Math.round(p))),m=p=>Jt(K=>({...K,[t.field]:x(s+p.clientX-a)})),w=()=>{l.removeEventListener("pointermove",m),l.removeEventListener("pointerup",w),l.removeEventListener("pointercancel",w)};l.addEventListener("pointermove",m),l.addEventListener("pointerup",w),l.addEventListener("pointercancel",w)};Kt(()=>{var s,l;const e={};let t=G&&M.some(x=>x.pinned==="left")?fe:0;for(const x of M)x.pinned==="left"&&(e[x.field]=t,t+=((s=Se.current.get(x.field))==null?void 0:s.offsetWidth)??0);let o=0;for(const x of[...M].reverse())x.pinned==="right"&&(e[x.field]=o,o+=((l=Se.current.get(x.field))==null?void 0:l.offsetWidth)??0);const a=Object.keys(e);(a.length!==Object.keys(ze).length||a.some(x=>e[x]!==ze[x]))&&Jr(e)}),u.useEffect(()=>{const e=()=>Gr(t=>t+1);return window.addEventListener("resize",e),()=>window.removeEventListener("resize",e)},[]);const fr=M.map(e=>e.pinned).lastIndexOf("left"),pn=M.findIndex(e=>e.pinned==="right"),ut=fr>=0,gr=(e,t)=>({className:e.pinned?P("rg-grid__pinned",`rg-grid__pinned--${e.pinned}`,t===fr&&"rg-grid__pinned--edge",t===pn&&"rg-grid__pinned--edge"):void 0,style:e.pinned==="left"?{left:ze[e.field]??0}:e.pinned==="right"?{right:ze[e.field]??0}:void 0}),hr=typeof Be=="object"?Be:{},pr=(e={})=>{const t={...hr,...e},o=t.scope??"filtered",a=o==="page"?$:o==="selected"?we.filter(m=>Tt.has(m.id)):ce,s=t.includeHidden?r:M,l=s.map(m=>ft(m)||m.field),x=a.map(({row:m},w)=>s.map(p=>{if(p.type==="sequence")return yr(p,w,o==="page"&&W&&!p.sequenceRestartEachPage?V*U:0);const K=Q(m,p.field);return p.exportValue?p.exportValue(K,m):p.type==="date"?z(K)??"":Pe(p,m)}));return Gn(l,x,{sanitize:t.sanitize})},mr=(e={})=>{const t={...hr,...e};Xn(pr(e),`${t.filename??"export"}.csv`)};u.useEffect(()=>{Ee&&(Ee.current={getCsv:pr,exportCsv:mr,getSelectedRows:()=>tr(ne),getSelectedRowIds:()=>ne,selectAll:()=>ir(!0),clearSelection:()=>rt([]),refresh:()=>{b&&tt(Qe.current)}})}),u.useEffect(()=>()=>{Ee&&(Ee.current=null)},[Ee]);const br=e=>{var o,a,s,l,x,m,w,p;const t=e.checkbox??{};return{variant:t.variant??xt,indicator:t.indicator,className:t.className,style:t.style,classNames:{root:P(A.checkbox,(o=t.classNames)==null?void 0:o.root),control:P(A.checkboxControl,(a=t.classNames)==null?void 0:a.control),indicator:P(A.checkboxIndicator,(s=t.classNames)==null?void 0:s.indicator),label:(l=t.classNames)==null?void 0:l.label},styles:{root:{...I.checkbox,...(x=t.styles)==null?void 0:x.root},control:{...I.checkboxControl,...(m=t.styles)==null?void 0:m.control},indicator:{...I.checkboxIndicator,...(w=t.styles)==null?void 0:w.indicator},label:(p=t.styles)==null?void 0:p.label}}},me=e=>e.stopPropagation(),mn=(e,t)=>i.jsx("span",{className:"rg-grid__checkbox-cell",onClick:me,onDoubleClick:me,children:i.jsx(xe,{...br(e),checked:!!t.value,disabled:!t.editable,"aria-label":`Toggle ${be(e)}`,onChange:o=>t.updateValue(o)})}),xr=e=>ce.filter(t=>Rt(e,it(e,t.row,t.index))),bn=(e,t)=>{const o=new Map(xr(e).map(l=>[l.index,l])),a=[],s=ye.current.map((l,x)=>{const m=o.get(x);if(!m)return l;const w=Q(l,e.field);if(!!w===t||e.validate&&!e.validate(t,l))return l;const p=Bt(l,e.field,t);return a.push({rowId:m.id,rowIndex:x,field:e.field,oldValue:w,newValue:t,row:p}),p});a.length!==0&&(Ht(s),a.forEach(l=>g==null?void 0:g(l)),f==null||f(s))},xn=e=>{const t=xr(e),o=t.length>0?t:ce,a=o.filter(l=>!!Q(l.row,e.field)).length,s=o.length>0&&a===o.length;return i.jsx("span",{className:"rg-grid__header-checkbox",onClick:me,onDoubleClick:me,children:i.jsx(xe,{...br(e),checked:s,indeterminate:a>0&&!s,disabled:t.length===0,label:ft(e)||void 0,"aria-label":`Select all ${be(e)}`,onChange:l=>bn(e,l)})})},_n=(e,t,o)=>{if(t.cellEditor)return i.jsx("div",{className:"rg-grid__custom-editor",onBlur:s=>{s.currentTarget.contains(s.relatedTarget)||o.session===ae.current&&(pe(e,t,{value:He.current},{focus:!1})||ue())},onKeyDown:s=>{s.key==="Escape"&&(s.preventDefault(),s.stopPropagation(),ue(),lt(e.id,t.field))},children:u.createElement(t.cellEditor,{value:o.draft,row:e.row,rowIndex:e.index,field:t.field,column:t,onChange:s=>{He.current=s,he(l=>l&&l.session===o.session?{...l,draft:s,invalid:!1}:l)},onCommit:(s,l="none")=>{o.session===ae.current&&pe(e,t,{value:s===void 0?He.current:s},{move:l})},onCancel:()=>{ue(),lt(e.id,t.field)}})});const a=t.type==="date";return a?i.jsx(An,{value:o.draft===null||o.draft===void 0?"":String(o.draft),label:`Edit ${be(t)}`,invalid:o.invalid,min:t.dateMin,max:t.dateMax,locale:t.dateLocale,theme:We,className:P("rg-grid__editor",o.invalid&&"rg-grid__editor--invalid",A.editor),style:{textAlign:t.align,...I.editor},onChange:s=>he(l=>l&&{...l,draft:s,invalid:!1}),onPick:s=>{o.session===ae.current&&pe(e,t,{text:s},{focus:!0})},onBlur:s=>{o.session===ae.current&&(pe(e,t,{text:s.currentTarget.value},{focus:!1})||ue())},onKeyDown:s=>cr(s,e,t)}):i.jsx("input",{autoFocus:!0,type:a?"date":"text",min:a?t.dateMin:void 0,max:a?t.dateMax:void 0,className:P("rg-grid__editor",o.invalid&&"rg-grid__editor--invalid",A.editor),style:{textAlign:t.align,...I.editor},value:o.draft===null||o.draft===void 0?"":String(o.draft),inputMode:t.type==="number"?"decimal":void 0,"aria-label":`Edit ${be(t)}`,"aria-invalid":o.invalid||void 0,onChange:s=>{const l=s.target.value;he(x=>x&&{...x,draft:l,invalid:!1})},onFocus:s=>{const l=s.currentTarget;a||(o.select==="all"?l.select():l.setSelectionRange(l.value.length,l.value.length))},onBlur:s=>{if(o.session===ae.current){if(Fr(s.currentTarget))return ue();pe(e,t,{text:s.currentTarget.value},{focus:!1})||ue()}},onKeyDown:s=>cr(s,e,t)})},yn=u.useMemo(()=>{const e=new Map;for(const t of M)t.filterable&&!t.filterRenderer&&Er(t)==="select"&&e.set(t.field,Bn(t,Ue,o=>Q(o,t.field),o=>Pe(t,o)));return e},[M,Ue]),vn=Kr||!!Ye,kn=Ye?{"--rg-stripe-a":Ye[0],"--rg-stripe-b":Ye[1]}:void 0,wn=Ke&&W&&(oe==="top"||oe==="both"),jn=Ke&&W&&(oe==="bottom"||oe==="both"),Dn=Ae&&(S||!!Ut||Wt||!!Be),_r=e=>i.jsxs("div",{className:P("rg-grid__footer",e==="top"&&"rg-grid__footer--top",A.footer),style:I.footer,"data-position":e,children:[i.jsxs("span",{...B("rowCount","rg-grid__count"),children:[De===0?"0 rows":`${Zr}–${en} of ${De}`,G&&ne.length>0?` · ${ne.length} selected`:""]}),i.jsxs("div",{...B("pagination","rg-grid__pagination"),children:[i.jsxs("label",{className:"rg-grid__page-size-label",children:["Rows per page",i.jsx("select",{value:U,onChange:t=>Vr(Number(t.target.value)),...B("pageSize","rg-grid__page-size"),children:(Ne.includes(U)?Ne:[...Ne,U].sort((t,o)=>t-o)).map(t=>i.jsx("option",{value:t,children:t},t))})]}),i.jsx("button",{type:"button","aria-label":"First page",disabled:V===0,onClick:()=>ke(0),...B("pageButton","rg-grid__page-btn"),children:"«"}),i.jsx("button",{type:"button","aria-label":"Previous page",disabled:V===0,onClick:()=>ke(V-1),...B("pageButton","rg-grid__page-btn"),children:"‹"}),i.jsxs("span",{...B("pageInfo","rg-grid__page-info"),children:["Page ",V+1," of ",de]}),i.jsx("button",{type:"button","aria-label":"Next page",disabled:V>=de-1,onClick:()=>ke(V+1),...B("pageButton","rg-grid__page-btn"),children:"›"}),i.jsx("button",{type:"button","aria-label":"Last page",disabled:V>=de-1,onClick:()=>ke(de-1),...B("pageButton","rg-grid__page-btn"),children:"»"})]})]}),Nn=e=>i.jsx("tr",{className:"rg-grid__tr rg-grid__skeleton-row","aria-hidden":"true",style:Z?{height:le}:void 0,children:Oe?i.jsx("td",{colSpan:Te,className:"rg-grid__td rg-grid__skeleton-cell",children:u.createElement(Oe,{rowIndex:e,columns:M})}):i.jsxs(i.Fragment,{children:[G&&i.jsx("td",{className:"rg-grid__td",children:i.jsx("span",{...B("skeleton","rg-grid__skeleton"),style:{...I.skeleton,width:18}})}),M.map((t,o)=>i.jsx("td",{className:"rg-grid__td",style:{textAlign:t.align},children:i.jsx("span",{...B("skeleton","rg-grid__skeleton"),style:{...I.skeleton,width:`${55+(e*7+o*13)%35}%`}})},t.field))]})},`sk${e}`),yr=(e,t,o=W&&!e.sequenceRestartEachPage?V*U:0)=>(e.sequenceStart??1)+o+t,En=(e,t)=>{const{row:o,id:a,index:s}=e,l=typeof yt=="function"?yt(o,s):yt,x=typeof vt=="function"?vt(o,s):vt,m=Tt.has(a),w=typeof _t=="function"?_t(o,s):_t;return i.jsxs("tr",{onClick:bt?()=>bt(o,s):void 0,"aria-selected":G?m:void 0,className:P("rg-grid__tr","rg-grid__row",vn&&(t%2===0?"rg-grid__row--stripe-a":"rg-grid__row--stripe-b"),Vt&&!Z&&(w||"rg-grid__row--enter"),m&&"rg-grid__row--selected",bt&&"rg-grid__row--clickable",A.row,l),style:{...Vt&&!Z?{"--rg-i":Math.min(t,24)}:null,...Z?{height:le}:null,...I.row,...x},children:[G&&i.jsx("td",{className:P("rg-grid__td rg-grid__select-cell",ut&&"rg-grid__pinned rg-grid__pinned--left"),style:{width:fe,minWidth:fe,maxWidth:fe,...ut?{left:0}:null},onClick:me,children:i.jsx("span",{className:"rg-grid__checkbox-cell",onClickCapture:p=>rr.current=p.shiftKey,children:i.jsx(xe,{variant:xt,checked:m,disabled:!nt(o),"aria-label":G==="single"?"Select row":`Select row ${s+1}`,onChange:p=>on(e,p),classNames:{root:A.checkbox,control:A.checkboxControl,indicator:A.checkboxIndicator},styles:{root:I.checkbox,control:I.checkboxControl,indicator:I.checkboxIndicator}})})}),M.map((p,K)=>{let X=sn(p,e);if(p.type==="sequence"){const ee=yr(p,t);X={...X,value:ee,formattedValue:p.valueFormatter?p.valueFormatter(ee,o):String(ee),editable:!1}}const Sn=typeof p.cellClassName=="function"?p.cellClassName(X):p.cellClassName,Cn=typeof p.cellStyle=="function"?p.cellStyle(X):p.cellStyle,vr=Ce!==null&&Ce.id===a&&Ce.field===p.field,$t=st(p,X),kr=gr(p,K),Fn=jt?jt.id===a&&jt.field===p.field:t===0&&K===0;return i.jsx("td",{ref:ee=>{const wr=At(a,p.field);ee?Je.current.set(wr,ee):Je.current.delete(wr)},tabIndex:mt?Fn?0:-1:$t?0:void 0,onFocus:mt?ee=>ee.target===ee.currentTarget&&Gt({id:a,field:p.field}):void 0,onDoubleClick:$t?()=>at(e,p):void 0,onKeyDown:ee=>dn(ee,e,p,X),className:P("rg-grid__td",$t&&"rg-grid__td--editable",vr&&"rg-grid__td--editing",kr.className,A.cell,p.className,Sn),style:{textAlign:p.align,...I.cell,...p.style,...Cn,...kr.style},children:vr&&Ce?_n(e,p,Ce):p.cellRenderer?u.createElement(p.cellRenderer,X):p.type==="boolean"&&!p.cellEditor?mn(p,X):X.formattedValue},p.field)})]},a)},Mn=ht??(W?Math.min(U,20):5);return i.jsxs("div",{className:P("rg-grid",Z&&"rg-grid--virtual",A.root,Or),style:{...kn,...I.root,...Br},"data-rg-theme":We||void 0,"aria-busy":Ft||void 0,children:[Dn&&i.jsxs("div",{...B("toolbar","rg-grid__toolbar"),children:[i.jsxs("div",{className:"rg-grid__toolbar-left",children:[S&&i.jsx("input",{type:"search",value:Me,onChange:e=>Yr(e.target.value),placeholder:N,"aria-label":"Search all columns",...B("search","rg-grid__search")}),G&&ne.length>0&&i.jsxs("span",{className:"rg-grid__selected-count",role:"status",children:[ne.length," selected"]})]}),i.jsxs("div",{className:"rg-grid__toolbar-actions",children:[Ut,Wt&&i.jsx(zn,{columns:r,hidden:Ve,onToggle:Hr,theme:We,className:A.toolButton,style:I.toolButton}),Be&&i.jsx("button",{type:"button",onClick:()=>mr(),...B("toolButton","rg-grid__tool-btn"),children:"Export CSV"})]})]}),wn&&_r("top"),i.jsx("div",{ref:Fe,...B("scroll","rg-grid__scroll"),onScroll:Z?e=>Xt({top:e.currentTarget.scrollTop,height:e.currentTarget.clientHeight}):void 0,style:{...I.scroll,...qe!==void 0?{maxHeight:qe}:Z?{maxHeight:400}:null},children:i.jsxs("table",{...B("table","rg-grid__table"),role:"grid",style:Lt?{...I.table,tableLayout:"fixed",width:M.reduce((e,t)=>e+dt(t),G?fe:0),minWidth:"100%"}:I.table,children:[i.jsx("thead",{...B("thead","rg-grid__thead"),children:i.jsxs("tr",{...B("headerRow","rg-grid__tr"),children:[G&&i.jsx("th",{scope:"col",className:P("rg-grid__th rg-grid__select-cell",ut&&"rg-grid__pinned rg-grid__pinned--left",A.headerCell),style:{width:fe,minWidth:fe,maxWidth:fe,...ut?{left:0}:null,...I.headerCell},children:G==="multiple"&&i.jsx("span",{className:"rg-grid__checkbox-cell",children:i.jsx(xe,{variant:xt,checked:or,indeterminate:nr>0&&!or,disabled:Re.length===0,"aria-label":"Select all rows",onChange:ir,classNames:{root:A.checkbox,control:A.checkboxControl,indicator:A.checkboxIndicator},styles:{root:I.checkbox,control:I.checkboxControl,indicator:I.checkboxIndicator}})})}),M.map((e,t)=>{const o=J.findIndex(m=>m.field===e.field),a=o>=0?J[o].direction:null,s=Et(e),l=Zt(e),x=gr(e,t);return i.jsxs("th",{ref:m=>{m?Se.current.set(e.field,m):Se.current.delete(e.field)},scope:"col","aria-sort":a?a==="asc"?"ascending":"descending":s?"none":void 0,tabIndex:s?0:void 0,onClick:m=>sr(e,m.shiftKey),onKeyDown:m=>{s&&m.target===m.currentTarget&&(m.key==="Enter"||m.key===" ")&&(m.preventDefault(),sr(e,m.shiftKey))},className:P("rg-grid__th",s&&"rg-grid__th--sortable",x.className,A.headerCell,e.className,e.headerClassName),style:{width:Lt?dt(e):e.width,minWidth:e.minWidth,textAlign:e.align,...I.headerCell,...e.style,...e.headerStyle,...x.style},children:[i.jsxs("span",{className:"rg-grid__th-content",children:[e.headerRenderer?u.createElement(e.headerRenderer,{column:e,sortDirection:a}):e.headerCheckbox&&e.type==="boolean"?xn(e):ft(e),e.filterable&&i.jsx(Vn,{column:e,label:be(e),kind:l,value:ve[e.field],onChange:m=>{const w={...ve};m===void 0?delete w[e.field]:w[e.field]=m,Wr(w)},options:yn.get(e.field)??[],debounce:e.filterDebounce??re,theme:We,indicatorClassName:P(A.filterIndicator,e.filterIndicatorClassName),indicatorStyle:{...I.filterIndicator,...e.filterIndicatorStyle},popupClassName:P(A.filterPopup,e.filterPopupClassName),popupStyle:{...I.filterPopup,...e.filterPopupStyle},inputClassName:A.filterInput,inputStyle:I.filterInput}),s&&i.jsxs("span",{className:"rg-grid__sort","aria-hidden":"true",children:[a==="asc"?"▲":a==="desc"?"▼":"↕",a&&J.length>1&&i.jsx("sup",{className:"rg-grid__sort-order",children:o+1})]})]}),e.resizable&&i.jsx("span",{className:"rg-grid__resizer",role:"separator","aria-orientation":"vertical","aria-label":`Resize ${be(e)}`,onPointerDown:m=>hn(m,e),onClick:me,onDoubleClick:me})]},e.field)})]})}),i.jsx("tbody",{...B("tbody","rg-grid__tbody"),children:Ft?Array.from({length:Mn},(e,t)=>Nn(t)):nn?i.jsx("tr",{children:i.jsxs("td",{colSpan:Te,...B("empty","rg-grid__empty rg-grid__error"),role:"alert",children:[Pr," ",i.jsx("button",{type:"button",className:"rg-grid__tool-btn",onClick:()=>tt(Qe.current),children:"Retry"})]})}):$.length===0?i.jsx("tr",{children:i.jsx("td",{colSpan:Te,...B("empty","rg-grid__empty"),children:Ar})}):i.jsxs(i.Fragment,{children:[Ie&&ct>0&&i.jsx("tr",{"aria-hidden":"true",className:"rg-grid__spacer",children:i.jsx("td",{colSpan:Te,style:{height:ct*le}})}),fn.map((e,t)=>En(e,ct+t)),Ie&&It<$.length&&i.jsx("tr",{"aria-hidden":"true",className:"rg-grid__spacer",children:i.jsx("td",{colSpan:Te,style:{height:($.length-It)*le}})})]})},dr)]})}),jn&&_r("bottom")]})}exports.Checkbox=xe;exports.DataGrid=to;
|