@sawabona/forms 0.8.0 → 0.9.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
package/README.md
CHANGED
|
@@ -134,6 +134,7 @@ Isso garante que sua lógica permaneça limpa e seu conteúdo seja facilmente ed
|
|
|
134
134
|
| `i18n` | `object` | (Opcional) Tradução de botões e textos fixos. |
|
|
135
135
|
| `autoReload` | `boolean` | (Opcional) Se `true`, reinicia o formulário automaticamente após o envio. |
|
|
136
136
|
| `reloadDelay` | `number` | (Opcional) Tempo em milissegundos para aguardar antes de reiniciar (Padrão: 3000). |
|
|
137
|
+
| `disableAutoFocus` | `boolean` | (Opcional) Desativar scroll automático no carregamento (Padrão: false). |
|
|
137
138
|
|
|
138
139
|
---
|
|
139
140
|
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"TextInput.d.ts","sourceRoot":"","sources":["../../../src/lib/components/ui/TextInput.tsx"],"names":[],"mappings":"AACA,OAAO,KAAK,EAAE,QAAQ,EAAE,MAAM,kBAAkB,CAAC;AAIjD,wBAAgB,SAAS,CAAC,EAAE,QAAQ,EAAE,EAAE;IAAE,QAAQ,EAAE,QAAQ,CAAA;CAAE,
|
|
1
|
+
{"version":3,"file":"TextInput.d.ts","sourceRoot":"","sources":["../../../src/lib/components/ui/TextInput.tsx"],"names":[],"mappings":"AACA,OAAO,KAAK,EAAE,QAAQ,EAAE,MAAM,kBAAkB,CAAC;AAIjD,wBAAgB,SAAS,CAAC,EAAE,QAAQ,EAAE,EAAE;IAAE,QAAQ,EAAE,QAAQ,CAAA;CAAE,2CAgI7D"}
|
package/dist/core/types.d.ts
CHANGED
package/dist/core/types.d.ts.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"types.d.ts","sourceRoot":"","sources":["../../src/lib/core/types.ts"],"names":[],"mappings":"AAEA,MAAM,MAAM,YAAY,GAClB,MAAM,GACN,OAAO,GACP,QAAQ,GACR,KAA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M,EAAE,MAAM,CAAC,CAAC;IAC/B,WAAW,EAAE,OAAO,CAAC;CACxB;AAED,MAAM,WAAW,eAAgB,SAAQ,SAAS;IAC9C,MAAM,EAAE,UAAU,CAAC;IACnB,SAAS,EAAE,CAAC,UAAU,EAAE,MAAM,EAAE,KAAK,EAAE,WAAW,KAAK,IAAI,CAAC;IAC5D,QAAQ,EAAE,MAAM,IAAI,CAAC;IACrB,QAAQ,EAAE,MAAM,IAAI,CAAC;IACrB,UAAU,EAAE,CAAC,MAAM,EAAE,MAAM,KAAK,IAAI,CAAC;IACrC,UAAU,EAAE,MAAM,IAAI,CAAC;IACvB,SAAS,EAAE,MAAM,IAAI,CAAC;IACtB,aAAa,EAAE,CAAC,UAAU,EAAE,MAAM,EAAE,KAAK,EAAE,MAAM,GAAG,IAAI,KAAK,IAAI,CAAC;CACrE"}
|
|
@@ -1,162 +1,164 @@
|
|
|
1
|
-
var
|
|
2
|
-
var
|
|
3
|
-
var
|
|
4
|
-
var
|
|
5
|
-
var
|
|
6
|
-
for (var r in
|
|
7
|
-
|
|
8
|
-
if (
|
|
9
|
-
for (var r of
|
|
10
|
-
|
|
1
|
+
var Q = Object.defineProperty, H = Object.defineProperties;
|
|
2
|
+
var K = Object.getOwnPropertyDescriptors;
|
|
3
|
+
var R = Object.getOwnPropertySymbols;
|
|
4
|
+
var z = Object.prototype.hasOwnProperty, $ = Object.prototype.propertyIsEnumerable;
|
|
5
|
+
var j = (e, i, r) => i in e ? Q(e, i, { enumerable: !0, configurable: !0, writable: !0, value: r }) : e[i] = r, h = (e, i) => {
|
|
6
|
+
for (var r in i || (i = {}))
|
|
7
|
+
z.call(i, r) && j(e, r, i[r]);
|
|
8
|
+
if (R)
|
|
9
|
+
for (var r of R(i))
|
|
10
|
+
$.call(i, r) && j(e, r, i[r]);
|
|
11
11
|
return e;
|
|
12
|
-
},
|
|
13
|
-
var
|
|
12
|
+
}, g = (e, i) => H(e, K(i));
|
|
13
|
+
var B = (e) => typeof e == "symbol" ? e : e + "", _ = (e, i) => {
|
|
14
14
|
var r = {};
|
|
15
15
|
for (var t in e)
|
|
16
|
-
|
|
17
|
-
if (e != null &&
|
|
18
|
-
for (var t of
|
|
19
|
-
|
|
16
|
+
z.call(e, t) && i.indexOf(t) < 0 && (r[t] = e[t]);
|
|
17
|
+
if (e != null && R)
|
|
18
|
+
for (var t of R(e))
|
|
19
|
+
i.indexOf(t) < 0 && $.call(e, t) && (r[t] = e[t]);
|
|
20
20
|
return r;
|
|
21
21
|
};
|
|
22
22
|
import { jsxs as m, jsx as n } from "react/jsx-runtime";
|
|
23
|
-
import { useState as
|
|
24
|
-
import { motion as
|
|
25
|
-
import { Check as
|
|
26
|
-
function
|
|
27
|
-
var
|
|
28
|
-
const [r, t] =
|
|
23
|
+
import { useState as V, useMemo as W, useCallback as S, createContext as M, useContext as U, useRef as G, useEffect as P } from "react";
|
|
24
|
+
import { motion as w, AnimatePresence as X } from "framer-motion";
|
|
25
|
+
import { Check as D, Star as J, ChevronLeft as Y, ChevronRight as Z } from "lucide-react";
|
|
26
|
+
function q({ schema: e, onSubmit: i }) {
|
|
27
|
+
var v;
|
|
28
|
+
const [r, t] = V({
|
|
29
29
|
answers: {},
|
|
30
|
-
currentStepId: ((
|
|
30
|
+
currentStepId: ((v = e.questions[0]) == null ? void 0 : v.id) || "",
|
|
31
31
|
history: [],
|
|
32
32
|
isSubmitting: !1,
|
|
33
33
|
errors: {},
|
|
34
34
|
isCompleted: !1
|
|
35
|
-
}),
|
|
36
|
-
() => e.questions.findIndex((
|
|
35
|
+
}), u = W(
|
|
36
|
+
() => e.questions.findIndex((a) => a.id === r.currentStepId),
|
|
37
37
|
[e.questions, r.currentStepId]
|
|
38
|
-
),
|
|
39
|
-
t((
|
|
40
|
-
answers:
|
|
41
|
-
[
|
|
38
|
+
), s = e.questions[u], p = S((a, o) => {
|
|
39
|
+
t((l) => g(h({}, l), {
|
|
40
|
+
answers: g(h({}, l.answers), {
|
|
41
|
+
[a]: o
|
|
42
42
|
}),
|
|
43
43
|
// Clear error on modification
|
|
44
|
-
errors:
|
|
45
|
-
[
|
|
44
|
+
errors: g(h({}, l.errors), {
|
|
45
|
+
[a]: ""
|
|
46
46
|
})
|
|
47
47
|
}));
|
|
48
|
-
}, []),
|
|
49
|
-
t((
|
|
48
|
+
}, []), d = S((a, o) => {
|
|
49
|
+
t((l) => {
|
|
50
50
|
if (o === null) {
|
|
51
|
-
const
|
|
52
|
-
return
|
|
51
|
+
const F = l.errors, { [a]: N } = F, y = _(F, [B(a)]);
|
|
52
|
+
return g(h({}, l), { errors: y });
|
|
53
53
|
}
|
|
54
|
-
return
|
|
55
|
-
errors:
|
|
54
|
+
return g(h({}, l), {
|
|
55
|
+
errors: g(h({}, l.errors), { [a]: o })
|
|
56
56
|
});
|
|
57
57
|
});
|
|
58
|
-
}, []), c =
|
|
59
|
-
var
|
|
60
|
-
if (!
|
|
61
|
-
const
|
|
62
|
-
return o && o.required && (
|
|
63
|
-
}, [
|
|
64
|
-
const o = e.questions.findIndex((
|
|
58
|
+
}, []), c = S(() => {
|
|
59
|
+
var l;
|
|
60
|
+
if (!s) return !0;
|
|
61
|
+
const a = r.answers[s.id], o = s.validation;
|
|
62
|
+
return o && o.required && (a === void 0 || a === "" || Array.isArray(a) && a.length === 0) ? (d(s.id, ((l = e.i18n) == null ? void 0 : l.required) || "This field is required"), !1) : !0;
|
|
63
|
+
}, [s, r.answers, d, e.i18n]), f = S((a) => {
|
|
64
|
+
const o = e.questions.findIndex((l) => l.id === a.id);
|
|
65
65
|
return o < e.questions.length - 1 ? e.questions[o + 1].id : "submit";
|
|
66
|
-
}, [e.questions]),
|
|
66
|
+
}, [e.questions]), x = S(() => {
|
|
67
67
|
if (!c()) return;
|
|
68
|
-
const
|
|
69
|
-
|
|
68
|
+
const a = f(s);
|
|
69
|
+
a === "submit" ? (t((o) => g(h({}, o), { isCompleted: !0 })), i == null || i(r.answers)) : t((o) => g(h({}, o), {
|
|
70
70
|
history: [...o.history, o.currentStepId],
|
|
71
|
-
currentStepId:
|
|
71
|
+
currentStepId: a
|
|
72
72
|
}));
|
|
73
|
-
}, [
|
|
73
|
+
}, [s, r.answers, c, f, i]), b = S(() => {
|
|
74
74
|
if (r.history.length === 0) return;
|
|
75
|
-
const
|
|
76
|
-
t((o) =>
|
|
75
|
+
const a = r.history[r.history.length - 1];
|
|
76
|
+
t((o) => g(h({}, o), {
|
|
77
77
|
history: o.history.slice(0, -1),
|
|
78
|
-
currentStepId:
|
|
78
|
+
currentStepId: a
|
|
79
79
|
}));
|
|
80
|
-
}, [r.history]),
|
|
81
|
-
if (!e.questions.some((
|
|
82
|
-
console.warn(`Step ${
|
|
80
|
+
}, [r.history]), C = S((a) => {
|
|
81
|
+
if (!e.questions.some((l) => l.id === a)) {
|
|
82
|
+
console.warn(`Step ${a} does not exist`);
|
|
83
83
|
return;
|
|
84
84
|
}
|
|
85
|
-
t((
|
|
86
|
-
history: [...
|
|
87
|
-
currentStepId:
|
|
85
|
+
t((l) => g(h({}, l), {
|
|
86
|
+
history: [...l.history, l.currentStepId],
|
|
87
|
+
currentStepId: a
|
|
88
88
|
}));
|
|
89
|
-
}, [e.questions]),
|
|
90
|
-
var
|
|
89
|
+
}, [e.questions]), I = S(() => {
|
|
90
|
+
var a;
|
|
91
91
|
t({
|
|
92
92
|
answers: {},
|
|
93
|
-
currentStepId: ((
|
|
93
|
+
currentStepId: ((a = e.questions[0]) == null ? void 0 : a.id) || "",
|
|
94
94
|
history: [],
|
|
95
95
|
isSubmitting: !1,
|
|
96
96
|
errors: {},
|
|
97
97
|
isCompleted: !1
|
|
98
98
|
});
|
|
99
99
|
}, [e.questions]);
|
|
100
|
-
return
|
|
101
|
-
setAnswer:
|
|
102
|
-
nextStep:
|
|
103
|
-
prevStep:
|
|
104
|
-
jumpToStep:
|
|
105
|
-
submitForm: () =>
|
|
106
|
-
resetForm:
|
|
107
|
-
registerError:
|
|
100
|
+
return g(h({}, r), {
|
|
101
|
+
setAnswer: p,
|
|
102
|
+
nextStep: x,
|
|
103
|
+
prevStep: b,
|
|
104
|
+
jumpToStep: C,
|
|
105
|
+
submitForm: () => i == null ? void 0 : i(r.answers),
|
|
106
|
+
resetForm: I,
|
|
107
|
+
registerError: d,
|
|
108
108
|
// Helper to calculate progress
|
|
109
|
-
progress:
|
|
109
|
+
progress: u / e.questions.length * 100
|
|
110
110
|
});
|
|
111
111
|
}
|
|
112
|
-
const
|
|
113
|
-
const e =
|
|
112
|
+
const O = M(void 0), L = () => {
|
|
113
|
+
const e = U(O);
|
|
114
114
|
if (!e)
|
|
115
115
|
throw new Error("useFormContext must be used within a FormProvider");
|
|
116
116
|
return e;
|
|
117
117
|
};
|
|
118
|
-
function
|
|
119
|
-
var
|
|
120
|
-
const { answers:
|
|
121
|
-
|
|
122
|
-
|
|
123
|
-
|
|
124
|
-
|
|
125
|
-
|
|
126
|
-
|
|
127
|
-
|
|
128
|
-
|
|
129
|
-
|
|
130
|
-
|
|
131
|
-
|
|
132
|
-
|
|
133
|
-
|
|
134
|
-
|
|
118
|
+
function ee({ question: e }) {
|
|
119
|
+
var v, a, o, l, F;
|
|
120
|
+
const { answers: i, setAnswer: r, nextStep: t, schema: u } = L(), s = i[e.id], p = s != null ? String(s) : "", d = G(null), c = u.questions[0].id === e.id, f = !u.disableAutoFocus || !c;
|
|
121
|
+
P(() => {
|
|
122
|
+
if (f) {
|
|
123
|
+
const N = setTimeout(() => {
|
|
124
|
+
var y;
|
|
125
|
+
(y = d.current) == null || y.focus();
|
|
126
|
+
}, 500);
|
|
127
|
+
return () => clearTimeout(N);
|
|
128
|
+
}
|
|
129
|
+
}, [e.id, f]);
|
|
130
|
+
const x = (N) => {
|
|
131
|
+
var E;
|
|
132
|
+
let y = N.target.value;
|
|
133
|
+
const A = ((E = e.validation) == null ? void 0 : E.maxLength) || 2048;
|
|
134
|
+
if (y.length > A && (y = y.slice(0, A)), e.type === "number") {
|
|
135
|
+
const T = y === "" ? "" : parseFloat(y);
|
|
136
|
+
r(e.id, T);
|
|
135
137
|
} else
|
|
136
|
-
r(e.id,
|
|
137
|
-
},
|
|
138
|
-
var
|
|
139
|
-
if ((
|
|
140
|
-
if (
|
|
141
|
-
if ((
|
|
142
|
-
if ((
|
|
138
|
+
r(e.id, y);
|
|
139
|
+
}, b = () => {
|
|
140
|
+
var N, y, A, E, T;
|
|
141
|
+
if ((N = e.validation) != null && N.required && !p) return !1;
|
|
142
|
+
if (p) {
|
|
143
|
+
if ((y = e.validation) != null && y.minLength && p.length < e.validation.minLength || e.type === "email" && !/^[^\s@]+@[^\s@]+\.[^\s@]+$/.test(p)) return !1;
|
|
144
|
+
if ((A = e.validation) != null && A.pattern)
|
|
143
145
|
try {
|
|
144
|
-
if (!new RegExp(e.validation.pattern).test(
|
|
145
|
-
} catch (
|
|
146
|
-
console.error("Invalid regex pattern in schema",
|
|
146
|
+
if (!new RegExp(e.validation.pattern).test(p)) return !1;
|
|
147
|
+
} catch (k) {
|
|
148
|
+
console.error("Invalid regex pattern in schema", k);
|
|
147
149
|
}
|
|
148
150
|
if (e.type === "number") {
|
|
149
|
-
const
|
|
150
|
-
if (!isNaN(
|
|
151
|
+
const k = parseFloat(p);
|
|
152
|
+
if (!isNaN(k) && (((E = e.validation) == null ? void 0 : E.min) !== void 0 && k < e.validation.min || ((T = e.validation) == null ? void 0 : T.max) !== void 0 && k > e.validation.max))
|
|
151
153
|
return !1;
|
|
152
154
|
}
|
|
153
155
|
}
|
|
154
156
|
return !0;
|
|
155
|
-
},
|
|
156
|
-
if (
|
|
157
|
-
if (
|
|
158
|
-
const
|
|
159
|
-
|
|
157
|
+
}, C = (N) => {
|
|
158
|
+
if (N.key === "Enter" && !N.shiftKey) {
|
|
159
|
+
if (N.preventDefault(), !b()) {
|
|
160
|
+
const y = document.querySelector(".sawabona-form-container") || document.body;
|
|
161
|
+
y.classList.add("shake-animation"), setTimeout(() => y.classList.remove("shake-animation"), 500);
|
|
160
162
|
return;
|
|
161
163
|
}
|
|
162
164
|
t();
|
|
@@ -166,25 +168,24 @@ function Y({ question: e }) {
|
|
|
166
168
|
/* @__PURE__ */ n(
|
|
167
169
|
"input",
|
|
168
170
|
{
|
|
169
|
-
ref:
|
|
171
|
+
ref: d,
|
|
170
172
|
type: e.type,
|
|
171
|
-
value: typeof
|
|
172
|
-
onChange:
|
|
173
|
-
onKeyDown:
|
|
173
|
+
value: typeof p == "string" || typeof p == "number" ? p : "",
|
|
174
|
+
onChange: x,
|
|
175
|
+
onKeyDown: C,
|
|
174
176
|
placeholder: e.placeholder,
|
|
175
|
-
minLength: (
|
|
176
|
-
maxLength: ((
|
|
177
|
-
min: (
|
|
178
|
-
max: (
|
|
179
|
-
pattern: (
|
|
177
|
+
minLength: (v = e.validation) == null ? void 0 : v.minLength,
|
|
178
|
+
maxLength: ((a = e.validation) == null ? void 0 : a.maxLength) || 2048,
|
|
179
|
+
min: (o = e.validation) == null ? void 0 : o.min,
|
|
180
|
+
max: (l = e.validation) == null ? void 0 : l.max,
|
|
181
|
+
pattern: (F = e.validation) == null ? void 0 : F.pattern,
|
|
180
182
|
className: `
|
|
181
183
|
w-full bg-transparent border-b-2 border-sw-text-secondary/20
|
|
182
184
|
py-4 text-2xl md:text-3xl font-medium outline-none transition-colors
|
|
183
185
|
placeholder:text-sw-text-secondary/30
|
|
184
186
|
focus:border-sw-primary
|
|
185
187
|
font-sw-heading
|
|
186
|
-
|
|
187
|
-
autoFocus: !0
|
|
188
|
+
`
|
|
188
189
|
}
|
|
189
190
|
),
|
|
190
191
|
void 0,
|
|
@@ -196,45 +197,45 @@ function Y({ question: e }) {
|
|
|
196
197
|
] })
|
|
197
198
|
] });
|
|
198
199
|
}
|
|
199
|
-
function
|
|
200
|
-
var
|
|
201
|
-
const { answers:
|
|
200
|
+
function te({ question: e }) {
|
|
201
|
+
var d;
|
|
202
|
+
const { answers: i, setAnswer: r, nextStep: t } = L(), u = i[e.id] || "", s = (c) => {
|
|
202
203
|
r(e.id, c), setTimeout(() => t(), 400);
|
|
203
|
-
},
|
|
204
|
-
return
|
|
205
|
-
const c = (
|
|
206
|
-
var
|
|
207
|
-
const
|
|
208
|
-
|
|
204
|
+
}, p = "ABCDEFGHIJKLMNOPQRSTUVWXYZ";
|
|
205
|
+
return P(() => {
|
|
206
|
+
const c = (f) => {
|
|
207
|
+
var C;
|
|
208
|
+
const x = f.key.toUpperCase(), b = p.indexOf(x);
|
|
209
|
+
b >= 0 && b < (((C = e.options) == null ? void 0 : C.length) || 0) && s(e.options[b].value);
|
|
209
210
|
};
|
|
210
211
|
return window.addEventListener("keydown", c), () => window.removeEventListener("keydown", c);
|
|
211
|
-
}, [e.options, e.id]), /* @__PURE__ */ n("div", { className: "flex flex-col gap-3 w-full max-w-xl", children: (
|
|
212
|
-
const
|
|
212
|
+
}, [e.options, e.id]), /* @__PURE__ */ n("div", { className: "flex flex-col gap-3 w-full max-w-xl", children: (d = e.options) == null ? void 0 : d.map((c, f) => {
|
|
213
|
+
const x = Array.isArray(u) ? u.includes(c.value) : u === c.value;
|
|
213
214
|
return /* @__PURE__ */ m(
|
|
214
|
-
|
|
215
|
+
w.button,
|
|
215
216
|
{
|
|
216
217
|
initial: { opacity: 0, y: 10 },
|
|
217
218
|
animate: { opacity: 1, y: 0 },
|
|
218
|
-
transition: { delay:
|
|
219
|
-
onClick: () =>
|
|
219
|
+
transition: { delay: f * 0.05 },
|
|
220
|
+
onClick: () => s(c.value),
|
|
220
221
|
className: `
|
|
221
222
|
w-full text-left p-4 rounded-lg border-2 transition-all duration-200
|
|
222
223
|
flex items-center justify-between group
|
|
223
|
-
${
|
|
224
|
+
${x ? "border-sw-primary bg-sw-primary/5 text-sw-primary" : "border-sw-text-secondary/10 hover:border-sw-primary/50 hover:bg-sw-primary/5"}
|
|
224
225
|
`,
|
|
225
226
|
children: [
|
|
226
227
|
/* @__PURE__ */ m("span", { className: "text-lg font-medium flex items-center gap-3", children: [
|
|
227
228
|
/* @__PURE__ */ n("span", { className: `
|
|
228
229
|
w-6 h-6 rounded-full border-2 flex items-center justify-center transition-colors
|
|
229
|
-
${
|
|
230
|
-
`, children:
|
|
230
|
+
${x ? "border-sw-primary bg-sw-primary" : "border-sw-text-secondary/30 group-hover:border-sw-primary/50"}
|
|
231
|
+
`, children: x && /* @__PURE__ */ n(D, { size: 14, className: "text-sw-background" }) }),
|
|
231
232
|
c.label
|
|
232
233
|
] }),
|
|
233
234
|
/* @__PURE__ */ m("span", { className: "opacity-0 group-hover:opacity-100 transition-opacity text-xs font-mono uppercase tracking-widest text-sw-text-secondary/50", children: [
|
|
234
235
|
"Select ",
|
|
235
236
|
/* @__PURE__ */ m("span", { className: "hidden md:inline", children: [
|
|
236
237
|
"Key ",
|
|
237
|
-
|
|
238
|
+
f + 1
|
|
238
239
|
] })
|
|
239
240
|
] })
|
|
240
241
|
]
|
|
@@ -243,58 +244,58 @@ function Z({ question: e }) {
|
|
|
243
244
|
);
|
|
244
245
|
}) });
|
|
245
246
|
}
|
|
246
|
-
function
|
|
247
|
-
var
|
|
248
|
-
const { answers:
|
|
247
|
+
function re({ question: e }) {
|
|
248
|
+
var s;
|
|
249
|
+
const { answers: i, setAnswer: r } = L(), t = i[e.id] || 0, u = Math.min(((s = e.validation) == null ? void 0 : s.max) || 5, 20);
|
|
249
250
|
return /* @__PURE__ */ m("div", { className: "flex flex-col gap-6", children: [
|
|
250
|
-
/* @__PURE__ */ n("div", { className: "flex gap-4 flex-wrap", children: Array.from({ length:
|
|
251
|
-
const c =
|
|
251
|
+
/* @__PURE__ */ n("div", { className: "flex gap-4 flex-wrap", children: Array.from({ length: u }).map((p, d) => {
|
|
252
|
+
const c = d + 1, f = c <= t;
|
|
252
253
|
return /* @__PURE__ */ n(
|
|
253
|
-
|
|
254
|
+
w.button,
|
|
254
255
|
{
|
|
255
256
|
initial: { opacity: 0, scale: 0 },
|
|
256
257
|
animate: { opacity: 1, scale: 1 },
|
|
257
|
-
transition: { delay:
|
|
258
|
+
transition: { delay: d * 0.05 },
|
|
258
259
|
onClick: () => r(e.id, c),
|
|
259
260
|
whileHover: { scale: 1.2, rotate: 5 },
|
|
260
261
|
whileTap: { scale: 0.9 },
|
|
261
262
|
className: "focus:outline-none",
|
|
262
263
|
children: /* @__PURE__ */ n(
|
|
263
|
-
|
|
264
|
+
J,
|
|
264
265
|
{
|
|
265
|
-
className: `w-12 h-12 md:w-16 md:h-16 transition-all duration-300 ${
|
|
266
|
+
className: `w-12 h-12 md:w-16 md:h-16 transition-all duration-300 ${f ? "fill-yellow-400 text-yellow-400 drop-shadow-[0_0_15px_rgba(250,204,21,0.4)]" : "text-zinc-600 hover:text-yellow-400/50"}`,
|
|
266
267
|
strokeWidth: 1.5
|
|
267
268
|
}
|
|
268
269
|
)
|
|
269
270
|
},
|
|
270
|
-
|
|
271
|
+
d
|
|
271
272
|
);
|
|
272
273
|
}) }),
|
|
273
274
|
/* @__PURE__ */ m("div", { className: "flex justify-between w-full max-w-[300px] md:max-w-[400px] px-2 items-center", children: [
|
|
274
275
|
/* @__PURE__ */ n("span", { className: "text-sm md:text-base font-medium text-sw-text-secondary/50 uppercase tracking-wide", children: e.minLabel || "Poor" }),
|
|
275
276
|
/* @__PURE__ */ n(
|
|
276
|
-
|
|
277
|
+
w.div,
|
|
277
278
|
{
|
|
278
279
|
initial: { opacity: 0, scale: 0.8 },
|
|
279
280
|
animate: { opacity: t ? 1 : 0, scale: t ? 1 : 0.8 },
|
|
280
281
|
className: "font-bold text-primary text-xl",
|
|
281
|
-
children: t ? `${t} / ${
|
|
282
|
+
children: t ? `${t} / ${u}` : ""
|
|
282
283
|
}
|
|
283
284
|
),
|
|
284
285
|
/* @__PURE__ */ n("span", { className: "text-sm md:text-base font-medium text-muted-foreground uppercase tracking-wide", children: e.maxLabel || "Excellent" })
|
|
285
286
|
] })
|
|
286
287
|
] });
|
|
287
288
|
}
|
|
288
|
-
function
|
|
289
|
-
const { schema:
|
|
289
|
+
function ne({ question: e }) {
|
|
290
|
+
const { schema: i } = L(), r = i.questions.findIndex((d) => d.id === e.id) + 1, t = i.questions.length, u = {
|
|
290
291
|
hidden: { opacity: 0, y: 20 },
|
|
291
292
|
visible: { opacity: 1, y: 0, transition: { duration: 0.5, ease: [0.22, 1, 0.36, 1] } }
|
|
292
|
-
},
|
|
293
|
-
const
|
|
294
|
-
return
|
|
295
|
-
}),
|
|
293
|
+
}, s = (d) => d && d.replace(/\{\{(\w+)\}\}/g, (c, f) => {
|
|
294
|
+
const x = p.answers[f];
|
|
295
|
+
return x != null ? String(x) : "";
|
|
296
|
+
}), p = L();
|
|
296
297
|
return /* @__PURE__ */ m(
|
|
297
|
-
|
|
298
|
+
w.div,
|
|
298
299
|
{
|
|
299
300
|
className: "flex flex-col gap-8 w-full max-w-4xl mx-auto",
|
|
300
301
|
initial: "hidden",
|
|
@@ -304,33 +305,33 @@ function ee({ question: e }) {
|
|
|
304
305
|
},
|
|
305
306
|
children: [
|
|
306
307
|
/* @__PURE__ */ m("div", { className: "flex flex-col gap-2", children: [
|
|
307
|
-
/* @__PURE__ */ n(
|
|
308
|
+
/* @__PURE__ */ n(w.div, { variants: u, className: "flex gap-4 items-baseline", children: /* @__PURE__ */ m("span", { className: "flex items-center gap-2 text-sm md:text-base font-medium text-sw-primary/90 bg-sw-primary/10 px-3 py-1 rounded-full border border-sw-primary/20 backdrop-blur-sm", children: [
|
|
308
309
|
/* @__PURE__ */ n("span", { children: r }),
|
|
309
310
|
/* @__PURE__ */ n("span", { className: "opacity-40 text-xs", children: "/" }),
|
|
310
311
|
/* @__PURE__ */ n("span", { className: "opacity-60", children: t })
|
|
311
312
|
] }) }),
|
|
312
313
|
/* @__PURE__ */ m(
|
|
313
|
-
|
|
314
|
+
w.h2,
|
|
314
315
|
{
|
|
315
|
-
variants:
|
|
316
|
+
variants: u,
|
|
316
317
|
className: "text-3xl md:text-4xl lg:text-5xl font-bold leading-tight tracking-tight text-pretty mt-2 font-sw-heading",
|
|
317
318
|
children: [
|
|
318
|
-
|
|
319
|
+
s(e.title),
|
|
319
320
|
" ",
|
|
320
321
|
/* @__PURE__ */ n("span", { className: "text-sw-primary", children: "*" })
|
|
321
322
|
]
|
|
322
323
|
}
|
|
323
324
|
),
|
|
324
325
|
e.description && /* @__PURE__ */ n(
|
|
325
|
-
|
|
326
|
+
w.p,
|
|
326
327
|
{
|
|
327
|
-
variants:
|
|
328
|
+
variants: u,
|
|
328
329
|
className: "text-lg md:text-xl text-muted-foreground font-normal leading-relaxed max-w-2xl mt-2",
|
|
329
|
-
children:
|
|
330
|
+
children: s(e.description)
|
|
330
331
|
}
|
|
331
332
|
)
|
|
332
333
|
] }),
|
|
333
|
-
/* @__PURE__ */ n(
|
|
334
|
+
/* @__PURE__ */ n(w.div, { variants: u, className: "w-full mt-6", children: e.type === "text" || e.type === "email" || e.type === "number" || e.type === "url" ? /* @__PURE__ */ n(ee, { question: e }) : e.type === "select" ? /* @__PURE__ */ n(te, { question: e }) : e.type === "rating" ? /* @__PURE__ */ n(re, { question: e }) : /* @__PURE__ */ m("div", { className: "p-4 bg-yellow-100 dark:bg-yellow-900/30 text-yellow-800 dark:text-yellow-200 rounded", children: [
|
|
334
335
|
"Unsupported question type: ",
|
|
335
336
|
e.type,
|
|
336
337
|
" (ID: ",
|
|
@@ -341,7 +342,7 @@ function ee({ question: e }) {
|
|
|
341
342
|
}
|
|
342
343
|
);
|
|
343
344
|
}
|
|
344
|
-
const
|
|
345
|
+
const ie = {
|
|
345
346
|
next: "Next",
|
|
346
347
|
back: "Back",
|
|
347
348
|
submit: "Submit",
|
|
@@ -349,16 +350,16 @@ const te = {
|
|
|
349
350
|
optional: "Optional",
|
|
350
351
|
stepInfo: "Question {{current}} of {{total}}"
|
|
351
352
|
};
|
|
352
|
-
function
|
|
353
|
-
var
|
|
354
|
-
const r =
|
|
353
|
+
function ce({ schema: e, onSubmit: i }) {
|
|
354
|
+
var I;
|
|
355
|
+
const r = q({ schema: e, onSubmit: i }), t = e.theme || {
|
|
355
356
|
backgroundColor: "#ffffff",
|
|
356
357
|
textColor: "#000000",
|
|
357
358
|
// Start with generic defaults, override in usage
|
|
358
359
|
primaryColor: "#000000",
|
|
359
360
|
borderRadius: "8px"
|
|
360
361
|
// fontFamily removed to allow inheritance
|
|
361
|
-
},
|
|
362
|
+
}, u = h(h({}, ie), e.i18n), s = {
|
|
362
363
|
backgroundColor: t.backgroundColor,
|
|
363
364
|
color: t.textColor,
|
|
364
365
|
fontFamily: t.fontFamily,
|
|
@@ -369,49 +370,49 @@ function se({ schema: e, onSubmit: a }) {
|
|
|
369
370
|
"--color-sw-text-secondary": t.textColor,
|
|
370
371
|
"--font-sw-heading": t.fontFamily || "inherit",
|
|
371
372
|
"--font-sw-body": t.fontFamily || "inherit"
|
|
372
|
-
},
|
|
373
|
-
backgroundColor:
|
|
374
|
-
color:
|
|
375
|
-
border:
|
|
373
|
+
}, p = t.buttonVariant === "outline", d = {
|
|
374
|
+
backgroundColor: p ? "transparent" : t.primaryColor,
|
|
375
|
+
color: p ? t.primaryColor : t.textColor,
|
|
376
|
+
border: p ? `2px solid ${t.primaryColor}` : "none",
|
|
376
377
|
borderRadius: t.borderRadius || "8px",
|
|
377
378
|
fontWeight: 600
|
|
378
379
|
}, c = {
|
|
379
380
|
color: t.primaryColor,
|
|
380
381
|
borderRadius: t.borderRadius || "8px",
|
|
381
382
|
fontWeight: 600
|
|
382
|
-
}, { autoReload:
|
|
383
|
-
if (
|
|
384
|
-
if (r.isCompleted &&
|
|
385
|
-
const
|
|
383
|
+
}, { autoReload: f, reloadDelay: x = 3e3 } = e;
|
|
384
|
+
if (P(() => {
|
|
385
|
+
if (r.isCompleted && f) {
|
|
386
|
+
const v = setTimeout(() => {
|
|
386
387
|
r.resetForm();
|
|
387
|
-
},
|
|
388
|
-
return () => clearTimeout(
|
|
388
|
+
}, x);
|
|
389
|
+
return () => clearTimeout(v);
|
|
389
390
|
}
|
|
390
|
-
}, [r.isCompleted,
|
|
391
|
+
}, [r.isCompleted, f, x, r.resetForm]), r.isCompleted)
|
|
391
392
|
return /* @__PURE__ */ m(
|
|
392
393
|
"div",
|
|
393
394
|
{
|
|
394
395
|
className: "flex flex-col items-center justify-center h-full w-full p-8 text-center relative overflow-hidden",
|
|
395
|
-
style:
|
|
396
|
+
style: s,
|
|
396
397
|
children: [
|
|
397
|
-
|
|
398
|
-
|
|
398
|
+
f && /* @__PURE__ */ n(
|
|
399
|
+
w.div,
|
|
399
400
|
{
|
|
400
401
|
initial: { width: "0%" },
|
|
401
402
|
animate: { width: "100%" },
|
|
402
|
-
transition: { duration:
|
|
403
|
+
transition: { duration: x / 1e3, ease: "linear" },
|
|
403
404
|
className: "absolute top-0 left-0 h-1 bg-green-500 z-50"
|
|
404
405
|
}
|
|
405
406
|
),
|
|
406
407
|
/* @__PURE__ */ m(
|
|
407
|
-
|
|
408
|
+
w.div,
|
|
408
409
|
{
|
|
409
410
|
initial: { scale: 0.9, opacity: 0, y: 20 },
|
|
410
411
|
animate: { scale: 1, opacity: 1, y: 0 },
|
|
411
412
|
transition: { duration: 0.6, ease: [0.22, 1, 0.36, 1] },
|
|
412
413
|
className: "flex flex-col items-center",
|
|
413
414
|
children: [
|
|
414
|
-
/* @__PURE__ */ n("div", { className: "mb-6 p-4 rounded-full bg-green-500/20 text-green-500 w-24 h-24 flex items-center justify-center", children: /* @__PURE__ */ n(
|
|
415
|
+
/* @__PURE__ */ n("div", { className: "mb-6 p-4 rounded-full bg-green-500/20 text-green-500 w-24 h-24 flex items-center justify-center", children: /* @__PURE__ */ n(D, { size: 48 }) }),
|
|
415
416
|
/* @__PURE__ */ n("h1", { className: "text-4xl md:text-5xl font-bold mb-4 tracking-tight", children: "Obrigado!" }),
|
|
416
417
|
/* @__PURE__ */ n("p", { className: "text-xl opacity-70 max-w-md leading-relaxed", children: "Suas respostas foram enviadas com sucesso." })
|
|
417
418
|
]
|
|
@@ -420,37 +421,37 @@ function se({ schema: e, onSubmit: a }) {
|
|
|
420
421
|
]
|
|
421
422
|
}
|
|
422
423
|
);
|
|
423
|
-
const
|
|
424
|
-
return /* @__PURE__ */ n(
|
|
424
|
+
const b = e.questions.find((v) => v.id === r.currentStepId), C = (e.questions.findIndex((v) => v.id === r.currentStepId) + 1) / e.questions.length * 100;
|
|
425
|
+
return /* @__PURE__ */ n(O.Provider, { value: g(h({}, r), { schema: e }), children: /* @__PURE__ */ m(
|
|
425
426
|
"div",
|
|
426
427
|
{
|
|
427
428
|
className: "w-full h-full flex flex-col relative overflow-hidden transition-colors duration-700",
|
|
428
|
-
style:
|
|
429
|
+
style: s,
|
|
429
430
|
children: [
|
|
430
431
|
/* @__PURE__ */ m("div", { className: "absolute top-0 left-0 w-full h-1 z-50", children: [
|
|
431
432
|
/* @__PURE__ */ n("div", { className: "absolute top-0 left-0 w-full h-full bg-current opacity-10" }),
|
|
432
433
|
/* @__PURE__ */ n(
|
|
433
|
-
|
|
434
|
+
w.div,
|
|
434
435
|
{
|
|
435
436
|
className: "h-full relative z-10",
|
|
436
437
|
initial: { width: 0 },
|
|
437
|
-
animate: { width: `${
|
|
438
|
+
animate: { width: `${C}%` },
|
|
438
439
|
transition: { duration: 0.5, ease: "easeInOut" },
|
|
439
440
|
style: { backgroundColor: t.primaryColor }
|
|
440
441
|
}
|
|
441
442
|
)
|
|
442
443
|
] }),
|
|
443
|
-
/* @__PURE__ */ n("div", { className: "flex-1 flex flex-col items-center justify-center p-6 md:p-12 w-full max-w-5xl mx-auto z-10", children: /* @__PURE__ */ n(
|
|
444
|
-
|
|
444
|
+
/* @__PURE__ */ n("div", { className: "flex-1 flex flex-col items-center justify-center p-6 md:p-12 w-full max-w-5xl mx-auto z-10", children: /* @__PURE__ */ n(X, { mode: "wait", children: b && /* @__PURE__ */ n(
|
|
445
|
+
w.div,
|
|
445
446
|
{
|
|
446
447
|
initial: { opacity: 0, y: 40 },
|
|
447
448
|
animate: { opacity: 1, y: 0 },
|
|
448
449
|
exit: { opacity: 0, y: -40 },
|
|
449
450
|
transition: { duration: 0.5, ease: [0.22, 1, 0.36, 1] },
|
|
450
451
|
className: "w-full",
|
|
451
|
-
children: /* @__PURE__ */ n(
|
|
452
|
+
children: /* @__PURE__ */ n(ne, { question: b })
|
|
452
453
|
},
|
|
453
|
-
|
|
454
|
+
b.id
|
|
454
455
|
) }) }),
|
|
455
456
|
/* @__PURE__ */ m("div", { className: "w-full px-6 pt-6 pb-8 md:p-10 flex flex-col md:flex-row justify-between items-center z-20 gap-4", children: [
|
|
456
457
|
t.showPoweredBy !== !1 && /* @__PURE__ */ m(
|
|
@@ -465,7 +466,7 @@ function se({ schema: e, onSubmit: a }) {
|
|
|
465
466
|
{
|
|
466
467
|
className: "text-[10px] md:text-xs font-mono font-bold tracking-[0.2em] uppercase transition-colors shadow-sw-primary",
|
|
467
468
|
style: { color: t.brandColor || t.primaryColor },
|
|
468
|
-
children: ((
|
|
469
|
+
children: ((I = t.poweredBy) == null ? void 0 : I.replace("Powered by ", "")) || "SAWABONA TECH"
|
|
469
470
|
}
|
|
470
471
|
)
|
|
471
472
|
]
|
|
@@ -473,7 +474,7 @@ function se({ schema: e, onSubmit: a }) {
|
|
|
473
474
|
),
|
|
474
475
|
/* @__PURE__ */ m("div", { className: "flex items-center gap-4 order-2 md:order-3 ml-auto", children: [
|
|
475
476
|
/* @__PURE__ */ n(
|
|
476
|
-
|
|
477
|
+
w.button,
|
|
477
478
|
{
|
|
478
479
|
onClick: r.prevStep,
|
|
479
480
|
disabled: r.history.length === 0,
|
|
@@ -481,20 +482,20 @@ function se({ schema: e, onSubmit: a }) {
|
|
|
481
482
|
whileTap: { scale: 0.95 },
|
|
482
483
|
className: "w-12 h-12 md:w-14 md:h-14 flex items-center justify-center disabled:opacity-0 disabled:pointer-events-none transition-all hover:bg-white/5 rounded-full",
|
|
483
484
|
style: c,
|
|
484
|
-
children: /* @__PURE__ */ n(
|
|
485
|
+
children: /* @__PURE__ */ n(Y, { size: 24 })
|
|
485
486
|
}
|
|
486
487
|
),
|
|
487
488
|
/* @__PURE__ */ m(
|
|
488
|
-
|
|
489
|
+
w.button,
|
|
489
490
|
{
|
|
490
491
|
onClick: r.nextStep,
|
|
491
492
|
whileHover: { scale: 1.02 },
|
|
492
493
|
whileTap: { scale: 0.98 },
|
|
493
494
|
className: "px-8 py-3 md:px-10 md:py-4 text-lg font-bold shadow-2xl flex items-center gap-3 transition-all rounded-lg",
|
|
494
|
-
style:
|
|
495
|
+
style: d,
|
|
495
496
|
children: [
|
|
496
|
-
/* @__PURE__ */ n("span", { children: r.currentStepId === e.questions[e.questions.length - 1].id ? t.submitText ||
|
|
497
|
-
r.currentStepId !== e.questions[e.questions.length - 1].id && /* @__PURE__ */ n(
|
|
497
|
+
/* @__PURE__ */ n("span", { children: r.currentStepId === e.questions[e.questions.length - 1].id ? t.submitText || u.submit : u.next }),
|
|
498
|
+
r.currentStepId !== e.questions[e.questions.length - 1].id && /* @__PURE__ */ n(Z, { size: 20, strokeWidth: 3 })
|
|
498
499
|
]
|
|
499
500
|
}
|
|
500
501
|
)
|
|
@@ -505,5 +506,5 @@ function se({ schema: e, onSubmit: a }) {
|
|
|
505
506
|
) });
|
|
506
507
|
}
|
|
507
508
|
export {
|
|
508
|
-
|
|
509
|
+
ce as FormRenderer
|
|
509
510
|
};
|
|
@@ -1,14 +1,14 @@
|
|
|
1
|
-
(function(
|
|
1
|
+
(function(n,t){typeof exports=="object"&&typeof module!="undefined"?t(exports,require("react/jsx-runtime"),require("react"),require("framer-motion"),require("lucide-react")):typeof define=="function"&&define.amd?define(["exports","react/jsx-runtime","react","framer-motion","lucide-react"],t):(n=typeof globalThis!="undefined"?globalThis:n||self,t(n.SawabonaForms={},n.jsxRuntime,n.React,n.Motion,n.Lucide))})(this,(function(n,t,o,l,I){"use strict";var X=Object.defineProperty,J=Object.defineProperties;var Y=Object.getOwnPropertyDescriptors;var P=Object.getOwnPropertySymbols;var B=Object.prototype.hasOwnProperty,O=Object.prototype.propertyIsEnumerable;var $=(n,t,o)=>t in n?X(n,t,{enumerable:!0,configurable:!0,writable:!0,value:o}):n[t]=o,g=(n,t)=>{for(var o in t||(t={}))B.call(t,o)&&$(n,o,t[o]);if(P)for(var o of P(t))O.call(t,o)&&$(n,o,t[o]);return n},b=(n,t)=>J(n,Y(t));var _=n=>typeof n=="symbol"?n:n+"",D=(n,t)=>{var o={};for(var l in n)B.call(n,l)&&t.indexOf(l)<0&&(o[l]=n[l]);if(n!=null&&P)for(var l of P(n))t.indexOf(l)<0&&O.call(n,l)&&(o[l]=n[l]);return o};function Q({schema:e,onSubmit:m}){var C;const[s,r]=o.useState({answers:{},currentStepId:((C=e.questions[0])==null?void 0:C.id)||"",history:[],isSubmitting:!1,errors:{},isCompleted:!1}),x=o.useMemo(()=>e.questions.findIndex(a=>a.id===s.currentStepId),[e.questions,s.currentStepId]),i=e.questions[x],f=o.useCallback((a,d)=>{r(c=>b(g({},c),{answers:b(g({},c.answers),{[a]:d}),errors:b(g({},c.errors),{[a]:""})}))},[]),p=o.useCallback((a,d)=>{r(c=>{if(d===null){const A=c.errors,{[a]:N}=A,w=D(A,[_(a)]);return b(g({},c),{errors:w})}return b(g({},c),{errors:b(g({},c.errors),{[a]:d})})})},[]),u=o.useCallback(()=>{var c;if(!i)return!0;const a=s.answers[i.id],d=i.validation;return d&&d.required&&(a===void 0||a===""||Array.isArray(a)&&a.length===0)?(p(i.id,((c=e.i18n)==null?void 0:c.required)||"This field is required"),!1):!0},[i,s.answers,p,e.i18n]),y=o.useCallback(a=>{const d=e.questions.findIndex(c=>c.id===a.id);return d<e.questions.length-1?e.questions[d+1].id:"submit"},[e.questions]),h=o.useCallback(()=>{if(!u())return;const a=y(i);a==="submit"?(r(d=>b(g({},d),{isCompleted:!0})),m==null||m(s.answers)):r(d=>b(g({},d),{history:[...d.history,d.currentStepId],currentStepId:a}))},[i,s.answers,u,y,m]),v=o.useCallback(()=>{if(s.history.length===0)return;const a=s.history[s.history.length-1];r(d=>b(g({},d),{history:d.history.slice(0,-1),currentStepId:a}))},[s.history]),k=o.useCallback(a=>{if(!e.questions.some(c=>c.id===a)){console.warn(`Step ${a} does not exist`);return}r(c=>b(g({},c),{history:[...c.history,c.currentStepId],currentStepId:a}))},[e.questions]),E=o.useCallback(()=>{var a;r({answers:{},currentStepId:((a=e.questions[0])==null?void 0:a.id)||"",history:[],isSubmitting:!1,errors:{},isCompleted:!1})},[e.questions]);return b(g({},s),{setAnswer:f,nextStep:h,prevStep:v,jumpToStep:k,submitForm:()=>m==null?void 0:m(s.answers),resetForm:E,registerError:p,progress:x/e.questions.length*100})}const z=o.createContext(void 0),F=()=>{const e=o.useContext(z);if(!e)throw new Error("useFormContext must be used within a FormProvider");return e};function H({question:e}){var C,a,d,c,A;const{answers:m,setAnswer:s,nextStep:r,schema:x}=F(),i=m[e.id],f=i!=null?String(i):"",p=o.useRef(null),u=x.questions[0].id===e.id,y=!x.disableAutoFocus||!u;o.useEffect(()=>{if(y){const N=setTimeout(()=>{var w;(w=p.current)==null||w.focus()},500);return()=>clearTimeout(N)}},[e.id,y]);const h=N=>{var L;let w=N.target.value;const T=((L=e.validation)==null?void 0:L.maxLength)||2048;if(w.length>T&&(w=w.slice(0,T)),e.type==="number"){const j=w===""?"":parseFloat(w);s(e.id,j)}else s(e.id,w)},v=()=>{var N,w,T,L,j;if((N=e.validation)!=null&&N.required&&!f)return!1;if(f){if((w=e.validation)!=null&&w.minLength&&f.length<e.validation.minLength||e.type==="email"&&!/^[^\s@]+@[^\s@]+\.[^\s@]+$/.test(f))return!1;if((T=e.validation)!=null&&T.pattern)try{if(!new RegExp(e.validation.pattern).test(f))return!1}catch(S){console.error("Invalid regex pattern in schema",S)}if(e.type==="number"){const S=parseFloat(f);if(!isNaN(S)&&(((L=e.validation)==null?void 0:L.min)!==void 0&&S<e.validation.min||((j=e.validation)==null?void 0:j.max)!==void 0&&S>e.validation.max))return!1}}return!0},k=N=>{if(N.key==="Enter"&&!N.shiftKey){if(N.preventDefault(),!v()){const w=document.querySelector(".sawabona-form-container")||document.body;w.classList.add("shake-animation"),setTimeout(()=>w.classList.remove("shake-animation"),500);return}r()}};return t.jsxs("div",{className:"w-full relative group",children:[t.jsx("input",{ref:p,type:e.type,value:typeof f=="string"||typeof f=="number"?f:"",onChange:h,onKeyDown:k,placeholder:e.placeholder,minLength:(C=e.validation)==null?void 0:C.minLength,maxLength:((a=e.validation)==null?void 0:a.maxLength)||2048,min:(d=e.validation)==null?void 0:d.min,max:(c=e.validation)==null?void 0:c.max,pattern:(A=e.validation)==null?void 0:A.pattern,className:`
|
|
2
2
|
w-full bg-transparent border-b-2 border-sw-text-secondary/20
|
|
3
3
|
py-4 text-2xl md:text-3xl font-medium outline-none transition-colors
|
|
4
4
|
placeholder:text-sw-text-secondary/30
|
|
5
5
|
focus:border-sw-primary
|
|
6
6
|
font-sw-heading
|
|
7
|
-
|
|
7
|
+
`}),void 0,t.jsxs("p",{className:"text-sm opacity-50 mt-4",children:[e.type==="email"&&"Press Enter to continue",e.type==="text"&&"Press Enter to continue",e.type==="number"&&"Press Enter to continue",e.type==="url"&&"Press Enter to continue"]})]})}function K({question:e}){var p;const{answers:m,setAnswer:s,nextStep:r}=F(),x=m[e.id]||"",i=u=>{s(e.id,u),setTimeout(()=>r(),400)},f="ABCDEFGHIJKLMNOPQRSTUVWXYZ";return o.useEffect(()=>{const u=y=>{var k;const h=y.key.toUpperCase(),v=f.indexOf(h);v>=0&&v<(((k=e.options)==null?void 0:k.length)||0)&&i(e.options[v].value)};return window.addEventListener("keydown",u),()=>window.removeEventListener("keydown",u)},[e.options,e.id]),t.jsx("div",{className:"flex flex-col gap-3 w-full max-w-xl",children:(p=e.options)==null?void 0:p.map((u,y)=>{const h=Array.isArray(x)?x.includes(u.value):x===u.value;return t.jsxs(l.motion.button,{initial:{opacity:0,y:10},animate:{opacity:1,y:0},transition:{delay:y*.05},onClick:()=>i(u.value),className:`
|
|
8
8
|
w-full text-left p-4 rounded-lg border-2 transition-all duration-200
|
|
9
9
|
flex items-center justify-between group
|
|
10
|
-
${
|
|
10
|
+
${h?"border-sw-primary bg-sw-primary/5 text-sw-primary":"border-sw-text-secondary/10 hover:border-sw-primary/50 hover:bg-sw-primary/5"}
|
|
11
11
|
`,children:[t.jsxs("span",{className:"text-lg font-medium flex items-center gap-3",children:[t.jsx("span",{className:`
|
|
12
12
|
w-6 h-6 rounded-full border-2 flex items-center justify-center transition-colors
|
|
13
|
-
${
|
|
14
|
-
`,children:
|
|
13
|
+
${h?"border-sw-primary bg-sw-primary":"border-sw-text-secondary/30 group-hover:border-sw-primary/50"}
|
|
14
|
+
`,children:h&&t.jsx(I.Check,{size:14,className:"text-sw-background"})}),u.label]}),t.jsxs("span",{className:"opacity-0 group-hover:opacity-100 transition-opacity text-xs font-mono uppercase tracking-widest text-sw-text-secondary/50",children:["Select ",t.jsxs("span",{className:"hidden md:inline",children:["Key ",y+1]})]})]},String(u.value))})})}function V({question:e}){var i;const{answers:m,setAnswer:s}=F(),r=m[e.id]||0,x=Math.min(((i=e.validation)==null?void 0:i.max)||5,20);return t.jsxs("div",{className:"flex flex-col gap-6",children:[t.jsx("div",{className:"flex gap-4 flex-wrap",children:Array.from({length:x}).map((f,p)=>{const u=p+1,y=u<=r;return t.jsx(l.motion.button,{initial:{opacity:0,scale:0},animate:{opacity:1,scale:1},transition:{delay:p*.05},onClick:()=>s(e.id,u),whileHover:{scale:1.2,rotate:5},whileTap:{scale:.9},className:"focus:outline-none",children:t.jsx(I.Star,{className:`w-12 h-12 md:w-16 md:h-16 transition-all duration-300 ${y?"fill-yellow-400 text-yellow-400 drop-shadow-[0_0_15px_rgba(250,204,21,0.4)]":"text-zinc-600 hover:text-yellow-400/50"}`,strokeWidth:1.5})},p)})}),t.jsxs("div",{className:"flex justify-between w-full max-w-[300px] md:max-w-[400px] px-2 items-center",children:[t.jsx("span",{className:"text-sm md:text-base font-medium text-sw-text-secondary/50 uppercase tracking-wide",children:e.minLabel||"Poor"}),t.jsx(l.motion.div,{initial:{opacity:0,scale:.8},animate:{opacity:r?1:0,scale:r?1:.8},className:"font-bold text-primary text-xl",children:r?`${r} / ${x}`:""}),t.jsx("span",{className:"text-sm md:text-base font-medium text-muted-foreground uppercase tracking-wide",children:e.maxLabel||"Excellent"})]})]})}function W({question:e}){const{schema:m}=F(),s=m.questions.findIndex(p=>p.id===e.id)+1,r=m.questions.length,x={hidden:{opacity:0,y:20},visible:{opacity:1,y:0,transition:{duration:.5,ease:[.22,1,.36,1]}}},i=p=>p&&p.replace(/\{\{(\w+)\}\}/g,(u,y)=>{const h=f.answers[y];return h!=null?String(h):""}),f=F();return t.jsxs(l.motion.div,{className:"flex flex-col gap-8 w-full max-w-4xl mx-auto",initial:"hidden",animate:"visible",variants:{visible:{transition:{staggerChildren:.1}}},children:[t.jsxs("div",{className:"flex flex-col gap-2",children:[t.jsx(l.motion.div,{variants:x,className:"flex gap-4 items-baseline",children:t.jsxs("span",{className:"flex items-center gap-2 text-sm md:text-base font-medium text-sw-primary/90 bg-sw-primary/10 px-3 py-1 rounded-full border border-sw-primary/20 backdrop-blur-sm",children:[t.jsx("span",{children:s}),t.jsx("span",{className:"opacity-40 text-xs",children:"/"}),t.jsx("span",{className:"opacity-60",children:r})]})}),t.jsxs(l.motion.h2,{variants:x,className:"text-3xl md:text-4xl lg:text-5xl font-bold leading-tight tracking-tight text-pretty mt-2 font-sw-heading",children:[i(e.title)," ",t.jsx("span",{className:"text-sw-primary",children:"*"})]}),e.description&&t.jsx(l.motion.p,{variants:x,className:"text-lg md:text-xl text-muted-foreground font-normal leading-relaxed max-w-2xl mt-2",children:i(e.description)})]}),t.jsx(l.motion.div,{variants:x,className:"w-full mt-6",children:e.type==="text"||e.type==="email"||e.type==="number"||e.type==="url"?t.jsx(H,{question:e}):e.type==="select"?t.jsx(K,{question:e}):e.type==="rating"?t.jsx(V,{question:e}):t.jsxs("div",{className:"p-4 bg-yellow-100 dark:bg-yellow-900/30 text-yellow-800 dark:text-yellow-200 rounded",children:["Unsupported question type: ",e.type," (ID: ",e.id,")"]})})]})}const U={next:"Next",back:"Back",submit:"Submit",required:"Required",optional:"Optional",stepInfo:"Question {{current}} of {{total}}"};function G({schema:e,onSubmit:m}){var E;const s=Q({schema:e,onSubmit:m}),r=e.theme||{backgroundColor:"#ffffff",textColor:"#000000",primaryColor:"#000000",borderRadius:"8px"},x=g(g({},U),e.i18n),i={backgroundColor:r.backgroundColor,color:r.textColor,fontFamily:r.fontFamily,"--color-sw-primary":r.primaryColor,"--color-sw-background":r.backgroundColor,"--color-sw-text-primary":r.primaryColor,"--color-sw-text-secondary":r.textColor,"--font-sw-heading":r.fontFamily||"inherit","--font-sw-body":r.fontFamily||"inherit"},f=r.buttonVariant==="outline",p={backgroundColor:f?"transparent":r.primaryColor,color:f?r.primaryColor:r.textColor,border:f?`2px solid ${r.primaryColor}`:"none",borderRadius:r.borderRadius||"8px",fontWeight:600},u={color:r.primaryColor,borderRadius:r.borderRadius||"8px",fontWeight:600},{autoReload:y,reloadDelay:h=3e3}=e;if(o.useEffect(()=>{if(s.isCompleted&&y){const C=setTimeout(()=>{s.resetForm()},h);return()=>clearTimeout(C)}},[s.isCompleted,y,h,s.resetForm]),s.isCompleted)return t.jsxs("div",{className:"flex flex-col items-center justify-center h-full w-full p-8 text-center relative overflow-hidden",style:i,children:[y&&t.jsx(l.motion.div,{initial:{width:"0%"},animate:{width:"100%"},transition:{duration:h/1e3,ease:"linear"},className:"absolute top-0 left-0 h-1 bg-green-500 z-50"}),t.jsxs(l.motion.div,{initial:{scale:.9,opacity:0,y:20},animate:{scale:1,opacity:1,y:0},transition:{duration:.6,ease:[.22,1,.36,1]},className:"flex flex-col items-center",children:[t.jsx("div",{className:"mb-6 p-4 rounded-full bg-green-500/20 text-green-500 w-24 h-24 flex items-center justify-center",children:t.jsx(I.Check,{size:48})}),t.jsx("h1",{className:"text-4xl md:text-5xl font-bold mb-4 tracking-tight",children:"Obrigado!"}),t.jsx("p",{className:"text-xl opacity-70 max-w-md leading-relaxed",children:"Suas respostas foram enviadas com sucesso."})]})]});const v=e.questions.find(C=>C.id===s.currentStepId),k=(e.questions.findIndex(C=>C.id===s.currentStepId)+1)/e.questions.length*100;return t.jsx(z.Provider,{value:b(g({},s),{schema:e}),children:t.jsxs("div",{className:"w-full h-full flex flex-col relative overflow-hidden transition-colors duration-700",style:i,children:[t.jsxs("div",{className:"absolute top-0 left-0 w-full h-1 z-50",children:[t.jsx("div",{className:"absolute top-0 left-0 w-full h-full bg-current opacity-10"}),t.jsx(l.motion.div,{className:"h-full relative z-10",initial:{width:0},animate:{width:`${k}%`},transition:{duration:.5,ease:"easeInOut"},style:{backgroundColor:r.primaryColor}})]}),t.jsx("div",{className:"flex-1 flex flex-col items-center justify-center p-6 md:p-12 w-full max-w-5xl mx-auto z-10",children:t.jsx(l.AnimatePresence,{mode:"wait",children:v&&t.jsx(l.motion.div,{initial:{opacity:0,y:40},animate:{opacity:1,y:0},exit:{opacity:0,y:-40},transition:{duration:.5,ease:[.22,1,.36,1]},className:"w-full",children:t.jsx(W,{question:v})},v.id)})}),t.jsxs("div",{className:"w-full px-6 pt-6 pb-8 md:p-10 flex flex-col md:flex-row justify-between items-center z-20 gap-4",children:[r.showPoweredBy!==!1&&t.jsxs("a",{href:"#",className:"order-3 md:order-1 group flex items-center gap-2 px-3 py-1.5 rounded-md border border-white/10 bg-black/20 hover:border-sw-primary/50 hover:bg-black/40 transition-all duration-300 cursor-pointer no-underline backdrop-blur-sm",children:[t.jsx("span",{className:"text-[10px] md:text-xs font-mono font-medium tracking-[0.2em] uppercase text-muted-foreground group-hover:text-muted-foreground/80 transition-colors",children:"Powered By"}),t.jsx("span",{className:"text-[10px] md:text-xs font-mono font-bold tracking-[0.2em] uppercase transition-colors shadow-sw-primary",style:{color:r.brandColor||r.primaryColor},children:((E=r.poweredBy)==null?void 0:E.replace("Powered by ",""))||"SAWABONA TECH"})]}),t.jsxs("div",{className:"flex items-center gap-4 order-2 md:order-3 ml-auto",children:[t.jsx(l.motion.button,{onClick:s.prevStep,disabled:s.history.length===0,whileHover:{scale:1.05},whileTap:{scale:.95},className:"w-12 h-12 md:w-14 md:h-14 flex items-center justify-center disabled:opacity-0 disabled:pointer-events-none transition-all hover:bg-white/5 rounded-full",style:u,children:t.jsx(I.ChevronLeft,{size:24})}),t.jsxs(l.motion.button,{onClick:s.nextStep,whileHover:{scale:1.02},whileTap:{scale:.98},className:"px-8 py-3 md:px-10 md:py-4 text-lg font-bold shadow-2xl flex items-center gap-3 transition-all rounded-lg",style:p,children:[t.jsx("span",{children:s.currentStepId===e.questions[e.questions.length-1].id?r.submitText||x.submit:x.next}),s.currentStepId!==e.questions[e.questions.length-1].id&&t.jsx(I.ChevronRight,{size:20,strokeWidth:3})]})]})]})]})})}n.FormRenderer=G,Object.defineProperty(n,Symbol.toStringTag,{value:"Module"})}));
|