rockin 0.0.34 → 0.0.36
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/chunk-3CZ2LLUN.js +198 -0
- package/dist/{chunk-7ZCRGTLA.js → chunk-54ZJAEO5.js} +5 -5
- package/dist/chunk-5GM3YR42.js +228 -0
- package/dist/chunk-6XUTSMTJ.js +183 -0
- package/dist/chunk-7JJBATB2.js +35 -0
- package/dist/chunk-BITCJZQZ.js +31 -0
- package/dist/chunk-COPQJFDI.js +158 -0
- package/dist/chunk-D6TULSM6.js +785 -0
- package/dist/chunk-DVNTJNDP.js +55 -0
- package/dist/chunk-EKDBYSMI.js +87 -0
- package/dist/chunk-FGWWRPMR.js +71 -0
- package/dist/chunk-G233W3IR.js +17 -0
- package/dist/chunk-G4NDAZTB.js +13 -0
- package/dist/chunk-GY2BX5SK.js +26 -0
- package/dist/chunk-MZBLIA6C.js +20 -0
- package/dist/chunk-OSVLAX37.js +101 -0
- package/dist/chunk-PRGKTXJU.js +20 -0
- package/dist/chunk-RUKQ532H.js +253 -0
- package/dist/chunk-S4H2HENE.js +113 -0
- package/dist/chunk-UHZTEDHK.js +61 -0
- package/dist/chunk-VFDNWPOI.js +293 -0
- package/dist/chunk-W4EIJWHF.js +150 -0
- package/dist/hooks/index.js +18 -9
- package/dist/index.js +4 -4
- package/dist/provider.js +3 -3
- package/dist/styles.css +2 -2
- package/dist/ui/accordion.js +95 -0
- package/dist/ui/alert-dialog.js +178 -0
- package/dist/ui/apple/english.js +7 -0
- package/dist/ui/apple/hindi.js +7 -0
- package/dist/ui/apple/index.js +52 -0
- package/dist/ui/apple/spanish.js +7 -0
- package/dist/ui/ariakit.js +7 -0
- package/dist/ui/autocomplete.js +296 -0
- package/dist/ui/avatar.js +106 -0
- package/dist/ui/badge.js +50 -0
- package/dist/ui/bridge.js +109 -0
- package/dist/ui/bubble.js +118 -0
- package/dist/ui/button-group.js +14 -0
- package/dist/ui/button.js +9 -0
- package/dist/ui/card.js +102 -0
- package/dist/ui/carousel.js +205 -0
- package/dist/ui/chart.js +253 -0
- package/dist/ui/checkbox.js +34 -0
- package/dist/ui/code-block.js +128 -0
- package/dist/ui/combobox.js +41 -0
- package/dist/ui/command.js +199 -0
- package/dist/ui/dashed.js +57 -0
- package/dist/ui/data-table/index.js +233 -0
- package/dist/ui/dialog.js +26 -0
- package/dist/ui/dock.js +86 -0
- package/dist/ui/drawer.js +216 -0
- package/dist/ui/dropdown-menu.js +35 -0
- package/dist/ui/empty.js +17 -0
- package/dist/ui/farmer/div.js +38 -0
- package/dist/ui/farmer/variants.js +314 -0
- package/dist/ui/field.js +224 -0
- package/dist/ui/filters.js +1524 -0
- package/dist/ui/image.js +88 -0
- package/dist/ui/index.d.ts +1 -1
- package/dist/ui/index.js +57 -8502
- package/dist/ui/input-group.js +20 -0
- package/dist/ui/input-otp.js +83 -0
- package/dist/ui/input.js +7 -0
- package/dist/ui/item.js +200 -0
- package/dist/ui/jelly.js +30 -0
- package/dist/ui/kbd.js +9 -0
- package/dist/ui/label.js +7 -0
- package/dist/ui/message-scroller.js +122 -0
- package/dist/ui/message.js +93 -0
- package/dist/ui/numberstepper.js +416 -0
- package/dist/ui/otp.js +403 -0
- package/dist/ui/popover.js +83 -0
- package/dist/ui/qr-code.js +124 -0
- package/dist/ui/quantity.js +48 -0
- package/dist/ui/radio-group.js +42 -0
- package/dist/ui/resizable.js +52 -0
- package/dist/ui/scroll-area.js +9 -0
- package/dist/ui/select.js +194 -0
- package/dist/ui/separator.js +7 -0
- package/dist/ui/skeleton.js +25 -0
- package/dist/ui/sonner.js +22 -0
- package/dist/ui/sortable.js +503 -0
- package/dist/ui/swipe-actions.js +45 -0
- package/dist/ui/switch.js +34 -0
- package/dist/ui/textarea.js +7 -0
- package/dist/ui/theme-toggle.js +141 -0
- package/dist/ui/tooltip.js +13 -0
- package/package.json +1 -1
- package/dist/chunk-4KFB6AJH.js +0 -1330
- /package/dist/{chunk-FYFBWCMJ.js → chunk-GBVAFFZR.js} +0 -0
|
@@ -0,0 +1,785 @@
|
|
|
1
|
+
import {
|
|
2
|
+
Combobox,
|
|
3
|
+
ComboboxContent,
|
|
4
|
+
ComboboxEmpty,
|
|
5
|
+
ComboboxInput,
|
|
6
|
+
ComboboxItem,
|
|
7
|
+
ComboboxList
|
|
8
|
+
} from "./chunk-VFDNWPOI.js";
|
|
9
|
+
import {
|
|
10
|
+
Input
|
|
11
|
+
} from "./chunk-7JJBATB2.js";
|
|
12
|
+
|
|
13
|
+
// src/ui/data-table/core/data-table-root.tsx
|
|
14
|
+
import * as React from "react";
|
|
15
|
+
import { cn } from "cn";
|
|
16
|
+
import { jsx } from "react/jsx-runtime";
|
|
17
|
+
var DataTableContext = React.createContext(
|
|
18
|
+
null
|
|
19
|
+
);
|
|
20
|
+
function useDataTable() {
|
|
21
|
+
const context = React.useContext(DataTableContext);
|
|
22
|
+
if (!context) {
|
|
23
|
+
throw new Error(
|
|
24
|
+
"DataTable components must be rendered inside DataTableRoot"
|
|
25
|
+
);
|
|
26
|
+
}
|
|
27
|
+
return context;
|
|
28
|
+
}
|
|
29
|
+
function DataTableRoot({
|
|
30
|
+
data,
|
|
31
|
+
columns,
|
|
32
|
+
children,
|
|
33
|
+
isLoading = false,
|
|
34
|
+
pageSize = 10,
|
|
35
|
+
getRowId = (_, index) => String(index),
|
|
36
|
+
className
|
|
37
|
+
}) {
|
|
38
|
+
const [globalFilter, setGlobalFilterState] = React.useState("");
|
|
39
|
+
const [pageIndex, setPageIndexState] = React.useState(0);
|
|
40
|
+
const filteredData = React.useMemo(() => {
|
|
41
|
+
const query = globalFilter.trim().toLowerCase();
|
|
42
|
+
if (!query) return data;
|
|
43
|
+
return data.filter(
|
|
44
|
+
(row) => columns.some((column) => {
|
|
45
|
+
if (column.enableSearch === false) return false;
|
|
46
|
+
const value = column.accessorFn ? column.accessorFn(row) : column.accessorKey ? row[column.accessorKey] : void 0;
|
|
47
|
+
return String(value ?? "").toLowerCase().includes(query);
|
|
48
|
+
})
|
|
49
|
+
);
|
|
50
|
+
}, [columns, data, globalFilter]);
|
|
51
|
+
const safePageSize = Math.max(1, pageSize);
|
|
52
|
+
const pageCount = Math.max(1, Math.ceil(filteredData.length / safePageSize));
|
|
53
|
+
const safePageIndex = Math.min(pageIndex, pageCount - 1);
|
|
54
|
+
const pageData = filteredData.slice(
|
|
55
|
+
safePageIndex * safePageSize,
|
|
56
|
+
(safePageIndex + 1) * safePageSize
|
|
57
|
+
);
|
|
58
|
+
React.useEffect(() => {
|
|
59
|
+
setPageIndexState((current) => Math.min(current, pageCount - 1));
|
|
60
|
+
}, [pageCount]);
|
|
61
|
+
const contextValue = React.useMemo(
|
|
62
|
+
() => ({
|
|
63
|
+
data,
|
|
64
|
+
columns,
|
|
65
|
+
filteredData,
|
|
66
|
+
pageData,
|
|
67
|
+
pageIndex: safePageIndex,
|
|
68
|
+
pageSize: safePageSize,
|
|
69
|
+
pageCount,
|
|
70
|
+
globalFilter,
|
|
71
|
+
isLoading,
|
|
72
|
+
getRowId,
|
|
73
|
+
setGlobalFilter: (value) => {
|
|
74
|
+
setGlobalFilterState(value);
|
|
75
|
+
setPageIndexState(0);
|
|
76
|
+
},
|
|
77
|
+
setPageIndex: (value) => setPageIndexState(Math.max(0, Math.min(value, pageCount - 1)))
|
|
78
|
+
}),
|
|
79
|
+
[
|
|
80
|
+
columns,
|
|
81
|
+
filteredData,
|
|
82
|
+
pageCount,
|
|
83
|
+
pageData,
|
|
84
|
+
safePageIndex,
|
|
85
|
+
safePageSize,
|
|
86
|
+
globalFilter,
|
|
87
|
+
isLoading,
|
|
88
|
+
getRowId
|
|
89
|
+
]
|
|
90
|
+
);
|
|
91
|
+
return /* @__PURE__ */ jsx(DataTableContext.Provider, { value: contextValue, children: /* @__PURE__ */ jsx("div", { className: cn("w-full space-y-3", className), children }) });
|
|
92
|
+
}
|
|
93
|
+
|
|
94
|
+
// src/ui/data-table/hooks/use-data-table-pagination.ts
|
|
95
|
+
function useDataTablePagination() {
|
|
96
|
+
const { pageIndex, pageSize, pageCount, setPageIndex } = useDataTable();
|
|
97
|
+
return {
|
|
98
|
+
pageIndex,
|
|
99
|
+
pageSize,
|
|
100
|
+
pageCount,
|
|
101
|
+
canPreviousPage: pageIndex > 0,
|
|
102
|
+
canNextPage: pageIndex < pageCount - 1,
|
|
103
|
+
goToPage: setPageIndex,
|
|
104
|
+
previousPage: () => setPageIndex(pageIndex - 1),
|
|
105
|
+
nextPage: () => setPageIndex(pageIndex + 1),
|
|
106
|
+
firstPage: () => setPageIndex(0),
|
|
107
|
+
lastPage: () => setPageIndex(pageCount - 1)
|
|
108
|
+
};
|
|
109
|
+
}
|
|
110
|
+
|
|
111
|
+
// src/ui/data-table/hooks/use-data-table-rows.ts
|
|
112
|
+
function useDataTableRows() {
|
|
113
|
+
const { data, filteredData, pageData, isLoading } = useDataTable();
|
|
114
|
+
return {
|
|
115
|
+
data,
|
|
116
|
+
rows: pageData,
|
|
117
|
+
pageRows: pageData,
|
|
118
|
+
filteredRows: filteredData,
|
|
119
|
+
totalRows: filteredData.length,
|
|
120
|
+
isLoading
|
|
121
|
+
};
|
|
122
|
+
}
|
|
123
|
+
|
|
124
|
+
// src/ui/data-table/hooks/use-data-table-search.ts
|
|
125
|
+
function useDataTableSearch() {
|
|
126
|
+
const { globalFilter, setGlobalFilter } = useDataTable();
|
|
127
|
+
return {
|
|
128
|
+
search: globalFilter,
|
|
129
|
+
setSearch: setGlobalFilter,
|
|
130
|
+
clearSearch: () => setGlobalFilter("")
|
|
131
|
+
};
|
|
132
|
+
}
|
|
133
|
+
|
|
134
|
+
// src/ui/data-table/data-grid.tsx
|
|
135
|
+
import * as React2 from "react";
|
|
136
|
+
import { cn as cn2 } from "cn";
|
|
137
|
+
import { Fragment, jsx as jsx2, jsxs } from "react/jsx-runtime";
|
|
138
|
+
function useDataGrid({
|
|
139
|
+
columnIds = [],
|
|
140
|
+
columns,
|
|
141
|
+
initialRows = [],
|
|
142
|
+
getRowId = (row, index) => String(row.id ?? index),
|
|
143
|
+
maxRows = 200
|
|
144
|
+
} = {}) {
|
|
145
|
+
const [rows, setRows] = React2.useState(initialRows);
|
|
146
|
+
const resolvedColumns = React2.useMemo(
|
|
147
|
+
() => columns ?? columnIds.map((id) => ({
|
|
148
|
+
id,
|
|
149
|
+
accessorKey: id,
|
|
150
|
+
header: id
|
|
151
|
+
})),
|
|
152
|
+
[columnIds, columns]
|
|
153
|
+
);
|
|
154
|
+
const getRow = React2.useCallback(
|
|
155
|
+
(rowId) => rows.find((row, index) => getRowId(row, index) === rowId),
|
|
156
|
+
[getRowId, rows]
|
|
157
|
+
);
|
|
158
|
+
const getCellValue = React2.useCallback(
|
|
159
|
+
(rowId, columnId) => {
|
|
160
|
+
const row = getRow(rowId);
|
|
161
|
+
return row?.[columnId];
|
|
162
|
+
},
|
|
163
|
+
[getRow]
|
|
164
|
+
);
|
|
165
|
+
const updateCell = React2.useCallback(
|
|
166
|
+
(rowId, columnId, value) => {
|
|
167
|
+
setRows(
|
|
168
|
+
(current) => current.map(
|
|
169
|
+
(row, index) => getRowId(row, index) === rowId ? { ...row, [columnId]: value } : row
|
|
170
|
+
)
|
|
171
|
+
);
|
|
172
|
+
},
|
|
173
|
+
[getRowId]
|
|
174
|
+
);
|
|
175
|
+
const updateRows = React2.useCallback(
|
|
176
|
+
(updater) => setRows((current) => updater(current).slice(0, maxRows)),
|
|
177
|
+
[maxRows]
|
|
178
|
+
);
|
|
179
|
+
const insertRows = React2.useCallback(
|
|
180
|
+
(nextRows, index = rows.length) => {
|
|
181
|
+
setRows((current) => {
|
|
182
|
+
const safeIndex = Math.max(0, Math.min(index, current.length));
|
|
183
|
+
return [
|
|
184
|
+
...current.slice(0, safeIndex),
|
|
185
|
+
...nextRows,
|
|
186
|
+
...current.slice(safeIndex)
|
|
187
|
+
].slice(0, maxRows);
|
|
188
|
+
});
|
|
189
|
+
},
|
|
190
|
+
[maxRows, rows.length]
|
|
191
|
+
);
|
|
192
|
+
const deleteRows = React2.useCallback(
|
|
193
|
+
(rowIds) => {
|
|
194
|
+
const ids = new Set(rowIds);
|
|
195
|
+
setRows(
|
|
196
|
+
(current) => current.filter((row, index) => !ids.has(getRowId(row, index)))
|
|
197
|
+
);
|
|
198
|
+
},
|
|
199
|
+
[getRowId]
|
|
200
|
+
);
|
|
201
|
+
const moveRow = React2.useCallback(
|
|
202
|
+
(rowId, toIndex) => {
|
|
203
|
+
setRows((current) => {
|
|
204
|
+
const fromIndex = current.findIndex(
|
|
205
|
+
(row2, index) => getRowId(row2, index) === rowId
|
|
206
|
+
);
|
|
207
|
+
if (fromIndex < 0) return current;
|
|
208
|
+
const next = [...current];
|
|
209
|
+
const [row] = next.splice(fromIndex, 1);
|
|
210
|
+
next.splice(Math.max(0, Math.min(toIndex, next.length)), 0, row);
|
|
211
|
+
return next;
|
|
212
|
+
});
|
|
213
|
+
},
|
|
214
|
+
[getRowId]
|
|
215
|
+
);
|
|
216
|
+
return React2.useMemo(
|
|
217
|
+
() => ({
|
|
218
|
+
rows,
|
|
219
|
+
columns: resolvedColumns,
|
|
220
|
+
getRowId,
|
|
221
|
+
getRow,
|
|
222
|
+
getCellValue,
|
|
223
|
+
updateCell,
|
|
224
|
+
updateRows,
|
|
225
|
+
insertRows,
|
|
226
|
+
deleteRows,
|
|
227
|
+
moveRow
|
|
228
|
+
}),
|
|
229
|
+
[
|
|
230
|
+
getCellValue,
|
|
231
|
+
getRow,
|
|
232
|
+
getRowId,
|
|
233
|
+
resolvedColumns,
|
|
234
|
+
rows,
|
|
235
|
+
updateCell,
|
|
236
|
+
updateRows,
|
|
237
|
+
insertRows,
|
|
238
|
+
deleteRows,
|
|
239
|
+
moveRow,
|
|
240
|
+
maxRows
|
|
241
|
+
]
|
|
242
|
+
);
|
|
243
|
+
}
|
|
244
|
+
var DataGridContext = React2.createContext(null);
|
|
245
|
+
function useDataGridContext() {
|
|
246
|
+
const context = React2.useContext(DataGridContext);
|
|
247
|
+
if (!context) throw new Error("DataGrid components must be inside DataGrid");
|
|
248
|
+
return context;
|
|
249
|
+
}
|
|
250
|
+
var DataGridCellContext = React2.createContext(null);
|
|
251
|
+
function DataGrid({
|
|
252
|
+
grid,
|
|
253
|
+
children,
|
|
254
|
+
className
|
|
255
|
+
}) {
|
|
256
|
+
const rootRef = React2.useRef(null);
|
|
257
|
+
const [activeCell, setActiveCell] = React2.useState(null);
|
|
258
|
+
const [selection, setSelection] = React2.useState(null);
|
|
259
|
+
const contextValue = React2.useMemo(
|
|
260
|
+
() => ({
|
|
261
|
+
...grid,
|
|
262
|
+
activeCell,
|
|
263
|
+
selection,
|
|
264
|
+
setActiveCell,
|
|
265
|
+
setSelection,
|
|
266
|
+
rootRef
|
|
267
|
+
}),
|
|
268
|
+
[activeCell, grid, selection]
|
|
269
|
+
);
|
|
270
|
+
function selectedCoordinates() {
|
|
271
|
+
if (!selection) return null;
|
|
272
|
+
const rowIndexes = [
|
|
273
|
+
grid.rows.findIndex((row, index) => grid.getRowId(row, index) === selection.anchor.rowId),
|
|
274
|
+
grid.rows.findIndex((row, index) => grid.getRowId(row, index) === selection.focus.rowId)
|
|
275
|
+
].sort((a, b) => a - b);
|
|
276
|
+
const columnIndexes = [
|
|
277
|
+
grid.columns.findIndex((column) => column.id === selection.anchor.columnId),
|
|
278
|
+
grid.columns.findIndex((column) => column.id === selection.focus.columnId)
|
|
279
|
+
].sort((a, b) => a - b);
|
|
280
|
+
if (rowIndexes.some((index) => index < 0) || columnIndexes.some((index) => index < 0)) return null;
|
|
281
|
+
return { rowIndexes, columnIndexes };
|
|
282
|
+
}
|
|
283
|
+
function focusCell(rowIndex, columnIndex) {
|
|
284
|
+
const row = grid.rows[rowIndex];
|
|
285
|
+
const column = grid.columns[columnIndex];
|
|
286
|
+
if (!row || !column) return;
|
|
287
|
+
const rowId = grid.getRowId(row, rowIndex);
|
|
288
|
+
const cell = rootRef.current?.querySelector(
|
|
289
|
+
`[data-grid-row-id="${CSS.escape(rowId)}"] [data-grid-column-id="${CSS.escape(column.id)}"]`
|
|
290
|
+
);
|
|
291
|
+
cell?.focus();
|
|
292
|
+
}
|
|
293
|
+
function handleCopy(event) {
|
|
294
|
+
const coordinates = selectedCoordinates();
|
|
295
|
+
if (!coordinates) return;
|
|
296
|
+
const value = coordinates.rowIndexes.map(
|
|
297
|
+
(rowIndex) => coordinates.columnIndexes.map(
|
|
298
|
+
(columnIndex) => String(grid.getCellValue(grid.getRowId(grid.rows[rowIndex], rowIndex), grid.columns[columnIndex].id) ?? "")
|
|
299
|
+
).join(" ")
|
|
300
|
+
).join("\n");
|
|
301
|
+
event.preventDefault();
|
|
302
|
+
event.clipboardData.setData("text/plain", value);
|
|
303
|
+
}
|
|
304
|
+
function handlePaste(event) {
|
|
305
|
+
if (!activeCell) return;
|
|
306
|
+
const startRow = grid.rows.findIndex(
|
|
307
|
+
(row, index) => grid.getRowId(row, index) === activeCell.rowId
|
|
308
|
+
);
|
|
309
|
+
const startColumn = grid.columns.findIndex(
|
|
310
|
+
(column) => column.id === activeCell.columnId
|
|
311
|
+
);
|
|
312
|
+
if (startRow < 0 || startColumn < 0) return;
|
|
313
|
+
const matrix = event.clipboardData.getData("text/plain").split(/\r?\n/).map((row) => row.split(" "));
|
|
314
|
+
event.preventDefault();
|
|
315
|
+
grid.updateRows(
|
|
316
|
+
(rows) => rows.map((row, rowIndex) => {
|
|
317
|
+
const values = matrix[rowIndex - startRow];
|
|
318
|
+
if (!values) return row;
|
|
319
|
+
const next = { ...row };
|
|
320
|
+
values.forEach((value, columnOffset) => {
|
|
321
|
+
const column = grid.columns[startColumn + columnOffset];
|
|
322
|
+
if (column) Object.assign(next, { [column.id]: value });
|
|
323
|
+
});
|
|
324
|
+
return next;
|
|
325
|
+
})
|
|
326
|
+
);
|
|
327
|
+
}
|
|
328
|
+
const childArray = React2.Children.toArray(children);
|
|
329
|
+
const headerRows = childArray.filter(
|
|
330
|
+
(child) => React2.isValidElement(child) && Boolean(child.props.header)
|
|
331
|
+
);
|
|
332
|
+
const bodyRows = childArray.filter(
|
|
333
|
+
(child) => !React2.isValidElement(child) || !child.props.header
|
|
334
|
+
);
|
|
335
|
+
return /* @__PURE__ */ jsx2(DataGridContext.Provider, { value: contextValue, children: /* @__PURE__ */ jsx2(
|
|
336
|
+
"div",
|
|
337
|
+
{
|
|
338
|
+
ref: rootRef,
|
|
339
|
+
className: cn2("w-full space-y-2 outline-none", className),
|
|
340
|
+
onCopy: handleCopy,
|
|
341
|
+
onPaste: handlePaste,
|
|
342
|
+
children: /* @__PURE__ */ jsxs("table", { className: "w-full border-collapse text-sm", children: [
|
|
343
|
+
headerRows.length > 0 && /* @__PURE__ */ jsx2("thead", { children: headerRows }),
|
|
344
|
+
/* @__PURE__ */ jsx2("tbody", { children: bodyRows })
|
|
345
|
+
] })
|
|
346
|
+
}
|
|
347
|
+
) });
|
|
348
|
+
}
|
|
349
|
+
function DataGridRow({
|
|
350
|
+
row,
|
|
351
|
+
rowId,
|
|
352
|
+
children,
|
|
353
|
+
header = false,
|
|
354
|
+
className
|
|
355
|
+
}) {
|
|
356
|
+
const grid = useDataGridContext();
|
|
357
|
+
const resolvedRowId = rowId ?? (row ? grid.getRowId(row, 0) : "");
|
|
358
|
+
const resolvedRow = row ?? grid.getRow(resolvedRowId);
|
|
359
|
+
return /* @__PURE__ */ jsx2(
|
|
360
|
+
"tr",
|
|
361
|
+
{
|
|
362
|
+
"data-grid-row-id": resolvedRowId,
|
|
363
|
+
"data-grid-header": header || void 0,
|
|
364
|
+
className: cn2("border-b last:border-0", className),
|
|
365
|
+
children: resolvedRow && children
|
|
366
|
+
}
|
|
367
|
+
);
|
|
368
|
+
}
|
|
369
|
+
function DataGridColumn({
|
|
370
|
+
column,
|
|
371
|
+
children,
|
|
372
|
+
className
|
|
373
|
+
}) {
|
|
374
|
+
return /* @__PURE__ */ jsx2("th", { className: cn2("min-w-0 px-3 py-2 text-left", className), children: children ?? column.header });
|
|
375
|
+
}
|
|
376
|
+
function DataGridCell({
|
|
377
|
+
row,
|
|
378
|
+
rowId,
|
|
379
|
+
columnId,
|
|
380
|
+
children,
|
|
381
|
+
state = "valid",
|
|
382
|
+
className
|
|
383
|
+
}) {
|
|
384
|
+
const grid = useDataGridContext();
|
|
385
|
+
const resolvedRowId = rowId ?? (row ? grid.getRowId(row, 0) : "");
|
|
386
|
+
const value = grid.getCellValue(resolvedRowId, columnId);
|
|
387
|
+
const rowIndex = grid.rows.findIndex(
|
|
388
|
+
(currentRow, index) => grid.getRowId(currentRow, index) === resolvedRowId
|
|
389
|
+
);
|
|
390
|
+
const columnIndex = grid.columns.findIndex((column) => column.id === columnId);
|
|
391
|
+
const isActive = grid.activeCell?.rowId === resolvedRowId && grid.activeCell.columnId === columnId;
|
|
392
|
+
const isSelected = (() => {
|
|
393
|
+
if (!grid.selection) return false;
|
|
394
|
+
const anchorRow = grid.rows.findIndex(
|
|
395
|
+
(currentRow, index) => grid.getRowId(currentRow, index) === grid.selection?.anchor.rowId
|
|
396
|
+
);
|
|
397
|
+
const focusRow = grid.rows.findIndex(
|
|
398
|
+
(currentRow, index) => grid.getRowId(currentRow, index) === grid.selection?.focus.rowId
|
|
399
|
+
);
|
|
400
|
+
const anchorColumn = grid.columns.findIndex(
|
|
401
|
+
(column) => column.id === grid.selection?.anchor.columnId
|
|
402
|
+
);
|
|
403
|
+
const focusColumn = grid.columns.findIndex(
|
|
404
|
+
(column) => column.id === grid.selection?.focus.columnId
|
|
405
|
+
);
|
|
406
|
+
return rowIndex >= Math.min(anchorRow, focusRow) && rowIndex <= Math.max(anchorRow, focusRow) && columnIndex >= Math.min(anchorColumn, focusColumn) && columnIndex <= Math.max(anchorColumn, focusColumn);
|
|
407
|
+
})();
|
|
408
|
+
function focusCell(nextRowIndex, nextColumnIndex) {
|
|
409
|
+
const nextRow = grid.rows[nextRowIndex];
|
|
410
|
+
const nextColumn = grid.columns[nextColumnIndex];
|
|
411
|
+
if (!nextRow || !nextColumn) return;
|
|
412
|
+
const nextRowId = grid.getRowId(nextRow, nextRowIndex);
|
|
413
|
+
grid.setActiveCell({ rowId: nextRowId, columnId: nextColumn.id });
|
|
414
|
+
const nextPosition = { rowId: nextRowId, columnId: nextColumn.id };
|
|
415
|
+
if (grid.activeCell && grid.selection?.anchor && pendingShift.current) {
|
|
416
|
+
grid.setSelection({ anchor: grid.selection.anchor, focus: nextPosition });
|
|
417
|
+
} else {
|
|
418
|
+
grid.setSelection({ anchor: nextPosition, focus: nextPosition });
|
|
419
|
+
}
|
|
420
|
+
const target = grid.rootRef.current?.querySelector(
|
|
421
|
+
`[data-grid-row-id="${CSS.escape(nextRowId)}"] [data-grid-column-id="${CSS.escape(nextColumn.id)}"]`
|
|
422
|
+
);
|
|
423
|
+
target?.focus();
|
|
424
|
+
}
|
|
425
|
+
const pendingShift = React2.useRef(false);
|
|
426
|
+
function fillSelection() {
|
|
427
|
+
if (!grid.selection) return;
|
|
428
|
+
const anchorRow = grid.rows.findIndex(
|
|
429
|
+
(currentRow, index) => grid.getRowId(currentRow, index) === grid.selection?.anchor.rowId
|
|
430
|
+
);
|
|
431
|
+
const focusRow = grid.rows.findIndex(
|
|
432
|
+
(currentRow, index) => grid.getRowId(currentRow, index) === grid.selection?.focus.rowId
|
|
433
|
+
);
|
|
434
|
+
const anchorColumn = grid.columns.findIndex(
|
|
435
|
+
(column) => column.id === grid.selection?.anchor.columnId
|
|
436
|
+
);
|
|
437
|
+
const focusColumn = grid.columns.findIndex(
|
|
438
|
+
(column) => column.id === grid.selection?.focus.columnId
|
|
439
|
+
);
|
|
440
|
+
if (anchorRow < 0 || focusRow < 0 || anchorColumn < 0 || focusColumn < 0) return;
|
|
441
|
+
const source = grid.getCellValue(
|
|
442
|
+
grid.getRowId(grid.rows[anchorRow], anchorRow),
|
|
443
|
+
grid.columns[anchorColumn].id
|
|
444
|
+
);
|
|
445
|
+
const minRow = Math.min(anchorRow, focusRow);
|
|
446
|
+
const maxRow = Math.max(anchorRow, focusRow);
|
|
447
|
+
const minColumn = Math.min(anchorColumn, focusColumn);
|
|
448
|
+
const maxColumn = Math.max(anchorColumn, focusColumn);
|
|
449
|
+
grid.updateRows(
|
|
450
|
+
(rows) => rows.map((row2, rowIndex2) => {
|
|
451
|
+
if (rowIndex2 < minRow || rowIndex2 > maxRow) return row2;
|
|
452
|
+
const next = { ...row2 };
|
|
453
|
+
for (let columnIndex2 = minColumn; columnIndex2 <= maxColumn; columnIndex2 += 1) {
|
|
454
|
+
Object.assign(next, { [grid.columns[columnIndex2].id]: source });
|
|
455
|
+
}
|
|
456
|
+
return next;
|
|
457
|
+
})
|
|
458
|
+
);
|
|
459
|
+
}
|
|
460
|
+
function onKeyDown(event) {
|
|
461
|
+
const target = event.target;
|
|
462
|
+
const isEditor = target.tagName === "INPUT" || target.tagName === "TEXTAREA";
|
|
463
|
+
if (isEditor && ["ArrowLeft", "ArrowRight"].includes(event.key)) return;
|
|
464
|
+
if (event.altKey && (event.key === "ArrowUp" || event.key === "ArrowDown")) {
|
|
465
|
+
event.preventDefault();
|
|
466
|
+
grid.moveRow(resolvedRowId, rowIndex + (event.key === "ArrowUp" ? -1 : 1));
|
|
467
|
+
return;
|
|
468
|
+
}
|
|
469
|
+
let nextRowIndex = rowIndex;
|
|
470
|
+
let nextColumnIndex = columnIndex;
|
|
471
|
+
if (event.key === "ArrowUp") nextRowIndex -= 1;
|
|
472
|
+
if (event.key === "ArrowDown" || event.key === "Enter") nextRowIndex += 1;
|
|
473
|
+
if (event.key === "ArrowLeft") nextColumnIndex -= 1;
|
|
474
|
+
if (event.key === "ArrowRight" || event.key === "Tab") nextColumnIndex += event.shiftKey ? -1 : 1;
|
|
475
|
+
if (event.key === "Home") nextColumnIndex = 0;
|
|
476
|
+
if (event.key === "End") nextColumnIndex = grid.columns.length - 1;
|
|
477
|
+
if (event.key === "PageUp") nextRowIndex = 0;
|
|
478
|
+
if (event.key === "PageDown") nextRowIndex = grid.rows.length - 1;
|
|
479
|
+
if (nextRowIndex === rowIndex && nextColumnIndex === columnIndex) return;
|
|
480
|
+
event.preventDefault();
|
|
481
|
+
pendingShift.current = event.shiftKey;
|
|
482
|
+
focusCell(nextRowIndex, nextColumnIndex);
|
|
483
|
+
pendingShift.current = false;
|
|
484
|
+
}
|
|
485
|
+
const selectionBounds = grid.selection ? {
|
|
486
|
+
minRow: Math.min(
|
|
487
|
+
grid.rows.findIndex((row2, index) => grid.getRowId(row2, index) === grid.selection?.anchor.rowId),
|
|
488
|
+
grid.rows.findIndex((row2, index) => grid.getRowId(row2, index) === grid.selection?.focus.rowId)
|
|
489
|
+
),
|
|
490
|
+
maxRow: Math.max(
|
|
491
|
+
grid.rows.findIndex((row2, index) => grid.getRowId(row2, index) === grid.selection?.anchor.rowId),
|
|
492
|
+
grid.rows.findIndex((row2, index) => grid.getRowId(row2, index) === grid.selection?.focus.rowId)
|
|
493
|
+
),
|
|
494
|
+
minColumn: Math.min(
|
|
495
|
+
grid.columns.findIndex((column) => column.id === grid.selection?.anchor.columnId),
|
|
496
|
+
grid.columns.findIndex((column) => column.id === grid.selection?.focus.columnId)
|
|
497
|
+
),
|
|
498
|
+
maxColumn: Math.max(
|
|
499
|
+
grid.columns.findIndex((column) => column.id === grid.selection?.anchor.columnId),
|
|
500
|
+
grid.columns.findIndex((column) => column.id === grid.selection?.focus.columnId)
|
|
501
|
+
)
|
|
502
|
+
} : null;
|
|
503
|
+
const showFillHandle = selectionBounds && (selectionBounds.minRow !== selectionBounds.maxRow || selectionBounds.minColumn !== selectionBounds.maxColumn) && rowIndex === selectionBounds.maxRow && columnIndex === selectionBounds.maxColumn;
|
|
504
|
+
return /* @__PURE__ */ jsx2(
|
|
505
|
+
DataGridCellContext.Provider,
|
|
506
|
+
{
|
|
507
|
+
value: { rowId: resolvedRowId, columnId, value },
|
|
508
|
+
children: /* @__PURE__ */ jsxs(
|
|
509
|
+
"td",
|
|
510
|
+
{
|
|
511
|
+
"data-grid-row-id": resolvedRowId,
|
|
512
|
+
"data-grid-column-id": columnId,
|
|
513
|
+
tabIndex: 0,
|
|
514
|
+
onFocus: () => {
|
|
515
|
+
grid.setActiveCell({ rowId: resolvedRowId, columnId });
|
|
516
|
+
if (!grid.selection) {
|
|
517
|
+
grid.setSelection({
|
|
518
|
+
anchor: { rowId: resolvedRowId, columnId },
|
|
519
|
+
focus: { rowId: resolvedRowId, columnId }
|
|
520
|
+
});
|
|
521
|
+
}
|
|
522
|
+
},
|
|
523
|
+
onClick: (event) => {
|
|
524
|
+
if (event.shiftKey && grid.activeCell) {
|
|
525
|
+
grid.setSelection({ anchor: grid.activeCell, focus: { rowId: resolvedRowId, columnId } });
|
|
526
|
+
} else {
|
|
527
|
+
grid.setSelection({
|
|
528
|
+
anchor: { rowId: resolvedRowId, columnId },
|
|
529
|
+
focus: { rowId: resolvedRowId, columnId }
|
|
530
|
+
});
|
|
531
|
+
}
|
|
532
|
+
grid.setActiveCell({ rowId: resolvedRowId, columnId });
|
|
533
|
+
},
|
|
534
|
+
onKeyDown,
|
|
535
|
+
"aria-invalid": state === "invalid" || void 0,
|
|
536
|
+
className: cn2(
|
|
537
|
+
"relative min-h-9 border-r border-b px-2 py-1.5 align-middle outline-none",
|
|
538
|
+
isSelected && "bg-accent/40",
|
|
539
|
+
isActive && "ring-2 ring-inset ring-primary",
|
|
540
|
+
state === "invalid" && "border-destructive/60 bg-destructive/10",
|
|
541
|
+
state === "pending" && "opacity-70",
|
|
542
|
+
className
|
|
543
|
+
),
|
|
544
|
+
children: [
|
|
545
|
+
children,
|
|
546
|
+
showFillHandle && /* @__PURE__ */ jsx2(
|
|
547
|
+
"button",
|
|
548
|
+
{
|
|
549
|
+
type: "button",
|
|
550
|
+
"aria-label": "Fill selected cells",
|
|
551
|
+
className: "absolute right-0 bottom-0 z-10 size-2 cursor-crosshair border border-background bg-primary",
|
|
552
|
+
onMouseDown: (event) => event.preventDefault(),
|
|
553
|
+
onClick: fillSelection
|
|
554
|
+
}
|
|
555
|
+
)
|
|
556
|
+
]
|
|
557
|
+
}
|
|
558
|
+
)
|
|
559
|
+
}
|
|
560
|
+
);
|
|
561
|
+
}
|
|
562
|
+
function useGridCell() {
|
|
563
|
+
const cell = React2.useContext(DataGridCellContext);
|
|
564
|
+
const grid = useDataGridContext();
|
|
565
|
+
if (!cell) throw new Error("Grid cell components must be inside DataGridCell");
|
|
566
|
+
return { ...cell, grid };
|
|
567
|
+
}
|
|
568
|
+
function GridTextCell({
|
|
569
|
+
value,
|
|
570
|
+
onChange,
|
|
571
|
+
placeholder
|
|
572
|
+
}) {
|
|
573
|
+
const cell = useGridCell();
|
|
574
|
+
const currentValue = value ?? String(cell.value ?? "");
|
|
575
|
+
return /* @__PURE__ */ jsx2(
|
|
576
|
+
Input,
|
|
577
|
+
{
|
|
578
|
+
className: "h-7 w-full min-w-0 bg-transparent text-sm outline-none placeholder:text-muted-foreground",
|
|
579
|
+
onChange: (event) => {
|
|
580
|
+
const nextValue = event.target.value;
|
|
581
|
+
onChange?.(nextValue);
|
|
582
|
+
cell.grid.updateCell(cell.rowId, cell.columnId, nextValue);
|
|
583
|
+
},
|
|
584
|
+
placeholder,
|
|
585
|
+
value: currentValue
|
|
586
|
+
}
|
|
587
|
+
);
|
|
588
|
+
}
|
|
589
|
+
function GridNumberCell({
|
|
590
|
+
value,
|
|
591
|
+
onChange,
|
|
592
|
+
min,
|
|
593
|
+
max,
|
|
594
|
+
step = "any",
|
|
595
|
+
allowEmpty = true
|
|
596
|
+
}) {
|
|
597
|
+
const cell = useGridCell();
|
|
598
|
+
const currentValue = value ?? (typeof cell.value === "number" ? cell.value : String(cell.value ?? ""));
|
|
599
|
+
const [invalid, setInvalid] = React2.useState(false);
|
|
600
|
+
return /* @__PURE__ */ jsx2(
|
|
601
|
+
Input,
|
|
602
|
+
{
|
|
603
|
+
"aria-invalid": invalid || void 0,
|
|
604
|
+
className: cn2(
|
|
605
|
+
"h-7 w-full min-w-0 bg-transparent text-sm outline-none",
|
|
606
|
+
invalid && "border-destructive ring-2 ring-destructive/20"
|
|
607
|
+
),
|
|
608
|
+
onChange: (event) => {
|
|
609
|
+
const rawValue = event.target.value;
|
|
610
|
+
if (!rawValue && allowEmpty) {
|
|
611
|
+
setInvalid(false);
|
|
612
|
+
cell.grid.updateCell(cell.rowId, cell.columnId, "");
|
|
613
|
+
return;
|
|
614
|
+
}
|
|
615
|
+
const nextValue = event.target.valueAsNumber;
|
|
616
|
+
if (Number.isNaN(nextValue)) return;
|
|
617
|
+
const nextInvalid = min !== void 0 && nextValue < min || max !== void 0 && nextValue > max;
|
|
618
|
+
setInvalid(nextInvalid);
|
|
619
|
+
onChange?.(nextValue);
|
|
620
|
+
cell.grid.updateCell(cell.rowId, cell.columnId, nextValue);
|
|
621
|
+
},
|
|
622
|
+
min,
|
|
623
|
+
max,
|
|
624
|
+
step,
|
|
625
|
+
type: "number",
|
|
626
|
+
value: currentValue
|
|
627
|
+
}
|
|
628
|
+
);
|
|
629
|
+
}
|
|
630
|
+
function GridComboboxCell({
|
|
631
|
+
options,
|
|
632
|
+
value,
|
|
633
|
+
onChange
|
|
634
|
+
}) {
|
|
635
|
+
const cell = useGridCell();
|
|
636
|
+
const currentValue = value ?? String(cell.value ?? "");
|
|
637
|
+
return /* @__PURE__ */ jsxs(
|
|
638
|
+
Combobox,
|
|
639
|
+
{
|
|
640
|
+
onValueChange: (nextValue) => {
|
|
641
|
+
if (nextValue === null) return;
|
|
642
|
+
onChange?.(nextValue);
|
|
643
|
+
cell.grid.updateCell(cell.rowId, cell.columnId, nextValue);
|
|
644
|
+
},
|
|
645
|
+
value: currentValue,
|
|
646
|
+
children: [
|
|
647
|
+
/* @__PURE__ */ jsx2(
|
|
648
|
+
ComboboxInput,
|
|
649
|
+
{
|
|
650
|
+
className: "h-7 w-full min-w-0 border-0 bg-transparent px-0 shadow-none",
|
|
651
|
+
showClear: false
|
|
652
|
+
}
|
|
653
|
+
),
|
|
654
|
+
/* @__PURE__ */ jsx2(ComboboxContent, { children: /* @__PURE__ */ jsx2(ComboboxList, { children: options.map((option) => /* @__PURE__ */ jsx2(ComboboxItem, { value: option.value, children: option.label }, option.value)) }) })
|
|
655
|
+
]
|
|
656
|
+
}
|
|
657
|
+
);
|
|
658
|
+
}
|
|
659
|
+
function GridAsyncComboboxCell({
|
|
660
|
+
value,
|
|
661
|
+
onChange,
|
|
662
|
+
loadOptions,
|
|
663
|
+
placeholder = "Search...",
|
|
664
|
+
minQueryLength = 0,
|
|
665
|
+
debounceMs = 250
|
|
666
|
+
}) {
|
|
667
|
+
const cell = useGridCell();
|
|
668
|
+
const selectedValue = value ?? String(cell.value ?? "");
|
|
669
|
+
const [query, setQuery] = React2.useState("");
|
|
670
|
+
const [options, setOptions] = React2.useState([]);
|
|
671
|
+
const [selectedOption, setSelectedOption] = React2.useState(null);
|
|
672
|
+
const [isLoading, setIsLoading] = React2.useState(false);
|
|
673
|
+
const requestId = React2.useRef(0);
|
|
674
|
+
const loadOptionsRef = React2.useRef(loadOptions);
|
|
675
|
+
React2.useEffect(() => {
|
|
676
|
+
loadOptionsRef.current = loadOptions;
|
|
677
|
+
}, [loadOptions]);
|
|
678
|
+
const stableLoadOptions = React2.useCallback(
|
|
679
|
+
(search) => loadOptionsRef.current(search),
|
|
680
|
+
[]
|
|
681
|
+
);
|
|
682
|
+
React2.useEffect(() => {
|
|
683
|
+
const currentRequestId = ++requestId.current;
|
|
684
|
+
const normalizedQuery = query.trim();
|
|
685
|
+
if (normalizedQuery.length < minQueryLength) {
|
|
686
|
+
setOptions([]);
|
|
687
|
+
setIsLoading(false);
|
|
688
|
+
return;
|
|
689
|
+
}
|
|
690
|
+
const timeout = window.setTimeout(async () => {
|
|
691
|
+
setIsLoading(true);
|
|
692
|
+
try {
|
|
693
|
+
const nextOptions = await stableLoadOptions(normalizedQuery);
|
|
694
|
+
if (currentRequestId === requestId.current) {
|
|
695
|
+
setOptions(nextOptions);
|
|
696
|
+
}
|
|
697
|
+
} catch {
|
|
698
|
+
if (currentRequestId === requestId.current) {
|
|
699
|
+
setOptions([]);
|
|
700
|
+
}
|
|
701
|
+
} finally {
|
|
702
|
+
if (currentRequestId === requestId.current) {
|
|
703
|
+
setIsLoading(false);
|
|
704
|
+
}
|
|
705
|
+
}
|
|
706
|
+
}, debounceMs);
|
|
707
|
+
return () => {
|
|
708
|
+
window.clearTimeout(timeout);
|
|
709
|
+
if (requestId.current === currentRequestId) {
|
|
710
|
+
requestId.current += 1;
|
|
711
|
+
}
|
|
712
|
+
};
|
|
713
|
+
}, [debounceMs, minQueryLength, query, stableLoadOptions]);
|
|
714
|
+
const selectedItem = options.find((option) => option.value === selectedValue) ?? (selectedOption?.value === selectedValue ? selectedOption : null);
|
|
715
|
+
return /* @__PURE__ */ jsxs(
|
|
716
|
+
Combobox,
|
|
717
|
+
{
|
|
718
|
+
items: options,
|
|
719
|
+
itemToStringLabel: (item) => item?.label ?? "",
|
|
720
|
+
itemToStringValue: (item) => item?.value ?? "",
|
|
721
|
+
onValueChange: (nextOption) => {
|
|
722
|
+
if (nextOption === null) return;
|
|
723
|
+
setSelectedOption(nextOption);
|
|
724
|
+
onChange?.(nextOption.value, nextOption);
|
|
725
|
+
cell.grid.updateCell(cell.rowId, cell.columnId, nextOption.value);
|
|
726
|
+
setQuery(nextOption.label);
|
|
727
|
+
},
|
|
728
|
+
value: selectedItem,
|
|
729
|
+
children: [
|
|
730
|
+
/* @__PURE__ */ jsx2(
|
|
731
|
+
ComboboxInput,
|
|
732
|
+
{
|
|
733
|
+
className: "h-7 w-full min-w-0 border-0 bg-transparent px-0 shadow-none",
|
|
734
|
+
onChange: (event) => setQuery(event.target.value),
|
|
735
|
+
placeholder,
|
|
736
|
+
showClear: false,
|
|
737
|
+
value: query
|
|
738
|
+
}
|
|
739
|
+
),
|
|
740
|
+
/* @__PURE__ */ jsxs(ComboboxContent, { children: [
|
|
741
|
+
isLoading && /* @__PURE__ */ jsx2(ComboboxEmpty, { children: "Loading..." }),
|
|
742
|
+
!isLoading && query.trim().length >= minQueryLength && options.length === 0 && /* @__PURE__ */ jsx2(ComboboxEmpty, { children: "No results found." }),
|
|
743
|
+
/* @__PURE__ */ jsx2(ComboboxList, { children: options.map((option) => /* @__PURE__ */ jsx2(ComboboxItem, { value: option, children: option.label }, option.value)) })
|
|
744
|
+
] })
|
|
745
|
+
]
|
|
746
|
+
}
|
|
747
|
+
);
|
|
748
|
+
}
|
|
749
|
+
function DataTableColumnResize() {
|
|
750
|
+
return /* @__PURE__ */ jsx2("span", { "aria-hidden": true, className: "absolute inset-y-0 right-0 w-px" });
|
|
751
|
+
}
|
|
752
|
+
function DataGridClipboard({
|
|
753
|
+
children
|
|
754
|
+
}) {
|
|
755
|
+
return /* @__PURE__ */ jsx2(Fragment, { children });
|
|
756
|
+
}
|
|
757
|
+
function DataGridFillHandle({
|
|
758
|
+
children
|
|
759
|
+
}) {
|
|
760
|
+
return /* @__PURE__ */ jsx2(Fragment, { children });
|
|
761
|
+
}
|
|
762
|
+
function DataGridMove({ children }) {
|
|
763
|
+
return /* @__PURE__ */ jsx2(Fragment, { children });
|
|
764
|
+
}
|
|
765
|
+
|
|
766
|
+
export {
|
|
767
|
+
useDataTable,
|
|
768
|
+
DataTableRoot,
|
|
769
|
+
useDataTablePagination,
|
|
770
|
+
useDataTableRows,
|
|
771
|
+
useDataTableSearch,
|
|
772
|
+
useDataGrid,
|
|
773
|
+
DataGrid,
|
|
774
|
+
DataGridRow,
|
|
775
|
+
DataGridColumn,
|
|
776
|
+
DataGridCell,
|
|
777
|
+
GridTextCell,
|
|
778
|
+
GridNumberCell,
|
|
779
|
+
GridComboboxCell,
|
|
780
|
+
GridAsyncComboboxCell,
|
|
781
|
+
DataTableColumnResize,
|
|
782
|
+
DataGridClipboard,
|
|
783
|
+
DataGridFillHandle,
|
|
784
|
+
DataGridMove
|
|
785
|
+
};
|