@middag-io/react 0.28.0 → 0.30.0

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.
Files changed (117) hide show
  1. package/dist-lib/{DateField-CU9qDJwH.js → DateField-CcRD2r-Z.js} +5 -5
  2. package/dist-lib/{DateRangeField-CvU7wiyr.js → DateRangeField-DKZMfKB2.js} +199 -198
  3. package/dist-lib/{DocumentField-COJZZV5_.js → DocumentField-DjnK9T7o.js} +3 -3
  4. package/dist-lib/FormPanelBlock-BW2oi2_O.js +1816 -0
  5. package/dist-lib/{MarkdownContent-DZf86c3J.js → MarkdownContent-C-X2QGA2.js} +18 -17
  6. package/dist-lib/MarkdownContent-D5FIjx_W.js +2 -0
  7. package/dist-lib/{PhoneField-fFUyYj--.js → PhoneField-D_djeYhK.js} +80 -75
  8. package/dist-lib/app/providers/index.d.ts +2 -4
  9. package/dist-lib/app/providers/index.d.ts.map +1 -1
  10. package/dist-lib/app/providers/inertia-error-reporter.d.ts.map +1 -1
  11. package/dist-lib/base/blocks/ActionGridBlock.d.ts.map +1 -1
  12. package/dist-lib/base/blocks/ActivityTimelineBlock.d.ts.map +1 -1
  13. package/dist-lib/base/blocks/CardGridBlock.d.ts.map +1 -1
  14. package/dist-lib/base/blocks/DenseTableBlock.d.ts.map +1 -1
  15. package/dist-lib/base/blocks/DetailPanelBlock.d.ts.map +1 -1
  16. package/dist-lib/base/blocks/EmptyStateBlock.d.ts.map +1 -1
  17. package/dist-lib/base/blocks/FormPanelBlock.d.ts.map +1 -1
  18. package/dist-lib/base/blocks/MarkdownPanelBlock.d.ts.map +1 -1
  19. package/dist-lib/base/blocks/MetricCardBlock.d.ts.map +1 -1
  20. package/dist-lib/base/blocks/StatusStripBlock.d.ts.map +1 -1
  21. package/dist-lib/base/blocks/TabbedPanelBlock.d.ts.map +1 -1
  22. package/dist-lib/base/blocks/WorkflowProgressBlock.d.ts.map +1 -1
  23. package/dist-lib/base/form/FormField.d.ts +2 -1
  24. package/dist-lib/base/form/FormField.d.ts.map +1 -1
  25. package/dist-lib/base/form/fields/DateRangeField.d.ts +1 -1
  26. package/dist-lib/base/form/fields/DateRangeField.d.ts.map +1 -1
  27. package/dist-lib/base/form/fields/FileUploadField.d.ts +2 -2
  28. package/dist-lib/base/form/fields/FileUploadField.d.ts.map +1 -1
  29. package/dist-lib/base/form/fields/MultiSelectField.d.ts.map +1 -1
  30. package/dist-lib/base/form/fields/NativeSelectField.d.ts.map +1 -1
  31. package/dist-lib/base/form/fields/RatingField.d.ts +1 -1
  32. package/dist-lib/base/form/fields/RatingField.d.ts.map +1 -1
  33. package/dist-lib/base/form/fields/SlugField.d.ts.map +1 -1
  34. package/dist-lib/base/form/form-schema-builder.d.ts +2 -1
  35. package/dist-lib/base/form/form-schema-builder.d.ts.map +1 -1
  36. package/dist-lib/base/form/form-utils.d.ts +15 -0
  37. package/dist-lib/base/form/form-utils.d.ts.map +1 -1
  38. package/dist-lib/base/layout/DashboardLayout.d.ts.map +1 -1
  39. package/dist-lib/base/partials/ActionBar/index.d.ts.map +1 -1
  40. package/dist-lib/base/partials/DataTable/index.d.ts.map +1 -1
  41. package/dist-lib/base/partials/FormSection/index.d.ts.map +1 -1
  42. package/dist-lib/base/partials/StatusBar/index.d.ts.map +1 -1
  43. package/dist-lib/base/partials/StatusIndicator/index.d.ts.map +1 -1
  44. package/dist-lib/base/shell/BasicShell.d.ts.map +1 -1
  45. package/dist-lib/base/shell/ImmersiveShell.d.ts.map +1 -1
  46. package/dist-lib/base/shell/partials/PageActionButton.d.ts.map +1 -1
  47. package/dist-lib/base/utils/time.d.ts.map +1 -1
  48. package/dist-lib/{button-Ba1PcsOx.js → button-Bm0X9WO5.js} +1 -1
  49. package/dist-lib/{calendar-DnlbmjNu.js → calendar-CucaItjm.js} +51 -50
  50. package/dist-lib/{chevron-right-Casn6MFU.js → chevron-right-DY3SdwdB.js} +1 -1
  51. package/dist-lib/chunk-DeC0fbbY.js +22 -0
  52. package/dist-lib/{combobox-BbYGWCFO.js → combobox-yfHHEi6f.js} +1518 -1602
  53. package/dist-lib/components/reui/data-grid/data-grid-table-virtual.d.ts.map +1 -1
  54. package/dist-lib/contracts/block-data/actions.d.ts +2 -1
  55. package/dist-lib/contracts/block-data/actions.d.ts.map +1 -1
  56. package/dist-lib/contracts/block-data/form.d.ts +74 -194
  57. package/dist-lib/contracts/block-data/form.d.ts.map +1 -1
  58. package/dist-lib/contracts/block-data/shared.d.ts +1 -16
  59. package/dist-lib/contracts/block-data/shared.d.ts.map +1 -1
  60. package/dist-lib/contracts/generated/contract-schema.d.ts +2 -1
  61. package/dist-lib/contracts/generated/contract-schema.d.ts.map +1 -1
  62. package/dist-lib/contracts/generated/contract-types.d.ts +239 -4
  63. package/dist-lib/contracts/generated/contract-types.d.ts.map +1 -1
  64. package/dist-lib/contracts/generated/index.d.ts +1 -1
  65. package/dist-lib/contracts/page-contract-schema.d.ts +1 -0
  66. package/dist-lib/contracts/page-contract-schema.d.ts.map +1 -1
  67. package/dist-lib/contracts/page-contract.d.ts +0 -2
  68. package/dist-lib/contracts/page-contract.d.ts.map +1 -1
  69. package/dist-lib/contracts/shared-props.d.ts +4 -0
  70. package/dist-lib/contracts/shared-props.d.ts.map +1 -1
  71. package/dist-lib/{dist-B-MyAb3x.js → dist-B7gC4peV.js} +1 -1
  72. package/dist-lib/{dist-7c0PXlrb.js → dist-Bbnbom8g.js} +2 -2
  73. package/dist-lib/{dist-DuO9WodV.js → dist-DdgpZG8v.js} +3 -3
  74. package/dist-lib/{document-validation-YgxIqb8k.js → document-validation-DX0fB9cu.js} +2 -2
  75. package/dist-lib/i18n/I18nProvider.d.ts +15 -0
  76. package/dist-lib/i18n/I18nProvider.d.ts.map +1 -0
  77. package/dist-lib/i18n/host-resolver.d.ts +11 -0
  78. package/dist-lib/i18n/host-resolver.d.ts.map +1 -0
  79. package/dist-lib/i18n/instance.d.ts +13 -0
  80. package/dist-lib/i18n/instance.d.ts.map +1 -0
  81. package/dist-lib/i18n/register-strings.d.ts +4 -0
  82. package/dist-lib/i18n/register-strings.d.ts.map +1 -0
  83. package/dist-lib/i18n/render-label.d.ts +14 -0
  84. package/dist-lib/i18n/render-label.d.ts.map +1 -0
  85. package/dist-lib/i18n/resolve-field-error.d.ts +9 -0
  86. package/dist-lib/i18n/resolve-field-error.d.ts.map +1 -0
  87. package/dist-lib/i18n/useHostString.d.ts +2 -0
  88. package/dist-lib/i18n/useHostString.d.ts.map +1 -0
  89. package/dist-lib/i18n/useTranslation.d.ts +12 -0
  90. package/dist-lib/i18n/useTranslation.d.ts.map +1 -0
  91. package/dist-lib/index.d.ts +9 -4
  92. package/dist-lib/index.d.ts.map +1 -1
  93. package/dist-lib/{input-CdUVNe54.js → input-BC9whKEm.js} +1 -1
  94. package/dist-lib/middag-react.css +1 -1
  95. package/dist-lib/middag-react.js +5961 -3980
  96. package/dist-lib/{popover-Bxsp1hlN.js → popover-BaiQ-JSz.js} +29 -29
  97. package/dist-lib/{FormSection-B6Tcbwrf.js → resolve-field-error-dbUy6DeX.js} +2172 -2076
  98. package/dist-lib/{scroll-area-B9TZ05bl.js → scroll-area-D94_a2-1.js} +57 -57
  99. package/dist-lib/{skeleton-HpnbVVji.js → skeleton-xL_Hzxj-.js} +1 -1
  100. package/dist-lib/{use-mobile-Kp3Dy8mh.js → use-mobile-CBJJLRL8.js} +36 -36
  101. package/dist-lib/useTranslation-BuyMWJ9T.js +321 -0
  102. package/dist-lib/{utils-Yj2czlvU.js → utils-CpaZ5_iF.js} +517 -538
  103. package/package.json +2 -1
  104. package/dist-lib/FormPanelBlock-Cd_uiDze.js +0 -1736
  105. package/dist-lib/MarkdownContent-BeNHDP09.js +0 -2
  106. package/dist-lib/app/providers/i18n-defaults.d.ts +0 -19
  107. package/dist-lib/app/providers/i18n-defaults.d.ts.map +0 -1
  108. package/dist-lib/app/providers/i18n.d.ts +0 -55
  109. package/dist-lib/app/providers/i18n.d.ts.map +0 -1
  110. package/dist-lib/app/providers/locales/pt-BR.d.ts +0 -15
  111. package/dist-lib/app/providers/locales/pt-BR.d.ts.map +0 -1
  112. package/dist-lib/i18n-D5Nt1tut.js +0 -326
  113. package/dist-lib/lib/i18n/render-label.d.ts +0 -31
  114. package/dist-lib/lib/i18n/render-label.d.ts.map +0 -1
  115. /package/dist-lib/{dist-CmB86BdM.js → dist-3F0-lo64.js} +0 -0
  116. /package/dist-lib/{dist-axU0pUop.js → dist-DdfRh_k3.js} +0 -0
  117. /package/dist-lib/{floating-ui.react-dom-BnOzLaz1.js → floating-ui.react-dom-CNntavPo.js} +0 -0
