@opennsw/jsonforms-renderers 0.9.0 → 0.11.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.
@@ -1,195 +1,194 @@
1
- var Ar = Object.defineProperty;
2
- var Cr = (e, t, r) => t in e ? Ar(e, t, { enumerable: !0, configurable: !0, writable: !0, value: r }) : e[t] = r;
3
- var Ze = (e, t, r) => Cr(e, typeof t != "symbol" ? t + "" : t, r);
4
- import { jsx as n, jsxs as g, Fragment as he } from "react/jsx-runtime";
5
- import { useContext as cr, createContext as ar, useMemo as Be, useEffect as ge, useState as $, useRef as pe, useCallback as ke } from "react";
6
- import { rankWith as q, isStringControl as Sr, or as We, isNumberControl as Or, isIntegerControl as Nr, isBooleanControl as xr, isEnumControl as ur, isOneOfControl as dr, schemaMatches as ze, isDateControl as Ir, isDateTimeControl as kr, isTimeControl as Dr, uiTypeIs as Le, and as Mr, Resolve as je, update as zr, createDefaultValue as Lr, isObjectArrayControl as Fr, isPrimitiveArrayControl as Ur } from "@jsonforms/core";
7
- import { withJsonFormsControlProps as me, JsonFormsDispatch as Fe, useJsonForms as fr, withJsonFormsArrayControlProps as Pr } from "@jsonforms/react";
8
- import { Box as x, Flex as S, Text as h, TextField as Se, Checkbox as $r, RadioGroup as Qe, Select as Pe, ScrollArea as _r, Spinner as xe, Button as De, Tabs as $e, Heading as hr, Card as pr, IconButton as Me, Table as Re, Tooltip as He } from "@radix-ui/themes";
9
- import { ChevronDownIcon as Vr, FileTextIcon as Hr, CheckCircledIcon as Wr, Cross2Icon as Ye, ExclamationTriangleIcon as Je, UploadIcon as Ne, TrashIcon as Xr, PlusIcon as Br } from "@radix-ui/react-icons";
10
- import jr from "dayjs";
11
- import { read as Kr, utils as Gr } from "@e965/xlsx";
12
- const mr = ar(null);
13
- function no({
1
+ var Jt = Object.defineProperty;
2
+ var Zt = (e, r, t) => r in e ? Jt(e, r, { enumerable: !0, configurable: !0, writable: !0, value: t }) : e[r] = t;
3
+ var ut = (e, r, t) => Zt(e, typeof r != "symbol" ? r + "" : r, t);
4
+ import { jsx as i, jsxs as y, Fragment as ge } from "react/jsx-runtime";
5
+ import { useContext as Rt, createContext as Ct, useMemo as _e, useEffect as de, useState as j, useRef as ae, useCallback as Fe } from "react";
6
+ import { rankWith as ee, isStringControl as Qt, or as Je, isNumberControl as er, isIntegerControl as tr, isBooleanControl as rr, isEnumControl as St, isOneOfControl as Ot, Resolve as Ve, schemaMatches as Ie, isDateControl as nr, isDateTimeControl as or, isTimeControl as ir, uiTypeIs as He, and as Nt, not as sr, optionIs as lr, update as cr, createDefaultValue as ar, isObjectArrayControl as ur, isPrimitiveArrayControl as dr } from "@jsonforms/core";
7
+ import { withJsonFormsControlProps as ue, useJsonForms as We, JsonFormsDispatch as Be, withJsonFormsArrayControlProps as fr } from "@jsonforms/react";
8
+ import { Box as S, Flex as D, Text as f, TextField as Ae, Checkbox as pr, RadioGroup as dt, ScrollArea as kt, Select as Ke, Spinner as Ue, Button as De, Tabs as Ye, Heading as It, Card as Dt, IconButton as je, Table as Te, Tooltip as qe } from "@radix-ui/themes";
9
+ import { ChevronDownIcon as Lt, FileTextIcon as hr, CheckCircledIcon as mr, Cross2Icon as rt, ExclamationTriangleIcon as nt, UploadIcon as ze, DownloadIcon as Mt, TrashIcon as gr, PlusIcon as yr } from "@radix-ui/react-icons";
10
+ import zt from "dayjs";
11
+ const Ft = Ct(null);
12
+ function ei({
14
13
  children: e,
15
- onUpload: t,
16
- getDownloadUrl: r
14
+ onUpload: r,
15
+ getDownloadUrl: t
17
16
  }) {
18
- const o = { onUpload: t, getDownloadUrl: r };
19
- return /* @__PURE__ */ n(mr.Provider, { value: o, children: e });
17
+ const n = { onUpload: r, getDownloadUrl: t };
18
+ return /* @__PURE__ */ i(Ft.Provider, { value: n, children: e });
20
19
  }
21
- function Yr() {
22
- return cr(mr);
20
+ function br() {
21
+ return Rt(Ft);
23
22
  }
24
- const gr = ar(null);
25
- function oo({
23
+ const Ut = Ct(null);
24
+ function ti({
26
25
  children: e,
27
- services: t
26
+ services: r
28
27
  }) {
29
- const r = Be(() => t, [t]);
30
- return /* @__PURE__ */ n(gr.Provider, { value: r, children: e });
31
- }
32
- function Jr(e) {
33
- const t = cr(gr);
34
- return !t || !e ? null : t[e] ?? null;
35
- }
36
- const be = (e, t, r, o = void 0) => {
37
- ge(() => {
38
- e === !1 && r(t, o);
39
- }, [e, t, r, o]);
40
- }, we = (e, t) => e ? e.split(`
41
- `).map((r) => r.trim() === "is a required property" ? `${t || "This field"} is required` : r).join(`
42
- `) : "", qr = ({
28
+ const t = _e(() => r, [r]);
29
+ return /* @__PURE__ */ i(Ut.Provider, { value: t, children: e });
30
+ }
31
+ function vr(e) {
32
+ const r = Rt(Ut);
33
+ return !r || !e ? null : r[e] ?? null;
34
+ }
35
+ const Ee = (e, r, t, n = void 0) => {
36
+ de(() => {
37
+ e === !1 && t(r, n);
38
+ }, [e, r, t, n]);
39
+ }, ye = (e, r) => e ? e.split(`
40
+ `).map((t) => t.trim() === "is a required property" ? `${r || "This field"} is required` : t).join(`
41
+ `) : "", wr = ({
43
42
  data: e,
44
- handleChange: t,
45
- path: r,
46
- label: o,
47
- required: u,
48
- errors: i,
49
- uischema: l,
50
- schema: a,
51
- enabled: s,
52
- visible: c = !0
43
+ handleChange: r,
44
+ path: t,
45
+ label: n,
46
+ required: l,
47
+ errors: o,
48
+ uischema: s,
49
+ schema: c,
50
+ enabled: a,
51
+ visible: d = !0
53
52
  }) => {
54
- var y;
55
- if (be(c, r, t), c === !1)
53
+ var h;
54
+ if (Ee(d, t, r), d === !1)
56
55
  return null;
57
- const d = i.length === 0;
58
- return /* @__PURE__ */ n(x, { mb: "4", children: /* @__PURE__ */ g(S, { direction: "column", gap: "1", children: [
59
- /* @__PURE__ */ g(h, { as: "label", size: "2", weight: "bold", htmlFor: r, children: [
60
- o,
56
+ const u = o.length === 0;
57
+ return /* @__PURE__ */ i(S, { mb: "4", children: /* @__PURE__ */ y(D, { direction: "column", gap: "1", children: [
58
+ /* @__PURE__ */ y(f, { as: "label", size: "2", weight: "bold", htmlFor: t, children: [
59
+ n,
61
60
  " ",
62
- u && /* @__PURE__ */ n(h, { color: "red", children: "*" })
61
+ l && /* @__PURE__ */ i(f, { color: "red", children: "*" })
63
62
  ] }),
64
- /* @__PURE__ */ n(
65
- Se.Root,
63
+ /* @__PURE__ */ i(
64
+ Ae.Root,
66
65
  {
67
66
  value: e || "",
68
- onChange: (p) => t(r, p.target.value),
69
- disabled: !s,
70
- placeholder: (y = l.options) == null ? void 0 : y.placeholder,
71
- color: d ? void 0 : "red",
72
- id: r
67
+ onChange: (p) => r(t, p.target.value),
68
+ disabled: !a,
69
+ placeholder: (h = s.options) == null ? void 0 : h.placeholder,
70
+ color: u ? void 0 : "red",
71
+ id: t
73
72
  }
74
73
  ),
75
- !d && /* @__PURE__ */ n(h, { color: "red", size: "1", children: we(i, o) }),
76
- a.description && /* @__PURE__ */ n(h, { size: "1", color: "gray", children: a.description })
74
+ !u && /* @__PURE__ */ i(f, { color: "red", size: "1", children: ye(o, n) }),
75
+ c.description && /* @__PURE__ */ i(f, { size: "1", color: "gray", children: c.description })
77
76
  ] }) });
78
- }, Zr = q(1, Sr), Qr = me(qr), et = ({
77
+ }, Er = ee(1, Qt), Tr = ue(wr), Ar = ({
79
78
  data: e,
80
- handleChange: t,
81
- path: r,
82
- label: o,
83
- required: u,
84
- errors: i,
85
- uischema: l,
86
- schema: a,
87
- enabled: s,
88
- visible: c = !0
79
+ handleChange: r,
80
+ path: t,
81
+ label: n,
82
+ required: l,
83
+ errors: o,
84
+ uischema: s,
85
+ schema: c,
86
+ enabled: a,
87
+ visible: d = !0
89
88
  }) => {
90
89
  var p;
91
- if (be(c, r, t), c === !1)
90
+ if (Ee(d, t, r), d === !1)
92
91
  return null;
93
- const d = i.length === 0, y = (m) => {
94
- if (m === "") {
95
- t(r, void 0);
92
+ const u = o.length === 0, h = (g) => {
93
+ if (g === "") {
94
+ r(t, void 0);
96
95
  return;
97
96
  }
98
- const v = Number(m);
99
- isNaN(v) || t(r, v);
97
+ const b = Number(g);
98
+ isNaN(b) || r(t, b);
100
99
  };
101
- return /* @__PURE__ */ n(x, { mb: "4", children: /* @__PURE__ */ g(S, { direction: "column", gap: "1", children: [
102
- /* @__PURE__ */ g(h, { as: "label", size: "2", weight: "bold", htmlFor: r, children: [
103
- o,
100
+ return /* @__PURE__ */ i(S, { mb: "4", children: /* @__PURE__ */ y(D, { direction: "column", gap: "1", children: [
101
+ /* @__PURE__ */ y(f, { as: "label", size: "2", weight: "bold", htmlFor: t, children: [
102
+ n,
104
103
  " ",
105
- u && /* @__PURE__ */ n(h, { color: "red", children: "*" })
104
+ l && /* @__PURE__ */ i(f, { color: "red", children: "*" })
106
105
  ] }),
107
- /* @__PURE__ */ n(
108
- Se.Root,
106
+ /* @__PURE__ */ i(
107
+ Ae.Root,
109
108
  {
110
109
  type: "number",
111
110
  value: e ?? "",
112
- onChange: (m) => y(m.target.value),
113
- disabled: !s,
114
- placeholder: (p = l.options) == null ? void 0 : p.placeholder,
115
- color: d ? void 0 : "red",
116
- id: r
111
+ onChange: (g) => h(g.target.value),
112
+ disabled: !a,
113
+ placeholder: (p = s.options) == null ? void 0 : p.placeholder,
114
+ color: u ? void 0 : "red",
115
+ id: t
117
116
  }
118
117
  ),
119
- !d && /* @__PURE__ */ n(h, { color: "red", size: "1", children: we(i, o) }),
120
- a.description && /* @__PURE__ */ n(h, { size: "1", color: "gray", children: a.description })
118
+ !u && /* @__PURE__ */ i(f, { color: "red", size: "1", children: ye(o, n) }),
119
+ c.description && /* @__PURE__ */ i(f, { size: "1", color: "gray", children: c.description })
121
120
  ] }) });
122
- }, rt = q(2, We(Or, Nr)), tt = me(et), nt = ({
121
+ }, xr = ee(2, Je(er, tr)), Rr = ue(Ar), Cr = ({
123
122
  data: e,
124
- handleChange: t,
125
- path: r,
126
- label: o,
127
- required: u,
128
- errors: i,
129
- schema: l,
130
- enabled: a,
131
- visible: s = !0
123
+ handleChange: r,
124
+ path: t,
125
+ label: n,
126
+ required: l,
127
+ errors: o,
128
+ schema: s,
129
+ enabled: c,
130
+ visible: a = !0
132
131
  }) => {
133
- if (be(s, r, t), s === !1)
132
+ if (Ee(a, t, r), a === !1)
134
133
  return null;
135
- const c = i.length === 0;
136
- return /* @__PURE__ */ g(x, { mb: "4", children: [
137
- /* @__PURE__ */ g(S, { gap: "2", align: "center", children: [
138
- /* @__PURE__ */ n(
139
- $r,
134
+ const d = o.length === 0;
135
+ return /* @__PURE__ */ y(S, { mb: "4", children: [
136
+ /* @__PURE__ */ y(D, { gap: "2", align: "center", children: [
137
+ /* @__PURE__ */ i(
138
+ pr,
140
139
  {
141
140
  checked: !!e,
142
- onCheckedChange: (d) => t(r, d === !0),
143
- disabled: !a,
144
- id: r
141
+ onCheckedChange: (u) => r(t, u === !0),
142
+ disabled: !c,
143
+ id: t
145
144
  }
146
145
  ),
147
- /* @__PURE__ */ g(h, { as: "label", size: "2", htmlFor: r, children: [
148
- o,
146
+ /* @__PURE__ */ y(f, { as: "label", size: "2", htmlFor: t, children: [
147
+ n,
149
148
  " ",
150
- u && "*"
149
+ l && "*"
151
150
  ] })
152
151
  ] }),
153
- !c && /* @__PURE__ */ n(h, { color: "red", size: "1", className: "block mt-1", children: we(i, o) }),
154
- l.description && /* @__PURE__ */ n(h, { size: "1", color: "gray", className: "block mt-1", children: l.description })
152
+ !d && /* @__PURE__ */ i(f, { color: "red", size: "1", className: "block mt-1", children: ye(o, n) }),
153
+ s.description && /* @__PURE__ */ i(f, { size: "1", color: "gray", className: "block mt-1", children: s.description })
155
154
  ] });
156
- }, ot = q(2, xr), it = me(nt), lt = ({
155
+ }, Sr = ee(2, rr), Or = ue(Cr), Nr = ({
157
156
  data: e,
158
- handleChange: t,
159
- path: r,
160
- label: o,
161
- required: u,
162
- errors: i,
163
- schema: l,
164
- enabled: a,
165
- visible: s = !0
157
+ handleChange: r,
158
+ path: t,
159
+ label: n,
160
+ required: l,
161
+ errors: o,
162
+ schema: s,
163
+ enabled: c,
164
+ visible: a = !0
166
165
  }) => {
167
- if (be(s, r, t), s === !1)
166
+ if (Ee(a, t, r), a === !1)
168
167
  return null;
169
- const c = i.length === 0;
170
- let d = [];
171
- l.enum ? d = l.enum.map((p) => ({ value: p, label: String(p) })) : l.oneOf && (d = l.oneOf.map((p) => ({
168
+ const d = o.length === 0;
169
+ let u = [];
170
+ s.enum ? u = s.enum.map((p) => ({ value: p, label: String(p) })) : s.oneOf && (u = s.oneOf.map((p) => ({
172
171
  value: p.const,
173
172
  label: p.title || String(p.const)
174
173
  })));
175
- const y = e;
176
- return /* @__PURE__ */ n(x, { mb: "4", children: /* @__PURE__ */ g(S, { direction: "column", gap: "1", children: [
177
- /* @__PURE__ */ g(h, { as: "div", size: "2", weight: "bold", children: [
178
- o,
174
+ const h = e;
175
+ return /* @__PURE__ */ i(S, { mb: "4", children: /* @__PURE__ */ y(D, { direction: "column", gap: "1", children: [
176
+ /* @__PURE__ */ y(f, { as: "div", size: "2", weight: "bold", children: [
177
+ n,
179
178
  " ",
180
- u && /* @__PURE__ */ n(h, { color: "red", children: "*" })
179
+ l && /* @__PURE__ */ i(f, { color: "red", children: "*" })
181
180
  ] }),
182
- /* @__PURE__ */ n(
183
- Qe.Root,
181
+ /* @__PURE__ */ i(
182
+ dt.Root,
184
183
  {
185
- value: y !== void 0 ? String(y) : "",
184
+ value: h !== void 0 ? String(h) : "",
186
185
  onValueChange: (p) => {
187
- const m = d.find((v) => String(v.value) === p);
188
- m && t(r, m.value);
186
+ const g = u.find((b) => String(b.value) === p);
187
+ g && r(t, g.value);
189
188
  },
190
- disabled: !a,
191
- children: /* @__PURE__ */ n(
192
- S,
189
+ disabled: !c,
190
+ children: /* @__PURE__ */ i(
191
+ D,
193
192
  {
194
193
  direction: "row",
195
194
  style: {
@@ -197,210 +196,387 @@ const be = (e, t, r, o = void 0) => {
197
196
  columnGap: "clamp(14px, 3vw, 36px)",
198
197
  rowGap: "clamp(8px, 1.6vw, 14px)"
199
198
  },
200
- children: d.map((p) => /* @__PURE__ */ g(S, { align: "center", gap: "2", style: { minWidth: "max-content" }, children: [
201
- /* @__PURE__ */ n(Qe.Item, { value: String(p.value) }),
202
- /* @__PURE__ */ n(h, { size: "2", color: a ? void 0 : "gray", children: p.label })
199
+ children: u.map((p) => /* @__PURE__ */ y(D, { align: "center", gap: "2", style: { minWidth: "max-content" }, children: [
200
+ /* @__PURE__ */ i(dt.Item, { value: String(p.value) }),
201
+ /* @__PURE__ */ i(f, { size: "2", color: c ? void 0 : "gray", children: p.label })
203
202
  ] }, String(p.value)))
204
203
  }
205
204
  )
206
205
  }
207
206
  ),
208
- !c && /* @__PURE__ */ n(h, { color: "red", size: "1", children: we(i, o) }),
209
- l.description && /* @__PURE__ */ n(h, { size: "1", color: "gray", children: l.description })
207
+ !d && /* @__PURE__ */ i(f, { color: "red", size: "1", children: ye(o, n) }),
208
+ s.description && /* @__PURE__ */ i(f, { size: "1", color: "gray", children: s.description })
210
209
  ] }) });
211
- }, st = (e, t, r) => {
212
- var u;
213
- return We(ur, dr)(e, t, r) && ((u = e == null ? void 0 : e.options) == null ? void 0 : u.format) === "radio" ? 3 : -1;
214
- }, ct = me(lt), at = ({
210
+ }, kr = (e, r, t) => {
211
+ var l;
212
+ return Je(St, Ot)(e, r, t) && ((l = e == null ? void 0 : e.options) == null ? void 0 : l.format) === "radio" ? 3 : -1;
213
+ }, Ir = ue(Nr), Dr = ({
215
214
  data: e,
216
- handleChange: t,
217
- path: r,
218
- label: o,
219
- required: u,
220
- errors: i,
221
- schema: l,
222
- uischema: a,
223
- enabled: s,
224
- visible: c = !0
215
+ handleChange: r,
216
+ path: t,
217
+ label: n,
218
+ required: l,
219
+ errors: o,
220
+ schema: s,
221
+ uischema: c,
222
+ enabled: a,
223
+ visible: d = !0
225
224
  }) => {
226
- var m;
227
- if (be(c, r, t), c === !1)
225
+ var N, U, z;
226
+ Ee(d, t, r);
227
+ const u = ((N = c.options) == null ? void 0 : N.autocomplete) === !0, [h, p] = j(!1), [g, b] = j(""), [I, O] = j(0), T = ae(null);
228
+ if (de(() => {
229
+ if (!u || !h) return;
230
+ const v = (E) => {
231
+ T.current && !T.current.contains(E.target) && p(!1);
232
+ };
233
+ return document.addEventListener("mousedown", v), () => document.removeEventListener("mousedown", v);
234
+ }, [u, h]), d === !1)
228
235
  return null;
229
- const d = i.length === 0;
230
- let y = [];
231
- l.enum ? y = l.enum.map((v) => ({ value: String(v), label: String(v) })) : l.oneOf && (y = l.oneOf.map((v) => ({
236
+ const A = o.length === 0;
237
+ let k = [];
238
+ s.enum ? k = s.enum.map((v) => ({ value: String(v), label: String(v) })) : s.oneOf && (k = s.oneOf.map((v) => ({
232
239
  value: String(v.const),
233
240
  label: v.title || String(v.const)
234
241
  })));
235
- const p = e !== void 0 ? String(e) : "";
236
- return /* @__PURE__ */ n(x, { mb: "4", children: /* @__PURE__ */ g(S, { direction: "column", gap: "1", children: [
237
- /* @__PURE__ */ g(h, { as: "label", size: "2", weight: "bold", htmlFor: r, children: [
238
- o,
242
+ const M = e !== void 0 ? String(e) : "", L = ((U = c.options) == null ? void 0 : U.placeholder) || "Select an option";
243
+ if (u) {
244
+ const v = ((z = k.find((R) => R.value === M)) == null ? void 0 : z.label) ?? "", E = h ? k.filter((R) => R.label.toLowerCase().includes(g.toLowerCase())) : k, B = Math.min(I, E.length - 1), K = (R) => {
245
+ r(t, R.value), p(!1);
246
+ }, J = (R) => {
247
+ R.stopPropagation(), r(t, void 0), b("");
248
+ }, F = (R) => {
249
+ (R.key === "Enter" || R.key === " ") && J(R);
250
+ };
251
+ return /* @__PURE__ */ i(S, { mb: "4", children: /* @__PURE__ */ y(D, { direction: "column", gap: "1", children: [
252
+ /* @__PURE__ */ y(f, { as: "label", size: "2", weight: "bold", htmlFor: t, children: [
253
+ n,
254
+ " ",
255
+ l && /* @__PURE__ */ i(f, { color: "red", children: "*" })
256
+ ] }),
257
+ /* @__PURE__ */ y("div", { ref: T, style: { position: "relative" }, children: [
258
+ /* @__PURE__ */ i(
259
+ Ae.Root,
260
+ {
261
+ id: t,
262
+ value: h ? g : v,
263
+ placeholder: L,
264
+ disabled: !a,
265
+ style: A ? void 0 : { outline: "2px solid var(--red-7)", outlineOffset: "-1px" },
266
+ onChange: (R) => {
267
+ b(R.target.value), O(0), h || p(!0);
268
+ },
269
+ onFocus: () => {
270
+ a && !h && (b(""), O(0), p(!0));
271
+ },
272
+ onKeyDown: (R) => {
273
+ R.key === "Escape" ? p(!1) : R.key === "ArrowDown" ? (R.preventDefault(), h ? O((Y) => Math.min(Y + 1, E.length - 1)) : (b(""), p(!0))) : R.key === "ArrowUp" ? (R.preventDefault(), h && O((Y) => Math.max(Y - 1, 0))) : R.key === "Enter" && h && E[B] && (R.preventDefault(), K(E[B]));
274
+ },
275
+ children: /* @__PURE__ */ i(Ae.Slot, { side: "right", children: /* @__PURE__ */ y(D, { align: "center", gap: "1", children: [
276
+ M && a && /* @__PURE__ */ i(
277
+ "span",
278
+ {
279
+ role: "button",
280
+ tabIndex: 0,
281
+ onMouseDown: (R) => R.preventDefault(),
282
+ onClick: J,
283
+ onKeyDown: F,
284
+ style: { lineHeight: 1, color: "var(--gray-9)", padding: "0 2px", cursor: "pointer" },
285
+ "aria-label": "Clear selection",
286
+ children: "×"
287
+ }
288
+ ),
289
+ /* @__PURE__ */ i(
290
+ Lt,
291
+ {
292
+ style: { transform: h ? "rotate(180deg)" : void 0, transition: "transform 150ms" }
293
+ }
294
+ )
295
+ ] }) })
296
+ }
297
+ ),
298
+ h && /* @__PURE__ */ i(
299
+ S,
300
+ {
301
+ style: {
302
+ position: "absolute",
303
+ top: "calc(100% + 4px)",
304
+ left: 0,
305
+ right: 0,
306
+ zIndex: 50,
307
+ background: "var(--color-panel-solid)",
308
+ borderRadius: "var(--radius-3)",
309
+ boxShadow: "var(--shadow-5)",
310
+ border: "1px solid var(--gray-a6)",
311
+ overflow: "hidden"
312
+ },
313
+ children: /* @__PURE__ */ i(kt, { style: { maxHeight: 240 }, children: /* @__PURE__ */ y(S, { p: "1", children: [
314
+ E.length === 0 && /* @__PURE__ */ i(S, { px: "3", py: "2", children: /* @__PURE__ */ i(f, { size: "2", color: "gray", children: "No results found." }) }),
315
+ E.map((R, Y) => /* @__PURE__ */ i(
316
+ S,
317
+ {
318
+ px: "3",
319
+ py: "2",
320
+ onMouseDown: (Q) => Q.preventDefault(),
321
+ onClick: () => K(R),
322
+ onMouseEnter: () => O(Y),
323
+ style: {
324
+ cursor: "pointer",
325
+ borderRadius: "var(--radius-2)",
326
+ backgroundColor: Y === B ? "var(--accent-4)" : R.value === M ? "var(--accent-3)" : void 0
327
+ },
328
+ children: /* @__PURE__ */ i(f, { size: "2", children: R.label })
329
+ },
330
+ R.value
331
+ ))
332
+ ] }) })
333
+ }
334
+ )
335
+ ] }),
336
+ !A && /* @__PURE__ */ i(f, { color: "red", size: "1", children: ye(o, n) }),
337
+ s.description && /* @__PURE__ */ i(f, { size: "1", color: "gray", children: s.description })
338
+ ] }) });
339
+ }
340
+ return /* @__PURE__ */ i(S, { mb: "4", children: /* @__PURE__ */ y(D, { direction: "column", gap: "1", children: [
341
+ /* @__PURE__ */ y(f, { as: "label", size: "2", weight: "bold", htmlFor: t, children: [
342
+ n,
239
343
  " ",
240
- u && /* @__PURE__ */ n(h, { color: "red", children: "*" })
344
+ l && /* @__PURE__ */ i(f, { color: "red", children: "*" })
241
345
  ] }),
242
- /* @__PURE__ */ g(Pe.Root, { value: p, onValueChange: (v) => t(r, v), disabled: !s, children: [
243
- /* @__PURE__ */ n(
244
- Pe.Trigger,
245
- {
246
- placeholder: ((m = a.options) == null ? void 0 : m.placeholder) || "Select an option",
247
- color: d ? void 0 : "red",
248
- id: r
249
- }
250
- ),
251
- /* @__PURE__ */ n(Pe.Content, { children: y.map((v) => /* @__PURE__ */ n(Pe.Item, { value: v.value, children: v.label }, v.value)) })
346
+ /* @__PURE__ */ y(Ke.Root, { value: M, onValueChange: (v) => r(t, v), disabled: !a, children: [
347
+ /* @__PURE__ */ i(Ke.Trigger, { placeholder: L, color: A ? void 0 : "red", id: t }),
348
+ /* @__PURE__ */ i(Ke.Content, { children: k.map((v) => /* @__PURE__ */ i(Ke.Item, { value: v.value, children: v.label }, v.value)) })
252
349
  ] }),
253
- !d && /* @__PURE__ */ n(h, { color: "red", size: "1", children: we(i, o) }),
254
- l.description && /* @__PURE__ */ n(h, { size: "1", color: "gray", children: l.description })
350
+ !A && /* @__PURE__ */ i(f, { color: "red", size: "1", children: ye(o, n) }),
351
+ s.description && /* @__PURE__ */ i(f, { size: "1", color: "gray", children: s.description })
255
352
  ] }) });
256
- }, ut = q(2, We(ur, dr)), dt = me(at), ft = {
353
+ }, Lr = ee(2, Je(St, Ot)), Mr = ue(Dr), Pt = /\{([A-Za-z0-9_]+)(?:\(([^(){}]*)\))?\}/g, zr = {
354
+ today: (e) => zt().format(e || "YYYY-MM-DD")
355
+ }, Fr = (e) => typeof e == "string" || typeof e == "number" || typeof e == "boolean" || typeof e == "bigint", ft = (e, r) => Object.prototype.hasOwnProperty.call(e, r);
356
+ function ot(e, r, t = {}) {
357
+ const n = { ...zr, ...t };
358
+ return e.replace(Pt, (l, o, s) => {
359
+ let c;
360
+ if (s === void 0) {
361
+ if (!ft(r, o)) return l;
362
+ c = r[o];
363
+ } else {
364
+ if (!ft(n, o)) return l;
365
+ try {
366
+ c = n[o](s);
367
+ } catch {
368
+ return l;
369
+ }
370
+ }
371
+ return c == null ? "" : Fr(c) ? String(c) : l;
372
+ });
373
+ }
374
+ function it(e) {
375
+ const r = [];
376
+ let t = 0;
377
+ for (const n of e.matchAll(Pt))
378
+ n.index > t && r.push(e.slice(t, n.index)), r.push(n[2] === void 0 ? { name: n[1] } : { name: n[1], arg: n[2] }), t = n.index + n[0].length;
379
+ return t < e.length && r.push(e.slice(t)), r;
380
+ }
381
+ function Ur(e) {
382
+ if (typeof e == "string" && e.length > 0) return e;
383
+ if (e && typeof e == "object" && typeof e.value == "string") {
384
+ const r = e.value;
385
+ return r.length > 0 ? r : void 0;
386
+ }
387
+ }
388
+ function Pr(e) {
389
+ if (typeof e == "string") return e.length > 0 ? { parent: e } : void 0;
390
+ if (!e || typeof e != "object") return;
391
+ const r = Object.entries(e);
392
+ if (r.length === 0) return;
393
+ const t = {}, n = [];
394
+ for (const [l, o] of r)
395
+ typeof o == "string" && o.length > 0 ? t[l] = o : n.push(l);
396
+ return n.length > 0 && console.warn(`x-search.dependsOn: ignoring invalid entries [${n.join(", ")}]`), Object.keys(t).length === 0 ? (console.warn("x-search.dependsOn: map has no valid entries; search will not fetch until fixed"), {}) : t;
397
+ }
398
+ function $r(e, r, t) {
399
+ const n = {};
400
+ for (const [l, o] of Object.entries(e))
401
+ n[l] = Ur(Ve.data(r, t ? `${t}.${o}` : o));
402
+ return n;
403
+ }
404
+ function pt(e, r) {
405
+ return r ? { ...e, name: ot(r, e) } : e;
406
+ }
407
+ const _r = {
257
408
  "small-list": { fetchOnOpen: !0, searchable: !1, paginated: !1 },
258
409
  "large-searchable-list": { fetchOnOpen: !0, searchable: !0, paginated: !1 },
259
410
  "large-paginated-list": { fetchOnOpen: !1, searchable: !0, paginated: !0 }
260
- }, ht = ({
411
+ }, Vr = ({
261
412
  data: e,
262
- handleChange: t,
263
- path: r,
264
- label: o,
265
- required: u,
266
- errors: i,
267
- enabled: l,
268
- visible: a = !0,
269
- schema: s,
270
- uischema: c
413
+ handleChange: r,
414
+ path: t,
415
+ label: n,
416
+ required: l,
417
+ errors: o,
418
+ enabled: s,
419
+ visible: c = !0,
420
+ schema: a,
421
+ uischema: d
271
422
  }) => {
272
- var Ee;
273
- const d = (s == null ? void 0 : s["x-search"]) ?? { service: "" }, y = d.service ?? "", p = d.mode ?? "large-paginated-list", m = ft[p], v = (m == null ? void 0 : m.fetchOnOpen) ?? !1, I = d.params, A = Jr(y), b = s.type === "object", k = b ? typeof e == "string" ? { value: e } : e ?? void 0 : void 0, F = b ? k == null ? void 0 : k.value : e, z = k == null ? void 0 : k.label, w = y ? A ? m ? null : `Invalid x-search.mode "${p}". Expected "small-list", "large-searchable-list", or "large-paginated-list".` : `Search service "${y}" is not registered.` : "Search not configured.", _ = l !== !1, V = !i || i.length === 0, [O, C] = $(!1), [H, B] = $(""), [W, j] = $([]), [ee, re] = $(!1), [le, oe] = $(!1), [se, de] = $(!1), [G, f] = $(null), [T, K] = $(void 0), N = pe(void 0), U = pe(null), Z = pe(null), ie = pe(null), J = pe(void 0);
274
- ge(() => {
275
- var ce, Q;
276
- if (!F) {
277
- K(void 0), J.current = void 0;
423
+ var Xe, pe;
424
+ const u = (a == null ? void 0 : a["x-search"]) ?? {
425
+ service: "",
426
+ displayTemplate: ""
427
+ }, h = u.service ?? "", p = u.mode ?? "large-paginated-list", g = _r[p], b = (g == null ? void 0 : g.fetchOnOpen) ?? !1, I = typeof u.displayTemplate == "string" ? u.displayTemplate : "", O = We(), T = t.split(".").slice(0, -1).join("."), { parentValues: A, parentValuesKey: k, missingParent: M } = _e(() => {
428
+ var he;
429
+ const w = Pr(u.dependsOn);
430
+ if (!w) return { parentValues: void 0, parentValuesKey: "", missingParent: !1 };
431
+ const Z = $r(w, (he = O.core) == null ? void 0 : he.data, T), ne = Object.keys(Z).length === 0 || Object.values(Z).some((Me) => !Me);
432
+ return { parentValues: Z, parentValuesKey: JSON.stringify(Z), missingParent: ne };
433
+ }, [u.dependsOn, (Xe = O.core) == null ? void 0 : Xe.data, T]), L = _e(() => A ? { ...u.params, ...A } : u.params, [A, k, u.params]), N = vr(h), U = a.type === "object", z = U ? typeof e == "string" ? { value: e } : e ?? void 0 : void 0, v = U ? z == null ? void 0 : z.value : e, E = z == null ? void 0 : z.label, B = h ? N ? g ? I ? null : "x-search.displayTemplate is required." : `Invalid x-search.mode "${p}". Expected "small-list", "large-searchable-list", or "large-paginated-list".` : `Search service "${h}" is not registered.` : "Search not configured.", K = s !== !1, J = !o || o.length === 0, [F, R] = j(!1), [Y, Q] = j(""), [be, oe] = j([]), [Se, m] = j(!1), [C, G] = j(!1), [P, _] = j(!1), [re, q] = j(null), [ie, $] = j(void 0), fe = ae(void 0), Oe = ae(null), Pe = ae(null), $e = ae(null), xe = ae(void 0), x = ae(void 0);
434
+ de(() => {
435
+ if (!A) return;
436
+ const w = x.current;
437
+ if (x.current = A, !w || !v) return;
438
+ Object.keys(A).some((ne) => w[ne] !== void 0 && w[ne] !== A[ne]) && r(t, U ? void 0 : null);
439
+ }, [k, v, r, t, U]), de(() => {
440
+ var Z, ne;
441
+ if (B) {
442
+ $(void 0), xe.current = void 0;
443
+ return;
444
+ }
445
+ if (!v) {
446
+ $(void 0), xe.current = void 0;
278
447
  return;
279
448
  }
280
- if (((ce = J.current) == null ? void 0 : ce.value) === F && ((Q = J.current) == null ? void 0 : Q.label) === z) return;
281
- if (J.current = { value: F, label: z }, b && z) {
282
- K({ id: F, name: z });
449
+ if (((Z = xe.current) == null ? void 0 : Z.value) === v && ((ne = xe.current) == null ? void 0 : ne.label) === E) return;
450
+ if (xe.current = { value: v, label: E }, U && E) {
451
+ $({ id: v, name: E });
283
452
  return;
284
453
  }
285
- if (K({ id: F, name: z ?? F }), !(A != null && A.resolve)) return;
286
- let R = !1;
287
- return A.resolve(F, I).then((ae) => {
288
- !R && ae && K(ae);
454
+ if ($({ id: v, name: E ?? v }), !(N != null && N.resolve)) return;
455
+ let w = !1;
456
+ return N.resolve(v, L).then((he) => {
457
+ !w && he && $(pt(he, I));
289
458
  }).catch(() => {
290
459
  }), () => {
291
- R = !0;
460
+ w = !0;
292
461
  };
293
- }, [F, z, b, A, I]);
294
- const D = ke(
295
- async (R, ce = !1) => {
296
- var ae;
297
- if (!A) {
298
- f("Search service not configured.");
462
+ }, [B, v, E, U, N, L, I]);
463
+ const V = Fe(
464
+ async (w, Z = !1) => {
465
+ var he;
466
+ if (B) return;
467
+ if (!N) {
468
+ q("Search service not configured.");
299
469
  return;
300
470
  }
301
- (ae = Z.current) == null || ae.abort();
302
- const Q = new AbortController();
303
- Z.current = Q, ce ? de(!0) : (oe(!0), de(!1), f(null));
471
+ (he = Pe.current) == null || he.abort();
472
+ const ne = new AbortController();
473
+ Pe.current = ne, Z ? _(!0) : (G(!0), _(!1), q(null));
304
474
  try {
305
- const Ae = await A.search({
306
- query: R,
307
- cursor: ce ? N.current : void 0,
308
- signal: Q.signal,
309
- params: I
310
- }), Ie = Ae.options ?? [];
311
- j(ce ? (Ue) => [...Ue, ...Ie] : Ie), N.current = Ae.nextCursor, re(((m == null ? void 0 : m.paginated) ?? !1) && Ae.nextCursor != null);
475
+ const Me = await N.search({
476
+ query: w,
477
+ cursor: Z ? fe.current : void 0,
478
+ signal: ne.signal,
479
+ params: L
480
+ });
481
+ if (ne.signal.aborted) return;
482
+ const at = (Me.options ?? []).map((Ze) => pt(Ze, I));
483
+ oe(Z ? (Ze) => [...Ze, ...at] : at), fe.current = Me.nextCursor, m(((g == null ? void 0 : g.paginated) ?? !1) && Me.nextCursor != null);
312
484
  } catch {
313
- if (Q.signal.aborted) return;
314
- f("Failed to load results. Please try again.");
485
+ if (ne.signal.aborted) return;
486
+ q("Failed to load results. Please try again.");
315
487
  } finally {
316
- Q.signal.aborted || (ce ? de(!1) : oe(!1));
488
+ ne.signal.aborted || (Z ? _(!1) : G(!1));
317
489
  }
318
490
  },
319
- [A, m == null ? void 0 : m.paginated, I]
491
+ [B, N, g == null ? void 0 : g.paginated, L, I]
320
492
  );
321
- if (ge(() => {
322
- if (!O) return;
323
- const R = (ce) => {
324
- ie.current && !ie.current.contains(ce.target) && C(!1);
493
+ if (de(() => {
494
+ if (!F) return;
495
+ const w = (Z) => {
496
+ $e.current && !$e.current.contains(Z.target) && R(!1);
325
497
  };
326
- return document.addEventListener("mousedown", R), () => document.removeEventListener("mousedown", R);
327
- }, [O]), ge(() => {
328
- var R;
329
- O || ((R = Z.current) == null || R.abort(), B(""), j([]), re(!1), f(null), oe(!1), de(!1), N.current = void 0);
330
- }, [O]), ge(() => {
331
- if (!O) return;
332
- if (!H && !v) {
333
- j([]), re(!1), f(null), N.current = void 0;
498
+ return document.addEventListener("mousedown", w), () => document.removeEventListener("mousedown", w);
499
+ }, [F]), de(() => {
500
+ var w;
501
+ F || ((w = Pe.current) == null || w.abort(), Q(""), oe([]), m(!1), q(null), G(!1), _(!1), fe.current = void 0);
502
+ }, [F]), de(() => {
503
+ if (!F) return;
504
+ if (M) {
505
+ oe([]), m(!1), q(null), fe.current = void 0;
334
506
  return;
335
507
  }
336
- U.current && clearTimeout(U.current);
337
- const R = H ? 300 : 0;
338
- return U.current = setTimeout(() => {
339
- j([]), re(!1), N.current = void 0, D(H);
340
- }, R), () => {
341
- U.current && clearTimeout(U.current);
508
+ if (!Y && !b) {
509
+ oe([]), m(!1), q(null), fe.current = void 0;
510
+ return;
511
+ }
512
+ Oe.current && clearTimeout(Oe.current);
513
+ const w = Y ? 300 : 0;
514
+ return Oe.current = setTimeout(() => {
515
+ oe([]), m(!1), fe.current = void 0, V(Y);
516
+ }, w), () => {
517
+ Oe.current && clearTimeout(Oe.current);
342
518
  };
343
- }, [H, O, v, D]), be(a, r, t, b ? void 0 : null), a === !1)
519
+ }, [Y, F, b, V, M, k]), Ee(c, t, r), c === !1)
344
520
  return null;
345
- const E = () => {
346
- B(""), j([]), re(!1), f(null), N.current = void 0, C(!0);
347
- }, L = (R) => {
348
- t(r, b ? { value: R.id, label: R.name } : R.id), K(R), J.current = { value: R.id, label: b ? R.name : void 0 }, C(!1);
349
- }, ue = (R) => {
350
- R.stopPropagation(), t(r, b ? void 0 : null), K(void 0);
351
- }, X = (R) => {
352
- (R.key === "Enter" || R.key === " ") && ue(R);
353
- }, P = ((Ee = c == null ? void 0 : c.options) == null ? void 0 : Ee.placeholder) ?? "Select an option";
354
- return /* @__PURE__ */ n(x, { mb: "4", children: /* @__PURE__ */ g(S, { direction: "column", gap: "1", children: [
355
- /* @__PURE__ */ g(h, { as: "label", size: "2", weight: "bold", htmlFor: r, children: [
356
- o,
521
+ const se = () => {
522
+ Q(""), oe([]), m(!1), q(null), fe.current = void 0, R(!0);
523
+ }, X = (w) => {
524
+ r(t, U ? { value: w.id, label: w.name } : w.id), $(w), xe.current = { value: w.id, label: U ? w.name : void 0 }, R(!1);
525
+ }, H = (w) => {
526
+ w.stopPropagation(), r(t, void 0), $(void 0);
527
+ }, Re = (w) => {
528
+ (w.key === "Enter" || w.key === " ") && H(w);
529
+ }, Le = ((pe = d == null ? void 0 : d.options) == null ? void 0 : pe.placeholder) ?? "Select an option";
530
+ return /* @__PURE__ */ i(S, { mb: "4", children: /* @__PURE__ */ y(D, { direction: "column", gap: "1", children: [
531
+ /* @__PURE__ */ y(f, { as: "label", size: "2", weight: "bold", htmlFor: t, children: [
532
+ n,
357
533
  " ",
358
- u && /* @__PURE__ */ n(h, { color: "red", children: "*" })
534
+ l && /* @__PURE__ */ i(f, { color: "red", children: "*" })
359
535
  ] }),
360
- /* @__PURE__ */ g("div", { ref: ie, style: { position: "relative" }, children: [
361
- /* @__PURE__ */ n(
362
- Se.Root,
536
+ /* @__PURE__ */ y("div", { ref: $e, style: { position: "relative" }, children: [
537
+ /* @__PURE__ */ i(
538
+ Ae.Root,
363
539
  {
364
- id: r,
365
- value: O ? H : (T == null ? void 0 : T.name) ?? "",
366
- placeholder: O && (m != null && m.searchable) ? "Search..." : P,
367
- disabled: !_,
368
- readOnly: O && !(m != null && m.searchable),
369
- style: V ? void 0 : { outline: "2px solid var(--red-7)", outlineOffset: "-1px" },
370
- onChange: (R) => {
371
- m != null && m.searchable && (B(R.target.value), O || E());
540
+ id: t,
541
+ value: F ? Y : (ie == null ? void 0 : ie.name) ?? "",
542
+ placeholder: F && (g != null && g.searchable) ? "Search..." : Le,
543
+ disabled: !K,
544
+ readOnly: F && !(g != null && g.searchable),
545
+ style: J ? void 0 : { outline: "2px solid var(--red-7)", outlineOffset: "-1px" },
546
+ onChange: (w) => {
547
+ g != null && g.searchable && (Q(w.target.value), F || se());
372
548
  },
373
549
  onFocus: () => {
374
- _ && !O && E();
550
+ K && !F && se();
375
551
  },
376
- onKeyDown: (R) => {
377
- R.key === "Escape" && C(!1);
552
+ onKeyDown: (w) => {
553
+ w.key === "Escape" && R(!1);
378
554
  },
379
- children: /* @__PURE__ */ n(Se.Slot, { side: "right", children: /* @__PURE__ */ g(S, { align: "center", gap: "1", children: [
380
- F && _ && /* @__PURE__ */ n(
555
+ children: /* @__PURE__ */ i(Ae.Slot, { side: "right", children: /* @__PURE__ */ y(D, { align: "center", gap: "1", children: [
556
+ v && K && /* @__PURE__ */ i(
381
557
  "span",
382
558
  {
383
559
  role: "button",
384
560
  tabIndex: 0,
385
- onMouseDown: (R) => R.preventDefault(),
386
- onClick: ue,
387
- onKeyDown: X,
561
+ onMouseDown: (w) => w.preventDefault(),
562
+ onClick: H,
563
+ onKeyDown: Re,
388
564
  style: { lineHeight: 1, color: "var(--gray-9)", padding: "0 2px", cursor: "pointer" },
389
565
  "aria-label": "Clear selection",
390
566
  children: "×"
391
567
  }
392
568
  ),
393
- /* @__PURE__ */ n(
394
- Vr,
569
+ /* @__PURE__ */ i(
570
+ Lt,
395
571
  {
396
- style: { transform: O ? "rotate(180deg)" : void 0, transition: "transform 150ms" }
572
+ style: { transform: F ? "rotate(180deg)" : void 0, transition: "transform 150ms" }
397
573
  }
398
574
  )
399
575
  ] }) })
400
576
  }
401
577
  ),
402
- O && /* @__PURE__ */ n(
403
- x,
578
+ F && /* @__PURE__ */ i(
579
+ S,
404
580
  {
405
581
  style: {
406
582
  position: "absolute",
@@ -414,341 +590,340 @@ const be = (e, t, r, o = void 0) => {
414
590
  border: "1px solid var(--gray-a6)",
415
591
  overflow: "hidden"
416
592
  },
417
- children: w ? /* @__PURE__ */ n(x, { p: "3", children: /* @__PURE__ */ n(h, { size: "2", color: "gray", children: w }) }) : /* @__PURE__ */ n(_r, { style: { maxHeight: 240 }, children: /* @__PURE__ */ g(x, { p: "1", children: [
418
- le && /* @__PURE__ */ n(S, { justify: "center", p: "4", children: /* @__PURE__ */ n(xe, {}) }),
419
- !le && G && /* @__PURE__ */ n(x, { px: "3", py: "2", children: /* @__PURE__ */ n(h, { size: "2", color: "red", children: G }) }),
420
- !le && !G && W.length === 0 && /* @__PURE__ */ n(x, { px: "3", py: "2", children: /* @__PURE__ */ n(h, { size: "2", color: "gray", children: H || v ? "No results found." : "Type to search…" }) }),
421
- W.map((R) => /* @__PURE__ */ n(
422
- x,
593
+ children: B ? /* @__PURE__ */ i(S, { p: "3", children: /* @__PURE__ */ i(f, { size: "2", color: "gray", children: B }) }) : /* @__PURE__ */ i(kt, { style: { maxHeight: 240 }, children: /* @__PURE__ */ y(S, { p: "1", children: [
594
+ C && /* @__PURE__ */ i(D, { justify: "center", p: "4", children: /* @__PURE__ */ i(Ue, {}) }),
595
+ !C && re && /* @__PURE__ */ i(S, { px: "3", py: "2", children: /* @__PURE__ */ i(f, { size: "2", color: "red", children: re }) }),
596
+ !C && !re && be.length === 0 && /* @__PURE__ */ i(S, { px: "3", py: "2", children: /* @__PURE__ */ i(f, { size: "2", color: "gray", children: M ? "Select the related field first." : Y || b ? "No results found." : "Type to search…" }) }),
597
+ be.map((w) => /* @__PURE__ */ i(
598
+ S,
423
599
  {
424
600
  px: "3",
425
601
  py: "2",
426
- onMouseDown: (ce) => ce.preventDefault(),
427
- onClick: () => L(R),
602
+ onMouseDown: (Z) => Z.preventDefault(),
603
+ onClick: () => X(w),
428
604
  style: {
429
605
  cursor: "pointer",
430
606
  borderRadius: "var(--radius-2)",
431
- backgroundColor: R.id === F ? "var(--accent-3)" : void 0
607
+ backgroundColor: w.id === v ? "var(--accent-3)" : void 0
432
608
  },
433
609
  className: "hover:bg-(--gray-3)",
434
- children: /* @__PURE__ */ n(h, { size: "2", children: R.name })
610
+ children: /* @__PURE__ */ i(f, { size: "2", children: w.name })
435
611
  },
436
- R.id
612
+ w.id
437
613
  )),
438
- (m == null ? void 0 : m.paginated) && ee && !se && /* @__PURE__ */ n(x, { px: "3", py: "2", children: /* @__PURE__ */ n(
614
+ (g == null ? void 0 : g.paginated) && Se && !P && /* @__PURE__ */ i(S, { px: "3", py: "2", children: /* @__PURE__ */ i(
439
615
  De,
440
616
  {
441
617
  variant: "ghost",
442
618
  size: "1",
443
619
  style: { width: "100%" },
444
- onMouseDown: (R) => R.preventDefault(),
445
- onClick: () => void D(H, !0),
620
+ onMouseDown: (w) => w.preventDefault(),
621
+ onClick: () => void V(Y, !0),
446
622
  children: "Load more"
447
623
  }
448
624
  ) }),
449
- se && /* @__PURE__ */ n(S, { justify: "center", p: "2", children: /* @__PURE__ */ n(xe, {}) })
625
+ P && /* @__PURE__ */ i(D, { justify: "center", p: "2", children: /* @__PURE__ */ i(Ue, {}) })
450
626
  ] }) })
451
627
  }
452
628
  )
453
629
  ] }),
454
- !V && /* @__PURE__ */ n(h, { color: "red", size: "1", children: we(i, o) }),
455
- s.description && /* @__PURE__ */ n(h, { size: "1", color: "gray", children: s.description })
630
+ !J && /* @__PURE__ */ i(f, { color: "red", size: "1", children: ye(o, n) }),
631
+ a.description && /* @__PURE__ */ i(f, { size: "1", color: "gray", children: a.description })
456
632
  ] }) });
457
- }, pt = me(ht), mt = q(
633
+ }, jr = ue(Vr), Hr = ee(
458
634
  3,
459
- ze((e) => {
460
- const t = e["x-search"];
461
- return (e.type === "string" || e.type === "object") && typeof (t == null ? void 0 : t.service) == "string" && t.service !== "";
635
+ Ie((e) => {
636
+ const r = e["x-search"];
637
+ return (e.type === "string" || e.type === "object") && typeof (r == null ? void 0 : r.service) == "string" && r.service !== "";
462
638
  })
463
- ), gt = (e, t) => jr(`${e}T${t}`).format(), yt = ({ path: e, label: t, required: r, errors: o, description: u, children: i }) => {
464
- const l = o.length === 0;
465
- return /* @__PURE__ */ n(x, { mb: "4", children: /* @__PURE__ */ g(S, { direction: "column", gap: "1", children: [
466
- /* @__PURE__ */ g(h, { as: "label", size: "2", weight: "bold", htmlFor: e, children: [
467
- t,
639
+ ), Wr = (e, r) => zt(`${e}T${r}`).format(), Br = ({ path: e, label: r, required: t, errors: n, description: l, children: o }) => {
640
+ const s = n.length === 0;
641
+ return /* @__PURE__ */ i(S, { mb: "4", children: /* @__PURE__ */ y(D, { direction: "column", gap: "1", children: [
642
+ /* @__PURE__ */ y(f, { as: "label", size: "2", weight: "bold", htmlFor: e, children: [
643
+ r,
468
644
  " ",
469
- r && /* @__PURE__ */ n(h, { color: "red", children: "*" })
645
+ t && /* @__PURE__ */ i(f, { color: "red", children: "*" })
470
646
  ] }),
471
- i,
472
- !l && /* @__PURE__ */ n(h, { color: "red", size: "1", children: we(o, t) }),
473
- u && /* @__PURE__ */ n(h, { size: "1", color: "gray", children: u })
647
+ o,
648
+ !s && /* @__PURE__ */ i(f, { color: "red", size: "1", children: ye(n, r) }),
649
+ l && /* @__PURE__ */ i(f, { size: "1", color: "gray", children: l })
474
650
  ] }) });
475
- }, vt = ({
651
+ }, Xr = ({
476
652
  data: e,
477
- handleChange: t,
478
- path: r,
479
- label: o,
480
- required: u,
481
- errors: i,
482
- schema: l,
483
- enabled: a,
484
- visible: s = !0
653
+ handleChange: r,
654
+ path: t,
655
+ label: n,
656
+ required: l,
657
+ errors: o,
658
+ schema: s,
659
+ enabled: c,
660
+ visible: a = !0
485
661
  }) => {
486
- if (ge(() => {
487
- s === !1 && t(r, void 0);
488
- }, [s, r, t]), s === !1)
662
+ if (de(() => {
663
+ a === !1 && r(t, void 0);
664
+ }, [a, t, r]), a === !1)
489
665
  return null;
490
- const c = i.length === 0, d = typeof e == "string" ? e : "", y = (b) => /* @__PURE__ */ n(yt, { path: r, label: o, required: u, errors: i, description: l.description, children: b });
491
- if (l.format === "time")
492
- return y(
493
- /* @__PURE__ */ n(
494
- Se.Root,
666
+ const d = o.length === 0, u = typeof e == "string" ? e : "", h = (T) => /* @__PURE__ */ i(Br, { path: t, label: n, required: l, errors: o, description: s.description, children: T });
667
+ if (s.format === "time")
668
+ return h(
669
+ /* @__PURE__ */ i(
670
+ Ae.Root,
495
671
  {
496
672
  type: "time",
497
- value: d,
498
- onChange: (b) => t(r, b.target.value),
499
- disabled: !a,
500
- color: c ? void 0 : "red",
501
- id: r
673
+ value: u,
674
+ onChange: (T) => r(t, T.target.value),
675
+ disabled: !c,
676
+ color: d ? void 0 : "red",
677
+ id: t
502
678
  }
503
679
  )
504
680
  );
505
- const p = l.format === "date-time", [m = "", v = ""] = d.split("T"), I = v.slice(0, 5), A = (b, k) => {
506
- if (!b) {
507
- t(r, void 0);
681
+ const p = s.format === "date-time", [g = "", b = ""] = u.split("T"), I = b.slice(0, 5), O = (T, A) => {
682
+ if (!T) {
683
+ r(t, void 0);
508
684
  return;
509
685
  }
510
- t(r, p ? gt(b, k || "00:00") : b);
686
+ r(t, p ? Wr(T, A || "00:00") : T);
511
687
  };
512
- return y(
513
- /* @__PURE__ */ g(S, { gap: "2", align: "center", children: [
514
- /* @__PURE__ */ n(
515
- Se.Root,
688
+ return h(
689
+ /* @__PURE__ */ y(D, { gap: "2", align: "center", children: [
690
+ /* @__PURE__ */ i(
691
+ Ae.Root,
516
692
  {
517
693
  type: "date",
518
- value: m,
519
- disabled: !a,
520
- color: c ? void 0 : "red",
521
- onChange: (b) => A(b.target.value, I),
522
- id: r,
694
+ value: g,
695
+ disabled: !c,
696
+ color: d ? void 0 : "red",
697
+ onChange: (T) => O(T.target.value, I),
698
+ id: t,
523
699
  style: { flex: 1 }
524
700
  }
525
701
  ),
526
- p && /* @__PURE__ */ n(
527
- Se.Root,
702
+ p && /* @__PURE__ */ i(
703
+ Ae.Root,
528
704
  {
529
705
  type: "time",
530
706
  value: I,
531
- disabled: !a || !m,
532
- color: c ? void 0 : "red",
533
- onChange: (b) => A(m, b.target.value),
707
+ disabled: !c || !g,
708
+ color: d ? void 0 : "red",
709
+ onChange: (T) => O(g, T.target.value),
534
710
  style: { flex: 1 }
535
711
  }
536
712
  )
537
713
  ] })
538
714
  );
539
- }, bt = q(2, We(Ir, kr, Dr)), wt = me(vt), Et = ({
715
+ }, Kr = ee(2, Je(nr, or, ir)), Yr = ue(Xr), Gr = ({
540
716
  uischema: e,
541
- schema: t,
542
- path: r,
543
- renderers: o,
544
- cells: u,
545
- enabled: i,
546
- visible: l = !0
717
+ schema: r,
718
+ path: t,
719
+ renderers: n,
720
+ cells: l,
721
+ enabled: o,
722
+ visible: s = !0
547
723
  }) => {
548
- const s = e.elements;
549
- return l === !1 ? null : /* @__PURE__ */ n(S, { direction: "column", gap: "4", children: s.map((c, d) => /* @__PURE__ */ n(
550
- Fe,
724
+ const a = e.elements;
725
+ return s === !1 ? null : /* @__PURE__ */ i(D, { direction: "column", gap: "4", children: a.map((d, u) => /* @__PURE__ */ i(
726
+ Be,
551
727
  {
552
- uischema: c,
553
- schema: t,
554
- path: r,
555
- renderers: o,
556
- cells: u,
557
- enabled: i
728
+ uischema: d,
729
+ schema: r,
730
+ path: t,
731
+ renderers: n,
732
+ cells: l,
733
+ enabled: o
558
734
  },
559
- `${r}-${d}`
735
+ `${t}-${u}`
560
736
  )) });
561
- }, Rt = q(1, Le("VerticalLayout")), Tt = ({
737
+ }, qr = ee(1, He("VerticalLayout")), Jr = ({
562
738
  uischema: e,
563
- schema: t,
564
- path: r,
565
- renderers: o,
566
- cells: u,
567
- enabled: i,
568
- visible: l = !0
739
+ schema: r,
740
+ path: t,
741
+ renderers: n,
742
+ cells: l,
743
+ enabled: o,
744
+ visible: s = !0
569
745
  }) => {
570
- const s = e.elements;
571
- return l === !1 ? null : /* @__PURE__ */ n(S, { direction: "row", gap: "4", children: s.map((c, d) => /* @__PURE__ */ n(x, { style: { flex: 1 }, children: /* @__PURE__ */ n(
572
- Fe,
746
+ const a = e.elements;
747
+ return s === !1 ? null : /* @__PURE__ */ i(D, { direction: "row", gap: "4", children: a.map((d, u) => /* @__PURE__ */ i(S, { style: { flex: 1 }, children: /* @__PURE__ */ i(
748
+ Be,
573
749
  {
574
- uischema: c,
575
- schema: t,
576
- path: r,
577
- renderers: o,
578
- cells: u,
579
- enabled: i
750
+ uischema: d,
751
+ schema: r,
752
+ path: t,
753
+ renderers: n,
754
+ cells: l,
755
+ enabled: o
580
756
  }
581
- ) }, `${r}-${d}`)) });
582
- }, At = q(1, Le("HorizontalLayout")), Ct = ({
757
+ ) }, `${t}-${u}`)) });
758
+ }, Zr = ee(1, He("HorizontalLayout")), Qr = ({
583
759
  uischema: e,
584
- schema: t,
585
- path: r,
586
- renderers: o,
587
- cells: u,
588
- enabled: i,
589
- visible: l = !0
760
+ schema: r,
761
+ path: t,
762
+ renderers: n,
763
+ cells: l,
764
+ enabled: o,
765
+ visible: s = !0
590
766
  }) => {
591
- const a = e, s = a.elements;
592
- return l === !1 ? null : /* @__PURE__ */ g(x, { mb: "6", children: [
593
- a.label && /* @__PURE__ */ n(hr, { size: "3", mb: "3", className: "text-gray-500 uppercase tracking-wide font-semibold", children: a.label }),
594
- /* @__PURE__ */ n(S, { direction: "column", gap: "4", children: s.map((c, d) => /* @__PURE__ */ n(
595
- Fe,
767
+ const c = e, a = c.elements;
768
+ return s === !1 ? null : /* @__PURE__ */ y(S, { mb: "6", children: [
769
+ c.label && /* @__PURE__ */ i(It, { size: "3", mb: "3", className: "text-gray-500 uppercase tracking-wide font-semibold", children: c.label }),
770
+ /* @__PURE__ */ i(D, { direction: "column", gap: "4", children: a.map((d, u) => /* @__PURE__ */ i(
771
+ Be,
596
772
  {
597
- uischema: c,
598
- schema: t,
599
- path: r,
600
- renderers: o,
601
- cells: u,
602
- enabled: i
773
+ uischema: d,
774
+ schema: r,
775
+ path: t,
776
+ renderers: n,
777
+ cells: l,
778
+ enabled: o
603
779
  },
604
- `${r}-${d}`
780
+ `${t}-${u}`
605
781
  )) })
606
782
  ] });
607
- }, St = q(1, Le("Group")), Ot = ({
783
+ }, en = ee(1, He("Group")), tn = ({
608
784
  uischema: e,
609
- schema: t,
610
- path: r,
611
- renderers: o,
612
- cells: u,
613
- enabled: i,
614
- visible: l = !0
785
+ schema: r,
786
+ path: t,
787
+ renderers: n,
788
+ cells: l,
789
+ enabled: o,
790
+ visible: s = !0
615
791
  }) => {
616
792
  var p;
617
- const s = e.elements.filter((m) => m.type === "Category"), [c, d] = $(((p = s[0]) == null ? void 0 : p.label) || "");
618
- if (l === !1 || !s.length) return null;
619
- const y = s.find((m) => m.label === c) ? c : s[0].label;
620
- return /* @__PURE__ */ g($e.Root, { value: y, onValueChange: d, children: [
621
- /* @__PURE__ */ n($e.List, { children: s.map((m, v) => /* @__PURE__ */ n($e.Trigger, { value: m.label, children: m.label }, `${r}-${v}`)) }),
622
- /* @__PURE__ */ n(x, { pt: "3", children: s.map((m, v) => /* @__PURE__ */ n($e.Content, { value: m.label, children: /* @__PURE__ */ n(S, { direction: "column", gap: "4", children: m.elements.map((I, A) => /* @__PURE__ */ n(
623
- Fe,
793
+ const a = e.elements.filter((g) => g.type === "Category"), [d, u] = j(((p = a[0]) == null ? void 0 : p.label) || "");
794
+ if (s === !1 || !a.length) return null;
795
+ const h = a.find((g) => g.label === d) ? d : a[0].label;
796
+ return /* @__PURE__ */ y(Ye.Root, { value: h, onValueChange: u, children: [
797
+ /* @__PURE__ */ i(Ye.List, { children: a.map((g, b) => /* @__PURE__ */ i(Ye.Trigger, { value: g.label, children: g.label }, `${t}-${b}`)) }),
798
+ /* @__PURE__ */ i(S, { pt: "3", children: a.map((g, b) => /* @__PURE__ */ i(Ye.Content, { value: g.label, children: /* @__PURE__ */ i(D, { direction: "column", gap: "4", children: g.elements.map((I, O) => /* @__PURE__ */ i(
799
+ Be,
624
800
  {
625
801
  uischema: I,
626
- schema: t,
627
- path: r,
628
- renderers: o,
629
- cells: u,
630
- enabled: i
802
+ schema: r,
803
+ path: t,
804
+ renderers: n,
805
+ cells: l,
806
+ enabled: o
631
807
  },
632
- `${r}-${v}-${A}`
633
- )) }) }, `${r}-${v}`)) })
808
+ `${t}-${b}-${O}`
809
+ )) }) }, `${t}-${b}`)) })
634
810
  ] });
635
- }, Nt = q(1, Le("Categorization"));
636
- function ye(e) {
811
+ }, rn = ee(1, He("Categorization"));
812
+ function ve(e) {
637
813
  return e >= 1024 * 1024 ? `${(e / (1024 * 1024)).toFixed(0)} MB` : e >= 1024 ? `${(e / 1024).toFixed(0)} KB` : `${e} B`;
638
814
  }
639
- function ve(e) {
640
- return e.split(",").map((t) => {
641
- if (t = t.trim(), t.endsWith("/*"))
642
- return t.split("/")[0].toUpperCase() + "S";
643
- if (t.startsWith("."))
644
- return t.slice(1).toUpperCase();
645
- const r = t.split("/")[1];
646
- return r ? r.toUpperCase() : t;
647
- }).join(", ");
648
- }
649
- function xt(e) {
815
+ function we(e) {
816
+ const r = e.split(",").map((o) => o.trim()).filter(Boolean), t = r.filter((o) => o.startsWith(".")), l = (t.length > 0 ? t : r).map((o) => {
817
+ if (o.endsWith("/*")) return o.split("/")[0].toUpperCase() + "S";
818
+ if (o.startsWith(".")) return o.slice(1).toUpperCase();
819
+ const s = o.split("/")[1];
820
+ return s ? s.toUpperCase() : o;
821
+ });
822
+ return [...new Set(l)].join(", ");
823
+ }
824
+ function nn(e) {
650
825
  return e ? Array.isArray(e) ? e : [e] : [];
651
826
  }
652
- const It = ({
827
+ const on = ({
653
828
  data: e,
654
- handleChange: t,
655
- path: r,
656
- label: o,
657
- required: u,
658
- uischema: i,
659
- schema: l,
660
- enabled: a,
661
- errors: s,
662
- visible: c = !0
829
+ handleChange: r,
830
+ path: t,
831
+ label: n,
832
+ required: l,
833
+ uischema: o,
834
+ schema: s,
835
+ enabled: c,
836
+ errors: a,
837
+ visible: d = !0
663
838
  }) => {
664
- const d = Yr();
665
- be(c, r, t, null);
666
- const y = !s || s.length === 0, p = (l == null ? void 0 : l["x-file"]) ?? {}, m = (i == null ? void 0 : i.options) ?? {}, v = p.maxFiles ?? m.maxFiles ?? 1, I = p.maxSize ?? m.maxSize ?? 5 * 1024 * 1024, A = p.accept ?? m.accept ?? "image/*,application/pdf", b = v > 1, k = a !== !1, [F, z] = $(!1), [w, _] = $(null), [V, O] = $({}), C = pe(/* @__PURE__ */ new Set()), H = pe(null), B = xt(e), W = B.length >= v;
667
- ge(() => () => {
668
- C.current.forEach((f) => URL.revokeObjectURL(f)), C.current.clear();
839
+ const u = br();
840
+ Ee(d, t, r);
841
+ const h = !a || a.length === 0, p = (s == null ? void 0 : s["x-file"]) ?? {}, g = (o == null ? void 0 : o.options) ?? {}, b = p.maxFiles ?? g.maxFiles ?? 1, I = p.maxSize ?? g.maxSize ?? 5 * 1024 * 1024, O = p.accept ?? g.accept ?? "image/*,application/pdf", T = b > 1, A = c !== !1, [k, M] = j(!1), [L, N] = j(null), [U, z] = j({}), v = ae(/* @__PURE__ */ new Set()), E = ae(null), B = nn(e), K = B.length >= b;
842
+ de(() => () => {
843
+ v.current.forEach((m) => URL.revokeObjectURL(m)), v.current.clear();
669
844
  }, []);
670
- const j = ke(
671
- async (f) => {
672
- if (_(null), B.length >= v) {
673
- _(`Maximum ${v} file${v > 1 ? "s" : ""} allowed.`);
845
+ const J = Fe(
846
+ async (m) => {
847
+ if (N(null), B.length >= b) {
848
+ N(`Maximum ${b} file${b > 1 ? "s" : ""} allowed.`);
674
849
  return;
675
850
  }
676
- if (f.size > I) {
677
- _(`File exceeds the ${ye(I)} limit.`);
851
+ if (m.size > I) {
852
+ N(`File exceeds the ${ve(I)} limit.`);
678
853
  return;
679
854
  }
680
- if (!A.split(",").map((N) => N.trim()).some((N) => N === "*" || N === "*/*" ? !0 : N.endsWith("/*") ? f.type.startsWith(N.slice(0, -1)) : N.startsWith(".") ? f.name.toLowerCase().endsWith(N.toLowerCase()) : f.type === N)) {
681
- _(`Invalid type. Accepted: ${ve(A)}`);
855
+ if (!O.split(",").map((P) => P.trim()).some((P) => P === "*" || P === "*/*" ? !0 : P.endsWith("/*") ? m.type.startsWith(P.slice(0, -1)) : P.startsWith(".") ? m.name.toLowerCase().endsWith(P.toLowerCase()) : m.type === P)) {
856
+ N(`Invalid type. Accepted: ${we(O)}`);
682
857
  return;
683
858
  }
684
- if (!(d != null && d.onUpload)) {
685
- _("Upload service not configured.");
859
+ if (!(u != null && u.onUpload)) {
860
+ N("Upload service not configured.");
686
861
  return;
687
862
  }
688
863
  try {
689
- const N = await d.onUpload(f), U = URL.createObjectURL(f);
690
- C.current.add(U);
691
- const Z = { key: N.key, name: N.name ?? f.name, blobUrl: U };
692
- O((J) => ({ ...J, [N.key]: Z }));
693
- const ie = [...B, N.key];
694
- t(r, b ? ie : ie[0]);
864
+ const P = await u.onUpload(m), _ = URL.createObjectURL(m);
865
+ v.current.add(_);
866
+ const re = { key: P.key, name: P.name ?? m.name, blobUrl: _ };
867
+ z((ie) => ({ ...ie, [P.key]: re }));
868
+ const q = [...B, P.key];
869
+ r(t, T ? q : q[0]);
695
870
  } catch {
696
- _("Upload failed. Please try again."), H.current && (H.current.value = "");
871
+ N("Upload failed. Please try again."), E.current && (E.current.value = "");
697
872
  }
698
873
  },
699
- [B, v, I, A, d, r, t, b]
874
+ [B, b, I, O, u, t, r, T]
700
875
  );
701
- if (c === !1)
876
+ if (d === !1)
702
877
  return null;
703
- const ee = (f) => {
704
- f.preventDefault(), f.stopPropagation(), !(!k || W) && z(f.type === "dragenter" || f.type === "dragover");
705
- }, re = (f) => {
706
- var T;
707
- f.preventDefault(), f.stopPropagation(), z(!1), !(!k || W) && (T = f.dataTransfer.files) != null && T[0] && j(f.dataTransfer.files[0]);
708
- }, le = (f) => {
709
- var T;
710
- (T = f.target.files) != null && T[0] && (j(f.target.files[0]), f.target.value = "");
711
- }, oe = (f) => {
712
- if (!k) return;
713
- O((K) => {
714
- var Z;
715
- const N = { ...K }, U = (Z = N[f]) == null ? void 0 : Z.blobUrl;
716
- return U && (URL.revokeObjectURL(U), C.current.delete(U)), delete N[f], N;
878
+ const F = (m) => {
879
+ m.preventDefault(), m.stopPropagation(), !(!A || K) && M(m.type === "dragenter" || m.type === "dragover");
880
+ }, R = (m) => {
881
+ var C;
882
+ m.preventDefault(), m.stopPropagation(), M(!1), !(!A || K) && (C = m.dataTransfer.files) != null && C[0] && J(m.dataTransfer.files[0]);
883
+ }, Y = (m) => {
884
+ var C;
885
+ (C = m.target.files) != null && C[0] && (J(m.target.files[0]), m.target.value = "");
886
+ }, Q = (m) => {
887
+ if (!A) return;
888
+ z((G) => {
889
+ var re;
890
+ const P = { ...G }, _ = (re = P[m]) == null ? void 0 : re.blobUrl;
891
+ return _ && (URL.revokeObjectURL(_), v.current.delete(_)), delete P[m], P;
717
892
  });
718
- const T = B.filter((K) => K !== f);
719
- t(r, b ? T.length > 0 ? T : null : T[0] ?? null);
720
- }, se = async (f, T) => {
721
- var U, Z, ie;
722
- f.preventDefault();
723
- const K = (U = V[T]) == null ? void 0 : U.blobUrl;
724
- if (K) {
725
- (Z = window.open(K, "_blank", "noopener,noreferrer")) == null || Z.focus();
893
+ const C = B.filter((G) => G !== m);
894
+ r(t, T ? C.length > 0 ? C : void 0 : C[0]);
895
+ }, be = async (m, C) => {
896
+ var _, re, q;
897
+ m.preventDefault();
898
+ const G = (_ = U[C]) == null ? void 0 : _.blobUrl;
899
+ if (G) {
900
+ (re = window.open(G, "_blank", "noopener,noreferrer")) == null || re.focus();
726
901
  return;
727
902
  }
728
- const N = window.open("", "_blank");
729
- if (N)
903
+ const P = window.open("", "_blank");
904
+ if (P)
730
905
  try {
731
- const J = await ((ie = d == null ? void 0 : d.getDownloadUrl) == null ? void 0 : ie.call(d, T));
732
- J != null && J.url ? N.location.href = J.url : N.close();
906
+ const ie = await ((q = u == null ? void 0 : u.getDownloadUrl) == null ? void 0 : q.call(u, C));
907
+ ie != null && ie.url ? P.location.href = ie.url : P.close();
733
908
  } catch {
734
- N.close();
909
+ P.close();
735
910
  }
736
911
  };
737
- if (!k && B.length === 0) return null;
738
- const de = v - B.length, G = k && !W;
739
- return /* @__PURE__ */ g(x, { mb: "4", children: [
740
- /* @__PURE__ */ g(S, { align: "center", justify: "between", mb: "2", children: [
741
- /* @__PURE__ */ g(h, { as: "label", size: "2", weight: "bold", children: [
742
- o,
743
- u && /* @__PURE__ */ n(h, { color: "red", children: " *" })
912
+ if (!A && B.length === 0) return null;
913
+ const oe = b - B.length, Se = A && !K;
914
+ return /* @__PURE__ */ y(S, { mb: "4", children: [
915
+ /* @__PURE__ */ y(D, { align: "center", justify: "between", mb: "2", children: [
916
+ /* @__PURE__ */ y(f, { as: "label", size: "2", weight: "bold", children: [
917
+ n,
918
+ l && /* @__PURE__ */ i(f, { color: "red", children: " *" })
744
919
  ] }),
745
- /* @__PURE__ */ n(h, { size: "1", color: "gray", children: b ? `Up to ${v} files · ${ye(I)} each · ${ve(A)}` : `${ye(I)} · ${ve(A)}` })
920
+ /* @__PURE__ */ i(f, { size: "1", color: "gray", children: T ? `Up to ${b} files · ${ve(I)} each · ${we(O)}` : `${ve(I)} · ${we(O)}` })
746
921
  ] }),
747
- B.map((f) => {
748
- var T;
749
- return /* @__PURE__ */ n(pr, { size: "2", variant: "surface", mb: "2", children: /* @__PURE__ */ g(S, { align: "center", gap: "3", children: [
750
- /* @__PURE__ */ n(
751
- x,
922
+ B.map((m) => {
923
+ var C;
924
+ return /* @__PURE__ */ i(Dt, { size: "2", variant: "surface", mb: "2", children: /* @__PURE__ */ y(D, { align: "center", gap: "3", children: [
925
+ /* @__PURE__ */ i(
926
+ S,
752
927
  {
753
928
  style: {
754
929
  background: "var(--blue-3)",
@@ -757,11 +932,11 @@ const It = ({
757
932
  color: "var(--blue-9)",
758
933
  flexShrink: 0
759
934
  },
760
- children: /* @__PURE__ */ n(Hr, { width: "20", height: "20" })
935
+ children: /* @__PURE__ */ i(hr, { width: "20", height: "20" })
761
936
  }
762
937
  ),
763
- /* @__PURE__ */ n(x, { style: { flex: 1, overflow: "hidden" }, children: /* @__PURE__ */ n(
764
- h,
938
+ /* @__PURE__ */ i(S, { style: { flex: 1, overflow: "hidden" }, children: /* @__PURE__ */ i(
939
+ f,
765
940
  {
766
941
  size: "2",
767
942
  weight: "bold",
@@ -771,115 +946,115 @@ const It = ({
771
946
  textOverflow: "ellipsis",
772
947
  whiteSpace: "nowrap"
773
948
  },
774
- children: ((T = V[f]) == null ? void 0 : T.name) ?? "Uploaded File"
949
+ children: ((C = U[m]) == null ? void 0 : C.name) ?? "Uploaded File"
775
950
  }
776
951
  ) }),
777
- /* @__PURE__ */ g(S, { align: "center", gap: "2", style: { flexShrink: 0 }, children: [
778
- /* @__PURE__ */ n(De, { variant: "soft", color: "blue", size: "1", onClick: (K) => se(K, f), children: "View" }),
779
- /* @__PURE__ */ n(Wr, { style: { color: "var(--green-9)", width: 18, height: 18 } }),
780
- k && /* @__PURE__ */ n(Me, { variant: "ghost", color: "gray", onClick: () => oe(f), children: /* @__PURE__ */ n(Ye, {}) })
952
+ /* @__PURE__ */ y(D, { align: "center", gap: "2", style: { flexShrink: 0 }, children: [
953
+ /* @__PURE__ */ i(De, { variant: "soft", color: "blue", size: "1", onClick: (G) => be(G, m), children: "View" }),
954
+ /* @__PURE__ */ i(mr, { style: { color: "var(--green-9)", width: 18, height: 18 } }),
955
+ A && /* @__PURE__ */ i(je, { variant: "ghost", color: "gray", onClick: () => Q(m), children: /* @__PURE__ */ i(rt, {}) })
781
956
  ] })
782
- ] }) }, f);
957
+ ] }) }, m);
783
958
  }),
784
- G && /* @__PURE__ */ g(
959
+ Se && /* @__PURE__ */ y(
785
960
  "div",
786
961
  {
787
962
  role: "button",
788
963
  tabIndex: 0,
789
964
  onClick: () => {
790
- var f;
791
- return (f = H.current) == null ? void 0 : f.click();
965
+ var m;
966
+ return (m = E.current) == null ? void 0 : m.click();
792
967
  },
793
- onKeyDown: (f) => {
794
- var T;
795
- (f.key === "Enter" || f.key === " ") && (f.preventDefault(), (T = H.current) == null || T.click());
968
+ onKeyDown: (m) => {
969
+ var C;
970
+ (m.key === "Enter" || m.key === " ") && (m.preventDefault(), (C = E.current) == null || C.click());
796
971
  },
797
- onDragEnter: ee,
798
- onDragLeave: ee,
799
- onDragOver: ee,
800
- onDrop: re,
972
+ onDragEnter: F,
973
+ onDragLeave: F,
974
+ onDragOver: F,
975
+ onDrop: R,
801
976
  style: { cursor: "pointer" },
802
977
  className: [
803
978
  "border-2 border-dashed rounded-lg p-6 text-center",
804
979
  "transition-all duration-200 ease-in-out",
805
- F ? "border-blue-500 bg-blue-50" : w ? "border-red-300 bg-red-50" : "border-gray-300 hover:border-blue-400 hover:bg-gray-50"
980
+ k ? "border-blue-500 bg-blue-50" : L ? "border-red-300 bg-red-50" : "border-gray-300 hover:border-blue-400 hover:bg-gray-50"
806
981
  ].join(" "),
807
982
  children: [
808
- /* @__PURE__ */ n("input", { ref: H, type: "file", style: { display: "none" }, accept: A, onChange: le }),
809
- /* @__PURE__ */ n(S, { direction: "column", align: "center", gap: "2", children: w ? /* @__PURE__ */ g(he, { children: [
810
- /* @__PURE__ */ n(Je, { style: { width: 32, height: 32, color: "var(--red-9)" } }),
811
- /* @__PURE__ */ n(h, { size: "2", color: "red", weight: "medium", children: w }),
812
- /* @__PURE__ */ n(h, { size: "1", color: "gray", children: "Click to try again" })
813
- ] }) : /* @__PURE__ */ g(he, { children: [
814
- /* @__PURE__ */ n(Ne, { style: { width: 32, height: 32, color: "var(--gray-8)" } }),
815
- /* @__PURE__ */ n(h, { size: "2", weight: "medium", children: B.length > 0 ? `Add another file (${de} remaining)` : "Click to upload or drag and drop" }),
816
- /* @__PURE__ */ g(h, { size: "1", color: "gray", children: [
817
- ye(I),
983
+ /* @__PURE__ */ i("input", { ref: E, type: "file", style: { display: "none" }, accept: O, onChange: Y }),
984
+ /* @__PURE__ */ i(D, { direction: "column", align: "center", gap: "2", children: L ? /* @__PURE__ */ y(ge, { children: [
985
+ /* @__PURE__ */ i(nt, { style: { width: 32, height: 32, color: "var(--red-9)" } }),
986
+ /* @__PURE__ */ i(f, { size: "2", color: "red", weight: "medium", children: L }),
987
+ /* @__PURE__ */ i(f, { size: "1", color: "gray", children: "Click to try again" })
988
+ ] }) : /* @__PURE__ */ y(ge, { children: [
989
+ /* @__PURE__ */ i(ze, { style: { width: 32, height: 32, color: "var(--gray-8)" } }),
990
+ /* @__PURE__ */ i(f, { size: "2", weight: "medium", children: B.length > 0 ? `Add another file (${oe} remaining)` : "Click to upload or drag and drop" }),
991
+ /* @__PURE__ */ y(f, { size: "1", color: "gray", children: [
992
+ ve(I),
818
993
  " max · ",
819
- ve(A)
994
+ we(O)
820
995
  ] })
821
996
  ] }) })
822
997
  ]
823
998
  }
824
999
  ),
825
- k && W && b && /* @__PURE__ */ g(h, { size: "1", color: "gray", mt: "1", style: { display: "block", textAlign: "center" }, children: [
1000
+ A && K && T && /* @__PURE__ */ y(f, { size: "1", color: "gray", mt: "1", style: { display: "block", textAlign: "center" }, children: [
826
1001
  "Maximum ",
827
- v,
1002
+ b,
828
1003
  " files uploaded. Remove one to replace it."
829
1004
  ] }),
830
- !y && /* @__PURE__ */ n(h, { color: "red", size: "1", mt: "2", style: { display: "block" }, children: we(s, o) })
1005
+ !h && /* @__PURE__ */ i(f, { color: "red", size: "1", mt: "2", style: { display: "block" }, children: ye(a, n) })
831
1006
  ] });
832
- }, kt = me(It), Dt = q(
1007
+ }, sn = ue(on), ln = ee(
833
1008
  10,
834
1009
  // high rank to beat default array renderer
835
- Mr(
1010
+ Nt(
836
1011
  // Match both single-file (type: string) and multi-file (type: array)
837
- ze((e) => {
1012
+ Ie((e) => {
838
1013
  if (e.type === "string" && e.format === "file") return !0;
839
1014
  if (e.type === "array") {
840
- const t = e.items;
841
- return (t == null ? void 0 : t.type) === "string" && (t == null ? void 0 : t.format) === "file";
1015
+ const r = e.items;
1016
+ return (r == null ? void 0 : r.type) === "string" && (r == null ? void 0 : r.format) === "file";
842
1017
  }
843
1018
  return !1;
844
1019
  })
845
1020
  )
846
1021
  );
847
- function yr(e, t) {
848
- return e !== !1 && t !== !0;
849
- }
850
- class Ke extends Error {
851
- }
852
- function Mt(e, t) {
853
- const r = Kr(e, { type: "array", cellDates: !0 });
854
- if (r.SheetNames.length === 0)
855
- throw new Ke("This file has no sheets.");
856
- const o = t ?? r.SheetNames[0], u = r.Sheets[o];
857
- if (!u)
858
- throw new Ke(`This file doesn't have a sheet named "${o}".`);
859
- const i = Gr.sheet_to_json(u, { header: 1, raw: !0, defval: null });
1022
+ function $t(e, r) {
1023
+ return e !== !1 && r !== !0;
1024
+ }
1025
+ class et extends Error {
1026
+ }
1027
+ async function cn(e, r) {
1028
+ const { read: t, utils: n } = await import("@e965/xlsx"), l = t(e, { type: "array", cellDates: !0 });
1029
+ if (l.SheetNames.length === 0)
1030
+ throw new et("This file has no sheets.");
1031
+ const o = r ?? l.SheetNames[0], s = l.Sheets[o];
1032
+ if (!s)
1033
+ throw new et(`This file doesn't have a sheet named "${o}".`);
1034
+ const c = n.sheet_to_json(s, { header: 1, raw: !0, defval: null });
860
1035
  return {
861
1036
  sheetName: o,
862
- matrix: i,
863
- rowCount: i.length,
864
- colCount: Math.max(0, ...i.map((l) => l.length))
1037
+ matrix: c,
1038
+ rowCount: c.length,
1039
+ colCount: Math.max(0, ...c.map((a) => a.length))
865
1040
  };
866
1041
  }
867
- function zt(e) {
868
- let t = e + 1, r = "";
869
- for (; t > 0; ) {
870
- const o = (t - 1) % 26;
871
- r = String.fromCharCode(65 + o) + r, t = Math.floor((t - 1) / 26);
1042
+ function an(e) {
1043
+ let r = e + 1, t = "";
1044
+ for (; r > 0; ) {
1045
+ const n = (r - 1) % 26;
1046
+ t = String.fromCharCode(65 + n) + t, r = Math.floor((r - 1) / 26);
872
1047
  }
873
- return r;
1048
+ return t;
874
1049
  }
875
- class ne extends Error {
876
- constructor(r, o) {
877
- super(o ?? r);
878
- Ze(this, "code");
879
- this.code = r, this.name = "FormulaError";
1050
+ class ce extends Error {
1051
+ constructor(t, n) {
1052
+ super(n ?? t);
1053
+ ut(this, "code");
1054
+ this.code = t, this.name = "FormulaError";
880
1055
  }
881
1056
  }
882
- const Lt = [
1057
+ const un = [
883
1058
  // Logical
884
1059
  // IF is excluded here even though its native body is real, non-stub code —
885
1060
  // see LOGICAL_FUNCTIONS_WITH_BROKEN_CONDITION_COERCION below for why it's
@@ -905,7 +1080,7 @@ const Lt = [
905
1080
  // DATE_FUNCTIONS_WITH_BROKEN_NATIVE_IMPL.
906
1081
  "DATE",
907
1082
  "TODAY"
908
- ], Ft = [
1083
+ ], dn = [
909
1084
  "MAX",
910
1085
  "MIN",
911
1086
  "MAXA",
@@ -924,7 +1099,7 @@ const Lt = [
924
1099
  "COUNTA",
925
1100
  // not present in fast-formula-parser's function table at all.
926
1101
  "UPPER"
927
- ], Ut = ["YEAR", "MONTH", "DAY", "WEEKDAY"], Pt = ["IF"], $t = [
1102
+ ], fn = ["YEAR", "MONTH", "DAY", "WEEKDAY"], pn = ["IF"], hn = [
928
1103
  "CONCATENATE",
929
1104
  "CONCAT",
930
1105
  "LEN",
@@ -935,115 +1110,115 @@ const Lt = [
935
1110
  "MID",
936
1111
  "FIND",
937
1112
  "SEARCH"
938
- ], _t = /* @__PURE__ */ new Set([
939
- ...Lt,
940
- ...Ft,
941
- ...Ut,
942
- ...$t,
943
- ...Pt
944
- ]), Vt = /"(?:[^"]|"")*"/g, er = new RegExp("(?<![A-Za-z0-9_.])([A-Za-z_][A-Za-z0-9_.]*)\\s*\\(", "g");
945
- function Ht(e) {
946
- const t = e.replace(Vt, (o) => " ".repeat(o.length));
947
- er.lastIndex = 0;
948
- let r;
949
- for (; (r = er.exec(t)) !== null; ) {
950
- const o = r[1].toUpperCase();
951
- if (!_t.has(o))
952
- throw new ne("NAME", `Function ${o} is not allowed.`);
1113
+ ], mn = /* @__PURE__ */ new Set([
1114
+ ...un,
1115
+ ...dn,
1116
+ ...fn,
1117
+ ...hn,
1118
+ ...pn
1119
+ ]), gn = /"(?:[^"]|"")*"/g, ht = new RegExp("(?<![A-Za-z0-9_.])([A-Za-z_][A-Za-z0-9_.]*)\\s*\\(", "g");
1120
+ function yn(e) {
1121
+ const r = e.replace(gn, (n) => " ".repeat(n.length));
1122
+ ht.lastIndex = 0;
1123
+ let t;
1124
+ for (; (t = ht.exec(r)) !== null; ) {
1125
+ const n = t[1].toUpperCase();
1126
+ if (!mn.has(n))
1127
+ throw new ce("NAME", `Function ${n} is not allowed.`);
953
1128
  }
954
1129
  }
955
- function Wt(e, t, r) {
956
- let o = e;
957
- if (o == null) throw r.NA;
958
- if (typeof o == "object" && !(o instanceof r) && (o = t.retrieveRef(o)), o instanceof r) throw o;
959
- if (typeof o == "boolean") return o;
960
- if (typeof o == "number") return o !== 0;
961
- throw r.VALUE;
1130
+ function bn(e, r, t) {
1131
+ let n = e;
1132
+ if (n == null) throw t.NA;
1133
+ if (typeof n == "object" && !(n instanceof t) && (n = r.retrieveRef(n)), n instanceof t) throw n;
1134
+ if (typeof n == "boolean") return n;
1135
+ if (typeof n == "number") return n !== 0;
1136
+ throw t.VALUE;
962
1137
  }
963
- function vr(e) {
1138
+ function _t(e) {
964
1139
  return e !== null && typeof e == "object" && "value" in e ? e.value : e;
965
1140
  }
966
- function Ce(e) {
967
- const t = vr(e);
968
- return Array.isArray(t) ? t.flat(1 / 0) : [t];
1141
+ function Ne(e) {
1142
+ const r = _t(e);
1143
+ return Array.isArray(r) ? r.flat(1 / 0) : [r];
969
1144
  }
970
- function M(e) {
971
- const t = vr(e);
972
- return Array.isArray(t) ? t.flat(1 / 0)[0] : t;
1145
+ function W(e) {
1146
+ const r = _t(e);
1147
+ return Array.isArray(r) ? r.flat(1 / 0)[0] : r;
973
1148
  }
974
- function _e(e) {
975
- return e === void 0 ? void 0 : M(e);
1149
+ function Ge(e) {
1150
+ return e === void 0 ? void 0 : W(e);
976
1151
  }
977
- function te(e) {
1152
+ function le(e) {
978
1153
  return e == null || e === "" ? "" : typeof e == "boolean" ? e ? "TRUE" : "FALSE" : e instanceof Date ? e.toLocaleDateString() : String(e);
979
1154
  }
980
- function Xt(e, t) {
981
- return e instanceof t ? e : new t(e.message || "#ERROR!");
1155
+ function vn(e, r) {
1156
+ return e instanceof r ? e : new r(e.message || "#ERROR!");
982
1157
  }
983
- function Y(e) {
984
- return e.find((t) => t instanceof Error);
1158
+ function te(e) {
1159
+ return e.find((r) => r instanceof Error);
985
1160
  }
986
- function Bt(e, t) {
987
- const r = (i) => {
988
- throw Xt(i, t);
989
- }, o = (i, { checkArgsForErrors: l = !0 } = {}) => (...a) => {
990
- const s = a.flatMap(Ce);
991
- if (l) {
992
- const d = Y(s);
993
- d && r(d);
1161
+ function wn(e, r) {
1162
+ const t = (o) => {
1163
+ throw vn(o, r);
1164
+ }, n = (o, { checkArgsForErrors: s = !0 } = {}) => (...c) => {
1165
+ const a = c.flatMap(Ne);
1166
+ if (s) {
1167
+ const u = te(a);
1168
+ u && t(u);
994
1169
  }
995
- const c = i(...s);
996
- return c instanceof Error ? r(c) : c;
997
- }, u = (i, { toText: l = !1 } = {}) => (a) => {
998
- const s = M(a), c = Y([s]);
999
- c && r(c);
1000
- const d = i(l ? te(s) : s);
1001
- return d instanceof Error ? r(d) : d;
1170
+ const d = o(...a);
1171
+ return d instanceof Error ? t(d) : d;
1172
+ }, l = (o, { toText: s = !1 } = {}) => (c) => {
1173
+ const a = W(c), d = te([a]);
1174
+ d && t(d);
1175
+ const u = o(s ? le(a) : a);
1176
+ return u instanceof Error ? t(u) : u;
1002
1177
  };
1003
1178
  return {
1004
1179
  // valueIfTrue/valueIfFalse are passed through unretrieved (not
1005
1180
  // dereferenced or type-checked here) — that's what makes
1006
1181
  // `IF(FALSE, B100, 99)` a genuine short-circuit rather than a lookup.
1007
- IF: (i, l, a, s) => {
1008
- const c = Wt(l, i, t);
1009
- if (a == null) throw t.NA;
1010
- return c ? a : s ?? !1;
1182
+ IF: (o, s, c, a) => {
1183
+ const d = bn(s, o, r);
1184
+ if (c == null) throw r.NA;
1185
+ return d ? c : a ?? !1;
1011
1186
  },
1012
1187
  // Empty input -> 0, matching both the hand-rolled engine this replaces
1013
1188
  // and formulajs's own convention for MAX/MIN.
1014
- MAX: o(e.MAX),
1015
- MIN: o(e.MIN),
1016
- MAXA: o(e.MAXA),
1017
- MINA: o(e.MINA),
1018
- MEDIAN: o(e.MEDIAN),
1189
+ MAX: n(e.MAX),
1190
+ MIN: n(e.MIN),
1191
+ MAXA: n(e.MAXA),
1192
+ MINA: n(e.MINA),
1193
+ MEDIAN: n(e.MEDIAN),
1019
1194
  // COUNTA counts non-blank entries; an error value among the args is
1020
1195
  // itself non-blank and gets counted (matching formulajs's own COUNTA,
1021
1196
  // which never checks for errors), so this skips the error propagation
1022
1197
  // the other aggregates use.
1023
- COUNTA: o(e.COUNTA, { checkArgsForErrors: !1 }),
1024
- LARGE: (i, l) => {
1025
- const a = Ce(i), s = M(l), c = Y([...a, s]);
1026
- c && r(c);
1027
- const d = e.LARGE(a, s);
1028
- return d instanceof Error ? r(d) : d;
1198
+ COUNTA: n(e.COUNTA, { checkArgsForErrors: !1 }),
1199
+ LARGE: (o, s) => {
1200
+ const c = Ne(o), a = W(s), d = te([...c, a]);
1201
+ d && t(d);
1202
+ const u = e.LARGE(c, a);
1203
+ return u instanceof Error ? t(u) : u;
1029
1204
  },
1030
- SMALL: (i, l) => {
1031
- const a = Ce(i), s = M(l), c = Y([...a, s]);
1032
- c && r(c);
1033
- const d = e.SMALL(a, s);
1034
- return d instanceof Error ? r(d) : d;
1205
+ SMALL: (o, s) => {
1206
+ const c = Ne(o), a = W(s), d = te([...c, a]);
1207
+ d && t(d);
1208
+ const u = e.SMALL(c, a);
1209
+ return u instanceof Error ? t(u) : u;
1035
1210
  },
1036
- PERMUT: (i, l) => {
1037
- const a = [M(i), M(l)], s = Y(a);
1038
- s && r(s);
1039
- const c = e.PERMUT(a[0], a[1]);
1040
- return c instanceof Error ? r(c) : c;
1211
+ PERMUT: (o, s) => {
1212
+ const c = [W(o), W(s)], a = te(c);
1213
+ a && t(a);
1214
+ const d = e.PERMUT(c[0], c[1]);
1215
+ return d instanceof Error ? t(d) : d;
1041
1216
  },
1042
- PERMUTATIONA: (i, l) => {
1043
- const a = [M(i), M(l)], s = Y(a);
1044
- s && r(s);
1045
- const c = e.PERMUTATIONA(a[0], a[1]);
1046
- return c instanceof Error ? r(c) : c;
1217
+ PERMUTATIONA: (o, s) => {
1218
+ const c = [W(o), W(s)], a = te(c);
1219
+ a && t(a);
1220
+ const d = e.PERMUTATIONA(c[0], c[1]);
1221
+ return d instanceof Error ? t(d) : d;
1047
1222
  },
1048
1223
  // match_type is intentionally ignored and forced to 0 (exact match)
1049
1224
  // regardless of what the formula author supplied — approximate/sorted
@@ -1051,43 +1226,43 @@ function Bt(e, t) {
1051
1226
  // Excel's own default too) risks silently mis-ranking unsorted
1052
1227
  // real-world data. Same scope decision as the hand-rolled engine this
1053
1228
  // replaces, carried forward deliberately rather than dropped.
1054
- MATCH: (i, l) => {
1055
- const a = M(i), s = Ce(l), c = Y([a, ...s]);
1056
- c && r(c);
1057
- const d = e.MATCH(a, s, 0);
1058
- return d instanceof Error ? r(d) : d;
1229
+ MATCH: (o, s) => {
1230
+ const c = W(o), a = Ne(s), d = te([c, ...a]);
1231
+ d && t(d);
1232
+ const u = e.MATCH(c, a, 0);
1233
+ return u instanceof Error ? t(u) : u;
1059
1234
  },
1060
- SWITCH: (...i) => {
1061
- const l = i.map(M), a = Y(l);
1062
- a && r(a);
1063
- const s = e.SWITCH(...l);
1064
- return s instanceof Error ? r(s) : s;
1235
+ SWITCH: (...o) => {
1236
+ const s = o.map(W), c = te(s);
1237
+ c && t(c);
1238
+ const a = e.SWITCH(...s);
1239
+ return a instanceof Error ? t(a) : a;
1065
1240
  },
1066
- SUBSTITUTE: (i, l, a, s) => {
1067
- const c = [te(M(i)), te(M(l)), te(M(a))];
1068
- s !== void 0 && c.push(M(s));
1069
- const d = Y(c);
1070
- d && r(d);
1071
- const y = e.SUBSTITUTE(...c);
1072
- return y instanceof Error ? r(y) : y;
1241
+ SUBSTITUTE: (o, s, c, a) => {
1242
+ const d = [le(W(o)), le(W(s)), le(W(c))];
1243
+ a !== void 0 && d.push(W(a));
1244
+ const u = te(d);
1245
+ u && t(u);
1246
+ const h = e.SUBSTITUTE(...d);
1247
+ return h instanceof Error ? t(h) : h;
1073
1248
  },
1074
- TEXTJOIN: (i, l, ...a) => {
1075
- const s = te(M(i)), c = M(l), d = a.flatMap(Ce).map(te), y = Y([s, c]);
1076
- y && r(y);
1077
- const p = e.TEXTJOIN(s, c, d);
1078
- return p instanceof Error ? r(p) : p;
1249
+ TEXTJOIN: (o, s, ...c) => {
1250
+ const a = le(W(o)), d = W(s), u = c.flatMap(Ne).map(le), h = te([a, d]);
1251
+ h && t(h);
1252
+ const p = e.TEXTJOIN(a, d, u);
1253
+ return p instanceof Error ? t(p) : p;
1079
1254
  },
1080
- UPPER: u(e.UPPER),
1255
+ UPPER: l(e.UPPER),
1081
1256
  // See DATE_FUNCTIONS_WITH_BROKEN_NATIVE_IMPL above for why these override
1082
1257
  // fast-formula-parser's own (real, but broken-for-Date-cells) versions.
1083
- YEAR: u(e.YEAR),
1084
- MONTH: u(e.MONTH),
1085
- DAY: u(e.DAY),
1086
- WEEKDAY: (i, l) => {
1087
- const a = M(i), s = M(l), c = Y([a]);
1088
- c && r(c);
1089
- const d = e.WEEKDAY(a, s);
1090
- return d instanceof Error ? r(d) : d;
1258
+ YEAR: l(e.YEAR),
1259
+ MONTH: l(e.MONTH),
1260
+ DAY: l(e.DAY),
1261
+ WEEKDAY: (o, s) => {
1262
+ const c = W(o), a = W(s), d = te([c]);
1263
+ d && t(d);
1264
+ const u = e.WEEKDAY(c, a);
1265
+ return u instanceof Error ? t(u) : u;
1091
1266
  },
1092
1267
  // See TEXT_FUNCTIONS_BROKEN_FOR_BLANK_CELLS above: these override fast-
1093
1268
  // formula-parser's own (real, but broken-for-a-bare-blank-cell) versions.
@@ -1098,54 +1273,54 @@ function Bt(e, t) {
1098
1273
  // Flattens every argument (a whole range included) and joins with no
1099
1274
  // separator, matching Excel's own range-argument behavior — the native
1100
1275
  // implementation instead inserts stray commas for a whole-range argument.
1101
- CONCATENATE: (...i) => {
1102
- const l = i.flatMap(Ce), a = Y(l);
1103
- a && r(a);
1104
- const s = e.CONCATENATE(...l.map(te));
1105
- return s instanceof Error ? r(s) : s;
1276
+ CONCATENATE: (...o) => {
1277
+ const s = o.flatMap(Ne), c = te(s);
1278
+ c && t(c);
1279
+ const a = e.CONCATENATE(...s.map(le));
1280
+ return a instanceof Error ? t(a) : a;
1106
1281
  },
1107
- CONCAT: (...i) => {
1108
- const l = i.flatMap(Ce), a = Y(l);
1109
- a && r(a);
1110
- const s = e.CONCAT(...l.map(te));
1111
- return s instanceof Error ? r(s) : s;
1282
+ CONCAT: (...o) => {
1283
+ const s = o.flatMap(Ne), c = te(s);
1284
+ c && t(c);
1285
+ const a = e.CONCAT(...s.map(le));
1286
+ return a instanceof Error ? t(a) : a;
1112
1287
  },
1113
- LEN: u(e.LEN, { toText: !0 }),
1114
- TRIM: u(e.TRIM, { toText: !0 }),
1115
- LOWER: u(e.LOWER, { toText: !0 }),
1116
- LEFT: (i, l) => {
1117
- const a = M(i), s = _e(l), c = Y([a]);
1118
- c && r(c);
1119
- const d = e.LEFT(te(a), s);
1120
- return d instanceof Error ? r(d) : d;
1288
+ LEN: l(e.LEN, { toText: !0 }),
1289
+ TRIM: l(e.TRIM, { toText: !0 }),
1290
+ LOWER: l(e.LOWER, { toText: !0 }),
1291
+ LEFT: (o, s) => {
1292
+ const c = W(o), a = Ge(s), d = te([c]);
1293
+ d && t(d);
1294
+ const u = e.LEFT(le(c), a);
1295
+ return u instanceof Error ? t(u) : u;
1121
1296
  },
1122
- RIGHT: (i, l) => {
1123
- const a = M(i), s = _e(l), c = Y([a]);
1124
- c && r(c);
1125
- const d = e.RIGHT(te(a), s);
1126
- return d instanceof Error ? r(d) : d;
1297
+ RIGHT: (o, s) => {
1298
+ const c = W(o), a = Ge(s), d = te([c]);
1299
+ d && t(d);
1300
+ const u = e.RIGHT(le(c), a);
1301
+ return u instanceof Error ? t(u) : u;
1127
1302
  },
1128
- MID: (i, l, a) => {
1129
- const s = M(i), c = M(l), d = M(a), y = Y([s, c, d]);
1130
- y && r(y);
1131
- const p = e.MID(te(s), c, d);
1132
- return p instanceof Error ? r(p) : p;
1303
+ MID: (o, s, c) => {
1304
+ const a = W(o), d = W(s), u = W(c), h = te([a, d, u]);
1305
+ h && t(h);
1306
+ const p = e.MID(le(a), d, u);
1307
+ return p instanceof Error ? t(p) : p;
1133
1308
  },
1134
- FIND: (i, l, a) => {
1135
- const s = M(i), c = M(l), d = _e(a), y = Y([s, c]);
1136
- y && r(y);
1137
- const p = e.FIND(te(s), te(c), d);
1138
- return p instanceof Error ? r(p) : p;
1309
+ FIND: (o, s, c) => {
1310
+ const a = W(o), d = W(s), u = Ge(c), h = te([a, d]);
1311
+ h && t(h);
1312
+ const p = e.FIND(le(a), le(d), u);
1313
+ return p instanceof Error ? t(p) : p;
1139
1314
  },
1140
- SEARCH: (i, l, a) => {
1141
- const s = M(i), c = M(l), d = _e(a), y = Y([s, c]);
1142
- y && r(y);
1143
- const p = e.SEARCH(te(s), te(c), d);
1144
- return p instanceof Error ? r(p) : p;
1315
+ SEARCH: (o, s, c) => {
1316
+ const a = W(o), d = W(s), u = Ge(c), h = te([a, d]);
1317
+ h && t(h);
1318
+ const p = e.SEARCH(le(a), le(d), u);
1319
+ return p instanceof Error ? t(p) : p;
1145
1320
  }
1146
1321
  };
1147
1322
  }
1148
- const jt = {
1323
+ const En = {
1149
1324
  "#REF!": "REF",
1150
1325
  "#VALUE!": "VALUE",
1151
1326
  "#DIV/0!": "DIV0",
@@ -1154,100 +1329,100 @@ const jt = {
1154
1329
  "#NUM!": "NUM",
1155
1330
  "#NULL!": "NULL"
1156
1331
  };
1157
- function rr(e) {
1158
- return jt[e.error] ?? "ERROR";
1159
- }
1160
- function tr(e, t) {
1161
- if (e instanceof ne) return e;
1162
- if (e instanceof t) {
1163
- const r = e.details;
1164
- return r instanceof ne ? r : r instanceof t ? new ne(rr(r), r.message) : new ne(rr(e), e.message);
1332
+ function mt(e) {
1333
+ return En[e.error] ?? "ERROR";
1334
+ }
1335
+ function gt(e, r) {
1336
+ if (e instanceof ce) return e;
1337
+ if (e instanceof r) {
1338
+ const t = e.details;
1339
+ return t instanceof ce ? t : t instanceof r ? new ce(mt(t), t.message) : new ce(mt(e), e.message);
1165
1340
  }
1166
- return new ne("ERROR", e instanceof Error ? e.message : void 0);
1341
+ return new ce("ERROR", e instanceof Error ? e.message : void 0);
1167
1342
  }
1168
- function Kt(e) {
1169
- return Math.max(0, ...e.map((t) => (t == null ? void 0 : t.length) ?? 0));
1170
- }
1171
- function Gt(e) {
1172
- return (t) => {
1173
- const r = e[t.row - 1];
1174
- if (t.row < 1 || t.col < 1 || r == null || t.col - 1 >= r.length)
1175
- throw new ne("REF");
1176
- const o = r[t.col - 1];
1177
- return o == null || o === "" ? null : o;
1343
+ function Tn(e) {
1344
+ return Math.max(0, ...e.map((r) => (r == null ? void 0 : r.length) ?? 0));
1345
+ }
1346
+ function An(e) {
1347
+ return (r) => {
1348
+ const t = e[r.row - 1];
1349
+ if (r.row < 1 || r.col < 1 || t == null || r.col - 1 >= t.length)
1350
+ throw new ce("REF");
1351
+ const n = t[r.col - 1];
1352
+ return n == null || n === "" ? null : n;
1178
1353
  };
1179
1354
  }
1180
- function Yt(e) {
1181
- return (t) => {
1182
- const r = Math.min(t.from.row, t.to.row), o = Math.min(t.from.col, t.to.col), u = Math.max(t.from.row, t.to.row), i = Math.max(t.from.col, t.to.col), l = Kt(e);
1183
- if (r > e.length || o > l)
1184
- throw new ne("REF");
1185
- const a = Math.min(u, e.length), s = [];
1186
- for (let c = r; c <= a; c++) {
1187
- const d = e[c - 1], y = [];
1188
- if (d != null) {
1189
- const p = Math.min(i, d.length);
1190
- for (let m = o; m <= p; m++) {
1191
- const v = d[m - 1];
1192
- y.push(v == null || v === "" ? null : v);
1355
+ function xn(e) {
1356
+ return (r) => {
1357
+ const t = Math.min(r.from.row, r.to.row), n = Math.min(r.from.col, r.to.col), l = Math.max(r.from.row, r.to.row), o = Math.max(r.from.col, r.to.col), s = Tn(e);
1358
+ if (t > e.length || n > s)
1359
+ throw new ce("REF");
1360
+ const c = Math.min(l, e.length), a = [];
1361
+ for (let d = t; d <= c; d++) {
1362
+ const u = e[d - 1], h = [];
1363
+ if (u != null) {
1364
+ const p = Math.min(o, u.length);
1365
+ for (let g = n; g <= p; g++) {
1366
+ const b = u[g - 1];
1367
+ h.push(b == null || b === "" ? null : b);
1193
1368
  }
1194
1369
  }
1195
- s.push(y);
1370
+ a.push(h);
1196
1371
  }
1197
- return s;
1372
+ return a;
1198
1373
  };
1199
1374
  }
1200
- function Jt(e) {
1375
+ function Rn(e) {
1201
1376
  if (e == null || e === "") return null;
1202
1377
  if (typeof e == "number" || typeof e == "string" || typeof e == "boolean" || e instanceof Date)
1203
1378
  return e;
1204
- throw new ne("VALUE");
1205
- }
1206
- async function br(e, t) {
1207
- if (typeof e != "string") throw new ne("ERROR");
1208
- const r = e.trim();
1209
- if (r === "") throw new ne("ERROR");
1210
- const o = r.startsWith("=") ? r.slice(1) : r;
1211
- Ht(o);
1212
- const [u, i] = await Promise.all([
1379
+ throw new ce("VALUE");
1380
+ }
1381
+ async function Vt(e, r) {
1382
+ if (typeof e != "string") throw new ce("ERROR");
1383
+ const t = e.trim();
1384
+ if (t === "") throw new ce("ERROR");
1385
+ const n = t.startsWith("=") ? t.slice(1) : t;
1386
+ yn(n);
1387
+ const [l, o] = await Promise.all([
1213
1388
  import("fast-formula-parser"),
1214
1389
  import("@formulajs/formulajs")
1215
- ]), l = u.default ?? u, a = l.FormulaError, s = new l({
1216
- ...t,
1390
+ ]), s = l.default ?? l, c = s.FormulaError, a = new s({
1391
+ ...r,
1217
1392
  // eslint-disable-next-line @typescript-eslint/no-explicit-any -- formulajs's own types are all `any`-typed; formulaFunctions.ts narrows the surface it actually calls.
1218
- functions: Bt(i, a)
1393
+ functions: wn(o, c)
1219
1394
  });
1220
- let c;
1395
+ let d;
1221
1396
  try {
1222
- c = s.parse(o, { row: 1, col: 1, sheet: "Sheet1" });
1223
- } catch (d) {
1224
- throw tr(d, a);
1397
+ d = a.parse(n, { row: 1, col: 1, sheet: "Sheet1" });
1398
+ } catch (u) {
1399
+ throw gt(u, c);
1225
1400
  }
1226
- if (c instanceof a)
1227
- throw tr(c, a);
1228
- return Jt(c);
1229
- }
1230
- async function qt(e, t) {
1231
- return br(t, { onCell: Gt(e), onRange: Yt(e) });
1232
- }
1233
- const nr = -1;
1234
- async function wr(e, t) {
1235
- const r = Object.keys(e);
1236
- return br(t, {
1237
- onVariable: (o) => {
1238
- const u = r.indexOf(o);
1239
- return u === -1 ? null : { row: nr, col: u + 1 };
1401
+ if (d instanceof c)
1402
+ throw gt(d, c);
1403
+ return Rn(d);
1404
+ }
1405
+ async function Cn(e, r) {
1406
+ return Vt(r, { onCell: An(e), onRange: xn(e) });
1407
+ }
1408
+ const yt = -1;
1409
+ async function jt(e, r) {
1410
+ const t = Object.keys(e);
1411
+ return Vt(r, {
1412
+ onVariable: (n) => {
1413
+ const l = t.indexOf(n);
1414
+ return l === -1 ? null : { row: yt, col: l + 1 };
1240
1415
  },
1241
- onCell: (o) => {
1242
- if (o.row === nr) return e[r[o.col - 1]] ?? null;
1243
- throw new ne("REF");
1416
+ onCell: (n) => {
1417
+ if (n.row === yt) return e[t[n.col - 1]] ?? null;
1418
+ throw new ce("REF");
1244
1419
  },
1245
1420
  onRange: () => {
1246
- throw new ne("REF");
1421
+ throw new ce("REF");
1247
1422
  }
1248
1423
  });
1249
1424
  }
1250
- const Er = {
1425
+ const Ht = {
1251
1426
  REF: "#REF!",
1252
1427
  VALUE: "#VALUE!",
1253
1428
  DIV0: "#DIV/0!",
@@ -1257,392 +1432,487 @@ const Er = {
1257
1432
  NUM: "#NUM!",
1258
1433
  NULL: "#NULL!"
1259
1434
  };
1260
- function qe(e) {
1261
- const t = e instanceof ne ? e.code : "ERROR";
1262
- return Er[t];
1263
- }
1264
- async function Zt(e, t) {
1265
- return e.length === 0 ? t.map((r) => ({
1266
- id: typeof (r == null ? void 0 : r.id) == "string" ? r.id : "(unknown)",
1267
- label: (r == null ? void 0 : r.label) ?? "(unknown)",
1435
+ function st(e) {
1436
+ const r = e instanceof ce ? e.code : "ERROR";
1437
+ return Ht[r];
1438
+ }
1439
+ async function Sn(e, r) {
1440
+ return e.length === 0 ? r.map((t) => ({
1441
+ id: typeof (t == null ? void 0 : t.id) == "string" ? t.id : "(unknown)",
1442
+ label: (t == null ? void 0 : t.label) ?? "(unknown)",
1268
1443
  value: null,
1269
- error: Er.ERROR
1444
+ error: Ht.ERROR
1270
1445
  })) : Promise.all(
1271
- t.map(async (r) => {
1446
+ r.map(async (t) => {
1272
1447
  try {
1273
- if (!r || typeof r.label != "string" || typeof r.expression != "string" || typeof r.id != "string")
1274
- throw new ne("ERROR");
1275
- return { id: r.id, label: r.label, value: await qt(e, r.expression) };
1276
- } catch (o) {
1448
+ if (!t || typeof t.label != "string" || typeof t.expression != "string" || typeof t.id != "string")
1449
+ throw new ce("ERROR");
1450
+ return { id: t.id, label: t.label, value: await Cn(e, t.expression) };
1451
+ } catch (n) {
1277
1452
  return {
1278
- id: typeof (r == null ? void 0 : r.id) == "string" ? r.id : "(unknown)",
1279
- label: (r == null ? void 0 : r.label) ?? "(unknown)",
1453
+ id: typeof (t == null ? void 0 : t.id) == "string" ? t.id : "(unknown)",
1454
+ label: (t == null ? void 0 : t.label) ?? "(unknown)",
1280
1455
  value: null,
1281
- error: qe(o)
1456
+ error: st(n)
1282
1457
  };
1283
1458
  }
1284
1459
  })
1285
1460
  );
1286
1461
  }
1287
- function Qt(e, t = {}) {
1288
- if (t.columnHeader && t.rowHeader)
1289
- throw new Error(
1290
- "x-spreadsheet: columnHeader and rowHeader cannot both be true — pick one orientation for the persisted sheet shape."
1291
- );
1292
- return t.columnHeader ? en(e) : t.rowHeader ? rn(e) : e;
1462
+ function bt(e) {
1463
+ const r = /* @__PURE__ */ new Set();
1464
+ for (const { id: t } of e) {
1465
+ if (r.has(t)) return t;
1466
+ r.add(t);
1467
+ }
1468
+ return null;
1293
1469
  }
1294
- function Rr(e) {
1295
- return e == null || e === "" ? null : e instanceof Date ? e.toISOString() : String(e);
1470
+ function Wt(e) {
1471
+ const { columnHeader: r, rowHeader: t, columns: n, rows: l } = e;
1472
+ if (n !== void 0 && !Array.isArray(n))
1473
+ return "columns must be an array of { id, label } objects.";
1474
+ if (l !== void 0 && !Array.isArray(l))
1475
+ return "rows must be an array of { id, label } objects.";
1476
+ if (n !== void 0 && n.length === 0)
1477
+ return "columns is declared but empty — declare at least one field, or omit it entirely for raw matrix mode.";
1478
+ if (l !== void 0 && l.length === 0)
1479
+ return "rows is declared but empty — declare at least one field, or omit it entirely for raw matrix mode.";
1480
+ const o = (u) => !!u && typeof u.id == "string" && u.id !== "" && typeof u.label == "string" && u.label !== "", s = n == null ? void 0 : n.findIndex((u) => !o(u));
1481
+ if (s != null && s !== -1)
1482
+ return `columns[${s}] must be a { id, label } object with non-empty string fields.`;
1483
+ const c = l == null ? void 0 : l.findIndex((u) => !o(u));
1484
+ if (c != null && c !== -1)
1485
+ return `rows[${c}] must be a { id, label } object with non-empty string fields.`;
1486
+ const a = !!n && n.length > 0, d = !!l && l.length > 0;
1487
+ if (a) {
1488
+ const u = bt(n);
1489
+ if (u) return `duplicate column id "${u}" — every declared column id must be unique.`;
1490
+ }
1491
+ if (d) {
1492
+ const u = bt(l);
1493
+ if (u) return `duplicate row id "${u}" — every declared row id must be unique.`;
1494
+ }
1495
+ return r && t ? "columnHeader and rowHeader cannot both be true — pick one orientation for the persisted sheet shape." : a && d ? "columns and rows cannot both be declared — pick one orientation for the persisted sheet shape." : r && !a ? "columnHeader is true but columns is missing or empty — declare the column list columnHeader positions map to." : t && !d ? "rowHeader is true but rows is missing or empty — declare the row list rowHeader positions map to." : null;
1296
1496
  }
1297
- function Tr(e, t) {
1298
- const r = /* @__PURE__ */ new Set();
1299
- for (const o of e)
1300
- if (o != null) {
1301
- if (r.has(o))
1302
- throw new Error(
1303
- `x-spreadsheet: duplicate ${t} value "${o}" — every ${t === "columnHeader" ? "column header" : "column-A value"} must be unique to shape as records.`
1304
- );
1305
- r.add(o);
1306
- }
1497
+ function vt(e, r = {}) {
1498
+ const t = Wt(r);
1499
+ if (t) throw new Error(`x-spreadsheet: ${t}`);
1500
+ const { columnHeader: n, rowHeader: l, columns: o, rows: s } = r;
1501
+ return o && o.length > 0 ? On(e, o, n === !0) : s && s.length > 0 ? Nn(e, s, l === !0) : e;
1307
1502
  }
1308
- function en(e) {
1309
- const [t, ...r] = e;
1310
- if (!t) return [];
1311
- const o = t.map(Rr);
1312
- return Tr(o, "columnHeader"), r.map((u) => {
1313
- const i = /* @__PURE__ */ Object.create(null);
1314
- return o.forEach((l, a) => {
1315
- l != null && (i[l] = u[a] ?? null);
1316
- }), i;
1503
+ function On(e, r, t) {
1504
+ return (t ? e.slice(1) : e).map((l) => {
1505
+ const o = /* @__PURE__ */ Object.create(null);
1506
+ return r.forEach((s, c) => {
1507
+ o[s.id] = l[c] ?? null;
1508
+ }), o;
1317
1509
  });
1318
1510
  }
1319
- function rn(e) {
1320
- const t = e.map((u) => Rr(u[0]));
1321
- Tr(t, "rowHeader");
1322
- const r = Math.max(0, ...e.map((u) => u.length)), o = Math.max(0, r - 1);
1323
- return Array.from({ length: o }, (u, i) => {
1324
- const l = i + 1, a = /* @__PURE__ */ Object.create(null);
1325
- return t.forEach((s, c) => {
1326
- s != null && (a[s] = e[c][l] ?? null);
1327
- }), a;
1511
+ function Nn(e, r, t) {
1512
+ const n = t ? 1 : 0, l = Math.max(0, ...e.map((s) => s.length)), o = Math.max(0, l - n);
1513
+ return Array.from({ length: o }, (s, c) => {
1514
+ const a = n + c, d = /* @__PURE__ */ Object.create(null);
1515
+ return r.forEach((u, h) => {
1516
+ var p;
1517
+ d[u.id] = ((p = e[h]) == null ? void 0 : p[a]) ?? null;
1518
+ }), d;
1328
1519
  });
1329
1520
  }
1330
- function tn(e) {
1521
+ function Bt(e) {
1331
1522
  return !Array.isArray(e[0]);
1332
1523
  }
1333
- function nn(e) {
1334
- const t = /* @__PURE__ */ Object.create(null);
1335
- for (const { id: r, label: o, value: u, error: i } of e)
1336
- t[r] = i === void 0 ? { label: o, value: u } : { label: o, value: u, error: i };
1337
- return t;
1524
+ function kn(e) {
1525
+ const r = /* @__PURE__ */ Object.create(null);
1526
+ for (const { id: t, label: n, value: l, error: o } of e)
1527
+ r[t] = o === void 0 ? { label: n, value: l } : { label: n, value: l, error: o };
1528
+ return r;
1338
1529
  }
1339
- function Ge(e, t) {
1340
- const r = (o) => o instanceof Date ? o.toISOString() : o ?? null;
1341
- return r(e) === r(t);
1530
+ function tt(e, r) {
1531
+ const t = (n) => n instanceof Date ? n.toISOString() : n ?? null;
1532
+ return t(e) === t(r);
1342
1533
  }
1343
- function on(e, t) {
1344
- const r = e ?? {}, o = t ?? {}, u = Object.keys(r);
1345
- return u.length !== Object.keys(o).length ? !1 : u.every((i) => {
1346
- if (!Object.prototype.hasOwnProperty.call(o, i)) return !1;
1347
- const l = r[i], a = o[i];
1348
- return l.label === a.label && l.error === a.error && Ge(l.value, a.value);
1534
+ function In(e, r) {
1535
+ const t = e ?? {}, n = r ?? {}, l = Object.keys(t);
1536
+ return l.length !== Object.keys(n).length ? !1 : l.every((o) => {
1537
+ if (!Object.prototype.hasOwnProperty.call(n, o)) return !1;
1538
+ const s = t[o], c = n[o];
1539
+ return s.label === c.label && s.error === c.error && tt(s.value, c.value);
1349
1540
  });
1350
1541
  }
1351
- function ln(e, t) {
1352
- if (e == null || t == null) return e === t;
1353
- const r = Array.isArray(e);
1354
- if (r !== Array.isArray(t)) return !1;
1355
- if (r) {
1356
- const l = e, a = t;
1357
- return l.length === a.length && l.every((s, c) => Ge(s, a[c]));
1542
+ function Dn(e, r) {
1543
+ if (e == null || r == null) return e === r;
1544
+ const t = Array.isArray(e);
1545
+ if (t !== Array.isArray(r)) return !1;
1546
+ if (t) {
1547
+ const s = e, c = r;
1548
+ return s.length === c.length && s.every((a, d) => tt(a, c[d]));
1358
1549
  }
1359
- const o = e, u = t, i = Object.keys(o);
1360
- return i.length !== Object.keys(u).length ? !1 : i.every((l) => Object.prototype.hasOwnProperty.call(u, l) && Ge(o[l], u[l]));
1550
+ const n = e, l = r, o = Object.keys(n);
1551
+ return o.length !== Object.keys(l).length ? !1 : o.every((s) => Object.prototype.hasOwnProperty.call(l, s) && tt(n[s], l[s]));
1361
1552
  }
1362
- function sn(e, t) {
1363
- if (e === t) return !0;
1364
- if (e == null || t == null) return !1;
1365
- const r = e, o = t;
1366
- return r.length !== o.length ? !1 : r.every((u, i) => ln(u, o[i]));
1553
+ function Ln(e, r) {
1554
+ if (e === r) return !0;
1555
+ if (e == null || r == null) return !1;
1556
+ const t = e, n = r;
1557
+ return t.length !== n.length ? !1 : t.every((l, o) => Dn(l, n[o]));
1367
1558
  }
1368
- function cn(e) {
1559
+ function Mn(e) {
1369
1560
  return e === null || typeof e == "string" || typeof e == "number" || typeof e == "boolean" || e instanceof Date;
1370
1561
  }
1371
- function an(e) {
1562
+ function Xt(e, r) {
1372
1563
  if (e.length === 0) return [];
1373
- const t = [], r = /* @__PURE__ */ new Set();
1374
- for (const u of e)
1375
- for (const i of Object.keys(u))
1376
- r.has(i) || (r.add(i), t.push(i));
1564
+ const t = [], n = /* @__PURE__ */ new Set();
1565
+ for (const o of r ?? [])
1566
+ n.has(o) || (n.add(o), t.push(o));
1567
+ for (const o of e)
1568
+ for (const s of Object.keys(o))
1569
+ n.has(s) || (n.add(s), t.push(s));
1377
1570
  if (t.length === 0) return [];
1378
- const o = e.map(
1379
- (u) => t.map((i) => {
1380
- if (!Object.prototype.hasOwnProperty.call(u, i)) return null;
1381
- const l = u[i];
1382
- return cn(l) ? l : null;
1571
+ const l = e.map(
1572
+ (o) => t.map((s) => {
1573
+ if (!Object.prototype.hasOwnProperty.call(o, s)) return null;
1574
+ const c = o[s];
1575
+ return Mn(c) ? c : null;
1383
1576
  })
1384
1577
  );
1385
- return [t, ...o];
1578
+ return [t, ...l];
1386
1579
  }
1387
- function un(e) {
1388
- const t = Math.max(0, ...e.map((r) => r.length));
1389
- return Array.from({ length: t }, (r, o) => e.map((u) => u[o] ?? null));
1580
+ function zn(e) {
1581
+ const r = Math.max(0, ...e.map((t) => t.length));
1582
+ return Array.from({ length: r }, (t, n) => e.map((l) => l[n] ?? null));
1390
1583
  }
1391
- const dn = ".xlsx,.xls,.csv,application/vnd.openxmlformats-officedocument.spreadsheetml.sheet,application/vnd.ms-excel,text/csv", fn = 10 * 1024 * 1024, Xe = 200, hn = 50, pn = [];
1392
- function Ve(e) {
1584
+ const Fn = ".xlsx,.xls,.csv,application/vnd.openxmlformats-officedocument.spreadsheetml.sheet,application/vnd.ms-excel,text/csv", Un = 10 * 1024 * 1024, Qe = 200, Pn = 50, $n = [];
1585
+ function wt(e) {
1393
1586
  return e == null || e === "" ? "" : e instanceof Date ? e.toLocaleDateString() : String(e);
1394
1587
  }
1395
- const mn = ({
1588
+ const _n = ({
1396
1589
  data: e,
1397
- handleChange: t,
1398
- path: r,
1399
- label: o,
1400
- required: u,
1401
- schema: i,
1402
- enabled: l,
1403
- readonly: a,
1404
- errors: s,
1405
- visible: c = !0
1590
+ handleChange: r,
1591
+ path: t,
1592
+ label: n,
1593
+ required: l,
1594
+ schema: o,
1595
+ enabled: s,
1596
+ readonly: c,
1597
+ errors: a,
1598
+ visible: d = !0
1406
1599
  }) => {
1407
- be(c, r, t, null);
1408
- const d = !s || s.length === 0, y = yr(l, a), p = (i == null ? void 0 : i["x-spreadsheet"]) ?? {}, m = (i == null ? void 0 : i["x-evaluate"]) ?? pn, v = p.accept ?? dn, I = p.maxSize ?? fn, A = p.columnHeader === !0, b = p.rowHeader === !0, k = p.showSheet !== !1, F = p.sheetName, z = p.persistSheet !== !1, w = e ?? null, [_, V] = $(
1409
- () => w != null && w.sheet || Object.keys((w == null ? void 0 : w.derivations) ?? {}).length > 0 ? "ready" : "empty"
1410
- ), [O, C] = $(null), [H, B] = $(!1), [W, j] = $(null), [ee, re] = $(null), le = pe(null), oe = pe(null), se = (w == null ? void 0 : w.sheet) ?? null, de = ke(
1411
- (E) => {
1412
- if (!tn(E)) return E;
1413
- const L = an(E);
1414
- return b ? un(L) : L;
1600
+ Ee(d, t, r);
1601
+ const u = !a || a.length === 0, h = $t(s, c), p = (o == null ? void 0 : o["x-spreadsheet"]) ?? {}, g = (o == null ? void 0 : o["x-evaluate"]) ?? $n, b = p.accept ?? Fn, I = p.maxSize ?? Un, O = p.columnHeader === !0, T = p.rowHeader === !0, A = p.columns, k = p.rows, M = Array.isArray(A) && A.length > 0, L = Array.isArray(k) && k.length > 0, N = Wt({ columnHeader: O, rowHeader: T, columns: A, rows: k }), U = p.showSheet !== !1, z = p.sheetName, v = p.persistSheet !== !1, E = e ?? null, [B, K] = j(
1602
+ () => E != null && E.sheet || Object.keys((E == null ? void 0 : E.derivations) ?? {}).length > 0 ? "ready" : "empty"
1603
+ ), [J, F] = j(null), [R, Y] = j(!1), [Q, be] = j(null), [oe, Se] = j(null), m = ae(null), C = ae(null), G = (E == null ? void 0 : E.sheet) ?? null, P = Fe(
1604
+ (x) => {
1605
+ if (!Bt(x)) return x;
1606
+ const V = L ? k : M ? A : void 0, se = Xt(
1607
+ x,
1608
+ V == null ? void 0 : V.map((X) => X.id)
1609
+ );
1610
+ return L ? zn(se) : se;
1415
1611
  },
1416
- [b]
1417
- ), G = Be(() => W ?? (se ? de(se) : null), [W, se, de]), f = ((ee == null ? void 0 : ee.matrix) === G ? ee.derivations : null) ?? (w == null ? void 0 : w.derivations) ?? {}, T = G != null || w != null, K = Be(() => {
1418
- const E = A ? 1 : 0, L = b ? 1 : 0, ue = G ? G.slice(E) : [], X = ue.slice(0, Xe), P = Math.min(
1419
- hn,
1420
- Math.max(0, ...X.map((Q) => Math.max(0, Q.length - L)))
1421
- ), Ee = Array.from({ length: P }, (Q, ae) => ae + L), R = "", ce = b && !A;
1422
- return /* @__PURE__ */ n(he, { children: G && k && /* @__PURE__ */ g(x, { mt: "3", children: [
1423
- /* @__PURE__ */ n(x, { style: { overflow: "auto", maxHeight: 420 }, children: /* @__PURE__ */ g(Re.Root, { variant: "surface", size: "1", children: [
1424
- !ce && /* @__PURE__ */ n(Re.Header, { children: /* @__PURE__ */ g(Re.Row, { children: [
1425
- /* @__PURE__ */ n(Re.ColumnHeaderCell, { children: R }),
1426
- Ee.map((Q) => {
1427
- var ae;
1612
+ [M, L, A, k]
1613
+ ), _ = _e(() => Q ?? (G ? P(G) : null), [Q, G, P]), re = ((oe == null ? void 0 : oe.matrix) === _ ? oe.derivations : null) ?? (E == null ? void 0 : E.derivations) ?? {}, q = _ != null || E != null, ie = _e(() => {
1614
+ const x = M ? 1 : 0, V = L ? 1 : 0, se = _ ? _.slice(x) : [], X = se.slice(0, Qe), H = Math.min(
1615
+ Pn,
1616
+ Math.max(0, ...X.map((pe) => Math.max(0, pe.length - V)))
1617
+ ), Re = Array.from({ length: H }, (pe, w) => w + V), Le = "", Xe = L && !M;
1618
+ return /* @__PURE__ */ i(ge, { children: _ && U && /* @__PURE__ */ y(S, { mt: "3", children: [
1619
+ /* @__PURE__ */ i(S, { style: { overflow: "auto", maxHeight: 420 }, children: /* @__PURE__ */ y(Te.Root, { variant: "surface", size: "1", children: [
1620
+ !Xe && /* @__PURE__ */ i(Te.Header, { children: /* @__PURE__ */ y(Te.Row, { children: [
1621
+ /* @__PURE__ */ i(Te.ColumnHeaderCell, { children: Le }),
1622
+ Re.map((pe) => {
1623
+ var w;
1428
1624
  return (
1429
- // This row only renders when rowHeader isn't the sole
1625
+ // This row only renders when hasRows isn't the sole
1430
1626
  // flag set (see suppressColumnHeaderRow) — so reaching
1431
- // here, either columnHeader is true (real labels) or
1432
- // both are false (columnLetter fallback).
1433
- /* @__PURE__ */ n(Re.ColumnHeaderCell, { children: A ? Ve((ae = G[0]) == null ? void 0 : ae[Q]) : zt(Q) }, Q)
1627
+ // here, either hasColumns is true (declared labels,
1628
+ // looked up positionally — never read from the matrix
1629
+ // cell itself, which only ever holds the id) or both
1630
+ // are false (columnLetter fallback).
1631
+ /* @__PURE__ */ i(Te.ColumnHeaderCell, { children: M ? ((w = A == null ? void 0 : A[pe]) == null ? void 0 : w.label) ?? "" : an(pe) }, pe)
1434
1632
  );
1435
1633
  })
1436
1634
  ] }) }),
1437
- /* @__PURE__ */ n(Re.Body, { children: X.map((Q, ae) => {
1438
- var Ie;
1439
- const Ae = E + ae;
1440
- return /* @__PURE__ */ g(Re.Row, { children: [
1441
- /* @__PURE__ */ n(
1442
- Re.RowHeaderCell,
1635
+ /* @__PURE__ */ i(Te.Body, { children: X.map((pe, w) => {
1636
+ var ne;
1637
+ const Z = x + w;
1638
+ return /* @__PURE__ */ y(Te.Row, { children: [
1639
+ /* @__PURE__ */ i(
1640
+ Te.RowHeaderCell,
1443
1641
  {
1444
- style: b ? { fontWeight: 700, background: "var(--gray-a3)" } : void 0,
1445
- children: b ? Ve((Ie = G[Ae]) == null ? void 0 : Ie[0]) : A ? "" : Ae + 1
1642
+ style: L ? { fontWeight: 700, background: "var(--gray-a3)" } : void 0,
1643
+ children: L ? ((ne = k == null ? void 0 : k[Z]) == null ? void 0 : ne.label) ?? "" : M ? "" : Z + 1
1446
1644
  }
1447
1645
  ),
1448
- Ee.map((Ue) => /* @__PURE__ */ n(Re.Cell, { children: Ve(Q[Ue]) }, Ue))
1449
- ] }, ae);
1646
+ Re.map((he) => /* @__PURE__ */ i(Te.Cell, { children: wt(pe[he]) }, he))
1647
+ ] }, w);
1450
1648
  }) })
1451
1649
  ] }) }),
1452
- ue.length > Xe && /* @__PURE__ */ g(h, { size: "1", color: "gray", mt: "1", style: { display: "block" }, children: [
1650
+ se.length > Qe && /* @__PURE__ */ y(f, { size: "1", color: "gray", mt: "1", style: { display: "block" }, children: [
1453
1651
  "Showing first ",
1454
- Xe,
1652
+ Qe,
1455
1653
  " of ",
1456
- ue.length,
1654
+ se.length,
1457
1655
  " rows"
1458
1656
  ] })
1459
1657
  ] }) });
1460
- }, [G, k, A, b]), N = ke(
1461
- async (E) => {
1462
- if (C(null), E.size > I) {
1463
- C(`File exceeds the ${ye(I)} limit.`);
1658
+ }, [_, U, M, L, A, k]), $ = Fe(
1659
+ async (x) => {
1660
+ if (F(null), x.size > I) {
1661
+ F(`File exceeds the ${ve(I)} limit.`);
1464
1662
  return;
1465
1663
  }
1466
- if (!v.split(",").map((P) => P.trim()).some((P) => P === "*" || P === "*/*" ? !0 : P.endsWith("/*") ? E.type.startsWith(P.slice(0, -1)) : P.startsWith(".") ? E.name.toLowerCase().endsWith(P.toLowerCase()) : E.type === P)) {
1467
- C(`Invalid type. Accepted: ${ve(v)}`);
1664
+ if (!b.split(",").map((H) => H.trim()).some((H) => H === "*" || H === "*/*" ? !0 : H.endsWith("/*") ? x.type.startsWith(H.slice(0, -1)) : H.startsWith(".") ? x.name.toLowerCase().endsWith(H.toLowerCase()) : x.type === H)) {
1665
+ F(`Invalid type. Accepted: ${we(b)}`);
1468
1666
  return;
1469
1667
  }
1470
- V("parsing");
1668
+ K("parsing");
1471
1669
  let X;
1472
1670
  try {
1473
- const P = await E.arrayBuffer();
1474
- X = Mt(P, F).matrix;
1475
- } catch (P) {
1476
- V("error"), C(
1477
- P instanceof Ke ? P.message : "This doesn't look like a valid spreadsheet. Please check the file and try again."
1671
+ const H = await x.arrayBuffer();
1672
+ X = (await cn(H, z)).matrix;
1673
+ } catch (H) {
1674
+ K("error"), F(
1675
+ H instanceof et ? H.message : "This doesn't look like a valid spreadsheet. Please check the file and try again."
1478
1676
  );
1479
1677
  return;
1480
1678
  }
1481
- oe.current = (e == null ? void 0 : e.sheet) ?? null, j(X), V("ready");
1679
+ if (M || L)
1680
+ try {
1681
+ X = P(vt(X, { columnHeader: O, rowHeader: T, columns: A, rows: k }));
1682
+ } catch (H) {
1683
+ K("error"), F(H instanceof Error ? H.message : "Failed to process this sheet.");
1684
+ return;
1685
+ }
1686
+ C.current = (e == null ? void 0 : e.sheet) ?? null, be(X), K("ready");
1482
1687
  },
1483
- [v, I, F, e]
1688
+ [b, I, z, e, O, T, A, k, M, L, P]
1484
1689
  );
1485
- if (ge(() => {
1486
- W != null && se != null && se !== oe.current && j(null);
1487
- }, [W, se]), ge(() => {
1488
- if (m.length === 0 && !z) return;
1489
- let E = !1;
1490
- const L = (X) => {
1491
- y && (on(w == null ? void 0 : w.derivations, X == null ? void 0 : X.derivations) && sn(w == null ? void 0 : w.sheet, X == null ? void 0 : X.sheet) || (oe.current = (X == null ? void 0 : X.sheet) ?? null, t(r, X)));
1492
- }, ue = G ?? [];
1493
- if (ue.length === 0) {
1494
- w != null && L(void 0);
1690
+ if (de(() => {
1691
+ Q != null && G != null && G !== C.current && be(null);
1692
+ }, [Q, G]), de(() => {
1693
+ if (N || g.length === 0 && !v) return;
1694
+ let x = !1;
1695
+ const V = (X) => {
1696
+ h && (In(E == null ? void 0 : E.derivations, X == null ? void 0 : X.derivations) && Ln(E == null ? void 0 : E.sheet, X == null ? void 0 : X.sheet) || (C.current = (X == null ? void 0 : X.sheet) ?? null, r(t, X)));
1697
+ }, se = _ ?? [];
1698
+ if (se.length === 0) {
1699
+ E != null && V(void 0);
1495
1700
  return;
1496
1701
  }
1497
- return Zt(ue, m).then((X) => {
1498
- if (E) return;
1499
- let P;
1500
- if (W != null) {
1501
- if (z)
1702
+ return Sn(se, g).then((X) => {
1703
+ if (x) return;
1704
+ let H;
1705
+ if (Q != null) {
1706
+ if (v)
1502
1707
  try {
1503
- P = Qt(ue, { columnHeader: A, rowHeader: b });
1504
- } catch (R) {
1505
- C(R instanceof Error ? R.message : "Failed to process this sheet.");
1708
+ H = vt(se, { columnHeader: M, rowHeader: L, columns: A, rows: k });
1709
+ } catch (Le) {
1710
+ F(Le instanceof Error ? Le.message : "Failed to process this sheet.");
1506
1711
  return;
1507
1712
  }
1508
1713
  } else
1509
- P = w == null ? void 0 : w.sheet;
1510
- C(null);
1511
- const Ee = nn(X);
1512
- re({ matrix: ue, derivations: Ee }), L(P === void 0 ? { derivations: Ee } : { sheet: P, derivations: Ee });
1714
+ H = E == null ? void 0 : E.sheet;
1715
+ F(null);
1716
+ const Re = kn(X);
1717
+ Se({ matrix: se, derivations: Re }), V(H === void 0 ? { derivations: Re } : { sheet: H, derivations: Re });
1513
1718
  }), () => {
1514
- E = !0;
1719
+ x = !0;
1515
1720
  };
1516
- }, [G, W, m, y, z, A, b]), c === !1)
1721
+ }, [_, Q, g, h, v, M, L, A, k, N]), d === !1)
1517
1722
  return null;
1518
- if (A && b)
1519
- return /* @__PURE__ */ g(x, { mb: "4", children: [
1520
- /* @__PURE__ */ n(h, { as: "label", size: "2", weight: "bold", children: o }),
1521
- /* @__PURE__ */ n(h, { size: "2", color: "red", style: { display: "block" }, children: "Invalid x-spreadsheet config: columnHeader and rowHeader cannot both be true — pick one orientation." })
1723
+ if (N)
1724
+ return /* @__PURE__ */ y(S, { mb: "4", children: [
1725
+ /* @__PURE__ */ i(f, { as: "label", size: "2", weight: "bold", children: n }),
1726
+ /* @__PURE__ */ y(f, { size: "2", color: "red", style: { display: "block" }, children: [
1727
+ "Invalid x-spreadsheet config: ",
1728
+ N
1729
+ ] })
1522
1730
  ] });
1523
- if (!y && !T) return null;
1524
- const U = (E) => {
1525
- E.preventDefault(), E.stopPropagation(), y && B(E.type === "dragenter" || E.type === "dragover");
1526
- }, Z = (E) => {
1527
- var L;
1528
- E.preventDefault(), E.stopPropagation(), B(!1), y && (L = E.dataTransfer.files) != null && L[0] && N(E.dataTransfer.files[0]);
1529
- }, ie = (E) => {
1530
- var L;
1531
- (L = E.target.files) != null && L[0] && (N(E.target.files[0]), E.target.value = "");
1532
- }, J = () => {
1533
- y && (j(null), re(null), oe.current = null, C(null), V("empty"), t(r, null));
1534
- }, D = k && G == null && w != null;
1535
- return /* @__PURE__ */ g(x, { mb: "4", children: [
1536
- /* @__PURE__ */ g(S, { align: "center", justify: "between", mb: "2", children: [
1537
- /* @__PURE__ */ g(S, { align: "center", gap: "1", children: [
1538
- /* @__PURE__ */ g(h, { as: "label", size: "2", weight: "bold", children: [
1539
- o,
1540
- u && /* @__PURE__ */ n(h, { color: "red", children: " *" })
1731
+ if (!h && !q) return null;
1732
+ const fe = (x) => {
1733
+ x.preventDefault(), x.stopPropagation(), h && Y(x.type === "dragenter" || x.type === "dragover");
1734
+ }, Oe = (x) => {
1735
+ var V;
1736
+ x.preventDefault(), x.stopPropagation(), Y(!1), h && (V = x.dataTransfer.files) != null && V[0] && $(x.dataTransfer.files[0]);
1737
+ }, Pe = (x) => {
1738
+ var V;
1739
+ (V = x.target.files) != null && V[0] && ($(x.target.files[0]), x.target.value = "");
1740
+ }, $e = () => {
1741
+ h && (be(null), Se(null), C.current = null, F(null), K("empty"), r(t, void 0));
1742
+ }, xe = U && _ == null && E != null;
1743
+ return /* @__PURE__ */ y(S, { mb: "4", children: [
1744
+ /* @__PURE__ */ y(D, { align: "center", justify: "between", mb: "2", children: [
1745
+ /* @__PURE__ */ y(D, { align: "center", gap: "1", children: [
1746
+ /* @__PURE__ */ y(f, { as: "label", size: "2", weight: "bold", children: [
1747
+ n,
1748
+ l && /* @__PURE__ */ i(f, { color: "red", children: " *" })
1541
1749
  ] }),
1542
- T && y && /* @__PURE__ */ g(he, { children: [
1543
- /* @__PURE__ */ n(He, { content: "Replace spreadsheet", children: /* @__PURE__ */ n(
1544
- Me,
1750
+ q && h && /* @__PURE__ */ y(ge, { children: [
1751
+ /* @__PURE__ */ i(qe, { content: "Replace spreadsheet", children: /* @__PURE__ */ i(
1752
+ je,
1545
1753
  {
1546
1754
  variant: "ghost",
1547
1755
  size: "1",
1548
1756
  onClick: () => {
1549
- var E;
1550
- return (E = le.current) == null ? void 0 : E.click();
1757
+ var x;
1758
+ return (x = m.current) == null ? void 0 : x.click();
1551
1759
  },
1552
1760
  "aria-label": "Replace spreadsheet",
1553
- children: /* @__PURE__ */ n(Ne, {})
1761
+ children: /* @__PURE__ */ i(ze, {})
1554
1762
  }
1555
1763
  ) }),
1556
- /* @__PURE__ */ n(He, { content: "Remove spreadsheet", children: /* @__PURE__ */ n(
1557
- Me,
1764
+ /* @__PURE__ */ i(qe, { content: "Remove spreadsheet", children: /* @__PURE__ */ i(
1765
+ je,
1558
1766
  {
1559
1767
  variant: "ghost",
1560
1768
  size: "1",
1561
1769
  color: "gray",
1562
- onClick: J,
1770
+ onClick: $e,
1563
1771
  "aria-label": "Remove spreadsheet",
1564
- children: /* @__PURE__ */ n(Ye, {})
1772
+ children: /* @__PURE__ */ i(rt, {})
1565
1773
  }
1566
1774
  ) })
1567
1775
  ] })
1568
1776
  ] }),
1569
- /* @__PURE__ */ g(h, { size: "1", color: "gray", children: [
1570
- ye(I),
1777
+ /* @__PURE__ */ y(f, { size: "1", color: "gray", children: [
1778
+ ve(I),
1571
1779
  " max · ",
1572
- ve(v)
1780
+ we(b)
1573
1781
  ] })
1574
1782
  ] }),
1575
- T && O && /* @__PURE__ */ n(h, { size: "2", color: "red", mb: "2", style: { display: "block" }, children: O }),
1576
- /* @__PURE__ */ n("input", { ref: le, type: "file", style: { display: "none" }, accept: v, onChange: ie }),
1577
- y && !T && /* @__PURE__ */ n(
1783
+ q && J && /* @__PURE__ */ i(f, { size: "2", color: "red", mb: "2", style: { display: "block" }, children: J }),
1784
+ /* @__PURE__ */ i("input", { ref: m, type: "file", style: { display: "none" }, accept: b, onChange: Pe }),
1785
+ h && !q && /* @__PURE__ */ i(
1578
1786
  "div",
1579
1787
  {
1580
1788
  role: "button",
1581
1789
  tabIndex: 0,
1582
1790
  onClick: () => {
1583
- var E;
1584
- return (E = le.current) == null ? void 0 : E.click();
1791
+ var x;
1792
+ return (x = m.current) == null ? void 0 : x.click();
1585
1793
  },
1586
- onKeyDown: (E) => {
1587
- var L;
1588
- (E.key === "Enter" || E.key === " ") && (E.preventDefault(), (L = le.current) == null || L.click());
1794
+ onKeyDown: (x) => {
1795
+ var V;
1796
+ (x.key === "Enter" || x.key === " ") && (x.preventDefault(), (V = m.current) == null || V.click());
1589
1797
  },
1590
- onDragEnter: U,
1591
- onDragLeave: U,
1592
- onDragOver: U,
1593
- onDrop: Z,
1798
+ onDragEnter: fe,
1799
+ onDragLeave: fe,
1800
+ onDragOver: fe,
1801
+ onDrop: Oe,
1594
1802
  style: { cursor: "pointer" },
1595
1803
  className: [
1596
1804
  "border-2 border-dashed rounded-lg p-6 text-center",
1597
1805
  "transition-all duration-200 ease-in-out",
1598
- H ? "border-blue-500 bg-blue-50" : O ? "border-red-300 bg-red-50" : "border-gray-300 hover:border-blue-400 hover:bg-gray-50"
1806
+ R ? "border-blue-500 bg-blue-50" : J ? "border-red-300 bg-red-50" : "border-gray-300 hover:border-blue-400 hover:bg-gray-50"
1599
1807
  ].join(" "),
1600
- children: /* @__PURE__ */ n(S, { direction: "column", align: "center", gap: "2", children: _ === "parsing" ? /* @__PURE__ */ g(he, { children: [
1601
- /* @__PURE__ */ n(xe, { size: "3" }),
1602
- /* @__PURE__ */ n(h, { size: "2", color: "gray", children: "Parsing spreadsheet…" })
1603
- ] }) : O ? /* @__PURE__ */ g(he, { children: [
1604
- /* @__PURE__ */ n(Je, { style: { width: 32, height: 32, color: "var(--red-9)" } }),
1605
- /* @__PURE__ */ n(h, { size: "2", color: "red", weight: "medium", children: O }),
1606
- /* @__PURE__ */ n(h, { size: "1", color: "gray", children: "Click to try again" })
1607
- ] }) : /* @__PURE__ */ g(he, { children: [
1608
- /* @__PURE__ */ n(Ne, { style: { width: 32, height: 32, color: "var(--gray-8)" } }),
1609
- /* @__PURE__ */ n(h, { size: "2", weight: "medium", children: "Click to upload or drag and drop" }),
1610
- /* @__PURE__ */ g(h, { size: "1", color: "gray", children: [
1611
- ye(I),
1808
+ children: /* @__PURE__ */ i(D, { direction: "column", align: "center", gap: "2", children: B === "parsing" ? /* @__PURE__ */ y(ge, { children: [
1809
+ /* @__PURE__ */ i(Ue, { size: "3" }),
1810
+ /* @__PURE__ */ i(f, { size: "2", color: "gray", children: "Parsing spreadsheet…" })
1811
+ ] }) : J ? /* @__PURE__ */ y(ge, { children: [
1812
+ /* @__PURE__ */ i(nt, { style: { width: 32, height: 32, color: "var(--red-9)" } }),
1813
+ /* @__PURE__ */ i(f, { size: "2", color: "red", weight: "medium", children: J }),
1814
+ /* @__PURE__ */ i(f, { size: "1", color: "gray", children: "Click to try again" })
1815
+ ] }) : /* @__PURE__ */ y(ge, { children: [
1816
+ /* @__PURE__ */ i(ze, { style: { width: 32, height: 32, color: "var(--gray-8)" } }),
1817
+ /* @__PURE__ */ i(f, { size: "2", weight: "medium", children: "Click to upload or drag and drop" }),
1818
+ /* @__PURE__ */ y(f, { size: "1", color: "gray", children: [
1819
+ ve(I),
1612
1820
  " max · ",
1613
- ve(v)
1821
+ we(b)
1614
1822
  ] })
1615
1823
  ] }) })
1616
1824
  }
1617
1825
  ),
1618
- K,
1619
- D && /* @__PURE__ */ n(h, { size: "2", color: "gray", mt: "3", style: { display: "block" }, children: "Sheet preview not stored for this field — re-upload to view contents." }),
1620
- Object.keys(f).length > 0 && /* @__PURE__ */ g(x, { mt: "3", children: [
1621
- /* @__PURE__ */ n(h, { size: "2", weight: "bold", as: "div", mb: "1", children: "Computed values" }),
1622
- /* @__PURE__ */ n(S, { direction: "column", gap: "1", children: Object.entries(f).map(([E, L]) => /* @__PURE__ */ g(S, { justify: "between", children: [
1623
- /* @__PURE__ */ n(h, { size: "2", children: L.label }),
1624
- L.error ? /* @__PURE__ */ n(h, { size: "2", color: "red", children: L.error }) : (
1826
+ ie,
1827
+ xe && /* @__PURE__ */ i(f, { size: "2", color: "gray", mt: "3", style: { display: "block" }, children: "Sheet preview not stored for this field — re-upload to view contents." }),
1828
+ Object.keys(re).length > 0 && /* @__PURE__ */ y(S, { mt: "3", children: [
1829
+ /* @__PURE__ */ i(f, { size: "2", weight: "bold", as: "div", mb: "1", children: "Computed values" }),
1830
+ /* @__PURE__ */ i(D, { direction: "column", gap: "1", children: Object.entries(re).map(([x, V]) => /* @__PURE__ */ y(D, { justify: "between", children: [
1831
+ /* @__PURE__ */ i(f, { size: "2", children: V.label }),
1832
+ V.error ? /* @__PURE__ */ i(f, { size: "2", color: "red", children: V.error }) : (
1625
1833
  // d.value is CellValue | null now (SUM/AVERAGE aren't the only
1626
1834
  // possible results anymore — INDEX/CONCATENATE can return a
1627
1835
  // string, a bare comparison can return a boolean, etc.), so
1628
1836
  // `.toLocaleString()` would throw for e.g. a boolean result.
1629
1837
  // Reuse the same formatCell used for the sheet-preview grid.
1630
- /* @__PURE__ */ n(h, { size: "2", children: Ve(L.value) })
1838
+ /* @__PURE__ */ i(f, { size: "2", children: wt(V.value) })
1631
1839
  )
1632
- ] }, E)) })
1840
+ ] }, x)) })
1633
1841
  ] }),
1634
- !d && /* @__PURE__ */ n(h, { color: "red", size: "1", mt: "2", style: { display: "block" }, children: we(s, o) })
1842
+ !u && /* @__PURE__ */ i(f, { color: "red", size: "1", mt: "2", style: { display: "block" }, children: ye(a, n) })
1635
1843
  ] });
1636
- }, gn = me(mn), yn = q(
1844
+ }, Vn = ue(_n), jn = ee(
1637
1845
  10,
1638
1846
  // matches FileControlTester's rank — beats the default object/Group renderer
1639
- ze(
1847
+ Ie(
1640
1848
  (e) => e.type === "object" && typeof e["x-spreadsheet"] == "object"
1641
1849
  )
1850
+ ), Hn = "Sheet1", Wn = "xlsx";
1851
+ function Bn(e) {
1852
+ if (e === void 0) return null;
1853
+ if (!Array.isArray(e)) return "columns must be an array of { id, label } objects.";
1854
+ if (e.length === 0)
1855
+ return "columns is declared but empty — declare at least one field, or omit it entirely.";
1856
+ const r = e.findIndex(
1857
+ (t) => !t || typeof t != "object" || typeof t.id != "string" || t.id === "" || typeof t.label != "string" || t.label === ""
1858
+ );
1859
+ return r !== -1 ? `columns[${r}] must be a { id, label } object with non-empty string fields.` : null;
1860
+ }
1861
+ function Xn(e, r) {
1862
+ if (!Bt(e)) return e;
1863
+ const t = Xt(
1864
+ e,
1865
+ r == null ? void 0 : r.map((s) => s.id)
1866
+ );
1867
+ if (!r || t.length === 0) return t;
1868
+ const n = new Map(r.map((s) => [s.id, s.label])), [l, ...o] = t;
1869
+ return [l.map((s) => n.get(String(s)) ?? s), ...o];
1870
+ }
1871
+ const Kn = ({ data: e, label: r, schema: t, visible: n = !0 }) => {
1872
+ const [l, o] = j(null);
1873
+ if (n === !1)
1874
+ return null;
1875
+ const s = (t == null ? void 0 : t["x-spreadsheet-export"]) ?? {}, c = s.columns, a = s.sheetName ?? Hn, d = s.fileType ?? Wn, u = s.fileName ?? `export.${d}`, h = Bn(c);
1876
+ if (h)
1877
+ return /* @__PURE__ */ y(S, { mb: "4", children: [
1878
+ /* @__PURE__ */ i(f, { as: "label", size: "2", weight: "bold", children: r }),
1879
+ /* @__PURE__ */ y(f, { size: "2", color: "red", style: { display: "block" }, children: [
1880
+ "Invalid x-spreadsheet-export config: ",
1881
+ h
1882
+ ] })
1883
+ ] });
1884
+ const p = Array.isArray(e) && e.length > 0, g = async () => {
1885
+ if (p) {
1886
+ o(null);
1887
+ try {
1888
+ const b = await import("@e965/xlsx"), I = Xn(e, c), O = b.utils.aoa_to_sheet(I), T = b.utils.book_new();
1889
+ b.utils.book_append_sheet(T, O, a), b.writeFile(T, u, { bookType: d });
1890
+ } catch (b) {
1891
+ o(b instanceof Error ? b.message : "Failed to build the workbook.");
1892
+ }
1893
+ }
1894
+ };
1895
+ return /* @__PURE__ */ y(S, { mb: "4", children: [
1896
+ /* @__PURE__ */ i(f, { as: "label", size: "2", weight: "bold", style: { display: "block", marginBottom: "var(--space-2)" }, children: r }),
1897
+ /* @__PURE__ */ y(De, { type: "button", variant: "soft", disabled: !p, onClick: () => void g(), children: [
1898
+ /* @__PURE__ */ i(Mt, {}),
1899
+ " Download Spreadsheet"
1900
+ ] }),
1901
+ l && /* @__PURE__ */ i(f, { size: "2", color: "red", style: { display: "block", marginTop: "var(--space-2)" }, children: l })
1902
+ ] });
1903
+ }, Yn = ue(Kn), Gn = ee(
1904
+ 10,
1905
+ Nt(
1906
+ Ie((e) => {
1907
+ const r = e["x-spreadsheet-export"];
1908
+ return e.type === "array" && typeof r == "object" && r !== null;
1909
+ }),
1910
+ sr(lr("editable", !0))
1911
+ )
1642
1912
  );
1643
- class Te extends Error {
1913
+ class Ce extends Error {
1644
1914
  }
1645
- const or = 5e6, vn = 1024, bn = /^<\?xml\s+[^>]*\bencoding\s*=\s*["']([^"']+)["']/i, wn = {
1915
+ const Et = 5e6, qn = 1024, Jn = /^<\?xml\s+[^>]*\bencoding\s*=\s*["']([^"']+)["']/i, Zn = {
1646
1916
  // Default is true, which would silently drop what in many formats is most of
1647
1917
  // the payload.
1648
1918
  ignoreAttributes: !1,
@@ -1689,478 +1959,658 @@ const or = 5e6, vn = 1024, bn = /^<\?xml\s+[^>]*\bencoding\s*=\s*["']([^"']+)["'
1689
1959
  maxNestedTags: 100,
1690
1960
  strictReservedNames: !0
1691
1961
  };
1692
- function En(e) {
1693
- const t = new Set(e);
1694
- return t.size === 0 ? () => !1 : (r, o) => (
1962
+ function Qn(e) {
1963
+ const r = new Set(e);
1964
+ return r.size === 0 ? () => !1 : (t, n) => (
1695
1965
  // A string while the library's own `jPath` option is true (the default) and
1696
1966
  // a matcher object otherwise; both stringify to the same dotted path.
1697
- t.has(typeof o == "string" ? o : o.toString()) || t.has(r)
1967
+ r.has(typeof n == "string" ? n : n.toString()) || r.has(t)
1698
1968
  );
1699
1969
  }
1700
- function Rn(e) {
1701
- const t = e instanceof Error ? e.message : "";
1702
- return t.startsWith("[SECURITY] Invalid name:") ? "This document uses a reserved JavaScript name (__proto__, constructor or prototype) as an element or attribute name, which cannot be represented safely." : t === "External entities are not supported" || t === "Parameter entities are not supported" ? `${t}. Please remove the DOCTYPE entity declarations and try again.` : t.startsWith("Maximum nested tags exceeded") ? "This document is nested too deeply to parse." : t.startsWith("Entity count") || t.includes("exceeds maximum allowed") ? "This document declares too many or too large entity definitions to expand safely." : "This doesn't look like a valid XML document. Please check the file and try again.";
1703
- }
1704
- async function Tn(e, t = {}) {
1705
- var c;
1706
- if (typeof e != "string") throw new Te("This file could not be read as text.");
1707
- const r = e.charCodeAt(0) === 65279 ? e.slice(1) : e;
1708
- if (r.trim() === "") throw new Te("This file is empty.");
1709
- if (r.length > or)
1710
- throw new Te(
1711
- `This document is too large to parse (over ${or / 1e6} million characters).`
1970
+ function eo(e) {
1971
+ const r = e instanceof Error ? e.message : "";
1972
+ return r.startsWith("[SECURITY] Invalid name:") ? "This document uses a reserved JavaScript name (__proto__, constructor or prototype) as an element or attribute name, which cannot be represented safely." : r === "External entities are not supported" || r === "Parameter entities are not supported" ? `${r}. Please remove the DOCTYPE entity declarations and try again.` : r.startsWith("Maximum nested tags exceeded") ? "This document is nested too deeply to parse." : r.startsWith("Entity count") || r.includes("exceeds maximum allowed") ? "This document declares too many or too large entity definitions to expand safely." : "This doesn't look like a valid XML document. Please check the file and try again.";
1973
+ }
1974
+ async function to(e, r = {}) {
1975
+ var d;
1976
+ if (typeof e != "string") throw new Ce("This file could not be read as text.");
1977
+ const t = e.charCodeAt(0) === 65279 ? e.slice(1) : e;
1978
+ if (t.trim() === "") throw new Ce("This file is empty.");
1979
+ if (t.length > Et)
1980
+ throw new Ce(
1981
+ `This document is too large to parse (over ${Et / 1e6} million characters).`
1712
1982
  );
1713
- const o = (c = bn.exec(r.slice(0, vn))) == null ? void 0 : c[1];
1714
- if (o && !/^utf-?8$/i.test(o))
1715
- throw new Te(
1716
- `This document declares the unsupported encoding "${o}". Only UTF-8 is supported.`
1983
+ const n = (d = Jn.exec(t.slice(0, qn))) == null ? void 0 : d[1];
1984
+ if (n && !/^utf-?8$/i.test(n))
1985
+ throw new Ce(
1986
+ `This document declares the unsupported encoding "${n}". Only UTF-8 is supported.`
1717
1987
  );
1718
- const { XMLParser: u, XMLValidator: i } = await import("fast-xml-parser"), l = i.validate(r, { allowBooleanAttributes: !1 });
1719
- if (l !== !0) {
1720
- const { msg: d, line: y, col: p } = l.err;
1721
- throw new Te(`Invalid XML at line ${y}, column ${p}: ${d}`);
1988
+ const { XMLParser: l, XMLValidator: o } = await import("fast-xml-parser"), s = o.validate(t, { allowBooleanAttributes: !1 });
1989
+ if (s !== !0) {
1990
+ const { msg: u, line: h, col: p } = s.err;
1991
+ throw new Ce(`Invalid XML at line ${h}, column ${p}: ${u}`);
1722
1992
  }
1723
- const a = new u({
1724
- ...wn,
1725
- removeNSPrefix: t.removeNamespaces === !0,
1726
- isArray: En(t.arrayPaths ?? [])
1993
+ const c = new l({
1994
+ ...Zn,
1995
+ removeNSPrefix: r.removeNamespaces === !0,
1996
+ isArray: Qn(r.arrayPaths ?? [])
1727
1997
  });
1728
- let s;
1998
+ let a;
1729
1999
  try {
1730
- s = a.parse(r);
1731
- } catch (d) {
1732
- throw new Te(Rn(d));
2000
+ a = c.parse(t);
2001
+ } catch (u) {
2002
+ throw new Ce(eo(u));
1733
2003
  }
1734
- if (s == null || typeof s != "object" || Array.isArray(s))
1735
- throw new Te("This document has no root element.");
1736
- return s;
2004
+ if (a == null || typeof a != "object" || Array.isArray(a))
2005
+ throw new Ce("This document has no root element.");
2006
+ return a;
1737
2007
  }
1738
- const Oe = { found: !1 }, fe = (e) => ({ found: !0, value: e });
1739
- function ir(e) {
1740
- return e == null || e === "" ? Oe : Array.isArray(e) || e instanceof Date ? fe(e) : typeof e == "object" ? Oe : typeof e == "string" || typeof e == "number" || typeof e == "boolean" ? fe(e) : Oe;
2008
+ const ke = { found: !1 }, me = (e) => ({ found: !0, value: e });
2009
+ function Tt(e) {
2010
+ return e == null || e === "" ? ke : Array.isArray(e) || e instanceof Date ? me(e) : typeof e == "object" ? ke : typeof e == "string" || typeof e == "number" || typeof e == "boolean" ? me(e) : ke;
1741
2011
  }
1742
- const An = /* @__PURE__ */ new Set(["true", "1", "yes", "y"]), Cn = /* @__PURE__ */ new Set(["false", "0", "no", "n"]);
1743
- async function Sn(e, t) {
1744
- switch (t.as) {
2012
+ const ro = /* @__PURE__ */ new Set(["true", "1", "yes", "y"]), no = /* @__PURE__ */ new Set(["false", "0", "no", "n"]);
2013
+ async function oo(e, r) {
2014
+ switch (r.as) {
1745
2015
  case void 0:
1746
- return fe(e);
2016
+ return me(e);
1747
2017
  case "string":
1748
- return fe(e instanceof Date ? e.toISOString() : String(e));
2018
+ return me(e instanceof Date ? e.toISOString() : String(e));
1749
2019
  case "number": {
1750
- const r = e instanceof Date ? e.getTime() : Number(e);
1751
- return Number.isFinite(r) ? fe(r) : Oe;
2020
+ const t = e instanceof Date ? e.getTime() : Number(e);
2021
+ return Number.isFinite(t) ? me(t) : ke;
1752
2022
  }
1753
2023
  case "boolean": {
1754
- const r = String(e).trim().toLowerCase();
1755
- return An.has(r) ? fe(!0) : Cn.has(r) ? fe(!1) : Oe;
2024
+ const t = String(e).trim().toLowerCase();
2025
+ return ro.has(t) ? me(!0) : no.has(t) ? me(!1) : ke;
1756
2026
  }
1757
2027
  case "date": {
1758
- const { default: r } = await import("dayjs"), { default: o } = await import("./customParseFormat-D14EWdSX.js").then((l) => l.c);
1759
- r.extend(o);
1760
- const u = e instanceof Date ? e.toISOString() : String(e), i = t.format ? r(u, t.format, !0) : r(u);
1761
- return i.isValid() ? fe(i.format("YYYY-MM-DD")) : Oe;
2028
+ const { default: t } = await import("dayjs"), { default: n } = await import("./customParseFormat-D14EWdSX.js").then((s) => s.c);
2029
+ t.extend(n);
2030
+ const l = e instanceof Date ? e.toISOString() : String(e), o = r.format ? t(l, r.format, !0) : t(l);
2031
+ return o.isValid() ? me(o.format("YYYY-MM-DD")) : ke;
1762
2032
  }
1763
2033
  }
1764
2034
  }
1765
- async function On(e, t) {
1766
- if (t.formula !== void 0) {
1767
- const r = {};
1768
- for (const [o, u] of Object.entries(t.inputs ?? {})) {
1769
- const i = ir(je.data(e, u));
1770
- if (!i.found || Array.isArray(i.value)) return Oe;
1771
- r[o] = i.value;
2035
+ async function io(e, r) {
2036
+ if (r.formula !== void 0) {
2037
+ const t = {};
2038
+ for (const [n, l] of Object.entries(r.inputs ?? {})) {
2039
+ const o = Tt(Ve.data(e, l));
2040
+ if (!o.found || Array.isArray(o.value)) return ke;
2041
+ t[n] = o.value;
1772
2042
  }
1773
2043
  try {
1774
- return fe(await wr(r, t.formula));
1775
- } catch (o) {
1776
- throw new Error(`x-xml.writeTo "${t.to}": ${qe(o)}`);
2044
+ return me(await jt(t, r.formula));
2045
+ } catch (n) {
2046
+ throw new Error(`writeTo "${r.to}": ${st(n)}`);
1777
2047
  }
1778
2048
  }
1779
- if (t.from === void 0) throw new Error(`x-xml.writeTo "${t.to}" needs either "from" or "formula".`);
1780
- return ir(je.data(e, t.from));
2049
+ if (r.from === void 0) throw new Error(`writeTo "${r.to}" needs either "from" or "formula".`);
2050
+ return Tt(Ve.data(e, r.from));
1781
2051
  }
1782
- async function Nn(e, t) {
1783
- const r = [];
1784
- for (const o of t) {
1785
- let u = await On(e, o);
1786
- const i = u.found && Array.isArray(u.value);
1787
- if (u.found && !i && o.map) {
1788
- const l = u.value instanceof Date ? u.value.toISOString() : String(u.value);
1789
- Object.prototype.hasOwnProperty.call(o.map, l) && (u = fe(o.map[l]));
2052
+ function Kt(e) {
2053
+ const r = {};
2054
+ for (const { to: t, value: n } of e) {
2055
+ const l = t.split(".").filter(Boolean);
2056
+ if (l.length === 0) continue;
2057
+ let o = r;
2058
+ for (const s of l.slice(0, -1)) {
2059
+ const c = o[s];
2060
+ if (c && typeof c == "object" && !Array.isArray(c))
2061
+ o = c;
2062
+ else {
2063
+ const a = {};
2064
+ o[s] = a, o = a;
2065
+ }
1790
2066
  }
1791
- if (u.found && !i && (u = await Sn(u.value, o)), !u.found) {
1792
- if (o.default === void 0) continue;
1793
- r.push({ to: o.to, value: o.default });
2067
+ o[l[l.length - 1]] = n;
2068
+ }
2069
+ return r;
2070
+ }
2071
+ async function lt(e, r) {
2072
+ const t = [];
2073
+ for (const n of r) {
2074
+ let l = await io(e, n);
2075
+ const o = l.found && Array.isArray(l.value);
2076
+ if (l.found && o && n.writeTo) {
2077
+ const s = await Promise.all(
2078
+ l.value.map(
2079
+ async (c) => Kt(await lt(c, n.writeTo))
2080
+ )
2081
+ );
2082
+ t.push({ to: n.to, value: s });
1794
2083
  continue;
1795
2084
  }
1796
- r.push({ to: o.to, value: u.value });
2085
+ if (l.found && !o && n.writeTo)
2086
+ throw new Error(`writeTo "${n.to}": "writeTo" is set, but "from" did not resolve to a repeating element.`);
2087
+ if (l.found && !o && n.map) {
2088
+ const s = l.value instanceof Date ? l.value.toISOString() : String(l.value);
2089
+ Object.prototype.hasOwnProperty.call(n.map, s) && (l = me(n.map[s]));
2090
+ }
2091
+ if (l.found && !o && (l = await oo(l.value, n)), !l.found) {
2092
+ if (n.default === void 0) continue;
2093
+ t.push({ to: n.to, value: n.default });
2094
+ continue;
2095
+ }
2096
+ t.push({ to: n.to, value: l.value });
1797
2097
  }
1798
- return r;
2098
+ return t;
1799
2099
  }
1800
- const xn = ".xml,text/xml,application/xml", In = 5 * 1024 * 1024, kn = ({
2100
+ const so = ".xml,text/xml,application/xml", lo = 5 * 1024 * 1024, co = ({
1801
2101
  data: e,
1802
- handleChange: t,
1803
- path: r,
1804
- label: o,
1805
- required: u,
1806
- schema: i,
1807
- enabled: l,
1808
- readonly: a,
1809
- errors: s,
1810
- visible: c = !0
2102
+ handleChange: r,
2103
+ path: t,
2104
+ label: n,
2105
+ required: l,
2106
+ schema: o,
2107
+ enabled: s,
2108
+ readonly: c,
2109
+ errors: a,
2110
+ visible: d = !0
1811
2111
  }) => {
1812
- be(c, r, t);
1813
- const d = !s || s.length === 0, y = yr(l, a), p = (i == null ? void 0 : i["x-xml"]) ?? {}, m = p.accept ?? xn, v = p.maxSize ?? In, I = p.arrayPaths, A = p.removeNamespaces === !0, b = p.writeTo, k = p.writeBase ?? "root", F = p.persistDocument !== !1, z = fr(), w = e ?? null, [_, V] = $(() => w ? "ready" : "empty"), [O, C] = $(null), [H, B] = $(!1), W = pe(null), j = pe(0), ee = w != null, re = b !== void 0 && b.length > 0, le = ke(
1814
- async (f) => {
1815
- var J;
1816
- const T = ++j.current;
1817
- if (C(null), f.size > v) {
1818
- C(`File exceeds the ${ye(v)} limit.`);
2112
+ Ee(d, t, r);
2113
+ const u = !a || a.length === 0, h = $t(s, c), p = (o == null ? void 0 : o["x-xml"]) ?? {}, g = p.accept ?? so, b = p.maxSize ?? lo, I = p.arrayPaths, O = p.removeNamespaces === !0, T = p.writeTo, A = p.writeBase ?? "root", k = p.persistDocument !== !1, M = We(), L = e ?? null, [N, U] = j(() => L ? "ready" : "empty"), [z, v] = j(null), [E, B] = j(!1), K = ae(null), J = ae(0), F = L != null, R = T !== void 0 && T.length > 0, Y = Fe(
2114
+ async (m) => {
2115
+ var ie;
2116
+ const C = ++J.current;
2117
+ if (v(null), m.size > b) {
2118
+ v(`File exceeds the ${ve(b)} limit.`);
1819
2119
  return;
1820
2120
  }
1821
- if (!m.split(",").map((D) => D.trim()).some((D) => D === "*" || D === "*/*" ? !0 : D.endsWith("/*") ? f.type.startsWith(D.slice(0, -1)) : D.startsWith(".") ? f.name.toLowerCase().endsWith(D.toLowerCase()) : f.type === D)) {
1822
- C(`Invalid type. Accepted: ${ve(m)}`);
2121
+ if (!g.split(",").map(($) => $.trim()).some(($) => $ === "*" || $ === "*/*" ? !0 : $.endsWith("/*") ? m.type.startsWith($.slice(0, -1)) : $.startsWith(".") ? m.name.toLowerCase().endsWith($.toLowerCase()) : m.type === $)) {
2122
+ v(`Invalid type. Accepted: ${we(g)}`);
1823
2123
  return;
1824
2124
  }
1825
- V("parsing");
1826
- let U;
2125
+ U("parsing");
2126
+ let _;
1827
2127
  try {
1828
- const D = await f.text();
1829
- U = await Tn(D, { arrayPaths: I, removeNamespaces: A });
1830
- } catch (D) {
1831
- if (T !== j.current) return;
1832
- V("error"), C(
1833
- D instanceof Te ? D.message : "This doesn't look like a valid XML document. Please check the file and try again."
2128
+ const $ = await m.text();
2129
+ _ = await to($, { arrayPaths: I, removeNamespaces: O });
2130
+ } catch ($) {
2131
+ if (C !== J.current) return;
2132
+ U("error"), v(
2133
+ $ instanceof Ce ? $.message : "This doesn't look like a valid XML document. Please check the file and try again."
1834
2134
  );
1835
2135
  return;
1836
2136
  }
1837
- let Z = [];
1838
- if (b && b.length > 0)
2137
+ let re = [];
2138
+ if (T && T.length > 0)
1839
2139
  try {
1840
- Z = await Nn(U, b);
1841
- } catch (D) {
1842
- if (T !== j.current) return;
1843
- V("error"), C(D instanceof Error ? D.message : "This document could not be mapped onto the form.");
2140
+ re = await lt(_, T);
2141
+ } catch ($) {
2142
+ if (C !== J.current) return;
2143
+ U("error"), v($ instanceof Error ? $.message : "This document could not be mapped onto the form.");
1844
2144
  return;
1845
2145
  }
1846
- if (T !== j.current) return;
1847
- F && t(r, U);
1848
- const ie = k === "parent" ? r.split(".").slice(0, -1).join(".") : "";
1849
- for (const D of Z) (J = z.dispatch) == null || J.call(z, zr(ie ? `${ie}.${D.to}` : D.to, () => D.value));
1850
- V("ready");
2146
+ if (C !== J.current) return;
2147
+ k && r(t, _);
2148
+ const q = A === "parent" ? t.split(".").slice(0, -1).join(".") : "";
2149
+ for (const $ of re) (ie = M.dispatch) == null || ie.call(M, cr(q ? `${q}.${$.to}` : $.to, () => $.value));
2150
+ U("ready");
1851
2151
  },
1852
- [m, v, I, A, b, k, F, r, t, z]
2152
+ [g, b, I, O, T, A, k, t, r, M]
1853
2153
  );
1854
- if (c === !1 || !y && !ee) return null;
1855
- const oe = (f) => {
1856
- f.preventDefault(), f.stopPropagation(), y && B(f.type === "dragenter" || f.type === "dragover");
1857
- }, se = (f) => {
1858
- var T;
1859
- f.preventDefault(), f.stopPropagation(), B(!1), y && (T = f.dataTransfer.files) != null && T[0] && le(f.dataTransfer.files[0]);
1860
- }, de = (f) => {
1861
- var T;
1862
- (T = f.target.files) != null && T[0] && (le(f.target.files[0]), f.target.value = "");
2154
+ if (d === !1 || !h && !F) return null;
2155
+ const Q = (m) => {
2156
+ m.preventDefault(), m.stopPropagation(), h && B(m.type === "dragenter" || m.type === "dragover");
2157
+ }, be = (m) => {
2158
+ var C;
2159
+ m.preventDefault(), m.stopPropagation(), B(!1), h && (C = m.dataTransfer.files) != null && C[0] && Y(m.dataTransfer.files[0]);
2160
+ }, oe = (m) => {
2161
+ var C;
2162
+ (C = m.target.files) != null && C[0] && (Y(m.target.files[0]), m.target.value = "");
1863
2163
  };
1864
- return /* @__PURE__ */ g(x, { mb: "4", children: [
1865
- /* @__PURE__ */ g(S, { align: "center", justify: "between", mb: "2", children: [
1866
- /* @__PURE__ */ g(S, { align: "center", gap: "1", children: [
1867
- /* @__PURE__ */ g(h, { as: "label", size: "2", weight: "bold", children: [
1868
- o,
1869
- u && /* @__PURE__ */ n(h, { color: "red", children: " *" })
2164
+ return /* @__PURE__ */ y(S, { mb: "4", children: [
2165
+ /* @__PURE__ */ y(D, { align: "center", justify: "between", mb: "2", children: [
2166
+ /* @__PURE__ */ y(D, { align: "center", gap: "1", children: [
2167
+ /* @__PURE__ */ y(f, { as: "label", size: "2", weight: "bold", children: [
2168
+ n,
2169
+ l && /* @__PURE__ */ i(f, { color: "red", children: " *" })
1870
2170
  ] }),
1871
- !re && ee && y && /* @__PURE__ */ g(he, { children: [
1872
- /* @__PURE__ */ n(He, { content: "Replace document", children: /* @__PURE__ */ n(
1873
- Me,
2171
+ !R && F && h && /* @__PURE__ */ y(ge, { children: [
2172
+ /* @__PURE__ */ i(qe, { content: "Replace document", children: /* @__PURE__ */ i(
2173
+ je,
1874
2174
  {
1875
2175
  variant: "ghost",
1876
2176
  size: "1",
1877
2177
  onClick: () => {
1878
- var f;
1879
- return (f = W.current) == null ? void 0 : f.click();
2178
+ var m;
2179
+ return (m = K.current) == null ? void 0 : m.click();
1880
2180
  },
1881
2181
  "aria-label": "Replace document",
1882
- children: /* @__PURE__ */ n(Ne, {})
2182
+ children: /* @__PURE__ */ i(ze, {})
1883
2183
  }
1884
2184
  ) }),
1885
- /* @__PURE__ */ n(He, { content: "Remove document", children: /* @__PURE__ */ n(Me, { variant: "ghost", size: "1", color: "gray", onClick: () => {
1886
- y && (++j.current, C(null), V("empty"), t(r, void 0));
1887
- }, "aria-label": "Remove document", children: /* @__PURE__ */ n(Ye, {}) }) })
2185
+ /* @__PURE__ */ i(qe, { content: "Remove document", children: /* @__PURE__ */ i(je, { variant: "ghost", size: "1", color: "gray", onClick: () => {
2186
+ h && (++J.current, v(null), U("empty"), r(t, void 0));
2187
+ }, "aria-label": "Remove document", children: /* @__PURE__ */ i(rt, {}) }) })
1888
2188
  ] })
1889
2189
  ] }),
1890
- /* @__PURE__ */ g(S, { align: "center", gap: "2", children: [
1891
- /* @__PURE__ */ g(h, { size: "1", color: "gray", children: [
1892
- ye(v),
2190
+ /* @__PURE__ */ y(D, { align: "center", gap: "2", children: [
2191
+ /* @__PURE__ */ y(f, { size: "1", color: "gray", children: [
2192
+ ve(b),
1893
2193
  " max · ",
1894
- ve(m)
2194
+ we(g)
1895
2195
  ] }),
1896
- re && y && /* @__PURE__ */ g(De, { size: "1", variant: "soft", onClick: () => {
1897
- var f;
1898
- return (f = W.current) == null ? void 0 : f.click();
1899
- }, disabled: _ === "parsing", children: [
1900
- _ === "parsing" ? /* @__PURE__ */ n(xe, { size: "1" }) : /* @__PURE__ */ n(Ne, {}),
2196
+ R && h && /* @__PURE__ */ y(De, { size: "1", variant: "soft", onClick: () => {
2197
+ var m;
2198
+ return (m = K.current) == null ? void 0 : m.click();
2199
+ }, disabled: N === "parsing", children: [
2200
+ N === "parsing" ? /* @__PURE__ */ i(Ue, { size: "1" }) : /* @__PURE__ */ i(ze, {}),
1901
2201
  "Upload"
1902
2202
  ] })
1903
2203
  ] })
1904
2204
  ] }),
1905
- (re || ee) && O && /* @__PURE__ */ n(h, { size: "2", color: "red", mb: "2", style: { display: "block" }, children: O }),
1906
- /* @__PURE__ */ n("input", { ref: W, type: "file", style: { display: "none" }, accept: m, onChange: de }),
1907
- !re && y && !ee && /* @__PURE__ */ n(
2205
+ (R || F) && z && /* @__PURE__ */ i(f, { size: "2", color: "red", mb: "2", style: { display: "block" }, children: z }),
2206
+ /* @__PURE__ */ i("input", { ref: K, type: "file", style: { display: "none" }, accept: g, onChange: oe }),
2207
+ !R && h && !F && /* @__PURE__ */ i(
1908
2208
  "div",
1909
2209
  {
1910
2210
  role: "button",
1911
2211
  tabIndex: 0,
1912
2212
  onClick: () => {
1913
- var f;
1914
- return (f = W.current) == null ? void 0 : f.click();
2213
+ var m;
2214
+ return (m = K.current) == null ? void 0 : m.click();
1915
2215
  },
1916
- onKeyDown: (f) => {
1917
- var T;
1918
- (f.key === "Enter" || f.key === " ") && (f.preventDefault(), (T = W.current) == null || T.click());
2216
+ onKeyDown: (m) => {
2217
+ var C;
2218
+ (m.key === "Enter" || m.key === " ") && (m.preventDefault(), (C = K.current) == null || C.click());
1919
2219
  },
1920
- onDragEnter: oe,
1921
- onDragLeave: oe,
1922
- onDragOver: oe,
1923
- onDrop: se,
2220
+ onDragEnter: Q,
2221
+ onDragLeave: Q,
2222
+ onDragOver: Q,
2223
+ onDrop: be,
1924
2224
  style: { cursor: "pointer" },
1925
2225
  className: [
1926
2226
  "border-2 border-dashed rounded-lg p-6 text-center",
1927
2227
  "transition-all duration-200 ease-in-out",
1928
- H ? "border-blue-500 bg-blue-50" : O ? "border-red-300 bg-red-50" : "border-gray-300 hover:border-blue-400 hover:bg-gray-50"
2228
+ E ? "border-blue-500 bg-blue-50" : z ? "border-red-300 bg-red-50" : "border-gray-300 hover:border-blue-400 hover:bg-gray-50"
1929
2229
  ].join(" "),
1930
- children: /* @__PURE__ */ n(S, { direction: "column", align: "center", gap: "2", children: _ === "parsing" ? /* @__PURE__ */ g(he, { children: [
1931
- /* @__PURE__ */ n(xe, { size: "3" }),
1932
- /* @__PURE__ */ n(h, { size: "2", color: "gray", children: "Parsing document…" })
1933
- ] }) : O ? /* @__PURE__ */ g(he, { children: [
1934
- /* @__PURE__ */ n(Je, { style: { width: 32, height: 32, color: "var(--red-9)" } }),
1935
- /* @__PURE__ */ n(h, { size: "2", color: "red", weight: "medium", children: O }),
1936
- /* @__PURE__ */ n(h, { size: "1", color: "gray", children: "Click to try again" })
1937
- ] }) : /* @__PURE__ */ g(he, { children: [
1938
- /* @__PURE__ */ n(Ne, { style: { width: 32, height: 32, color: "var(--gray-8)" } }),
1939
- /* @__PURE__ */ n(h, { size: "2", weight: "medium", children: "Click to upload or drag and drop" }),
1940
- /* @__PURE__ */ g(h, { size: "1", color: "gray", children: [
1941
- ye(v),
2230
+ children: /* @__PURE__ */ i(D, { direction: "column", align: "center", gap: "2", children: N === "parsing" ? /* @__PURE__ */ y(ge, { children: [
2231
+ /* @__PURE__ */ i(Ue, { size: "3" }),
2232
+ /* @__PURE__ */ i(f, { size: "2", color: "gray", children: "Parsing document…" })
2233
+ ] }) : z ? /* @__PURE__ */ y(ge, { children: [
2234
+ /* @__PURE__ */ i(nt, { style: { width: 32, height: 32, color: "var(--red-9)" } }),
2235
+ /* @__PURE__ */ i(f, { size: "2", color: "red", weight: "medium", children: z }),
2236
+ /* @__PURE__ */ i(f, { size: "1", color: "gray", children: "Click to try again" })
2237
+ ] }) : /* @__PURE__ */ y(ge, { children: [
2238
+ /* @__PURE__ */ i(ze, { style: { width: 32, height: 32, color: "var(--gray-8)" } }),
2239
+ /* @__PURE__ */ i(f, { size: "2", weight: "medium", children: "Click to upload or drag and drop" }),
2240
+ /* @__PURE__ */ y(f, { size: "1", color: "gray", children: [
2241
+ ve(b),
1942
2242
  " max · ",
1943
- ve(m)
2243
+ we(g)
1944
2244
  ] })
1945
2245
  ] }) })
1946
2246
  }
1947
2247
  ),
1948
- !d && /* @__PURE__ */ n(h, { color: "red", size: "1", mt: "2", style: { display: "block" }, children: we(s, o) })
2248
+ !u && /* @__PURE__ */ i(f, { color: "red", size: "1", mt: "2", style: { display: "block" }, children: ye(a, n) })
1949
2249
  ] });
1950
- }, Dn = me(kn), Mn = q(
2250
+ }, ao = ue(co), uo = ee(
1951
2251
  10,
1952
- ze((e) => {
1953
- const t = e["x-xml"];
1954
- return e.type === "object" && typeof t == "object" && t !== null;
2252
+ Ie((e) => {
2253
+ const r = e["x-xml"];
2254
+ return e.type === "object" && typeof r == "object" && r !== null;
1955
2255
  })
1956
2256
  );
1957
- function zn(e, t, r) {
1958
- const o = {};
1959
- for (const [u, i] of Object.entries(r)) {
1960
- const { path: l, default: a } = typeof i == "string" ? { path: i, default: void 0 } : i, s = t ? `${t}.${l}` : l, c = je.data(e, s);
1961
- if (c == null) {
1962
- if (a === void 0) return;
1963
- o[u] = a;
1964
- } else
1965
- o[u] = c;
2257
+ function fo(e, r, t) {
2258
+ const n = new Blob([e], { type: t }), l = URL.createObjectURL(n), o = document.createElement("a");
2259
+ o.href = l, o.download = r, o.click(), URL.revokeObjectURL(l);
2260
+ }
2261
+ const po = "root", ho = "export.xml";
2262
+ function mo(e) {
2263
+ return e === void 0 ? "writeTo is required — see docs/xml-export-control.md." : Array.isArray(e) ? e.length === 0 ? "writeTo is declared but empty — declare at least one entry." : null : "writeTo must be an array of { from | formula, to } entries.";
2264
+ }
2265
+ function go(e) {
2266
+ return e == null ? !0 : Array.isArray(e) ? e.length === 0 : typeof e == "object" ? Object.keys(e).length === 0 : !1;
2267
+ }
2268
+ const yo = ({ path: e, label: r, schema: t, visible: n = !0 }) => {
2269
+ var T, A;
2270
+ const l = (t == null ? void 0 : t["x-xml-export"]) ?? {}, o = l.rootElement ?? po, s = l.fileName ?? ho, c = l.writeTo, a = l.writeBase ?? "root", d = mo(c), u = We(), h = a === "parent" ? e.split(".").slice(0, -1).join(".") : "", p = h ? Ve.data((T = u.core) == null ? void 0 : T.data, h) : (A = u.core) == null ? void 0 : A.data, [g, b] = j(null), I = go(p), O = Fe(async () => {
2271
+ if (!c) return;
2272
+ b(null);
2273
+ let k;
2274
+ try {
2275
+ const z = await lt(p, c);
2276
+ k = Kt(z);
2277
+ } catch (z) {
2278
+ b(z instanceof Error ? z.message : "This mapping could not be resolved.");
2279
+ return;
2280
+ }
2281
+ const { XMLBuilder: M } = await import("fast-xml-parser"), L = { [o]: k }, U = new M({ format: !0, indentBy: " ", ignoreAttributes: !0 }).build(L);
2282
+ fo(U, s, "application/xml");
2283
+ }, [c, p, o, s]);
2284
+ return n === !1 ? null : d ? /* @__PURE__ */ y(S, { mb: "4", children: [
2285
+ /* @__PURE__ */ i(f, { as: "label", size: "2", weight: "bold", children: r }),
2286
+ /* @__PURE__ */ y(f, { size: "2", color: "red", style: { display: "block" }, children: [
2287
+ "Invalid x-xml-export config: ",
2288
+ d
2289
+ ] })
2290
+ ] }) : /* @__PURE__ */ y(S, { mb: "4", children: [
2291
+ /* @__PURE__ */ i(f, { as: "label", size: "2", weight: "bold", style: { display: "block", marginBottom: "var(--space-2)" }, children: r }),
2292
+ /* @__PURE__ */ y(De, { size: "1", variant: "soft", disabled: I, onClick: () => void O(), children: [
2293
+ /* @__PURE__ */ i(Mt, {}),
2294
+ "Download XML"
2295
+ ] }),
2296
+ g && /* @__PURE__ */ i(f, { size: "2", color: "red", style: { display: "block", marginTop: "var(--space-2)" }, children: g })
2297
+ ] });
2298
+ }, bo = ue(yo), vo = ee(
2299
+ 10,
2300
+ Ie((e) => {
2301
+ const r = e["x-xml-export"];
2302
+ return e.type === "object" && typeof r == "object" && r !== null;
2303
+ })
2304
+ );
2305
+ function Yt(e, r, t) {
2306
+ const { path: n, default: l } = typeof t == "string" ? { path: t, default: void 0 } : t, o = Ve.data(e, r ? `${r}.${n}` : n);
2307
+ return o ?? l;
2308
+ }
2309
+ function wo(e, r, t) {
2310
+ const n = {};
2311
+ for (const [l, o] of Object.entries(t)) {
2312
+ const s = Yt(e, r, o);
2313
+ if (s === void 0) return;
2314
+ n[l] = s;
1966
2315
  }
1967
- return o;
2316
+ return n;
1968
2317
  }
1969
- async function Ln(e, t) {
2318
+ async function Eo(e, r) {
1970
2319
  try {
1971
- return { status: "ok", value: await wr(e, t) };
1972
- } catch (r) {
1973
- return { status: "error", error: qe(r) };
2320
+ return { status: "ok", value: await jt(e, r) };
2321
+ } catch (t) {
2322
+ return { status: "error", error: st(t) };
1974
2323
  }
1975
2324
  }
1976
- function Fn(e, t) {
1977
- return e == null ? "" : typeof e == "number" ? e.toFixed(Un(t)) : e instanceof Date ? e.toLocaleDateString() : String(e);
2325
+ function To(e, r) {
2326
+ return e == null ? "" : typeof e == "number" ? e.toFixed(Ao(r)) : e instanceof Date ? e.toLocaleDateString() : String(e);
1978
2327
  }
1979
- function Un(e) {
2328
+ function Ao(e) {
1980
2329
  return Number.isFinite(e) ? Math.min(100, Math.max(0, Math.trunc(e))) : 0;
1981
2330
  }
1982
- const lr = "{value}", Pn = 2, $n = {}, _n = ({ data: e, handleChange: t, path: r, label: o, schema: u, visible: i = !0 }) => {
1983
- var _;
1984
- be(i, r, t, null);
1985
- const l = u == null ? void 0 : u["x-computed"], a = (l == null ? void 0 : l.inputs) ?? $n, s = (l == null ? void 0 : l.formula) ?? "", c = (l == null ? void 0 : l.format) ?? lr, d = (l == null ? void 0 : l.decimals) ?? Pn, y = fr(), p = r.split(".").slice(0, -1).join("."), m = zn((_ = y.core) == null ? void 0 : _.data, p, a), v = m ? JSON.stringify(m) : null, I = y.readonly === !0, [A, b] = $(() => typeof e == "number" ? "ok" : "unavailable"), [k, F] = $(() => typeof e == "number" ? e : null), [z, w] = $(null);
1986
- return ge(() => {
1987
- if (!i) return;
1988
- let V = !1;
1989
- const O = (C) => {
1990
- I || C !== (e ?? null) && t(r, C);
2331
+ const xo = "{value}", Ro = 2, Co = {}, So = ({ data: e, handleChange: r, path: t, label: n, schema: l, visible: o = !0 }) => {
2332
+ var N;
2333
+ Ee(o, t, r);
2334
+ const s = l == null ? void 0 : l["x-computed"], c = (s == null ? void 0 : s.inputs) ?? Co, a = (s == null ? void 0 : s.formula) ?? "", d = (s == null ? void 0 : s.format) ?? xo, u = (s == null ? void 0 : s.decimals) ?? Ro, h = We(), p = t.split(".").slice(0, -1).join("."), g = wo((N = h.core) == null ? void 0 : N.data, p, c), b = g ? JSON.stringify(g) : null, I = h.readonly === !0, [O, T] = j(() => typeof e == "number" ? "ok" : "unavailable"), [A, k] = j(() => typeof e == "number" ? e : null), [M, L] = j(null);
2335
+ return de(() => {
2336
+ if (!o) return;
2337
+ let U = !1;
2338
+ const z = (v) => {
2339
+ I || v !== e && r(t, v);
1991
2340
  };
1992
- if (m === void 0) {
1993
- b("unavailable"), w(null), F(null), O(null);
2341
+ if (g === void 0) {
2342
+ T("unavailable"), L(null), k(null), z(void 0);
1994
2343
  return;
1995
2344
  }
1996
- return b((C) => C === "ok" ? C : "loading"), Ln(m, s).then((C) => {
1997
- if (V) return;
1998
- const H = C.status === "ok" && typeof C.value == "number" && Number.isFinite(C.value) ? C.value : null;
1999
- if (H === null) {
2000
- b("error"), w(
2001
- C.status === "error" ? C.error ?? "Unable to compute value." : "Computed value must be a number."
2002
- ), F(null), O(null);
2345
+ return T((v) => v === "ok" ? v : "loading"), Eo(g, a).then((v) => {
2346
+ if (U) return;
2347
+ const E = v.status === "ok" && typeof v.value == "number" && Number.isFinite(v.value) ? v.value : null;
2348
+ if (E === null) {
2349
+ T("error"), L(
2350
+ v.status === "error" ? v.error ?? "Unable to compute value." : "Computed value must be a number."
2351
+ ), k(null), z(void 0);
2003
2352
  return;
2004
2353
  }
2005
- b("ok"), w(null), F(H), O(H);
2354
+ T("ok"), L(null), k(E), z(E);
2006
2355
  }), () => {
2007
- V = !0;
2356
+ U = !0;
2008
2357
  };
2009
- }, [v, s, i, I]), i === !1 ? null : /* @__PURE__ */ n(x, { mb: "4", children: /* @__PURE__ */ g(S, { direction: "column", gap: "1", children: [
2010
- /* @__PURE__ */ n(h, { as: "label", size: "2", weight: "bold", children: o }),
2011
- A === "unavailable" ? /* @__PURE__ */ n(h, { size: "2", color: "gray", children: "Not yet available." }) : A === "loading" ? /* @__PURE__ */ g(S, { align: "center", gap: "2", children: [
2012
- /* @__PURE__ */ n(xe, { size: "1" }),
2013
- /* @__PURE__ */ n(h, { size: "2", color: "gray", children: "Computing…" })
2014
- ] }) : A === "error" ? /* @__PURE__ */ n(h, { size: "2", color: "red", children: z }) : /* @__PURE__ */ n(h, { size: "2", children: c.split(lr).join(Fn(k, d)) }),
2015
- u.description && /* @__PURE__ */ n(h, { size: "1", color: "gray", children: u.description })
2358
+ }, [b, a, o, I]), o === !1 ? null : /* @__PURE__ */ i(S, { mb: "4", children: /* @__PURE__ */ y(D, { direction: "column", gap: "1", children: [
2359
+ /* @__PURE__ */ i(f, { as: "label", size: "2", weight: "bold", children: n }),
2360
+ O === "unavailable" ? /* @__PURE__ */ i(f, { size: "2", color: "gray", children: "Not yet available." }) : O === "loading" ? /* @__PURE__ */ y(D, { align: "center", gap: "2", children: [
2361
+ /* @__PURE__ */ i(Ue, { size: "1" }),
2362
+ /* @__PURE__ */ i(f, { size: "2", color: "gray", children: "Computing…" })
2363
+ ] }) : O === "error" ? /* @__PURE__ */ i(f, { size: "2", color: "red", children: M }) : /* @__PURE__ */ i(f, { size: "2", children: ot(d, { value: To(A, u) }) }),
2364
+ l.description && /* @__PURE__ */ i(f, { size: "1", color: "gray", children: l.description })
2016
2365
  ] }) });
2017
- }, Vn = me(_n), Hn = q(
2366
+ }, Oo = ue(So), No = ee(
2018
2367
  5,
2019
- ze((e) => {
2020
- const t = e["x-computed"];
2021
- return e.type === "number" && typeof t == "object" && t !== null;
2368
+ Ie((e) => {
2369
+ const r = e["x-computed"];
2370
+ return e.type === "number" && typeof r == "object" && r !== null;
2022
2371
  })
2023
- ), Wn = ({
2372
+ ), Gt = "seq", At = 2, ko = (e) => e == null || e === "", qt = (e) => typeof e == "object" && e !== null && !Array.isArray(e) ? e : void 0, Io = (e) => {
2373
+ const r = e == null ? void 0 : e["x-template"];
2374
+ if (typeof r != "object" || r === null) return;
2375
+ const { template: t, inputs: n } = r;
2376
+ if (!(typeof t != "string" || t === ""))
2377
+ return { template: t, inputs: n };
2378
+ }, ct = (e) => typeof e == "object" && e.name === Gt && e.arg !== void 0, Do = (e) => e.every((r, t) => !ct(r) || typeof e[t - 1] != "object" && typeof e[t + 1] != "object"), Lo = (e) => {
2379
+ const r = /* @__PURE__ */ new Set();
2380
+ for (const t of it(e))
2381
+ typeof t == "object" && t.arg === void 0 && r.add(t.name);
2382
+ return [...r];
2383
+ }, Mo = (e) => {
2384
+ const r = [];
2385
+ for (const [t, n] of Object.entries((e == null ? void 0 : e.properties) ?? {})) {
2386
+ const l = Io(n);
2387
+ l && r.push([t, l]);
2388
+ }
2389
+ return r;
2390
+ }, zo = (e, r, t) => {
2391
+ var l;
2392
+ const n = {};
2393
+ for (const o of Lo(t.template)) {
2394
+ const s = Yt(e, r, ((l = t.inputs) == null ? void 0 : l[o]) ?? o);
2395
+ n[o] = typeof s == "string" || typeof s == "number" || typeof s == "boolean" ? String(s) : "";
2396
+ }
2397
+ return n;
2398
+ }, Fo = (e) => (r) => {
2399
+ const t = r.trim() === "" ? At : Number(r);
2400
+ return `${e}`.padStart(Number.isInteger(t) && t >= 0 ? t : At, "0");
2401
+ }, Uo = (e) => {
2402
+ const r = (n) => n.replace(/[.*+?^${}()|[\]\\]/g, "\\$&");
2403
+ let t = "";
2404
+ for (const n of it(e))
2405
+ typeof n == "string" ? t += r(n) : t += ct(n) ? "(\\d+)" : ".*?";
2406
+ return new RegExp(`^${t}$`);
2407
+ }, Po = (e, r, t) => {
2408
+ var o, s;
2409
+ const n = Uo(t.template);
2410
+ let l = 0;
2411
+ for (const c of e) {
2412
+ const a = (o = qt(c)) == null ? void 0 : o[r];
2413
+ if (typeof a != "string") continue;
2414
+ const d = Number((s = n.exec(a)) == null ? void 0 : s[1]);
2415
+ Number.isFinite(d) && d > l && (l = d);
2416
+ }
2417
+ return l;
2418
+ }, $o = (e, r, t, n, l, o) => {
2419
+ const s = Mo(e);
2420
+ if (s.length === 0) return r;
2421
+ const c = qt(r);
2422
+ if (!c) return r;
2423
+ const a = { ...c };
2424
+ for (const [d, u] of s) {
2425
+ if (!ko(a[d])) continue;
2426
+ const h = it(u.template), p = {};
2427
+ if (h.some(ct)) {
2428
+ if (!Do(h)) {
2429
+ console.warn(
2430
+ `x-template: {seq(…)} needs literal text between it and other placeholders; not numbering "${u.template}"`
2431
+ );
2432
+ continue;
2433
+ }
2434
+ const g = Math.max(o[d] ?? 0, Po(t, d, u)) + 1;
2435
+ o[d] = g, p[Gt] = Fo(g);
2436
+ }
2437
+ a[d] = ot(u.template, zo(n, l, u), p);
2438
+ }
2439
+ return a;
2440
+ }, _o = ({ path: e, items: r, itemsSchema: t, rootSchema: n, addItem: l, sequences: o }) => {
2441
+ const s = We();
2442
+ return /* @__PURE__ */ i(S, { mt: "2", children: /* @__PURE__ */ y(De, { type: "button", variant: "surface", onClick: () => {
2443
+ var d;
2444
+ const a = $o(
2445
+ t,
2446
+ ar(t, n),
2447
+ r,
2448
+ (d = s.core) == null ? void 0 : d.data,
2449
+ // The object CONTAINING the array, not the row: a row being filled is
2450
+ // empty, so what a template reaches for sits alongside the array.
2451
+ e.split(".").slice(0, -1).join("."),
2452
+ o.current
2453
+ );
2454
+ l && l(e, a)();
2455
+ }, children: [
2456
+ /* @__PURE__ */ i(yr, {}),
2457
+ "Add Item"
2458
+ ] }) });
2459
+ }, Vo = ({
2024
2460
  data: e,
2025
- path: t,
2026
- schema: r,
2027
- uischema: o,
2028
- enabled: u,
2029
- visible: i,
2030
- addItem: l,
2031
- removeItems: a,
2032
- rootSchema: s,
2033
- arraySchema: c
2461
+ path: r,
2462
+ schema: t,
2463
+ uischema: n,
2464
+ enabled: l,
2465
+ visible: o,
2466
+ addItem: s,
2467
+ removeItems: c,
2468
+ rootSchema: a,
2469
+ arraySchema: d
2034
2470
  }) => {
2035
- const d = c ? r : r.items, y = c || r;
2036
- if (i === !1 || !d || typeof d != "object" || Array.isArray(d))
2471
+ const u = ae({}), h = d ? t : t.items, p = d || t;
2472
+ if (o === !1 || !h || typeof h != "object" || Array.isArray(h))
2037
2473
  return null;
2038
- const p = d, m = Array.isArray(e) ? e : [], v = y.title || "Array Items", I = o.options ?? {}, A = u && I.addable !== !1, b = u && I.removable !== !1, k = () => {
2039
- const z = Lr(p, s);
2040
- l && l(t, z)();
2041
- }, F = (z) => {
2042
- if (a) {
2043
- const w = a(t, [z]);
2044
- w && w();
2474
+ const g = h, b = Array.isArray(e) ? e : [], I = p.title || "Array Items", O = n.options ?? {}, T = l && O.addable !== !1, A = l && O.removable !== !1, k = O.itemLabel || "Item", M = (L) => {
2475
+ if (c) {
2476
+ const N = c(r, [L]);
2477
+ N && N();
2045
2478
  }
2046
2479
  };
2047
- return /* @__PURE__ */ n(x, { mb: "6", children: /* @__PURE__ */ g(S, { direction: "column", gap: "4", children: [
2048
- /* @__PURE__ */ n(h, { as: "div", size: "4", weight: "bold", children: v }),
2049
- m.length === 0 && /* @__PURE__ */ n(x, { py: "4", px: "4", style: { backgroundColor: "var(--gray-3)", borderRadius: "var(--radius-3)" }, children: /* @__PURE__ */ n(h, { size: "2", color: "gray", children: "No items have been added yet." }) }),
2050
- m.map((z, w) => {
2051
- var V;
2052
- const _ = `${t}.${w}`;
2053
- return /* @__PURE__ */ n(pr, { size: "3", variant: "surface", children: /* @__PURE__ */ g(S, { direction: "column", gap: "4", children: [
2054
- /* @__PURE__ */ g(S, { justify: "between", align: "center", children: [
2055
- /* @__PURE__ */ g(h, { size: "3", weight: "bold", children: [
2056
- "Item ",
2057
- w + 1
2480
+ return /* @__PURE__ */ i(S, { mb: "6", children: /* @__PURE__ */ y(D, { direction: "column", gap: "4", children: [
2481
+ /* @__PURE__ */ i(f, { as: "div", size: "4", weight: "bold", children: I }),
2482
+ b.length === 0 && /* @__PURE__ */ i(S, { py: "4", px: "4", style: { backgroundColor: "var(--gray-3)", borderRadius: "var(--radius-3)" }, children: /* @__PURE__ */ i(f, { size: "2", color: "gray", children: "No items have been added yet." }) }),
2483
+ b.map((L, N) => {
2484
+ var z;
2485
+ const U = `${r}.${N}`;
2486
+ return /* @__PURE__ */ i(Dt, { size: "3", variant: "surface", children: /* @__PURE__ */ y(D, { direction: "column", gap: "4", children: [
2487
+ /* @__PURE__ */ y(D, { justify: "between", align: "center", children: [
2488
+ /* @__PURE__ */ y(f, { size: "3", weight: "bold", children: [
2489
+ k,
2490
+ " ",
2491
+ N + 1
2058
2492
  ] }),
2059
- b && /* @__PURE__ */ g(
2493
+ A && /* @__PURE__ */ y(
2060
2494
  De,
2061
2495
  {
2062
2496
  type: "button",
2063
2497
  color: "red",
2064
2498
  variant: "soft",
2065
- onClick: () => F(w),
2499
+ onClick: () => M(N),
2066
2500
  title: "Remove item",
2067
2501
  children: [
2068
- /* @__PURE__ */ n(Xr, {}),
2502
+ /* @__PURE__ */ i(gr, {}),
2069
2503
  "Remove"
2070
2504
  ]
2071
2505
  }
2072
2506
  )
2073
2507
  ] }),
2074
- /* @__PURE__ */ n(x, { children: /* @__PURE__ */ n(
2075
- Fe,
2508
+ /* @__PURE__ */ i(S, { children: /* @__PURE__ */ i(
2509
+ Be,
2076
2510
  {
2077
- schema: p,
2078
- uischema: ((V = o.options) == null ? void 0 : V.detail) || (p.type === "object" || p.properties ? {
2511
+ schema: g,
2512
+ uischema: ((z = n.options) == null ? void 0 : z.detail) || (g.type === "object" || g.properties ? {
2079
2513
  type: "VerticalLayout",
2080
- elements: Object.keys(p.properties || {}).map((O) => ({
2514
+ elements: Object.keys(g.properties || {}).map((v) => ({
2081
2515
  type: "Control",
2082
- scope: `#/properties/${O}`
2516
+ scope: `#/properties/${v}`
2083
2517
  }))
2084
2518
  } : {
2085
2519
  type: "Control",
2086
2520
  scope: "#"
2087
2521
  }),
2088
- path: _,
2089
- enabled: u,
2522
+ path: U,
2523
+ enabled: l,
2090
2524
  renderers: void 0,
2091
2525
  cells: void 0
2092
2526
  }
2093
2527
  ) })
2094
- ] }) }, _);
2528
+ ] }) }, U);
2095
2529
  }),
2096
- A && /* @__PURE__ */ n(x, { mt: "2", children: /* @__PURE__ */ g(De, { type: "button", variant: "surface", onClick: k, children: [
2097
- /* @__PURE__ */ n(Br, {}),
2098
- "Add Item"
2099
- ] }) })
2530
+ T && /* @__PURE__ */ i(
2531
+ _o,
2532
+ {
2533
+ path: r,
2534
+ items: b,
2535
+ itemsSchema: g,
2536
+ rootSchema: a,
2537
+ addItem: s,
2538
+ sequences: u
2539
+ }
2540
+ )
2100
2541
  ] }) });
2101
- }, sr = Pr(Wn), Xn = q(3, Fr), Bn = ({ uischema: e, visible: t }) => {
2102
- const r = e;
2103
- return t === !1 ? null : /* @__PURE__ */ n(x, { mb: "4", children: /* @__PURE__ */ n(hr, { size: "4", children: r.text }) });
2104
- }, jn = q(1, Le("Label")), Kn = q(3, Ur), io = [
2105
- { tester: Zr, renderer: Qr },
2106
- { tester: rt, renderer: tt },
2107
- { tester: ot, renderer: it },
2108
- { tester: st, renderer: ct },
2109
- { tester: mt, renderer: pt },
2110
- { tester: ut, renderer: dt },
2111
- { tester: bt, renderer: wt },
2112
- { tester: Rt, renderer: Et },
2113
- { tester: At, renderer: Tt },
2114
- { tester: St, renderer: Ct },
2115
- { tester: Nt, renderer: Ot },
2116
- { tester: Dt, renderer: kt },
2117
- { tester: yn, renderer: gn },
2542
+ }, xt = fr(Vo), jo = ee(3, ur), Ho = ({ uischema: e, visible: r }) => {
2543
+ const t = e;
2544
+ return r === !1 ? null : /* @__PURE__ */ i(S, { mb: "4", children: /* @__PURE__ */ i(It, { size: "4", children: t.text }) });
2545
+ }, Wo = ee(1, He("Label")), Bo = ee(3, dr), ri = [
2546
+ { tester: Er, renderer: Tr },
2547
+ { tester: xr, renderer: Rr },
2548
+ { tester: Sr, renderer: Or },
2549
+ { tester: kr, renderer: Ir },
2550
+ { tester: Hr, renderer: jr },
2551
+ { tester: Lr, renderer: Mr },
2552
+ { tester: Kr, renderer: Yr },
2553
+ { tester: qr, renderer: Gr },
2554
+ { tester: Zr, renderer: Jr },
2555
+ { tester: en, renderer: Qr },
2556
+ { tester: rn, renderer: tn },
2557
+ { tester: ln, renderer: sn },
2558
+ { tester: jn, renderer: Vn },
2559
+ { tester: Gn, renderer: Yn },
2118
2560
  // After SpreadsheetControl on purpose: both testers rank 10, and a tie is
2119
2561
  // resolved by registration order (see XmlControlTester's comment).
2120
- { tester: Mn, renderer: Dn },
2121
- { tester: Hn, renderer: Vn },
2122
- { tester: Xn, renderer: sr },
2123
- { tester: Kn, renderer: sr },
2124
- { tester: jn, renderer: Bn }
2562
+ { tester: uo, renderer: ao },
2563
+ // Also rank 10, but matches the distinct `x-xml-export` keyword rather
2564
+ // than `x-xml`, so it never ties with XmlControlTester on the same schema
2565
+ // node (see XmlExportControlTester's own comment).
2566
+ { tester: vo, renderer: bo },
2567
+ { tester: No, renderer: Oo },
2568
+ { tester: jo, renderer: xt },
2569
+ { tester: Bo, renderer: xt },
2570
+ { tester: Wo, renderer: Ho }
2125
2571
  ];
2126
2572
  export {
2127
- sr as ArrayControl,
2128
- Xn as ArrayControlTester,
2129
- nt as BooleanControl,
2130
- ot as BooleanControlTester,
2131
- Ot as CategorizationLayoutRenderer,
2132
- Nt as CategorizationLayoutTester,
2133
- Vn as ComputedControl,
2134
- Hn as ComputedControlTester,
2135
- vt as DateControl,
2136
- bt as DateControlTester,
2137
- kt as FileControl,
2138
- Dt as FileControlTester,
2139
- Ct as GroupLayoutRenderer,
2140
- St as GroupLayoutTester,
2141
- Tt as HorizontalLayoutRenderer,
2142
- At as HorizontalLayoutTester,
2143
- Bn as LabelRenderer,
2144
- jn as LabelTester,
2145
- et as NumberControl,
2146
- rt as NumberControlTester,
2147
- lt as RadioControl,
2148
- st as RadioControlTester,
2149
- pt as SearchSelectControl,
2150
- mt as SearchSelectControlTester,
2151
- oo as SearchServiceProvider,
2152
- at as SelectControl,
2153
- ut as SelectControlTester,
2154
- gn as SpreadsheetControl,
2155
- yn as SpreadsheetControlTester,
2156
- qr as TextControl,
2157
- Zr as TextControlTester,
2158
- no as UploadProvider,
2159
- Et as VerticalLayoutRenderer,
2160
- Rt as VerticalLayoutTester,
2161
- Dn as XmlControl,
2162
- Mn as XmlControlTester,
2163
- io as radixRenderers,
2164
- Jr as useSearchService,
2165
- Yr as useUpload
2573
+ xt as ArrayControl,
2574
+ jo as ArrayControlTester,
2575
+ Cr as BooleanControl,
2576
+ Sr as BooleanControlTester,
2577
+ tn as CategorizationLayoutRenderer,
2578
+ rn as CategorizationLayoutTester,
2579
+ Oo as ComputedControl,
2580
+ No as ComputedControlTester,
2581
+ Xr as DateControl,
2582
+ Kr as DateControlTester,
2583
+ sn as FileControl,
2584
+ ln as FileControlTester,
2585
+ Qr as GroupLayoutRenderer,
2586
+ en as GroupLayoutTester,
2587
+ Jr as HorizontalLayoutRenderer,
2588
+ Zr as HorizontalLayoutTester,
2589
+ Ho as LabelRenderer,
2590
+ Wo as LabelTester,
2591
+ Ar as NumberControl,
2592
+ xr as NumberControlTester,
2593
+ Nr as RadioControl,
2594
+ kr as RadioControlTester,
2595
+ jr as SearchSelectControl,
2596
+ Hr as SearchSelectControlTester,
2597
+ ti as SearchServiceProvider,
2598
+ Dr as SelectControl,
2599
+ Lr as SelectControlTester,
2600
+ Vn as SpreadsheetControl,
2601
+ jn as SpreadsheetControlTester,
2602
+ Yn as SpreadsheetExportControl,
2603
+ Gn as SpreadsheetExportControlTester,
2604
+ wr as TextControl,
2605
+ Er as TextControlTester,
2606
+ ei as UploadProvider,
2607
+ Gr as VerticalLayoutRenderer,
2608
+ qr as VerticalLayoutTester,
2609
+ ao as XmlControl,
2610
+ uo as XmlControlTester,
2611
+ bo as XmlExportControl,
2612
+ vo as XmlExportControlTester,
2613
+ ri as radixRenderers,
2614
+ vr as useSearchService,
2615
+ br as useUpload
2166
2616
  };