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