@@ -1,1736 +0,0 @@
1
- import { t as e } from "./utils-Yj2czlvU.js";
2
- import { B as t, C as n, E as r, F as i, H as a, O as o, P as s, R as c, S as l, T as u, U as d, V as f, _ as p, a as m, at as h, c as g, ct as _, d as v, f as y, ft as b, g as x, gt as S, h as C, ht as ee, i as w, l as T, lt as E, m as D, mt as O, n as k, o as A, ot as te, p as ne, r as re, s as j, st as ie, t as ae, u as oe, ut as se, v as ce, w as le, z as ue } from "./FormSection-B6Tcbwrf.js";
3
- import { t as M } from "./button-Ba1PcsOx.js";
4
- import { n as de } from "./i18n-D5Nt1tut.js";
5
- import { t as fe } from "./skeleton-HpnbVVji.js";
6
- import { t as pe } from "./document-validation-YgxIqb8k.js";
7
- import N, { Suspense as P, lazy as F, useCallback as me, useEffect as he, useId as ge, useMemo as _e, useRef as ve, useState as ye } from "react";
8
- import { router as be } from "@inertiajs/core";
9
- import { Fragment as xe, jsx as I, jsxs as L } from "react/jsx-runtime";
10
- //#region node_modules/react-hook-form/dist/index.esm.mjs
11
- var Se = (e) => e.type === "checkbox", R = (e) => e instanceof Date, z = (e) => e == null, Ce = (e) => typeof e == "object", B = (e) => !z(e) && !Array.isArray(e) && Ce(e) && !R(e), we = (e) => B(e) && e.target ? Se(e.target) ? e.target.checked : e.target.value : e, Te = (e, t) => t.split(".").some((t, n, r) => !isNaN(Number(t)) && e.has(r.slice(0, n).join("."))), Ee = (e) => {
12
- let t = e.constructor && e.constructor.prototype;
13
- return B(t) && t.hasOwnProperty("isPrototypeOf");
14
- }, De = typeof window < "u" && window.HTMLElement !== void 0 && typeof document < "u";
15
- function V(e) {
16
- if (e instanceof Date) return new Date(e);
17
- let t = typeof FileList < "u" && e instanceof FileList;
18
- if (De && (e instanceof Blob || t)) return e;
19
- let n = Array.isArray(e);
20
- if (!n && !(B(e) && Ee(e))) return e;
21
- let r = n ? [] : Object.create(Object.getPrototypeOf(e));
22
- for (let t in e) Object.prototype.hasOwnProperty.call(e, t) && (r[t] = V(e[t]));
23
- return r;
24
- }
25
- var Oe = (e) => /^\w*$/.test(e), H = (e) => e === void 0, ke = (e) => Array.isArray(e) ? e.filter(Boolean) : [], Ae = (e) => ke(e.replace(/["|']|\]/g, "").split(/\.|\[/)), U = (e, t, n) => {
26
- if (!t || !B(e)) return n;
27
- let r = (Oe(t) ? [t] : Ae(t)).reduce((e, t) => z(e) ? void 0 : e[t], e);
28
- return H(r) || r === e ? H(e[t]) ? n : e[t] : r;
29
- }, W = (e) => typeof e == "boolean", G = (e) => typeof e == "function", K = (e, t, n) => {
30
- let r = -1, i = Oe(t) ? [t] : Ae(t), a = i.length, o = a - 1;
31
- for (; ++r < a;) {
32
- let t = i[r], a = n;
33
- if (r !== o) {
34
- let n = e[t];
35
- a = B(n) || Array.isArray(n) ? n : isNaN(+i[r + 1]) ? {} : [];
36
- }
37
- if (t === "__proto__" || t === "constructor" || t === "prototype") return;
38
- e[t] = a, e = e[t];
39
- }
40
- }, q = {
41
- BLUR: "blur",
42
- FOCUS_OUT: "focusout",
43
- CHANGE: "change",
44
- SUBMIT: "submit",
45
- TRIGGER: "trigger",
46
- VALID: "valid"
47
- }, J = {
48
- onBlur: "onBlur",
49
- onChange: "onChange",
50
- onSubmit: "onSubmit",
51
- onTouched: "onTouched",
52
- all: "all"
53
- }, Y = {
54
- max: "max",
55
- min: "min",
56
- maxLength: "maxLength",
57
- minLength: "minLength",
58
- pattern: "pattern",
59
- required: "required",
60
- validate: "validate"
61
- }, je = "form", Me = "root", Ne = N.createContext(null);
62
- Ne.displayName = "HookFormControlContext";
63
- var Pe = () => N.useContext(Ne), Fe = (e, t, n, r = !0) => {
64
- let i = {};
65
- for (let a in e) Object.defineProperty(i, a, { get: () => {
66
- let i = a;
67
- return t._proxyFormState[i] !== J.all && (t._proxyFormState[i] = !r || J.all), n && (n[i] = !0), e[i];
68
- } });
69
- return i;
70
- }, Ie = typeof window < "u" ? N.useLayoutEffect : N.useEffect, X = (e) => typeof e == "string", Le = (e, t, n, r, i) => X(e) ? (r && t.watch.add(e), U(n, e, i)) : Array.isArray(e) ? e.map((e) => (r && t.watch.add(e), U(n, e))) : (r && (t.watchAll = !0), n), Re = (e) => z(e) || !Ce(e);
71
- function Z(e, t, n = /* @__PURE__ */ new WeakSet()) {
72
- if (e === t) return !0;
73
- if (Re(e) || Re(t)) return Object.is(e, t);
74
- if (R(e) && R(t)) return Object.is(e.getTime(), t.getTime());
75
- let r = Object.keys(e), i = Object.keys(t);
76
- if (r.length !== i.length) return !1;
77
- if (n.has(e) || n.has(t)) return !0;
78
- n.add(e), n.add(t);
79
- for (let i of r) {
80
- let r = e[i];
81
- if (!(i in t)) return !1;
82
- if (i !== "ref") {
83
- let e = t[i];
84
- if (R(r) && R(e) || (B(r) || Array.isArray(r)) && (B(e) || Array.isArray(e)) ? !Z(r, e, n) : !Object.is(r, e)) return !1;
85
- }
86
- }
87
- return !0;
88
- }
89
- function ze(e) {
90
- let t = Pe(), { control: n = t, name: r, defaultValue: i, disabled: a, exact: o, compute: s } = e || {}, c = N.useRef(i), l = N.useRef(s), u = N.useRef(void 0), d = N.useRef(n), f = N.useRef(r);
91
- l.current = s;
92
- let [p, m] = N.useState(() => {
93
- let e = n._getWatch(r, c.current);
94
- return l.current ? l.current(e) : e;
95
- }), h = N.useCallback((e) => {
96
- let t = Le(r, n._names, e || n._formValues, !1, c.current);
97
- return l.current ? l.current(t) : t;
98
- }, [
99
- n._formValues,
100
- n._names,
101
- r
102
- ]), g = N.useCallback((e) => {
103
- if (!a) {
104
- let t = Le(r, n._names, e || n._formValues, !1, c.current);
105
- if (l.current) {
106
- let e = l.current(t);
107
- Z(e, u.current) || (m(e), u.current = e);
108
- } else m(t);
109
- }
110
- }, [
111
- n._formValues,
112
- n._names,
113
- a,
114
- r
115
- ]);
116
- Ie(() => ((d.current !== n || !Z(f.current, r)) && (d.current = n, f.current = r, g()), n._subscribe({
117
- name: r,
118
- formState: { values: !0 },
119
- exact: o,
120
- callback: (e) => {
121
- g(e.values);
122
- }
123
- })), [
124
- n,
125
- o,
126
- r,
127
- g
128
- ]), N.useEffect(() => n._removeUnmounted());
129
- let _ = d.current !== n, v = f.current, y = N.useMemo(() => {
130
- if (a) return null;
131
- let e = !_ && !Z(v, r);
132
- return _ || e ? h() : null;
133
- }, [
134
- a,
135
- _,
136
- r,
137
- v,
138
- h
139
- ]);
140
- return y === null ? p : y;
141
- }
142
- var Be = N.createContext(null);
143
- Be.displayName = "HookFormContext";
144
- var Ve = (e, t, n, r, i) => t ? {
145
- ...n[e],
146
- types: {
147
- ...n[e] && n[e].types ? n[e].types : {},
148
- [r]: i || !0
149
- }
150
- } : {}, He = (e) => Array.isArray(e) ? e : [e], Ue = () => {
151
- let e = [];
152
- return {
153
- get observers() {
154
- return e;
155
- },
156
- next: (t) => {
157
- for (let n of e) n.next && n.next(t);
158
- },
159
- subscribe: (t) => (e.push(t), { unsubscribe: () => {
160
- e = e.filter((e) => e !== t);
161
- } }),
162
- unsubscribe: () => {
163
- e = [];
164
- }
165
- };
166
- };
167
- function We(e, t) {
168
- let n = {};
169
- for (let r in e) if (e.hasOwnProperty(r)) {
170
- let i = e[r], a = t[r];
171
- if (i && B(i) && a) {
172
- let e = We(i, a);
173
- B(e) && (n[r] = e);
174
- } else e[r] && (n[r] = a);
175
- }
176
- return n;
177
- }
178
- var Q = (e) => B(e) && !Object.keys(e).length, Ge = (e) => e.type === "file", Ke = (e) => {
179
- if (!De) return !1;
180
- let t = e ? e.ownerDocument : 0;
181
- return e instanceof (t && t.defaultView ? t.defaultView.HTMLElement : HTMLElement);
182
- }, qe = (e) => e.type === "select-multiple", Je = (e) => e.type === "radio", Ye = (e) => Je(e) || Se(e), Xe = (e) => Ke(e) && e.isConnected;
183
- function Ze(e, t) {
184
- let n = t.slice(0, -1).length, r = 0;
185
- for (; r < n;) {
186
- if (z(e)) {
187
- e = void 0;
188
- break;
189
- }
190
- e = e[t[r]], r++;
191
- }
192
- return e;
193
- }
194
- function Qe(e) {
195
- for (let t in e) if (e.hasOwnProperty(t) && !H(e[t])) return !1;
196
- return !0;
197
- }
198
- function $(e, t) {
199
- if (X(t) && Object.prototype.hasOwnProperty.call(e, t)) return delete e[t], e;
200
- let n = Array.isArray(t) ? t : Oe(t) ? [t] : Ae(t), r = n.length === 1 ? e : Ze(e, n), i = n.length - 1, a = n[i];
201
- return r && delete r[a], i !== 0 && (B(r) && Q(r) || Array.isArray(r) && Qe(r)) && $(e, n.slice(0, -1)), e;
202
- }
203
- var $e = (e) => {
204
- for (let t in e) if (G(e[t])) return !0;
205
- return !1;
206
- };
207
- function et(e) {
208
- return Array.isArray(e) || B(e) && !$e(e);
209
- }
210
- function tt(e, t = {}) {
211
- for (let n in e) {
212
- let r = e[n];
213
- et(r) ? (t[n] = Array.isArray(r) ? [] : {}, tt(r, t[n])) : H(r) || (t[n] = !0);
214
- }
215
- return t;
216
- }
217
- function nt(e) {
218
- if (e !== !1) {
219
- if (e === !0) return !0;
220
- if (Array.isArray(e)) {
221
- let t = e.map((e) => nt(e));
222
- return t.some((e) => e !== void 0) ? t : void 0;
223
- }
224
- if (B(e)) {
225
- let t = {};
226
- for (let n in e) {
227
- let r = nt(e[n]);
228
- H(r) || (t[n] = r);
229
- }
230
- return Object.keys(t).length ? t : void 0;
231
- }
232
- }
233
- }
234
- function rt(e, t, n) {
235
- n ||= tt(t);
236
- for (let r in e) {
237
- let i = e[r];
238
- if (et(i)) H(t) || Re(n[r]) ? n[r] = tt(i, Array.isArray(i) ? [] : {}) : rt(i, z(t) ? {} : t[r], n[r]);
239
- else {
240
- let e = t[r];
241
- n[r] = !Z(i, e);
242
- }
243
- }
244
- return nt(n) || {};
245
- }
246
- var it = {
247
- value: !1,
248
- isValid: !1
249
- }, at = {
250
- value: !0,
251
- isValid: !0
252
- }, ot = (e) => {
253
- if (Array.isArray(e)) {
254
- if (e.length > 1) {
255
- let t = e.filter((e) => e && e.checked && !e.disabled).map((e) => e.value);
256
- return {
257
- value: t,
258
- isValid: !!t.length
259
- };
260
- }
261
- return e[0].checked && !e[0].disabled ? e[0].attributes && !H(e[0].attributes.value) ? H(e[0].value) || e[0].value === "" ? at : {
262
- value: e[0].value,
263
- isValid: !0
264
- } : at : it;
265
- }
266
- return it;
267
- }, st = (e, { valueAsNumber: t, valueAsDate: n, setValueAs: r }) => H(e) ? e : t ? e === "" ? NaN : e && +e : n && X(e) ? new Date(e) : r ? r(e) : e, ct = {
268
- isValid: !1,
269
- value: null
270
- }, lt = (e) => Array.isArray(e) ? e.reduce((e, t) => t && t.checked && !t.disabled ? {
271
- isValid: !0,
272
- value: t.value
273
- } : e, ct) : ct;
274
- function ut(e) {
275
- let t = e.ref;
276
- return Ge(t) ? t.files : Je(t) ? lt(e.refs).value : qe(t) ? [...t.selectedOptions].map(({ value: e }) => e) : Se(t) ? ot(e.refs).value : st(H(t.value) ? e.ref.value : t.value, e);
277
- }
278
- var dt = (e, t, n, r) => {
279
- let i = {};
280
- for (let n of e) {
281
- let e = U(t, n);
282
- e && K(i, n, e._f);
283
- }
284
- return {
285
- criteriaMode: n,
286
- names: [...e],
287
- fields: i,
288
- shouldUseNativeValidation: r
289
- };
290
- }, ft = (e) => e instanceof RegExp, pt = (e) => H(e) ? e : ft(e) ? e.source : B(e) ? ft(e.value) ? e.value.source : e.value : e, mt = (e) => ({
291
- isOnSubmit: !e || e === J.onSubmit,
292
- isOnBlur: e === J.onBlur,
293
- isOnChange: e === J.onChange,
294
- isOnAll: e === J.all,
295
- isOnTouch: e === J.onTouched
296
- }), ht = "AsyncFunction", gt = (e) => !!e && !!e.validate && !!(G(e.validate) && e.validate.constructor.name === ht || B(e.validate) && Object.values(e.validate).find((e) => e.constructor.name === ht)), _t = (e) => e.mount && (e.required || e.min || e.max || e.maxLength || e.minLength || e.pattern || e.validate), vt = (e, t, n) => !n && (t.watchAll || t.watch.has(e) || [...t.watch].some((t) => e.startsWith(t) && /^\.\w+/.test(e.slice(t.length)))), yt = (e, t, n, r) => {
297
- for (let i of n || Object.keys(e)) {
298
- let n = U(e, i);
299
- if (n) {
300
- let { _f: e, ...a } = n;
301
- if (e) {
302
- if (e.refs && e.refs[0] && t(e.refs[0], i) && !r || e.ref && t(e.ref, e.name) && !r) return !0;
303
- if (yt(a, t)) break;
304
- } else if (B(a) && yt(a, t)) break;
305
- }
306
- }
307
- };
308
- function bt(e, t, n) {
309
- let r = U(e, n);
310
- if (r || Oe(n)) return {
311
- error: r,
312
- name: n
313
- };
314
- let i = n.split(".");
315
- for (; i.length;) {
316
- let r = i.join("."), a = U(t, r), o = U(e, r);
317
- if (a && !Array.isArray(a) && n !== r) return { name: n };
318
- if (o && o.type) return {
319
- name: r,
320
- error: o
321
- };
322
- if (o && o.root && o.root.type) return {
323
- name: `${r}.root`,
324
- error: o.root
325
- };
326
- i.pop();
327
- }
328
- return { name: n };
329
- }
330
- var xt = (e, t, n, r) => {
331
- n(e);
332
- let { name: i, ...a } = e;
333
- return Q(a) || r && Object.keys(a).length >= Object.keys(t).length || Object.keys(a).find((e) => t[e] === (!r || J.all));
334
- }, St = (e, t, n) => !e || !t || e === t || He(e).some((e) => e && (n ? e === t : e.startsWith(t) || t.startsWith(e))), Ct = (e, t, n, r, i) => i.isOnAll ? !1 : !n && i.isOnTouch ? !(t || e) : (n ? r.isOnBlur : i.isOnBlur) ? !e : (n ? r.isOnChange : i.isOnChange) ? e : !0, wt = (e, t) => !ke(U(e, t)).length && $(e, t), Tt = (e, t, n) => {
335
- let r = He(U(e, n));
336
- return K(r, Me, t[n]), K(e, n, r), e;
337
- };
338
- function Et(e, t, n = "validate") {
339
- if (X(e) || Array.isArray(e) && e.every(X) || W(e) && !e) return {
340
- type: n,
341
- message: X(e) ? e : "",
342
- ref: t
343
- };
344
- }
345
- var Dt = (e) => B(e) && !ft(e) ? e : {
346
- value: e,
347
- message: ""
348
- }, Ot = async (e, t, n, r, i, a) => {
349
- let { ref: o, refs: s, required: c, maxLength: l, minLength: u, min: d, max: f, pattern: p, validate: m, name: h, valueAsNumber: g, mount: _ } = e._f, v = U(n, h);
350
- if (!_ || t.has(h)) return {};
351
- let y = s ? s[0] : o, b = (e) => {
352
- i && y.reportValidity && (y.setCustomValidity(W(e) ? "" : e || ""), y.reportValidity());
353
- }, x = {}, S = Je(o), C = Se(o), ee = S || C, w = (g || Ge(o)) && H(o.value) && H(v) || Ke(o) && o.value === "" || v === "" || Array.isArray(v) && !v.length || g && typeof v == "number" && isNaN(v), T = Ve.bind(null, h, r, x), E = (e, t, n, r = Y.maxLength, i = Y.minLength) => {
354
- let a = e ? t : n;
355
- x[h] = {
356
- type: e ? r : i,
357
- message: a,
358
- ref: o,
359
- ...T(e ? r : i, a)
360
- };
361
- };
362
- if (a ? !Array.isArray(v) || !v.length : c && (!ee && (w || z(v)) || W(v) && !v || C && !ot(s).isValid || S && !lt(s).isValid)) {
363
- let { value: e, message: t } = X(c) ? {
364
- value: !!c,
365
- message: c
366
- } : Dt(c);
367
- if (e && (x[h] = {
368
- type: Y.required,
369
- message: t,
370
- ref: y,
371
- ...T(Y.required, t)
372
- }, !r)) return b(t), x;
373
- }
374
- if (!w && (!z(d) || !z(f))) {
375
- let e, t, n = Dt(f), i = Dt(d);
376
- if (!z(v) && !isNaN(v)) {
377
- let r = o.valueAsNumber || v && +v;
378
- z(n.value) || (e = r > n.value), z(i.value) || (t = r < i.value);
379
- } else {
380
- let r = o.valueAsDate || new Date(v), a = (e) => /* @__PURE__ */ new Date((/* @__PURE__ */ new Date()).toDateString() + " " + e), s = o.type == "time", c = o.type == "week";
381
- X(n.value) && v && (e = s ? a(v) > a(n.value) : c ? v > n.value : r > new Date(n.value)), X(i.value) && v && (t = s ? a(v) < a(i.value) : c ? v < i.value : r < new Date(i.value));
382
- }
383
- if ((e || t) && (E(!!e, n.message, i.message, Y.max, Y.min), !r)) return b(x[h].message), x;
384
- }
385
- if ((l || u) && !w && (X(v) || a && Array.isArray(v))) {
386
- let e = Dt(l), t = Dt(u), n = !z(e.value) && v.length > +e.value, i = !z(t.value) && v.length < +t.value;
387
- if ((n || i) && (E(n, e.message, t.message), !r)) return b(x[h].message), x;
388
- }
389
- if (p && !w && X(v)) {
390
- let { value: e, message: t } = Dt(p);
391
- if (ft(e) && !v.match(e) && (x[h] = {
392
- type: Y.pattern,
393
- message: t,
394
- ref: o,
395
- ...T(Y.pattern, t)
396
- }, !r)) return b(t), x;
397
- }
398
- if (m) {
399
- if (G(m)) {
400
- let e = Et(await m(v, n), y);
401
- if (e && (x[h] = {
402
- ...e,
403
- ...T(Y.validate, e.message)
404
- }, !r)) return b(e.message), x;
405
- } else if (B(m)) {
406
- let e = {};
407
- for (let t in m) {
408
- if (!Q(e) && !r) break;
409
- let i = Et(await m[t](v, n), y, t);
410
- i && (e = {
411
- ...i,
412
- ...T(t, i.message)
413
- }, b(i.message), r && (x[h] = e));
414
- }
415
- if (!Q(e) && (x[h] = {
416
- ref: y,
417
- ...e
418
- }, !r)) return x;
419
- }
420
- }
421
- return b(!0), x;
422
- }, kt = {
423
- mode: J.onSubmit,
424
- reValidateMode: J.onChange,
425
- shouldFocusError: !0
426
- }, At = {
427
- submitCount: 0,
428
- isDirty: !1,
429
- isReady: !1,
430
- isValidating: !1,
431
- isSubmitted: !1,
432
- isSubmitting: !1,
433
- isSubmitSuccessful: !1,
434
- isValid: !1,
435
- touchedFields: {},
436
- dirtyFields: {},
437
- validatingFields: {}
438
- };
439
- function jt(e = {}) {
440
- let t = {
441
- ...kt,
442
- ...e
443
- }, n = {
444
- ...V(At),
445
- isLoading: G(t.defaultValues),
446
- errors: t.errors || {},
447
- disabled: t.disabled || !1
448
- }, r = {}, i = (B(t.defaultValues) || B(t.values)) && V(t.defaultValues || t.values) || {}, a = t.shouldUnregister ? {} : V(i), o = {
449
- action: !1,
450
- mount: !1,
451
- watch: !1,
452
- keepIsValid: !1
453
- }, s = {
454
- mount: /* @__PURE__ */ new Set(),
455
- disabled: /* @__PURE__ */ new Set(),
456
- unMount: /* @__PURE__ */ new Set(),
457
- array: /* @__PURE__ */ new Set(),
458
- watch: /* @__PURE__ */ new Set(),
459
- registerName: /* @__PURE__ */ new Set()
460
- }, c, l = 0, u = {
461
- isDirty: !1,
462
- dirtyFields: !1,
463
- validatingFields: !1,
464
- touchedFields: !1,
465
- isValidating: !1,
466
- isValid: !1,
467
- errors: !1
468
- }, d = { ...u }, f = { ...d }, p = {
469
- array: Ue(),
470
- state: Ue()
471
- }, m = t.criteriaMode === J.all, h = (e) => (t) => {
472
- clearTimeout(l), l = setTimeout(e, t);
473
- }, g = async (e) => {
474
- if (!o.keepIsValid && !t.disabled && (d.isValid || f.isValid || e)) {
475
- let e;
476
- t.resolver ? (e = Q((await w()).errors), _()) : e = await D({
477
- fields: r,
478
- onlyCheckValid: !0,
479
- eventType: q.VALID
480
- }), e !== n.isValid && p.state.next({ isValid: e });
481
- }
482
- }, _ = (e, r) => {
483
- !t.disabled && (d.isValidating || d.validatingFields || f.isValidating || f.validatingFields) && ((e || Array.from(s.mount)).forEach((e) => {
484
- e && (r ? K(n.validatingFields, e, r) : $(n.validatingFields, e));
485
- }), p.state.next({
486
- validatingFields: n.validatingFields,
487
- isValidating: !Q(n.validatingFields)
488
- }));
489
- }, v = () => {
490
- n.dirtyFields = rt(i, a);
491
- }, y = (e, i = [], s, c, l = !0, u = !0) => {
492
- if (c && s && !t.disabled) {
493
- if (o.action = !0, u && Array.isArray(U(r, e))) {
494
- let t = s(U(r, e), c.argA, c.argB);
495
- l && K(r, e, t);
496
- }
497
- if (u && Array.isArray(U(n.errors, e))) {
498
- let t = s(U(n.errors, e), c.argA, c.argB);
499
- l && K(n.errors, e, t), wt(n.errors, e);
500
- }
501
- if ((d.touchedFields || f.touchedFields) && u && Array.isArray(U(n.touchedFields, e))) {
502
- let t = s(U(n.touchedFields, e), c.argA, c.argB);
503
- l && K(n.touchedFields, e, t);
504
- }
505
- (d.dirtyFields || f.dirtyFields) && v(), p.state.next({
506
- name: e,
507
- isDirty: k(e, i),
508
- dirtyFields: n.dirtyFields,
509
- errors: n.errors,
510
- isValid: n.isValid
511
- });
512
- } else K(a, e, i);
513
- }, b = (e, t) => {
514
- K(n.errors, e, t), p.state.next({ errors: n.errors });
515
- }, x = (e) => {
516
- n.errors = e, p.state.next({
517
- errors: n.errors,
518
- isValid: !1
519
- });
520
- }, S = (e, t, s, c) => {
521
- let l = U(r, e);
522
- if (l) {
523
- let r = H(U(a, e)), u = U(a, e, H(s) ? U(i, e) : s);
524
- H(u) || c && c.defaultChecked || t ? K(a, e, t ? u : ut(l._f)) : ne(e, u), o.mount && !o.action && (g(), r && n.isDirty && (d.isDirty || f.isDirty) && (k() || (n.isDirty = !1, p.state.next({ ...n }))));
525
- }
526
- }, C = (e, r, a, o, s) => {
527
- let c = !1, l = !1, u = { name: e };
528
- if (!t.disabled) {
529
- if (!a || o) {
530
- (d.isDirty || f.isDirty) && (l = n.isDirty, n.isDirty = u.isDirty = k(), c = l !== u.isDirty);
531
- let t = Z(U(i, e), r);
532
- l = !!U(n.dirtyFields, e), t ? $(n.dirtyFields, e) : K(n.dirtyFields, e, !0), u.dirtyFields = n.dirtyFields, c ||= (d.dirtyFields || f.dirtyFields) && l !== !t;
533
- }
534
- if (a) {
535
- let t = U(n.touchedFields, e);
536
- t || (K(n.touchedFields, e, a), u.touchedFields = n.touchedFields, c ||= (d.touchedFields || f.touchedFields) && t !== a);
537
- }
538
- c && s && p.state.next(u);
539
- }
540
- return c ? u : {};
541
- }, ee = (e, r, i, a) => {
542
- let o = U(n.errors, e), s = (d.isValid || f.isValid) && W(r) && n.isValid !== r;
543
- if (t.delayError && i ? (c = h(() => b(e, i)), c(t.delayError)) : (clearTimeout(l), c = null, i ? K(n.errors, e, i) : $(n.errors, e)), (i ? !Z(o, i) : o) || !Q(a) || s) {
544
- let t = {
545
- ...a,
546
- ...s && W(r) ? { isValid: r } : {},
547
- errors: n.errors,
548
- name: e
549
- };
550
- n = {
551
- ...n,
552
- ...t
553
- }, p.state.next(t);
554
- }
555
- }, w = async (e) => (_(e, !0), await t.resolver(a, t.context, dt(e || s.mount, r, t.criteriaMode, t.shouldUseNativeValidation))), T = async (e) => {
556
- let { errors: t } = await w(e);
557
- if (_(e), e) for (let r of e) {
558
- let e = U(t, r);
559
- e ? K(n.errors, r, e) : $(n.errors, r);
560
- }
561
- else n.errors = t;
562
- return t;
563
- }, E = async ({ name: t, eventType: r }) => {
564
- if (e.validate) {
565
- let i = await e.validate({
566
- formValues: a,
567
- formState: n,
568
- name: t,
569
- eventType: r
570
- });
571
- if (B(i)) for (let e in i) i[e] && M(`${je}.${e}`, {
572
- message: X(i.message) ? i.message : "",
573
- type: Y.validate
574
- });
575
- else X(i) || !i ? M(je, {
576
- message: i || "",
577
- type: Y.validate
578
- }) : ue(je);
579
- return i;
580
- }
581
- return !0;
582
- }, D = async ({ fields: r, onlyCheckValid: i, name: o, eventType: c, context: l = {
583
- valid: !0,
584
- runRootValidation: !1
585
- } }) => {
586
- if (e.validate && (l.runRootValidation = !0, !await E({
587
- name: o,
588
- eventType: c
589
- }) && (l.valid = !1, i))) return l.valid;
590
- for (let o in r) {
591
- let u = r[o];
592
- if (u) {
593
- let { _f: r, ...f } = u;
594
- if (r) {
595
- let o = s.array.has(r.name), c = u._f && gt(u._f);
596
- c && d.validatingFields && _([r.name], !0);
597
- let f = await Ot(u, s.disabled, a, m, t.shouldUseNativeValidation && !i, o);
598
- if (c && d.validatingFields && _([r.name]), f[r.name] && (l.valid = !1, i) || (!i && (U(f, r.name) ? o ? Tt(n.errors, f, r.name) : K(n.errors, r.name, f[r.name]) : $(n.errors, r.name)), e.shouldUseNativeValidation && f[r.name])) break;
599
- }
600
- !Q(f) && await D({
601
- context: l,
602
- onlyCheckValid: i,
603
- fields: f,
604
- name: o,
605
- eventType: c
606
- });
607
- }
608
- }
609
- return l.valid;
610
- }, O = () => {
611
- for (let e of s.unMount) {
612
- let t = U(r, e);
613
- t && (t._f.refs ? t._f.refs.every((e) => !Xe(e)) : !Xe(t._f.ref)) && N(e);
614
- }
615
- s.unMount = /* @__PURE__ */ new Set();
616
- }, k = (e, n) => !t.disabled && (e && n && K(a, e, n), !Z(ce(), i)), A = (e, t, n) => Le(e, s, { ...o.mount ? a : H(t) ? i : X(e) ? { [e]: t } : t }, n, t), te = (e) => ke(U(o.mount ? a : i, e, t.shouldUnregister ? U(i, e, []) : [])), ne = (e, t, n = {}) => {
617
- let i = U(r, e), o = t;
618
- if (i) {
619
- let n = i._f;
620
- n && (!n.disabled && K(a, e, st(t, n)), o = Ke(n.ref) && z(t) ? "" : t, qe(n.ref) ? [...n.ref.options].forEach((e) => e.selected = o.includes(e.value)) : n.refs ? Se(n.ref) ? n.refs.forEach((e) => {
621
- (!e.defaultChecked || !e.disabled) && (Array.isArray(o) ? e.checked = !!o.find((t) => t === e.value) : e.checked = o === e.value || !!o);
622
- }) : n.refs.forEach((e) => e.checked = e.value === o) : Ge(n.ref) ? n.ref.value = "" : (n.ref.value = o, n.ref.type || p.state.next({
623
- name: e,
624
- values: V(a)
625
- })));
626
- }
627
- (n.shouldDirty || n.shouldTouch) && C(e, o, n.shouldTouch, n.shouldDirty, !0), n.shouldValidate && se(e);
628
- }, re = (e, t, n) => {
629
- for (let i in t) {
630
- if (!t.hasOwnProperty(i)) return;
631
- let a = t[i], o = e + "." + i, c = U(r, o);
632
- (s.array.has(e) || B(a) || c && !c._f) && !R(a) ? re(o, a, n) : ne(o, a, n);
633
- }
634
- }, j = (e, t, i = {}) => {
635
- let c = U(r, e), l = s.array.has(e), u = V(t), m = Z(U(a, e), u);
636
- if (K(a, e, u), l) p.array.next({
637
- name: e,
638
- values: V(a)
639
- }), (d.isDirty || d.dirtyFields || f.isDirty || f.dirtyFields) && i.shouldDirty && (v(), p.state.next({
640
- name: e,
641
- dirtyFields: n.dirtyFields,
642
- isDirty: k(e, u)
643
- }));
644
- else {
645
- let t = Array.isArray(u) && !u.length || Q(u);
646
- !c || c._f || z(u) || t ? ne(e, u, i) : re(e, u, i);
647
- }
648
- if (!m) {
649
- let t = vt(e, s);
650
- p.state.next({
651
- ...t && n,
652
- name: o.mount || t ? e : void 0,
653
- values: V(a)
654
- });
655
- }
656
- }, ie = (e) => {
657
- let t = G(e) ? e(a) : e;
658
- Z(a, t) || (a = {
659
- ...a,
660
- ...t
661
- }, p.state.next({
662
- ...n,
663
- values: a
664
- }));
665
- }, ae = async (i) => {
666
- o.mount = !0;
667
- let l = i.target, u = l.name, h = !0, v = U(r, u), y = (e) => {
668
- h = Number.isNaN(e) || R(e) && isNaN(e.getTime()) || Z(e, U(a, u, e));
669
- }, b = mt(t.mode), x = mt(t.reValidateMode);
670
- if (v) {
671
- let o, S, T = l.type ? ut(v._f) : we(i), O = i.type === q.BLUR || i.type === q.FOCUS_OUT, k = !_t(v._f) && !e.validate && !t.resolver && !U(n.errors, u) && !v._f.deps || Ct(O, U(n.touchedFields, u), n.isSubmitted, x, b), A = vt(u, s, O);
672
- K(a, u, T), O ? (!l || !l.readOnly) && (v._f.onBlur && v._f.onBlur(i), c && c(0)) : v._f.onChange && v._f.onChange(i);
673
- let te = C(u, T, O), ne = !Q(te) || A;
674
- if (!O && p.state.next({
675
- name: u,
676
- type: i.type,
677
- values: V(a)
678
- }), k) return (d.isValid || f.isValid) && (t.mode === "onBlur" ? O && g() : O || g()), ne && p.state.next({
679
- name: u,
680
- ...A ? {} : te
681
- });
682
- if (!t.resolver && e.validate && await E({
683
- name: u,
684
- eventType: i.type
685
- }), !O && A && p.state.next({ ...n }), t.resolver) {
686
- let { errors: e } = await w([u]);
687
- if (_([u]), y(T), h) {
688
- let t = bt(n.errors, r, u), i = bt(e, r, t.name || u);
689
- o = i.error, u = i.name, S = Q(e);
690
- }
691
- } else _([u], !0), o = (await Ot(v, s.disabled, a, m, t.shouldUseNativeValidation))[u], _([u]), y(T), h && (o ? S = !1 : (d.isValid || f.isValid) && (S = await D({
692
- fields: r,
693
- onlyCheckValid: !0,
694
- name: u,
695
- eventType: i.type
696
- })));
697
- h && (v._f.deps && (!Array.isArray(v._f.deps) || v._f.deps.length > 0) && se(v._f.deps), ee(u, S, o, te));
698
- }
699
- }, oe = (e, t) => {
700
- if (U(n.errors, t) && e.focus) return e.focus(), 1;
701
- }, se = async (e, i = {}) => {
702
- let a, o, c = He(e);
703
- if (t.resolver) {
704
- let t = await T(H(e) ? e : c);
705
- a = Q(t), o = e ? !c.some((e) => U(t, e)) : a;
706
- } else e ? (o = (await Promise.all(c.map(async (e) => {
707
- let t = U(r, e);
708
- return await D({
709
- fields: t && t._f ? { [e]: t } : t,
710
- eventType: q.TRIGGER
711
- });
712
- }))).every(Boolean), !(!o && !n.isValid) && g()) : o = a = await D({
713
- fields: r,
714
- name: e,
715
- eventType: q.TRIGGER
716
- });
717
- return p.state.next({
718
- ...!X(e) || (d.isValid || f.isValid) && a !== n.isValid ? {} : { name: e },
719
- ...t.resolver || !e ? { isValid: a } : {},
720
- errors: n.errors
721
- }), i.shouldFocus && !o && yt(r, oe, e ? c : s.mount), o;
722
- }, ce = (e, t) => {
723
- let r = { ...o.mount ? a : i };
724
- return t && (r = We(t.dirtyFields ? n.dirtyFields : n.touchedFields, r)), H(e) ? r : X(e) ? U(r, e) : e.map((e) => U(r, e));
725
- }, le = (e, t) => ({
726
- invalid: !!U((t || n).errors, e),
727
- isDirty: !!U((t || n).dirtyFields, e),
728
- error: U((t || n).errors, e),
729
- isValidating: !!U(n.validatingFields, e),
730
- isTouched: !!U((t || n).touchedFields, e)
731
- }), ue = (e) => {
732
- let t = e ? He(e) : void 0;
733
- t?.forEach((e) => $(n.errors, e)), t ? t.forEach((e) => {
734
- p.state.next({
735
- name: e,
736
- errors: n.errors
737
- });
738
- }) : p.state.next({ errors: {} });
739
- }, M = (e, t, i) => {
740
- let a = (U(r, e, { _f: {} })._f || {}).ref, { ref: o, message: s, type: c, ...l } = U(n.errors, e) || {};
741
- K(n.errors, e, {
742
- ...l,
743
- ...t,
744
- ref: a
745
- }), p.state.next({
746
- name: e,
747
- errors: n.errors,
748
- isValid: !1
749
- }), i && i.shouldFocus && a && a.focus && a.focus();
750
- }, de = (e, t) => G(e) ? p.state.subscribe({ next: (n) => "values" in n && e(n.values || A(void 0, t), n) }) : A(e, t, !0), fe = (e) => p.state.subscribe({ next: (t) => {
751
- if (St(e.name, t.name, e.exact) && xt(t, e.formState || d, xe, e.reRenderRoot)) {
752
- let r = { ...a };
753
- e.callback({
754
- values: r,
755
- ...n,
756
- ...t,
757
- defaultValues: i
758
- });
759
- }
760
- } }).unsubscribe, pe = (e) => (o.mount = !0, f = {
761
- ...f,
762
- ...e.formState
763
- }, fe({
764
- ...e,
765
- formState: {
766
- ...u,
767
- ...e.formState
768
- }
769
- })), N = (e, o = {}) => {
770
- for (let c of e ? He(e) : s.mount) s.mount.delete(c), s.array.delete(c), o.keepValue || ($(r, c), $(a, c)), !o.keepError && $(n.errors, c), !o.keepDirty && $(n.dirtyFields, c), !o.keepTouched && $(n.touchedFields, c), !o.keepIsValidating && $(n.validatingFields, c), !t.shouldUnregister && !o.keepDefaultValue && $(i, c);
771
- p.state.next({ values: V(a) }), p.state.next({
772
- ...n,
773
- ...o.keepDirty ? { isDirty: k() } : {}
774
- }), !o.keepIsValid && g();
775
- }, P = ({ disabled: e, name: t }) => {
776
- if (W(e) && o.mount || e || s.disabled.has(t)) {
777
- let n = s.disabled.has(t) !== !!e;
778
- e ? s.disabled.add(t) : s.disabled.delete(t), n && o.mount && !o.action && g();
779
- }
780
- }, F = (e, n = {}) => {
781
- let a = U(r, e), c = W(n.disabled) || W(t.disabled), l = !s.registerName.has(e) && a && a._f && !a._f.mount;
782
- return K(r, e, {
783
- ...a || {},
784
- _f: {
785
- ...a && a._f ? a._f : { ref: { name: e } },
786
- name: e,
787
- mount: !0,
788
- ...n
789
- }
790
- }), s.mount.add(e), a && !l ? P({
791
- disabled: W(n.disabled) ? n.disabled : t.disabled,
792
- name: e
793
- }) : S(e, !0, n.value), {
794
- ...c ? { disabled: n.disabled || t.disabled } : {},
795
- ...t.progressive ? {
796
- required: !!n.required,
797
- min: pt(n.min),
798
- max: pt(n.max),
799
- minLength: pt(n.minLength),
800
- maxLength: pt(n.maxLength),
801
- pattern: pt(n.pattern)
802
- } : {},
803
- name: e,
804
- onChange: ae,
805
- onBlur: ae,
806
- ref: (c) => {
807
- if (c) {
808
- s.registerName.add(e), F(e, n), s.registerName.delete(e), a = U(r, e);
809
- let t = H(c.value) && c.querySelectorAll && c.querySelectorAll("input,select,textarea")[0] || c, o = Ye(t), l = a._f.refs || [];
810
- if (o ? l.find((e) => e === t) : t === a._f.ref) return;
811
- K(r, e, { _f: {
812
- ...a._f,
813
- ...o ? {
814
- refs: [
815
- ...l.filter(Xe),
816
- t,
817
- ...Array.isArray(U(i, e)) ? [{}] : []
818
- ],
819
- ref: {
820
- type: t.type,
821
- name: e
822
- }
823
- } : { ref: t }
824
- } }), S(e, !1, void 0, t);
825
- } else a = U(r, e, {}), a._f && (a._f.mount = !1), (t.shouldUnregister || n.shouldUnregister) && !(Te(s.array, e) && o.action) && s.unMount.add(e);
826
- }
827
- };
828
- }, me = () => t.shouldFocusError && yt(r, oe, s.mount), he = (e) => {
829
- W(e) && (p.state.next({ disabled: e }), yt(r, (t, n) => {
830
- let i = U(r, n);
831
- i && (t.disabled = i._f.disabled || e, Array.isArray(i._f.refs) && i._f.refs.forEach((t) => {
832
- t.disabled = i._f.disabled || e;
833
- }));
834
- }, 0, !1));
835
- }, ge = (e, i) => async (o) => {
836
- let c;
837
- o && (o.preventDefault && o.preventDefault(), o.persist && o.persist());
838
- let l = V(a);
839
- if (p.state.next({ isSubmitting: !0 }), t.resolver) {
840
- let { errors: e, values: t } = await w();
841
- _(), n.errors = e, l = V(t);
842
- } else await D({
843
- fields: r,
844
- eventType: q.SUBMIT
845
- });
846
- if (s.disabled.size) for (let e of s.disabled) $(l, e);
847
- if ($(n.errors, Me), Q(n.errors)) {
848
- p.state.next({ errors: {} });
849
- try {
850
- await e(l, o);
851
- } catch (e) {
852
- c = e;
853
- }
854
- } else i && await i({ ...n.errors }, o), me(), setTimeout(me);
855
- if (p.state.next({
856
- isSubmitted: !0,
857
- isSubmitting: !1,
858
- isSubmitSuccessful: Q(n.errors) && !c,
859
- submitCount: n.submitCount + 1,
860
- errors: n.errors
861
- }), c) throw c;
862
- }, _e = (e, t = {}) => {
863
- U(r, e) && (H(t.defaultValue) ? j(e, V(U(i, e))) : (j(e, t.defaultValue), K(i, e, V(t.defaultValue))), t.keepTouched || $(n.touchedFields, e), t.keepDirty || ($(n.dirtyFields, e), n.isDirty = t.defaultValue ? k(e, V(U(i, e))) : k()), t.keepError || ($(n.errors, e), d.isValid && g()), p.state.next({ ...n }));
864
- }, ve = (e, c = {}) => {
865
- let l = e ? V(e) : i, u = V(l), f = Q(e), m = f ? i : u;
866
- if (c.keepDefaultValues || (i = l), !c.keepValues) {
867
- if (c.keepDirtyValues) {
868
- let e = new Set([...s.mount, ...Object.keys(rt(i, a))]);
869
- for (let t of Array.from(e)) {
870
- let e = U(n.dirtyFields, t), r = U(a, t), i = U(m, t);
871
- e && !H(r) ? K(m, t, r) : !e && !H(i) && j(t, i);
872
- }
873
- } else {
874
- if (De && H(e)) for (let e of s.mount) {
875
- let t = U(r, e);
876
- if (t && t._f) {
877
- let e = Array.isArray(t._f.refs) ? t._f.refs[0] : t._f.ref;
878
- if (Ke(e)) {
879
- let t = e.closest("form");
880
- if (t) {
881
- t.reset();
882
- break;
883
- }
884
- }
885
- }
886
- }
887
- if (c.keepFieldsRef) for (let e of s.mount) j(e, U(m, e));
888
- else r = {};
889
- }
890
- a = t.shouldUnregister ? c.keepDefaultValues ? V(i) : {} : V(m), p.array.next({ values: { ...m } }), p.state.next({ values: { ...m } });
891
- }
892
- s = {
893
- mount: c.keepDirtyValues ? s.mount : /* @__PURE__ */ new Set(),
894
- unMount: /* @__PURE__ */ new Set(),
895
- array: /* @__PURE__ */ new Set(),
896
- registerName: /* @__PURE__ */ new Set(),
897
- disabled: /* @__PURE__ */ new Set(),
898
- watch: /* @__PURE__ */ new Set(),
899
- watchAll: !1,
900
- focus: ""
901
- }, o.mount = !d.isValid || !!c.keepIsValid || !!c.keepDirtyValues || !t.shouldUnregister && !Q(m), o.watch = !!t.shouldUnregister, o.keepIsValid = !!c.keepIsValid, o.action = !1, c.keepErrors || (n.errors = {}), p.state.next({
902
- submitCount: c.keepSubmitCount ? n.submitCount : 0,
903
- isDirty: f ? !1 : c.keepDirty ? n.isDirty : !!(c.keepDefaultValues && !Z(e, i)),
904
- isSubmitted: c.keepIsSubmitted ? n.isSubmitted : !1,
905
- dirtyFields: f ? {} : c.keepDirtyValues ? c.keepDefaultValues && a ? rt(i, a) : n.dirtyFields : c.keepDefaultValues && e ? rt(i, e) : c.keepDirty ? n.dirtyFields : {},
906
- touchedFields: c.keepTouched ? n.touchedFields : {},
907
- errors: c.keepErrors ? n.errors : {},
908
- isSubmitSuccessful: c.keepIsSubmitSuccessful ? n.isSubmitSuccessful : !1,
909
- isSubmitting: !1,
910
- defaultValues: i
911
- });
912
- }, ye = (e, n) => ve(G(e) ? e(a) : e, {
913
- ...t.resetOptions,
914
- ...n
915
- }), be = (e, t = {}) => {
916
- let n = U(r, e), i = n && n._f;
917
- if (i) {
918
- let e = i.refs ? i.refs[0] : i.ref;
919
- e.focus && setTimeout(() => {
920
- e.focus(), t.shouldSelect && G(e.select) && e.select();
921
- });
922
- }
923
- }, xe = (e) => {
924
- n = {
925
- ...n,
926
- ...e
927
- };
928
- }, I = {
929
- control: {
930
- register: F,
931
- unregister: N,
932
- getFieldState: le,
933
- handleSubmit: ge,
934
- setError: M,
935
- _subscribe: fe,
936
- _runSchema: w,
937
- _updateIsValidating: _,
938
- _focusError: me,
939
- _getWatch: A,
940
- _getDirty: k,
941
- _setValid: g,
942
- _setFieldArray: y,
943
- _setDisabledField: P,
944
- _setErrors: x,
945
- _getFieldArray: te,
946
- _reset: ve,
947
- _resetDefaultValues: () => G(t.defaultValues) && t.defaultValues().then((e) => {
948
- ye(e, t.resetOptions), p.state.next({ isLoading: !1 });
949
- }),
950
- _removeUnmounted: O,
951
- _disableForm: he,
952
- _subjects: p,
953
- _proxyFormState: d,
954
- get _fields() {
955
- return r;
956
- },
957
- get _formValues() {
958
- return a;
959
- },
960
- get _state() {
961
- return o;
962
- },
963
- set _state(e) {
964
- o = e;
965
- },
966
- get _defaultValues() {
967
- return i;
968
- },
969
- get _names() {
970
- return s;
971
- },
972
- set _names(e) {
973
- s = e;
974
- },
975
- get _formState() {
976
- return n;
977
- },
978
- get _options() {
979
- return t;
980
- },
981
- set _options(e) {
982
- t = {
983
- ...t,
984
- ...e
985
- };
986
- }
987
- },
988
- subscribe: pe,
989
- trigger: se,
990
- register: F,
991
- handleSubmit: ge,
992
- watch: de,
993
- setValue: j,
994
- setValues: ie,
995
- getValues: ce,
996
- reset: ye,
997
- resetField: _e,
998
- clearErrors: ue,
999
- unregister: N,
1000
- setError: M,
1001
- setFocus: be,
1002
- getFieldState: le
1003
- };
1004
- return {
1005
- ...I,
1006
- formControl: I
1007
- };
1008
- }
1009
- function Mt(e = {}) {
1010
- let t = N.useRef(void 0), n = N.useRef(void 0), [r, i] = N.useState(() => ({
1011
- ...V(At),
1012
- isLoading: G(e.defaultValues),
1013
- errors: e.errors || {},
1014
- disabled: e.disabled || !1,
1015
- defaultValues: G(e.defaultValues) ? void 0 : e.defaultValues
1016
- }));
1017
- if (!t.current) if (e.formControl) t.current = {
1018
- ...e.formControl,
1019
- formState: r
1020
- }, e.defaultValues && !G(e.defaultValues) && e.formControl.reset(e.defaultValues, e.resetOptions);
1021
- else {
1022
- let { formControl: n, ...i } = jt(e);
1023
- t.current = {
1024
- ...i,
1025
- formState: r
1026
- };
1027
- }
1028
- let a = t.current.control;
1029
- return a._options = e, Ie(() => {
1030
- let e = a._subscribe({
1031
- formState: a._proxyFormState,
1032
- callback: () => i({ ...a._formState }),
1033
- reRenderRoot: !0
1034
- });
1035
- return i((e) => ({
1036
- ...e,
1037
- isReady: !0
1038
- })), a._formState.isReady = !0, e;
1039
- }, [a]), N.useEffect(() => a._disableForm(e.disabled), [a, e.disabled]), N.useEffect(() => {
1040
- e.mode && (a._options.mode = e.mode), e.reValidateMode && (a._options.reValidateMode = e.reValidateMode);
1041
- }, [
1042
- a,
1043
- e.mode,
1044
- e.reValidateMode
1045
- ]), N.useEffect(() => {
1046
- e.errors && (a._setErrors(e.errors), a._focusError());
1047
- }, [a, e.errors]), N.useEffect(() => {
1048
- e.shouldUnregister && a._subjects.state.next({ values: a._getWatch() });
1049
- }, [a, e.shouldUnregister]), N.useEffect(() => {
1050
- if (a._proxyFormState.isDirty) {
1051
- let e = a._getDirty();
1052
- e !== r.isDirty && a._subjects.state.next({ isDirty: e });
1053
- }
1054
- }, [a, r.isDirty]), N.useEffect(() => {
1055
- e.values && !Z(e.values, n.current) ? (a._reset(e.values, {
1056
- keepFieldsRef: !0,
1057
- ...a._options.resetOptions
1058
- }), a._options.resetOptions?.keepIsValid || a._setValid(), n.current = e.values, i((e) => ({ ...e }))) : a._resetDefaultValues();
1059
- }, [a, e.values]), N.useEffect(() => {
1060
- a._state.mount || (a._setValid(), a._state.mount = !0), a._state.watch && (a._state.watch = !1, a._subjects.state.next({ ...a._formState })), a._removeUnmounted();
1061
- }), t.current.formState = N.useMemo(() => Fe(r, a), [a, r]), t.current;
1062
- }
1063
- //#endregion
1064
- //#region node_modules/@hookform/resolvers/dist/resolvers.mjs
1065
- var Nt = (e, t, n) => {
1066
- if (e && "reportValidity" in e) {
1067
- let r = U(n, t);
1068
- e.setCustomValidity(r && r.message || ""), e.reportValidity();
1069
- }
1070
- }, Pt = (e, t) => {
1071
- for (let n in t.fields) {
1072
- let r = t.fields[n];
1073
- r && r.ref && "reportValidity" in r.ref ? Nt(r.ref, n, e) : r && r.refs && r.refs.forEach((t) => Nt(t, n, e));
1074
- }
1075
- }, Ft = (e, t) => {
1076
- t.shouldUseNativeValidation && Pt(e, t);
1077
- let n = {};
1078
- for (let r in e) {
1079
- let i = U(t.fields, r), a = Object.assign(e[r] || {}, { ref: i && i.ref });
1080
- if (It(t.names || Object.keys(e), r)) {
1081
- let e = Object.assign({}, U(n, r));
1082
- K(e, "root", a), K(n, r, e);
1083
- } else K(n, r, a);
1084
- }
1085
- return n;
1086
- }, It = (e, t) => {
1087
- let n = Lt(t);
1088
- return e.some((e) => Lt(e).match(`^${n}\\.\\d+`));
1089
- };
1090
- function Lt(e) {
1091
- return e.replace(/\]|\[/g, "");
1092
- }
1093
- //#endregion
1094
- //#region node_modules/@hookform/resolvers/zod/dist/zod.mjs
1095
- function Rt(e, t) {
1096
- try {
1097
- var n = e();
1098
- } catch (e) {
1099
- return t(e);
1100
- }
1101
- return n && n.then ? n.then(void 0, t) : n;
1102
- }
1103
- function zt(e, t) {
1104
- for (var n = {}; e.length;) {
1105
- var r = e[0], i = r.code, a = r.message, o = r.path.join(".");
1106
- if (!n[o]) if ("unionErrors" in r) {
1107
- var s = r.unionErrors[0].errors[0];
1108
- n[o] = {
1109
- message: s.message,
1110
- type: s.code
1111
- };
1112
- } else n[o] = {
1113
- message: a,
1114
- type: i
1115
- };
1116
- if ("unionErrors" in r && r.unionErrors.forEach(function(t) {
1117
- return t.errors.forEach(function(t) {
1118
- return e.push(t);
1119
- });
1120
- }), t) {
1121
- var c = n[o].types, l = c && c[r.code];
1122
- n[o] = Ve(o, t, n, i, l ? [].concat(l, r.message) : r.message);
1123
- }
1124
- e.shift();
1125
- }
1126
- return n;
1127
- }
1128
- function Bt(e, t) {
1129
- for (var n = {}; e.length;) {
1130
- var r = e[0], i = r.code, a = r.message, o = r.path.join(".");
1131
- if (!n[o]) if (r.code === "invalid_union" && r.errors.length > 0) {
1132
- var s = r.errors[0][0];
1133
- n[o] = {
1134
- message: s.message,
1135
- type: s.code
1136
- };
1137
- } else n[o] = {
1138
- message: a,
1139
- type: i
1140
- };
1141
- if (r.code === "invalid_union" && r.errors.forEach(function(t) {
1142
- return t.forEach(function(t) {
1143
- return e.push(t);
1144
- });
1145
- }), t) {
1146
- var c = n[o].types, l = c && c[r.code];
1147
- n[o] = Ve(o, t, n, i, l ? [].concat(l, r.message) : r.message);
1148
- }
1149
- e.shift();
1150
- }
1151
- return n;
1152
- }
1153
- function Vt(e, t, n) {
1154
- if (n === void 0 && (n = {}), function(e) {
1155
- return "_def" in e && typeof e._def == "object" && "typeName" in e._def;
1156
- }(e)) return function(r, i, a) {
1157
- try {
1158
- return Promise.resolve(Rt(function() {
1159
- return Promise.resolve(e[n.mode === "sync" ? "parse" : "parseAsync"](r, t)).then(function(e) {
1160
- return a.shouldUseNativeValidation && Pt({}, a), {
1161
- errors: {},
1162
- values: n.raw ? Object.assign({}, r) : e
1163
- };
1164
- });
1165
- }, function(e) {
1166
- if (function(e) {
1167
- return Array.isArray(e?.issues);
1168
- }(e)) return {
1169
- values: {},
1170
- errors: Ft(zt(e.errors, !a.shouldUseNativeValidation && a.criteriaMode === "all"), a)
1171
- };
1172
- throw e;
1173
- }));
1174
- } catch (e) {
1175
- return Promise.reject(e);
1176
- }
1177
- };
1178
- if (function(e) {
1179
- return "_zod" in e && typeof e._zod == "object";
1180
- }(e)) return function(r, i, a) {
1181
- try {
1182
- return Promise.resolve(Rt(function() {
1183
- return Promise.resolve((n.mode === "sync" ? O : ee)(e, r, t)).then(function(e) {
1184
- return a.shouldUseNativeValidation && Pt({}, a), {
1185
- errors: {},
1186
- values: n.raw ? Object.assign({}, r) : e
1187
- };
1188
- });
1189
- }, function(e) {
1190
- if (function(e) {
1191
- return e instanceof S;
1192
- }(e)) return {
1193
- values: {},
1194
- errors: Ft(Bt(e.issues, !a.shouldUseNativeValidation && a.criteriaMode === "all"), a)
1195
- };
1196
- throw e;
1197
- }));
1198
- } catch (e) {
1199
- return Promise.reject(e);
1200
- }
1201
- };
1202
- throw Error("Invalid input: not a Zod schema");
1203
- }
1204
- //#endregion
1205
- //#region src/base/form/form-utils.ts
1206
- function Ht(e) {
1207
- let t = [];
1208
- for (let n of e) n.kind === "field" ? t.push(n) : (n.kind === "section" || n.kind === "group") && t.push(...Ht(n.children));
1209
- return t;
1210
- }
1211
- function Ut(e, t) {
1212
- if (e.component === "header") return !0;
1213
- let { props: n } = e;
1214
- return !(n.hidden_when && r(n.hidden_when, t) || n.visible_when && !r(n.visible_when, t));
1215
- }
1216
- //#endregion
1217
- //#region src/base/form/form-schema-builder.ts
1218
- function Wt(e, t) {
1219
- let { component: n, props: r } = e, i = r.validation, a = r.required;
1220
- switch (n) {
1221
- case "text":
1222
- case "textarea":
1223
- case "password":
1224
- case "slug":
1225
- case "color": {
1226
- let e = b();
1227
- return a && (e = e.min(1, t("middag.ui.validation.required"))), i?.minLength && (e = e.min(i.minLength, t("middag.ui.validation.min_length", { min: i.minLength }))), i?.maxLength && (e = e.max(i.maxLength, t("middag.ui.validation.max_length", { max: i.maxLength }))), i?.pattern && (e = e.regex(new RegExp(i.pattern), i.patternMessage ?? t("middag.ui.validation.pattern"))), a ? e : e.or(_(""));
1228
- }
1229
- case "email": {
1230
- let e = b();
1231
- if (a) e = e.min(1, t("middag.ui.validation.required")).email(t("middag.ui.validation.email"));
1232
- else return e.email(t("middag.ui.validation.email")).or(_(""));
1233
- return e;
1234
- }
1235
- case "url": {
1236
- let e = b();
1237
- if (a) e = e.min(1, t("middag.ui.validation.required")).url(t("middag.ui.validation.url"));
1238
- else return e.url(t("middag.ui.validation.url")).or(_(""));
1239
- return e;
1240
- }
1241
- case "int": {
1242
- let e = E({ message: t("middag.ui.validation.integer") }).int(t("middag.ui.validation.integer"));
1243
- return r.min != null && (e = e.min(r.min, t("middag.ui.validation.min_value", { min: r.min }))), r.max != null && (e = e.max(r.max, t("middag.ui.validation.max_value", { max: r.max }))), a ? e : e.nullable();
1244
- }
1245
- case "float": {
1246
- let e = E();
1247
- return r.min != null && (e = e.min(r.min, t("middag.ui.validation.min_value", { min: r.min }))), r.max != null && (e = e.max(r.max, t("middag.ui.validation.max_value", { max: r.max }))), a ? e : e.nullable();
1248
- }
1249
- case "currency": {
1250
- let e = E();
1251
- return a ? e : e.nullable();
1252
- }
1253
- case "select":
1254
- case "radio":
1255
- case "entity_picker": {
1256
- let e = b();
1257
- return a ? e.min(1, t("middag.ui.validation.required")) : e;
1258
- }
1259
- case "multiselect":
1260
- case "tags": {
1261
- let e = te(b());
1262
- return a ? e.min(1, t("middag.ui.validation.required")) : e;
1263
- }
1264
- case "checkbox":
1265
- case "switch": return ie();
1266
- case "date":
1267
- case "datetime": {
1268
- let e = b();
1269
- return a ? e.min(1, t("middag.ui.validation.required")) : e;
1270
- }
1271
- case "phone": {
1272
- let e = b();
1273
- return a ? e.min(1, t("middag.ui.validation.required")) : e;
1274
- }
1275
- case "document": {
1276
- let e = r.documentType ?? "generic", n = r.documentScope ?? "any", i = b();
1277
- return a ? i.min(1, t("middag.ui.validation.required")).refine((t) => pe(t, e, n), t("middag.ui.validation.document_invalid")) : i.refine((t) => t === "" || pe(t, e, n), t("middag.ui.validation.document_invalid"));
1278
- }
1279
- default: return h();
1280
- }
1281
- }
1282
- function Gt(e, t, n) {
1283
- let r = Ht(e), i = {};
1284
- for (let e of r) e.component === "header" || e.component === "hidden" || e.component === "static" || Ut(e, t) && (i[e.key] = Wt(e, n));
1285
- return se(i);
1286
- }
1287
- //#endregion
1288
- //#region src/base/form/FormField.tsx
1289
- var Kt = F(() => import("./PhoneField-fFUyYj--.js").then((e) => ({ default: e.PhoneField }))), qt = F(() => import("./DateField-CU9qDJwH.js").then((e) => ({ default: e.DateField }))), Jt = F(() => import("./DocumentField-COJZZV5_.js").then((e) => ({ default: e.DocumentField }))), Yt = F(() => import("./DateRangeField-CvU7wiyr.js").then((e) => ({ default: e.DateRangeField })));
1290
- function Xt() {
1291
- return /* @__PURE__ */ I(fe, { className: "h-9 w-full rounded-md" });
1292
- }
1293
- function Zt({ label: e }) {
1294
- return /* @__PURE__ */ I("div", {
1295
- className: "pt-4 pb-1",
1296
- children: /* @__PURE__ */ I("h4", {
1297
- className: "text-foreground text-sm font-semibold",
1298
- children: e
1299
- })
1300
- });
1301
- }
1302
- function Qt({ id: e, value: t }) {
1303
- return /* @__PURE__ */ I("input", {
1304
- type: "hidden",
1305
- id: e,
1306
- value: String(t ?? "")
1307
- });
1308
- }
1309
- function $t({ field: e, value: t, onChange: n, error: r }) {
1310
- let { t: i } = de(), a = ge(), o = `field-${e.key}-${a}`, s = `${o}-help`, c = `${o}-error`, { component: l, props: d } = e;
1311
- if (l === "header") return /* @__PURE__ */ I(Zt, { label: d.label });
1312
- if (l === "hidden") return /* @__PURE__ */ I(Qt, {
1313
- id: o,
1314
- value: t
1315
- });
1316
- let f = l === "checkbox" || l === "switch", p = en(l, o, t, n, d, r, s, c, i);
1317
- return /* @__PURE__ */ L("div", {
1318
- className: "space-y-1.5",
1319
- children: [
1320
- !f && /* @__PURE__ */ L(u, {
1321
- htmlFor: o,
1322
- children: [d.label, d.required && /* @__PURE__ */ I("span", {
1323
- className: "text-destructive ml-0.5",
1324
- children: "*"
1325
- })]
1326
- }),
1327
- d.helpText && /* @__PURE__ */ I("p", {
1328
- id: s,
1329
- className: "text-muted-foreground text-xs",
1330
- children: d.helpText
1331
- }),
1332
- p,
1333
- r && /* @__PURE__ */ I("p", {
1334
- id: c,
1335
- className: "text-destructive text-xs",
1336
- "aria-live": "polite",
1337
- children: r
1338
- })
1339
- ]
1340
- });
1341
- }
1342
- function en(e, t, r, i, a, o, s, c, u) {
1343
- let d = {
1344
- id: t,
1345
- error: o,
1346
- helpTextId: s,
1347
- errorId: c,
1348
- disabled: a.disabled,
1349
- required: a.required
1350
- };
1351
- switch (e) {
1352
- case "text": return /* @__PURE__ */ I(k, {
1353
- ...d,
1354
- type: "text",
1355
- value: r,
1356
- onChange: i,
1357
- placeholder: a.placeholder,
1358
- readOnly: a.readOnly
1359
- });
1360
- case "email": return /* @__PURE__ */ I(k, {
1361
- ...d,
1362
- type: "email",
1363
- value: r,
1364
- onChange: i,
1365
- placeholder: a.placeholder,
1366
- readOnly: a.readOnly
1367
- });
1368
- case "url": return /* @__PURE__ */ I(k, {
1369
- ...d,
1370
- type: "url",
1371
- value: r,
1372
- onChange: i,
1373
- placeholder: a.placeholder,
1374
- readOnly: a.readOnly
1375
- });
1376
- case "textarea": return /* @__PURE__ */ I(re, {
1377
- ...d,
1378
- value: r,
1379
- onChange: i,
1380
- placeholder: a.placeholder,
1381
- rows: a.rows,
1382
- readOnly: a.readOnly
1383
- });
1384
- case "password": return /* @__PURE__ */ I(y, {
1385
- ...d,
1386
- value: r,
1387
- onChange: i,
1388
- placeholder: a.placeholder
1389
- });
1390
- case "otp": return /* @__PURE__ */ I(ne, {
1391
- ...d,
1392
- value: r,
1393
- onChange: i,
1394
- maxLength: a.maxLength,
1395
- pattern: a.pattern,
1396
- groupSize: a.groupSize
1397
- });
1398
- case "select": return /* @__PURE__ */ I(T, {
1399
- ...d,
1400
- value: r,
1401
- onChange: i,
1402
- options: a.options ?? [],
1403
- placeholder: a.placeholder
1404
- });
1405
- case "native_select": return /* @__PURE__ */ I(C, {
1406
- ...d,
1407
- value: r,
1408
- onChange: i,
1409
- options: a.options ?? [],
1410
- placeholder: a.placeholder
1411
- });
1412
- case "multiselect": return /* @__PURE__ */ I(x, {
1413
- ...d,
1414
- value: r,
1415
- onChange: i,
1416
- options: a.options ?? [],
1417
- placeholder: a.placeholder
1418
- });
1419
- case "radio": return /* @__PURE__ */ I(v, {
1420
- ...d,
1421
- value: r,
1422
- onChange: i,
1423
- options: a.options ?? []
1424
- });
1425
- case "int": return /* @__PURE__ */ I(D, {
1426
- ...d,
1427
- value: r,
1428
- onChange: i,
1429
- min: a.min,
1430
- max: a.max,
1431
- step: 1
1432
- });
1433
- case "float": return /* @__PURE__ */ I(D, {
1434
- ...d,
1435
- value: r,
1436
- onChange: i,
1437
- min: a.min,
1438
- max: a.max,
1439
- step: a.step ?? .1
1440
- });
1441
- case "slider": return /* @__PURE__ */ I(g, {
1442
- ...d,
1443
- value: r,
1444
- onChange: i,
1445
- min: a.min,
1446
- max: a.max,
1447
- step: a.step,
1448
- multiple: a.multiple
1449
- });
1450
- case "checkbox": return /* @__PURE__ */ I(le, {
1451
- ...d,
1452
- value: r,
1453
- onChange: i,
1454
- label: a.label
1455
- });
1456
- case "switch": return /* @__PURE__ */ I(m, {
1457
- ...d,
1458
- value: r,
1459
- onChange: i,
1460
- label: a.label
1461
- });
1462
- case "date": return /* @__PURE__ */ I(P, {
1463
- fallback: /* @__PURE__ */ I(Xt, {}),
1464
- children: /* @__PURE__ */ I(qt, {
1465
- ...d,
1466
- mode: "date",
1467
- value: r,
1468
- onChange: i,
1469
- placeholder: a.placeholder
1470
- })
1471
- });
1472
- case "datetime": return /* @__PURE__ */ I(P, {
1473
- fallback: /* @__PURE__ */ I(Xt, {}),
1474
- children: /* @__PURE__ */ I(qt, {
1475
- ...d,
1476
- mode: "datetime",
1477
- value: r,
1478
- onChange: i,
1479
- placeholder: a.placeholder
1480
- })
1481
- });
1482
- case "file": return /* @__PURE__ */ I(p, {
1483
- ...d,
1484
- value: r,
1485
- onChange: i,
1486
- accept: a.accept,
1487
- multiple: a.multiple,
1488
- maxFiles: a.maxFiles,
1489
- maxSize: a.maxSize
1490
- });
1491
- case "entity_picker": return /* @__PURE__ */ I(ce, {
1492
- ...d,
1493
- value: r,
1494
- onChange: i,
1495
- options: a.options,
1496
- autocompleteHref: a.autocompleteHref,
1497
- autocompleteMinChars: a.autocompleteMinChars,
1498
- initialOption: a.initialOption,
1499
- entityAvatarField: a.entityAvatarField,
1500
- entitySubtitleField: a.entitySubtitleField,
1501
- placeholder: a.placeholder
1502
- });
1503
- case "static": return /* @__PURE__ */ I(A, {
1504
- id: t,
1505
- value: r
1506
- });
1507
- case "phone": return /* @__PURE__ */ I(P, {
1508
- fallback: /* @__PURE__ */ I(Xt, {}),
1509
- children: /* @__PURE__ */ I(Kt, {
1510
- ...d,
1511
- value: r,
1512
- onChange: i,
1513
- placeholder: a.placeholder,
1514
- defaultCountry: a.defaultCountry,
1515
- fixedCountry: a.fixedCountry
1516
- })
1517
- });
1518
- case "document": return /* @__PURE__ */ I(P, {
1519
- fallback: /* @__PURE__ */ I(Xt, {}),
1520
- children: /* @__PURE__ */ I(Jt, {
1521
- ...d,
1522
- value: r,
1523
- onChange: i,
1524
- documentType: a.documentType,
1525
- documentScope: a.documentScope,
1526
- documentMasks: a.documentMasks,
1527
- placeholder: a.placeholder
1528
- })
1529
- });
1530
- case "currency": return /* @__PURE__ */ I(l, {
1531
- ...d,
1532
- value: r,
1533
- onChange: i,
1534
- currency: a.currency,
1535
- placeholder: a.placeholder,
1536
- min: a.min,
1537
- max: a.max
1538
- });
1539
- case "color": return /* @__PURE__ */ I(n, {
1540
- ...d,
1541
- value: r,
1542
- onChange: i,
1543
- placeholder: a.placeholder
1544
- });
1545
- case "slug": return /* @__PURE__ */ I(j, {
1546
- ...d,
1547
- value: r,
1548
- onChange: i,
1549
- sourceValue: a.sourceField,
1550
- prefix: a.prefix,
1551
- placeholder: a.placeholder
1552
- });
1553
- case "tags": return /* @__PURE__ */ I(w, {
1554
- ...d,
1555
- value: r,
1556
- onChange: i,
1557
- placeholder: a.placeholder,
1558
- maxTags: a.maxTags
1559
- });
1560
- case "date_range": return /* @__PURE__ */ I(P, {
1561
- fallback: /* @__PURE__ */ I(Xt, {}),
1562
- children: /* @__PURE__ */ I(Yt, {
1563
- ...d,
1564
- value: r,
1565
- onChange: i,
1566
- operator: a.operator
1567
- })
1568
- });
1569
- case "rating": return /* @__PURE__ */ I(oe, {
1570
- ...d,
1571
- value: r,
1572
- onChange: i,
1573
- maxRating: a.maxRating
1574
- });
1575
- default: return /* @__PURE__ */ L("p", {
1576
- className: "text-destructive text-xs",
1577
- children: ["Unknown field component: ", e]
1578
- });
1579
- }
1580
- }
1581
- //#endregion
1582
- //#region src/base/blocks/FormPanelBlock.tsx
1583
- function tn({ nodes: t, values: n, errors: r, onChange: i }) {
1584
- return /* @__PURE__ */ I(xe, { children: t.map((t, a) => {
1585
- switch (t.kind) {
1586
- case "field": return Ut(t, n) ? /* @__PURE__ */ I($t, {
1587
- field: t,
1588
- value: n[t.key] ?? "",
1589
- onChange: (e) => i(t.key, e),
1590
- error: r[t.key]
1591
- }, t.key) : null;
1592
- case "section": return /* @__PURE__ */ I(ae, {
1593
- id: t.id,
1594
- title: t.label,
1595
- defaultCollapsed: t.defaultCollapsed,
1596
- hasErrors: t.children.some((e) => e.kind === "field" && !!r[e.key]),
1597
- errorCount: t.children.filter((e) => e.kind === "field" && !!r[e.key]).length,
1598
- children: /* @__PURE__ */ I(tn, {
1599
- nodes: t.children,
1600
- values: n,
1601
- errors: r,
1602
- onChange: i
1603
- })
1604
- }, t.id);
1605
- case "group": return /* @__PURE__ */ I("div", {
1606
- className: e("grid gap-6", t.columns === 2 ? "md:grid-cols-2" : "grid-cols-1"),
1607
- children: /* @__PURE__ */ I(tn, {
1608
- nodes: t.children,
1609
- values: n,
1610
- errors: r,
1611
- onChange: i
1612
- })
1613
- }, t.id);
1614
- case "header": return /* @__PURE__ */ L("div", {
1615
- className: "space-y-2",
1616
- children: [/* @__PURE__ */ I(o, {}), /* @__PURE__ */ I("h4", {
1617
- className: "text-foreground text-base font-semibold",
1618
- children: t.label
1619
- })]
1620
- }, `header-${a}`);
1621
- default: return null;
1622
- }
1623
- }) });
1624
- }
1625
- function nn({ block: e }) {
1626
- let { t: n } = de(), { data: r } = e, o = _e(() => Ht(r.schema), [r.schema]), l = (r.meta.validation ?? "both") !== "server", u = _e(() => Object.fromEntries(o.map((e) => [e.key, r.values[e.key] ?? ""])), [o, r.values]), p = ve(l ? Gt(r.schema, u, n) : null), m = Mt({
1627
- defaultValues: u,
1628
- mode: "onTouched",
1629
- resolver: _e(() => {
1630
- if (l) return async (e, t, n) => p.current ? Vt(p.current)(e, t, n) : {
1631
- values: e,
1632
- errors: {}
1633
- };
1634
- }, [l])
1635
- }), h = ze({ control: m.control }) ?? u, g = o.map((e) => Ut(e, h) ? "1" : "0").join("");
1636
- he(() => {
1637
- l && (p.current = Gt(r.schema, h, n));
1638
- }, [
1639
- l,
1640
- r.schema,
1641
- n,
1642
- g
1643
- ]);
1644
- let [_, v] = ye(!1), [y, b] = ye(null);
1645
- he(() => {
1646
- if (Object.keys(r.errors).length > 0) for (let [e, t] of Object.entries(r.errors)) m.setError(e, {
1647
- type: "server",
1648
- message: t
1649
- });
1650
- }, [JSON.stringify(r.errors)]);
1651
- let { isDirty: x, isSubmitting: S } = m.formState;
1652
- he(() => {
1653
- if (!x) return;
1654
- let e = (e) => {
1655
- e.preventDefault();
1656
- };
1657
- return window.addEventListener("beforeunload", e), () => window.removeEventListener("beforeunload", e);
1658
- }, [x]);
1659
- let C = me((e, t) => {
1660
- m.setValue(e, t, {
1661
- shouldDirty: !0,
1662
- shouldValidate: m.formState.isSubmitted
1663
- }), m.clearErrors(e);
1664
- }, [m]), ee = me((e) => {
1665
- let t = o.filter((t) => Ut(t, e)), n = Object.fromEntries(t.map((t) => [t.key, e[t.key]])), i = Object.values(n).some((e) => e instanceof File || Array.isArray(e) && e.some((e) => e instanceof File));
1666
- be[r.method === "put" ? "put" : r.method === "patch" ? "patch" : "post"](r.action, n, {
1667
- forceFormData: i,
1668
- onProgress: (e) => {
1669
- e && typeof e.percentage == "number" && b(Math.round(e.percentage));
1670
- },
1671
- onError: (e) => {
1672
- for (let [t, n] of Object.entries(e)) m.setError(t, {
1673
- type: "server",
1674
- message: n
1675
- });
1676
- },
1677
- onFinish: () => b(null)
1678
- });
1679
- }, [
1680
- o,
1681
- r,
1682
- m
1683
- ]), w = me(() => {
1684
- x ? v(!0) : r.meta.cancelHref ? be.visit(r.meta.cancelHref) : window.history.back();
1685
- }, [x, r.meta.cancelHref]), T = _e(() => {
1686
- let e = {};
1687
- for (let [t, n] of Object.entries(m.formState.errors)) n?.message && (e[t] = n.message);
1688
- return e;
1689
- }, [m.formState.errors]);
1690
- return o.filter((e) => Ut(e, h)).length === 0 && r.schema.length === 0 ? /* @__PURE__ */ I(s, {
1691
- variant: "inline",
1692
- title: n("middag.ui.form.no_fields")
1693
- }) : /* @__PURE__ */ L(xe, { children: [/* @__PURE__ */ L("form", {
1694
- onSubmit: m.handleSubmit(ee),
1695
- className: "mx-auto max-w-[720px] space-y-6",
1696
- noValidate: !0,
1697
- role: "form",
1698
- "aria-label": i(e.title, n) || n("middag.ui.form.default_title"),
1699
- children: [/* @__PURE__ */ I(tn, {
1700
- nodes: r.schema,
1701
- values: h,
1702
- errors: T,
1703
- onChange: C
1704
- }), /* @__PURE__ */ L("div", {
1705
- className: "flex gap-3 pt-4",
1706
- children: [/* @__PURE__ */ I(M, {
1707
- type: "submit",
1708
- disabled: S,
1709
- "aria-disabled": S,
1710
- "aria-busy": S,
1711
- children: S ? y === null ? n("middag.ui.form.saving") : `${n("middag.ui.form.saving")} ${y}%` : r.meta.submitLabel ?? n("middag.ui.form.save")
1712
- }), /* @__PURE__ */ I(M, {
1713
- type: "button",
1714
- variant: "outline",
1715
- onClick: w,
1716
- children: r.meta.cancelLabel ?? n("middag.ui.cancel")
1717
- })]
1718
- })]
1719
- }), /* @__PURE__ */ I(c, {
1720
- open: _,
1721
- onOpenChange: v,
1722
- children: /* @__PURE__ */ L(ue, { children: [/* @__PURE__ */ L(a, { children: [/* @__PURE__ */ I(d, { children: n("middag.ui.form.dirty_title") }), /* @__PURE__ */ I(t, { children: n("middag.ui.form.dirty_message") })] }), /* @__PURE__ */ L(f, { children: [/* @__PURE__ */ I(M, {
1723
- variant: "outline",
1724
- onClick: () => v(!1),
1725
- children: n("middag.ui.cancel")
1726
- }), /* @__PURE__ */ I(M, {
1727
- variant: "destructive",
1728
- onClick: () => {
1729
- v(!1), r.meta.cancelHref ? be.visit(r.meta.cancelHref) : window.history.back();
1730
- },
1731
- children: n("middag.ui.form.dirty_leave")
1732
- })] })] })
1733
- })] });
1734
- }
1735
- //#endregion
1736
- export { nn as FormPanelBlock };