@trungkhai/dynamic-form 0.1.3 → 0.1.5

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/index.es.js CHANGED
@@ -1,46 +1,46 @@
1
- import { jsx as f, jsxs as Be, Fragment as x } from "react/jsx-runtime";
2
- import { Select as Fe, Form as U, Upload as ke, Button as Ee, DatePicker as Ge, Checkbox as Ie, Radio as We, InputNumber as Ke, Input as ve, Row as $e, Col as ze, App as He, Flex as ie, Spin as ae } from "antd";
3
- import { createContext as Ye, useContext as Re, memo as C, useState as P, useMemo as R, useEffect as V, useCallback as T, useRef as B, forwardRef as Ne, useImperativeHandle as Je } from "react";
4
- import Z from "dayjs";
5
- import { FileImageOutlined as Qe, UploadOutlined as Xe } from "@ant-design/icons";
6
- const oe = Ye(
1
+ import { jsx as l, jsxs as ae, Fragment as V } from "react/jsx-runtime";
2
+ import { Select as Ie, Form as X, Upload as qe, Button as Ae, Alert as N, Collapse as at, DatePicker as ct, Checkbox as lt, Radio as dt, InputNumber as ut, Input as Le, Row as ft, Col as mt, App as pt, Flex as Se, Spin as be, Table as yt } from "antd";
3
+ import { createContext as ht, useContext as Be, memo as Q, useState as L, useMemo as C, useEffect as j, useRef as I, useCallback as D, forwardRef as _t, useImperativeHandle as bt } from "react";
4
+ import ge from "dayjs";
5
+ import { FileImageOutlined as gt, UploadOutlined as wt, DeleteOutlined as vt, PlusOutlined as At } from "@ant-design/icons";
6
+ const ke = ht(
7
7
  null
8
8
  );
9
- function M() {
10
- const e = Re(oe);
9
+ function U() {
10
+ const e = Be(ke);
11
11
  if (!e)
12
12
  throw new Error(
13
13
  "useDynamicFormContext must be used within DynamicFormProvider"
14
14
  );
15
15
  return e;
16
16
  }
17
- function en() {
18
- return Re(oe);
17
+ function qn() {
18
+ return Be(ke);
19
19
  }
20
- function Ze(e, t = []) {
20
+ function St(e, t = []) {
21
21
  for (const r of t) {
22
22
  if (typeof r == "function")
23
23
  continue;
24
- const { match: i, render: a } = r;
24
+ const { match: i, render: s } = r;
25
25
  if (typeof i == "string") {
26
26
  if (i === e.field?.type?.code || i === e.code)
27
- return a;
27
+ return s;
28
28
  } else if (i(e))
29
- return a;
29
+ return s;
30
30
  }
31
31
  const n = e.field?.type?.code;
32
32
  for (const r of t)
33
33
  ;
34
34
  }
35
- function et(e, t = [], n = {}) {
36
- return Ze(e, t) ?? n[e.code] ?? n[e.field?.type?.code ?? ""];
35
+ function kt(e, t = [], n = {}) {
36
+ return St(e, t) ?? n[e.code] ?? n[e.field?.type?.code ?? ""];
37
37
  }
38
- function tt(e, t) {
38
+ function Ft(e, t) {
39
39
  const n = t.option_config?.label_attr, r = t.option_config?.value_attr || "value";
40
40
  let i;
41
41
  if (n?.length) {
42
- const a = n.join(" - ");
43
- e[a] !== void 0 ? i = String(e[a]) : i = n.map((s) => e[s]).filter((s) => s != null && s !== "").join(" - ");
42
+ const s = n.join(" - ");
43
+ e[s] !== void 0 ? i = String(e[s]) : i = n.map((o) => e[o]).filter((o) => o != null && o !== "").join(" - ");
44
44
  } else
45
45
  i = String(e[r] ?? "");
46
46
  return {
@@ -48,256 +48,1132 @@ function tt(e, t) {
48
48
  value: e[r]
49
49
  };
50
50
  }
51
- function nt(e, t) {
52
- return t.option_config && t.is_option_api ? e?.map((n) => tt(n, t)) : t.metas?.map((n) => ({
51
+ function Ct(e, t) {
52
+ return t.option_config && t.is_option_api ? e?.map((n) => Ft(n, t)) : t.metas?.map((n) => ({
53
53
  label: n.label,
54
54
  value: n.value
55
55
  }));
56
56
  }
57
- function se(e, t) {
57
+ function Ke(e, t) {
58
+ const n = t.option_config?.value_attr || "value";
59
+ return e[n];
60
+ }
61
+ function Et(e, t) {
62
+ const n = /* @__PURE__ */ new Set(), r = [];
63
+ return e.forEach((i) => {
64
+ const s = Ke(i, t), o = String(s);
65
+ n.has(o) || (n.add(o), r.push(i));
66
+ }), r;
67
+ }
68
+ function Fe(e, t) {
58
69
  let n;
59
70
  return (...r) => {
60
71
  n && clearTimeout(n), n = setTimeout(() => e(...r), t);
61
72
  };
62
73
  }
63
- const rt = ({
74
+ const Rt = ({
64
75
  onSearchKeyword: e,
65
76
  searchDebounceMs: t = 500,
66
77
  ...n
67
78
  }) => {
68
- const [r, i] = P(""), a = R(
69
- () => se((o) => e?.(o), t),
79
+ const [r, i] = L(""), s = C(
80
+ () => Fe((a) => e?.(a), t),
70
81
  [e, t]
71
82
  );
72
- return /* @__PURE__ */ f(
73
- Fe,
83
+ return /* @__PURE__ */ l(
84
+ Ie,
74
85
  {
75
86
  allowClear: !0,
76
87
  showSearch: !0,
77
88
  searchValue: r,
78
- onSearch: (o) => {
79
- i(o), a(o);
89
+ onSearch: (a) => {
90
+ i(a), s(a);
80
91
  },
81
92
  filterOption: !1,
82
93
  ...n
83
94
  }
84
95
  );
85
- }, it = C(rt), at = ({
96
+ }, xt = Q(Rt), Tt = ({
86
97
  fieldName: e,
87
98
  formInstance: t,
88
99
  ...n
89
100
  }) => {
90
- const r = U.useWatch(e, t);
91
- return V(() => {
101
+ const r = X.useWatch(e, t);
102
+ return j(() => {
92
103
  if (r?.fileList?.length && r.fileList.some(
93
- (s) => !s.type?.startsWith("image/")
104
+ (o) => !o.type?.startsWith("image/")
94
105
  )) {
95
- const s = r.fileList.filter(
96
- (o) => o.type?.startsWith("image/")
106
+ const o = r.fileList.filter(
107
+ (a) => a.type?.startsWith("image/")
97
108
  );
98
109
  t.setFieldValue(
99
110
  e,
100
- s?.length ? {
101
- file: s[0]?.originFileObj,
102
- fileList: s
111
+ o?.length ? {
112
+ file: o[0]?.originFileObj,
113
+ fileList: o
103
114
  } : null
104
115
  );
105
116
  }
106
- }, [e, t, r]), /* @__PURE__ */ f(ke, { listType: "picture-card", accept: "image/*", ...n, children: /* @__PURE__ */ f(
117
+ }, [e, t, r]), /* @__PURE__ */ l(qe, { listType: "picture-card", accept: "image/*", ...n, children: /* @__PURE__ */ l(
107
118
  "button",
108
119
  {
109
120
  style: { border: 0, background: "none", cursor: "pointer" },
110
121
  type: "button",
111
- children: /* @__PURE__ */ f(Qe, {})
122
+ children: /* @__PURE__ */ l(gt, {})
112
123
  }
113
124
  ) });
114
- }, ot = C(at), st = ({
125
+ }, Mt = Q(Tt), Dt = ({
115
126
  fieldName: e,
116
127
  formInstance: t,
117
128
  ...n
118
129
  }) => {
119
- const r = U.useWatch(e, t);
120
- return /* @__PURE__ */ f(ke, { fileList: r?.fileList, ...n, children: /* @__PURE__ */ f(Ee, { icon: /* @__PURE__ */ f(Xe, {}) }) });
121
- }, lt = C(st), ct = ({
130
+ const r = X.useWatch(e, t);
131
+ return /* @__PURE__ */ l(qe, { fileList: r?.fileList, ...n, children: /* @__PURE__ */ l(Ae, { icon: /* @__PURE__ */ l(wt, {}) }) });
132
+ }, Lt = Q(Dt);
133
+ function we(e, t, n = {}) {
134
+ const { enabled: r = !0 } = n, [i, s] = L(), [o, a] = L(!1), [m, f] = L(), y = I(t);
135
+ y.current = t;
136
+ const u = D(async () => {
137
+ if (r) {
138
+ a(!0);
139
+ try {
140
+ const c = await y.current();
141
+ return s(c), f(void 0), c;
142
+ } catch (c) {
143
+ throw f(c), c;
144
+ } finally {
145
+ a(!1);
146
+ }
147
+ }
148
+ }, [r]);
149
+ return j(() => {
150
+ r && u();
151
+ }, [r, u, ...e]), { data: i, isLoading: o, error: m, refetch: u };
152
+ }
153
+ function Ue(e) {
154
+ if (!e) return;
155
+ const { mode: t } = e;
156
+ if (t === "api" && e.api?.url)
157
+ return e.api;
158
+ if (t === "api_ids" && e.api_ids?.url) {
159
+ const n = e.api_ids, r = n.method?.toUpperCase() === "POST";
160
+ return {
161
+ url: n.url,
162
+ method: n.method,
163
+ data_path: n.data_path,
164
+ mapping_attr: n.mapping_attr,
165
+ link: n.link,
166
+ result_type: n.result_type ?? "array",
167
+ params: n.params ?? (!r && !n.data ? { ids: "{{value}}" } : void 0),
168
+ data: n.data ?? (r && !n.params ? { ids: "{{value}}" } : void 0)
169
+ };
170
+ }
171
+ if (t === "api_detail" && e.api_detail?.url) {
172
+ const n = e.api_detail;
173
+ return {
174
+ url: n.url,
175
+ method: n.method,
176
+ data_path: n.data_path,
177
+ mapping_attr: n.mapping_attr,
178
+ link: n.link,
179
+ result_type: n.result_type ?? "object",
180
+ url_template: n.url_template ?? !0,
181
+ params: n.params,
182
+ data: n.data
183
+ };
184
+ }
185
+ }
186
+ function Pe(e) {
187
+ return {
188
+ value: e,
189
+ id: e
190
+ };
191
+ }
192
+ function Pt(e, t) {
193
+ const n = t.method || "GET", r = n.toUpperCase() === "GET";
194
+ if (t.url_template)
195
+ return (Array.isArray(e) ? e.filter((m) => m != null && m !== "") : e != null && e !== "" ? [e] : []).map((m) => {
196
+ const f = Pe(m), y = he(t.url, f), u = t.params ? ie(t.params, f) : void 0, c = t.data ? ie(t.data, f) : void 0;
197
+ return {
198
+ method: n,
199
+ url: y,
200
+ params: r ? u : void 0,
201
+ data: r ? void 0 : c
202
+ };
203
+ });
204
+ const i = Pe(e), s = t.params ? ie(t.params, i) : void 0, o = t.data ? ie(t.data, i) : void 0;
205
+ return [
206
+ {
207
+ method: n,
208
+ url: t.url,
209
+ params: r ? s : void 0,
210
+ data: r ? void 0 : o
211
+ }
212
+ ];
213
+ }
214
+ function Ne(e, t) {
215
+ const n = t.data_path ? se(e, t.data_path) : e;
216
+ return (t.result_type ?? (Array.isArray(n) ? "array" : "object")) === "array" ? Array.isArray(n) ? n : n != null ? [n] : [] : Array.isArray(n) ? n.length ? [n[0]] : [] : n && typeof n == "object" ? [n] : [];
217
+ }
218
+ function We(e, t) {
219
+ return It(e, t.mapping_attr);
220
+ }
221
+ function $e(e, t) {
222
+ return qt(t.link, e);
223
+ }
224
+ async function Vt(e, t, n, r) {
225
+ const i = Pt(e, t);
226
+ if (!i.length) return [];
227
+ const s = await Promise.all(
228
+ i.map((a) => n({ ...a, signal: r }))
229
+ ), o = [];
230
+ for (const a of s)
231
+ o.push(...Ne(a.data, t));
232
+ return o;
233
+ }
234
+ function W(e) {
235
+ return !!(e == null || e === "" || Array.isArray(e) && e.length === 0);
236
+ }
237
+ function Ce(e, t) {
238
+ const n = e.option_config?.api_options?.params, r = e.option_config?.api_options?.data;
239
+ if (!n && !r) return;
240
+ const i = (s) => {
241
+ const o = {};
242
+ for (const a in s)
243
+ if (typeof s[a] == "string" && s[a].startsWith("{{") && s[a].endsWith("}}")) {
244
+ const m = s[a].slice(2, -2).trim();
245
+ o[a] = t?.[m];
246
+ } else
247
+ o[a] = s[a];
248
+ return o;
249
+ };
250
+ return {
251
+ params: n ? i(n) : void 0,
252
+ data: r ? i(r) : void 0
253
+ };
254
+ }
255
+ function jt(e, t) {
256
+ const n = t.option_config?.label_attr, r = t.option_config?.value_attr || "";
257
+ if (n?.length) {
258
+ const i = n.join(" - ");
259
+ return e[i] !== void 0 ? String(e[i]) : n.map((s) => e[s]).filter((s) => s != null && s !== "").join(" - ");
260
+ }
261
+ return String(e[r] ?? "");
262
+ }
263
+ function Ee(e, t) {
264
+ if (!t?.length) return null;
265
+ const r = (Array.isArray(e) ? e : [e]).map((i) => t.find((s) => String(s.value) === String(i))?.label).filter((i) => !!i);
266
+ return r.length ? r.join(", ") : null;
267
+ }
268
+ function oe(e, t, n) {
269
+ if (W(e)) return null;
270
+ const r = t.option_config?.value_attr || "value", i = Array.isArray(e) ? e : [e];
271
+ if (t.is_option_api && n?.length) {
272
+ const o = i.map((a) => {
273
+ const m = n.find(
274
+ (f) => String(f[r]) === String(a)
275
+ );
276
+ return m ? jt(m, t) : String(a);
277
+ }).filter(Boolean);
278
+ return o.length ? o.join(", ") : null;
279
+ }
280
+ const s = Ee(e, t.metas);
281
+ return s || i.map(String).join(", ");
282
+ }
283
+ function ze(e, t) {
284
+ if (W(e)) return null;
285
+ const n = t.additional_config?.datetime?.format, r = ge(e);
286
+ return r.isValid() ? n ? r.format(n) : r.format("YYYY-MM-DD HH:mm:ss") : String(e);
287
+ }
288
+ function Ot(e) {
289
+ if (W(e)) return null;
290
+ if (Array.isArray(e)) {
291
+ const t = e.map(
292
+ (n) => typeof n == "object" && n && "name" in n ? String(n.name) : String(n)
293
+ ).filter(Boolean);
294
+ return t.length ? t.join(", ") : null;
295
+ }
296
+ return String(e);
297
+ }
298
+ function It(e, t) {
299
+ return t?.length ? t.map((n) => {
300
+ const r = se(e, n) ?? e[n];
301
+ return r != null ? String(r) : "";
302
+ }).filter(Boolean).join(" - ") : JSON.stringify(e);
303
+ }
304
+ function qt(e, t) {
305
+ return e ? e.replace(/\{\{(.+?)\}\}/g, (n, r) => {
306
+ const i = r.trim(), s = se(t, i) ?? t[i];
307
+ return s != null ? String(s) : "";
308
+ }) : null;
309
+ }
310
+ function Ve(e, t, n) {
311
+ if (W(e)) return null;
312
+ switch (t?.mode ?? "formatted") {
313
+ case "raw":
314
+ case "formatted":
315
+ return Array.isArray(e) ? e.map(String).join(", ") : String(e);
316
+ case "api":
317
+ case "api_ids":
318
+ case "api_detail": {
319
+ const i = Ue(t);
320
+ if (!n || !i)
321
+ return Array.isArray(e) ? e.map(String).join(", ") : String(e);
322
+ const s = Ne(n, i);
323
+ return s.length ? s.map((a) => {
324
+ const m = We(a, i), f = $e(a, i);
325
+ return f ? `${m} (${f})` : m;
326
+ }).filter(Boolean).join(", ") || null : String(e);
327
+ }
328
+ default:
329
+ return String(e);
330
+ }
331
+ }
332
+ function Bt(e, t, n) {
333
+ const r = e.additional_config?.view_value;
334
+ if (r?.mode === "api" || r?.mode === "api_ids" || r?.mode === "api_detail")
335
+ return Ve(
336
+ t,
337
+ r,
338
+ n.viewValueFetched
339
+ );
340
+ switch (e.field?.type?.code) {
341
+ case "text":
342
+ case "number":
343
+ return W(t) ? null : String(t);
344
+ case "datetime":
345
+ return ze(t, e);
346
+ case "select":
347
+ case "radio":
348
+ case "checkbox":
349
+ return oe(t, e, n.optionList);
350
+ case "image":
351
+ case "file":
352
+ return Ot(t);
353
+ default:
354
+ return r ? Ve(
355
+ t,
356
+ r,
357
+ n.viewValueFetched
358
+ ) : W(t) ? null : String(t);
359
+ }
360
+ }
361
+ function ce(e) {
362
+ const t = e.additional_config?.default;
363
+ return typeof t == "string" && t.trim() ? t : void 0;
364
+ }
365
+ function He(e, t, n) {
366
+ if (!t || typeof t != "object" || Array.isArray(t))
367
+ return {};
368
+ const r = n ?? ce(e), i = t;
369
+ if (r && r in i) {
370
+ const s = i[r];
371
+ if (s && typeof s == "object" && !Array.isArray(s))
372
+ return s;
373
+ }
374
+ return i;
375
+ }
376
+ function Ye(e, t, n) {
377
+ if (Array.isArray(t))
378
+ return t;
379
+ const r = n ?? ce(e);
380
+ if (!r || W(t))
381
+ return [];
382
+ if (t && typeof t == "object" && !Array.isArray(t)) {
383
+ const i = t;
384
+ if (r in i && Array.isArray(i[r]))
385
+ return i[r];
386
+ }
387
+ return Je(
388
+ e,
389
+ { [e.code]: t },
390
+ r
391
+ );
392
+ }
393
+ function Bn(e) {
394
+ return {
395
+ id: e.id,
396
+ code: e.code,
397
+ form_id: e.id,
398
+ method: "POST",
399
+ action: "",
400
+ config: {
401
+ body: ""
402
+ },
403
+ created_at: e.created_at ?? "",
404
+ updated_at: e.updated_at ?? "",
405
+ created_by: e.created_by,
406
+ deleted_at: e.deleted_at,
407
+ form: e
408
+ };
409
+ }
410
+ function Re(e) {
411
+ return e.additional_config?.form?.submit_container_key ?? e.additional_config?.multiple_form?.submit_container_key ?? e.code;
412
+ }
413
+ function Kt(e, t, n, r) {
414
+ const i = Re(e), s = t[e.code] ?? t[i];
415
+ if (!W(s) && s && typeof s == "object" && !Array.isArray(s)) {
416
+ const o = s;
417
+ if (n in o) {
418
+ const a = o[n];
419
+ return a && typeof a == "object" && !Array.isArray(a) ? a : void 0;
420
+ }
421
+ return o;
422
+ }
423
+ }
424
+ function Je(e, t, n) {
425
+ const r = Re(e), i = t[e.code] ?? t[r];
426
+ if (W(i))
427
+ return [];
428
+ if (i && typeof i == "object" && !Array.isArray(i)) {
429
+ const s = i;
430
+ if (n in s && Array.isArray(s[n]))
431
+ return s[n];
432
+ }
433
+ return Array.isArray(i) ? i : [];
434
+ }
435
+ function se(e, t) {
436
+ return t.split(".").reduce((n, r) => {
437
+ if (n && typeof n == "object")
438
+ return n[r];
439
+ }, e);
440
+ }
441
+ function Ut(e, t) {
442
+ if (typeof e != "string") return e;
443
+ const n = e.match(/^\{\{(.+?)\}\}$/);
444
+ if (!n) return e;
445
+ const r = n[1].trim(), i = se(t, r);
446
+ return i !== void 0 ? i : e;
447
+ }
448
+ function Nt(e, t) {
449
+ const n = {};
450
+ for (const r in e)
451
+ n[r] = Ut(
452
+ e[r],
453
+ t
454
+ );
455
+ return n;
456
+ }
457
+ function Xe(e, t) {
458
+ const n = { ...e };
459
+ return t.forEach((r) => {
460
+ const i = e[r.code];
461
+ if (i == null) return;
462
+ switch (r.field?.type?.code) {
463
+ case "datetime": {
464
+ if (i && typeof i == "object" && typeof i.isValid == "function") {
465
+ n[r.code] = i;
466
+ break;
467
+ }
468
+ const o = ge(i);
469
+ o.isValid() && (n[r.code] = o);
470
+ break;
471
+ }
472
+ case "file":
473
+ case "image": {
474
+ if (Array.isArray(i) && i.length > 0) {
475
+ const o = i.map((a, m) => {
476
+ const f = a;
477
+ return {
478
+ uid: String(f.uid ?? f.path ?? m),
479
+ name: f.name ?? `file-${m}`,
480
+ status: "done",
481
+ percent: 100,
482
+ type: f.type,
483
+ size: f.size,
484
+ response: a
485
+ };
486
+ });
487
+ n[r.code] = { fileList: o };
488
+ }
489
+ break;
490
+ }
491
+ case "form": {
492
+ const o = ce(r);
493
+ n[r.code] = He(r, i, o);
494
+ break;
495
+ }
496
+ case "multiple-form": {
497
+ const o = ce(r);
498
+ n[r.code] = Ye(r, i, o);
499
+ break;
500
+ }
501
+ }
502
+ }), n;
503
+ }
504
+ function Wt(e) {
505
+ const t = e.option_config?.api_options?.params || {}, n = e.option_config?.api_options?.data || {}, r = (i) => Object.values(i).filter(
506
+ (s) => typeof s == "string" && s.startsWith("{{") && s.endsWith("}}")
507
+ ).map((s) => s.slice(2, -2).trim());
508
+ return Array.from(/* @__PURE__ */ new Set([...r(t), ...r(n)]));
509
+ }
510
+ function ie(e, t) {
511
+ const n = {};
512
+ for (const r in e) {
513
+ const i = e[r];
514
+ if (typeof i == "string" && i.startsWith("{{") && i.endsWith("}}")) {
515
+ const s = i.slice(2, -2).trim();
516
+ n[r] = t?.[s];
517
+ } else
518
+ n[r] = i;
519
+ }
520
+ return n;
521
+ }
522
+ function he(e, t) {
523
+ return e.replace(/\{\{\s*(\w+)\s*\}\}/g, (n, r) => {
524
+ const i = t?.[r];
525
+ return i != null ? String(i) : "";
526
+ });
527
+ }
528
+ function $t(e, t, n) {
529
+ const i = t.find((s) => s.code === e)?.additional_config?.on_field_change?.clear ?? [];
530
+ return i.length === 0 ? [] : i.filter(
531
+ (s) => n?.[s] !== void 0 && n?.[s] !== null
532
+ );
533
+ }
534
+ const zt = (e) => ({
535
+ id: e.id,
536
+ code: e.code,
537
+ form_id: e.id,
538
+ method: "POST",
539
+ action: "",
540
+ config: {
541
+ body: ""
542
+ },
543
+ created_at: e.created_at ?? "",
544
+ updated_at: e.updated_at ?? "",
545
+ created_by: e.created_by,
546
+ deleted_at: e.deleted_at,
547
+ form: e
548
+ }), Ht = ({
549
+ group: e,
550
+ value: t,
551
+ onChange: n,
552
+ disabled: r = !1,
553
+ readOnly: i = !1,
554
+ registerNestedForm: s
555
+ }) => {
556
+ const o = U(), [a] = X.useForm(), m = I(null), f = e.additional_config?.form?.config_url, y = e.additional_config?.form?.method ?? "GET", {
557
+ data: u,
558
+ isLoading: c,
559
+ error: d
560
+ } = we(
561
+ [f, y],
562
+ async () => {
563
+ if (!f)
564
+ throw new Error("Missing additional_config.form.config_url");
565
+ const h = await o.client.request({
566
+ method: y,
567
+ url: f
568
+ });
569
+ return o.parsers.formConfigResponse(h.data);
570
+ },
571
+ { enabled: !!f }
572
+ ), p = C(
573
+ () => u ? zt(u) : void 0,
574
+ [u]
575
+ );
576
+ return j(() => {
577
+ if (u)
578
+ return s?.(e.code, m, {
579
+ formCode: u.code,
580
+ fieldType: "form"
581
+ }), () => {
582
+ s?.(e.code, null);
583
+ };
584
+ }, [e.code, u, s]), j(() => {
585
+ if (!u) return;
586
+ const h = He(e, t, u.code);
587
+ a.setFieldsValue(
588
+ Xe(h, u.field_groups)
589
+ );
590
+ }, [e, a, u, t]), f ? c ? /* @__PURE__ */ l(N, { type: "info", message: "Loading...", showIcon: !0 }) : d || !p ? /* @__PURE__ */ l(N, { type: "error", message: "Failed to load nested form", showIcon: !0 }) : /* @__PURE__ */ l(
591
+ "div",
592
+ {
593
+ style: {
594
+ border: "1px solid rgba(5, 5, 5, 0.12)",
595
+ borderRadius: 8,
596
+ padding: 12,
597
+ background: "#fff"
598
+ },
599
+ children: /* @__PURE__ */ l(
600
+ xe,
601
+ {
602
+ ref: m,
603
+ formConfig: p,
604
+ formInstance: a,
605
+ manualSubmit: !0,
606
+ disableHtmlFormWrapper: !0,
607
+ readOnly: r || i,
608
+ onValuesChange: (h, _) => {
609
+ n?.(_ ?? {});
610
+ }
611
+ }
612
+ )
613
+ }
614
+ ) : /* @__PURE__ */ l(N, { type: "warning", message: "Missing nested form config_url", showIcon: !0 });
615
+ };
616
+ function le(e) {
617
+ return JSON.stringify(e);
618
+ }
619
+ function Yt(e, t) {
620
+ const n = e.get(t);
621
+ if (n) {
622
+ if (Date.now() > n.expiresAt) {
623
+ e.delete(t);
624
+ return;
625
+ }
626
+ return n.data;
627
+ }
628
+ }
629
+ function Jt(e, t, n, r) {
630
+ e.set(t, { data: n, expiresAt: Date.now() + r });
631
+ }
632
+ async function de(e, t, n, r, i) {
633
+ const s = e[t];
634
+ if (e.cache.enabled) {
635
+ const f = Yt(s, n);
636
+ if (f !== void 0) return f;
637
+ }
638
+ const o = new AbortController(), a = i ? AbortSignal.any([i, o.signal]) : o.signal, m = await r(a);
639
+ return e.cache.enabled && Jt(s, n, m, e.cache.ttlMs), m;
640
+ }
641
+ function Xt(e) {
642
+ const t = e?.field?.type?.code;
643
+ return t === "select" || t === "radio" || t === "checkbox";
644
+ }
645
+ async function Qt(e, t, n, r, i) {
646
+ if (W(n))
647
+ return i;
648
+ if (!Xt(t))
649
+ return String(n);
650
+ const s = Ee(n, t.metas);
651
+ if (s)
652
+ return s;
653
+ if (t.is_option_api && t.option_config?.url) {
654
+ const o = Ce(t, r), a = t.option_config.method?.toUpperCase() === "GET" || !t.option_config.method, f = { [t.option_config.value_attr || "value"]: n }, y = le([
655
+ "collapseTitle",
656
+ t.code,
657
+ t.option_config.url,
658
+ t.option_config.method,
659
+ o,
660
+ n
661
+ ]);
662
+ try {
663
+ const u = await de(
664
+ e,
665
+ "optionCache",
666
+ y,
667
+ async (d) => {
668
+ const p = await e.client.request({
669
+ method: t.option_config?.method || "GET",
670
+ url: t.option_config?.url,
671
+ params: a ? {
672
+ ...o?.params,
673
+ filter: {
674
+ ...o?.params?.filter,
675
+ ...f
676
+ }
677
+ } : o?.params,
678
+ data: a ? o?.data : {
679
+ ...o?.data,
680
+ filter: {
681
+ ...o?.data?.filter,
682
+ ...f
683
+ }
684
+ },
685
+ signal: d
686
+ });
687
+ return e.parsers.optionResponse(p.data, t);
688
+ }
689
+ ), c = oe(
690
+ n,
691
+ t,
692
+ u
693
+ );
694
+ if (c) return c;
695
+ } catch {
696
+ }
697
+ }
698
+ return oe(n, t) ?? i;
699
+ }
700
+ function Zt(e, t, n, r, i) {
701
+ const s = U(), [o, a] = L({});
702
+ return j(() => {
703
+ if (!t || !e) {
704
+ a({});
705
+ return;
706
+ }
707
+ let m = !1;
708
+ return (async () => {
709
+ const y = await Promise.all(
710
+ n.map(async (u, c) => {
711
+ const d = r[u.key] ?? {}, p = await Qt(
712
+ s,
713
+ e,
714
+ d[t],
715
+ d,
716
+ `${i} ${c + 1}`
717
+ );
718
+ return [u.key, p];
719
+ })
720
+ );
721
+ m || a(Object.fromEntries(y));
722
+ })(), () => {
723
+ m = !0;
724
+ };
725
+ }, [s, i, n, t, e, r]), o;
726
+ }
727
+ const Gt = (e) => ({
728
+ id: e.id,
729
+ code: e.code,
730
+ form_id: e.id,
731
+ method: "POST",
732
+ action: "",
733
+ config: {
734
+ body: ""
735
+ },
736
+ created_at: e.created_at ?? "",
737
+ updated_at: e.updated_at ?? "",
738
+ created_by: e.created_by,
739
+ deleted_at: e.deleted_at,
740
+ form: e
741
+ });
742
+ function en({
743
+ itemKey: e,
744
+ nestedFormConfig: t,
745
+ value: n,
746
+ disabled: r = !1,
747
+ readOnly: i = !1,
748
+ registerItemRef: s,
749
+ onValuesChange: o
750
+ }) {
751
+ const [a] = X.useForm(), m = I(null);
752
+ return j(() => (s(e, m), () => {
753
+ s(e, null);
754
+ }), [e, s]), j(() => {
755
+ a.setFieldsValue(
756
+ Xe(n ?? {}, t.form.field_groups)
757
+ );
758
+ }, [a, t.form.field_groups, n]), /* @__PURE__ */ l(
759
+ xe,
760
+ {
761
+ ref: m,
762
+ formConfig: t,
763
+ formInstance: a,
764
+ manualSubmit: !0,
765
+ disableHtmlFormWrapper: !0,
766
+ readOnly: r || i,
767
+ onValuesChange: (f, y) => {
768
+ o(e, y ?? {});
769
+ }
770
+ }
771
+ );
772
+ }
773
+ const tn = ({
774
+ group: e,
775
+ value: t,
776
+ onChange: n,
777
+ disabled: r = !1,
778
+ readOnly: i = !1,
779
+ registerNestedForm: s
780
+ }) => {
781
+ const o = U(), a = e.additional_config?.multiple_form, m = a?.config_url, f = a?.method ?? "GET", y = a?.primary_field, u = I(0), [c, d] = L([{ key: u.current++ }]), [p, h] = L(
782
+ {}
783
+ ), _ = I(p), A = I(c), [w, S] = L(
784
+ String(c[0]?.key ?? "")
785
+ ), b = I(/* @__PURE__ */ new Map()), {
786
+ data: v,
787
+ isLoading: T,
788
+ error: F
789
+ } = we(
790
+ [m, f],
791
+ async () => {
792
+ if (!m)
793
+ throw new Error("Missing additional_config.multiple_form.config_url");
794
+ const g = await o.client.request({
795
+ method: f,
796
+ url: m
797
+ });
798
+ return o.parsers.formConfigResponse(g.data);
799
+ },
800
+ { enabled: !!m }
801
+ );
802
+ j(() => {
803
+ _.current = p;
804
+ }, [p]), j(() => {
805
+ A.current = c;
806
+ }, [c]), j(() => {
807
+ const g = v?.code ?? ce(e), k = Ye(e, t, g);
808
+ d((E) => {
809
+ if (E.length === k.length && E.length > 0) {
810
+ const J = E.reduce(
811
+ (te, re, me) => (te[re.key] = k[me] ?? {}, te),
812
+ {}
813
+ );
814
+ return h(J), E;
815
+ }
816
+ const M = k.length > 0 ? k : [{}], O = M.map(() => ({ key: u.current++ })), ne = O.reduce(
817
+ (J, te, re) => (J[te.key] = M[re] ?? {}, J),
818
+ {}
819
+ );
820
+ return h(ne), S(String(O[0]?.key ?? "")), O;
821
+ });
822
+ }, [e, v?.code, t]);
823
+ const R = C(
824
+ () => v ? Gt(v) : void 0,
825
+ [v]
826
+ ), $ = C(
827
+ () => v?.field_groups.find((g) => g.code === y),
828
+ [v, y]
829
+ ), z = Zt(
830
+ $,
831
+ y,
832
+ c,
833
+ p,
834
+ e.label
835
+ ), q = D(
836
+ (g, k) => {
837
+ const E = g.map((M) => k[M.key] ?? {});
838
+ n?.(E);
839
+ },
840
+ [n]
841
+ ), H = D(
842
+ (g, k) => {
843
+ if (k) {
844
+ b.current.set(g, k);
845
+ return;
846
+ }
847
+ b.current.delete(g);
848
+ },
849
+ []
850
+ ), ee = D(
851
+ (g, k) => {
852
+ h((E) => {
853
+ const M = { ...E, [g]: k };
854
+ return q(A.current, M), M;
855
+ });
856
+ },
857
+ [q]
858
+ ), P = I({
859
+ submit: async () => {
860
+ },
861
+ isSubmitting: () => !1,
862
+ getProcessedValues: async () => ({})
863
+ });
864
+ j(() => {
865
+ P.current && (P.current.getProcessedValues = async () => await Promise.all(
866
+ A.current.map(async (k) => {
867
+ const E = b.current.get(k.key);
868
+ return E?.current ? E.current.getProcessedValues() : _.current[k.key] ?? {};
869
+ })
870
+ ));
871
+ }, []), j(() => {
872
+ if (v)
873
+ return s?.(e.code, P, {
874
+ formCode: v.code,
875
+ fieldType: "multiple-form"
876
+ }), () => {
877
+ s?.(e.code, null);
878
+ };
879
+ }, [e.code, v, s]);
880
+ const Z = D(() => {
881
+ const g = { key: u.current++ };
882
+ d((k) => {
883
+ const E = [...k, g];
884
+ return h((M) => {
885
+ const O = { ...M, [g.key]: {} };
886
+ return q(E, O), O;
887
+ }), E;
888
+ }), S(String(g.key));
889
+ }, [q]), B = D(
890
+ (g) => {
891
+ d((k) => {
892
+ const E = k.filter((M) => M.key !== g);
893
+ return h((M) => {
894
+ const O = { ...M };
895
+ return delete O[g], q(E, O), O;
896
+ }), S(String(E[0]?.key ?? "")), E;
897
+ });
898
+ },
899
+ [q]
900
+ ), fe = C(() => c.map((g, k) => {
901
+ const E = p[g.key] ?? {}, M = z[g.key] ?? `${e.label} ${k + 1}`;
902
+ return {
903
+ key: String(g.key),
904
+ label: /* @__PURE__ */ ae("div", { style: { display: "flex", justifyContent: "space-between", width: "100%" }, children: [
905
+ /* @__PURE__ */ l("span", { children: M }),
906
+ !r && !i ? /* @__PURE__ */ l(
907
+ vt,
908
+ {
909
+ onClick: (O) => {
910
+ O.preventDefault(), O.stopPropagation(), B(g.key);
911
+ }
912
+ }
913
+ ) : null
914
+ ] }),
915
+ children: R ? /* @__PURE__ */ l(
916
+ en,
917
+ {
918
+ itemKey: g.key,
919
+ nestedFormConfig: R,
920
+ value: E,
921
+ disabled: r,
922
+ readOnly: i,
923
+ registerItemRef: H,
924
+ onValuesChange: ee
925
+ }
926
+ ) : null
927
+ };
928
+ }), [
929
+ r,
930
+ e.label,
931
+ B,
932
+ c,
933
+ R,
934
+ ee,
935
+ i,
936
+ H,
937
+ z,
938
+ p
939
+ ]);
940
+ return m ? y ? T ? /* @__PURE__ */ l(N, { type: "info", message: "Loading...", showIcon: !0 }) : F || !R ? /* @__PURE__ */ l(N, { type: "error", message: "Failed to load nested form", showIcon: !0 }) : /* @__PURE__ */ ae("div", { children: [
941
+ /* @__PURE__ */ l(
942
+ at,
943
+ {
944
+ accordion: !0,
945
+ activeKey: w,
946
+ onChange: (g) => S(Array.isArray(g) ? String(g[0] ?? "") : String(g)),
947
+ items: fe
948
+ }
949
+ ),
950
+ !r && !i ? /* @__PURE__ */ l(
951
+ Ae,
952
+ {
953
+ style: { marginTop: 12 },
954
+ block: !0,
955
+ type: "dashed",
956
+ onClick: Z,
957
+ icon: /* @__PURE__ */ l(At, {}),
958
+ children: "Add item"
959
+ }
960
+ ) : null
961
+ ] }) : /* @__PURE__ */ l(
962
+ N,
963
+ {
964
+ type: "warning",
965
+ message: "Missing multiple_form primary_field",
966
+ showIcon: !0
967
+ }
968
+ ) : /* @__PURE__ */ l(
969
+ N,
970
+ {
971
+ type: "warning",
972
+ message: "Missing multiple_form config_url",
973
+ showIcon: !0
974
+ }
975
+ );
976
+ }, nn = ({
122
977
  formInstance: e,
123
978
  uploadUrl: t,
124
979
  setFieldState: n
125
980
  }) => {
126
- const { client: r, upload: i, i18n: a, renderers: s } = M(), { messages: o } = a, d = T(() => {
981
+ const { client: r, upload: i, i18n: s, renderers: o } = U(), { messages: a } = s, m = D(() => {
127
982
  if (i.upload) return i.upload;
128
- const l = t ?? i.uploadUrl;
129
- if (l)
130
- return async ({ file: p, signal: h, onProgress: u, fieldCode: v, fieldGroup: _, metadata: w }) => {
131
- const b = i.getPayload ? i.getPayload({
132
- file: p,
133
- fieldCode: v,
134
- fieldGroup: _,
135
- uploadUrl: l,
136
- signal: h,
137
- onProgress: u,
983
+ const c = t ?? i.uploadUrl;
984
+ if (c)
985
+ return async ({ file: d, signal: p, onProgress: h, fieldCode: _, fieldGroup: A, metadata: w }) => {
986
+ const S = i.getPayload ? i.getPayload({
987
+ file: d,
988
+ fieldCode: _,
989
+ fieldGroup: A,
990
+ uploadUrl: c,
991
+ signal: p,
992
+ onProgress: h,
138
993
  metadata: w
139
994
  }) : (() => {
140
- const g = new FormData();
141
- return g.append("file", p), w && Object.entries(w).forEach(([k, D]) => {
142
- g.append(k, String(D));
143
- }), g;
144
- })(), A = (await r.request({
995
+ const T = new FormData();
996
+ return T.append("file", d), w && Object.entries(w).forEach(([F, R]) => {
997
+ T.append(F, String(R));
998
+ }), T;
999
+ })(), v = (await r.request({
145
1000
  method: "POST",
146
- url: l,
147
- data: b,
148
- headers: b instanceof FormData ? { "Content-Type": "multipart/form-data" } : void 0,
149
- signal: h,
150
- onUploadProgress: (g) => {
151
- u?.(
152
- Math.round(g.loaded * 100 / (g.total || 1))
1001
+ url: c,
1002
+ data: S,
1003
+ headers: S instanceof FormData ? { "Content-Type": "multipart/form-data" } : void 0,
1004
+ signal: p,
1005
+ onUploadProgress: (T) => {
1006
+ h?.(
1007
+ Math.round(T.loaded * 100 / (T.total || 1))
153
1008
  );
154
1009
  }
155
1010
  })).data;
156
1011
  return {
157
- uid: p.uid,
158
- ...A,
159
- path: String(A.path ?? "")
1012
+ uid: d.uid,
1013
+ ...v,
1014
+ path: String(v.path ?? "")
160
1015
  };
161
1016
  };
162
- }, [r, i, t]), c = T(
163
- (l, p) => (h) => {
164
- const { file: u, onProgress: v, onError: _, onSuccess: w } = h, b = new AbortController(), S = d();
165
- return S ? (S({
166
- file: u,
167
- fieldCode: l,
168
- fieldGroup: p,
1017
+ }, [r, i, t]), f = D(
1018
+ (c, d) => (p) => {
1019
+ const { file: h, onProgress: _, onError: A, onSuccess: w } = p, S = new AbortController(), b = m();
1020
+ return b ? (b({
1021
+ file: h,
1022
+ fieldCode: c,
1023
+ fieldGroup: d,
169
1024
  uploadUrl: t ?? i.uploadUrl,
170
- signal: b.signal,
171
- onProgress: (A) => v?.({ percent: A })
1025
+ signal: S.signal,
1026
+ onProgress: (v) => _?.({ percent: v })
172
1027
  }).then(
173
- (A) => w?.({
174
- ...A,
175
- uid: A.uid ?? u.uid,
176
- path: A.path,
177
- upload_date: Z().format("YYYY-MM-DD HH:mm:ss")
1028
+ (v) => w?.({
1029
+ ...v,
1030
+ uid: v.uid ?? h.uid,
1031
+ path: v.path,
1032
+ upload_date: ge().format("YYYY-MM-DD HH:mm:ss")
178
1033
  })
179
- ).catch((A) => _?.(A)), { abort: () => b.abort() }) : (_?.(new Error(o.uploadError ?? "Upload not configured")), { abort() {
1034
+ ).catch((v) => A?.(v)), { abort: () => S.abort() }) : (A?.(new Error(a.uploadError ?? "Upload not configured")), { abort() {
180
1035
  } });
181
1036
  },
182
- [o.uploadError, d, i.uploadUrl, t]
183
- ), y = T(
184
- (l, p) => async (h) => {
185
- const u = h.response?.path;
186
- return u ? i.remove({ path: u, fieldCode: l, fieldGroup: p }) : !0;
1037
+ [a.uploadError, m, i.uploadUrl, t]
1038
+ ), y = D(
1039
+ (c, d) => async (p) => {
1040
+ const h = p.response?.path;
1041
+ return h ? i.remove({ path: h, fieldCode: c, fieldGroup: d }) : !0;
187
1042
  },
188
1043
  [i]
189
- ), m = T(
190
- (l, {
191
- state: p,
192
- options: h,
193
- optionsLoading: u,
194
- optionsError: v,
195
- onSearchKeyword: _,
196
- readOnly: w = !1
1044
+ ), u = D(
1045
+ (c, {
1046
+ state: d,
1047
+ options: p,
1048
+ optionsLoading: h,
1049
+ optionsError: _,
1050
+ onSearchKeyword: A,
1051
+ readOnly: w = !1,
1052
+ registerNestedForm: S
197
1053
  }) => {
198
- const { additional_config: b, field: S } = l, A = S?.type?.code, g = w || l.is_readonly || p?.disabled, k = et(
199
- l,
200
- s.fields
1054
+ const { additional_config: b, field: v } = c, T = v?.type?.code, F = w || c.is_readonly || d?.disabled, R = kt(
1055
+ c,
1056
+ o.fields
201
1057
  );
202
- if (k)
203
- return k(l, {
204
- state: p,
205
- options: h,
206
- optionsLoading: u,
207
- optionsError: v,
208
- onSearchKeyword: _,
1058
+ if (R)
1059
+ return R(c, {
1060
+ state: d,
1061
+ options: p,
1062
+ optionsLoading: h,
1063
+ optionsError: _,
1064
+ onSearchKeyword: A,
209
1065
  readOnly: w,
210
1066
  formInstance: e,
211
- disabled: !!g,
1067
+ disabled: !!F,
212
1068
  setFieldState: n
213
1069
  });
214
- const D = nt(h, l);
215
- switch (A) {
1070
+ const $ = Ct(p, c);
1071
+ switch (T) {
216
1072
  case "text":
217
- return b?.text?.textarea ? /* @__PURE__ */ f(
218
- ve.TextArea,
1073
+ return b?.text?.textarea ? /* @__PURE__ */ l(
1074
+ Le.TextArea,
219
1075
  {
220
- disabled: g,
221
- placeholder: o.inputPlaceholder(l.label),
1076
+ disabled: F,
1077
+ placeholder: a.inputPlaceholder(c.label),
222
1078
  rows: b?.text?.rows
223
1079
  }
224
- ) : /* @__PURE__ */ f(
225
- ve,
1080
+ ) : /* @__PURE__ */ l(
1081
+ Le,
226
1082
  {
227
- disabled: g,
228
- placeholder: o.inputPlaceholder(l.label)
1083
+ disabled: F,
1084
+ placeholder: a.inputPlaceholder(c.label)
229
1085
  }
230
1086
  );
231
1087
  case "number":
232
- return /* @__PURE__ */ f(
233
- Ke,
1088
+ return /* @__PURE__ */ l(
1089
+ ut,
234
1090
  {
235
1091
  style: { width: "100%" },
236
- disabled: g,
237
- placeholder: o.inputPlaceholder(l.label),
1092
+ disabled: F,
1093
+ placeholder: a.inputPlaceholder(c.label),
238
1094
  min: b?.number?.min,
239
1095
  max: b?.number?.max
240
1096
  }
241
1097
  );
242
1098
  case "select": {
243
- const j = {
244
- disabled: g,
245
- options: D,
246
- placeholder: o.selectPlaceholder(l.label),
1099
+ const z = {
1100
+ disabled: F,
1101
+ options: $,
1102
+ placeholder: a.selectPlaceholder(c.label),
247
1103
  allowClear: !0,
248
- loading: u,
1104
+ loading: h,
249
1105
  mode: b?.select?.multiple ? "multiple" : void 0,
250
- notFoundContent: v ? o.optionError : u ? o.optionLoading : void 0
1106
+ notFoundContent: _ ? a.optionError : h ? a.optionLoading : void 0
251
1107
  };
252
- return _ ? /* @__PURE__ */ f(
253
- it,
1108
+ return A ? /* @__PURE__ */ l(
1109
+ xt,
254
1110
  {
255
- ...j,
256
- onSearchKeyword: _,
1111
+ ...z,
1112
+ onSearchKeyword: A,
257
1113
  searchDebounceMs: b?.select?.searchDebounceMs ?? 500
258
1114
  }
259
- ) : /* @__PURE__ */ f(Fe, { ...j, showSearch: !0, optionFilterProp: "label" });
1115
+ ) : /* @__PURE__ */ l(Ie, { ...z, showSearch: !0, optionFilterProp: "label" });
260
1116
  }
261
1117
  case "radio":
262
- return /* @__PURE__ */ f(We.Group, { disabled: g, options: D });
1118
+ return /* @__PURE__ */ l(dt.Group, { disabled: F, options: $ });
263
1119
  case "checkbox":
264
- return /* @__PURE__ */ f(Ie.Group, { disabled: g, options: D });
1120
+ return /* @__PURE__ */ l(lt.Group, { disabled: F, options: $ });
265
1121
  case "datetime":
266
- return /* @__PURE__ */ f(
267
- Ge,
1122
+ return /* @__PURE__ */ l(
1123
+ ct,
268
1124
  {
269
1125
  style: { width: "100%" },
270
- disabled: g,
1126
+ disabled: F,
271
1127
  showTime: b?.datetime?.showTime,
272
1128
  format: b?.datetime?.format
273
1129
  }
274
1130
  );
275
1131
  case "file":
276
- return /* @__PURE__ */ f(
277
- lt,
1132
+ return /* @__PURE__ */ l(
1133
+ Lt,
278
1134
  {
279
- disabled: g,
280
- fieldName: l.code,
1135
+ disabled: F,
1136
+ fieldName: c.code,
281
1137
  formInstance: e,
282
1138
  multiple: b?.file?.multiple || !1,
283
1139
  maxCount: b?.file?.max,
284
1140
  accept: b?.file?.accept,
285
- customRequest: c(l.code, l),
286
- onRemove: y(l.code, l)
1141
+ customRequest: f(c.code, c),
1142
+ onRemove: y(c.code, c)
287
1143
  }
288
1144
  );
289
1145
  case "image":
290
- return /* @__PURE__ */ f(
291
- ot,
1146
+ return /* @__PURE__ */ l(
1147
+ Mt,
292
1148
  {
293
- disabled: g,
294
- fieldName: l.code,
1149
+ disabled: F,
1150
+ fieldName: c.code,
295
1151
  formInstance: e,
296
1152
  multiple: b?.image?.multiple || !1,
297
1153
  maxCount: b?.image?.max,
298
1154
  accept: b?.image?.accept ?? "image/*",
299
- customRequest: c(l.code, l),
300
- onRemove: y(l.code, l)
1155
+ customRequest: f(c.code, c),
1156
+ onRemove: y(c.code, c)
1157
+ }
1158
+ );
1159
+ case "form":
1160
+ return /* @__PURE__ */ l(
1161
+ Ht,
1162
+ {
1163
+ group: c,
1164
+ disabled: !!F,
1165
+ readOnly: w,
1166
+ registerNestedForm: S
1167
+ }
1168
+ );
1169
+ case "multiple-form":
1170
+ return /* @__PURE__ */ l(
1171
+ tn,
1172
+ {
1173
+ group: c,
1174
+ disabled: !!F,
1175
+ readOnly: w,
1176
+ registerNestedForm: S
301
1177
  }
302
1178
  );
303
1179
  default:
@@ -305,277 +1181,223 @@ const rt = ({
305
1181
  }
306
1182
  },
307
1183
  [
308
- c,
1184
+ f,
309
1185
  y,
310
1186
  e,
311
- o,
312
- s.fields,
1187
+ a,
1188
+ o.fields,
313
1189
  n
314
1190
  ]
315
1191
  );
316
- return R(() => ({ getDynamicField: m }), [m]);
1192
+ return C(() => ({ getDynamicField: u }), [u]);
317
1193
  };
318
- function le(e) {
319
- return JSON.stringify(e);
320
- }
321
- function dt(e, t) {
322
- const n = e.get(t);
323
- if (n) {
324
- if (Date.now() > n.expiresAt) {
325
- e.delete(t);
326
- return;
327
- }
328
- return n.data;
329
- }
330
- }
331
- function ut(e, t, n, r) {
332
- e.set(t, { data: n, expiresAt: Date.now() + r });
333
- }
334
- async function re(e, t, n, r, i) {
335
- const a = e[t];
336
- if (e.cache.enabled) {
337
- const c = dt(a, n);
338
- if (c !== void 0) return c;
339
- }
340
- const s = new AbortController(), o = i ? AbortSignal.any([i, s.signal]) : s.signal, d = await r(o);
341
- return e.cache.enabled && ut(a, n, d, e.cache.ttlMs), d;
342
- }
343
- function I(e, t) {
344
- return t.split(".").reduce((n, r) => {
345
- if (n && typeof n == "object")
346
- return n[r];
347
- }, e);
348
- }
349
- function ft(e, t) {
350
- if (typeof e != "string") return e;
351
- const n = e.match(/^\{\{(.+?)\}\}$/);
352
- if (!n) return e;
353
- const r = n[1].trim(), i = I(t, r);
354
- return i !== void 0 ? i : e;
355
- }
356
- function mt(e, t) {
357
- const n = {};
358
- for (const r in e)
359
- n[r] = ft(
360
- e[r],
361
- t
362
- );
363
- return n;
364
- }
365
- function tn(e, t) {
366
- const n = { ...e };
367
- return t.forEach((r) => {
368
- const i = e[r.code];
369
- if (i == null) return;
370
- switch (r.field?.type?.code) {
371
- case "datetime": {
372
- const s = Z(i);
373
- s.isValid() && (n[r.code] = s);
374
- break;
375
- }
376
- case "file":
377
- case "image": {
378
- if (Array.isArray(i) && i.length > 0) {
379
- const s = i.map((o, d) => {
380
- const c = o;
381
- return {
382
- uid: String(c.uid ?? c.path ?? d),
383
- name: c.name ?? `file-${d}`,
384
- status: "done",
385
- percent: 100,
386
- type: c.type,
387
- size: c.size,
388
- response: o
389
- };
390
- });
391
- n[r.code] = { fileList: s };
392
- }
393
- break;
394
- }
395
- }
396
- }), n;
397
- }
398
- function pt(e) {
399
- const t = e.option_config?.api_options?.params || {}, n = e.option_config?.api_options?.data || {}, r = (i) => Object.values(i).filter(
400
- (a) => typeof a == "string" && a.startsWith("{{") && a.endsWith("}}")
401
- ).map((a) => a.slice(2, -2).trim());
402
- return Array.from(/* @__PURE__ */ new Set([...r(t), ...r(n)]));
403
- }
404
- function q(e, t) {
405
- const n = {};
406
- for (const r in e) {
407
- const i = e[r];
408
- if (typeof i == "string" && i.startsWith("{{") && i.endsWith("}}")) {
409
- const a = i.slice(2, -2).trim();
410
- n[r] = t?.[a];
411
- } else
412
- n[r] = i;
413
- }
414
- return n;
415
- }
416
- function Q(e, t) {
417
- return e.replace(/\{\{\s*(\w+)\s*\}\}/g, (n, r) => {
418
- const i = t?.[r];
419
- return i != null ? String(i) : "";
420
- });
421
- }
422
- function ht(e, t, n) {
423
- const i = t.find((a) => a.code === e)?.additional_config?.on_field_change?.clear ?? [];
424
- return i.length === 0 ? [] : i.filter(
425
- (a) => n?.[a] !== void 0 && n?.[a] !== null
426
- );
427
- }
428
- function yt(e, t) {
429
- const n = R(
430
- () => pt(e),
1194
+ function rn(e, t) {
1195
+ const n = C(
1196
+ () => Wt(e),
431
1197
  [e]
432
- ), r = U.useWatch(
1198
+ ), r = X.useWatch(
433
1199
  n.length > 0 ? n : void 0,
434
1200
  t
435
1201
  );
436
- return R(() => {
1202
+ return C(() => {
437
1203
  if (!n.length) return {};
438
1204
  const i = {};
439
- return n.forEach((a, s) => {
440
- Array.isArray(r) ? i[a] = r[s] : i[a] = r;
1205
+ return n.forEach((s, o) => {
1206
+ Array.isArray(r) ? i[s] = r[o] : i[s] = r;
441
1207
  }), i;
442
1208
  }, [n, r]);
443
1209
  }
444
- function bt({
1210
+ function on({
445
1211
  group: e,
446
1212
  formInstance: t,
447
1213
  searchKeyword: n = "",
448
1214
  searchDebounceMs: r = 500
449
1215
  }) {
450
- const i = M(), a = yt(e, t), [s, o] = P(), [d, c] = P(!1), [y, m] = P(), l = B(null), [p, h] = P(n), u = e.additional_config?.select?.search_keyword ?? !1, v = R(
451
- () => se((b) => h(b), r),
1216
+ const i = U(), s = rn(e, t), o = X.useWatch(e.code, t), [a, m] = L(), [f, y] = L(!1), [u, c] = L(), d = I(null), [p, h] = L(n), _ = e.additional_config?.select?.search_keyword ?? !1, A = C(
1217
+ () => Fe((b) => h(b), r),
452
1218
  [r]
453
1219
  );
454
- V(() => {
455
- u ? v(n) : h("");
456
- }, [n, u, v]);
457
- const _ = R(() => {
458
- const b = e.option_config?.api_options?.params, S = e.option_config?.api_options?.data;
459
- if (!(!b && !S))
1220
+ j(() => {
1221
+ _ ? A(n) : h("");
1222
+ }, [n, _, A]);
1223
+ const w = C(() => {
1224
+ const b = e.option_config?.api_options?.params, v = e.option_config?.api_options?.data;
1225
+ if (!(!b && !v))
460
1226
  return {
461
- params: b ? q(b, a) : void 0,
462
- data: S ? q(S, a) : void 0
1227
+ params: b ? ie(b, s) : void 0,
1228
+ data: v ? ie(v, s) : void 0
463
1229
  };
464
- }, [a, e]), w = T(async () => {
1230
+ }, [s, e]), S = D(async () => {
465
1231
  if (!e.option_config || !e.is_option_api || !e.option_config.url)
466
1232
  return;
467
- l.current?.abort();
1233
+ d.current?.abort();
468
1234
  const b = new AbortController();
469
- l.current = b;
470
- const S = e.option_config.method?.toUpperCase() === "GET" || !e.option_config.method, A = u ? p : "", g = le([
1235
+ d.current = b;
1236
+ const v = e.option_config.method?.toUpperCase() === "GET" || !e.option_config.method, T = _ ? p : "", F = le([
471
1237
  e.code,
472
1238
  e.option_config.url,
473
1239
  e.option_config.method,
474
- _,
475
- A
1240
+ w,
1241
+ T
476
1242
  ]);
477
- c(!0), m(void 0);
1243
+ y(!0), c(void 0);
478
1244
  try {
479
- const k = await re(
1245
+ const R = await de(
480
1246
  i,
481
1247
  "optionCache",
482
- g,
483
- async (D) => {
484
- const j = await i.client.request({
1248
+ F,
1249
+ async (P) => {
1250
+ const Z = await i.client.request({
485
1251
  method: e.option_config?.method || "GET",
486
1252
  url: e.option_config?.url,
487
- params: S && u ? { ..._?.params, keywords: A } : _?.params,
488
- data: !S && u ? { ..._?.data, keywords: A } : _?.data,
489
- signal: D
1253
+ params: v && _ ? { ...w?.params, keywords: T } : w?.params,
1254
+ data: !v && _ ? { ...w?.data, keywords: T } : w?.data,
1255
+ signal: P
490
1256
  });
491
- return i.parsers.optionResponse(j.data, e);
1257
+ return i.parsers.optionResponse(Z.data, e);
492
1258
  },
493
1259
  b.signal
1260
+ ), $ = Array.isArray(o) ? o : o == null ? [] : [o], z = new Set(
1261
+ R.map((P) => String(Ke(P, e)))
1262
+ ), q = $.filter((P) => P == null || P === "" ? !1 : !z.has(String(P)));
1263
+ let H = [];
1264
+ q.length > 0 && (H = (await Promise.all(
1265
+ q.map(async (P) => {
1266
+ const Z = le([
1267
+ e.code,
1268
+ e.option_config?.url,
1269
+ e.option_config?.method,
1270
+ w,
1271
+ "selected",
1272
+ P
1273
+ ]);
1274
+ return de(
1275
+ i,
1276
+ "optionCache",
1277
+ Z,
1278
+ async (B) => {
1279
+ const g = { [e.option_config?.value_attr || "value"]: P }, k = await i.client.request({
1280
+ method: e.option_config?.method || "GET",
1281
+ url: e.option_config?.url,
1282
+ params: v ? {
1283
+ ...w?.params,
1284
+ filter: {
1285
+ ...w?.params?.filter,
1286
+ ...g
1287
+ }
1288
+ } : w?.params,
1289
+ data: v ? w?.data : {
1290
+ ...w?.data,
1291
+ filter: {
1292
+ ...w?.data?.filter,
1293
+ ...g
1294
+ }
1295
+ },
1296
+ signal: B
1297
+ });
1298
+ return i.parsers.optionResponse(k.data, e);
1299
+ },
1300
+ b.signal
1301
+ );
1302
+ })
1303
+ )).flat());
1304
+ const ee = Et(
1305
+ [...R, ...H],
1306
+ e
494
1307
  );
495
- b.signal.aborted || o(k);
496
- } catch (k) {
497
- b.signal.aborted || m(k);
1308
+ b.signal.aborted || m(ee);
1309
+ } catch (R) {
1310
+ b.signal.aborted || c(R);
498
1311
  } finally {
499
- b.signal.aborted || c(!1);
1312
+ b.signal.aborted || y(!1);
500
1313
  }
501
- }, [_, i, p, e, u]);
502
- return V(() => (e.option_config && e.is_option_api && w(), () => l.current?.abort()), [w, e]), { options: s, isLoading: d, error: y, refetch: w };
1314
+ }, [
1315
+ w,
1316
+ i,
1317
+ p,
1318
+ e,
1319
+ _,
1320
+ o
1321
+ ]);
1322
+ return j(() => (e.option_config && e.is_option_api && S(), () => d.current?.abort()), [S, e]), { options: a, isLoading: f, error: u, refetch: S };
503
1323
  }
504
- const _t = ({
1324
+ const sn = ({
505
1325
  group: e,
506
1326
  formInstance: t,
507
1327
  fieldState: n,
508
1328
  setFieldState: r,
509
1329
  uploadUrl: i,
510
- readOnly: a = !1,
511
- size: s = "middle",
512
- ...o
1330
+ readOnly: s = !1,
1331
+ size: o = "middle",
1332
+ registerNestedForm: a,
1333
+ ...m
513
1334
  }) => {
514
- const { getDynamicField: d } = ct({
1335
+ const { getDynamicField: f } = nn({
515
1336
  formInstance: t,
516
1337
  uploadUrl: i,
517
1338
  setFieldState: r
518
- }), c = U.useWatch(e.code, t), [y, m] = P(""), l = e.additional_config?.select?.search_keyword ?? !1, { options: p, isLoading: h, error: u } = bt({
1339
+ }), y = X.useWatch(e.code, t), [u, c] = L(""), d = e.additional_config?.select?.search_keyword ?? !1, { options: p, isLoading: h, error: _ } = on({
519
1340
  group: e,
520
1341
  formInstance: t,
521
- searchKeyword: y,
1342
+ searchKeyword: u,
522
1343
  searchDebounceMs: e.additional_config?.select?.searchDebounceMs ?? 500
523
- }), v = T((w) => {
524
- m(w);
1344
+ }), A = D((S) => {
1345
+ c(S);
525
1346
  }, []);
526
- V(() => {
527
- e.additional_config?.on_field_empty?.disable?.length && e.additional_config.on_field_empty.disable.forEach((w) => {
528
- r(w, { disabled: !c });
1347
+ j(() => {
1348
+ e.additional_config?.on_field_empty?.disable?.length && e.additional_config.on_field_empty.disable.forEach((S) => {
1349
+ r(S, { disabled: !y });
529
1350
  });
530
- }, [c, t, e, r]);
531
- const _ = s === "small" ? 4 : 12;
532
- return /* @__PURE__ */ f(
533
- U.Item,
1351
+ }, [y, t, e, r]);
1352
+ const w = o === "small" ? 4 : 12;
1353
+ return /* @__PURE__ */ l(
1354
+ X.Item,
534
1355
  {
535
1356
  label: e.label,
536
1357
  name: e.code,
537
1358
  hidden: n?.hidden,
538
1359
  rules: [{ required: n?.required || !1 }],
539
- style: { marginBottom: _, ...o.style },
540
- ...o,
541
- children: d(e, {
1360
+ style: { marginBottom: w, ...m.style },
1361
+ ...m,
1362
+ children: f(e, {
542
1363
  state: n,
543
1364
  options: p,
544
1365
  optionsLoading: h,
545
- optionsError: u,
546
- onSearchKeyword: l ? v : void 0,
547
- readOnly: a
1366
+ optionsError: _,
1367
+ onSearchKeyword: d ? A : void 0,
1368
+ readOnly: s,
1369
+ registerNestedForm: a
548
1370
  })
549
1371
  }
550
1372
  );
551
1373
  };
552
- function vt(e, t) {
553
- return e.group.id === t.group.id && e.readOnly === t.readOnly && e.uploadUrl === t.uploadUrl && e.size === t.size && e.fieldState?.disabled === t.fieldState?.disabled && e.fieldState?.hidden === t.fieldState?.hidden && e.fieldState?.required === t.fieldState?.required;
1374
+ function an(e, t) {
1375
+ return e.group.id === t.group.id && e.readOnly === t.readOnly && e.uploadUrl === t.uploadUrl && e.size === t.size && e.registerNestedForm === t.registerNestedForm && e.fieldState?.disabled === t.fieldState?.disabled && e.fieldState?.hidden === t.fieldState?.hidden && e.fieldState?.required === t.fieldState?.required;
554
1376
  }
555
- const wt = C(_t, vt);
556
- function gt({
1377
+ const cn = Q(sn, an);
1378
+ function ln({
557
1379
  fieldGroups: e,
558
1380
  fieldStates: t,
559
1381
  renderField: n,
560
1382
  gutter: r,
561
1383
  defaultColSpan: i
562
1384
  }) {
563
- return /* @__PURE__ */ f($e, { gutter: r, children: e.map((a) => {
564
- const s = t[a.code]?.hidden ? 0 : Number(a.additional_config?.field_col_span) || i;
565
- return /* @__PURE__ */ f(ze, { xs: s, children: n(a) }, a.id);
1385
+ return /* @__PURE__ */ l(ft, { gutter: r, children: e.map((s) => {
1386
+ const o = t[s.code]?.hidden ? 0 : Number(s.additional_config?.field_col_span) || i;
1387
+ return /* @__PURE__ */ l(mt, { xs: o, children: n(s) }, s.id);
566
1388
  }) });
567
1389
  }
568
- function At(e) {
569
- return R(() => {
1390
+ function dn(e) {
1391
+ return C(() => {
570
1392
  const t = e?.form?.field_groups ?? [], n = /* @__PURE__ */ new Map(), r = {};
571
- t.forEach((a) => {
572
- n.set(a.code, a), a.additional_config?.default !== void 0 && (r[a.code] = a.additional_config.default);
1393
+ t.forEach((s) => {
1394
+ n.set(s.code, s), s.additional_config?.default !== void 0 && (r[s.code] = s.additional_config.default);
573
1395
  });
574
- const i = t.filter((a) => !a.is_hidden);
1396
+ const i = t.filter((s) => !s.is_hidden);
575
1397
  return { fieldGroups: t, fieldByCode: n, visibleFieldGroups: i, initialValues: r };
576
1398
  }, [e]);
577
1399
  }
578
- function we(e) {
1400
+ function je(e) {
579
1401
  const t = {};
580
1402
  return e.forEach((n) => {
581
1403
  t[n.code] = {
@@ -585,731 +1407,846 @@ function we(e) {
585
1407
  };
586
1408
  }), t;
587
1409
  }
588
- function St(e) {
589
- const [t, n] = P(
590
- () => we(e)
1410
+ function un(e) {
1411
+ const [t, n] = L(
1412
+ () => je(e)
591
1413
  );
592
- V(() => {
593
- n(we(e));
1414
+ j(() => {
1415
+ n(je(e));
594
1416
  }, [e]);
595
- const r = T((i, a) => {
596
- n((s) => ({
597
- ...s,
598
- [i]: { ...s[i], ...a }
1417
+ const r = D((i, s) => {
1418
+ n((o) => ({
1419
+ ...o,
1420
+ [i]: { ...o[i], ...s }
599
1421
  }));
600
1422
  }, []);
601
1423
  return { fieldStates: t, setFieldStates: n, setFieldState: r };
602
1424
  }
603
- function Ft({
1425
+ function fn(e) {
1426
+ const t = {}, n = {};
1427
+ return e.forEach((r) => {
1428
+ t[r.containerKey] || (t[r.containerKey] = {}), t[r.containerKey][r.formCode] = r.value, n[r.fieldGroupCode] = [{ form_code: r.formCode }];
1429
+ }), { containers: t, formReferences: n };
1430
+ }
1431
+ function mn({
604
1432
  formInstance: e,
605
1433
  fieldByCode: t,
606
1434
  relatedData: n,
607
- transformers: r
1435
+ transformers: r,
1436
+ nestedFormRefs: i
608
1437
  }) {
609
- return { buildProcessedValues: T(async () => {
1438
+ return { buildProcessedValues: D(async () => {
610
1439
  await e.validateFields();
611
- const a = e.getFieldsValue(), s = {};
612
- for (const c of Object.keys(a)) {
613
- const y = t.get(c);
614
- if (!y) continue;
615
- let m;
616
- switch (y.field?.type?.code) {
1440
+ const o = e.getFieldsValue(), a = {}, m = [];
1441
+ for (const u of Object.keys(o)) {
1442
+ const c = t.get(u);
1443
+ if (!c) continue;
1444
+ let d;
1445
+ switch (c.field?.type?.code) {
617
1446
  case "datetime":
618
- m = a[c] ? Z(a[c]).format(
619
- y.additional_config?.datetime?.format
1447
+ d = o[u] ? ge(o[u]).format(
1448
+ c.additional_config?.datetime?.format
620
1449
  ) : null;
621
1450
  break;
622
1451
  case "image":
623
1452
  case "file":
624
- a[c]?.fileList?.length && (m = a[c].fileList.filter((l) => l.percent === 100).map((l) => ({
625
- ...l.response,
626
- name: l.name,
627
- type: l.type,
628
- size: l.size
1453
+ o[u]?.fileList?.length && (d = o[u].fileList.filter((p) => p.percent === 100).map((p) => ({
1454
+ ...p.response,
1455
+ name: p.name,
1456
+ type: p.type,
1457
+ size: p.size
629
1458
  })));
630
1459
  break;
1460
+ case "form":
1461
+ case "multiple-form": {
1462
+ const p = i.current.get(u);
1463
+ p?.ref.current ? d = await p.ref.current.getProcessedValues() : d = o[u], r.transformFieldValue && (d = r.transformFieldValue(u, d, c)), p ? m.push({
1464
+ fieldGroupCode: u,
1465
+ formCode: p.formCode,
1466
+ value: d,
1467
+ containerKey: Re(c)
1468
+ }) : a[u] = d;
1469
+ break;
1470
+ }
631
1471
  default:
632
- m = a[c];
1472
+ d = o[u];
633
1473
  }
634
- r.transformFieldValue && (m = r.transformFieldValue(c, m, y)), s[c] = m;
1474
+ c.field?.type?.code !== "form" && c.field?.type?.code !== "multiple-form" && (r.transformFieldValue && (d = r.transformFieldValue(u, d, c)), a[u] = d);
635
1475
  }
636
- let o = s;
637
- return r.transformSubmitValues && (o = r.transformSubmitValues(
638
- o,
1476
+ if (m.length > 0) {
1477
+ const { containers: u, formReferences: c } = fn(m);
1478
+ Object.assign(a, u), Object.keys(c).length > 0 && (a.form_references = c);
1479
+ }
1480
+ let f = a;
1481
+ return r.transformSubmitValues && (f = r.transformSubmitValues(
1482
+ f,
639
1483
  Array.from(t.values()),
640
1484
  n
641
- )), (r.parseRelatedDataTemplates ?? mt)(o, n ?? {});
642
- }, [t, e, n, r]) };
1485
+ )), (r.parseRelatedDataTemplates ?? Nt)(f, n ?? {});
1486
+ }, [t, e, i, n, r]) };
643
1487
  }
644
- const kt = Ne(
1488
+ const xe = _t(
645
1489
  ({
646
1490
  formConfig: e,
647
1491
  formInstance: t,
648
1492
  relatedData: n,
649
1493
  uploadUrl: r,
650
1494
  uploadResourceUrl: i,
651
- submitTrackingUrl: a,
652
- onBeforeSubmit: s,
653
- onSubmitSuccess: o,
654
- onSubmitError: d,
655
- isRedirectAfterCreate: c,
1495
+ submitTrackingUrl: s,
1496
+ onBeforeSubmit: o,
1497
+ onSubmitSuccess: a,
1498
+ onSubmitError: m,
1499
+ isRedirectAfterCreate: f,
656
1500
  onRedirect: y,
657
- size: m = "middle",
658
- manualSubmit: l = !1,
659
- onValuesChange: p,
660
- readOnly: h = !1,
661
- submitDebounceMs: u,
662
- gutter: v = [8, 0],
663
- defaultColSpan: _ = 12,
664
- submitButtonLabel: w
1501
+ size: u = "middle",
1502
+ manualSubmit: c = !1,
1503
+ onValuesChange: d,
1504
+ readOnly: p = !1,
1505
+ submitDebounceMs: h,
1506
+ gutter: _ = [8, 0],
1507
+ defaultColSpan: A = 12,
1508
+ submitButtonLabel: w,
1509
+ disableHtmlFormWrapper: S = !1
665
1510
  }, b) => {
666
- const { message: S } = He.useApp(), A = M(), { i18n: g, client: k, parsers: D, redirectHandler: j, renderers: K, transformers: $ } = A, ce = r ?? i, de = u ?? A.submitDebounceMs, ue = w ?? g.messages.submit, { fieldGroups: L, fieldByCode: Oe, initialValues: z } = At(e), { fieldStates: H, setFieldState: fe } = St(L), { buildProcessedValues: Y } = Ft({
1511
+ const { message: v } = pt.useApp(), T = U(), { i18n: F, client: R, parsers: $, redirectHandler: z, renderers: q, transformers: H } = T, ee = r ?? i, P = h ?? T.submitDebounceMs, Z = w ?? F.messages.submit, { fieldGroups: B, fieldByCode: fe, initialValues: g } = dn(e), { fieldStates: k, setFieldState: E } = un(B), M = I(/* @__PURE__ */ new Map()), O = D(
1512
+ (x, Y, G) => {
1513
+ if (Y && G) {
1514
+ M.current.set(x, { ref: Y, ...G });
1515
+ return;
1516
+ }
1517
+ M.current.delete(x);
1518
+ },
1519
+ []
1520
+ ), { buildProcessedValues: ne } = mn({
667
1521
  formInstance: t,
668
- fieldByCode: Oe,
1522
+ fieldByCode: fe,
669
1523
  relatedData: n,
670
- transformers: $
671
- }), N = B(!1), [me, pe] = P(!1), [he, ye] = P(!1);
672
- V(() => {
673
- if (Object.keys(z).length > 0) {
674
- const F = $.normalizeInitialValues ? $.normalizeInitialValues(z, L) : z;
675
- t.setFieldsValue(F);
1524
+ transformers: H,
1525
+ nestedFormRefs: M
1526
+ }), J = I(!1), [te, re] = L(!1), [me, Te] = L(!1);
1527
+ j(() => {
1528
+ if (Object.keys(g).length > 0) {
1529
+ const x = H.normalizeInitialValues ? H.normalizeInitialValues(g, B) : g;
1530
+ t.setFieldsValue(x);
676
1531
  }
677
- }, [L, t, z, $]);
678
- const J = T(async () => {
679
- if (!N.current) {
680
- N.current = !0, pe(!0);
1532
+ }, [B, t, g, H]);
1533
+ const pe = D(async () => {
1534
+ if (!J.current) {
1535
+ J.current = !0, re(!0);
681
1536
  try {
682
- let F = await Y();
1537
+ let x = await ne();
683
1538
  try {
684
- a && (ye(!0), await k.request({
1539
+ s && (Te(!0), await R.request({
685
1540
  method: "POST",
686
- url: a,
687
- data: F
1541
+ url: s,
1542
+ data: x
688
1543
  }));
689
- const E = await s?.(F);
690
- if (E === !1) return;
691
- E && typeof E == "object" && (F = E);
692
- } catch (E) {
693
- console.error(E);
1544
+ const K = await o?.(x);
1545
+ if (K === !1) return;
1546
+ K && typeof K == "object" && (x = K);
1547
+ } catch (K) {
1548
+ console.error(K);
694
1549
  return;
695
1550
  } finally {
696
- ye(!1);
1551
+ Te(!1);
697
1552
  }
698
- const O = await k.request({
1553
+ const Y = await R.request({
699
1554
  method: e.method,
700
1555
  url: e.action,
701
- data: F
1556
+ data: x
702
1557
  });
703
1558
  t.resetFields(
704
- L.filter((E) => !E.is_hidden).map((E) => E.code)
1559
+ B.filter((K) => !K.is_hidden).map((K) => K.code)
705
1560
  );
706
- const W = D.submitResponse(O.data);
707
- c && W.redirectUrl && (y ?? j)(W.redirectUrl, "_blank"), o?.({
708
- values: F,
709
- response: O.data,
710
- data: W.data ?? O.data
1561
+ const G = $.submitResponse(Y.data);
1562
+ f && G.redirectUrl && (y ?? z)(G.redirectUrl, "_blank"), a?.({
1563
+ values: x,
1564
+ response: Y.data,
1565
+ data: G.data ?? Y.data
711
1566
  });
712
- } catch (F) {
713
- const O = F;
714
- S.error(
715
- O?.response?.data?.message ?? g.messages.submitError
716
- ), d?.(F);
1567
+ } catch (x) {
1568
+ const Y = x;
1569
+ v.error(
1570
+ Y?.response?.data?.message ?? F.messages.submitError
1571
+ ), m?.(x);
717
1572
  } finally {
718
- N.current = !1, pe(!1);
1573
+ J.current = !1, re(!1);
719
1574
  }
720
1575
  }
721
1576
  }, [
722
- Y,
723
- k,
724
- L,
1577
+ ne,
1578
+ R,
1579
+ B,
725
1580
  e.action,
726
1581
  e.method,
727
1582
  t,
728
- g.messages.submitError,
729
- c,
730
- S,
731
- s,
732
- y,
733
- d,
1583
+ F.messages.submitError,
1584
+ f,
1585
+ v,
734
1586
  o,
735
- D,
736
- j,
737
- a
1587
+ y,
1588
+ m,
1589
+ a,
1590
+ $,
1591
+ z,
1592
+ s
738
1593
  ]);
739
- Je(
1594
+ bt(
740
1595
  b,
741
1596
  () => ({
742
- submit: J,
743
- getProcessedValues: Y,
744
- isSubmitting: () => N.current
1597
+ submit: pe,
1598
+ getProcessedValues: ne,
1599
+ isSubmitting: () => J.current
745
1600
  }),
746
- [Y, J]
1601
+ [ne, pe]
747
1602
  );
748
- const be = R(
749
- () => se(() => {
750
- J();
751
- }, de),
752
- [J, de]
753
- ), Ve = T(
754
- (F, O) => {
755
- Object.keys(F).forEach((W) => {
756
- const E = ht(
757
- W,
758
- L,
1603
+ const Me = C(
1604
+ () => Fe(() => {
1605
+ pe();
1606
+ }, P),
1607
+ [pe, P]
1608
+ ), it = D(
1609
+ (x, Y) => {
1610
+ Object.keys(x).forEach((G) => {
1611
+ const K = $t(
1612
+ G,
1613
+ B,
759
1614
  t.getFieldsValue()
760
1615
  );
761
- E.length > 0 && t.resetFields(E);
762
- }), p?.(F, O);
1616
+ K.length > 0 && t.resetFields(K);
1617
+ }), d?.(x, Y);
763
1618
  },
764
- [L, t, p]
765
- ), _e = T(
766
- (F) => /* @__PURE__ */ f(
767
- wt,
1619
+ [B, t, d]
1620
+ ), De = D(
1621
+ (x) => /* @__PURE__ */ l(
1622
+ cn,
768
1623
  {
769
- group: F,
1624
+ group: x,
770
1625
  formInstance: t,
771
- fieldState: H[F.code],
772
- setFieldState: fe,
773
- uploadUrl: ce,
774
- readOnly: h,
775
- size: m
1626
+ fieldState: k[x.code],
1627
+ setFieldState: E,
1628
+ uploadUrl: ee,
1629
+ readOnly: p,
1630
+ size: u,
1631
+ registerNestedForm: O
776
1632
  },
777
- F.id
1633
+ x.id
778
1634
  ),
779
1635
  [
780
- H,
1636
+ k,
781
1637
  t,
782
- h,
783
- ce,
784
- fe,
785
- m
1638
+ O,
1639
+ p,
1640
+ ee,
1641
+ E,
1642
+ u
786
1643
  ]
787
- ), qe = K.layout ? K.layout({
788
- fieldGroups: L,
789
- fieldStates: H,
790
- renderField: _e,
791
- gutter: v,
792
- defaultColSpan: _,
793
- size: m
794
- }) : /* @__PURE__ */ f(
795
- gt,
1644
+ ), ot = q.layout ? q.layout({
1645
+ fieldGroups: B,
1646
+ fieldStates: k,
1647
+ renderField: De,
1648
+ gutter: _,
1649
+ defaultColSpan: A,
1650
+ size: u
1651
+ }) : /* @__PURE__ */ l(
1652
+ ln,
796
1653
  {
797
- fieldGroups: L,
798
- fieldStates: H,
799
- renderField: _e,
800
- gutter: v,
801
- defaultColSpan: _,
802
- size: m
1654
+ fieldGroups: B,
1655
+ fieldStates: k,
1656
+ renderField: De,
1657
+ gutter: _,
1658
+ defaultColSpan: A,
1659
+ size: u
803
1660
  }
804
- ), Ue = !l && !h && (K.submitActions ? K.submitActions({
805
- onSubmit: be,
806
- loading: me || he,
807
- label: ue
808
- }) : /* @__PURE__ */ f(ie, { justify: "flex-end", children: /* @__PURE__ */ f(
809
- Ee,
1661
+ ), st = !c && !p && (q.submitActions ? q.submitActions({
1662
+ onSubmit: Me,
1663
+ loading: te || me,
1664
+ label: Z
1665
+ }) : /* @__PURE__ */ l(Se, { justify: "flex-end", children: /* @__PURE__ */ l(
1666
+ Ae,
810
1667
  {
811
1668
  type: "primary",
812
- onClick: be,
813
- loading: me || he,
814
- children: ue
1669
+ onClick: Me,
1670
+ loading: te || me,
1671
+ children: Z
815
1672
  }
816
1673
  ) }));
817
- return /* @__PURE__ */ Be(
818
- U,
1674
+ return /* @__PURE__ */ ae(
1675
+ X,
819
1676
  {
820
1677
  layout: "vertical",
821
1678
  form: t,
822
- size: m,
823
- onValuesChange: Ve,
1679
+ size: u,
1680
+ component: S ? !1 : void 0,
1681
+ onValuesChange: it,
824
1682
  children: [
825
- qe,
826
- Ue
1683
+ ot,
1684
+ st
827
1685
  ]
828
1686
  }
829
1687
  );
830
1688
  }
831
1689
  );
832
- kt.displayName = "DynamicForm";
833
- function De(e) {
834
- if (!e) return;
835
- const { mode: t } = e;
836
- if (t === "api" && e.api?.url)
837
- return e.api;
838
- if (t === "api_ids" && e.api_ids?.url) {
839
- const n = e.api_ids, r = n.method?.toUpperCase() === "POST";
840
- return {
841
- url: n.url,
842
- method: n.method,
843
- data_path: n.data_path,
844
- mapping_attr: n.mapping_attr,
845
- link: n.link,
846
- result_type: n.result_type ?? "array",
847
- params: n.params ?? (!r && !n.data ? { ids: "{{value}}" } : void 0),
848
- data: n.data ?? (r && !n.params ? { ids: "{{value}}" } : void 0)
849
- };
850
- }
851
- if (t === "api_detail" && e.api_detail?.url) {
852
- const n = e.api_detail;
853
- return {
854
- url: n.url,
855
- method: n.method,
856
- data_path: n.data_path,
857
- mapping_attr: n.mapping_attr,
858
- link: n.link,
859
- result_type: n.result_type ?? "object",
860
- url_template: n.url_template ?? !0,
861
- params: n.params,
862
- data: n.data
863
- };
864
- }
865
- }
866
- function ge(e) {
867
- return {
868
- value: e,
869
- id: e
870
- };
871
- }
872
- function Et(e, t) {
873
- const n = t.method || "GET", r = n.toUpperCase() === "GET";
874
- if (t.url_template)
875
- return (Array.isArray(e) ? e.filter((d) => d != null && d !== "") : e != null && e !== "" ? [e] : []).map((d) => {
876
- const c = ge(d), y = Q(t.url, c), m = t.params ? q(t.params, c) : void 0, l = t.data ? q(t.data, c) : void 0;
877
- return {
878
- method: n,
879
- url: y,
880
- params: r ? m : void 0,
881
- data: r ? void 0 : l
882
- };
883
- });
884
- const i = ge(e), a = t.params ? q(t.params, i) : void 0, s = t.data ? q(t.data, i) : void 0;
885
- return [
886
- {
887
- method: n,
888
- url: t.url,
889
- params: r ? a : void 0,
890
- data: r ? void 0 : s
891
- }
892
- ];
893
- }
894
- function Pe(e, t) {
895
- const n = t.data_path ? I(e, t.data_path) : e;
896
- return (t.result_type ?? (Array.isArray(n) ? "array" : "object")) === "array" ? Array.isArray(n) ? n : n != null ? [n] : [] : Array.isArray(n) ? n.length ? [n[0]] : [] : n && typeof n == "object" ? [n] : [];
897
- }
898
- function Te(e, t) {
899
- return Mt(e, t.mapping_attr);
900
- }
901
- function xe(e, t) {
902
- return jt(t.link, e);
903
- }
904
- async function Rt(e, t, n, r) {
905
- const i = Et(e, t);
906
- if (!i.length) return [];
907
- const a = await Promise.all(
908
- i.map((o) => n({ ...o, signal: r }))
909
- ), s = [];
910
- for (const o of a)
911
- s.push(...Pe(o.data, t));
912
- return s;
913
- }
914
- function G(e) {
915
- return !!(e == null || e === "" || Array.isArray(e) && e.length === 0);
916
- }
917
- function Dt(e, t) {
918
- const n = e.option_config?.api_options?.params, r = e.option_config?.api_options?.data;
919
- if (!n && !r) return;
920
- const i = (a) => {
921
- const s = {};
922
- for (const o in a)
923
- if (typeof a[o] == "string" && a[o].startsWith("{{") && a[o].endsWith("}}")) {
924
- const d = a[o].slice(2, -2).trim();
925
- s[o] = t?.[d];
926
- } else
927
- s[o] = a[o];
928
- return s;
929
- };
930
- return {
931
- params: n ? i(n) : void 0,
932
- data: r ? i(r) : void 0
933
- };
934
- }
935
- function Pt(e, t) {
936
- const n = t.option_config?.label_attr, r = t.option_config?.value_attr || "";
937
- if (n?.length) {
938
- const i = n.join(" - ");
939
- return e[i] !== void 0 ? String(e[i]) : n.map((a) => e[a]).filter((a) => a != null && a !== "").join(" - ");
940
- }
941
- return String(e[r] ?? "");
942
- }
943
- function Tt(e, t) {
944
- if (!t?.length) return null;
945
- const r = (Array.isArray(e) ? e : [e]).map((i) => t.find((a) => String(a.value) === String(i))?.label).filter((i) => !!i);
946
- return r.length ? r.join(", ") : null;
947
- }
948
- function xt(e, t, n) {
949
- if (G(e)) return null;
950
- const r = t.option_config?.value_attr || "value", i = Array.isArray(e) ? e : [e];
951
- if (t.is_option_api && n?.length) {
952
- const s = i.map((o) => {
953
- const d = n.find(
954
- (c) => String(c[r]) === String(o)
955
- );
956
- return d ? Pt(d, t) : String(o);
957
- }).filter(Boolean);
958
- return s.length ? s.join(", ") : null;
959
- }
960
- const a = Tt(e, t.metas);
961
- return a || i.map(String).join(", ");
962
- }
963
- function Lt(e, t) {
964
- if (G(e)) return null;
965
- const n = t.additional_config?.datetime?.format, r = Z(e);
966
- return r.isValid() ? n ? r.format(n) : r.format("YYYY-MM-DD HH:mm:ss") : String(e);
967
- }
968
- function Ct(e) {
969
- if (G(e)) return null;
970
- if (Array.isArray(e)) {
971
- const t = e.map(
972
- (n) => typeof n == "object" && n && "name" in n ? String(n.name) : String(n)
973
- ).filter(Boolean);
974
- return t.length ? t.join(", ") : null;
975
- }
976
- return String(e);
977
- }
978
- function Mt(e, t) {
979
- return t?.length ? t.map((n) => {
980
- const r = I(e, n) ?? e[n];
981
- return r != null ? String(r) : "";
982
- }).filter(Boolean).join(" - ") : JSON.stringify(e);
983
- }
984
- function jt(e, t) {
985
- return e ? e.replace(/\{\{(.+?)\}\}/g, (n, r) => {
986
- const i = r.trim(), a = I(t, i) ?? t[i];
987
- return a != null ? String(a) : "";
988
- }) : null;
989
- }
990
- function Ae(e, t, n) {
991
- if (G(e)) return null;
992
- switch (t?.mode ?? "formatted") {
993
- case "raw":
994
- case "formatted":
995
- return Array.isArray(e) ? e.map(String).join(", ") : String(e);
996
- case "api":
997
- case "api_ids":
998
- case "api_detail": {
999
- const i = De(t);
1000
- if (!n || !i)
1001
- return Array.isArray(e) ? e.map(String).join(", ") : String(e);
1002
- const a = Pe(n, i);
1003
- return a.length ? a.map((o) => {
1004
- const d = Te(o, i), c = xe(o, i);
1005
- return c ? `${d} (${c})` : d;
1006
- }).filter(Boolean).join(", ") || null : String(e);
1007
- }
1008
- default:
1009
- return String(e);
1010
- }
1011
- }
1012
- function Ot(e, t, n) {
1013
- const r = e.additional_config?.view_value;
1014
- if (r?.mode === "api" || r?.mode === "api_ids" || r?.mode === "api_detail")
1015
- return Ae(
1016
- t,
1017
- r,
1018
- n.viewValueFetched
1019
- );
1020
- switch (e.field?.type?.code) {
1021
- case "text":
1022
- case "number":
1023
- return G(t) ? null : String(t);
1024
- case "datetime":
1025
- return Lt(t, e);
1026
- case "select":
1027
- case "radio":
1028
- case "checkbox":
1029
- return xt(t, e, n.optionList);
1030
- case "image":
1031
- case "file":
1032
- return Ct(t);
1033
- default:
1034
- return r ? Ae(
1035
- t,
1036
- r,
1037
- n.viewValueFetched
1038
- ) : G(t) ? null : String(t);
1039
- }
1040
- }
1041
- const X = /* @__PURE__ */ new Map(), Vt = 3e4;
1042
- function qt(e) {
1043
- const t = X.get(e);
1690
+ xe.displayName = "DynamicForm";
1691
+ const _e = /* @__PURE__ */ new Map(), pn = 3e4;
1692
+ function yn(e) {
1693
+ const t = _e.get(e);
1044
1694
  if (t) {
1045
1695
  if (Date.now() > t.expiresAt) {
1046
- X.delete(e);
1696
+ _e.delete(e);
1047
1697
  return;
1048
1698
  }
1049
1699
  return t.error;
1050
1700
  }
1051
1701
  }
1052
- function Se(e, t) {
1053
- X.set(e, {
1702
+ function Oe(e, t) {
1703
+ _e.set(e, {
1054
1704
  error: t,
1055
- expiresAt: Date.now() + Vt
1705
+ expiresAt: Date.now() + pn
1056
1706
  });
1057
1707
  }
1058
- function ee(e, t, n = !0) {
1059
- const r = M(), [i, a] = P(), [s, o] = P(!1), [d, c] = P(), y = B(t), m = B(r);
1060
- y.current = t, m.current = r;
1061
- const l = le(e);
1062
- return V(() => {
1708
+ function ue(e, t, n = !0) {
1709
+ const r = U(), [i, s] = L(), [o, a] = L(!1), [m, f] = L(), y = I(t), u = I(r);
1710
+ y.current = t, u.current = r;
1711
+ const c = le(e);
1712
+ return j(() => {
1063
1713
  if (!n) {
1064
- a(void 0), c(void 0), o(!1);
1714
+ s(void 0), f(void 0), a(!1);
1065
1715
  return;
1066
1716
  }
1067
- const h = qt(l);
1068
- if (h !== void 0) {
1069
- c(h), o(!1);
1717
+ const p = yn(c);
1718
+ if (p !== void 0) {
1719
+ f(p), a(!1);
1070
1720
  return;
1071
1721
  }
1072
- const u = new AbortController();
1073
- return o(!0), c(void 0), (async () => {
1722
+ const h = new AbortController();
1723
+ return a(!0), f(void 0), (async () => {
1074
1724
  try {
1075
- const _ = await re(
1076
- m.current,
1725
+ const A = await de(
1726
+ u.current,
1077
1727
  "viewCache",
1078
- l,
1728
+ c,
1079
1729
  (w) => y.current(w),
1080
- u.signal
1730
+ h.signal
1081
1731
  );
1082
- u.signal.aborted || (a(_), c(void 0));
1083
- } catch (_) {
1084
- u.signal.aborted || (Se(l, _), c(_));
1732
+ h.signal.aborted || (s(A), f(void 0));
1733
+ } catch (A) {
1734
+ h.signal.aborted || (Oe(c, A), f(A));
1085
1735
  } finally {
1086
- u.signal.aborted || o(!1);
1736
+ h.signal.aborted || a(!1);
1087
1737
  }
1088
- })(), () => u.abort();
1089
- }, [n, l]), { data: i, isLoading: s, error: d, refetch: async () => {
1090
- if (X.delete(l), !n) return;
1091
- const h = new AbortController();
1092
- o(!0), c(void 0);
1738
+ })(), () => h.abort();
1739
+ }, [n, c]), { data: i, isLoading: o, error: m, refetch: async () => {
1740
+ if (_e.delete(c), !n) return;
1741
+ const p = new AbortController();
1742
+ a(!0), f(void 0);
1093
1743
  try {
1094
- const u = await re(
1095
- m.current,
1744
+ const h = await de(
1745
+ u.current,
1096
1746
  "viewCache",
1097
- l,
1098
- (v) => y.current(v),
1099
- h.signal
1747
+ c,
1748
+ (_) => y.current(_),
1749
+ p.signal
1100
1750
  );
1101
- return a(u), u;
1102
- } catch (u) {
1103
- throw Se(l, u), c(u), u;
1751
+ return s(h), h;
1752
+ } catch (h) {
1753
+ throw Oe(c, h), f(h), h;
1104
1754
  } finally {
1105
- o(!1);
1755
+ a(!1);
1106
1756
  }
1107
1757
  } };
1108
1758
  }
1109
- const Ut = ({ value: e, code: t, modeConfig: n }) => {
1110
- const { client: r, renderers: i, i18n: a } = M(), s = R(
1759
+ const hn = ({ value: e, code: t, modeConfig: n }) => {
1760
+ const { client: r, renderers: i, i18n: s } = U(), o = C(
1111
1761
  () => (Array.isArray(e) ? e : [e]).filter(Boolean),
1112
1762
  [e]
1113
1763
  ), {
1114
- data: o,
1115
- isLoading: d,
1116
- error: c
1117
- } = ee(
1118
- ["api_detail", t, s, n?.url, n?.method],
1119
- async (l) => (await Promise.all(
1120
- s.map(async (h) => {
1121
- const u = Q(n?.url || "", { id: h });
1764
+ data: a,
1765
+ isLoading: m,
1766
+ error: f
1767
+ } = ue(
1768
+ ["api_detail", t, o, n?.url, n?.method],
1769
+ async (c) => (await Promise.all(
1770
+ o.map(async (p) => {
1771
+ const h = he(n?.url || "", { id: p });
1122
1772
  return (await r.request({
1123
1773
  method: n?.method,
1124
- url: u,
1125
- signal: l
1774
+ url: h,
1775
+ signal: c
1126
1776
  })).data;
1127
1777
  })
1128
1778
  )).filter(Boolean),
1129
- !!(s.length && n?.url)
1130
- ), y = (l, p, h) => i.link ? i.link({ url: l, label: p, data: h }) : /* @__PURE__ */ f("a", { href: l, target: "_blank", rel: "noreferrer", children: p }), m = (l) => {
1131
- const p = n?.mapping_attr?.map((h) => l?.[h]).join(" - ");
1779
+ !!(o.length && n?.url)
1780
+ ), y = (c, d, p) => i.link ? i.link({ url: c, label: d, data: p }) : /* @__PURE__ */ l("a", { href: c, target: "_blank", rel: "noreferrer", children: d }), u = (c) => {
1781
+ const d = n?.mapping_attr?.map((p) => c?.[p]).join(" - ");
1132
1782
  if (n?.link) {
1133
- const h = Q(n.link, l);
1134
- return y(h, p, l);
1783
+ const p = he(n.link, c);
1784
+ return y(p, d, c);
1135
1785
  }
1136
- return p;
1786
+ return d;
1137
1787
  };
1138
- return d ? /* @__PURE__ */ f(x, { children: i.viewLoading?.() ?? /* @__PURE__ */ f(ae, { size: "small" }) }) : c ? /* @__PURE__ */ f(x, { children: i.viewError?.(c) ?? a.messages.viewError }) : o?.length ? /* @__PURE__ */ f(x, { children: o.map((l, p) => /* @__PURE__ */ f("div", { children: m(l) }, p)) }) : /* @__PURE__ */ f(x, { children: i.viewEmpty?.() ?? a.messages.viewEmpty });
1139
- }, Le = C(Ut), Bt = ({ value: e, code: t, modeConfig: n }) => {
1140
- const { client: r, renderers: i, i18n: a } = M(), {
1141
- data: s,
1142
- isLoading: o,
1143
- error: d
1144
- } = ee(
1788
+ return m ? /* @__PURE__ */ l(V, { children: i.viewLoading?.() ?? /* @__PURE__ */ l(be, { size: "small" }) }) : f ? /* @__PURE__ */ l(V, { children: i.viewError?.(f) ?? s.messages.viewError }) : a?.length ? /* @__PURE__ */ l(V, { children: a.map((c, d) => /* @__PURE__ */ l("div", { children: u(c) }, d)) }) : /* @__PURE__ */ l(V, { children: i.viewEmpty?.() ?? s.messages.viewEmpty });
1789
+ }, Qe = Q(hn), _n = ({ value: e, code: t, modeConfig: n }) => {
1790
+ const { client: r, renderers: i, i18n: s } = U(), {
1791
+ data: o,
1792
+ isLoading: a,
1793
+ error: m
1794
+ } = ue(
1145
1795
  ["api_ids", t, e, n?.url, n?.method],
1146
- async (m) => {
1147
- const l = n?.method || "GET", p = l.toUpperCase() === "POST", h = Array.isArray(e) ? e : [e], v = (await r.request({
1148
- method: l,
1796
+ async (u) => {
1797
+ const c = n?.method || "GET", d = c.toUpperCase() === "POST", p = Array.isArray(e) ? e : [e], _ = (await r.request({
1798
+ method: c,
1149
1799
  url: n?.url || "",
1150
- data: p ? { ids: h } : void 0,
1151
- params: p ? void 0 : { ids: h },
1152
- signal: m
1153
- })).data, _ = n?.data_path ? I(v, n.data_path) : v;
1154
- return Array.isArray(_) ? _ : v;
1800
+ data: d ? { ids: p } : void 0,
1801
+ params: d ? void 0 : { ids: p },
1802
+ signal: u
1803
+ })).data, A = n?.data_path ? se(_, n.data_path) : _;
1804
+ return Array.isArray(A) ? A : _;
1155
1805
  },
1156
1806
  !!(e && n?.url)
1157
- ), c = (m, l, p) => i.link ? i.link({ url: m, label: l, data: p }) : /* @__PURE__ */ f("a", { href: m, target: "_blank", rel: "noreferrer", children: l }), y = (m) => {
1158
- const l = n?.mapping_attr?.map((p) => m?.[p]).join(" - ");
1807
+ ), f = (u, c, d) => i.link ? i.link({ url: u, label: c, data: d }) : /* @__PURE__ */ l("a", { href: u, target: "_blank", rel: "noreferrer", children: c }), y = (u) => {
1808
+ const c = n?.mapping_attr?.map((d) => u?.[d]).join(" - ");
1159
1809
  if (n?.link) {
1160
- const p = Q(n.link, m);
1161
- return c(p, l, m);
1810
+ const d = he(n.link, u);
1811
+ return f(d, c, u);
1162
1812
  }
1163
- return l;
1813
+ return c;
1164
1814
  };
1165
- return o ? /* @__PURE__ */ f(x, { children: i.viewLoading?.() ?? /* @__PURE__ */ f(ae, { size: "small" }) }) : d ? /* @__PURE__ */ f(x, { children: i.viewError?.(d) ?? a.messages.viewError }) : s ? Array.isArray(e) ? /* @__PURE__ */ f(ie, { vertical: !0, children: (Array.isArray(s) ? s : [s]).map((m, l) => /* @__PURE__ */ f("div", { children: y(m) }, m.id ?? l)) }) : y(
1166
- Array.isArray(s) ? s[0] : s
1167
- ) : /* @__PURE__ */ f(x, { children: i.viewEmpty?.() ?? a.messages.viewEmpty });
1168
- }, Ce = C(Bt), Gt = ({
1815
+ return a ? /* @__PURE__ */ l(V, { children: i.viewLoading?.() ?? /* @__PURE__ */ l(be, { size: "small" }) }) : m ? /* @__PURE__ */ l(V, { children: i.viewError?.(m) ?? s.messages.viewError }) : o ? Array.isArray(e) ? /* @__PURE__ */ l(Se, { vertical: !0, children: (Array.isArray(o) ? o : [o]).map((u, c) => /* @__PURE__ */ l("div", { children: y(u) }, u.id ?? c)) }) : y(
1816
+ Array.isArray(o) ? o[0] : o
1817
+ ) : /* @__PURE__ */ l(V, { children: i.viewEmpty?.() ?? s.messages.viewEmpty });
1818
+ }, Ze = Q(_n), bn = ({
1169
1819
  value: e,
1170
1820
  code: t,
1171
1821
  modeConfig: n,
1172
1822
  viewConfig: r
1173
1823
  }) => {
1174
- const { client: i, renderers: a, i18n: s } = M(), o = R(
1175
- () => n ?? (r ? De(r) : void 0),
1824
+ const { client: i, renderers: s, i18n: o } = U(), a = C(
1825
+ () => n ?? (r ? Ue(r) : void 0),
1176
1826
  [n, r]
1177
- ), d = R(
1178
- () => ["api_view", t, e, o?.url, o?.method, o?.data_path],
1179
- [t, e, o?.url, o?.method, o?.data_path]
1180
- ), c = T(
1181
- async (u) => o ? Rt(
1827
+ ), m = C(
1828
+ () => ["api_view", t, e, a?.url, a?.method, a?.data_path],
1829
+ [t, e, a?.url, a?.method, a?.data_path]
1830
+ ), f = D(
1831
+ async (h) => a ? Vt(
1182
1832
  e,
1183
- o,
1184
- (v) => i.request({ ...v, signal: u })
1833
+ a,
1834
+ (_) => i.request({ ..._, signal: h })
1185
1835
  ) : [],
1186
- [i, o, e]
1187
- ), { data: y, isLoading: m, error: l } = ee(d, c, !!(e && o?.url)), p = (u, v, _) => a.link ? a.link({ url: u, label: v, data: _ }) : /* @__PURE__ */ f("a", { href: u, target: "_blank", rel: "noreferrer", children: v }), h = (u, v) => {
1188
- if (!o) return null;
1189
- const _ = Te(u, o), w = xe(u, o), b = w ? p(w, _, u) : _;
1190
- return /* @__PURE__ */ f("div", { children: b }, u.id ?? v);
1836
+ [i, a, e]
1837
+ ), { data: y, isLoading: u, error: c } = ue(m, f, !!(e && a?.url)), d = (h, _, A) => s.link ? s.link({ url: h, label: _, data: A }) : /* @__PURE__ */ l("a", { href: h, target: "_blank", rel: "noreferrer", children: _ }), p = (h, _) => {
1838
+ if (!a) return null;
1839
+ const A = We(h, a), w = $e(h, a), S = w ? d(w, A, h) : A;
1840
+ return /* @__PURE__ */ l("div", { children: S }, h.id ?? _);
1191
1841
  };
1192
- return m ? /* @__PURE__ */ f(x, { children: a.viewLoading?.() ?? /* @__PURE__ */ f(ae, { size: "small" }) }) : l ? /* @__PURE__ */ f(x, { children: a.viewError?.(l) ?? s.messages.viewError }) : y?.length ? o?.result_type === "object" && y.length === 1 ? h(y[0], 0) : /* @__PURE__ */ f(ie, { vertical: !0, children: y.map(h) }) : /* @__PURE__ */ f(x, { children: a.viewEmpty?.() ?? s.messages.viewEmpty });
1193
- }, Me = C(Gt);
1194
- function It(e) {
1842
+ return u ? /* @__PURE__ */ l(V, { children: s.viewLoading?.() ?? /* @__PURE__ */ l(be, { size: "small" }) }) : c ? /* @__PURE__ */ l(V, { children: s.viewError?.(c) ?? o.messages.viewError }) : y?.length ? a?.result_type === "object" && y.length === 1 ? p(y[0], 0) : /* @__PURE__ */ l(Se, { vertical: !0, children: y.map(p) }) : /* @__PURE__ */ l(V, { children: s.viewEmpty?.() ?? o.messages.viewEmpty });
1843
+ }, Ge = Q(bn), gn = {
1844
+ whiteSpace: "normal",
1845
+ wordBreak: "break-word",
1846
+ verticalAlign: "top"
1847
+ }, et = ({
1848
+ group: e,
1849
+ value: t,
1850
+ formValues: n = {}
1851
+ }) => {
1852
+ const r = U(), i = e.additional_config?.multiple_form, s = i?.config_url, o = i?.method ?? "GET", {
1853
+ data: a,
1854
+ isLoading: m,
1855
+ error: f
1856
+ } = we(
1857
+ [s, o],
1858
+ async () => {
1859
+ if (!s)
1860
+ throw new Error("Missing additional_config.multiple_form.config_url");
1861
+ const d = await r.client.request({
1862
+ method: o,
1863
+ url: s
1864
+ });
1865
+ return r.parsers.formConfigResponse(d.data);
1866
+ },
1867
+ { enabled: !!s }
1868
+ ), y = C(() => {
1869
+ if (!a) return [];
1870
+ if (t && typeof t == "object" && !Array.isArray(t)) {
1871
+ const d = t;
1872
+ if (a.code in d && Array.isArray(d[a.code]))
1873
+ return d[a.code];
1874
+ }
1875
+ return Array.isArray(t) ? t : Je(
1876
+ e,
1877
+ { ...n, [e.code]: t },
1878
+ a.code
1879
+ );
1880
+ }, [n, e, a, t]), u = C(() => a ? [...a.field_groups].filter((d) => !d.is_hidden).sort(
1881
+ (d, p) => Number(d.position ?? 0) - Number(p.position ?? 0)
1882
+ ).map((d) => ({
1883
+ key: d.code,
1884
+ title: d.label,
1885
+ dataIndex: d.code,
1886
+ width: 140,
1887
+ onCell: () => ({
1888
+ style: gn
1889
+ }),
1890
+ render: (p, h) => /* @__PURE__ */ l(
1891
+ tt,
1892
+ {
1893
+ code: d.code,
1894
+ value: h[d.code],
1895
+ fieldGroup: d,
1896
+ formValues: h
1897
+ }
1898
+ )
1899
+ })) : [], [a]), c = C(
1900
+ () => y.map((d, p) => ({
1901
+ key: p,
1902
+ ...d
1903
+ })),
1904
+ [y]
1905
+ );
1906
+ return s ? m ? /* @__PURE__ */ l(N, { type: "info", message: "Loading...", showIcon: !0 }) : f || !a ? /* @__PURE__ */ l(N, { type: "error", message: "Failed to load nested form", showIcon: !0 }) : y.length === 0 ? "-" : /* @__PURE__ */ l(
1907
+ "div",
1908
+ {
1909
+ style: {
1910
+ width: "100%",
1911
+ maxWidth: "100%",
1912
+ overflowX: "auto",
1913
+ overflowY: "hidden"
1914
+ },
1915
+ children: /* @__PURE__ */ l(
1916
+ yt,
1917
+ {
1918
+ size: "small",
1919
+ bordered: !0,
1920
+ pagination: {
1921
+ pageSize: 5,
1922
+ hideOnSinglePage: !0,
1923
+ size: "small"
1924
+ },
1925
+ columns: u,
1926
+ dataSource: c
1927
+ }
1928
+ )
1929
+ }
1930
+ ) : /* @__PURE__ */ l(
1931
+ N,
1932
+ {
1933
+ type: "warning",
1934
+ message: "Missing multiple_form config_url",
1935
+ showIcon: !0
1936
+ }
1937
+ );
1938
+ }, wn = ({
1939
+ value: e,
1940
+ fieldGroup: t,
1941
+ formValues: n = {}
1942
+ }) => {
1943
+ const r = U(), { renderers: i } = r, s = C(
1944
+ () => Ee(e, t.metas),
1945
+ [t.metas, e]
1946
+ ), o = !!(t.is_option_api && t.option_config?.url), a = o && !s && !W(e), {
1947
+ data: m,
1948
+ isLoading: f,
1949
+ error: y
1950
+ } = ue(
1951
+ [
1952
+ "selectLikeView",
1953
+ t.code,
1954
+ t.option_config?.url,
1955
+ t.option_config?.method,
1956
+ e,
1957
+ n
1958
+ ],
1959
+ async (u) => {
1960
+ const c = Ce(t, n), d = t.option_config?.method?.toUpperCase() === "GET" || !t.option_config?.method, h = { [t.option_config?.value_attr || "value"]: e }, _ = await r.client.request({
1961
+ method: t.option_config?.method || "GET",
1962
+ url: t.option_config?.url || "",
1963
+ params: d ? {
1964
+ ...c?.params,
1965
+ filter: {
1966
+ ...c?.params?.filter,
1967
+ ...h
1968
+ }
1969
+ } : c?.params,
1970
+ data: d ? c?.data : {
1971
+ ...c?.data,
1972
+ filter: {
1973
+ ...c?.data?.filter,
1974
+ ...h
1975
+ }
1976
+ },
1977
+ signal: u
1978
+ });
1979
+ return r.parsers.optionResponse(_.data, t);
1980
+ },
1981
+ a
1982
+ );
1983
+ return W(e) ? /* @__PURE__ */ l(V, { children: i.viewEmpty?.() ?? "-" }) : s ? /* @__PURE__ */ l(V, { children: s }) : o ? f ? /* @__PURE__ */ l(V, { children: i.viewLoading?.() ?? /* @__PURE__ */ l(be, { size: "small" }) }) : y ? /* @__PURE__ */ l(V, { children: i.viewError?.(y) ?? oe(e, t) ?? String(e) }) : /* @__PURE__ */ l(V, { children: oe(e, t, m) ?? String(e) }) : /* @__PURE__ */ l(V, { children: oe(e, t) ?? String(e) });
1984
+ }, vn = Q(wn), An = ({
1985
+ code: e,
1986
+ value: t,
1987
+ fieldGroup: n,
1988
+ formValues: r
1989
+ }) => {
1990
+ const i = n?.field?.type?.code, s = r ?? { [e]: t };
1991
+ if (i === "form" && n)
1992
+ return /* @__PURE__ */ l(
1993
+ nt,
1994
+ {
1995
+ group: n,
1996
+ value: t,
1997
+ formValues: s
1998
+ }
1999
+ );
2000
+ if (i === "multiple-form" && n)
2001
+ return /* @__PURE__ */ l(
2002
+ et,
2003
+ {
2004
+ group: n,
2005
+ value: t,
2006
+ formValues: s
2007
+ }
2008
+ );
2009
+ const o = n?.additional_config?.view_value, a = t == null ? "" : String(t);
2010
+ if ((i === "select" || i === "radio" || i === "checkbox") && n && !o?.mode)
2011
+ return /* @__PURE__ */ l(
2012
+ vn,
2013
+ {
2014
+ value: t,
2015
+ fieldGroup: n,
2016
+ formValues: s
2017
+ }
2018
+ );
2019
+ if (i === "datetime" && n && !o?.mode)
2020
+ return /* @__PURE__ */ l(V, { children: ze(t, n) ?? (W(t) ? "-" : a) });
2021
+ switch (o?.mode) {
2022
+ case "raw":
2023
+ return a;
2024
+ case "api":
2025
+ return /* @__PURE__ */ l(Ge, { code: e, value: a, viewConfig: o });
2026
+ case "api_ids": {
2027
+ const m = o?.api_ids;
2028
+ return /* @__PURE__ */ l(Ze, { code: e, value: a, modeConfig: m });
2029
+ }
2030
+ case "api_detail": {
2031
+ const m = o?.api_detail;
2032
+ return /* @__PURE__ */ l(Qe, { code: e, value: a, modeConfig: m });
2033
+ }
2034
+ default:
2035
+ return a;
2036
+ }
2037
+ }, tt = Q(An), Sn = {
2038
+ flexShrink: 0,
2039
+ whiteSpace: "nowrap",
2040
+ color: "rgba(0, 0, 0, 0.45)"
2041
+ }, kn = {
2042
+ flex: 1,
2043
+ minWidth: 0,
2044
+ whiteSpace: "normal",
2045
+ wordBreak: "break-word"
2046
+ }, Fn = {
2047
+ display: "flex",
2048
+ alignItems: "flex-start",
2049
+ gap: 12,
2050
+ marginBottom: 8
2051
+ }, Cn = ({
2052
+ fieldGroups: e,
2053
+ values: t
2054
+ }) => {
2055
+ const n = C(() => [...e].sort(
2056
+ (r, i) => Number(r.position ?? 0) - Number(i.position ?? 0)
2057
+ ).filter((r) => !r.is_hidden && r.code in t).map((r) => ({
2058
+ key: r.code,
2059
+ label: r.label,
2060
+ content: /* @__PURE__ */ l(
2061
+ tt,
2062
+ {
2063
+ code: r.code,
2064
+ value: t[r.code],
2065
+ fieldGroup: r,
2066
+ formValues: t
2067
+ }
2068
+ )
2069
+ })), [e, t]);
2070
+ return n.length === 0 ? /* @__PURE__ */ l(V, { children: "-" }) : /* @__PURE__ */ l("div", { style: { width: "100%" }, children: n.map((r) => /* @__PURE__ */ ae("div", { style: Fn, children: [
2071
+ /* @__PURE__ */ ae("div", { style: Sn, children: [
2072
+ r.label,
2073
+ ":"
2074
+ ] }),
2075
+ /* @__PURE__ */ l("div", { style: kn, children: r.content })
2076
+ ] }, r.key)) });
2077
+ }, nt = ({
2078
+ group: e,
2079
+ value: t,
2080
+ formValues: n = {}
2081
+ }) => {
2082
+ const r = U(), i = e.additional_config?.form?.config_url, s = e.additional_config?.form?.method ?? "GET", {
2083
+ data: o,
2084
+ isLoading: a,
2085
+ error: m
2086
+ } = we(
2087
+ [i, s],
2088
+ async () => {
2089
+ if (!i)
2090
+ throw new Error("Missing additional_config.form.config_url");
2091
+ const y = await r.client.request({
2092
+ method: s,
2093
+ url: i
2094
+ });
2095
+ return r.parsers.formConfigResponse(y.data);
2096
+ },
2097
+ { enabled: !!i }
2098
+ ), f = C(() => {
2099
+ if (o) {
2100
+ if (t && typeof t == "object" && !Array.isArray(t)) {
2101
+ const y = t;
2102
+ if (o.code in y) {
2103
+ const u = y[o.code];
2104
+ return u && typeof u == "object" && !Array.isArray(u) ? u : void 0;
2105
+ }
2106
+ return y;
2107
+ }
2108
+ return Kt(
2109
+ e,
2110
+ { ...n, [e.code]: t },
2111
+ o.code
2112
+ );
2113
+ }
2114
+ }, [n, e, o, t]);
2115
+ return i ? a ? /* @__PURE__ */ l(N, { type: "info", message: "Loading...", showIcon: !0 }) : m || !o ? /* @__PURE__ */ l(N, { type: "error", message: "Failed to load nested form", showIcon: !0 }) : !f || Object.keys(f).length === 0 ? "-" : /* @__PURE__ */ l(
2116
+ Cn,
2117
+ {
2118
+ fieldGroups: o.field_groups,
2119
+ values: f
2120
+ }
2121
+ ) : /* @__PURE__ */ l(N, { type: "warning", message: "Missing nested form config_url", showIcon: !0 });
2122
+ };
2123
+ function En(e) {
1195
2124
  return !!(e.option_config && e.is_option_api);
1196
2125
  }
1197
- function Wt(e, t) {
1198
- const n = M(), r = le([
2126
+ function Rn(e, t) {
2127
+ const n = U(), r = le([
1199
2128
  "viewModeOptions",
1200
- e.map((a) => a.code),
2129
+ e.map((s) => s.code),
1201
2130
  t
1202
- ]), { data: i } = ee(
2131
+ ]), { data: i } = ue(
1203
2132
  [r],
1204
- async (a) => {
1205
- const s = {};
2133
+ async (s) => {
2134
+ const o = {};
1206
2135
  return await Promise.all(
1207
- e.map(async (o) => {
1208
- if (!o.option_config?.url) return;
1209
- const d = Dt(o, t), c = o.option_config.method?.toUpperCase() === "GET" || !o.option_config.method, y = await n.client.request({
1210
- method: o.option_config.method || "GET",
1211
- url: o.option_config.url,
1212
- params: c ? d?.params : void 0,
1213
- data: c ? void 0 : d?.data,
1214
- signal: a
2136
+ e.map(async (a) => {
2137
+ if (!a.option_config?.url) return;
2138
+ const m = Ce(a, t), f = a.option_config.method?.toUpperCase() === "GET" || !a.option_config.method, y = await n.client.request({
2139
+ method: a.option_config.method || "GET",
2140
+ url: a.option_config.url,
2141
+ params: f ? m?.params : void 0,
2142
+ data: f ? void 0 : m?.data,
2143
+ signal: s
1215
2144
  });
1216
- s[o.code] = {
1217
- optionList: n.parsers.optionResponse(y.data, o)
2145
+ o[a.code] = {
2146
+ optionList: n.parsers.optionResponse(y.data, a)
1218
2147
  };
1219
2148
  })
1220
- ), s;
2149
+ ), o;
1221
2150
  },
1222
2151
  e.length > 0
1223
2152
  );
1224
2153
  return i ?? {};
1225
2154
  }
1226
- const nn = ({
2155
+ const Kn = ({
1227
2156
  formConfig: e,
1228
2157
  formValues: t
1229
2158
  }) => {
1230
- const n = e?.form?.field_groups ?? [], r = R(
1231
- () => n.filter(It),
2159
+ const n = e?.form?.field_groups ?? [], r = C(
2160
+ () => n.filter(En),
1232
2161
  [n]
1233
- ), i = Wt(r, t);
1234
- return R(() => n.filter((s) => !s.is_hidden).map((s) => {
1235
- const o = t?.[s.code], d = s.additional_config?.view_value, c = d?.mode;
1236
- if (c === "api" && d)
2162
+ ), i = Rn(r, t);
2163
+ return C(() => n.filter((o) => !o.is_hidden).map((o) => {
2164
+ const a = t?.[o.code], m = o.field?.type?.code, f = o.additional_config?.view_value, y = f?.mode;
2165
+ if (m === "form")
1237
2166
  return {
1238
- key: s.code,
1239
- label: s.label,
1240
- rawValue: o,
1241
- viewValue: /* @__PURE__ */ f(
1242
- Me,
2167
+ key: o.code,
2168
+ label: o.label,
2169
+ rawValue: a,
2170
+ viewValue: /* @__PURE__ */ l(
2171
+ nt,
1243
2172
  {
1244
- code: s.code,
1245
- value: o,
1246
- viewConfig: d
2173
+ group: o,
2174
+ value: a,
2175
+ formValues: t
1247
2176
  }
1248
2177
  ),
1249
- field_group: s
2178
+ field_group: o
1250
2179
  };
1251
- if (c === "api_ids" && d?.api_ids)
2180
+ if (m === "multiple-form")
1252
2181
  return {
1253
- key: s.code,
1254
- label: s.label,
1255
- rawValue: o,
1256
- viewValue: /* @__PURE__ */ f(
1257
- Ce,
2182
+ key: o.code,
2183
+ label: o.label,
2184
+ rawValue: a,
2185
+ viewValue: /* @__PURE__ */ l(
2186
+ et,
1258
2187
  {
1259
- code: s.code,
1260
- value: o,
1261
- modeConfig: d.api_ids
2188
+ group: o,
2189
+ value: a,
2190
+ formValues: t
1262
2191
  }
1263
2192
  ),
1264
- field_group: s
2193
+ field_group: o
1265
2194
  };
1266
- if (c === "api_detail" && d?.api_detail)
2195
+ if (y === "api" && f)
1267
2196
  return {
1268
- key: s.code,
1269
- label: s.label,
1270
- rawValue: o,
1271
- viewValue: /* @__PURE__ */ f(
1272
- Le,
2197
+ key: o.code,
2198
+ label: o.label,
2199
+ rawValue: a,
2200
+ viewValue: /* @__PURE__ */ l(
2201
+ Ge,
1273
2202
  {
1274
- code: s.code,
1275
- value: o,
1276
- modeConfig: d.api_detail
2203
+ code: o.code,
2204
+ value: a,
2205
+ viewConfig: f
1277
2206
  }
1278
2207
  ),
1279
- field_group: s
2208
+ field_group: o
1280
2209
  };
1281
- const y = i[s.code] ?? {};
2210
+ if (y === "api_ids" && f?.api_ids)
2211
+ return {
2212
+ key: o.code,
2213
+ label: o.label,
2214
+ rawValue: a,
2215
+ viewValue: /* @__PURE__ */ l(
2216
+ Ze,
2217
+ {
2218
+ code: o.code,
2219
+ value: a,
2220
+ modeConfig: f.api_ids
2221
+ }
2222
+ ),
2223
+ field_group: o
2224
+ };
2225
+ if (y === "api_detail" && f?.api_detail)
2226
+ return {
2227
+ key: o.code,
2228
+ label: o.label,
2229
+ rawValue: a,
2230
+ viewValue: /* @__PURE__ */ l(
2231
+ Qe,
2232
+ {
2233
+ code: o.code,
2234
+ value: a,
2235
+ modeConfig: f.api_detail
2236
+ }
2237
+ ),
2238
+ field_group: o
2239
+ };
2240
+ const u = i[o.code] ?? {};
1282
2241
  return {
1283
- key: s.code,
1284
- label: s.label,
1285
- rawValue: o,
1286
- viewValue: Ot(s, o, y),
1287
- field_group: s
2242
+ key: o.code,
2243
+ label: o.label,
2244
+ rawValue: a,
2245
+ viewValue: Bt(o, a, u),
2246
+ field_group: o
1288
2247
  };
1289
2248
  }), [i, n, t]);
1290
- }, Kt = ({
1291
- code: e,
1292
- value: t,
1293
- fieldGroup: n
1294
- }) => {
1295
- const r = n?.additional_config?.view_value;
1296
- switch (r?.mode) {
1297
- case "raw":
1298
- return t;
1299
- case "api":
1300
- return /* @__PURE__ */ f(Me, { code: e, value: t, viewConfig: r });
1301
- case "api_ids": {
1302
- const i = r?.api_ids;
1303
- return /* @__PURE__ */ f(Ce, { code: e, value: t, modeConfig: i });
1304
- }
1305
- case "api_detail": {
1306
- const i = r?.api_detail;
1307
- return /* @__PURE__ */ f(Le, { code: e, value: t, modeConfig: i });
1308
- }
1309
- default:
1310
- return t;
1311
- }
1312
- }, rn = C(Kt), je = {
2249
+ }, rt = {
1313
2250
  submit: "Save",
1314
2251
  submitError: "Failed to submit form",
1315
2252
  inputPlaceholder: (e) => `Enter ${e}`,
@@ -1320,9 +2257,9 @@ const nn = ({
1320
2257
  viewLoading: "Loading...",
1321
2258
  viewEmpty: "-",
1322
2259
  viewError: "Failed to load"
1323
- }, an = {
1324
- messages: je
1325
- }, $t = (e) => {
2260
+ }, Un = {
2261
+ messages: rt
2262
+ }, xn = (e) => {
1326
2263
  if (Array.isArray(e)) return e;
1327
2264
  if (e && typeof e == "object" && "items" in e && Array.isArray(e.items))
1328
2265
  return e.items;
@@ -1331,104 +2268,107 @@ const nn = ({
1331
2268
  return Array.isArray(t.items) ? t.items : [];
1332
2269
  }
1333
2270
  return [];
1334
- }, zt = (e) => ({
2271
+ }, Tn = (e) => ({
1335
2272
  redirectUrl: e?.redirect_after_create,
1336
2273
  data: e
1337
- }), Ht = (e, t) => t?.dataPath ? I(e, t.dataPath) : e, te = {
1338
- optionResponse: $t,
1339
- submitResponse: zt,
1340
- viewResponse: Ht
1341
- }, Yt = (e, t = "_blank") => {
2274
+ }), Mn = (e, t) => t?.dataPath ? se(e, t.dataPath) : e, Dn = (e) => e, ye = {
2275
+ optionResponse: xn,
2276
+ submitResponse: Tn,
2277
+ viewResponse: Mn,
2278
+ formConfigResponse: Dn
2279
+ }, Ln = (e, t = "_blank") => {
1342
2280
  window.open(e, t);
1343
- }, ne = {
2281
+ }, ve = {
1344
2282
  upload: async () => {
1345
2283
  throw new Error("Upload adapter is not configured");
1346
2284
  },
1347
2285
  remove: async () => !1
1348
2286
  };
1349
- function on({
2287
+ function Nn({
1350
2288
  children: e,
1351
2289
  client: t,
1352
2290
  upload: n,
1353
2291
  i18n: r,
1354
2292
  parsers: i,
1355
- renderers: a = {},
1356
- transformers: s = {},
1357
- cache: o,
1358
- submitDebounceMs: d = 200,
1359
- redirectHandler: c,
2293
+ renderers: s = {},
2294
+ transformers: o = {},
2295
+ cache: a,
2296
+ submitDebounceMs: m = 200,
2297
+ redirectHandler: f,
1360
2298
  // legacy props
1361
2299
  requestClient: y,
1362
- uploadAdapter: m,
1363
- deleteUploadAdapter: l,
1364
- messages: p,
1365
- optionResponseParser: h,
1366
- customFieldRenderers: u
2300
+ uploadAdapter: u,
2301
+ deleteUploadAdapter: c,
2302
+ messages: d,
2303
+ optionResponseParser: p,
2304
+ customFieldRenderers: h
1367
2305
  }) {
1368
- const v = B(/* @__PURE__ */ new Map()), _ = B(/* @__PURE__ */ new Map()), w = R(() => {
1369
- const b = t ?? {
2306
+ const _ = I(/* @__PURE__ */ new Map()), A = I(/* @__PURE__ */ new Map()), w = C(() => {
2307
+ const S = t ?? {
1370
2308
  request: y ?? (() => {
1371
2309
  throw new Error("DynamicFormProvider requires client or requestClient");
1372
2310
  })
1373
- }, S = u ? Object.entries(u).map(([k, D]) => ({
1374
- match: k,
1375
- render: D
1376
- })) : [], A = {
1377
- ...je,
2311
+ }, b = h ? Object.entries(h).map(([F, R]) => ({
2312
+ match: F,
2313
+ render: R
2314
+ })) : [], v = {
2315
+ ...rt,
1378
2316
  ...r?.messages,
1379
- ...p
1380
- }, g = {
1381
- ...ne,
2317
+ ...d
2318
+ }, T = {
2319
+ ...ve,
1382
2320
  ...n,
1383
- upload: n?.upload ?? m ?? ne.upload,
1384
- remove: n?.remove ?? (l ? (k) => l(k.path) : ne.remove)
2321
+ upload: n?.upload ?? u ?? ve.upload,
2322
+ remove: n?.remove ?? (c ? (F) => c(F.path) : ve.remove)
1385
2323
  };
1386
2324
  return {
1387
- client: b,
1388
- upload: g,
1389
- i18n: { messages: A },
2325
+ client: S,
2326
+ upload: T,
2327
+ i18n: { messages: v },
1390
2328
  parsers: {
1391
- optionResponse: i?.optionResponse ?? h ?? te.optionResponse,
1392
- submitResponse: i?.submitResponse ?? te.submitResponse,
1393
- viewResponse: i?.viewResponse ?? te.viewResponse
2329
+ optionResponse: i?.optionResponse ?? p ?? ye.optionResponse,
2330
+ submitResponse: i?.submitResponse ?? ye.submitResponse,
2331
+ viewResponse: i?.viewResponse ?? ye.viewResponse,
2332
+ formConfigResponse: i?.formConfigResponse ?? ye.formConfigResponse
1394
2333
  },
1395
2334
  renderers: {
1396
- ...a,
1397
- fields: [...a.fields ?? [], ...S]
2335
+ ...s,
2336
+ fields: [...s.fields ?? [], ...b]
1398
2337
  },
1399
- transformers: s,
2338
+ transformers: o,
1400
2339
  cache: {
1401
- enabled: o?.enabled ?? !0,
1402
- ttlMs: o?.ttlMs ?? 6e4
2340
+ enabled: a?.enabled ?? !0,
2341
+ ttlMs: a?.ttlMs ?? 6e4
1403
2342
  },
1404
- submitDebounceMs: d,
1405
- redirectHandler: c ?? Yt,
1406
- optionCache: v.current,
1407
- viewCache: _.current
2343
+ submitDebounceMs: m,
2344
+ redirectHandler: f ?? Ln,
2345
+ optionCache: _.current,
2346
+ viewCache: A.current
1408
2347
  };
1409
2348
  }, [
1410
2349
  t,
1411
2350
  y,
1412
2351
  n,
1413
- m,
1414
- l,
2352
+ u,
2353
+ c,
1415
2354
  r?.messages,
1416
- p,
2355
+ d,
1417
2356
  i?.optionResponse,
1418
2357
  i?.submitResponse,
1419
2358
  i?.viewResponse,
1420
- h,
1421
- a,
1422
- u,
2359
+ i?.formConfigResponse,
2360
+ p,
1423
2361
  s,
1424
- o?.enabled,
1425
- o?.ttlMs,
1426
- d,
1427
- c
2362
+ h,
2363
+ o,
2364
+ a?.enabled,
2365
+ a?.ttlMs,
2366
+ m,
2367
+ f
1428
2368
  ]);
1429
- return /* @__PURE__ */ f(oe.Provider, { value: w, children: e });
2369
+ return /* @__PURE__ */ l(ke.Provider, { value: w, children: e });
1430
2370
  }
1431
- function sn(e) {
2371
+ function Wn(e) {
1432
2372
  return {
1433
2373
  request: async (t) => ({ data: (await e({
1434
2374
  method: t.method,
@@ -1442,55 +2382,67 @@ function sn(e) {
1442
2382
  };
1443
2383
  }
1444
2384
  export {
1445
- Le as ApiDetailItem,
1446
- Ce as ApiItem,
1447
- Me as ApiViewItem,
1448
- gt as DefaultLayout,
1449
- kt as DynamicForm,
1450
- on as DynamicFormProvider,
1451
- wt as FormItem,
1452
- rn as MetaItemValue,
1453
- Et as buildApiViewRequests,
2385
+ Qe as ApiDetailItem,
2386
+ Ze as ApiItem,
2387
+ Ge as ApiViewItem,
2388
+ ln as DefaultLayout,
2389
+ xe as DynamicForm,
2390
+ Nn as DynamicFormProvider,
2391
+ cn as FormItem,
2392
+ tt as MetaItemValue,
2393
+ tn as MultipleNestedForm,
2394
+ et as MultipleNestedFormView,
2395
+ Ht as NestedForm,
2396
+ nt as NestedFormView,
2397
+ Pt as buildApiViewRequests,
1454
2398
  le as buildCacheKey,
1455
- re as cachedRequest,
1456
- sn as createAxiosDynamicFormClient,
1457
- se as debounce,
1458
- an as defaultI18n,
1459
- je as defaultMessages,
1460
- $t as defaultOptionResponseParser,
1461
- te as defaultParsers,
1462
- Yt as defaultRedirectHandler,
1463
- zt as defaultSubmitResponseParser,
1464
- Ht as defaultViewResponseParser,
1465
- pt as extractDependencyFields,
1466
- Pe as extractViewData,
1467
- Rt as fetchApiViewItems,
1468
- Q as fillTemplate,
1469
- I as getByPath,
1470
- dt as getCached,
1471
- Te as getMappedLabel,
1472
- xe as getMappedLink,
1473
- G as isEmptyValue,
1474
- tt as mapOptionToSelectItem,
1475
- nt as mapOptions,
1476
- De as normalizeApiViewConfig,
1477
- tn as normalizeMetaForForm,
1478
- mt as parseFormValues,
1479
- q as replaceTemplateInObject,
1480
- Dt as resolveApiOptionMeta,
1481
- Ze as resolveFieldRenderer,
1482
- et as resolveFieldRendererFromMap,
1483
- Ot as resolveFieldViewValue,
1484
- Ae as resolveViewValueConfig,
1485
- ut as setCache,
1486
- ee as useCachedViewRequest,
1487
- yt as useDependencyValues,
1488
- ct as useDynamicField,
1489
- M as useDynamicFormContext,
1490
- en as useDynamicFormContextOptional,
1491
- bt as useDynamicOptions,
1492
- At as useFieldGroups,
1493
- St as useFieldStates,
1494
- Ft as useProcessedValues,
1495
- nn as useViewMode
2399
+ de as cachedRequest,
2400
+ Wn as createAxiosDynamicFormClient,
2401
+ Bn as createNestedDynamicFormData,
2402
+ Fe as debounce,
2403
+ Dn as defaultFormConfigResponseParser,
2404
+ Un as defaultI18n,
2405
+ rt as defaultMessages,
2406
+ xn as defaultOptionResponseParser,
2407
+ ye as defaultParsers,
2408
+ Ln as defaultRedirectHandler,
2409
+ Tn as defaultSubmitResponseParser,
2410
+ Mn as defaultViewResponseParser,
2411
+ Wt as extractDependencyFields,
2412
+ Je as extractMultipleNestedFormValues,
2413
+ Kt as extractNestedFormValue,
2414
+ Ne as extractViewData,
2415
+ Vt as fetchApiViewItems,
2416
+ he as fillTemplate,
2417
+ se as getByPath,
2418
+ Yt as getCached,
2419
+ We as getMappedLabel,
2420
+ $e as getMappedLink,
2421
+ ce as getNestedFormCodeHint,
2422
+ Re as getNestedSubmitContainerKey,
2423
+ W as isEmptyValue,
2424
+ Ft as mapOptionToSelectItem,
2425
+ Ct as mapOptions,
2426
+ Ue as normalizeApiViewConfig,
2427
+ Xe as normalizeMetaForForm,
2428
+ Nt as parseFormValues,
2429
+ ie as replaceTemplateInObject,
2430
+ Ce as resolveApiOptionMeta,
2431
+ St as resolveFieldRenderer,
2432
+ kt as resolveFieldRendererFromMap,
2433
+ Bt as resolveFieldViewValue,
2434
+ Ve as resolveViewValueConfig,
2435
+ Jt as setCache,
2436
+ Ye as unwrapMultipleFormValueForEdit,
2437
+ He as unwrapSingleFormValueForEdit,
2438
+ ue as useCachedViewRequest,
2439
+ rn as useDependencyValues,
2440
+ nn as useDynamicField,
2441
+ U as useDynamicFormContext,
2442
+ qn as useDynamicFormContextOptional,
2443
+ on as useDynamicOptions,
2444
+ dn as useFieldGroups,
2445
+ un as useFieldStates,
2446
+ mn as useProcessedValues,
2447
+ Kn as useViewMode
1496
2448
  };