@wordrhyme/auto-crud 1.6.0 → 1.7.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.js CHANGED
@@ -2,12 +2,13 @@ import * as React from "react";
2
2
  import { forwardRef, useCallback, useEffect, useImperativeHandle, useMemo, useReducer, useRef, useState, useSyncExternalStore } from "react";
3
3
  import { ArrowDownUp, BadgeCheck, CalendarIcon, Check, CheckCircle2, ChevronDown, ChevronLeft, ChevronRight, ChevronUp, ChevronsLeft, ChevronsRight, ChevronsUpDown, CommandIcon, Download, Ellipsis, EyeOff, FileDown, FileSpreadsheetIcon, GripVertical, ListFilter, ListFilterIcon, Loader2, PlusCircle, RefreshCw, Settings2, Text, Trash2, Upload, X, XCircle } from "lucide-react";
4
4
  import { flexRender, getCoreRowModel, getFacetedMinMaxValues, getFacetedRowModel, getFacetedUniqueValues, getFilteredRowModel, getPaginationRowModel, getSortedRowModel, useReactTable } from "@tanstack/react-table";
5
- import { AlertDialog, AlertDialogAction, AlertDialogCancel, AlertDialogContent, AlertDialogDescription, AlertDialogFooter, AlertDialogHeader, AlertDialogTitle, Badge, Button, Calendar, Checkbox, Command, CommandEmpty, CommandGroup, CommandInput, CommandItem, CommandList, Dialog, DialogContent, DialogDescription, DialogHeader, DialogTitle, DropdownMenu, DropdownMenuCheckboxItem, DropdownMenuContent, DropdownMenuItem, DropdownMenuRadioGroup, DropdownMenuRadioItem, DropdownMenuSeparator, DropdownMenuTrigger, Input, Label, Popover, PopoverContent, PopoverTrigger, Select as Select$1, SelectContent, SelectItem, SelectTrigger, SelectValue, Separator, Sheet, SheetContent, SheetDescription, SheetHeader, SheetTitle, Slider, Switch, Table as Table$1, TableBody, TableCell, TableHead, TableHeader, TableRow, cn as cn$1 } from "@wordrhyme/shadcn";
5
+ import { AlertDialog, AlertDialogAction, AlertDialogCancel, AlertDialogContent, AlertDialogDescription, AlertDialogFooter, AlertDialogHeader, AlertDialogTitle, Badge, Button, Calendar, Checkbox, Command, CommandEmpty, CommandGroup, CommandInput, CommandItem, CommandList, Dialog, DialogContent, DialogDescription, DialogHeader, DialogTitle, DropdownMenu, DropdownMenuCheckboxItem, DropdownMenuContent, DropdownMenuItem, DropdownMenuRadioGroup, DropdownMenuRadioItem, DropdownMenuTrigger, Input, Label, Popover, PopoverContent, PopoverTrigger, Select as Select$1, SelectContent, SelectItem, SelectTrigger, SelectValue, Separator, Sheet, SheetContent, SheetHeader, SheetTitle, Slider, Switch, Table as Table$1, TableBody, TableCell, TableHead, TableHeader, TableRow, cn as cn$1 } from "@wordrhyme/shadcn";
6
6
  import { clsx } from "clsx";
7
7
  import { twMerge } from "tailwind-merge";
8
8
  import { Fragment, jsx, jsxs } from "react/jsx-runtime";
9
9
  import { customAlphabet } from "nanoid";
10
10
  import { ActionBar, ActionBarClose, ActionBarGroup, ActionBarItem, ActionBarSelection, ActionBarSeparator, Faceted, FacetedBadgeList, FacetedContent, FacetedEmpty, FacetedGroup, FacetedInput, FacetedItem, FacetedList, FacetedTrigger, MultiCombobox, Select, Select as Select$2, Sortable, SortableContent, SortableItem, SortableItemHandle, SortableOverlay } from "@wordrhyme/shadcn-ui";
11
+ import { Dialog as Dialog$1, DialogContent as DialogContent$1, DialogDescription as DialogDescription$1, DialogHeader as DialogHeader$1, DialogTitle as DialogTitle$1, DropdownMenu as DropdownMenu$1, DropdownMenuContent as DropdownMenuContent$1, DropdownMenuItem as DropdownMenuItem$1, DropdownMenuSeparator, DropdownMenuTrigger as DropdownMenuTrigger$1, Sheet as Sheet$1, SheetContent as SheetContent$1, SheetDescription, SheetHeader as SheetHeader$1, SheetTitle as SheetTitle$1 } from "@wordrhyme/ui";
11
12
  import { z } from "zod";
