@moontra/moonui-pro 2.3.8 → 2.4.0

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
@@ -3,15 +3,16 @@ import { twMerge } from 'tailwind-merge';
3
3
  import * as t from 'react';
4
4
  import t__default, { useState, useRef, useCallback, forwardRef, createContext, useContext, useMemo, useEffect, useDebugValue, Component, useLayoutEffect } from 'react';
5
5
  import * as AccordionPrimitive from '@radix-ui/react-accordion';
6
- import { ChevronDown, Info, AlertCircle, AlertTriangle, Check, X, MoreHorizontal, Loader2, Minus, Search, ChevronRight, Circle, ChevronUp, Lock, Sparkles, Plus, ChevronLeft, Calendar, Edit, Trash2, Clock, MapPin, User, GripVertical, MessageCircle, Paperclip, Bold as Bold$1, Italic as Italic$1, Underline as Underline$1, Strikethrough, Code as Code$1, Type, Heading1, Heading2, Heading3, AlignLeft, AlignCenter, AlignRight, AlignJustify, List, ListOrdered, CheckSquare, Quote, Palette, Highlighter, Link2, Image as Image$1, Table as Table$1, Settings, Undo, Redo, Eye, RefreshCw, Wand2, Maximize, FileText, Languages, TrendingUp, TrendingDown, Download, Maximize2, Activity, Star, Upload, CheckCircle2, Filter, ArrowUp, ArrowDown, ArrowUpDown, ChevronsLeft, ChevronsRight, ExternalLink, BarChart3, Users, DollarSign, Github, GitFork, Server, EyeOff, ZoomOut, ZoomIn, RotateCw, Zap, Monitor, Timer, Cpu, MemoryStick, HardDrive, Network, CheckCircle, Video, Music, Archive, File, XCircle, ArrowDownRight, ArrowUpRight } from 'lucide-react';
6
+ import { ChevronDown, Info, AlertCircle, AlertTriangle, Check, X, MoreHorizontal, Loader2, Minus, Search, ChevronRight, Circle, ChevronUp, Lock, Sparkles, Plus, ChevronLeft, Calendar, Edit, Trash2, Clock, MapPin, User, GripVertical, MessageCircle, Paperclip, Bold as Bold$1, Italic as Italic$1, Underline as Underline$1, Strikethrough, Code as Code$1, Type, Heading1, Heading2, Heading3, AlignLeft, AlignCenter, AlignRight, AlignJustify, List, ListOrdered, CheckSquare, Quote, Palette, Highlighter, Link2, Image as Image$1, Table as Table$1, Settings, Undo, Redo, Eye, RefreshCw, Wand2, Maximize, FileText, Languages, TrendingUp, TrendingDown, Download, Maximize2, Activity, Star, Upload, CheckCircle2, Filter, FileSpreadsheet, FileJson, FileDown, ArrowUp, ArrowDown, ArrowUpDown, ChevronsLeft, ChevronsRight, ExternalLink, BarChart3, Users, DollarSign, Github, GitFork, Server, EyeOff, ZoomOut, ZoomIn, RotateCw, Zap, Monitor, Timer, Cpu, MemoryStick, HardDrive, Network, CheckCircle, Video, Music, Archive, File, Columns, XCircle, ArrowDownRight, ArrowUpRight } from 'lucide-react';
7
7
  import { jsx, jsxs, Fragment } from 'react/jsx-runtime';
8
8
  import { cva } from 'class-variance-authority';
9
9
  import * as AvatarPrimitive from '@radix-ui/react-avatar';
10
10
  import { motion, AnimatePresence, useMotionValue, useSpring, useTransform, animate } from 'framer-motion';
11
11
  import * as CheckboxPrimitive from '@radix-ui/react-checkbox';
12
12
  import ReactDOM3 from 'react-dom';
13
- import { createSlot } from '@radix-ui/react-slot';
13
+ import { createSlot, createSlottable } from '@radix-ui/react-slot';
14
14
  import * as DialogPrimitive from '@radix-ui/react-dialog';
15
+ import { createDialogScope } from '@radix-ui/react-dialog';
15
16
  import * as DropdownMenuPrimitive from '@radix-ui/react-dropdown-menu';
16
17
  import * as LabelPrimitive from '@radix-ui/react-label';
17
18
  import * as PopoverPrimitive from '@radix-ui/react-popover';
@@ -26,7 +27,7 @@ import { useSyncExternalStoreWithSelector } from 'use-sync-external-store/shim/w
26
27
  import { ResponsiveContainer, ScatterChart, CartesianGrid, XAxis, YAxis, Tooltip, Legend, Scatter, PieChart, Pie, Cell, AreaChart, Area, ReferenceLine, Brush, BarChart, Bar, LineChart, Line, ReferenceArea } from 'recharts';
27
28
  import { DragDropContext, Droppable, Draggable } from '@hello-pangea/dnd';
28
29
  import { useForm } from 'react-hook-form';
29
- import { useReactTable, getCoreRowModel, getPaginationRowModel, getSortedRowModel, getFilteredRowModel, flexRender } from '@tanstack/react-table';
30
+ import { flexRender, useReactTable, getCoreRowModel, getPaginationRowModel, getSortedRowModel, getFilteredRowModel } from '@tanstack/react-table';
30
31
 
31
32
  /**
32
33
  * @moontra/moonui-pro v2.0.9
@@ -51095,7 +51096,7 @@ var PerformanceDebuggerInternal = ({
51095
51096
  return /* @__PURE__ */ jsx(Activity, { className: "h-4 w-4 text-muted-foreground" });
51096
51097
  }
51097
51098
  };
