performa 1.0.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.
@@ -0,0 +1,1466 @@
1
+ 'use strict';
2
+
3
+ var reactRouter = require('react-router');
4
+ var react = require('react');
5
+ var jsxRuntime = require('react/jsx-runtime');
6
+ var lucideReact = require('lucide-react');
7
+
8
+ // src/adapters/react-router.tsx
9
+ var FormContext = react.createContext(null);
10
+
11
+ // src/core/utils.ts
12
+ function isImage(filename) {
13
+ const imageExtensions = [
14
+ ".jpg",
15
+ ".jpeg",
16
+ ".png",
17
+ ".gif",
18
+ ".webp",
19
+ ".svg",
20
+ ".bmp",
21
+ ".tiff",
22
+ ".ico"
23
+ ];
24
+ const ext = filename.toLowerCase().slice(filename.lastIndexOf("."));
25
+ return imageExtensions.includes(ext);
26
+ }
27
+ var widthClasses = {
28
+ 1: "col-span-12 @lg:col-span-1",
29
+ 2: "col-span-4 @lg:col-span-2",
30
+ 3: "col-span-6 @lg:col-span-3",
31
+ 4: "col-span-8 @lg:col-span-4",
32
+ 5: "col-span-12 @lg:col-span-5",
33
+ 6: "col-span-12 @lg:col-span-6",
34
+ 7: "col-span-12 @lg:col-span-7",
35
+ 8: "col-span-12 @lg:col-span-8",
36
+ 9: "col-span-12 @lg:col-span-9",
37
+ 10: "col-span-12 @lg:col-span-10",
38
+ 11: "col-span-12 @lg:col-span-11",
39
+ 12: "col-span-12"
40
+ };
41
+ var defaultTheme = {
42
+ darkMode: true,
43
+ formGroup: "form-group",
44
+ form: "w-full",
45
+ fieldset: "@container grid grid-cols-12 gap-4",
46
+ label: {
47
+ base: "block text-sm font-medium text-gray-700 dark:text-gray-300",
48
+ required: "text-red-500 ml-1"
49
+ },
50
+ input: {
51
+ base: "block w-full px-3 py-2 border border-gray-300 dark:border-gray-600 rounded-md shadow-sm bg-white dark:bg-gray-800 text-gray-900 dark:text-gray-100 placeholder-gray-400 dark:placeholder-gray-500 focus:outline-none focus:ring focus:ring-primary focus:border-primary",
52
+ error: "border-red-500 dark:border-red-400",
53
+ disabled: "disabled:bg-gray-100 dark:disabled:bg-gray-700 disabled:cursor-not-allowed",
54
+ focus: "focus:outline-none focus:ring focus:ring-primary focus:border-primary"
55
+ },
56
+ select: {
57
+ base: "mt-1 block w-full px-3 py-2 border border-gray-300 dark:border-gray-600 rounded-md shadow-sm bg-white dark:bg-gray-800 text-gray-900 dark:text-gray-100 focus:outline-none focus:ring focus:ring-primary focus:border-primary disabled:bg-gray-100 dark:disabled:bg-gray-700 disabled:cursor-not-allowed",
58
+ error: "border-red-500 dark:border-red-400",
59
+ disabled: "disabled:bg-gray-100 dark:disabled:bg-gray-700 disabled:cursor-not-allowed",
60
+ option: "bg-white dark:bg-gray-800 text-gray-900 dark:text-gray-100"
61
+ },
62
+ textarea: {
63
+ base: "mt-1 block w-full px-3 py-2 border border-gray-300 dark:border-gray-600 rounded-md shadow-sm bg-white dark:bg-gray-800 text-gray-900 dark:text-gray-100 placeholder-gray-400 dark:placeholder-gray-500 focus:outline-none focus:ring focus:ring-primary focus:border-primary disabled:bg-gray-100 dark:disabled:bg-gray-700 disabled:cursor-not-allowed",
64
+ error: "border-red-500 dark:border-red-400",
65
+ disabled: "disabled:bg-gray-100 dark:disabled:bg-gray-700 disabled:cursor-not-allowed"
66
+ },
67
+ checkbox: {
68
+ base: "h-4 w-4 text-primary focus:ring-primary border-gray-300 dark:border-gray-600 dark:bg-gray-800 rounded disabled:cursor-not-allowed",
69
+ error: "border-red-500 dark:border-red-400",
70
+ label: "ml-2 block text-sm font-medium text-gray-700 dark:text-gray-300"
71
+ },
72
+ toggle: {
73
+ track: "absolute inset-0 rounded-full transition-colors duration-200 bg-gray-300 dark:bg-gray-600 peer-focus:ring-2 peer-focus:ring-primary peer-focus:ring-offset-2 dark:peer-focus:ring-offset-gray-800",
74
+ trackActive: "peer-checked:bg-primary peer-checked:dark:bg-primary-light",
75
+ thumb: "absolute left-1 top-1 w-4 h-4 bg-white dark:bg-gray-200 rounded-full transition-transform duration-200 peer-checked:translate-x-5",
76
+ label: "block text-sm font-medium text-gray-700 dark:text-gray-300"
77
+ },
78
+ radio: {
79
+ base: "h-4 w-4 text-primary focus:ring-primary border-gray-300 dark:border-gray-600 dark:bg-gray-800 disabled:cursor-not-allowed",
80
+ label: "ml-2 text-sm text-gray-700 dark:text-gray-300",
81
+ group: "mt-1"
82
+ },
83
+ file: {
84
+ dropzone: "flex flex-col items-center justify-center w-full p-6 border-2 border-dashed rounded-md cursor-pointer border-gray-300 dark:border-gray-600 hover:border-primary dark:hover:border-primary transition-colors duration-200",
85
+ dropzoneActive: "border-primary bg-primary-50 dark:bg-primary-900/20",
86
+ dropzoneError: "border-red-500 dark:border-red-400 hover:border-red-500 dark:hover:border-red-400",
87
+ icon: "w-8 h-8 text-gray-400 dark:text-gray-500",
88
+ text: "mt-2 text-sm text-gray-500 dark:text-gray-400",
89
+ hint: "mt-1 text-xs text-gray-500 dark:text-gray-400"
90
+ },
91
+ submit: {
92
+ base: "mt-1 flex items-center justify-center w-full px-4 py-2 border border-transparent rounded-md shadow-sm text-white bg-primary hover:bg-primary-dark dark:bg-primary-light dark:hover:bg-primary focus:outline-none focus:ring-2 focus:ring-offset-2 dark:focus:ring-offset-gray-800 focus:ring-primary transition-colors cursor-pointer disabled:opacity-50 disabled:cursor-not-allowed",
93
+ loading: "opacity-75",
94
+ spinner: "mr-3 -ml-1 size-5 animate-spin text-white"
95
+ },
96
+ error: "mt-1 text-sm text-red-600 dark:text-red-400",
97
+ alert: {
98
+ base: "p-4 mb-4 border rounded-md",
99
+ error: "bg-red-50 dark:bg-red-900/20 text-red-800 dark:text-red-200 border-red-200 dark:border-red-800",
100
+ success: "bg-green-50 dark:bg-green-900/20 text-green-800 dark:text-green-200 border-green-200 dark:border-green-800",
101
+ warning: "bg-yellow-50 dark:bg-yellow-900/20 text-yellow-800 dark:text-yellow-200 border-yellow-200 dark:border-yellow-800",
102
+ info: "bg-blue-50 dark:bg-blue-900/20 text-blue-800 dark:text-blue-200 border-blue-200 dark:border-blue-800"
103
+ },
104
+ datetime: {
105
+ input: "block w-full px-3 py-2 pr-10 border border-gray-300 dark:border-gray-600 rounded-md shadow-sm bg-white dark:bg-gray-800 text-gray-900 dark:text-gray-100 placeholder-gray-400 dark:placeholder-gray-500 focus:outline-none focus:ring focus:ring-primary focus:border-primary disabled:bg-gray-100 dark:disabled:bg-gray-700 disabled:cursor-not-allowed cursor-pointer",
106
+ dropdown: "absolute z-50 mt-2 p-4 bg-white dark:bg-gray-800 border border-gray-300 dark:border-gray-600 rounded-lg shadow-lg w-80",
107
+ picker: "absolute z-50 mt-2 p-4 bg-white dark:bg-gray-800 border border-gray-300 dark:border-gray-600 rounded-lg shadow-lg w-80",
108
+ calendar: "grid grid-cols-7 gap-1 mb-4",
109
+ day: "p-2 text-sm rounded hover:bg-primary hover:text-white transition-colors text-gray-700 dark:text-gray-300",
110
+ daySelected: "bg-primary text-white",
111
+ dayButton: "p-2 text-sm rounded hover:bg-primary hover:text-white transition-colors text-gray-700 dark:text-gray-300",
112
+ dayButtonSelected: "bg-primary text-white",
113
+ timeInput: "w-14 px-2 py-1 text-center border border-gray-300 dark:border-gray-600 rounded bg-white dark:bg-gray-700 text-gray-900 dark:text-gray-100",
114
+ timeLabel: "text-xs font-medium text-gray-700 dark:text-gray-300",
115
+ periodButton: "px-3 py-1 text-xs rounded bg-gray-100 dark:bg-gray-700 text-gray-700 dark:text-gray-300",
116
+ periodButtonActive: "bg-primary text-white",
117
+ iconButton: "absolute right-2 top-1/2 -translate-y-1/2 text-gray-500 dark:text-gray-400",
118
+ navButton: "p-1 hover:bg-gray-100 dark:hover:bg-gray-700 rounded text-gray-700 dark:text-white",
119
+ monthYear: "text-sm font-medium text-gray-900 dark:text-gray-100",
120
+ weekday: "text-center text-xs font-medium text-gray-500 dark:text-gray-400 p-2",
121
+ formatButton: "px-2 py-1 text-xs bg-gray-100 dark:bg-gray-700 text-gray-700 dark:text-gray-300 rounded hover:bg-gray-200 dark:hover:bg-gray-600"
122
+ },
123
+ button: {
124
+ primary: "flex-1 px-3 py-2 text-sm bg-primary text-white rounded hover:bg-primary-dark focus:outline-none focus:ring-2 focus:ring-primary focus:ring-offset-2",
125
+ secondary: "flex-1 px-3 py-2 text-sm border border-gray-300 dark:border-gray-600 rounded hover:bg-gray-50 dark:hover:bg-gray-700 text-gray-700 dark:text-gray-300"
126
+ },
127
+ readonly: "mt-1 block w-full px-3 py-2 border border-gray-300 dark:border-gray-600 rounded-md shadow-sm bg-gray-100 dark:bg-gray-700 text-gray-900 dark:text-gray-100",
128
+ none: {
129
+ container: "form-group",
130
+ label: "block text-sm font-medium text-gray-700 dark:text-gray-300",
131
+ value: "mt-1 block w-full px-3 py-2 border border-gray-300 dark:border-gray-600 rounded-md shadow-sm bg-gray-100 dark:bg-gray-700 text-gray-900 dark:text-gray-100"
132
+ }
133
+ };
134
+ var defaultLabels = {
135
+ required: "*",
136
+ loading: "Loading...",
137
+ fileUpload: {
138
+ clickToUpload: "Click to upload",
139
+ dragAndDrop: "or drag and drop",
140
+ allowedTypes: "Allowed types:",
141
+ maxSize: "Max size:"
142
+ },
143
+ datetime: {
144
+ clear: "Clear",
145
+ done: "Done",
146
+ timeFormat: "Time Format"
147
+ },
148
+ select: {
149
+ loading: "Loading options...",
150
+ noOptions: "No options available"
151
+ }
152
+ };
153
+ var ThemeContext = react.createContext({
154
+ theme: defaultTheme,
155
+ labels: defaultLabels
156
+ });
157
+ function useFormTheme() {
158
+ const { theme } = react.useContext(ThemeContext);
159
+ return theme;
160
+ }
161
+ function useFormLabels() {
162
+ const { labels } = react.useContext(ThemeContext);
163
+ return labels;
164
+ }
165
+ function cx(...classes) {
166
+ return classes.filter(Boolean).join(" ");
167
+ }
168
+ function Alert({ type, message, className = "" }) {
169
+ const theme = useFormTheme();
170
+ const alertClass = theme.alert?.[type] ?? "";
171
+ return /* @__PURE__ */ jsxRuntime.jsx(
172
+ "div",
173
+ {
174
+ className: cx(theme.alert?.base, alertClass, className),
175
+ role: "alert",
176
+ children: message
177
+ }
178
+ );
179
+ }
180
+ var Alert_default = react.memo(Alert);
181
+ function DateTimeInput({
182
+ label,
183
+ name,
184
+ placeholder,
185
+ defaultValue,
186
+ className,
187
+ disabled,
188
+ error,
189
+ rules,
190
+ before,
191
+ beforeClassName,
192
+ after,
193
+ afterClassName
194
+ }) {
195
+ const [selectedDate, setSelectedDate] = react.useState(null);
196
+ const [displayValue, setDisplayValue] = react.useState("");
197
+ const [showPicker, setShowPicker] = react.useState(false);
198
+ const [currentMonth, setCurrentMonth] = react.useState(/* @__PURE__ */ new Date());
199
+ const [hours, setHours] = react.useState("12");
200
+ const [minutes, setMinutes] = react.useState("00");
201
+ const [period, setPeriod] = react.useState("PM");
202
+ const [use24Hour, setUse24Hour] = react.useState(true);
203
+ const pickerRef = react.useRef(null);
204
+ const theme = useFormTheme();
205
+ const labels = useFormLabels();
206
+ react.useEffect(() => {
207
+ if (defaultValue) {
208
+ const date = new Date(defaultValue.toString());
209
+ if (!isNaN(date.getTime())) {
210
+ setSelectedDate(date);
211
+ setCurrentMonth(date);
212
+ updateDisplayValue(date);
213
+ const h24 = date.getHours();
214
+ const m = date.getMinutes();
215
+ const p = h24 >= 12 ? "PM" : "AM";
216
+ const h12 = h24 % 12 || 12;
217
+ if (use24Hour) {
218
+ setHours(String(h24).padStart(2, "0"));
219
+ } else {
220
+ setHours(String(h12).padStart(2, "0"));
221
+ }
222
+ setMinutes(String(m).padStart(2, "0"));
223
+ setPeriod(p);
224
+ }
225
+ }
226
+ }, [defaultValue, use24Hour]);
227
+ react.useEffect(() => {
228
+ const handleClickOutside = (event) => {
229
+ if (pickerRef.current && !pickerRef.current.contains(event.target)) {
230
+ setShowPicker(false);
231
+ }
232
+ };
233
+ if (showPicker) {
234
+ document.addEventListener("mousedown", handleClickOutside);
235
+ }
236
+ return () => {
237
+ document.removeEventListener("mousedown", handleClickOutside);
238
+ };
239
+ }, [showPicker]);
240
+ const updateDisplayValue = (date) => {
241
+ setDisplayValue(date.toLocaleString());
242
+ };
243
+ const getDaysInMonth = (date) => {
244
+ const year = date.getFullYear();
245
+ const month = date.getMonth();
246
+ const firstDay = new Date(year, month, 1);
247
+ const lastDay = new Date(year, month + 1, 0);
248
+ const daysInMonth = lastDay.getDate();
249
+ const startingDayOfWeek = firstDay.getDay();
250
+ return { daysInMonth, startingDayOfWeek };
251
+ };
252
+ const handleDateSelect = (day) => {
253
+ let hour24 = parseInt(hours, 10);
254
+ if (!use24Hour) {
255
+ if (period === "PM" && hour24 !== 12) hour24 += 12;
256
+ if (period === "AM" && hour24 === 12) hour24 = 0;
257
+ }
258
+ const newDate = new Date(
259
+ currentMonth.getFullYear(),
260
+ currentMonth.getMonth(),
261
+ day,
262
+ hour24,
263
+ parseInt(minutes, 10)
264
+ );
265
+ setSelectedDate(newDate);
266
+ updateDisplayValue(newDate);
267
+ };
268
+ const handleTimeChange = () => {
269
+ if (selectedDate) {
270
+ const newDate = new Date(selectedDate);
271
+ let h = parseInt(hours, 10);
272
+ if (!use24Hour) {
273
+ if (period === "PM" && h !== 12) h += 12;
274
+ if (period === "AM" && h === 12) h = 0;
275
+ }
276
+ newDate.setHours(h, parseInt(minutes, 10));
277
+ setSelectedDate(newDate);
278
+ updateDisplayValue(newDate);
279
+ }
280
+ };
281
+ const changeMonth = (offset) => {
282
+ setCurrentMonth(
283
+ (prev) => new Date(prev.getFullYear(), prev.getMonth() + offset, 1)
284
+ );
285
+ };
286
+ const renderCalendar = () => {
287
+ const { daysInMonth, startingDayOfWeek } = getDaysInMonth(currentMonth);
288
+ const days = [];
289
+ for (let i = 0; i < startingDayOfWeek; i++) {
290
+ days.push(/* @__PURE__ */ jsxRuntime.jsx("div", { className: "p-2" }, `empty-${i}`));
291
+ }
292
+ for (let day = 1; day <= daysInMonth; day++) {
293
+ const isSelected = selectedDate && selectedDate.getDate() === day && selectedDate.getMonth() === currentMonth.getMonth() && selectedDate.getFullYear() === currentMonth.getFullYear();
294
+ days.push(
295
+ /* @__PURE__ */ jsxRuntime.jsx(
296
+ "button",
297
+ {
298
+ type: "button",
299
+ onClick: () => handleDateSelect(day),
300
+ className: cx(
301
+ theme.datetime?.day,
302
+ isSelected && theme.datetime?.daySelected
303
+ ),
304
+ children: day
305
+ },
306
+ day
307
+ )
308
+ );
309
+ }
310
+ return days;
311
+ };
312
+ return /* @__PURE__ */ jsxRuntime.jsxs("div", { className: cx(theme.formGroup, className), ref: pickerRef, children: [
313
+ before && /* @__PURE__ */ jsxRuntime.jsx("p", { className: beforeClassName ?? "", children: before }),
314
+ /* @__PURE__ */ jsxRuntime.jsxs("label", { htmlFor: name, className: theme.label?.base, children: [
315
+ label,
316
+ " ",
317
+ rules?.required && /* @__PURE__ */ jsxRuntime.jsx("span", { className: theme.label?.required, children: "*" })
318
+ ] }),
319
+ /* @__PURE__ */ jsxRuntime.jsxs("div", { className: "relative mt-1", children: [
320
+ /* @__PURE__ */ jsxRuntime.jsx(
321
+ "input",
322
+ {
323
+ type: "text",
324
+ value: displayValue,
325
+ placeholder,
326
+ readOnly: true,
327
+ onFocus: () => !disabled && setShowPicker(true),
328
+ onClick: () => !disabled && setShowPicker(true),
329
+ className: cx(
330
+ theme.datetime?.input,
331
+ error && theme.input?.error
332
+ )
333
+ }
334
+ ),
335
+ /* @__PURE__ */ jsxRuntime.jsx(
336
+ "button",
337
+ {
338
+ type: "button",
339
+ onClick: () => !disabled && setShowPicker(true),
340
+ disabled,
341
+ className: theme.datetime?.iconButton,
342
+ children: /* @__PURE__ */ jsxRuntime.jsx(lucideReact.Calendar, { className: "h-5 w-5" })
343
+ }
344
+ ),
345
+ /* @__PURE__ */ jsxRuntime.jsx(
346
+ "input",
347
+ {
348
+ type: "hidden",
349
+ name,
350
+ id: name,
351
+ value: selectedDate ? selectedDate.toISOString() : "",
352
+ "aria-invalid": !!error,
353
+ "aria-describedby": error ? `${name}-error` : void 0
354
+ }
355
+ ),
356
+ showPicker && /* @__PURE__ */ jsxRuntime.jsxs("div", { className: theme.datetime?.dropdown, children: [
357
+ /* @__PURE__ */ jsxRuntime.jsxs("div", { className: "flex items-center justify-between mb-4", children: [
358
+ /* @__PURE__ */ jsxRuntime.jsx(
359
+ "button",
360
+ {
361
+ type: "button",
362
+ onClick: () => changeMonth(-1),
363
+ className: theme.datetime?.navButton,
364
+ children: /* @__PURE__ */ jsxRuntime.jsx(lucideReact.ChevronLeft, { className: "w-5 h-5" })
365
+ }
366
+ ),
367
+ /* @__PURE__ */ jsxRuntime.jsx("span", { className: theme.datetime?.monthYear, children: currentMonth.toLocaleDateString("en-GB", {
368
+ month: "long",
369
+ year: "numeric"
370
+ }) }),
371
+ /* @__PURE__ */ jsxRuntime.jsx(
372
+ "button",
373
+ {
374
+ type: "button",
375
+ onClick: () => changeMonth(1),
376
+ className: theme.datetime?.navButton,
377
+ children: /* @__PURE__ */ jsxRuntime.jsx(lucideReact.ChevronRight, { className: "w-5 h-5" })
378
+ }
379
+ )
380
+ ] }),
381
+ /* @__PURE__ */ jsxRuntime.jsx("div", { className: "grid grid-cols-7 gap-1 mb-2", children: (labels.datetime?.weekdays ?? [
382
+ "Su",
383
+ "Mo",
384
+ "Tu",
385
+ "We",
386
+ "Th",
387
+ "Fr",
388
+ "Sa"
389
+ ]).map((day) => /* @__PURE__ */ jsxRuntime.jsx(
390
+ "div",
391
+ {
392
+ className: theme.datetime?.weekday,
393
+ children: day
394
+ },
395
+ day
396
+ )) }),
397
+ /* @__PURE__ */ jsxRuntime.jsx("div", { className: "grid grid-cols-7 gap-1 mb-4", children: renderCalendar() }),
398
+ /* @__PURE__ */ jsxRuntime.jsxs("div", { className: "border-t border-gray-200 dark:border-gray-700 pt-4", children: [
399
+ /* @__PURE__ */ jsxRuntime.jsxs("div", { className: "flex items-center justify-between mb-3", children: [
400
+ /* @__PURE__ */ jsxRuntime.jsx("span", { className: theme.datetime?.timeLabel, children: labels.datetime?.timeFormat }),
401
+ /* @__PURE__ */ jsxRuntime.jsx(
402
+ "button",
403
+ {
404
+ type: "button",
405
+ onClick: () => {
406
+ const newFormat = !use24Hour;
407
+ setUse24Hour(newFormat);
408
+ if (selectedDate) {
409
+ const h24 = selectedDate.getHours();
410
+ if (newFormat) {
411
+ setHours(
412
+ String(h24).padStart(2, "0")
413
+ );
414
+ } else {
415
+ const h12 = h24 % 12 || 12;
416
+ setHours(
417
+ String(h12).padStart(2, "0")
418
+ );
419
+ setPeriod(
420
+ h24 >= 12 ? "PM" : "AM"
421
+ );
422
+ }
423
+ }
424
+ },
425
+ className: theme.datetime?.formatButton,
426
+ children: use24Hour ? "24hr" : "12hr"
427
+ }
428
+ )
429
+ ] }),
430
+ /* @__PURE__ */ jsxRuntime.jsxs("div", { className: "flex items-center justify-center gap-2", children: [
431
+ /* @__PURE__ */ jsxRuntime.jsx(lucideReact.Clock, { className: "h-4 w-4 text-gray-500 dark:text-gray-400" }),
432
+ /* @__PURE__ */ jsxRuntime.jsx(
433
+ "input",
434
+ {
435
+ type: "number",
436
+ min: use24Hour ? "0" : "1",
437
+ max: use24Hour ? "23" : "12",
438
+ value: hours,
439
+ onChange: (e) => {
440
+ const val = parseInt(e.target.value, 10);
441
+ const max = use24Hour ? 23 : 12;
442
+ const min = use24Hour ? 0 : 1;
443
+ if (val >= min && val <= max) {
444
+ setHours(
445
+ e.target.value.padStart(2, "0")
446
+ );
447
+ handleTimeChange();
448
+ }
449
+ },
450
+ className: theme.datetime?.timeInput
451
+ }
452
+ ),
453
+ /* @__PURE__ */ jsxRuntime.jsx("span", { className: "text-gray-900 dark:text-gray-100", children: ":" }),
454
+ /* @__PURE__ */ jsxRuntime.jsx(
455
+ "input",
456
+ {
457
+ type: "number",
458
+ min: "0",
459
+ max: "59",
460
+ value: minutes,
461
+ onChange: (e) => {
462
+ const val = parseInt(e.target.value, 10);
463
+ if (val >= 0 && val <= 59) {
464
+ setMinutes(
465
+ e.target.value.padStart(2, "0")
466
+ );
467
+ handleTimeChange();
468
+ }
469
+ },
470
+ className: theme.datetime?.timeInput
471
+ }
472
+ ),
473
+ !use24Hour && /* @__PURE__ */ jsxRuntime.jsxs("div", { className: "flex gap-1", children: [
474
+ /* @__PURE__ */ jsxRuntime.jsx(
475
+ "button",
476
+ {
477
+ type: "button",
478
+ onClick: () => {
479
+ setPeriod("AM");
480
+ handleTimeChange();
481
+ },
482
+ className: cx(
483
+ theme.datetime?.periodButton,
484
+ period === "AM" && theme.datetime?.periodButtonActive
485
+ ),
486
+ children: "AM"
487
+ }
488
+ ),
489
+ /* @__PURE__ */ jsxRuntime.jsx(
490
+ "button",
491
+ {
492
+ type: "button",
493
+ onClick: () => {
494
+ setPeriod("PM");
495
+ handleTimeChange();
496
+ },
497
+ className: cx(
498
+ theme.datetime?.periodButton,
499
+ period === "PM" && theme.datetime?.periodButtonActive
500
+ ),
501
+ children: "PM"
502
+ }
503
+ )
504
+ ] })
505
+ ] })
506
+ ] }),
507
+ /* @__PURE__ */ jsxRuntime.jsxs("div", { className: "flex gap-2 mt-4", children: [
508
+ /* @__PURE__ */ jsxRuntime.jsx(
509
+ "button",
510
+ {
511
+ type: "button",
512
+ onClick: () => {
513
+ setSelectedDate(null);
514
+ setDisplayValue("");
515
+ setShowPicker(false);
516
+ },
517
+ className: theme.button?.secondary,
518
+ children: labels.datetime?.clear
519
+ }
520
+ ),
521
+ /* @__PURE__ */ jsxRuntime.jsx(
522
+ "button",
523
+ {
524
+ type: "button",
525
+ onClick: () => setShowPicker(false),
526
+ className: theme.button?.primary,
527
+ children: labels.datetime?.done
528
+ }
529
+ )
530
+ ] })
531
+ ] })
532
+ ] }),
533
+ error && /* @__PURE__ */ jsxRuntime.jsx("p", { id: `${name}-error`, className: theme.error, children: error }),
534
+ after && /* @__PURE__ */ jsxRuntime.jsx("p", { className: afterClassName ?? "", children: after })
535
+ ] });
536
+ }
537
+ var DateTimeInput_default = react.memo(DateTimeInput);
538
+ function TextInput({
539
+ label,
540
+ placeholder,
541
+ name,
542
+ defaultValue,
543
+ className,
544
+ disabled,
545
+ error,
546
+ rules,
547
+ type = "text",
548
+ before,
549
+ beforeClassName,
550
+ after,
551
+ afterClassName
552
+ }) {
553
+ const [passwordVisible, setPasswordVisible] = react.useState(false);
554
+ const theme = useFormTheme();
555
+ const onTogglePassword = () => {
556
+ setPasswordVisible((prev) => !prev);
557
+ };
558
+ return /* @__PURE__ */ jsxRuntime.jsxs("div", { className: cx(theme.formGroup, className), children: [
559
+ before && /* @__PURE__ */ jsxRuntime.jsx("p", { className: beforeClassName ?? "", children: before }),
560
+ /* @__PURE__ */ jsxRuntime.jsxs("label", { htmlFor: name, className: theme.label?.base, children: [
561
+ label,
562
+ rules?.required && /* @__PURE__ */ jsxRuntime.jsx("span", { className: theme.label?.required, children: "*" })
563
+ ] }),
564
+ /* @__PURE__ */ jsxRuntime.jsxs("div", { className: "relative mt-1", children: [
565
+ /* @__PURE__ */ jsxRuntime.jsx(
566
+ "input",
567
+ {
568
+ type: type === "password" ? passwordVisible ? "text" : "password" : type,
569
+ name,
570
+ id: name,
571
+ placeholder,
572
+ defaultValue: defaultValue?.toString(),
573
+ disabled,
574
+ "aria-invalid": !!error,
575
+ "aria-describedby": error ? `${name}-error` : void 0,
576
+ className: cx(
577
+ theme.input?.base,
578
+ error && theme.input?.error,
579
+ theme.input?.disabled
580
+ )
581
+ }
582
+ ),
583
+ type === "password" && /* @__PURE__ */ jsxRuntime.jsxs(
584
+ "button",
585
+ {
586
+ type: "button",
587
+ onClick: onTogglePassword,
588
+ className: "absolute right-2 top-1/2 -translate-y-1/2 text-gray-500 hover:text-gray-700 dark:text-gray-400 dark:hover:text-gray-200 z-10",
589
+ "aria-label": passwordVisible ? "Hide password" : "Show password",
590
+ children: [
591
+ passwordVisible ? /* @__PURE__ */ jsxRuntime.jsx(lucideReact.Eye, { className: "h-5 w-5" }) : /* @__PURE__ */ jsxRuntime.jsx(lucideReact.EyeOff, { className: "h-5 w-5 opacity-50" }),
592
+ /* @__PURE__ */ jsxRuntime.jsx("span", { className: "sr-only", children: passwordVisible ? "Hide password" : "Show password" })
593
+ ]
594
+ }
595
+ )
596
+ ] }),
597
+ error && /* @__PURE__ */ jsxRuntime.jsx("p", { id: `${name}-error`, className: theme.error, children: error }),
598
+ after && /* @__PURE__ */ jsxRuntime.jsx("p", { className: afterClassName ?? "", children: after })
599
+ ] });
600
+ }
601
+ var TextInput_default = react.memo(TextInput);
602
+ function SelectInput({
603
+ label,
604
+ name,
605
+ options,
606
+ defaultValue,
607
+ className,
608
+ disabled,
609
+ error,
610
+ rules,
611
+ before,
612
+ beforeClassName,
613
+ after,
614
+ afterClassName
615
+ }) {
616
+ const theme = useFormTheme();
617
+ const labels = useFormLabels();
618
+ return /* @__PURE__ */ jsxRuntime.jsxs("div", { className: cx(theme.formGroup, className), children: [
619
+ before && /* @__PURE__ */ jsxRuntime.jsx("p", { className: beforeClassName ?? "", children: before }),
620
+ /* @__PURE__ */ jsxRuntime.jsxs("label", { htmlFor: name, className: theme.label?.base, children: [
621
+ label,
622
+ rules?.required && /* @__PURE__ */ jsxRuntime.jsx("span", { className: theme.label?.required, children: "*" })
623
+ ] }),
624
+ /* @__PURE__ */ jsxRuntime.jsx(
625
+ "select",
626
+ {
627
+ name,
628
+ id: name,
629
+ defaultValue: defaultValue?.toString(),
630
+ disabled,
631
+ "aria-invalid": !!error,
632
+ "aria-describedby": error ? `${name}-error` : void 0,
633
+ className: cx(
634
+ theme.select?.base,
635
+ error && theme.select?.error
636
+ ),
637
+ children: !options || options.length === 0 ? /* @__PURE__ */ jsxRuntime.jsx("option", { value: "", disabled: true, className: theme.select?.option, children: !options ? labels.select?.loading : labels.select?.noOptions }) : options.map((option) => /* @__PURE__ */ jsxRuntime.jsx(
638
+ "option",
639
+ {
640
+ value: option.value,
641
+ className: theme.select?.option,
642
+ children: option.label
643
+ },
644
+ option.value
645
+ ))
646
+ }
647
+ ),
648
+ error && /* @__PURE__ */ jsxRuntime.jsx("p", { id: `${name}-error`, className: theme.error, children: error }),
649
+ after && /* @__PURE__ */ jsxRuntime.jsx("p", { className: afterClassName ?? "", children: after })
650
+ ] });
651
+ }
652
+ var SelectInput_default = react.memo(SelectInput);
653
+ function TextAreaInput({
654
+ label,
655
+ name,
656
+ placeholder,
657
+ defaultValue,
658
+ className,
659
+ disabled,
660
+ error,
661
+ rules,
662
+ before,
663
+ beforeClassName,
664
+ after,
665
+ afterClassName
666
+ }) {
667
+ const theme = useFormTheme();
668
+ return /* @__PURE__ */ jsxRuntime.jsxs("div", { className: cx(theme.formGroup, className), children: [
669
+ before && /* @__PURE__ */ jsxRuntime.jsx("p", { className: beforeClassName ?? "", children: before }),
670
+ /* @__PURE__ */ jsxRuntime.jsxs("label", { htmlFor: name, className: theme.label?.base, children: [
671
+ label,
672
+ rules?.required && /* @__PURE__ */ jsxRuntime.jsx("span", { className: theme.label?.required, children: "*" })
673
+ ] }),
674
+ /* @__PURE__ */ jsxRuntime.jsx(
675
+ "textarea",
676
+ {
677
+ name,
678
+ id: name,
679
+ placeholder,
680
+ defaultValue: defaultValue?.toString(),
681
+ disabled,
682
+ "aria-invalid": !!error,
683
+ "aria-describedby": error ? `${name}-error` : void 0,
684
+ className: cx(
685
+ theme.textarea?.base,
686
+ error && theme.textarea?.error
687
+ ),
688
+ rows: 4
689
+ }
690
+ ),
691
+ error && /* @__PURE__ */ jsxRuntime.jsx("p", { id: `${name}-error`, className: theme.error, children: error }),
692
+ after && /* @__PURE__ */ jsxRuntime.jsx("p", { className: afterClassName ?? "", children: after })
693
+ ] });
694
+ }
695
+ var TextAreaInput_default = react.memo(TextAreaInput);
696
+ function CheckboxInput({
697
+ label,
698
+ name,
699
+ defaultChecked,
700
+ className,
701
+ disabled,
702
+ error,
703
+ rules,
704
+ before,
705
+ beforeClassName,
706
+ after,
707
+ afterClassName
708
+ }) {
709
+ const theme = useFormTheme();
710
+ return /* @__PURE__ */ jsxRuntime.jsxs("div", { className: cx(theme.formGroup, className), children: [
711
+ before && /* @__PURE__ */ jsxRuntime.jsx("p", { className: beforeClassName ?? "", children: before }),
712
+ /* @__PURE__ */ jsxRuntime.jsxs("div", { className: "flex items-center", children: [
713
+ /* @__PURE__ */ jsxRuntime.jsx(
714
+ "input",
715
+ {
716
+ type: "checkbox",
717
+ name,
718
+ id: name,
719
+ defaultChecked,
720
+ disabled,
721
+ "aria-invalid": !!error,
722
+ "aria-describedby": error ? `${name}-error` : void 0,
723
+ className: cx(
724
+ theme.checkbox?.base,
725
+ error && theme.checkbox?.error
726
+ )
727
+ }
728
+ ),
729
+ /* @__PURE__ */ jsxRuntime.jsxs("label", { htmlFor: name, className: theme.checkbox?.label, children: [
730
+ label,
731
+ rules?.required && /* @__PURE__ */ jsxRuntime.jsx("span", { className: theme.label?.required, children: "*" })
732
+ ] })
733
+ ] }),
734
+ error && /* @__PURE__ */ jsxRuntime.jsx("p", { id: `${name}-error`, className: theme.error, children: error }),
735
+ after && /* @__PURE__ */ jsxRuntime.jsx("p", { className: afterClassName ?? "", children: after })
736
+ ] });
737
+ }
738
+ var CheckboxInput_default = react.memo(CheckboxInput);
739
+ function ToggleInput({
740
+ label,
741
+ name,
742
+ defaultChecked,
743
+ className,
744
+ disabled,
745
+ error,
746
+ rules,
747
+ before,
748
+ beforeClassName,
749
+ after,
750
+ afterClassName
751
+ }) {
752
+ const theme = useFormTheme();
753
+ return /* @__PURE__ */ jsxRuntime.jsxs("div", { className: cx(theme.formGroup, className), children: [
754
+ before && /* @__PURE__ */ jsxRuntime.jsx("p", { className: beforeClassName ?? "", children: before }),
755
+ /* @__PURE__ */ jsxRuntime.jsxs("div", { className: "flex items-center justify-between", children: [
756
+ /* @__PURE__ */ jsxRuntime.jsxs("label", { htmlFor: name, className: theme.toggle?.label, children: [
757
+ label,
758
+ rules?.required && /* @__PURE__ */ jsxRuntime.jsx("span", { className: theme.label?.required, children: "*" })
759
+ ] }),
760
+ /* @__PURE__ */ jsxRuntime.jsxs(
761
+ "label",
762
+ {
763
+ htmlFor: name,
764
+ className: "relative inline-block w-11 h-6 cursor-pointer",
765
+ children: [
766
+ /* @__PURE__ */ jsxRuntime.jsx(
767
+ "input",
768
+ {
769
+ type: "checkbox",
770
+ name,
771
+ id: name,
772
+ defaultChecked,
773
+ disabled,
774
+ "aria-invalid": !!error,
775
+ "aria-describedby": error ? `${name}-error` : void 0,
776
+ className: "sr-only peer"
777
+ }
778
+ ),
779
+ /* @__PURE__ */ jsxRuntime.jsx(
780
+ "span",
781
+ {
782
+ className: cx(
783
+ theme.toggle?.track,
784
+ !disabled && theme.toggle?.trackActive,
785
+ disabled && "cursor-not-allowed"
786
+ )
787
+ }
788
+ ),
789
+ /* @__PURE__ */ jsxRuntime.jsx("span", { className: theme.toggle?.thumb })
790
+ ]
791
+ }
792
+ )
793
+ ] }),
794
+ error && /* @__PURE__ */ jsxRuntime.jsx("p", { id: `${name}-error`, className: theme.error, children: error }),
795
+ after && /* @__PURE__ */ jsxRuntime.jsx("p", { className: afterClassName ?? "", children: after })
796
+ ] });
797
+ }
798
+ var ToggleInput_default = react.memo(ToggleInput);
799
+ function RadioInput({
800
+ label,
801
+ name,
802
+ options,
803
+ defaultValue,
804
+ className,
805
+ disabled,
806
+ error,
807
+ rules,
808
+ before,
809
+ beforeClassName,
810
+ after,
811
+ afterClassName
812
+ }) {
813
+ const theme = useFormTheme();
814
+ return /* @__PURE__ */ jsxRuntime.jsxs("div", { className: cx(theme.formGroup, className), children: [
815
+ before && /* @__PURE__ */ jsxRuntime.jsx("p", { className: beforeClassName ?? "", children: before }),
816
+ /* @__PURE__ */ jsxRuntime.jsxs("div", { id: `${name}-group`, className: theme.label?.base, children: [
817
+ label,
818
+ rules?.required && /* @__PURE__ */ jsxRuntime.jsx("span", { className: theme.label?.required, children: "*" })
819
+ ] }),
820
+ /* @__PURE__ */ jsxRuntime.jsx(
821
+ "div",
822
+ {
823
+ className: theme.radio?.group,
824
+ role: "radiogroup",
825
+ "aria-labelledby": `${name}-group`,
826
+ children: options?.map((option) => /* @__PURE__ */ jsxRuntime.jsxs("div", { className: "flex items-center mb-2", children: [
827
+ /* @__PURE__ */ jsxRuntime.jsx(
828
+ "input",
829
+ {
830
+ type: "radio",
831
+ name,
832
+ id: `${name}-${option.value}`,
833
+ value: option.value,
834
+ defaultChecked: defaultValue === option.value,
835
+ disabled,
836
+ "aria-invalid": !!error,
837
+ className: theme.radio?.base
838
+ }
839
+ ),
840
+ /* @__PURE__ */ jsxRuntime.jsx(
841
+ "label",
842
+ {
843
+ htmlFor: `${name}-${option.value}`,
844
+ className: theme.radio?.label,
845
+ children: option.label
846
+ }
847
+ )
848
+ ] }, option.value))
849
+ }
850
+ ),
851
+ error && /* @__PURE__ */ jsxRuntime.jsx("p", { id: `${name}-error`, className: theme.error, children: error }),
852
+ after && /* @__PURE__ */ jsxRuntime.jsx("p", { className: afterClassName ?? "", children: after })
853
+ ] });
854
+ }
855
+ var RadioInput_default = react.memo(RadioInput);
856
+
857
+ // src/core/types.ts
858
+ var mimeTypes = {
859
+ JPG: "image/jpeg",
860
+ JPEG: "image/jpeg",
861
+ PNG: "image/png",
862
+ GIF: "image/gif",
863
+ WEBP: "image/webp",
864
+ SVG: "image/svg+xml",
865
+ BMP: "image/bmp",
866
+ TIFF: "image/tiff",
867
+ ICO: "image/x-icon",
868
+ PDF: "application/pdf",
869
+ DOC: "application/msword",
870
+ DOCX: "application/vnd.openxmlformats-officedocument.wordprocessingml.document",
871
+ XLS: "application/vnd.ms-excel",
872
+ XLSX: "application/vnd.openxmlformats-officedocument.spreadsheetml.sheet",
873
+ PPT: "application/vnd.ms-powerpoint",
874
+ PPTX: "application/vnd.openxmlformats-officedocument.presentationml.presentation",
875
+ ZIP: "application/zip",
876
+ RAR: "application/x-rar-compressed",
877
+ "7Z": "application/x-7z-compressed",
878
+ TAR: "application/x-tar",
879
+ GZ: "application/x-gzip",
880
+ BZ2: "application/x-bzip2",
881
+ ISO: "application/x-iso9660-image",
882
+ SWF: "application/x-shockwave-flash",
883
+ TTF: "application/x-font-ttf",
884
+ MP4: "video/mp4",
885
+ MP3: "audio/mpeg",
886
+ MOV: "video/quicktime",
887
+ AVI: "video/x-msvideo",
888
+ WMV: "video/x-ms-wmv",
889
+ MPEG: "video/mpeg",
890
+ TXT: "text/plain",
891
+ CSV: "text/csv"
892
+ };
893
+ function FileInput({
894
+ label,
895
+ name,
896
+ className,
897
+ disabled,
898
+ error,
899
+ rules,
900
+ before,
901
+ beforeClassName,
902
+ after,
903
+ afterClassName,
904
+ defaultValue,
905
+ metaData,
906
+ uploadDir,
907
+ baseUrl
908
+ }) {
909
+ const [fileName, setFileName] = react.useState(null);
910
+ const [isDragging, setIsDragging] = react.useState(false);
911
+ const inputRef = react.useRef(null);
912
+ const theme = useFormTheme();
913
+ const labels = useFormLabels();
914
+ const handleChange = (e) => {
915
+ if (e.target.files && e.target.files.length > 0) {
916
+ setFileName(e.target.files[0].name);
917
+ } else {
918
+ setFileName(null);
919
+ }
920
+ };
921
+ const handleDragEnter = (e) => {
922
+ e.preventDefault();
923
+ e.stopPropagation();
924
+ if (!disabled) setIsDragging(true);
925
+ };
926
+ const handleDragLeave = (e) => {
927
+ e.preventDefault();
928
+ e.stopPropagation();
929
+ setIsDragging(false);
930
+ };
931
+ const handleDragOver = (e) => {
932
+ e.preventDefault();
933
+ e.stopPropagation();
934
+ if (!disabled) setIsDragging(true);
935
+ };
936
+ const handleDrop = (e) => {
937
+ e.preventDefault();
938
+ e.stopPropagation();
939
+ setIsDragging(false);
940
+ if (disabled) return;
941
+ if (e.dataTransfer.files && e.dataTransfer.files.length > 0) {
942
+ if (inputRef.current) {
943
+ inputRef.current.files = e.dataTransfer.files;
944
+ setFileName(e.dataTransfer.files[0].name);
945
+ const event = new Event("change", { bubbles: true });
946
+ inputRef.current.dispatchEvent(event);
947
+ }
948
+ }
949
+ };
950
+ const getFileUrl = () => {
951
+ if (!defaultValue) return null;
952
+ if (baseUrl && uploadDir) {
953
+ return `${baseUrl}/${uploadDir}/${defaultValue}`;
954
+ }
955
+ if (baseUrl) {
956
+ return `${baseUrl}/${defaultValue}`;
957
+ }
958
+ return null;
959
+ };
960
+ const fileUrl = getFileUrl();
961
+ return /* @__PURE__ */ jsxRuntime.jsxs("div", { className: cx(theme.formGroup, className), children: [
962
+ before && /* @__PURE__ */ jsxRuntime.jsx("p", { className: beforeClassName ?? "", children: before }),
963
+ /* @__PURE__ */ jsxRuntime.jsxs("div", { className: cx(theme.label?.base, "mb-1"), children: [
964
+ label,
965
+ rules?.required && /* @__PURE__ */ jsxRuntime.jsx("span", { className: theme.label?.required, children: "*" })
966
+ ] }),
967
+ /* @__PURE__ */ jsxRuntime.jsxs("div", { className: "relative", children: [
968
+ /* @__PURE__ */ jsxRuntime.jsx(
969
+ "input",
970
+ {
971
+ ref: inputRef,
972
+ type: "file",
973
+ name,
974
+ id: name,
975
+ disabled,
976
+ onChange: handleChange,
977
+ "aria-invalid": !!error,
978
+ "aria-describedby": error ? `${name}-error` : void 0,
979
+ className: "sr-only",
980
+ accept: rules?.mimeTypes ? rules.mimeTypes.map((type) => mimeTypes[type]).join(",") : "*"
981
+ }
982
+ ),
983
+ /* @__PURE__ */ jsxRuntime.jsx(
984
+ "label",
985
+ {
986
+ htmlFor: name,
987
+ onDragEnter: handleDragEnter,
988
+ onDragLeave: handleDragLeave,
989
+ onDragOver: handleDragOver,
990
+ onDrop: handleDrop,
991
+ className: cx(
992
+ theme.file?.dropzone,
993
+ disabled && "cursor-not-allowed",
994
+ isDragging && theme.file?.dropzoneActive,
995
+ error && theme.file?.dropzoneError
996
+ ),
997
+ children: /* @__PURE__ */ jsxRuntime.jsxs("div", { className: "flex flex-col items-center justify-center", children: [
998
+ /* @__PURE__ */ jsxRuntime.jsx(
999
+ "svg",
1000
+ {
1001
+ xmlns: "http://www.w3.org/2000/svg",
1002
+ className: theme.file?.icon,
1003
+ fill: "none",
1004
+ viewBox: "0 0 24 24",
1005
+ stroke: "currentColor",
1006
+ children: /* @__PURE__ */ jsxRuntime.jsx(
1007
+ "path",
1008
+ {
1009
+ strokeLinecap: "round",
1010
+ strokeLinejoin: "round",
1011
+ strokeWidth: 2,
1012
+ d: "M7 16a4 4 0 01-.88-7.903A5 5 0 1115.9 6L16 6a5 5 0 011 9.9M15 13l-3-3m0 0l-3 3m3-3v12"
1013
+ }
1014
+ )
1015
+ }
1016
+ ),
1017
+ /* @__PURE__ */ jsxRuntime.jsx("p", { className: theme.file?.text, children: fileName ? /* @__PURE__ */ jsxRuntime.jsx("span", { className: "font-medium text-primary", children: fileName }) : /* @__PURE__ */ jsxRuntime.jsxs(jsxRuntime.Fragment, { children: [
1018
+ /* @__PURE__ */ jsxRuntime.jsx("span", { className: "font-medium", children: labels.fileUpload?.clickToUpload }),
1019
+ " ",
1020
+ labels.fileUpload?.dragAndDrop
1021
+ ] }) }),
1022
+ rules?.mimeTypes && /* @__PURE__ */ jsxRuntime.jsxs("p", { className: theme.file?.hint, children: [
1023
+ labels.fileUpload?.allowedTypes,
1024
+ " ",
1025
+ Object.values(rules.mimeTypes).join(", ")
1026
+ ] }),
1027
+ rules?.maxFileSize && /* @__PURE__ */ jsxRuntime.jsxs("p", { className: theme.file?.hint, children: [
1028
+ labels.fileUpload?.maxSize,
1029
+ " ",
1030
+ Math.round(
1031
+ rules.maxFileSize / 1024 / 1024 * 10
1032
+ ) / 10,
1033
+ " ",
1034
+ "MB"
1035
+ ] })
1036
+ ] })
1037
+ }
1038
+ ),
1039
+ fileUrl && defaultValue && isImage(defaultValue.toString()) && /* @__PURE__ */ jsxRuntime.jsxs(jsxRuntime.Fragment, { children: [
1040
+ /* @__PURE__ */ jsxRuntime.jsx(
1041
+ "img",
1042
+ {
1043
+ src: fileUrl,
1044
+ alt: "",
1045
+ className: "mt-2 max-h-40 object-contain rounded-md border border-gray-300 dark:border-gray-600"
1046
+ }
1047
+ ),
1048
+ /* @__PURE__ */ jsxRuntime.jsxs(
1049
+ "a",
1050
+ {
1051
+ href: fileUrl,
1052
+ target: "_blank",
1053
+ rel: "noopener noreferrer",
1054
+ className: "mt-2 inline-flex items-center text-xs text-primary hover:underline dark:text-gray-50",
1055
+ children: [
1056
+ "View Current ",
1057
+ label,
1058
+ /* @__PURE__ */ jsxRuntime.jsx(
1059
+ "svg",
1060
+ {
1061
+ xmlns: "http://www.w3.org/2000/svg",
1062
+ className: "ml-1 h-4 w-4",
1063
+ fill: "none",
1064
+ viewBox: "0 0 24 24",
1065
+ stroke: "currentColor",
1066
+ children: /* @__PURE__ */ jsxRuntime.jsx(
1067
+ "path",
1068
+ {
1069
+ strokeLinecap: "round",
1070
+ strokeLinejoin: "round",
1071
+ strokeWidth: 2,
1072
+ d: "M10 6H6a2 2 0 00-2 2v10a2 2 0 002 2h10a2 2 0 002-2v-4M14 4h6m0 0v6m0-6L10 14"
1073
+ }
1074
+ )
1075
+ }
1076
+ )
1077
+ ]
1078
+ }
1079
+ )
1080
+ ] })
1081
+ ] }),
1082
+ error && /* @__PURE__ */ jsxRuntime.jsx("p", { id: `${name}-error`, className: theme.error, children: error }),
1083
+ after && /* @__PURE__ */ jsxRuntime.jsx("p", { className: afterClassName ?? "", children: after })
1084
+ ] });
1085
+ }
1086
+ var FileInput_default = react.memo(FileInput);
1087
+ function HiddenInput({
1088
+ name,
1089
+ defaultValue,
1090
+ className,
1091
+ disabled
1092
+ }) {
1093
+ return /* @__PURE__ */ jsxRuntime.jsx(
1094
+ "input",
1095
+ {
1096
+ type: "hidden",
1097
+ name,
1098
+ defaultValue: defaultValue?.toString(),
1099
+ disabled,
1100
+ className
1101
+ }
1102
+ );
1103
+ }
1104
+ function SubmitInput({
1105
+ label,
1106
+ name,
1107
+ className,
1108
+ disabled,
1109
+ loading,
1110
+ defaultValue,
1111
+ hideSpinner
1112
+ }) {
1113
+ const theme = useFormTheme();
1114
+ return /* @__PURE__ */ jsxRuntime.jsxs(
1115
+ "button",
1116
+ {
1117
+ type: "submit",
1118
+ name,
1119
+ disabled: disabled || loading,
1120
+ value: defaultValue?.toString() ?? "",
1121
+ className: cx(
1122
+ theme.submit?.base,
1123
+ loading && theme.submit?.loading,
1124
+ className
1125
+ ),
1126
+ children: [
1127
+ loading && hideSpinner !== true && /* @__PURE__ */ jsxRuntime.jsxs(
1128
+ "svg",
1129
+ {
1130
+ className: theme.submit?.spinner,
1131
+ xmlns: "http://www.w3.org/2000/svg",
1132
+ fill: "none",
1133
+ viewBox: "0 0 24 24",
1134
+ children: [
1135
+ /* @__PURE__ */ jsxRuntime.jsx(
1136
+ "circle",
1137
+ {
1138
+ className: "opacity-25",
1139
+ cx: "12",
1140
+ cy: "12",
1141
+ r: "10",
1142
+ stroke: "currentColor",
1143
+ strokeWidth: "4"
1144
+ }
1145
+ ),
1146
+ /* @__PURE__ */ jsxRuntime.jsx(
1147
+ "path",
1148
+ {
1149
+ className: "opacity-75",
1150
+ fill: "currentColor",
1151
+ d: "M4 12a8 8 0 018-8V0C5.373 0 0 5.373 0 12h4zm2 5.291A7.962 7.962 0 014 12H0c0 3.042 1.135 5.824 3 7.938l3-2.647z"
1152
+ }
1153
+ )
1154
+ ]
1155
+ }
1156
+ ),
1157
+ label
1158
+ ]
1159
+ }
1160
+ );
1161
+ }
1162
+ function NoneInput({ label, value, className }) {
1163
+ const theme = useFormTheme();
1164
+ const isJsonString = (str) => {
1165
+ try {
1166
+ JSON.parse(str);
1167
+ return true;
1168
+ } catch {
1169
+ return false;
1170
+ }
1171
+ };
1172
+ return /* @__PURE__ */ jsxRuntime.jsxs("div", { className: cx(theme.formGroup, className), children: [
1173
+ /* @__PURE__ */ jsxRuntime.jsx("span", { className: theme.label?.base, children: label }),
1174
+ /* @__PURE__ */ jsxRuntime.jsx("div", { className: theme.readonly, children: isJsonString(value) ? /* @__PURE__ */ jsxRuntime.jsx("ul", { className: "list-disc list-inside space-y-1", children: Object.entries(JSON.parse(value)).map(([key, val]) => /* @__PURE__ */ jsxRuntime.jsxs("li", { className: "text-sm", children: [
1175
+ /* @__PURE__ */ jsxRuntime.jsxs("span", { className: "font-medium", children: [
1176
+ key,
1177
+ ":"
1178
+ ] }),
1179
+ " ",
1180
+ String(val)
1181
+ ] }, key)) }) : value })
1182
+ ] });
1183
+ }
1184
+ var NoneInput_default = react.memo(NoneInput);
1185
+ function Form({
1186
+ config,
1187
+ className,
1188
+ errors,
1189
+ isSubmitting = false,
1190
+ formElement: FormElement,
1191
+ formProps = {},
1192
+ fileBaseUrl
1193
+ }) {
1194
+ const theme = useFormTheme();
1195
+ const {
1196
+ method = "post",
1197
+ encType = config.encType || "application/x-www-form-urlencoded",
1198
+ action = "",
1199
+ fields
1200
+ } = config;
1201
+ const state = {
1202
+ errors,
1203
+ isSubmitting
1204
+ };
1205
+ const contextValue = {
1206
+ state,
1207
+ config
1208
+ };
1209
+ const FormTag = FormElement || "form";
1210
+ const formContent = /* @__PURE__ */ jsxRuntime.jsxs(jsxRuntime.Fragment, { children: [
1211
+ errors && "__server" in errors && errors.__server ? /* @__PURE__ */ jsxRuntime.jsx(Alert_default, { type: "error", message: errors.__server }) : null,
1212
+ /* @__PURE__ */ jsxRuntime.jsx(
1213
+ "fieldset",
1214
+ {
1215
+ className: theme.fieldset,
1216
+ disabled: isSubmitting,
1217
+ children: Object.entries(fields).map(([key, field]) => {
1218
+ const fieldError = errors?.[key];
1219
+ switch (field.type) {
1220
+ case "text":
1221
+ case "email":
1222
+ case "password":
1223
+ case "number":
1224
+ return /* @__PURE__ */ jsxRuntime.jsx(
1225
+ TextInput_default,
1226
+ {
1227
+ label: field.label,
1228
+ placeholder: field.placeholder,
1229
+ name: key,
1230
+ defaultValue: field.defaultValue,
1231
+ className: `${widthClasses[field.width || 12]} ${field.className || ""}`,
1232
+ disabled: field.disabled,
1233
+ error: fieldError,
1234
+ rules: field.rules,
1235
+ type: field.type,
1236
+ before: field.before,
1237
+ beforeClassName: field.beforeClassName,
1238
+ after: field.after,
1239
+ afterClassName: field.afterClassName
1240
+ },
1241
+ key
1242
+ );
1243
+ case "datetime":
1244
+ return /* @__PURE__ */ jsxRuntime.jsx(
1245
+ DateTimeInput_default,
1246
+ {
1247
+ label: field.label,
1248
+ placeholder: field.placeholder,
1249
+ name: key,
1250
+ defaultValue: field.defaultValue,
1251
+ className: `${widthClasses[field.width || 12]} ${field.className || ""}`,
1252
+ disabled: field.disabled,
1253
+ error: fieldError,
1254
+ rules: field.rules,
1255
+ before: field.before,
1256
+ beforeClassName: field.beforeClassName,
1257
+ after: field.after,
1258
+ afterClassName: field.afterClassName
1259
+ },
1260
+ key
1261
+ );
1262
+ case "select":
1263
+ return /* @__PURE__ */ jsxRuntime.jsx(
1264
+ SelectInput_default,
1265
+ {
1266
+ label: field.label,
1267
+ name: key,
1268
+ options: field.options,
1269
+ defaultValue: field.defaultValue,
1270
+ className: `${widthClasses[field.width || 12]} ${field.className || ""}`,
1271
+ disabled: field.disabled,
1272
+ error: fieldError,
1273
+ rules: field.rules,
1274
+ before: field.before,
1275
+ beforeClassName: field.beforeClassName,
1276
+ after: field.after,
1277
+ afterClassName: field.afterClassName
1278
+ },
1279
+ key
1280
+ );
1281
+ case "textarea":
1282
+ return /* @__PURE__ */ jsxRuntime.jsx(
1283
+ TextAreaInput_default,
1284
+ {
1285
+ label: field.label,
1286
+ placeholder: field.placeholder,
1287
+ name: key,
1288
+ defaultValue: field.defaultValue,
1289
+ className: `${widthClasses[field.width || 12]} ${field.className || ""}`,
1290
+ disabled: field.disabled,
1291
+ error: fieldError,
1292
+ rules: field.rules,
1293
+ before: field.before,
1294
+ beforeClassName: field.beforeClassName,
1295
+ after: field.after,
1296
+ afterClassName: field.afterClassName
1297
+ },
1298
+ key
1299
+ );
1300
+ case "checkbox":
1301
+ return /* @__PURE__ */ jsxRuntime.jsx(
1302
+ CheckboxInput_default,
1303
+ {
1304
+ label: field.label,
1305
+ name: key,
1306
+ defaultChecked: field.defaultChecked,
1307
+ className: `${widthClasses[field.width || 12]} ${field.className || ""}`,
1308
+ disabled: field.disabled,
1309
+ error: fieldError,
1310
+ rules: field.rules,
1311
+ before: field.before,
1312
+ beforeClassName: field.beforeClassName,
1313
+ after: field.after,
1314
+ afterClassName: field.afterClassName
1315
+ },
1316
+ key
1317
+ );
1318
+ case "toggle":
1319
+ return /* @__PURE__ */ jsxRuntime.jsx(
1320
+ ToggleInput_default,
1321
+ {
1322
+ label: field.label,
1323
+ name: key,
1324
+ defaultChecked: field.defaultChecked,
1325
+ className: `${widthClasses[field.width || 12]} ${field.className || ""}`,
1326
+ disabled: field.disabled,
1327
+ error: fieldError,
1328
+ rules: field.rules,
1329
+ before: field.before,
1330
+ beforeClassName: field.beforeClassName,
1331
+ after: field.after,
1332
+ afterClassName: field.afterClassName
1333
+ },
1334
+ key
1335
+ );
1336
+ case "radio":
1337
+ return /* @__PURE__ */ jsxRuntime.jsx(
1338
+ RadioInput_default,
1339
+ {
1340
+ label: field.label,
1341
+ name: key,
1342
+ options: field.options,
1343
+ defaultValue: field.defaultValue,
1344
+ className: `${widthClasses[field.width || 12]} ${field.className || ""}`,
1345
+ disabled: field.disabled,
1346
+ error: fieldError,
1347
+ rules: field.rules,
1348
+ before: field.before,
1349
+ beforeClassName: field.beforeClassName,
1350
+ after: field.after,
1351
+ afterClassName: field.afterClassName
1352
+ },
1353
+ key
1354
+ );
1355
+ case "file":
1356
+ return /* @__PURE__ */ jsxRuntime.jsx(
1357
+ FileInput_default,
1358
+ {
1359
+ label: field.label,
1360
+ name: key,
1361
+ className: `${widthClasses[field.width || 12]} ${field.className || ""}`,
1362
+ disabled: field.disabled,
1363
+ defaultValue: field.defaultValue,
1364
+ error: fieldError,
1365
+ rules: field.rules,
1366
+ before: field.before,
1367
+ beforeClassName: field.beforeClassName,
1368
+ after: field.after,
1369
+ afterClassName: field.afterClassName,
1370
+ metaData: field.metaData,
1371
+ uploadDir: field.uploadDir,
1372
+ baseUrl: fileBaseUrl
1373
+ },
1374
+ key
1375
+ );
1376
+ case "hidden":
1377
+ return /* @__PURE__ */ jsxRuntime.jsx(
1378
+ HiddenInput,
1379
+ {
1380
+ name: key,
1381
+ defaultValue: field.defaultValue,
1382
+ disabled: field.disabled
1383
+ },
1384
+ key
1385
+ );
1386
+ case "submit":
1387
+ return /* @__PURE__ */ jsxRuntime.jsx(
1388
+ SubmitInput,
1389
+ {
1390
+ label: field.label,
1391
+ name: key,
1392
+ className: `${widthClasses[field.width || 12]} ${field.className || ""}`,
1393
+ disabled: field.disabled,
1394
+ rules: field.rules,
1395
+ loading: isSubmitting,
1396
+ defaultValue: field.defaultValue,
1397
+ hideSpinner: field.hideSpinner
1398
+ },
1399
+ key
1400
+ );
1401
+ case "none":
1402
+ return /* @__PURE__ */ jsxRuntime.jsx(
1403
+ NoneInput_default,
1404
+ {
1405
+ className: `${widthClasses[field.width || 12]} ${field.className || ""}`,
1406
+ value: field.defaultValue?.toString() ?? "",
1407
+ label: field.label
1408
+ },
1409
+ key
1410
+ );
1411
+ default:
1412
+ return null;
1413
+ }
1414
+ })
1415
+ }
1416
+ )
1417
+ ] });
1418
+ return /* @__PURE__ */ jsxRuntime.jsx(FormContext.Provider, { value: contextValue, children: /* @__PURE__ */ jsxRuntime.jsx(
1419
+ FormTag,
1420
+ {
1421
+ method,
1422
+ encType,
1423
+ action,
1424
+ className: cx(theme.form, className),
1425
+ noValidate: true,
1426
+ ...formProps,
1427
+ children: formContent
1428
+ }
1429
+ ) });
1430
+ }
1431
+ function ReactRouterForm({
1432
+ config,
1433
+ className,
1434
+ fileBaseUrl
1435
+ }) {
1436
+ const fetcher = reactRouter.useFetcher({ key: config.key });
1437
+ const errors = fetcher.data?.errors;
1438
+ const isSubmitting = fetcher.state !== "idle";
1439
+ return /* @__PURE__ */ jsxRuntime.jsx(
1440
+ Form,
1441
+ {
1442
+ config,
1443
+ className,
1444
+ errors,
1445
+ isSubmitting,
1446
+ formElement: fetcher.Form,
1447
+ fileBaseUrl
1448
+ }
1449
+ );
1450
+ }
1451
+ function useReactRouterForm(formKey) {
1452
+ const fetcher = reactRouter.useFetcher({ key: formKey });
1453
+ const errors = fetcher.data?.errors;
1454
+ const isSubmitting = fetcher.state !== "idle";
1455
+ return {
1456
+ fetcher,
1457
+ errors,
1458
+ isSubmitting,
1459
+ data: fetcher.data
1460
+ };
1461
+ }
1462
+
1463
+ exports.ReactRouterForm = ReactRouterForm;
1464
+ exports.useReactRouterForm = useReactRouterForm;
1465
+ //# sourceMappingURL=react-router.cjs.map
1466
+ //# sourceMappingURL=react-router.cjs.map