@nccirtu/tablefy 0.8.4 → 0.9.1
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/README.md +224 -200
- package/dist/columns/forms/builders/actions-builder.d.ts +14 -0
- package/dist/columns/forms/builders/form-schema.d.ts +35 -0
- package/dist/columns/forms/builders/index.d.ts +5 -0
- package/dist/columns/forms/builders/section-builder.d.ts +16 -0
- package/dist/columns/forms/builders/tab-builder.d.ts +16 -0
- package/dist/columns/forms/builders/wizard-builder.d.ts +17 -0
- package/dist/columns/forms/components/field-renderer.d.ts +12 -0
- package/dist/columns/forms/components/form-actions.d.ts +9 -0
- package/dist/columns/forms/components/form-renderer.d.ts +14 -0
- package/dist/columns/forms/components/grid-layout.d.ts +7 -0
- package/dist/columns/forms/components/index.d.ts +9 -0
- package/dist/columns/forms/components/section-renderer.d.ts +14 -0
- package/dist/columns/forms/components/tab-renderer.d.ts +15 -0
- package/dist/columns/forms/components/wizard-renderer.d.ts +17 -0
- package/dist/columns/forms/fields/base-field.d.ts +24 -0
- package/dist/columns/forms/fields/checkbox-group.d.ts +12 -0
- package/dist/columns/forms/fields/checkbox.d.ts +9 -0
- package/dist/columns/forms/fields/date-picker.d.ts +15 -0
- package/dist/columns/forms/fields/file-upload.d.ts +17 -0
- package/dist/columns/forms/fields/hidden.d.ts +9 -0
- package/dist/columns/forms/fields/index.d.ts +12 -0
- package/dist/columns/forms/fields/radio-group.d.ts +14 -0
- package/dist/columns/forms/fields/repeater.d.ts +21 -0
- package/dist/columns/forms/fields/select.d.ts +16 -0
- package/dist/columns/forms/fields/text-input.d.ts +20 -0
- package/dist/columns/forms/fields/textarea.d.ts +14 -0
- package/dist/columns/forms/fields/toggle.d.ts +11 -0
- package/dist/columns/forms/index.d.ts +26 -0
- package/dist/columns/forms/types/actions.d.ts +11 -0
- package/dist/columns/forms/types/field.d.ts +98 -0
- package/dist/columns/forms/types/form.d.ts +37 -0
- package/dist/columns/forms/types/index.d.ts +4 -0
- package/dist/columns/forms/types/layout.d.ts +31 -0
- package/dist/columns/index.d.ts +2 -0
- package/dist/columns/inertia/index.d.ts +4 -0
- package/dist/columns/inertia/precognition.d.ts +6 -0
- package/dist/columns/inertia/types.d.ts +63 -0
- package/dist/columns/inertia/use-inertia-form.d.ts +2 -0
- package/dist/columns/inertia/use-server-table.d.ts +2 -0
- package/dist/forms/builders/actions-builder.d.ts +14 -0
- package/dist/forms/builders/empty-state.d.ts +46 -0
- package/dist/forms/builders/form-schema.d.ts +35 -0
- package/dist/forms/builders/index.d.ts +2 -0
- package/dist/forms/builders/section-builder.d.ts +16 -0
- package/dist/forms/builders/tab-builder.d.ts +16 -0
- package/dist/forms/builders/table-schema.d.ts +45 -0
- package/dist/forms/builders/wizard-builder.d.ts +17 -0
- package/dist/forms/columns/actions-column.d.ts +26 -0
- package/dist/forms/columns/avatar-group-column.d.ts +38 -0
- package/dist/forms/columns/badge-column.d.ts +29 -0
- package/dist/forms/columns/base-column.d.ts +21 -0
- package/dist/forms/columns/button-column.d.ts +14 -0
- package/dist/forms/columns/checkbox-column.d.ts +5 -0
- package/dist/forms/columns/date-column.d.ts +24 -0
- package/dist/forms/columns/dropdown-column.d.ts +17 -0
- package/dist/forms/columns/enum-column.d.ts +52 -0
- package/dist/forms/columns/icon-column.d.ts +58 -0
- package/dist/forms/columns/image-column.d.ts +21 -0
- package/dist/forms/columns/index.d.ts +18 -0
- package/dist/forms/columns/input-column.d.ts +27 -0
- package/dist/forms/columns/link-column.d.ts +27 -0
- package/dist/forms/columns/number-column.d.ts +23 -0
- package/dist/forms/columns/progress-column.d.ts +30 -0
- package/dist/forms/columns/select-column.d.ts +24 -0
- package/dist/forms/columns/text-column.d.ts +14 -0
- package/dist/forms/columns/types.d.ts +46 -0
- package/dist/forms/components/field-renderer.d.ts +12 -0
- package/dist/forms/components/form-actions.d.ts +9 -0
- package/dist/forms/components/form-renderer.d.ts +14 -0
- package/dist/forms/components/grid-layout.d.ts +7 -0
- package/dist/forms/components/index.d.ts +9 -0
- package/dist/forms/components/section-renderer.d.ts +14 -0
- package/dist/forms/components/tab-renderer.d.ts +15 -0
- package/dist/forms/components/wizard-renderer.d.ts +17 -0
- package/dist/forms/confirm/ConfirmProvider.d.ts +6 -0
- package/dist/forms/confirm/confirm.d.ts +3 -0
- package/dist/forms/confirm/index.d.ts +3 -0
- package/dist/forms/confirm/types.d.ts +10 -0
- package/dist/forms/fields/base-field.d.ts +24 -0
- package/dist/forms/fields/checkbox-group.d.ts +12 -0
- package/dist/forms/fields/checkbox.d.ts +9 -0
- package/dist/forms/fields/date-picker.d.ts +15 -0
- package/dist/forms/fields/file-upload.d.ts +17 -0
- package/dist/forms/fields/hidden.d.ts +9 -0
- package/dist/forms/fields/index.d.ts +12 -0
- package/dist/forms/fields/radio-group.d.ts +14 -0
- package/dist/forms/fields/repeater.d.ts +21 -0
- package/dist/forms/fields/select.d.ts +16 -0
- package/dist/forms/fields/text-input.d.ts +20 -0
- package/dist/forms/fields/textarea.d.ts +14 -0
- package/dist/forms/fields/toggle.d.ts +11 -0
- package/dist/forms/forms/builders/actions-builder.d.ts +14 -0
- package/dist/forms/forms/builders/form-schema.d.ts +35 -0
- package/dist/forms/forms/builders/index.d.ts +5 -0
- package/dist/forms/forms/builders/section-builder.d.ts +16 -0
- package/dist/forms/forms/builders/tab-builder.d.ts +16 -0
- package/dist/forms/forms/builders/wizard-builder.d.ts +17 -0
- package/dist/forms/forms/components/field-renderer.d.ts +12 -0
- package/dist/forms/forms/components/form-actions.d.ts +9 -0
- package/dist/forms/forms/components/form-renderer.d.ts +14 -0
- package/dist/forms/forms/components/grid-layout.d.ts +7 -0
- package/dist/forms/forms/components/index.d.ts +9 -0
- package/dist/forms/forms/components/section-renderer.d.ts +14 -0
- package/dist/forms/forms/components/tab-renderer.d.ts +15 -0
- package/dist/forms/forms/components/wizard-renderer.d.ts +17 -0
- package/dist/forms/forms/fields/base-field.d.ts +24 -0
- package/dist/forms/forms/fields/checkbox-group.d.ts +12 -0
- package/dist/forms/forms/fields/checkbox.d.ts +9 -0
- package/dist/forms/forms/fields/date-picker.d.ts +15 -0
- package/dist/forms/forms/fields/file-upload.d.ts +17 -0
- package/dist/forms/forms/fields/hidden.d.ts +9 -0
- package/dist/forms/forms/fields/index.d.ts +12 -0
- package/dist/forms/forms/fields/radio-group.d.ts +14 -0
- package/dist/forms/forms/fields/repeater.d.ts +21 -0
- package/dist/forms/forms/fields/select.d.ts +16 -0
- package/dist/forms/forms/fields/text-input.d.ts +20 -0
- package/dist/forms/forms/fields/textarea.d.ts +14 -0
- package/dist/forms/forms/fields/toggle.d.ts +11 -0
- package/dist/forms/forms/index.d.ts +26 -0
- package/dist/forms/forms/types/actions.d.ts +11 -0
- package/dist/forms/forms/types/field.d.ts +98 -0
- package/dist/forms/forms/types/form.d.ts +37 -0
- package/dist/forms/forms/types/index.d.ts +4 -0
- package/dist/forms/forms/types/layout.d.ts +31 -0
- package/dist/forms/index.d.ts +25 -0
- package/dist/forms/index.esm.js +1052 -0
- package/dist/forms/index.esm.js.map +1 -0
- package/dist/forms/index.js +1077 -0
- package/dist/forms/index.js.map +1 -0
- package/dist/forms/inertia/index.d.ts +4 -0
- package/dist/forms/inertia/precognition.d.ts +6 -0
- package/dist/forms/inertia/types.d.ts +63 -0
- package/dist/forms/inertia/use-inertia-form.d.ts +2 -0
- package/dist/forms/inertia/use-server-table.d.ts +2 -0
- package/dist/forms/tablefy/avatar-list.d.ts +15 -0
- package/dist/forms/tablefy/data-table-empty.d.ts +8 -0
- package/dist/forms/tablefy/data-table-header.d.ts +17 -0
- package/dist/forms/tablefy/data-table-pagination.d.ts +9 -0
- package/dist/forms/tablefy/data-table-schema.d.ts +1 -0
- package/dist/forms/tablefy/data-table.d.ts +13 -0
- package/dist/forms/tablefy/index.d.ts +6 -0
- package/dist/forms/types/actions.d.ts +21 -0
- package/dist/forms/types/empty-state.d.ts +18 -0
- package/dist/forms/types/field.d.ts +98 -0
- package/dist/forms/types/filters.d.ts +25 -0
- package/dist/forms/types/form.d.ts +37 -0
- package/dist/forms/types/index.d.ts +4 -0
- package/dist/forms/types/layout.d.ts +31 -0
- package/dist/forms/types/table.d.ts +42 -0
- package/dist/forms/utils.d.ts +1 -0
- package/dist/index.d.ts +2 -0
- package/dist/index.esm.js +1050 -9
- package/dist/index.esm.js.map +1 -1
- package/dist/index.js +1058 -0
- package/dist/index.js.map +1 -1
- package/dist/inertia/builders/empty-state.d.ts +46 -0
- package/dist/inertia/builders/index.d.ts +2 -0
- package/dist/inertia/builders/table-schema.d.ts +45 -0
- package/dist/inertia/columns/actions-column.d.ts +26 -0
- package/dist/inertia/columns/avatar-group-column.d.ts +38 -0
- package/dist/inertia/columns/badge-column.d.ts +29 -0
- package/dist/inertia/columns/base-column.d.ts +21 -0
- package/dist/inertia/columns/button-column.d.ts +14 -0
- package/dist/inertia/columns/checkbox-column.d.ts +5 -0
- package/dist/inertia/columns/date-column.d.ts +24 -0
- package/dist/inertia/columns/dropdown-column.d.ts +17 -0
- package/dist/inertia/columns/enum-column.d.ts +52 -0
- package/dist/inertia/columns/icon-column.d.ts +58 -0
- package/dist/inertia/columns/image-column.d.ts +21 -0
- package/dist/inertia/columns/index.d.ts +18 -0
- package/dist/inertia/columns/input-column.d.ts +27 -0
- package/dist/inertia/columns/link-column.d.ts +27 -0
- package/dist/inertia/columns/number-column.d.ts +23 -0
- package/dist/inertia/columns/progress-column.d.ts +30 -0
- package/dist/inertia/columns/select-column.d.ts +24 -0
- package/dist/inertia/columns/text-column.d.ts +14 -0
- package/dist/inertia/columns/types.d.ts +46 -0
- package/dist/inertia/confirm/ConfirmProvider.d.ts +6 -0
- package/dist/inertia/confirm/confirm.d.ts +3 -0
- package/dist/inertia/confirm/index.d.ts +3 -0
- package/dist/inertia/confirm/types.d.ts +10 -0
- package/dist/inertia/forms/builders/actions-builder.d.ts +14 -0
- package/dist/inertia/forms/builders/form-schema.d.ts +35 -0
- package/dist/inertia/forms/builders/index.d.ts +5 -0
- package/dist/inertia/forms/builders/section-builder.d.ts +16 -0
- package/dist/inertia/forms/builders/tab-builder.d.ts +16 -0
- package/dist/inertia/forms/builders/wizard-builder.d.ts +17 -0
- package/dist/inertia/forms/components/field-renderer.d.ts +12 -0
- package/dist/inertia/forms/components/form-actions.d.ts +9 -0
- package/dist/inertia/forms/components/form-renderer.d.ts +14 -0
- package/dist/inertia/forms/components/grid-layout.d.ts +7 -0
- package/dist/inertia/forms/components/index.d.ts +9 -0
- package/dist/inertia/forms/components/section-renderer.d.ts +14 -0
- package/dist/inertia/forms/components/tab-renderer.d.ts +15 -0
- package/dist/inertia/forms/components/wizard-renderer.d.ts +17 -0
- package/dist/inertia/forms/fields/base-field.d.ts +24 -0
- package/dist/inertia/forms/fields/checkbox-group.d.ts +12 -0
- package/dist/inertia/forms/fields/checkbox.d.ts +9 -0
- package/dist/inertia/forms/fields/date-picker.d.ts +15 -0
- package/dist/inertia/forms/fields/file-upload.d.ts +17 -0
- package/dist/inertia/forms/fields/hidden.d.ts +9 -0
- package/dist/inertia/forms/fields/index.d.ts +12 -0
- package/dist/inertia/forms/fields/radio-group.d.ts +14 -0
- package/dist/inertia/forms/fields/repeater.d.ts +21 -0
- package/dist/inertia/forms/fields/select.d.ts +16 -0
- package/dist/inertia/forms/fields/text-input.d.ts +20 -0
- package/dist/inertia/forms/fields/textarea.d.ts +14 -0
- package/dist/inertia/forms/fields/toggle.d.ts +11 -0
- package/dist/inertia/forms/index.d.ts +26 -0
- package/dist/inertia/forms/types/actions.d.ts +11 -0
- package/dist/inertia/forms/types/field.d.ts +98 -0
- package/dist/inertia/forms/types/form.d.ts +37 -0
- package/dist/inertia/forms/types/index.d.ts +4 -0
- package/dist/inertia/forms/types/layout.d.ts +31 -0
- package/dist/inertia/index.d.ts +4 -0
- package/dist/inertia/index.esm.js +149 -0
- package/dist/inertia/index.esm.js.map +1 -0
- package/dist/inertia/index.js +153 -0
- package/dist/inertia/index.js.map +1 -0
- package/dist/inertia/inertia/index.d.ts +4 -0
- package/dist/inertia/inertia/precognition.d.ts +6 -0
- package/dist/inertia/inertia/types.d.ts +63 -0
- package/dist/inertia/inertia/use-inertia-form.d.ts +2 -0
- package/dist/inertia/inertia/use-server-table.d.ts +2 -0
- package/dist/inertia/precognition.d.ts +6 -0
- package/dist/inertia/tablefy/avatar-list.d.ts +15 -0
- package/dist/inertia/tablefy/data-table-empty.d.ts +8 -0
- package/dist/inertia/tablefy/data-table-header.d.ts +17 -0
- package/dist/inertia/tablefy/data-table-pagination.d.ts +9 -0
- package/dist/inertia/tablefy/data-table-schema.d.ts +1 -0
- package/dist/inertia/tablefy/data-table.d.ts +13 -0
- package/dist/inertia/tablefy/index.d.ts +6 -0
- package/dist/inertia/types/actions.d.ts +21 -0
- package/dist/inertia/types/empty-state.d.ts +18 -0
- package/dist/inertia/types/filters.d.ts +25 -0
- package/dist/inertia/types/index.d.ts +4 -0
- package/dist/inertia/types/table.d.ts +42 -0
- package/dist/inertia/types.d.ts +63 -0
- package/dist/inertia/use-inertia-form.d.ts +2 -0
- package/dist/inertia/use-server-table.d.ts +2 -0
- package/dist/inertia/utils.d.ts +1 -0
- package/package.json +41 -14
package/dist/index.esm.js
CHANGED
|
@@ -1,18 +1,26 @@
|
|
|
1
1
|
import { jsxs, jsx, Fragment } from 'react/jsx-runtime';
|
|
2
|
-
import { useState, useEffect } from 'react';
|
|
2
|
+
import { useState, useEffect, useRef, useCallback, useMemo } from 'react';
|
|
3
3
|
import { useReactTable, getCoreRowModel, getSortedRowModel, getFilteredRowModel, getPaginationRowModel, flexRender } from '@tanstack/react-table';
|
|
4
4
|
import { Table, TableHeader, TableRow, TableHead, TableBody, TableCell } from '@/components/ui/table';
|
|
5
5
|
import { cn } from '@/lib/utils';
|
|
6
6
|
import { Button } from '@/components/ui/button';
|
|
7
7
|
import { Input } from '@/components/ui/input';
|
|
8
8
|
import { DropdownMenu, DropdownMenuTrigger, DropdownMenuContent, DropdownMenuLabel, DropdownMenuSeparator, DropdownMenuCheckboxItem, DropdownMenuItem } from '@/components/ui/dropdown-menu';
|
|
9
|
-
import { Search, X, Columns, ChevronDown, ChevronsLeft, ChevronLeft, ChevronRight, ChevronsRight, ArrowUpDown, Calendar, ExternalLink, MoreHorizontal } from 'lucide-react';
|
|
10
|
-
import { Select, SelectTrigger, SelectValue, SelectContent, SelectItem } from '@/components/ui/select';
|
|
9
|
+
import { Search, X, Columns, ChevronDown, ChevronsLeft, ChevronLeft, ChevronRight, ChevronsRight, ArrowUpDown, Calendar, ExternalLink, MoreHorizontal, CalendarIcon, Upload, File, GripVertical, Trash2, Plus, Check } from 'lucide-react';
|
|
10
|
+
import { Select as Select$1, SelectTrigger, SelectValue, SelectContent, SelectItem } from '@/components/ui/select';
|
|
11
11
|
import { Badge } from '@/components/ui/badge';
|
|
12
|
-
import { Checkbox } from '@/components/ui/checkbox';
|
|
12
|
+
import { Checkbox as Checkbox$1 } from '@/components/ui/checkbox';
|
|
13
13
|
import { TooltipProvider, Tooltip, TooltipTrigger, TooltipContent } from '@/components/ui/tooltip';
|
|
14
14
|
import { Progress } from '@/components/ui/progress';
|
|
15
15
|
import { AlertDialog, AlertDialogContent, AlertDialogHeader, AlertDialogTitle, AlertDialogDescription, AlertDialogFooter, AlertDialogCancel, AlertDialogAction } from '@/components/ui/alert-dialog';
|
|
16
|
+
import { Textarea as Textarea$1 } from '@/components/ui/textarea';
|
|
17
|
+
import { Switch } from '@/components/ui/switch';
|
|
18
|
+
import { RadioGroup as RadioGroup$1, RadioGroupItem } from '@/components/ui/radio-group';
|
|
19
|
+
import { Label } from '@/components/ui/label';
|
|
20
|
+
import { Calendar as Calendar$1 } from '@/components/ui/calendar';
|
|
21
|
+
import { Popover, PopoverTrigger, PopoverContent } from '@/components/ui/popover';
|
|
22
|
+
import { Card, CardContent, CardHeader, CardTitle, CardDescription } from '@/components/ui/card';
|
|
23
|
+
import { Tabs, TabsList, TabsTrigger, TabsContent } from '@/components/ui/tabs';
|
|
16
24
|
|
|
17
25
|
function DataTableHeader({ title, description, actions = [], search, searchValue = "", onSearchChange, table, selectedCount = 0, enableColumnVisibility = false, columnVisibilityLabel = "Spalten", className, }) {
|
|
18
26
|
const normalActions = actions.filter((a) => !a.bulk && !a.hidden);
|
|
@@ -72,7 +80,7 @@ function DataTablePagination({ table, config, className, }) {
|
|
|
72
80
|
if (!config?.enabled)
|
|
73
81
|
return null;
|
|
74
82
|
const { showPageInfo = true, showPageSizeSelector = true, pageSizeOptions = [10, 20, 30, 50, 100], } = config;
|
|
75
|
-
return (jsxs("div", { className: cn("flex flex-col gap-4 px-4 py-4 sm:flex-row sm:items-center sm:justify-between", className), children: [jsx("div", { className: "text-sm text-muted-foreground", children: table.getFilteredSelectedRowModel().rows.length > 0 ? (jsxs("span", { children: [table.getFilteredSelectedRowModel().rows.length, " von", " ", table.getFilteredRowModel().rows.length, " Zeile(n) ausgew\u00E4hlt"] })) : showPageInfo ? (jsxs("span", { children: [table.getFilteredRowModel().rows.length, " Eintr\u00E4ge"] })) : null }), jsxs("div", { className: "flex flex-col gap-4 sm:flex-row sm:items-center sm:gap-6", children: [showPageSizeSelector && (jsxs("div", { className: "flex items-center gap-2", children: [jsx("span", { className: "text-sm text-muted-foreground whitespace-nowrap", children: "Zeilen pro Seite" }), jsxs(Select, { value: `${table.getState().pagination.pageSize}`, onValueChange: (value) => table.setPageSize(Number(value)), children: [jsx(SelectTrigger, { className: "h-8 w-[70px]", children: jsx(SelectValue, { placeholder: table.getState().pagination.pageSize }) }), jsx(SelectContent, { side: "top", children: pageSizeOptions.map((pageSize) => (jsx(SelectItem, { value: `${pageSize}`, children: pageSize }, pageSize))) })] })] })), showPageInfo && (jsxs("div", { className: "text-sm text-muted-foreground whitespace-nowrap", children: ["Seite", " ", table.getPageCount() > 0
|
|
83
|
+
return (jsxs("div", { className: cn("flex flex-col gap-4 px-4 py-4 sm:flex-row sm:items-center sm:justify-between", className), children: [jsx("div", { className: "text-sm text-muted-foreground", children: table.getFilteredSelectedRowModel().rows.length > 0 ? (jsxs("span", { children: [table.getFilteredSelectedRowModel().rows.length, " von", " ", table.getFilteredRowModel().rows.length, " Zeile(n) ausgew\u00E4hlt"] })) : showPageInfo ? (jsxs("span", { children: [table.getFilteredRowModel().rows.length, " Eintr\u00E4ge"] })) : null }), jsxs("div", { className: "flex flex-col gap-4 sm:flex-row sm:items-center sm:gap-6", children: [showPageSizeSelector && (jsxs("div", { className: "flex items-center gap-2", children: [jsx("span", { className: "text-sm text-muted-foreground whitespace-nowrap", children: "Zeilen pro Seite" }), jsxs(Select$1, { value: `${table.getState().pagination.pageSize}`, onValueChange: (value) => table.setPageSize(Number(value)), children: [jsx(SelectTrigger, { className: "h-8 w-[70px]", children: jsx(SelectValue, { placeholder: table.getState().pagination.pageSize }) }), jsx(SelectContent, { side: "top", children: pageSizeOptions.map((pageSize) => (jsx(SelectItem, { value: `${pageSize}`, children: pageSize }, pageSize))) })] })] })), showPageInfo && (jsxs("div", { className: "text-sm text-muted-foreground whitespace-nowrap", children: ["Seite", " ", table.getPageCount() > 0
|
|
76
84
|
? table.getState().pagination.pageIndex + 1
|
|
77
85
|
: 0, " ", "von ", Math.max(table.getPageCount(), 0)] })), jsxs("div", { className: "flex items-center gap-1", children: [jsxs(Button, { variant: "outline", size: "icon", className: "h-8 w-8", onClick: () => table.setPageIndex(0), disabled: !table.getCanPreviousPage(), children: [jsx(ChevronsLeft, { className: "h-4 w-4" }), jsx("span", { className: "sr-only", children: "Erste Seite" })] }), jsxs(Button, { variant: "outline", size: "icon", className: "h-8 w-8", onClick: () => table.previousPage(), disabled: !table.getCanPreviousPage(), children: [jsx(ChevronLeft, { className: "h-4 w-4" }), jsx("span", { className: "sr-only", children: "Vorherige Seite" })] }), jsxs(Button, { variant: "outline", size: "icon", className: "h-8 w-8", onClick: () => table.nextPage(), disabled: !table.getCanNextPage(), children: [jsx(ChevronRight, { className: "h-4 w-4" }), jsx("span", { className: "sr-only", children: "N\u00E4chste Seite" })] }), jsxs(Button, { variant: "outline", size: "icon", className: "h-8 w-8", onClick: () => table.setPageIndex(table.getPageCount() - 1), disabled: !table.getCanNextPage(), children: [jsx(ChevronsRight, { className: "h-4 w-4" }), jsx("span", { className: "sr-only", children: "Letzte Seite" })] })] })] })] }));
|
|
78
86
|
}
|
|
@@ -669,9 +677,9 @@ class CheckboxColumn {
|
|
|
669
677
|
build() {
|
|
670
678
|
return {
|
|
671
679
|
id: "select",
|
|
672
|
-
header: ({ table }) => (jsx(Checkbox, { checked: table.getIsAllPageRowsSelected() ||
|
|
680
|
+
header: ({ table }) => (jsx(Checkbox$1, { checked: table.getIsAllPageRowsSelected() ||
|
|
673
681
|
(table.getIsSomePageRowsSelected() && "indeterminate"), onCheckedChange: (value) => table.toggleAllPageRowsSelected(!!value), "aria-label": "Alle ausw\u00E4hlen" })),
|
|
674
|
-
cell: ({ row }) => (jsx(Checkbox, { checked: row.getIsSelected(), onCheckedChange: (value) => row.toggleSelected(!!value), "aria-label": "Zeile ausw\u00E4hlen" })),
|
|
682
|
+
cell: ({ row }) => (jsx(Checkbox$1, { checked: row.getIsSelected(), onCheckedChange: (value) => row.toggleSelected(!!value), "aria-label": "Zeile ausw\u00E4hlen" })),
|
|
675
683
|
enableSorting: false,
|
|
676
684
|
enableHiding: false,
|
|
677
685
|
};
|
|
@@ -1559,7 +1567,7 @@ class SelectColumn extends BaseColumn {
|
|
|
1559
1567
|
onValueChange(row.original, newValue);
|
|
1560
1568
|
}
|
|
1561
1569
|
};
|
|
1562
|
-
return (jsxs(Select, { value: localValue, onValueChange: handleValueChange, disabled: isDisabled, children: [jsx(SelectTrigger, { className: cn("h-8", this.config.cellClassName), children: jsx(SelectValue, { placeholder: placeholder || "Select..." }) }), jsx(SelectContent, { children: options?.map((option, index) => (jsx(SelectItem, { value: option.value, disabled: option.disabled, children: option.label }, index))) })] }));
|
|
1570
|
+
return (jsxs(Select$1, { value: localValue, onValueChange: handleValueChange, disabled: isDisabled, children: [jsx(SelectTrigger, { className: cn("h-8", this.config.cellClassName), children: jsx(SelectValue, { placeholder: placeholder || "Select..." }) }), jsx(SelectContent, { children: options?.map((option, index) => (jsx(SelectItem, { value: option.value, disabled: option.disabled, children: option.label }, index))) })] }));
|
|
1563
1571
|
},
|
|
1564
1572
|
};
|
|
1565
1573
|
}
|
|
@@ -1857,5 +1865,1038 @@ function ConfirmProvider({ children }) {
|
|
|
1857
1865
|
return (jsxs(Fragment, { children: [children, jsx(AlertDialog, { open: !!currentRequest, onOpenChange: (open) => !open && handleCancel(), children: jsxs(AlertDialogContent, { className: "max-w-md", children: [jsxs(AlertDialogHeader, { children: [jsx(AlertDialogTitle, { className: "text-center", children: title || "Bestätigung erforderlich" }), description && (jsx(AlertDialogDescription, { className: "text-center", children: description }))] }), image && (jsx("div", { className: "flex justify-center py-4", children: jsx("img", { src: image, alt: "Confirmation", className: "h-24 w-24 object-contain" }) })), icon && !image && (jsx("div", { className: "flex justify-center py-4 text-6xl", children: icon })), jsxs(AlertDialogFooter, { className: "flex flex-row !justify-between w-full", children: [jsx(AlertDialogCancel, { onClick: handleCancel, className: "mt-0", children: cancelLabel || "Abbrechen" }), jsx(AlertDialogAction, { onClick: handleConfirm, variant: variant === "destructive" ? "destructive" : "default", children: confirmLabel || "Bestätigen" })] })] }) })] }));
|
|
1858
1866
|
}
|
|
1859
1867
|
|
|
1860
|
-
|
|
1868
|
+
class ActionsBuilder {
|
|
1869
|
+
actionsList = [];
|
|
1870
|
+
submit(opts = {}) {
|
|
1871
|
+
this.actionsList.push({
|
|
1872
|
+
type: "submit",
|
|
1873
|
+
label: opts.label || "Submit",
|
|
1874
|
+
variant: opts.variant || "default",
|
|
1875
|
+
...opts,
|
|
1876
|
+
});
|
|
1877
|
+
return this;
|
|
1878
|
+
}
|
|
1879
|
+
cancel(opts = {}) {
|
|
1880
|
+
this.actionsList.push({
|
|
1881
|
+
type: "cancel",
|
|
1882
|
+
label: opts.label || "Cancel",
|
|
1883
|
+
variant: opts.variant || "outline",
|
|
1884
|
+
...opts,
|
|
1885
|
+
});
|
|
1886
|
+
return this;
|
|
1887
|
+
}
|
|
1888
|
+
custom(opts) {
|
|
1889
|
+
this.actionsList.push({ ...opts, type: "custom" });
|
|
1890
|
+
return this;
|
|
1891
|
+
}
|
|
1892
|
+
build() {
|
|
1893
|
+
return [...this.actionsList];
|
|
1894
|
+
}
|
|
1895
|
+
}
|
|
1896
|
+
|
|
1897
|
+
/**
|
|
1898
|
+
* Form Schema Builder
|
|
1899
|
+
* Fluent API for building complete form configurations
|
|
1900
|
+
*/
|
|
1901
|
+
class FormSchema {
|
|
1902
|
+
fieldBuilders = [];
|
|
1903
|
+
schemaConfig = {};
|
|
1904
|
+
static make() {
|
|
1905
|
+
return new FormSchema();
|
|
1906
|
+
}
|
|
1907
|
+
// --- Configuration ---
|
|
1908
|
+
title(title) {
|
|
1909
|
+
this.schemaConfig.title = title;
|
|
1910
|
+
return this;
|
|
1911
|
+
}
|
|
1912
|
+
description(description) {
|
|
1913
|
+
this.schemaConfig.description = description;
|
|
1914
|
+
return this;
|
|
1915
|
+
}
|
|
1916
|
+
columns(columns) {
|
|
1917
|
+
this.schemaConfig.columns = columns;
|
|
1918
|
+
return this;
|
|
1919
|
+
}
|
|
1920
|
+
bordered(bordered = true) {
|
|
1921
|
+
this.schemaConfig.bordered = bordered;
|
|
1922
|
+
return this;
|
|
1923
|
+
}
|
|
1924
|
+
spacing(spacing) {
|
|
1925
|
+
this.schemaConfig.spacing = spacing;
|
|
1926
|
+
return this;
|
|
1927
|
+
}
|
|
1928
|
+
disabled(disabled) {
|
|
1929
|
+
this.schemaConfig.disabled = disabled;
|
|
1930
|
+
return this;
|
|
1931
|
+
}
|
|
1932
|
+
// --- Fields ---
|
|
1933
|
+
fields(...builders) {
|
|
1934
|
+
this.fieldBuilders.push(...builders);
|
|
1935
|
+
return this;
|
|
1936
|
+
}
|
|
1937
|
+
// --- Layout ---
|
|
1938
|
+
sections(...sections) {
|
|
1939
|
+
this.schemaConfig.sections = sections.map((s) => s.build());
|
|
1940
|
+
return this;
|
|
1941
|
+
}
|
|
1942
|
+
tabs(...tabs) {
|
|
1943
|
+
this.schemaConfig.tabs = tabs.map((t) => t.build());
|
|
1944
|
+
return this;
|
|
1945
|
+
}
|
|
1946
|
+
wizard(...steps) {
|
|
1947
|
+
this.schemaConfig.wizardSteps = steps.map((s) => s.build());
|
|
1948
|
+
return this;
|
|
1949
|
+
}
|
|
1950
|
+
// --- Actions ---
|
|
1951
|
+
actions(fn) {
|
|
1952
|
+
const builder = new ActionsBuilder();
|
|
1953
|
+
this.schemaConfig.actions = fn(builder).build();
|
|
1954
|
+
return this;
|
|
1955
|
+
}
|
|
1956
|
+
actionsPosition(position) {
|
|
1957
|
+
this.schemaConfig.actionsPosition = position;
|
|
1958
|
+
return this;
|
|
1959
|
+
}
|
|
1960
|
+
// --- Build ---
|
|
1961
|
+
build() {
|
|
1962
|
+
const fields = this.fieldBuilders.map((b) => b.build());
|
|
1963
|
+
return {
|
|
1964
|
+
fields,
|
|
1965
|
+
config: {
|
|
1966
|
+
...this.schemaConfig,
|
|
1967
|
+
fields,
|
|
1968
|
+
},
|
|
1969
|
+
};
|
|
1970
|
+
}
|
|
1971
|
+
}
|
|
1972
|
+
|
|
1973
|
+
class SectionBuilder {
|
|
1974
|
+
sectionConfig;
|
|
1975
|
+
constructor(title) {
|
|
1976
|
+
this.sectionConfig = {
|
|
1977
|
+
id: title.toLowerCase().replace(/\s+/g, "-"),
|
|
1978
|
+
title,
|
|
1979
|
+
fields: [],
|
|
1980
|
+
columns: 1,
|
|
1981
|
+
collapsible: false,
|
|
1982
|
+
collapsed: false,
|
|
1983
|
+
};
|
|
1984
|
+
}
|
|
1985
|
+
static make(title) {
|
|
1986
|
+
return new SectionBuilder(title);
|
|
1987
|
+
}
|
|
1988
|
+
id(id) {
|
|
1989
|
+
this.sectionConfig.id = id;
|
|
1990
|
+
return this;
|
|
1991
|
+
}
|
|
1992
|
+
description(description) {
|
|
1993
|
+
this.sectionConfig.description = description;
|
|
1994
|
+
return this;
|
|
1995
|
+
}
|
|
1996
|
+
fields(fields) {
|
|
1997
|
+
this.sectionConfig.fields = fields;
|
|
1998
|
+
return this;
|
|
1999
|
+
}
|
|
2000
|
+
columns(columns) {
|
|
2001
|
+
this.sectionConfig.columns = columns;
|
|
2002
|
+
return this;
|
|
2003
|
+
}
|
|
2004
|
+
collapsible(collapsible = true) {
|
|
2005
|
+
this.sectionConfig.collapsible = collapsible;
|
|
2006
|
+
return this;
|
|
2007
|
+
}
|
|
2008
|
+
collapsed(collapsed = true) {
|
|
2009
|
+
this.sectionConfig.collapsed = collapsed;
|
|
2010
|
+
this.sectionConfig.collapsible = true;
|
|
2011
|
+
return this;
|
|
2012
|
+
}
|
|
2013
|
+
icon(icon) {
|
|
2014
|
+
this.sectionConfig.icon = icon;
|
|
2015
|
+
return this;
|
|
2016
|
+
}
|
|
2017
|
+
hidden(fn) {
|
|
2018
|
+
this.sectionConfig.hidden = fn;
|
|
2019
|
+
return this;
|
|
2020
|
+
}
|
|
2021
|
+
build() {
|
|
2022
|
+
return { ...this.sectionConfig };
|
|
2023
|
+
}
|
|
2024
|
+
}
|
|
2025
|
+
|
|
2026
|
+
class TabBuilder {
|
|
2027
|
+
tabConfig;
|
|
2028
|
+
constructor(label) {
|
|
2029
|
+
this.tabConfig = {
|
|
2030
|
+
id: label.toLowerCase().replace(/\s+/g, "-"),
|
|
2031
|
+
label,
|
|
2032
|
+
};
|
|
2033
|
+
}
|
|
2034
|
+
static make(label) {
|
|
2035
|
+
return new TabBuilder(label);
|
|
2036
|
+
}
|
|
2037
|
+
id(id) {
|
|
2038
|
+
this.tabConfig.id = id;
|
|
2039
|
+
return this;
|
|
2040
|
+
}
|
|
2041
|
+
icon(icon) {
|
|
2042
|
+
this.tabConfig.icon = icon;
|
|
2043
|
+
return this;
|
|
2044
|
+
}
|
|
2045
|
+
fields(fields) {
|
|
2046
|
+
this.tabConfig.fields = fields;
|
|
2047
|
+
return this;
|
|
2048
|
+
}
|
|
2049
|
+
sections(...sections) {
|
|
2050
|
+
this.tabConfig.sections = sections.map((s) => s.build());
|
|
2051
|
+
return this;
|
|
2052
|
+
}
|
|
2053
|
+
badge(badge) {
|
|
2054
|
+
this.tabConfig.badge = badge;
|
|
2055
|
+
return this;
|
|
2056
|
+
}
|
|
2057
|
+
disabled(fn) {
|
|
2058
|
+
this.tabConfig.disabled = fn;
|
|
2059
|
+
return this;
|
|
2060
|
+
}
|
|
2061
|
+
build() {
|
|
2062
|
+
return { ...this.tabConfig };
|
|
2063
|
+
}
|
|
2064
|
+
}
|
|
2065
|
+
|
|
2066
|
+
class WizardStep {
|
|
2067
|
+
stepConfig;
|
|
2068
|
+
constructor(label) {
|
|
2069
|
+
this.stepConfig = {
|
|
2070
|
+
id: label.toLowerCase().replace(/\s+/g, "-"),
|
|
2071
|
+
label,
|
|
2072
|
+
};
|
|
2073
|
+
}
|
|
2074
|
+
static make(label) {
|
|
2075
|
+
return new WizardStep(label);
|
|
2076
|
+
}
|
|
2077
|
+
id(id) {
|
|
2078
|
+
this.stepConfig.id = id;
|
|
2079
|
+
return this;
|
|
2080
|
+
}
|
|
2081
|
+
description(description) {
|
|
2082
|
+
this.stepConfig.description = description;
|
|
2083
|
+
return this;
|
|
2084
|
+
}
|
|
2085
|
+
icon(icon) {
|
|
2086
|
+
this.stepConfig.icon = icon;
|
|
2087
|
+
return this;
|
|
2088
|
+
}
|
|
2089
|
+
fields(fields) {
|
|
2090
|
+
this.stepConfig.fields = fields;
|
|
2091
|
+
return this;
|
|
2092
|
+
}
|
|
2093
|
+
sections(...sections) {
|
|
2094
|
+
this.stepConfig.sections = sections.map((s) => s.build());
|
|
2095
|
+
return this;
|
|
2096
|
+
}
|
|
2097
|
+
canProceed(fn) {
|
|
2098
|
+
this.stepConfig.canProceed = fn;
|
|
2099
|
+
return this;
|
|
2100
|
+
}
|
|
2101
|
+
beforeNext(fn) {
|
|
2102
|
+
this.stepConfig.beforeNext = fn;
|
|
2103
|
+
return this;
|
|
2104
|
+
}
|
|
2105
|
+
build() {
|
|
2106
|
+
return { ...this.stepConfig };
|
|
2107
|
+
}
|
|
2108
|
+
}
|
|
2109
|
+
|
|
2110
|
+
class BaseField {
|
|
2111
|
+
config;
|
|
2112
|
+
constructor(name) {
|
|
2113
|
+
this.config = {
|
|
2114
|
+
name,
|
|
2115
|
+
required: false,
|
|
2116
|
+
disabled: false,
|
|
2117
|
+
readOnly: false,
|
|
2118
|
+
hidden: false,
|
|
2119
|
+
columnSpan: 1,
|
|
2120
|
+
rules: [],
|
|
2121
|
+
dependsOn: [],
|
|
2122
|
+
};
|
|
2123
|
+
}
|
|
2124
|
+
// --- Fluent API ---
|
|
2125
|
+
label(label) {
|
|
2126
|
+
this.config.label = label;
|
|
2127
|
+
return this;
|
|
2128
|
+
}
|
|
2129
|
+
placeholder(placeholder) {
|
|
2130
|
+
this.config.placeholder = placeholder;
|
|
2131
|
+
return this;
|
|
2132
|
+
}
|
|
2133
|
+
helperText(text) {
|
|
2134
|
+
this.config.helperText = text;
|
|
2135
|
+
return this;
|
|
2136
|
+
}
|
|
2137
|
+
required(required = true) {
|
|
2138
|
+
this.config.required = required;
|
|
2139
|
+
if (required &&
|
|
2140
|
+
!this.config.rules?.some((r) => r.type === "required")) {
|
|
2141
|
+
this.config.rules = [
|
|
2142
|
+
...(this.config.rules || []),
|
|
2143
|
+
{
|
|
2144
|
+
type: "required",
|
|
2145
|
+
message: `${this.config.label || this.config.name} is required`,
|
|
2146
|
+
},
|
|
2147
|
+
];
|
|
2148
|
+
}
|
|
2149
|
+
return this;
|
|
2150
|
+
}
|
|
2151
|
+
disabled(disabled = true) {
|
|
2152
|
+
this.config.disabled = disabled;
|
|
2153
|
+
return this;
|
|
2154
|
+
}
|
|
2155
|
+
readOnly(readOnly = true) {
|
|
2156
|
+
this.config.readOnly = readOnly;
|
|
2157
|
+
return this;
|
|
2158
|
+
}
|
|
2159
|
+
hidden(hidden = true) {
|
|
2160
|
+
this.config.hidden = hidden;
|
|
2161
|
+
return this;
|
|
2162
|
+
}
|
|
2163
|
+
default(value) {
|
|
2164
|
+
this.config.defaultValue = value;
|
|
2165
|
+
return this;
|
|
2166
|
+
}
|
|
2167
|
+
columnSpan(span) {
|
|
2168
|
+
this.config.columnSpan = span;
|
|
2169
|
+
return this;
|
|
2170
|
+
}
|
|
2171
|
+
className(className) {
|
|
2172
|
+
this.config.className = className;
|
|
2173
|
+
return this;
|
|
2174
|
+
}
|
|
2175
|
+
rules(rules) {
|
|
2176
|
+
this.config.rules = [...(this.config.rules || []), ...rules];
|
|
2177
|
+
return this;
|
|
2178
|
+
}
|
|
2179
|
+
zodSchema(schema) {
|
|
2180
|
+
this.config.zodSchema = schema;
|
|
2181
|
+
return this;
|
|
2182
|
+
}
|
|
2183
|
+
dependsOn(field, condition, effect = "show", effectValue) {
|
|
2184
|
+
this.config.dependsOn = [
|
|
2185
|
+
...(this.config.dependsOn || []),
|
|
2186
|
+
{ field, condition, effect, effectValue },
|
|
2187
|
+
];
|
|
2188
|
+
return this;
|
|
2189
|
+
}
|
|
2190
|
+
reactive(reactive = true) {
|
|
2191
|
+
this.config.reactive = reactive;
|
|
2192
|
+
return this;
|
|
2193
|
+
}
|
|
2194
|
+
// --- Build ---
|
|
2195
|
+
build() {
|
|
2196
|
+
return {
|
|
2197
|
+
name: this.config.name,
|
|
2198
|
+
type: this.fieldType,
|
|
2199
|
+
config: { ...this.config },
|
|
2200
|
+
render: (props) => this.renderField(props),
|
|
2201
|
+
};
|
|
2202
|
+
}
|
|
2203
|
+
}
|
|
2204
|
+
|
|
2205
|
+
class TextInput extends BaseField {
|
|
2206
|
+
fieldType = "text";
|
|
2207
|
+
static make(name) {
|
|
2208
|
+
return new TextInput(name);
|
|
2209
|
+
}
|
|
2210
|
+
type(type) {
|
|
2211
|
+
this.config.type = type;
|
|
2212
|
+
return this;
|
|
2213
|
+
}
|
|
2214
|
+
email() {
|
|
2215
|
+
return this.type("email");
|
|
2216
|
+
}
|
|
2217
|
+
password() {
|
|
2218
|
+
return this.type("password");
|
|
2219
|
+
}
|
|
2220
|
+
number() {
|
|
2221
|
+
return this.type("number");
|
|
2222
|
+
}
|
|
2223
|
+
url() {
|
|
2224
|
+
return this.type("url");
|
|
2225
|
+
}
|
|
2226
|
+
tel() {
|
|
2227
|
+
return this.type("tel");
|
|
2228
|
+
}
|
|
2229
|
+
minLength(min) {
|
|
2230
|
+
this.config.minLength = min;
|
|
2231
|
+
this.config.rules = [
|
|
2232
|
+
...(this.config.rules || []),
|
|
2233
|
+
{
|
|
2234
|
+
type: "min",
|
|
2235
|
+
value: min,
|
|
2236
|
+
message: `${this.config.label || this.config.name} must be at least ${min} characters`,
|
|
2237
|
+
},
|
|
2238
|
+
];
|
|
2239
|
+
return this;
|
|
2240
|
+
}
|
|
2241
|
+
maxLength(max) {
|
|
2242
|
+
this.config.maxLength = max;
|
|
2243
|
+
this.config.rules = [
|
|
2244
|
+
...(this.config.rules || []),
|
|
2245
|
+
{
|
|
2246
|
+
type: "max",
|
|
2247
|
+
value: max,
|
|
2248
|
+
message: `${this.config.label || this.config.name} must be at most ${max} characters`,
|
|
2249
|
+
},
|
|
2250
|
+
];
|
|
2251
|
+
return this;
|
|
2252
|
+
}
|
|
2253
|
+
prefix(prefix) {
|
|
2254
|
+
this.config.prefix = prefix;
|
|
2255
|
+
return this;
|
|
2256
|
+
}
|
|
2257
|
+
suffix(suffix) {
|
|
2258
|
+
this.config.suffix = suffix;
|
|
2259
|
+
return this;
|
|
2260
|
+
}
|
|
2261
|
+
autocomplete(value) {
|
|
2262
|
+
this.config.autocomplete = value;
|
|
2263
|
+
return this;
|
|
2264
|
+
}
|
|
2265
|
+
renderField({ value, onChange, onBlur, error, disabled, }) {
|
|
2266
|
+
const { type, placeholder, maxLength, readOnly, autocomplete, className, prefix, suffix, } = this.config;
|
|
2267
|
+
const input = (jsx(Input, { type: type || "text", value: value ?? "", onChange: (e) => onChange(type === "number" ? Number(e.target.value) : e.target.value), onBlur: onBlur, placeholder: placeholder, maxLength: maxLength, disabled: disabled, readOnly: readOnly, autoComplete: autocomplete, className: cn(error && "border-destructive", className) }));
|
|
2268
|
+
if (prefix || suffix) {
|
|
2269
|
+
return (jsxs("div", { className: "flex items-center gap-2", children: [prefix && (jsx("span", { className: "text-sm text-muted-foreground", children: prefix })), input, suffix && (jsx("span", { className: "text-sm text-muted-foreground", children: suffix }))] }));
|
|
2270
|
+
}
|
|
2271
|
+
return input;
|
|
2272
|
+
}
|
|
2273
|
+
}
|
|
2274
|
+
|
|
2275
|
+
class Textarea extends BaseField {
|
|
2276
|
+
fieldType = "textarea";
|
|
2277
|
+
constructor(name) {
|
|
2278
|
+
super(name);
|
|
2279
|
+
this.config.rows = 3;
|
|
2280
|
+
}
|
|
2281
|
+
static make(name) {
|
|
2282
|
+
return new Textarea(name);
|
|
2283
|
+
}
|
|
2284
|
+
rows(rows) {
|
|
2285
|
+
this.config.rows = rows;
|
|
2286
|
+
return this;
|
|
2287
|
+
}
|
|
2288
|
+
minLength(min) {
|
|
2289
|
+
this.config.minLength = min;
|
|
2290
|
+
this.config.rules = [
|
|
2291
|
+
...(this.config.rules || []),
|
|
2292
|
+
{
|
|
2293
|
+
type: "min",
|
|
2294
|
+
value: min,
|
|
2295
|
+
message: `${this.config.label || this.config.name} must be at least ${min} characters`,
|
|
2296
|
+
},
|
|
2297
|
+
];
|
|
2298
|
+
return this;
|
|
2299
|
+
}
|
|
2300
|
+
maxLength(max) {
|
|
2301
|
+
this.config.maxLength = max;
|
|
2302
|
+
this.config.rules = [
|
|
2303
|
+
...(this.config.rules || []),
|
|
2304
|
+
{
|
|
2305
|
+
type: "max",
|
|
2306
|
+
value: max,
|
|
2307
|
+
message: `${this.config.label || this.config.name} must be at most ${max} characters`,
|
|
2308
|
+
},
|
|
2309
|
+
];
|
|
2310
|
+
return this;
|
|
2311
|
+
}
|
|
2312
|
+
autoResize(autoResize = true) {
|
|
2313
|
+
this.config.autoResize = autoResize;
|
|
2314
|
+
return this;
|
|
2315
|
+
}
|
|
2316
|
+
renderField({ value, onChange, onBlur, error, disabled, }) {
|
|
2317
|
+
const { placeholder, rows, maxLength, readOnly, className } = this.config;
|
|
2318
|
+
return (jsx(Textarea$1, { value: value ?? "", onChange: (e) => onChange(e.target.value), onBlur: onBlur, placeholder: placeholder, rows: rows, maxLength: maxLength, disabled: disabled, readOnly: readOnly, className: cn(error && "border-destructive", className) }));
|
|
2319
|
+
}
|
|
2320
|
+
}
|
|
2321
|
+
|
|
2322
|
+
class Select extends BaseField {
|
|
2323
|
+
fieldType = "select";
|
|
2324
|
+
constructor(name) {
|
|
2325
|
+
super(name);
|
|
2326
|
+
this.config.options = [];
|
|
2327
|
+
this.config.multiple = false;
|
|
2328
|
+
this.config.searchable = false;
|
|
2329
|
+
this.config.clearable = false;
|
|
2330
|
+
}
|
|
2331
|
+
static make(name) {
|
|
2332
|
+
return new Select(name);
|
|
2333
|
+
}
|
|
2334
|
+
options(options) {
|
|
2335
|
+
this.config.options = options;
|
|
2336
|
+
return this;
|
|
2337
|
+
}
|
|
2338
|
+
multiple(multiple = true) {
|
|
2339
|
+
this.config.multiple = multiple;
|
|
2340
|
+
return this;
|
|
2341
|
+
}
|
|
2342
|
+
searchable(searchable = true) {
|
|
2343
|
+
this.config.searchable = searchable;
|
|
2344
|
+
return this;
|
|
2345
|
+
}
|
|
2346
|
+
clearable(clearable = true) {
|
|
2347
|
+
this.config.clearable = clearable;
|
|
2348
|
+
return this;
|
|
2349
|
+
}
|
|
2350
|
+
maxItems(max) {
|
|
2351
|
+
this.config.maxItems = max;
|
|
2352
|
+
return this;
|
|
2353
|
+
}
|
|
2354
|
+
loadOptions(fn) {
|
|
2355
|
+
this.config.loadOptions = fn;
|
|
2356
|
+
return this;
|
|
2357
|
+
}
|
|
2358
|
+
renderField({ value, onChange, error, disabled, data, }) {
|
|
2359
|
+
const cfg = this.config;
|
|
2360
|
+
const resolvedOptions = typeof cfg.options === "function" ? cfg.options(data) : cfg.options;
|
|
2361
|
+
return (jsxs(Select$1, { value: value ?? "", onValueChange: onChange, disabled: disabled, children: [jsx(SelectTrigger, { className: cn(error && "border-destructive", cfg.className), children: jsx(SelectValue, { placeholder: cfg.placeholder || "Select..." }) }), jsx(SelectContent, { children: resolvedOptions.map((opt) => (jsx(SelectItem, { value: opt.value, disabled: opt.disabled, children: opt.label }, opt.value))) })] }));
|
|
2362
|
+
}
|
|
2363
|
+
}
|
|
2364
|
+
|
|
2365
|
+
class Checkbox extends BaseField {
|
|
2366
|
+
fieldType = "checkbox";
|
|
2367
|
+
static make(name) {
|
|
2368
|
+
return new Checkbox(name);
|
|
2369
|
+
}
|
|
2370
|
+
renderField({ value, onChange, error, disabled, }) {
|
|
2371
|
+
const { className } = this.config;
|
|
2372
|
+
return (jsxs("div", { className: cn("flex items-center space-x-2", className), children: [jsx(Checkbox$1, { id: this.config.name, checked: !!value, onCheckedChange: (checked) => onChange(!!checked), disabled: disabled, className: cn(error && "border-destructive") }), this.config.label && (jsx("label", { htmlFor: this.config.name, className: cn("text-sm font-medium leading-none peer-disabled:cursor-not-allowed peer-disabled:opacity-70", error && "text-destructive"), children: this.config.label }))] }));
|
|
2373
|
+
}
|
|
2374
|
+
}
|
|
2375
|
+
|
|
2376
|
+
class Toggle extends BaseField {
|
|
2377
|
+
fieldType = "toggle";
|
|
2378
|
+
static make(name) {
|
|
2379
|
+
return new Toggle(name);
|
|
2380
|
+
}
|
|
2381
|
+
onLabel(label) {
|
|
2382
|
+
this.config.onLabel = label;
|
|
2383
|
+
return this;
|
|
2384
|
+
}
|
|
2385
|
+
offLabel(label) {
|
|
2386
|
+
this.config.offLabel = label;
|
|
2387
|
+
return this;
|
|
2388
|
+
}
|
|
2389
|
+
renderField({ value, onChange, error, disabled, }) {
|
|
2390
|
+
const { onLabel, offLabel, className } = this.config;
|
|
2391
|
+
const displayLabel = value ? onLabel : offLabel;
|
|
2392
|
+
return (jsxs("div", { className: cn("flex items-center space-x-2", className), children: [jsx(Switch, { id: this.config.name, checked: !!value, onCheckedChange: (checked) => onChange(checked), disabled: disabled, className: cn(error && "border-destructive") }), displayLabel && (jsx("label", { htmlFor: this.config.name, className: "text-sm text-muted-foreground", children: displayLabel }))] }));
|
|
2393
|
+
}
|
|
2394
|
+
}
|
|
2395
|
+
|
|
2396
|
+
class RadioGroup extends BaseField {
|
|
2397
|
+
fieldType = "radio-group";
|
|
2398
|
+
constructor(name) {
|
|
2399
|
+
super(name);
|
|
2400
|
+
this.config.options = [];
|
|
2401
|
+
this.config.orientation = "vertical";
|
|
2402
|
+
}
|
|
2403
|
+
static make(name) {
|
|
2404
|
+
return new RadioGroup(name);
|
|
2405
|
+
}
|
|
2406
|
+
options(options) {
|
|
2407
|
+
this.config.options = options;
|
|
2408
|
+
return this;
|
|
2409
|
+
}
|
|
2410
|
+
orientation(orientation) {
|
|
2411
|
+
this.config.orientation = orientation;
|
|
2412
|
+
return this;
|
|
2413
|
+
}
|
|
2414
|
+
horizontal() {
|
|
2415
|
+
return this.orientation("horizontal");
|
|
2416
|
+
}
|
|
2417
|
+
vertical() {
|
|
2418
|
+
return this.orientation("vertical");
|
|
2419
|
+
}
|
|
2420
|
+
renderField({ value, onChange, error, disabled, }) {
|
|
2421
|
+
const cfg = this.config;
|
|
2422
|
+
const isHorizontal = cfg.orientation === "horizontal";
|
|
2423
|
+
return (jsx(RadioGroup$1, { value: value ?? "", onValueChange: onChange, disabled: disabled, className: cn(isHorizontal ? "flex flex-row gap-4" : "flex flex-col gap-2", cfg.className), children: cfg.options.map((opt) => (jsxs("div", { className: "flex items-center space-x-2", children: [jsx(RadioGroupItem, { value: opt.value, id: `${cfg.name}-${opt.value}`, disabled: opt.disabled, className: cn(error && "border-destructive") }), jsx(Label, { htmlFor: `${cfg.name}-${opt.value}`, className: "text-sm font-normal", children: opt.label })] }, opt.value))) }));
|
|
2424
|
+
}
|
|
2425
|
+
}
|
|
2426
|
+
|
|
2427
|
+
class DatePicker extends BaseField {
|
|
2428
|
+
fieldType = "date-picker";
|
|
2429
|
+
constructor(name) {
|
|
2430
|
+
super(name);
|
|
2431
|
+
this.config.format = "PPP";
|
|
2432
|
+
this.config.includeTime = false;
|
|
2433
|
+
this.config.locale = "en-US";
|
|
2434
|
+
}
|
|
2435
|
+
static make(name) {
|
|
2436
|
+
return new DatePicker(name);
|
|
2437
|
+
}
|
|
2438
|
+
minDate(date) {
|
|
2439
|
+
this.config.minDate = date;
|
|
2440
|
+
return this;
|
|
2441
|
+
}
|
|
2442
|
+
maxDate(date) {
|
|
2443
|
+
this.config.maxDate = date;
|
|
2444
|
+
return this;
|
|
2445
|
+
}
|
|
2446
|
+
format(format) {
|
|
2447
|
+
this.config.format = format;
|
|
2448
|
+
return this;
|
|
2449
|
+
}
|
|
2450
|
+
includeTime(includeTime = true) {
|
|
2451
|
+
this.config.includeTime = includeTime;
|
|
2452
|
+
if (includeTime) {
|
|
2453
|
+
this.fieldType = "date-time-picker";
|
|
2454
|
+
}
|
|
2455
|
+
return this;
|
|
2456
|
+
}
|
|
2457
|
+
locale(locale) {
|
|
2458
|
+
this.config.locale = locale;
|
|
2459
|
+
return this;
|
|
2460
|
+
}
|
|
2461
|
+
renderField({ value, onChange, error, disabled, data, }) {
|
|
2462
|
+
const { placeholder, className, locale } = this.config;
|
|
2463
|
+
const resolvedMinDate = typeof this.config.minDate === "function"
|
|
2464
|
+
? this.config.minDate(data)
|
|
2465
|
+
: this.config.minDate;
|
|
2466
|
+
const resolvedMaxDate = typeof this.config.maxDate === "function"
|
|
2467
|
+
? this.config.maxDate(data)
|
|
2468
|
+
: this.config.maxDate;
|
|
2469
|
+
const dateValue = value ? new Date(value) : undefined;
|
|
2470
|
+
const formatDate = (date) => {
|
|
2471
|
+
return date.toLocaleDateString(locale || "en-US", {
|
|
2472
|
+
year: "numeric",
|
|
2473
|
+
month: "long",
|
|
2474
|
+
day: "numeric",
|
|
2475
|
+
});
|
|
2476
|
+
};
|
|
2477
|
+
return (jsxs(Popover, { children: [jsx(PopoverTrigger, { asChild: true, children: jsxs(Button, { variant: "outline", disabled: disabled, className: cn("w-full justify-start text-left font-normal", !dateValue && "text-muted-foreground", error && "border-destructive", className), children: [jsx(CalendarIcon, { className: "mr-2 h-4 w-4" }), dateValue ? formatDate(dateValue) : placeholder || "Pick a date"] }) }), jsx(PopoverContent, { className: "w-auto p-0", align: "start", children: jsx(Calendar$1, { mode: "single", selected: dateValue, onSelect: (date) => onChange(date ? date.toISOString().split("T")[0] : ""), disabled: (date) => {
|
|
2478
|
+
if (resolvedMinDate && date < resolvedMinDate)
|
|
2479
|
+
return true;
|
|
2480
|
+
if (resolvedMaxDate && date > resolvedMaxDate)
|
|
2481
|
+
return true;
|
|
2482
|
+
return false;
|
|
2483
|
+
}, initialFocus: true }) })] }));
|
|
2484
|
+
}
|
|
2485
|
+
}
|
|
2486
|
+
|
|
2487
|
+
class Hidden extends BaseField {
|
|
2488
|
+
fieldType = "hidden";
|
|
2489
|
+
static make(name) {
|
|
2490
|
+
return new Hidden(name);
|
|
2491
|
+
}
|
|
2492
|
+
renderField({ value }) {
|
|
2493
|
+
return jsx("input", { type: "hidden", name: this.config.name, value: value ?? "" });
|
|
2494
|
+
}
|
|
2495
|
+
}
|
|
2496
|
+
|
|
2497
|
+
class FileUpload extends BaseField {
|
|
2498
|
+
fieldType = "file-upload";
|
|
2499
|
+
constructor(name) {
|
|
2500
|
+
super(name);
|
|
2501
|
+
this.config.multiple = false;
|
|
2502
|
+
this.config.preview = true;
|
|
2503
|
+
this.config.maxFiles = 1;
|
|
2504
|
+
}
|
|
2505
|
+
static make(name) {
|
|
2506
|
+
return new FileUpload(name);
|
|
2507
|
+
}
|
|
2508
|
+
accept(accept) {
|
|
2509
|
+
this.config.accept = accept;
|
|
2510
|
+
return this;
|
|
2511
|
+
}
|
|
2512
|
+
maxSize(bytes) {
|
|
2513
|
+
this.config.maxSize = bytes;
|
|
2514
|
+
return this;
|
|
2515
|
+
}
|
|
2516
|
+
multiple(multiple = true) {
|
|
2517
|
+
this.config.multiple = multiple;
|
|
2518
|
+
return this;
|
|
2519
|
+
}
|
|
2520
|
+
maxFiles(max) {
|
|
2521
|
+
this.config.maxFiles = max;
|
|
2522
|
+
return this;
|
|
2523
|
+
}
|
|
2524
|
+
preview(preview = true) {
|
|
2525
|
+
this.config.preview = preview;
|
|
2526
|
+
return this;
|
|
2527
|
+
}
|
|
2528
|
+
image() {
|
|
2529
|
+
return this.accept("image/*");
|
|
2530
|
+
}
|
|
2531
|
+
pdf() {
|
|
2532
|
+
return this.accept("application/pdf");
|
|
2533
|
+
}
|
|
2534
|
+
renderField({ value, onChange, error, disabled, }) {
|
|
2535
|
+
const cfg = this.config;
|
|
2536
|
+
const inputRef = useRef(null);
|
|
2537
|
+
const [dragOver, setDragOver] = useState(false);
|
|
2538
|
+
const files = Array.isArray(value) ? value : value ? [value] : [];
|
|
2539
|
+
const handleFiles = (fileList) => {
|
|
2540
|
+
if (!fileList)
|
|
2541
|
+
return;
|
|
2542
|
+
const newFiles = Array.from(fileList);
|
|
2543
|
+
if (cfg.maxSize) {
|
|
2544
|
+
const oversized = newFiles.find((f) => f.size > cfg.maxSize);
|
|
2545
|
+
if (oversized)
|
|
2546
|
+
return;
|
|
2547
|
+
}
|
|
2548
|
+
if (cfg.multiple) {
|
|
2549
|
+
const combined = [...files, ...newFiles].slice(0, cfg.maxFiles);
|
|
2550
|
+
onChange(combined);
|
|
2551
|
+
}
|
|
2552
|
+
else {
|
|
2553
|
+
onChange(newFiles[0] || null);
|
|
2554
|
+
}
|
|
2555
|
+
};
|
|
2556
|
+
const removeFile = (index) => {
|
|
2557
|
+
if (cfg.multiple) {
|
|
2558
|
+
const updated = files.filter((_, i) => i !== index);
|
|
2559
|
+
onChange(updated.length ? updated : null);
|
|
2560
|
+
}
|
|
2561
|
+
else {
|
|
2562
|
+
onChange(null);
|
|
2563
|
+
}
|
|
2564
|
+
};
|
|
2565
|
+
return (jsxs("div", { className: cn("space-y-2", cfg.className), children: [jsxs("div", { className: cn("flex flex-col items-center justify-center rounded-lg border-2 border-dashed p-6 transition-colors", dragOver
|
|
2566
|
+
? "border-primary bg-primary/5"
|
|
2567
|
+
: "border-muted-foreground/25", error && "border-destructive", disabled && "cursor-not-allowed opacity-50"), onDragOver: (e) => {
|
|
2568
|
+
e.preventDefault();
|
|
2569
|
+
if (!disabled)
|
|
2570
|
+
setDragOver(true);
|
|
2571
|
+
}, onDragLeave: () => setDragOver(false), onDrop: (e) => {
|
|
2572
|
+
e.preventDefault();
|
|
2573
|
+
setDragOver(false);
|
|
2574
|
+
if (!disabled)
|
|
2575
|
+
handleFiles(e.dataTransfer.files);
|
|
2576
|
+
}, children: [jsx(Upload, { className: "mb-2 h-8 w-8 text-muted-foreground" }), jsxs("p", { className: "text-sm text-muted-foreground", children: ["Drag & drop or", " ", jsx("button", { type: "button", className: "text-primary underline", onClick: () => inputRef.current?.click(), disabled: disabled, children: "browse" })] }), cfg.accept && (jsxs("p", { className: "mt-1 text-xs text-muted-foreground", children: ["Accepted: ", cfg.accept] })), jsx("input", { ref: inputRef, type: "file", accept: cfg.accept, multiple: cfg.multiple, onChange: (e) => handleFiles(e.target.files), className: "hidden", disabled: disabled })] }), files.length > 0 && (jsx("ul", { className: "space-y-1", children: files.map((file, index) => (jsxs("li", { className: "flex items-center justify-between rounded-md border px-3 py-2 text-sm", children: [jsxs("span", { className: "flex items-center gap-2 truncate", children: [jsx(File, { className: "h-4 w-4 text-muted-foreground" }), file.name] }), jsx(Button, { type: "button", variant: "ghost", size: "sm", className: "h-6 w-6 p-0", onClick: () => removeFile(index), disabled: disabled, children: jsx(X, { className: "h-3 w-3" }) })] }, index))) }))] }));
|
|
2577
|
+
}
|
|
2578
|
+
}
|
|
2579
|
+
|
|
2580
|
+
class CheckboxGroup extends BaseField {
|
|
2581
|
+
fieldType = "checkbox-group";
|
|
2582
|
+
constructor(name) {
|
|
2583
|
+
super(name);
|
|
2584
|
+
this.config.options = [];
|
|
2585
|
+
this.config.columns = 1;
|
|
2586
|
+
}
|
|
2587
|
+
static make(name) {
|
|
2588
|
+
return new CheckboxGroup(name);
|
|
2589
|
+
}
|
|
2590
|
+
options(options) {
|
|
2591
|
+
this.config.options = options;
|
|
2592
|
+
return this;
|
|
2593
|
+
}
|
|
2594
|
+
columns(columns) {
|
|
2595
|
+
this.config.columns = columns;
|
|
2596
|
+
return this;
|
|
2597
|
+
}
|
|
2598
|
+
renderField({ value, onChange, error, disabled, }) {
|
|
2599
|
+
const cfg = this.config;
|
|
2600
|
+
const selectedValues = Array.isArray(value) ? value : [];
|
|
2601
|
+
const gridColsClass = {
|
|
2602
|
+
1: "grid-cols-1",
|
|
2603
|
+
2: "grid-cols-2",
|
|
2604
|
+
3: "grid-cols-3",
|
|
2605
|
+
4: "grid-cols-4",
|
|
2606
|
+
};
|
|
2607
|
+
const handleToggle = (optionValue, checked) => {
|
|
2608
|
+
if (checked) {
|
|
2609
|
+
onChange([...selectedValues, optionValue]);
|
|
2610
|
+
}
|
|
2611
|
+
else {
|
|
2612
|
+
onChange(selectedValues.filter((v) => v !== optionValue));
|
|
2613
|
+
}
|
|
2614
|
+
};
|
|
2615
|
+
return (jsx("div", { className: cn("grid gap-2", gridColsClass[cfg.columns || 1] || gridColsClass[1], cfg.className), children: cfg.options.map((opt) => (jsxs("div", { className: "flex items-center space-x-2", children: [jsx(Checkbox$1, { id: `${cfg.name}-${opt.value}`, checked: selectedValues.includes(opt.value), onCheckedChange: (checked) => handleToggle(opt.value, !!checked), disabled: disabled || opt.disabled, className: cn(error && "border-destructive") }), jsx(Label, { htmlFor: `${cfg.name}-${opt.value}`, className: "text-sm font-normal", children: opt.label })] }, opt.value))) }));
|
|
2616
|
+
}
|
|
2617
|
+
}
|
|
2618
|
+
|
|
2619
|
+
class Repeater extends BaseField {
|
|
2620
|
+
fieldType = "repeater";
|
|
2621
|
+
fieldBuilders = [];
|
|
2622
|
+
constructor(name) {
|
|
2623
|
+
super(name);
|
|
2624
|
+
this.config.minItems = 0;
|
|
2625
|
+
this.config.maxItems = Infinity;
|
|
2626
|
+
this.config.addLabel = "Add item";
|
|
2627
|
+
this.config.collapsible = false;
|
|
2628
|
+
this.config.orderable = false;
|
|
2629
|
+
}
|
|
2630
|
+
static make(name) {
|
|
2631
|
+
return new Repeater(name);
|
|
2632
|
+
}
|
|
2633
|
+
fields(...builders) {
|
|
2634
|
+
this.fieldBuilders = builders;
|
|
2635
|
+
this.config.fields = builders.map((b) => b.build());
|
|
2636
|
+
return this;
|
|
2637
|
+
}
|
|
2638
|
+
minItems(min) {
|
|
2639
|
+
this.config.minItems = min;
|
|
2640
|
+
return this;
|
|
2641
|
+
}
|
|
2642
|
+
maxItems(max) {
|
|
2643
|
+
this.config.maxItems = max;
|
|
2644
|
+
return this;
|
|
2645
|
+
}
|
|
2646
|
+
addLabel(label) {
|
|
2647
|
+
this.config.addLabel = label;
|
|
2648
|
+
return this;
|
|
2649
|
+
}
|
|
2650
|
+
collapsible(collapsible = true) {
|
|
2651
|
+
this.config.collapsible = collapsible;
|
|
2652
|
+
return this;
|
|
2653
|
+
}
|
|
2654
|
+
orderable(orderable = true) {
|
|
2655
|
+
this.config.orderable = orderable;
|
|
2656
|
+
return this;
|
|
2657
|
+
}
|
|
2658
|
+
renderField({ value, onChange, error, disabled, data, }) {
|
|
2659
|
+
const cfg = this.config;
|
|
2660
|
+
const items = Array.isArray(value) ? value : [];
|
|
2661
|
+
const builtFields = cfg.fields;
|
|
2662
|
+
const addItem = () => {
|
|
2663
|
+
if (items.length >= (cfg.maxItems || Infinity))
|
|
2664
|
+
return;
|
|
2665
|
+
const defaults = {};
|
|
2666
|
+
builtFields.forEach((f) => {
|
|
2667
|
+
defaults[f.name] = f.config.defaultValue ?? "";
|
|
2668
|
+
});
|
|
2669
|
+
onChange([...items, defaults]);
|
|
2670
|
+
};
|
|
2671
|
+
const removeItem = (index) => {
|
|
2672
|
+
if (items.length <= (cfg.minItems || 0))
|
|
2673
|
+
return;
|
|
2674
|
+
onChange(items.filter((_, i) => i !== index));
|
|
2675
|
+
};
|
|
2676
|
+
const updateItem = (index, fieldName, fieldValue) => {
|
|
2677
|
+
const updated = items.map((item, i) => i === index ? { ...item, [fieldName]: fieldValue } : item);
|
|
2678
|
+
onChange(updated);
|
|
2679
|
+
};
|
|
2680
|
+
const canAdd = items.length < (cfg.maxItems || Infinity);
|
|
2681
|
+
const canRemove = items.length > (cfg.minItems || 0);
|
|
2682
|
+
return (jsxs("div", { className: cn("space-y-3", cfg.className), children: [items.map((item, index) => (jsx(Card, { children: jsxs(CardContent, { className: "flex items-start gap-3 pt-4", children: [cfg.orderable && (jsx(GripVertical, { className: "mt-2 h-5 w-5 cursor-grab text-muted-foreground" })), jsx("div", { className: "grid flex-1 gap-3", children: builtFields.map((field) => (jsxs("div", { className: "space-y-1", children: [field.config.label && (jsx("label", { className: "text-sm font-medium", children: field.config.label })), field.render({
|
|
2683
|
+
value: item[field.name],
|
|
2684
|
+
onChange: (v) => updateItem(index, field.name, v),
|
|
2685
|
+
disabled,
|
|
2686
|
+
data,
|
|
2687
|
+
})] }, field.name))) }), canRemove && (jsx(Button, { type: "button", variant: "ghost", size: "sm", className: "mt-1 h-8 w-8 p-0 text-destructive", onClick: () => removeItem(index), disabled: disabled, children: jsx(Trash2, { className: "h-4 w-4" }) }))] }) }, index))), canAdd && (jsxs(Button, { type: "button", variant: "outline", size: "sm", onClick: addItem, disabled: disabled, className: "w-full", children: [jsx(Plus, { className: "mr-2 h-4 w-4" }), cfg.addLabel] }))] }));
|
|
2688
|
+
}
|
|
2689
|
+
}
|
|
2690
|
+
|
|
2691
|
+
function FieldRenderer({ field, value, error, disabled, data, onChange, onBlur, }) {
|
|
2692
|
+
// Hidden fields render without wrapper
|
|
2693
|
+
if (field.type === "hidden") {
|
|
2694
|
+
return field.render({ value, onChange, onBlur, error, disabled, data });
|
|
2695
|
+
}
|
|
2696
|
+
// Checkbox and Toggle handle their own labels inline
|
|
2697
|
+
const skipLabel = field.type === "checkbox" || field.type === "toggle";
|
|
2698
|
+
return (jsxs("div", { className: cn("space-y-2", field.config.columnSpan && field.config.columnSpan > 1
|
|
2699
|
+
? `col-span-${field.config.columnSpan}`
|
|
2700
|
+
: undefined, field.config.className), children: [field.config.label && !skipLabel && (jsxs(Label, { htmlFor: field.name, className: cn(error && "text-destructive"), children: [field.config.label, field.config.required && (jsx("span", { className: "text-destructive ml-1", children: "*" }))] })), field.render({
|
|
2701
|
+
value,
|
|
2702
|
+
onChange,
|
|
2703
|
+
onBlur,
|
|
2704
|
+
error,
|
|
2705
|
+
disabled,
|
|
2706
|
+
data,
|
|
2707
|
+
}), error && jsx("p", { className: "text-sm text-destructive", children: error }), !error && field.config.helperText && (jsx("p", { className: "text-sm text-muted-foreground", children: field.config.helperText }))] }));
|
|
2708
|
+
}
|
|
2709
|
+
|
|
2710
|
+
const gridColsClass = {
|
|
2711
|
+
1: "grid-cols-1",
|
|
2712
|
+
2: "grid-cols-1 sm:grid-cols-2",
|
|
2713
|
+
3: "grid-cols-1 sm:grid-cols-2 lg:grid-cols-3",
|
|
2714
|
+
4: "grid-cols-1 sm:grid-cols-2 lg:grid-cols-4",
|
|
2715
|
+
};
|
|
2716
|
+
function GridLayout({ columns = 1, children, className, }) {
|
|
2717
|
+
return (jsx("div", { className: cn("grid gap-4", gridColsClass[columns] || gridColsClass[1], className), children: children }));
|
|
2718
|
+
}
|
|
2719
|
+
|
|
2720
|
+
const positionClass = {
|
|
2721
|
+
start: "justify-start",
|
|
2722
|
+
center: "justify-center",
|
|
2723
|
+
between: "justify-between",
|
|
2724
|
+
end: "justify-end",
|
|
2725
|
+
};
|
|
2726
|
+
function FormActions({ actions, position = "end", data, processing = false, }) {
|
|
2727
|
+
if (!actions.length)
|
|
2728
|
+
return null;
|
|
2729
|
+
return (jsx("div", { className: cn("flex gap-2", positionClass[position]), children: actions.map((action, i) => {
|
|
2730
|
+
const isDisabled = typeof action.disabled === "function"
|
|
2731
|
+
? action.disabled(data, processing)
|
|
2732
|
+
: action.disabled;
|
|
2733
|
+
if (action.type === "submit") {
|
|
2734
|
+
return (jsxs(Button, { type: "submit", variant: action.variant || "default", disabled: isDisabled || processing, children: [action.icon && jsx("span", { className: "mr-2", children: action.icon }), processing ? "Processing..." : action.label] }, i));
|
|
2735
|
+
}
|
|
2736
|
+
if (action.type === "cancel" && action.href) {
|
|
2737
|
+
return (jsx(Button, { type: "button", variant: action.variant || "outline", disabled: processing, asChild: true, children: jsxs("a", { href: action.href, children: [action.icon && jsx("span", { className: "mr-2", children: action.icon }), action.label] }) }, i));
|
|
2738
|
+
}
|
|
2739
|
+
return (jsxs(Button, { type: "button", variant: action.variant || "outline", onClick: action.onClick, disabled: isDisabled || (action.type === "cancel" && processing), children: [action.icon && jsx("span", { className: "mr-2", children: action.icon }), action.label] }, i));
|
|
2740
|
+
}) }));
|
|
2741
|
+
}
|
|
2742
|
+
|
|
2743
|
+
function SectionRenderer({ section, fields, data, errors, onChange, onBlur, isFieldVisible, isFieldDisabled, }) {
|
|
2744
|
+
const [isCollapsed, setIsCollapsed] = useState(section.collapsed ?? false);
|
|
2745
|
+
if (section.hidden && section.hidden(data))
|
|
2746
|
+
return null;
|
|
2747
|
+
const sectionFields = fields.filter((f) => section.fields.includes(f.name));
|
|
2748
|
+
return (jsxs(Card, { children: [jsxs(CardHeader, { className: cn(section.collapsible && "cursor-pointer select-none"), onClick: section.collapsible ? () => setIsCollapsed(!isCollapsed) : undefined, children: [jsxs("div", { className: "flex items-center justify-between", children: [jsxs("div", { className: "flex items-center gap-2", children: [section.icon, jsx(CardTitle, { className: "text-lg", children: section.title })] }), section.collapsible && (jsx(Button, { variant: "ghost", size: "sm", className: "h-8 w-8 p-0", children: jsx(ChevronDown, { className: cn("h-4 w-4 transition-transform", isCollapsed && "-rotate-90") }) }))] }), section.description && (jsx(CardDescription, { children: section.description }))] }), !isCollapsed && (jsx(CardContent, { children: jsx(GridLayout, { columns: section.columns, children: sectionFields.map((field) => {
|
|
2749
|
+
if (!isFieldVisible(field))
|
|
2750
|
+
return null;
|
|
2751
|
+
return (jsx(FieldRenderer, { field: field, value: data[field.name], error: errors[field.name], disabled: isFieldDisabled(field), data: data, onChange: (v) => onChange(field.name, v), onBlur: onBlur ? () => onBlur(field.name) : undefined }, field.name));
|
|
2752
|
+
}) }) }))] }));
|
|
2753
|
+
}
|
|
2754
|
+
|
|
2755
|
+
function TabRenderer({ tabs, fields, data, errors, onChange, onBlur, isFieldVisible, isFieldDisabled, columns, }) {
|
|
2756
|
+
const firstTab = tabs[0]?.id;
|
|
2757
|
+
return (jsxs(Tabs, { defaultValue: firstTab, children: [jsx(TabsList, { children: tabs.map((tab) => {
|
|
2758
|
+
const isDisabled = tab.disabled ? tab.disabled(data) : false;
|
|
2759
|
+
const badge = typeof tab.badge === "function" ? tab.badge(data) : tab.badge;
|
|
2760
|
+
return (jsx(TabsTrigger, { value: tab.id, disabled: isDisabled, children: jsxs("span", { className: "flex items-center gap-2", children: [tab.icon, tab.label, badge !== undefined && badge !== null && (jsx("span", { className: "ml-1 rounded-full bg-muted px-2 py-0.5 text-xs", children: badge }))] }) }, tab.id));
|
|
2761
|
+
}) }), tabs.map((tab) => {
|
|
2762
|
+
const tabFields = tab.fields
|
|
2763
|
+
? fields.filter((f) => tab.fields.includes(f.name))
|
|
2764
|
+
: [];
|
|
2765
|
+
return (jsx(TabsContent, { value: tab.id, className: "mt-4", children: tab.sections ? (jsx("div", { className: "space-y-4", children: tab.sections.map((section) => (jsx(SectionRenderer, { section: section, fields: fields, data: data, errors: errors, onChange: onChange, onBlur: onBlur, isFieldVisible: isFieldVisible, isFieldDisabled: isFieldDisabled }, section.id))) })) : (jsx(GridLayout, { columns: columns, children: tabFields.map((field) => {
|
|
2766
|
+
if (!isFieldVisible(field))
|
|
2767
|
+
return null;
|
|
2768
|
+
return (jsx(FieldRenderer, { field: field, value: data[field.name], error: errors[field.name], disabled: isFieldDisabled(field), data: data, onChange: (v) => onChange(field.name, v), onBlur: onBlur ? () => onBlur(field.name) : undefined }, field.name));
|
|
2769
|
+
}) })) }, tab.id));
|
|
2770
|
+
})] }));
|
|
2771
|
+
}
|
|
2772
|
+
|
|
2773
|
+
function WizardRenderer({ steps, fields, data, errors, onChange, onBlur, isFieldVisible, isFieldDisabled, columns, onSubmit, processing = false, }) {
|
|
2774
|
+
const [currentStep, setCurrentStep] = useState(0);
|
|
2775
|
+
const currentStepConfig = steps[currentStep];
|
|
2776
|
+
const isLastStep = currentStep === steps.length - 1;
|
|
2777
|
+
const isFirstStep = currentStep === 0;
|
|
2778
|
+
const canProceed = currentStepConfig?.canProceed
|
|
2779
|
+
? currentStepConfig.canProceed(data)
|
|
2780
|
+
: true;
|
|
2781
|
+
const handleNext = useCallback(async () => {
|
|
2782
|
+
if (currentStepConfig?.beforeNext) {
|
|
2783
|
+
const canContinue = await currentStepConfig.beforeNext(data);
|
|
2784
|
+
if (!canContinue)
|
|
2785
|
+
return;
|
|
2786
|
+
}
|
|
2787
|
+
if (isLastStep) {
|
|
2788
|
+
onSubmit();
|
|
2789
|
+
}
|
|
2790
|
+
else {
|
|
2791
|
+
setCurrentStep((prev) => Math.min(prev + 1, steps.length - 1));
|
|
2792
|
+
}
|
|
2793
|
+
}, [currentStep, currentStepConfig, data, isLastStep, onSubmit, steps.length]);
|
|
2794
|
+
const handlePrevious = useCallback(() => {
|
|
2795
|
+
setCurrentStep((prev) => Math.max(prev - 1, 0));
|
|
2796
|
+
}, []);
|
|
2797
|
+
const stepFields = currentStepConfig?.fields
|
|
2798
|
+
? fields.filter((f) => currentStepConfig.fields.includes(f.name))
|
|
2799
|
+
: [];
|
|
2800
|
+
return (jsxs("div", { className: "space-y-6", children: [jsx("nav", { "aria-label": "Progress", children: jsx("ol", { className: "flex items-center", children: steps.map((step, index) => (jsxs("li", { className: cn("flex items-center", index < steps.length - 1 && "flex-1"), children: [jsxs("div", { className: "flex items-center gap-2", children: [jsx("div", { className: cn("flex h-8 w-8 items-center justify-center rounded-full border-2 text-sm font-medium", index < currentStep &&
|
|
2801
|
+
"border-primary bg-primary text-primary-foreground", index === currentStep &&
|
|
2802
|
+
"border-primary text-primary", index > currentStep &&
|
|
2803
|
+
"border-muted-foreground/25 text-muted-foreground"), children: index < currentStep ? (jsx(Check, { className: "h-4 w-4" })) : (index + 1) }), jsxs("div", { className: "hidden sm:block", children: [jsx("p", { className: cn("text-sm font-medium", index <= currentStep
|
|
2804
|
+
? "text-foreground"
|
|
2805
|
+
: "text-muted-foreground"), children: step.label }), step.description && (jsx("p", { className: "text-xs text-muted-foreground", children: step.description }))] })] }), index < steps.length - 1 && (jsx("div", { className: cn("mx-4 hidden h-0.5 flex-1 sm:block", index < currentStep ? "bg-primary" : "bg-muted") }))] }, step.id))) }) }), jsx("div", { children: currentStepConfig?.sections ? (jsx("div", { className: "space-y-4", children: currentStepConfig.sections.map((section) => (jsx(SectionRenderer, { section: section, fields: fields, data: data, errors: errors, onChange: onChange, onBlur: onBlur, isFieldVisible: isFieldVisible, isFieldDisabled: isFieldDisabled }, section.id))) })) : (jsx(GridLayout, { columns: columns, children: stepFields.map((field) => {
|
|
2806
|
+
if (!isFieldVisible(field))
|
|
2807
|
+
return null;
|
|
2808
|
+
return (jsx(FieldRenderer, { field: field, value: data[field.name], error: errors[field.name], disabled: isFieldDisabled(field), data: data, onChange: (v) => onChange(field.name, v), onBlur: onBlur ? () => onBlur(field.name) : undefined }, field.name));
|
|
2809
|
+
}) })) }), jsxs("div", { className: "flex justify-between", children: [jsx(Button, { type: "button", variant: "outline", onClick: handlePrevious, disabled: isFirstStep, children: "Previous" }), jsx(Button, { type: isLastStep ? "submit" : "button", onClick: handleNext, disabled: !canProceed || (isLastStep && processing), children: isLastStep
|
|
2810
|
+
? processing
|
|
2811
|
+
? "Processing..."
|
|
2812
|
+
: "Submit"
|
|
2813
|
+
: "Next" })] })] }));
|
|
2814
|
+
}
|
|
2815
|
+
|
|
2816
|
+
function FormRenderer({ schema, data, errors, onChange, onSubmit, processing = false, className, disabled = false, onBlur, }) {
|
|
2817
|
+
const { fields, config } = schema;
|
|
2818
|
+
const resolvedTitle = useMemo(() => {
|
|
2819
|
+
if (typeof config.title === "function")
|
|
2820
|
+
return config.title(data);
|
|
2821
|
+
return config.title;
|
|
2822
|
+
}, [config.title, data]);
|
|
2823
|
+
const resolvedDescription = useMemo(() => {
|
|
2824
|
+
if (typeof config.description === "function")
|
|
2825
|
+
return config.description(data);
|
|
2826
|
+
return config.description;
|
|
2827
|
+
}, [config.description, data]);
|
|
2828
|
+
const isFieldVisible = useCallback((field) => {
|
|
2829
|
+
if (typeof field.config.hidden === "function")
|
|
2830
|
+
return !field.config.hidden(data);
|
|
2831
|
+
if (typeof field.config.hidden === "boolean")
|
|
2832
|
+
return !field.config.hidden;
|
|
2833
|
+
for (const dep of field.config.dependsOn || []) {
|
|
2834
|
+
const depValue = data[dep.field];
|
|
2835
|
+
if (dep.effect === "show" && !dep.condition(depValue, data))
|
|
2836
|
+
return false;
|
|
2837
|
+
if (dep.effect === "hide" && dep.condition(depValue, data))
|
|
2838
|
+
return false;
|
|
2839
|
+
}
|
|
2840
|
+
return true;
|
|
2841
|
+
}, [data]);
|
|
2842
|
+
const isFieldDisabled = useCallback((field) => {
|
|
2843
|
+
if (disabled)
|
|
2844
|
+
return true;
|
|
2845
|
+
if (typeof config.disabled === "function" && config.disabled(data))
|
|
2846
|
+
return true;
|
|
2847
|
+
if (typeof config.disabled === "boolean" && config.disabled)
|
|
2848
|
+
return true;
|
|
2849
|
+
if (typeof field.config.disabled === "function")
|
|
2850
|
+
return field.config.disabled(data);
|
|
2851
|
+
if (typeof field.config.disabled === "boolean")
|
|
2852
|
+
return field.config.disabled;
|
|
2853
|
+
for (const dep of field.config.dependsOn || []) {
|
|
2854
|
+
const depValue = data[dep.field];
|
|
2855
|
+
if (dep.effect === "disable" && dep.condition(depValue, data))
|
|
2856
|
+
return true;
|
|
2857
|
+
if (dep.effect === "enable" &&
|
|
2858
|
+
!dep.condition(depValue, data))
|
|
2859
|
+
return true;
|
|
2860
|
+
}
|
|
2861
|
+
return false;
|
|
2862
|
+
}, [disabled, config.disabled, data]);
|
|
2863
|
+
const renderFieldsFlat = () => (jsx(GridLayout, { columns: config.columns, children: fields.map((field) => {
|
|
2864
|
+
if (!isFieldVisible(field))
|
|
2865
|
+
return null;
|
|
2866
|
+
return (jsx(FieldRenderer, { field: field, value: data[field.name], error: errors[field.name], disabled: isFieldDisabled(field), data: data, onChange: (v) => onChange(field.name, v), onBlur: onBlur ? () => onBlur(field.name) : undefined }, field.name));
|
|
2867
|
+
}) }));
|
|
2868
|
+
const renderContent = () => {
|
|
2869
|
+
// Wizard mode
|
|
2870
|
+
if (config.wizardSteps?.length) {
|
|
2871
|
+
return (jsx(WizardRenderer, { steps: config.wizardSteps, fields: fields, data: data, errors: errors, onChange: onChange, onBlur: onBlur, isFieldVisible: isFieldVisible, isFieldDisabled: isFieldDisabled, columns: config.columns, onSubmit: onSubmit, processing: processing }));
|
|
2872
|
+
}
|
|
2873
|
+
// Tabs mode
|
|
2874
|
+
if (config.tabs?.length) {
|
|
2875
|
+
return (jsx(TabRenderer, { tabs: config.tabs, fields: fields, data: data, errors: errors, onChange: onChange, onBlur: onBlur, isFieldVisible: isFieldVisible, isFieldDisabled: isFieldDisabled, columns: config.columns }));
|
|
2876
|
+
}
|
|
2877
|
+
// Sections mode
|
|
2878
|
+
if (config.sections?.length) {
|
|
2879
|
+
return (jsx("div", { className: "space-y-4", children: config.sections.map((section) => (jsx(SectionRenderer, { section: section, fields: fields, data: data, errors: errors, onChange: onChange, onBlur: onBlur, isFieldVisible: isFieldVisible, isFieldDisabled: isFieldDisabled }, section.id))) }));
|
|
2880
|
+
}
|
|
2881
|
+
// Flat mode (default)
|
|
2882
|
+
return renderFieldsFlat();
|
|
2883
|
+
};
|
|
2884
|
+
const spacingClass = {
|
|
2885
|
+
compact: "space-y-3",
|
|
2886
|
+
normal: "space-y-6",
|
|
2887
|
+
relaxed: "space-y-8",
|
|
2888
|
+
}[config.spacing || "normal"];
|
|
2889
|
+
// Wizard handles its own submit button
|
|
2890
|
+
const showActions = config.actions?.length && !config.wizardSteps?.length;
|
|
2891
|
+
const formBody = (jsxs("form", { onSubmit: (e) => {
|
|
2892
|
+
e.preventDefault();
|
|
2893
|
+
onSubmit();
|
|
2894
|
+
}, className: cn(spacingClass, className), children: [(resolvedTitle || resolvedDescription) && (jsxs("div", { className: "space-y-1", children: [resolvedTitle && (jsx("h2", { className: "text-2xl font-semibold tracking-tight", children: resolvedTitle })), resolvedDescription && (jsx("p", { className: "text-sm text-muted-foreground", children: resolvedDescription }))] })), renderContent(), showActions && (jsx(FormActions, { actions: config.actions, position: config.actionsPosition, data: data, processing: processing }))] }));
|
|
2895
|
+
if (config.bordered) {
|
|
2896
|
+
return (jsx(Card, { children: jsx(CardContent, { className: "pt-6", children: formBody }) }));
|
|
2897
|
+
}
|
|
2898
|
+
return formBody;
|
|
2899
|
+
}
|
|
2900
|
+
|
|
2901
|
+
export { ActionsBuilder, ActionsColumn, AvatarGroupColumn, BadgeColumn, ButtonColumn, Checkbox, CheckboxColumn, CheckboxGroup, ConfirmProvider, DataTable, DataTableSchema, DateColumn, DatePicker, DropdownColumn, EmptyStateBuilder, EnumColumn, FileUpload, FormRenderer, FormSchema, Hidden, IconColumn, ImageColumn, InputColumn, LinkColumn, NumberColumn, ProgressColumn, RadioGroup, Repeater, SectionBuilder, Select, SelectColumn, TabBuilder, TableSchema, TextColumn, TextInput, Textarea, Toggle, WizardStep, ActionsColumn as actionsColumn, AvatarGroupColumn as avatarGroupColumn, BadgeColumn as badgeColumn, ButtonColumn as buttonColumn, CheckboxColumn as checkboxColumn, confirm, DateColumn as dateColumn, DropdownColumn as dropdownColumn, EnumColumn as enumColumn, IconColumn as iconColumn, InputColumn as inputColumn, TextColumn as textColumn };
|
|
1861
2902
|
//# sourceMappingURL=index.esm.js.map
|