treege 3.0.0-beta.26 → 3.0.0-beta.28

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.
Files changed (58) hide show
  1. package/README.md +188 -24
  2. package/dist/ThemeContext-BBEqRK_Q.js +429 -0
  3. package/dist/{TreegeEditor-WqTXkYl3.js → TreegeEditor-Bi7GcSKl.js} +198 -197
  4. package/dist/TreegeRenderer-DbE0m_4e.js +1047 -0
  5. package/dist/editor.js +2 -2
  6. package/dist/main.js +50 -49
  7. package/dist/renderer/features/TreegeRenderer/native/TreegeRenderer.d.ts +19 -11
  8. package/dist/renderer/features/TreegeRenderer/native/components/DefaultFormWrapper.d.ts +7 -7
  9. package/dist/renderer/features/TreegeRenderer/native/components/DefaultGroup.d.ts +7 -7
  10. package/dist/renderer/features/TreegeRenderer/native/components/DefaultInputs.d.ts +26 -15
  11. package/dist/renderer/features/TreegeRenderer/native/components/DefaultSubmitButton.d.ts +9 -7
  12. package/dist/renderer/features/TreegeRenderer/native/components/DefaultSubmitButtonWrapper.d.ts +11 -0
  13. package/dist/renderer/features/TreegeRenderer/native/components/DefaultUI.d.ts +8 -7
  14. package/dist/renderer/features/TreegeRenderer/native/components/inputs/DefaultAddressInput.d.ts +3 -0
  15. package/dist/renderer/features/TreegeRenderer/native/components/inputs/DefaultAutocompleteInput.d.ts +3 -0
  16. package/dist/renderer/features/TreegeRenderer/native/components/inputs/DefaultCheckboxInput.d.ts +3 -0
  17. package/dist/renderer/features/TreegeRenderer/native/components/inputs/DefaultDateInput.d.ts +3 -0
  18. package/dist/renderer/features/TreegeRenderer/native/components/inputs/DefaultDateRangeInput.d.ts +3 -0
  19. package/dist/renderer/features/TreegeRenderer/native/components/inputs/DefaultFileInput.d.ts +3 -0
  20. package/dist/renderer/features/TreegeRenderer/native/components/inputs/DefaultHiddenInput.d.ts +3 -0
  21. package/dist/renderer/features/TreegeRenderer/native/components/inputs/DefaultHttpInput.d.ts +3 -0
  22. package/dist/renderer/features/TreegeRenderer/native/components/inputs/DefaultNumberInput.d.ts +3 -0
  23. package/dist/renderer/features/TreegeRenderer/native/components/inputs/DefaultPasswordInput.d.ts +3 -0
  24. package/dist/renderer/features/TreegeRenderer/native/components/inputs/DefaultRadioInput.d.ts +3 -0
  25. package/dist/renderer/features/TreegeRenderer/native/components/inputs/DefaultSelectInput.d.ts +3 -0
  26. package/dist/renderer/features/TreegeRenderer/native/components/inputs/DefaultSwitchInput.d.ts +3 -0
  27. package/dist/renderer/features/TreegeRenderer/native/components/inputs/DefaultTextInput.d.ts +3 -0
  28. package/dist/renderer/features/TreegeRenderer/native/components/inputs/DefaultTextareaInput.d.ts +3 -0
  29. package/dist/renderer/features/TreegeRenderer/native/components/inputs/DefaultTimeInput.d.ts +3 -0
  30. package/dist/renderer/features/TreegeRenderer/native/components/inputs/DefaultTimeRangeInput.d.ts +3 -0
  31. package/dist/renderer/features/TreegeRenderer/useTreegeRenderer.d.ts +81 -23
  32. package/dist/renderer/features/TreegeRenderer/web/TreegeRenderer.d.ts +1 -1
  33. package/dist/renderer/hooks/useRenderNode.d.ts +55 -0
  34. package/dist/renderer/index.d.ts +1 -0
  35. package/dist/renderer/index.native.d.ts +19 -0
  36. package/dist/renderer/types/renderer.d.ts +20 -4
  37. package/dist/renderer/utils/sanitize.native.d.ts +69 -0
  38. package/dist/renderer/utils/submit.d.ts +1 -1
  39. package/dist/renderer-native.d.ts +2 -0
  40. package/dist/renderer-native.js +2833 -0
  41. package/dist/renderer.js +48 -47
  42. package/dist/separator-oCo7kxCK.js +364 -0
  43. package/dist/shared/constants/colors.d.ts +45 -0
  44. package/dist/shared/context/ThemeContext.d.ts +2 -0
  45. package/dist/shared/context/ThemeContext.native.d.ts +22 -0
  46. package/dist/shared/hooks/useThemeColors.d.ts +37 -0
  47. package/dist/shared/locales/ar.json.d.ts +13 -5
  48. package/dist/shared/locales/de.json.d.ts +13 -5
  49. package/dist/shared/locales/en.json.d.ts +13 -5
  50. package/dist/shared/locales/es.json.d.ts +13 -5
  51. package/dist/shared/locales/fr.json.d.ts +13 -5
  52. package/dist/shared/locales/it.json.d.ts +13 -5
  53. package/dist/shared/locales/pt.json.d.ts +13 -5
  54. package/dist/shared/types/node.d.ts +2 -2
  55. package/dist/useRenderNode-BACcrUML.js +863 -0
  56. package/package.json +24 -1
  57. package/dist/ThemeContext-BIT4DHqC.js +0 -764
  58. package/dist/TreegeRenderer-BSR_ez96.js +0 -1812
