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