react-gridix 0.1.0 → 0.1.1

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/dist/index.d.ts CHANGED
@@ -1,47 +1,12 @@
1
- import { ButtonHTMLAttributes } from 'react';
2
1
  import { ComponentType } from 'react';
3
2
  import { CSSProperties } from 'react';
4
- import { ForwardRefExoticComponent } from 'react';
5
- import { HTMLAttributes } from 'react';
6
- import { InputHTMLAttributes } from 'react';
7
3
  import { JSX as JSX_2 } from 'react';
8
4
  import { ReactNode } from 'react';
9
- import { ReactPortal } from 'react';
10
- import { RefAttributes } from 'react';
11
-
12
- export declare function Alert({ tone, title, onClose, className, children, ...rest }: AlertProps): JSX_2.Element;
13
-
14
- export declare interface AlertProps extends Omit<HTMLAttributes<HTMLDivElement>, "title"> {
15
- tone?: "info" | "success" | "warning" | "danger";
16
- title?: ReactNode;
17
- onClose?: () => void;
18
- }
19
5
 
20
6
  declare type AnyRow = Record<string, any>;
21
7
 
22
- export declare function Badge({ tone, className, children, ...rest }: BadgeProps): JSX_2.Element;
23
-
24
- export declare interface BadgeProps extends HTMLAttributes<HTMLSpanElement> {
25
- tone?: "neutral" | "info" | "success" | "warning" | "danger";
26
- }
27
-
28
- export declare const Button: ForwardRefExoticComponent<ButtonProps & RefAttributes<HTMLButtonElement>>;
29
-
30
- export declare interface ButtonProps extends ButtonHTMLAttributes<HTMLButtonElement> {
31
- variant?: "primary" | "secondary" | "ghost" | "danger";
32
- size?: "sm" | "md" | "lg";
33
- loading?: boolean;
34
- }
35
-
36
- export declare function Card({ title, footer, className, children, ...rest }: CardProps): JSX_2.Element;
37
-
38
- export declare interface CardProps extends Omit<HTMLAttributes<HTMLDivElement>, "title"> {
39
- title?: ReactNode;
40
- footer?: ReactNode;
41
- }
42
-
43
8
  export declare interface CellEditableParams<T = Record<string, any>> {
44
- /** The raw value stored in the row. */
9
+ /** The raw value stored in the row (read from nested objects for `"a.b"` fields). */
45
10
  value: unknown;
46
11
  /** The value as text, after `valueFormatter`. */
47
12
  formattedValue: string;
@@ -54,9 +19,11 @@ export declare interface CellEditableParams<T = Record<string, any>> {
54
19
  export declare interface CellEditEvent<T> {
55
20
  rowId: string | number;
56
21
  rowIndex: number;
22
+ /** The column's field, for example `"contact.phone"`. */
57
23
  field: string;
58
24
  oldValue: unknown;
59
25
  newValue: unknown;
26
+ /** The updated row. */
60
27
  row: T;
61
28
  }
62
29
 
@@ -136,7 +103,7 @@ export declare type CheckboxVariant = "button" | "tick" | "native";
136
103
  export declare interface ColumnCheckboxOptions {
137
104
  /** Overrides the grid's `checkboxVariant` for this column. */
138
105
  variant?: CheckboxVariant;
139
- /** Replaces what is drawn inside the `"button"` and `"tick"` variants. */
106
+ /** A custom character (or any node) drawn inside the box when checked, for example `"✕"` or `"★"`. */
140
107
  indicator?: ReactNode;
141
108
  className?: string;
142
109
  style?: CSSProperties;
@@ -145,9 +112,15 @@ export declare interface ColumnCheckboxOptions {
145
112
  }
146
113
 
147
114
  export declare interface ColumnDef<T = Record<string, any>> {
148
- /** Key of the row object this column reads and writes. */
149
- field: keyof T & string;
150
- /** Text shown in the header. Defaults to the field name. */
115
+ /**
116
+ * Key of the row object this column reads and writes. Use dot notation for nested objects:
117
+ * `"contact.phone"`. Edits to a nested field copy the objects on the way and never change your data in place.
118
+ */
119
+ field: FieldPath<T> & string;
120
+ /**
121
+ * Text shown in the header. Defaults to the field name, except for `type: "boolean"` columns,
122
+ * which default to an empty string.
123
+ */
151
124
  headerName?: string;
152
125
  /**
153
126
  * "number" columns sort numerically and parse edits as numbers.
@@ -159,8 +132,22 @@ export declare interface ColumnDef<T = Record<string, any>> {
159
132
  align?: "left" | "center" | "right";
160
133
  /** Overrides the grid-level `sortable`. */
161
134
  sortable?: boolean;
162
- /** Overrides the grid-level `columnFilters`. */
135
+ /** Show a filter indicator in this column's header. Default false. Clicking it opens the filter popup. */
163
136
  filterable?: boolean;
137
+ /** Placeholder of the default filter text box. */
138
+ filterPlaceholder?: string;
139
+ /** A React component drawn instead of the default dot. Receives `{ column, active, open }`. */
140
+ filterIndicator?: ComponentType<FilterIndicatorProps<T>>;
141
+ /** Classes for this column's filter indicator button (Tailwind works). */
142
+ filterIndicatorClassName?: string;
143
+ /** Inline styles for this column's filter indicator button. */
144
+ filterIndicatorStyle?: CSSProperties;
145
+ /** Classes for this column's filter popup. */
146
+ filterPopupClassName?: string;
147
+ /** Inline styles for this column's filter popup. */
148
+ filterPopupStyle?: CSSProperties;
149
+ /** A React component that replaces the filter text box inside the popup. */
150
+ filterRenderer?: ComponentType<FilterRendererProps<T>>;
164
151
  /**
165
152
  * `true` / `false`, or a function that decides per cell. Overrides the grid-level `editable`.
166
153
  * Example: `editable: ({ row }) => row.status !== "locked"`.
@@ -178,10 +165,12 @@ export declare interface ColumnDef<T = Record<string, any>> {
178
165
  cellRenderer?: ComponentType<CellParams<T>>;
179
166
  /** A React component used instead of the text box when editing this column. */
180
167
  cellEditor?: ComponentType<CellEditorProps<T>>;
181
- /** A React component that renders the header label (the sort arrow is still added). */
168
+ /** A React component that renders the header label (the filter indicator and sort arrow are still added). */
182
169
  headerRenderer?: ComponentType<HeaderRendererProps<T>>;
183
- /** A React component that replaces the filter text box under the header. */
184
- filterRenderer?: ComponentType<FilterRendererProps<T>>;
170
+ /** Classes for the whole column: its header cell and every body cell. Tailwind works. */
171
+ className?: string;
172
+ /** Inline styles for the whole column: its header cell and every body cell. */
173
+ style?: CSSProperties;
185
174
  headerClassName?: string;
186
175
  headerStyle?: CSSProperties;
187
176
  cellClassName?: string | ((params: CellParams<T>) => string);
@@ -190,14 +179,14 @@ export declare interface ColumnDef<T = Record<string, any>> {
190
179
  checkbox?: ColumnCheckboxOptions;
191
180
  /**
192
181
  * For `type: "boolean"` columns: draws a checkbox in the header, with the header name as its
193
- * label. Clicking it checks every row that matches the current search and filters (all pages),
194
- * or unchecks them all when they are already checked. It shows a mixed state when only some
195
- * are checked. Ignored when the column has a `headerRenderer`.
182
+ * label (no label when the name is empty). Clicking it checks every row that matches the current
183
+ * search and filters (all pages), or unchecks them all when they are already checked. It shows a
184
+ * mixed state when only some are checked. Ignored when the column has a `headerRenderer`.
196
185
  */
197
186
  headerCheckbox?: boolean;
198
187
  }
199
188
 
200
- export declare function DataGrid<T extends AnyRow = AnyRow>({ columns, rows, getRowId, editable, enterMovesDown, onCellEdit, onRowsChange, sortable, defaultSort, onSortChange, searchable, searchPlaceholder, columnFilters, pagination, paginationPosition, pageSize: initialPageSize, pageSizeOptions, onRowClick, toolbar, emptyMessage, striped, checkboxVariant, maxHeight, className, style, classNames, styles, rowClassName, rowStyle, }: DataGridProps<T>): JSX_2.Element;
189
+ export declare function DataGrid<T extends AnyRow = AnyRow>({ columns, rows, getRowId, editable, enterMovesDown, onCellEdit, onRowsChange, sortable, defaultSort, onSortChange, searchable, searchPlaceholder, pagination, paginationPosition, pageSize: initialPageSize, pageSizeOptions, onRowClick, toolbar, emptyMessage, striped, stripeColors, checkboxVariant, animateRows, theme, maxHeight, className, style, classNames, styles, rowClassName, rowStyle, }: DataGridProps<T>): JSX_2.Element;
201
190
 
202
191
  export declare interface DataGridProps<T = Record<string, any>> {
203
192
  columns: ColumnDef<T>[];
@@ -223,8 +212,6 @@ export declare interface DataGridProps<T = Record<string, any>> {
223
212
  /** Global search box above the grid. Default true. */
224
213
  searchable?: boolean;
225
214
  searchPlaceholder?: string;
226
- /** Per-column filter inputs under the header. Default true. */
227
- columnFilters?: boolean;
228
215
  /** Default true. */
229
216
  pagination?: boolean;
230
217
  /** Where the row count and page controls go: "bottom" (default), "top" or "both". */
@@ -235,9 +222,19 @@ export declare interface DataGridProps<T = Record<string, any>> {
235
222
  /** Extra content on the right side of the toolbar. */
236
223
  toolbar?: ReactNode;
237
224
  emptyMessage?: ReactNode;
225
+ /** Alternate row shading. Default false. */
238
226
  striped?: boolean;
227
+ /** Two colours for the alternating rows, for example `["#ffffff", "#f1f5f9"]`. Implies `striped`. */
228
+ stripeColors?: [string, string];
239
229
  /** Checkbox style for `type: "boolean"` columns: "button", "tick" or "native" (default). */
240
230
  checkboxVariant?: CheckboxVariant;
231
+ /** Rows slide in smoothly when they render (new page, sort, search). Default true. Respects "reduce motion". */
232
+ animateRows?: boolean;
233
+ /**
234
+ * Name of a theme. Nothing changes unless you pass one: "ocean", "midnight", "sunset" or "forest",
235
+ * or the name of your own `[data-rk-theme="..."]` CSS.
236
+ */
237
+ theme?: GridTheme | (string & {});
241
238
  /** Makes the body scroll with a sticky header, e.g. 400 or "60vh". */
242
239
  maxHeight?: number | string;
243
240
  /** Tailwind or any CSS classes for the root element. */
@@ -252,14 +249,37 @@ export declare interface DataGridProps<T = Record<string, any>> {
252
249
  rowStyle?: CSSProperties | ((row: T, rowIndex: number) => CSSProperties);
253
250
  }
254
251
 
255
- /** Props received by a column's `filterRenderer` component. */
252
+ /**
253
+ * Every field a column can point at: top-level keys, plus dot paths into nested objects
254
+ * (`"contact.phone"`). Goes up to 5 levels deep. Arrays are treated as plain values.
255
+ */
256
+ export declare type FieldPath<T, D extends number = 5> = [D] extends [never] ? never : T extends Primitive | readonly unknown[] ? never : {
257
+ [K in keyof T & string]: NonNullable<T[K]> extends Primitive | readonly unknown[] ? K : K | `${K}.${FieldPath<NonNullable<T[K]>, Prev[D]>}`;
258
+ }[keyof T & string];
259
+
260
+ /** Props received by a column's `filterIndicator` component. */
261
+ export declare interface FilterIndicatorProps<T = Record<string, any>> {
262
+ column: ColumnDef<T>;
263
+ /** True while a filter text is set for this column. */
264
+ active: boolean;
265
+ /** True while the filter popup is open. */
266
+ open: boolean;
267
+ }
268
+
269
+ /** Props received by a column's `filterRenderer` component (it is shown inside the filter popup). */
256
270
  export declare interface FilterRendererProps<T = Record<string, any>> {
257
271
  column: ColumnDef<T>;
258
272
  value: string;
259
273
  onChange: (value: string) => void;
260
274
  }
261
275
 
262
- export declare type GridSlot = "root" | "toolbar" | "search" | "scroll" | "table" | "thead" | "headerRow" | "headerCell" | "filterRow" | "filterCell" | "filterInput" | "tbody" | "row" | "cell" | "editor" | "empty" | "footer" | "rowCount" | "pageInfo" | "pageSize" | "pagination" | "pageButton" | "checkbox" | "checkboxControl" | "checkboxIndicator";
276
+ export declare type GridSlot = "root" | "toolbar" | "search" | "scroll" | "table" | "thead" | "headerRow" | "headerCell" | "filterIndicator" | "filterPopup" | "filterInput" | "tbody" | "row" | "cell" | "editor" | "empty" | "footer" | "rowCount" | "pageInfo" | "pageSize" | "pagination" | "pageButton" | "checkbox" | "checkboxControl" | "checkboxIndicator";
277
+
278
+ /**
279
+ * Built-in themes. A theme only applies when you pass its name to `<DataGrid theme="..." />`.
280
+ * Any other string works too if you define `[data-rk-theme="name"]` CSS variables yourself.
281
+ */
282
+ export declare type GridTheme = "ocean" | "midnight" | "sunset" | "forest";
263
283
 
264
284
  /** Props received by a column's `headerRenderer` component. */
265
285
  export declare interface HeaderRendererProps<T = Record<string, any>> {
@@ -267,28 +287,14 @@ export declare interface HeaderRendererProps<T = Record<string, any>> {
267
287
  sortDirection: SortDirection | null;
268
288
  }
269
289
 
270
- export declare const Input: ForwardRefExoticComponent<InputProps & RefAttributes<HTMLInputElement>>;
271
-
272
- export declare interface InputProps extends InputHTMLAttributes<HTMLInputElement> {
273
- label?: string;
274
- error?: string;
275
- hint?: string;
276
- }
277
-
278
- export declare function Modal({ open, onClose, title, footer, children }: ModalProps): ReactPortal | null;
279
-
280
- export declare interface ModalProps {
281
- open: boolean;
282
- onClose: () => void;
283
- title?: ReactNode;
284
- footer?: ReactNode;
285
- children?: ReactNode;
286
- }
287
-
288
290
  export declare type MoveDirection = "down" | "up" | "left" | "right" | "none";
289
291
 
290
292
  export declare type PaginationPosition = "bottom" | "top" | "both";
291
293
 
294
+ declare type Prev = [never, 0, 1, 2, 3, 4, 5];
295
+
296
+ declare type Primitive = string | number | boolean | bigint | symbol | null | undefined | Date | ((...args: any[]) => any);
297
+
292
298
  export declare type SortDirection = "asc" | "desc";
293
299
 
294
300
  export declare interface SortModel {
@@ -1 +1 @@
1
- "use strict";Object.defineProperty(exports,Symbol.toStringTag,{value:"Module"});const l=require("react/jsx-runtime"),h=require("react"),Ue=require("react-dom"),Xe=h.forwardRef(function({variant:d="primary",size:c="md",loading:k=!1,disabled:_,className:b,children:p,...m},D){const v=["rk-btn",`rk-btn--${d}`,`rk-btn--${c}`,b].filter(Boolean).join(" ");return l.jsxs("button",{ref:D,className:v,disabled:_||k,"aria-busy":k||void 0,...m,children:[k&&l.jsx("span",{className:"rk-spinner","aria-hidden":"true"}),p]})}),Ze=h.forwardRef(function({label:d,error:c,hint:k,id:_,className:b,...p},m){const D=h.useId(),v=_??D,C=c||k?`${v}-desc`:void 0;return l.jsxs("div",{className:["rk-field",b].filter(Boolean).join(" "),children:[d&&l.jsx("label",{className:"rk-label",htmlFor:v,children:d}),l.jsx("input",{ref:m,id:v,className:`rk-input${c?" rk-input--error":""}`,"aria-invalid":c?!0:void 0,"aria-describedby":C,...p}),(c||k)&&l.jsx("span",{id:C,className:c?"rk-error-text":"rk-hint",children:c??k})]})});function et({title:i,footer:d,className:c,children:k,..._}){return l.jsxs("div",{className:["rk-card",c].filter(Boolean).join(" "),..._,children:[i&&l.jsx("div",{className:"rk-card__header",children:i}),l.jsx("div",{className:"rk-card__body",children:k}),d&&l.jsx("div",{className:"rk-card__footer",children:d})]})}function tt({tone:i="neutral",className:d,children:c,...k}){return l.jsx("span",{className:["rk-badge",`rk-badge--${i}`,d].filter(Boolean).join(" "),...k,children:c})}function rt({tone:i="info",title:d,onClose:c,className:k,children:_,...b}){return l.jsxs("div",{role:i==="danger"||i==="warning"?"alert":"status",className:["rk-alert",`rk-alert--${i}`,k].filter(Boolean).join(" "),...b,children:[l.jsxs("div",{className:"rk-alert__content",children:[d&&l.jsx("strong",{className:"rk-alert__title",children:d}),l.jsx("div",{children:_})]}),c&&l.jsx("button",{type:"button",className:"rk-alert__close","aria-label":"Dismiss",onClick:c,children:"×"})]})}function nt({open:i,onClose:d,title:c,footer:k,children:_}){const b=h.useId(),p=h.useRef(null);return h.useEffect(()=>{var C;if(!i)return;const m=document.activeElement;(C=p.current)==null||C.focus();const D=M=>{M.key==="Escape"&&d()};document.addEventListener("keydown",D);const v=document.body.style.overflow;return document.body.style.overflow="hidden",()=>{var M;document.removeEventListener("keydown",D),document.body.style.overflow=v,(M=m==null?void 0:m.focus)==null||M.call(m)}},[i,d]),!i||typeof document>"u"?null:Ue.createPortal(l.jsx("div",{className:"rk-overlay",onMouseDown:m=>m.target===m.currentTarget&&d(),children:l.jsxs("div",{ref:p,role:"dialog","aria-modal":"true","aria-labelledby":c?b:void 0,tabIndex:-1,className:"rk-modal",children:[c&&l.jsxs("div",{className:"rk-modal__header",children:[l.jsx("h2",{id:b,className:"rk-modal__title",children:c}),l.jsx("button",{type:"button",className:"rk-alert__close","aria-label":"Close",onClick:d,children:"×"})]}),l.jsx("div",{className:"rk-modal__body",children:_}),k&&l.jsx("div",{className:"rk-modal__footer",children:k})]})}),document.body)}const H=(...i)=>i.filter(Boolean).join(" ");function lt(){return l.jsx("svg",{viewBox:"0 0 16 16",width:"100%",height:"100%","aria-hidden":"true",focusable:"false",children:l.jsx("path",{d:"M3.5 8.5l3 3 6-7",fill:"none",stroke:"currentColor",strokeWidth:"2.2",strokeLinecap:"round",strokeLinejoin:"round"})})}function it(){return l.jsx("svg",{viewBox:"0 0 16 16",width:"100%",height:"100%","aria-hidden":"true",focusable:"false",children:l.jsx("path",{d:"M4 8h8",fill:"none",stroke:"currentColor",strokeWidth:"2.2",strokeLinecap:"round"})})}function fe({checked:i,onChange:d,indeterminate:c=!1,variant:k="native",disabled:_=!1,label:b,"aria-label":p,id:m,name:D,indicator:v,className:C,style:M,classNames:P={},styles:j={}}){const S=c?"indeterminate":i?"checked":"unchecked";return l.jsxs("label",{className:H("rk-checkbox",`rk-checkbox--${k}`,S==="checked"&&"rk-checkbox--checked",c&&"rk-checkbox--indeterminate",_&&"rk-checkbox--disabled",P.root,C),style:{...j.root,...M},"data-state":S,children:[k==="native"?l.jsx("input",{type:"checkbox",id:m,name:D,ref:K=>{K&&(K.indeterminate=c)},className:H("rk-checkbox__control",P.control),style:j.control,checked:i,disabled:_,"aria-label":p,"data-state":S,onChange:K=>d(K.target.checked)}):l.jsx("button",{type:"button",role:"checkbox",id:m,className:H("rk-checkbox__control",P.control),style:j.control,"aria-checked":c?"mixed":i,"aria-label":p,disabled:_,"data-state":S,onClick:()=>d(!i),children:l.jsx("span",{className:H("rk-checkbox__indicator",v!==void 0&&!c&&"rk-checkbox__indicator--custom",P.indicator),style:j.indicator,"data-state":S,"aria-hidden":"true",children:c?k==="tick"?l.jsx(it,{}):null:v!==void 0?v:k==="tick"?l.jsx(lt,{}):null})}),b!=null&&l.jsx("span",{className:H("rk-checkbox__label",P.label),style:j.label,children:b})]})}const T=(...i)=>i.filter(Boolean).join(" "),Se=(i,d)=>`${typeof i}:${i}\0${d}`;function ue(i,d){const c=d[i.field];return i.valueFormatter?i.valueFormatter(c,d):i.type==="boolean"&&typeof c=="boolean"?c?"Yes":"No":c==null?"":c instanceof Date?c.toLocaleDateString():String(c)}function ot(i,d){return typeof i=="number"&&typeof d=="number"?i-d:i instanceof Date&&d instanceof Date?i.getTime()-d.getTime():typeof i=="boolean"&&typeof d=="boolean"?Number(i)-Number(d):String(i).localeCompare(String(d),void 0,{numeric:!0,sensitivity:"base"})}function at({columns:i,rows:d,getRowId:c,editable:k=!1,enterMovesDown:_=!0,onCellEdit:b,onRowsChange:p,sortable:m=!0,defaultSort:D=null,onSortChange:v,searchable:C=!0,searchPlaceholder:M="Search…",columnFilters:P=!0,pagination:j=!0,paginationPosition:S="bottom",pageSize:K=10,pageSizeOptions:ne=[5,10,25,50],onRowClick:le,toolbar:he,emptyMessage:Ie="No rows to show",striped:Be=!1,checkboxVariant:Te="native",maxHeight:ke,className:$e,style:Me,classNames:I={},styles:w={},rowClassName:ie,rowStyle:oe}){const g=(e,t)=>({className:T(t,I[e]),style:w[e]}),[xe,be]=h.useState(d),V=h.useRef(d);h.useEffect(()=>{V.current=d,be(d)},[d]);const ge=e=>{V.current=e,be(e)},[J,Pe]=h.useState(""),[A,me]=h.useState({}),[N,Ke]=h.useState(D),[Re,q]=h.useState(0),[B,Fe]=h.useState(K),[z,W]=h.useState(null),R=h.useRef(0),Q=h.useRef(null),ae=h.useRef(new Map),pe=h.useMemo(()=>xe.map((e,t)=>({row:e,index:t,id:c?c(e,t):t})),[xe,c]),G=h.useMemo(()=>{const e=J.trim().toLowerCase(),t=Object.entries(A).filter(([,n])=>n.trim()!=="");let r=pe.filter(({row:n})=>e&&!i.some(s=>ue(s,n).toLowerCase().includes(e))?!1:t.every(([o,s])=>{const f=i.find(a=>a.field===o);return f?ue(f,n).toLowerCase().includes(s.trim().toLowerCase()):!0}));if(N){const n=i.find(o=>o.field===N.field);if(n){const o=N.direction==="asc"?1:-1;r=[...r].sort((s,f)=>{const a=s.row[n.field],u=f.row[n.field],x=a==null||a==="",y=u==null||u==="";return x||y?x===y?0:x?1:-1:(n.comparator?n.comparator(a,u,s.row,f.row):ot(a,u))*o})}}return r},[pe,i,J,A,N]);h.useEffect(()=>q(0),[J,A,N,B]);const F=G.length,O=j?Math.max(1,Math.ceil(F/B)):1,E=Math.min(Re,O-1),$=j?G.slice(E*B,E*B+B):G,Le=F===0?0:j?E*B+1:1,Ve=j?Math.min(F,(E+1)*B):F,_e=e=>e.sortable??m,ve=e=>e.filterable??P,U=(e,t,r)=>({value:t[e.field],formattedValue:ue(e,t),row:t,rowIndex:r,field:e.field,column:e}),se=(e,t)=>{const r=e.editable??k;return typeof r=="function"?r(t):!!r},X=(e,t)=>se(e,t)&&!(e.type==="boolean"&&!e.cellEditor),Ae=(e,t)=>{const r=U(e,t.row,t.index),n=se(e,r);return{...r,editable:n,updateValue:o=>n&&ye(t,e,{value:o})}},je=e=>{if(!_e(e))return;let t;!N||N.field!==e.field?t={field:e.field,direction:"asc"}:N.direction==="asc"?t={field:e.field,direction:"desc"}:t=null,Ke(t),v==null||v(t)},Z=(e,t)=>{var r;return(r=ae.current.get(Se(e,t)))==null?void 0:r.focus()},L=()=>{R.current+=1,W(null)},ee=(e,t,r={})=>{if(!X(t,U(t,e.row,e.index)))return!1;const n=e.row[t.field],o=t.cellEditor?n:r.text??(n==null?"":String(n));return Q.current=o,R.current+=1,W({id:e.id,field:t.field,draft:o,session:R.current,select:r.select??"end",invalid:!1}),!0},ye=(e,t,r)=>{const n=V.current[e.index]??e.row,o=n[t.field];let s;if("value"in r)s=r.value;else if(t.valueParser)s=t.valueParser(r.text,n);else if(t.type==="number")if(r.text.trim()==="")s=null;else{const u=Number(r.text);if(!Number.isFinite(u))return!1;s=u}else s=r.text;if(Object.is(s,o))return!0;if(t.validate&&!t.validate(s,n))return!1;const f={...n,[t.field]:s},a=V.current.map((u,x)=>x===e.index?f:u);return ge(a),b==null||b({rowId:e.id,rowIndex:e.index,field:t.field,oldValue:o,newValue:s,row:f}),p==null||p(a),!0},Ne=(e,t,r)=>{const n=$.findIndex(x=>x.id===e.id),o=i.findIndex(x=>x.field===t);if(n<0||o<0)return null;const s=(x,y)=>X(y,U(y,x.row,x.index));if(r==="down"||r==="up"){const x=r==="down"?1:-1;for(let y=n+x;y>=0&&y<$.length;y+=x)if(s($[y],i[o]))return{entry:$[y],col:i[o]};return null}const f=r==="right"?1:-1;let a=n,u=o+f;for(;a>=0&&a<$.length;){for(;u>=0&&u<i.length;){if(s($[a],i[u]))return{entry:$[a],col:i[u]};u+=f}a+=f,u=f>0?0:i.length-1}return null},Y=(e,t,r,n={})=>{const{move:o="none",focus:s=!0}=n;if(!ye(e,t,r))return W(a=>a&&{...a,invalid:!0}),!1;const f=o==="none"?null:Ne(e,t.field,o);return f?ee(f.entry,f.col,{select:"all"}):(L(),s&&Z(e.id,t.field)),!0},qe=(e,t,r)=>{if(e.nativeEvent.isComposing)return;const n=e.currentTarget.value;if(e.key==="Enter"){e.preventDefault();const o=_?e.shiftKey?"up":"down":"none";Y(t,r,{text:n},{move:o})}else if(e.key==="Escape")e.preventDefault(),L(),Z(t.id,r.field);else if(e.key==="Tab"){const o=e.shiftKey?"left":"right";Ne(t,r.field,o)&&(e.preventDefault(),Y(t,r,{text:n},{move:o}))}},ze=(e,t,r,n)=>{e.target!==e.currentTarget||!X(r,n)||(e.key==="Enter"||e.key==="F2"?(e.preventDefault(),ee(t,r)):!r.cellEditor&&e.key.length===1&&!e.ctrlKey&&!e.metaKey&&!e.altKey&&(e.preventDefault(),ee(t,r,{text:e.key})))},We=(e,t,r)=>t.cellEditor?l.jsx("div",{className:"rk-grid__custom-editor",onBlur:n=>{n.currentTarget.contains(n.relatedTarget)||r.session===R.current&&(Y(e,t,{value:Q.current},{focus:!1})||L())},onKeyDown:n=>{n.key==="Escape"&&(n.preventDefault(),n.stopPropagation(),L(),Z(e.id,t.field))},children:h.createElement(t.cellEditor,{value:r.draft,row:e.row,rowIndex:e.index,field:t.field,column:t,onChange:n=>{Q.current=n,W(o=>o&&o.session===r.session?{...o,draft:n,invalid:!1}:o)},onCommit:(n,o="none")=>{r.session===R.current&&Y(e,t,{value:n===void 0?Q.current:n},{move:o})},onCancel:()=>{L(),Z(e.id,t.field)}})}):l.jsx("input",{autoFocus:!0,className:T("rk-grid__editor",r.invalid&&"rk-grid__editor--invalid",I.editor),style:{textAlign:t.align,...w.editor},value:r.draft===null||r.draft===void 0?"":String(r.draft),inputMode:t.type==="number"?"decimal":void 0,"aria-label":`Edit ${t.headerName??t.field}`,"aria-invalid":r.invalid||void 0,onChange:n=>{const o=n.target.value;W(s=>s&&{...s,draft:o,invalid:!1})},onFocus:n=>{const o=n.currentTarget;r.select==="all"?o.select():o.setSelectionRange(o.value.length,o.value.length)},onBlur:n=>{r.session===R.current&&(Y(e,t,{text:n.currentTarget.value},{focus:!1})||L())},onKeyDown:n=>qe(n,e,t)}),we=e=>{var r,n,o,s,f,a,u,x;const t=e.checkbox??{};return{variant:t.variant??Te,indicator:t.indicator,className:t.className,style:t.style,classNames:{root:T(I.checkbox,(r=t.classNames)==null?void 0:r.root),control:T(I.checkboxControl,(n=t.classNames)==null?void 0:n.control),indicator:T(I.checkboxIndicator,(o=t.classNames)==null?void 0:o.indicator),label:(s=t.classNames)==null?void 0:s.label},styles:{root:{...w.checkbox,...(f=t.styles)==null?void 0:f.root},control:{...w.checkboxControl,...(a=t.styles)==null?void 0:a.control},indicator:{...w.checkboxIndicator,...(u=t.styles)==null?void 0:u.indicator},label:(x=t.styles)==null?void 0:x.label}}},te=e=>e.stopPropagation(),Ge=(e,t)=>l.jsx("span",{className:"rk-grid__checkbox-cell",onClick:te,onDoubleClick:te,children:l.jsx(fe,{...we(e),checked:!!t.value,disabled:!t.editable,"aria-label":`Toggle ${e.headerName??e.field}`,onChange:r=>t.updateValue(r)})}),Ee=e=>G.filter(t=>se(e,U(e,t.row,t.index))),Oe=(e,t)=>{const r=new Map(Ee(e).map(s=>[s.index,s])),n=[],o=V.current.map((s,f)=>{const a=r.get(f);if(!a)return s;const u=s[e.field];if(!!u===t||e.validate&&!e.validate(t,s))return s;const x={...s,[e.field]:t};return n.push({rowId:a.id,rowIndex:f,field:e.field,oldValue:u,newValue:t,row:x}),x});n.length!==0&&(ge(o),n.forEach(s=>b==null?void 0:b(s)),p==null||p(o))},Ye=e=>{const t=Ee(e),r=t.length>0?t:G,n=r.filter(s=>!!s.row[e.field]).length,o=r.length>0&&n===r.length;return l.jsx("span",{className:"rk-grid__header-checkbox",onClick:te,onDoubleClick:te,children:l.jsx(fe,{...we(e),checked:o,indeterminate:n>0&&!o,disabled:t.length===0,label:e.headerName??e.field,onChange:s=>Oe(e,s)})})},He=j&&(S==="top"||S==="both"),Je=!j||S==="bottom"||S==="both",De=e=>l.jsxs("div",{className:T("rk-grid__footer",e==="top"&&"rk-grid__footer--top",I.footer),style:w.footer,"data-position":e,children:[l.jsx("span",{...g("rowCount","rk-grid__count"),children:F===0?"0 rows":`${Le}–${Ve} of ${F}`}),j&&l.jsxs("div",{...g("pagination","rk-grid__pagination"),children:[l.jsxs("label",{className:"rk-grid__page-size-label",children:["Rows per page",l.jsx("select",{value:B,onChange:t=>Fe(Number(t.target.value)),...g("pageSize","rk-grid__page-size"),children:(ne.includes(B)?ne:[...ne,B].sort((t,r)=>t-r)).map(t=>l.jsx("option",{value:t,children:t},t))})]}),l.jsx("button",{type:"button","aria-label":"First page",disabled:E===0,onClick:()=>q(0),...g("pageButton","rk-grid__page-btn"),children:"«"}),l.jsx("button",{type:"button","aria-label":"Previous page",disabled:E===0,onClick:()=>q(E-1),...g("pageButton","rk-grid__page-btn"),children:"‹"}),l.jsxs("span",{...g("pageInfo","rk-grid__page-info"),children:["Page ",E+1," of ",O]}),l.jsx("button",{type:"button","aria-label":"Next page",disabled:E>=O-1,onClick:()=>q(E+1),...g("pageButton","rk-grid__page-btn"),children:"›"}),l.jsx("button",{type:"button","aria-label":"Last page",disabled:E>=O-1,onClick:()=>q(O-1),...g("pageButton","rk-grid__page-btn"),children:"»"})]})]}),Qe=i.some(ve);return l.jsxs("div",{className:T("rk-grid",I.root,$e),style:{...w.root,...Me},children:[(C||he)&&l.jsxs("div",{...g("toolbar","rk-grid__toolbar"),children:[C?l.jsx("input",{type:"search",value:J,onChange:e=>Pe(e.target.value),placeholder:M,"aria-label":"Search all columns",...g("search","rk-grid__search")}):l.jsx("span",{}),he]}),He&&De("top"),l.jsx("div",{...g("scroll","rk-grid__scroll"),style:{...w.scroll,...ke!==void 0?{maxHeight:ke}:null},children:l.jsxs("table",{...g("table","rk-grid__table"),role:"grid",children:[l.jsxs("thead",{...g("thead","rk-grid__thead"),children:[l.jsx("tr",{...g("headerRow","rk-grid__tr"),children:i.map(e=>{const t=(N==null?void 0:N.field)===e.field?N.direction:null,r=_e(e);return l.jsx("th",{scope:"col","aria-sort":t?t==="asc"?"ascending":"descending":r?"none":void 0,tabIndex:r?0:void 0,onClick:()=>je(e),onKeyDown:n=>{r&&n.target===n.currentTarget&&(n.key==="Enter"||n.key===" ")&&(n.preventDefault(),je(e))},className:T("rk-grid__th",r&&"rk-grid__th--sortable",I.headerCell,e.headerClassName),style:{width:e.width,minWidth:e.minWidth,textAlign:e.align,...w.headerCell,...e.headerStyle},children:l.jsxs("span",{className:"rk-grid__th-content",children:[e.headerRenderer?h.createElement(e.headerRenderer,{column:e,sortDirection:t}):e.headerCheckbox&&e.type==="boolean"?Ye(e):e.headerName??e.field,r&&l.jsx("span",{className:"rk-grid__sort","aria-hidden":"true",children:t==="asc"?"▲":t==="desc"?"▼":"↕"})]})},e.field)})}),Qe&&l.jsx("tr",{...g("filterRow","rk-grid__tr"),children:i.map(e=>l.jsx("th",{...g("filterCell","rk-grid__filter-cell"),children:ve(e)&&(e.filterRenderer?h.createElement(e.filterRenderer,{column:e,value:A[e.field]??"",onChange:t=>me(r=>({...r,[e.field]:t}))}):l.jsx("input",{value:A[e.field]??"",onChange:t=>me(r=>({...r,[e.field]:t.target.value})),placeholder:"Filter","aria-label":`Filter ${e.headerName??e.field}`,...g("filterInput","rk-grid__filter-input")}))},e.field))})]}),l.jsx("tbody",{...g("tbody","rk-grid__tbody"),children:$.length===0?l.jsx("tr",{children:l.jsx("td",{colSpan:i.length,...g("empty","rk-grid__empty"),children:Ie})}):$.map((e,t)=>{const{row:r,id:n,index:o}=e,s=typeof ie=="function"?ie(r,o):ie,f=typeof oe=="function"?oe(r,o):oe;return l.jsx("tr",{onClick:le?()=>le(r,o):void 0,className:T("rk-grid__tr","rk-grid__row",Be&&t%2===1&&"rk-grid__row--striped",le&&"rk-grid__row--clickable",I.row,s),style:{...w.row,...f},children:i.map(a=>{const u=Ae(a,e),x=typeof a.cellClassName=="function"?a.cellClassName(u):a.cellClassName,y=typeof a.cellStyle=="function"?a.cellStyle(u):a.cellStyle,de=z!==null&&z.id===n&&z.field===a.field,ce=X(a,u);return l.jsx("td",{ref:re=>{const Ce=Se(n,a.field);re?ae.current.set(Ce,re):ae.current.delete(Ce)},tabIndex:ce?0:void 0,onDoubleClick:ce?()=>ee(e,a):void 0,onKeyDown:re=>ze(re,e,a,u),className:T("rk-grid__td",ce&&"rk-grid__td--editable",de&&"rk-grid__td--editing",I.cell,x),style:{textAlign:a.align,...w.cell,...y},children:de&&z?We(e,a,z):a.cellRenderer?h.createElement(a.cellRenderer,u):a.type==="boolean"&&!a.cellEditor?Ge(a,u):u.formattedValue},a.field)})},n)})})]})}),Je&&De("bottom")]})}exports.Alert=rt;exports.Badge=tt;exports.Button=Xe;exports.Card=et;exports.Checkbox=fe;exports.DataGrid=at;exports.Input=Ze;exports.Modal=nt;
1
+ "use strict";Object.defineProperty(exports,Symbol.toStringTag,{value:"Module"});const l=require("react/jsx-runtime"),f=require("react"),ct=require("react-dom"),oe=(...o)=>o.filter(Boolean).join(" ");function ut(){return l.jsx("svg",{viewBox:"0 0 16 16",width:"100%",height:"100%","aria-hidden":"true",focusable:"false",children:l.jsx("path",{d:"M3.5 8.5l3 3 6-7",fill:"none",stroke:"currentColor",strokeWidth:"2.2",strokeLinecap:"round",strokeLinejoin:"round"})})}function ft(){return l.jsx("svg",{viewBox:"0 0 16 16",width:"100%",height:"100%","aria-hidden":"true",focusable:"false",children:l.jsx("path",{d:"M4 8h8",fill:"none",stroke:"currentColor",strokeWidth:"2.2",strokeLinecap:"round"})})}function je({checked:o,onChange:d,indeterminate:c=!1,variant:g="native",disabled:P=!1,label:x,"aria-label":m,id:A,name:U,indicator:T,className:W,style:w,classNames:k={},styles:E={}}){const B=c?"indeterminate":o?"checked":"unchecked";return l.jsxs("label",{className:oe("rk-checkbox",`rk-checkbox--${g}`,B==="checked"&&"rk-checkbox--checked",c&&"rk-checkbox--indeterminate",P&&"rk-checkbox--disabled",k.root,W),style:{...E.root,...w},"data-state":B,children:[g==="native"?l.jsx("input",{type:"checkbox",id:A,name:U,ref:y=>{y&&(y.indeterminate=c)},className:oe("rk-checkbox__control",k.control),style:E.control,checked:o,disabled:P,"aria-label":m,"data-state":B,onChange:y=>d(y.target.checked)}):l.jsx("button",{type:"button",role:"checkbox",id:A,className:oe("rk-checkbox__control",k.control),style:E.control,"aria-checked":c?"mixed":o,"aria-label":m,disabled:P,"data-state":B,onClick:()=>d(!o),children:l.jsx("span",{className:oe("rk-checkbox__indicator",T!==void 0&&!c&&"rk-checkbox__indicator--custom",k.indicator),style:E.indicator,"data-state":B,"aria-hidden":"true",children:c?g==="tick"?l.jsx(ft,{}):null:T!==void 0?T:g==="tick"?l.jsx(ut,{}):null})}),x!=null&&x!==!1&&x!==""&&l.jsx("span",{className:oe("rk-checkbox__label",k.label),style:E.label,children:x})]})}const ve=(...o)=>o.filter(Boolean).join(" "),ht=typeof window<"u"?f.useLayoutEffect:f.useEffect;function pt({column:o,label:d,value:c,onChange:g,theme:P,indicatorClassName:x,indicatorStyle:m,popupClassName:A,popupStyle:U,inputClassName:T,inputStyle:W}){const[w,k]=f.useState(!1),[E,B]=f.useState({top:0,left:0}),y=f.useRef(null),z=f.useRef(null),O=c.trim()!=="",$=f.useCallback(()=>{var R;const b=y.current;if(!b)return;const F=b.getBoundingClientRect(),K=((R=z.current)==null?void 0:R.offsetWidth)??260,L=Math.max(8,Math.min(F.left,window.innerWidth-K-8));B({top:F.bottom+6,left:L})},[]);ht(()=>{w&&$()},[w,$]),f.useEffect(()=>{if(!w)return;const b=K=>{var R,ie;const L=K.target;(R=z.current)!=null&&R.contains(L)||(ie=y.current)!=null&&ie.contains(L)||k(!1)},F=K=>{var L;K.key==="Escape"&&(k(!1),(L=y.current)==null||L.focus())};return document.addEventListener("mousedown",b),document.addEventListener("keydown",F),window.addEventListener("resize",$),window.addEventListener("scroll",$,!0),()=>{document.removeEventListener("mousedown",b),document.removeEventListener("keydown",F),window.removeEventListener("resize",$),window.removeEventListener("scroll",$,!0)}},[w,$]);const pe=()=>{var b;k(!1),(b=y.current)==null||b.focus()};return l.jsxs(l.Fragment,{children:[l.jsx("button",{ref:y,type:"button",className:ve("rk-grid__filter-btn",O&&"rk-grid__filter-btn--active",w&&"rk-grid__filter-btn--open",x),style:m,"aria-label":`Filter ${d}`,"aria-haspopup":"dialog","aria-expanded":w,"data-active":O||void 0,onClick:b=>{b.stopPropagation(),w||$(),k(F=>!F)},children:o.filterIndicator?f.createElement(o.filterIndicator,{column:o,active:O,open:w}):l.jsx("span",{className:"rk-grid__filter-dot","aria-hidden":"true"})}),w&&typeof document<"u"&&ct.createPortal(l.jsxs("div",{ref:z,role:"dialog","aria-label":`Filter ${d}`,"data-rk-theme":P||void 0,className:ve("rk-grid-popup",A),style:{position:"fixed",top:E.top,left:E.left,...U},children:[o.filterRenderer?f.createElement(o.filterRenderer,{column:o,value:c,onChange:g}):l.jsx("input",{autoFocus:!0,type:"text",className:ve("rk-grid__filter-input",T),style:W,value:c,placeholder:o.filterPlaceholder??`Filter ${d}…`,"aria-label":`Filter text for ${d}`,onChange:b=>g(b.target.value),onKeyDown:b=>{b.key==="Enter"&&pe()}}),O&&l.jsx("button",{type:"button",className:"rk-grid__filter-clear",onClick:()=>g(""),children:"Clear"})]}),document.body)]})}const we=new Set(["__proto__","prototype","constructor"]),We=(o,d)=>Object.prototype.hasOwnProperty.call(o,d);function V(o,d){if(o===null||typeof o!="object")return;if(We(o,d))return o[d];let c=o;for(const g of d.split(".")){if(c==null||typeof c!="object"||we.has(g))return;c=c[g]}return c}function ze(o,d,c){if(Array.isArray(o)){const g=[...o];return g[d]=c,g}return{...o,[d]:c}}function Ee(o,d,c){const g=o??{};if(We(g,d)||!d.includes("."))return we.has(d)?o:ze(g,d,c);const[P,...x]=d.split(".");if(we.has(P))return o;const m=g[P];return ze(g,P,Ee(m!==null&&typeof m=="object"?m:{},x.join("."),c))}const D=(...o)=>o.filter(Boolean).join(" "),Oe=(o,d)=>`${typeof o}:${o}\0${d}`,Se=o=>o.headerName??(o.type==="boolean"?"":o.field),he=o=>Se(o)||o.field;function ye(o,d){const c=V(d,o.field);return o.valueFormatter?o.valueFormatter(c,d):o.type==="boolean"&&typeof c=="boolean"?c?"Yes":"No":c==null?"":c instanceof Date?c.toLocaleDateString():String(c)}function gt(o,d){return typeof o=="number"&&typeof d=="number"?o-d:o instanceof Date&&d instanceof Date?o.getTime()-d.getTime():typeof o=="boolean"&&typeof d=="boolean"?Number(o)-Number(d):String(o).localeCompare(String(d),void 0,{numeric:!0,sensitivity:"base"})}function bt({columns:o,rows:d,getRowId:c,editable:g=!1,enterMovesDown:P=!0,onCellEdit:x,onRowsChange:m,sortable:A=!0,defaultSort:U=null,onSortChange:T,searchable:W=!0,searchPlaceholder:w="Search…",pagination:k=!0,paginationPosition:E="bottom",pageSize:B=10,pageSizeOptions:y=[5,10,25,50],onRowClick:z,toolbar:O,emptyMessage:$="No rows to show",striped:pe=!1,stripeColors:b,checkboxVariant:F="native",animateRows:K=!0,theme:L,maxHeight:R,className:ie,style:qe,classNames:S={},styles:j={},rowClassName:ge,rowStyle:be}){const _=(e,t)=>({className:D(t,S[e]),style:j[e]}),[Ne,Ce]=f.useState(d),Y=f.useRef(d);f.useEffect(()=>{Y.current=d,Ce(d)},[d]);const De=e=>{Y.current=e,Ce(e)},[H,Ge]=f.useState(""),[Q,Je]=f.useState({}),[v,Ue]=f.useState(U),[Ye,X]=f.useState(0),[I,He]=f.useState(B),[Z,ee]=f.useState(null),q=f.useRef(0),le=f.useRef(null),ke=f.useRef(new Map),Pe=f.useMemo(()=>Ne.map((e,t)=>({row:e,index:t,id:c?c(e,t):t})),[Ne,c]),te=f.useMemo(()=>{const e=H.trim().toLowerCase(),t=Object.entries(Q).filter(([n,i])=>i.trim()!==""&&o.some(s=>s.field===n&&s.filterable));let r=Pe.filter(({row:n})=>e&&!o.some(s=>ye(s,n).toLowerCase().includes(e))?!1:t.every(([i,s])=>{const h=o.find(a=>a.field===i);return h?ye(h,n).toLowerCase().includes(s.trim().toLowerCase()):!0}));if(v){const n=o.find(i=>i.field===v.field);if(n){const i=v.direction==="asc"?1:-1;r=[...r].sort((s,h)=>{const a=V(s.row,n.field),u=V(h.row,n.field),p=a==null||a==="",N=u==null||u==="";return p||N?p===N?0:p?1:-1:(n.comparator?n.comparator(a,u,s.row,h.row):gt(a,u))*i})}}return r},[Pe,o,H,Q,v]);f.useEffect(()=>X(0),[H,Q,v,I]);const Ie=f.useRef(null),G=te.length,re=k?Math.max(1,Math.ceil(G/I)):1,C=Math.min(Ye,re-1),M=k?te.slice(C*I,C*I+I):te,Qe=G===0?0:k?C*I+1:1,Xe=k?Math.min(G,(C+1)*I):G,$e=e=>e.sortable??A,Le=`${C}|${I}|${v?`${v.field}:${v.direction}`:""}|${H}|${JSON.stringify(Q)}`,Te=f.useRef(!0);f.useEffect(()=>{if(Te.current){Te.current=!1;return}const e=Ie.current;e&&typeof e.scrollTo=="function"&&e.scrollTop>0&&e.scrollTo({top:0,behavior:"smooth"})},[Le]);const se=(e,t,r)=>({value:V(t,e.field),formattedValue:ye(e,t),row:t,rowIndex:r,field:e.field,column:e}),xe=(e,t)=>{const r=e.editable??g;return typeof r=="function"?r(t):!!r},ae=(e,t)=>xe(e,t)&&!(e.type==="boolean"&&!e.cellEditor),Ze=(e,t)=>{const r=se(e,t.row,t.index),n=xe(e,r);return{...r,editable:n,updateValue:i=>n&&Fe(t,e,{value:i})}},Be=e=>{if(!$e(e))return;let t;!v||v.field!==e.field?t={field:e.field,direction:"asc"}:v.direction==="asc"?t={field:e.field,direction:"desc"}:t=null,Ue(t),T==null||T(t)},de=(e,t)=>{var r;return(r=ke.current.get(Oe(e,t)))==null?void 0:r.focus()},J=()=>{q.current+=1,ee(null)},ce=(e,t,r={})=>{if(!ae(t,se(t,e.row,e.index)))return!1;const n=V(e.row,t.field),i=t.cellEditor?n:r.text??(n==null?"":String(n));return le.current=i,q.current+=1,ee({id:e.id,field:t.field,draft:i,session:q.current,select:r.select??"end",invalid:!1}),!0},Fe=(e,t,r)=>{const n=Y.current[e.index]??e.row,i=V(n,t.field);let s;if("value"in r)s=r.value;else if(t.valueParser)s=t.valueParser(r.text,n);else if(t.type==="number")if(r.text.trim()==="")s=null;else{const u=Number(r.text);if(!Number.isFinite(u))return!1;s=u}else s=r.text;if(Object.is(s,i))return!0;if(t.validate&&!t.validate(s,n))return!1;const h=Ee(n,t.field,s),a=Y.current.map((u,p)=>p===e.index?h:u);return De(a),x==null||x({rowId:e.id,rowIndex:e.index,field:t.field,oldValue:i,newValue:s,row:h}),m==null||m(a),!0},Me=(e,t,r)=>{const n=M.findIndex(p=>p.id===e.id),i=o.findIndex(p=>p.field===t);if(n<0||i<0)return null;const s=(p,N)=>ae(N,se(N,p.row,p.index));if(r==="down"||r==="up"){const p=r==="down"?1:-1;for(let N=n+p;N>=0&&N<M.length;N+=p)if(s(M[N],o[i]))return{entry:M[N],col:o[i]};return null}const h=r==="right"?1:-1;let a=n,u=i+h;for(;a>=0&&a<M.length;){for(;u>=0&&u<o.length;){if(s(M[a],o[u]))return{entry:M[a],col:o[u]};u+=h}a+=h,u=h>0?0:o.length-1}return null},ne=(e,t,r,n={})=>{const{move:i="none",focus:s=!0}=n;if(!Fe(e,t,r))return ee(a=>a&&{...a,invalid:!0}),!1;const h=i==="none"?null:Me(e,t.field,i);return h?ce(h.entry,h.col,{select:"all"}):(J(),s&&de(e.id,t.field)),!0},et=(e,t,r)=>{if(e.nativeEvent.isComposing)return;const n=e.currentTarget.value;if(e.key==="Enter"){e.preventDefault();const i=P?e.shiftKey?"up":"down":"none";ne(t,r,{text:n},{move:i})}else if(e.key==="Escape")e.preventDefault(),J(),de(t.id,r.field);else if(e.key==="Tab"){const i=e.shiftKey?"left":"right";Me(t,r.field,i)&&(e.preventDefault(),ne(t,r,{text:n},{move:i}))}},tt=(e,t,r,n)=>{e.target!==e.currentTarget||!ae(r,n)||(e.key==="Enter"||e.key==="F2"?(e.preventDefault(),ce(t,r)):!r.cellEditor&&e.key.length===1&&!e.ctrlKey&&!e.metaKey&&!e.altKey&&(e.preventDefault(),ce(t,r,{text:e.key})))},rt=(e,t,r)=>t.cellEditor?l.jsx("div",{className:"rk-grid__custom-editor",onBlur:n=>{n.currentTarget.contains(n.relatedTarget)||r.session===q.current&&(ne(e,t,{value:le.current},{focus:!1})||J())},onKeyDown:n=>{n.key==="Escape"&&(n.preventDefault(),n.stopPropagation(),J(),de(e.id,t.field))},children:f.createElement(t.cellEditor,{value:r.draft,row:e.row,rowIndex:e.index,field:t.field,column:t,onChange:n=>{le.current=n,ee(i=>i&&i.session===r.session?{...i,draft:n,invalid:!1}:i)},onCommit:(n,i="none")=>{r.session===q.current&&ne(e,t,{value:n===void 0?le.current:n},{move:i})},onCancel:()=>{J(),de(e.id,t.field)}})}):l.jsx("input",{autoFocus:!0,className:D("rk-grid__editor",r.invalid&&"rk-grid__editor--invalid",S.editor),style:{textAlign:t.align,...j.editor},value:r.draft===null||r.draft===void 0?"":String(r.draft),inputMode:t.type==="number"?"decimal":void 0,"aria-label":`Edit ${he(t)}`,"aria-invalid":r.invalid||void 0,onChange:n=>{const i=n.target.value;ee(s=>s&&{...s,draft:i,invalid:!1})},onFocus:n=>{const i=n.currentTarget;r.select==="all"?i.select():i.setSelectionRange(i.value.length,i.value.length)},onBlur:n=>{r.session===q.current&&(ne(e,t,{text:n.currentTarget.value},{focus:!1})||J())},onKeyDown:n=>et(n,e,t)}),Ke=e=>{var r,n,i,s,h,a,u,p;const t=e.checkbox??{};return{variant:t.variant??F,indicator:t.indicator,className:t.className,style:t.style,classNames:{root:D(S.checkbox,(r=t.classNames)==null?void 0:r.root),control:D(S.checkboxControl,(n=t.classNames)==null?void 0:n.control),indicator:D(S.checkboxIndicator,(i=t.classNames)==null?void 0:i.indicator),label:(s=t.classNames)==null?void 0:s.label},styles:{root:{...j.checkbox,...(h=t.styles)==null?void 0:h.root},control:{...j.checkboxControl,...(a=t.styles)==null?void 0:a.control},indicator:{...j.checkboxIndicator,...(u=t.styles)==null?void 0:u.indicator},label:(p=t.styles)==null?void 0:p.label}}},ue=e=>e.stopPropagation(),nt=(e,t)=>l.jsx("span",{className:"rk-grid__checkbox-cell",onClick:ue,onDoubleClick:ue,children:l.jsx(je,{...Ke(e),checked:!!t.value,disabled:!t.editable,"aria-label":`Toggle ${he(e)}`,onChange:r=>t.updateValue(r)})}),Re=e=>te.filter(t=>xe(e,se(e,t.row,t.index))),ot=(e,t)=>{const r=new Map(Re(e).map(s=>[s.index,s])),n=[],i=Y.current.map((s,h)=>{const a=r.get(h);if(!a)return s;const u=V(s,e.field);if(!!u===t||e.validate&&!e.validate(t,s))return s;const p=Ee(s,e.field,t);return n.push({rowId:a.id,rowIndex:h,field:e.field,oldValue:u,newValue:t,row:p}),p});n.length!==0&&(De(i),n.forEach(s=>x==null?void 0:x(s)),m==null||m(i))},it=e=>{const t=Re(e),r=t.length>0?t:te,n=r.filter(s=>!!V(s.row,e.field)).length,i=r.length>0&&n===r.length;return l.jsx("span",{className:"rk-grid__header-checkbox",onClick:ue,onDoubleClick:ue,children:l.jsx(je,{...Ke(e),checked:i,indeterminate:n>0&&!i,disabled:t.length===0,label:Se(e)||void 0,"aria-label":`Select all ${he(e)}`,onChange:s=>ot(e,s)})})},lt=pe||!!b,st=b?{"--rk-stripe-a":b[0],"--rk-stripe-b":b[1]}:void 0,at=k&&(E==="top"||E==="both"),dt=!k||E==="bottom"||E==="both",Ve=e=>l.jsxs("div",{className:D("rk-grid__footer",e==="top"&&"rk-grid__footer--top",S.footer),style:j.footer,"data-position":e,children:[l.jsx("span",{..._("rowCount","rk-grid__count"),children:G===0?"0 rows":`${Qe}–${Xe} of ${G}`}),k&&l.jsxs("div",{..._("pagination","rk-grid__pagination"),children:[l.jsxs("label",{className:"rk-grid__page-size-label",children:["Rows per page",l.jsx("select",{value:I,onChange:t=>He(Number(t.target.value)),..._("pageSize","rk-grid__page-size"),children:(y.includes(I)?y:[...y,I].sort((t,r)=>t-r)).map(t=>l.jsx("option",{value:t,children:t},t))})]}),l.jsx("button",{type:"button","aria-label":"First page",disabled:C===0,onClick:()=>X(0),..._("pageButton","rk-grid__page-btn"),children:"«"}),l.jsx("button",{type:"button","aria-label":"Previous page",disabled:C===0,onClick:()=>X(C-1),..._("pageButton","rk-grid__page-btn"),children:"‹"}),l.jsxs("span",{..._("pageInfo","rk-grid__page-info"),children:["Page ",C+1," of ",re]}),l.jsx("button",{type:"button","aria-label":"Next page",disabled:C>=re-1,onClick:()=>X(C+1),..._("pageButton","rk-grid__page-btn"),children:"›"}),l.jsx("button",{type:"button","aria-label":"Last page",disabled:C>=re-1,onClick:()=>X(re-1),..._("pageButton","rk-grid__page-btn"),children:"»"})]})]});return l.jsxs("div",{className:D("rk-grid",S.root,ie),style:{...st,...j.root,...qe},"data-rk-theme":L||void 0,children:[(W||O)&&l.jsxs("div",{..._("toolbar","rk-grid__toolbar"),children:[W?l.jsx("input",{type:"search",value:H,onChange:e=>Ge(e.target.value),placeholder:w,"aria-label":"Search all columns",..._("search","rk-grid__search")}):l.jsx("span",{}),O]}),at&&Ve("top"),l.jsx("div",{ref:Ie,..._("scroll","rk-grid__scroll"),style:{...j.scroll,...R!==void 0?{maxHeight:R}:null},children:l.jsxs("table",{..._("table","rk-grid__table"),role:"grid",children:[l.jsx("thead",{..._("thead","rk-grid__thead"),children:l.jsx("tr",{..._("headerRow","rk-grid__tr"),children:o.map(e=>{const t=(v==null?void 0:v.field)===e.field?v.direction:null,r=$e(e);return l.jsx("th",{scope:"col","aria-sort":t?t==="asc"?"ascending":"descending":r?"none":void 0,tabIndex:r?0:void 0,onClick:()=>Be(e),onKeyDown:n=>{r&&n.target===n.currentTarget&&(n.key==="Enter"||n.key===" ")&&(n.preventDefault(),Be(e))},className:D("rk-grid__th",r&&"rk-grid__th--sortable",S.headerCell,e.className,e.headerClassName),style:{width:e.width,minWidth:e.minWidth,textAlign:e.align,...j.headerCell,...e.style,...e.headerStyle},children:l.jsxs("span",{className:"rk-grid__th-content",children:[e.headerRenderer?f.createElement(e.headerRenderer,{column:e,sortDirection:t}):e.headerCheckbox&&e.type==="boolean"?it(e):Se(e),e.filterable&&l.jsx(pt,{column:e,label:he(e),value:Q[e.field]??"",onChange:n=>Je(i=>({...i,[e.field]:n})),theme:L,indicatorClassName:D(S.filterIndicator,e.filterIndicatorClassName),indicatorStyle:{...j.filterIndicator,...e.filterIndicatorStyle},popupClassName:D(S.filterPopup,e.filterPopupClassName),popupStyle:{...j.filterPopup,...e.filterPopupStyle},inputClassName:S.filterInput,inputStyle:j.filterInput}),r&&l.jsx("span",{className:"rk-grid__sort","aria-hidden":"true",children:t==="asc"?"▲":t==="desc"?"▼":"↕"})]})},e.field)})})}),l.jsx("tbody",{..._("tbody","rk-grid__tbody"),children:M.length===0?l.jsx("tr",{children:l.jsx("td",{colSpan:o.length,..._("empty","rk-grid__empty"),children:$})}):M.map((e,t)=>{const{row:r,id:n,index:i}=e,s=typeof ge=="function"?ge(r,i):ge,h=typeof be=="function"?be(r,i):be;return l.jsx("tr",{onClick:z?()=>z(r,i):void 0,className:D("rk-grid__tr","rk-grid__row",lt&&(t%2===0?"rk-grid__row--stripe-a":"rk-grid__row--stripe-b"),K&&"rk-grid__row--enter",z&&"rk-grid__row--clickable",S.row,s),style:{...K?{"--rk-i":Math.min(t,24)}:null,...j.row,...h},children:o.map(a=>{const u=Ze(a,e),p=typeof a.cellClassName=="function"?a.cellClassName(u):a.cellClassName,N=typeof a.cellStyle=="function"?a.cellStyle(u):a.cellStyle,_e=Z!==null&&Z.id===n&&Z.field===a.field,me=ae(a,u);return l.jsx("td",{ref:fe=>{const Ae=Oe(n,a.field);fe?ke.current.set(Ae,fe):ke.current.delete(Ae)},tabIndex:me?0:void 0,onDoubleClick:me?()=>ce(e,a):void 0,onKeyDown:fe=>tt(fe,e,a,u),className:D("rk-grid__td",me&&"rk-grid__td--editable",_e&&"rk-grid__td--editing",S.cell,a.className,p),style:{textAlign:a.align,...j.cell,...a.style,...N},children:_e&&Z?rt(e,a,Z):a.cellRenderer?f.createElement(a.cellRenderer,u):a.type==="boolean"&&!a.cellEditor?nt(a,u):u.formattedValue},a.field)})},n)})},Le)]})}),dt&&Ve("bottom")]})}exports.Checkbox=je;exports.DataGrid=bt;