rockin 0.0.18 → 0.0.20

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/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "rockin",
3
- "version": "0.0.18",
3
+ "version": "0.0.20",
4
4
  "description": "Reusable React UI components, hooks, icons, utilities, and styles for Rock Star projects.",
5
5
  "keywords": [
6
6
  "react",
@@ -1,389 +0,0 @@
1
- // src/ui/data-table/core/data-table-root.tsx
2
- import * as React from "react";
3
- import { cn } from "cn";
4
- import { jsx } from "react/jsx-runtime";
5
- var DataTableContext = React.createContext(
6
- null
7
- );
8
- function useDataTable() {
9
- const context = React.useContext(DataTableContext);
10
- if (!context) {
11
- throw new Error(
12
- "DataTable components must be rendered inside DataTableRoot"
13
- );
14
- }
15
- return context;
16
- }
17
- function DataTableRoot({
18
- data,
19
- columns,
20
- children,
21
- isLoading = false,
22
- pageSize = 10,
23
- getRowId = (_, index) => String(index),
24
- className
25
- }) {
26
- const [globalFilter, setGlobalFilterState] = React.useState("");
27
- const [pageIndex, setPageIndexState] = React.useState(0);
28
- const filteredData = React.useMemo(() => {
29
- const query = globalFilter.trim().toLowerCase();
30
- if (!query) return data;
31
- return data.filter(
32
- (row) => columns.some((column) => {
33
- if (column.enableSearch === false) return false;
34
- const value = column.accessorFn ? column.accessorFn(row) : column.accessorKey ? row[column.accessorKey] : void 0;
35
- return String(value ?? "").toLowerCase().includes(query);
36
- })
37
- );
38
- }, [columns, data, globalFilter]);
39
- const safePageSize = Math.max(1, pageSize);
40
- const pageCount = Math.max(1, Math.ceil(filteredData.length / safePageSize));
41
- const safePageIndex = Math.min(pageIndex, pageCount - 1);
42
- const pageData = filteredData.slice(
43
- safePageIndex * safePageSize,
44
- (safePageIndex + 1) * safePageSize
45
- );
46
- React.useEffect(() => {
47
- setPageIndexState((current) => Math.min(current, pageCount - 1));
48
- }, [pageCount]);
49
- const contextValue = React.useMemo(
50
- () => ({
51
- data,
52
- columns,
53
- filteredData,
54
- pageData,
55
- pageIndex: safePageIndex,
56
- pageSize: safePageSize,
57
- pageCount,
58
- globalFilter,
59
- isLoading,
60
- getRowId,
61
- setGlobalFilter: (value) => {
62
- setGlobalFilterState(value);
63
- setPageIndexState(0);
64
- },
65
- setPageIndex: (value) => setPageIndexState(Math.max(0, Math.min(value, pageCount - 1)))
66
- }),
67
- [
68
- columns,
69
- filteredData,
70
- pageCount,
71
- pageData,
72
- safePageIndex,
73
- safePageSize,
74
- globalFilter,
75
- isLoading,
76
- getRowId
77
- ]
78
- );
79
- return /* @__PURE__ */ jsx(DataTableContext.Provider, { value: contextValue, children: /* @__PURE__ */ jsx("div", { className: cn("w-full space-y-3", className), children }) });
80
- }
81
-
82
- // src/ui/data-table/hooks/use-data-table-pagination.ts
83
- function useDataTablePagination() {
84
- const { pageIndex, pageSize, pageCount, setPageIndex } = useDataTable();
85
- return {
86
- pageIndex,
87
- pageSize,
88
- pageCount,
89
- canPreviousPage: pageIndex > 0,
90
- canNextPage: pageIndex < pageCount - 1,
91
- goToPage: setPageIndex,
92
- previousPage: () => setPageIndex(pageIndex - 1),
93
- nextPage: () => setPageIndex(pageIndex + 1),
94
- firstPage: () => setPageIndex(0),
95
- lastPage: () => setPageIndex(pageCount - 1)
96
- };
97
- }
98
-
99
- // src/ui/data-table/hooks/use-data-table-rows.ts
100
- function useDataTableRows() {
101
- const { data, filteredData, pageData, isLoading } = useDataTable();
102
- return {
103
- data,
104
- rows: pageData,
105
- pageRows: pageData,
106
- filteredRows: filteredData,
107
- totalRows: filteredData.length,
108
- isLoading
109
- };
110
- }
111
-
112
- // src/ui/data-table/hooks/use-data-table-search.ts
113
- function useDataTableSearch() {
114
- const { globalFilter, setGlobalFilter } = useDataTable();
115
- return {
116
- search: globalFilter,
117
- setSearch: setGlobalFilter,
118
- clearSearch: () => setGlobalFilter("")
119
- };
120
- }
121
-
122
- // src/ui/data-table/data-grid.tsx
123
- import * as React2 from "react";
124
- import { cn as cn2 } from "cn";
125
- import { Fragment, jsx as jsx2 } from "react/jsx-runtime";
126
- function useDataGrid({
127
- columnIds = [],
128
- columns,
129
- initialRows = [],
130
- getRowId = (row, index) => String(row.id ?? index)
131
- } = {}) {
132
- const [rows, setRows] = React2.useState(initialRows);
133
- const resolvedColumns = React2.useMemo(
134
- () => columns ?? columnIds.map((id) => ({
135
- id,
136
- accessorKey: id,
137
- header: id
138
- })),
139
- [columnIds, columns]
140
- );
141
- const getRow = React2.useCallback(
142
- (rowId) => rows.find((row, index) => getRowId(row, index) === rowId),
143
- [getRowId, rows]
144
- );
145
- const getCellValue = React2.useCallback(
146
- (rowId, columnId) => {
147
- const row = getRow(rowId);
148
- return row?.[columnId];
149
- },
150
- [getRow]
151
- );
152
- const updateCell = React2.useCallback(
153
- (rowId, columnId, value) => {
154
- setRows(
155
- (current) => current.map(
156
- (row, index) => getRowId(row, index) === rowId ? { ...row, [columnId]: value } : row
157
- )
158
- );
159
- },
160
- [getRowId]
161
- );
162
- const updateRows = React2.useCallback(
163
- (updater) => setRows(updater),
164
- []
165
- );
166
- return React2.useMemo(
167
- () => ({
168
- rows,
169
- columns: resolvedColumns,
170
- getRowId,
171
- getRow,
172
- getCellValue,
173
- updateCell,
174
- updateRows
175
- }),
176
- [
177
- getCellValue,
178
- getRow,
179
- getRowId,
180
- resolvedColumns,
181
- rows,
182
- updateCell,
183
- updateRows
184
- ]
185
- );
186
- }
187
- var DataGridContext = React2.createContext(null);
188
- function useDataGridContext() {
189
- const context = React2.useContext(DataGridContext);
190
- if (!context) throw new Error("DataGrid components must be inside DataGrid");
191
- return context;
192
- }
193
- var DataGridCellContext = React2.createContext(null);
194
- function DataGrid({
195
- grid,
196
- children,
197
- className
198
- }) {
199
- return /* @__PURE__ */ jsx2(DataGridContext.Provider, { value: grid, children: /* @__PURE__ */ jsx2("div", { className: cn2("w-full space-y-2 outline-none", className), children }) });
200
- }
201
- function DataGridRow({
202
- row,
203
- rowId,
204
- children,
205
- className
206
- }) {
207
- const grid = useDataGridContext();
208
- const resolvedRowId = rowId ?? (row ? grid.getRowId(row, 0) : "");
209
- const resolvedRow = row ?? grid.getRow(resolvedRowId);
210
- return /* @__PURE__ */ jsx2(
211
- "div",
212
- {
213
- className: cn2(
214
- "grid grid-cols-[repeat(var(--data-grid-columns),minmax(9rem,1fr))]",
215
- className
216
- ),
217
- children: resolvedRow && children
218
- }
219
- );
220
- }
221
- function DataGridColumn({
222
- column,
223
- children,
224
- className
225
- }) {
226
- return /* @__PURE__ */ jsx2("div", { className: cn2("min-w-0", className), children: children ?? column.header });
227
- }
228
- function DataGridCell({
229
- row,
230
- rowId,
231
- columnId,
232
- children,
233
- state = "valid",
234
- className
235
- }) {
236
- const grid = useDataGridContext();
237
- const resolvedRowId = rowId ?? (row ? grid.getRowId(row, 0) : "");
238
- const value = grid.getCellValue(resolvedRowId, columnId);
239
- return /* @__PURE__ */ jsx2(
240
- DataGridCellContext.Provider,
241
- {
242
- value: { rowId: resolvedRowId, columnId, value },
243
- children: /* @__PURE__ */ jsx2(
244
- "div",
245
- {
246
- "aria-invalid": state === "invalid" || void 0,
247
- className: cn2(
248
- "min-h-9 border-r border-b px-2 py-1.5",
249
- state === "invalid" && "border-destructive/60 bg-destructive/10",
250
- state === "pending" && "opacity-70",
251
- className
252
- ),
253
- children
254
- }
255
- )
256
- }
257
- );
258
- }
259
- function useGridCell() {
260
- const cell = React2.useContext(DataGridCellContext);
261
- const grid = useDataGridContext();
262
- if (!cell) throw new Error("Grid cell components must be inside DataGridCell");
263
- return { ...cell, grid };
264
- }
265
- function GridTextCell({
266
- value,
267
- onChange,
268
- placeholder
269
- }) {
270
- const cell = useGridCell();
271
- const currentValue = value ?? String(cell.value ?? "");
272
- return /* @__PURE__ */ jsx2(
273
- "input",
274
- {
275
- className: "h-7 w-full min-w-0 bg-transparent text-sm outline-none placeholder:text-muted-foreground",
276
- onChange: (event) => {
277
- const nextValue = event.target.value;
278
- onChange?.(nextValue);
279
- cell.grid.updateCell(cell.rowId, cell.columnId, nextValue);
280
- },
281
- placeholder,
282
- value: currentValue
283
- }
284
- );
285
- }
286
- function GridNumberCell({
287
- value,
288
- onChange
289
- }) {
290
- const cell = useGridCell();
291
- const currentValue = value ?? (typeof cell.value === "number" ? cell.value : "");
292
- return /* @__PURE__ */ jsx2(
293
- "input",
294
- {
295
- className: "h-7 w-full min-w-0 bg-transparent text-sm outline-none",
296
- onChange: (event) => {
297
- const nextValue = event.target.valueAsNumber;
298
- if (Number.isNaN(nextValue)) return;
299
- onChange?.(nextValue);
300
- cell.grid.updateCell(cell.rowId, cell.columnId, nextValue);
301
- },
302
- type: "number",
303
- value: currentValue
304
- }
305
- );
306
- }
307
- function GridComboboxCell({
308
- options,
309
- value,
310
- onChange
311
- }) {
312
- const cell = useGridCell();
313
- const currentValue = value ?? String(cell.value ?? "");
314
- return /* @__PURE__ */ jsx2(
315
- "select",
316
- {
317
- className: "h-7 w-full min-w-0 bg-transparent text-sm outline-none",
318
- onChange: (event) => {
319
- const nextValue = event.target.value;
320
- onChange?.(nextValue);
321
- cell.grid.updateCell(cell.rowId, cell.columnId, nextValue);
322
- },
323
- value: currentValue,
324
- children: options.map((option) => /* @__PURE__ */ jsx2("option", { value: option.value, children: option.label }, option.value))
325
- }
326
- );
327
- }
328
- function DataTableColumnResize() {
329
- return /* @__PURE__ */ jsx2("span", { "aria-hidden": true, className: "absolute inset-y-0 right-0 w-px" });
330
- }
331
- function DataGridClipboard({
332
- children
333
- }) {
334
- return /* @__PURE__ */ jsx2(Fragment, { children });
335
- }
336
- function DataGridFillHandle({
337
- children
338
- }) {
339
- return /* @__PURE__ */ jsx2(Fragment, { children });
340
- }
341
- function DataGridMove({ children }) {
342
- return /* @__PURE__ */ jsx2(Fragment, { children });
343
- }
344
-
345
- // src/hooks/useMediaQuery.ts
346
- import { useEffect as useEffect2, useState as useState3 } from "react";
347
- function useMediaQuery(query) {
348
- const [matches, setMatches] = useState3(false);
349
- useEffect2(() => {
350
- const mediaQuery = window.matchMedia(query);
351
- const handleChange = () => setMatches(mediaQuery.matches);
352
- handleChange();
353
- mediaQuery.addEventListener("change", handleChange);
354
- return () => mediaQuery.removeEventListener("change", handleChange);
355
- }, [query]);
356
- return matches;
357
- }
358
-
359
- // src/hooks/useMounted.ts
360
- import { useEffect as useEffect3, useState as useState4 } from "react";
361
- function useMounted() {
362
- const [mounted, setMounted] = useState4(false);
363
- useEffect3(() => {
364
- setMounted(true);
365
- }, []);
366
- return { mounted };
367
- }
368
-
369
- export {
370
- useDataTable,
371
- DataTableRoot,
372
- useDataTablePagination,
373
- useDataTableRows,
374
- useDataTableSearch,
375
- useDataGrid,
376
- DataGrid,
377
- DataGridRow,
378
- DataGridColumn,
379
- DataGridCell,
380
- GridTextCell,
381
- GridNumberCell,
382
- GridComboboxCell,
383
- DataTableColumnResize,
384
- DataGridClipboard,
385
- DataGridFillHandle,
386
- DataGridMove,
387
- useMediaQuery,
388
- useMounted
389
- };