treege 3.0.0-beta.81 → 3.0.0-beta.83
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/{DefaultSubmitButton-Dg9GPvh-.js → DefaultSubmitButton-DpeL3OxC.js} +758 -702
- package/dist/{ThemeContext-BgTIhoK6.js → ThemeContext-BnPOFQC7.js} +82 -74
- package/dist/editor/features/TreegeEditor/inputs/TranslatableInput.d.ts +20 -0
- package/dist/{editor-h20-TVM8.js → editor-CbcW0OVV.js} +1340 -1430
- package/dist/editor.js +2 -2
- package/dist/main.js +6 -6
- package/dist/renderer/features/TreegeViewer/utils/viewerFields.d.ts +78 -0
- package/dist/renderer/features/TreegeViewer/web/TreegeViewer.d.ts +70 -0
- package/dist/renderer/index.d.ts +3 -0
- package/dist/renderer/utils/file.d.ts +15 -2
- package/dist/renderer-KRzuU6OD.js +411 -0
- package/dist/renderer-native.js +946 -946
- package/dist/renderer.js +5 -5
- package/dist/shared/utils/normalizeLabel.d.ts +2 -1
- package/dist/shared/utils/translations.d.ts +21 -1
- package/dist/useRenderNode-DQ5lvXuj.js +527 -0
- package/package.json +1 -1
- package/dist/renderer-DI6nF4St.js +0 -256
- package/dist/useRenderNode-B1sfwbia.js +0 -527
package/dist/renderer.js
CHANGED
|
@@ -1,5 +1,5 @@
|
|
|
1
|
-
import {
|
|
2
|
-
import { C as
|
|
3
|
-
import { a as
|
|
4
|
-
import { i as
|
|
5
|
-
export {
|
|
1
|
+
import { G as e, I as t, L 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-BnPOFQC7.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-DpeL3OxC.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-DQ5lvXuj.js";
|
|
4
|
+
import { a as K, i as q, n as J, o as Y, r as X, s as Z, t as Q } from "./renderer-KRzuU6OD.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, K as Divider, g as ThemeProvider, Y as Title, q as TreegeRenderer, z as TreegeRendererProvider, Q as TreegeViewer, m as applyReferenceTransformation, l as buildInitialFormValues, i as calculateReferenceFieldUpdates, p as checkFormFieldHasValue, h as convertFormValuesToNamedFormat, j as defaultInputRenderers, Z 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, e as getTranslatedText, J as getViewerFields, o as isFieldEmpty, X as isImageFile, _ as isRemoteFileData, R as isStartNode, v as normalizeSerializableFiles, u as resolveNodeDefaultValue, t as sanitize, n as sanitizeHttpResponse, a as serializableToFile, f as useTheme, H as useTreegeRenderer, V as useTreegeRendererConfig };
|
|
@@ -16,6 +16,7 @@ import { Translatable } from '../types/translate';
|
|
|
16
16
|
export declare const normalizeLabel: (text: string) => string;
|
|
17
17
|
/**
|
|
18
18
|
* Applies {@link normalizeLabel} to every language entry of a `Translatable`
|
|
19
|
-
* label, preserving its shape.
|
|
19
|
+
* label, preserving its shape. Labels are always the object form here — plain
|
|
20
|
+
* strings are coerced upstream by `normalizeFlowLabels` on ingestion.
|
|
20
21
|
*/
|
|
21
22
|
export declare const normalizeTranslatableLabel: (label: Translatable) => Translatable;
|
|
@@ -21,7 +21,27 @@ export type TranslationKey = DotNotationKeys<typeof en>;
|
|
|
21
21
|
* @param language - Optional preferred language (defaults to 'en')
|
|
22
22
|
* @returns The translated string or empty string if none available
|
|
23
23
|
*/
|
|
24
|
-
export declare const getTranslatedText: (text?: Translatable
|
|
24
|
+
export declare const getTranslatedText: (text?: Translatable, language?: string) => string;
|
|
25
|
+
/**
|
|
26
|
+
* Reads the value of a translatable field for a given language while tolerating a
|
|
27
|
+
* value for a language. Returns "" when the value or the language entry is absent.
|
|
28
|
+
*
|
|
29
|
+
* Use this for editor inputs instead of `value?.[language]` so reads/writes stay
|
|
30
|
+
* consistent with {@link setTranslatableValue}.
|
|
31
|
+
*/
|
|
32
|
+
export declare const getTranslatableValue: (value: Translatable | undefined, language: string) => string;
|
|
33
|
+
/**
|
|
34
|
+
* Sets `language` to `next` on a translatable field and returns a NEW Translatable,
|
|
35
|
+
* preserving the other language entries. Always use this when writing a
|
|
36
|
+
* translatable field from the editor rather than spreading the previous value
|
|
37
|
+
* inline.
|
|
38
|
+
*
|
|
39
|
+
* The `typeof === "object"` guard is purely defensive: the type system guarantees
|
|
40
|
+
* an object, but should a stray non-object (e.g. unsupported legacy string data)
|
|
41
|
+
* reach this at runtime, it is dropped rather than spread into indexed character
|
|
42
|
+
* keys (`"Hi"` → `{ "0": "H", "1": "i" }`).
|
|
43
|
+
*/
|
|
44
|
+
export declare const setTranslatableValue: (value: Translatable | undefined, language: string, next: string) => Translatable;
|
|
25
45
|
/**
|
|
26
46
|
* Get static translations for a specific language
|
|
27
47
|
* Falls back to English if language not found
|
|
@@ -0,0 +1,527 @@
|
|
|
1
|
+
import { A as e, B as t, C as n, F as r, G as i, I as a, J as o, M as s, N as c, O as l, V as u, Y as d, a as f, c as p, d as m, f as h, i as g, j as _, k as v, l as y, o as b, p as x, q as S, s as C, u as ee } from "./ThemeContext-BnPOFQC7.js";
|
|
2
|
+
import { Fragment as w, createContext as T, useCallback as E, useContext as D, useEffect as O, useMemo as k, useRef as A, useState as j } from "react";
|
|
3
|
+
import { jsx as M } from "react/jsx-runtime";
|
|
4
|
+
//#region src/renderer/context/TreegeRendererProvider.tsx
|
|
5
|
+
var N = T(void 0), te = () => D(N), P = ({ children: e, ...t }) => /* @__PURE__ */ M(N.Provider, {
|
|
6
|
+
value: t,
|
|
7
|
+
children: e
|
|
8
|
+
}), F = async (t, r, i, a, o) => {
|
|
9
|
+
if (!t.url || t.url.trim() === "") return {
|
|
10
|
+
error: "No URL configured for submission",
|
|
11
|
+
success: !1
|
|
12
|
+
};
|
|
13
|
+
let u = c(_(t.url, r, { encode: !0 }), o);
|
|
14
|
+
if (!u || u.trim() === "") return {
|
|
15
|
+
error: "Invalid URL after template replacement",
|
|
16
|
+
success: !1
|
|
17
|
+
};
|
|
18
|
+
let d = t.payloadTemplate ? n(t.payloadTemplate, r, i) : void 0, f = await l({
|
|
19
|
+
body: d === void 0 ? t.sendAllFormValues ? JSON.stringify(C(r, i)) : void 0 : JSON.stringify(d),
|
|
20
|
+
headers: v(s(a, r), s(t.headers, r)),
|
|
21
|
+
method: t.method || "POST",
|
|
22
|
+
queryParams: s(t.queryParams, r),
|
|
23
|
+
url: u
|
|
24
|
+
});
|
|
25
|
+
if (!f.success) return {
|
|
26
|
+
data: f.data,
|
|
27
|
+
error: f.error,
|
|
28
|
+
success: !1
|
|
29
|
+
};
|
|
30
|
+
let p = t.redirectUrl ? (() => {
|
|
31
|
+
let n = e(t.redirectUrl, f.data);
|
|
32
|
+
return n && n.trim() !== "" ? n : void 0;
|
|
33
|
+
})() : void 0;
|
|
34
|
+
return {
|
|
35
|
+
data: f.data,
|
|
36
|
+
redirectUrl: p,
|
|
37
|
+
success: !0
|
|
38
|
+
};
|
|
39
|
+
}, I = (e) => {
|
|
40
|
+
e && (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);
|
|
41
|
+
}, ne = (e, t, n, r, a, s) => {
|
|
42
|
+
let [c, l] = j(!1), [u, d] = j(null), f = k(() => {
|
|
43
|
+
let t = e.find((e) => o(e) && e.data?.type === "submit");
|
|
44
|
+
return t && o(t) ? t : null;
|
|
45
|
+
}, [e]), p = E(async (e) => {
|
|
46
|
+
if (!f?.data?.submitConfig) return null;
|
|
47
|
+
let o = f.data.submitConfig;
|
|
48
|
+
if (!o.url || o.url.trim() === "") return null;
|
|
49
|
+
d(null), o.showLoading !== !1 && l(!0);
|
|
50
|
+
try {
|
|
51
|
+
let c = await F(o, t, r, a, s);
|
|
52
|
+
if (c.success) {
|
|
53
|
+
let t = i(o.successMessage, n);
|
|
54
|
+
if (t && d({
|
|
55
|
+
message: t,
|
|
56
|
+
type: "success"
|
|
57
|
+
}), e && e(c.data), c.redirectUrl) {
|
|
58
|
+
let e = c.redirectUrl;
|
|
59
|
+
setTimeout(() => I(e), 1e3);
|
|
60
|
+
}
|
|
61
|
+
} else d({
|
|
62
|
+
message: i(o.errorMessage, n) || c.error || "An error occurred during submission",
|
|
63
|
+
type: "error"
|
|
64
|
+
});
|
|
65
|
+
return c;
|
|
66
|
+
} catch (e) {
|
|
67
|
+
let t = i(o.errorMessage, n) || (e instanceof Error ? e.message : "An unexpected error occurred");
|
|
68
|
+
return d({
|
|
69
|
+
message: t,
|
|
70
|
+
type: "error"
|
|
71
|
+
}), {
|
|
72
|
+
error: t,
|
|
73
|
+
success: !1
|
|
74
|
+
};
|
|
75
|
+
} finally {
|
|
76
|
+
l(!1);
|
|
77
|
+
}
|
|
78
|
+
}, [
|
|
79
|
+
f,
|
|
80
|
+
t,
|
|
81
|
+
n,
|
|
82
|
+
r,
|
|
83
|
+
a,
|
|
84
|
+
s
|
|
85
|
+
]);
|
|
86
|
+
return {
|
|
87
|
+
clearSubmitMessage: E(() => {
|
|
88
|
+
d(null);
|
|
89
|
+
}, []),
|
|
90
|
+
handleSubmitWithConfig: p,
|
|
91
|
+
hasSubmitConfig: !!f?.data?.submitConfig,
|
|
92
|
+
isSubmitting: c,
|
|
93
|
+
submitButtonNode: f,
|
|
94
|
+
submitMessage: u
|
|
95
|
+
};
|
|
96
|
+
}, L = (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), R = (e, t, n) => {
|
|
97
|
+
let r = L(e), i = L(t);
|
|
98
|
+
if (r === null || i === null) switch (n) {
|
|
99
|
+
case "===": return r === i;
|
|
100
|
+
case "!==": return r !== i;
|
|
101
|
+
default: return !1;
|
|
102
|
+
}
|
|
103
|
+
if ([
|
|
104
|
+
">",
|
|
105
|
+
"<",
|
|
106
|
+
">=",
|
|
107
|
+
"<="
|
|
108
|
+
].includes(n)) {
|
|
109
|
+
let e = Number(r), t = Number(i);
|
|
110
|
+
if (!(Number.isNaN(e) || Number.isNaN(t))) switch (n) {
|
|
111
|
+
case ">": return e > t;
|
|
112
|
+
case "<": return e < t;
|
|
113
|
+
case ">=": return e >= t;
|
|
114
|
+
case "<=": return e <= t;
|
|
115
|
+
default: return !1;
|
|
116
|
+
}
|
|
117
|
+
return !1;
|
|
118
|
+
}
|
|
119
|
+
switch (n) {
|
|
120
|
+
case "===": {
|
|
121
|
+
let e = Number(r), t = Number(i);
|
|
122
|
+
return Number.isNaN(e) || Number.isNaN(t) ? String(r) === String(i) : e === t;
|
|
123
|
+
}
|
|
124
|
+
case "!==": {
|
|
125
|
+
let e = Number(r), t = Number(i);
|
|
126
|
+
return Number.isNaN(e) || Number.isNaN(t) ? String(r) !== String(i) : e !== t;
|
|
127
|
+
}
|
|
128
|
+
default: return !1;
|
|
129
|
+
}
|
|
130
|
+
}, z = (e, t, n) => {
|
|
131
|
+
let { field: r, operator: i, value: a } = e;
|
|
132
|
+
if (!(r && i) || a === void 0) return !0;
|
|
133
|
+
let s = t[r], c = s === void 0 && n ? n.get(r) : void 0, l = c && o(c) ? t[c.id] : s;
|
|
134
|
+
return Array.isArray(l) ? i === "===" ? l.some((e) => R(e, a, "===")) || R(l, a, "===") : i === "!==" ? l.every((e) => R(e, a, "!==")) && R(l, a, "!==") : l.some((e) => R(e, a, i)) : R(l, a, i);
|
|
135
|
+
}, B = (e, t, n) => {
|
|
136
|
+
if (!e || e.length === 0) return !0;
|
|
137
|
+
if (e.length === 1) return z(e[0], t, n);
|
|
138
|
+
let r = z(e[0], t, n);
|
|
139
|
+
for (let i = 1; i < e.length; i += 1) {
|
|
140
|
+
let a = e[i], o = z(a, t, n), s = e[i - 1].logicalOperator || u.AND;
|
|
141
|
+
if (s === u.AND) {
|
|
142
|
+
if (r &&= o, !r) return !1;
|
|
143
|
+
} else if (s === u.OR && (r ||= o, r)) return !0;
|
|
144
|
+
}
|
|
145
|
+
return r;
|
|
146
|
+
}, V = (e) => {
|
|
147
|
+
let t = /* @__PURE__ */ new Map();
|
|
148
|
+
return e.forEach((e) => {
|
|
149
|
+
let n = t.get(e.source);
|
|
150
|
+
n ? n.push(e) : t.set(e.source, [e]);
|
|
151
|
+
}), t;
|
|
152
|
+
}, re = (e, t, n) => {
|
|
153
|
+
let r = [], i = [], a = [];
|
|
154
|
+
e.forEach((e) => {
|
|
155
|
+
let t = e.data?.isFallback, n = e.data?.conditions?.length;
|
|
156
|
+
t ? a.push(e) : n ? i.push(e) : r.push(e);
|
|
157
|
+
});
|
|
158
|
+
let s = [...r];
|
|
159
|
+
if (i.length === 0) return a.length > 0 && s.length === 0 && s.push(...a), {
|
|
160
|
+
edgesToFollow: s,
|
|
161
|
+
waitingForInput: !1
|
|
162
|
+
};
|
|
163
|
+
if (!i.every((e) => {
|
|
164
|
+
let r = e.data?.conditions;
|
|
165
|
+
return r ? r.every((e) => {
|
|
166
|
+
if (!e.field) return !0;
|
|
167
|
+
let r = n.get(e.field);
|
|
168
|
+
return b(o(r) ? r.id : e.field, t);
|
|
169
|
+
}) : !1;
|
|
170
|
+
})) return a.length > 0 && s.push(...a), {
|
|
171
|
+
edgesToFollow: s,
|
|
172
|
+
waitingForInput: s.length === 0
|
|
173
|
+
};
|
|
174
|
+
let c = i.filter((e) => B(e.data?.conditions, t, n));
|
|
175
|
+
return c.length > 0 ? (s.push(...c), {
|
|
176
|
+
edgesToFollow: s,
|
|
177
|
+
waitingForInput: !1
|
|
178
|
+
}) : (s.push(...a), {
|
|
179
|
+
edgesToFollow: s,
|
|
180
|
+
waitingForInput: !1
|
|
181
|
+
});
|
|
182
|
+
}, H = (e, t) => !t.some((t) => t.target === e), U = (e, t) => {
|
|
183
|
+
let n = e.filter((e) => H(e.id, t));
|
|
184
|
+
return n.find(o) || n[0];
|
|
185
|
+
}, W = (e, t, n = /* @__PURE__ */ new Set()) => !e || n.has(e) ? [] : (n.add(e), [e, ...W(t.get(e)?.parentId, t, n)]), G = (e, t, n, r) => {
|
|
186
|
+
e.forEach((e) => {
|
|
187
|
+
let i = n.get(e);
|
|
188
|
+
W(r.get(e)?.parentId, r).forEach((e) => {
|
|
189
|
+
t.add(e), !n.has(e) && i !== void 0 && n.set(e, i);
|
|
190
|
+
});
|
|
191
|
+
});
|
|
192
|
+
}, ie = (e, t, n) => {
|
|
193
|
+
let r = U(e, t);
|
|
194
|
+
if (!r) return {
|
|
195
|
+
endOfPathReached: !0,
|
|
196
|
+
visibleNodeIds: /* @__PURE__ */ new Set(),
|
|
197
|
+
visibleNodes: [],
|
|
198
|
+
visibleRootNodes: []
|
|
199
|
+
};
|
|
200
|
+
let i = new Map(e.map((e) => [e.id, e])), a = V(t), o = [], s = /* @__PURE__ */ new Set(), c = /* @__PURE__ */ new Set(), l = !1, u = (e) => {
|
|
201
|
+
if (c.has(e)) return;
|
|
202
|
+
c.add(e);
|
|
203
|
+
let t = i.get(e);
|
|
204
|
+
if (!t) return;
|
|
205
|
+
s.add(e), o.push(t);
|
|
206
|
+
let { edgesToFollow: r, waitingForInput: d } = re(a.get(e) || [], n, i);
|
|
207
|
+
if (d) {
|
|
208
|
+
l = !0;
|
|
209
|
+
return;
|
|
210
|
+
}
|
|
211
|
+
r.forEach((e) => {
|
|
212
|
+
u(e.target);
|
|
213
|
+
});
|
|
214
|
+
};
|
|
215
|
+
u(r.id);
|
|
216
|
+
let d = new Map(o.map((e, t) => [e.id, t])), f = new Set(s);
|
|
217
|
+
G(s, f, d, i);
|
|
218
|
+
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)));
|
|
219
|
+
return {
|
|
220
|
+
endOfPathReached: !l,
|
|
221
|
+
visibleNodeIds: f,
|
|
222
|
+
visibleNodes: p,
|
|
223
|
+
visibleRootNodes: m
|
|
224
|
+
};
|
|
225
|
+
}, ae = (e) => e.filter((e) => !S(e)).reduce((e, t) => {
|
|
226
|
+
let n = t.parentId ?? null, r = e.at(-1);
|
|
227
|
+
return r && r.groupId === n ? [...e.slice(0, -1), {
|
|
228
|
+
...r,
|
|
229
|
+
nodes: [...r.nodes, t]
|
|
230
|
+
}] : [...e, {
|
|
231
|
+
groupId: n,
|
|
232
|
+
nodes: [t]
|
|
233
|
+
}];
|
|
234
|
+
}, []), K = (e) => {
|
|
235
|
+
if (typeof e != "object" || !e) return JSON.stringify(e) ?? "null";
|
|
236
|
+
if (Array.isArray(e)) return `[${e.map(K).join(",")}]`;
|
|
237
|
+
let t = e;
|
|
238
|
+
return `{${Object.keys(t).sort().map((e) => `${JSON.stringify(e)}:${K(t[e])}`).join(",")}}`;
|
|
239
|
+
}, oe = ({ baseUrl: e, components: t, flow: i, googleApiKey: a, headers: s, language: c, onChange: l, onSubmit: u, showPoweredBy: d, theme: m, validate: h, validationMode: _, initialValues: b = {} }) => {
|
|
240
|
+
let x = te(), w = k(() => ({
|
|
241
|
+
baseUrl: e ?? x?.baseUrl,
|
|
242
|
+
components: {
|
|
243
|
+
form: t?.form ?? x?.components?.form,
|
|
244
|
+
inputs: {
|
|
245
|
+
...x?.components?.inputs,
|
|
246
|
+
...t?.inputs
|
|
247
|
+
},
|
|
248
|
+
loadingSkeleton: t?.loadingSkeleton ?? x?.components?.loadingSkeleton,
|
|
249
|
+
step: t?.step ?? x?.components?.step,
|
|
250
|
+
submitButton: t?.submitButton ?? x?.components?.submitButton,
|
|
251
|
+
submitButtonWrapper: t?.submitButtonWrapper ?? x?.components?.submitButtonWrapper,
|
|
252
|
+
ui: {
|
|
253
|
+
...x?.components?.ui,
|
|
254
|
+
...t?.ui
|
|
255
|
+
}
|
|
256
|
+
},
|
|
257
|
+
googleApiKey: a ?? x?.googleApiKey,
|
|
258
|
+
headers: v(x?.headers, s),
|
|
259
|
+
language: c ?? x?.language ?? "en",
|
|
260
|
+
showPoweredBy: d ?? x?.showPoweredBy ?? !0,
|
|
261
|
+
theme: m ?? x?.theme ?? "dark",
|
|
262
|
+
validationMode: _ ?? x?.validationMode ?? "onSubmit"
|
|
263
|
+
}), [
|
|
264
|
+
e,
|
|
265
|
+
t,
|
|
266
|
+
x,
|
|
267
|
+
a,
|
|
268
|
+
s,
|
|
269
|
+
c,
|
|
270
|
+
d,
|
|
271
|
+
m,
|
|
272
|
+
_
|
|
273
|
+
]), T = k(() => i?.nodes ?? [], [i]), D = k(() => i?.edges ?? [], [i]), M = k(() => ee(T), [T]), N = r(w.language), P = A({}), F = A(null), [I, L] = j({}), [R, z] = j(() => g(b, M)), B = k(() => K(b), [b]), V = A(B), { endOfPathReached: re, visibleNodes: H, visibleRootNodes: U } = k(() => ie(T, D, R), [
|
|
274
|
+
T,
|
|
275
|
+
D,
|
|
276
|
+
R
|
|
277
|
+
]), W = k(() => ee(H), [H]), G = k(() => ae(H), [H]), oe = k(() => {
|
|
278
|
+
let e = /* @__PURE__ */ new Map();
|
|
279
|
+
return T.forEach((t) => {
|
|
280
|
+
S(t) && e.set(t.id, t);
|
|
281
|
+
}), e;
|
|
282
|
+
}, [T]), [q, J] = j(0), Y = G.length === 0 ? 0 : Math.min(q, G.length - 1), X = G[Y], se = X?.groupId ? oe.get(X.groupId) : void 0, ce = Y === 0, le = G.length === 0 || Y >= G.length - 1, { clearSubmitMessage: ue, handleSubmitWithConfig: de, hasSubmitConfig: fe, isSubmitting: pe, submitButtonNode: me, submitMessage: he } = ne(H, R, w.language, W, w.headers, w.baseUrl), ge = A(l), _e = A(h), Z = k(() => C(R, W), [R, W]), Q = k(() => {
|
|
283
|
+
let e = me?.data?.submitConfig?.payloadTemplate;
|
|
284
|
+
return e ? n(e, R, W) ?? Z : Z;
|
|
285
|
+
}, [
|
|
286
|
+
me,
|
|
287
|
+
R,
|
|
288
|
+
W,
|
|
289
|
+
Z
|
|
290
|
+
]), ve = E((e, t) => {
|
|
291
|
+
z((n) => ({
|
|
292
|
+
...n,
|
|
293
|
+
[e]: t
|
|
294
|
+
})), L((t) => {
|
|
295
|
+
let n = { ...t };
|
|
296
|
+
return delete n[e], n;
|
|
297
|
+
});
|
|
298
|
+
}, []), ye = E((e) => {
|
|
299
|
+
Object.keys(e).length !== 0 && (z((t) => ({
|
|
300
|
+
...t,
|
|
301
|
+
...e
|
|
302
|
+
})), L((t) => {
|
|
303
|
+
let n = { ...t };
|
|
304
|
+
return Object.keys(e).forEach((e) => {
|
|
305
|
+
delete n[e];
|
|
306
|
+
}), n;
|
|
307
|
+
}));
|
|
308
|
+
}, []), $ = E((e) => {
|
|
309
|
+
let t = {};
|
|
310
|
+
H.forEach((e) => {
|
|
311
|
+
if (o(e)) {
|
|
312
|
+
let n = e.id, r = R[n];
|
|
313
|
+
if (e.data.required && p(r)) {
|
|
314
|
+
t[n] = N(e.data.errorMessage) || N("validation.required");
|
|
315
|
+
return;
|
|
316
|
+
}
|
|
317
|
+
if (!p(r) && e.data.pattern) try {
|
|
318
|
+
new RegExp(e.data.pattern).test(String(r)) || (t[n] = N(e.data.errorMessage) || N("validation.invalidFormat"));
|
|
319
|
+
} catch (e) {
|
|
320
|
+
console.error(`Invalid pattern for field ${n}:`, e);
|
|
321
|
+
}
|
|
322
|
+
}
|
|
323
|
+
});
|
|
324
|
+
let n = e ? e(R, H) : {}, r = {
|
|
325
|
+
...t,
|
|
326
|
+
...n
|
|
327
|
+
};
|
|
328
|
+
return L(r), {
|
|
329
|
+
errors: r,
|
|
330
|
+
hasCustomErrors: Object.keys(n).length > 0,
|
|
331
|
+
isValid: Object.keys(r).length === 0
|
|
332
|
+
};
|
|
333
|
+
}, [
|
|
334
|
+
H,
|
|
335
|
+
R,
|
|
336
|
+
N
|
|
337
|
+
]), be = E(() => {
|
|
338
|
+
J((e) => e >= G.length - 1 ? e : e + 1);
|
|
339
|
+
}, [G.length]), xe = E(() => {
|
|
340
|
+
J((e) => Math.max(0, e - 1));
|
|
341
|
+
}, []), Se = E(async () => {
|
|
342
|
+
let { isValid: e } = $(_e.current);
|
|
343
|
+
if (!e) return !1;
|
|
344
|
+
if (fe) {
|
|
345
|
+
let e = await de((e) => {
|
|
346
|
+
u && u(Q, { httpResponse: e });
|
|
347
|
+
});
|
|
348
|
+
if (e === null) return u?.(Q), !0;
|
|
349
|
+
if (!e.success) return !0;
|
|
350
|
+
} else u && u(Q);
|
|
351
|
+
return !0;
|
|
352
|
+
}, [
|
|
353
|
+
$,
|
|
354
|
+
fe,
|
|
355
|
+
de,
|
|
356
|
+
u,
|
|
357
|
+
Q
|
|
358
|
+
]), Ce = k(() => {
|
|
359
|
+
if (!X) return [];
|
|
360
|
+
let e = [];
|
|
361
|
+
return X.nodes.forEach((t) => {
|
|
362
|
+
o(t) && t.data.type !== "submit" && t.data.required && p(R[t.id]) && e.push(N(t.data.label) || t.id);
|
|
363
|
+
}), e;
|
|
364
|
+
}, [
|
|
365
|
+
X,
|
|
366
|
+
R,
|
|
367
|
+
N
|
|
368
|
+
]), we = k(() => H.some((e) => o(e) && e.data.type === "submit"), [H]), Te = k(() => X ? X.nodes.every((e) => !o(e) || !e.data.required || e.data.type === "submit" ? !0 : !p(R[e.id])) : !1, [X, R]), Ee = k(() => {
|
|
369
|
+
let e = Object.keys(I);
|
|
370
|
+
return e.length > 0 ? e[0] : void 0;
|
|
371
|
+
}, [I]);
|
|
372
|
+
return O(() => {
|
|
373
|
+
if (G.length === 0) {
|
|
374
|
+
q !== 0 && J(0);
|
|
375
|
+
return;
|
|
376
|
+
}
|
|
377
|
+
q > G.length - 1 && J(G.length - 1);
|
|
378
|
+
}, [G.length, q]), O(() => {
|
|
379
|
+
ge.current = l;
|
|
380
|
+
}, [l]), O(() => {
|
|
381
|
+
_e.current = h;
|
|
382
|
+
}, [h]), O(() => {
|
|
383
|
+
ge.current?.(Z);
|
|
384
|
+
}, [Z]), O(() => {
|
|
385
|
+
w.validationMode === "onChange" && $(_e.current);
|
|
386
|
+
}, [w.validationMode, $]), O(() => {
|
|
387
|
+
let e = f(M, R, P.current);
|
|
388
|
+
Object.keys(e).length > 0 && ye(e), P.current = R;
|
|
389
|
+
}, [
|
|
390
|
+
R,
|
|
391
|
+
M,
|
|
392
|
+
ye
|
|
393
|
+
]), O(() => {
|
|
394
|
+
let e = F.current, t = new Set(W.map((e) => e.id));
|
|
395
|
+
if (F.current = t, !e) return;
|
|
396
|
+
let n = [...e].filter((e) => !t.has(e)), r = {};
|
|
397
|
+
W.forEach((t) => {
|
|
398
|
+
if (e.has(t.id) || R[t.id] !== void 0) return;
|
|
399
|
+
let n = y(t, R);
|
|
400
|
+
n !== void 0 && (r[t.id] = n);
|
|
401
|
+
}), !(n.length === 0 && Object.keys(r).length === 0) && (z((e) => {
|
|
402
|
+
let t = {
|
|
403
|
+
...e,
|
|
404
|
+
...r
|
|
405
|
+
};
|
|
406
|
+
return n.forEach((e) => {
|
|
407
|
+
delete t[e];
|
|
408
|
+
}), t;
|
|
409
|
+
}), n.length > 0 && L((e) => {
|
|
410
|
+
let t = !1, r = { ...e };
|
|
411
|
+
return n.forEach((e) => {
|
|
412
|
+
e in r && (delete r[e], t = !0);
|
|
413
|
+
}), t ? r : e;
|
|
414
|
+
}));
|
|
415
|
+
}, [W, R]), O(() => {
|
|
416
|
+
V.current !== B && (V.current = B, z(g(b, M)), L({}), F.current = null);
|
|
417
|
+
}, [
|
|
418
|
+
B,
|
|
419
|
+
b,
|
|
420
|
+
M
|
|
421
|
+
]), {
|
|
422
|
+
canContinueStep: Te,
|
|
423
|
+
canSubmit: (we || re) && T.length > 0,
|
|
424
|
+
clearSubmitMessage: ue,
|
|
425
|
+
config: w,
|
|
426
|
+
currentStep: X,
|
|
427
|
+
currentStepGroupNode: se,
|
|
428
|
+
currentStepIndex: Y,
|
|
429
|
+
firstErrorFieldId: Ee,
|
|
430
|
+
formErrors: I,
|
|
431
|
+
formValues: R,
|
|
432
|
+
goToNextStep: be,
|
|
433
|
+
goToPreviousStep: xe,
|
|
434
|
+
handleSubmit: Se,
|
|
435
|
+
hasSubmitInput: we,
|
|
436
|
+
inputNodes: M,
|
|
437
|
+
isFirstStep: ce,
|
|
438
|
+
isLastStep: le,
|
|
439
|
+
isSubmitting: pe,
|
|
440
|
+
missingRequiredFields: Ce,
|
|
441
|
+
prevFormValuesRef: P,
|
|
442
|
+
setFieldErrors: L,
|
|
443
|
+
setFieldValue: ve,
|
|
444
|
+
setMultipleFieldValues: ye,
|
|
445
|
+
steps: G,
|
|
446
|
+
submitMessage: he,
|
|
447
|
+
t: N,
|
|
448
|
+
validateForm: $,
|
|
449
|
+
visibleNodes: H,
|
|
450
|
+
visibleRootNodes: U
|
|
451
|
+
};
|
|
452
|
+
}, q = /\{\{([\w-]+)}}/g, J = (e) => e == null || e === "", Y = (...e) => {
|
|
453
|
+
let t = [];
|
|
454
|
+
for (let n of e) if (n) for (let e of n.matchAll(q)) t.includes(e[1]) || t.push(e[1]);
|
|
455
|
+
return t;
|
|
456
|
+
}, X = (e) => {
|
|
457
|
+
let t = e.data.httpConfig ?? e.data.optionsSource;
|
|
458
|
+
if (!t) return [];
|
|
459
|
+
let n = Object.values(t.queryParams ?? {});
|
|
460
|
+
return Y(t.url, t.body, ...n);
|
|
461
|
+
}, se = (e, t, n, r) => X(e).filter((e) => J(t[e])).map((e) => {
|
|
462
|
+
let t = n.find((t) => t.id === e);
|
|
463
|
+
return {
|
|
464
|
+
id: e,
|
|
465
|
+
label: t ? x(t, r) : e
|
|
466
|
+
};
|
|
467
|
+
}), ce = ({ DefaultFormWrapper: e, DefaultInputLabel: n, DefaultInputWrapper: r, DefaultSubmitButton: s, DefaultSubmitButtonWrapper: c, config: l, defaultInputRenderers: u, defaultUI: f, formErrors: p, formValues: g, inputNodes: _, isSubmitting: v, missingRequiredFields: y, setFieldValue: b }) => {
|
|
468
|
+
let x = k(() => l.components.form || e, [l.components.form, e]), S = k(() => l.components.submitButton || s, [l.components.submitButton, s]), C = k(() => l.components.submitButtonWrapper || c || w, [l.components.submitButtonWrapper, c]), ee = k(() => l.components.inputLabel || n, [l.components.inputLabel, n]);
|
|
469
|
+
return {
|
|
470
|
+
FormWrapper: x,
|
|
471
|
+
renderNode: E(function(e) {
|
|
472
|
+
let { type: n } = e;
|
|
473
|
+
switch (n) {
|
|
474
|
+
case t.input: {
|
|
475
|
+
if (!o(e)) return null;
|
|
476
|
+
let t = e.data, n = t.type || "text", s = l.components.inputs?.[n], c = u[n], d = s || c, f = e.id, x = (e) => b(f, e), S = g[f], C = p[f], w = i(t.label, l.language), T = m(t, l.language), E = i(t.helperText, l.language), D = h(e), O = a(w), k = a(T), A = a(E);
|
|
477
|
+
return d ? /* @__PURE__ */ M(r, {
|
|
478
|
+
node: e,
|
|
479
|
+
children: /* @__PURE__ */ M(d, {
|
|
480
|
+
field: {
|
|
481
|
+
"aria-invalid": C ? !0 : void 0,
|
|
482
|
+
id: e.id,
|
|
483
|
+
name: D,
|
|
484
|
+
placeholder: k,
|
|
485
|
+
required: t.required,
|
|
486
|
+
value: S
|
|
487
|
+
},
|
|
488
|
+
extra: {
|
|
489
|
+
error: C,
|
|
490
|
+
helperText: A,
|
|
491
|
+
InputLabel: ee,
|
|
492
|
+
isSubmitting: v,
|
|
493
|
+
label: O,
|
|
494
|
+
missingDependencies: se(e, g, _, l.language),
|
|
495
|
+
missingRequiredFields: y,
|
|
496
|
+
node: e,
|
|
497
|
+
setValue: x
|
|
498
|
+
}
|
|
499
|
+
}, n)
|
|
500
|
+
}, e.id) : (console.warn("No renderer found for input type:", n), null);
|
|
501
|
+
}
|
|
502
|
+
case t.group: return null;
|
|
503
|
+
case t.ui: {
|
|
504
|
+
if (!d(e)) return null;
|
|
505
|
+
let t = e.data.type || "title", n = l.components.ui?.[t], r = f[t], i = n || r;
|
|
506
|
+
return i ? /* @__PURE__ */ M(i, { node: e }, e.id) : null;
|
|
507
|
+
}
|
|
508
|
+
default: return console.warn("Unknown node type:", n), null;
|
|
509
|
+
}
|
|
510
|
+
}, [
|
|
511
|
+
l,
|
|
512
|
+
g,
|
|
513
|
+
p,
|
|
514
|
+
b,
|
|
515
|
+
v,
|
|
516
|
+
y,
|
|
517
|
+
_,
|
|
518
|
+
u,
|
|
519
|
+
f,
|
|
520
|
+
r
|
|
521
|
+
]),
|
|
522
|
+
SubmitButton: S,
|
|
523
|
+
SubmitButtonWrapper: C
|
|
524
|
+
};
|
|
525
|
+
};
|
|
526
|
+
//#endregion
|
|
527
|
+
export { H as a, P as c, ie as i, te as l, oe as n, z as o, U as r, B as s, ce as t };
|