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