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