treege 3.0.0-beta.95 → 3.0.0-beta.96

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
package/dist/renderer.js CHANGED
@@ -1,5 +1,5 @@
1
- import { I as e, L as t, Y as n, _ as r, a as i, b as a, c as o, g as s, h as c, i as l, l as u, m as d, n as f, o as p, r as m, s as h, t as g, v as _, y as v } from "./ThemeContext-CDewydK5.js";
2
- import { C as y, L as b, S as x, _ as S, a as C, b as w, c as T, d as E, g as D, h as O, i as k, m as A, n as j, o as M, r as N, u as P, v as F, x as I, y as L } from "./DefaultSubmitButton-D4Hqyara.js";
3
- import { a as R, c as z, i as B, l as V, n as H, o as U, r as W, s as G } from "./useRenderNode-BaBKq6Ed.js";
4
- import { a as K, c as q, i as J, l as Y, n as X, o as Z, r as Q, s as $, t as ee } from "./renderer-Cd2P21x9.js";
5
- export { y as DefaultAddressInput, x as DefaultAutocompleteInput, I as DefaultCheckboxInput, w as DefaultDateInput, L as DefaultDateRangeInput, F as DefaultFileInput, S as DefaultHiddenInput, D as DefaultHttpInput, b as DefaultInputLabel, O as DefaultNumberInput, A as DefaultPasswordInput, E as DefaultRadioInput, P as DefaultSelectInput, T as DefaultSwitchInput, M as DefaultTextAreaInput, C as DefaultTextInput, k as DefaultTimeInput, N as DefaultTimeRangeInput, Z as Divider, g as ThemeProvider, $ as Title, K as TreegeRenderer, z as TreegeRendererProvider, ee as TreegeViewer, Y as TreegeViewerProvider, m as applyReferenceTransformation, l as buildInitialFormValues, i as calculateReferenceFieldUpdates, p as checkFormFieldHasValue, h as convertFormValuesToNamedFormat, j as defaultInputRenderers, q as defaultUI, U as evaluateCondition, G as evaluateConditions, d as fileNameFromUrl, c as fileToSerializable, s as filesToSerializable, W as findStartNode, r as formatFileSize, B as getFlowRenderState, n as getTranslatedText, X as getViewerFields, o as isFieldEmpty, Q as isImageFile, _ as isRemoteFileData, R as isStartNode, v as normalizeSerializableFiles, u as resolveNodeDefaultValue, e as sanitize, t as sanitizeHttpResponse, a as serializableToFile, f as useTheme, H as useTreegeRenderer, V as useTreegeRendererConfig, J as viewerFieldsFromResponse };
1
+ import { L as e, R as t, X as n, _ as r, a as i, b as a, c as o, g as s, h as c, i as l, l as u, n as d, o as f, r as p, s as m, t as h, u as g, v as _, x as v, y } from "./ThemeContext-B9-cptw0.js";
2
+ import { C as b, L as x, S, _ as C, a as w, b as T, c as E, d as D, g as O, h as k, i as A, m as j, n as M, o as N, r as P, u as F, v as I, x as L, y as R } from "./DefaultSubmitButton-CAOTg3w7.js";
3
+ import { a as z, c as B, i as V, l as H, n as U, o as W, r as G, s as K } from "./useRenderNode-C9RSQFX3.js";
4
+ import { a as q, c as J, i as Y, l as X, n as Z, o as Q, r as $, s as ee, t as te } from "./renderer-DX3WeZtk.js";
5
+ export { b as DefaultAddressInput, S as DefaultAutocompleteInput, L as DefaultCheckboxInput, T as DefaultDateInput, R as DefaultDateRangeInput, I as DefaultFileInput, C as DefaultHiddenInput, O as DefaultHttpInput, x as DefaultInputLabel, k as DefaultNumberInput, j as DefaultPasswordInput, D as DefaultRadioInput, F as DefaultSelectInput, E as DefaultSwitchInput, N as DefaultTextAreaInput, w as DefaultTextInput, A as DefaultTimeInput, P as DefaultTimeRangeInput, Q as Divider, h as ThemeProvider, ee as Title, q as TreegeRenderer, B as TreegeRendererProvider, te as TreegeViewer, X as TreegeViewerProvider, p as applyReferenceTransformation, l as buildInitialFormValues, i as calculateReferenceFieldUpdates, f as checkFormFieldHasValue, m as convertFormValuesToNamedFormat, M as defaultInputRenderers, J as defaultUI, W as evaluateCondition, K as evaluateConditions, c as fileNameFromUrl, s as fileToSerializable, r as filesToSerializable, G as findStartNode, _ as formatFileSize, V as getFlowRenderState, n as getTranslatedText, Z as getViewerFields, o as isFieldEmpty, $ as isImageFile, y as isRemoteFileData, z as isStartNode, a as normalizeSerializableFiles, u as resolveEmptyInputValue, g as resolveNodeDefaultValue, e as sanitize, t as sanitizeHttpResponse, v as serializableToFile, d as useTheme, U as useTreegeRenderer, H as useTreegeRendererConfig, Y as viewerFieldsFromResponse };
@@ -0,0 +1,600 @@
1
+ import { $ as e, A as t, I as n, K as r, L as i, M as a, N as o, P as s, Q as c, U as l, W as u, X as d, a as f, c as p, d as m, et as h, f as g, i as _, j as v, k as y, l as ee, m as b, o as x, p as S, s as C, u as te, w as ne } from "./ThemeContext-B9-cptw0.js";
2
+ import { Fragment as re, createContext as w, useCallback as T, useContext as E, useEffect as D, useMemo as O, useRef as k, useState as A } from "react";
3
+ import { jsx as j } from "react/jsx-runtime";
4
+ //#region src/renderer/context/TreegeRendererProvider.tsx
5
+ var ie = w(void 0), ae = () => E(ie), M = ({ children: e, ...t }) => /* @__PURE__ */ j(ie.Provider, {
6
+ value: t,
7
+ children: e
8
+ }), oe = (e, t, n) => {
9
+ if (!t) return e;
10
+ let r = typeof t == "function" ? t(n) : t;
11
+ return !r || typeof r != "object" || Array.isArray(r) ? e : e == null ? r : typeof e != "object" || Array.isArray(e) ? e : {
12
+ ...e,
13
+ ...r
14
+ };
15
+ }, N = async (e, n, r, i, c, l) => {
16
+ if (!e.url || e.url.trim() === "") return {
17
+ error: "No URL configured for submission",
18
+ success: !1
19
+ };
20
+ let u = s(a(e.url, n, { encode: !0 }), c);
21
+ if (!u || u.trim() === "") return {
22
+ error: "Invalid URL after template replacement",
23
+ success: !1
24
+ };
25
+ let d = C(n, r), f = e.payloadTemplate ? ne(e.payloadTemplate, n, r) : void 0, p = oe(f === void 0 ? e.sendAllFormValues ? d : void 0 : f, l, d), m = await y({
26
+ body: p === void 0 ? void 0 : JSON.stringify(p),
27
+ headers: t(o(i, n), o(e.headers, n)),
28
+ method: e.method || "POST",
29
+ queryParams: o(e.queryParams, n),
30
+ url: u
31
+ });
32
+ if (!m.success) return {
33
+ data: m.data,
34
+ error: m.error,
35
+ success: !1
36
+ };
37
+ let h = e.redirectUrl ? (() => {
38
+ let t = v(e.redirectUrl, m.data);
39
+ return t && t.trim() !== "" ? t : void 0;
40
+ })() : void 0;
41
+ return {
42
+ data: m.data,
43
+ redirectUrl: h,
44
+ success: !0
45
+ };
46
+ }, P = (e) => {
47
+ e && (typeof window > "u" || !window.location || (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));
48
+ }, se = (t, n, r, i, a, o, s) => {
49
+ let [c, l] = A(!1), [u, f] = A(null), p = O(() => {
50
+ let n = t.find((t) => e(t) && t.data?.type === "submit");
51
+ return n && e(n) ? n : null;
52
+ }, [t]), m = T(async (e) => {
53
+ if (!p?.data?.submitConfig) return null;
54
+ let t = p.data.submitConfig;
55
+ if (!t.url || t.url.trim() === "") return null;
56
+ f(null), t.showLoading !== !1 && l(!0);
57
+ try {
58
+ let c = await N(t, n, i, a, o, s);
59
+ if (c.success) {
60
+ let n = d(t.successMessage, r);
61
+ if (n && f({
62
+ message: n,
63
+ type: "success"
64
+ }), e && e(c.data), c.redirectUrl) {
65
+ let e = c.redirectUrl;
66
+ setTimeout(() => P(e), 1e3);
67
+ }
68
+ } else f({
69
+ message: d(t.errorMessage, r) || c.error || "An error occurred during submission",
70
+ type: "error"
71
+ });
72
+ return c;
73
+ } catch (e) {
74
+ let n = d(t.errorMessage, r) || (e instanceof Error ? e.message : "An unexpected error occurred");
75
+ return f({
76
+ message: n,
77
+ type: "error"
78
+ }), {
79
+ error: n,
80
+ success: !1
81
+ };
82
+ } finally {
83
+ l(!1);
84
+ }
85
+ }, [
86
+ p,
87
+ n,
88
+ r,
89
+ i,
90
+ a,
91
+ o,
92
+ s
93
+ ]);
94
+ return {
95
+ clearSubmitMessage: T(() => {
96
+ f(null);
97
+ }, []),
98
+ handleSubmitWithConfig: m,
99
+ hasSubmitConfig: !!p?.data?.submitConfig,
100
+ isSubmitting: c,
101
+ submitButtonNode: p,
102
+ submitMessage: u
103
+ };
104
+ }, F = (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), I = (e, t, n) => {
105
+ let r = F(e), i = F(t);
106
+ if (r === null || i === null) switch (n) {
107
+ case "===": return r === i;
108
+ case "!==": return r !== i;
109
+ default: return !1;
110
+ }
111
+ if ([
112
+ ">",
113
+ "<",
114
+ ">=",
115
+ "<="
116
+ ].includes(n)) {
117
+ let e = Number(r), t = Number(i);
118
+ if (!(Number.isNaN(e) || Number.isNaN(t))) switch (n) {
119
+ case ">": return e > t;
120
+ case "<": return e < t;
121
+ case ">=": return e >= t;
122
+ case "<=": return e <= t;
123
+ default: return !1;
124
+ }
125
+ return !1;
126
+ }
127
+ switch (n) {
128
+ case "===": {
129
+ let e = Number(r), t = Number(i);
130
+ return Number.isNaN(e) || Number.isNaN(t) ? String(r) === String(i) : e === t;
131
+ }
132
+ case "!==": {
133
+ let e = Number(r), t = Number(i);
134
+ return Number.isNaN(e) || Number.isNaN(t) ? String(r) !== String(i) : e !== t;
135
+ }
136
+ default: return !1;
137
+ }
138
+ }, L = (t, n, r) => {
139
+ let { field: i, operator: a, value: o } = t;
140
+ if (!(i && a) || o === void 0) return !0;
141
+ let s = n[i], c = s === void 0 && r ? r.get(i) : void 0, l = c && e(c) ? n[c.id] : s;
142
+ return Array.isArray(l) ? a === "===" ? l.some((e) => I(e, o, "===")) || I(l, o, "===") : a === "!==" ? l.every((e) => I(e, o, "!==")) && I(l, o, "!==") : l.some((e) => I(e, o, a)) : I(l, o, a);
143
+ }, R = (e, t, n) => {
144
+ if (!e || e.length === 0) return !0;
145
+ if (e.length === 1) return L(e[0], t, n);
146
+ let i = L(e[0], t, n);
147
+ for (let a = 1; a < e.length; a += 1) {
148
+ let o = e[a], s = L(o, t, n), c = e[a - 1].logicalOperator || r.AND;
149
+ if (c === r.AND) {
150
+ if (i &&= s, !i) return !1;
151
+ } else if (c === r.OR && (i ||= s, i)) return !0;
152
+ }
153
+ return i;
154
+ }, z = (e) => {
155
+ let t = /* @__PURE__ */ new Map();
156
+ return e.forEach((e) => {
157
+ let n = t.get(e.source);
158
+ n ? n.push(e) : t.set(e.source, [e]);
159
+ }), t;
160
+ }, B = (t, n, r) => {
161
+ let i = [], a = [], o = [];
162
+ t.forEach((e) => {
163
+ let t = e.data?.isFallback, n = e.data?.conditions?.length;
164
+ t ? o.push(e) : n ? a.push(e) : i.push(e);
165
+ });
166
+ let s = [...i];
167
+ if (a.length === 0) return o.length > 0 && s.length === 0 && s.push(...o), {
168
+ edgesToFollow: s,
169
+ waitingForInput: !1
170
+ };
171
+ if (!a.every((t) => {
172
+ let i = t.data?.conditions;
173
+ return i ? i.every((t) => {
174
+ if (!t.field) return !0;
175
+ let i = r.get(t.field);
176
+ return x(e(i) ? i.id : t.field, n);
177
+ }) : !1;
178
+ })) return o.length > 0 && s.push(...o), {
179
+ edgesToFollow: s,
180
+ waitingForInput: s.length === 0
181
+ };
182
+ let c = a.filter((e) => R(e.data?.conditions, n, r));
183
+ return c.length > 0 ? (s.push(...c), {
184
+ edgesToFollow: s,
185
+ waitingForInput: !1
186
+ }) : (s.push(...o), {
187
+ edgesToFollow: s,
188
+ waitingForInput: !1
189
+ });
190
+ }, V = (e, t) => !t.some((t) => t.target === e), ce = (t, n) => {
191
+ let r = t.filter((e) => V(e.id, n));
192
+ return r.find(e) || r[0];
193
+ }, H = (e, t, n = /* @__PURE__ */ new Set()) => !e || n.has(e) ? [] : (n.add(e), [e, ...H(t.get(e)?.parentId, t, n)]), le = (e, t, n, r) => {
194
+ e.forEach((e) => {
195
+ let i = n.get(e);
196
+ H(r.get(e)?.parentId, r).forEach((e) => {
197
+ t.add(e), !n.has(e) && i !== void 0 && n.set(e, i);
198
+ });
199
+ });
200
+ }, ue = (e, t, n) => {
201
+ let r = ce(e, t);
202
+ if (!r) return {
203
+ endOfPathReached: !0,
204
+ visibleNodeIds: /* @__PURE__ */ new Set(),
205
+ visibleNodes: [],
206
+ visibleRootNodes: []
207
+ };
208
+ let i = new Map(e.map((e) => [e.id, e])), a = z(t), o = [], s = /* @__PURE__ */ new Set(), c = /* @__PURE__ */ new Set(), l = !1, u = (e) => {
209
+ if (c.has(e)) return;
210
+ c.add(e);
211
+ let t = i.get(e);
212
+ if (!t) return;
213
+ s.add(e), o.push(t);
214
+ let { edgesToFollow: r, waitingForInput: d } = B(a.get(e) || [], n, i);
215
+ if (d) {
216
+ l = !0;
217
+ return;
218
+ }
219
+ r.forEach((e) => {
220
+ u(e.target);
221
+ });
222
+ };
223
+ u(r.id);
224
+ let d = new Map(o.map((e, t) => [e.id, t])), f = new Set(s);
225
+ le(s, f, d, i);
226
+ let p = e.filter((e) => f.has(e.id)).sort((e, t) => (d.get(e.id) ?? 2 ** 53 - 1) - (d.get(t.id) ?? 2 ** 53 - 1)), m = p.filter((e) => !(e.parentId && f.has(e.parentId)));
227
+ return {
228
+ endOfPathReached: !l,
229
+ visibleNodeIds: f,
230
+ visibleNodes: p,
231
+ visibleRootNodes: m
232
+ };
233
+ }, de = (e) => e.filter((e) => !c(e)).reduce((e, t) => {
234
+ let n = t.parentId ?? null, r = e.at(-1);
235
+ return r && r.groupId === n ? [...e.slice(0, -1), {
236
+ ...r,
237
+ nodes: [...r.nodes, t]
238
+ }] : [...e, {
239
+ groupId: n,
240
+ nodes: [t]
241
+ }];
242
+ }, []), U = [
243
+ u.radio,
244
+ u.select,
245
+ u.autocomplete
246
+ ], fe = (t) => {
247
+ if (!t) return;
248
+ let n = t.nodes.filter(e).filter((e) => e.data.type !== u.hidden && e.data.type !== u.submit);
249
+ if (n.length !== 1) return;
250
+ let [r] = n, { httpConfig: i, multiple: a, type: o } = r.data;
251
+ if (o === u.http) return i?.responseMapping ? r.id : void 0;
252
+ if (!(!(o && U.includes(o)) || a)) return r.id;
253
+ }, pe = 180, me = (e) => {
254
+ if (typeof e != "object" || !e) return JSON.stringify(e) ?? "null";
255
+ if (Array.isArray(e)) return `[${e.map(me).join(",")}]`;
256
+ let t = e;
257
+ return `{${Object.keys(t).sort().map((e) => `${JSON.stringify(e)}:${me(t[e])}`).join(",")}}`;
258
+ }, W = ({ baseUrl: r, components: i, extraPayload: a, flow: o, googleApiKey: s, headers: l, language: u, onBack: d, onChange: h, onSubmit: g, showPoweredBy: v, theme: y, title: ee, validate: b, validationMode: x, initialValues: S = {}, isSubmitting: re = !1 }) => {
259
+ let w = ae(), E = O(() => ({
260
+ baseUrl: r ?? w?.baseUrl,
261
+ components: {
262
+ form: i?.form ?? w?.components?.form,
263
+ inputs: {
264
+ ...w?.components?.inputs,
265
+ ...i?.inputs
266
+ },
267
+ loadingSkeleton: i?.loadingSkeleton ?? w?.components?.loadingSkeleton,
268
+ step: i?.step ?? w?.components?.step,
269
+ submitButton: i?.submitButton ?? w?.components?.submitButton,
270
+ submitButtonWrapper: i?.submitButtonWrapper ?? w?.components?.submitButtonWrapper,
271
+ ui: {
272
+ ...w?.components?.ui,
273
+ ...i?.ui
274
+ }
275
+ },
276
+ googleApiKey: s ?? w?.googleApiKey,
277
+ headers: t(w?.headers, l),
278
+ language: u ?? w?.language ?? "en",
279
+ showPoweredBy: v ?? w?.showPoweredBy ?? !0,
280
+ theme: y ?? w?.theme ?? "dark",
281
+ validationMode: x ?? w?.validationMode ?? "onSubmit"
282
+ }), [
283
+ r,
284
+ i,
285
+ w,
286
+ s,
287
+ l,
288
+ u,
289
+ v,
290
+ y,
291
+ x
292
+ ]), j = O(() => o?.nodes ?? [], [o]), ie = O(() => o?.edges ?? [], [o]), M = O(() => m(j), [j]), N = n(E.language), P = k({}), F = k(null), [I, L] = A({}), [R, z] = A(() => _(S, M)), B = O(() => me(S), [S]), V = k(B), { endOfPathReached: ce, visibleNodes: H, visibleRootNodes: le } = O(() => ue(j, ie, R), [
293
+ j,
294
+ ie,
295
+ R
296
+ ]), U = O(() => m(H), [H]), W = O(() => de(H), [H]), he = O(() => {
297
+ let e = /* @__PURE__ */ new Map();
298
+ return j.forEach((t) => {
299
+ c(t) && e.set(t.id, t);
300
+ }), e;
301
+ }, [j]), [G, K] = A(0), q = W.length === 0 ? 0 : Math.min(G, W.length - 1), J = W[q], ge = J?.groupId ? he.get(J.groupId) : void 0, _e = q === 0, Y = W.length === 0 || q >= W.length - 1, X = k(null), ve = k(q), ye = O(() => fe(J), [J]), be = k(null), { clearSubmitMessage: xe, handleSubmitWithConfig: Se, hasSubmitConfig: Ce, isSubmitting: we, submitButtonNode: Te, submitMessage: Ee } = se(H, R, E.language, U, E.headers, E.baseUrl, a), De = k(h), Oe = k(b), Z = O(() => C(R, U), [R, U]), ke = O(() => {
302
+ let e = Te?.data?.submitConfig?.payloadTemplate;
303
+ return e ? ne(e, R, U) ?? Z : Z;
304
+ }, [
305
+ Te,
306
+ R,
307
+ U,
308
+ Z
309
+ ]), Ae = T((e, t) => {
310
+ z((n) => ({
311
+ ...n,
312
+ [e]: t
313
+ })), L((t) => {
314
+ let n = { ...t };
315
+ return delete n[e], n;
316
+ });
317
+ let n = be.current;
318
+ !n || e !== n.autoAdvanceNodeId || (X.current !== null && (clearTimeout(X.current), X.current = null), !p(t) && (X.current = setTimeout(() => {
319
+ X.current = null;
320
+ let t = be.current;
321
+ t && t.autoAdvanceNodeId === e && t.canContinueStep && !t.isLastStep && t.goToNextStep();
322
+ }, pe)));
323
+ }, []), je = T((e) => {
324
+ Object.keys(e).length !== 0 && (z((t) => ({
325
+ ...t,
326
+ ...e
327
+ })), L((t) => {
328
+ let n = { ...t };
329
+ return Object.keys(e).forEach((e) => {
330
+ delete n[e];
331
+ }), n;
332
+ }));
333
+ }, []), Q = T((t) => {
334
+ let n = {};
335
+ H.forEach((t) => {
336
+ if (e(t)) {
337
+ let e = t.id, r = R[e];
338
+ if (t.data.required && p(r)) {
339
+ n[e] = N(t.data.errorMessage) || N("validation.required");
340
+ return;
341
+ }
342
+ if (!p(r) && t.data.pattern) try {
343
+ new RegExp(t.data.pattern).test(String(r)) || (n[e] = N(t.data.errorMessage) || N("validation.invalidFormat"));
344
+ } catch (t) {
345
+ console.error(`Invalid pattern for field ${e}:`, t);
346
+ }
347
+ }
348
+ });
349
+ let r = t ? t(R, H) : {}, i = {
350
+ ...n,
351
+ ...r
352
+ };
353
+ return L(i), {
354
+ errors: i,
355
+ hasCustomErrors: Object.keys(r).length > 0,
356
+ isValid: Object.keys(i).length === 0
357
+ };
358
+ }, [
359
+ H,
360
+ R,
361
+ N
362
+ ]), $ = T(() => {
363
+ K((e) => e >= W.length - 1 ? e : e + 1);
364
+ }, [W.length]), Me = T(() => {
365
+ K((e) => Math.max(0, e - 1));
366
+ }, []), Ne = T(async () => {
367
+ let { isValid: e } = Q(Oe.current);
368
+ if (!e) return !1;
369
+ let t = oe(ke, a, Z);
370
+ if (Ce) {
371
+ let e = await Se((e) => {
372
+ g && g(t, { httpResponse: e });
373
+ });
374
+ if (e === null) return g?.(t), !0;
375
+ if (!e.success) return !0;
376
+ } else g && g(t);
377
+ return !0;
378
+ }, [
379
+ Q,
380
+ Ce,
381
+ Se,
382
+ g,
383
+ ke,
384
+ a,
385
+ Z
386
+ ]), Pe = O(() => {
387
+ if (!J) return [];
388
+ let t = [];
389
+ return J.nodes.forEach((n) => {
390
+ e(n) && n.data.type !== "submit" && n.data.required && p(R[n.id]) && t.push(N(n.data.label) || n.id);
391
+ }), t;
392
+ }, [
393
+ J,
394
+ R,
395
+ N
396
+ ]), Fe = O(() => H.some((t) => e(t) && t.data.type === "submit"), [H]), Ie = (Fe || ce) && j.length > 0, Le = Y && Ie, Re = re || we, ze = O(() => J ? J.nodes.every((t) => !e(t) || !t.data.required || t.data.type === "submit" ? !0 : !p(R[t.id])) : !1, [J, R]), Be = O(() => {
397
+ let e = Object.keys(I);
398
+ return e.length > 0 ? e[0] : void 0;
399
+ }, [I]), Ve = ze && (Le || !Y), He = T(() => {
400
+ if (Le) {
401
+ Ne();
402
+ return;
403
+ }
404
+ $();
405
+ }, [
406
+ Le,
407
+ Ne,
408
+ $
409
+ ]), Ue = T(() => {
410
+ if (_e) {
411
+ d?.();
412
+ return;
413
+ }
414
+ Me();
415
+ }, [
416
+ _e,
417
+ d,
418
+ Me
419
+ ]), We = !_e || !!d, Ge = O(() => N(ge?.data?.label), [N, ge]), Ke = O(() => N(ee), [N, ee]);
420
+ return D(() => {
421
+ if (W.length === 0) {
422
+ G !== 0 && K(0);
423
+ return;
424
+ }
425
+ G > W.length - 1 && K(W.length - 1);
426
+ }, [W.length, G]), D(() => {
427
+ be.current = {
428
+ autoAdvanceNodeId: ye,
429
+ canContinueStep: ze,
430
+ goToNextStep: $,
431
+ isLastStep: Y
432
+ };
433
+ }, [
434
+ ye,
435
+ ze,
436
+ $,
437
+ Y
438
+ ]), D(() => {
439
+ ve.current !== q && (ve.current = q, X.current !== null && (clearTimeout(X.current), X.current = null));
440
+ }, [q]), D(() => () => {
441
+ X.current !== null && (clearTimeout(X.current), X.current = null);
442
+ }, []), D(() => {
443
+ De.current = h;
444
+ }, [h]), D(() => {
445
+ Oe.current = b;
446
+ }, [b]), D(() => {
447
+ De.current?.(Z);
448
+ }, [Z]), D(() => {
449
+ E.validationMode === "onChange" && Q(Oe.current);
450
+ }, [E.validationMode, Q]), D(() => {
451
+ let e = f(M, R, P.current);
452
+ Object.keys(e).length > 0 && je(e), P.current = R;
453
+ }, [
454
+ R,
455
+ M,
456
+ je
457
+ ]), D(() => {
458
+ let e = F.current, t = new Set(U.map((e) => e.id));
459
+ if (F.current = t, !e) return;
460
+ let n = [...e].filter((e) => !t.has(e)), r = {};
461
+ U.forEach((t) => {
462
+ if (e.has(t.id) || R[t.id] !== void 0) return;
463
+ let n = te(t, R);
464
+ n !== void 0 && (r[t.id] = n);
465
+ }), !(n.length === 0 && Object.keys(r).length === 0) && (z((e) => {
466
+ let t = {
467
+ ...e,
468
+ ...r
469
+ };
470
+ return n.forEach((e) => {
471
+ delete t[e];
472
+ }), t;
473
+ }), n.length > 0 && L((e) => {
474
+ let t = !1, r = { ...e };
475
+ return n.forEach((e) => {
476
+ e in r && (delete r[e], t = !0);
477
+ }), t ? r : e;
478
+ }));
479
+ }, [U, R]), D(() => {
480
+ V.current !== B && (V.current = B, z(_(S, M)), L({}), F.current = null);
481
+ }, [
482
+ B,
483
+ S,
484
+ M
485
+ ]), {
486
+ canContinue: Ve,
487
+ canContinueStep: ze,
488
+ canGoBack: We,
489
+ canSubmit: Ie,
490
+ clearSubmitMessage: xe,
491
+ config: E,
492
+ currentStep: J,
493
+ currentStepGroupNode: ge,
494
+ currentStepIndex: q,
495
+ firstErrorFieldId: Be,
496
+ formErrors: I,
497
+ formTitle: Ke,
498
+ formValues: R,
499
+ goToNextStep: $,
500
+ goToPreviousStep: Me,
501
+ handleBack: Ue,
502
+ handleContinue: He,
503
+ handleSubmit: Ne,
504
+ hasSubmitInput: Fe,
505
+ inputNodes: M,
506
+ isFinalStep: Le,
507
+ isFirstStep: _e,
508
+ isLastStep: Y,
509
+ isSubmitting: Re,
510
+ missingRequiredFields: Pe,
511
+ prevFormValuesRef: P,
512
+ setFieldErrors: L,
513
+ setFieldValue: Ae,
514
+ setMultipleFieldValues: je,
515
+ stepLabel: Ge,
516
+ steps: W,
517
+ submitMessage: Ee,
518
+ t: N,
519
+ validateForm: Q,
520
+ visibleNodes: H,
521
+ visibleRootNodes: le
522
+ };
523
+ }, he = /\{\{([\w-]+)}}/g, G = (e) => e == null || e === "", K = (...e) => {
524
+ let t = [];
525
+ for (let n of e) if (n) for (let e of n.matchAll(he)) t.includes(e[1]) || t.push(e[1]);
526
+ return t;
527
+ }, q = (e) => {
528
+ let t = e.data.httpConfig ?? e.data.optionsSource;
529
+ if (!t) return [];
530
+ let n = Object.values(t.queryParams ?? {});
531
+ return K(t.url, t.body, ...n);
532
+ }, J = (e, t, n, r) => q(e).filter((e) => G(t[e])).map((e) => {
533
+ let t = n.find((t) => t.id === e);
534
+ return {
535
+ id: e,
536
+ label: t ? b(t, r) : e
537
+ };
538
+ }), ge = ({ DefaultFormWrapper: t, DefaultInputLabel: n, DefaultInputWrapper: r, DefaultLoadingSkeleton: a, DefaultStep: o, DefaultSubmitButton: s, DefaultSubmitButtonWrapper: c, config: u, defaultInputRenderers: f, defaultUI: p, formErrors: m, formValues: _, inputNodes: v, isSubmitting: y, missingRequiredFields: b, setFieldValue: x }) => {
539
+ let C = O(() => u.components.form || t, [u.components.form, t]), te = O(() => u.components.submitButton || s, [u.components.submitButton, s]), ne = O(() => u.components.submitButtonWrapper || c || re, [u.components.submitButtonWrapper, c]), w = O(() => u.components.inputLabel || n, [u.components.inputLabel, n]), E = O(() => u.components.step || o, [u.components.step, o]);
540
+ return {
541
+ FormWrapper: C,
542
+ LoadingSkeleton: O(() => u.components.loadingSkeleton || a, [u.components.loadingSkeleton, a]),
543
+ renderNode: T(function(t) {
544
+ let { type: n } = t;
545
+ switch (n) {
546
+ case l.input: {
547
+ if (!e(t)) return null;
548
+ let n = (e) => x(p, e), a = t.data, o = a.type || "text", s = u.components.inputs?.[o], c = f[o], l = s || c, p = t.id, h = _[p] === void 0 ? ee(t) : _[p], C = m[p], te = d(a.label, u.language), ne = g(a, u.language), re = d(a.helperText, u.language), T = S(t), E = i(te), D = i(ne), O = i(re);
549
+ return l ? /* @__PURE__ */ j(r, {
550
+ node: t,
551
+ children: /* @__PURE__ */ j(l, {
552
+ field: {
553
+ "aria-invalid": C ? !0 : void 0,
554
+ id: t.id,
555
+ name: T,
556
+ placeholder: D,
557
+ required: a.required,
558
+ value: h
559
+ },
560
+ extra: {
561
+ error: C,
562
+ helperText: O,
563
+ InputLabel: w,
564
+ isSubmitting: y,
565
+ label: E,
566
+ missingDependencies: J(t, _, v, u.language),
567
+ missingRequiredFields: b,
568
+ node: t,
569
+ setValue: n
570
+ }
571
+ }, o)
572
+ }, t.id) : (console.warn("No renderer found for input type:", o), null);
573
+ }
574
+ case l.group: return null;
575
+ case l.ui: {
576
+ if (!h(t)) return null;
577
+ let e = t.data.type || "title", n = u.components.ui?.[e], r = p[e], i = n || r;
578
+ return i ? /* @__PURE__ */ j(i, { node: t }, t.id) : null;
579
+ }
580
+ default: return console.warn("Unknown node type:", n), null;
581
+ }
582
+ }, [
583
+ u,
584
+ _,
585
+ m,
586
+ x,
587
+ y,
588
+ b,
589
+ v,
590
+ f,
591
+ p,
592
+ r
593
+ ]),
594
+ StepComponent: E,
595
+ SubmitButton: te,
596
+ SubmitButtonWrapper: ne
597
+ };
598
+ };
599
+ //#endregion
600
+ export { V as a, M as c, ue as i, ae as l, W as n, L as o, ce as r, R as s, ge as t };
package/package.json CHANGED
@@ -2,7 +2,7 @@
2
2
  "name": "treege",
3
3
  "description": "Powerful form generator",
4
4
  "license": "ISC",
5
- "version": "3.0.0-beta.95",
5
+ "version": "3.0.0-beta.96",
6
6
  "type": "module",
7
7
  "types": "./dist/main.d.ts",
8
8
  "module": "./dist/main.js",