@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 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: /* @__PURE__ */ jsx(AnimatePresence, { mode: "wait", children: isPaginationLoading ? /* @__PURE__ */ jsx(
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
- ) : table.getRowModel().rows?.length ? table.getRowModel().rows.flatMap((row, index) => {
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
- const mainRow = /* @__PURE__ */ jsx(
52333
- motion.tr,
52334
- {
52335
- initial: { opacity: 0, y: 20 },
52336
- animate: { opacity: 1, y: 0 },
52337
- exit: { opacity: 0, y: -20 },
52338
- transition: {
52339
- duration: 0.3,
52340
- delay: index * 0.05,
52341
- ease: "easeOut"
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
- 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
- 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.6",
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
- <AnimatePresence mode="wait">
325
- {isPaginationLoading ? (
326
- <motion.tr
327
- key="loading"
328
- initial={{ opacity: 0 }}
329
- animate={{ opacity: 1 }}
330
- exit={{ opacity: 0 }}
331
- transition={{ duration: 0.2 }}
332
- >
333
- <td colSpan={columns.length} className="h-24 text-center">
334
- <div className="flex items-center justify-center space-x-2">
335
- <span suppressHydrationWarning><Loader2 className="h-4 w-4 animate-spin" /></span>
336
- <span className="text-sm text-muted-foreground">Loading...</span>
337
- </div>
338
- </td>
339
- </motion.tr>
340
- ) : table.getRowModel().rows?.length ? (
341
- table.getRowModel().rows.flatMap((row, index) => {
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
- const mainRow = (
346
- <motion.tr
347
- key={row.id}
348
- initial={{ opacity: 0, y: 20 }}
349
- animate={{ opacity: 1, y: 0 }}
350
- exit={{ opacity: 0, y: -20 }}
351
- transition={{
352
- duration: 0.3,
353
- delay: index * 0.05,
354
- ease: "easeOut"
355
- }}
356
- className={cn(
357
- "border-b transition-colors hover:bg-muted/50",
358
- row.getIsSelected() && "bg-muted",
359
- isExpanded && "border-b-0"
360
- )}
361
- >
362
- {row.getVisibleCells().map((cell) => (
363
- <td key={cell.id} className="moonui-data-table-td p-4 align-middle">
364
- {flexRender(cell.column.columnDef.cell, cell.getContext())}
365
- </td>
366
- ))}
367
- </motion.tr>
368
- )
369
-
370
- const expandedRow = isExpanded && renderSubComponent ? (
371
- <motion.tr
372
- key={`${row.id}-expanded`}
373
- initial={{ opacity: 0, height: 0 }}
374
- animate={{ opacity: 1, height: "auto" }}
375
- exit={{ opacity: 0, height: 0 }}
376
- transition={{ duration: 0.3, ease: "easeOut" }}
377
- className="border-b"
378
- >
379
- <td colSpan={columns.length} className="p-0">
380
- <div className="border-t border-border/50">
381
- {renderSubComponent({ row: { original: row.original, id: rowId } })}
382
- </div>
383
- </td>
384
- </motion.tr>
385
- ) : null;
386
-
387
- return expandedRow ? [mainRow, expandedRow] : [mainRow];
388
- })
389
- ) : (
390
- <motion.tr
391
- key="no-results"
392
- initial={{ opacity: 0 }}
393
- animate={{ opacity: 1 }}
394
- exit={{ opacity: 0 }}
395
- transition={{ duration: 0.2 }}
396
- >
397
- <td colSpan={columns.length} className="h-24 text-center">
398
- No results found.
399
- </td>
400
- </motion.tr>
401
- )}
402
- </AnimatePresence>
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>