51098
- const exportData = () => {
51099
+ const exportData2 = () => {
51099
51100
  const data = {
51100
51101
  timestamp: (/* @__PURE__ */ new Date()).toISOString(),
51101
51102
  entries,
@@ -51173,7 +51174,7 @@ var PerformanceDebuggerInternal = ({
51173
51174
  {
51174
51175
  variant: "outline",
51175
51176
  size: "sm",
51176
- onClick: exportData,
51177
+ onClick: exportData2,
51177
51178
  children: /* @__PURE__ */ jsx(Download, { className: "h-4 w-4" })
51178
51179
  }
51179
51180
  ),
@@ -52153,6 +52154,562 @@ function FileUpload({
52153
52154
  ] })
52154
52155
  ] });
52155
52156
  }
52157
+ function DataTableColumnToggle({ table, trigger }) {
52158
+ const [search, setSearch] = t__default.useState("");
52159
+ const columns = table.getAllColumns().filter((column) => column.getCanHide());
52160
+ const filteredColumns = t__default.useMemo(() => {
52161
+ if (!search)
52162
+ return columns;
52163
+ return columns.filter((column) => {
52164
+ const header = column.columnDef.header;
52165
+ const headerText = typeof header === "string" ? header : column.id;
52166
+ return headerText.toLowerCase().includes(search.toLowerCase());
52167
+ });
52168
+ }, [columns, search]);
52169
+ const visibleCount = columns.filter((col) => col.getIsVisible()).length;
52170
+ const handleToggleAll = (visible) => {
52171
+ columns.forEach((column) => {
52172
+ column.toggleVisibility(visible);
52173
+ });
52174
+ };
52175
+ return /* @__PURE__ */ jsxs(MoonUIDropdownMenuPro, { children: [
52176
+ /* @__PURE__ */ jsx(MoonUIDropdownMenuTriggerPro, { asChild: true, children: trigger || /* @__PURE__ */ jsxs(MoonUIButtonPro, { variant: "outline", size: "sm", className: "gap-2", children: [
52177
+ /* @__PURE__ */ jsx(Columns, { className: "h-4 w-4" }),
52178
+ "Columns",
52179
+ visibleCount < columns.length && /* @__PURE__ */ jsxs("span", { className: "ml-1 rounded-full bg-primary/10 px-1.5 py-0.5 text-xs", children: [
52180
+ visibleCount,
52181
+ "/",
52182
+ columns.length
52183
+ ] })
52184
+ ] }) }),
52185
+ /* @__PURE__ */ jsxs(MoonUIDropdownMenuContentPro, { align: "end", className: "w-56", children: [
52186
+ /* @__PURE__ */ jsx(MoonUIDropdownMenuLabelPro, { children: "Toggle Columns" }),
52187
+ columns.length > 5 && /* @__PURE__ */ jsxs(Fragment, { children: [
52188
+ /* @__PURE__ */ jsx("div", { className: "px-2 py-1.5", children: /* @__PURE__ */ jsxs("div", { className: "relative", children: [
52189
+ /* @__PURE__ */ jsx(Search, { className: "absolute left-2 top-2.5 h-3 w-3 text-muted-foreground" }),
52190
+ /* @__PURE__ */ jsx(
52191
+ MoonUIInputPro,
52192
+ {
52193
+ placeholder: "Search columns...",
52194
+ value: search,
52195
+ onChange: (e) => setSearch(e.target.value),
52196
+ className: "h-8 pl-7 text-xs"
52197
+ }
52198
+ )
52199
+ ] }) }),
52200
+ /* @__PURE__ */ jsx(MoonUIDropdownMenuSeparatorPro, {})
52201
+ ] }),
52202
+ /* @__PURE__ */ jsxs("div", { className: "flex items-center justify-between px-2 py-1.5", children: [
52203
+ /* @__PURE__ */ jsx(
52204
+ MoonUIButtonPro,
52205
+ {
52206
+ variant: "ghost",
52207
+ size: "sm",
52208
+ className: "h-7 text-xs",
52209
+ onClick: () => handleToggleAll(true),
52210
+ children: "Show all"
52211
+ }
52212
+ ),
52213
+ /* @__PURE__ */ jsx(
52214
+ MoonUIButtonPro,
52215
+ {
52216
+ variant: "ghost",
52217
+ size: "sm",
52218
+ className: "h-7 text-xs",
52219
+ onClick: () => handleToggleAll(false),
52220
+ children: "Hide all"
52221
+ }
52222
+ )
52223
+ ] }),
52224
+ /* @__PURE__ */ jsx(MoonUIDropdownMenuSeparatorPro, {}),
52225
+ /* @__PURE__ */ jsx("div", { className: "max-h-64 overflow-y-auto", children: filteredColumns.length === 0 ? /* @__PURE__ */ jsx("div", { className: "px-2 py-4 text-center text-xs text-muted-foreground", children: "No columns found" }) : filteredColumns.map((column) => {
52226
+ const isVisible = column.getIsVisible();
52227
+ const header = column.columnDef.header;
52228
+ const headerText = typeof header === "string" ? header : column.id;
52229
+ return /* @__PURE__ */ jsx(
52230
+ MoonUIDropdownMenuItemPro,
52231
+ {
52232
+ className: cn(
52233
+ "cursor-pointer",
52234
+ !isVisible && "text-muted-foreground"
52235
+ ),
52236
+ onSelect: (e) => {
52237
+ e.preventDefault();
52238
+ column.toggleVisibility();
52239
+ },
52240
+ children: /* @__PURE__ */ jsxs("div", { className: "flex items-center gap-2 flex-1", children: [
52241
+ /* @__PURE__ */ jsx("div", { className: cn(
52242
+ "flex h-4 w-4 items-center justify-center rounded-sm border",
52243
+ isVisible ? "border-primary bg-primary text-primary-foreground" : "border-muted-foreground"
52244
+ ), children: isVisible && /* @__PURE__ */ jsx(Check, { className: "h-3 w-3" }) }),
52245
+ /* @__PURE__ */ jsx("span", { className: "truncate", children: headerText })
52246
+ ] })
52247
+ },
52248
+ column.id
52249
+ );
52250
+ }) }),
52251
+ columns.length > 0 && /* @__PURE__ */ jsxs(Fragment, { children: [
52252
+ /* @__PURE__ */ jsx(MoonUIDropdownMenuSeparatorPro, {}),
52253
+ /* @__PURE__ */ jsxs("div", { className: "px-2 py-1.5 text-xs text-muted-foreground text-center", children: [
52254
+ visibleCount,
52255
+ " of ",
52256
+ columns.length,
52257
+ " columns visible"
52258
+ ] })
52259
+ ] })
52260
+ ] })
52261
+ ] });
52262
+ }
52263
+ var ROOT_NAME = "AlertDialog";
52264
+ var [createAlertDialogContext, createAlertDialogScope] = createContextScope(ROOT_NAME, [
52265
+ createDialogScope
52266
+ ]);
52267
+ var useDialogScope = createDialogScope();
52268
+ var AlertDialog = (props) => {
52269
+ const { __scopeAlertDialog, ...alertDialogProps } = props;
52270
+ const dialogScope = useDialogScope(__scopeAlertDialog);
52271
+ return /* @__PURE__ */ jsx(DialogPrimitive.Root, { ...dialogScope, ...alertDialogProps, modal: true });
52272
+ };
52273
+ AlertDialog.displayName = ROOT_NAME;
52274
+ var TRIGGER_NAME2 = "AlertDialogTrigger";
52275
+ var AlertDialogTrigger = t.forwardRef(
52276
+ (props, forwardedRef) => {
52277
+ const { __scopeAlertDialog, ...triggerProps } = props;
52278
+ const dialogScope = useDialogScope(__scopeAlertDialog);
52279
+ return /* @__PURE__ */ jsx(DialogPrimitive.Trigger, { ...dialogScope, ...triggerProps, ref: forwardedRef });
52280
+ }
52281
+ );
52282
+ AlertDialogTrigger.displayName = TRIGGER_NAME2;
52283
+ var PORTAL_NAME = "AlertDialogPortal";
52284
+ var AlertDialogPortal = (props) => {
52285
+ const { __scopeAlertDialog, ...portalProps } = props;
52286
+ const dialogScope = useDialogScope(__scopeAlertDialog);
52287
+ return /* @__PURE__ */ jsx(DialogPrimitive.Portal, { ...dialogScope, ...portalProps });
52288
+ };
52289
+ AlertDialogPortal.displayName = PORTAL_NAME;
52290
+ var OVERLAY_NAME = "AlertDialogOverlay";
52291
+ var AlertDialogOverlay = t.forwardRef(
52292
+ (props, forwardedRef) => {
52293
+ const { __scopeAlertDialog, ...overlayProps } = props;
52294
+ const dialogScope = useDialogScope(__scopeAlertDialog);
52295
+ return /* @__PURE__ */ jsx(DialogPrimitive.Overlay, { ...dialogScope, ...overlayProps, ref: forwardedRef });
52296
+ }
52297
+ );
52298
+ AlertDialogOverlay.displayName = OVERLAY_NAME;
52299
+ var CONTENT_NAME2 = "AlertDialogContent";
52300
+ var [AlertDialogContentProvider, useAlertDialogContentContext] = createAlertDialogContext(CONTENT_NAME2);
52301
+ var Slottable = createSlottable("AlertDialogContent");
52302
+ var AlertDialogContent = t.forwardRef(
52303
+ (props, forwardedRef) => {
52304
+ const { __scopeAlertDialog, children, ...contentProps } = props;
52305
+ const dialogScope = useDialogScope(__scopeAlertDialog);
52306
+ const contentRef = t.useRef(null);
52307
+ const composedRefs = useComposedRefs(forwardedRef, contentRef);
52308
+ const cancelRef = t.useRef(null);
52309
+ return /* @__PURE__ */ jsx(
52310
+ DialogPrimitive.WarningProvider,
52311
+ {
52312
+ contentName: CONTENT_NAME2,
52313
+ titleName: TITLE_NAME,
52314
+ docsSlug: "alert-dialog",
52315
+ children: /* @__PURE__ */ jsx(AlertDialogContentProvider, { scope: __scopeAlertDialog, cancelRef, children: /* @__PURE__ */ jsxs(
52316
+ DialogPrimitive.Content,
52317
+ {
52318
+ role: "alertdialog",
52319
+ ...dialogScope,
52320
+ ...contentProps,
52321
+ ref: composedRefs,
52322
+ onOpenAutoFocus: composeEventHandlers(contentProps.onOpenAutoFocus, (event) => {
52323
+ event.preventDefault();
52324
+ cancelRef.current?.focus({ preventScroll: true });
52325
+ }),
52326
+ onPointerDownOutside: (event) => event.preventDefault(),
52327
+ onInteractOutside: (event) => event.preventDefault(),
52328
+ children: [
52329
+ /* @__PURE__ */ jsx(Slottable, { children }),
52330
+ /* @__PURE__ */ jsx(DescriptionWarning, { contentRef })
52331
+ ]
52332
+ }
52333
+ ) })
52334
+ }
52335
+ );
52336
+ }
52337
+ );
52338
+ AlertDialogContent.displayName = CONTENT_NAME2;
52339
+ var TITLE_NAME = "AlertDialogTitle";
52340
+ var AlertDialogTitle = t.forwardRef(
52341
+ (props, forwardedRef) => {
52342
+ const { __scopeAlertDialog, ...titleProps } = props;
52343
+ const dialogScope = useDialogScope(__scopeAlertDialog);
52344
+ return /* @__PURE__ */ jsx(DialogPrimitive.Title, { ...dialogScope, ...titleProps, ref: forwardedRef });
52345
+ }
52346
+ );
52347
+ AlertDialogTitle.displayName = TITLE_NAME;
52348
+ var DESCRIPTION_NAME = "AlertDialogDescription";
52349
+ var AlertDialogDescription = t.forwardRef((props, forwardedRef) => {
52350
+ const { __scopeAlertDialog, ...descriptionProps } = props;
52351
+ const dialogScope = useDialogScope(__scopeAlertDialog);
52352
+ return /* @__PURE__ */ jsx(DialogPrimitive.Description, { ...dialogScope, ...descriptionProps, ref: forwardedRef });
52353
+ });
52354
+ AlertDialogDescription.displayName = DESCRIPTION_NAME;
52355
+ var ACTION_NAME = "AlertDialogAction";
52356
+ var AlertDialogAction = t.forwardRef(
52357
+ (props, forwardedRef) => {
52358
+ const { __scopeAlertDialog, ...actionProps } = props;
52359
+ const dialogScope = useDialogScope(__scopeAlertDialog);
52360
+ return /* @__PURE__ */ jsx(DialogPrimitive.Close, { ...dialogScope, ...actionProps, ref: forwardedRef });
52361
+ }
52362
+ );
52363
+ AlertDialogAction.displayName = ACTION_NAME;
52364
+ var CANCEL_NAME = "AlertDialogCancel";
52365
+ var AlertDialogCancel = t.forwardRef(
52366
+ (props, forwardedRef) => {
52367
+ const { __scopeAlertDialog, ...cancelProps } = props;
52368
+ const { cancelRef } = useAlertDialogContentContext(CANCEL_NAME, __scopeAlertDialog);
52369
+ const dialogScope = useDialogScope(__scopeAlertDialog);
52370
+ const ref = useComposedRefs(forwardedRef, cancelRef);
52371
+ return /* @__PURE__ */ jsx(DialogPrimitive.Close, { ...dialogScope, ...cancelProps, ref });
52372
+ }
52373
+ );
52374
+ AlertDialogCancel.displayName = CANCEL_NAME;
52375
+ var DescriptionWarning = ({ contentRef }) => {
52376
+ const MESSAGE = `\`${CONTENT_NAME2}\` requires a description for the component to be accessible for screen reader users.
52377
+
52378
+ You can add a description to the \`${CONTENT_NAME2}\` by passing a \`${DESCRIPTION_NAME}\` component as a child, which also benefits sighted users by adding visible context to the dialog.
52379
+
52380
+ Alternatively, you can use your own component as a description by assigning it an \`id\` and passing the same value to the \`aria-describedby\` prop in \`${CONTENT_NAME2}\`. If the description is confusing or duplicative for sighted users, you can use the \`@radix-ui/react-visually-hidden\` primitive as a wrapper around your description component.
52381
+
52382
+ For more information, see https://radix-ui.com/primitives/docs/components/alert-dialog`;
52383
+ t.useEffect(() => {
52384
+ const hasDescription = document.getElementById(
52385
+ contentRef.current?.getAttribute("aria-describedby")
52386
+ );
52387
+ if (!hasDescription)
52388
+ console.warn(MESSAGE);
52389
+ }, [MESSAGE, contentRef]);
52390
+ return null;
52391
+ };
52392
+ var Root22 = AlertDialog;
52393
+ var Portal22 = AlertDialogPortal;
52394
+ var Overlay22 = AlertDialogOverlay;
52395
+ var Content22 = AlertDialogContent;
52396
+ var Action2 = AlertDialogAction;
52397
+ var Cancel = AlertDialogCancel;
52398
+ var Title22 = AlertDialogTitle;
52399
+ var Description22 = AlertDialogDescription;
52400
+ var AlertDialog2 = Root22;
52401
+ var AlertDialogPortal2 = Portal22;
52402
+ var AlertDialogOverlay2 = t.forwardRef(({ className, ...props }, ref) => /* @__PURE__ */ jsx(
52403
+ Overlay22,
52404
+ {
52405
+ className: cn(
52406
+ "fixed inset-0 z-50 bg-black/80 data-[state=open]:animate-in data-[state=closed]:animate-out data-[state=closed]:fade-out-0 data-[state=open]:fade-in-0",
52407
+ className
52408
+ ),
52409
+ ...props,
52410
+ ref
52411
+ }
52412
+ ));
52413
+ AlertDialogOverlay2.displayName = Overlay22.displayName;
52414
+ var AlertDialogContent2 = t.forwardRef(({ className, ...props }, ref) => /* @__PURE__ */ jsxs(AlertDialogPortal2, { children: [
52415
+ /* @__PURE__ */ jsx(AlertDialogOverlay2, {}),
52416
+ /* @__PURE__ */ jsx(
52417
+ Content22,
52418
+ {
52419
+ ref,
52420
+ className: cn(
52421
+ "fixed left-[50%] top-[50%] z-50 grid w-full max-w-lg translate-x-[-50%] translate-y-[-50%] gap-4 border bg-background p-6 shadow-lg duration-200 data-[state=open]:animate-in data-[state=closed]:animate-out data-[state=closed]:fade-out-0 data-[state=open]:fade-in-0 data-[state=closed]:zoom-out-95 data-[state=open]:zoom-in-95 data-[state=closed]:slide-out-to-left-1/2 data-[state=closed]:slide-out-to-top-[48%] data-[state=open]:slide-in-from-left-1/2 data-[state=open]:slide-in-from-top-[48%] sm:rounded-lg",
52422
+ className
52423
+ ),
52424
+ ...props
52425
+ }
52426
+ )
52427
+ ] }));
52428
+ AlertDialogContent2.displayName = Content22.displayName;
52429
+ var AlertDialogHeader = ({
52430
+ className,
52431
+ ...props
52432
+ }) => /* @__PURE__ */ jsx(
52433
+ "div",
52434
+ {
52435
+ className: cn(
52436
+ "flex flex-col space-y-2 text-center sm:text-left",
52437
+ className
52438
+ ),
52439
+ ...props
52440
+ }
52441
+ );
52442
+ AlertDialogHeader.displayName = "AlertDialogHeader";
52443
+ var AlertDialogFooter = ({
52444
+ className,
52445
+ ...props
52446
+ }) => /* @__PURE__ */ jsx(
52447
+ "div",
52448
+ {
52449
+ className: cn(
52450
+ "flex flex-col-reverse sm:flex-row sm:justify-end sm:space-x-2",
52451
+ className
52452
+ ),
52453
+ ...props
52454
+ }
52455
+ );
52456
+ AlertDialogFooter.displayName = "AlertDialogFooter";
52457
+ var AlertDialogTitle2 = t.forwardRef(({ className, ...props }, ref) => /* @__PURE__ */ jsx(
52458
+ Title22,
52459
+ {
52460
+ ref,
52461
+ className: cn("text-lg font-semibold", className),
52462
+ ...props
52463
+ }
52464
+ ));
52465
+ AlertDialogTitle2.displayName = Title22.displayName;
52466
+ var AlertDialogDescription2 = t.forwardRef(({ className, ...props }, ref) => /* @__PURE__ */ jsx(
52467
+ Description22,
52468
+ {
52469
+ ref,
52470
+ className: cn("text-sm text-muted-foreground", className),
52471
+ ...props
52472
+ }
52473
+ ));
52474
+ AlertDialogDescription2.displayName = Description22.displayName;
52475
+ var AlertDialogAction2 = t.forwardRef(({ className, ...props }, ref) => /* @__PURE__ */ jsx(
52476
+ Action2,
52477
+ {
52478
+ ref,
52479
+ className: cn(moonUIButtonProVariants(), className),
52480
+ ...props
52481
+ }
52482
+ ));
52483
+ AlertDialogAction2.displayName = Action2.displayName;
52484
+ var AlertDialogCancel2 = t.forwardRef(({ className, ...props }, ref) => /* @__PURE__ */ jsx(
52485
+ Cancel,
52486
+ {
52487
+ ref,
52488
+ className: cn(
52489
+ moonUIButtonProVariants({ variant: "outline" }),
52490
+ "mt-2 sm:mt-0",
52491
+ className
52492
+ ),
52493
+ ...props
52494
+ }
52495
+ ));
52496
+ AlertDialogCancel2.displayName = Cancel.displayName;
52497
+ function DataTableBulkActions({
52498
+ selectedRows,
52499
+ actions,
52500
+ onClearSelection,
52501
+ className
52502
+ }) {
52503
+ const [isLoading, setIsLoading] = t__default.useState(false);
52504
+ const [pendingAction, setPendingAction] = t__default.useState(null);
52505
+ const selectedCount = selectedRows.length;
52506
+ const handleAction = async (action) => {
52507
+ if (action.confirmMessage) {
52508
+ setPendingAction(action);
52509
+ return;
52510
+ }
52511
+ await executeAction(action);
52512
+ };
52513
+ const executeAction = async (action) => {
52514
+ setIsLoading(true);
52515
+ try {
52516
+ await action.action(selectedRows);
52517
+ if (onClearSelection) {
52518
+ onClearSelection();
52519
+ }
52520
+ } catch (error) {
52521
+ console.error("Bulk action failed:", error);
52522
+ } finally {
52523
+ setIsLoading(false);
52524
+ setPendingAction(null);
52525
+ }
52526
+ };
52527
+ const handleConfirm = async () => {
52528
+ if (pendingAction) {
52529
+ await executeAction(pendingAction);
52530
+ }
52531
+ };
52532
+ if (selectedCount === 0) {
52533
+ return null;
52534
+ }
52535
+ return /* @__PURE__ */ jsxs(Fragment, { children: [
52536
+ /* @__PURE__ */ jsxs("div", { className: cn("flex items-center gap-2", className), children: [
52537
+ /* @__PURE__ */ jsxs(MoonUIBadgePro, { variant: "secondary", className: "gap-1", children: [
52538
+ /* @__PURE__ */ jsx("span", { className: "font-semibold", children: selectedCount }),
52539
+ /* @__PURE__ */ jsx("span", { children: "selected" })
52540
+ ] }),
52541
+ /* @__PURE__ */ jsxs(MoonUIDropdownMenuPro, { children: [
52542
+ /* @__PURE__ */ jsx(MoonUIDropdownMenuTriggerPro, { asChild: true, children: /* @__PURE__ */ jsx(
52543
+ MoonUIButtonPro,
52544
+ {
52545
+ variant: "outline",
52546
+ size: "sm",
52547
+ disabled: isLoading,
52548
+ className: "gap-2",
52549
+ children: isLoading ? /* @__PURE__ */ jsxs(Fragment, { children: [
52550
+ /* @__PURE__ */ jsx(Loader2, { className: "h-4 w-4 animate-spin" }),
52551
+ "Processing..."
52552
+ ] }) : /* @__PURE__ */ jsxs(Fragment, { children: [
52553
+ /* @__PURE__ */ jsx(MoreHorizontal, { className: "h-4 w-4" }),
52554
+ "Bulk Actions"
52555
+ ] })
52556
+ }
52557
+ ) }),
52558
+ /* @__PURE__ */ jsxs(MoonUIDropdownMenuContentPro, { align: "end", className: "w-48", children: [
52559
+ actions.map((action, index) => {
52560
+ const isDisabled = typeof action.disabled === "function" ? action.disabled(selectedRows) : action.disabled;
52561
+ return /* @__PURE__ */ jsxs(
52562
+ MoonUIDropdownMenuItemPro,
52563
+ {
52564
+ disabled: isDisabled || isLoading,
52565
+ onSelect: () => handleAction(action),
52566
+ className: cn(
52567
+ "cursor-pointer",
52568
+ action.variant === "destructive" && "text-destructive focus:text-destructive"
52569
+ ),
52570
+ children: [
52571
+ action.icon && /* @__PURE__ */ jsx("span", { className: "mr-2 h-4 w-4", children: action.icon }),
52572
+ action.label
52573
+ ]
52574
+ },
52575
+ index
52576
+ );
52577
+ }),
52578
+ onClearSelection && /* @__PURE__ */ jsxs(Fragment, { children: [
52579
+ /* @__PURE__ */ jsx(MoonUIDropdownMenuSeparatorPro, {}),
52580
+ /* @__PURE__ */ jsx(
52581
+ MoonUIDropdownMenuItemPro,
52582
+ {
52583
+ onSelect: onClearSelection,
52584
+ className: "cursor-pointer text-muted-foreground",
52585
+ children: "Clear selection"
52586
+ }
52587
+ )
52588
+ ] })
52589
+ ] })
52590
+ ] })
52591
+ ] }),
52592
+ /* @__PURE__ */ jsx(
52593
+ AlertDialog2,
52594
+ {
52595
+ open: !!pendingAction,
52596
+ onOpenChange: (open) => !open && setPendingAction(null),
52597
+ children: /* @__PURE__ */ jsxs(AlertDialogContent2, { children: [
52598
+ /* @__PURE__ */ jsxs(AlertDialogHeader, { children: [
52599
+ /* @__PURE__ */ jsxs(AlertDialogTitle2, { className: "flex items-center gap-2", children: [
52600
+ pendingAction?.variant === "destructive" && /* @__PURE__ */ jsx(AlertTriangle, { className: "h-5 w-5 text-destructive" }),
52601
+ pendingAction?.confirmTitle || "Confirm Action"
52602
+ ] }),
52603
+ /* @__PURE__ */ jsx(AlertDialogDescription2, { children: pendingAction?.confirmMessage || `This action will affect ${selectedCount} selected item${selectedCount > 1 ? "s" : ""}. This action cannot be undone.` })
52604
+ ] }),
52605
+ /* @__PURE__ */ jsxs(AlertDialogFooter, { children: [
52606
+ /* @__PURE__ */ jsx(AlertDialogCancel2, { disabled: isLoading, children: "Cancel" }),
52607
+ /* @__PURE__ */ jsx(
52608
+ AlertDialogAction2,
52609
+ {
52610
+ onClick: handleConfirm,
52611
+ disabled: isLoading,
52612
+ className: cn(
52613
+ pendingAction?.variant === "destructive" && "bg-destructive text-destructive-foreground hover:bg-destructive/90"
52614
+ ),
52615
+ children: isLoading ? /* @__PURE__ */ jsxs(Fragment, { children: [
52616
+ /* @__PURE__ */ jsx(Loader2, { className: "mr-2 h-4 w-4 animate-spin" }),
52617
+ "Processing..."
52618
+ ] }) : "Confirm"
52619
+ }
52620
+ )
52621
+ ] })
52622
+ ] })
52623
+ }
52624
+ )
52625
+ ] });
52626
+ }
52627
+
52628
+ // src/components/data-table/data-table-export.ts
52629
+ function dataToCSV(data, columns, includeHeaders = true) {
52630
+ if (data.length === 0)
52631
+ return "";
52632
+ const cols = columns || Object.keys(data[0]);
52633
+ const rows = [];
52634
+ if (includeHeaders) {
52635
+ const headers = cols.map((col) => {
52636
+ const value = String(col);
52637
+ return value.includes(",") || value.includes('"') || value.includes("\n") ? `"${value.replace(/"/g, '""')}"` : value;
52638
+ });
52639
+ rows.push(headers.join(","));
52640
+ }
52641
+ data.forEach((item) => {
52642
+ const row = cols.map((col) => {
52643
+ const value = item[col];
52644
+ if (value === null || value === void 0)
52645
+ return "";
52646
+ if (value instanceof Date)
52647
+ return value.toISOString();
52648
+ if (typeof value === "object")
52649
+ return JSON.stringify(value);
52650
+ const stringValue = String(value);
52651
+ return stringValue.includes(",") || stringValue.includes('"') || stringValue.includes("\n") ? `"${stringValue.replace(/"/g, '""')}"` : stringValue;
52652
+ });
52653
+ rows.push(row.join(","));
52654
+ });
52655
+ return rows.join("\n");
52656
+ }
52657
+ function dataToJSON(data, columns) {
52658
+ if (!columns || columns.length === 0) {
52659
+ return JSON.stringify(data, null, 2);
52660
+ }
52661
+ const filteredData = data.map((item) => {
52662
+ const filtered = {};
52663
+ columns.forEach((col) => {
52664
+ if (col in item) {
52665
+ filtered[col] = item[col];
52666
+ }
52667
+ });
52668
+ return filtered;
52669
+ });
52670
+ return JSON.stringify(filteredData, null, 2);
52671
+ }
52672
+ function downloadFile(content, filename, mimeType) {
52673
+ const blob = new Blob([content], { type: mimeType });
52674
+ const url = URL.createObjectURL(blob);
52675
+ const link = document.createElement("a");
52676
+ link.href = url;
52677
+ link.download = filename;
52678
+ document.body.appendChild(link);
52679
+ link.click();
52680
+ document.body.removeChild(link);
52681
+ URL.revokeObjectURL(url);
52682
+ }
52683
+ async function exportData(data, options) {
52684
+ const { format, filename = "data-export", columns, includeHeaders = true } = options;
52685
+ let content;
52686
+ let mimeType;
52687
+ let extension;
52688
+ switch (format) {
52689
+ case "csv":
52690
+ content = dataToCSV(data, columns, includeHeaders);
52691
+ mimeType = "text/csv;charset=utf-8;";
52692
+ extension = "csv";
52693
+ break;
52694
+ case "json":
52695
+ content = dataToJSON(data, columns);
52696
+ mimeType = "application/json;charset=utf-8;";
52697
+ extension = "json";
52698
+ break;
52699
+ case "xlsx":
52700
+ throw new Error("XLSX export requires additional dependencies. Use CSV format instead.");
52701
+ default:
52702
+ throw new Error(`Unsupported export format: ${format}`);
52703
+ }
52704
+ const finalFilename = `${filename}-${( new Date()).toISOString().split("T")[0]}.${extension}`;
52705
+ downloadFile(content, finalFilename, mimeType);
52706
+ }
52707
+ function getVisibleColumns(columns, columnVisibility) {
52708
+ return columns.filter((col) => {
52709
+ const key = col.id || col.accessorKey;
52710
+ return key && columnVisibility[key] !== false;
52711
+ }).map((col) => col.id || col.accessorKey).filter(Boolean);
52712
+ }
52156
52713
  function DataTable({
52157
52714
  columns,
52158
52715
  data,
@@ -52169,6 +52726,7 @@ function DataTable({
52169
52726
  renderSubComponent,
52170
52727
  expandedRows: controlledExpandedRows,
52171
52728
  onRowExpandChange,
52729
+ bulkActions = [],
52172
52730
  features = {},
52173
52731
  theme = {},
52174
52732
  texts = {},
@@ -52237,7 +52795,12 @@ function DataTable({
52237
52795
  pagination: {
52238
52796
  pageSize: actualPageSize
52239
52797
  }
52240
- }
52798
+ },
52799
+ // Prevent re-renders on state changes
52800
+ autoResetAll: false,
52801
+ autoResetPageIndex: false,
52802
+ autoResetExpanded: false,
52803
+ getRowId: (row) => row.id || row.orderId || Math.random().toString()
52241
52804
  });
52242
52805
  t__default.useEffect(() => {
52243
52806
  if (onRowSelect && selectable) {
@@ -52245,12 +52808,17 @@ function DataTable({
52245
52808
  onRowSelect(selectedRows);
52246
52809
  }
52247
52810
  }, [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
- );
52811
+ table.getState();
52812
+ const rowModel = table.getRowModel();
52813
+ const rowsRef = t__default.useRef(rowModel.rows);
52814
+ t__default.useMemo(() => {
52815
+ const changed = rowsRef.current !== rowModel.rows;
52816
+ if (changed) {
52817
+ rowsRef.current = rowModel.rows;
52818
+ }
52819
+ return changed;
52820
+ }, [rowModel.rows]);
52821
+ const rows = rowsRef.current;
52254
52822
  ({
52255
52823
  sorting: features.sorting !== false,
52256
52824
  filtering: features.filtering !== false || filterable,
@@ -52260,12 +52828,38 @@ function DataTable({
52260
52828
  rowSelection: features.rowSelection !== false || selectable,
52261
52829
  export: features.export !== false || exportable
52262
52830
  });
52263
- const handleExport = () => {
52831
+ const handleExport = async (format) => {
52832
+ const selectedRows = table.getFilteredSelectedRowModel().rows;
52833
+ const dataToExport = selectedRows.length > 0 ? selectedRows.map((row) => row.original) : table.getFilteredRowModel().rows.map((row) => row.original);
52834
+ if (typeof exportable === "object" && exportable.onExport) {
52835
+ exportable.onExport(dataToExport, format);
52836
+ return;
52837
+ }
52264
52838
  if (onExport) {
52265
- const selectedRows = table.getFilteredSelectedRowModel().rows;
52266
- const dataToExport = selectedRows.length > 0 ? selectedRows.map((row) => row.original) : table.getFilteredRowModel().rows.map((row) => row.original);
52267
52839
  onExport(dataToExport);
52840
+ return;
52268
52841
  }
52842
+ const filename = typeof exportable === "object" && exportable.filename ? exportable.filename : "data-export";
52843
+ const visibleColumns = getVisibleColumns(columns, columnVisibility);
52844
+ await exportData(dataToExport, {
52845
+ format,
52846
+ filename,
52847
+ columns: visibleColumns,
52848
+ includeHeaders: true
52849
+ });
52850
+ };
52851
+ const exportFormats = t__default.useMemo(() => {
52852
+ if (!exportable)
52853
+ return [];
52854
+ if (exportable === true)
52855
+ return ["csv", "json"];
52856
+ if (typeof exportable === "object" && exportable.formats) {
52857
+ return exportable.formats;
52858
+ }
52859
+ return ["csv", "json"];
52860
+ }, [exportable]);
52861
+ const clearRowSelection = () => {
52862
+ table.resetRowSelection();
52269
52863
  };
52270
52864
  return /* @__PURE__ */ jsxs("div", { className: cn("moonui-pro-datatable-container flex flex-col gap-4", className), children: [
52271
52865
  /* @__PURE__ */ jsxs("div", { className: "moonui-pro-datatable-toolbar flex items-center justify-between", children: [
@@ -52285,17 +52879,38 @@ function DataTable({
52285
52879
  filterable && /* @__PURE__ */ jsxs(MoonUIButtonPro, { variant: "outline", size: "sm", children: [
52286
52880
  /* @__PURE__ */ jsx("span", { suppressHydrationWarning: true, children: /* @__PURE__ */ jsx(Filter, { className: "mr-2 h-4 w-4" }) }),
52287
52881
  "Filters"
52288
- ] })
52882
+ ] }),
52883
+ selectable && bulkActions.length > 0 && /* @__PURE__ */ jsx(
52884
+ DataTableBulkActions,
52885
+ {
52886
+ selectedRows: table.getFilteredSelectedRowModel().rows.map((row) => row.original),
52887
+ actions: bulkActions,
52888
+ onClearSelection: clearRowSelection
52889
+ }
52890
+ )
52289
52891
  ] }),
52290
52892
  /* @__PURE__ */ jsxs("div", { className: "flex items-center space-x-2", children: [
52291
- exportable && /* @__PURE__ */ jsxs(MoonUIButtonPro, { variant: "outline", size: "sm", onClick: handleExport, children: [
52292
- /* @__PURE__ */ jsx("span", { suppressHydrationWarning: true, children: /* @__PURE__ */ jsx(Download, { className: "mr-2 h-4 w-4" }) }),
52293
- "Export"
52893
+ exportable && exportFormats.length > 0 && /* @__PURE__ */ jsxs(MoonUIDropdownMenuPro, { children: [
52894
+ /* @__PURE__ */ jsx(MoonUIDropdownMenuTriggerPro, { asChild: true, children: /* @__PURE__ */ jsxs(MoonUIButtonPro, { variant: "outline", size: "sm", children: [
52895
+ /* @__PURE__ */ jsx("span", { suppressHydrationWarning: true, children: /* @__PURE__ */ jsx(Download, { className: "mr-2 h-4 w-4" }) }),
52896
+ "Export"
52897
+ ] }) }),
52898
+ /* @__PURE__ */ jsxs(MoonUIDropdownMenuContentPro, { align: "end", children: [
52899
+ exportFormats.includes("csv") && /* @__PURE__ */ jsxs(MoonUIDropdownMenuItemPro, { onClick: () => handleExport("csv"), children: [
52900
+ /* @__PURE__ */ jsx(FileSpreadsheet, { className: "mr-2 h-4 w-4" }),
52901
+ "Export as CSV"
52902
+ ] }),
52903
+ exportFormats.includes("json") && /* @__PURE__ */ jsxs(MoonUIDropdownMenuItemPro, { onClick: () => handleExport("json"), children: [
52904
+ /* @__PURE__ */ jsx(FileJson, { className: "mr-2 h-4 w-4" }),
52905
+ "Export as JSON"
52906
+ ] }),
52907
+ exportFormats.includes("xlsx") && /* @__PURE__ */ jsxs(MoonUIDropdownMenuItemPro, { onClick: () => handleExport("xlsx"), children: [
52908
+ /* @__PURE__ */ jsx(FileDown, { className: "mr-2 h-4 w-4" }),
52909
+ "Export as Excel"
52910
+ ] })
52911
+ ] })
52294
52912
  ] }),
52295
- /* @__PURE__ */ jsxs(MoonUIButtonPro, { variant: "outline", size: "sm", children: [
52296
- /* @__PURE__ */ jsx("span", { suppressHydrationWarning: true, children: /* @__PURE__ */ jsx(Settings, { className: "mr-2 h-4 w-4" }) }),
52297
- "Columns"
52298
- ] })
52913
+ /* @__PURE__ */ jsx(DataTableColumnToggle, { table })
52299
52914
  ] })
52300
52915
  ] }),
52301
52916
  /* @__PURE__ */ jsx("div", { className: "moonui-pro-datatable-wrapper rounded-md border overflow-hidden", style: { contain: "layout style" }, children: /* @__PURE__ */ jsx("div", { style: { overflowX: "auto" }, children: /* @__PURE__ */ jsxs("table", { className: "moonui-pro-datatable", style: { width: "100%", tableLayout: "auto" }, children: [
@@ -52336,66 +52951,17 @@ function DataTable({
52336
52951
  ) : rows?.length ? /* @__PURE__ */ jsx(Fragment, { children: rows.map((row, index) => {
52337
52952
  const rowId = row.original.id || row.id;
52338
52953
  const isExpanded = enableExpandable && expandedRows.has(rowId);
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
- ) })
52395
- },
52396
- `${row.id}-expanded`
52397
- ) })
52398
- ] }, rowId);
52954
+ return /* @__PURE__ */ jsx(
52955
+ TableRow2,
52956
+ {
52957
+ row,
52958
+ columns,
52959
+ isExpanded,
52960
+ enableExpandable,
52961
+ renderSubComponent
52962
+ },
52963
+ rowId
52964
+ );
52399
52965
  }) }) : /* @__PURE__ */ jsx(
52400
52966
  motion.tr,
52401
52967
  {
@@ -52567,6 +53133,44 @@ function useExpandableRows(initialExpanded = /* @__PURE__ */ new Set()) {
52567
53133
  collapseAll
52568
53134
  };
52569
53135
  }
53136
+ var TableRow2 = t__default.memo(({
53137
+ row,
53138
+ columns,
53139
+ isExpanded,
53140
+ enableExpandable,
53141
+ renderSubComponent
53142
+ }) => {
53143
+ const rowId = row.original.id || row.id;
53144
+ return /* @__PURE__ */ jsxs(Fragment, { children: [
53145
+ /* @__PURE__ */ jsx(
53146
+ "tr",
53147
+ {
53148
+ className: cn(
53149
+ "border-b transition-colors hover:bg-muted/50",
53150
+ row.getIsSelected() && "bg-muted",
53151
+ isExpanded && "border-b-0"
53152
+ ),
53153
+ 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))
53154
+ }
53155
+ ),
53156
+ isExpanded && renderSubComponent && /* @__PURE__ */ jsx("tr", { className: "border-b", children: /* @__PURE__ */ jsx("td", { colSpan: columns.length, className: "p-0 overflow-hidden", children: /* @__PURE__ */ jsx(
53157
+ "div",
53158
+ {
53159
+ className: "transition-all duration-300 ease-out",
53160
+ style: {
53161
+ maxHeight: isExpanded ? "1000px" : "0",
53162
+ opacity: isExpanded ? 1 : 0
53163
+ },
53164
+ children: /* @__PURE__ */ jsx("div", { className: "border-t border-border/50", children: renderSubComponent({ row: { original: row.original, id: rowId } }) })
53165
+ }
53166
+ ) }) })
53167
+ ] });
53168
+ }, (prevProps, nextProps) => {
53169
+ const prevRowId = prevProps.row.original.id || prevProps.row.id;
53170
+ const nextRowId = nextProps.row.original.id || nextProps.row.id;
53171
+ return prevRowId === nextRowId && prevProps.isExpanded === nextProps.isExpanded && prevProps.row.getIsSelected() === nextProps.row.getIsSelected();
53172
+ });
53173
+ TableRow2.displayName = "TableRow";
52570
53174
 
52571
53175
  // src/components/enhanced/index.ts
52572
53176
  var enhanced_exports = {};