@@ -1,1812 +0,0 @@
1
- import { j as t, i as G, L as ye, b as Qe, e as It, F as O, f as A, I as X, C as Ee, h as Oe, k as ke, l as _e, m as Pe, n as k, o as _, P as pe, p as he, B as ce, q as ge, r as Xe, s as y, t as Le, v as Be, S as Ye, w as Ze, x as et, y as tt, z as st, A as rt, D as At, E as Dt, G as Ne, g as ae, N as fe, a as Rt, c as Et, T as Ot } from "./ThemeContext-BIT4DHqC.js";
2
- import * as qe from "react";
3
- import { createContext as nt, useContext as at, useMemo as U, useRef as K, useState as L, useCallback as Q, useEffect as J, forwardRef as kt } from "react";
4
- import He from "dompurify";
5
- import { MapPin as Ue, ChevronsUpDown as ot, Check as it, ChevronLeftIcon as _t, ChevronRightIcon as Pt, ChevronDownIcon as Me, Loader2 as we, CircleIcon as Mt } from "lucide-react";
6
- import { getDefaultClassNames as lt, DayPicker as $t } from "react-day-picker";
7
- import * as oe from "@radix-ui/react-tooltip";
8
- import * as Ae from "@radix-ui/react-radio-group";
9
- import "cmdk";
10
- import "@radix-ui/react-dialog";
11
- import "clsx";
12
- import "tailwind-merge";
13
- import "@radix-ui/react-label";
14
- import "@radix-ui/react-popover";
15
- import "@radix-ui/react-checkbox";
16
- import "@radix-ui/react-select";
17
- import "@radix-ui/react-switch";
18
- import "@radix-ui/react-separator";
19
- const ct = nt(void 0), dt = () => at(ct), Zs = ({
20
- children: e,
21
- components: r,
22
- googleApiKey: n,
23
- language: s,
24
- theme: a,
25
- validationMode: i
26
- }) => {
27
- const o = {
28
- components: r,
29
- googleApiKey: n,
30
- language: s,
31
- theme: a,
32
- validationMode: i
33
- };
34
- return /* @__PURE__ */ t.jsx(ct.Provider, { value: o, children: e });
35
- }, We = (e) => e == null ? null : typeof e == "boolean" || typeof e == "number" ? e : typeof e == "string" ? e === "" ? null : e : typeof e == "object" ? JSON.stringify(e) : String(e), zt = (e, r, n) => {
36
- const s = We(e), a = We(r);
37
- if (s === null || a === null)
38
- switch (n) {
39
- case "===":
40
- return s === a;
41
- case "!==":
42
- return s !== a;
43
- default:
44
- return !1;
45
- }
46
- if ([">", "<", ">=", "<="].includes(n)) {
47
- const i = Number(s), o = Number(a);
48
- if (!(Number.isNaN(i) || Number.isNaN(o)))
49
- switch (n) {
50
- case ">":
51
- return i > o;
52
- case "<":
53
- return i < o;
54
- case ">=":
55
- return i >= o;
56
- case "<=":
57
- return i <= o;
58
- default:
59
- return !1;
60
- }
61
- return !1;
62
- }
63
- switch (n) {
64
- case "===": {
65
- const i = Number(s), o = Number(a);
66
- return Number.isNaN(i) || Number.isNaN(o) ? String(s) === String(a) : i === o;
67
- }
68
- case "!==": {
69
- const i = Number(s), o = Number(a);
70
- return Number.isNaN(i) || Number.isNaN(o) ? String(s) !== String(a) : i !== o;
71
- }
72
- default:
73
- return !1;
74
- }
75
- }, ve = (e, r, n) => {
76
- const { field: s, operator: a, value: i } = e;
77
- if (!(s && a) || i === void 0)
78
- return !0;
79
- let o = r[s];
80
- if (o === void 0 && n) {
81
- const c = n.get(s);
82
- c && G(c) && (o = r[c.id]);
83
- }
84
- return zt(o, i, a);
85
- }, Vt = (e, r, n) => {
86
- if (!e || e.length === 0)
87
- return !0;
88
- if (e.length === 1)
89
- return ve(e[0], r, n);
90
- let s = ve(e[0], r, n);
91
- for (let a = 1; a < e.length; a += 1) {
92
- const i = e[a], o = ve(i, r, n), c = e[a - 1].logicalOperator || ye.AND;
93
- if (c === ye.AND) {
94
- if (s = s && o, !s)
95
- return !1;
96
- } else if (c === ye.OR && (s = s || o, s))
97
- return !0;
98
- }
99
- return s;
100
- }, Lt = (e) => e.filter(G), $e = (e) => {
101
- if (e.data.name)
102
- return e.data.name;
103
- if (e.data.label) {
104
- if (e.data.label.en)
105
- return e.data.label.en;
106
- const r = Object.values(e.data.label).find(Boolean);
107
- if (r)
108
- return r;
109
- }
110
- return e.id;
111
- }, Bt = (e, r) => {
112
- const n = r.find((s) => s.id === e);
113
- return n ? $e(n) : void 0;
114
- }, Se = (e) => e == null || typeof e == "string" && e.trim() === "" ? !0 : Array.isArray(e) && e.length === 0, qt = (e, r) => {
115
- if (!e)
116
- return !1;
117
- const n = r[e];
118
- return n != null;
119
- }, ze = (e, r) => {
120
- const n = {};
121
- return r.forEach((s) => {
122
- const a = s.id, i = $e(s);
123
- e[a] !== void 0 && (n[i] = e[a]);
124
- }), n;
125
- }, Ge = (e, r, n) => {
126
- if (!r)
127
- return e;
128
- switch (r) {
129
- case "toString":
130
- return String(e);
131
- case "toNumber":
132
- return Number(e);
133
- case "toBoolean":
134
- if (typeof e == "string") {
135
- const s = e.trim().toLowerCase();
136
- if (["true", "1", "yes", "on"].includes(s))
137
- return !0;
138
- if (["false", "0", "no", "off", ""].includes(s))
139
- return !1;
140
- }
141
- return typeof e == "number" ? e !== 0 : typeof e == "boolean" ? e : !!e;
142
- case "toArray":
143
- return Array.isArray(e) ? e : [e];
144
- case "toObject":
145
- if (n && Array.isArray(n)) {
146
- if (typeof e != "object" || e === null)
147
- return e;
148
- const s = {};
149
- return n.forEach((a) => {
150
- a.sourceKey && a.targetKey && (s[a.targetKey] = e[a.sourceKey]);
151
- }), s;
152
- }
153
- return e;
154
- default:
155
- return e;
156
- }
157
- }, Ke = (e, r) => {
158
- if (Object.is(e, r))
159
- return !0;
160
- if (!(e && r) || typeof e != "object" || typeof r != "object")
161
- return !1;
162
- try {
163
- return JSON.stringify(e) === JSON.stringify(r);
164
- } catch {
165
- return !1;
166
- }
167
- }, Ht = (e, r, n) => {
168
- const s = {};
169
- return e.forEach((a) => {
170
- const { defaultValue: i } = a.data;
171
- if (!i || i.type !== "reference" || !i.referenceField)
172
- return;
173
- const o = a.id, { referenceField: c, transformFunction: l, objectMapping: m } = i, u = r[c], d = n[c];
174
- if (u === d || u === void 0 || u === null)
175
- return;
176
- const f = Ge(u, l, m), g = Ge(d, l, m), h = r[o], p = Ke(h, g), j = Ke(h, f);
177
- !p || j || (s[o] = f);
178
- }), s;
179
- }, Ut = (e) => {
180
- const r = /* @__PURE__ */ new Map();
181
- return e.forEach((n) => {
182
- const s = r.get(n.source);
183
- s ? s.push(n) : r.set(n.source, [n]);
184
- }), r;
185
- }, Wt = (e, r, n) => {
186
- const s = [], a = [], i = [];
187
- e.forEach((m) => {
188
- const u = m.data?.isFallback, d = m.data?.conditions?.length;
189
- u ? i.push(m) : d ? a.push(m) : s.push(m);
190
- });
191
- const o = [...s];
192
- if (a.length === 0)
193
- return i.length > 0 && o.length === 0 && o.push(...i), { edgesToFollow: o, waitingForInput: !1 };
194
- if (!a.every((m) => {
195
- const u = m.data?.conditions;
196
- return u ? u.every((d) => {
197
- if (!d.field)
198
- return !0;
199
- const f = n.get(d.field), g = G(f) ? f.id : d.field;
200
- return qt(g, r);
201
- }) : !1;
202
- }))
203
- return i.length > 0 && o.push(...i), { edgesToFollow: o, waitingForInput: o.length === 0 };
204
- const l = a.filter((m) => Vt(m.data?.conditions, r, n));
205
- return l.length > 0 ? (o.push(...l), { edgesToFollow: o, waitingForInput: !1 }) : (o.push(...i), { edgesToFollow: o, waitingForInput: !1 });
206
- }, ut = (e, r) => !r.some((n) => n.target === e), Gt = (e, r) => {
207
- const n = e.filter((s) => ut(s.id, r));
208
- return n.find(G) || n[0];
209
- }, Kt = (e, r, n, s) => {
210
- e.forEach((a) => {
211
- const i = s.get(a);
212
- if (!i)
213
- return;
214
- let { parentId: o } = i;
215
- const c = /* @__PURE__ */ new Set();
216
- for (; o && !c.has(o); ) {
217
- if (c.add(o), r.add(o), !n.has(o)) {
218
- const l = n.get(a);
219
- l !== void 0 && n.set(o, l);
220
- }
221
- o = s.get(o)?.parentId;
222
- }
223
- });
224
- }, Jt = (e, r, n) => {
225
- const s = Gt(e, r);
226
- if (!s)
227
- return {
228
- endOfPathReached: !0,
229
- visibleNodeIds: /* @__PURE__ */ new Set(),
230
- visibleNodes: [],
231
- visibleRootNodes: []
232
- };
233
- const a = new Map(e.map((p) => [p.id, p])), i = Ut(r), o = [], c = /* @__PURE__ */ new Set(), l = /* @__PURE__ */ new Set();
234
- let m = !1;
235
- const u = (p) => {
236
- if (l.has(p))
237
- return;
238
- l.add(p);
239
- const j = a.get(p);
240
- if (!j)
241
- return;
242
- c.add(p), o.push(j);
243
- const I = i.get(p) || [], { edgesToFollow: M, waitingForInput: D } = Wt(I, n, a);
244
- if (D) {
245
- m = !0;
246
- return;
247
- }
248
- M.forEach((w) => {
249
- u(w.target);
250
- });
251
- };
252
- u(s.id);
253
- const d = new Map(o.map((p, j) => [p.id, j])), f = new Set(c);
254
- Kt(c, f, d, a);
255
- const g = e.filter((p) => f.has(p.id)).sort((p, j) => (d.get(p.id) ?? Number.MAX_SAFE_INTEGER) - (d.get(j.id) ?? Number.MAX_SAFE_INTEGER)), h = g.filter((p) => !(p.parentId && f.has(p.parentId)));
256
- return {
257
- endOfPathReached: !m,
258
- visibleNodeIds: f,
259
- visibleNodes: g,
260
- visibleRootNodes: h
261
- };
262
- }, Qt = (e) => {
263
- if (e.length === 1)
264
- return e[0];
265
- const r = new Set(e.map((s) => s.id)), n = /* @__PURE__ */ new Set();
266
- return e.forEach((s) => {
267
- s.nodes.forEach((a) => {
268
- if (Qe(a)) {
269
- const i = a.data.targetId;
270
- i && r.has(i) && n.add(i);
271
- }
272
- });
273
- }), e.find((s) => !n.has(s.id)) || e[0];
274
- }, mt = (e, r, n, s, a = /* @__PURE__ */ new Set()) => {
275
- const i = /* @__PURE__ */ new Set();
276
- for (const o of e)
277
- if (n.has(o)) {
278
- const c = s.get(o), l = c ? r.get(c) : void 0;
279
- if (l) {
280
- if (c && a.has(c))
281
- continue;
282
- c && a.add(c);
283
- const m = new Set(l.nodes.map((d) => d.id)), u = mt(m, r, n, s, a);
284
- for (const d of u)
285
- i.add(d);
286
- }
287
- } else
288
- i.add(o);
289
- return i;
290
- }, Xt = (e, r) => {
291
- const n = /* @__PURE__ */ new Set();
292
- return r.forEach((s) => {
293
- e.has(s.source) && e.has(s.target) && n.add(s.source);
294
- }), Array.from(e).filter((s) => !n.has(s));
295
- }, ft = (e) => {
296
- if (!e)
297
- return { edges: [], id: "empty", nodes: [] };
298
- const r = Array.isArray(e) ? e : [e];
299
- if (r.length === 0)
300
- return { edges: [], id: "empty", nodes: [] };
301
- const n = Qt(r);
302
- if (r.length === 1)
303
- return n;
304
- const s = new Map(r.map((f) => [f.id, f])), a = [], i = [...n.edges], o = /* @__PURE__ */ new Set([n.id]), c = /* @__PURE__ */ new Map(), l = /* @__PURE__ */ new Map(), m = /* @__PURE__ */ new Map(), u = (f) => {
305
- const g = [];
306
- return f.forEach((h) => {
307
- if (!Qe(h)) {
308
- g.push(h);
309
- return;
310
- }
311
- const p = h.data.targetId;
312
- if (!p)
313
- return;
314
- const j = s.get(p);
315
- if (!j) {
316
- console.warn(`Flow with id "${p}" not found`);
317
- return;
318
- }
319
- const I = j.nodes.find((M) => !M.parentId);
320
- if (!I) {
321
- console.warn(`Flow "${p}" has no root node; preserving FlowNode "${h.id}"`), g.push(h);
322
- return;
323
- }
324
- c.set(h.id, I.id), l.set(h.id, p), o.has(p) || (o.add(p), i.push(...j.edges), g.push(...u(j.nodes)));
325
- }), g;
326
- };
327
- a.push(...u(n.nodes)), i.forEach((f) => {
328
- if (c.has(f.source)) {
329
- const g = m.get(f.source);
330
- g ? g.push(f) : m.set(f.source, [f]);
331
- }
332
- });
333
- const d = i.map((f) => {
334
- if (c.has(f.source))
335
- return null;
336
- const g = c.get(f.target);
337
- return g ? { ...f, target: g } : f;
338
- }).filter((f) => f !== null);
339
- return c.forEach((f, g) => {
340
- const h = m.get(g);
341
- if (!h?.length)
342
- return;
343
- const p = l.get(g), j = p ? s.get(p) : void 0;
344
- if (!j)
345
- return;
346
- const I = new Set(j.nodes.map((w) => w.id)), M = mt(
347
- I,
348
- s,
349
- c,
350
- l,
351
- new Set(p ? [p] : [])
352
- );
353
- Xt(M, d).forEach((w) => {
354
- h.forEach((x) => {
355
- const b = c.get(x.target) ?? x.target, v = x.id ?? `${g}__${x.target}`;
356
- d.push({
357
- ...x,
358
- id: `${w}__${v}`,
359
- source: w,
360
- target: b
361
- });
362
- });
363
- });
364
- }), {
365
- edges: d,
366
- id: n.id,
367
- nodes: a
368
- };
369
- }, pt = nt(null), Yt = ({ children: e, value: r }) => /* @__PURE__ */ t.jsx(pt.Provider, { value: r, children: e }), xe = () => {
370
- const r = at(pt) ?? {
371
- flows: null,
372
- formErrors: {},
373
- formValues: {},
374
- googleApiKey: void 0,
375
- inputNodes: [],
376
- language: "",
377
- setFieldValue: () => {
378
- }
379
- }, n = U(() => r.flows ? ft(r.flows).edges : [], [r.flows]);
380
- return {
381
- ...r,
382
- edges: n
383
- };
384
- }, Zt = ["b", "i", "em", "strong", "u", "br", "p", "span"], es = ["class"], te = (e, r = {}) => {
385
- if (e == null || e === "")
386
- return "";
387
- const n = String(e), { plainTextOnly: s = !0, allowedTags: a, allowedAttributes: i } = r;
388
- if (s)
389
- return He.sanitize(n, {
390
- ALLOWED_ATTR: [],
391
- ALLOWED_TAGS: []
392
- });
393
- const o = a ?? Zt, c = i ?? es;
394
- return He.sanitize(n, {
395
- // Additional security options
396
- ALLOW_DATA_ATTR: !1,
397
- // Prevent data-* attributes
398
- ALLOW_UNKNOWN_PROTOCOLS: !1,
399
- // Only allow http, https, mailto, etc.
400
- ALLOWED_ATTR: c,
401
- ALLOWED_TAGS: o,
402
- FORBID_ATTR: ["style"],
403
- // Prevent inline styles
404
- FORBID_TAGS: ["style", "script"],
405
- // Explicitly forbid these
406
- KEEP_CONTENT: !0,
407
- // Keep text content when removing tags
408
- RETURN_DOM: !1,
409
- // Return string, not DOM
410
- RETURN_DOM_FRAGMENT: !1
411
- // Return string, not DOM fragment
412
- });
413
- }, Je = 100, De = (e, r = {}, n = 0, s = /* @__PURE__ */ new WeakSet()) => {
414
- if (n > Je)
415
- return console.warn(`sanitizeHttpResponse: Maximum depth (${Je}) exceeded.`), typeof e == "string" ? te(e, r) : "[Max Depth Exceeded]";
416
- if (e == null)
417
- return e;
418
- if (typeof e == "string")
419
- return te(e, r);
420
- if (Array.isArray(e))
421
- return e.map((a) => De(a, r, n + 1, s));
422
- if (typeof e == "object") {
423
- if (s.has(e))
424
- return console.warn("sanitizeHttpResponse: Circular reference detected. Breaking cycle to prevent infinite recursion."), "[Circular Reference]";
425
- s.add(e);
426
- const a = {};
427
- for (const [i, o] of Object.entries(e))
428
- a[i] = De(o, r, n + 1, s);
429
- return s.delete(e), a;
430
- }
431
- return e;
432
- }, B = (e) => {
433
- const r = xe(), n = e ?? r.language, s = It(n);
434
- return U(
435
- () => (a) => {
436
- const i = s(a);
437
- return typeof a == "object" && a !== null ? te(i) : i;
438
- },
439
- [s]
440
- );
441
- }, ts = (e, r = {}, n = "en") => {
442
- const s = U(() => ft(e), [e]), { nodes: a, edges: i } = s, o = U(() => Lt(a), [a]), c = B(n), l = K({}), [m, u] = L({}), [d, f] = L(() => {
443
- const x = { ...r };
444
- return a.forEach((b) => {
445
- if (G(b)) {
446
- const v = b.id;
447
- if (x[v] !== void 0)
448
- return;
449
- const { defaultValue: F } = b.data;
450
- if (!F)
451
- return;
452
- if (F.type === "static" && F.staticValue !== void 0 && (x[v] = F.staticValue), F.type === "reference" && F.referenceField) {
453
- const { referenceField: P } = F, q = x[P];
454
- q !== void 0 && (x[v] = q);
455
- }
456
- }
457
- }), x;
458
- }), { endOfPathReached: g, visibleNodes: h, visibleRootNodes: p } = U(
459
- () => Jt(a, i, d),
460
- [a, i, d]
461
- ), j = Q((x, b) => {
462
- f((v) => ({
463
- ...v,
464
- [x]: b
465
- })), u((v) => {
466
- const F = { ...v };
467
- return delete F[x], F;
468
- });
469
- }, []), I = Q((x) => {
470
- Object.keys(x).length !== 0 && (f((b) => ({
471
- ...b,
472
- ...x
473
- })), u((b) => {
474
- const v = { ...b };
475
- return Object.keys(x).forEach((F) => {
476
- delete v[F];
477
- }), v;
478
- }));
479
- }, []), M = Q(
480
- (x) => {
481
- const b = {};
482
- h.forEach((P) => {
483
- if (G(P)) {
484
- const q = P.id, ee = d[q];
485
- if (P.data.required && Se(ee)) {
486
- b[q] = c(P.data.errorMessage) || c("validation.required");
487
- return;
488
- }
489
- if (!Se(ee) && P.data.pattern)
490
- try {
491
- new RegExp(P.data.pattern).test(String(ee)) || (b[q] = c(P.data.errorMessage) || c("validation.invalidFormat"));
492
- } catch (Y) {
493
- console.error(`Invalid pattern for field ${q}:`, Y);
494
- }
495
- }
496
- });
497
- const v = x ? x(d, h) : {}, F = {
498
- ...b,
499
- ...v
500
- };
501
- return u(F), {
502
- errors: F,
503
- hasCustomErrors: Object.keys(v).length > 0,
504
- isValid: Object.keys(F).length === 0
505
- };
506
- },
507
- [h, d, c]
508
- ), D = U(() => {
509
- const x = [];
510
- return h.forEach((b) => {
511
- if (!G(b))
512
- return;
513
- const v = b.id, F = d[v];
514
- if (b.data.required && Se(F)) {
515
- const P = c(b.data.label) || v;
516
- x.push(P);
517
- }
518
- }), x;
519
- }, [h, d, c]);
520
- return {
521
- canSubmit: !U(() => h.some((x) => G(x) && x.data.type === "submit"), [h]) && g && a.length > 0,
522
- formErrors: m,
523
- formValues: d,
524
- inputNodes: o,
525
- mergedFlow: s,
526
- missingRequiredFields: D,
527
- prevFormValuesRef: l,
528
- setFieldValue: j,
529
- setFormErrors: u,
530
- setMultipleFieldValues: I,
531
- t: c,
532
- validateForm: M,
533
- visibleNodes: h,
534
- visibleRootNodes: p
535
- };
536
- }, ss = ({ children: e, onSubmit: r }) => /* @__PURE__ */ t.jsx("form", { onSubmit: r, className: "mx-auto max-w-2xl gap-y-3", children: e }), rs = ({ node: e, children: r }) => {
537
- const n = B();
538
- return /* @__PURE__ */ t.jsxs("section", { className: "mb-6 rounded-lg border p-4", children: [
539
- e.data.label && /* @__PURE__ */ t.jsx("h3", { className: "mb-4 font-semibold text-lg", children: n(e.data.label) }),
540
- r
541
- ] });
542
- }, ns = async (e, r) => {
543
- if (!e || e.trim().length < 3)
544
- return [];
545
- try {
546
- const n = await fetch(
547
- `https://nominatim.openstreetmap.org/search?q=${encodeURIComponent(e)}&format=jsonv2&addressdetails=1&limit=5`,
548
- {
549
- headers: {
550
- Accept: "application/json",
551
- "User-Agent": "Treege Renderer",
552
- ...r && { "Accept-Language": r }
553
- }
554
- }
555
- );
556
- return n.ok ? (await n.json()).map((a) => ({
557
- label: a.display_name,
558
- value: a.display_name
559
- })) : [];
560
- } catch (n) {
561
- return console.error("Nominatim fetch error:", n), [];
562
- }
563
- }, as = (e) => !e || e.trim().length < 3 ? Promise.resolve([]) : new Promise((r) => {
564
- if (!window.google?.maps?.places) {
565
- console.warn("Google Places SDK not loaded yet"), r([]);
566
- return;
567
- }
568
- new window.google.maps.places.AutocompleteService().getPlacePredictions({ input: e }, (s, a) => {
569
- if (a !== google.maps.places.PlacesServiceStatus.OK || !s) {
570
- console.warn("Google Places API status:", a), r([]);
571
- return;
572
- }
573
- r(
574
- s.map((i) => ({
575
- label: i.description,
576
- value: i.description
577
- }))
578
- );
579
- });
580
- }), os = ({ node: e, value: r, setValue: n, error: s, label: a, placeholder: i, helperText: o, id: c, name: l }) => {
581
- const [m, u] = L(""), [d, f] = L([]), [g, h] = L(!1), { googleApiKey: p, language: j } = xe(), I = B(), M = Q(
582
- (w) => {
583
- n(w.value), u(w.value), h(!1);
584
- },
585
- [n]
586
- );
587
- J(() => {
588
- if (!m || m.trim().length < 3) {
589
- f([]);
590
- return;
591
- }
592
- const w = setTimeout(async () => {
593
- const x = p ? await as(m) : await ns(m, j);
594
- f(x);
595
- }, 300);
596
- return () => clearTimeout(w);
597
- }, [m, p, j]);
598
- const D = Q(
599
- (w) => {
600
- n(w), u(w), w.length >= 3 && h(!0);
601
- },
602
- [n]
603
- );
604
- return /* @__PURE__ */ t.jsxs(t.Fragment, { children: [
605
- p && /* @__PURE__ */ t.jsx("script", { async: !0, src: `https://maps.googleapis.com/maps/api/js?key=${p}&libraries=places` }),
606
- /* @__PURE__ */ t.jsxs(O, { className: "mb-4", children: [
607
- /* @__PURE__ */ t.jsxs(A, { htmlFor: c, children: [
608
- a || e.data.name,
609
- e.data.required && /* @__PURE__ */ t.jsx("span", { className: "text-red-500", children: "*" })
610
- ] }),
611
- /* @__PURE__ */ t.jsxs("div", { className: "relative", children: [
612
- /* @__PURE__ */ t.jsx(
613
- X,
614
- {
615
- type: "text",
616
- id: c,
617
- name: l,
618
- value: r || "",
619
- onChange: (w) => D(w.target.value),
620
- onFocus: () => {
621
- d.length > 0 && h(!0);
622
- },
623
- placeholder: i || I("renderer.defaultAddressInput.enterAddress"),
624
- className: "pr-10",
625
- autoComplete: "off"
626
- }
627
- ),
628
- /* @__PURE__ */ t.jsx(Ue, { className: "-translate-y-1/2 pointer-events-none absolute top-1/2 right-3 h-4 w-4 text-muted-foreground" }),
629
- g && /* @__PURE__ */ t.jsx("div", { className: "absolute z-50 mt-1 w-full rounded-md border bg-popover shadow-md", children: /* @__PURE__ */ t.jsx(Ee, { children: /* @__PURE__ */ t.jsxs(Oe, { children: [
630
- /* @__PURE__ */ t.jsx(ke, { children: I("renderer.defaultAddressInput.noAddressesFound") }),
631
- /* @__PURE__ */ t.jsx(_e, { children: d.map((w, x) => /* @__PURE__ */ t.jsxs(
632
- Pe,
633
- {
634
- value: w.value,
635
- onSelect: () => M(w),
636
- onMouseDown: (b) => b.preventDefault(),
637
- children: [
638
- /* @__PURE__ */ t.jsx(Ue, { className: "mr-2 h-4 w-4" }),
639
- w.label
640
- ]
641
- },
642
- x
643
- )) })
644
- ] }) }) })
645
- ] }),
646
- s && /* @__PURE__ */ t.jsx(k, { children: s }),
647
- o && !s && /* @__PURE__ */ t.jsx(_, { children: o })
648
- ] })
649
- ] });
650
- }, is = ({
651
- node: e,
652
- value: r,
653
- setValue: n,
654
- error: s,
655
- label: a,
656
- placeholder: i,
657
- helperText: o,
658
- id: c
659
- }) => {
660
- const l = B(), [m, u] = L(!1), d = `${c}-trigger`, f = `${c}-error`, g = e.data.options || [], h = g.find((p) => p.value === r);
661
- return /* @__PURE__ */ t.jsxs(O, { className: "mb-4", children: [
662
- /* @__PURE__ */ t.jsxs(A, { htmlFor: d, children: [
663
- a || e.data.name,
664
- e.data.required && /* @__PURE__ */ t.jsx("span", { className: "text-red-500", children: "*" })
665
- ] }),
666
- /* @__PURE__ */ t.jsxs(pe, { open: m, onOpenChange: u, children: [
667
- /* @__PURE__ */ t.jsx(he, { asChild: !0, children: /* @__PURE__ */ t.jsxs(
668
- ce,
669
- {
670
- id: d,
671
- variant: "outline",
672
- role: "combobox",
673
- "aria-expanded": m,
674
- "aria-invalid": !!s || void 0,
675
- "aria-describedby": s ? f : void 0,
676
- className: "w-full justify-between font-normal",
677
- children: [
678
- r ? h?.label ? l(h.label) : r : i || l("renderer.defaultAutocompleteInput.selectOption"),
679
- /* @__PURE__ */ t.jsx(ot, { className: "ml-2 size-4 shrink-0 opacity-50" })
680
- ]
681
- }
682
- ) }),
683
- /* @__PURE__ */ t.jsx(ge, { className: "w-full p-0", align: "start", children: /* @__PURE__ */ t.jsxs(Ee, { children: [
684
- /* @__PURE__ */ t.jsx(Xe, { placeholder: i || l("renderer.defaultAutocompleteInput.search") }),
685
- /* @__PURE__ */ t.jsxs(Oe, { children: [
686
- /* @__PURE__ */ t.jsx(ke, { children: l("renderer.defaultAutocompleteInput.noResults") }),
687
- /* @__PURE__ */ t.jsx(_e, { children: g.map((p) => /* @__PURE__ */ t.jsxs(
688
- Pe,
689
- {
690
- value: p.value,
691
- disabled: p.disabled,
692
- onSelect: (j) => {
693
- n(j === r ? "" : j), u(!1);
694
- },
695
- children: [
696
- /* @__PURE__ */ t.jsx(it, { className: y("mr-2 size-4", r === p.value ? "opacity-100" : "opacity-0") }),
697
- l(p.label)
698
- ]
699
- },
700
- p.value
701
- )) })
702
- ] })
703
- ] }) })
704
- ] }),
705
- s && /* @__PURE__ */ t.jsx(k, { id: f, children: s }),
706
- o && !s && /* @__PURE__ */ t.jsx(_, { children: o })
707
- ] });
708
- }, ls = ({ node: e, value: r, setValue: n, error: s, label: a, helperText: i, id: o, name: c }) => {
709
- const l = B();
710
- if (e.data.options && e.data.options.length > 0) {
711
- const m = Array.isArray(r) ? r.map(String) : [], u = (d, f) => {
712
- const g = f ? [...m, d] : m.filter((h) => h !== d);
713
- n(g);
714
- };
715
- return /* @__PURE__ */ t.jsxs(O, { className: "mb-4", children: [
716
- /* @__PURE__ */ t.jsxs(A, { className: "mb-1", children: [
717
- a || e.data.name,
718
- e.data.required && /* @__PURE__ */ t.jsx("span", { className: "text-red-500", children: "*" })
719
- ] }),
720
- /* @__PURE__ */ t.jsx("div", { className: "space-y-2", children: e.data.options.map((d, f) => /* @__PURE__ */ t.jsxs("div", { className: "flex items-center gap-3", children: [
721
- /* @__PURE__ */ t.jsx(
722
- Le,
723
- {
724
- id: `${o}-${d.value}`,
725
- name: c,
726
- checked: m.includes(String(d.value)),
727
- onCheckedChange: (g) => u(String(d.value), !!g),
728
- disabled: d.disabled
729
- }
730
- ),
731
- /* @__PURE__ */ t.jsx(A, { htmlFor: `${o}-${d.value}`, className: "cursor-pointer font-normal text-sm", children: l(d.label) ? l(d.label) : d.value })
732
- ] }, d.value + f)) }),
733
- s && /* @__PURE__ */ t.jsx(k, { children: s }),
734
- i && !s && /* @__PURE__ */ t.jsx(_, { children: i })
735
- ] });
736
- }
737
- return /* @__PURE__ */ t.jsxs(O, { className: "mb-4", children: [
738
- /* @__PURE__ */ t.jsxs("div", { className: "flex items-center gap-3", children: [
739
- /* @__PURE__ */ t.jsx(
740
- Le,
741
- {
742
- id: o,
743
- name: c,
744
- checked: typeof r == "boolean" ? r : !1,
745
- onCheckedChange: (m) => n(!!m)
746
- }
747
- ),
748
- /* @__PURE__ */ t.jsxs("div", { children: [
749
- /* @__PURE__ */ t.jsxs(A, { htmlFor: o, className: "cursor-pointer font-medium text-sm", children: [
750
- a || e.data.name,
751
- e.data.required && /* @__PURE__ */ t.jsx("span", { className: "text-red-500", children: "*" })
752
- ] }),
753
- i && !s && /* @__PURE__ */ t.jsx(_, { children: i })
754
- ] })
755
- ] }),
756
- s && /* @__PURE__ */ t.jsx(k, { children: s })
757
- ] });
758
- };
759
- function ht({
760
- className: e,
761
- classNames: r,
762
- showOutsideDays: n = !0,
763
- captionLayout: s = "label",
764
- buttonVariant: a = "ghost",
765
- formatters: i,
766
- components: o,
767
- ...c
768
- }) {
769
- const l = lt();
770
- return /* @__PURE__ */ t.jsx(
771
- $t,
772
- {
773
- showOutsideDays: n,
774
- className: y(
775
- "group/calendar bg-background p-3 [--cell-size:--spacing(8)] [[data-slot=card-content]_&]:bg-transparent [[data-slot=popover-content]_&]:bg-transparent",
776
- String.raw`rtl:**:[.rdp-button\_next>svg]:rotate-180`,
777
- String.raw`rtl:**:[.rdp-button\_previous>svg]:rotate-180`,
778
- e
779
- ),
780
- captionLayout: s,
781
- formatters: {
782
- formatMonthDropdown: (m) => m.toLocaleString("default", { month: "short" }),
783
- ...i
784
- },
785
- classNames: {
786
- button_next: y(
787
- Be({ variant: a }),
788
- "size-(--cell-size) aria-disabled:opacity-50 p-0 select-none",
789
- l.button_next
790
- ),
791
- button_previous: y(
792
- Be({ variant: a }),
793
- "size-(--cell-size) aria-disabled:opacity-50 p-0 select-none",
794
- l.button_previous
795
- ),
796
- caption_label: y(
797
- "select-none font-medium",
798
- s === "label" ? "text-sm" : "rounded-md pl-2 pr-1 flex items-center gap-1 text-sm h-8 [&>svg]:text-muted-foreground [&>svg]:size-3.5",
799
- l.caption_label
800
- ),
801
- day: y(
802
- "relative w-full h-full p-0 text-center [&:first-child[data-selected=true]_button]:rounded-l-md [&:last-child[data-selected=true]_button]:rounded-r-md group/day aspect-square select-none",
803
- l.day
804
- ),
805
- disabled: y("text-muted-foreground opacity-50", l.disabled),
806
- dropdown: y("absolute bg-popover inset-0 opacity-0", l.dropdown),
807
- dropdown_root: y(
808
- "relative has-focus:border-ring border border-input shadow-xs has-focus:ring-ring/50 has-focus:ring-[3px] rounded-md",
809
- l.dropdown_root
810
- ),
811
- dropdowns: y("w-full flex items-center text-sm font-medium justify-center h-(--cell-size) gap-1.5", l.dropdowns),
812
- hidden: y("invisible", l.hidden),
813
- month: y("flex flex-col w-full gap-4", l.month),
814
- month_caption: y("flex items-center justify-center h-(--cell-size) w-full px-(--cell-size)", l.month_caption),
815
- months: y("flex gap-4 flex-col md:flex-row relative", l.months),
816
- nav: y("flex items-center gap-1 w-full absolute top-0 inset-x-0 justify-between", l.nav),
817
- outside: y("text-muted-foreground aria-selected:text-muted-foreground", l.outside),
818
- range_end: y("rounded-r-md bg-accent", l.range_end),
819
- range_middle: y("rounded-none", l.range_middle),
820
- range_start: y("rounded-l-md bg-accent", l.range_start),
821
- root: y("w-fit", l.root),
822
- table: "w-full border-collapse",
823
- today: y("bg-accent text-accent-foreground rounded-md data-[selected=true]:rounded-none", l.today),
824
- week: y("flex w-full mt-2", l.week),
825
- week_number: y("text-[0.8rem] select-none text-muted-foreground", l.week_number),
826
- week_number_header: y("select-none w-(--cell-size)", l.week_number_header),
827
- weekday: y("text-muted-foreground rounded-md flex-1 font-normal text-[0.8rem] select-none", l.weekday),
828
- weekdays: y("flex", l.weekdays),
829
- ...r
830
- },
831
- components: {
832
- Chevron: ({ className: m, orientation: u, ...d }) => u === "left" ? /* @__PURE__ */ t.jsx(_t, { className: y("size-4", m), ...d }) : u === "right" ? /* @__PURE__ */ t.jsx(Pt, { className: y("size-4", m), ...d }) : /* @__PURE__ */ t.jsx(Me, { className: y("size-4", m), ...d }),
833
- DayButton: cs,
834
- Root: ({ className: m, rootRef: u, ...d }) => /* @__PURE__ */ t.jsx("div", { "data-slot": "calendar", ref: u, className: y(m), ...d }),
835
- WeekNumber: ({ children: m, ...u }) => /* @__PURE__ */ t.jsx("td", { ...u, children: /* @__PURE__ */ t.jsx("div", { className: "flex size-(--cell-size) items-center justify-center text-center", children: m }) }),
836
- ...o
837
- },
838
- ...c
839
- }
840
- );
841
- }
842
- function cs({ className: e, day: r, modifiers: n, ...s }) {
843
- const a = lt(), i = qe.useRef(null);
844
- return qe.useEffect(() => {
845
- n.focused && i.current?.focus();
846
- }, [n.focused]), /* @__PURE__ */ t.jsx(
847
- ce,
848
- {
849
- ref: i,
850
- variant: "ghost",
851
- size: "icon",
852
- "data-day": r.date.toLocaleDateString(),
853
- "data-selected-single": n.selected && !n.range_start && !n.range_end && !n.range_middle,
854
- "data-range-start": n.range_start,
855
- "data-range-end": n.range_end,
856
- "data-range-middle": n.range_middle,
857
- className: y(
858
- "flex aspect-square size-auto w-full min-w-(--cell-size) flex-col gap-1 font-normal leading-none data-[range-end=true]:rounded-md data-[range-middle=true]:rounded-none data-[range-start=true]:rounded-md data-[range-end=true]:rounded-r-md data-[range-start=true]:rounded-l-md data-[range-end=true]:bg-primary data-[range-middle=true]:bg-accent data-[range-start=true]:bg-primary data-[selected-single=true]:bg-primary data-[range-end=true]:text-primary-foreground data-[range-middle=true]:text-accent-foreground data-[range-start=true]:text-primary-foreground data-[selected-single=true]:text-primary-foreground group-data-[focused=true]/day:relative group-data-[focused=true]/day:z-10 group-data-[focused=true]/day:border-ring group-data-[focused=true]/day:ring-[3px] group-data-[focused=true]/day:ring-ring/50 dark:hover:text-accent-foreground [&>span]:text-xs [&>span]:opacity-70",
859
- a.day,
860
- e
861
- ),
862
- ...s
863
- }
864
- );
865
- }
866
- const ds = ({ node: e, value: r, setValue: n, error: s, label: a, placeholder: i, helperText: o, id: c, name: l }) => {
867
- const [m, u] = L(!1), d = B(), f = r ? new Date(r) : void 0, g = (h) => {
868
- if (e.data.disablePast) {
869
- const p = /* @__PURE__ */ new Date();
870
- return p.setHours(0, 0, 0, 0), h < p;
871
- }
872
- return !1;
873
- };
874
- return /* @__PURE__ */ t.jsxs(O, { className: "mb-4", children: [
875
- /* @__PURE__ */ t.jsxs(A, { htmlFor: c, children: [
876
- a || e.data.name,
877
- e.data.required && /* @__PURE__ */ t.jsx("span", { className: "text-red-500", children: "*" })
878
- ] }),
879
- /* @__PURE__ */ t.jsxs(pe, { open: m, onOpenChange: u, children: [
880
- /* @__PURE__ */ t.jsx(he, { asChild: !0, children: /* @__PURE__ */ t.jsxs(ce, { variant: "outline", id: c, name: l, className: "w-full justify-between font-normal", children: [
881
- f ? f.toLocaleDateString() : i || d("renderer.defaultInputs.selectDate"),
882
- /* @__PURE__ */ t.jsx(Me, { className: "size-4" })
883
- ] }) }),
884
- /* @__PURE__ */ t.jsx(ge, { className: "w-auto overflow-hidden p-0", align: "start", children: /* @__PURE__ */ t.jsx(
885
- ht,
886
- {
887
- mode: "single",
888
- selected: f,
889
- captionLayout: "dropdown",
890
- disabled: g,
891
- onSelect: (h) => {
892
- n(h ? h.toISOString() : ""), u(!1);
893
- }
894
- }
895
- ) })
896
- ] }),
897
- s && /* @__PURE__ */ t.jsx(k, { children: s }),
898
- o && !s && /* @__PURE__ */ t.jsx(_, { children: o })
899
- ] });
900
- }, us = ({ node: e, value: r, setValue: n, error: s, label: a, helperText: i, id: o }) => {
901
- const [c, l] = L(!1), m = B(), u = Array.isArray(r) ? r : [], d = u[0] ? new Date(u[0]) : void 0, f = u[1] ? new Date(u[1]) : void 0, g = (j) => {
902
- n([j?.from ? j.from.toISOString() : void 0, j?.to ? j.to.toISOString() : void 0]);
903
- }, h = () => d && f ? `${d.toLocaleDateString()} - ${f.toLocaleDateString()}` : d ? d.toLocaleDateString() : m("renderer.defaultInputs.selectDateRange"), p = (j) => {
904
- if (e.data.disablePast) {
905
- const I = /* @__PURE__ */ new Date();
906
- return I.setHours(0, 0, 0, 0), j < I;
907
- }
908
- return !1;
909
- };
910
- return /* @__PURE__ */ t.jsxs(O, { className: "mb-4", children: [
911
- /* @__PURE__ */ t.jsxs(A, { htmlFor: o, children: [
912
- a || e.data.name,
913
- e.data.required && /* @__PURE__ */ t.jsx("span", { className: "text-red-500", children: "*" })
914
- ] }),
915
- /* @__PURE__ */ t.jsxs(pe, { open: c, onOpenChange: l, children: [
916
- /* @__PURE__ */ t.jsx(he, { asChild: !0, children: /* @__PURE__ */ t.jsxs(ce, { id: o, variant: "outline", className: "w-full justify-between font-normal", children: [
917
- h(),
918
- /* @__PURE__ */ t.jsx(Me, { className: "size-4" })
919
- ] }) }),
920
- /* @__PURE__ */ t.jsx(ge, { className: "w-auto overflow-hidden p-0", align: "start", children: /* @__PURE__ */ t.jsx(
921
- ht,
922
- {
923
- mode: "range",
924
- selected: { from: d, to: f },
925
- captionLayout: "dropdown",
926
- disabled: p,
927
- onSelect: g,
928
- numberOfMonths: 2
929
- }
930
- ) })
931
- ] }),
932
- s && /* @__PURE__ */ t.jsx(k, { children: s }),
933
- i && !s && /* @__PURE__ */ t.jsx(_, { children: i })
934
- ] });
935
- }, gt = (e) => new Promise((r, n) => {
936
- const s = new FileReader();
937
- s.onload = () => {
938
- const a = s.result;
939
- r({
940
- data: a,
941
- lastModified: e.lastModified,
942
- name: e.name,
943
- size: e.size,
944
- type: e.type
945
- });
946
- }, s.onerror = () => {
947
- n(new Error(`Failed to read file: ${e.name}`));
948
- }, s.readAsDataURL(e);
949
- }), er = (e) => {
950
- const r = e.data.split(",")[1], n = atob(r), s = new ArrayBuffer(n.length), a = new Uint8Array(s);
951
- for (let o = 0; o < n.length; o++)
952
- a[o] = n.charCodeAt(o);
953
- const i = new Blob([s], { type: e.type });
954
- return new File([i], e.name, {
955
- lastModified: e.lastModified,
956
- type: e.type
957
- });
958
- }, ms = (e) => Promise.all(e.map((r) => gt(r))), fs = ({ node: e, setValue: r, error: n, label: s, placeholder: a, helperText: i, name: o, id: c }) => {
959
- const l = async (m) => {
960
- const { files: u } = m.target;
961
- if (!u || u.length === 0) {
962
- r(null);
963
- return;
964
- }
965
- if (e.data.multiple) {
966
- const f = await ms(Array.from(u));
967
- r(f);
968
- return;
969
- }
970
- const d = await gt(u[0]);
971
- r(d);
972
- };
973
- return /* @__PURE__ */ t.jsxs(O, { className: "mb-4", children: [
974
- /* @__PURE__ */ t.jsxs(A, { htmlFor: c, children: [
975
- s || e.data.name,
976
- e.data.required && /* @__PURE__ */ t.jsx("span", { className: "text-red-500", children: "*" })
977
- ] }),
978
- /* @__PURE__ */ t.jsx(X, { type: "file", name: o, id: c, onChange: l, multiple: e.data.multiple, placeholder: a }),
979
- n && /* @__PURE__ */ t.jsx(k, { children: n }),
980
- i && !n && /* @__PURE__ */ t.jsx(_, { children: i })
981
- ] });
982
- }, ps = ({ value: e, name: r, id: n }) => /* @__PURE__ */ t.jsx(X, { type: "hidden", id: n, name: r, value: e ?? "" });
983
- function Ve({ delayDuration: e = 0, ...r }) {
984
- return /* @__PURE__ */ t.jsx(oe.Provider, { "data-slot": "tooltip-provider", delayDuration: e, ...r });
985
- }
986
- function xt({ ...e }) {
987
- return /* @__PURE__ */ t.jsx(Ve, { children: /* @__PURE__ */ t.jsx(oe.Root, { "data-slot": "tooltip", ...e }) });
988
- }
989
- function bt({ ...e }) {
990
- return /* @__PURE__ */ t.jsx(oe.Trigger, { "data-slot": "tooltip-trigger", ...e });
991
- }
992
- function jt({ className: e, sideOffset: r = 0, children: n, ...s }) {
993
- return /* @__PURE__ */ t.jsx(oe.Portal, { children: /* @__PURE__ */ t.jsxs(
994
- oe.Content,
995
- {
996
- "data-slot": "tooltip-content",
997
- sideOffset: r,
998
- className: y(
999
- "fade-in-0 zoom-in-95 data-[state=closed]:fade-out-0 data-[state=closed]:zoom-out-95 data-[side=bottom]:slide-in-from-top-2 data-[side=left]:slide-in-from-right-2 data-[side=right]:slide-in-from-left-2 data-[side=top]:slide-in-from-bottom-2 z-50 w-fit origin-(--radix-tooltip-content-transform-origin) animate-in text-balance rounded-md bg-foreground px-3 py-1.5 text-background text-xs data-[state=closed]:animate-out",
1000
- e
1001
- ),
1002
- ...s,
1003
- children: [
1004
- n,
1005
- /* @__PURE__ */ t.jsx(oe.Arrow, { className: "z-50 size-2.5 translate-y-[calc(-50%_-_2px)] rotate-45 rounded-[2px] bg-foreground fill-foreground" })
1006
- ]
1007
- }
1008
- ) });
1009
- }
1010
- const Fe = (e, r) => r ? r.split(".").reduce((s, a) => {
1011
- if (s == null)
1012
- return;
1013
- const i = a.match(/^(\w+)\[(\d+)]$/);
1014
- if (i) {
1015
- const [, o, c] = i, l = s[o];
1016
- return Array.isArray(l) ? l[Number.parseInt(c, 10)] : l;
1017
- }
1018
- return s[a];
1019
- }, e) : e, Re = (e) => {
1020
- const r = e.matchAll(/{{([\w-]+)}}/g);
1021
- return Array.from(r, (n) => n[1]);
1022
- }, Ce = (e, r) => Re(e).every((s) => {
1023
- const a = r[s];
1024
- return a != null && a !== "";
1025
- }), Te = (e, r, n = !1) => e.replace(/{{([\w-]+)}}/g, (s, a) => {
1026
- const i = String(r[a] || "");
1027
- return n ? encodeURIComponent(i) : i;
1028
- }), hs = ({ node: e, value: r, setValue: n, error: s, label: a, placeholder: i, helperText: o, id: c, name: l }) => {
1029
- const [m, u] = L(!1), [d, f] = L(null), [g, h] = L([]), [p, j] = L(""), [I, M] = L(!1), { formValues: D, inputNodes: w } = xe(), x = B(), { httpConfig: b } = e.data, v = K(!1), F = K(""), P = K(b), q = K(D), ee = K(w), Y = K(n), de = K(null), se = U(() => b?.url ? Re(b.url) : [], [b?.url]), re = se.length > 0, ie = U(() => se.map((C) => `${C}:${String(D[C] ?? "")}`).join("|"), [se, D]), le = U(() => b?.url ? re ? Ce(b.url, D) : !0 : !1, [b?.url, re, D]), W = Q(
1030
- async (C) => {
1031
- const T = P.current, V = q.current, N = Y.current;
1032
- if (!T?.url) {
1033
- f(x("renderer.defaultHttpInput.noUrlConfigured"));
1034
- return;
1035
- }
1036
- if (!(T.url && !Ce(T.url, V))) {
1037
- u(!0), f(null);
1038
- try {
1039
- const $ = Te(T.url, V, !0), R = T.searchParam && C ? `${$}${$.includes("?") ? "&" : "?"}${T.searchParam}=${encodeURIComponent(C)}` : $, E = {};
1040
- T.headers?.forEach((ne) => {
1041
- E[ne.key] = Te(ne.value, V);
1042
- });
1043
- const S = ["POST", "PUT", "PATCH"].includes(T.method || "") ? T.sendFormData ? JSON.stringify(ze(V, ee.current)) : T.body ? Te(T.body, V) : void 0 : void 0, z = await fetch(R, {
1044
- body: S || void 0,
1045
- headers: {
1046
- "Content-Type": "application/json",
1047
- ...E
1048
- },
1049
- method: T.method || "GET"
1050
- });
1051
- if (!z.ok) {
1052
- f(`HTTP Error ${z.status}: ${z.statusText}`), u(!1);
1053
- return;
1054
- }
1055
- const H = await z.json(), ue = De(H), Z = T.responsePath ? Fe(ue, T.responsePath) : ue;
1056
- if (T.responseMapping && Array.isArray(Z)) {
1057
- const { valueField: ne = "value", labelField: be = "label" } = T.responseMapping, je = Z.map((me) => ({
1058
- label: String(Fe(me, be) || ""),
1059
- value: String(Fe(me, ne) || "")
1060
- }));
1061
- h(je);
1062
- } else
1063
- N(typeof Z == "string" ? Z : JSON.stringify(Z));
1064
- } catch ($) {
1065
- const R = $ instanceof Error ? $.message : x("renderer.defaultHttpInput.fetchFailed");
1066
- f(R), console.error("HTTP Input fetch error:", $);
1067
- } finally {
1068
- u(!1);
1069
- }
1070
- }
1071
- },
1072
- [x]
1073
- );
1074
- if (J(() => {
1075
- P.current = b, q.current = D, ee.current = w, Y.current = n, de.current = W;
1076
- }, [b, D, w, n, W]), J(() => {
1077
- if (v.current)
1078
- return;
1079
- v.current = !0;
1080
- const C = P.current, T = q.current, V = de.current, N = C?.url && Ce(C.url, T);
1081
- if (C?.fetchOnMount && N && V && (V(), C.url)) {
1082
- const $ = Re(C.url);
1083
- F.current = $.map((R) => `${R}:${String(T[R] ?? "")}`).join("|");
1084
- }
1085
- }, []), J(() => {
1086
- if (!v.current || !re || F.current === ie || !le)
1087
- return;
1088
- const C = setTimeout(() => {
1089
- W(), F.current = ie;
1090
- }, 500);
1091
- return () => clearTimeout(C);
1092
- }, [ie, re, le, W]), J(() => {
1093
- if (!(b?.searchParam && p))
1094
- return;
1095
- const C = setTimeout(() => {
1096
- W(p);
1097
- }, 300);
1098
- return () => clearTimeout(C);
1099
- }, [p, b?.searchParam, W]), b?.responseMapping) {
1100
- const C = Array.isArray(r) ? r[0] : r, T = g.find((S) => S.value === C);
1101
- if (b.searchParam) {
1102
- const z = m && b?.showLoading ? /* @__PURE__ */ t.jsxs("div", { className: "flex items-center gap-2", children: [
1103
- /* @__PURE__ */ t.jsx(we, { className: "h-4 w-4 animate-spin" }),
1104
- /* @__PURE__ */ t.jsx("span", { className: "text-muted-foreground", children: T?.label || i || x("renderer.defaultHttpInput.search") })
1105
- ] }) : T?.label || i || x("renderer.defaultHttpInput.search");
1106
- return /* @__PURE__ */ t.jsxs(O, { className: "mb-4", children: [
1107
- /* @__PURE__ */ t.jsxs(A, { children: [
1108
- a || e.data.name,
1109
- e.data.required && /* @__PURE__ */ t.jsx("span", { className: "text-red-500", children: "*" })
1110
- ] }),
1111
- /* @__PURE__ */ t.jsxs(pe, { open: I, onOpenChange: M, children: [
1112
- /* @__PURE__ */ t.jsx(he, { asChild: !0, children: /* @__PURE__ */ t.jsxs(ce, { variant: "outline", role: "combobox", "aria-expanded": I, className: "w-full justify-between", children: [
1113
- z,
1114
- /* @__PURE__ */ t.jsx(ot, { className: "ml-2 h-4 w-4 shrink-0 opacity-50" })
1115
- ] }) }),
1116
- /* @__PURE__ */ t.jsx(ge, { className: "w-[300px] p-0", align: "start", children: /* @__PURE__ */ t.jsxs(Ee, { shouldFilter: !1, children: [
1117
- /* @__PURE__ */ t.jsx(
1118
- Xe,
1119
- {
1120
- placeholder: x("renderer.defaultHttpInput.search"),
1121
- value: p,
1122
- onValueChange: (H) => {
1123
- j(H), f(null);
1124
- }
1125
- }
1126
- ),
1127
- /* @__PURE__ */ t.jsxs(Oe, { children: [
1128
- m && /* @__PURE__ */ t.jsx("div", { className: "flex items-center justify-center p-4", children: /* @__PURE__ */ t.jsx(we, { className: "h-4 w-4 animate-spin" }) }),
1129
- !m && d && /* @__PURE__ */ t.jsxs("div", { className: "p-4 text-destructive text-sm", children: [
1130
- /* @__PURE__ */ t.jsx("div", { children: d }),
1131
- /* @__PURE__ */ t.jsx("button", { type: "button", onClick: () => W(p), className: "mt-2 block text-primary hover:underline", children: x("renderer.defaultHttpInput.retry") })
1132
- ] }),
1133
- !(m || d) && /* @__PURE__ */ t.jsxs(t.Fragment, { children: [
1134
- /* @__PURE__ */ t.jsx(ke, { children: x("renderer.defaultHttpInput.noResults") }),
1135
- /* @__PURE__ */ t.jsx(_e, { children: g.map((H) => /* @__PURE__ */ t.jsxs(
1136
- Pe,
1137
- {
1138
- value: H.value,
1139
- onSelect: () => {
1140
- n(H.value), M(!1);
1141
- },
1142
- children: [
1143
- /* @__PURE__ */ t.jsx(it, { className: y("mr-2 h-4 w-4", r === H.value ? "opacity-100" : "opacity-0") }),
1144
- H.label
1145
- ]
1146
- },
1147
- H.value
1148
- )) })
1149
- ] })
1150
- ] })
1151
- ] }) })
1152
- ] }),
1153
- s && /* @__PURE__ */ t.jsx(k, { children: s }),
1154
- o && !s && /* @__PURE__ */ t.jsx(_, { children: o })
1155
- ] });
1156
- }
1157
- const V = m && b?.showLoading, N = se.filter((S) => {
1158
- const z = D[S];
1159
- return z == null || z === "";
1160
- }), $ = N.map((S) => Bt(S, w) || S), R = g.length === 0 && !V ? d || (N.length > 0 ? `${x("renderer.defaultHttpInput.waitingForRequiredFields")}: ${$.join(", ")}` : x("renderer.defaultHttpInput.noDataAvailable")) : void 0, E = /* @__PURE__ */ t.jsxs(
1161
- Ye,
1162
- {
1163
- value: Array.isArray(r) ? r[0] ?? "" : r ?? "",
1164
- onValueChange: (S) => n(S),
1165
- disabled: V || g.length === 0,
1166
- name: l,
1167
- children: [
1168
- /* @__PURE__ */ t.jsxs(Ze, { id: c, name: l, className: "w-full", children: [
1169
- V && /* @__PURE__ */ t.jsx(we, { className: "mr-2 h-4 w-4 animate-spin" }),
1170
- /* @__PURE__ */ t.jsx(et, { placeholder: i || x("renderer.defaultHttpInput.selectOption") })
1171
- ] }),
1172
- /* @__PURE__ */ t.jsx(tt, { children: /* @__PURE__ */ t.jsx(st, { children: g.map((S, z) => /* @__PURE__ */ t.jsx(rt, { value: S.value, children: S.label }, S.value + z)) }) })
1173
- ]
1174
- }
1175
- );
1176
- return /* @__PURE__ */ t.jsxs(O, { className: "mb-4", children: [
1177
- /* @__PURE__ */ t.jsxs(A, { htmlFor: c, children: [
1178
- a || e.data.name,
1179
- e.data.required && /* @__PURE__ */ t.jsx("span", { className: "text-red-500", children: "*" })
1180
- ] }),
1181
- R ? /* @__PURE__ */ t.jsx(Ve, { children: /* @__PURE__ */ t.jsxs(xt, { children: [
1182
- /* @__PURE__ */ t.jsx(bt, { asChild: !0, children: /* @__PURE__ */ t.jsx("div", { className: "w-full", children: E }) }),
1183
- /* @__PURE__ */ t.jsx(jt, { children: /* @__PURE__ */ t.jsx("p", { children: R }) })
1184
- ] }) }) : E,
1185
- s && /* @__PURE__ */ t.jsx(k, { children: s }),
1186
- o && !s && /* @__PURE__ */ t.jsx(_, { children: o })
1187
- ] });
1188
- }
1189
- return /* @__PURE__ */ t.jsxs(O, { className: "mb-4", children: [
1190
- /* @__PURE__ */ t.jsxs(A, { htmlFor: c, children: [
1191
- a || e.data.name,
1192
- e.data.required && /* @__PURE__ */ t.jsx("span", { className: "text-red-500", children: "*" })
1193
- ] }),
1194
- /* @__PURE__ */ t.jsx(X, { type: "text", name: l, id: c, value: typeof r == "string" ? r : JSON.stringify(r), readOnly: !0, disabled: !0 }),
1195
- s && /* @__PURE__ */ t.jsx(k, { children: s }),
1196
- o && !s && /* @__PURE__ */ t.jsx(_, { children: o })
1197
- ] });
1198
- }, gs = ({ node: e, value: r, setValue: n, error: s, label: a, placeholder: i, helperText: o, name: c, id: l }) => /* @__PURE__ */ t.jsxs(O, { className: "mb-4", children: [
1199
- /* @__PURE__ */ t.jsxs(A, { htmlFor: l, children: [
1200
- a || e.data.name,
1201
- e.data.required && /* @__PURE__ */ t.jsx("span", { className: "text-red-500", children: "*" })
1202
- ] }),
1203
- /* @__PURE__ */ t.jsx(
1204
- X,
1205
- {
1206
- id: l,
1207
- type: "number",
1208
- name: c,
1209
- value: r ?? "",
1210
- onChange: (m) => n(m.target.value === "" ? null : Number(m.target.value)),
1211
- placeholder: i
1212
- }
1213
- ),
1214
- s && /* @__PURE__ */ t.jsx(k, { children: s }),
1215
- o && !s && /* @__PURE__ */ t.jsx(_, { children: o })
1216
- ] }), xs = ({ node: e, value: r, setValue: n, error: s, label: a, placeholder: i, helperText: o, name: c, id: l }) => /* @__PURE__ */ t.jsxs(O, { className: "mb-4", children: [
1217
- /* @__PURE__ */ t.jsxs(A, { htmlFor: l, children: [
1218
- a || e.data.name,
1219
- e.data.required && /* @__PURE__ */ t.jsx("span", { className: "text-red-500", children: "*" })
1220
- ] }),
1221
- /* @__PURE__ */ t.jsx(
1222
- X,
1223
- {
1224
- id: l,
1225
- name: c,
1226
- type: "password",
1227
- value: r ?? "",
1228
- onChange: (m) => n(m.target.value),
1229
- placeholder: i,
1230
- autoComplete: "new-password"
1231
- }
1232
- ),
1233
- s && /* @__PURE__ */ t.jsx(k, { children: s }),
1234
- o && !s && /* @__PURE__ */ t.jsx(_, { children: o })
1235
- ] });
1236
- function bs({ className: e, ...r }) {
1237
- return /* @__PURE__ */ t.jsx(Ae.Root, { "data-slot": "radio-group", className: y("grid gap-3", e), ...r });
1238
- }
1239
- function js({ className: e, ...r }) {
1240
- return /* @__PURE__ */ t.jsx(
1241
- Ae.Item,
1242
- {
1243
- "data-slot": "radio-group-item",
1244
- className: y(
1245
- "aspect-square size-4 shrink-0 rounded-full border border-input text-primary shadow-xs outline-none transition-[color,box-shadow] focus-visible:border-ring focus-visible:ring-[3px] focus-visible:ring-ring/50 disabled:cursor-not-allowed disabled:opacity-50 aria-invalid:border-destructive aria-invalid:ring-destructive/20 dark:bg-input/30 dark:aria-invalid:ring-destructive/40",
1246
- e
1247
- ),
1248
- ...r,
1249
- children: /* @__PURE__ */ t.jsx(Ae.Indicator, { "data-slot": "radio-group-indicator", className: "relative flex items-center justify-center", children: /* @__PURE__ */ t.jsx(Mt, { className: "-translate-x-1/2 -translate-y-1/2 absolute top-1/2 left-1/2 size-2 fill-primary" }) })
1250
- }
1251
- );
1252
- }
1253
- const ys = ({ node: e, value: r, setValue: n, error: s, label: a, helperText: i, id: o, name: c }) => {
1254
- const l = B(), m = r ? String(r) : "";
1255
- return /* @__PURE__ */ t.jsxs(O, { className: "mb-4", children: [
1256
- /* @__PURE__ */ t.jsxs(A, { className: "mb-1", htmlFor: o, children: [
1257
- a || e.data.name,
1258
- e.data.required && /* @__PURE__ */ t.jsx("span", { className: "text-red-500", children: "*" })
1259
- ] }),
1260
- /* @__PURE__ */ t.jsx(bs, { value: m, onValueChange: (u) => n(u), id: o, name: c, children: e.data.options?.map((u, d) => /* @__PURE__ */ t.jsxs("div", { className: "flex items-center space-x-2", children: [
1261
- /* @__PURE__ */ t.jsx(js, { value: String(u.value), id: `${o}-${u.value}`, disabled: u.disabled }),
1262
- /* @__PURE__ */ t.jsx(A, { htmlFor: `${o}-${u.value}`, className: "cursor-pointer font-normal text-sm", children: l(u.label) ? l(u.label) : u.value })
1263
- ] }, u.value + d)) }),
1264
- s && /* @__PURE__ */ t.jsx(k, { children: s }),
1265
- i && !s && /* @__PURE__ */ t.jsx(_, { children: i })
1266
- ] });
1267
- }, Ns = ({ node: e, value: r, setValue: n, error: s, label: a, placeholder: i, helperText: o, name: c, id: l }) => {
1268
- const m = B(), u = r ? String(r) : "";
1269
- return /* @__PURE__ */ t.jsxs(O, { className: "mb-4", children: [
1270
- /* @__PURE__ */ t.jsxs(A, { htmlFor: l, children: [
1271
- a || e.data.name,
1272
- e.data.required && /* @__PURE__ */ t.jsx("span", { className: "text-red-500", children: "*" })
1273
- ] }),
1274
- /* @__PURE__ */ t.jsxs(Ye, { name: c, value: u, onValueChange: (d) => n(d), children: [
1275
- /* @__PURE__ */ t.jsx(Ze, { id: l, name: c, className: "w-full", children: /* @__PURE__ */ t.jsx(et, { placeholder: i || m("renderer.defaultSelectInput.selectOption") }) }),
1276
- /* @__PURE__ */ t.jsx(tt, { children: /* @__PURE__ */ t.jsx(st, { children: e.data.options?.map((d, f) => /* @__PURE__ */ t.jsx(rt, { value: String(d.value), disabled: d.disabled, children: m(d.label) ? m(d.label) : d.value }, `${d.value}-${f}`)) }) })
1277
- ] }),
1278
- s && /* @__PURE__ */ t.jsx(k, { children: s }),
1279
- o && !s && /* @__PURE__ */ t.jsx(_, { children: o })
1280
- ] });
1281
- }, yt = kt(
1282
- ({ label: e, id: r, disabled: n, onBlur: s, onClick: a, onFocus: i, onPointerDown: o, onPointerLeave: c, onPointerMove: l, ...m }, u) => {
1283
- const d = B();
1284
- return /* @__PURE__ */ t.jsx(
1285
- "button",
1286
- {
1287
- ref: u,
1288
- id: r,
1289
- onBlur: s,
1290
- onClick: a,
1291
- onFocus: i,
1292
- onPointerDown: o,
1293
- disabled: n,
1294
- onPointerLeave: c,
1295
- onPointerMove: l,
1296
- type: "submit",
1297
- className: "mt-4 rounded-md bg-blue-500 px-4 py-2 font-medium text-white transition-colors hover:bg-blue-600 focus:outline-none focus:ring-2 focus:ring-blue-500 focus:ring-offset-2 disabled:cursor-not-allowed disabled:opacity-50",
1298
- ...m,
1299
- children: e || d("renderer.defaultSubmitButton.submit")
1300
- }
1301
- );
1302
- }
1303
- ), Nt = ({ children: e, missingFields: r = [] }) => {
1304
- const n = r.length > 0, s = B();
1305
- return n ? /* @__PURE__ */ t.jsx(Ve, { children: /* @__PURE__ */ t.jsxs(xt, { children: [
1306
- /* @__PURE__ */ t.jsx(bt, { asChild: !0, children: e }),
1307
- /* @__PURE__ */ t.jsx(jt, { children: /* @__PURE__ */ t.jsxs("div", { className: "space-y-1", children: [
1308
- /* @__PURE__ */ t.jsxs("p", { className: "font-semibold", children: [
1309
- s("renderer.defaultSubmitButton.requiredFieldsMissing"),
1310
- ":"
1311
- ] }),
1312
- /* @__PURE__ */ t.jsx("ul", { className: "list-inside list-disc", children: r.map((a, i) => /* @__PURE__ */ t.jsx("li", { children: a }, i)) })
1313
- ] }) })
1314
- ] }) }) : e;
1315
- }, ws = ({ missingRequiredFields: e, isSubmitting: r, label: n }) => {
1316
- const s = dt(), a = s?.components?.submitButton, i = s?.components?.submitButtonWrapper, o = a || yt, c = i || Nt;
1317
- return /* @__PURE__ */ t.jsx(c, { missingFields: e, children: /* @__PURE__ */ t.jsx(o, { label: n, disabled: r }) });
1318
- }, vs = ({ node: e, value: r, setValue: n, error: s, label: a, helperText: i, name: o, id: c }) => /* @__PURE__ */ t.jsxs(O, { className: "mb-4", children: [
1319
- /* @__PURE__ */ t.jsxs(A, { htmlFor: c, children: [
1320
- a || e.data.name,
1321
- e.data.required && /* @__PURE__ */ t.jsx("span", { className: "text-red-500", children: "*" })
1322
- ] }),
1323
- /* @__PURE__ */ t.jsx(At, { id: c, name: o, checked: r, onCheckedChange: n }),
1324
- i && !s && /* @__PURE__ */ t.jsx(_, { children: i }),
1325
- s && /* @__PURE__ */ t.jsx(k, { children: s })
1326
- ] }), Ss = ({ node: e, value: r, setValue: n, error: s, label: a, placeholder: i, helperText: o, name: c, id: l }) => /* @__PURE__ */ t.jsxs(O, { className: "mb-4", children: [
1327
- /* @__PURE__ */ t.jsxs(A, { htmlFor: l, children: [
1328
- a || e.data.name,
1329
- e.data.required && /* @__PURE__ */ t.jsx("span", { className: "text-red-500", children: "*" })
1330
- ] }),
1331
- /* @__PURE__ */ t.jsx(
1332
- Dt,
1333
- {
1334
- id: l,
1335
- name: c,
1336
- value: r ?? "",
1337
- onChange: (m) => n(m.target.value),
1338
- placeholder: i,
1339
- className: "w-full rounded-md border px-3 py-2",
1340
- rows: 4
1341
- }
1342
- ),
1343
- s && /* @__PURE__ */ t.jsx(k, { children: s }),
1344
- o && !s && /* @__PURE__ */ t.jsx(_, { children: o })
1345
- ] }), Fs = ({ node: e, value: r, setValue: n, error: s, label: a, placeholder: i, helperText: o, name: c, id: l }) => /* @__PURE__ */ t.jsxs(O, { className: "mb-4", children: [
1346
- /* @__PURE__ */ t.jsxs(A, { htmlFor: l, children: [
1347
- a || e.data.name,
1348
- e.data.required && /* @__PURE__ */ t.jsx("span", { className: "text-red-500", children: "*" })
1349
- ] }),
1350
- /* @__PURE__ */ t.jsx(X, { type: "text", id: l, name: c, value: r ?? "", onChange: (m) => n(m.target.value), placeholder: i }),
1351
- s && /* @__PURE__ */ t.jsx(k, { children: s }),
1352
- o && !s && /* @__PURE__ */ t.jsx(_, { children: o })
1353
- ] }), Cs = ({ node: e, value: r, setValue: n, error: s, label: a, placeholder: i, helperText: o, name: c, id: l }) => /* @__PURE__ */ t.jsxs(O, { className: "mb-4", children: [
1354
- /* @__PURE__ */ t.jsxs(A, { htmlFor: l, children: [
1355
- a || e.data.name,
1356
- e.data.required && /* @__PURE__ */ t.jsx("span", { className: "text-red-500", children: "*" })
1357
- ] }),
1358
- /* @__PURE__ */ t.jsx(
1359
- X,
1360
- {
1361
- type: "time",
1362
- id: l,
1363
- name: c,
1364
- value: r ?? "",
1365
- onChange: (m) => n(m.target.value),
1366
- placeholder: i,
1367
- className: "bg-background [color-scheme:light] dark:[color-scheme:dark]"
1368
- }
1369
- ),
1370
- s && /* @__PURE__ */ t.jsx(k, { children: s }),
1371
- o && !s && /* @__PURE__ */ t.jsx(_, { children: o })
1372
- ] }), Ts = ({ node: e, value: r, setValue: n, error: s, label: a, helperText: i, id: o, name: c }) => {
1373
- const l = B(), m = Array.isArray(r) ? r : [], u = m[0] || "", d = m[1] || "", f = (h) => {
1374
- n([h, d]);
1375
- }, g = (h) => {
1376
- n([u, h]);
1377
- };
1378
- return /* @__PURE__ */ t.jsxs(O, { className: "mb-4", children: [
1379
- /* @__PURE__ */ t.jsxs(A, { htmlFor: `${o}-start`, children: [
1380
- a || e.data.name,
1381
- e.data.required && /* @__PURE__ */ t.jsx("span", { className: "text-red-500", children: "*" })
1382
- ] }),
1383
- /* @__PURE__ */ t.jsxs("div", { className: "flex gap-2", children: [
1384
- /* @__PURE__ */ t.jsx(
1385
- X,
1386
- {
1387
- id: `${o}-start`,
1388
- name: `${c}-start`,
1389
- "aria-label": `${a || e.data.name} - ${l("renderer.defaultInputs.startTime")}`,
1390
- "aria-invalid": !!s,
1391
- "aria-describedby": s ? `${e.id}-error` : void 0,
1392
- type: "time",
1393
- value: u,
1394
- onChange: (h) => f(h.target.value),
1395
- placeholder: l("renderer.defaultInputs.startTime"),
1396
- className: "flex-1 bg-background [color-scheme:light] dark:[color-scheme:dark]"
1397
- }
1398
- ),
1399
- /* @__PURE__ */ t.jsx(
1400
- X,
1401
- {
1402
- id: `${o}-end`,
1403
- name: `${c}-end`,
1404
- "aria-label": `${a || e.data.name} - ${l("renderer.defaultInputs.endTime")}`,
1405
- "aria-invalid": !!s,
1406
- "aria-describedby": s ? `${e.id}-error` : void 0,
1407
- type: "time",
1408
- value: d,
1409
- onChange: (h) => g(h.target.value),
1410
- placeholder: l("renderer.defaultInputs.endTime"),
1411
- className: "flex-1 bg-background [color-scheme:light] dark:[color-scheme:dark]"
1412
- }
1413
- )
1414
- ] }),
1415
- s && /* @__PURE__ */ t.jsx(k, { children: s }),
1416
- i && !s && /* @__PURE__ */ t.jsx(_, { children: i })
1417
- ] });
1418
- }, Is = {
1419
- address: os,
1420
- autocomplete: is,
1421
- checkbox: ls,
1422
- date: ds,
1423
- daterange: us,
1424
- file: fs,
1425
- hidden: ps,
1426
- http: hs,
1427
- number: gs,
1428
- password: xs,
1429
- radio: ys,
1430
- select: Ns,
1431
- submit: ws,
1432
- switch: vs,
1433
- text: Fs,
1434
- textarea: Ss,
1435
- time: Cs,
1436
- timerange: Ts
1437
- }, As = ({ node: e }) => {
1438
- const n = B()(e.data?.label);
1439
- return n ? /* @__PURE__ */ t.jsxs("div", { className: "flex items-center gap-x-3", children: [
1440
- /* @__PURE__ */ t.jsx(Ne, { className: "my-8 flex-1" }),
1441
- /* @__PURE__ */ t.jsx("h4", { className: "font-semibold text-sm", children: n }),
1442
- /* @__PURE__ */ t.jsx(Ne, { className: "my-8 flex-1" })
1443
- ] }) : /* @__PURE__ */ t.jsx(Ne, { className: "my-8" });
1444
- }, Ds = ({ node: e }) => {
1445
- const { edges: r } = xe(), n = B(), s = ut(e.id, r);
1446
- return /* @__PURE__ */ t.jsx("h2", { className: y("mb-5 font-bold text-2xl", !s && "mt-10"), children: n(e.data?.label) });
1447
- }, Rs = {
1448
- divider: As,
1449
- title: Ds
1450
- }, Es = async (e) => {
1451
- try {
1452
- const { url: r, method: n = "GET", headers: s = [], body: a } = e;
1453
- if (!r || r.trim() === "")
1454
- return {
1455
- error: "No URL provided",
1456
- success: !1
1457
- };
1458
- const i = {
1459
- "Content-Type": "application/json"
1460
- };
1461
- s.forEach((u) => {
1462
- u.key && u.value && (i[u.key] = u.value);
1463
- });
1464
- const o = {
1465
- headers: i,
1466
- method: n
1467
- };
1468
- a && n && ["POST", "PUT", "PATCH"].includes(n) && (o.body = a);
1469
- const c = await fetch(r, o);
1470
- let l;
1471
- return c.headers.get("content-type")?.includes("application/json") ? l = await c.json() : l = await c.text(), c.ok ? {
1472
- data: l,
1473
- status: c.status,
1474
- statusText: c.statusText,
1475
- success: !0
1476
- } : {
1477
- data: l,
1478
- error: `HTTP ${c.status}: ${c.statusText}`,
1479
- status: c.status,
1480
- statusText: c.statusText,
1481
- success: !1
1482
- };
1483
- } catch (r) {
1484
- return {
1485
- error: r instanceof Error ? r.message : "An unknown error occurred",
1486
- success: !1
1487
- };
1488
- }
1489
- }, Ie = (e, r, n = {}) => {
1490
- if (!e)
1491
- return "";
1492
- const { encode: s = !1, json: a = !1 } = n;
1493
- return e.replace(/\{\{([\w-]+)}}/g, (i, o) => {
1494
- const c = r[o.trim()];
1495
- if (c == null)
1496
- return a ? "null" : "";
1497
- const l = typeof c == "string" ? te(c) : c;
1498
- if (s)
1499
- return encodeURIComponent(String(l));
1500
- if (a) {
1501
- if (typeof l == "string")
1502
- return `"${l.replace(/\\/g, "\\\\").replace(/"/g, '\\"')}"`;
1503
- if (typeof l == "number" || typeof l == "boolean")
1504
- return String(l);
1505
- if (typeof l == "object")
1506
- return JSON.stringify(l);
1507
- }
1508
- return String(l);
1509
- });
1510
- }, Os = (e, r) => e ? e.replace(/\{\{response\.([\w.-]+)}}/g, (n, s) => {
1511
- const a = ks(r, s.trim());
1512
- return a != null ? String(a) : "";
1513
- }) : "", ks = (e, r) => {
1514
- if (!(!e || typeof e != "object"))
1515
- return r.split(".").reduce((n, s) => {
1516
- if (!(n == null || typeof n != "object"))
1517
- return n[s];
1518
- }, e);
1519
- }, _s = async (e, r, n) => {
1520
- if (!e.url || e.url.trim() === "")
1521
- return {
1522
- error: "No URL configured for submission",
1523
- success: !1
1524
- };
1525
- const s = Ie(e.url, r, { encode: !0 });
1526
- if (!s || s.trim() === "")
1527
- return {
1528
- error: "Invalid URL after template replacement",
1529
- success: !1
1530
- };
1531
- const a = e.headers?.map((l) => ({
1532
- key: l.key,
1533
- value: Ie(l.value, r)
1534
- })), i = e.sendFormData ? JSON.stringify(ze(r, n)) : e.body ? Ie(e.body, r, { json: !0 }) : void 0, o = await Es({
1535
- body: i,
1536
- headers: a,
1537
- method: e.method || "POST",
1538
- url: s
1539
- });
1540
- if (!o.success)
1541
- return {
1542
- data: o.data,
1543
- error: o.error,
1544
- success: !1
1545
- };
1546
- const c = e.redirectUrl ? (() => {
1547
- const l = Os(e.redirectUrl, o.data);
1548
- return l && l.trim() !== "" ? l : void 0;
1549
- })() : void 0;
1550
- return {
1551
- data: o.data,
1552
- redirectUrl: c,
1553
- success: !0
1554
- };
1555
- }, Ps = (e) => {
1556
- if (!e)
1557
- return;
1558
- e.startsWith("http://") || e.startsWith("https://") ? window.location.href = e : window.history?.pushState ? (window.history.pushState({}, "", e), window.dispatchEvent(new PopStateEvent("popstate"))) : window.location.href = e;
1559
- }, Ms = (e, r, n, s) => {
1560
- const [a, i] = L(!1), [o, c] = L(null), l = U(() => {
1561
- const d = e.find((f) => G(f) && f.data?.type === "submit");
1562
- return d && G(d) ? d : null;
1563
- }, [e]), m = Q(
1564
- async (d) => {
1565
- if (!l?.data?.submitConfig)
1566
- return null;
1567
- const f = l.data.submitConfig;
1568
- if (!f.url || f.url.trim() === "")
1569
- return null;
1570
- c(null), f.showLoading !== !1 && i(!0);
1571
- try {
1572
- const g = await _s(f, r, s);
1573
- if (g.success) {
1574
- const h = ae(f.successMessage, n);
1575
- if (h && c({ message: h, type: "success" }), d && d(g.data), g.redirectUrl) {
1576
- const p = g.redirectUrl;
1577
- setTimeout(() => Ps(p), 1e3);
1578
- }
1579
- } else {
1580
- const h = ae(f.errorMessage, n) || g.error || "An error occurred during submission";
1581
- c({ message: h, type: "error" });
1582
- }
1583
- return g;
1584
- } catch (g) {
1585
- const h = ae(f.errorMessage, n) || (g instanceof Error ? g.message : "An unexpected error occurred");
1586
- return c({ message: h, type: "error" }), {
1587
- error: h,
1588
- success: !1
1589
- };
1590
- } finally {
1591
- i(!1);
1592
- }
1593
- },
1594
- [l, r, n, s]
1595
- );
1596
- return {
1597
- clearSubmitMessage: Q(() => {
1598
- c(null);
1599
- }, []),
1600
- handleSubmitWithConfig: m,
1601
- hasSubmitConfig: !!l?.data?.submitConfig,
1602
- isSubmitting: a,
1603
- submitButtonNode: l,
1604
- submitMessage: o
1605
- };
1606
- }, tr = ({
1607
- components: e,
1608
- flows: r,
1609
- googleApiKey: n,
1610
- language: s,
1611
- onChange: a,
1612
- onSubmit: i,
1613
- theme: o,
1614
- validate: c,
1615
- validationMode: l,
1616
- initialValues: m = {}
1617
- }) => {
1618
- const u = dt(), d = {
1619
- components: {
1620
- form: e?.form ?? u?.components?.form,
1621
- group: e?.group ?? u?.components?.group,
1622
- inputs: { ...u?.components?.inputs, ...e?.inputs },
1623
- submitButton: e?.submitButton ?? u?.components?.submitButton,
1624
- submitButtonWrapper: e?.submitButtonWrapper ?? u?.components?.submitButtonWrapper,
1625
- ui: { ...u?.components?.ui, ...e?.ui }
1626
- },
1627
- googleApiKey: n ?? u?.googleApiKey,
1628
- language: s ?? u?.language ?? "en",
1629
- theme: o ?? u?.theme ?? "dark",
1630
- validationMode: l ?? u?.validationMode ?? "onSubmit"
1631
- }, {
1632
- canSubmit: f,
1633
- mergedFlow: g,
1634
- formErrors: h,
1635
- formValues: p,
1636
- inputNodes: j,
1637
- missingRequiredFields: I,
1638
- prevFormValuesRef: M,
1639
- visibleNodes: D,
1640
- visibleRootNodes: w,
1641
- setFieldValue: x,
1642
- setMultipleFieldValues: b,
1643
- validateForm: v,
1644
- t: F
1645
- } = ts(r, m, d.language), { handleSubmitWithConfig: P, hasSubmitConfig: q, isSubmitting: ee, submitMessage: Y, clearSubmitMessage: de } = Ms(
1646
- D,
1647
- p,
1648
- d.language,
1649
- j
1650
- ), se = d.components.form || ss, re = d.components.submitButton || yt, ie = d.components.submitButtonWrapper || Nt, le = K(a), W = K(c), C = U(() => ze(p, j), [p, j]), T = Q(
1651
- async (N) => {
1652
- N.preventDefault();
1653
- const { isValid: $, errors: R } = v(W.current);
1654
- if (!$) {
1655
- const E = Object.keys(R)[0];
1656
- E && document.getElementById(E)?.focus();
1657
- return;
1658
- }
1659
- if (q) {
1660
- const E = await P((S) => {
1661
- i && i(C, { httpResponse: S });
1662
- });
1663
- if (E === null) {
1664
- i?.(C);
1665
- return;
1666
- }
1667
- if (!E.success)
1668
- return;
1669
- } else i && i(C);
1670
- },
1671
- [v, q, P, i, C]
1672
- ), V = Q(
1673
- (N) => {
1674
- const { type: $ } = N;
1675
- switch ($) {
1676
- case fe.input: {
1677
- if (!G(N))
1678
- return null;
1679
- const R = N.data, E = R.type || "text", S = d.components.inputs?.[E], z = Is[E], H = S || z, ue = (Tt) => x(Z, Tt), Z = N.id, ne = p[Z], be = h[Z], je = ae(R.label, d.language), me = ae(R.placeholder, d.language), wt = ae(R.helperText, d.language), vt = $e(N), St = te(je), Ft = te(me), Ct = te(wt);
1680
- return /* @__PURE__ */ t.jsx(
1681
- H,
1682
- {
1683
- id: N.id,
1684
- node: N,
1685
- value: ne,
1686
- error: be,
1687
- label: St,
1688
- placeholder: Ft,
1689
- helperText: Ct,
1690
- name: vt,
1691
- setValue: ue,
1692
- missingRequiredFields: I
1693
- },
1694
- N.id
1695
- );
1696
- }
1697
- case fe.group: {
1698
- if (!Et(N))
1699
- return null;
1700
- const R = d.components.group || rs, E = D.filter((S) => S.parentId === N.id);
1701
- return /* @__PURE__ */ t.jsx(R, { node: N, children: E.map((S) => V(S)) }, N.id);
1702
- }
1703
- case fe.ui: {
1704
- if (!Rt(N))
1705
- return null;
1706
- const E = N.data.type || "title", S = d.components.ui?.[E], z = Rs[E], H = S || z;
1707
- return /* @__PURE__ */ t.jsx(H, { node: N }, N.id);
1708
- }
1709
- case fe.flow:
1710
- return null;
1711
- default:
1712
- return console.warn("Unknown node type:", $), null;
1713
- }
1714
- },
1715
- [d.components, d.language, D, p, h, x, I]
1716
- );
1717
- return J(() => {
1718
- le.current = a;
1719
- }, [a]), J(() => {
1720
- W.current = c;
1721
- }, [c]), J(() => {
1722
- le.current?.(C);
1723
- }, [C]), J(() => {
1724
- d.validationMode === "onChange" && v(W.current);
1725
- }, [d.validationMode, v]), J(() => {
1726
- const N = Ht(j, p, M.current);
1727
- Object.keys(N).length > 0 && b(N), M.current = p;
1728
- }, [p, j, b, M]), /* @__PURE__ */ t.jsx("div", { className: "treege", children: /* @__PURE__ */ t.jsx(Ot, { theme: d.theme, storageKey: "treege-renderer-theme", children: /* @__PURE__ */ t.jsxs(
1729
- Yt,
1730
- {
1731
- value: {
1732
- flows: g,
1733
- formErrors: h,
1734
- formValues: p,
1735
- googleApiKey: d.googleApiKey,
1736
- inputNodes: j,
1737
- language: d.language,
1738
- setFieldValue: x
1739
- },
1740
- children: [
1741
- /* @__PURE__ */ t.jsxs(se, { onSubmit: T, children: [
1742
- w.map((N) => V(N)),
1743
- f && /* @__PURE__ */ t.jsx(ie, { missingFields: I, children: /* @__PURE__ */ t.jsx(re, { label: F("renderer.defaultSubmitButton.submit"), disabled: ee }) })
1744
- ] }),
1745
- /* @__PURE__ */ t.jsx("p", { className: "py-2 text-muted-foreground text-xs", children: "Powered by Treege" }),
1746
- Y && /* @__PURE__ */ t.jsx(
1747
- "div",
1748
- {
1749
- className: `my-4 rounded-md p-4 ${Y.type === "success" ? "bg-green-50 text-green-800 dark:bg-green-900/20 dark:text-green-300" : "bg-red-50 text-red-800 dark:bg-red-900/20 dark:text-red-300"}`,
1750
- role: "alert",
1751
- children: /* @__PURE__ */ t.jsxs("div", { className: "flex items-center justify-between", children: [
1752
- /* @__PURE__ */ t.jsx("p", { className: "font-medium text-sm", children: Y.message }),
1753
- /* @__PURE__ */ t.jsx(
1754
- "button",
1755
- {
1756
- type: "button",
1757
- onClick: de,
1758
- className: "ml-4 font-medium text-sm underline hover:no-underline focus:outline-none",
1759
- children: F("common.close")
1760
- }
1761
- )
1762
- ] })
1763
- }
1764
- )
1765
- ]
1766
- }
1767
- ) }) });
1768
- };
1769
- export {
1770
- gt as A,
1771
- er as B,
1772
- ms as C,
1773
- rs as D,
1774
- ut as E,
1775
- Gt as F,
1776
- Jt as G,
1777
- ft as H,
1778
- Se as I,
1779
- qt as J,
1780
- ze as K,
1781
- Ge as L,
1782
- Ht as M,
1783
- te as N,
1784
- De as O,
1785
- Zs as T,
1786
- ts as a,
1787
- tr as b,
1788
- os as c,
1789
- is as d,
1790
- ls as e,
1791
- ds as f,
1792
- us as g,
1793
- fs as h,
1794
- ps as i,
1795
- hs as j,
1796
- gs as k,
1797
- xs as l,
1798
- ys as m,
1799
- Ns as n,
1800
- vs as o,
1801
- Ss as p,
1802
- Fs as q,
1803
- Cs as r,
1804
- Ts as s,
1805
- Is as t,
1806
- dt as u,
1807
- As as v,
1808
- Ds as w,
1809
- Rs as x,
1810
- ve as y,
1811
- Vt as z
1812
- };