survo-react-widget 1.0.0 → 1.0.1

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.
@@ -1,296 +1,37 @@
1
- import te, { useState as y, useCallback as ne, useEffect as X } from "react";
2
- var z = { exports: {} }, w = {};
3
- var Z;
4
- function oe() {
5
- if (Z) return w;
6
- Z = 1;
7
- var x = /* @__PURE__ */ Symbol.for("react.transitional.element"), b = /* @__PURE__ */ Symbol.for("react.fragment");
8
- function m(_, u, i) {
9
- var h = null;
10
- if (i !== void 0 && (h = "" + i), u.key !== void 0 && (h = "" + u.key), "key" in u) {
11
- i = {};
12
- for (var p in u)
13
- p !== "key" && (i[p] = u[p]);
14
- } else i = u;
15
- return u = i.ref, {
16
- $$typeof: x,
17
- type: _,
18
- key: h,
19
- ref: u !== void 0 ? u : null,
20
- props: i
21
- };
22
- }
23
- return w.Fragment = b, w.jsx = m, w.jsxs = m, w;
24
- }
25
- var k = {};
26
- var Q;
27
- function ae() {
28
- return Q || (Q = 1, process.env.NODE_ENV !== "production" && (function() {
29
- function x(e) {
30
- if (e == null) return null;
31
- if (typeof e == "function")
32
- return e.$$typeof === a ? null : e.displayName || e.name || null;
33
- if (typeof e == "string") return e;
34
- switch (e) {
35
- case j:
36
- return "Fragment";
37
- case I:
38
- return "Profiler";
39
- case P:
40
- return "StrictMode";
41
- case g:
42
- return "Suspense";
43
- case $:
44
- return "SuspenseList";
45
- case c:
46
- return "Activity";
47
- }
48
- if (typeof e == "object")
49
- switch (typeof e.tag == "number" && console.error(
50
- "Received an unexpected object in getComponentNameFromType(). This is likely a bug in React. Please file an issue."
51
- ), e.$$typeof) {
52
- case W:
53
- return "Portal";
54
- case Y:
55
- return e.displayName || "Context";
56
- case F:
57
- return (e._context.displayName || "Context") + ".Consumer";
58
- case d:
59
- var r = e.render;
60
- return e = e.displayName, e || (e = r.displayName || r.name || "", e = e !== "" ? "ForwardRef(" + e + ")" : "ForwardRef"), e;
61
- case D:
62
- return r = e.displayName || null, r !== null ? r : x(e.type) || "Memo";
63
- case n:
64
- r = e._payload, e = e._init;
65
- try {
66
- return x(e(r));
67
- } catch {
68
- }
69
- }
70
- return null;
71
- }
72
- function b(e) {
73
- return "" + e;
74
- }
75
- function m(e) {
76
- try {
77
- b(e);
78
- var r = !1;
79
- } catch {
80
- r = !0;
81
- }
82
- if (r) {
83
- r = console;
84
- var o = r.error, s = typeof Symbol == "function" && Symbol.toStringTag && e[Symbol.toStringTag] || e.constructor.name || "Object";
85
- return o.call(
86
- r,
87
- "The provided key is an unsupported type %s. This value must be coerced to a string before using it here.",
88
- s
89
- ), b(e);
90
- }
91
- }
92
- function _(e) {
93
- if (e === j) return "<>";
94
- if (typeof e == "object" && e !== null && e.$$typeof === n)
95
- return "<...>";
96
- try {
97
- var r = x(e);
98
- return r ? "<" + r + ">" : "<...>";
99
- } catch {
100
- return "<...>";
101
- }
102
- }
103
- function u() {
104
- var e = f.A;
105
- return e === null ? null : e.getOwner();
106
- }
107
- function i() {
108
- return Error("react-stack-top-frame");
109
- }
110
- function h(e) {
111
- if (V.call(e, "key")) {
112
- var r = Object.getOwnPropertyDescriptor(e, "key").get;
113
- if (r && r.isReactWarning) return !1;
114
- }
115
- return e.key !== void 0;
116
- }
117
- function p(e, r) {
118
- function o() {
119
- J || (J = !0, console.error(
120
- "%s: `key` is not a prop. Trying to access it will result in `undefined` being returned. If you need to access the same value within the child component, you should pass it as a different prop. (https://react.dev/link/special-props)",
121
- r
122
- ));
123
- }
124
- o.isReactWarning = !0, Object.defineProperty(e, "key", {
125
- get: o,
126
- configurable: !0
127
- });
128
- }
129
- function T() {
130
- var e = x(this.type);
131
- return H[e] || (H[e] = !0, console.error(
132
- "Accessing element.ref was removed in React 19. ref is now a regular prop. It will be removed from the JSX Element type in a future release."
133
- )), e = this.props.ref, e !== void 0 ? e : null;
134
- }
135
- function A(e, r, o, s, N, q) {
136
- var l = o.ref;
137
- return e = {
138
- $$typeof: C,
139
- type: e,
140
- key: r,
141
- props: o,
142
- _owner: s
143
- }, (l !== void 0 ? l : null) !== null ? Object.defineProperty(e, "ref", {
144
- enumerable: !1,
145
- get: T
146
- }) : Object.defineProperty(e, "ref", { enumerable: !1, value: null }), e._store = {}, Object.defineProperty(e._store, "validated", {
147
- configurable: !1,
148
- enumerable: !1,
149
- writable: !0,
150
- value: 0
151
- }), Object.defineProperty(e, "_debugInfo", {
152
- configurable: !1,
153
- enumerable: !1,
154
- writable: !0,
155
- value: null
156
- }), Object.defineProperty(e, "_debugStack", {
157
- configurable: !1,
158
- enumerable: !1,
159
- writable: !0,
160
- value: N
161
- }), Object.defineProperty(e, "_debugTask", {
162
- configurable: !1,
163
- enumerable: !1,
164
- writable: !0,
165
- value: q
166
- }), Object.freeze && (Object.freeze(e.props), Object.freeze(e)), e;
167
- }
168
- function O(e, r, o, s, N, q) {
169
- var l = r.children;
170
- if (l !== void 0)
171
- if (s)
172
- if (ee(l)) {
173
- for (s = 0; s < l.length; s++)
174
- S(l[s]);
175
- Object.freeze && Object.freeze(l);
176
- } else
177
- console.error(
178
- "React.jsx: Static children should always be an array. You are likely explicitly calling React.jsxs or React.jsxDEV. Use the Babel transform instead."
179
- );
180
- else S(l);
181
- if (V.call(r, "key")) {
182
- l = x(e);
183
- var R = Object.keys(r).filter(function(re) {
184
- return re !== "key";
185
- });
186
- s = 0 < R.length ? "{key: someKey, " + R.join(": ..., ") + ": ...}" : "{key: someKey}", B[l + s] || (R = 0 < R.length ? "{" + R.join(": ..., ") + ": ...}" : "{}", console.error(
187
- `A props object containing a "key" prop is being spread into JSX:
188
- let props = %s;
189
- <%s {...props} />
190
- React keys must be passed directly to JSX without using spread:
191
- let props = %s;
192
- <%s key={someKey} {...props} />`,
193
- s,
194
- l,
195
- R,
196
- l
197
- ), B[l + s] = !0);
198
- }
199
- if (l = null, o !== void 0 && (m(o), l = "" + o), h(r) && (m(r.key), l = "" + r.key), "key" in r) {
200
- o = {};
201
- for (var L in r)
202
- L !== "key" && (o[L] = r[L]);
203
- } else o = r;
204
- return l && p(
205
- o,
206
- typeof e == "function" ? e.displayName || e.name || "Unknown" : e
207
- ), A(
208
- e,
209
- l,
210
- o,
211
- u(),
212
- N,
213
- q
214
- );
215
- }
216
- function S(e) {
217
- E(e) ? e._store && (e._store.validated = 1) : typeof e == "object" && e !== null && e.$$typeof === n && (e._payload.status === "fulfilled" ? E(e._payload.value) && e._payload.value._store && (e._payload.value._store.validated = 1) : e._store && (e._store.validated = 1));
218
- }
219
- function E(e) {
220
- return typeof e == "object" && e !== null && e.$$typeof === C;
221
- }
222
- var v = te, C = /* @__PURE__ */ Symbol.for("react.transitional.element"), W = /* @__PURE__ */ Symbol.for("react.portal"), j = /* @__PURE__ */ Symbol.for("react.fragment"), P = /* @__PURE__ */ Symbol.for("react.strict_mode"), I = /* @__PURE__ */ Symbol.for("react.profiler"), F = /* @__PURE__ */ Symbol.for("react.consumer"), Y = /* @__PURE__ */ Symbol.for("react.context"), d = /* @__PURE__ */ Symbol.for("react.forward_ref"), g = /* @__PURE__ */ Symbol.for("react.suspense"), $ = /* @__PURE__ */ Symbol.for("react.suspense_list"), D = /* @__PURE__ */ Symbol.for("react.memo"), n = /* @__PURE__ */ Symbol.for("react.lazy"), c = /* @__PURE__ */ Symbol.for("react.activity"), a = /* @__PURE__ */ Symbol.for("react.client.reference"), f = v.__CLIENT_INTERNALS_DO_NOT_USE_OR_WARN_USERS_THEY_CANNOT_UPGRADE, V = Object.prototype.hasOwnProperty, ee = Array.isArray, M = console.createTask ? console.createTask : function() {
223
- return null;
224
- };
225
- v = {
226
- react_stack_bottom_frame: function(e) {
227
- return e();
228
- }
229
- };
230
- var J, H = {}, U = v.react_stack_bottom_frame.bind(
231
- v,
232
- i
233
- )(), G = M(_(i)), B = {};
234
- k.Fragment = j, k.jsx = function(e, r, o) {
235
- var s = 1e4 > f.recentlyCreatedOwnerStacks++;
236
- return O(
237
- e,
238
- r,
239
- o,
240
- !1,
241
- s ? Error("react-stack-top-frame") : U,
242
- s ? M(_(e)) : G
243
- );
244
- }, k.jsxs = function(e, r, o) {
245
- var s = 1e4 > f.recentlyCreatedOwnerStacks++;
246
- return O(
247
- e,
248
- r,
249
- o,
250
- !0,
251
- s ? Error("react-stack-top-frame") : U,
252
- s ? M(_(e)) : G
253
- );
254
- };
255
- })()), k;
256
- }
257
- var K;
258
- function ie() {
259
- return K || (K = 1, process.env.NODE_ENV === "production" ? z.exports = oe() : z.exports = ae()), z.exports;
260
- }
261
- var t = ie();
262
- const le = ({
263
- apiKey: x,
264
- surveyId: b,
265
- display: m = "modal",
266
- containerId: _ = "survo-widget",
1
+ import { jsxs as a, jsx as e } from "react/jsx-runtime";
2
+ import { useState as c, useCallback as F, useEffect as S } from "react";
3
+ const H = ({
4
+ apiKey: p,
5
+ surveyId: f,
6
+ display: g = "modal",
7
+ containerId: E = "survo-widget",
267
8
  baseUrl: u = "https://api.survo.digital"
268
9
  }) => {
269
- const [i, h] = y(null), [p, T] = y(-1), [A, O] = y({}), [S, E] = y(!0), [v, C] = y(!1), [W, j] = y(!0), P = ne(async () => {
10
+ const [l, k] = c(null), [s, h] = c(-1), [b, z] = c({}), [y, x] = c(!0), [m, C] = c(!1), [W, v] = c(!0), w = F(async () => {
270
11
  try {
271
- const n = await fetch(`${u}/api/v1/widget/config?key=${x}&surveyId=${b}`);
272
- if (!n.ok) throw new Error("Failed to load");
273
- const c = await n.json();
274
- h(c.survey);
275
- } catch (n) {
276
- console.error("[Survo Widget] Error loading survey:", n);
12
+ const t = await fetch(`${u}/api/v1/widget/config?key=${p}&surveyId=${f}`);
13
+ if (!t.ok) throw new Error("Failed to load");
14
+ const r = await t.json();
15
+ k(r.survey);
16
+ } catch (t) {
17
+ console.error("[Survo Widget] Error loading survey:", t);
277
18
  } finally {
278
- E(!1);
19
+ x(!1);
279
20
  }
280
- }, [x, b, u]);
281
- X(() => {
282
- P();
283
- }, [P]);
284
- const I = async () => {
285
- E(!0);
21
+ }, [p, f, u]);
22
+ S(() => {
23
+ w();
24
+ }, [w]);
25
+ const j = async () => {
26
+ x(!0);
286
27
  try {
287
28
  await fetch(`${u}/api/v1/widget/submit`, {
288
29
  method: "POST",
289
30
  headers: { "Content-Type": "application/json" },
290
31
  body: JSON.stringify({
291
- key: x,
292
- surveyId: b,
293
- answers: A,
32
+ key: p,
33
+ surveyId: f,
34
+ answers: b,
294
35
  metadata: {
295
36
  domain: window.location.hostname,
296
37
  url: window.location.href,
@@ -298,27 +39,27 @@ const le = ({
298
39
  }
299
40
  })
300
41
  }), C(!0);
301
- } catch (n) {
302
- console.error("[Survo Widget] Error submitting answers:", n), alert("Erro ao enviar. Por favor tente novamente.");
42
+ } catch (t) {
43
+ console.error("[Survo Widget] Error submitting answers:", t), alert("Erro ao enviar. Por favor tente novamente.");
303
44
  } finally {
304
- E(!1);
45
+ x(!1);
305
46
  }
306
- }, F = (n) => {
307
- const c = i?.questions[p];
308
- if (c?.required && (n === null || n === "")) {
47
+ }, A = (t) => {
48
+ const r = l?.questions[s];
49
+ if (r?.required && (t === null || t === "")) {
309
50
  alert("Por favor, responda a esta pergunta.");
310
51
  return;
311
52
  }
312
- const a = { ...A };
313
- c && (a[c.id] = n), O(a), p + 1 >= (i?.questions.length || 0) ? I() : T(p + 1);
53
+ const n = { ...b };
54
+ r && (n[r.id] = t), z(n), s + 1 >= (l?.questions.length || 0) ? j() : h(s + 1);
314
55
  };
315
- if (!W || !S && !i) return null;
316
- const Y = () => {
317
- if (S && !v)
318
- return /* @__PURE__ */ t.jsx("div", { style: { textAlign: "center", padding: "40px 0" }, children: /* @__PURE__ */ t.jsx("p", { style: { color: "#64748b", fontSize: "14px" }, children: "A carregar..." }) });
319
- if (v)
320
- return /* @__PURE__ */ t.jsxs("div", { style: { textAlign: "center", padding: "20px 0" }, children: [
321
- /* @__PURE__ */ t.jsx("div", { style: {
56
+ if (!W || !y && !l) return null;
57
+ const R = () => {
58
+ if (y && !m)
59
+ return /* @__PURE__ */ e("div", { style: { textAlign: "center", padding: "40px 0" }, children: /* @__PURE__ */ e("p", { style: { color: "#64748b", fontSize: "14px" }, children: "A carregar..." }) });
60
+ if (m)
61
+ return /* @__PURE__ */ a("div", { style: { textAlign: "center", padding: "20px 0" }, children: [
62
+ /* @__PURE__ */ e("div", { style: {
322
63
  width: "64px",
323
64
  height: "64px",
324
65
  background: "#000",
@@ -331,12 +72,12 @@ const le = ({
331
72
  fontSize: "32px",
332
73
  fontWeight: 700
333
74
  }, children: "✓" }),
334
- /* @__PURE__ */ t.jsx("h3", { style: { margin: 0, fontSize: "20px", fontWeight: 700, color: "#000" }, children: "Muito Obrigado!" }),
335
- /* @__PURE__ */ t.jsx("p", { style: { fontSize: "14px", color: "#64748b", marginTop: "12px", lineHeight: 1.5 }, children: "Recebemos as suas respostas com sucesso. A sua opinião faz a diferença!" }),
336
- /* @__PURE__ */ t.jsx(
75
+ /* @__PURE__ */ e("h3", { style: { margin: 0, fontSize: "20px", fontWeight: 700, color: "#000" }, children: "Muito Obrigado!" }),
76
+ /* @__PURE__ */ e("p", { style: { fontSize: "14px", color: "#64748b", marginTop: "12px", lineHeight: 1.5 }, children: "Recebemos as suas respostas com sucesso. A sua opinião faz a diferença!" }),
77
+ /* @__PURE__ */ e(
337
78
  "button",
338
79
  {
339
- onClick: () => j(!1),
80
+ onClick: () => v(!1),
340
81
  style: {
341
82
  marginTop: "24px",
342
83
  padding: "12px",
@@ -352,13 +93,13 @@ const le = ({
352
93
  }
353
94
  )
354
95
  ] });
355
- if (p === -1)
356
- return /* @__PURE__ */ t.jsxs("div", { children: [
357
- /* @__PURE__ */ t.jsx("p", { style: { color: "#64748b", fontSize: "14px", margin: "0 0 24px 0", lineHeight: 1.5 }, children: i?.description || "A sua opinião é muito importante para nós." }),
358
- /* @__PURE__ */ t.jsx(
96
+ if (s === -1)
97
+ return /* @__PURE__ */ a("div", { children: [
98
+ /* @__PURE__ */ e("p", { style: { color: "#64748b", fontSize: "14px", margin: "0 0 24px 0", lineHeight: 1.5 }, children: l?.description || "A sua opinião é muito importante para nós." }),
99
+ /* @__PURE__ */ e(
359
100
  "button",
360
101
  {
361
- onClick: () => T(0),
102
+ onClick: () => h(0),
362
103
  style: {
363
104
  width: "100%",
364
105
  padding: "12px",
@@ -374,21 +115,21 @@ const le = ({
374
115
  }
375
116
  )
376
117
  ] });
377
- const n = i.questions[p];
378
- return /* @__PURE__ */ t.jsxs("div", { children: [
379
- /* @__PURE__ */ t.jsxs("div", { style: { fontSize: "10px", fontWeight: 700, color: "#94a3b8", textTransform: "uppercase", marginBottom: "8px", letterSpacing: "0.05em" }, children: [
118
+ const t = l.questions[s];
119
+ return /* @__PURE__ */ a("div", { children: [
120
+ /* @__PURE__ */ a("div", { style: { fontSize: "10px", fontWeight: 700, color: "#94a3b8", textTransform: "uppercase", marginBottom: "8px", letterSpacing: "0.05em" }, children: [
380
121
  "Pergunta ",
381
- p + 1,
122
+ s + 1,
382
123
  " de ",
383
- i.questions.length
124
+ l.questions.length
384
125
  ] }),
385
- /* @__PURE__ */ t.jsx("h4", { style: { margin: "0 0 20px 0", fontSize: "16px", color: "#000", fontWeight: 600, lineHeight: 1.4 }, children: n.title }),
386
- /* @__PURE__ */ t.jsx("div", { style: { marginBottom: "20px" }, children: $(n) }),
387
- /* @__PURE__ */ t.jsx(
126
+ /* @__PURE__ */ e("h4", { style: { margin: "0 0 20px 0", fontSize: "16px", color: "#000", fontWeight: 600, lineHeight: 1.4 }, children: t.title }),
127
+ /* @__PURE__ */ e("div", { style: { marginBottom: "20px" }, children: I(t) }),
128
+ /* @__PURE__ */ e(
388
129
  "button",
389
130
  {
390
131
  id: "survo-next-btn",
391
- onClick: () => F(d),
132
+ onClick: () => A(o),
392
133
  style: {
393
134
  width: "100%",
394
135
  padding: "12px",
@@ -400,21 +141,21 @@ const le = ({
400
141
  fontWeight: 600,
401
142
  fontSize: "14px"
402
143
  },
403
- children: p + 1 === i.questions.length ? "Finalizar" : "Continuar"
144
+ children: s + 1 === l.questions.length ? "Finalizar" : "Continuar"
404
145
  }
405
146
  )
406
147
  ] });
407
- }, [d, g] = y(null);
408
- X(() => {
409
- g(null);
410
- }, [p]);
411
- const $ = (n) => {
412
- if (["choice", "multiple_choice", "single_choice"].includes(n.type)) {
413
- const c = Object.values(n.options || {});
414
- return /* @__PURE__ */ t.jsx("div", { style: { display: "flex", flexDirection: "column", gap: "8px" }, children: c.map((a, f) => /* @__PURE__ */ t.jsx(
148
+ }, [o, d] = c(null);
149
+ S(() => {
150
+ d(null);
151
+ }, [s]);
152
+ const I = (t) => {
153
+ if (["choice", "multiple_choice", "single_choice"].includes(t.type)) {
154
+ const r = Object.values(t.options || {});
155
+ return /* @__PURE__ */ e("div", { style: { display: "flex", flexDirection: "column", gap: "8px" }, children: r.map((n, i) => /* @__PURE__ */ e(
415
156
  "div",
416
157
  {
417
- onClick: () => g(a),
158
+ onClick: () => d(n),
418
159
  style: {
419
160
  padding: "12px",
420
161
  border: "1px solid #e2e8f0",
@@ -422,60 +163,56 @@ const le = ({
422
163
  cursor: "pointer",
423
164
  fontSize: "14px",
424
165
  color: "#1e293b",
425
- background: d === a ? "#f1f5f9" : "#fff",
426
- borderColor: d === a ? "#000" : "#e2e8f0",
427
- borderWidth: d === a ? "2px" : "1px",
428
- fontWeight: d === a ? 600 : 400,
166
+ background: o === n ? "#f1f5f9" : "#fff",
167
+ borderColor: o === n ? "#000" : "#e2e8f0",
168
+ borderWidth: o === n ? "2px" : "1px",
169
+ fontWeight: o === n ? 600 : 400,
429
170
  textAlign: "left"
430
171
  },
431
- children: a
172
+ children: n
432
173
  },
433
- f
174
+ i
434
175
  )) });
435
176
  }
436
- if (n.type === "rating") {
437
- const c = n.maxStars || 5;
438
- return /* @__PURE__ */ t.jsx("div", { style: { display: "flex", gap: "12px", justifyContent: "flex-start" }, children: Array.from({ length: c }).map((a, f) => /* @__PURE__ */ t.jsx(
177
+ if (t.type === "rating") {
178
+ const r = t.maxStars || 5;
179
+ return /* @__PURE__ */ e("div", { style: { display: "flex", gap: "12px", justifyContent: "flex-start" }, children: Array.from({ length: r }).map((n, i) => /* @__PURE__ */ e(
439
180
  "button",
440
181
  {
441
- onClick: () => g(f + 1),
182
+ onClick: () => d(i + 1),
442
183
  style: {
443
184
  fontSize: "34px",
444
185
  background: "none",
445
186
  border: "none",
446
187
  cursor: "pointer",
447
- color: (d || 0) > f ? "#000" : "#e2e8f0",
188
+ color: (o || 0) > i ? "#000" : "#e2e8f0",
448
189
  padding: 0
449
190
  },
450
191
  children: "★"
451
192
  },
452
- f
193
+ i
453
194
  )) });
454
195
  }
455
- if (n.type === "rating_emoji") {
456
- const c = ["😡", "🙁", "😐", "🙂", "😍"];
457
- return /* @__PURE__ */ t.jsx("div", { style: { display: "flex", gap: "12px", justifyContent: "flex-start" }, children: c.map((a, f) => /* @__PURE__ */ t.jsx(
458
- "span",
459
- {
460
- onClick: () => g(f + 1),
461
- style: {
462
- fontSize: "28px",
463
- cursor: "pointer",
464
- opacity: d === f + 1 ? 1 : 0.3,
465
- filter: d === f + 1 ? "grayscale(0)" : "grayscale(1)",
466
- transform: d === f + 1 ? "scale(1.2)" : "scale(1)",
467
- transition: "all 0.2s"
468
- },
469
- children: a
196
+ return t.type === "rating_emoji" ? /* @__PURE__ */ e("div", { style: { display: "flex", gap: "12px", justifyContent: "flex-start" }, children: ["😡", "🙁", "😐", "🙂", "😍"].map((n, i) => /* @__PURE__ */ e(
197
+ "span",
198
+ {
199
+ onClick: () => d(i + 1),
200
+ style: {
201
+ fontSize: "28px",
202
+ cursor: "pointer",
203
+ opacity: o === i + 1 ? 1 : 0.3,
204
+ filter: o === i + 1 ? "grayscale(0)" : "grayscale(1)",
205
+ transform: o === i + 1 ? "scale(1.2)" : "scale(1)",
206
+ transition: "all 0.2s"
470
207
  },
471
- f
472
- )) });
473
- }
474
- return n.type === "nps" ? /* @__PURE__ */ t.jsxs("div", { children: [
475
- /* @__PURE__ */ t.jsx("div", { style: { display: "flex", justifyContent: "space-between", border: "1px solid #e2e8f0", borderRadius: "8px", padding: "4px" }, children: Array.from({ length: 11 }).map((c, a) => /* @__PURE__ */ t.jsx(
208
+ children: n
209
+ },
210
+ i
211
+ )) }) : t.type === "nps" ? /* @__PURE__ */ a("div", { children: [
212
+ /* @__PURE__ */ e("div", { style: { display: "flex", justifyContent: "space-between", border: "1px solid #e2e8f0", borderRadius: "8px", padding: "4px" }, children: Array.from({ length: 11 }).map((r, n) => /* @__PURE__ */ e(
476
213
  "div",
477
214
  {
478
- onClick: () => g(a),
215
+ onClick: () => d(n),
479
216
  style: {
480
217
  flex: 1,
481
218
  textAlign: "center",
@@ -484,23 +221,23 @@ const le = ({
484
221
  fontWeight: 600,
485
222
  cursor: "pointer",
486
223
  borderRadius: "4px",
487
- background: d === a ? "#000" : "transparent",
488
- color: d === a ? "#fff" : "#1e293b"
224
+ background: o === n ? "#000" : "transparent",
225
+ color: o === n ? "#fff" : "#1e293b"
489
226
  },
490
- children: a
227
+ children: n
491
228
  },
492
- a
229
+ n
493
230
  )) }),
494
- /* @__PURE__ */ t.jsxs("div", { style: { display: "flex", justifyContent: "space-between", fontSize: "10px", color: "#94a3b8", marginTop: "8px" }, children: [
495
- /* @__PURE__ */ t.jsx("span", { children: "Nada provável" }),
496
- /* @__PURE__ */ t.jsx("span", { children: "Muito provável" })
231
+ /* @__PURE__ */ a("div", { style: { display: "flex", justifyContent: "space-between", fontSize: "10px", color: "#94a3b8", marginTop: "8px" }, children: [
232
+ /* @__PURE__ */ e("span", { children: "Nada provável" }),
233
+ /* @__PURE__ */ e("span", { children: "Muito provável" })
497
234
  ] })
498
- ] }) : n.type === "long_text" ? /* @__PURE__ */ t.jsx(
235
+ ] }) : t.type === "long_text" ? /* @__PURE__ */ e(
499
236
  "textarea",
500
237
  {
501
238
  autoFocus: !0,
502
- value: d || "",
503
- onChange: (c) => g(c.target.value),
239
+ value: o || "",
240
+ onChange: (r) => d(r.target.value),
504
241
  placeholder: "Escreva a sua resposta detalhada...",
505
242
  style: {
506
243
  width: "100%",
@@ -513,13 +250,13 @@ const le = ({
513
250
  boxSizing: "border-box"
514
251
  }
515
252
  }
516
- ) : /* @__PURE__ */ t.jsx(
253
+ ) : /* @__PURE__ */ e(
517
254
  "input",
518
255
  {
519
256
  autoFocus: !0,
520
257
  type: "text",
521
- value: d || "",
522
- onChange: (c) => g(c.target.value),
258
+ value: o || "",
259
+ onChange: (r) => d(r.target.value),
523
260
  placeholder: "Escreva aqui...",
524
261
  style: {
525
262
  width: "100%",
@@ -532,7 +269,8 @@ const le = ({
532
269
  }
533
270
  }
534
271
  );
535
- }, D = m === "modal" ? {
272
+ };
273
+ return /* @__PURE__ */ a("div", { className: "survo-react-widget", style: g === "modal" ? {
536
274
  position: "fixed",
537
275
  bottom: "20px",
538
276
  right: "20px",
@@ -556,26 +294,25 @@ const le = ({
556
294
  flexDirection: "column",
557
295
  overflow: "hidden",
558
296
  fontFamily: "'Inter', -apple-system, sans-serif"
559
- };
560
- return /* @__PURE__ */ t.jsxs("div", { className: "survo-react-widget", style: D, children: [
561
- /* @__PURE__ */ t.jsxs("div", { style: { padding: "16px", background: "#fff", borderBottom: "1px solid #f1f5f9", display: "flex", justifyContent: "space-between", alignItems: "center" }, children: [
562
- /* @__PURE__ */ t.jsx("span", { style: { fontWeight: 700, fontSize: "14px", color: "#000", overflow: "hidden", textOverflow: "ellipsis", whiteSpace: "nowrap" }, children: i?.title || "Carregando..." }),
563
- m === "modal" && /* @__PURE__ */ t.jsx(
297
+ }, children: [
298
+ /* @__PURE__ */ a("div", { style: { padding: "16px", background: "#fff", borderBottom: "1px solid #f1f5f9", display: "flex", justifyContent: "space-between", alignItems: "center" }, children: [
299
+ /* @__PURE__ */ e("span", { style: { fontWeight: 700, fontSize: "14px", color: "#000", overflow: "hidden", textOverflow: "ellipsis", whiteSpace: "nowrap" }, children: l?.title || "Carregando..." }),
300
+ g === "modal" && /* @__PURE__ */ e(
564
301
  "button",
565
302
  {
566
- onClick: () => j(!1),
303
+ onClick: () => v(!1),
567
304
  style: { background: "none", border: "none", cursor: "pointer", color: "#000", fontSize: "24px", lineHeight: 1, padding: "4px" },
568
305
  children: "×"
569
306
  }
570
307
  )
571
308
  ] }),
572
- /* @__PURE__ */ t.jsx("div", { style: { padding: "24px", overflowY: "auto" }, children: Y() }),
573
- /* @__PURE__ */ t.jsxs("div", { style: { padding: "10px", textAlign: "center", fontSize: "10px", color: "#94a3b8", background: "#fff", borderTop: "1px solid #f1f5f9" }, children: [
309
+ /* @__PURE__ */ e("div", { style: { padding: "24px", overflowY: "auto" }, children: R() }),
310
+ /* @__PURE__ */ a("div", { style: { padding: "10px", textAlign: "center", fontSize: "10px", color: "#94a3b8", background: "#fff", borderTop: "1px solid #f1f5f9" }, children: [
574
311
  "Disponibilizado pelo ",
575
- /* @__PURE__ */ t.jsx("a", { href: "https://survo.digital", target: "_blank", rel: "noopener noreferrer", style: { color: "#64748b", fontWeight: 700, textDecoration: "none" }, children: "Survo" })
312
+ /* @__PURE__ */ e("a", { href: "https://survo.digital", target: "_blank", rel: "noopener noreferrer", style: { color: "#64748b", fontWeight: 700, textDecoration: "none" }, children: "Survo" })
576
313
  ] })
577
314
  ] });
578
315
  };
579
316
  export {
580
- le as SurvoWidget
317
+ H as SurvoWidget
581
318
  };
@@ -1,6 +1 @@
1
- (function(v,u){typeof exports=="object"&&typeof module<"u"?u(exports,require("react")):typeof define=="function"&&define.amd?define(["exports","react"],u):(v=typeof globalThis<"u"?globalThis:v||self,u(v.SurvoReact={},v.React))})(this,(function(v,u){"use strict";var A={exports:{}},w={};var U;function ee(){if(U)return w;U=1;var g=Symbol.for("react.transitional.element"),m=Symbol.for("react.fragment");function h(j,d,i){var y=null;if(i!==void 0&&(y=""+i),d.key!==void 0&&(y=""+d.key),"key"in d){i={};for(var x in d)x!=="key"&&(i[x]=d[x])}else i=d;return d=i.ref,{$$typeof:g,type:j,key:y,ref:d!==void 0?d:null,props:i}}return w.Fragment=m,w.jsx=h,w.jsxs=h,w}var k={};var G;function re(){return G||(G=1,process.env.NODE_ENV!=="production"&&(function(){function g(e){if(e==null)return null;if(typeof e=="function")return e.$$typeof===a?null:e.displayName||e.name||null;if(typeof e=="string")return e;switch(e){case _:return"Fragment";case F:return"Profiler";case z:return"StrictMode";case b:return"Suspense";case M:return"SuspenseList";case c:return"Activity"}if(typeof e=="object")switch(typeof e.tag=="number"&&console.error("Received an unexpected object in getComponentNameFromType(). This is likely a bug in React. Please file an issue."),e.$$typeof){case I:return"Portal";case D:return e.displayName||"Context";case Y:return(e._context.displayName||"Context")+".Consumer";case f:var r=e.render;return e=e.displayName,e||(e=r.displayName||r.name||"",e=e!==""?"ForwardRef("+e+")":"ForwardRef"),e;case L:return r=e.displayName||null,r!==null?r:g(e.type)||"Memo";case n:r=e._payload,e=e._init;try{return g(e(r))}catch{}}return null}function m(e){return""+e}function h(e){try{m(e);var r=!1}catch{r=!0}if(r){r=console;var o=r.error,s=typeof Symbol=="function"&&Symbol.toStringTag&&e[Symbol.toStringTag]||e.constructor.name||"Object";return o.call(r,"The provided key is an unsupported type %s. This value must be coerced to a string before using it here.",s),m(e)}}function j(e){if(e===_)return"<>";if(typeof e=="object"&&e!==null&&e.$$typeof===n)return"<...>";try{var r=g(e);return r?"<"+r+">":"<...>"}catch{return"<...>"}}function d(){var e=p.A;return e===null?null:e.getOwner()}function i(){return Error("react-stack-top-frame")}function y(e){if(X.call(e,"key")){var r=Object.getOwnPropertyDescriptor(e,"key").get;if(r&&r.isReactWarning)return!1}return e.key!==void 0}function x(e,r){function o(){q||(q=!0,console.error("%s: `key` is not a prop. Trying to access it will result in `undefined` being returned. If you need to access the same value within the child component, you should pass it as a different prop. (https://react.dev/link/special-props)",r))}o.isReactWarning=!0,Object.defineProperty(e,"key",{get:o,configurable:!0})}function O(){var e=g(this.type);return Z[e]||(Z[e]=!0,console.error("Accessing element.ref was removed in React 19. ref is now a regular prop. It will be removed from the JSX Element type in a future release.")),e=this.props.ref,e!==void 0?e:null}function C(e,r,o,s,W,J){var l=o.ref;return e={$$typeof:N,type:e,key:r,props:o,_owner:s},(l!==void 0?l:null)!==null?Object.defineProperty(e,"ref",{enumerable:!1,get:O}):Object.defineProperty(e,"ref",{enumerable:!1,value:null}),e._store={},Object.defineProperty(e._store,"validated",{configurable:!1,enumerable:!1,writable:!0,value:0}),Object.defineProperty(e,"_debugInfo",{configurable:!1,enumerable:!1,writable:!0,value:null}),Object.defineProperty(e,"_debugStack",{configurable:!1,enumerable:!1,writable:!0,value:W}),Object.defineProperty(e,"_debugTask",{configurable:!1,enumerable:!1,writable:!0,value:J}),Object.freeze&&(Object.freeze(e.props),Object.freeze(e)),e}function P(e,r,o,s,W,J){var l=r.children;if(l!==void 0)if(s)if(oe(l)){for(s=0;s<l.length;s++)T(l[s]);Object.freeze&&Object.freeze(l)}else console.error("React.jsx: Static children should always be an array. You are likely explicitly calling React.jsxs or React.jsxDEV. Use the Babel transform instead.");else T(l);if(X.call(r,"key")){l=g(e);var R=Object.keys(r).filter(function(ae){return ae!=="key"});s=0<R.length?"{key: someKey, "+R.join(": ..., ")+": ...}":"{key: someKey}",K[l+s]||(R=0<R.length?"{"+R.join(": ..., ")+": ...}":"{}",console.error(`A props object containing a "key" prop is being spread into JSX:
2
- let props = %s;
3
- <%s {...props} />
4
- React keys must be passed directly to JSX without using spread:
5
- let props = %s;
6
- <%s key={someKey} {...props} />`,s,l,R,l),K[l+s]=!0)}if(l=null,o!==void 0&&(h(o),l=""+o),y(r)&&(h(r.key),l=""+r.key),"key"in r){o={};for(var H in r)H!=="key"&&(o[H]=r[H])}else o=r;return l&&x(o,typeof e=="function"?e.displayName||e.name||"Unknown":e),C(e,l,o,d(),W,J)}function T(e){E(e)?e._store&&(e._store.validated=1):typeof e=="object"&&e!==null&&e.$$typeof===n&&(e._payload.status==="fulfilled"?E(e._payload.value)&&e._payload.value._store&&(e._payload.value._store.validated=1):e._store&&(e._store.validated=1))}function E(e){return typeof e=="object"&&e!==null&&e.$$typeof===N}var S=u,N=Symbol.for("react.transitional.element"),I=Symbol.for("react.portal"),_=Symbol.for("react.fragment"),z=Symbol.for("react.strict_mode"),F=Symbol.for("react.profiler"),Y=Symbol.for("react.consumer"),D=Symbol.for("react.context"),f=Symbol.for("react.forward_ref"),b=Symbol.for("react.suspense"),M=Symbol.for("react.suspense_list"),L=Symbol.for("react.memo"),n=Symbol.for("react.lazy"),c=Symbol.for("react.activity"),a=Symbol.for("react.client.reference"),p=S.__CLIENT_INTERNALS_DO_NOT_USE_OR_WARN_USERS_THEY_CANNOT_UPGRADE,X=Object.prototype.hasOwnProperty,oe=Array.isArray,V=console.createTask?console.createTask:function(){return null};S={react_stack_bottom_frame:function(e){return e()}};var q,Z={},Q=S.react_stack_bottom_frame.bind(S,i)(),$=V(j(i)),K={};k.Fragment=_,k.jsx=function(e,r,o){var s=1e4>p.recentlyCreatedOwnerStacks++;return P(e,r,o,!1,s?Error("react-stack-top-frame"):Q,s?V(j(e)):$)},k.jsxs=function(e,r,o){var s=1e4>p.recentlyCreatedOwnerStacks++;return P(e,r,o,!0,s?Error("react-stack-top-frame"):Q,s?V(j(e)):$)}})()),k}var B;function te(){return B||(B=1,process.env.NODE_ENV==="production"?A.exports=ee():A.exports=re()),A.exports}var t=te();const ne=({apiKey:g,surveyId:m,display:h="modal",containerId:j="survo-widget",baseUrl:d="https://api.survo.digital"})=>{const[i,y]=u.useState(null),[x,O]=u.useState(-1),[C,P]=u.useState({}),[T,E]=u.useState(!0),[S,N]=u.useState(!1),[I,_]=u.useState(!0),z=u.useCallback(async()=>{try{const n=await fetch(`${d}/api/v1/widget/config?key=${g}&surveyId=${m}`);if(!n.ok)throw new Error("Failed to load");const c=await n.json();y(c.survey)}catch(n){console.error("[Survo Widget] Error loading survey:",n)}finally{E(!1)}},[g,m,d]);u.useEffect(()=>{z()},[z]);const F=async()=>{E(!0);try{await fetch(`${d}/api/v1/widget/submit`,{method:"POST",headers:{"Content-Type":"application/json"},body:JSON.stringify({key:g,surveyId:m,answers:C,metadata:{domain:window.location.hostname,url:window.location.href,submittedVia:"react-widget"}})}),N(!0)}catch(n){console.error("[Survo Widget] Error submitting answers:",n),alert("Erro ao enviar. Por favor tente novamente.")}finally{E(!1)}},Y=n=>{const c=i?.questions[x];if(c?.required&&(n===null||n==="")){alert("Por favor, responda a esta pergunta.");return}const a={...C};c&&(a[c.id]=n),P(a),x+1>=(i?.questions.length||0)?F():O(x+1)};if(!I||!T&&!i)return null;const D=()=>{if(T&&!S)return t.jsx("div",{style:{textAlign:"center",padding:"40px 0"},children:t.jsx("p",{style:{color:"#64748b",fontSize:"14px"},children:"A carregar..."})});if(S)return t.jsxs("div",{style:{textAlign:"center",padding:"20px 0"},children:[t.jsx("div",{style:{width:"64px",height:"64px",background:"#000",borderRadius:"50%",margin:"0 auto 16px auto",display:"flex",alignItems:"center",justifyContent:"center",color:"#fff",fontSize:"32px",fontWeight:700},children:"✓"}),t.jsx("h3",{style:{margin:0,fontSize:"20px",fontWeight:700,color:"#000"},children:"Muito Obrigado!"}),t.jsx("p",{style:{fontSize:"14px",color:"#64748b",marginTop:"12px",lineHeight:1.5},children:"Recebemos as suas respostas com sucesso. A sua opinião faz a diferença!"}),t.jsx("button",{onClick:()=>_(!1),style:{marginTop:"24px",padding:"12px",width:"100%",background:"#f1f5f9",color:"#475569",border:"none",borderRadius:"8px",cursor:"pointer",fontWeight:600},children:"Fechar"})]});if(x===-1)return t.jsxs("div",{children:[t.jsx("p",{style:{color:"#64748b",fontSize:"14px",margin:"0 0 24px 0",lineHeight:1.5},children:i?.description||"A sua opinião é muito importante para nós."}),t.jsx("button",{onClick:()=>O(0),style:{width:"100%",padding:"12px",background:"#000",color:"#fff",border:"none",borderRadius:"8px",cursor:"pointer",fontWeight:600,fontSize:"14px"},children:"Começar Inquérito"})]});const n=i.questions[x];return t.jsxs("div",{children:[t.jsxs("div",{style:{fontSize:"10px",fontWeight:700,color:"#94a3b8",textTransform:"uppercase",marginBottom:"8px",letterSpacing:"0.05em"},children:["Pergunta ",x+1," de ",i.questions.length]}),t.jsx("h4",{style:{margin:"0 0 20px 0",fontSize:"16px",color:"#000",fontWeight:600,lineHeight:1.4},children:n.title}),t.jsx("div",{style:{marginBottom:"20px"},children:M(n)}),t.jsx("button",{id:"survo-next-btn",onClick:()=>Y(f),style:{width:"100%",padding:"12px",background:"#000",color:"#fff",border:"none",borderRadius:"8px",cursor:"pointer",fontWeight:600,fontSize:"14px"},children:x+1===i.questions.length?"Finalizar":"Continuar"})]})},[f,b]=u.useState(null);u.useEffect(()=>{b(null)},[x]);const M=n=>{if(["choice","multiple_choice","single_choice"].includes(n.type)){const c=Object.values(n.options||{});return t.jsx("div",{style:{display:"flex",flexDirection:"column",gap:"8px"},children:c.map((a,p)=>t.jsx("div",{onClick:()=>b(a),style:{padding:"12px",border:"1px solid #e2e8f0",borderRadius:"8px",cursor:"pointer",fontSize:"14px",color:"#1e293b",background:f===a?"#f1f5f9":"#fff",borderColor:f===a?"#000":"#e2e8f0",borderWidth:f===a?"2px":"1px",fontWeight:f===a?600:400,textAlign:"left"},children:a},p))})}if(n.type==="rating"){const c=n.maxStars||5;return t.jsx("div",{style:{display:"flex",gap:"12px",justifyContent:"flex-start"},children:Array.from({length:c}).map((a,p)=>t.jsx("button",{onClick:()=>b(p+1),style:{fontSize:"34px",background:"none",border:"none",cursor:"pointer",color:(f||0)>p?"#000":"#e2e8f0",padding:0},children:"★"},p))})}if(n.type==="rating_emoji"){const c=["😡","🙁","😐","🙂","😍"];return t.jsx("div",{style:{display:"flex",gap:"12px",justifyContent:"flex-start"},children:c.map((a,p)=>t.jsx("span",{onClick:()=>b(p+1),style:{fontSize:"28px",cursor:"pointer",opacity:f===p+1?1:.3,filter:f===p+1?"grayscale(0)":"grayscale(1)",transform:f===p+1?"scale(1.2)":"scale(1)",transition:"all 0.2s"},children:a},p))})}return n.type==="nps"?t.jsxs("div",{children:[t.jsx("div",{style:{display:"flex",justifyContent:"space-between",border:"1px solid #e2e8f0",borderRadius:"8px",padding:"4px"},children:Array.from({length:11}).map((c,a)=>t.jsx("div",{onClick:()=>b(a),style:{flex:1,textAlign:"center",padding:"8px 0",fontSize:"12px",fontWeight:600,cursor:"pointer",borderRadius:"4px",background:f===a?"#000":"transparent",color:f===a?"#fff":"#1e293b"},children:a},a))}),t.jsxs("div",{style:{display:"flex",justifyContent:"space-between",fontSize:"10px",color:"#94a3b8",marginTop:"8px"},children:[t.jsx("span",{children:"Nada provável"}),t.jsx("span",{children:"Muito provável"})]})]}):n.type==="long_text"?t.jsx("textarea",{autoFocus:!0,value:f||"",onChange:c=>b(c.target.value),placeholder:"Escreva a sua resposta detalhada...",style:{width:"100%",padding:"12px",border:"1px solid #e2e8f0",borderRadius:"8px",fontSize:"14px",fontFamily:"inherit",minHeight:"100px",boxSizing:"border-box"}}):t.jsx("input",{autoFocus:!0,type:"text",value:f||"",onChange:c=>b(c.target.value),placeholder:"Escreva aqui...",style:{width:"100%",padding:"12px",border:"1px solid #e2e8f0",borderRadius:"8px",fontSize:"14px",fontFamily:"inherit",boxSizing:"border-box"}})},L=h==="modal"?{position:"fixed",bottom:"20px",right:"20px",width:"360px",maxHeight:"85vh",boxShadow:"0 15px 45px rgba(0,0,0,0.15)",borderRadius:"16px",zIndex:9999990,background:"#fff",border:"1px solid rgba(0,0,0,0.1)",display:"flex",flexDirection:"column",overflow:"hidden",fontFamily:"'Inter', -apple-system, sans-serif"}:{width:"100%",background:"#fff",border:"1px solid rgba(0,0,0,0.1)",borderRadius:"12px",display:"flex",flexDirection:"column",overflow:"hidden",fontFamily:"'Inter', -apple-system, sans-serif"};return t.jsxs("div",{className:"survo-react-widget",style:L,children:[t.jsxs("div",{style:{padding:"16px",background:"#fff",borderBottom:"1px solid #f1f5f9",display:"flex",justifyContent:"space-between",alignItems:"center"},children:[t.jsx("span",{style:{fontWeight:700,fontSize:"14px",color:"#000",overflow:"hidden",textOverflow:"ellipsis",whiteSpace:"nowrap"},children:i?.title||"Carregando..."}),h==="modal"&&t.jsx("button",{onClick:()=>_(!1),style:{background:"none",border:"none",cursor:"pointer",color:"#000",fontSize:"24px",lineHeight:1,padding:"4px"},children:"×"})]}),t.jsx("div",{style:{padding:"24px",overflowY:"auto"},children:D()}),t.jsxs("div",{style:{padding:"10px",textAlign:"center",fontSize:"10px",color:"#94a3b8",background:"#fff",borderTop:"1px solid #f1f5f9"},children:["Disponibilizado pelo ",t.jsx("a",{href:"https://survo.digital",target:"_blank",rel:"noopener noreferrer",style:{color:"#64748b",fontWeight:700,textDecoration:"none"},children:"Survo"})]})]})};v.SurvoWidget=ne,Object.defineProperty(v,Symbol.toStringTag,{value:"Module"})}));
1
+ (function(a,e){typeof exports=="object"&&typeof module<"u"?e(exports,require("react/jsx-runtime"),require("react")):typeof define=="function"&&define.amd?define(["exports","react/jsx-runtime","react"],e):(a=typeof globalThis<"u"?globalThis:a||self,e(a.SurvoReact={},a.React,a.React))})(this,(function(a,e,s){"use strict";const m=({apiKey:c,surveyId:f,display:g="modal",containerId:E="survo-widget",baseUrl:u="https://api.survo.digital"})=>{const[d,k]=s.useState(null),[l,h]=s.useState(-1),[b,z]=s.useState({}),[y,x]=s.useState(!0),[v,C]=s.useState(!1),[j,S]=s.useState(!0),w=s.useCallback(async()=>{try{const t=await fetch(`${u}/api/v1/widget/config?key=${c}&surveyId=${f}`);if(!t.ok)throw new Error("Failed to load");const r=await t.json();k(r.survey)}catch(t){console.error("[Survo Widget] Error loading survey:",t)}finally{x(!1)}},[c,f,u]);s.useEffect(()=>{w()},[w]);const W=async()=>{x(!0);try{await fetch(`${u}/api/v1/widget/submit`,{method:"POST",headers:{"Content-Type":"application/json"},body:JSON.stringify({key:c,surveyId:f,answers:b,metadata:{domain:window.location.hostname,url:window.location.href,submittedVia:"react-widget"}})}),C(!0)}catch(t){console.error("[Survo Widget] Error submitting answers:",t),alert("Erro ao enviar. Por favor tente novamente.")}finally{x(!1)}},A=t=>{const r=d?.questions[l];if(r?.required&&(t===null||t==="")){alert("Por favor, responda a esta pergunta.");return}const o={...b};r&&(o[r.id]=t),z(o),l+1>=(d?.questions.length||0)?W():h(l+1)};if(!j||!y&&!d)return null;const I=()=>{if(y&&!v)return e.jsx("div",{style:{textAlign:"center",padding:"40px 0"},children:e.jsx("p",{style:{color:"#64748b",fontSize:"14px"},children:"A carregar..."})});if(v)return e.jsxs("div",{style:{textAlign:"center",padding:"20px 0"},children:[e.jsx("div",{style:{width:"64px",height:"64px",background:"#000",borderRadius:"50%",margin:"0 auto 16px auto",display:"flex",alignItems:"center",justifyContent:"center",color:"#fff",fontSize:"32px",fontWeight:700},children:""}),e.jsx("h3",{style:{margin:0,fontSize:"20px",fontWeight:700,color:"#000"},children:"Muito Obrigado!"}),e.jsx("p",{style:{fontSize:"14px",color:"#64748b",marginTop:"12px",lineHeight:1.5},children:"Recebemos as suas respostas com sucesso. A sua opinião faz a diferença!"}),e.jsx("button",{onClick:()=>S(!1),style:{marginTop:"24px",padding:"12px",width:"100%",background:"#f1f5f9",color:"#475569",border:"none",borderRadius:"8px",cursor:"pointer",fontWeight:600},children:"Fechar"})]});if(l===-1)return e.jsxs("div",{children:[e.jsx("p",{style:{color:"#64748b",fontSize:"14px",margin:"0 0 24px 0",lineHeight:1.5},children:d?.description||"A sua opinião é muito importante para nós."}),e.jsx("button",{onClick:()=>h(0),style:{width:"100%",padding:"12px",background:"#000",color:"#fff",border:"none",borderRadius:"8px",cursor:"pointer",fontWeight:600,fontSize:"14px"},children:"Começar Inquérito"})]});const t=d.questions[l];return e.jsxs("div",{children:[e.jsxs("div",{style:{fontSize:"10px",fontWeight:700,color:"#94a3b8",textTransform:"uppercase",marginBottom:"8px",letterSpacing:"0.05em"},children:["Pergunta ",l+1," de ",d.questions.length]}),e.jsx("h4",{style:{margin:"0 0 20px 0",fontSize:"16px",color:"#000",fontWeight:600,lineHeight:1.4},children:t.title}),e.jsx("div",{style:{marginBottom:"20px"},children:T(t)}),e.jsx("button",{id:"survo-next-btn",onClick:()=>A(n),style:{width:"100%",padding:"12px",background:"#000",color:"#fff",border:"none",borderRadius:"8px",cursor:"pointer",fontWeight:600,fontSize:"14px"},children:l+1===d.questions.length?"Finalizar":"Continuar"})]})},[n,p]=s.useState(null);s.useEffect(()=>{p(null)},[l]);const T=t=>{if(["choice","multiple_choice","single_choice"].includes(t.type)){const r=Object.values(t.options||{});return e.jsx("div",{style:{display:"flex",flexDirection:"column",gap:"8px"},children:r.map((o,i)=>e.jsx("div",{onClick:()=>p(o),style:{padding:"12px",border:"1px solid #e2e8f0",borderRadius:"8px",cursor:"pointer",fontSize:"14px",color:"#1e293b",background:n===o?"#f1f5f9":"#fff",borderColor:n===o?"#000":"#e2e8f0",borderWidth:n===o?"2px":"1px",fontWeight:n===o?600:400,textAlign:"left"},children:o},i))})}if(t.type==="rating"){const r=t.maxStars||5;return e.jsx("div",{style:{display:"flex",gap:"12px",justifyContent:"flex-start"},children:Array.from({length:r}).map((o,i)=>e.jsx("button",{onClick:()=>p(i+1),style:{fontSize:"34px",background:"none",border:"none",cursor:"pointer",color:(n||0)>i?"#000":"#e2e8f0",padding:0},children:"★"},i))})}if(t.type==="rating_emoji"){const r=["😡","🙁","😐","🙂","😍"];return e.jsx("div",{style:{display:"flex",gap:"12px",justifyContent:"flex-start"},children:r.map((o,i)=>e.jsx("span",{onClick:()=>p(i+1),style:{fontSize:"28px",cursor:"pointer",opacity:n===i+1?1:.3,filter:n===i+1?"grayscale(0)":"grayscale(1)",transform:n===i+1?"scale(1.2)":"scale(1)",transition:"all 0.2s"},children:o},i))})}return t.type==="nps"?e.jsxs("div",{children:[e.jsx("div",{style:{display:"flex",justifyContent:"space-between",border:"1px solid #e2e8f0",borderRadius:"8px",padding:"4px"},children:Array.from({length:11}).map((r,o)=>e.jsx("div",{onClick:()=>p(o),style:{flex:1,textAlign:"center",padding:"8px 0",fontSize:"12px",fontWeight:600,cursor:"pointer",borderRadius:"4px",background:n===o?"#000":"transparent",color:n===o?"#fff":"#1e293b"},children:o},o))}),e.jsxs("div",{style:{display:"flex",justifyContent:"space-between",fontSize:"10px",color:"#94a3b8",marginTop:"8px"},children:[e.jsx("span",{children:"Nada provável"}),e.jsx("span",{children:"Muito provável"})]})]}):t.type==="long_text"?e.jsx("textarea",{autoFocus:!0,value:n||"",onChange:r=>p(r.target.value),placeholder:"Escreva a sua resposta detalhada...",style:{width:"100%",padding:"12px",border:"1px solid #e2e8f0",borderRadius:"8px",fontSize:"14px",fontFamily:"inherit",minHeight:"100px",boxSizing:"border-box"}}):e.jsx("input",{autoFocus:!0,type:"text",value:n||"",onChange:r=>p(r.target.value),placeholder:"Escreva aqui...",style:{width:"100%",padding:"12px",border:"1px solid #e2e8f0",borderRadius:"8px",fontSize:"14px",fontFamily:"inherit",boxSizing:"border-box"}})},F=g==="modal"?{position:"fixed",bottom:"20px",right:"20px",width:"360px",maxHeight:"85vh",boxShadow:"0 15px 45px rgba(0,0,0,0.15)",borderRadius:"16px",zIndex:9999990,background:"#fff",border:"1px solid rgba(0,0,0,0.1)",display:"flex",flexDirection:"column",overflow:"hidden",fontFamily:"'Inter', -apple-system, sans-serif"}:{width:"100%",background:"#fff",border:"1px solid rgba(0,0,0,0.1)",borderRadius:"12px",display:"flex",flexDirection:"column",overflow:"hidden",fontFamily:"'Inter', -apple-system, sans-serif"};return e.jsxs("div",{className:"survo-react-widget",style:F,children:[e.jsxs("div",{style:{padding:"16px",background:"#fff",borderBottom:"1px solid #f1f5f9",display:"flex",justifyContent:"space-between",alignItems:"center"},children:[e.jsx("span",{style:{fontWeight:700,fontSize:"14px",color:"#000",overflow:"hidden",textOverflow:"ellipsis",whiteSpace:"nowrap"},children:d?.title||"Carregando..."}),g==="modal"&&e.jsx("button",{onClick:()=>S(!1),style:{background:"none",border:"none",cursor:"pointer",color:"#000",fontSize:"24px",lineHeight:1,padding:"4px"},children:"×"})]}),e.jsx("div",{style:{padding:"24px",overflowY:"auto"},children:I()}),e.jsxs("div",{style:{padding:"10px",textAlign:"center",fontSize:"10px",color:"#94a3b8",background:"#fff",borderTop:"1px solid #f1f5f9"},children:["Disponibilizado pelo ",e.jsx("a",{href:"https://survo.digital",target:"_blank",rel:"noopener noreferrer",style:{color:"#64748b",fontWeight:700,textDecoration:"none"},children:"Survo"})]})]})};a.SurvoWidget=m,Object.defineProperty(a,Symbol.toStringTag,{value:"Module"})}));
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "survo-react-widget",
3
- "version": "1.0.0",
3
+ "version": "1.0.1",
4
4
  "description": "Native React widget for Survo surveys — embed beautiful survey forms in your React app",
5
5
  "type": "module",
6
6
  "main": "./dist/survo-react.umd.js",