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