12
13
  import { createForm } from "@formily/core";
13
14
  import { action, observable } from "@formily/reactive";
@@ -458,8 +459,14 @@ function formatDate(date, opts = {}, preset) {
458
459
 
459
460
  //#endregion
460
461
  //#region src/components/data-table/data-table.tsx
461
- function DataTable({ table, actionBar, children, className,...props }) {
462
+ function DataTable({ table, actionBar, children, className, classNames,...props }) {
462
463
  useDateFormatterVersion();
464
+ const columns = [
465
+ ...table.getLeftVisibleLeafColumns(),
466
+ ...table.getCenterVisibleLeafColumns(),
467
+ ...table.getRightVisibleLeafColumns()
468
+ ];
469
+ const hasWidthCap = columns.some((column) => (column.columnDef.maxSize ?? Number.MAX_SAFE_INTEGER) < Number.MAX_SAFE_INTEGER);
463
470
  return /* @__PURE__ */ jsxs("div", {
464
471
  className: cn("flex w-full flex-col gap-2.5 overflow-auto", className),
465
472
  ...props,
@@ -467,21 +474,53 @@ function DataTable({ table, actionBar, children, className,...props }) {
467
474
  children,
468
475
  /* @__PURE__ */ jsx("div", {
469
476
  className: "overflow-hidden rounded-md border",
470
- children: /* @__PURE__ */ jsxs(Table$1, { children: [/* @__PURE__ */ jsx(TableHeader, { children: table.getHeaderGroups().map((headerGroup) => /* @__PURE__ */ jsx(TableRow, { children: headerGroup.headers.map((header) => /* @__PURE__ */ jsx(TableHead, {
471
- colSpan: header.colSpan,
472
- style: { ...getColumnPinningStyle({ column: header.column }) },
473
- children: header.isPlaceholder ? null : flexRender(header.column.columnDef.header, header.getContext())
474
- }, header.id)) }, headerGroup.id)) }), /* @__PURE__ */ jsx(TableBody, { children: table.getRowModel().rows?.length ? table.getRowModel().rows.map((row) => /* @__PURE__ */ jsx(TableRow, {
475
- "data-state": row.getIsSelected() && "selected",
476
- children: row.getVisibleCells().map((cell) => /* @__PURE__ */ jsx(TableCell, {
477
- style: { ...getColumnPinningStyle({ column: cell.column }) },
478
- children: flexRender(cell.column.columnDef.cell, cell.getContext())
479
- }, cell.id))
480
- }, row.id)) : /* @__PURE__ */ jsx(TableRow, { children: /* @__PURE__ */ jsx(TableCell, {
481
- colSpan: table.getAllColumns().length,
482
- className: "h-24 text-center",
483
- children: "No results."
484
- }) }) })] })
477
+ children: /* @__PURE__ */ jsxs(Table$1, {
478
+ className: classNames?.table,
479
+ style: hasWidthCap ? {
480
+ tableLayout: "fixed",
481
+ width: columns.reduce((width, column) => width + column.getSize(), 0)
482
+ } : void 0,
483
+ children: [
484
+ hasWidthCap && /* @__PURE__ */ jsx("colgroup", { children: columns.map((column) => /* @__PURE__ */ jsx("col", { style: { width: column.getSize() } }, column.id)) }),
485
+ /* @__PURE__ */ jsx(TableHeader, {
486
+ className: classNames?.thead,
487
+ children: table.getHeaderGroups().map((headerGroup) => /* @__PURE__ */ jsx(TableRow, {
488
+ className: classNames?.tr,
489
+ children: headerGroup.headers.map((header) => {
490
+ const columnClassName = header.column.columnDef.meta?.classNames?.th;
491
+ return /* @__PURE__ */ jsx(TableHead, {
492
+ colSpan: header.colSpan,
493
+ className: cn(hasWidthCap && "overflow-hidden text-ellipsis", classNames?.th, typeof columnClassName === "string" ? columnClassName : void 0),
494
+ style: { ...getColumnPinningStyle({ column: header.column }) },
495
+ children: header.isPlaceholder ? null : flexRender(header.column.columnDef.header, header.getContext())
496
+ }, header.id);
497
+ })
498
+ }, headerGroup.id))
499
+ }),
500
+ /* @__PURE__ */ jsx(TableBody, {
501
+ className: classNames?.tbody,
502
+ children: table.getRowModel().rows?.length ? table.getRowModel().rows.map((row) => /* @__PURE__ */ jsx(TableRow, {
503
+ className: classNames?.tr,
504
+ "data-state": row.getIsSelected() && "selected",
505
+ children: row.getVisibleCells().map((cell) => {
506
+ const columnClassName = cell.column.columnDef.meta?.classNames?.td;
507
+ return /* @__PURE__ */ jsx(TableCell, {
508
+ className: cn(hasWidthCap && "overflow-hidden text-ellipsis", classNames?.td, typeof columnClassName === "string" ? columnClassName : void 0),
509
+ style: { ...getColumnPinningStyle({ column: cell.column }) },
510
+ children: flexRender(cell.column.columnDef.cell, cell.getContext())
511
+ }, cell.id);
512
+ })
513
+ }, row.id)) : /* @__PURE__ */ jsx(TableRow, {
514
+ className: classNames?.tr,
515
+ children: /* @__PURE__ */ jsx(TableCell, {
516
+ colSpan: table.getAllColumns().length,
517
+ className: cn("h-24 text-center", classNames?.td),
518
+ children: "No results."
519
+ })
520
+ })
521
+ })
522
+ ]
523
+ })
485
524
  }),
486
525
  /* @__PURE__ */ jsxs("div", {
487
526
  className: "flex flex-col gap-2.5",
@@ -3375,10 +3414,7 @@ function renderCell(value, type, options) {
3375
3414
  className: "tabular-nums",
3376
3415
  children: String(value)
3377
3416
  });
3378
- default: return /* @__PURE__ */ jsx("span", {
3379
- className: "truncate max-w-48",
3380
- children: String(value)
3381
- });
3417
+ default: return /* @__PURE__ */ jsx("span", { children: String(value) });
3382
3418
  }
3383
3419
  }
3384
3420
  /**
@@ -3464,33 +3500,38 @@ function createSelectColumn() {
3464
3500
  size: 40
3465
3501
  };
3466
3502
  }
3503
+ function ActionsCell({ row, column }) {
3504
+ const items = column.columnDef.meta?.rowActions ?? [];
3505
+ const renderActionComponent = (item) => {
3506
+ if (!item.component) return null;
3507
+ return typeof item.component === "function" ? item.component(item.getContext?.(row.original)) : item.component;
3508
+ };
3509
+ return /* @__PURE__ */ jsxs(DropdownMenu$1, { children: [/* @__PURE__ */ jsx(DropdownMenuTrigger$1, {
3510
+ asChild: true,
3511
+ children: /* @__PURE__ */ jsx(Button, {
3512
+ "aria-label": "Open menu",
3513
+ variant: "ghost",
3514
+ className: "flex size-8 p-0 data-[state=open]:bg-muted",
3515
+ children: /* @__PURE__ */ jsx(Ellipsis, { className: "size-4" })
3516
+ })
3517
+ }), /* @__PURE__ */ jsx(DropdownMenuContent$1, {
3518
+ align: "end",
3519
+ className: "w-40",
3520
+ children: items.map((item, i) => /* @__PURE__ */ jsxs(React.Fragment, { children: [item.separator && /* @__PURE__ */ jsx(DropdownMenuSeparator, {}), item.component ? renderActionComponent(item) : item.label && item.onClick ? /* @__PURE__ */ jsx(DropdownMenuItem$1, {
3521
+ className: item.variant === "destructive" ? "text-destructive" : "",
3522
+ onClick: () => item.onClick?.(row.original),
3523
+ children: item.label
3524
+ }) : null] }, i))
3525
+ })] });
3526
+ }
3467
3527
  /**
3468
3528
  * 创建操作列
3469
3529
  */
3470
3530
  function createActionsColumn(items) {
3471
- const renderActionComponent = (item, row) => {
3472
- if (!item.component) return null;
3473
- return typeof item.component === "function" ? item.component(item.getContext?.(row.original)) : item.component;
3474
- };
3475
3531
  return {
3476
3532
  id: "actions",
3477
- cell: ({ row }) => /* @__PURE__ */ jsxs(DropdownMenu, { children: [/* @__PURE__ */ jsx(DropdownMenuTrigger, {
3478
- asChild: true,
3479
- children: /* @__PURE__ */ jsx(Button, {
3480
- "aria-label": "Open menu",
3481
- variant: "ghost",
3482
- className: "flex size-8 p-0 data-[state=open]:bg-muted",
3483
- children: /* @__PURE__ */ jsx(Ellipsis, { className: "size-4" })
3484
- })
3485
- }), /* @__PURE__ */ jsx(DropdownMenuContent, {
3486
- align: "end",
3487
- className: "w-40",
3488
- children: items.map((item, i) => /* @__PURE__ */ jsxs(React.Fragment, { children: [item.separator && /* @__PURE__ */ jsx(DropdownMenuSeparator, {}), item.component ? renderActionComponent(item, row) : item.label && item.onClick ? /* @__PURE__ */ jsx(DropdownMenuItem, {
3489
- className: item.variant === "destructive" ? "text-destructive" : "",
3490
- onClick: () => item.onClick?.(row.original),
3491
- children: item.label
3492
- }) : null] }, i))
3493
- })] }),
3533
+ cell: ActionsCell,
3534
+ meta: { rowActions: items },
3494
3535
  size: 40
3495
3536
  };
3496
3537
  }
@@ -4169,7 +4210,7 @@ const filterModeConfig = {
4169
4210
  tooltip: "Linear-style command filters"
4170
4211
  }
4171
4212
  };
4172
- function AutoTable({ schema, data, pageCount = 1, total, overrides, enableRowSelection = true, exclude, actions, pinnedColumns, filterMode, search = false, onDeleteSelected, onUpdateSelected, batchUpdateFields, actionBarExtra, actionBarActions, deleteConfirmation, initialSorting, enableExport = true, showDefaultExport = true, onSelectedCountChange, onSelectedRowsChange, getSelectedRows }) {
4213
+ function AutoTable({ schema, data, pageCount = 1, total, overrides, classNames, enableRowSelection = true, exclude, actions, pinnedColumns, filterMode, search = false, onDeleteSelected, onUpdateSelected, batchUpdateFields, actionBarExtra, actionBarActions, deleteConfirmation, initialSorting, enableExport = true, showDefaultExport = true, onSelectedCountChange, onSelectedRowsChange, getSelectedRows }) {
4173
4214
  const modes = filterMode ? Array.isArray(filterMode) ? filterMode : [filterMode] : DEFAULT_MODES;
4174
4215
  const [currentMode, setCurrentMode] = useQueryState("filterMode", parseAsStringEnum(modes).withDefault(modes[0] ?? "simple"));
4175
4216
  const showToggle = modes.length > 1;
@@ -4331,7 +4372,10 @@ function AutoTable({ schema, data, pageCount = 1, total, overrides, enableRowSel
4331
4372
  ]
4332
4373
  })]
4333
4374
  }),
4334
- /* @__PURE__ */ jsx(DataTable, { table }),
4375
+ /* @__PURE__ */ jsx(DataTable, {
4376
+ table,
4377
+ classNames
4378
+ }),
4335
4379
  enableRowSelection && /* @__PURE__ */ jsx(AutoTableActionBar, {
4336
4380
  table,
4337
4381
  onDeleteSelected,
@@ -4351,16 +4395,16 @@ function AutoTable({ schema, data, pageCount = 1, total, overrides, enableRowSel
4351
4395
  //#endregion
4352
4396
  //#region src/components/auto-crud/form-modal.tsx
4353
4397
  function FormModal({ open, onOpenChange, title, description, children, variant = "dialog", side = "right", className, footer }) {
4354
- if (variant === "sheet") return /* @__PURE__ */ jsx(Sheet, {
4398
+ if (variant === "sheet") return /* @__PURE__ */ jsx(Sheet$1, {
4355
4399
  open,
4356
4400
  onOpenChange,
4357
- children: /* @__PURE__ */ jsxs(SheetContent, {
4401
+ children: /* @__PURE__ */ jsxs(SheetContent$1, {
4358
4402
  side,
4359
4403
  className: cn("sm:max-w-lg flex flex-col p-0", className),
4360
4404
  children: [
4361
- /* @__PURE__ */ jsxs(SheetHeader, {
4405
+ /* @__PURE__ */ jsxs(SheetHeader$1, {
4362
4406
  className: "flex-shrink-0 px-6 pt-6",
4363
- children: [/* @__PURE__ */ jsx(SheetTitle, { children: title }), description && /* @__PURE__ */ jsx(SheetDescription, { children: description })]
4407
+ children: [/* @__PURE__ */ jsx(SheetTitle$1, { children: title }), description && /* @__PURE__ */ jsx(SheetDescription, { children: description })]
4364
4408
  }),
4365
4409
  /* @__PURE__ */ jsx("div", {
4366
4410
  className: "flex-1 overflow-y-auto min-h-0",
@@ -4376,15 +4420,15 @@ function FormModal({ open, onOpenChange, title, description, children, variant =
4376
4420
  ]
4377
4421
  })
4378
4422
  });
4379
- return /* @__PURE__ */ jsx(Dialog, {
4423
+ return /* @__PURE__ */ jsx(Dialog$1, {
4380
4424
  open,
4381
4425
  onOpenChange,
4382
- children: /* @__PURE__ */ jsxs(DialogContent, {
4426
+ children: /* @__PURE__ */ jsxs(DialogContent$1, {
4383
4427
  className: cn("max-w-2xl sm:max-w-2xl flex flex-col max-h-[85vh] overflow-hidden p-0", className),
4384
4428
  children: [
4385
- /* @__PURE__ */ jsxs(DialogHeader, {
4429
+ /* @__PURE__ */ jsxs(DialogHeader$1, {
4386
4430
  className: "flex-shrink-0 px-6 pt-6",
4387
- children: [/* @__PURE__ */ jsx(DialogTitle, { children: title }), description && /* @__PURE__ */ jsx(DialogDescription, { children: description })]
4431
+ children: [/* @__PURE__ */ jsx(DialogTitle$1, { children: title }), description && /* @__PURE__ */ jsx(DialogDescription$1, { children: description })]
4388
4432
  }),
4389
4433
  /* @__PURE__ */ jsx("div", {
4390
4434
  className: "flex-1 overflow-y-auto min-h-0",
@@ -5560,6 +5604,31 @@ function CrudFormModal({ open, onOpenChange, mode, schema, initialValues, onSubm
5560
5604
  });
5561
5605
  }
5562
5606
 
5607
+ //#endregion
5608
+ //#region src/lib/row-action-dialog.tsx
5609
+ /** Keep custom dialogs at table level, independently of the source row's lifetime. */
5610
+ function useRowActionDialog() {
5611
+ const [dialog, setDialog] = React.useState(null);
5612
+ const session = React.useRef(0);
5613
+ return {
5614
+ openComponent: React.useCallback((next) => {
5615
+ const id = ++session.current;
5616
+ const dismiss = () => {
5617
+ if (session.current === id) setDialog(null);
5618
+ };
5619
+ setDialog(React.cloneElement(next, {
5620
+ key: id,
5621
+ open: true,
5622
+ onOpenChange: (open) => {
5623
+ if (!open) dismiss();
5624
+ },
5625
+ onDismiss: dismiss
5626
+ }));
5627
+ }, []),
5628
+ dialog
5629
+ };
5630
+ }
5631
+
5563
5632
  //#endregion
5564
5633
  //#region src/components/auto-crud/import-dialog.tsx
5565
5634
  function ImportDialog({ open, onOpenChange, onImport, columns = [], title, locale = zhCN.importDialog }) {
@@ -5916,22 +5985,29 @@ function isCustomAction$1(action$1) {
5916
5985
  return action$1.type === "custom";
5917
5986
  }
5918
5987
  function resolveActions$1(targetId, zone, ownerActions) {
5919
- const baseActions = ownerActions.filter((action$1) => !action$1.hidden).map((action$1) => withoutRegistryMeta(action$1));
5920
- if (!targetId) return baseActions;
5921
- const registered = crudActions.get(targetId, zone);
5988
+ const registered = targetId ? crudActions.get(targetId, zone) : [];
5989
+ const hiddenCustomIds = new Set(registered.flatMap(({ action: action$1 }) => isCustomAction$1(action$1) && action$1.hidden && action$1.id ? [action$1.id] : []));
5990
+ const isMaskedCustom = (action$1) => isCustomAction$1(action$1) && Boolean(action$1.id && hiddenCustomIds.has(action$1.id));
5991
+ const customOverrides = /* @__PURE__ */ new Map();
5992
+ for (const entry of registered) {
5993
+ const { action: action$1 } = entry;
5994
+ if (isCustomAction$1(action$1) && action$1.id && !isMaskedCustom(action$1)) customOverrides.set(action$1.id, entry);
5995
+ }
5996
+ const ownerCustomIds = new Set(ownerActions.flatMap((action$1) => isCustomAction$1(action$1) && action$1.id ? [action$1.id] : []));
5997
+ const baseActions = ownerActions.filter((action$1) => !action$1.hidden && !isMaskedCustom(action$1)).map((action$1) => withoutRegistryMeta(isCustomAction$1(action$1) && action$1.id ? customOverrides.get(action$1.id)?.action ?? action$1 : action$1));
5998
+ const isReplacedCustom = ({ action: action$1, seq: seq$1 }) => isCustomAction$1(action$1) && Boolean(action$1.id && (ownerCustomIds.has(action$1.id) || customOverrides.get(action$1.id)?.seq !== seq$1));
5922
5999
  if (registered.length === 0) return baseActions;
5923
6000
  const nextActions = [...baseActions];
5924
6001
  const startCustomActions = [];
5925
6002
  const endCustomActions = [];
6003
+ const groups = /* @__PURE__ */ new Map();
5926
6004
  for (const entry of registered) {
6005
+ if (isMaskedCustom(entry.action)) continue;
6006
+ const group = groups.get(entry.ownerId) ?? [];
6007
+ group.push(entry);
6008
+ groups.set(entry.ownerId, group);
5927
6009
  const action$1 = entry.action;
5928
- if (action$1.hidden && isCustomAction$1(action$1)) continue;
5929
- if (isCustomAction$1(action$1)) {
5930
- const custom = withoutRegistryMeta(action$1);
5931
- if (custom.position === "start") startCustomActions.push(custom);
5932
- else endCustomActions.push(custom);
5933
- continue;
5934
- }
6010
+ if (isCustomAction$1(action$1)) continue;
5935
6011
  const existingIndex = nextActions.findIndex((item) => item.type === action$1.type);
5936
6012
  if (action$1.hidden) {
5937
6013
  if (existingIndex >= 0) nextActions.splice(existingIndex, 1);
@@ -5944,6 +6020,31 @@ function resolveActions$1(targetId, zone, ownerActions) {
5944
6020
  };
5945
6021
  else nextActions.push(builtin);
5946
6022
  }
6023
+ for (const group of groups.values()) {
6024
+ const items = group.sort((left, right) => left.seq - right.seq).flatMap((entry) => {
6025
+ const { action: action$1 } = entry;
6026
+ if (action$1.hidden || isReplacedCustom(entry)) return [];
6027
+ if (isCustomAction$1(action$1)) return [withoutRegistryMeta(action$1)];
6028
+ const builtin = nextActions.find((item) => item.type === action$1.type);
6029
+ return builtin ? [builtin] : [];
6030
+ });
6031
+ const firstBuiltin = items.find((item) => !isCustomAction$1(item));
6032
+ if (firstBuiltin) {
6033
+ let cursor = nextActions.indexOf(firstBuiltin);
6034
+ for (const item of items) {
6035
+ const existing = nextActions.indexOf(item);
6036
+ if (existing >= cursor) cursor = existing + 1;
6037
+ else {
6038
+ if (existing >= 0) {
6039
+ nextActions.splice(existing, 1);
6040
+ cursor -= 1;
6041
+ }
6042
+ nextActions.splice(cursor, 0, item);
6043
+ cursor += 1;
6044
+ }
6045
+ }
6046
+ } else for (const custom of items) (custom.position === "start" ? startCustomActions : endCustomActions).push(custom);
6047
+ }
5947
6048
  return [
5948
6049
  ...startCustomActions,
5949
6050
  ...nextActions,
@@ -6572,6 +6673,7 @@ function buildTableOverrides(fields, legacyOverrides, dynamicFilterState, dynami
6572
6673
  const mergedSharedDynamicOptions = mergeFieldOptions(dynamicFilterLabelOptions, tableConfig?.dataSource ? void 0 : dynamicResolveOptions);
6573
6674
  const dynamicOptions = !fieldOptions && mergedSharedDynamicOptions ? toTableOptions(mergedSharedDynamicOptions) : void 0;
6574
6675
  const tableMeta = config.table !== false && typeof config.table === "object" ? config.table.meta : void 0;
6676
+ const tableClassNames = tableConfig?.classNames;
6575
6677
  const fieldEnumMeta = tableOptions ? {
6576
6678
  options: tableOptions,
6577
6679
  variant: "multiSelect"
@@ -6611,13 +6713,14 @@ function buildTableOverrides(fields, legacyOverrides, dynamicFilterState, dynami
6611
6713
  enableColumnFilter: false
6612
6714
  };
6613
6715
  }
6614
- if (fieldEnumMeta || fieldDataSourceMeta || tableMeta || filterMeta) result[key] = {
6716
+ if (fieldEnumMeta || fieldDataSourceMeta || tableMeta || tableClassNames !== void 0 || filterMeta) result[key] = {
6615
6717
  ...result[key],
6616
6718
  meta: {
6617
6719
  ...result[key]?.meta ?? {},
6618
6720
  ...fieldEnumMeta ?? {},
6619
6721
  ...fieldDataSourceMeta ?? {},
6620
6722
  ...tableMeta ?? {},
6723
+ ...tableClassNames !== void 0 ? { classNames: tableClassNames } : {},
6621
6724
  ...filterMeta ?? {}
6622
6725
  }
6623
6726
  };
@@ -6635,6 +6738,7 @@ function buildTableOverrides(fields, legacyOverrides, dynamicFilterState, dynami
6635
6738
  };
6636
6739
  else if (config.table && typeof config.table === "object") {
6637
6740
  const { meta, display,...tableProps } = config.table;
6741
+ delete tableProps.classNames;
6638
6742
  delete tableProps.options;
6639
6743
  delete tableProps.dataSource;
6640
6744
  result[key] = {
@@ -6667,7 +6771,7 @@ function buildCapabilityTableOverrides(schema, capabilities) {
6667
6771
  const override = {};
6668
6772
  if (capabilities.filters) {
6669
6773
  if (!capabilities.filters.enabled) override.enableColumnFilter = false;
6670
- else if (filterSet) override.enableColumnFilter = filterSet.has(key);
6774
+ else if (filterSet && !filterSet.has(key)) override.enableColumnFilter = false;
6671
6775
  }
6672
6776
  if (capabilities.sort) {
6673
6777
  if (!capabilities.sort.enabled) override.enableSorting = false;
@@ -6791,6 +6895,21 @@ function renderFieldValue(value, type, booleanLocale, options, display = "auto",
6791
6895
  children: ["+", value.length - maxItems]
6792
6896
  })]
6793
6897
  });
6898
+ const tone = options.find((option) => option.value === String(value))?.badgeTone;
6899
+ const toneClassName = tone && {
6900
+ neutral: "border-border bg-muted text-muted-foreground",
6901
+ success: "border-emerald-200 bg-emerald-50 text-emerald-700 dark:border-emerald-800 dark:bg-emerald-950 dark:text-emerald-300",
6902
+ warning: "border-amber-200 bg-amber-50 text-amber-700 dark:border-amber-800 dark:bg-amber-950 dark:text-amber-300",
6903
+ info: "border-blue-200 bg-blue-50 text-blue-700 dark:border-blue-800 dark:bg-blue-950 dark:text-blue-300"
6904
+ }[tone];
6905
+ if (toneClassName) return /* @__PURE__ */ jsxs(Badge, {
6906
+ variant: "outline",
6907
+ className: toneClassName,
6908
+ children: [/* @__PURE__ */ jsx("span", {
6909
+ "aria-hidden": "true",
6910
+ className: "size-1.5 shrink-0 rounded-full bg-current"
6911
+ }), getOptionLabel(value, options)]
6912
+ });
6794
6913
  return /* @__PURE__ */ jsx(Badge, {
6795
6914
  variant: "outline",
6796
6915
  className: "capitalize",
@@ -6901,14 +7020,9 @@ function ViewModalContent({ open, onOpenChange, variant, data, schema, fields: f
6901
7020
  /**
6902
7021
  * 解析列表行操作
6903
7022
  */
6904
- function resolveActions(actionsOrFn, defaults, rowActionsLocale, context) {
6905
- const resolvedItems = typeof actionsOrFn === "function" ? actionsOrFn([
6906
- { type: "view" },
6907
- { type: "edit" },
6908
- { type: "copy" },
6909
- { type: "delete" }
6910
- ]) : actionsOrFn;
7023
+ function resolveActions(actions, defaults, rowActionsLocale, context) {
6911
7024
  const getContext = (row) => ({
7025
+ MenuItem: DropdownMenuItem$1,
6912
7026
  crudId: context.crudId,
6913
7027
  idKey: context.idKey,
6914
7028
  row,
@@ -6916,54 +7030,13 @@ function resolveActions(actionsOrFn, defaults, rowActionsLocale, context) {
6916
7030
  openView: defaults.openView,
6917
7031
  ...defaults.openEdit ? { openEdit: defaults.openEdit } : {},
6918
7032
  ...defaults.copyRow ? { copyRow: defaults.copyRow } : {},
6919
- ...defaults.openDelete ? { openDelete: defaults.openDelete } : {}
7033
+ ...defaults.openDelete ? { openDelete: defaults.openDelete } : {},
7034
+ open: (options) => {
7035
+ if (options.type === "custom") context.openComponent(options.component);
7036
+ else handlerMap[options.type]?.(options.row);
7037
+ }
6920
7038
  });
6921
- const defaultItems = [
6922
- {
6923
- label: rowActionsLocale.view,
6924
- onClick: defaults.openView
6925
- },
6926
- ...defaults.openEdit ? [{
6927
- label: rowActionsLocale.edit,
6928
- onClick: defaults.openEdit
6929
- }] : [],
6930
- ...defaults.copyRow ? [{
6931
- label: rowActionsLocale.copy,
6932
- onClick: defaults.copyRow
6933
- }] : [],
6934
- ...defaults.openDelete ? [{
6935
- label: rowActionsLocale.delete,
6936
- onClick: defaults.openDelete,
6937
- separator: true,
6938
- variant: "destructive"
6939
- }] : []
6940
- ];
6941
- if (resolvedItems === void 0) return defaultItems;
6942
- const items = resolvedItems.filter((item) => !item.hidden);
6943
- if (items.length === 0) return [];
6944
- if (!items.some((i) => i.type !== "custom")) {
6945
- const startItems = items.filter((i) => i.type === "custom" && i.position === "start").map(({ label, onClick, component, separator, variant }) => ({
6946
- label,
6947
- onClick,
6948
- component,
6949
- getContext,
6950
- separator,
6951
- variant
6952
- }));
6953
- const endItems = items.filter((i) => i.type === "custom" && i.position !== "start").map(({ label, onClick, component, separator, variant }) => ({
6954
- label,
6955
- onClick,
6956
- component,
6957
- getContext,
6958
- separator,
6959
- variant
6960
- }));
6961
- return [
6962
- ...startItems,
6963
- ...defaultItems,
6964
- ...endItems
6965
- ];
6966
- }
7039
+ const items = actions.filter((item) => !item.hidden);
6967
7040
  const handlerMap = {
6968
7041
  view: defaults.openView,
6969
7042
  edit: defaults.openEdit,
@@ -7215,15 +7288,18 @@ function AutoCrudTable({ id, title, description, schema, resource, fields, table
7215
7288
  resource.handlers.openEdit,
7216
7289
  resource.handlers.openView
7217
7290
  ]);
7291
+ const { openComponent, dialog: rowActionDialog } = useRowActionDialog();
7218
7292
  const tableRowActions = React.useMemo(() => resolveActions(registryRowActions, rowActionDefaults, locale.rowActions, {
7219
7293
  crudId: id ?? "",
7220
- idKey: resourceIdKey
7294
+ idKey: resourceIdKey,
7295
+ openComponent
7221
7296
  }), [
7222
7297
  id,
7223
7298
  locale.rowActions,
7224
7299
  registryRowActions,
7225
7300
  resourceIdKey,
7226
- rowActionDefaults
7301
+ rowActionDefaults,
7302
+ openComponent
7227
7303
  ]);
7228
7304
  return /* @__PURE__ */ jsxs("div", {
7229
7305
  className: "space-y-4",
@@ -7319,6 +7395,7 @@ function AutoCrudTable({ id, title, description, schema, resource, fields, table
7319
7395
  pageCount: resource.tableData.pageCount,
7320
7396
  ...resource.tableData.total !== void 0 ? { total: resource.tableData.total } : {},
7321
7397
  overrides: tableOverrides,
7398
+ classNames: tableConfig?.classNames,
7322
7399
  exclude: hiddenColumns,
7323
7400
  filterMode: tableConfig?.filterModes,
7324
7401
  search: searchConfig,
@@ -7334,6 +7411,7 @@ function AutoCrudTable({ id, title, description, schema, resource, fields, table
7334
7411
  onSelectedRowsChange: handleSelectedRowsChange,
7335
7412
  getSelectedRows: getSelectedRowsRef
7336
7413
  }),
7414
+ rowActionDialog,
7337
7415
  /* @__PURE__ */ jsx(CrudFormModal, {
7338
7416
  open: resource.modal.createOpen || resource.modal.editOpen,
7339
7417
  onOpenChange: (open) => !open && resource.handlers.closeModals(),