treege 3.0.0-beta.94 → 3.0.0-beta.95

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