@sawabona/forms 1.0.2 → 1.0.3
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 +27 -0
- package/dist/components/FormRenderer.d.ts +1 -0
- package/dist/components/FormRenderer.d.ts.map +1 -1
- package/dist/components/QuestionRenderer.d.ts +1 -0
- package/dist/components/QuestionRenderer.d.ts.map +1 -1
- package/dist/components/ui/RatingInput.d.ts +1 -0
- package/dist/components/ui/SelectInput.d.ts +1 -0
- package/dist/components/ui/SelectInput.d.ts.map +1 -1
- package/dist/components/ui/TextInput.d.ts +1 -0
- package/dist/components/ui/TextInput.d.ts.map +1 -1
- package/dist/core/FormContext.d.ts +1 -0
- package/dist/core/types.d.ts +15 -0
- package/dist/core/types.d.ts.map +1 -1
- package/dist/core/useFormEngine.d.ts +1 -0
- package/dist/index.d.ts +1 -0
- package/dist/sawabona-forms.css +2 -2
- package/dist/sawabona-forms.es.js +270 -234
- package/dist/sawabona-forms.umd.js +7 -7
- package/dist/utils.d.ts +2 -0
- package/dist/utils.d.ts.map +1 -1
- package/package.json +10 -10
|
@@ -1,92 +1,92 @@
|
|
|
1
|
-
var H = Object.defineProperty,
|
|
2
|
-
var
|
|
3
|
-
var
|
|
4
|
-
var
|
|
5
|
-
var
|
|
6
|
-
for (var r in
|
|
7
|
-
|
|
8
|
-
if (
|
|
9
|
-
for (var r of
|
|
10
|
-
_.call(
|
|
1
|
+
var H = Object.defineProperty, U = Object.defineProperties;
|
|
2
|
+
var M = Object.getOwnPropertyDescriptors;
|
|
3
|
+
var L = Object.getOwnPropertySymbols;
|
|
4
|
+
var W = Object.prototype.hasOwnProperty, _ = Object.prototype.propertyIsEnumerable;
|
|
5
|
+
var P = (e, n, r) => n in e ? H(e, n, { enumerable: !0, configurable: !0, writable: !0, value: r }) : e[n] = r, o = (e, n) => {
|
|
6
|
+
for (var r in n || (n = {}))
|
|
7
|
+
W.call(n, r) && P(e, r, n[r]);
|
|
8
|
+
if (L)
|
|
9
|
+
for (var r of L(n))
|
|
10
|
+
_.call(n, r) && P(e, r, n[r]);
|
|
11
11
|
return e;
|
|
12
|
-
},
|
|
13
|
-
var
|
|
12
|
+
}, N = (e, n) => U(e, M(n));
|
|
13
|
+
var D = (e) => typeof e == "symbol" ? e : e + "", K = (e, n) => {
|
|
14
14
|
var r = {};
|
|
15
15
|
for (var t in e)
|
|
16
|
-
|
|
17
|
-
if (e != null &&
|
|
18
|
-
for (var t of
|
|
19
|
-
|
|
16
|
+
W.call(e, t) && n.indexOf(t) < 0 && (r[t] = e[t]);
|
|
17
|
+
if (e != null && L)
|
|
18
|
+
for (var t of L(e))
|
|
19
|
+
n.indexOf(t) < 0 && _.call(e, t) && (r[t] = e[t]);
|
|
20
20
|
return r;
|
|
21
21
|
};
|
|
22
|
-
import { jsxs as
|
|
23
|
-
import { useState as
|
|
24
|
-
import { motion as
|
|
25
|
-
import { Check as O, Star as
|
|
26
|
-
function
|
|
27
|
-
var
|
|
28
|
-
const [r, t] =
|
|
22
|
+
import { jsxs as f, jsx as i } from "react/jsx-runtime";
|
|
23
|
+
import { useState as G, useMemo as X, useCallback as k, createContext as Z, useContext as J, useRef as Y, useEffect as T } from "react";
|
|
24
|
+
import { motion as b, AnimatePresence as q } from "framer-motion";
|
|
25
|
+
import { Check as O, Star as ee, ChevronLeft as te, ChevronRight as re } from "lucide-react";
|
|
26
|
+
function ne({ schema: e, onSubmit: n }) {
|
|
27
|
+
var x;
|
|
28
|
+
const [r, t] = G({
|
|
29
29
|
answers: {},
|
|
30
|
-
currentStepId: ((
|
|
30
|
+
currentStepId: ((x = e.questions[0]) == null ? void 0 : x.id) || "",
|
|
31
31
|
history: [],
|
|
32
32
|
isSubmitting: !1,
|
|
33
33
|
errors: {},
|
|
34
34
|
isCompleted: !1
|
|
35
|
-
}),
|
|
35
|
+
}), l = X(
|
|
36
36
|
() => e.questions.findIndex((a) => a.id === r.currentStepId),
|
|
37
37
|
[e.questions, r.currentStepId]
|
|
38
|
-
),
|
|
39
|
-
t((
|
|
40
|
-
answers:
|
|
38
|
+
), d = e.questions[l], m = k((a, s) => {
|
|
39
|
+
t((p) => N(o({}, p), {
|
|
40
|
+
answers: N(o({}, p.answers), {
|
|
41
41
|
[a]: s
|
|
42
42
|
}),
|
|
43
43
|
// Clear error on modification
|
|
44
|
-
errors:
|
|
44
|
+
errors: N(o({}, p.errors), {
|
|
45
45
|
[a]: ""
|
|
46
46
|
})
|
|
47
47
|
}));
|
|
48
|
-
}, []),
|
|
49
|
-
t((
|
|
48
|
+
}, []), y = k((a, s) => {
|
|
49
|
+
t((p) => {
|
|
50
50
|
if (s === null) {
|
|
51
|
-
const
|
|
52
|
-
return
|
|
51
|
+
const $ = p.errors, { [a]: B } = $, E = K($, [D(a)]);
|
|
52
|
+
return N(o({}, p), { errors: E });
|
|
53
53
|
}
|
|
54
|
-
return
|
|
55
|
-
errors:
|
|
54
|
+
return N(o({}, p), {
|
|
55
|
+
errors: N(o({}, p.errors), { [a]: s })
|
|
56
56
|
});
|
|
57
57
|
});
|
|
58
|
-
}, []),
|
|
59
|
-
var
|
|
60
|
-
if (!
|
|
61
|
-
const a = r.answers[
|
|
62
|
-
return s && s.required && (a === void 0 || a === "" || Array.isArray(a) && a.length === 0) ? (
|
|
63
|
-
}, [
|
|
64
|
-
const s = e.questions.findIndex((
|
|
58
|
+
}, []), h = k(() => {
|
|
59
|
+
var p;
|
|
60
|
+
if (!d) return !0;
|
|
61
|
+
const a = r.answers[d.id], s = d.validation;
|
|
62
|
+
return s && s.required && (a === void 0 || a === "" || Array.isArray(a) && a.length === 0) ? (y(d.id, ((p = e.i18n) == null ? void 0 : p.required) || "This field is required"), !1) : !0;
|
|
63
|
+
}, [d, r.answers, y, e.i18n]), c = k((a) => {
|
|
64
|
+
const s = e.questions.findIndex((p) => p.id === a.id);
|
|
65
65
|
return s < e.questions.length - 1 ? e.questions[s + 1].id : "submit";
|
|
66
|
-
}, [e.questions]),
|
|
67
|
-
if (!
|
|
68
|
-
const a =
|
|
69
|
-
a === "submit" ? (t((s) =>
|
|
66
|
+
}, [e.questions]), g = k(() => {
|
|
67
|
+
if (!h()) return;
|
|
68
|
+
const a = c(d);
|
|
69
|
+
a === "submit" ? (t((s) => N(o({}, s), { isCompleted: !0 })), n == null || n(r.answers)) : t((s) => N(o({}, s), {
|
|
70
70
|
history: [...s.history, s.currentStepId],
|
|
71
71
|
currentStepId: a
|
|
72
72
|
}));
|
|
73
|
-
}, [
|
|
73
|
+
}, [d, r.answers, h, c, n]), u = k(() => {
|
|
74
74
|
if (r.history.length === 0) return;
|
|
75
75
|
const a = r.history[r.history.length - 1];
|
|
76
|
-
t((s) =>
|
|
76
|
+
t((s) => N(o({}, s), {
|
|
77
77
|
history: s.history.slice(0, -1),
|
|
78
78
|
currentStepId: a
|
|
79
79
|
}));
|
|
80
|
-
}, [r.history]),
|
|
81
|
-
if (!e.questions.some((
|
|
80
|
+
}, [r.history]), v = k((a) => {
|
|
81
|
+
if (!e.questions.some((p) => p.id === a)) {
|
|
82
82
|
console.warn(`Step ${a} does not exist`);
|
|
83
83
|
return;
|
|
84
84
|
}
|
|
85
|
-
t((
|
|
86
|
-
history: [...
|
|
85
|
+
t((p) => N(o({}, p), {
|
|
86
|
+
history: [...p.history, p.currentStepId],
|
|
87
87
|
currentStepId: a
|
|
88
88
|
}));
|
|
89
|
-
}, [e.questions]),
|
|
89
|
+
}, [e.questions]), C = k(() => {
|
|
90
90
|
var a;
|
|
91
91
|
t({
|
|
92
92
|
answers: {},
|
|
@@ -97,200 +97,234 @@ function ee({ schema: e, onSubmit: i }) {
|
|
|
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 N(o({}, r), {
|
|
101
|
+
setAnswer: m,
|
|
102
|
+
nextStep: g,
|
|
103
|
+
prevStep: u,
|
|
104
|
+
jumpToStep: v,
|
|
105
|
+
submitForm: () => n == null ? void 0 : n(r.answers),
|
|
106
|
+
resetForm: C,
|
|
107
|
+
registerError: y,
|
|
108
108
|
// Helper to calculate progress
|
|
109
|
-
progress:
|
|
109
|
+
progress: l / e.questions.length * 100
|
|
110
110
|
});
|
|
111
111
|
}
|
|
112
|
-
const Q =
|
|
113
|
-
const e =
|
|
112
|
+
const Q = Z(void 0), R = () => {
|
|
113
|
+
const e = J(Q);
|
|
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
|
-
|
|
120
|
-
const
|
|
121
|
-
|
|
122
|
-
|
|
123
|
-
|
|
124
|
-
|
|
125
|
-
|
|
118
|
+
function ie(e, n, r) {
|
|
119
|
+
if (!e) return "";
|
|
120
|
+
const t = e.replace(/\D/g, "");
|
|
121
|
+
if (n === "phone")
|
|
122
|
+
return t.replace(/(\d{2})(\d)/, "($1) $2").replace(/(\d{4})(\d)/, "$1-$2").slice(0, 14);
|
|
123
|
+
if (n === "cellphone")
|
|
124
|
+
return t.replace(/(\d{2})(\d)/, "($1) $2").replace(/(\d{5})(\d)/, "$1-$2").slice(0, 15);
|
|
125
|
+
if (n === "cpf")
|
|
126
|
+
return t.replace(/(\d{3})(\d)/, "$1.$2").replace(/(\d{3})(\d)/, "$1.$2").replace(/(\d{3})(\d{1,2})/, "$1-$2").replace(/(-\d{2})\d+?$/, "$1");
|
|
127
|
+
if (n === "cnpj")
|
|
128
|
+
return t.replace(/(\d{2})(\d)/, "$1.$2").replace(/(\d{3})(\d)/, "$1.$2").replace(/(\d{3})(\d)/, "$1/$2").replace(/(\d{4})(\d)/, "$1-$2").replace(/(-\d{2})\d+?$/, "$1");
|
|
129
|
+
if (n === "cep")
|
|
130
|
+
return t.replace(/(\d{5})(\d)/, "$1-$2").slice(0, 9);
|
|
131
|
+
if (n === "custom" && r) {
|
|
132
|
+
let l = 0;
|
|
133
|
+
return r.replace(/[#X0]/g, () => t[l++] || "").replace(/[^0-9a-zA-Z]+$/, "");
|
|
134
|
+
}
|
|
135
|
+
return e;
|
|
136
|
+
}
|
|
137
|
+
function oe({ question: e }) {
|
|
138
|
+
var x, a, s, p, $, B, E, j;
|
|
139
|
+
const { answers: n, setAnswer: r, nextStep: t, schema: l } = R(), d = n[e.id], m = d != null ? String(d) : "", y = Y(null), h = l.questions[0].id === e.id, c = !l.disableAutoFocus || !h;
|
|
140
|
+
T(() => {
|
|
141
|
+
if (c) {
|
|
142
|
+
const S = setTimeout(() => {
|
|
143
|
+
var w;
|
|
144
|
+
(w = y.current) == null || w.focus();
|
|
126
145
|
}, 500);
|
|
127
|
-
return () => clearTimeout(
|
|
146
|
+
return () => clearTimeout(S);
|
|
128
147
|
}
|
|
129
|
-
}, [e.id,
|
|
130
|
-
const
|
|
131
|
-
var
|
|
132
|
-
let
|
|
133
|
-
|
|
134
|
-
|
|
135
|
-
|
|
136
|
-
|
|
148
|
+
}, [e.id, c]);
|
|
149
|
+
const g = (S) => {
|
|
150
|
+
var I, A, F;
|
|
151
|
+
let w = S.target.value;
|
|
152
|
+
((I = e.validation) != null && I.maskType || (A = e.validation) != null && A.mask) && (w = ie(w, e.validation.maskType, e.validation.mask));
|
|
153
|
+
const z = ((F = e.validation) == null ? void 0 : F.maxLength) || 2048;
|
|
154
|
+
if (w.length > z && (w = w.slice(0, z)), e.type === "number") {
|
|
155
|
+
const V = w === "" ? "" : parseFloat(w);
|
|
156
|
+
r(e.id, V);
|
|
137
157
|
} else
|
|
138
|
-
r(e.id,
|
|
139
|
-
},
|
|
140
|
-
var
|
|
141
|
-
if ((
|
|
142
|
-
if (
|
|
143
|
-
if ((
|
|
144
|
-
if ((
|
|
158
|
+
r(e.id, w);
|
|
159
|
+
}, u = () => {
|
|
160
|
+
var S, w, z, I, A;
|
|
161
|
+
if ((S = e.validation) != null && S.required && !m) return !1;
|
|
162
|
+
if (m) {
|
|
163
|
+
if ((w = e.validation) != null && w.minLength && m.length < e.validation.minLength || e.type === "email" && !/^[^\s@]+@[^\s@]+\.[^\s@]+$/.test(m)) return !1;
|
|
164
|
+
if ((z = e.validation) != null && z.pattern)
|
|
145
165
|
try {
|
|
146
|
-
if (!new RegExp(e.validation.pattern).test(
|
|
147
|
-
} catch (
|
|
148
|
-
console.error("Invalid regex pattern in schema",
|
|
166
|
+
if (!new RegExp(e.validation.pattern).test(m)) return !1;
|
|
167
|
+
} catch (F) {
|
|
168
|
+
console.error("Invalid regex pattern in schema", F);
|
|
149
169
|
}
|
|
150
170
|
if (e.type === "number") {
|
|
151
|
-
const
|
|
152
|
-
if (!isNaN(
|
|
171
|
+
const F = parseFloat(m);
|
|
172
|
+
if (!isNaN(F) && (((I = e.validation) == null ? void 0 : I.min) !== void 0 && F < e.validation.min || ((A = e.validation) == null ? void 0 : A.max) !== void 0 && F > e.validation.max))
|
|
153
173
|
return !1;
|
|
154
174
|
}
|
|
155
175
|
}
|
|
156
176
|
return !0;
|
|
157
|
-
},
|
|
158
|
-
if (
|
|
159
|
-
if (
|
|
160
|
-
const
|
|
161
|
-
|
|
177
|
+
}, v = (S) => {
|
|
178
|
+
if (S.key === "Enter" && !S.shiftKey) {
|
|
179
|
+
if (S.preventDefault(), !u()) {
|
|
180
|
+
const w = document.querySelector(".sawabona-form-container") || document.body;
|
|
181
|
+
w.classList.add("shake-animation"), setTimeout(() => w.classList.remove("shake-animation"), 500);
|
|
162
182
|
return;
|
|
163
183
|
}
|
|
164
184
|
t();
|
|
165
185
|
}
|
|
166
186
|
};
|
|
167
|
-
return /* @__PURE__ */
|
|
168
|
-
/* @__PURE__ */
|
|
187
|
+
return /* @__PURE__ */ f("div", { className: "w-full relative group", children: [
|
|
188
|
+
/* @__PURE__ */ i(
|
|
169
189
|
"input",
|
|
170
190
|
{
|
|
171
|
-
ref:
|
|
191
|
+
ref: y,
|
|
172
192
|
type: e.type,
|
|
173
|
-
value: typeof
|
|
174
|
-
onChange:
|
|
175
|
-
onKeyDown:
|
|
193
|
+
value: typeof m == "string" || typeof m == "number" ? m : "",
|
|
194
|
+
onChange: g,
|
|
195
|
+
onKeyDown: v,
|
|
176
196
|
placeholder: e.placeholder,
|
|
177
|
-
minLength: (
|
|
197
|
+
minLength: (x = e.validation) == null ? void 0 : x.minLength,
|
|
178
198
|
maxLength: ((a = e.validation) == null ? void 0 : a.maxLength) || 2048,
|
|
179
199
|
min: (s = e.validation) == null ? void 0 : s.min,
|
|
180
|
-
max: (
|
|
181
|
-
pattern: (
|
|
200
|
+
max: (p = e.validation) == null ? void 0 : p.max,
|
|
201
|
+
pattern: ($ = e.validation) == null ? void 0 : $.pattern,
|
|
182
202
|
className: `
|
|
183
203
|
w-full bg-transparent border-b-2 border-sw-text-secondary/20
|
|
184
204
|
py-4 text-2xl md:text-3xl font-medium outline-none transition-colors
|
|
185
205
|
placeholder:text-sw-text-secondary/30
|
|
186
206
|
focus:border-sw-primary
|
|
187
207
|
font-sw-heading
|
|
188
|
-
|
|
208
|
+
`,
|
|
209
|
+
style: o(o({}, ((B = l.theme) == null ? void 0 : B.labelFont) && { fontFamily: "var(--font-sw-label)" }), ((E = l.theme) == null ? void 0 : E.labelFontSize) && { fontSize: "var(--size-sw-label)" })
|
|
189
210
|
}
|
|
190
211
|
),
|
|
191
212
|
void 0,
|
|
192
|
-
/* @__PURE__ */
|
|
213
|
+
/* @__PURE__ */ i("p", { className: "text-sm opacity-50 mt-4", children: (e.type === "email" || e.type === "text" || e.type === "number" || e.type === "url") && (((j = l.i18n) == null ? void 0 : j.pressEnter) || "Press Enter to continue") })
|
|
193
214
|
] });
|
|
194
215
|
}
|
|
195
|
-
function
|
|
196
|
-
var
|
|
197
|
-
const { answers:
|
|
198
|
-
r(e.id,
|
|
199
|
-
},
|
|
200
|
-
return
|
|
201
|
-
const
|
|
216
|
+
function ae({ question: e }) {
|
|
217
|
+
var h;
|
|
218
|
+
const { answers: n, setAnswer: r, nextStep: t, schema: l } = R(), d = n[e.id] || "", m = (c) => {
|
|
219
|
+
r(e.id, c), setTimeout(() => t(), 400);
|
|
220
|
+
}, y = "ABCDEFGHIJKLMNOPQRSTUVWXYZ";
|
|
221
|
+
return T(() => {
|
|
222
|
+
const c = (g) => {
|
|
202
223
|
var C;
|
|
203
|
-
const
|
|
204
|
-
v >= 0 && v < (((C = e.options) == null ? void 0 : C.length) || 0) &&
|
|
224
|
+
const u = g.key.toUpperCase(), v = y.indexOf(u);
|
|
225
|
+
v >= 0 && v < (((C = e.options) == null ? void 0 : C.length) || 0) && m(e.options[v].value);
|
|
205
226
|
};
|
|
206
|
-
return window.addEventListener("keydown",
|
|
207
|
-
}, [e.options, e.id]), /* @__PURE__ */
|
|
208
|
-
|
|
209
|
-
|
|
210
|
-
|
|
227
|
+
return window.addEventListener("keydown", c), () => window.removeEventListener("keydown", c);
|
|
228
|
+
}, [e.options, e.id]), /* @__PURE__ */ i("div", { className: "flex flex-col gap-3 w-full max-w-xl", style: { gap: "var(--sw-option-gap, 0.75rem)" }, children: (h = e.options) == null ? void 0 : h.map((c, g) => {
|
|
229
|
+
var v, C, x, a, s, p;
|
|
230
|
+
const u = Array.isArray(d) ? d.includes(c.value) : d === c.value;
|
|
231
|
+
return /* @__PURE__ */ f(
|
|
232
|
+
b.button,
|
|
211
233
|
{
|
|
212
234
|
initial: { opacity: 0, y: 10 },
|
|
213
235
|
animate: { opacity: 1, y: 0 },
|
|
214
|
-
transition: { delay:
|
|
215
|
-
onClick: () =>
|
|
236
|
+
transition: { delay: g * 0.05 },
|
|
237
|
+
onClick: () => m(c.value),
|
|
216
238
|
className: `
|
|
217
239
|
w-full text-left p-4 rounded-lg border-2 transition-all duration-200
|
|
218
240
|
flex items-center justify-between group
|
|
219
|
-
${
|
|
241
|
+
${u ? "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"}
|
|
220
242
|
`,
|
|
243
|
+
style: o({
|
|
244
|
+
padding: "var(--sw-option-padding, 1rem)",
|
|
245
|
+
borderRadius: "var(--sw-option-radius, 0.5rem)",
|
|
246
|
+
borderWidth: "var(--sw-option-border, 2px)"
|
|
247
|
+
}, u && ((v = l.theme) != null && v.optionActiveColor) ? {
|
|
248
|
+
borderColor: "var(--sw-option-active)"
|
|
249
|
+
} : {}),
|
|
221
250
|
children: [
|
|
222
|
-
/* @__PURE__ */
|
|
223
|
-
/* @__PURE__ */
|
|
224
|
-
w-6 h-6 rounded-full border-2 flex items-center justify-center transition-colors
|
|
225
|
-
${
|
|
226
|
-
`,
|
|
227
|
-
|
|
251
|
+
/* @__PURE__ */ f("span", { className: "text-lg font-medium flex items-center gap-3", style: o(o({}, ((C = l.theme) == null ? void 0 : C.labelFont) && { fontFamily: "var(--font-sw-label)" }), ((x = l.theme) == null ? void 0 : x.labelFontSize) && { fontSize: "var(--size-sw-label)" }), children: [
|
|
252
|
+
/* @__PURE__ */ i("span", { className: `
|
|
253
|
+
flex-shrink-0 w-6 h-6 rounded-full border-2 flex items-center justify-center transition-colors
|
|
254
|
+
${u ? "border-sw-primary bg-sw-primary" : "border-sw-text-secondary/30 group-hover:border-sw-primary/50"}
|
|
255
|
+
`, style: o({}, u && ((a = l.theme) != null && a.optionActiveColor) ? {
|
|
256
|
+
borderColor: "var(--sw-option-active)",
|
|
257
|
+
backgroundColor: "var(--sw-option-active)"
|
|
258
|
+
} : {}), children: u && /* @__PURE__ */ i(O, { size: 14, className: "text-sw-background" }) }),
|
|
259
|
+
c.label
|
|
228
260
|
] }),
|
|
229
|
-
/* @__PURE__ */
|
|
230
|
-
"Select
|
|
231
|
-
|
|
261
|
+
!((s = l.i18n) != null && s.hideSelectText) && /* @__PURE__ */ f("span", { className: "opacity-0 group-hover:opacity-100 transition-opacity text-xs font-mono uppercase tracking-widest text-sw-text-secondary/50", children: [
|
|
262
|
+
((p = l.i18n) == null ? void 0 : p.selectKey) || "Select",
|
|
263
|
+
" ",
|
|
264
|
+
/* @__PURE__ */ f("span", { className: "hidden md:inline", children: [
|
|
232
265
|
"Key ",
|
|
233
|
-
|
|
266
|
+
g + 1
|
|
234
267
|
] })
|
|
235
268
|
] })
|
|
236
269
|
]
|
|
237
270
|
},
|
|
238
|
-
String(
|
|
271
|
+
String(c.value)
|
|
239
272
|
);
|
|
240
273
|
}) });
|
|
241
274
|
}
|
|
242
|
-
function
|
|
243
|
-
var
|
|
244
|
-
const { answers:
|
|
245
|
-
return /* @__PURE__ */
|
|
246
|
-
/* @__PURE__ */
|
|
247
|
-
const
|
|
248
|
-
return /* @__PURE__ */
|
|
249
|
-
|
|
275
|
+
function le({ question: e }) {
|
|
276
|
+
var d;
|
|
277
|
+
const { answers: n, setAnswer: r } = R(), t = n[e.id] || 0, l = Math.min(((d = e.validation) == null ? void 0 : d.max) || 5, 20);
|
|
278
|
+
return /* @__PURE__ */ f("div", { className: "flex flex-col gap-6", children: [
|
|
279
|
+
/* @__PURE__ */ i("div", { className: "flex gap-4 flex-wrap", children: Array.from({ length: l }).map((m, y) => {
|
|
280
|
+
const h = y + 1, c = h <= t;
|
|
281
|
+
return /* @__PURE__ */ i(
|
|
282
|
+
b.button,
|
|
250
283
|
{
|
|
251
284
|
initial: { opacity: 0, scale: 0 },
|
|
252
285
|
animate: { opacity: 1, scale: 1 },
|
|
253
|
-
transition: { delay:
|
|
254
|
-
onClick: () => r(e.id,
|
|
286
|
+
transition: { delay: y * 0.05 },
|
|
287
|
+
onClick: () => r(e.id, h),
|
|
255
288
|
whileHover: { scale: 1.2, rotate: 5 },
|
|
256
289
|
whileTap: { scale: 0.9 },
|
|
257
290
|
className: "focus:outline-none",
|
|
258
|
-
children: /* @__PURE__ */
|
|
259
|
-
|
|
291
|
+
children: /* @__PURE__ */ i(
|
|
292
|
+
ee,
|
|
260
293
|
{
|
|
261
|
-
className: `w-12 h-12 md:w-16 md:h-16 transition-all duration-300 ${
|
|
294
|
+
className: `w-12 h-12 md:w-16 md:h-16 transition-all duration-300 ${c ? "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"}`,
|
|
262
295
|
strokeWidth: 1.5
|
|
263
296
|
}
|
|
264
297
|
)
|
|
265
298
|
},
|
|
266
|
-
|
|
299
|
+
y
|
|
267
300
|
);
|
|
268
301
|
}) }),
|
|
269
|
-
/* @__PURE__ */
|
|
270
|
-
/* @__PURE__ */
|
|
271
|
-
/* @__PURE__ */
|
|
272
|
-
|
|
302
|
+
/* @__PURE__ */ f("div", { className: "flex justify-between w-full max-w-[300px] md:max-w-[400px] px-2 items-center", children: [
|
|
303
|
+
/* @__PURE__ */ i("span", { className: "text-sm md:text-base font-medium text-sw-text-secondary/50 uppercase tracking-wide", children: e.minLabel || "Poor" }),
|
|
304
|
+
/* @__PURE__ */ i(
|
|
305
|
+
b.div,
|
|
273
306
|
{
|
|
274
307
|
initial: { opacity: 0, scale: 0.8 },
|
|
275
308
|
animate: { opacity: t ? 1 : 0, scale: t ? 1 : 0.8 },
|
|
276
309
|
className: "font-bold text-primary text-xl",
|
|
277
|
-
children: t ? `${t} / ${
|
|
310
|
+
children: t ? `${t} / ${l}` : ""
|
|
278
311
|
}
|
|
279
312
|
),
|
|
280
|
-
/* @__PURE__ */
|
|
313
|
+
/* @__PURE__ */ i("span", { className: "text-sm md:text-base font-medium text-muted-foreground uppercase tracking-wide", children: e.maxLabel || "Excellent" })
|
|
281
314
|
] })
|
|
282
315
|
] });
|
|
283
316
|
}
|
|
284
|
-
function
|
|
285
|
-
|
|
317
|
+
function se({ question: e }) {
|
|
318
|
+
var y, h, c, g;
|
|
319
|
+
const { schema: n } = R(), r = n.questions.findIndex((u) => u.id === e.id) + 1, t = n.questions.length, l = {
|
|
286
320
|
hidden: { opacity: 0, y: 20 },
|
|
287
321
|
visible: { opacity: 1, y: 0, transition: { duration: 0.5, ease: [0.22, 1, 0.36, 1] } }
|
|
288
|
-
},
|
|
289
|
-
const x =
|
|
322
|
+
}, d = (u) => u && u.replace(/\{\{(\w+)\}\}/g, (v, C) => {
|
|
323
|
+
const x = m.answers[C];
|
|
290
324
|
return x != null ? String(x) : "";
|
|
291
|
-
}),
|
|
292
|
-
return /* @__PURE__ */
|
|
293
|
-
|
|
325
|
+
}), m = R();
|
|
326
|
+
return /* @__PURE__ */ f(
|
|
327
|
+
b.div,
|
|
294
328
|
{
|
|
295
329
|
className: "flex flex-col gap-8 w-full max-w-4xl mx-auto",
|
|
296
330
|
initial: "hidden",
|
|
@@ -299,34 +333,36 @@ function ie({ question: e }) {
|
|
|
299
333
|
visible: { transition: { staggerChildren: 0.1 } }
|
|
300
334
|
},
|
|
301
335
|
children: [
|
|
302
|
-
/* @__PURE__ */
|
|
303
|
-
/* @__PURE__ */
|
|
304
|
-
/* @__PURE__ */
|
|
305
|
-
/* @__PURE__ */
|
|
306
|
-
/* @__PURE__ */
|
|
336
|
+
/* @__PURE__ */ f("div", { className: "flex flex-col gap-2", children: [
|
|
337
|
+
/* @__PURE__ */ i(b.div, { variants: l, className: "flex gap-4 items-baseline", children: /* @__PURE__ */ f("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: [
|
|
338
|
+
/* @__PURE__ */ i("span", { children: r }),
|
|
339
|
+
/* @__PURE__ */ i("span", { className: "opacity-40 text-xs", children: "/" }),
|
|
340
|
+
/* @__PURE__ */ i("span", { className: "opacity-60", children: t })
|
|
307
341
|
] }) }),
|
|
308
|
-
/* @__PURE__ */
|
|
309
|
-
|
|
342
|
+
/* @__PURE__ */ f(
|
|
343
|
+
b.h2,
|
|
310
344
|
{
|
|
311
|
-
variants:
|
|
345
|
+
variants: l,
|
|
312
346
|
className: "text-3xl md:text-4xl lg:text-5xl font-bold leading-tight tracking-tight text-pretty mt-2 font-sw-heading",
|
|
347
|
+
style: o(o({}, ((y = n.theme) == null ? void 0 : y.titleFont) && { fontFamily: "var(--font-sw-title)" }), ((h = n.theme) == null ? void 0 : h.titleFontSize) && { fontSize: "var(--size-sw-title)" }),
|
|
313
348
|
children: [
|
|
314
|
-
|
|
349
|
+
d(e.title),
|
|
315
350
|
" ",
|
|
316
|
-
/* @__PURE__ */
|
|
351
|
+
/* @__PURE__ */ i("span", { className: "text-sw-primary", children: "*" })
|
|
317
352
|
]
|
|
318
353
|
}
|
|
319
354
|
),
|
|
320
|
-
e.description && /* @__PURE__ */
|
|
321
|
-
|
|
355
|
+
e.description && /* @__PURE__ */ i(
|
|
356
|
+
b.p,
|
|
322
357
|
{
|
|
323
|
-
variants:
|
|
358
|
+
variants: l,
|
|
324
359
|
className: "text-lg md:text-xl text-muted-foreground font-normal leading-relaxed max-w-2xl mt-2",
|
|
325
|
-
|
|
360
|
+
style: o(o({}, ((c = n.theme) == null ? void 0 : c.descriptionFont) && { fontFamily: "var(--font-sw-description)" }), ((g = n.theme) == null ? void 0 : g.descriptionFontSize) && { fontSize: "var(--size-sw-description)" }),
|
|
361
|
+
children: d(e.description)
|
|
326
362
|
}
|
|
327
363
|
)
|
|
328
364
|
] }),
|
|
329
|
-
/* @__PURE__ */
|
|
365
|
+
/* @__PURE__ */ i(b.div, { variants: l, className: "w-full mt-6", children: e.type === "text" || e.type === "email" || e.type === "number" || e.type === "url" ? /* @__PURE__ */ i(oe, { question: e }) : e.type === "select" ? /* @__PURE__ */ i(ae, { question: e }) : e.type === "rating" ? /* @__PURE__ */ i(le, { question: e }) : /* @__PURE__ */ f("div", { className: "p-4 bg-yellow-100 dark:bg-yellow-900/30 text-yellow-800 dark:text-yellow-200 rounded", children: [
|
|
330
366
|
"Unsupported question type: ",
|
|
331
367
|
e.type,
|
|
332
368
|
" (ID: ",
|
|
@@ -337,7 +373,7 @@ function ie({ question: e }) {
|
|
|
337
373
|
}
|
|
338
374
|
);
|
|
339
375
|
}
|
|
340
|
-
const
|
|
376
|
+
const de = {
|
|
341
377
|
next: "Next",
|
|
342
378
|
back: "Back",
|
|
343
379
|
submit: "Submit",
|
|
@@ -345,16 +381,16 @@ const ae = {
|
|
|
345
381
|
optional: "Optional",
|
|
346
382
|
stepInfo: "Question {{current}} of {{total}}"
|
|
347
383
|
};
|
|
348
|
-
function
|
|
349
|
-
var
|
|
350
|
-
const r =
|
|
384
|
+
function xe({ schema: e, onSubmit: n }) {
|
|
385
|
+
var C;
|
|
386
|
+
const r = ne({ schema: e, onSubmit: n }), t = e.theme || {
|
|
351
387
|
backgroundColor: "#ffffff",
|
|
352
388
|
textColor: "#000000",
|
|
353
389
|
// Start with generic defaults, override in usage
|
|
354
390
|
primaryColor: "#000000",
|
|
355
391
|
borderRadius: "8px"
|
|
356
392
|
// fontFamily removed to allow inheritance
|
|
357
|
-
},
|
|
393
|
+
}, l = o(o({}, de), e.i18n), d = o(o(o(o(o(o(o(o(o(o(o({
|
|
358
394
|
backgroundColor: t.backgroundColor,
|
|
359
395
|
color: t.textColor,
|
|
360
396
|
fontFamily: t.fontFamily,
|
|
@@ -365,91 +401,91 @@ function me({ schema: e, onSubmit: i }) {
|
|
|
365
401
|
"--color-sw-text-secondary": t.textColor,
|
|
366
402
|
"--font-sw-heading": t.fontFamily || "inherit",
|
|
367
403
|
"--font-sw-body": t.fontFamily || "inherit"
|
|
368
|
-
},
|
|
369
|
-
backgroundColor:
|
|
370
|
-
color:
|
|
371
|
-
border:
|
|
404
|
+
}, t.titleFont && { "--font-sw-title": t.titleFont }), t.descriptionFont && { "--font-sw-description": t.descriptionFont }), t.labelFont && { "--font-sw-label": t.labelFont }), t.titleFontSize && { "--size-sw-title": t.titleFontSize }), t.descriptionFontSize && { "--size-sw-description": t.descriptionFontSize }), t.labelFontSize && { "--size-sw-label": t.labelFontSize }), t.optionPadding && { "--sw-option-padding": t.optionPadding }), t.optionBorderRadius && { "--sw-option-radius": t.optionBorderRadius }), t.optionBorderWidth && { "--sw-option-border": t.optionBorderWidth }), t.optionGap && { "--sw-option-gap": t.optionGap }), t.optionActiveColor && { "--sw-option-active": t.optionActiveColor }), m = t.buttonVariant === "outline", y = {
|
|
405
|
+
backgroundColor: m ? "transparent" : t.primaryColor,
|
|
406
|
+
color: m ? t.primaryColor : t.textColor,
|
|
407
|
+
border: m ? `2px solid ${t.primaryColor}` : "none",
|
|
372
408
|
borderRadius: t.borderRadius || "8px",
|
|
373
409
|
fontWeight: 600
|
|
374
|
-
},
|
|
410
|
+
}, h = {
|
|
375
411
|
color: t.primaryColor,
|
|
376
412
|
borderRadius: t.borderRadius || "8px",
|
|
377
413
|
fontWeight: 600
|
|
378
|
-
}, { autoReload:
|
|
379
|
-
if (
|
|
380
|
-
if (r.isCompleted &&
|
|
381
|
-
const
|
|
414
|
+
}, { autoReload: c, reloadDelay: g = 3e3 } = e;
|
|
415
|
+
if (T(() => {
|
|
416
|
+
if (r.isCompleted && c) {
|
|
417
|
+
const x = setTimeout(() => {
|
|
382
418
|
r.resetForm();
|
|
383
|
-
},
|
|
384
|
-
return () => clearTimeout(
|
|
419
|
+
}, g);
|
|
420
|
+
return () => clearTimeout(x);
|
|
385
421
|
}
|
|
386
|
-
}, [r.isCompleted,
|
|
387
|
-
return /* @__PURE__ */
|
|
422
|
+
}, [r.isCompleted, c, g, r.resetForm]), r.isCompleted)
|
|
423
|
+
return /* @__PURE__ */ f(
|
|
388
424
|
"div",
|
|
389
425
|
{
|
|
390
426
|
className: "flex flex-col items-center justify-center h-full w-full p-8 text-center relative overflow-hidden",
|
|
391
|
-
style:
|
|
427
|
+
style: d,
|
|
392
428
|
children: [
|
|
393
|
-
|
|
394
|
-
|
|
429
|
+
c && /* @__PURE__ */ i(
|
|
430
|
+
b.div,
|
|
395
431
|
{
|
|
396
432
|
initial: { width: "0%" },
|
|
397
433
|
animate: { width: "100%" },
|
|
398
|
-
transition: { duration:
|
|
434
|
+
transition: { duration: g / 1e3, ease: "linear" },
|
|
399
435
|
className: "absolute top-0 left-0 h-1 bg-green-500 z-50"
|
|
400
436
|
}
|
|
401
437
|
),
|
|
402
|
-
/* @__PURE__ */
|
|
403
|
-
|
|
438
|
+
/* @__PURE__ */ f(
|
|
439
|
+
b.div,
|
|
404
440
|
{
|
|
405
441
|
initial: { scale: 0.9, opacity: 0, y: 20 },
|
|
406
442
|
animate: { scale: 1, opacity: 1, y: 0 },
|
|
407
443
|
transition: { duration: 0.6, ease: [0.22, 1, 0.36, 1] },
|
|
408
444
|
className: "flex flex-col items-center",
|
|
409
445
|
children: [
|
|
410
|
-
/* @__PURE__ */
|
|
411
|
-
/* @__PURE__ */
|
|
412
|
-
/* @__PURE__ */
|
|
446
|
+
/* @__PURE__ */ i("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__ */ i(O, { size: 48 }) }),
|
|
447
|
+
/* @__PURE__ */ i("h1", { className: "text-4xl md:text-5xl font-bold mb-4 tracking-tight", children: "Obrigado!" }),
|
|
448
|
+
/* @__PURE__ */ i("p", { className: "text-xl opacity-70 max-w-md leading-relaxed", children: "Suas respostas foram enviadas com sucesso." })
|
|
413
449
|
]
|
|
414
450
|
}
|
|
415
451
|
)
|
|
416
452
|
]
|
|
417
453
|
}
|
|
418
454
|
);
|
|
419
|
-
const
|
|
420
|
-
return /* @__PURE__ */
|
|
455
|
+
const u = e.questions.find((x) => x.id === r.currentStepId), v = (e.questions.findIndex((x) => x.id === r.currentStepId) + 1) / e.questions.length * 100;
|
|
456
|
+
return /* @__PURE__ */ i(Q.Provider, { value: N(o({}, r), { schema: e }), children: /* @__PURE__ */ f(
|
|
421
457
|
"div",
|
|
422
458
|
{
|
|
423
459
|
className: "w-full h-full flex flex-col relative overflow-hidden transition-colors duration-700",
|
|
424
|
-
style:
|
|
460
|
+
style: d,
|
|
425
461
|
children: [
|
|
426
|
-
/* @__PURE__ */
|
|
427
|
-
/* @__PURE__ */
|
|
428
|
-
/* @__PURE__ */
|
|
429
|
-
|
|
462
|
+
/* @__PURE__ */ f("div", { className: "absolute top-0 left-0 w-full h-1 z-50", children: [
|
|
463
|
+
/* @__PURE__ */ i("div", { className: "absolute top-0 left-0 w-full h-full bg-current opacity-10" }),
|
|
464
|
+
/* @__PURE__ */ i(
|
|
465
|
+
b.div,
|
|
430
466
|
{
|
|
431
467
|
className: "h-full relative z-10",
|
|
432
468
|
initial: { width: 0 },
|
|
433
|
-
animate: { width: `${
|
|
469
|
+
animate: { width: `${v}%` },
|
|
434
470
|
transition: { duration: 0.5, ease: "easeInOut" },
|
|
435
471
|
style: { backgroundColor: t.primaryColor }
|
|
436
472
|
}
|
|
437
473
|
)
|
|
438
474
|
] }),
|
|
439
|
-
/* @__PURE__ */
|
|
440
|
-
|
|
475
|
+
/* @__PURE__ */ i("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__ */ i(q, { mode: "wait", children: u && /* @__PURE__ */ i(
|
|
476
|
+
b.div,
|
|
441
477
|
{
|
|
442
478
|
initial: { opacity: 0, y: 40 },
|
|
443
479
|
animate: { opacity: 1, y: 0 },
|
|
444
480
|
exit: { opacity: 0, y: -40 },
|
|
445
481
|
transition: { duration: 0.5, ease: [0.22, 1, 0.36, 1] },
|
|
446
482
|
className: "w-full",
|
|
447
|
-
children: /* @__PURE__ */
|
|
483
|
+
children: /* @__PURE__ */ i(se, { question: u })
|
|
448
484
|
},
|
|
449
|
-
|
|
485
|
+
u.id
|
|
450
486
|
) }) }),
|
|
451
|
-
/* @__PURE__ */
|
|
452
|
-
t.showPoweredBy !== !1 && /* @__PURE__ */
|
|
487
|
+
/* @__PURE__ */ f("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: [
|
|
488
|
+
t.showPoweredBy !== !1 && /* @__PURE__ */ f(
|
|
453
489
|
"a",
|
|
454
490
|
{
|
|
455
491
|
href: t.poweredByUrl || "#",
|
|
@@ -457,42 +493,42 @@ function me({ schema: e, onSubmit: i }) {
|
|
|
457
493
|
rel: t.poweredByUrl ? "noopener noreferrer" : void 0,
|
|
458
494
|
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",
|
|
459
495
|
children: [
|
|
460
|
-
/* @__PURE__ */
|
|
461
|
-
/* @__PURE__ */
|
|
496
|
+
/* @__PURE__ */ i("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" }),
|
|
497
|
+
/* @__PURE__ */ i(
|
|
462
498
|
"span",
|
|
463
499
|
{
|
|
464
500
|
className: "text-[10px] md:text-xs font-mono font-bold tracking-[0.2em] uppercase transition-colors shadow-sw-primary",
|
|
465
501
|
style: { color: t.brandColor || t.primaryColor },
|
|
466
|
-
children: ((
|
|
502
|
+
children: ((C = t.poweredBy) == null ? void 0 : C.replace("Powered by ", "")) || "SAWABONA TECH"
|
|
467
503
|
}
|
|
468
504
|
)
|
|
469
505
|
]
|
|
470
506
|
}
|
|
471
507
|
),
|
|
472
|
-
/* @__PURE__ */
|
|
473
|
-
/* @__PURE__ */
|
|
474
|
-
|
|
508
|
+
/* @__PURE__ */ f("div", { className: "flex items-center gap-4 order-2 md:order-3 ml-auto", children: [
|
|
509
|
+
/* @__PURE__ */ i(
|
|
510
|
+
b.button,
|
|
475
511
|
{
|
|
476
512
|
onClick: r.prevStep,
|
|
477
513
|
disabled: r.history.length === 0,
|
|
478
514
|
whileHover: { scale: 1.05 },
|
|
479
515
|
whileTap: { scale: 0.95 },
|
|
480
516
|
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",
|
|
481
|
-
style:
|
|
482
|
-
children: /* @__PURE__ */
|
|
517
|
+
style: h,
|
|
518
|
+
children: /* @__PURE__ */ i(te, { size: 24 })
|
|
483
519
|
}
|
|
484
520
|
),
|
|
485
|
-
/* @__PURE__ */
|
|
486
|
-
|
|
521
|
+
/* @__PURE__ */ f(
|
|
522
|
+
b.button,
|
|
487
523
|
{
|
|
488
524
|
onClick: r.nextStep,
|
|
489
525
|
whileHover: { scale: 1.02 },
|
|
490
526
|
whileTap: { scale: 0.98 },
|
|
491
527
|
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",
|
|
492
|
-
style:
|
|
528
|
+
style: y,
|
|
493
529
|
children: [
|
|
494
|
-
/* @__PURE__ */
|
|
495
|
-
r.currentStepId !== e.questions[e.questions.length - 1].id && /* @__PURE__ */
|
|
530
|
+
/* @__PURE__ */ i("span", { children: r.currentStepId === e.questions[e.questions.length - 1].id ? t.submitText || l.submit : l.next }),
|
|
531
|
+
r.currentStepId !== e.questions[e.questions.length - 1].id && /* @__PURE__ */ i(re, { size: 20, strokeWidth: 3 })
|
|
496
532
|
]
|
|
497
533
|
}
|
|
498
534
|
)
|
|
@@ -503,5 +539,5 @@ function me({ schema: e, onSubmit: i }) {
|
|
|
503
539
|
) });
|
|
504
540
|
}
|
|
505
541
|
export {
|
|
506
|
-
|
|
542
|
+
xe as FormRenderer
|
|
507
543
|
};
|