@moontra/moonui-pro 2.3.6 → 2.3.8
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.mjs +71 -37
- package/package.json +1 -1
- package/src/components/data-table/index.tsx +113 -77
package/dist/index.mjs
CHANGED
|
@@ -52210,8 +52210,9 @@ function DataTable({
|
|
|
52210
52210
|
const [internalExpandedRows, setInternalExpandedRows] = t__default.useState(/* @__PURE__ */ new Set());
|
|
52211
52211
|
const expandedRows = controlledExpandedRows || internalExpandedRows;
|
|
52212
52212
|
const actualPageSize = defaultPageSize || pageSize;
|
|
52213
|
+
const stableData = t__default.useMemo(() => data, [data]);
|
|
52213
52214
|
const table = useReactTable({
|
|
52214
|
-
data,
|
|
52215
|
+
data: stableData,
|
|
52215
52216
|
columns,
|
|
52216
52217
|
onSortingChange: onSortingChange !== void 0 ? onSortingChange : setSorting,
|
|
52217
52218
|
onColumnFiltersChange: onColumnFiltersChange !== void 0 ? onColumnFiltersChange : setColumnFilters,
|
|
@@ -52244,6 +52245,12 @@ function DataTable({
|
|
|
52244
52245
|
onRowSelect(selectedRows);
|
|
52245
52246
|
}
|
|
52246
52247
|
}, [rowSelection, onRowSelect, selectable, table]);
|
|
52248
|
+
const tableState = table.getState();
|
|
52249
|
+
const rows = t__default.useMemo(
|
|
52250
|
+
() => table.getRowModel().rows,
|
|
52251
|
+
// Only recalculate when data or filtering/sorting changes, not on expand/collapse
|
|
52252
|
+
[stableData, tableState.sorting, tableState.columnFilters, tableState.globalFilter, tableState.pagination.pageIndex, tableState.pagination.pageSize]
|
|
52253
|
+
);
|
|
52247
52254
|
({
|
|
52248
52255
|
sorting: features.sorting !== false,
|
|
52249
52256
|
filtering: features.filtering !== false || filterable,
|
|
@@ -52313,7 +52320,7 @@ function DataTable({
|
|
|
52313
52320
|
},
|
|
52314
52321
|
header.id
|
|
52315
52322
|
)) }, headerGroup.id)) }),
|
|
52316
|
-
/* @__PURE__ */ jsx("tbody", { className: "moonui-data-table-body", children:
|
|
52323
|
+
/* @__PURE__ */ jsx("tbody", { className: "moonui-data-table-body", children: isPaginationLoading ? /* @__PURE__ */ jsx(
|
|
52317
52324
|
motion.tr,
|
|
52318
52325
|
{
|
|
52319
52326
|
initial: { opacity: 0 },
|
|
@@ -52326,43 +52333,70 @@ function DataTable({
|
|
|
52326
52333
|
] }) })
|
|
52327
52334
|
},
|
|
52328
52335
|
"loading"
|
|
52329
|
-
) :
|
|
52336
|
+
) : rows?.length ? /* @__PURE__ */ jsx(Fragment, { children: rows.map((row, index) => {
|
|
52330
52337
|
const rowId = row.original.id || row.id;
|
|
52331
52338
|
const isExpanded = enableExpandable && expandedRows.has(rowId);
|
|
52332
|
-
|
|
52333
|
-
|
|
52334
|
-
|
|
52335
|
-
|
|
52336
|
-
|
|
52337
|
-
|
|
52338
|
-
|
|
52339
|
-
|
|
52340
|
-
|
|
52341
|
-
|
|
52339
|
+
return /* @__PURE__ */ jsxs(t__default.Fragment, { children: [
|
|
52340
|
+
/* @__PURE__ */ jsx(
|
|
52341
|
+
"tr",
|
|
52342
|
+
{
|
|
52343
|
+
className: cn(
|
|
52344
|
+
"border-b transition-colors hover:bg-muted/50",
|
|
52345
|
+
row.getIsSelected() && "bg-muted",
|
|
52346
|
+
isExpanded && "border-b-0"
|
|
52347
|
+
),
|
|
52348
|
+
children: row.getVisibleCells().map((cell) => /* @__PURE__ */ jsx("td", { className: "moonui-data-table-td p-4 align-middle", children: flexRender(cell.column.columnDef.cell, cell.getContext()) }, cell.id))
|
|
52349
|
+
}
|
|
52350
|
+
),
|
|
52351
|
+
/* @__PURE__ */ jsx(AnimatePresence, { initial: false, children: isExpanded && renderSubComponent && /* @__PURE__ */ jsx(
|
|
52352
|
+
motion.tr,
|
|
52353
|
+
{
|
|
52354
|
+
initial: { height: 0, opacity: 0 },
|
|
52355
|
+
animate: {
|
|
52356
|
+
height: "auto",
|
|
52357
|
+
opacity: 1,
|
|
52358
|
+
transition: {
|
|
52359
|
+
height: {
|
|
52360
|
+
duration: 0.3,
|
|
52361
|
+
ease: "easeOut"
|
|
52362
|
+
},
|
|
52363
|
+
opacity: {
|
|
52364
|
+
duration: 0.2,
|
|
52365
|
+
delay: 0.1
|
|
52366
|
+
}
|
|
52367
|
+
}
|
|
52368
|
+
},
|
|
52369
|
+
exit: {
|
|
52370
|
+
height: 0,
|
|
52371
|
+
opacity: 0,
|
|
52372
|
+
transition: {
|
|
52373
|
+
height: {
|
|
52374
|
+
duration: 0.3,
|
|
52375
|
+
ease: "easeIn"
|
|
52376
|
+
},
|
|
52377
|
+
opacity: {
|
|
52378
|
+
duration: 0.2
|
|
52379
|
+
}
|
|
52380
|
+
}
|
|
52381
|
+
},
|
|
52382
|
+
style: { overflow: "hidden" },
|
|
52383
|
+
className: "border-b",
|
|
52384
|
+
children: /* @__PURE__ */ jsx("td", { colSpan: columns.length, className: "p-0", children: /* @__PURE__ */ jsx(
|
|
52385
|
+
motion.div,
|
|
52386
|
+
{
|
|
52387
|
+
initial: { y: -10 },
|
|
52388
|
+
animate: { y: 0 },
|
|
52389
|
+
exit: { y: -10 },
|
|
52390
|
+
transition: { duration: 0.2 },
|
|
52391
|
+
className: "border-t border-border/50",
|
|
52392
|
+
children: renderSubComponent({ row: { original: row.original, id: rowId } })
|
|
52393
|
+
}
|
|
52394
|
+
) })
|
|
52342
52395
|
},
|
|
52343
|
-
|
|
52344
|
-
|
|
52345
|
-
|
|
52346
|
-
|
|
52347
|
-
),
|
|
52348
|
-
children: row.getVisibleCells().map((cell) => /* @__PURE__ */ jsx("td", { className: "moonui-data-table-td p-4 align-middle", children: flexRender(cell.column.columnDef.cell, cell.getContext()) }, cell.id))
|
|
52349
|
-
},
|
|
52350
|
-
row.id
|
|
52351
|
-
);
|
|
52352
|
-
const expandedRow = isExpanded && renderSubComponent ? /* @__PURE__ */ jsx(
|
|
52353
|
-
motion.tr,
|
|
52354
|
-
{
|
|
52355
|
-
initial: { opacity: 0, height: 0 },
|
|
52356
|
-
animate: { opacity: 1, height: "auto" },
|
|
52357
|
-
exit: { opacity: 0, height: 0 },
|
|
52358
|
-
transition: { duration: 0.3, ease: "easeOut" },
|
|
52359
|
-
className: "border-b",
|
|
52360
|
-
children: /* @__PURE__ */ jsx("td", { colSpan: columns.length, className: "p-0", children: /* @__PURE__ */ jsx("div", { className: "border-t border-border/50", children: renderSubComponent({ row: { original: row.original, id: rowId } }) }) })
|
|
52361
|
-
},
|
|
52362
|
-
`${row.id}-expanded`
|
|
52363
|
-
) : null;
|
|
52364
|
-
return expandedRow ? [mainRow, expandedRow] : [mainRow];
|
|
52365
|
-
}) : /* @__PURE__ */ jsx(
|
|
52396
|
+
`${row.id}-expanded`
|
|
52397
|
+
) })
|
|
52398
|
+
] }, rowId);
|
|
52399
|
+
}) }) : /* @__PURE__ */ jsx(
|
|
52366
52400
|
motion.tr,
|
|
52367
52401
|
{
|
|
52368
52402
|
initial: { opacity: 0 },
|
|
@@ -52372,7 +52406,7 @@ function DataTable({
|
|
|
52372
52406
|
children: /* @__PURE__ */ jsx("td", { colSpan: columns.length, className: "h-24 text-center", children: "No results found." })
|
|
52373
52407
|
},
|
|
52374
52408
|
"no-results"
|
|
52375
|
-
) })
|
|
52409
|
+
) })
|
|
52376
52410
|
] }) }) }),
|
|
52377
52411
|
pagination && /* @__PURE__ */ jsxs("div", { className: "flex items-center justify-between px-2", children: [
|
|
52378
52412
|
/* @__PURE__ */ jsx("div", { className: "flex-1 text-sm text-muted-foreground", children: selectable && table.getFilteredSelectedRowModel().rows.length > 0 && /* @__PURE__ */ jsxs("span", { children: [
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@moontra/moonui-pro",
|
|
3
|
-
"version": "2.3.
|
|
3
|
+
"version": "2.3.8",
|
|
4
4
|
"description": "Premium React components for MoonUI - Advanced UI library with 50+ pro components including performance, interactive, and gesture components",
|
|
5
5
|
"type": "module",
|
|
6
6
|
"main": "dist/index.mjs",
|
|
@@ -13,6 +13,7 @@ import {
|
|
|
13
13
|
ColumnFiltersState,
|
|
14
14
|
VisibilityState,
|
|
15
15
|
OnChangeFn,
|
|
16
|
+
Row,
|
|
16
17
|
} from '@tanstack/react-table'
|
|
17
18
|
import { Button } from '../ui/button'
|
|
18
19
|
import { Input } from '../ui/input'
|
|
@@ -182,8 +183,11 @@ export function DataTable<TData, TValue>({
|
|
|
182
183
|
|
|
183
184
|
const actualPageSize = defaultPageSize || pageSize
|
|
184
185
|
|
|
186
|
+
// Memoize data to prevent unnecessary re-renders
|
|
187
|
+
const stableData = React.useMemo(() => data, [data])
|
|
188
|
+
|
|
185
189
|
const table = useReactTable({
|
|
186
|
-
data,
|
|
190
|
+
data: stableData,
|
|
187
191
|
columns,
|
|
188
192
|
onSortingChange: onSortingChange !== undefined ? onSortingChange : setSorting,
|
|
189
193
|
onColumnFiltersChange: onColumnFiltersChange !== undefined ? onColumnFiltersChange : setColumnFilters,
|
|
@@ -217,6 +221,14 @@ export function DataTable<TData, TValue>({
|
|
|
217
221
|
onRowSelect(selectedRows)
|
|
218
222
|
}
|
|
219
223
|
}, [rowSelection, onRowSelect, selectable, table])
|
|
224
|
+
|
|
225
|
+
// Memoize row model to prevent unnecessary re-renders when only expanded state changes
|
|
226
|
+
const tableState = table.getState()
|
|
227
|
+
const rows = React.useMemo(
|
|
228
|
+
() => table.getRowModel().rows,
|
|
229
|
+
// Only recalculate when data or filtering/sorting changes, not on expand/collapse
|
|
230
|
+
[stableData, tableState.sorting, tableState.columnFilters, tableState.globalFilter, tableState.pagination.pageIndex, tableState.pagination.pageSize]
|
|
231
|
+
)
|
|
220
232
|
|
|
221
233
|
// Merge features with defaults
|
|
222
234
|
const enabledFeatures = {
|
|
@@ -321,85 +333,109 @@ export function DataTable<TData, TValue>({
|
|
|
321
333
|
))}
|
|
322
334
|
</thead>
|
|
323
335
|
<tbody className="moonui-data-table-body">
|
|
324
|
-
|
|
325
|
-
|
|
326
|
-
|
|
327
|
-
|
|
328
|
-
|
|
329
|
-
|
|
330
|
-
|
|
331
|
-
|
|
332
|
-
>
|
|
333
|
-
<
|
|
334
|
-
<
|
|
335
|
-
|
|
336
|
-
|
|
337
|
-
|
|
338
|
-
|
|
339
|
-
|
|
340
|
-
|
|
341
|
-
|
|
336
|
+
{isPaginationLoading ? (
|
|
337
|
+
<motion.tr
|
|
338
|
+
key="loading"
|
|
339
|
+
initial={{ opacity: 0 }}
|
|
340
|
+
animate={{ opacity: 1 }}
|
|
341
|
+
exit={{ opacity: 0 }}
|
|
342
|
+
transition={{ duration: 0.2 }}
|
|
343
|
+
>
|
|
344
|
+
<td colSpan={columns.length} className="h-24 text-center">
|
|
345
|
+
<div className="flex items-center justify-center space-x-2">
|
|
346
|
+
<span suppressHydrationWarning><Loader2 className="h-4 w-4 animate-spin" /></span>
|
|
347
|
+
<span className="text-sm text-muted-foreground">Loading...</span>
|
|
348
|
+
</div>
|
|
349
|
+
</td>
|
|
350
|
+
</motion.tr>
|
|
351
|
+
) : rows?.length ? (
|
|
352
|
+
<>
|
|
353
|
+
{rows.map((row, index) => {
|
|
342
354
|
const rowId = (row.original as any).id || row.id
|
|
343
355
|
const isExpanded = enableExpandable && expandedRows.has(rowId)
|
|
344
356
|
|
|
345
|
-
|
|
346
|
-
<
|
|
347
|
-
|
|
348
|
-
|
|
349
|
-
|
|
350
|
-
|
|
351
|
-
|
|
352
|
-
|
|
353
|
-
|
|
354
|
-
|
|
355
|
-
|
|
356
|
-
|
|
357
|
-
|
|
358
|
-
|
|
359
|
-
|
|
360
|
-
|
|
361
|
-
|
|
362
|
-
|
|
363
|
-
|
|
364
|
-
|
|
365
|
-
|
|
366
|
-
|
|
367
|
-
|
|
368
|
-
|
|
369
|
-
|
|
370
|
-
|
|
371
|
-
|
|
372
|
-
|
|
373
|
-
|
|
374
|
-
|
|
375
|
-
|
|
376
|
-
|
|
377
|
-
|
|
378
|
-
|
|
379
|
-
|
|
380
|
-
|
|
381
|
-
|
|
382
|
-
|
|
383
|
-
|
|
384
|
-
|
|
385
|
-
|
|
386
|
-
|
|
387
|
-
|
|
388
|
-
|
|
389
|
-
|
|
390
|
-
|
|
391
|
-
|
|
392
|
-
|
|
393
|
-
|
|
394
|
-
|
|
395
|
-
|
|
396
|
-
|
|
397
|
-
|
|
398
|
-
|
|
399
|
-
|
|
400
|
-
|
|
401
|
-
|
|
402
|
-
|
|
357
|
+
return (
|
|
358
|
+
<React.Fragment key={rowId}>
|
|
359
|
+
<tr
|
|
360
|
+
className={cn(
|
|
361
|
+
"border-b transition-colors hover:bg-muted/50",
|
|
362
|
+
row.getIsSelected() && "bg-muted",
|
|
363
|
+
isExpanded && "border-b-0"
|
|
364
|
+
)}
|
|
365
|
+
>
|
|
366
|
+
{row.getVisibleCells().map((cell) => (
|
|
367
|
+
<td key={cell.id} className="moonui-data-table-td p-4 align-middle">
|
|
368
|
+
{flexRender(cell.column.columnDef.cell, cell.getContext())}
|
|
369
|
+
</td>
|
|
370
|
+
))}
|
|
371
|
+
</tr>
|
|
372
|
+
|
|
373
|
+
<AnimatePresence initial={false}>
|
|
374
|
+
{isExpanded && renderSubComponent && (
|
|
375
|
+
<motion.tr
|
|
376
|
+
key={`${row.id}-expanded`}
|
|
377
|
+
initial={{ height: 0, opacity: 0 }}
|
|
378
|
+
animate={{
|
|
379
|
+
height: "auto",
|
|
380
|
+
opacity: 1,
|
|
381
|
+
transition: {
|
|
382
|
+
height: {
|
|
383
|
+
duration: 0.3,
|
|
384
|
+
ease: "easeOut"
|
|
385
|
+
},
|
|
386
|
+
opacity: {
|
|
387
|
+
duration: 0.2,
|
|
388
|
+
delay: 0.1
|
|
389
|
+
}
|
|
390
|
+
}
|
|
391
|
+
}}
|
|
392
|
+
exit={{
|
|
393
|
+
height: 0,
|
|
394
|
+
opacity: 0,
|
|
395
|
+
transition: {
|
|
396
|
+
height: {
|
|
397
|
+
duration: 0.3,
|
|
398
|
+
ease: "easeIn"
|
|
399
|
+
},
|
|
400
|
+
opacity: {
|
|
401
|
+
duration: 0.2
|
|
402
|
+
}
|
|
403
|
+
}
|
|
404
|
+
}}
|
|
405
|
+
style={{ overflow: "hidden" }}
|
|
406
|
+
className="border-b"
|
|
407
|
+
>
|
|
408
|
+
<td colSpan={columns.length} className="p-0">
|
|
409
|
+
<motion.div
|
|
410
|
+
initial={{ y: -10 }}
|
|
411
|
+
animate={{ y: 0 }}
|
|
412
|
+
exit={{ y: -10 }}
|
|
413
|
+
transition={{ duration: 0.2 }}
|
|
414
|
+
className="border-t border-border/50"
|
|
415
|
+
>
|
|
416
|
+
{renderSubComponent({ row: { original: row.original, id: rowId } })}
|
|
417
|
+
</motion.div>
|
|
418
|
+
</td>
|
|
419
|
+
</motion.tr>
|
|
420
|
+
)}
|
|
421
|
+
</AnimatePresence>
|
|
422
|
+
</React.Fragment>
|
|
423
|
+
);
|
|
424
|
+
})}
|
|
425
|
+
</>
|
|
426
|
+
) : (
|
|
427
|
+
<motion.tr
|
|
428
|
+
key="no-results"
|
|
429
|
+
initial={{ opacity: 0 }}
|
|
430
|
+
animate={{ opacity: 1 }}
|
|
431
|
+
exit={{ opacity: 0 }}
|
|
432
|
+
transition={{ duration: 0.2 }}
|
|
433
|
+
>
|
|
434
|
+
<td colSpan={columns.length} className="h-24 text-center">
|
|
435
|
+
No results found.
|
|
436
|
+
</td>
|
|
437
|
+
</motion.tr>
|
|
438
|
+
)}
|
|
403
439
|
</tbody>
|
|
404
440
|
</table>
|
|
405
441
|
</div>
|