react-table-craft 0.1.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/CHANGELOG.md +21 -0
- package/LICENSE +21 -0
- package/README.md +407 -0
- package/dist/index.d.mts +639 -0
- package/dist/index.d.ts +639 -0
- package/dist/index.js +3487 -0
- package/dist/index.js.map +1 -0
- package/dist/index.mjs +3431 -0
- package/dist/index.mjs.map +1 -0
- package/package.json +76 -0
package/dist/index.js
ADDED
|
@@ -0,0 +1,3487 @@
|
|
|
1
|
+
'use strict';
|
|
2
|
+
|
|
3
|
+
var React22 = require('react');
|
|
4
|
+
var reactTable = require('@tanstack/react-table');
|
|
5
|
+
var clsx = require('clsx');
|
|
6
|
+
var tailwindMerge = require('tailwind-merge');
|
|
7
|
+
var jsxRuntime = require('react/jsx-runtime');
|
|
8
|
+
var lucideReact = require('lucide-react');
|
|
9
|
+
var reactSlot = require('@radix-ui/react-slot');
|
|
10
|
+
var classVarianceAuthority = require('class-variance-authority');
|
|
11
|
+
var SelectPrimitive = require('@radix-ui/react-select');
|
|
12
|
+
var dateFns = require('date-fns');
|
|
13
|
+
var locale = require('date-fns/locale');
|
|
14
|
+
var exportToCsv = require('export-to-csv');
|
|
15
|
+
var CheckboxPrimitive = require('@radix-ui/react-checkbox');
|
|
16
|
+
var PopoverPrimitive = require('@radix-ui/react-popover');
|
|
17
|
+
var cmdk = require('cmdk');
|
|
18
|
+
var DropdownMenuPrimitive = require('@radix-ui/react-dropdown-menu');
|
|
19
|
+
var TooltipPrimitive = require('@radix-ui/react-tooltip');
|
|
20
|
+
var vaul = require('vaul');
|
|
21
|
+
|
|
22
|
+
function _interopNamespace(e) {
|
|
23
|
+
if (e && e.__esModule) return e;
|
|
24
|
+
var n = Object.create(null);
|
|
25
|
+
if (e) {
|
|
26
|
+
Object.keys(e).forEach(function (k) {
|
|
27
|
+
if (k !== 'default') {
|
|
28
|
+
var d = Object.getOwnPropertyDescriptor(e, k);
|
|
29
|
+
Object.defineProperty(n, k, d.get ? d : {
|
|
30
|
+
enumerable: true,
|
|
31
|
+
get: function () { return e[k]; }
|
|
32
|
+
});
|
|
33
|
+
}
|
|
34
|
+
});
|
|
35
|
+
}
|
|
36
|
+
n.default = e;
|
|
37
|
+
return Object.freeze(n);
|
|
38
|
+
}
|
|
39
|
+
|
|
40
|
+
var React22__namespace = /*#__PURE__*/_interopNamespace(React22);
|
|
41
|
+
var SelectPrimitive__namespace = /*#__PURE__*/_interopNamespace(SelectPrimitive);
|
|
42
|
+
var CheckboxPrimitive__namespace = /*#__PURE__*/_interopNamespace(CheckboxPrimitive);
|
|
43
|
+
var PopoverPrimitive__namespace = /*#__PURE__*/_interopNamespace(PopoverPrimitive);
|
|
44
|
+
var DropdownMenuPrimitive__namespace = /*#__PURE__*/_interopNamespace(DropdownMenuPrimitive);
|
|
45
|
+
var TooltipPrimitive__namespace = /*#__PURE__*/_interopNamespace(TooltipPrimitive);
|
|
46
|
+
|
|
47
|
+
// src/components/data-table.tsx
|
|
48
|
+
function useDebounce(value, delay) {
|
|
49
|
+
const [debouncedValue, setDebouncedValue] = React22.useState(value);
|
|
50
|
+
React22.useEffect(() => {
|
|
51
|
+
const handler = setTimeout(() => {
|
|
52
|
+
setDebouncedValue(value);
|
|
53
|
+
}, delay);
|
|
54
|
+
return () => {
|
|
55
|
+
clearTimeout(handler);
|
|
56
|
+
};
|
|
57
|
+
}, [value, delay]);
|
|
58
|
+
return debouncedValue;
|
|
59
|
+
}
|
|
60
|
+
function cn(...inputs) {
|
|
61
|
+
return tailwindMerge.twMerge(clsx.clsx(inputs));
|
|
62
|
+
}
|
|
63
|
+
var Table = React22__namespace.forwardRef(
|
|
64
|
+
({ className, ...props }, ref) => /* @__PURE__ */ jsxRuntime.jsx("div", { className: "relative w-full overflow-auto", children: /* @__PURE__ */ jsxRuntime.jsx(
|
|
65
|
+
"table",
|
|
66
|
+
{
|
|
67
|
+
ref,
|
|
68
|
+
className: cn("w-full caption-bottom text-sm", className),
|
|
69
|
+
...props
|
|
70
|
+
}
|
|
71
|
+
) })
|
|
72
|
+
);
|
|
73
|
+
Table.displayName = "Table";
|
|
74
|
+
var TableHeader = React22__namespace.forwardRef(({ className, ...props }, ref) => /* @__PURE__ */ jsxRuntime.jsx("thead", { ref, className: cn("[&_tr]:border-b", className), ...props }));
|
|
75
|
+
TableHeader.displayName = "TableHeader";
|
|
76
|
+
var TableBody = React22__namespace.forwardRef(({ className, ...props }, ref) => /* @__PURE__ */ jsxRuntime.jsx("tbody", { ref, className: cn("[&_tr:last-child]:border-0", className), ...props }));
|
|
77
|
+
TableBody.displayName = "TableBody";
|
|
78
|
+
var TableFooter = React22__namespace.forwardRef(({ className, ...props }, ref) => /* @__PURE__ */ jsxRuntime.jsx(
|
|
79
|
+
"tfoot",
|
|
80
|
+
{
|
|
81
|
+
ref,
|
|
82
|
+
className: cn("border-t bg-muted/50 font-medium [&>tr]:last:border-b-0", className),
|
|
83
|
+
...props
|
|
84
|
+
}
|
|
85
|
+
));
|
|
86
|
+
TableFooter.displayName = "TableFooter";
|
|
87
|
+
var TableRow = React22__namespace.forwardRef(
|
|
88
|
+
({ className, ...props }, ref) => /* @__PURE__ */ jsxRuntime.jsx(
|
|
89
|
+
"tr",
|
|
90
|
+
{
|
|
91
|
+
ref,
|
|
92
|
+
className: cn(
|
|
93
|
+
"border-b transition-colors hover:bg-muted/50 data-[state=selected]:bg-muted",
|
|
94
|
+
className
|
|
95
|
+
),
|
|
96
|
+
...props
|
|
97
|
+
}
|
|
98
|
+
)
|
|
99
|
+
);
|
|
100
|
+
TableRow.displayName = "TableRow";
|
|
101
|
+
var TableHead = React22__namespace.forwardRef(({ className, ...props }, ref) => /* @__PURE__ */ jsxRuntime.jsx(
|
|
102
|
+
"th",
|
|
103
|
+
{
|
|
104
|
+
ref,
|
|
105
|
+
className: cn(
|
|
106
|
+
"h-10 px-4 text-start align-middle font-medium text-muted-foreground [&:has([role=checkbox])]:pe-0 [&>[role=checkbox]]:translate-y-[2px]",
|
|
107
|
+
className
|
|
108
|
+
),
|
|
109
|
+
...props
|
|
110
|
+
}
|
|
111
|
+
));
|
|
112
|
+
TableHead.displayName = "TableHead";
|
|
113
|
+
var TableCell = React22__namespace.forwardRef(({ className, ...props }, ref) => /* @__PURE__ */ jsxRuntime.jsx(
|
|
114
|
+
"td",
|
|
115
|
+
{
|
|
116
|
+
ref,
|
|
117
|
+
className: cn(
|
|
118
|
+
"px-4 py-2.5 align-middle [&:has([role=checkbox])]:pe-0 [&>[role=checkbox]]:translate-y-[2px]",
|
|
119
|
+
className
|
|
120
|
+
),
|
|
121
|
+
...props
|
|
122
|
+
}
|
|
123
|
+
));
|
|
124
|
+
TableCell.displayName = "TableCell";
|
|
125
|
+
var TableCaption = React22__namespace.forwardRef(({ className, ...props }, ref) => /* @__PURE__ */ jsxRuntime.jsx("caption", { ref, className: cn("mt-4 text-sm text-muted-foreground", className), ...props }));
|
|
126
|
+
TableCaption.displayName = "TableCaption";
|
|
127
|
+
var buttonVariants = classVarianceAuthority.cva(
|
|
128
|
+
"inline-flex items-center justify-center gap-2 whitespace-nowrap rounded-lg text-sm font-medium transition-all duration-200 focus-visible:outline-none focus-visible:ring-2 focus-visible:ring-ring focus-visible:ring-offset-2 disabled:pointer-events-none disabled:opacity-50 cursor-pointer",
|
|
129
|
+
{
|
|
130
|
+
variants: {
|
|
131
|
+
variant: {
|
|
132
|
+
default: "bg-primary text-primary-foreground hover:bg-primary/90 shadow-sm",
|
|
133
|
+
brand: "bg-brand text-brand-foreground hover:bg-brand/90 shadow-sm shadow-brand/25",
|
|
134
|
+
outline: "border border-border bg-background hover:bg-accent hover:text-accent-foreground",
|
|
135
|
+
ghost: "hover:bg-accent hover:text-accent-foreground",
|
|
136
|
+
link: "text-brand underline-offset-4 hover:underline"
|
|
137
|
+
},
|
|
138
|
+
size: {
|
|
139
|
+
default: "h-10 px-4 py-2",
|
|
140
|
+
sm: "h-9 rounded-md px-3 text-xs",
|
|
141
|
+
lg: "h-12 rounded-xl px-8 text-base",
|
|
142
|
+
icon: "h-10 w-10"
|
|
143
|
+
}
|
|
144
|
+
},
|
|
145
|
+
defaultVariants: {
|
|
146
|
+
variant: "default",
|
|
147
|
+
size: "default"
|
|
148
|
+
}
|
|
149
|
+
}
|
|
150
|
+
);
|
|
151
|
+
var Button = React22.forwardRef(
|
|
152
|
+
({ className, variant, size, asChild = false, ...props }, ref) => {
|
|
153
|
+
const Comp = asChild ? reactSlot.Slot : "button";
|
|
154
|
+
return /* @__PURE__ */ jsxRuntime.jsx(
|
|
155
|
+
Comp,
|
|
156
|
+
{
|
|
157
|
+
className: cn(buttonVariants({ variant, size, className })),
|
|
158
|
+
ref,
|
|
159
|
+
...props
|
|
160
|
+
}
|
|
161
|
+
);
|
|
162
|
+
}
|
|
163
|
+
);
|
|
164
|
+
Button.displayName = "Button";
|
|
165
|
+
var Select = SelectPrimitive__namespace.Root;
|
|
166
|
+
var SelectGroup = SelectPrimitive__namespace.Group;
|
|
167
|
+
var SelectValue = SelectPrimitive__namespace.Value;
|
|
168
|
+
var SelectTrigger = React22__namespace.forwardRef(({ className, children, ...props }, ref) => /* @__PURE__ */ jsxRuntime.jsxs(
|
|
169
|
+
SelectPrimitive__namespace.Trigger,
|
|
170
|
+
{
|
|
171
|
+
ref,
|
|
172
|
+
className: cn(
|
|
173
|
+
"flex h-9 w-full items-center justify-between whitespace-nowrap rounded-md border border-input bg-transparent px-3 py-2 text-sm ring-offset-background placeholder:text-muted-foreground focus:outline-none focus:ring-1 focus:ring-ring disabled:cursor-not-allowed disabled:opacity-50 [&>span]:line-clamp-1",
|
|
174
|
+
className
|
|
175
|
+
),
|
|
176
|
+
...props,
|
|
177
|
+
children: [
|
|
178
|
+
children,
|
|
179
|
+
/* @__PURE__ */ jsxRuntime.jsx(SelectPrimitive__namespace.Icon, { asChild: true, children: /* @__PURE__ */ jsxRuntime.jsx(lucideReact.ChevronDown, { className: "h-4 w-4 opacity-50" }) })
|
|
180
|
+
]
|
|
181
|
+
}
|
|
182
|
+
));
|
|
183
|
+
SelectTrigger.displayName = SelectPrimitive__namespace.Trigger.displayName;
|
|
184
|
+
var SelectContent = React22__namespace.forwardRef(({ className, children, position = "popper", ...props }, ref) => /* @__PURE__ */ jsxRuntime.jsx(SelectPrimitive__namespace.Portal, { children: /* @__PURE__ */ jsxRuntime.jsx(
|
|
185
|
+
SelectPrimitive__namespace.Content,
|
|
186
|
+
{
|
|
187
|
+
ref,
|
|
188
|
+
className: cn(
|
|
189
|
+
"relative z-50 max-h-96 min-w-[8rem] overflow-hidden rounded-md border bg-popover text-popover-foreground shadow-md data-[state=open]:animate-in data-[state=closed]:animate-out data-[state=closed]:fade-out-0 data-[state=open]:fade-in-0 data-[state=closed]:zoom-out-95 data-[state=open]:zoom-in-95 data-[side=bottom]:slide-in-from-top-2 data-[side=left]:slide-in-from-right-2 data-[side=right]:slide-in-from-left-2 data-[side=top]:slide-in-from-bottom-2",
|
|
190
|
+
position === "popper" && "data-[side=bottom]:translate-y-1 data-[side=left]:-translate-x-1 data-[side=right]:translate-x-1 data-[side=top]:-translate-y-1",
|
|
191
|
+
className
|
|
192
|
+
),
|
|
193
|
+
position,
|
|
194
|
+
...props,
|
|
195
|
+
children: /* @__PURE__ */ jsxRuntime.jsx(
|
|
196
|
+
SelectPrimitive__namespace.Viewport,
|
|
197
|
+
{
|
|
198
|
+
className: cn(
|
|
199
|
+
"p-1",
|
|
200
|
+
position === "popper" && "h-[var(--radix-select-trigger-height)] w-full min-w-[var(--radix-select-trigger-width)]"
|
|
201
|
+
),
|
|
202
|
+
children
|
|
203
|
+
}
|
|
204
|
+
)
|
|
205
|
+
}
|
|
206
|
+
) }));
|
|
207
|
+
SelectContent.displayName = SelectPrimitive__namespace.Content.displayName;
|
|
208
|
+
var SelectItem = React22__namespace.forwardRef(({ className, children, ...props }, ref) => /* @__PURE__ */ jsxRuntime.jsxs(
|
|
209
|
+
SelectPrimitive__namespace.Item,
|
|
210
|
+
{
|
|
211
|
+
ref,
|
|
212
|
+
className: cn(
|
|
213
|
+
"relative flex w-full cursor-default select-none items-center rounded-sm py-1.5 pe-8 ps-2 text-sm outline-none focus:bg-accent focus:text-accent-foreground data-[disabled]:pointer-events-none data-[disabled]:opacity-50",
|
|
214
|
+
className
|
|
215
|
+
),
|
|
216
|
+
...props,
|
|
217
|
+
children: [
|
|
218
|
+
/* @__PURE__ */ jsxRuntime.jsx("span", { className: "absolute end-2 flex h-3.5 w-3.5 items-center justify-center", children: /* @__PURE__ */ jsxRuntime.jsx(SelectPrimitive__namespace.ItemIndicator, { children: /* @__PURE__ */ jsxRuntime.jsx(lucideReact.Check, { className: "h-4 w-4" }) }) }),
|
|
219
|
+
/* @__PURE__ */ jsxRuntime.jsx(SelectPrimitive__namespace.ItemText, { children })
|
|
220
|
+
]
|
|
221
|
+
}
|
|
222
|
+
));
|
|
223
|
+
SelectItem.displayName = SelectPrimitive__namespace.Item.displayName;
|
|
224
|
+
var SelectSeparator = React22__namespace.forwardRef(({ className, ...props }, ref) => /* @__PURE__ */ jsxRuntime.jsx(
|
|
225
|
+
SelectPrimitive__namespace.Separator,
|
|
226
|
+
{
|
|
227
|
+
ref,
|
|
228
|
+
className: cn("-mx-1 my-1 h-px bg-muted", className),
|
|
229
|
+
...props
|
|
230
|
+
}
|
|
231
|
+
));
|
|
232
|
+
SelectSeparator.displayName = SelectPrimitive__namespace.Separator.displayName;
|
|
233
|
+
|
|
234
|
+
// src/config/defaults.ts
|
|
235
|
+
var DEFAULT_TABLE_CONFIG = Object.freeze({
|
|
236
|
+
features: Object.freeze({
|
|
237
|
+
search: true,
|
|
238
|
+
filter: true,
|
|
239
|
+
pagination: true,
|
|
240
|
+
columnVisibility: true,
|
|
241
|
+
csvExport: true,
|
|
242
|
+
rowSelection: true,
|
|
243
|
+
viewToggle: true,
|
|
244
|
+
floatingBar: false,
|
|
245
|
+
advancedFilter: false,
|
|
246
|
+
sorting: true
|
|
247
|
+
}),
|
|
248
|
+
pagination: Object.freeze({
|
|
249
|
+
pageSizeOptions: Object.freeze([10, 20, 30, 40, 50]),
|
|
250
|
+
defaultPageSize: 10
|
|
251
|
+
}),
|
|
252
|
+
search: Object.freeze({
|
|
253
|
+
debounceMs: 500,
|
|
254
|
+
minSearchLength: 0
|
|
255
|
+
}),
|
|
256
|
+
i18n: Object.freeze({
|
|
257
|
+
locale: "en",
|
|
258
|
+
direction: "auto",
|
|
259
|
+
translationFn: void 0,
|
|
260
|
+
namespace: "table"
|
|
261
|
+
}),
|
|
262
|
+
performance: Object.freeze({
|
|
263
|
+
memoStrategy: "smart",
|
|
264
|
+
virtualizationOverscan: 5,
|
|
265
|
+
batchUpdates: true
|
|
266
|
+
}),
|
|
267
|
+
enterprise: Object.freeze({
|
|
268
|
+
strictAccessibility: false,
|
|
269
|
+
errorRecovery: false,
|
|
270
|
+
debugMode: false
|
|
271
|
+
}),
|
|
272
|
+
dev: Object.freeze({
|
|
273
|
+
warnings: true,
|
|
274
|
+
performanceHints: false,
|
|
275
|
+
renderCostThresholdMs: 16
|
|
276
|
+
}),
|
|
277
|
+
plugins: [],
|
|
278
|
+
router: void 0
|
|
279
|
+
});
|
|
280
|
+
|
|
281
|
+
// src/config/merge.ts
|
|
282
|
+
function deepMergeConfig(base, overrides) {
|
|
283
|
+
const result = { ...base };
|
|
284
|
+
for (const key of Object.keys(overrides)) {
|
|
285
|
+
const overrideValue = overrides[key];
|
|
286
|
+
if (overrideValue === void 0) continue;
|
|
287
|
+
if (Array.isArray(overrideValue)) {
|
|
288
|
+
result[key] = overrideValue;
|
|
289
|
+
} else if (overrideValue !== null && typeof overrideValue === "object" && !Array.isArray(base[key]) && typeof base[key] === "object" && base[key] !== null) {
|
|
290
|
+
const baseObj = base[key];
|
|
291
|
+
const overrideObj = overrideValue;
|
|
292
|
+
const merged = { ...baseObj };
|
|
293
|
+
for (const subKey of Object.keys(overrideObj)) {
|
|
294
|
+
if (overrideObj[subKey] !== void 0) {
|
|
295
|
+
merged[subKey] = overrideObj[subKey];
|
|
296
|
+
}
|
|
297
|
+
}
|
|
298
|
+
result[key] = merged;
|
|
299
|
+
} else {
|
|
300
|
+
result[key] = overrideValue;
|
|
301
|
+
}
|
|
302
|
+
}
|
|
303
|
+
return result;
|
|
304
|
+
}
|
|
305
|
+
|
|
306
|
+
// src/config/context.ts
|
|
307
|
+
var TableConfigContext = React22.createContext(null);
|
|
308
|
+
function TableProvider({ config, children }) {
|
|
309
|
+
const resolvedConfig = React22.useMemo(
|
|
310
|
+
() => deepMergeConfig(DEFAULT_TABLE_CONFIG, config),
|
|
311
|
+
[config]
|
|
312
|
+
);
|
|
313
|
+
return React22__namespace.default.createElement(
|
|
314
|
+
TableConfigContext.Provider,
|
|
315
|
+
{ value: resolvedConfig },
|
|
316
|
+
children
|
|
317
|
+
);
|
|
318
|
+
}
|
|
319
|
+
function useGlobalTableConfig() {
|
|
320
|
+
const context = React22.useContext(TableConfigContext);
|
|
321
|
+
return context != null ? context : DEFAULT_TABLE_CONFIG;
|
|
322
|
+
}
|
|
323
|
+
|
|
324
|
+
// src/hooks/use-table-translations.ts
|
|
325
|
+
var DEFAULT_TRANSLATIONS = {
|
|
326
|
+
// Toolbar
|
|
327
|
+
"Filter": "Filter",
|
|
328
|
+
"filter-by": "Filter by",
|
|
329
|
+
"Reset": "Reset",
|
|
330
|
+
"add": "Add",
|
|
331
|
+
"add-filter": "Add filter",
|
|
332
|
+
"new": "New",
|
|
333
|
+
"columns": "Columns",
|
|
334
|
+
"Toggle-Visibility": "Toggle Visibility",
|
|
335
|
+
"export-csv": "Export CSV",
|
|
336
|
+
"tableView": "Table",
|
|
337
|
+
"cardView": "Cards",
|
|
338
|
+
"Apply": "Apply",
|
|
339
|
+
"data-table-filter": "Use filters to narrow down results.",
|
|
340
|
+
// Search
|
|
341
|
+
"search": "Search",
|
|
342
|
+
// Sorting
|
|
343
|
+
"asc": "Asc",
|
|
344
|
+
"desc": "Desc",
|
|
345
|
+
"Hide": "Hide",
|
|
346
|
+
"sorted-desc": "Sorted descending",
|
|
347
|
+
"sorted-asc": "Sorted ascending",
|
|
348
|
+
"not-sorted": "Not sorted",
|
|
349
|
+
"sort-ascending": "Sort ascending",
|
|
350
|
+
"sort-descending": "Sort descending",
|
|
351
|
+
"hide-column": "Hide column",
|
|
352
|
+
// Pagination
|
|
353
|
+
"pagination": "Pagination",
|
|
354
|
+
"showing": "Showing",
|
|
355
|
+
"of": "of",
|
|
356
|
+
"records": "records",
|
|
357
|
+
"Rows Per Page": "Rows per page",
|
|
358
|
+
"previous": "Previous",
|
|
359
|
+
"next": "Next",
|
|
360
|
+
// Selection
|
|
361
|
+
"select": "Select",
|
|
362
|
+
"clear-selection": "Clear selection",
|
|
363
|
+
"row(s) selected": "row(s) selected",
|
|
364
|
+
"delete-selected": "Delete selected",
|
|
365
|
+
// Empty state
|
|
366
|
+
"no-records-found": "No records found",
|
|
367
|
+
"no-records-hint": "Try adjusting your search or filter criteria.",
|
|
368
|
+
"reset-filters": "Reset filters",
|
|
369
|
+
// Filters
|
|
370
|
+
"no-items-found": "No items found.",
|
|
371
|
+
"clear-filters": "Clear filters",
|
|
372
|
+
"all": "All",
|
|
373
|
+
"advanced-filter": "Advanced filter",
|
|
374
|
+
// Actions
|
|
375
|
+
"actions": "Actions",
|
|
376
|
+
"edit": "Edit",
|
|
377
|
+
"show": "Show",
|
|
378
|
+
"delete": "Delete",
|
|
379
|
+
"download": "Download",
|
|
380
|
+
"cancel": "Cancel",
|
|
381
|
+
// Date
|
|
382
|
+
"datePlaceholder": "Pick a date",
|
|
383
|
+
// Client-side table
|
|
384
|
+
"row-number": "#"
|
|
385
|
+
};
|
|
386
|
+
function useTableTranslations() {
|
|
387
|
+
const config = useGlobalTableConfig();
|
|
388
|
+
if (config.i18n.translationFn) {
|
|
389
|
+
return config.i18n.translationFn;
|
|
390
|
+
}
|
|
391
|
+
return (key) => {
|
|
392
|
+
var _a;
|
|
393
|
+
return (_a = DEFAULT_TRANSLATIONS[key]) != null ? _a : key;
|
|
394
|
+
};
|
|
395
|
+
}
|
|
396
|
+
|
|
397
|
+
// src/config/create-config.ts
|
|
398
|
+
function createTableConfig(input) {
|
|
399
|
+
if (!input) return DEFAULT_TABLE_CONFIG;
|
|
400
|
+
const merged = deepMergeConfig(DEFAULT_TABLE_CONFIG, input);
|
|
401
|
+
return Object.freeze(merged);
|
|
402
|
+
}
|
|
403
|
+
|
|
404
|
+
// src/config/dev-warnings.ts
|
|
405
|
+
function runDevValidation(config) {
|
|
406
|
+
if (process.env.NODE_ENV !== "development") return;
|
|
407
|
+
if (!config.dev.warnings) return;
|
|
408
|
+
if (!config.pagination.pageSizeOptions.includes(config.pagination.defaultPageSize)) {
|
|
409
|
+
console.warn(
|
|
410
|
+
`[TableCraft] defaultPageSize (${config.pagination.defaultPageSize}) is not in pageSizeOptions [${config.pagination.pageSizeOptions.join(", ")}]. The page size dropdown may not show the default selection.`
|
|
411
|
+
);
|
|
412
|
+
}
|
|
413
|
+
if (config.search.debounceMs < 0) {
|
|
414
|
+
console.warn(
|
|
415
|
+
`[TableCraft] search.debounceMs is negative (${config.search.debounceMs}). This will be treated as 0.`
|
|
416
|
+
);
|
|
417
|
+
}
|
|
418
|
+
if (config.features.advancedFilter && !config.features.filter) {
|
|
419
|
+
console.warn(
|
|
420
|
+
`[TableCraft] features.advancedFilter is enabled but features.filter is disabled. Advanced filter will have no effect.`
|
|
421
|
+
);
|
|
422
|
+
}
|
|
423
|
+
if (config.i18n.direction === "auto" && !config.i18n.locale) {
|
|
424
|
+
console.warn(
|
|
425
|
+
`[TableCraft] i18n.direction is 'auto' but i18n.locale is empty. Direction detection may not work correctly. Set an explicit direction or locale.`
|
|
426
|
+
);
|
|
427
|
+
}
|
|
428
|
+
}
|
|
429
|
+
|
|
430
|
+
// src/config/use-resolved-config.ts
|
|
431
|
+
function useResolvedTableConfig(instanceConfig) {
|
|
432
|
+
const globalConfig = useGlobalTableConfig();
|
|
433
|
+
const resolved = React22.useMemo(() => {
|
|
434
|
+
var _a;
|
|
435
|
+
let config = instanceConfig ? deepMergeConfig(globalConfig, instanceConfig) : globalConfig;
|
|
436
|
+
if (config.plugins.length > 0) {
|
|
437
|
+
const sortedPlugins = [...config.plugins].sort((a, b) => a.priority - b.priority);
|
|
438
|
+
for (const plugin of sortedPlugins) {
|
|
439
|
+
config = deepMergeConfig(config, plugin.config);
|
|
440
|
+
}
|
|
441
|
+
for (const plugin of sortedPlugins) {
|
|
442
|
+
(_a = plugin.onResolve) == null ? void 0 : _a.call(plugin, config);
|
|
443
|
+
}
|
|
444
|
+
}
|
|
445
|
+
return config;
|
|
446
|
+
}, [globalConfig, instanceConfig]);
|
|
447
|
+
if (process.env.NODE_ENV === "development") {
|
|
448
|
+
runDevValidation(resolved);
|
|
449
|
+
}
|
|
450
|
+
return resolved;
|
|
451
|
+
}
|
|
452
|
+
function useTableConfig(selector) {
|
|
453
|
+
const config = useGlobalTableConfig();
|
|
454
|
+
return React22.useMemo(() => {
|
|
455
|
+
if (selector) return selector(config);
|
|
456
|
+
return config;
|
|
457
|
+
}, [config, selector]);
|
|
458
|
+
}
|
|
459
|
+
function getVisiblePages(currentPage, totalPages) {
|
|
460
|
+
if (totalPages <= 5) {
|
|
461
|
+
return Array.from({ length: totalPages }, (_, i) => i + 1);
|
|
462
|
+
}
|
|
463
|
+
const pages = [];
|
|
464
|
+
if (currentPage <= 3) {
|
|
465
|
+
pages.push(1, 2, 3, 4, "ellipsis", totalPages);
|
|
466
|
+
} else if (currentPage >= totalPages - 2) {
|
|
467
|
+
pages.push(1, "ellipsis", totalPages - 3, totalPages - 2, totalPages - 1, totalPages);
|
|
468
|
+
} else {
|
|
469
|
+
pages.push(1, "ellipsis", currentPage - 1, currentPage, currentPage + 1, "ellipsis", totalPages);
|
|
470
|
+
}
|
|
471
|
+
return pages;
|
|
472
|
+
}
|
|
473
|
+
function DataTablePagination({
|
|
474
|
+
table,
|
|
475
|
+
pageSizeOptions,
|
|
476
|
+
isQueryPagination = false,
|
|
477
|
+
paginationData
|
|
478
|
+
}) {
|
|
479
|
+
var _a, _b, _c, _d, _e, _f, _g, _h, _i, _j, _k, _l;
|
|
480
|
+
const t = useTableTranslations();
|
|
481
|
+
const config = useTableConfig();
|
|
482
|
+
const isArabic = config.i18n.direction === "rtl" || config.i18n.direction === "auto" && config.i18n.locale === "ar";
|
|
483
|
+
const resolvedPageSizeOptions = pageSizeOptions != null ? pageSizeOptions : config.pagination.pageSizeOptions;
|
|
484
|
+
const currentPage = isQueryPagination ? (_c = (_b = (_a = paginationData == null ? void 0 : paginationData.paginationResponse) == null ? void 0 : _a.meta) == null ? void 0 : _b.current_page) != null ? _c : 1 : table.getState().pagination.pageIndex + 1;
|
|
485
|
+
const totalPages = isQueryPagination ? (_f = (_e = (_d = paginationData == null ? void 0 : paginationData.paginationResponse) == null ? void 0 : _d.meta) == null ? void 0 : _e.last_page) != null ? _f : 1 : table.getPageCount();
|
|
486
|
+
const pageSize = isQueryPagination ? (_i = (_h = (_g = paginationData == null ? void 0 : paginationData.paginationResponse) == null ? void 0 : _g.meta) == null ? void 0 : _h.per_page) != null ? _i : 10 : table.getState().pagination.pageSize;
|
|
487
|
+
const totalItems = isQueryPagination ? (_l = (_k = (_j = paginationData == null ? void 0 : paginationData.paginationResponse) == null ? void 0 : _j.meta) == null ? void 0 : _k.total) != null ? _l : 0 : table.getFilteredRowModel().rows.length;
|
|
488
|
+
const from = totalItems === 0 ? 0 : (currentPage - 1) * pageSize + 1;
|
|
489
|
+
const to = Math.min(currentPage * pageSize, totalItems);
|
|
490
|
+
const goToPage = (page) => {
|
|
491
|
+
if (isQueryPagination && paginationData) {
|
|
492
|
+
paginationData.onPageChange(page);
|
|
493
|
+
} else {
|
|
494
|
+
table.setPageIndex(page - 1);
|
|
495
|
+
}
|
|
496
|
+
};
|
|
497
|
+
const visiblePages = getVisiblePages(currentPage, totalPages);
|
|
498
|
+
return /* @__PURE__ */ jsxRuntime.jsxs("nav", { role: "navigation", "aria-label": t("pagination"), className: "flex w-full flex-col gap-4 border-t px-4 py-4 sm:flex-row sm:items-center sm:justify-between", children: [
|
|
499
|
+
/* @__PURE__ */ jsxRuntime.jsxs("div", { className: "flex flex-wrap items-center gap-4", children: [
|
|
500
|
+
/* @__PURE__ */ jsxRuntime.jsxs("p", { className: "text-sm text-muted-foreground", children: [
|
|
501
|
+
t("showing"),
|
|
502
|
+
" ",
|
|
503
|
+
/* @__PURE__ */ jsxRuntime.jsxs("span", { className: "font-semibold text-foreground", children: [
|
|
504
|
+
from,
|
|
505
|
+
"-",
|
|
506
|
+
to
|
|
507
|
+
] }),
|
|
508
|
+
" ",
|
|
509
|
+
t("of"),
|
|
510
|
+
" ",
|
|
511
|
+
/* @__PURE__ */ jsxRuntime.jsx("span", { className: "font-semibold text-foreground", children: totalItems }),
|
|
512
|
+
" ",
|
|
513
|
+
t("records")
|
|
514
|
+
] }),
|
|
515
|
+
/* @__PURE__ */ jsxRuntime.jsxs("div", { className: "flex items-center gap-2", children: [
|
|
516
|
+
/* @__PURE__ */ jsxRuntime.jsx("p", { className: "text-sm text-muted-foreground", children: t("Rows Per Page") }),
|
|
517
|
+
/* @__PURE__ */ jsxRuntime.jsxs(
|
|
518
|
+
Select,
|
|
519
|
+
{
|
|
520
|
+
value: `${pageSize}`,
|
|
521
|
+
onValueChange: (value) => {
|
|
522
|
+
const newSize = Number(value);
|
|
523
|
+
if (isQueryPagination && paginationData) {
|
|
524
|
+
paginationData.onPageSizeChange(newSize);
|
|
525
|
+
} else {
|
|
526
|
+
table.setPageSize(newSize);
|
|
527
|
+
}
|
|
528
|
+
},
|
|
529
|
+
children: [
|
|
530
|
+
/* @__PURE__ */ jsxRuntime.jsx(SelectTrigger, { className: "h-8 w-[70px]", children: /* @__PURE__ */ jsxRuntime.jsx(SelectValue, { placeholder: pageSize }) }),
|
|
531
|
+
/* @__PURE__ */ jsxRuntime.jsx(SelectContent, { side: "top", children: resolvedPageSizeOptions.map((size) => /* @__PURE__ */ jsxRuntime.jsx(SelectItem, { value: `${size}`, children: size }, size)) })
|
|
532
|
+
]
|
|
533
|
+
}
|
|
534
|
+
)
|
|
535
|
+
] })
|
|
536
|
+
] }),
|
|
537
|
+
totalPages > 0 && /* @__PURE__ */ jsxRuntime.jsxs("div", { className: "flex items-center gap-1", children: [
|
|
538
|
+
/* @__PURE__ */ jsxRuntime.jsxs(
|
|
539
|
+
Button,
|
|
540
|
+
{
|
|
541
|
+
variant: "outline",
|
|
542
|
+
size: "sm",
|
|
543
|
+
className: "h-8 gap-1 px-3 text-sm",
|
|
544
|
+
onClick: (e) => {
|
|
545
|
+
e.preventDefault();
|
|
546
|
+
goToPage(currentPage - 1);
|
|
547
|
+
},
|
|
548
|
+
disabled: currentPage === 1,
|
|
549
|
+
children: [
|
|
550
|
+
/* @__PURE__ */ jsxRuntime.jsx(lucideReact.ChevronLeft, { className: cn("size-4", isArabic && "rotate-180") }),
|
|
551
|
+
t("previous")
|
|
552
|
+
]
|
|
553
|
+
}
|
|
554
|
+
),
|
|
555
|
+
/* @__PURE__ */ jsxRuntime.jsx("div", { className: "hidden items-center gap-1 sm:flex", children: visiblePages.map(
|
|
556
|
+
(page, idx) => page === "ellipsis" ? /* @__PURE__ */ jsxRuntime.jsx("span", { className: "px-1 text-sm text-muted-foreground", children: "..." }, `ellipsis-${idx}`) : /* @__PURE__ */ jsxRuntime.jsx(
|
|
557
|
+
Button,
|
|
558
|
+
{
|
|
559
|
+
variant: page === currentPage ? "default" : "ghost",
|
|
560
|
+
size: "sm",
|
|
561
|
+
className: cn(
|
|
562
|
+
"size-8 p-0 text-sm",
|
|
563
|
+
page === currentPage && "bg-brand text-brand-foreground hover:bg-brand/90"
|
|
564
|
+
),
|
|
565
|
+
onClick: (e) => {
|
|
566
|
+
e.preventDefault();
|
|
567
|
+
goToPage(page);
|
|
568
|
+
},
|
|
569
|
+
...page === currentPage ? { "aria-current": "page" } : {},
|
|
570
|
+
children: page
|
|
571
|
+
},
|
|
572
|
+
page
|
|
573
|
+
)
|
|
574
|
+
) }),
|
|
575
|
+
/* @__PURE__ */ jsxRuntime.jsxs("span", { className: "text-sm text-muted-foreground sm:hidden", children: [
|
|
576
|
+
currentPage,
|
|
577
|
+
" / ",
|
|
578
|
+
totalPages
|
|
579
|
+
] }),
|
|
580
|
+
/* @__PURE__ */ jsxRuntime.jsxs(
|
|
581
|
+
Button,
|
|
582
|
+
{
|
|
583
|
+
variant: "outline",
|
|
584
|
+
size: "sm",
|
|
585
|
+
className: "h-8 gap-1 px-3 text-sm",
|
|
586
|
+
onClick: (e) => {
|
|
587
|
+
e.preventDefault();
|
|
588
|
+
goToPage(currentPage + 1);
|
|
589
|
+
},
|
|
590
|
+
disabled: currentPage === totalPages,
|
|
591
|
+
children: [
|
|
592
|
+
t("next"),
|
|
593
|
+
/* @__PURE__ */ jsxRuntime.jsx(lucideReact.ChevronRight, { className: cn("size-4", isArabic && "rotate-180") })
|
|
594
|
+
]
|
|
595
|
+
}
|
|
596
|
+
)
|
|
597
|
+
] })
|
|
598
|
+
] });
|
|
599
|
+
}
|
|
600
|
+
var DEFAULT_IGNORED_COLUMNS = ["actions", "select"];
|
|
601
|
+
function createCsvConfig(options = {}) {
|
|
602
|
+
return exportToCsv.mkConfig({
|
|
603
|
+
fieldSeparator: ",",
|
|
604
|
+
decimalSeparator: ".",
|
|
605
|
+
useKeysAsHeaders: true,
|
|
606
|
+
filename: options.fileName || "table-export"
|
|
607
|
+
});
|
|
608
|
+
}
|
|
609
|
+
function exportSelectedRowsCsv(table, options = {}) {
|
|
610
|
+
const selectedRows = table.getSelectedRowModel().rows;
|
|
611
|
+
if (selectedRows.length === 0) {
|
|
612
|
+
return;
|
|
613
|
+
}
|
|
614
|
+
const ignoredColumns = [
|
|
615
|
+
...DEFAULT_IGNORED_COLUMNS,
|
|
616
|
+
...options.ignoredCols || []
|
|
617
|
+
];
|
|
618
|
+
const csvConfig = createCsvConfig(options);
|
|
619
|
+
try {
|
|
620
|
+
const tableData = selectedRows.map((row) => {
|
|
621
|
+
return row._getAllVisibleCells().reduce(
|
|
622
|
+
(acc, cell) => {
|
|
623
|
+
if (!ignoredColumns.includes(cell.column.id)) {
|
|
624
|
+
const rawValue = cell.getValue();
|
|
625
|
+
const original = cell.row.original;
|
|
626
|
+
const value = rawValue != null ? rawValue : original[cell.column.id];
|
|
627
|
+
if (value !== void 0 && value !== null && value !== "") {
|
|
628
|
+
const headerKey = typeof cell.column.columnDef.header === "string" ? cell.column.columnDef.header : cell.column.id;
|
|
629
|
+
acc[headerKey] = String(value);
|
|
630
|
+
}
|
|
631
|
+
}
|
|
632
|
+
return acc;
|
|
633
|
+
},
|
|
634
|
+
{}
|
|
635
|
+
);
|
|
636
|
+
});
|
|
637
|
+
if (tableData.length === 0) {
|
|
638
|
+
return;
|
|
639
|
+
}
|
|
640
|
+
const csv = exportToCsv.generateCsv(csvConfig)(tableData);
|
|
641
|
+
exportToCsv.download(csvConfig)(csv);
|
|
642
|
+
} catch (error) {
|
|
643
|
+
console.error("CSV export failed:", error);
|
|
644
|
+
}
|
|
645
|
+
}
|
|
646
|
+
var Input = React22__namespace.forwardRef(
|
|
647
|
+
({ className, type, ...props }, ref) => {
|
|
648
|
+
return /* @__PURE__ */ jsxRuntime.jsx(
|
|
649
|
+
"input",
|
|
650
|
+
{
|
|
651
|
+
type,
|
|
652
|
+
className: cn(
|
|
653
|
+
"flex h-9 w-full rounded-md border border-input bg-transparent px-3 py-1 text-sm transition-colors file:border-0 file:bg-transparent file:text-sm file:font-medium placeholder:text-muted-foreground focus-visible:outline-none focus-visible:ring-1 focus-visible:ring-ring disabled:cursor-not-allowed disabled:opacity-50",
|
|
654
|
+
className
|
|
655
|
+
),
|
|
656
|
+
ref,
|
|
657
|
+
...props
|
|
658
|
+
}
|
|
659
|
+
);
|
|
660
|
+
}
|
|
661
|
+
);
|
|
662
|
+
Input.displayName = "Input";
|
|
663
|
+
function Calendar({ className, mode = "single", selected, onSelect }) {
|
|
664
|
+
const [currentMonth, setCurrentMonth] = React22__namespace.useState(() => selected || /* @__PURE__ */ new Date());
|
|
665
|
+
const year = currentMonth.getFullYear();
|
|
666
|
+
const month = currentMonth.getMonth();
|
|
667
|
+
const firstDay = new Date(year, month, 1);
|
|
668
|
+
const lastDay = new Date(year, month + 1, 0);
|
|
669
|
+
const startDayOfWeek = firstDay.getDay();
|
|
670
|
+
const daysInMonth = lastDay.getDate();
|
|
671
|
+
const prevMonth = () => setCurrentMonth(new Date(year, month - 1, 1));
|
|
672
|
+
const nextMonth = () => setCurrentMonth(new Date(year, month + 1, 1));
|
|
673
|
+
const monthName = currentMonth.toLocaleString("default", { month: "long", year: "numeric" });
|
|
674
|
+
const dayNames = ["Su", "Mo", "Tu", "We", "Th", "Fr", "Sa"];
|
|
675
|
+
const isSelected = (day) => {
|
|
676
|
+
if (!selected) return false;
|
|
677
|
+
return selected.getFullYear() === year && selected.getMonth() === month && selected.getDate() === day;
|
|
678
|
+
};
|
|
679
|
+
const isToday = (day) => {
|
|
680
|
+
const today = /* @__PURE__ */ new Date();
|
|
681
|
+
return today.getFullYear() === year && today.getMonth() === month && today.getDate() === day;
|
|
682
|
+
};
|
|
683
|
+
const handleSelect = (day) => {
|
|
684
|
+
const date = new Date(year, month, day);
|
|
685
|
+
onSelect == null ? void 0 : onSelect(date);
|
|
686
|
+
};
|
|
687
|
+
const cells = [];
|
|
688
|
+
for (let i = 0; i < startDayOfWeek; i++) cells.push(null);
|
|
689
|
+
for (let d = 1; d <= daysInMonth; d++) cells.push(d);
|
|
690
|
+
return /* @__PURE__ */ jsxRuntime.jsxs("div", { className: cn("p-3", className), children: [
|
|
691
|
+
/* @__PURE__ */ jsxRuntime.jsxs("div", { className: "flex items-center justify-between mb-2", children: [
|
|
692
|
+
/* @__PURE__ */ jsxRuntime.jsx(Button, { variant: "outline", size: "icon", className: "h-7 w-7", onClick: prevMonth, children: /* @__PURE__ */ jsxRuntime.jsx(lucideReact.ChevronLeft, { className: "h-4 w-4" }) }),
|
|
693
|
+
/* @__PURE__ */ jsxRuntime.jsx("span", { className: "text-sm font-medium", children: monthName }),
|
|
694
|
+
/* @__PURE__ */ jsxRuntime.jsx(Button, { variant: "outline", size: "icon", className: "h-7 w-7", onClick: nextMonth, children: /* @__PURE__ */ jsxRuntime.jsx(lucideReact.ChevronRight, { className: "h-4 w-4" }) })
|
|
695
|
+
] }),
|
|
696
|
+
/* @__PURE__ */ jsxRuntime.jsx("div", { className: "grid grid-cols-7 gap-1 text-center text-xs text-muted-foreground mb-1", children: dayNames.map((d) => /* @__PURE__ */ jsxRuntime.jsx("div", { className: "py-1", children: d }, d)) }),
|
|
697
|
+
/* @__PURE__ */ jsxRuntime.jsx("div", { className: "grid grid-cols-7 gap-1", children: cells.map(
|
|
698
|
+
(day, i) => day === null ? /* @__PURE__ */ jsxRuntime.jsx("div", {}, `empty-${i}`) : /* @__PURE__ */ jsxRuntime.jsx(
|
|
699
|
+
"button",
|
|
700
|
+
{
|
|
701
|
+
type: "button",
|
|
702
|
+
onClick: () => handleSelect(day),
|
|
703
|
+
className: cn(
|
|
704
|
+
"h-8 w-8 rounded-md text-sm transition-colors hover:bg-accent mx-auto flex items-center justify-center",
|
|
705
|
+
isSelected(day) && "bg-primary text-primary-foreground hover:bg-primary/90",
|
|
706
|
+
isToday(day) && !isSelected(day) && "bg-accent text-accent-foreground"
|
|
707
|
+
),
|
|
708
|
+
children: day
|
|
709
|
+
},
|
|
710
|
+
day
|
|
711
|
+
)
|
|
712
|
+
) })
|
|
713
|
+
] });
|
|
714
|
+
}
|
|
715
|
+
var Checkbox = React22__namespace.forwardRef(({ className, ...props }, ref) => /* @__PURE__ */ jsxRuntime.jsx(
|
|
716
|
+
CheckboxPrimitive__namespace.Root,
|
|
717
|
+
{
|
|
718
|
+
ref,
|
|
719
|
+
className: cn(
|
|
720
|
+
"peer h-4 w-4 shrink-0 rounded-sm border border-primary shadow focus-visible:outline-none focus-visible:ring-1 focus-visible:ring-ring disabled:cursor-not-allowed disabled:opacity-50 data-[state=checked]:bg-primary data-[state=checked]:text-primary-foreground",
|
|
721
|
+
className
|
|
722
|
+
),
|
|
723
|
+
...props,
|
|
724
|
+
children: /* @__PURE__ */ jsxRuntime.jsx(CheckboxPrimitive__namespace.Indicator, { className: cn("flex items-center justify-center text-current"), children: /* @__PURE__ */ jsxRuntime.jsx(lucideReact.Check, { className: "h-4 w-4" }) })
|
|
725
|
+
}
|
|
726
|
+
));
|
|
727
|
+
Checkbox.displayName = CheckboxPrimitive__namespace.Root.displayName;
|
|
728
|
+
var Label = React22__namespace.forwardRef(
|
|
729
|
+
({ className, ...props }, ref) => /* @__PURE__ */ jsxRuntime.jsx(
|
|
730
|
+
"label",
|
|
731
|
+
{
|
|
732
|
+
ref,
|
|
733
|
+
className: cn(
|
|
734
|
+
"text-sm font-medium leading-none peer-disabled:cursor-not-allowed peer-disabled:opacity-70",
|
|
735
|
+
className
|
|
736
|
+
),
|
|
737
|
+
...props
|
|
738
|
+
}
|
|
739
|
+
)
|
|
740
|
+
);
|
|
741
|
+
Label.displayName = "Label";
|
|
742
|
+
var Popover = PopoverPrimitive__namespace.Root;
|
|
743
|
+
var PopoverTrigger = PopoverPrimitive__namespace.Trigger;
|
|
744
|
+
var PopoverContent = React22__namespace.forwardRef(({ className, align = "center", sideOffset = 4, ...props }, ref) => /* @__PURE__ */ jsxRuntime.jsx(PopoverPrimitive__namespace.Portal, { children: /* @__PURE__ */ jsxRuntime.jsx(
|
|
745
|
+
PopoverPrimitive__namespace.Content,
|
|
746
|
+
{
|
|
747
|
+
ref,
|
|
748
|
+
align,
|
|
749
|
+
sideOffset,
|
|
750
|
+
className: cn(
|
|
751
|
+
"z-50 w-72 rounded-md border bg-popover p-4 text-popover-foreground shadow-md outline-none data-[state=open]:animate-in data-[state=closed]:animate-out data-[state=closed]:fade-out-0 data-[state=open]:fade-in-0 data-[state=closed]:zoom-out-95 data-[state=open]:zoom-in-95 data-[side=bottom]:slide-in-from-top-2 data-[side=left]:slide-in-from-right-2 data-[side=right]:slide-in-from-left-2 data-[side=top]:slide-in-from-bottom-2",
|
|
752
|
+
className
|
|
753
|
+
),
|
|
754
|
+
...props
|
|
755
|
+
}
|
|
756
|
+
) }));
|
|
757
|
+
PopoverContent.displayName = PopoverPrimitive__namespace.Content.displayName;
|
|
758
|
+
var badgeVariants = classVarianceAuthority.cva(
|
|
759
|
+
"inline-flex items-center rounded-full border px-2.5 py-0.5 text-xs font-semibold transition-colors",
|
|
760
|
+
{
|
|
761
|
+
variants: {
|
|
762
|
+
variant: {
|
|
763
|
+
default: "border-transparent bg-primary text-primary-foreground",
|
|
764
|
+
secondary: "border-transparent bg-secondary text-secondary-foreground",
|
|
765
|
+
brand: "border-transparent bg-brand-muted text-brand",
|
|
766
|
+
outline: "text-foreground"
|
|
767
|
+
}
|
|
768
|
+
},
|
|
769
|
+
defaultVariants: {
|
|
770
|
+
variant: "default"
|
|
771
|
+
}
|
|
772
|
+
}
|
|
773
|
+
);
|
|
774
|
+
function Badge({ className, variant, ...props }) {
|
|
775
|
+
return /* @__PURE__ */ jsxRuntime.jsx("div", { className: cn(badgeVariants({ variant }), className), ...props });
|
|
776
|
+
}
|
|
777
|
+
var Command = React22__namespace.forwardRef(({ className, ...props }, ref) => /* @__PURE__ */ jsxRuntime.jsx(
|
|
778
|
+
cmdk.Command,
|
|
779
|
+
{
|
|
780
|
+
ref,
|
|
781
|
+
className: cn(
|
|
782
|
+
"flex h-full w-full flex-col overflow-hidden rounded-md bg-popover text-popover-foreground",
|
|
783
|
+
className
|
|
784
|
+
),
|
|
785
|
+
...props
|
|
786
|
+
}
|
|
787
|
+
));
|
|
788
|
+
Command.displayName = cmdk.Command.displayName;
|
|
789
|
+
var CommandInput = React22__namespace.forwardRef(({ className, ...props }, ref) => /* @__PURE__ */ jsxRuntime.jsxs("div", { className: "flex items-center border-b px-3", "cmdk-input-wrapper": "", children: [
|
|
790
|
+
/* @__PURE__ */ jsxRuntime.jsx(lucideReact.Search, { className: "me-2 h-4 w-4 shrink-0 opacity-50" }),
|
|
791
|
+
/* @__PURE__ */ jsxRuntime.jsx(
|
|
792
|
+
cmdk.Command.Input,
|
|
793
|
+
{
|
|
794
|
+
ref,
|
|
795
|
+
className: cn(
|
|
796
|
+
"flex h-10 w-full rounded-md bg-transparent py-3 text-sm outline-none placeholder:text-muted-foreground disabled:cursor-not-allowed disabled:opacity-50",
|
|
797
|
+
className
|
|
798
|
+
),
|
|
799
|
+
...props
|
|
800
|
+
}
|
|
801
|
+
)
|
|
802
|
+
] }));
|
|
803
|
+
CommandInput.displayName = cmdk.Command.Input.displayName;
|
|
804
|
+
var CommandList = React22__namespace.forwardRef(({ className, ...props }, ref) => /* @__PURE__ */ jsxRuntime.jsx(
|
|
805
|
+
cmdk.Command.List,
|
|
806
|
+
{
|
|
807
|
+
ref,
|
|
808
|
+
className: cn("max-h-[300px] overflow-y-auto overflow-x-hidden", className),
|
|
809
|
+
...props
|
|
810
|
+
}
|
|
811
|
+
));
|
|
812
|
+
CommandList.displayName = cmdk.Command.List.displayName;
|
|
813
|
+
var CommandEmpty = React22__namespace.forwardRef((props, ref) => /* @__PURE__ */ jsxRuntime.jsx(cmdk.Command.Empty, { ref, className: "py-6 text-center text-sm", ...props }));
|
|
814
|
+
CommandEmpty.displayName = cmdk.Command.Empty.displayName;
|
|
815
|
+
var CommandGroup = React22__namespace.forwardRef(({ className, ...props }, ref) => /* @__PURE__ */ jsxRuntime.jsx(
|
|
816
|
+
cmdk.Command.Group,
|
|
817
|
+
{
|
|
818
|
+
ref,
|
|
819
|
+
className: cn(
|
|
820
|
+
"overflow-hidden p-1 text-foreground [&_[cmdk-group-heading]]:px-2 [&_[cmdk-group-heading]]:py-1.5 [&_[cmdk-group-heading]]:text-xs [&_[cmdk-group-heading]]:font-medium [&_[cmdk-group-heading]]:text-muted-foreground",
|
|
821
|
+
className
|
|
822
|
+
),
|
|
823
|
+
...props
|
|
824
|
+
}
|
|
825
|
+
));
|
|
826
|
+
CommandGroup.displayName = cmdk.Command.Group.displayName;
|
|
827
|
+
var CommandSeparator = React22__namespace.forwardRef(({ className, ...props }, ref) => /* @__PURE__ */ jsxRuntime.jsx(
|
|
828
|
+
cmdk.Command.Separator,
|
|
829
|
+
{
|
|
830
|
+
ref,
|
|
831
|
+
className: cn("-mx-1 h-px bg-border", className),
|
|
832
|
+
...props
|
|
833
|
+
}
|
|
834
|
+
));
|
|
835
|
+
CommandSeparator.displayName = cmdk.Command.Separator.displayName;
|
|
836
|
+
var CommandItem = React22__namespace.forwardRef(({ className, ...props }, ref) => /* @__PURE__ */ jsxRuntime.jsx(
|
|
837
|
+
cmdk.Command.Item,
|
|
838
|
+
{
|
|
839
|
+
ref,
|
|
840
|
+
className: cn(
|
|
841
|
+
"relative flex cursor-default select-none items-center rounded-sm px-2 py-1.5 text-sm outline-none data-[selected=true]:bg-accent data-[selected=true]:text-accent-foreground data-[disabled=true]:pointer-events-none data-[disabled=true]:opacity-50",
|
|
842
|
+
className
|
|
843
|
+
),
|
|
844
|
+
...props
|
|
845
|
+
}
|
|
846
|
+
));
|
|
847
|
+
CommandItem.displayName = cmdk.Command.Item.displayName;
|
|
848
|
+
var Separator2 = React22__namespace.forwardRef(
|
|
849
|
+
({ className, orientation = "horizontal", decorative = true, ...props }, ref) => /* @__PURE__ */ jsxRuntime.jsx(
|
|
850
|
+
"div",
|
|
851
|
+
{
|
|
852
|
+
ref,
|
|
853
|
+
role: decorative ? "none" : "separator",
|
|
854
|
+
"aria-orientation": !decorative ? orientation : void 0,
|
|
855
|
+
className: cn(
|
|
856
|
+
"shrink-0 bg-border",
|
|
857
|
+
orientation === "horizontal" ? "h-[1px] w-full" : "h-full w-[1px]",
|
|
858
|
+
className
|
|
859
|
+
),
|
|
860
|
+
...props
|
|
861
|
+
}
|
|
862
|
+
)
|
|
863
|
+
);
|
|
864
|
+
Separator2.displayName = "Separator";
|
|
865
|
+
function DataTableFacetedFilter({
|
|
866
|
+
column,
|
|
867
|
+
title,
|
|
868
|
+
options,
|
|
869
|
+
variant = "popover",
|
|
870
|
+
className,
|
|
871
|
+
isQueryFilter = false,
|
|
872
|
+
handleFilterChange,
|
|
873
|
+
currentValue
|
|
874
|
+
}) {
|
|
875
|
+
const t = useTableTranslations();
|
|
876
|
+
const [selectedValues, setSelectedValues] = React22.useState(/* @__PURE__ */ new Set());
|
|
877
|
+
React22.useEffect(() => {
|
|
878
|
+
let filterValue = [];
|
|
879
|
+
if (isQueryFilter) {
|
|
880
|
+
filterValue = currentValue ? [currentValue] : [];
|
|
881
|
+
} else if (column) {
|
|
882
|
+
const columnFilterValue = column == null ? void 0 : column.getFilterValue();
|
|
883
|
+
filterValue = Array.isArray(columnFilterValue) ? columnFilterValue : [];
|
|
884
|
+
}
|
|
885
|
+
setSelectedValues(new Set(filterValue));
|
|
886
|
+
}, [currentValue, column, isQueryFilter]);
|
|
887
|
+
const handleValueChange = (value) => {
|
|
888
|
+
if (isQueryFilter) {
|
|
889
|
+
setSelectedValues(/* @__PURE__ */ new Set([value]));
|
|
890
|
+
} else {
|
|
891
|
+
const newSelectedValues = new Set(selectedValues);
|
|
892
|
+
if (newSelectedValues.has(value)) {
|
|
893
|
+
newSelectedValues.delete(value);
|
|
894
|
+
} else {
|
|
895
|
+
newSelectedValues.add(value);
|
|
896
|
+
}
|
|
897
|
+
setSelectedValues(newSelectedValues);
|
|
898
|
+
}
|
|
899
|
+
if (isQueryFilter && handleFilterChange && column) {
|
|
900
|
+
handleFilterChange(String(column.id), value);
|
|
901
|
+
} else if (!isQueryFilter && column) {
|
|
902
|
+
const newSelectedValues = new Set(selectedValues);
|
|
903
|
+
if (newSelectedValues.has(value)) {
|
|
904
|
+
newSelectedValues.delete(value);
|
|
905
|
+
} else {
|
|
906
|
+
newSelectedValues.add(value);
|
|
907
|
+
}
|
|
908
|
+
const filterValues = Array.from(newSelectedValues);
|
|
909
|
+
const finalValue = filterValues.length > 0 ? filterValues : void 0;
|
|
910
|
+
column.setFilterValue(finalValue);
|
|
911
|
+
}
|
|
912
|
+
};
|
|
913
|
+
const clearFilters = () => {
|
|
914
|
+
if (isQueryFilter && handleFilterChange && column) {
|
|
915
|
+
handleFilterChange(String(column.id), void 0);
|
|
916
|
+
} else if (!isQueryFilter && column) {
|
|
917
|
+
column.setFilterValue(void 0);
|
|
918
|
+
}
|
|
919
|
+
};
|
|
920
|
+
const renderBadges = () => {
|
|
921
|
+
if (selectedValues.size === 0) return null;
|
|
922
|
+
const filteredOptions = options.filter((option) => selectedValues.has(option.value));
|
|
923
|
+
return /* @__PURE__ */ jsxRuntime.jsxs(jsxRuntime.Fragment, { children: [
|
|
924
|
+
/* @__PURE__ */ jsxRuntime.jsx(Separator2, { orientation: "vertical", className: "mx-2 h-4" }),
|
|
925
|
+
/* @__PURE__ */ jsxRuntime.jsx("div", { className: "flex space-x-1", children: filteredOptions.map((option) => /* @__PURE__ */ jsxRuntime.jsx(Badge, { variant: "secondary", className: "rounded-sm px-1 font-normal", children: option.label }, option.value)) })
|
|
926
|
+
] });
|
|
927
|
+
};
|
|
928
|
+
const renderCommandItems = () => /* @__PURE__ */ jsxRuntime.jsxs(jsxRuntime.Fragment, { children: [
|
|
929
|
+
/* @__PURE__ */ jsxRuntime.jsx(CommandGroup, { children: options.map((option) => {
|
|
930
|
+
const isSelected = selectedValues.has(option.value);
|
|
931
|
+
return /* @__PURE__ */ jsxRuntime.jsxs(CommandItem, { onSelect: () => handleValueChange(option.value), children: [
|
|
932
|
+
/* @__PURE__ */ jsxRuntime.jsx(
|
|
933
|
+
"div",
|
|
934
|
+
{
|
|
935
|
+
className: cn(
|
|
936
|
+
"me-2 flex size-4 items-center justify-center rounded-sm border border-primary",
|
|
937
|
+
isSelected ? "bg-primary text-primary-foreground" : "opacity-50 [&_svg]:invisible"
|
|
938
|
+
),
|
|
939
|
+
children: /* @__PURE__ */ jsxRuntime.jsx(lucideReact.Check, { className: cn("size-4"), "aria-hidden": "true" })
|
|
940
|
+
}
|
|
941
|
+
),
|
|
942
|
+
option.icon && /* @__PURE__ */ jsxRuntime.jsx(option.icon, { className: "me-2 size-4 text-muted-foreground", "aria-hidden": "true" }),
|
|
943
|
+
/* @__PURE__ */ jsxRuntime.jsx("span", { children: option.label })
|
|
944
|
+
] }, option.value);
|
|
945
|
+
}) }),
|
|
946
|
+
selectedValues.size > 0 && /* @__PURE__ */ jsxRuntime.jsxs(jsxRuntime.Fragment, { children: [
|
|
947
|
+
/* @__PURE__ */ jsxRuntime.jsx(CommandSeparator, {}),
|
|
948
|
+
/* @__PURE__ */ jsxRuntime.jsx(CommandGroup, { children: /* @__PURE__ */ jsxRuntime.jsx(CommandItem, { onSelect: clearFilters, className: "justify-center text-center", children: t("clear-filters") }) })
|
|
949
|
+
] })
|
|
950
|
+
] });
|
|
951
|
+
if (variant === "command") {
|
|
952
|
+
return /* @__PURE__ */ jsxRuntime.jsxs(Command, { className: "p-1", children: [
|
|
953
|
+
/* @__PURE__ */ jsxRuntime.jsx(
|
|
954
|
+
CommandInput,
|
|
955
|
+
{
|
|
956
|
+
placeholder: title,
|
|
957
|
+
autoFocus: true,
|
|
958
|
+
className: "flex h-8 w-full rounded-md border border-input bg-background px-3 py-1 text-sm shadow-sm transition-colors file:border-0 file:bg-transparent file:text-sm file:font-medium placeholder:text-muted-foreground focus-visible:outline-none focus-visible:ring-1 focus-visible:ring-ring disabled:cursor-not-allowed disabled:opacity-50"
|
|
959
|
+
}
|
|
960
|
+
),
|
|
961
|
+
/* @__PURE__ */ jsxRuntime.jsxs(CommandList, { className: "mt-1", children: [
|
|
962
|
+
/* @__PURE__ */ jsxRuntime.jsx(CommandEmpty, { children: t("no-items-found") }),
|
|
963
|
+
renderCommandItems()
|
|
964
|
+
] })
|
|
965
|
+
] });
|
|
966
|
+
}
|
|
967
|
+
return /* @__PURE__ */ jsxRuntime.jsxs(Popover, { children: [
|
|
968
|
+
/* @__PURE__ */ jsxRuntime.jsx(PopoverTrigger, { asChild: true, children: /* @__PURE__ */ jsxRuntime.jsxs(Button, { variant: "outline", size: "sm", className: `${className} h-8 border-dashed`, children: [
|
|
969
|
+
/* @__PURE__ */ jsxRuntime.jsx(lucideReact.Filter, { className: "me-2 size-4" }),
|
|
970
|
+
title,
|
|
971
|
+
renderBadges()
|
|
972
|
+
] }) }),
|
|
973
|
+
/* @__PURE__ */ jsxRuntime.jsx(PopoverContent, { className: "w-[200px] p-0", align: "start", children: /* @__PURE__ */ jsxRuntime.jsxs(Command, { children: [
|
|
974
|
+
/* @__PURE__ */ jsxRuntime.jsx(CommandInput, { placeholder: title }),
|
|
975
|
+
/* @__PURE__ */ jsxRuntime.jsxs(CommandList, { children: [
|
|
976
|
+
/* @__PURE__ */ jsxRuntime.jsx(CommandEmpty, { children: t("no-items-found") }),
|
|
977
|
+
renderCommandItems()
|
|
978
|
+
] })
|
|
979
|
+
] }) })
|
|
980
|
+
] });
|
|
981
|
+
}
|
|
982
|
+
function DataTableSingleSelectFilter({
|
|
983
|
+
column,
|
|
984
|
+
title,
|
|
985
|
+
options,
|
|
986
|
+
className,
|
|
987
|
+
isQueryFilter = false,
|
|
988
|
+
handleFilterChange,
|
|
989
|
+
currentValue
|
|
990
|
+
}) {
|
|
991
|
+
var _a;
|
|
992
|
+
const t = useTableTranslations();
|
|
993
|
+
const [open, setOpen] = React22.useState(false);
|
|
994
|
+
const [selectedValue, setSelectedValue] = React22.useState("");
|
|
995
|
+
const columnFilterValue = column && "getFilterValue" in column ? column.getFilterValue() : void 0;
|
|
996
|
+
React22.useEffect(() => {
|
|
997
|
+
let filterValue = "";
|
|
998
|
+
if (isQueryFilter) {
|
|
999
|
+
filterValue = currentValue || "";
|
|
1000
|
+
} else if (column) {
|
|
1001
|
+
if (Array.isArray(columnFilterValue) && columnFilterValue.length > 0) {
|
|
1002
|
+
filterValue = columnFilterValue[0] || "";
|
|
1003
|
+
} else if (typeof columnFilterValue === "string") {
|
|
1004
|
+
filterValue = columnFilterValue;
|
|
1005
|
+
} else {
|
|
1006
|
+
filterValue = "";
|
|
1007
|
+
}
|
|
1008
|
+
}
|
|
1009
|
+
setSelectedValue(filterValue);
|
|
1010
|
+
}, [currentValue, column, isQueryFilter, columnFilterValue]);
|
|
1011
|
+
const handleValueChange = (value) => {
|
|
1012
|
+
const newValue = value === selectedValue ? "" : value;
|
|
1013
|
+
setSelectedValue(newValue);
|
|
1014
|
+
setOpen(false);
|
|
1015
|
+
if (isQueryFilter && handleFilterChange && column) {
|
|
1016
|
+
handleFilterChange(String(column.id), newValue || void 0);
|
|
1017
|
+
} else if (!isQueryFilter && column) {
|
|
1018
|
+
const filterValue = newValue ? [newValue] : void 0;
|
|
1019
|
+
column.setFilterValue(filterValue);
|
|
1020
|
+
}
|
|
1021
|
+
};
|
|
1022
|
+
const selectedOptionLabel = (_a = options.find((option) => option.value === selectedValue)) == null ? void 0 : _a.label;
|
|
1023
|
+
return /* @__PURE__ */ jsxRuntime.jsxs(Popover, { open, onOpenChange: setOpen, children: [
|
|
1024
|
+
/* @__PURE__ */ jsxRuntime.jsx(PopoverTrigger, { asChild: true, children: /* @__PURE__ */ jsxRuntime.jsxs(
|
|
1025
|
+
Button,
|
|
1026
|
+
{
|
|
1027
|
+
variant: "outline",
|
|
1028
|
+
size: "sm",
|
|
1029
|
+
className: cn("h-8 border-dashed", className),
|
|
1030
|
+
children: [
|
|
1031
|
+
/* @__PURE__ */ jsxRuntime.jsx(lucideReact.PlusCircle, { className: "me-2 h-4 w-4" }),
|
|
1032
|
+
title,
|
|
1033
|
+
selectedValue && /* @__PURE__ */ jsxRuntime.jsxs(jsxRuntime.Fragment, { children: [
|
|
1034
|
+
/* @__PURE__ */ jsxRuntime.jsx(Separator2, { orientation: "vertical", className: "mx-2 h-4" }),
|
|
1035
|
+
/* @__PURE__ */ jsxRuntime.jsx(Badge, { variant: "secondary", className: "rounded-sm px-1 font-normal lg:hidden", children: "1" }),
|
|
1036
|
+
/* @__PURE__ */ jsxRuntime.jsx("div", { className: "hidden space-x-1 lg:flex", children: /* @__PURE__ */ jsxRuntime.jsx(Badge, { variant: "secondary", className: "rounded-sm px-1 font-normal", children: selectedOptionLabel }) })
|
|
1037
|
+
] })
|
|
1038
|
+
]
|
|
1039
|
+
}
|
|
1040
|
+
) }),
|
|
1041
|
+
/* @__PURE__ */ jsxRuntime.jsx(PopoverContent, { className: "w-[200px] p-0", align: "start", children: /* @__PURE__ */ jsxRuntime.jsx(Command, { children: /* @__PURE__ */ jsxRuntime.jsx(CommandList, { children: /* @__PURE__ */ jsxRuntime.jsxs(CommandGroup, { children: [
|
|
1042
|
+
/* @__PURE__ */ jsxRuntime.jsxs(CommandItem, { onSelect: () => handleValueChange(""), className: "justify-between", children: [
|
|
1043
|
+
t("all") || "All",
|
|
1044
|
+
/* @__PURE__ */ jsxRuntime.jsx(
|
|
1045
|
+
lucideReact.Check,
|
|
1046
|
+
{
|
|
1047
|
+
className: cn("h-4 w-4", selectedValue === "" ? "opacity-100" : "opacity-0")
|
|
1048
|
+
}
|
|
1049
|
+
)
|
|
1050
|
+
] }),
|
|
1051
|
+
/* @__PURE__ */ jsxRuntime.jsx(CommandSeparator, {}),
|
|
1052
|
+
options.map((option) => {
|
|
1053
|
+
const isSelected = selectedValue === option.value;
|
|
1054
|
+
return /* @__PURE__ */ jsxRuntime.jsxs(
|
|
1055
|
+
CommandItem,
|
|
1056
|
+
{
|
|
1057
|
+
onSelect: () => handleValueChange(option.value),
|
|
1058
|
+
className: "justify-between",
|
|
1059
|
+
children: [
|
|
1060
|
+
/* @__PURE__ */ jsxRuntime.jsxs("div", { className: "flex items-center", children: [
|
|
1061
|
+
option.icon && /* @__PURE__ */ jsxRuntime.jsx(
|
|
1062
|
+
option.icon,
|
|
1063
|
+
{
|
|
1064
|
+
className: "me-2 h-4 w-4 text-muted-foreground",
|
|
1065
|
+
"aria-hidden": "true"
|
|
1066
|
+
}
|
|
1067
|
+
),
|
|
1068
|
+
/* @__PURE__ */ jsxRuntime.jsx("span", { children: option.label })
|
|
1069
|
+
] }),
|
|
1070
|
+
/* @__PURE__ */ jsxRuntime.jsx(lucideReact.Check, { className: cn("h-4 w-4", isSelected ? "opacity-100" : "opacity-0") })
|
|
1071
|
+
]
|
|
1072
|
+
},
|
|
1073
|
+
option.value
|
|
1074
|
+
);
|
|
1075
|
+
})
|
|
1076
|
+
] }) }) }) })
|
|
1077
|
+
] });
|
|
1078
|
+
}
|
|
1079
|
+
var DropdownMenu = DropdownMenuPrimitive__namespace.Root;
|
|
1080
|
+
var DropdownMenuTrigger = DropdownMenuPrimitive__namespace.Trigger;
|
|
1081
|
+
var DropdownMenuGroup = DropdownMenuPrimitive__namespace.Group;
|
|
1082
|
+
var DropdownMenuSubTrigger = React22__namespace.forwardRef(({ className, inset, children, ...props }, ref) => /* @__PURE__ */ jsxRuntime.jsxs(
|
|
1083
|
+
DropdownMenuPrimitive__namespace.SubTrigger,
|
|
1084
|
+
{
|
|
1085
|
+
ref,
|
|
1086
|
+
className: cn(
|
|
1087
|
+
"flex cursor-default select-none items-center rounded-sm px-2 py-1.5 text-sm outline-none focus:bg-accent data-[state=open]:bg-accent",
|
|
1088
|
+
inset && "ps-8",
|
|
1089
|
+
className
|
|
1090
|
+
),
|
|
1091
|
+
...props,
|
|
1092
|
+
children: [
|
|
1093
|
+
children,
|
|
1094
|
+
/* @__PURE__ */ jsxRuntime.jsx(lucideReact.ChevronRight, { className: "ms-auto h-4 w-4" })
|
|
1095
|
+
]
|
|
1096
|
+
}
|
|
1097
|
+
));
|
|
1098
|
+
DropdownMenuSubTrigger.displayName = DropdownMenuPrimitive__namespace.SubTrigger.displayName;
|
|
1099
|
+
var DropdownMenuSubContent = React22__namespace.forwardRef(({ className, ...props }, ref) => /* @__PURE__ */ jsxRuntime.jsx(
|
|
1100
|
+
DropdownMenuPrimitive__namespace.SubContent,
|
|
1101
|
+
{
|
|
1102
|
+
ref,
|
|
1103
|
+
className: cn(
|
|
1104
|
+
"z-50 min-w-[8rem] overflow-hidden rounded-md border bg-popover p-1 text-popover-foreground shadow-lg data-[state=open]:animate-in data-[state=closed]:animate-out data-[state=closed]:fade-out-0 data-[state=open]:fade-in-0 data-[state=closed]:zoom-out-95 data-[state=open]:zoom-in-95 data-[side=bottom]:slide-in-from-top-2 data-[side=left]:slide-in-from-right-2 data-[side=right]:slide-in-from-left-2 data-[side=top]:slide-in-from-bottom-2",
|
|
1105
|
+
className
|
|
1106
|
+
),
|
|
1107
|
+
...props
|
|
1108
|
+
}
|
|
1109
|
+
));
|
|
1110
|
+
DropdownMenuSubContent.displayName = DropdownMenuPrimitive__namespace.SubContent.displayName;
|
|
1111
|
+
var DropdownMenuContent = React22__namespace.forwardRef(({ className, sideOffset = 4, ...props }, ref) => /* @__PURE__ */ jsxRuntime.jsx(DropdownMenuPrimitive__namespace.Portal, { children: /* @__PURE__ */ jsxRuntime.jsx(
|
|
1112
|
+
DropdownMenuPrimitive__namespace.Content,
|
|
1113
|
+
{
|
|
1114
|
+
ref,
|
|
1115
|
+
sideOffset,
|
|
1116
|
+
className: cn(
|
|
1117
|
+
"z-50 min-w-[8rem] overflow-hidden rounded-md border bg-popover p-1 text-popover-foreground shadow-md data-[state=open]:animate-in data-[state=closed]:animate-out data-[state=closed]:fade-out-0 data-[state=open]:fade-in-0 data-[state=closed]:zoom-out-95 data-[state=open]:zoom-in-95 data-[side=bottom]:slide-in-from-top-2 data-[side=left]:slide-in-from-right-2 data-[side=right]:slide-in-from-left-2 data-[side=top]:slide-in-from-bottom-2",
|
|
1118
|
+
className
|
|
1119
|
+
),
|
|
1120
|
+
...props
|
|
1121
|
+
}
|
|
1122
|
+
) }));
|
|
1123
|
+
DropdownMenuContent.displayName = DropdownMenuPrimitive__namespace.Content.displayName;
|
|
1124
|
+
var DropdownMenuItem = React22__namespace.forwardRef(({ className, inset, ...props }, ref) => /* @__PURE__ */ jsxRuntime.jsx(
|
|
1125
|
+
DropdownMenuPrimitive__namespace.Item,
|
|
1126
|
+
{
|
|
1127
|
+
ref,
|
|
1128
|
+
className: cn(
|
|
1129
|
+
"relative flex cursor-default select-none items-center rounded-sm px-2 py-1.5 text-sm outline-none transition-colors focus:bg-accent focus:text-accent-foreground data-[disabled]:pointer-events-none data-[disabled]:opacity-50",
|
|
1130
|
+
inset && "ps-8",
|
|
1131
|
+
className
|
|
1132
|
+
),
|
|
1133
|
+
...props
|
|
1134
|
+
}
|
|
1135
|
+
));
|
|
1136
|
+
DropdownMenuItem.displayName = DropdownMenuPrimitive__namespace.Item.displayName;
|
|
1137
|
+
var DropdownMenuCheckboxItem = React22__namespace.forwardRef(({ className, children, checked, ...props }, ref) => /* @__PURE__ */ jsxRuntime.jsxs(
|
|
1138
|
+
DropdownMenuPrimitive__namespace.CheckboxItem,
|
|
1139
|
+
{
|
|
1140
|
+
ref,
|
|
1141
|
+
className: cn(
|
|
1142
|
+
"relative flex cursor-default select-none items-center rounded-sm py-1.5 pe-2 ps-8 text-sm outline-none transition-colors focus:bg-accent focus:text-accent-foreground data-[disabled]:pointer-events-none data-[disabled]:opacity-50",
|
|
1143
|
+
className
|
|
1144
|
+
),
|
|
1145
|
+
checked,
|
|
1146
|
+
...props,
|
|
1147
|
+
children: [
|
|
1148
|
+
/* @__PURE__ */ jsxRuntime.jsx("span", { className: "absolute start-2 flex h-3.5 w-3.5 items-center justify-center", children: /* @__PURE__ */ jsxRuntime.jsx(DropdownMenuPrimitive__namespace.ItemIndicator, { children: /* @__PURE__ */ jsxRuntime.jsx(lucideReact.Check, { className: "h-4 w-4" }) }) }),
|
|
1149
|
+
children
|
|
1150
|
+
]
|
|
1151
|
+
}
|
|
1152
|
+
));
|
|
1153
|
+
DropdownMenuCheckboxItem.displayName = DropdownMenuPrimitive__namespace.CheckboxItem.displayName;
|
|
1154
|
+
var DropdownMenuRadioItem = React22__namespace.forwardRef(({ className, children, ...props }, ref) => /* @__PURE__ */ jsxRuntime.jsxs(
|
|
1155
|
+
DropdownMenuPrimitive__namespace.RadioItem,
|
|
1156
|
+
{
|
|
1157
|
+
ref,
|
|
1158
|
+
className: cn(
|
|
1159
|
+
"relative flex cursor-default select-none items-center rounded-sm py-1.5 pe-2 ps-8 text-sm outline-none transition-colors focus:bg-accent focus:text-accent-foreground data-[disabled]:pointer-events-none data-[disabled]:opacity-50",
|
|
1160
|
+
className
|
|
1161
|
+
),
|
|
1162
|
+
...props,
|
|
1163
|
+
children: [
|
|
1164
|
+
/* @__PURE__ */ jsxRuntime.jsx("span", { className: "absolute start-2 flex h-3.5 w-3.5 items-center justify-center", children: /* @__PURE__ */ jsxRuntime.jsx(DropdownMenuPrimitive__namespace.ItemIndicator, { children: /* @__PURE__ */ jsxRuntime.jsx(lucideReact.Circle, { className: "h-2 w-2 fill-current" }) }) }),
|
|
1165
|
+
children
|
|
1166
|
+
]
|
|
1167
|
+
}
|
|
1168
|
+
));
|
|
1169
|
+
DropdownMenuRadioItem.displayName = DropdownMenuPrimitive__namespace.RadioItem.displayName;
|
|
1170
|
+
var DropdownMenuLabel = React22__namespace.forwardRef(({ className, inset, ...props }, ref) => /* @__PURE__ */ jsxRuntime.jsx(
|
|
1171
|
+
DropdownMenuPrimitive__namespace.Label,
|
|
1172
|
+
{
|
|
1173
|
+
ref,
|
|
1174
|
+
className: cn("px-2 py-1.5 text-sm font-semibold", inset && "ps-8", className),
|
|
1175
|
+
...props
|
|
1176
|
+
}
|
|
1177
|
+
));
|
|
1178
|
+
DropdownMenuLabel.displayName = DropdownMenuPrimitive__namespace.Label.displayName;
|
|
1179
|
+
var DropdownMenuSeparator = React22__namespace.forwardRef(({ className, ...props }, ref) => /* @__PURE__ */ jsxRuntime.jsx(
|
|
1180
|
+
DropdownMenuPrimitive__namespace.Separator,
|
|
1181
|
+
{
|
|
1182
|
+
ref,
|
|
1183
|
+
className: cn("-mx-1 my-1 h-px bg-muted", className),
|
|
1184
|
+
...props
|
|
1185
|
+
}
|
|
1186
|
+
));
|
|
1187
|
+
DropdownMenuSeparator.displayName = DropdownMenuPrimitive__namespace.Separator.displayName;
|
|
1188
|
+
var DropdownMenuShortcut = ({ className, ...props }) => {
|
|
1189
|
+
return /* @__PURE__ */ jsxRuntime.jsx("span", { className: cn("ms-auto text-xs tracking-widest opacity-60", className), ...props });
|
|
1190
|
+
};
|
|
1191
|
+
DropdownMenuShortcut.displayName = "DropdownMenuShortcut";
|
|
1192
|
+
function DataTableViewOptions({ table }) {
|
|
1193
|
+
const t = useTableTranslations();
|
|
1194
|
+
const config = useTableConfig();
|
|
1195
|
+
const language = config.i18n.direction === "rtl" || config.i18n.direction === "auto" && config.i18n.locale === "ar" ? "ar" : "en";
|
|
1196
|
+
return /* @__PURE__ */ jsxRuntime.jsxs(DropdownMenu, { children: [
|
|
1197
|
+
/* @__PURE__ */ jsxRuntime.jsx(DropdownMenuPrimitive.DropdownMenuTrigger, { asChild: true, children: /* @__PURE__ */ jsxRuntime.jsxs(
|
|
1198
|
+
Button,
|
|
1199
|
+
{
|
|
1200
|
+
variant: "outline",
|
|
1201
|
+
size: "sm",
|
|
1202
|
+
className: "flex h-9 items-center justify-center gap-2 px-4",
|
|
1203
|
+
children: [
|
|
1204
|
+
t("columns"),
|
|
1205
|
+
/* @__PURE__ */ jsxRuntime.jsx(lucideReact.Columns3, { className: "size-4" })
|
|
1206
|
+
]
|
|
1207
|
+
}
|
|
1208
|
+
) }),
|
|
1209
|
+
/* @__PURE__ */ jsxRuntime.jsxs(DropdownMenuContent, { align: "end", className: "max-w-sm", children: [
|
|
1210
|
+
/* @__PURE__ */ jsxRuntime.jsx(
|
|
1211
|
+
DropdownMenuLabel,
|
|
1212
|
+
{
|
|
1213
|
+
style: {
|
|
1214
|
+
direction: language === "ar" ? "rtl" : "ltr"
|
|
1215
|
+
},
|
|
1216
|
+
children: t("Toggle-Visibility")
|
|
1217
|
+
}
|
|
1218
|
+
),
|
|
1219
|
+
/* @__PURE__ */ jsxRuntime.jsx(DropdownMenuSeparator, {}),
|
|
1220
|
+
table.getAllColumns().filter((column) => typeof column.accessorFn !== "undefined" && column.getCanHide()).map((column) => {
|
|
1221
|
+
return /* @__PURE__ */ jsxRuntime.jsx(
|
|
1222
|
+
DropdownMenuCheckboxItem,
|
|
1223
|
+
{
|
|
1224
|
+
className: "cursor-pointer capitalize",
|
|
1225
|
+
checked: column.getIsVisible(),
|
|
1226
|
+
onCheckedChange: (value) => column.toggleVisibility(!!value),
|
|
1227
|
+
style: {
|
|
1228
|
+
direction: language === "ar" ? "rtl" : "ltr"
|
|
1229
|
+
},
|
|
1230
|
+
children: typeof column.columnDef.header === "string" ? String(column.columnDef.header) : column.id
|
|
1231
|
+
},
|
|
1232
|
+
column.id
|
|
1233
|
+
);
|
|
1234
|
+
})
|
|
1235
|
+
] })
|
|
1236
|
+
] });
|
|
1237
|
+
}
|
|
1238
|
+
var TooltipProvider = TooltipPrimitive__namespace.Provider;
|
|
1239
|
+
var Tooltip = ({ children, ...props }) => /* @__PURE__ */ jsxRuntime.jsx(TooltipProvider, { children: /* @__PURE__ */ jsxRuntime.jsx(TooltipPrimitive__namespace.Root, { ...props, children }) });
|
|
1240
|
+
var TooltipTrigger = TooltipPrimitive__namespace.Trigger;
|
|
1241
|
+
var TooltipContent = React22__namespace.forwardRef(({ className, sideOffset = 4, ...props }, ref) => /* @__PURE__ */ jsxRuntime.jsx(TooltipPrimitive__namespace.Portal, { children: /* @__PURE__ */ jsxRuntime.jsx(
|
|
1242
|
+
TooltipPrimitive__namespace.Content,
|
|
1243
|
+
{
|
|
1244
|
+
ref,
|
|
1245
|
+
sideOffset,
|
|
1246
|
+
className: cn(
|
|
1247
|
+
"z-50 overflow-hidden rounded-md bg-primary px-3 py-1.5 text-xs text-primary-foreground animate-in fade-in-0 zoom-in-95 data-[state=closed]:animate-out data-[state=closed]:fade-out-0 data-[state=closed]:zoom-out-95 data-[side=bottom]:slide-in-from-top-2 data-[side=left]:slide-in-from-right-2 data-[side=right]:slide-in-from-left-2 data-[side=top]:slide-in-from-bottom-2",
|
|
1248
|
+
className
|
|
1249
|
+
),
|
|
1250
|
+
...props
|
|
1251
|
+
}
|
|
1252
|
+
) }));
|
|
1253
|
+
TooltipContent.displayName = TooltipPrimitive__namespace.Content.displayName;
|
|
1254
|
+
var ButtonTooltip = ({ content }) => {
|
|
1255
|
+
return /* @__PURE__ */ jsxRuntime.jsxs(Tooltip, { children: [
|
|
1256
|
+
/* @__PURE__ */ jsxRuntime.jsx(TooltipTrigger, { asChild: true, children: /* @__PURE__ */ jsxRuntime.jsx("span", { className: "absolute inset-0" }) }),
|
|
1257
|
+
/* @__PURE__ */ jsxRuntime.jsx(TooltipContent, { className: "max-w-96 text-wrap", children: content })
|
|
1258
|
+
] });
|
|
1259
|
+
};
|
|
1260
|
+
var ActionButton = ({
|
|
1261
|
+
onClick,
|
|
1262
|
+
disabled,
|
|
1263
|
+
className,
|
|
1264
|
+
icon,
|
|
1265
|
+
tooltip,
|
|
1266
|
+
variant = "default"
|
|
1267
|
+
}) => {
|
|
1268
|
+
return /* @__PURE__ */ jsxRuntime.jsxs(
|
|
1269
|
+
Button,
|
|
1270
|
+
{
|
|
1271
|
+
onClick,
|
|
1272
|
+
size: "icon",
|
|
1273
|
+
variant,
|
|
1274
|
+
className: `relative ${className} ${disabled ? "cursor-not-allowed" : ""}`,
|
|
1275
|
+
disabled,
|
|
1276
|
+
children: [
|
|
1277
|
+
icon,
|
|
1278
|
+
tooltip && /* @__PURE__ */ jsxRuntime.jsx(ButtonTooltip, { content: tooltip })
|
|
1279
|
+
]
|
|
1280
|
+
}
|
|
1281
|
+
);
|
|
1282
|
+
};
|
|
1283
|
+
var TableActionsRow = ({
|
|
1284
|
+
editAction,
|
|
1285
|
+
showAction,
|
|
1286
|
+
deleteAction,
|
|
1287
|
+
downloadAction,
|
|
1288
|
+
className,
|
|
1289
|
+
customButtons,
|
|
1290
|
+
text,
|
|
1291
|
+
dropMoreActions,
|
|
1292
|
+
useDropdown = true,
|
|
1293
|
+
cancelAction
|
|
1294
|
+
}) => {
|
|
1295
|
+
const t = useTableTranslations();
|
|
1296
|
+
const config = useTableConfig();
|
|
1297
|
+
const isArabic = config.i18n.direction === "rtl" || config.i18n.direction === "auto" && config.i18n.locale === "ar";
|
|
1298
|
+
const commonActions = [
|
|
1299
|
+
editAction && {
|
|
1300
|
+
text: t("edit"),
|
|
1301
|
+
icon: /* @__PURE__ */ jsxRuntime.jsx(lucideReact.Edit, { className: "text-tab-teal size-4" }),
|
|
1302
|
+
function: editAction.action,
|
|
1303
|
+
disabled: editAction.disabled,
|
|
1304
|
+
className: "bg-tab-teal hover:bg-tab-teal-800",
|
|
1305
|
+
tooltip: t("edit")
|
|
1306
|
+
},
|
|
1307
|
+
showAction && {
|
|
1308
|
+
text: t("show"),
|
|
1309
|
+
icon: /* @__PURE__ */ jsxRuntime.jsx(lucideReact.Eye, { className: "size-4" }),
|
|
1310
|
+
function: showAction.action,
|
|
1311
|
+
disabled: showAction.disabled,
|
|
1312
|
+
className: "bg-tab-turquoise hover:bg-tab-turquoise-800",
|
|
1313
|
+
tooltip: t("show")
|
|
1314
|
+
},
|
|
1315
|
+
downloadAction && {
|
|
1316
|
+
text: t("download"),
|
|
1317
|
+
icon: /* @__PURE__ */ jsxRuntime.jsx(lucideReact.Download, { className: "text-main size-4" }),
|
|
1318
|
+
function: downloadAction.action,
|
|
1319
|
+
disabled: downloadAction.disabled,
|
|
1320
|
+
className: "outline outline-1 outline-main",
|
|
1321
|
+
tooltip: t("download"),
|
|
1322
|
+
variant: "ghost"
|
|
1323
|
+
},
|
|
1324
|
+
deleteAction && {
|
|
1325
|
+
text: t("delete"),
|
|
1326
|
+
icon: /* @__PURE__ */ jsxRuntime.jsx(lucideReact.Trash2Icon, { className: "size-4 text-rose-700" }),
|
|
1327
|
+
function: deleteAction.action,
|
|
1328
|
+
disabled: deleteAction.disabled,
|
|
1329
|
+
className: "outline outline-1 outline-rose-700",
|
|
1330
|
+
tooltip: t("delete"),
|
|
1331
|
+
variant: "ghost"
|
|
1332
|
+
},
|
|
1333
|
+
cancelAction && {
|
|
1334
|
+
text: t("cancel"),
|
|
1335
|
+
icon: /* @__PURE__ */ jsxRuntime.jsx(lucideReact.XCircle, { className: "size-4 text-rose-600" }),
|
|
1336
|
+
function: cancelAction.action,
|
|
1337
|
+
disabled: cancelAction.disabled,
|
|
1338
|
+
className: "outline outline-1 outline-rose-600",
|
|
1339
|
+
tooltip: cancelAction.tooltip || t("cancel"),
|
|
1340
|
+
variant: "ghost"
|
|
1341
|
+
}
|
|
1342
|
+
].filter(Boolean);
|
|
1343
|
+
const renderActionButtons = () => {
|
|
1344
|
+
if (useDropdown) {
|
|
1345
|
+
return /* @__PURE__ */ jsxRuntime.jsxs(DropdownMenu, { dir: isArabic ? "rtl" : "ltr", children: [
|
|
1346
|
+
/* @__PURE__ */ jsxRuntime.jsx(DropdownMenuTrigger, { asChild: true, children: /* @__PURE__ */ jsxRuntime.jsx(Button, { variant: "outline", size: "icon", type: "button", children: /* @__PURE__ */ jsxRuntime.jsx(lucideReact.MoreVertical, { size: 20 }) }) }),
|
|
1347
|
+
/* @__PURE__ */ jsxRuntime.jsxs(DropdownMenuContent, { align: "end", className: "w-56", children: [
|
|
1348
|
+
/* @__PURE__ */ jsxRuntime.jsx(DropdownMenuLabel, { children: t("actions") }),
|
|
1349
|
+
/* @__PURE__ */ jsxRuntime.jsx(DropdownMenuSeparator, {}),
|
|
1350
|
+
/* @__PURE__ */ jsxRuntime.jsxs(DropdownMenuGroup, { children: [
|
|
1351
|
+
commonActions.map((action, index) => /* @__PURE__ */ jsxRuntime.jsxs(
|
|
1352
|
+
DropdownMenuItem,
|
|
1353
|
+
{
|
|
1354
|
+
disabled: action == null ? void 0 : action.disabled,
|
|
1355
|
+
className: "flex !justify-between",
|
|
1356
|
+
onClick: action == null ? void 0 : action.function,
|
|
1357
|
+
children: [
|
|
1358
|
+
/* @__PURE__ */ jsxRuntime.jsx("span", { children: action == null ? void 0 : action.text }),
|
|
1359
|
+
/* @__PURE__ */ jsxRuntime.jsx(DropdownMenuShortcut, { children: action == null ? void 0 : action.icon })
|
|
1360
|
+
]
|
|
1361
|
+
},
|
|
1362
|
+
index
|
|
1363
|
+
)),
|
|
1364
|
+
dropMoreActions == null ? void 0 : dropMoreActions.map((item, index) => /* @__PURE__ */ jsxRuntime.jsxs(
|
|
1365
|
+
DropdownMenuItem,
|
|
1366
|
+
{
|
|
1367
|
+
disabled: item.disabled,
|
|
1368
|
+
className: "flex !justify-between",
|
|
1369
|
+
onClick: item.function,
|
|
1370
|
+
...item == null ? void 0 : item.attr,
|
|
1371
|
+
children: [
|
|
1372
|
+
/* @__PURE__ */ jsxRuntime.jsx("span", { children: item.text }),
|
|
1373
|
+
/* @__PURE__ */ jsxRuntime.jsx(DropdownMenuShortcut, { children: item.icon }),
|
|
1374
|
+
item.toolTip && /* @__PURE__ */ jsxRuntime.jsx(ButtonTooltip, { content: item.toolTip })
|
|
1375
|
+
]
|
|
1376
|
+
},
|
|
1377
|
+
`more-${index}`
|
|
1378
|
+
))
|
|
1379
|
+
] })
|
|
1380
|
+
] })
|
|
1381
|
+
] });
|
|
1382
|
+
}
|
|
1383
|
+
return /* @__PURE__ */ jsxRuntime.jsx(jsxRuntime.Fragment, { children: commonActions.map((action, index) => /* @__PURE__ */ jsxRuntime.jsx(
|
|
1384
|
+
ActionButton,
|
|
1385
|
+
{
|
|
1386
|
+
onClick: action == null ? void 0 : action.function,
|
|
1387
|
+
disabled: action == null ? void 0 : action.disabled,
|
|
1388
|
+
className: (action == null ? void 0 : action.className) || "",
|
|
1389
|
+
icon: action == null ? void 0 : action.icon,
|
|
1390
|
+
tooltip: action == null ? void 0 : action.tooltip,
|
|
1391
|
+
variant: action == null ? void 0 : action.variant
|
|
1392
|
+
},
|
|
1393
|
+
index
|
|
1394
|
+
)) });
|
|
1395
|
+
};
|
|
1396
|
+
return /* @__PURE__ */ jsxRuntime.jsxs("div", { className: `${className} flex flex-row items-center gap-1 text-center md:gap-3`, children: [
|
|
1397
|
+
renderActionButtons(),
|
|
1398
|
+
customButtons && Array.isArray(customButtons) ? customButtons.filter((customButton) => Object.keys(customButton).length !== 0).map((customButton, index) => /* @__PURE__ */ jsxRuntime.jsxs(
|
|
1399
|
+
Button,
|
|
1400
|
+
{
|
|
1401
|
+
onClick: customButton == null ? void 0 : customButton.function,
|
|
1402
|
+
className: `${customButton.className || ""} relative flex justify-center gap-2`,
|
|
1403
|
+
...customButton.attr,
|
|
1404
|
+
children: [
|
|
1405
|
+
customButton.toolTip && /* @__PURE__ */ jsxRuntime.jsx(ButtonTooltip, { content: customButton.toolTip }),
|
|
1406
|
+
customButton.text,
|
|
1407
|
+
customButton.icon,
|
|
1408
|
+
customButton.children
|
|
1409
|
+
]
|
|
1410
|
+
},
|
|
1411
|
+
index
|
|
1412
|
+
)) : React22__namespace.default.isValidElement(customButtons) ? customButtons : null,
|
|
1413
|
+
text && /* @__PURE__ */ jsxRuntime.jsx("span", { children: text }),
|
|
1414
|
+
!useDropdown && dropMoreActions && /* @__PURE__ */ jsxRuntime.jsxs(DropdownMenu, { dir: isArabic ? "rtl" : "ltr", children: [
|
|
1415
|
+
/* @__PURE__ */ jsxRuntime.jsx(DropdownMenuTrigger, { asChild: true, children: /* @__PURE__ */ jsxRuntime.jsx(Button, { variant: "outline", size: "icon", children: /* @__PURE__ */ jsxRuntime.jsx(lucideReact.MoreVertical, { size: 20 }) }) }),
|
|
1416
|
+
/* @__PURE__ */ jsxRuntime.jsxs(DropdownMenuContent, { align: "end", className: "w-56", children: [
|
|
1417
|
+
/* @__PURE__ */ jsxRuntime.jsx(DropdownMenuLabel, { children: t("actions") }),
|
|
1418
|
+
/* @__PURE__ */ jsxRuntime.jsx(DropdownMenuSeparator, {}),
|
|
1419
|
+
/* @__PURE__ */ jsxRuntime.jsx(DropdownMenuGroup, { children: dropMoreActions.filter((action) => Object.keys(action).length !== 0).map((item, index) => /* @__PURE__ */ jsxRuntime.jsxs(
|
|
1420
|
+
DropdownMenuItem,
|
|
1421
|
+
{
|
|
1422
|
+
disabled: item.disabled,
|
|
1423
|
+
className: "flex !justify-between",
|
|
1424
|
+
onClick: item.function,
|
|
1425
|
+
children: [
|
|
1426
|
+
/* @__PURE__ */ jsxRuntime.jsx("span", { children: item.text }),
|
|
1427
|
+
/* @__PURE__ */ jsxRuntime.jsx(DropdownMenuShortcut, { children: item.icon })
|
|
1428
|
+
]
|
|
1429
|
+
},
|
|
1430
|
+
index
|
|
1431
|
+
)) })
|
|
1432
|
+
] })
|
|
1433
|
+
] })
|
|
1434
|
+
] });
|
|
1435
|
+
};
|
|
1436
|
+
var table_actions_row_default = TableActionsRow;
|
|
1437
|
+
function DataTableToolbar({
|
|
1438
|
+
table,
|
|
1439
|
+
viewMode,
|
|
1440
|
+
onViewModeChange,
|
|
1441
|
+
filterableColumns = [],
|
|
1442
|
+
searchableColumns = [],
|
|
1443
|
+
newRowLink,
|
|
1444
|
+
addItemPagePath,
|
|
1445
|
+
deleteRowsAction,
|
|
1446
|
+
isShowExportButtons = {
|
|
1447
|
+
isShow: true,
|
|
1448
|
+
ignoredCols: [],
|
|
1449
|
+
fileName: ""
|
|
1450
|
+
},
|
|
1451
|
+
customButtons,
|
|
1452
|
+
isQuerySearch = false,
|
|
1453
|
+
searchableQuery,
|
|
1454
|
+
isQueryFilter = false,
|
|
1455
|
+
handleFilterChange,
|
|
1456
|
+
filterableQuery,
|
|
1457
|
+
currentFilters,
|
|
1458
|
+
onClearFilters,
|
|
1459
|
+
customCss = ""
|
|
1460
|
+
}) {
|
|
1461
|
+
const isFiltered = table.getState().columnFilters.length > 0;
|
|
1462
|
+
const isQueryFiltered = isQueryFilter && currentFilters && Object.keys(currentFilters).length > 0;
|
|
1463
|
+
const hasActiveFilters = isFiltered || isQueryFiltered;
|
|
1464
|
+
const [isPending, startTransition] = React22__namespace.useTransition();
|
|
1465
|
+
const [isGoPath, setGoPath] = React22__namespace.useState(false);
|
|
1466
|
+
const t = useTableTranslations();
|
|
1467
|
+
const config = useTableConfig();
|
|
1468
|
+
const router = config.router;
|
|
1469
|
+
const [date, setDate] = React22__namespace.useState();
|
|
1470
|
+
const isArabic = config.i18n.direction === "rtl" || config.i18n.direction === "auto" && config.i18n.locale === "ar";
|
|
1471
|
+
const goAddItemPage = () => {
|
|
1472
|
+
setGoPath(true);
|
|
1473
|
+
if (addItemPagePath && router) {
|
|
1474
|
+
router.push(addItemPagePath.url);
|
|
1475
|
+
}
|
|
1476
|
+
};
|
|
1477
|
+
const handleExportSelectedRowsCSV = () => {
|
|
1478
|
+
exportSelectedRowsCsv(table, {
|
|
1479
|
+
fileName: isShowExportButtons.fileName,
|
|
1480
|
+
ignoredCols: isShowExportButtons.ignoredCols
|
|
1481
|
+
});
|
|
1482
|
+
};
|
|
1483
|
+
const activeFilterColumns = isQueryFilter ? filterableQuery || [] : filterableColumns;
|
|
1484
|
+
const hasFilters = activeFilterColumns.length > 0;
|
|
1485
|
+
isQuerySearch ? searchableQuery && searchableQuery.length > 0 : searchableColumns.length > 0;
|
|
1486
|
+
return /* @__PURE__ */ jsxRuntime.jsxs("div", { className: "flex w-full flex-col gap-3", children: [
|
|
1487
|
+
/* @__PURE__ */ jsxRuntime.jsxs("div", { className: "flex items-center gap-3", children: [
|
|
1488
|
+
config.features.viewToggle && viewMode && onViewModeChange && /* @__PURE__ */ jsxRuntime.jsxs("div", { className: "flex items-center rounded-lg border bg-muted/30 p-0.5", children: [
|
|
1489
|
+
/* @__PURE__ */ jsxRuntime.jsxs(
|
|
1490
|
+
"button",
|
|
1491
|
+
{
|
|
1492
|
+
onClick: () => onViewModeChange("table"),
|
|
1493
|
+
className: cn(
|
|
1494
|
+
"inline-flex items-center gap-1.5 rounded-md px-3 py-1.5 text-sm font-medium transition-colors",
|
|
1495
|
+
viewMode === "table" ? "bg-primary text-primary-foreground shadow-sm" : "text-muted-foreground hover:text-foreground"
|
|
1496
|
+
),
|
|
1497
|
+
children: [
|
|
1498
|
+
/* @__PURE__ */ jsxRuntime.jsx(lucideReact.TableIcon, { className: "size-4" }),
|
|
1499
|
+
t("tableView")
|
|
1500
|
+
]
|
|
1501
|
+
}
|
|
1502
|
+
),
|
|
1503
|
+
/* @__PURE__ */ jsxRuntime.jsxs(
|
|
1504
|
+
"button",
|
|
1505
|
+
{
|
|
1506
|
+
onClick: () => onViewModeChange("cards"),
|
|
1507
|
+
className: cn(
|
|
1508
|
+
"inline-flex items-center gap-1.5 rounded-md px-3 py-1.5 text-sm font-medium transition-colors",
|
|
1509
|
+
viewMode === "cards" ? "bg-primary text-primary-foreground shadow-sm" : "text-muted-foreground hover:text-foreground"
|
|
1510
|
+
),
|
|
1511
|
+
children: [
|
|
1512
|
+
/* @__PURE__ */ jsxRuntime.jsx(lucideReact.LayoutGrid, { className: "size-4" }),
|
|
1513
|
+
t("cardView")
|
|
1514
|
+
]
|
|
1515
|
+
}
|
|
1516
|
+
)
|
|
1517
|
+
] }),
|
|
1518
|
+
/* @__PURE__ */ jsxRuntime.jsxs("div", { className: "flex flex-1 items-center gap-3", children: [
|
|
1519
|
+
config.features.search && isQuerySearch && searchableQuery && searchableQuery.length > 0 && /* @__PURE__ */ jsxRuntime.jsx(jsxRuntime.Fragment, { children: searchableQuery.map((column) => /* @__PURE__ */ jsxRuntime.jsxs("div", { className: "relative flex-1 max-w-sm", children: [
|
|
1520
|
+
/* @__PURE__ */ jsxRuntime.jsx(lucideReact.Search, { className: "absolute start-3 top-2.5 h-4 w-4 text-muted-foreground" }),
|
|
1521
|
+
/* @__PURE__ */ jsxRuntime.jsx(
|
|
1522
|
+
Input,
|
|
1523
|
+
{
|
|
1524
|
+
id: String(column.id),
|
|
1525
|
+
type: (column == null ? void 0 : column.type) || "text",
|
|
1526
|
+
placeholder: `${t("Filter")} ${column.title}...`,
|
|
1527
|
+
onChange: column.handleInputChange,
|
|
1528
|
+
defaultValue: column.defaultSearch || "",
|
|
1529
|
+
className: "ps-9"
|
|
1530
|
+
}
|
|
1531
|
+
)
|
|
1532
|
+
] }, String(column.id))) }),
|
|
1533
|
+
config.features.search && !isQuerySearch && searchableColumns.length > 0 && searchableColumns.map(
|
|
1534
|
+
(column) => {
|
|
1535
|
+
var _a, _b, _c, _d, _e;
|
|
1536
|
+
return table.getColumn(column.id ? String(column.id) : "") && /* @__PURE__ */ jsxRuntime.jsx("div", { className: "flex-1 max-w-sm", children: (column == null ? void 0 : column.type) === "checkbox" ? /* @__PURE__ */ jsxRuntime.jsxs("div", { className: "flex items-center gap-2", children: [
|
|
1537
|
+
/* @__PURE__ */ jsxRuntime.jsx(
|
|
1538
|
+
Checkbox,
|
|
1539
|
+
{
|
|
1540
|
+
id: String(column.id),
|
|
1541
|
+
checked: ((_a = table.getColumn(String(column.id))) == null ? void 0 : _a.getFilterValue()) === "true",
|
|
1542
|
+
onCheckedChange: (value) => {
|
|
1543
|
+
var _a2;
|
|
1544
|
+
return (_a2 = table.getColumn(String(column.id))) == null ? void 0 : _a2.setFilterValue(value ? "true" : "false");
|
|
1545
|
+
},
|
|
1546
|
+
"aria-label": `Filter ${column.title}`,
|
|
1547
|
+
className: "size-4"
|
|
1548
|
+
}
|
|
1549
|
+
),
|
|
1550
|
+
/* @__PURE__ */ jsxRuntime.jsx(Label, { className: "cursor-pointer text-sm", htmlFor: String(column.id), children: column.title })
|
|
1551
|
+
] }) : (column == null ? void 0 : column.type) === "date" ? /* @__PURE__ */ jsxRuntime.jsxs(Popover, { children: [
|
|
1552
|
+
/* @__PURE__ */ jsxRuntime.jsx(PopoverTrigger, { asChild: true, children: /* @__PURE__ */ jsxRuntime.jsxs(
|
|
1553
|
+
Button,
|
|
1554
|
+
{
|
|
1555
|
+
variant: "outline",
|
|
1556
|
+
className: cn(
|
|
1557
|
+
"w-full justify-start text-start font-normal",
|
|
1558
|
+
!date && "text-muted-foreground"
|
|
1559
|
+
),
|
|
1560
|
+
children: [
|
|
1561
|
+
/* @__PURE__ */ jsxRuntime.jsx(lucideReact.CalendarIcon, { className: "me-2 size-4" }),
|
|
1562
|
+
date ? (() => {
|
|
1563
|
+
var _a2;
|
|
1564
|
+
const filterValue = (_a2 = table.getColumn(String(column.id))) == null ? void 0 : _a2.getFilterValue();
|
|
1565
|
+
const parsedDate = filterValue ? new Date(filterValue) : null;
|
|
1566
|
+
return parsedDate && !isNaN(parsedDate.getTime()) ? dateFns.format(parsedDate, "PPP", {
|
|
1567
|
+
locale: isArabic ? locale.ar : locale.enUS
|
|
1568
|
+
}) : t("datePlaceholder");
|
|
1569
|
+
})() : t("datePlaceholder")
|
|
1570
|
+
]
|
|
1571
|
+
}
|
|
1572
|
+
) }),
|
|
1573
|
+
/* @__PURE__ */ jsxRuntime.jsx(PopoverContent, { className: "w-auto p-0", children: /* @__PURE__ */ jsxRuntime.jsx(
|
|
1574
|
+
Calendar,
|
|
1575
|
+
{
|
|
1576
|
+
className: "py-2 text-sm",
|
|
1577
|
+
mode: "single",
|
|
1578
|
+
selected: ((_b = table.getColumn(String(column.id))) == null ? void 0 : _b.getFilterValue()) ? new Date(
|
|
1579
|
+
(_c = table.getColumn(String(column.id))) == null ? void 0 : _c.getFilterValue()
|
|
1580
|
+
) : void 0,
|
|
1581
|
+
onSelect: (selectedDate) => {
|
|
1582
|
+
var _a2;
|
|
1583
|
+
if (selectedDate && !isNaN(selectedDate.getTime())) {
|
|
1584
|
+
(_a2 = table.getColumn(String(column.id))) == null ? void 0 : _a2.setFilterValue(dateFns.format(selectedDate, "yyyy-MM-dd"));
|
|
1585
|
+
setDate(selectedDate);
|
|
1586
|
+
}
|
|
1587
|
+
},
|
|
1588
|
+
initialFocus: true
|
|
1589
|
+
}
|
|
1590
|
+
) })
|
|
1591
|
+
] }) : /* @__PURE__ */ jsxRuntime.jsxs("div", { className: "relative", children: [
|
|
1592
|
+
/* @__PURE__ */ jsxRuntime.jsx(lucideReact.Search, { className: "absolute start-3 top-2.5 h-4 w-4 text-muted-foreground" }),
|
|
1593
|
+
/* @__PURE__ */ jsxRuntime.jsx(
|
|
1594
|
+
Input,
|
|
1595
|
+
{
|
|
1596
|
+
id: String(column.id),
|
|
1597
|
+
type: (column == null ? void 0 : column.type) || "text",
|
|
1598
|
+
placeholder: `${t("Filter")} ${column.title}...`,
|
|
1599
|
+
value: (_e = (_d = table.getColumn(String(column.id))) == null ? void 0 : _d.getFilterValue()) != null ? _e : "",
|
|
1600
|
+
onChange: (event) => {
|
|
1601
|
+
var _a2;
|
|
1602
|
+
return (_a2 = table.getColumn(String(column.id))) == null ? void 0 : _a2.setFilterValue(event.target.value);
|
|
1603
|
+
},
|
|
1604
|
+
className: `ps-9 ${customCss}`
|
|
1605
|
+
},
|
|
1606
|
+
String(column.id)
|
|
1607
|
+
)
|
|
1608
|
+
] }) }, String(column.id));
|
|
1609
|
+
}
|
|
1610
|
+
)
|
|
1611
|
+
] }),
|
|
1612
|
+
/* @__PURE__ */ jsxRuntime.jsxs("div", { className: "flex items-center gap-2", children: [
|
|
1613
|
+
deleteRowsAction && table.getSelectedRowModel().rows.length > 0 ? /* @__PURE__ */ jsxRuntime.jsxs(
|
|
1614
|
+
Button,
|
|
1615
|
+
{
|
|
1616
|
+
"aria-label": "Delete selected rows",
|
|
1617
|
+
variant: "outline",
|
|
1618
|
+
size: "sm",
|
|
1619
|
+
className: "h-9",
|
|
1620
|
+
onClick: (event) => {
|
|
1621
|
+
startTransition(() => {
|
|
1622
|
+
table.toggleAllPageRowsSelected(false);
|
|
1623
|
+
deleteRowsAction(event);
|
|
1624
|
+
});
|
|
1625
|
+
},
|
|
1626
|
+
disabled: isPending,
|
|
1627
|
+
children: [
|
|
1628
|
+
/* @__PURE__ */ jsxRuntime.jsx(lucideReact.Trash2, { className: "me-2 size-4", "aria-hidden": "true" }),
|
|
1629
|
+
t("Delete")
|
|
1630
|
+
]
|
|
1631
|
+
}
|
|
1632
|
+
) : newRowLink ? /* @__PURE__ */ jsxRuntime.jsxs(
|
|
1633
|
+
"a",
|
|
1634
|
+
{
|
|
1635
|
+
"aria-label": "Create new row",
|
|
1636
|
+
href: newRowLink,
|
|
1637
|
+
className: cn(
|
|
1638
|
+
buttonVariants({
|
|
1639
|
+
variant: "outline",
|
|
1640
|
+
size: "sm",
|
|
1641
|
+
className: "h-9"
|
|
1642
|
+
})
|
|
1643
|
+
),
|
|
1644
|
+
children: [
|
|
1645
|
+
/* @__PURE__ */ jsxRuntime.jsx(lucideReact.PlusCircle, { className: "me-2 size-4", "aria-hidden": "true" }),
|
|
1646
|
+
t("new")
|
|
1647
|
+
]
|
|
1648
|
+
}
|
|
1649
|
+
) : null,
|
|
1650
|
+
config.features.columnVisibility && /* @__PURE__ */ jsxRuntime.jsx(DataTableViewOptions, { table }),
|
|
1651
|
+
config.features.csvExport && isShowExportButtons.isShow && /* @__PURE__ */ jsxRuntime.jsxs(
|
|
1652
|
+
Button,
|
|
1653
|
+
{
|
|
1654
|
+
disabled: !table.getSelectedRowModel().rows.length,
|
|
1655
|
+
"aria-label": "Export CSV",
|
|
1656
|
+
title: "Export CSV",
|
|
1657
|
+
variant: "outline",
|
|
1658
|
+
size: "sm",
|
|
1659
|
+
className: "h-9 gap-1.5",
|
|
1660
|
+
onClick: handleExportSelectedRowsCSV,
|
|
1661
|
+
children: [
|
|
1662
|
+
/* @__PURE__ */ jsxRuntime.jsx(lucideReact.Sheet, { className: "size-4", "aria-hidden": "true" }),
|
|
1663
|
+
t("export-csv")
|
|
1664
|
+
]
|
|
1665
|
+
}
|
|
1666
|
+
),
|
|
1667
|
+
customButtons && Array.isArray(customButtons) ? customButtons.filter((customButton) => Object.keys(customButton).length !== 0).map((customButton, index) => /* @__PURE__ */ jsxRuntime.jsxs(
|
|
1668
|
+
Button,
|
|
1669
|
+
{
|
|
1670
|
+
onClick: customButton.function,
|
|
1671
|
+
size: "sm",
|
|
1672
|
+
className: `${customButton.className ? customButton.className : ""} relative h-9 gap-1.5`,
|
|
1673
|
+
...customButton.attr,
|
|
1674
|
+
children: [
|
|
1675
|
+
customButton.toolTip && /* @__PURE__ */ jsxRuntime.jsx(ButtonTooltip, { content: customButton.toolTip }),
|
|
1676
|
+
customButton.icon,
|
|
1677
|
+
customButton.text,
|
|
1678
|
+
customButton.children
|
|
1679
|
+
]
|
|
1680
|
+
},
|
|
1681
|
+
index
|
|
1682
|
+
)) : React22__namespace.isValidElement(customButtons) ? customButtons : null,
|
|
1683
|
+
addItemPagePath ? (addItemPagePath == null ? void 0 : addItemPagePath.url) ? /* @__PURE__ */ jsxRuntime.jsxs(
|
|
1684
|
+
Button,
|
|
1685
|
+
{
|
|
1686
|
+
onClick: goAddItemPage,
|
|
1687
|
+
size: "sm",
|
|
1688
|
+
className: "h-9",
|
|
1689
|
+
disabled: isGoPath,
|
|
1690
|
+
children: [
|
|
1691
|
+
isGoPath ? /* @__PURE__ */ jsxRuntime.jsx(lucideReact.Loader2, { size: 20, className: "animate-spin" }) : /* @__PURE__ */ jsxRuntime.jsx(lucideReact.Plus, { size: 20 }),
|
|
1692
|
+
addItemPagePath.text ? addItemPagePath.text : t("add")
|
|
1693
|
+
]
|
|
1694
|
+
}
|
|
1695
|
+
) : null : null
|
|
1696
|
+
] })
|
|
1697
|
+
] }),
|
|
1698
|
+
config.features.filter && hasFilters && /* @__PURE__ */ jsxRuntime.jsxs("div", { className: "flex items-center gap-3", children: [
|
|
1699
|
+
/* @__PURE__ */ jsxRuntime.jsx("span", { className: "text-xs font-medium text-muted-foreground whitespace-nowrap", children: t("filter-by") }),
|
|
1700
|
+
/* @__PURE__ */ jsxRuntime.jsxs("div", { className: "flex flex-wrap items-center gap-2", children: [
|
|
1701
|
+
!isQueryFilter && filterableColumns.length > 0 && /* @__PURE__ */ jsxRuntime.jsx(jsxRuntime.Fragment, { children: filterableColumns.map((column) => {
|
|
1702
|
+
const columnId = String(column.id);
|
|
1703
|
+
if (column.isSingleSelect) {
|
|
1704
|
+
return /* @__PURE__ */ jsxRuntime.jsx(
|
|
1705
|
+
DataTableSingleSelectFilter,
|
|
1706
|
+
{
|
|
1707
|
+
column: table.getColumn(columnId),
|
|
1708
|
+
title: column.title,
|
|
1709
|
+
options: column.options,
|
|
1710
|
+
className: ""
|
|
1711
|
+
},
|
|
1712
|
+
columnId
|
|
1713
|
+
);
|
|
1714
|
+
}
|
|
1715
|
+
return /* @__PURE__ */ jsxRuntime.jsx(
|
|
1716
|
+
DataTableFacetedFilter,
|
|
1717
|
+
{
|
|
1718
|
+
column: table.getColumn(columnId),
|
|
1719
|
+
title: column.title,
|
|
1720
|
+
options: column.options
|
|
1721
|
+
},
|
|
1722
|
+
columnId
|
|
1723
|
+
);
|
|
1724
|
+
}) }),
|
|
1725
|
+
isQueryFilter && filterableQuery && filterableQuery.length > 0 && /* @__PURE__ */ jsxRuntime.jsx(jsxRuntime.Fragment, { children: filterableQuery.map((column) => {
|
|
1726
|
+
if (column.isSingleSelect) {
|
|
1727
|
+
return /* @__PURE__ */ jsxRuntime.jsx(
|
|
1728
|
+
DataTableSingleSelectFilter,
|
|
1729
|
+
{
|
|
1730
|
+
column,
|
|
1731
|
+
title: column.title,
|
|
1732
|
+
options: column.options,
|
|
1733
|
+
isQueryFilter,
|
|
1734
|
+
handleFilterChange,
|
|
1735
|
+
currentValue: currentFilters == null ? void 0 : currentFilters[column.id],
|
|
1736
|
+
className: "w-[180px]"
|
|
1737
|
+
},
|
|
1738
|
+
String(column.id)
|
|
1739
|
+
);
|
|
1740
|
+
}
|
|
1741
|
+
return /* @__PURE__ */ jsxRuntime.jsx(
|
|
1742
|
+
DataTableFacetedFilter,
|
|
1743
|
+
{
|
|
1744
|
+
column,
|
|
1745
|
+
title: column.title,
|
|
1746
|
+
options: column.options,
|
|
1747
|
+
isQueryFilter,
|
|
1748
|
+
handleFilterChange,
|
|
1749
|
+
currentValue: currentFilters == null ? void 0 : currentFilters[column.id]
|
|
1750
|
+
},
|
|
1751
|
+
String(column.id)
|
|
1752
|
+
);
|
|
1753
|
+
}) }),
|
|
1754
|
+
hasActiveFilters && /* @__PURE__ */ jsxRuntime.jsxs(
|
|
1755
|
+
Button,
|
|
1756
|
+
{
|
|
1757
|
+
"aria-label": "Reset filters",
|
|
1758
|
+
variant: "ghost",
|
|
1759
|
+
size: "sm",
|
|
1760
|
+
className: "h-8 gap-1.5 text-muted-foreground hover:text-foreground",
|
|
1761
|
+
onClick: () => {
|
|
1762
|
+
if (isQueryFilter && onClearFilters) {
|
|
1763
|
+
onClearFilters();
|
|
1764
|
+
} else {
|
|
1765
|
+
table.resetColumnFilters();
|
|
1766
|
+
}
|
|
1767
|
+
},
|
|
1768
|
+
children: [
|
|
1769
|
+
/* @__PURE__ */ jsxRuntime.jsx(lucideReact.RotateCcw, { className: "size-3.5", "aria-hidden": "true" }),
|
|
1770
|
+
t("Reset")
|
|
1771
|
+
]
|
|
1772
|
+
}
|
|
1773
|
+
)
|
|
1774
|
+
] })
|
|
1775
|
+
] })
|
|
1776
|
+
] });
|
|
1777
|
+
}
|
|
1778
|
+
var Card = React22__namespace.forwardRef(
|
|
1779
|
+
({ className, ...props }, ref) => /* @__PURE__ */ jsxRuntime.jsx(
|
|
1780
|
+
"div",
|
|
1781
|
+
{
|
|
1782
|
+
ref,
|
|
1783
|
+
className: cn("rounded-xl border bg-card text-card-foreground shadow-sm", className),
|
|
1784
|
+
...props
|
|
1785
|
+
}
|
|
1786
|
+
)
|
|
1787
|
+
);
|
|
1788
|
+
Card.displayName = "Card";
|
|
1789
|
+
var CardHeader = React22__namespace.forwardRef(
|
|
1790
|
+
({ className, ...props }, ref) => /* @__PURE__ */ jsxRuntime.jsx("div", { ref, className: cn("flex flex-col space-y-1.5 p-6", className), ...props })
|
|
1791
|
+
);
|
|
1792
|
+
CardHeader.displayName = "CardHeader";
|
|
1793
|
+
var CardTitle = React22__namespace.forwardRef(
|
|
1794
|
+
({ className, ...props }, ref) => /* @__PURE__ */ jsxRuntime.jsx("div", { ref, className: cn("font-semibold leading-none tracking-tight", className), ...props })
|
|
1795
|
+
);
|
|
1796
|
+
CardTitle.displayName = "CardTitle";
|
|
1797
|
+
var CardDescription = React22__namespace.forwardRef(
|
|
1798
|
+
({ className, ...props }, ref) => /* @__PURE__ */ jsxRuntime.jsx("div", { ref, className: cn("text-sm text-muted-foreground", className), ...props })
|
|
1799
|
+
);
|
|
1800
|
+
CardDescription.displayName = "CardDescription";
|
|
1801
|
+
var CardContent = React22__namespace.forwardRef(
|
|
1802
|
+
({ className, ...props }, ref) => /* @__PURE__ */ jsxRuntime.jsx("div", { ref, className: cn("p-6 pt-0", className), ...props })
|
|
1803
|
+
);
|
|
1804
|
+
CardContent.displayName = "CardContent";
|
|
1805
|
+
var CardFooter = React22__namespace.forwardRef(
|
|
1806
|
+
({ className, ...props }, ref) => /* @__PURE__ */ jsxRuntime.jsx("div", { ref, className: cn("flex items-center p-6 pt-0", className), ...props })
|
|
1807
|
+
);
|
|
1808
|
+
CardFooter.displayName = "CardFooter";
|
|
1809
|
+
function DataTableCardView({ table }) {
|
|
1810
|
+
const t = useTableTranslations();
|
|
1811
|
+
const rows = table.getRowModel().rows;
|
|
1812
|
+
if (!rows.length) {
|
|
1813
|
+
return /* @__PURE__ */ jsxRuntime.jsx(Card, { className: "mt-3", children: /* @__PURE__ */ jsxRuntime.jsx(CardContent, { className: "py-16", children: /* @__PURE__ */ jsxRuntime.jsxs("div", { className: "flex flex-col items-center gap-3", children: [
|
|
1814
|
+
/* @__PURE__ */ jsxRuntime.jsx(lucideReact.SearchX, { className: "size-10 text-muted-foreground/50", "aria-hidden": "true" }),
|
|
1815
|
+
/* @__PURE__ */ jsxRuntime.jsxs("div", { className: "space-y-1 text-center", children: [
|
|
1816
|
+
/* @__PURE__ */ jsxRuntime.jsx("p", { className: "font-semibold", children: t("no-records-found") }),
|
|
1817
|
+
/* @__PURE__ */ jsxRuntime.jsx("p", { className: "text-sm text-muted-foreground", children: t("no-records-hint") })
|
|
1818
|
+
] }),
|
|
1819
|
+
table.getState().columnFilters.length > 0 && /* @__PURE__ */ jsxRuntime.jsxs(
|
|
1820
|
+
Button,
|
|
1821
|
+
{
|
|
1822
|
+
variant: "outline",
|
|
1823
|
+
size: "sm",
|
|
1824
|
+
className: "mt-1 gap-1.5",
|
|
1825
|
+
onClick: () => table.resetColumnFilters(),
|
|
1826
|
+
children: [
|
|
1827
|
+
/* @__PURE__ */ jsxRuntime.jsx(lucideReact.RotateCcw, { className: "size-3.5", "aria-hidden": "true" }),
|
|
1828
|
+
t("reset-filters")
|
|
1829
|
+
]
|
|
1830
|
+
}
|
|
1831
|
+
)
|
|
1832
|
+
] }) }) });
|
|
1833
|
+
}
|
|
1834
|
+
return /* @__PURE__ */ jsxRuntime.jsx("div", { className: "mt-3 grid grid-cols-1 gap-3 sm:grid-cols-2 lg:grid-cols-3", children: rows.map((row) => {
|
|
1835
|
+
const visibleCells = row.getVisibleCells();
|
|
1836
|
+
return /* @__PURE__ */ jsxRuntime.jsx(
|
|
1837
|
+
Card,
|
|
1838
|
+
{
|
|
1839
|
+
"data-state": row.getIsSelected() && "selected",
|
|
1840
|
+
className: "transition-colors data-[state=selected]:border-primary/50 data-[state=selected]:bg-primary/5",
|
|
1841
|
+
children: /* @__PURE__ */ jsxRuntime.jsxs(CardContent, { className: "p-4", children: [
|
|
1842
|
+
/* @__PURE__ */ jsxRuntime.jsxs("div", { className: "mb-3 flex items-center gap-2", children: [
|
|
1843
|
+
/* @__PURE__ */ jsxRuntime.jsx(
|
|
1844
|
+
Checkbox,
|
|
1845
|
+
{
|
|
1846
|
+
checked: row.getIsSelected(),
|
|
1847
|
+
onCheckedChange: (value) => row.toggleSelected(!!value),
|
|
1848
|
+
"aria-label": t("select"),
|
|
1849
|
+
className: "size-4"
|
|
1850
|
+
}
|
|
1851
|
+
),
|
|
1852
|
+
/* @__PURE__ */ jsxRuntime.jsxs("span", { className: "text-xs text-muted-foreground", children: [
|
|
1853
|
+
"#",
|
|
1854
|
+
row.index + 1
|
|
1855
|
+
] })
|
|
1856
|
+
] }),
|
|
1857
|
+
/* @__PURE__ */ jsxRuntime.jsx("div", { className: "space-y-2", children: visibleCells.map((cell) => {
|
|
1858
|
+
if (cell.column.id === "select") return null;
|
|
1859
|
+
const header = cell.column.columnDef.header;
|
|
1860
|
+
const headerLabel = typeof header === "string" ? header : cell.column.id;
|
|
1861
|
+
return /* @__PURE__ */ jsxRuntime.jsxs("div", { className: "flex items-start justify-between gap-2", children: [
|
|
1862
|
+
/* @__PURE__ */ jsxRuntime.jsx("span", { className: "text-xs font-medium text-muted-foreground capitalize shrink-0", children: headerLabel }),
|
|
1863
|
+
/* @__PURE__ */ jsxRuntime.jsx("span", { className: "text-sm text-end", children: reactTable.flexRender(cell.column.columnDef.cell, cell.getContext()) })
|
|
1864
|
+
] }, cell.id);
|
|
1865
|
+
}) })
|
|
1866
|
+
] })
|
|
1867
|
+
},
|
|
1868
|
+
row.id
|
|
1869
|
+
);
|
|
1870
|
+
}) });
|
|
1871
|
+
}
|
|
1872
|
+
function DataTableAdvancedFilter({
|
|
1873
|
+
options,
|
|
1874
|
+
selectedOptions,
|
|
1875
|
+
setSelectedOptions,
|
|
1876
|
+
children
|
|
1877
|
+
}) {
|
|
1878
|
+
const [value, setValue] = React22__namespace.useState("");
|
|
1879
|
+
const [open, setOpen] = React22__namespace.useState(false);
|
|
1880
|
+
const [selectedOption, setSelectedOption] = React22__namespace.useState(options[0]);
|
|
1881
|
+
const t = useTableTranslations();
|
|
1882
|
+
return /* @__PURE__ */ jsxRuntime.jsxs(Popover, { open, onOpenChange: setOpen, children: [
|
|
1883
|
+
/* @__PURE__ */ jsxRuntime.jsx(PopoverTrigger, { asChild: true, children: children != null ? children : /* @__PURE__ */ jsxRuntime.jsxs(
|
|
1884
|
+
Button,
|
|
1885
|
+
{
|
|
1886
|
+
variant: "outline",
|
|
1887
|
+
size: "sm",
|
|
1888
|
+
role: "combobox",
|
|
1889
|
+
className: "h-9 gap-1.5",
|
|
1890
|
+
children: [
|
|
1891
|
+
/* @__PURE__ */ jsxRuntime.jsx(lucideReact.ListFilter, { className: "size-4" }),
|
|
1892
|
+
t("Filter"),
|
|
1893
|
+
/* @__PURE__ */ jsxRuntime.jsx(lucideReact.ChevronDown, { className: "size-3.5 opacity-50" })
|
|
1894
|
+
]
|
|
1895
|
+
}
|
|
1896
|
+
) }),
|
|
1897
|
+
/* @__PURE__ */ jsxRuntime.jsx(PopoverContent, { className: "w-[220px] p-0", align: "end", children: /* @__PURE__ */ jsxRuntime.jsxs(Command, { children: [
|
|
1898
|
+
/* @__PURE__ */ jsxRuntime.jsx(CommandInput, { placeholder: t("filter-by") }),
|
|
1899
|
+
/* @__PURE__ */ jsxRuntime.jsx(CommandEmpty, { children: t("no-items-found") }),
|
|
1900
|
+
/* @__PURE__ */ jsxRuntime.jsx(CommandGroup, { heading: t("Filter"), children: options.map((option) => {
|
|
1901
|
+
const isSelected = selectedOptions.some(
|
|
1902
|
+
(sel) => sel.value === option.value && !sel.isMulti
|
|
1903
|
+
);
|
|
1904
|
+
return /* @__PURE__ */ jsxRuntime.jsxs(
|
|
1905
|
+
CommandItem,
|
|
1906
|
+
{
|
|
1907
|
+
className: "gap-2 capitalize",
|
|
1908
|
+
value: String(option.value),
|
|
1909
|
+
onSelect: (currentValue) => {
|
|
1910
|
+
setValue(currentValue === value ? "" : currentValue);
|
|
1911
|
+
setOpen(false);
|
|
1912
|
+
setSelectedOption(option);
|
|
1913
|
+
setSelectedOptions((prev) => {
|
|
1914
|
+
if (isSelected) {
|
|
1915
|
+
return prev.filter(
|
|
1916
|
+
(item) => item.value !== option.value || item.isMulti
|
|
1917
|
+
);
|
|
1918
|
+
} else {
|
|
1919
|
+
return [...prev, option];
|
|
1920
|
+
}
|
|
1921
|
+
});
|
|
1922
|
+
},
|
|
1923
|
+
children: [
|
|
1924
|
+
option.items.length > 0 ? /* @__PURE__ */ jsxRuntime.jsx(lucideReact.Rows3, { className: "size-4 text-muted-foreground" }) : /* @__PURE__ */ jsxRuntime.jsx(lucideReact.Type, { className: "size-4 text-muted-foreground" }),
|
|
1925
|
+
/* @__PURE__ */ jsxRuntime.jsx("span", { className: "flex-1", children: option.label }),
|
|
1926
|
+
isSelected && /* @__PURE__ */ jsxRuntime.jsx(lucideReact.Check, { className: "size-4 text-primary" })
|
|
1927
|
+
]
|
|
1928
|
+
},
|
|
1929
|
+
String(option.value)
|
|
1930
|
+
);
|
|
1931
|
+
}) }),
|
|
1932
|
+
/* @__PURE__ */ jsxRuntime.jsx(CommandSeparator, {}),
|
|
1933
|
+
/* @__PURE__ */ jsxRuntime.jsx(CommandGroup, { children: /* @__PURE__ */ jsxRuntime.jsxs(
|
|
1934
|
+
CommandItem,
|
|
1935
|
+
{
|
|
1936
|
+
className: "gap-2",
|
|
1937
|
+
onSelect: () => {
|
|
1938
|
+
var _a;
|
|
1939
|
+
setOpen(false);
|
|
1940
|
+
setSelectedOptions([
|
|
1941
|
+
...selectedOptions,
|
|
1942
|
+
{
|
|
1943
|
+
id: crypto.randomUUID(),
|
|
1944
|
+
label: String(selectedOption == null ? void 0 : selectedOption.label),
|
|
1945
|
+
value: String(selectedOption == null ? void 0 : selectedOption.value),
|
|
1946
|
+
items: (_a = selectedOption == null ? void 0 : selectedOption.items) != null ? _a : [],
|
|
1947
|
+
isMulti: true
|
|
1948
|
+
}
|
|
1949
|
+
]);
|
|
1950
|
+
},
|
|
1951
|
+
children: [
|
|
1952
|
+
/* @__PURE__ */ jsxRuntime.jsx(lucideReact.Rows3, { className: "size-4 text-muted-foreground" }),
|
|
1953
|
+
t("advanced-filter")
|
|
1954
|
+
]
|
|
1955
|
+
}
|
|
1956
|
+
) })
|
|
1957
|
+
] }) })
|
|
1958
|
+
] });
|
|
1959
|
+
}
|
|
1960
|
+
function DataTableAdvancedFilterItem({
|
|
1961
|
+
table,
|
|
1962
|
+
selectedOption,
|
|
1963
|
+
setSelectedOptions
|
|
1964
|
+
}) {
|
|
1965
|
+
var _a;
|
|
1966
|
+
const config = useTableConfig();
|
|
1967
|
+
const router = config.router;
|
|
1968
|
+
const searchParams = router ? router.getSearchParams() : new URLSearchParams();
|
|
1969
|
+
const pathname = router ? router.getPathname() : "";
|
|
1970
|
+
const [value, setValue] = React22__namespace.useState("");
|
|
1971
|
+
const debounceValue = useDebounce(value, 500);
|
|
1972
|
+
const [open, setOpen] = React22__namespace.useState(true);
|
|
1973
|
+
const selectedValues = selectedOption.items.length > 0 ? Array.from(
|
|
1974
|
+
new Set(
|
|
1975
|
+
(_a = table.getColumn(String(selectedOption.value))) == null ? void 0 : _a.getFilterValue()
|
|
1976
|
+
)
|
|
1977
|
+
) : [];
|
|
1978
|
+
const filterVarieties = selectedOption.items.length > 0 ? ["is", "is not"] : ["contains", "does not contain", "is", "is not"];
|
|
1979
|
+
const [filterVariety, setFilterVariety] = React22__namespace.useState(filterVarieties[0]);
|
|
1980
|
+
const createQueryString = React22__namespace.useCallback(
|
|
1981
|
+
(params) => {
|
|
1982
|
+
const newSearchParams = new URLSearchParams(searchParams.toString());
|
|
1983
|
+
for (const [key, value2] of Object.entries(params)) {
|
|
1984
|
+
if (value2 === null) {
|
|
1985
|
+
newSearchParams.delete(key);
|
|
1986
|
+
} else {
|
|
1987
|
+
newSearchParams.set(key, String(value2));
|
|
1988
|
+
}
|
|
1989
|
+
}
|
|
1990
|
+
return newSearchParams.toString();
|
|
1991
|
+
},
|
|
1992
|
+
[searchParams]
|
|
1993
|
+
);
|
|
1994
|
+
React22__namespace.useEffect(() => {
|
|
1995
|
+
if (!router) return;
|
|
1996
|
+
if (debounceValue.length > 0) {
|
|
1997
|
+
router.push(
|
|
1998
|
+
`${pathname}?${createQueryString({
|
|
1999
|
+
[selectedOption.value]: `${debounceValue}${debounceValue.length > 0 ? `.${filterVariety}` : ""}`
|
|
2000
|
+
})}`
|
|
2001
|
+
);
|
|
2002
|
+
}
|
|
2003
|
+
if (debounceValue.length === 0) {
|
|
2004
|
+
router.push(
|
|
2005
|
+
`${pathname}?${createQueryString({
|
|
2006
|
+
[selectedOption.value]: null
|
|
2007
|
+
})}`
|
|
2008
|
+
);
|
|
2009
|
+
}
|
|
2010
|
+
}, [debounceValue, filterVariety, selectedOption.value]);
|
|
2011
|
+
const handleRemove = () => {
|
|
2012
|
+
if (router) {
|
|
2013
|
+
router.push(
|
|
2014
|
+
`${pathname}?${createQueryString({
|
|
2015
|
+
[selectedOption.value]: null
|
|
2016
|
+
})}`
|
|
2017
|
+
);
|
|
2018
|
+
}
|
|
2019
|
+
setSelectedOptions(
|
|
2020
|
+
(prev) => prev.filter((item) => item.value !== selectedOption.value)
|
|
2021
|
+
);
|
|
2022
|
+
};
|
|
2023
|
+
const hasValue = value.length > 0 || selectedValues.length > 0;
|
|
2024
|
+
return /* @__PURE__ */ jsxRuntime.jsxs(Popover, { open, onOpenChange: setOpen, children: [
|
|
2025
|
+
/* @__PURE__ */ jsxRuntime.jsx(PopoverTrigger, { asChild: true, children: /* @__PURE__ */ jsxRuntime.jsxs(
|
|
2026
|
+
Button,
|
|
2027
|
+
{
|
|
2028
|
+
variant: "outline",
|
|
2029
|
+
size: "sm",
|
|
2030
|
+
className: cn(
|
|
2031
|
+
"h-8 gap-1.5 rounded-full border-dashed",
|
|
2032
|
+
hasValue && "border-solid border-primary/30 bg-primary/5 text-primary hover:bg-primary/10"
|
|
2033
|
+
),
|
|
2034
|
+
children: [
|
|
2035
|
+
/* @__PURE__ */ jsxRuntime.jsx("span", { className: "font-medium capitalize", children: selectedOption.label }),
|
|
2036
|
+
hasValue && /* @__PURE__ */ jsxRuntime.jsxs(jsxRuntime.Fragment, { children: [
|
|
2037
|
+
/* @__PURE__ */ jsxRuntime.jsx("span", { className: "text-muted-foreground", children: filterVariety }),
|
|
2038
|
+
selectedValues.length > 0 ? /* @__PURE__ */ jsxRuntime.jsx("span", { className: "font-semibold", children: selectedValues.length > 2 ? `${selectedValues.length} selected` : selectedValues.join(", ") }) : /* @__PURE__ */ jsxRuntime.jsx("span", { className: "max-w-[100px] truncate font-semibold", children: value })
|
|
2039
|
+
] }),
|
|
2040
|
+
/* @__PURE__ */ jsxRuntime.jsx(
|
|
2041
|
+
lucideReact.X,
|
|
2042
|
+
{
|
|
2043
|
+
className: "size-3.5 shrink-0 opacity-50 hover:opacity-100",
|
|
2044
|
+
onClick: (e) => {
|
|
2045
|
+
e.stopPropagation();
|
|
2046
|
+
handleRemove();
|
|
2047
|
+
}
|
|
2048
|
+
}
|
|
2049
|
+
)
|
|
2050
|
+
]
|
|
2051
|
+
}
|
|
2052
|
+
) }),
|
|
2053
|
+
/* @__PURE__ */ jsxRuntime.jsxs(PopoverContent, { className: "w-64 space-y-2 p-3 text-xs", align: "start", children: [
|
|
2054
|
+
/* @__PURE__ */ jsxRuntime.jsxs("div", { className: "flex items-center gap-1.5", children: [
|
|
2055
|
+
/* @__PURE__ */ jsxRuntime.jsx("span", { className: "shrink-0 text-sm font-medium capitalize", children: selectedOption.label }),
|
|
2056
|
+
/* @__PURE__ */ jsxRuntime.jsxs(Select, { onValueChange: (value2) => setFilterVariety(value2), children: [
|
|
2057
|
+
/* @__PURE__ */ jsxRuntime.jsx(SelectTrigger, { className: "h-7 w-fit shrink-0 gap-1 rounded-md border-none bg-muted/50 px-2 text-xs font-medium hover:bg-muted", children: /* @__PURE__ */ jsxRuntime.jsx(SelectValue, { placeholder: filterVarieties[0] }) }),
|
|
2058
|
+
/* @__PURE__ */ jsxRuntime.jsx(SelectContent, { children: /* @__PURE__ */ jsxRuntime.jsx(SelectGroup, { children: filterVarieties.map((variety) => /* @__PURE__ */ jsxRuntime.jsx(SelectItem, { value: variety, className: "text-xs", children: variety }, variety)) }) })
|
|
2059
|
+
] }),
|
|
2060
|
+
/* @__PURE__ */ jsxRuntime.jsx("div", { className: "flex-1" }),
|
|
2061
|
+
/* @__PURE__ */ jsxRuntime.jsx(
|
|
2062
|
+
Button,
|
|
2063
|
+
{
|
|
2064
|
+
"aria-label": "Remove filter",
|
|
2065
|
+
variant: "ghost",
|
|
2066
|
+
size: "icon",
|
|
2067
|
+
className: "size-7 shrink-0 text-muted-foreground hover:text-destructive",
|
|
2068
|
+
onClick: handleRemove,
|
|
2069
|
+
children: /* @__PURE__ */ jsxRuntime.jsx(lucideReact.Trash2, { className: "size-3.5" })
|
|
2070
|
+
}
|
|
2071
|
+
)
|
|
2072
|
+
] }),
|
|
2073
|
+
selectedOption.items.length > 0 ? table.getColumn(
|
|
2074
|
+
selectedOption.value ? String(selectedOption.value) : ""
|
|
2075
|
+
) && /* @__PURE__ */ jsxRuntime.jsx(
|
|
2076
|
+
DataTableFacetedFilter,
|
|
2077
|
+
{
|
|
2078
|
+
column: table.getColumn(
|
|
2079
|
+
selectedOption.value ? String(selectedOption.value) : ""
|
|
2080
|
+
),
|
|
2081
|
+
title: selectedOption.label,
|
|
2082
|
+
options: selectedOption.items,
|
|
2083
|
+
variant: "command"
|
|
2084
|
+
},
|
|
2085
|
+
String(selectedOption.value)
|
|
2086
|
+
) : /* @__PURE__ */ jsxRuntime.jsx(
|
|
2087
|
+
Input,
|
|
2088
|
+
{
|
|
2089
|
+
placeholder: "Type here...",
|
|
2090
|
+
className: "h-8 text-xs",
|
|
2091
|
+
value,
|
|
2092
|
+
onChange: (event) => setValue(event.target.value),
|
|
2093
|
+
autoFocus: true
|
|
2094
|
+
}
|
|
2095
|
+
)
|
|
2096
|
+
] })
|
|
2097
|
+
] });
|
|
2098
|
+
}
|
|
2099
|
+
var operators = [
|
|
2100
|
+
{ label: "And", value: "and" },
|
|
2101
|
+
{ label: "Or", value: "or" }
|
|
2102
|
+
];
|
|
2103
|
+
function DataTableMultiFilter({
|
|
2104
|
+
table,
|
|
2105
|
+
allOptions,
|
|
2106
|
+
options,
|
|
2107
|
+
setSelectedOptions
|
|
2108
|
+
}) {
|
|
2109
|
+
const [open, setOpen] = React22__namespace.useState(true);
|
|
2110
|
+
const [operator, setOperator] = React22__namespace.useState(operators[0]);
|
|
2111
|
+
const t = useTableTranslations();
|
|
2112
|
+
return /* @__PURE__ */ jsxRuntime.jsxs(Popover, { open, onOpenChange: setOpen, children: [
|
|
2113
|
+
/* @__PURE__ */ jsxRuntime.jsx(PopoverTrigger, { asChild: true, children: /* @__PURE__ */ jsxRuntime.jsxs(
|
|
2114
|
+
Button,
|
|
2115
|
+
{
|
|
2116
|
+
variant: "outline",
|
|
2117
|
+
size: "sm",
|
|
2118
|
+
className: "h-8 gap-1.5 rounded-full border-dashed",
|
|
2119
|
+
children: [
|
|
2120
|
+
/* @__PURE__ */ jsxRuntime.jsx(lucideReact.GripVertical, { className: "size-3.5 text-muted-foreground" }),
|
|
2121
|
+
/* @__PURE__ */ jsxRuntime.jsxs("span", { className: "font-medium", children: [
|
|
2122
|
+
options.length,
|
|
2123
|
+
" ",
|
|
2124
|
+
options.length === 1 ? "rule" : "rules"
|
|
2125
|
+
] })
|
|
2126
|
+
]
|
|
2127
|
+
}
|
|
2128
|
+
) }),
|
|
2129
|
+
/* @__PURE__ */ jsxRuntime.jsxs(PopoverContent, { className: "w-fit min-w-[420px] p-0", align: "start", children: [
|
|
2130
|
+
/* @__PURE__ */ jsxRuntime.jsx("div", { className: "space-y-2 p-4", children: options.map((option, i) => {
|
|
2131
|
+
var _a;
|
|
2132
|
+
return /* @__PURE__ */ jsxRuntime.jsx(
|
|
2133
|
+
MultiFilterRow,
|
|
2134
|
+
{
|
|
2135
|
+
i,
|
|
2136
|
+
option,
|
|
2137
|
+
table,
|
|
2138
|
+
allOptions,
|
|
2139
|
+
options,
|
|
2140
|
+
setSelectedOptions,
|
|
2141
|
+
operator,
|
|
2142
|
+
setOperator
|
|
2143
|
+
},
|
|
2144
|
+
(_a = option.id) != null ? _a : i
|
|
2145
|
+
);
|
|
2146
|
+
}) }),
|
|
2147
|
+
/* @__PURE__ */ jsxRuntime.jsx(Separator2, {}),
|
|
2148
|
+
/* @__PURE__ */ jsxRuntime.jsx("div", { className: "p-2", children: /* @__PURE__ */ jsxRuntime.jsxs(
|
|
2149
|
+
Button,
|
|
2150
|
+
{
|
|
2151
|
+
"aria-label": "Delete filter",
|
|
2152
|
+
variant: "ghost",
|
|
2153
|
+
size: "sm",
|
|
2154
|
+
className: "w-full justify-start gap-2 text-muted-foreground hover:text-destructive",
|
|
2155
|
+
onClick: () => {
|
|
2156
|
+
setSelectedOptions((prev) => prev.filter((item) => !item.isMulti));
|
|
2157
|
+
},
|
|
2158
|
+
children: [
|
|
2159
|
+
/* @__PURE__ */ jsxRuntime.jsx(lucideReact.Trash2, { className: "size-3.5" }),
|
|
2160
|
+
t("delete")
|
|
2161
|
+
]
|
|
2162
|
+
}
|
|
2163
|
+
) })
|
|
2164
|
+
] })
|
|
2165
|
+
] });
|
|
2166
|
+
}
|
|
2167
|
+
function MultiFilterRow({
|
|
2168
|
+
i,
|
|
2169
|
+
table,
|
|
2170
|
+
option,
|
|
2171
|
+
allOptions,
|
|
2172
|
+
options,
|
|
2173
|
+
setSelectedOptions,
|
|
2174
|
+
operator,
|
|
2175
|
+
setOperator
|
|
2176
|
+
}) {
|
|
2177
|
+
const config = useTableConfig();
|
|
2178
|
+
const router = config.router;
|
|
2179
|
+
const searchParams = router ? router.getSearchParams() : new URLSearchParams();
|
|
2180
|
+
const pathname = router ? router.getPathname() : "";
|
|
2181
|
+
const [value, setValue] = React22__namespace.useState("");
|
|
2182
|
+
const debounceValue = useDebounce(value, 500);
|
|
2183
|
+
const [selectedOption, setSelectedOption] = React22__namespace.useState(options[0]);
|
|
2184
|
+
const filterVarieties = (selectedOption == null ? void 0 : selectedOption.items.length) ? ["is", "is not"] : ["contains", "does not contain", "is", "is not"];
|
|
2185
|
+
const [filterVariety, setFilterVariety] = React22__namespace.useState(filterVarieties[0]);
|
|
2186
|
+
React22__namespace.useEffect(() => {
|
|
2187
|
+
if (selectedOption == null ? void 0 : selectedOption.items.length) {
|
|
2188
|
+
setFilterVariety("is");
|
|
2189
|
+
}
|
|
2190
|
+
}, [selectedOption == null ? void 0 : selectedOption.items.length]);
|
|
2191
|
+
const createQueryString = React22__namespace.useCallback(
|
|
2192
|
+
(params) => {
|
|
2193
|
+
const newSearchParams = new URLSearchParams(searchParams.toString());
|
|
2194
|
+
for (const [key, value2] of Object.entries(params)) {
|
|
2195
|
+
if (value2 === null) {
|
|
2196
|
+
newSearchParams.delete(key);
|
|
2197
|
+
} else {
|
|
2198
|
+
newSearchParams.set(key, String(value2));
|
|
2199
|
+
}
|
|
2200
|
+
}
|
|
2201
|
+
return newSearchParams.toString();
|
|
2202
|
+
},
|
|
2203
|
+
[searchParams]
|
|
2204
|
+
);
|
|
2205
|
+
React22__namespace.useEffect(() => {
|
|
2206
|
+
var _a, _b;
|
|
2207
|
+
if (!router) return;
|
|
2208
|
+
if (debounceValue.length > 0) {
|
|
2209
|
+
router.push(
|
|
2210
|
+
`${pathname}?${createQueryString({
|
|
2211
|
+
[(_a = selectedOption == null ? void 0 : selectedOption.value) != null ? _a : ""]: `${debounceValue}${debounceValue.length > 0 ? `.${filterVariety}` : ""}`
|
|
2212
|
+
})}`
|
|
2213
|
+
);
|
|
2214
|
+
}
|
|
2215
|
+
if (debounceValue.length === 0) {
|
|
2216
|
+
router.push(
|
|
2217
|
+
`${pathname}?${createQueryString({
|
|
2218
|
+
[(_b = selectedOption == null ? void 0 : selectedOption.value) != null ? _b : ""]: null
|
|
2219
|
+
})}`
|
|
2220
|
+
);
|
|
2221
|
+
}
|
|
2222
|
+
}, [debounceValue, filterVariety, selectedOption == null ? void 0 : selectedOption.value]);
|
|
2223
|
+
React22__namespace.useEffect(() => {
|
|
2224
|
+
if (!router) return;
|
|
2225
|
+
if (operator == null ? void 0 : operator.value) {
|
|
2226
|
+
router.push(
|
|
2227
|
+
`${pathname}?${createQueryString({
|
|
2228
|
+
operator: operator.value
|
|
2229
|
+
})}`
|
|
2230
|
+
);
|
|
2231
|
+
}
|
|
2232
|
+
}, [operator == null ? void 0 : operator.value]);
|
|
2233
|
+
return /* @__PURE__ */ jsxRuntime.jsxs("div", { className: "flex items-center gap-2", children: [
|
|
2234
|
+
/* @__PURE__ */ jsxRuntime.jsx("div", { className: "w-[60px] shrink-0", children: i === 0 ? /* @__PURE__ */ jsxRuntime.jsx("span", { className: "text-xs font-medium text-muted-foreground", children: "Where" }) : i === 1 ? /* @__PURE__ */ jsxRuntime.jsxs(
|
|
2235
|
+
Select,
|
|
2236
|
+
{
|
|
2237
|
+
value: operator == null ? void 0 : operator.value,
|
|
2238
|
+
onValueChange: (value2) => {
|
|
2239
|
+
const found = operators.find((o) => o.value === value2);
|
|
2240
|
+
if (found) setOperator(found);
|
|
2241
|
+
},
|
|
2242
|
+
children: [
|
|
2243
|
+
/* @__PURE__ */ jsxRuntime.jsx(SelectTrigger, { className: "h-8 w-[60px] text-xs", children: /* @__PURE__ */ jsxRuntime.jsx(SelectValue, { placeholder: operator == null ? void 0 : operator.label }) }),
|
|
2244
|
+
/* @__PURE__ */ jsxRuntime.jsx(SelectContent, { children: /* @__PURE__ */ jsxRuntime.jsx(SelectGroup, { children: operators.map((op) => /* @__PURE__ */ jsxRuntime.jsx(
|
|
2245
|
+
SelectItem,
|
|
2246
|
+
{
|
|
2247
|
+
value: op.value,
|
|
2248
|
+
className: "text-xs",
|
|
2249
|
+
children: op.label
|
|
2250
|
+
},
|
|
2251
|
+
op.value
|
|
2252
|
+
)) }) })
|
|
2253
|
+
]
|
|
2254
|
+
}
|
|
2255
|
+
) : /* @__PURE__ */ jsxRuntime.jsx("span", { className: "text-xs font-medium text-muted-foreground", children: operator == null ? void 0 : operator.label }, operator == null ? void 0 : operator.value) }),
|
|
2256
|
+
/* @__PURE__ */ jsxRuntime.jsxs(
|
|
2257
|
+
Select,
|
|
2258
|
+
{
|
|
2259
|
+
value: String(selectedOption == null ? void 0 : selectedOption.value),
|
|
2260
|
+
onValueChange: (value2) => {
|
|
2261
|
+
setSelectedOption(allOptions.find((option2) => option2.value === value2));
|
|
2262
|
+
setSelectedOptions(
|
|
2263
|
+
(prev) => prev.map((item) => {
|
|
2264
|
+
if (item.id === option.id) {
|
|
2265
|
+
return { ...item, value: value2 };
|
|
2266
|
+
} else {
|
|
2267
|
+
return item;
|
|
2268
|
+
}
|
|
2269
|
+
})
|
|
2270
|
+
);
|
|
2271
|
+
},
|
|
2272
|
+
children: [
|
|
2273
|
+
/* @__PURE__ */ jsxRuntime.jsx(SelectTrigger, { className: "h-8 w-[120px] text-xs capitalize", children: /* @__PURE__ */ jsxRuntime.jsx(SelectValue, { placeholder: selectedOption == null ? void 0 : selectedOption.label }) }),
|
|
2274
|
+
/* @__PURE__ */ jsxRuntime.jsx(SelectContent, { children: /* @__PURE__ */ jsxRuntime.jsx(SelectGroup, { children: allOptions.map((opt) => /* @__PURE__ */ jsxRuntime.jsx(
|
|
2275
|
+
SelectItem,
|
|
2276
|
+
{
|
|
2277
|
+
value: String(opt.value),
|
|
2278
|
+
className: "text-xs capitalize",
|
|
2279
|
+
children: opt.label
|
|
2280
|
+
},
|
|
2281
|
+
String(opt.value)
|
|
2282
|
+
)) }) })
|
|
2283
|
+
]
|
|
2284
|
+
}
|
|
2285
|
+
),
|
|
2286
|
+
/* @__PURE__ */ jsxRuntime.jsxs(
|
|
2287
|
+
Select,
|
|
2288
|
+
{
|
|
2289
|
+
value: filterVariety,
|
|
2290
|
+
onValueChange: (value2) => setFilterVariety(value2),
|
|
2291
|
+
children: [
|
|
2292
|
+
/* @__PURE__ */ jsxRuntime.jsx(SelectTrigger, { className: "h-8 w-[140px] text-xs", children: /* @__PURE__ */ jsxRuntime.jsx(SelectValue, { placeholder: filterVarieties[0] }) }),
|
|
2293
|
+
/* @__PURE__ */ jsxRuntime.jsx(SelectContent, { children: /* @__PURE__ */ jsxRuntime.jsx(SelectGroup, { children: filterVarieties.map((variety) => /* @__PURE__ */ jsxRuntime.jsx(SelectItem, { value: variety, className: "text-xs", children: variety }, variety)) }) })
|
|
2294
|
+
]
|
|
2295
|
+
}
|
|
2296
|
+
),
|
|
2297
|
+
(selectedOption == null ? void 0 : selectedOption.items.length) ? table.getColumn(selectedOption.value ? String(option.value) : "") && /* @__PURE__ */ jsxRuntime.jsx(
|
|
2298
|
+
DataTableFacetedFilter,
|
|
2299
|
+
{
|
|
2300
|
+
column: table.getColumn(
|
|
2301
|
+
selectedOption.value ? String(selectedOption.value) : ""
|
|
2302
|
+
),
|
|
2303
|
+
title: selectedOption.label,
|
|
2304
|
+
options: selectedOption.items
|
|
2305
|
+
},
|
|
2306
|
+
selectedOption.id
|
|
2307
|
+
) : /* @__PURE__ */ jsxRuntime.jsx(
|
|
2308
|
+
Input,
|
|
2309
|
+
{
|
|
2310
|
+
placeholder: "Type here...",
|
|
2311
|
+
className: "h-8 min-w-[120px] text-xs",
|
|
2312
|
+
value,
|
|
2313
|
+
onChange: (event) => setValue(event.target.value),
|
|
2314
|
+
autoFocus: true
|
|
2315
|
+
}
|
|
2316
|
+
),
|
|
2317
|
+
/* @__PURE__ */ jsxRuntime.jsxs(DropdownMenu, { children: [
|
|
2318
|
+
/* @__PURE__ */ jsxRuntime.jsx(DropdownMenuTrigger, { asChild: true, children: /* @__PURE__ */ jsxRuntime.jsx(Button, { variant: "ghost", size: "icon", className: "size-8 shrink-0", children: /* @__PURE__ */ jsxRuntime.jsx(lucideReact.MoreHorizontal, { className: "size-4" }) }) }),
|
|
2319
|
+
/* @__PURE__ */ jsxRuntime.jsxs(DropdownMenuContent, { align: "end", children: [
|
|
2320
|
+
/* @__PURE__ */ jsxRuntime.jsxs(
|
|
2321
|
+
DropdownMenuItem,
|
|
2322
|
+
{
|
|
2323
|
+
className: "gap-2 text-destructive focus:text-destructive",
|
|
2324
|
+
onClick: () => {
|
|
2325
|
+
setSelectedOptions(
|
|
2326
|
+
(prev) => prev.filter((item) => item.id !== option.id)
|
|
2327
|
+
);
|
|
2328
|
+
},
|
|
2329
|
+
children: [
|
|
2330
|
+
/* @__PURE__ */ jsxRuntime.jsx(lucideReact.Trash2, { className: "size-3.5" }),
|
|
2331
|
+
"Remove"
|
|
2332
|
+
]
|
|
2333
|
+
}
|
|
2334
|
+
),
|
|
2335
|
+
/* @__PURE__ */ jsxRuntime.jsxs(
|
|
2336
|
+
DropdownMenuItem,
|
|
2337
|
+
{
|
|
2338
|
+
className: "gap-2",
|
|
2339
|
+
onClick: () => {
|
|
2340
|
+
setSelectedOptions((prev) => {
|
|
2341
|
+
var _a;
|
|
2342
|
+
return [
|
|
2343
|
+
...prev,
|
|
2344
|
+
{
|
|
2345
|
+
id: crypto.randomUUID(),
|
|
2346
|
+
label: String(selectedOption == null ? void 0 : selectedOption.label),
|
|
2347
|
+
value: String(selectedOption == null ? void 0 : selectedOption.value),
|
|
2348
|
+
isMulti: true,
|
|
2349
|
+
items: (_a = selectedOption == null ? void 0 : selectedOption.items) != null ? _a : []
|
|
2350
|
+
}
|
|
2351
|
+
];
|
|
2352
|
+
});
|
|
2353
|
+
},
|
|
2354
|
+
children: [
|
|
2355
|
+
/* @__PURE__ */ jsxRuntime.jsx(lucideReact.Copy, { className: "size-3.5" }),
|
|
2356
|
+
"Duplicate"
|
|
2357
|
+
]
|
|
2358
|
+
}
|
|
2359
|
+
)
|
|
2360
|
+
] })
|
|
2361
|
+
] })
|
|
2362
|
+
] });
|
|
2363
|
+
}
|
|
2364
|
+
function DataTableAdvancedToolbar({
|
|
2365
|
+
table,
|
|
2366
|
+
filterableColumns = [],
|
|
2367
|
+
searchableColumns = [],
|
|
2368
|
+
addItemPagePath
|
|
2369
|
+
}) {
|
|
2370
|
+
const [selectedOptions, setSelectedOptions] = React22__namespace.useState([]);
|
|
2371
|
+
const [open, setOpen] = React22__namespace.useState(false);
|
|
2372
|
+
const t = useTableTranslations();
|
|
2373
|
+
const config = useTableConfig();
|
|
2374
|
+
const router = config.router;
|
|
2375
|
+
React22__namespace.useEffect(() => {
|
|
2376
|
+
if (selectedOptions.length > 0) {
|
|
2377
|
+
setOpen(true);
|
|
2378
|
+
}
|
|
2379
|
+
}, [selectedOptions]);
|
|
2380
|
+
const options = React22__namespace.useMemo(() => {
|
|
2381
|
+
const searchableOptions = searchableColumns.map((column) => {
|
|
2382
|
+
var _a;
|
|
2383
|
+
return {
|
|
2384
|
+
id: crypto.randomUUID(),
|
|
2385
|
+
label: (_a = column.title) != null ? _a : String(column.id),
|
|
2386
|
+
value: column.id,
|
|
2387
|
+
items: []
|
|
2388
|
+
};
|
|
2389
|
+
});
|
|
2390
|
+
const filterableOptions = filterableColumns.map((column) => ({
|
|
2391
|
+
id: crypto.randomUUID(),
|
|
2392
|
+
label: column.title,
|
|
2393
|
+
value: column.id,
|
|
2394
|
+
items: column.options
|
|
2395
|
+
}));
|
|
2396
|
+
return [...searchableOptions, ...filterableOptions];
|
|
2397
|
+
}, [filterableColumns, searchableColumns]);
|
|
2398
|
+
const goAddItemPage = () => {
|
|
2399
|
+
if (addItemPagePath && router) {
|
|
2400
|
+
router.push(addItemPagePath);
|
|
2401
|
+
}
|
|
2402
|
+
};
|
|
2403
|
+
const handleClearAll = () => {
|
|
2404
|
+
var _a, _b;
|
|
2405
|
+
setSelectedOptions([]);
|
|
2406
|
+
setOpen(false);
|
|
2407
|
+
for (const col of searchableColumns) {
|
|
2408
|
+
(_a = table.getColumn(String(col.id))) == null ? void 0 : _a.setFilterValue("");
|
|
2409
|
+
}
|
|
2410
|
+
for (const col of filterableColumns) {
|
|
2411
|
+
(_b = table.getColumn(String(col.id))) == null ? void 0 : _b.setFilterValue(void 0);
|
|
2412
|
+
}
|
|
2413
|
+
};
|
|
2414
|
+
const hasActiveFilters = selectedOptions.length > 0 || searchableColumns.some(
|
|
2415
|
+
(col) => {
|
|
2416
|
+
var _a;
|
|
2417
|
+
return !!((_a = table.getColumn(String(col.id))) == null ? void 0 : _a.getFilterValue());
|
|
2418
|
+
}
|
|
2419
|
+
);
|
|
2420
|
+
return /* @__PURE__ */ jsxRuntime.jsxs("div", { className: "flex w-full flex-col gap-3", children: [
|
|
2421
|
+
/* @__PURE__ */ jsxRuntime.jsxs("div", { className: "flex items-center gap-3", children: [
|
|
2422
|
+
/* @__PURE__ */ jsxRuntime.jsx("div", { className: "flex flex-1 items-center gap-3", children: searchableColumns.length > 0 && searchableColumns.map(
|
|
2423
|
+
(column) => {
|
|
2424
|
+
var _a, _b, _c;
|
|
2425
|
+
return table.getColumn(column.id ? String(column.id) : "") && /* @__PURE__ */ jsxRuntime.jsxs("div", { className: "relative flex-1 max-w-sm", children: [
|
|
2426
|
+
/* @__PURE__ */ jsxRuntime.jsx(lucideReact.Search, { className: "absolute start-3 top-2.5 size-4 text-muted-foreground" }),
|
|
2427
|
+
/* @__PURE__ */ jsxRuntime.jsx(
|
|
2428
|
+
Input,
|
|
2429
|
+
{
|
|
2430
|
+
placeholder: `${t("Filter")} ${(_a = column.title) != null ? _a : String(column.id)}...`,
|
|
2431
|
+
value: (_c = (_b = table.getColumn(String(column.id))) == null ? void 0 : _b.getFilterValue()) != null ? _c : "",
|
|
2432
|
+
onChange: (event) => {
|
|
2433
|
+
var _a2;
|
|
2434
|
+
return (_a2 = table.getColumn(String(column.id))) == null ? void 0 : _a2.setFilterValue(event.target.value);
|
|
2435
|
+
},
|
|
2436
|
+
className: "ps-9"
|
|
2437
|
+
}
|
|
2438
|
+
)
|
|
2439
|
+
] }, String(column.id));
|
|
2440
|
+
}
|
|
2441
|
+
) }),
|
|
2442
|
+
/* @__PURE__ */ jsxRuntime.jsxs("div", { className: "flex items-center gap-2", children: [
|
|
2443
|
+
selectedOptions.length > 0 ? /* @__PURE__ */ jsxRuntime.jsxs(
|
|
2444
|
+
Button,
|
|
2445
|
+
{
|
|
2446
|
+
variant: "outline",
|
|
2447
|
+
size: "sm",
|
|
2448
|
+
className: "h-9 gap-1.5",
|
|
2449
|
+
onClick: () => setOpen((prev) => !prev),
|
|
2450
|
+
children: [
|
|
2451
|
+
/* @__PURE__ */ jsxRuntime.jsx(lucideReact.ListFilter, { className: "size-4" }),
|
|
2452
|
+
t("Filter"),
|
|
2453
|
+
/* @__PURE__ */ jsxRuntime.jsx("span", { className: "flex size-5 items-center justify-center rounded-full bg-primary text-[10px] font-bold text-primary-foreground", children: selectedOptions.length })
|
|
2454
|
+
]
|
|
2455
|
+
}
|
|
2456
|
+
) : /* @__PURE__ */ jsxRuntime.jsx(
|
|
2457
|
+
DataTableAdvancedFilter,
|
|
2458
|
+
{
|
|
2459
|
+
options: options.filter(
|
|
2460
|
+
(option) => !selectedOptions.some(
|
|
2461
|
+
(selectedOption) => selectedOption.value === option.value
|
|
2462
|
+
)
|
|
2463
|
+
),
|
|
2464
|
+
selectedOptions,
|
|
2465
|
+
setSelectedOptions
|
|
2466
|
+
}
|
|
2467
|
+
),
|
|
2468
|
+
/* @__PURE__ */ jsxRuntime.jsx(DataTableViewOptions, { table }),
|
|
2469
|
+
addItemPagePath && /* @__PURE__ */ jsxRuntime.jsxs(
|
|
2470
|
+
Button,
|
|
2471
|
+
{
|
|
2472
|
+
onClick: goAddItemPage,
|
|
2473
|
+
size: "sm",
|
|
2474
|
+
className: "h-9",
|
|
2475
|
+
children: [
|
|
2476
|
+
/* @__PURE__ */ jsxRuntime.jsx(lucideReact.Plus, { className: "size-4" }),
|
|
2477
|
+
t("add")
|
|
2478
|
+
]
|
|
2479
|
+
}
|
|
2480
|
+
)
|
|
2481
|
+
] })
|
|
2482
|
+
] }),
|
|
2483
|
+
open && /* @__PURE__ */ jsxRuntime.jsxs("div", { className: "flex flex-wrap items-center gap-2", children: [
|
|
2484
|
+
/* @__PURE__ */ jsxRuntime.jsx("span", { className: "text-sm font-medium text-muted-foreground whitespace-nowrap", children: t("filter-by") }),
|
|
2485
|
+
selectedOptions.some((option) => option.isMulti) && /* @__PURE__ */ jsxRuntime.jsx(
|
|
2486
|
+
DataTableMultiFilter,
|
|
2487
|
+
{
|
|
2488
|
+
table,
|
|
2489
|
+
allOptions: options,
|
|
2490
|
+
options: selectedOptions.filter((option) => option.isMulti),
|
|
2491
|
+
setSelectedOptions
|
|
2492
|
+
}
|
|
2493
|
+
),
|
|
2494
|
+
selectedOptions.filter((option) => !option.isMulti).map((selectedOption) => /* @__PURE__ */ jsxRuntime.jsx(
|
|
2495
|
+
DataTableAdvancedFilterItem,
|
|
2496
|
+
{
|
|
2497
|
+
table,
|
|
2498
|
+
selectedOption,
|
|
2499
|
+
setSelectedOptions
|
|
2500
|
+
},
|
|
2501
|
+
String(selectedOption.value)
|
|
2502
|
+
)),
|
|
2503
|
+
/* @__PURE__ */ jsxRuntime.jsx(
|
|
2504
|
+
DataTableAdvancedFilter,
|
|
2505
|
+
{
|
|
2506
|
+
options,
|
|
2507
|
+
selectedOptions,
|
|
2508
|
+
setSelectedOptions,
|
|
2509
|
+
children: /* @__PURE__ */ jsxRuntime.jsxs(
|
|
2510
|
+
Button,
|
|
2511
|
+
{
|
|
2512
|
+
variant: "outline",
|
|
2513
|
+
size: "sm",
|
|
2514
|
+
role: "combobox",
|
|
2515
|
+
className: "h-8 gap-1.5 rounded-full border-dashed text-muted-foreground hover:text-foreground",
|
|
2516
|
+
children: [
|
|
2517
|
+
/* @__PURE__ */ jsxRuntime.jsx(lucideReact.Plus, { className: "size-3.5" }),
|
|
2518
|
+
t("add-filter")
|
|
2519
|
+
]
|
|
2520
|
+
}
|
|
2521
|
+
)
|
|
2522
|
+
}
|
|
2523
|
+
),
|
|
2524
|
+
hasActiveFilters && /* @__PURE__ */ jsxRuntime.jsxs(
|
|
2525
|
+
Button,
|
|
2526
|
+
{
|
|
2527
|
+
variant: "ghost",
|
|
2528
|
+
size: "sm",
|
|
2529
|
+
className: "h-8 gap-1.5 text-muted-foreground hover:text-foreground",
|
|
2530
|
+
onClick: handleClearAll,
|
|
2531
|
+
children: [
|
|
2532
|
+
/* @__PURE__ */ jsxRuntime.jsx(lucideReact.RotateCcw, { className: "size-3.5" }),
|
|
2533
|
+
t("Reset")
|
|
2534
|
+
]
|
|
2535
|
+
}
|
|
2536
|
+
)
|
|
2537
|
+
] })
|
|
2538
|
+
] });
|
|
2539
|
+
}
|
|
2540
|
+
var Drawer = ({ shouldScaleBackground = true, ...props }) => /* @__PURE__ */ jsxRuntime.jsx(vaul.Drawer.Root, { shouldScaleBackground, ...props });
|
|
2541
|
+
Drawer.displayName = "Drawer";
|
|
2542
|
+
var DrawerTrigger = vaul.Drawer.Trigger;
|
|
2543
|
+
var DrawerPortal = vaul.Drawer.Portal;
|
|
2544
|
+
var DrawerClose = vaul.Drawer.Close;
|
|
2545
|
+
var DrawerOverlay = React22__namespace.forwardRef(({ className, ...props }, ref) => /* @__PURE__ */ jsxRuntime.jsx(
|
|
2546
|
+
vaul.Drawer.Overlay,
|
|
2547
|
+
{
|
|
2548
|
+
ref,
|
|
2549
|
+
className: cn("fixed inset-0 z-50 bg-black/80", className),
|
|
2550
|
+
...props
|
|
2551
|
+
}
|
|
2552
|
+
));
|
|
2553
|
+
DrawerOverlay.displayName = vaul.Drawer.Overlay.displayName;
|
|
2554
|
+
var DrawerContent = React22__namespace.forwardRef(({ className, children, ...props }, ref) => /* @__PURE__ */ jsxRuntime.jsxs(DrawerPortal, { children: [
|
|
2555
|
+
/* @__PURE__ */ jsxRuntime.jsx(DrawerOverlay, {}),
|
|
2556
|
+
/* @__PURE__ */ jsxRuntime.jsxs(
|
|
2557
|
+
vaul.Drawer.Content,
|
|
2558
|
+
{
|
|
2559
|
+
ref,
|
|
2560
|
+
className: cn(
|
|
2561
|
+
"fixed inset-x-0 bottom-0 z-50 mt-24 flex h-auto flex-col rounded-t-[10px] border bg-background",
|
|
2562
|
+
className
|
|
2563
|
+
),
|
|
2564
|
+
...props,
|
|
2565
|
+
children: [
|
|
2566
|
+
/* @__PURE__ */ jsxRuntime.jsx("div", { className: "mx-auto mt-4 h-2 w-[100px] rounded-full bg-muted" }),
|
|
2567
|
+
children
|
|
2568
|
+
]
|
|
2569
|
+
}
|
|
2570
|
+
)
|
|
2571
|
+
] }));
|
|
2572
|
+
DrawerContent.displayName = "DrawerContent";
|
|
2573
|
+
var DrawerHeader = ({ className, ...props }) => /* @__PURE__ */ jsxRuntime.jsx("div", { className: cn("grid gap-1.5 p-4 text-center sm:text-start", className), ...props });
|
|
2574
|
+
DrawerHeader.displayName = "DrawerHeader";
|
|
2575
|
+
var DrawerFooter = ({ className, ...props }) => /* @__PURE__ */ jsxRuntime.jsx("div", { className: cn("mt-auto flex flex-col gap-2 p-4", className), ...props });
|
|
2576
|
+
DrawerFooter.displayName = "DrawerFooter";
|
|
2577
|
+
var DrawerTitle = React22__namespace.forwardRef(({ className, ...props }, ref) => /* @__PURE__ */ jsxRuntime.jsx(
|
|
2578
|
+
vaul.Drawer.Title,
|
|
2579
|
+
{
|
|
2580
|
+
ref,
|
|
2581
|
+
className: cn("text-lg font-semibold leading-none tracking-tight", className),
|
|
2582
|
+
...props
|
|
2583
|
+
}
|
|
2584
|
+
));
|
|
2585
|
+
DrawerTitle.displayName = vaul.Drawer.Title.displayName;
|
|
2586
|
+
var DrawerDescription = React22__namespace.forwardRef(({ className, ...props }, ref) => /* @__PURE__ */ jsxRuntime.jsx(
|
|
2587
|
+
vaul.Drawer.Description,
|
|
2588
|
+
{
|
|
2589
|
+
ref,
|
|
2590
|
+
className: cn("text-sm text-muted-foreground", className),
|
|
2591
|
+
...props
|
|
2592
|
+
}
|
|
2593
|
+
));
|
|
2594
|
+
DrawerDescription.displayName = vaul.Drawer.Description.displayName;
|
|
2595
|
+
function DataTableMobileToolbar({
|
|
2596
|
+
table,
|
|
2597
|
+
filterableColumns = [],
|
|
2598
|
+
searchableColumns = [],
|
|
2599
|
+
addItemPagePath,
|
|
2600
|
+
isShowExportButtons = {
|
|
2601
|
+
isShow: true,
|
|
2602
|
+
ignoredCols: [],
|
|
2603
|
+
fileName: ""
|
|
2604
|
+
},
|
|
2605
|
+
customButtons
|
|
2606
|
+
}) {
|
|
2607
|
+
const isFiltered = table.getState().columnFilters.length > 0;
|
|
2608
|
+
const [isGoPath, setGoPath] = React22__namespace.useState(false);
|
|
2609
|
+
const t = useTableTranslations();
|
|
2610
|
+
const config = useTableConfig();
|
|
2611
|
+
const router = config.router;
|
|
2612
|
+
const [date, setDate] = React22__namespace.useState();
|
|
2613
|
+
const isArabic = config.i18n.direction === "rtl" || config.i18n.direction === "auto" && config.i18n.locale === "ar";
|
|
2614
|
+
const goAddItemPage = () => {
|
|
2615
|
+
setGoPath(true);
|
|
2616
|
+
if (addItemPagePath && router) {
|
|
2617
|
+
router.push(addItemPagePath.url);
|
|
2618
|
+
}
|
|
2619
|
+
};
|
|
2620
|
+
const handleExportSelectedRowsCSV = () => {
|
|
2621
|
+
exportSelectedRowsCsv(table, {
|
|
2622
|
+
fileName: isShowExportButtons.fileName,
|
|
2623
|
+
ignoredCols: isShowExportButtons.ignoredCols
|
|
2624
|
+
});
|
|
2625
|
+
};
|
|
2626
|
+
return /* @__PURE__ */ jsxRuntime.jsxs(Drawer, { children: [
|
|
2627
|
+
/* @__PURE__ */ jsxRuntime.jsx(DrawerTrigger, { asChild: true, children: /* @__PURE__ */ jsxRuntime.jsxs(Button, { variant: "outline", size: "sm", className: "h-8 px-2", children: [
|
|
2628
|
+
isFiltered ? /* @__PURE__ */ jsxRuntime.jsx("span", { className: "bg-main me-2 inline-flex size-3 rounded-full" }) : /* @__PURE__ */ jsxRuntime.jsx(lucideReact.Filter, { className: "me-2 size-4", "aria-hidden": "true" }),
|
|
2629
|
+
t("Filter")
|
|
2630
|
+
] }) }),
|
|
2631
|
+
isShowExportButtons.isShow && /* @__PURE__ */ jsxRuntime.jsxs(
|
|
2632
|
+
Button,
|
|
2633
|
+
{
|
|
2634
|
+
disabled: !table.getSelectedRowModel().rows.length,
|
|
2635
|
+
"aria-label": t("export-csv"),
|
|
2636
|
+
title: t("export-csv"),
|
|
2637
|
+
variant: "outline",
|
|
2638
|
+
className: "h-8 px-2 text-sm",
|
|
2639
|
+
onClick: handleExportSelectedRowsCSV,
|
|
2640
|
+
children: [
|
|
2641
|
+
/* @__PURE__ */ jsxRuntime.jsx(lucideReact.Sheet, { className: "me-2 size-4", "aria-hidden": "true" }),
|
|
2642
|
+
t("export-csv")
|
|
2643
|
+
]
|
|
2644
|
+
}
|
|
2645
|
+
),
|
|
2646
|
+
addItemPagePath ? (addItemPagePath == null ? void 0 : addItemPagePath.url) ? /* @__PURE__ */ jsxRuntime.jsxs(
|
|
2647
|
+
Button,
|
|
2648
|
+
{
|
|
2649
|
+
onClick: goAddItemPage,
|
|
2650
|
+
size: "sm",
|
|
2651
|
+
className: "flex h-8 flex-row gap-3 px-2 text-sm",
|
|
2652
|
+
disabled: isGoPath,
|
|
2653
|
+
children: [
|
|
2654
|
+
isGoPath ? /* @__PURE__ */ jsxRuntime.jsx(lucideReact.Loader2, { size: 20, className: "animate-spin" }) : /* @__PURE__ */ jsxRuntime.jsx(lucideReact.Plus, { size: 20 }),
|
|
2655
|
+
addItemPagePath.text ? addItemPagePath.text : t("add")
|
|
2656
|
+
]
|
|
2657
|
+
}
|
|
2658
|
+
) : null : null,
|
|
2659
|
+
/* @__PURE__ */ jsxRuntime.jsx(DrawerContent, { children: /* @__PURE__ */ jsxRuntime.jsxs("div", { className: "mx-auto size-full max-w-sm text-sm", children: [
|
|
2660
|
+
/* @__PURE__ */ jsxRuntime.jsxs(DrawerHeader, { children: [
|
|
2661
|
+
/* @__PURE__ */ jsxRuntime.jsx(DrawerTitle, { children: t("Filter") }),
|
|
2662
|
+
/* @__PURE__ */ jsxRuntime.jsx(DrawerDescription, { children: t("data-table-filter") })
|
|
2663
|
+
] }),
|
|
2664
|
+
/* @__PURE__ */ jsxRuntime.jsx("div", { className: "p-4 pb-0 text-sm", children: /* @__PURE__ */ jsxRuntime.jsx("div", { className: "mt-3", children: /* @__PURE__ */ jsxRuntime.jsxs("div", { className: "flex w-full flex-col gap-4", children: [
|
|
2665
|
+
/* @__PURE__ */ jsxRuntime.jsxs("div", { className: "flex flex-col items-end gap-2", children: [
|
|
2666
|
+
searchableColumns.length > 0 && searchableColumns.map(
|
|
2667
|
+
(column) => {
|
|
2668
|
+
var _a, _b, _c, _d, _e;
|
|
2669
|
+
return table.getColumn(column.id ? String(column.id) : "") && /* @__PURE__ */ jsxRuntime.jsx("div", { className: "w-full space-y-2", children: (column == null ? void 0 : column.type) === "checkbox" ? /* @__PURE__ */ jsxRuntime.jsxs("div", { className: "mb-2 flex justify-between gap-2", children: [
|
|
2670
|
+
/* @__PURE__ */ jsxRuntime.jsx(Label, { className: "cursor-pointer", htmlFor: String(column.id), children: column.title }),
|
|
2671
|
+
/* @__PURE__ */ jsxRuntime.jsx(
|
|
2672
|
+
Checkbox,
|
|
2673
|
+
{
|
|
2674
|
+
id: String(column.id),
|
|
2675
|
+
checked: ((_a = table.getColumn(String(column.id))) == null ? void 0 : _a.getFilterValue()) === "true",
|
|
2676
|
+
onCheckedChange: (value) => {
|
|
2677
|
+
var _a2;
|
|
2678
|
+
return (_a2 = table.getColumn(String(column.id))) == null ? void 0 : _a2.setFilterValue(value ? "true" : "false");
|
|
2679
|
+
},
|
|
2680
|
+
"aria-label": `Filter ${column.title}`,
|
|
2681
|
+
className: "size-4"
|
|
2682
|
+
}
|
|
2683
|
+
)
|
|
2684
|
+
] }) : (column == null ? void 0 : column.type) === "date" ? /* @__PURE__ */ jsxRuntime.jsxs("div", { className: "flex flex-col items-start gap-2", children: [
|
|
2685
|
+
/* @__PURE__ */ jsxRuntime.jsx(Label, { htmlFor: String(column.id), children: column.title }),
|
|
2686
|
+
/* @__PURE__ */ jsxRuntime.jsxs(Popover, { children: [
|
|
2687
|
+
/* @__PURE__ */ jsxRuntime.jsx(PopoverTrigger, { asChild: true, children: /* @__PURE__ */ jsxRuntime.jsxs(
|
|
2688
|
+
Button,
|
|
2689
|
+
{
|
|
2690
|
+
variant: "outline",
|
|
2691
|
+
className: cn(
|
|
2692
|
+
"w-full justify-start text-start font-normal",
|
|
2693
|
+
!date && "text-muted-foreground"
|
|
2694
|
+
),
|
|
2695
|
+
children: [
|
|
2696
|
+
/* @__PURE__ */ jsxRuntime.jsx(lucideReact.CalendarIcon, { className: "mx-2 size-4" }),
|
|
2697
|
+
date ? (() => {
|
|
2698
|
+
var _a2;
|
|
2699
|
+
const filterValue = (_a2 = table.getColumn(String(column.id))) == null ? void 0 : _a2.getFilterValue();
|
|
2700
|
+
const parsedDate = filterValue && !isNaN(new Date(filterValue).getTime()) ? new Date(filterValue) : null;
|
|
2701
|
+
return parsedDate ? dateFns.format(parsedDate, "PPP", {
|
|
2702
|
+
locale: isArabic ? locale.ar : locale.enUS
|
|
2703
|
+
}) : `${t("Filter")} ${column.title}...`;
|
|
2704
|
+
})() : `${t("Filter")} ${column.title}...`
|
|
2705
|
+
]
|
|
2706
|
+
}
|
|
2707
|
+
) }),
|
|
2708
|
+
/* @__PURE__ */ jsxRuntime.jsx(PopoverContent, { className: "w-auto p-0", children: /* @__PURE__ */ jsxRuntime.jsx(
|
|
2709
|
+
Calendar,
|
|
2710
|
+
{
|
|
2711
|
+
className: "py-2 text-sm",
|
|
2712
|
+
mode: "single",
|
|
2713
|
+
selected: ((_b = table.getColumn(String(column.id))) == null ? void 0 : _b.getFilterValue()) ? new Date(
|
|
2714
|
+
(_c = table.getColumn(String(column.id))) == null ? void 0 : _c.getFilterValue()
|
|
2715
|
+
) : void 0,
|
|
2716
|
+
onSelect: (selectedDate) => {
|
|
2717
|
+
var _a2;
|
|
2718
|
+
if (selectedDate && !isNaN(selectedDate.getTime())) {
|
|
2719
|
+
(_a2 = table.getColumn(String(column.id))) == null ? void 0 : _a2.setFilterValue(dateFns.format(selectedDate, "yyyy-MM-dd"));
|
|
2720
|
+
setDate(selectedDate);
|
|
2721
|
+
}
|
|
2722
|
+
},
|
|
2723
|
+
initialFocus: true
|
|
2724
|
+
}
|
|
2725
|
+
) })
|
|
2726
|
+
] })
|
|
2727
|
+
] }) : /* @__PURE__ */ jsxRuntime.jsxs(jsxRuntime.Fragment, { children: [
|
|
2728
|
+
/* @__PURE__ */ jsxRuntime.jsx(Label, { htmlFor: String(column.id), children: column.title }),
|
|
2729
|
+
/* @__PURE__ */ jsxRuntime.jsx(
|
|
2730
|
+
Input,
|
|
2731
|
+
{
|
|
2732
|
+
id: String(column.id),
|
|
2733
|
+
type: (column == null ? void 0 : column.type) || "text",
|
|
2734
|
+
placeholder: `${t("Filter")} ${column.title}...`,
|
|
2735
|
+
value: (_e = (_d = table.getColumn(String(column.id))) == null ? void 0 : _d.getFilterValue()) != null ? _e : "",
|
|
2736
|
+
onChange: (event) => {
|
|
2737
|
+
var _a2;
|
|
2738
|
+
return (_a2 = table.getColumn(String(column.id))) == null ? void 0 : _a2.setFilterValue(event.target.value);
|
|
2739
|
+
},
|
|
2740
|
+
className: "h-8 w-full py-0"
|
|
2741
|
+
},
|
|
2742
|
+
String(column.id)
|
|
2743
|
+
)
|
|
2744
|
+
] }) }, String(column.id));
|
|
2745
|
+
}
|
|
2746
|
+
),
|
|
2747
|
+
/* @__PURE__ */ jsxRuntime.jsx(Separator2, { className: "bg-main-300 my-2 h-px w-full" }),
|
|
2748
|
+
/* @__PURE__ */ jsxRuntime.jsx("div", { className: "flex w-full flex-col gap-4", children: filterableColumns.length > 0 && filterableColumns.map(
|
|
2749
|
+
(column) => table.getColumn(column.id ? String(column.id) : "") && /* @__PURE__ */ jsxRuntime.jsx(
|
|
2750
|
+
DataTableFacetedFilter,
|
|
2751
|
+
{
|
|
2752
|
+
className: "justify-start",
|
|
2753
|
+
column: table.getColumn(column.id ? String(column.id) : ""),
|
|
2754
|
+
title: column.title,
|
|
2755
|
+
options: column.options
|
|
2756
|
+
},
|
|
2757
|
+
String(column.id)
|
|
2758
|
+
)
|
|
2759
|
+
) }),
|
|
2760
|
+
/* @__PURE__ */ jsxRuntime.jsx(Separator2, { className: "bg-main-300 my-2 h-px w-full" })
|
|
2761
|
+
] }),
|
|
2762
|
+
/* @__PURE__ */ jsxRuntime.jsxs("div", { className: "grid gap-4", children: [
|
|
2763
|
+
/* @__PURE__ */ jsxRuntime.jsx(DataTableViewOptions, { table }),
|
|
2764
|
+
customButtons && Array.isArray(customButtons) ? customButtons.filter((customButton) => Object.keys(customButton).length !== 0).map((customButton, index) => /* @__PURE__ */ jsxRuntime.jsxs(
|
|
2765
|
+
Button,
|
|
2766
|
+
{
|
|
2767
|
+
onClick: customButton.function,
|
|
2768
|
+
variant: "outline",
|
|
2769
|
+
className: `${customButton.className ? customButton.className : ""} relative flex justify-center gap-2 text-nowrap text-sm`,
|
|
2770
|
+
...customButton.attr,
|
|
2771
|
+
children: [
|
|
2772
|
+
customButton.toolTip && /* @__PURE__ */ jsxRuntime.jsx(ButtonTooltip, { content: customButton.toolTip }),
|
|
2773
|
+
customButton.text,
|
|
2774
|
+
customButton.icon,
|
|
2775
|
+
customButton.children
|
|
2776
|
+
]
|
|
2777
|
+
},
|
|
2778
|
+
index
|
|
2779
|
+
)) : React22__namespace.isValidElement(customButtons) ? customButtons : null
|
|
2780
|
+
] })
|
|
2781
|
+
] }) }) }),
|
|
2782
|
+
/* @__PURE__ */ jsxRuntime.jsxs(DrawerFooter, { className: "grid grid-cols-2", children: [
|
|
2783
|
+
/* @__PURE__ */ jsxRuntime.jsx(Separator2, { className: "bg-main-300 col-span-2 my-2 h-px" }),
|
|
2784
|
+
/* @__PURE__ */ jsxRuntime.jsx(DrawerClose, { asChild: true, children: /* @__PURE__ */ jsxRuntime.jsx(Button, { disabled: !isFiltered, children: t("Apply") }) }),
|
|
2785
|
+
/* @__PURE__ */ jsxRuntime.jsxs(
|
|
2786
|
+
Button,
|
|
2787
|
+
{
|
|
2788
|
+
"aria-label": "Reset filters",
|
|
2789
|
+
variant: "outline",
|
|
2790
|
+
disabled: !isFiltered,
|
|
2791
|
+
onClick: () => table.resetColumnFilters(),
|
|
2792
|
+
children: [
|
|
2793
|
+
t("Reset"),
|
|
2794
|
+
/* @__PURE__ */ jsxRuntime.jsx(lucideReact.X, { className: "ms-2 size-4", "aria-hidden": "true" })
|
|
2795
|
+
]
|
|
2796
|
+
}
|
|
2797
|
+
)
|
|
2798
|
+
] })
|
|
2799
|
+
] }) })
|
|
2800
|
+
] });
|
|
2801
|
+
}
|
|
2802
|
+
var EMPTY_DATA = [];
|
|
2803
|
+
function DataTable({
|
|
2804
|
+
columns,
|
|
2805
|
+
data,
|
|
2806
|
+
pageCount,
|
|
2807
|
+
pageSize: defaultPageSize,
|
|
2808
|
+
filterableColumns = [],
|
|
2809
|
+
searchableColumns = [],
|
|
2810
|
+
showFilter,
|
|
2811
|
+
showPagination,
|
|
2812
|
+
floatingBar,
|
|
2813
|
+
deleteRowsAction,
|
|
2814
|
+
addItemPagePath,
|
|
2815
|
+
isShowExportButtons = {
|
|
2816
|
+
isShow: true,
|
|
2817
|
+
ignoredCols: [],
|
|
2818
|
+
fileName: ""
|
|
2819
|
+
},
|
|
2820
|
+
customButtons,
|
|
2821
|
+
isQueryPagination = false,
|
|
2822
|
+
paginationData,
|
|
2823
|
+
isQuerySearch = false,
|
|
2824
|
+
searchableQuery = [],
|
|
2825
|
+
isLoading,
|
|
2826
|
+
isQueryFilter = false,
|
|
2827
|
+
handleFilterChange,
|
|
2828
|
+
filterableQuery,
|
|
2829
|
+
currentFilters,
|
|
2830
|
+
onClearFilters,
|
|
2831
|
+
customCss,
|
|
2832
|
+
isShowAdvancedFilter,
|
|
2833
|
+
config: instanceConfig
|
|
2834
|
+
}) {
|
|
2835
|
+
var _a, _b, _c, _d, _e, _f;
|
|
2836
|
+
const t = useTableTranslations();
|
|
2837
|
+
const resolvedConfig = useResolvedTableConfig(instanceConfig);
|
|
2838
|
+
const router = resolvedConfig.router;
|
|
2839
|
+
const shouldShowFilter = showFilter != null ? showFilter : resolvedConfig.features.filter;
|
|
2840
|
+
const shouldShowPagination = showPagination != null ? showPagination : resolvedConfig.features.pagination;
|
|
2841
|
+
floatingBar != null ? floatingBar : resolvedConfig.features.floatingBar;
|
|
2842
|
+
const shouldShowAdvancedFilter = isShowAdvancedFilter != null ? isShowAdvancedFilter : resolvedConfig.features.advancedFilter;
|
|
2843
|
+
const resolvedPageSize = defaultPageSize != null ? defaultPageSize : resolvedConfig.pagination.defaultPageSize;
|
|
2844
|
+
const isManualFiltering = isQuerySearch || isQueryFilter;
|
|
2845
|
+
const isManualPagination = isQueryPagination;
|
|
2846
|
+
const isManualSorting = isQueryPagination || isQuerySearch || isQueryFilter;
|
|
2847
|
+
const searchParams = router ? router.getSearchParams() : new URLSearchParams();
|
|
2848
|
+
const pathname = router ? router.getPathname() : "";
|
|
2849
|
+
const page = (_a = searchParams.get("page")) != null ? _a : "1";
|
|
2850
|
+
const pageAsNumber = Number(page);
|
|
2851
|
+
const fallbackPage = isNaN(pageAsNumber) || pageAsNumber < 1 ? 1 : pageAsNumber;
|
|
2852
|
+
const per_page = (_b = searchParams.get("per_page")) != null ? _b : "10";
|
|
2853
|
+
const perPageAsNumber = Number(per_page);
|
|
2854
|
+
const fallbackPerPage = isNaN(perPageAsNumber) ? resolvedPageSize : perPageAsNumber;
|
|
2855
|
+
const sort = searchParams.get("sort");
|
|
2856
|
+
const [column, order] = (_c = sort == null ? void 0 : sort.split(".")) != null ? _c : [];
|
|
2857
|
+
const createQueryString = React22__namespace.useCallback(
|
|
2858
|
+
(params) => {
|
|
2859
|
+
const newSearchParams = new URLSearchParams(searchParams.toString());
|
|
2860
|
+
for (const [key, value] of Object.entries(params)) {
|
|
2861
|
+
if (value === null) {
|
|
2862
|
+
newSearchParams.delete(key);
|
|
2863
|
+
} else {
|
|
2864
|
+
newSearchParams.set(key, String(value));
|
|
2865
|
+
}
|
|
2866
|
+
}
|
|
2867
|
+
return newSearchParams.toString();
|
|
2868
|
+
},
|
|
2869
|
+
[searchParams]
|
|
2870
|
+
);
|
|
2871
|
+
const [viewMode, setViewMode] = React22__namespace.useState("table");
|
|
2872
|
+
const [rowSelection, setRowSelection] = React22__namespace.useState({});
|
|
2873
|
+
const [columnVisibility, setColumnVisibility] = React22__namespace.useState({});
|
|
2874
|
+
const initializeColumnFilters = React22__namespace.useCallback(() => {
|
|
2875
|
+
const filters = [];
|
|
2876
|
+
if (!isQuerySearch && searchableColumns.length > 0) {
|
|
2877
|
+
for (const col of searchableColumns) {
|
|
2878
|
+
const urlValue = searchParams.get(String(col.id));
|
|
2879
|
+
if (urlValue) {
|
|
2880
|
+
filters.push({ id: String(col.id), value: urlValue });
|
|
2881
|
+
}
|
|
2882
|
+
}
|
|
2883
|
+
}
|
|
2884
|
+
if (!isQueryFilter && filterableColumns.length > 0) {
|
|
2885
|
+
for (const col of filterableColumns) {
|
|
2886
|
+
const urlValue = searchParams.get(String(col.id));
|
|
2887
|
+
if (urlValue) {
|
|
2888
|
+
filters.push({ id: String(col.id), value: urlValue.split(".") });
|
|
2889
|
+
}
|
|
2890
|
+
}
|
|
2891
|
+
}
|
|
2892
|
+
return filters;
|
|
2893
|
+
}, [searchParams, searchableColumns, filterableColumns, isQuerySearch, isQueryFilter]);
|
|
2894
|
+
const [columnFilters, setColumnFilters] = React22__namespace.useState(initializeColumnFilters);
|
|
2895
|
+
React22__namespace.useEffect(() => {
|
|
2896
|
+
const urlFilters = initializeColumnFilters();
|
|
2897
|
+
setColumnFilters((prevFilters) => {
|
|
2898
|
+
const urlFilterString = JSON.stringify(urlFilters);
|
|
2899
|
+
const prevFilterString = JSON.stringify(prevFilters);
|
|
2900
|
+
if (urlFilterString !== prevFilterString) {
|
|
2901
|
+
return urlFilters;
|
|
2902
|
+
}
|
|
2903
|
+
return prevFilters;
|
|
2904
|
+
});
|
|
2905
|
+
}, [initializeColumnFilters]);
|
|
2906
|
+
const [{ pageIndex, pageSize }, setPagination] = React22__namespace.useState({
|
|
2907
|
+
pageIndex: fallbackPage - 1,
|
|
2908
|
+
pageSize: fallbackPerPage
|
|
2909
|
+
});
|
|
2910
|
+
const pagination = React22__namespace.useMemo(
|
|
2911
|
+
() => ({ pageIndex, pageSize }),
|
|
2912
|
+
[pageIndex, pageSize]
|
|
2913
|
+
);
|
|
2914
|
+
React22__namespace.useEffect(() => {
|
|
2915
|
+
setPagination({
|
|
2916
|
+
pageIndex: fallbackPage - 1,
|
|
2917
|
+
pageSize: fallbackPerPage
|
|
2918
|
+
});
|
|
2919
|
+
}, [fallbackPage, fallbackPerPage]);
|
|
2920
|
+
const paginationMountRef = React22__namespace.useRef(true);
|
|
2921
|
+
React22__namespace.useEffect(() => {
|
|
2922
|
+
if (isQueryPagination || !router) return;
|
|
2923
|
+
if (paginationMountRef.current) {
|
|
2924
|
+
paginationMountRef.current = false;
|
|
2925
|
+
return;
|
|
2926
|
+
}
|
|
2927
|
+
const replaceUrl = router.replace || router.push;
|
|
2928
|
+
replaceUrl(`${pathname}?${createQueryString({ page: pageIndex + 1, per_page: pageSize })}`);
|
|
2929
|
+
}, [pageIndex, pageSize, isQueryPagination]);
|
|
2930
|
+
const [sorting, setSorting] = React22__namespace.useState(
|
|
2931
|
+
column ? [{ id: column, desc: order === "desc" }] : []
|
|
2932
|
+
);
|
|
2933
|
+
const sortingMountRef = React22__namespace.useRef(true);
|
|
2934
|
+
React22__namespace.useEffect(() => {
|
|
2935
|
+
var _a2, _b2, _c2;
|
|
2936
|
+
if (!router) return;
|
|
2937
|
+
if (sortingMountRef.current) {
|
|
2938
|
+
sortingMountRef.current = false;
|
|
2939
|
+
return;
|
|
2940
|
+
}
|
|
2941
|
+
const replaceUrl = router.replace || router.push;
|
|
2942
|
+
replaceUrl(
|
|
2943
|
+
`${pathname}?${createQueryString({
|
|
2944
|
+
page,
|
|
2945
|
+
sort: ((_a2 = sorting[0]) == null ? void 0 : _a2.id) ? `${(_b2 = sorting[0]) == null ? void 0 : _b2.id}.${((_c2 = sorting[0]) == null ? void 0 : _c2.desc) ? "desc" : "asc"}` : null
|
|
2946
|
+
})}`
|
|
2947
|
+
);
|
|
2948
|
+
}, [sorting]);
|
|
2949
|
+
const searchableColumnFilters = React22__namespace.useMemo(
|
|
2950
|
+
() => columnFilters.filter((filter) => searchableColumns.find((col) => col.id === filter.id)),
|
|
2951
|
+
[columnFilters, searchableColumns]
|
|
2952
|
+
);
|
|
2953
|
+
const debouncedSearchableColumnFilters = useDebounce(searchableColumnFilters, resolvedConfig.search.debounceMs);
|
|
2954
|
+
const filterableColumnFilters = React22__namespace.useMemo(
|
|
2955
|
+
() => columnFilters.filter((filter) => filterableColumns.find((col) => col.id === filter.id)),
|
|
2956
|
+
[columnFilters, filterableColumns]
|
|
2957
|
+
);
|
|
2958
|
+
const debouncedSearchableString = JSON.stringify(debouncedSearchableColumnFilters);
|
|
2959
|
+
const filterableString = JSON.stringify(filterableColumnFilters);
|
|
2960
|
+
React22__namespace.useEffect(() => {
|
|
2961
|
+
if (isQuerySearch || !router) return;
|
|
2962
|
+
const currentDebouncedFilters = JSON.parse(debouncedSearchableString);
|
|
2963
|
+
const updates = {};
|
|
2964
|
+
let hasChanges = false;
|
|
2965
|
+
for (const col of currentDebouncedFilters) {
|
|
2966
|
+
if (typeof col.value === "string" && col.value.trim()) {
|
|
2967
|
+
const newValue = col.value.trim();
|
|
2968
|
+
updates[col.id] = newValue;
|
|
2969
|
+
if (searchParams.get(String(col.id)) !== newValue) {
|
|
2970
|
+
hasChanges = true;
|
|
2971
|
+
}
|
|
2972
|
+
}
|
|
2973
|
+
}
|
|
2974
|
+
for (const key of Array.from(searchParams.keys())) {
|
|
2975
|
+
if (searchableColumns.find((col) => String(col.id) === key) && !currentDebouncedFilters.find((col) => col.id === key)) {
|
|
2976
|
+
updates[key] = null;
|
|
2977
|
+
hasChanges = true;
|
|
2978
|
+
}
|
|
2979
|
+
}
|
|
2980
|
+
if (hasChanges) {
|
|
2981
|
+
updates.page = 1;
|
|
2982
|
+
}
|
|
2983
|
+
const newQueryString = createQueryString(updates);
|
|
2984
|
+
const currentQueryString = searchParams.toString() || "";
|
|
2985
|
+
if (newQueryString !== currentQueryString && hasChanges) {
|
|
2986
|
+
const replaceUrl = router.replace || router.push;
|
|
2987
|
+
replaceUrl(`${pathname}?${newQueryString}`);
|
|
2988
|
+
}
|
|
2989
|
+
}, [debouncedSearchableString, isQuerySearch]);
|
|
2990
|
+
React22__namespace.useEffect(() => {
|
|
2991
|
+
if (isQueryFilter || !router) return;
|
|
2992
|
+
const currentFilterableFilters = JSON.parse(filterableString);
|
|
2993
|
+
const updates = {};
|
|
2994
|
+
let hasChanges = false;
|
|
2995
|
+
for (const col of currentFilterableFilters) {
|
|
2996
|
+
if (typeof col.value === "object" && Array.isArray(col.value) && col.value.length > 0) {
|
|
2997
|
+
const newValue = col.value.join(".");
|
|
2998
|
+
updates[col.id] = newValue;
|
|
2999
|
+
if (searchParams.get(String(col.id)) !== newValue) {
|
|
3000
|
+
hasChanges = true;
|
|
3001
|
+
}
|
|
3002
|
+
}
|
|
3003
|
+
}
|
|
3004
|
+
for (const key of Array.from(searchParams.keys())) {
|
|
3005
|
+
if (filterableColumns.find((col) => String(col.id) === key) && !currentFilterableFilters.find((col) => col.id === key)) {
|
|
3006
|
+
updates[key] = null;
|
|
3007
|
+
hasChanges = true;
|
|
3008
|
+
}
|
|
3009
|
+
}
|
|
3010
|
+
if (hasChanges) {
|
|
3011
|
+
updates.page = 1;
|
|
3012
|
+
}
|
|
3013
|
+
const newQueryString = createQueryString(updates);
|
|
3014
|
+
const currentQueryString = searchParams.toString() || "";
|
|
3015
|
+
if (newQueryString !== currentQueryString && hasChanges) {
|
|
3016
|
+
const replaceUrl = router.replace || router.push;
|
|
3017
|
+
replaceUrl(`${pathname}?${newQueryString}`);
|
|
3018
|
+
}
|
|
3019
|
+
}, [filterableString, isQueryFilter]);
|
|
3020
|
+
const table = reactTable.useReactTable({
|
|
3021
|
+
data: data != null ? data : EMPTY_DATA,
|
|
3022
|
+
columns,
|
|
3023
|
+
pageCount: pageCount != null ? pageCount : -1,
|
|
3024
|
+
state: {
|
|
3025
|
+
pagination,
|
|
3026
|
+
sorting,
|
|
3027
|
+
columnVisibility,
|
|
3028
|
+
rowSelection,
|
|
3029
|
+
columnFilters
|
|
3030
|
+
},
|
|
3031
|
+
enableRowSelection: resolvedConfig.features.rowSelection,
|
|
3032
|
+
enableSorting: resolvedConfig.features.sorting,
|
|
3033
|
+
onRowSelectionChange: setRowSelection,
|
|
3034
|
+
onPaginationChange: setPagination,
|
|
3035
|
+
onSortingChange: setSorting,
|
|
3036
|
+
onColumnFiltersChange: setColumnFilters,
|
|
3037
|
+
onColumnVisibilityChange: setColumnVisibility,
|
|
3038
|
+
getCoreRowModel: reactTable.getCoreRowModel(),
|
|
3039
|
+
getFilteredRowModel: reactTable.getFilteredRowModel(),
|
|
3040
|
+
getPaginationRowModel: reactTable.getPaginationRowModel(),
|
|
3041
|
+
getSortedRowModel: reactTable.getSortedRowModel(),
|
|
3042
|
+
getFacetedRowModel: reactTable.getFacetedRowModel(),
|
|
3043
|
+
getFacetedUniqueValues: reactTable.getFacetedUniqueValues(),
|
|
3044
|
+
manualPagination: isManualPagination,
|
|
3045
|
+
manualSorting: isManualSorting,
|
|
3046
|
+
manualFiltering: isManualFiltering
|
|
3047
|
+
});
|
|
3048
|
+
return /* @__PURE__ */ jsxRuntime.jsxs(jsxRuntime.Fragment, { children: [
|
|
3049
|
+
shouldShowFilter ? /* @__PURE__ */ jsxRuntime.jsxs(jsxRuntime.Fragment, { children: [
|
|
3050
|
+
/* @__PURE__ */ jsxRuntime.jsx("div", { className: "max-md:hidden", children: shouldShowAdvancedFilter && !isQuerySearch && !isQueryFilter ? /* @__PURE__ */ jsxRuntime.jsx(
|
|
3051
|
+
DataTableAdvancedToolbar,
|
|
3052
|
+
{
|
|
3053
|
+
table,
|
|
3054
|
+
searchableColumns,
|
|
3055
|
+
filterableColumns,
|
|
3056
|
+
addItemPagePath: addItemPagePath == null ? void 0 : addItemPagePath.url
|
|
3057
|
+
}
|
|
3058
|
+
) : /* @__PURE__ */ jsxRuntime.jsx(
|
|
3059
|
+
DataTableToolbar,
|
|
3060
|
+
{
|
|
3061
|
+
table,
|
|
3062
|
+
viewMode,
|
|
3063
|
+
onViewModeChange: setViewMode,
|
|
3064
|
+
addItemPagePath,
|
|
3065
|
+
isShowExportButtons,
|
|
3066
|
+
customButtons,
|
|
3067
|
+
customCss,
|
|
3068
|
+
...isQuerySearch === true ? {
|
|
3069
|
+
isQuerySearch,
|
|
3070
|
+
searchableQuery
|
|
3071
|
+
} : {
|
|
3072
|
+
isQuerySearch,
|
|
3073
|
+
searchableColumns
|
|
3074
|
+
},
|
|
3075
|
+
...isQueryFilter && handleFilterChange ? {
|
|
3076
|
+
isQueryFilter: true,
|
|
3077
|
+
handleFilterChange,
|
|
3078
|
+
filterableQuery: filterableQuery || [],
|
|
3079
|
+
currentFilters,
|
|
3080
|
+
onClearFilters
|
|
3081
|
+
} : {
|
|
3082
|
+
isQueryFilter: false,
|
|
3083
|
+
filterableColumns
|
|
3084
|
+
}
|
|
3085
|
+
}
|
|
3086
|
+
) }),
|
|
3087
|
+
/* @__PURE__ */ jsxRuntime.jsx("div", { className: "flex items-center justify-between md:hidden", children: /* @__PURE__ */ jsxRuntime.jsx(
|
|
3088
|
+
DataTableMobileToolbar,
|
|
3089
|
+
{
|
|
3090
|
+
table,
|
|
3091
|
+
filterableColumns,
|
|
3092
|
+
searchableColumns,
|
|
3093
|
+
addItemPagePath,
|
|
3094
|
+
isShowExportButtons,
|
|
3095
|
+
customButtons
|
|
3096
|
+
}
|
|
3097
|
+
) })
|
|
3098
|
+
] }) : null,
|
|
3099
|
+
viewMode === "cards" ? /* @__PURE__ */ jsxRuntime.jsxs(jsxRuntime.Fragment, { children: [
|
|
3100
|
+
/* @__PURE__ */ jsxRuntime.jsx(DataTableCardView, { table }),
|
|
3101
|
+
shouldShowPagination ? /* @__PURE__ */ jsxRuntime.jsx(Card, { className: "mt-3 overflow-hidden", children: /* @__PURE__ */ jsxRuntime.jsx("div", { className: "space-y-2.5", children: isQueryPagination && paginationData ? /* @__PURE__ */ jsxRuntime.jsx(
|
|
3102
|
+
DataTablePagination,
|
|
3103
|
+
{
|
|
3104
|
+
table,
|
|
3105
|
+
isQueryPagination: true,
|
|
3106
|
+
paginationData
|
|
3107
|
+
}
|
|
3108
|
+
) : /* @__PURE__ */ jsxRuntime.jsx(DataTablePagination, { table, isQueryPagination: false }) }) }) : null
|
|
3109
|
+
] }) : /* @__PURE__ */ jsxRuntime.jsxs(Card, { className: "mt-3 overflow-hidden", children: [
|
|
3110
|
+
/* @__PURE__ */ jsxRuntime.jsx(CardContent, { className: "p-0", children: /* @__PURE__ */ jsxRuntime.jsxs(Table, { children: [
|
|
3111
|
+
/* @__PURE__ */ jsxRuntime.jsx(TableHeader, { className: "bg-muted/50", children: table.getHeaderGroups().map((headerGroup) => /* @__PURE__ */ jsxRuntime.jsx(TableRow, { children: headerGroup.headers.map((header) => {
|
|
3112
|
+
const sortDirection = header.column.getIsSorted();
|
|
3113
|
+
return /* @__PURE__ */ jsxRuntime.jsx(
|
|
3114
|
+
TableHead,
|
|
3115
|
+
{
|
|
3116
|
+
className: "text-nowrap",
|
|
3117
|
+
"aria-sort": sortDirection === "asc" ? "ascending" : sortDirection === "desc" ? "descending" : void 0,
|
|
3118
|
+
children: header.isPlaceholder ? null : reactTable.flexRender(header.column.columnDef.header, header.getContext())
|
|
3119
|
+
},
|
|
3120
|
+
header.id
|
|
3121
|
+
);
|
|
3122
|
+
}) }, headerGroup.id)) }),
|
|
3123
|
+
/* @__PURE__ */ jsxRuntime.jsx(TableBody, { children: ((_e = (_d = table.getRowModel()) == null ? void 0 : _d.rows) == null ? void 0 : _e.length) ? (_f = table.getRowModel()) == null ? void 0 : _f.rows.map((row, rowIndex) => /* @__PURE__ */ jsxRuntime.jsx(
|
|
3124
|
+
TableRow,
|
|
3125
|
+
{
|
|
3126
|
+
"data-state": row.getIsSelected() && "selected",
|
|
3127
|
+
"aria-rowindex": pageIndex * pageSize + rowIndex + 2,
|
|
3128
|
+
children: row.getVisibleCells().map((cell) => /* @__PURE__ */ jsxRuntime.jsx(TableCell, { className: "max-w-60 text-ellipsis text-nowrap", children: reactTable.flexRender(cell.column.columnDef.cell, cell.getContext()) }, cell.id))
|
|
3129
|
+
},
|
|
3130
|
+
row.id
|
|
3131
|
+
)) : /* @__PURE__ */ jsxRuntime.jsx(TableRow, { children: /* @__PURE__ */ jsxRuntime.jsx(TableCell, { colSpan: columns.length, className: "py-16 text-center", children: /* @__PURE__ */ jsxRuntime.jsxs("div", { className: "flex flex-col items-center gap-3", children: [
|
|
3132
|
+
/* @__PURE__ */ jsxRuntime.jsx(lucideReact.SearchX, { className: "size-10 text-muted-foreground/50", "aria-hidden": "true" }),
|
|
3133
|
+
/* @__PURE__ */ jsxRuntime.jsxs("div", { className: "space-y-1", children: [
|
|
3134
|
+
/* @__PURE__ */ jsxRuntime.jsx("p", { className: "font-semibold", children: t("no-records-found") }),
|
|
3135
|
+
/* @__PURE__ */ jsxRuntime.jsx("p", { className: "text-sm text-muted-foreground", children: t("no-records-hint") })
|
|
3136
|
+
] }),
|
|
3137
|
+
(table.getState().columnFilters.length > 0 || isQueryFilter && currentFilters && Object.keys(currentFilters).length > 0) && /* @__PURE__ */ jsxRuntime.jsxs(
|
|
3138
|
+
Button,
|
|
3139
|
+
{
|
|
3140
|
+
variant: "outline",
|
|
3141
|
+
size: "sm",
|
|
3142
|
+
className: "mt-1 gap-1.5",
|
|
3143
|
+
onClick: () => {
|
|
3144
|
+
if (isQueryFilter && onClearFilters) {
|
|
3145
|
+
onClearFilters();
|
|
3146
|
+
} else {
|
|
3147
|
+
table.resetColumnFilters();
|
|
3148
|
+
}
|
|
3149
|
+
},
|
|
3150
|
+
children: [
|
|
3151
|
+
/* @__PURE__ */ jsxRuntime.jsx(lucideReact.RotateCcw, { className: "size-3.5", "aria-hidden": "true" }),
|
|
3152
|
+
t("reset-filters")
|
|
3153
|
+
]
|
|
3154
|
+
}
|
|
3155
|
+
)
|
|
3156
|
+
] }) }) }) })
|
|
3157
|
+
] }) }),
|
|
3158
|
+
shouldShowPagination ? /* @__PURE__ */ jsxRuntime.jsx("div", { className: "space-y-2.5", children: isQueryPagination && paginationData ? /* @__PURE__ */ jsxRuntime.jsx(
|
|
3159
|
+
DataTablePagination,
|
|
3160
|
+
{
|
|
3161
|
+
table,
|
|
3162
|
+
isQueryPagination: true,
|
|
3163
|
+
paginationData
|
|
3164
|
+
}
|
|
3165
|
+
) : /* @__PURE__ */ jsxRuntime.jsx(DataTablePagination, { table, isQueryPagination: false }) }) : null
|
|
3166
|
+
] })
|
|
3167
|
+
] });
|
|
3168
|
+
}
|
|
3169
|
+
function DataTableColumnHeader({
|
|
3170
|
+
column,
|
|
3171
|
+
title,
|
|
3172
|
+
className
|
|
3173
|
+
}) {
|
|
3174
|
+
const t = useTableTranslations();
|
|
3175
|
+
if (!column.getCanSort()) {
|
|
3176
|
+
return /* @__PURE__ */ jsxRuntime.jsx("div", { className: cn(className), children: title });
|
|
3177
|
+
}
|
|
3178
|
+
return /* @__PURE__ */ jsxRuntime.jsx("div", { className: cn("flex items-center gap-2", className), children: /* @__PURE__ */ jsxRuntime.jsxs(DropdownMenu, { children: [
|
|
3179
|
+
/* @__PURE__ */ jsxRuntime.jsx(DropdownMenuTrigger, { asChild: true, children: /* @__PURE__ */ jsxRuntime.jsxs(
|
|
3180
|
+
Button,
|
|
3181
|
+
{
|
|
3182
|
+
"aria-label": column.getIsSorted() === "desc" ? t("sorted-desc") : column.getIsSorted() === "asc" ? t("sorted-asc") : t("not-sorted"),
|
|
3183
|
+
variant: "ghost",
|
|
3184
|
+
size: "sm",
|
|
3185
|
+
className: "-ms-3 h-8 data-[state=open]:bg-accent",
|
|
3186
|
+
children: [
|
|
3187
|
+
/* @__PURE__ */ jsxRuntime.jsx("span", { children: title }),
|
|
3188
|
+
column.getIsSorted() === "desc" ? /* @__PURE__ */ jsxRuntime.jsx(lucideReact.ArrowDown, { className: "ms-2 size-4", "aria-hidden": "true" }) : column.getIsSorted() === "asc" ? /* @__PURE__ */ jsxRuntime.jsx(lucideReact.ArrowUp, { className: "ms-2 size-4", "aria-hidden": "true" }) : /* @__PURE__ */ jsxRuntime.jsx(lucideReact.SortAsc, { className: "ms-2 size-4", "aria-hidden": "true" })
|
|
3189
|
+
]
|
|
3190
|
+
}
|
|
3191
|
+
) }),
|
|
3192
|
+
/* @__PURE__ */ jsxRuntime.jsxs(DropdownMenuContent, { align: "start", children: [
|
|
3193
|
+
/* @__PURE__ */ jsxRuntime.jsxs(DropdownMenuItem, { "aria-label": t("sort-ascending"), onClick: () => column.toggleSorting(false), children: [
|
|
3194
|
+
/* @__PURE__ */ jsxRuntime.jsx(lucideReact.ArrowUpIcon, { className: "me-2 size-3.5 text-muted-foreground/70", "aria-hidden": "true" }),
|
|
3195
|
+
t("asc")
|
|
3196
|
+
] }),
|
|
3197
|
+
/* @__PURE__ */ jsxRuntime.jsxs(DropdownMenuItem, { "aria-label": t("sort-descending"), onClick: () => column.toggleSorting(true), children: [
|
|
3198
|
+
/* @__PURE__ */ jsxRuntime.jsx(lucideReact.ArrowDownIcon, { className: "me-2 size-3.5 text-muted-foreground/70", "aria-hidden": "true" }),
|
|
3199
|
+
t("desc")
|
|
3200
|
+
] }),
|
|
3201
|
+
/* @__PURE__ */ jsxRuntime.jsx(DropdownMenuSeparator, {}),
|
|
3202
|
+
/* @__PURE__ */ jsxRuntime.jsxs(DropdownMenuItem, { "aria-label": t("hide-column"), onClick: () => column.toggleVisibility(false), children: [
|
|
3203
|
+
/* @__PURE__ */ jsxRuntime.jsx(lucideReact.EyeOffIcon, { className: "me-2 size-3.5 text-muted-foreground/70", "aria-hidden": "true" }),
|
|
3204
|
+
t("Hide")
|
|
3205
|
+
] })
|
|
3206
|
+
] })
|
|
3207
|
+
] }) });
|
|
3208
|
+
}
|
|
3209
|
+
function ClientSideTable({
|
|
3210
|
+
data,
|
|
3211
|
+
pageCount,
|
|
3212
|
+
pageSize = 10,
|
|
3213
|
+
columns: initialColumns,
|
|
3214
|
+
searchableColumns = [],
|
|
3215
|
+
showFilter = true,
|
|
3216
|
+
showPagination = true,
|
|
3217
|
+
filterableColumns = [],
|
|
3218
|
+
addItemPagePath,
|
|
3219
|
+
isShowExportButtons = {
|
|
3220
|
+
isShow: true,
|
|
3221
|
+
ignoredCols: [],
|
|
3222
|
+
fileName: ""
|
|
3223
|
+
},
|
|
3224
|
+
customButtons,
|
|
3225
|
+
withIndex = true,
|
|
3226
|
+
isQueryPagination = false,
|
|
3227
|
+
paginationData,
|
|
3228
|
+
isLoading = false,
|
|
3229
|
+
isQuerySearch = false,
|
|
3230
|
+
searchableQuery = [],
|
|
3231
|
+
isQueryFilter = false,
|
|
3232
|
+
handleFilterChange,
|
|
3233
|
+
filterableQuery,
|
|
3234
|
+
currentFilters,
|
|
3235
|
+
onClearFilters,
|
|
3236
|
+
customCss,
|
|
3237
|
+
isShowAdvancedFilter = false,
|
|
3238
|
+
config
|
|
3239
|
+
}) {
|
|
3240
|
+
const t = useTableTranslations();
|
|
3241
|
+
const columns = React22__namespace.useMemo(() => {
|
|
3242
|
+
return [
|
|
3243
|
+
...withIndex ? [
|
|
3244
|
+
{
|
|
3245
|
+
accessorKey: "i",
|
|
3246
|
+
header: ({ column }) => /* @__PURE__ */ jsxRuntime.jsx(DataTableColumnHeader, { column, title: t("row-number") }),
|
|
3247
|
+
cell: ({ row, table }) => /* @__PURE__ */ jsxRuntime.jsx("div", { className: "w-full", children: table.getState().pagination.pageIndex + 1 === 1 ? row.index + 1 : table.getState().pagination.pageIndex + 1 > 1 ? table.getState().pagination.pageIndex * table.getState().pagination.pageSize + (row.index + 1) : row.index + 1 }),
|
|
3248
|
+
enableSorting: false,
|
|
3249
|
+
enableHiding: false
|
|
3250
|
+
}
|
|
3251
|
+
] : [],
|
|
3252
|
+
...initialColumns
|
|
3253
|
+
];
|
|
3254
|
+
}, [initialColumns, withIndex, t]);
|
|
3255
|
+
return /* @__PURE__ */ jsxRuntime.jsx(
|
|
3256
|
+
DataTable,
|
|
3257
|
+
{
|
|
3258
|
+
columns,
|
|
3259
|
+
data,
|
|
3260
|
+
pageCount,
|
|
3261
|
+
pageSize,
|
|
3262
|
+
showFilter,
|
|
3263
|
+
showPagination,
|
|
3264
|
+
addItemPagePath,
|
|
3265
|
+
isShowExportButtons,
|
|
3266
|
+
customButtons,
|
|
3267
|
+
floatingBar: true,
|
|
3268
|
+
isLoading,
|
|
3269
|
+
customCss,
|
|
3270
|
+
isShowAdvancedFilter,
|
|
3271
|
+
config,
|
|
3272
|
+
...isQuerySearch ? { isQuerySearch: true, searchableQuery } : {
|
|
3273
|
+
isQuerySearch: false,
|
|
3274
|
+
searchableColumns
|
|
3275
|
+
},
|
|
3276
|
+
...isQueryPagination && paginationData ? { isQueryPagination: true, paginationData } : { isQueryPagination: false },
|
|
3277
|
+
...isQueryFilter && handleFilterChange ? {
|
|
3278
|
+
isQueryFilter: true,
|
|
3279
|
+
handleFilterChange,
|
|
3280
|
+
filterableQuery: filterableQuery || [],
|
|
3281
|
+
currentFilters,
|
|
3282
|
+
onClearFilters
|
|
3283
|
+
} : {
|
|
3284
|
+
isQueryFilter: false,
|
|
3285
|
+
filterableColumns: filterableColumns || []
|
|
3286
|
+
}
|
|
3287
|
+
}
|
|
3288
|
+
);
|
|
3289
|
+
}
|
|
3290
|
+
function DataTableFloatingBar({
|
|
3291
|
+
table,
|
|
3292
|
+
deleteRowsAction,
|
|
3293
|
+
className,
|
|
3294
|
+
...props
|
|
3295
|
+
}) {
|
|
3296
|
+
const t = useTableTranslations();
|
|
3297
|
+
if (table.getFilteredSelectedRowModel().rows.length <= 0) return null;
|
|
3298
|
+
return /* @__PURE__ */ jsxRuntime.jsxs(
|
|
3299
|
+
"div",
|
|
3300
|
+
{
|
|
3301
|
+
className: cn(
|
|
3302
|
+
"mx-auto flex w-fit items-center gap-2 rounded-md bg-zinc-900 px-4 py-2 text-white",
|
|
3303
|
+
className
|
|
3304
|
+
),
|
|
3305
|
+
...props,
|
|
3306
|
+
children: [
|
|
3307
|
+
/* @__PURE__ */ jsxRuntime.jsx(
|
|
3308
|
+
Button,
|
|
3309
|
+
{
|
|
3310
|
+
"aria-label": t("clear-selection"),
|
|
3311
|
+
title: t("clear-selection"),
|
|
3312
|
+
className: "h-auto bg-transparent p-1 text-white hover:bg-zinc-700",
|
|
3313
|
+
onClick: () => table.toggleAllRowsSelected(false),
|
|
3314
|
+
children: /* @__PURE__ */ jsxRuntime.jsx(lucideReact.X, { className: "size-4", "aria-hidden": "true" })
|
|
3315
|
+
}
|
|
3316
|
+
),
|
|
3317
|
+
/* @__PURE__ */ jsxRuntime.jsxs("span", { children: [
|
|
3318
|
+
table.getFilteredSelectedRowModel().rows.length,
|
|
3319
|
+
" ",
|
|
3320
|
+
t("row(s) selected")
|
|
3321
|
+
] }),
|
|
3322
|
+
deleteRowsAction && /* @__PURE__ */ jsxRuntime.jsx(
|
|
3323
|
+
Button,
|
|
3324
|
+
{
|
|
3325
|
+
"aria-label": t("delete-selected"),
|
|
3326
|
+
title: t("delete"),
|
|
3327
|
+
className: "h-auto bg-transparent p-1 text-white hover:bg-zinc-700",
|
|
3328
|
+
onClick: (event) => {
|
|
3329
|
+
table.toggleAllPageRowsSelected(false);
|
|
3330
|
+
deleteRowsAction(event);
|
|
3331
|
+
},
|
|
3332
|
+
children: /* @__PURE__ */ jsxRuntime.jsx(lucideReact.TrashIcon, { className: "size-4", "aria-hidden": "true" })
|
|
3333
|
+
}
|
|
3334
|
+
)
|
|
3335
|
+
]
|
|
3336
|
+
}
|
|
3337
|
+
);
|
|
3338
|
+
}
|
|
3339
|
+
function DataTableRoleFilter({
|
|
3340
|
+
column,
|
|
3341
|
+
title,
|
|
3342
|
+
options,
|
|
3343
|
+
paramKey
|
|
3344
|
+
}) {
|
|
3345
|
+
var _a;
|
|
3346
|
+
const config = useTableConfig();
|
|
3347
|
+
const router = config.router;
|
|
3348
|
+
const t = useTableTranslations();
|
|
3349
|
+
const resolvedParamKey = paramKey != null ? paramKey : column ? String(column.id) : "role";
|
|
3350
|
+
const searchParams = router ? router.getSearchParams() : new URLSearchParams();
|
|
3351
|
+
const currentValue = router ? searchParams.get(resolvedParamKey) || void 0 : column == null ? void 0 : column.getFilterValue();
|
|
3352
|
+
const handleSelect = (value) => {
|
|
3353
|
+
if (router) {
|
|
3354
|
+
const newParams = new URLSearchParams(searchParams.toString());
|
|
3355
|
+
if (value) {
|
|
3356
|
+
newParams.set(resolvedParamKey, value);
|
|
3357
|
+
} else {
|
|
3358
|
+
newParams.delete(resolvedParamKey);
|
|
3359
|
+
}
|
|
3360
|
+
newParams.set("page", "1");
|
|
3361
|
+
router.push(`?${newParams.toString()}`);
|
|
3362
|
+
}
|
|
3363
|
+
column == null ? void 0 : column.setFilterValue(value);
|
|
3364
|
+
};
|
|
3365
|
+
return /* @__PURE__ */ jsxRuntime.jsxs(Popover, { children: [
|
|
3366
|
+
/* @__PURE__ */ jsxRuntime.jsx(PopoverTrigger, { asChild: true, children: /* @__PURE__ */ jsxRuntime.jsxs(Button, { variant: "outline", size: "sm", className: "h-8 border-dashed", children: [
|
|
3367
|
+
/* @__PURE__ */ jsxRuntime.jsx(lucideReact.ChevronsUpDown, { className: "me-2 h-4 w-4 opacity-50" }),
|
|
3368
|
+
title,
|
|
3369
|
+
currentValue && /* @__PURE__ */ jsxRuntime.jsxs(jsxRuntime.Fragment, { children: [
|
|
3370
|
+
/* @__PURE__ */ jsxRuntime.jsx("span", { className: "mx-2 text-muted-foreground", children: "|" }),
|
|
3371
|
+
/* @__PURE__ */ jsxRuntime.jsx(Badge, { variant: "secondary", className: "rounded-sm px-1 font-normal", children: (_a = options.find((opt) => opt.value === currentValue)) == null ? void 0 : _a.label })
|
|
3372
|
+
] })
|
|
3373
|
+
] }) }),
|
|
3374
|
+
/* @__PURE__ */ jsxRuntime.jsx(PopoverContent, { className: "w-[200px] p-0", align: "start", children: /* @__PURE__ */ jsxRuntime.jsxs(Command, { children: [
|
|
3375
|
+
/* @__PURE__ */ jsxRuntime.jsx(CommandInput, { placeholder: `${t("Filter")} ${title}...` }),
|
|
3376
|
+
/* @__PURE__ */ jsxRuntime.jsx(CommandEmpty, { children: t("no-items-found") }),
|
|
3377
|
+
/* @__PURE__ */ jsxRuntime.jsxs(CommandGroup, { className: "max-h-64 overflow-auto", children: [
|
|
3378
|
+
/* @__PURE__ */ jsxRuntime.jsxs(CommandItem, { onSelect: () => handleSelect(void 0), className: "cursor-pointer", children: [
|
|
3379
|
+
/* @__PURE__ */ jsxRuntime.jsx(
|
|
3380
|
+
"div",
|
|
3381
|
+
{
|
|
3382
|
+
className: cn(
|
|
3383
|
+
"me-2 flex h-4 w-4 items-center justify-center rounded-sm border border-primary",
|
|
3384
|
+
!currentValue ? "bg-primary text-primary-foreground" : "opacity-50 [&_svg]:invisible"
|
|
3385
|
+
),
|
|
3386
|
+
children: /* @__PURE__ */ jsxRuntime.jsx(lucideReact.Check, { className: "h-4 w-4" })
|
|
3387
|
+
}
|
|
3388
|
+
),
|
|
3389
|
+
/* @__PURE__ */ jsxRuntime.jsx("span", { children: t("all") })
|
|
3390
|
+
] }),
|
|
3391
|
+
options.map((option) => {
|
|
3392
|
+
const isSelected = currentValue === option.value;
|
|
3393
|
+
return /* @__PURE__ */ jsxRuntime.jsxs(
|
|
3394
|
+
CommandItem,
|
|
3395
|
+
{
|
|
3396
|
+
onSelect: () => handleSelect(option.value),
|
|
3397
|
+
className: "cursor-pointer",
|
|
3398
|
+
children: [
|
|
3399
|
+
/* @__PURE__ */ jsxRuntime.jsx(
|
|
3400
|
+
"div",
|
|
3401
|
+
{
|
|
3402
|
+
className: cn(
|
|
3403
|
+
"me-2 flex h-4 w-4 items-center justify-center rounded-sm border border-primary",
|
|
3404
|
+
isSelected ? "bg-primary text-primary-foreground" : "opacity-50 [&_svg]:invisible"
|
|
3405
|
+
),
|
|
3406
|
+
children: /* @__PURE__ */ jsxRuntime.jsx(lucideReact.Check, { className: "h-4 w-4" })
|
|
3407
|
+
}
|
|
3408
|
+
),
|
|
3409
|
+
/* @__PURE__ */ jsxRuntime.jsx("span", { children: option.label })
|
|
3410
|
+
]
|
|
3411
|
+
},
|
|
3412
|
+
option.value
|
|
3413
|
+
);
|
|
3414
|
+
})
|
|
3415
|
+
] })
|
|
3416
|
+
] }) })
|
|
3417
|
+
] });
|
|
3418
|
+
}
|
|
3419
|
+
function Skeleton({ className, ...props }) {
|
|
3420
|
+
return /* @__PURE__ */ jsxRuntime.jsx("div", { className: cn("animate-pulse rounded-md bg-primary/10", className), ...props });
|
|
3421
|
+
}
|
|
3422
|
+
var DataTableLoading = React22__namespace.default.memo(function DataTableLoading2({ columnCount, rowCount = 10 }) {
|
|
3423
|
+
return /* @__PURE__ */ jsxRuntime.jsxs("div", { className: "w-full space-y-3 overflow-auto", role: "status", "aria-busy": "true", "aria-label": "Loading data", children: [
|
|
3424
|
+
/* @__PURE__ */ jsxRuntime.jsxs("div", { className: "flex w-full items-center justify-between gap-2 overflow-auto p-1", children: [
|
|
3425
|
+
/* @__PURE__ */ jsxRuntime.jsxs("div", { className: "flex flex-1 items-center gap-2", children: [
|
|
3426
|
+
/* @__PURE__ */ jsxRuntime.jsx(Skeleton, { className: "h-7 w-[150px] lg:w-[250px]" }),
|
|
3427
|
+
/* @__PURE__ */ jsxRuntime.jsx(Skeleton, { className: "h-7 w-[70px] border-dashed" })
|
|
3428
|
+
] }),
|
|
3429
|
+
/* @__PURE__ */ jsxRuntime.jsx(Skeleton, { className: "ms-auto hidden h-7 w-[70px] lg:flex" })
|
|
3430
|
+
] }),
|
|
3431
|
+
/* @__PURE__ */ jsxRuntime.jsx("div", { className: "rounded-md border", children: /* @__PURE__ */ jsxRuntime.jsxs(Table, { children: [
|
|
3432
|
+
/* @__PURE__ */ jsxRuntime.jsx(TableHeader, { children: Array.from({ length: 1 }).map((_, i) => /* @__PURE__ */ jsxRuntime.jsx(TableRow, { className: "hover:bg-transparent", children: Array.from({ length: columnCount }).map((_2, j) => /* @__PURE__ */ jsxRuntime.jsx(TableHead, { children: /* @__PURE__ */ jsxRuntime.jsx(Skeleton, { className: "h-6 w-full" }) }, j)) }, i)) }),
|
|
3433
|
+
/* @__PURE__ */ jsxRuntime.jsx(TableBody, { children: Array.from({ length: rowCount }).map((_, i) => /* @__PURE__ */ jsxRuntime.jsx(TableRow, { className: "hover:bg-transparent", children: Array.from({ length: columnCount }).map((_2, j) => /* @__PURE__ */ jsxRuntime.jsx(TableCell, { children: /* @__PURE__ */ jsxRuntime.jsx(Skeleton, { className: "h-6 w-full" }) }, j)) }, i)) })
|
|
3434
|
+
] }) }),
|
|
3435
|
+
/* @__PURE__ */ jsxRuntime.jsxs("div", { className: "flex w-full flex-col items-center justify-between gap-4 overflow-auto px-2 py-1 sm:flex-row sm:gap-8", children: [
|
|
3436
|
+
/* @__PURE__ */ jsxRuntime.jsx("div", { className: "flex-1", children: /* @__PURE__ */ jsxRuntime.jsx(Skeleton, { className: "h-8 w-40" }) }),
|
|
3437
|
+
/* @__PURE__ */ jsxRuntime.jsxs("div", { className: "flex flex-col items-center gap-4 sm:flex-row sm:gap-6 lg:gap-8", children: [
|
|
3438
|
+
/* @__PURE__ */ jsxRuntime.jsxs("div", { className: "flex items-center gap-2", children: [
|
|
3439
|
+
/* @__PURE__ */ jsxRuntime.jsx(Skeleton, { className: "h-8 w-24" }),
|
|
3440
|
+
/* @__PURE__ */ jsxRuntime.jsx(Skeleton, { className: "h-8 w-[70px]" })
|
|
3441
|
+
] }),
|
|
3442
|
+
/* @__PURE__ */ jsxRuntime.jsx("div", { className: "flex w-[100px] items-center justify-center text-sm font-medium", children: /* @__PURE__ */ jsxRuntime.jsx(Skeleton, { className: "h-8 w-20" }) }),
|
|
3443
|
+
/* @__PURE__ */ jsxRuntime.jsxs("div", { className: "flex items-center gap-2", children: [
|
|
3444
|
+
/* @__PURE__ */ jsxRuntime.jsx(Skeleton, { className: "hidden size-8 lg:block" }),
|
|
3445
|
+
/* @__PURE__ */ jsxRuntime.jsx(Skeleton, { className: "size-8" }),
|
|
3446
|
+
/* @__PURE__ */ jsxRuntime.jsx(Skeleton, { className: "size-8" }),
|
|
3447
|
+
/* @__PURE__ */ jsxRuntime.jsx(Skeleton, { className: "hidden size-8 lg:block" })
|
|
3448
|
+
] })
|
|
3449
|
+
] })
|
|
3450
|
+
] })
|
|
3451
|
+
] });
|
|
3452
|
+
});
|
|
3453
|
+
|
|
3454
|
+
exports.ButtonTooltip = ButtonTooltip;
|
|
3455
|
+
exports.ClientSideTable = ClientSideTable;
|
|
3456
|
+
exports.DEFAULT_TABLE_CONFIG = DEFAULT_TABLE_CONFIG;
|
|
3457
|
+
exports.DataTable = DataTable;
|
|
3458
|
+
exports.DataTableAdvancedFilter = DataTableAdvancedFilter;
|
|
3459
|
+
exports.DataTableAdvancedFilterItem = DataTableAdvancedFilterItem;
|
|
3460
|
+
exports.DataTableAdvancedToolbar = DataTableAdvancedToolbar;
|
|
3461
|
+
exports.DataTableCardView = DataTableCardView;
|
|
3462
|
+
exports.DataTableColumnHeader = DataTableColumnHeader;
|
|
3463
|
+
exports.DataTableFacetedFilter = DataTableFacetedFilter;
|
|
3464
|
+
exports.DataTableFloatingBar = DataTableFloatingBar;
|
|
3465
|
+
exports.DataTableLoading = DataTableLoading;
|
|
3466
|
+
exports.DataTableMobileToolbar = DataTableMobileToolbar;
|
|
3467
|
+
exports.DataTableMultiFilter = DataTableMultiFilter;
|
|
3468
|
+
exports.DataTablePagination = DataTablePagination;
|
|
3469
|
+
exports.DataTableRoleFilter = DataTableRoleFilter;
|
|
3470
|
+
exports.DataTableSingleSelectFilter = DataTableSingleSelectFilter;
|
|
3471
|
+
exports.DataTableToolbar = DataTableToolbar;
|
|
3472
|
+
exports.DataTableViewOptions = DataTableViewOptions;
|
|
3473
|
+
exports.MultiFilterRow = MultiFilterRow;
|
|
3474
|
+
exports.TableActionsRow = table_actions_row_default;
|
|
3475
|
+
exports.TableProvider = TableProvider;
|
|
3476
|
+
exports.cn = cn;
|
|
3477
|
+
exports.createCsvConfig = createCsvConfig;
|
|
3478
|
+
exports.createTableConfig = createTableConfig;
|
|
3479
|
+
exports.deepMergeConfig = deepMergeConfig;
|
|
3480
|
+
exports.exportSelectedRowsCsv = exportSelectedRowsCsv;
|
|
3481
|
+
exports.useDebounce = useDebounce;
|
|
3482
|
+
exports.useGlobalTableConfig = useGlobalTableConfig;
|
|
3483
|
+
exports.useResolvedTableConfig = useResolvedTableConfig;
|
|
3484
|
+
exports.useTableConfig = useTableConfig;
|
|
3485
|
+
exports.useTableTranslations = useTableTranslations;
|
|
3486
|
+
//# sourceMappingURL=index.js.map
|
|
3487
|
+
//# sourceMappingURL=index.js.map
|