@nivaro/react 0.3.15 → 0.3.17

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (37) hide show
  1. package/dist/full.css +1 -1
  2. package/dist/hooks/useSessionRecorder.js +1 -1
  3. package/dist/index.d.ts +127 -6
  4. package/dist/index.js +736 -734
  5. package/dist/shared/components/CollectionBrowserView.js +2344 -2309
  6. package/dist/shared/components/ItemEditForm.js +3773 -3604
  7. package/dist/shared/components/RecordGridEditor.js +319 -282
  8. package/dist/shared/components/RecordReadView.js +202 -200
  9. package/dist/shared/components/cbv/unknown-fields.js +18 -8
  10. package/dist/shared/components/chat/ChatAnalyticsView.js +2 -2
  11. package/dist/shared/components/import/DocumentAutofillButton.js +148 -142
  12. package/dist/shared/components/item-edit/CatalogPickerField.js +264 -276
  13. package/dist/shared/components/item-edit/FieldRenderer.js +136 -133
  14. package/dist/shared/components/item-edit/FieldRow.js +198 -184
  15. package/dist/shared/components/item-edit/HeaderTools.js +107 -99
  16. package/dist/shared/components/item-edit/InlineTableField.js +138 -136
  17. package/dist/shared/components/item-edit/RecordLiveSync.js +1 -0
  18. package/dist/shared/components/item-edit/RelationCombobox.js +30 -23
  19. package/dist/shared/components/item-edit/SummaryPanel.js +334 -294
  20. package/dist/shared/components/item-edit/column-length.js +12 -0
  21. package/dist/shared/components/panels/AccessDeniedPanel.js +47 -37
  22. package/dist/shared/components/panels/ItemLockBanner.js +307 -285
  23. package/dist/shared/components/panels/PipelinePanel.js +486 -465
  24. package/dist/shared/components/panels/RevisionsPanel.js +210 -204
  25. package/dist/shared/components/pipeline/PipelineEditorView.js +1672 -1568
  26. package/dist/shared/components/profile/DelegationCard.js +178 -121
  27. package/dist/shared/components/profile/PersonActivity.js +152 -139
  28. package/dist/shared/components/queue/QueueWorklist.js +668 -659
  29. package/dist/shared/components/queue/transition-note.js +90 -0
  30. package/dist/shared/components/support/SupportRequestDialog.js +100 -89
  31. package/dist/shared/components/support/TicketDetailSheet.js +104 -91
  32. package/dist/shared/lib/autofill-runs.js +33 -26
  33. package/dist/shared/lib/draft-store.js +40 -24
  34. package/dist/shared/lib/live-queries.js +10 -9
  35. package/dist/shared/lib/request-gate.js +140 -127
  36. package/dist/shared/lib/restore-skipped.js +10 -0
  37. package/package.json +1 -1
@@ -1,17 +1,17 @@
1
- import { jsx as l, jsxs as i, Fragment as qe } from "react/jsx-runtime";
1
+ import { jsx as l, jsxs as c, Fragment as je } from "react/jsx-runtime";
2
2
  import { useQueryClient as Ne, useQuery as be } from "@tanstack/react-query";
3
- import { Loader2 as pe, X as ye, ChevronRight as je } from "lucide-react";
4
- import { useState as N, useMemo as I, useCallback as Oe, useEffect as Te } from "react";
5
- import { useNivaroClient as ke } from "../context.js";
6
- import { get as se, patch as we, post as he, del as ge } from "../lib/commands.js";
7
- import { userErrorMessage as ve } from "../lib/safe-error.js";
8
- import { cn as G } from "../lib/utils.js";
3
+ import { Loader2 as pe, X as ye, ChevronRight as Oe } from "lucide-react";
4
+ import { useState as N, useMemo as Z, useCallback as Te, useEffect as Ee } from "react";
5
+ import { useNivaroClient as we } from "../context.js";
6
+ import { get as oe, patch as ke, post as he, del as ve } from "../lib/commands.js";
7
+ import { userErrorMessage as ge } from "../lib/safe-error.js";
8
+ import { cn as X } from "../lib/utils.js";
9
9
  import { ChangeReasonDialog as _e, changeReasonChallenge as $e } from "./item-edit/ChangeReasonDialog.js";
10
- import { applyDisplayTemplate as Fe } from "./item-edit/helpers.js";
10
+ import { applyDisplayTemplate as Ae } from "./item-edit/helpers.js";
11
11
  import { RelationCombobox as xe } from "./item-edit/RelationCombobox.js";
12
12
  import { JsonMapEditor as Me } from "./JsonMapEditor.js";
13
- import { colorPair as De } from "./QueryTable.js";
14
- const J = [
13
+ import { colorPair as Fe } from "./QueryTable.js";
14
+ const W = [
15
15
  "january",
16
16
  "february",
17
17
  "march",
@@ -38,64 +38,64 @@ const J = [
38
38
  "Nov",
39
39
  "Dec"
40
40
  ];
41
- function W(t, m) {
42
- return typeof t == "string" && t.startsWith("$scope.") ? m[t.slice(7)] : Array.isArray(t) ? t.map((E) => W(E, m)) : t && typeof t == "object" ? Object.fromEntries(
43
- Object.entries(t).map(([E, c]) => [
44
- E,
45
- W(c, m)
41
+ function Y(t, m) {
42
+ return typeof t == "string" && t.startsWith("$scope.") ? m[t.slice(7)] : Array.isArray(t) ? t.map((_) => Y(_, m)) : t && typeof t == "object" ? Object.fromEntries(
43
+ Object.entries(t).map(([_, i]) => [
44
+ _,
45
+ Y(i, m)
46
46
  ])
47
47
  ) : t;
48
48
  }
49
49
  function fe(t) {
50
50
  return t === void 0 ? !0 : Array.isArray(t) ? t.some(fe) : t && typeof t == "object" ? Object.values(t).some(fe) : !1;
51
51
  }
52
- function Xe({ config: t }) {
53
- return t.browse ? /* @__PURE__ */ l(Ae, { config: t }) : /* @__PURE__ */ l(Ee, { config: t });
52
+ function Ye({ config: t }) {
53
+ return t.browse ? /* @__PURE__ */ l(Re, { config: t }) : /* @__PURE__ */ l(De, { config: t });
54
54
  }
55
- function Ee({ config: t }) {
56
- var ce, re;
57
- const m = ke(), E = Ne(), [c, f] = N({}), [O, w] = N({}), [y, $] = N([]), [S, C] = N(/* @__PURE__ */ new Set()), [H, X] = N(!1), [oe, Z] = N(null), [P, z] = N(null), [j, h] = N(null), v = (t.scope ?? []).every(
58
- (r) => c[r.field] !== null && c[r.field] !== void 0 && c[r.field] !== ""
59
- ), g = JSON.stringify(c), de = I(() => {
55
+ function De({ config: t }) {
56
+ var ce, le;
57
+ const m = we(), _ = Ne(), [i, p] = N({}), [$, k] = N({}), [S, C] = N([]), [v, x] = N(/* @__PURE__ */ new Set()), [J, L] = N(!1), [z, O] = N(null), [B, P] = N(null), [E, f] = N(null), q = (t.scope ?? []).every(
58
+ (r) => i[r.field] !== null && i[r.field] !== void 0 && i[r.field] !== ""
59
+ ), g = JSON.stringify(i), de = Z(() => {
60
60
  const r = [];
61
- for (const s of t.month_sets ?? []) for (const n of J) r.push(`${n}${s.suffix}`);
61
+ for (const s of t.month_sets ?? []) for (const n of W) r.push(`${n}${s.suffix}`);
62
62
  for (const s of t.columns ?? []) r.push(s.field);
63
63
  return r;
64
- }, [t]), { data: Y = [], isLoading: ne } = be({
64
+ }, [t]), { data: ee = [], isLoading: ne } = be({
65
65
  queryKey: ["record-grid-rows", t.collection, g],
66
66
  queryFn: () => {
67
67
  const r = {};
68
- for (const s of t.scope ?? []) r[s.field] = { _eq: c[s.field] };
68
+ for (const s of t.scope ?? []) r[s.field] = { _eq: i[s.field] };
69
69
  return m.request(
70
- se(`/items/${t.collection}`, {
70
+ oe(`/items/${t.collection}`, {
71
71
  limit: 2e3,
72
72
  ...Object.keys(r).length ? { filter: JSON.stringify(r) } : {}
73
73
  })
74
74
  ).then((s) => s.data ?? []);
75
75
  },
76
- enabled: v,
76
+ enabled: q,
77
77
  staleTime: 1e4
78
- }), { data: L = [] } = be({
78
+ }), { data: R = [] } = be({
79
79
  queryKey: ["record-grid-source", (ce = t.row_source) == null ? void 0 : ce.collection, g],
80
80
  queryFn: () => {
81
81
  const r = t.row_source;
82
82
  if (!r) return Promise.resolve([]);
83
- const s = W(r.filter, c), n = s && !fe(s) ? s : void 0;
83
+ const s = Y(r.filter, i), n = s && !fe(s) ? s : void 0;
84
84
  return m.request(
85
- se(`/items/${r.collection}`, {
85
+ oe(`/items/${r.collection}`, {
86
86
  limit: 1e3,
87
87
  ...r.sort ? { sort: r.sort } : {},
88
88
  ...n ? { filter: JSON.stringify(n) } : {}
89
89
  })
90
- ).then((p) => p.data ?? []);
90
+ ).then((h) => h.data ?? []);
91
91
  },
92
- enabled: v && !!t.row_source,
92
+ enabled: q && !!t.row_source,
93
93
  staleTime: 3e4
94
- }), _ = I(() => {
94
+ }), j = Z(() => {
95
95
  if (t.row_source) {
96
96
  const r = t.row_source;
97
- return L.map((s) => {
98
- const n = Y.find((p) => String(p[r.fk_field]) === String(s.id)) ?? null;
97
+ return R.map((s) => {
98
+ const n = ee.find((h) => String(h[r.fk_field]) === String(s.id)) ?? null;
99
99
  return {
100
100
  key: `src-${s.id}`,
101
101
  record: n,
@@ -106,91 +106,91 @@ function Ee({ config: t }) {
106
106
  });
107
107
  }
108
108
  return [
109
- ...Y.filter((r) => !S.has(String(r.id))).map((r) => ({ key: `rec-${r.id}`, record: r, isNew: !1 })),
110
- ...y.map((r) => ({ key: r, record: null, isNew: !0 }))
109
+ ...ee.filter((r) => !v.has(String(r.id))).map((r) => ({ key: `rec-${r.id}`, record: r, isNew: !1 })),
110
+ ...S.map((r) => ({ key: r, record: null, isNew: !0 }))
111
111
  ];
112
- }, [t.row_source, L, Y, y, S]), B = (r, s) => {
113
- var T, x;
114
- const n = (T = O[r.key]) == null ? void 0 : T[s];
112
+ }, [t.row_source, R, ee, S, v]), I = (r, s) => {
113
+ var A, y;
114
+ const n = (A = $[r.key]) == null ? void 0 : A[s];
115
115
  if (n !== void 0) return n;
116
- const p = (x = r.record) == null ? void 0 : x[s];
117
- return p == null ? "" : String(p);
118
- }, k = (r, s, n) => w((p) => ({ ...p, [r]: { ...p[r] ?? {}, [s]: n } })), ee = Object.values(O).some((r) => Object.keys(r).length > 0) || y.length > 0 || S.size > 0;
119
- async function A(r) {
120
- var T;
121
- X(!0), z(null);
122
- let s = 0, n = 0, p = 0;
116
+ const h = (y = r.record) == null ? void 0 : y[s];
117
+ return h == null ? "" : String(h);
118
+ }, w = (r, s, n) => k((h) => ({ ...h, [r]: { ...h[r] ?? {}, [s]: n } })), te = Object.values($).some((r) => Object.keys(r).length > 0) || S.length > 0 || v.size > 0;
119
+ async function V(r) {
120
+ var A;
121
+ L(!0), P(null);
122
+ let s = 0, n = 0, h = 0;
123
123
  try {
124
- for (const x of _) {
125
- const q = O[x.key] ?? {}, V = Object.keys(q).length > 0;
126
- if (!x.record && !V) continue;
127
- const F = {};
128
- for (const [M, D] of Object.entries(q))
129
- !de.includes(M) && !(t.key_columns ?? []).some((K) => K.field === M) || (F[M] = D === "" ? null : Number.isNaN(Number(D)) ? D : Number(D));
130
- if (t.computed_total_field && ((T = t.month_sets) != null && T.length)) {
131
- const M = t.month_sets[0];
132
- F[t.computed_total_field] = J.reduce((D, K) => {
133
- var le;
134
- const Q = `${K}${M.suffix}`, ue = q[Q] !== void 0 ? Number(q[Q]) || 0 : Number((le = x.record) == null ? void 0 : le[Q]) || 0;
124
+ for (const y of j) {
125
+ const T = $[y.key] ?? {}, G = Object.keys(T).length > 0;
126
+ if (!y.record && !G) continue;
127
+ const M = {};
128
+ for (const [F, D] of Object.entries(T))
129
+ !de.includes(F) && !(t.key_columns ?? []).some((U) => U.field === F) || (M[F] = D === "" ? null : Number.isNaN(Number(D)) ? D : Number(D));
130
+ if (t.computed_total_field && ((A = t.month_sets) != null && A.length)) {
131
+ const F = t.month_sets[0];
132
+ M[t.computed_total_field] = W.reduce((D, U) => {
133
+ var ae;
134
+ const Q = `${U}${F.suffix}`, ue = T[Q] !== void 0 ? Number(T[Q]) || 0 : Number((ae = y.record) == null ? void 0 : ae[Q]) || 0;
135
135
  return D + ue;
136
136
  }, 0);
137
137
  }
138
- if (x.record) {
139
- if (Object.keys(F).length === 0) continue;
140
- r && (F._change_reason = r), await m.request(we(`/items/${t.collection}/${x.record.id}`, F)), n++;
138
+ if (y.record) {
139
+ if (Object.keys(M).length === 0) continue;
140
+ r && (M._change_reason = r), await m.request(ke(`/items/${t.collection}/${y.record.id}`, M)), n++;
141
141
  } else {
142
- if (!V) continue;
143
- for (const M of t.scope ?? []) F[M.field] = c[M.field];
144
- t.row_source && (F[t.row_source.fk_field] = x.sourceId), await m.request(he(`/items/${t.collection}`, F)), s++;
142
+ if (!G) continue;
143
+ for (const F of t.scope ?? []) M[F.field] = i[F.field];
144
+ t.row_source && (M[t.row_source.fk_field] = y.sourceId), await m.request(he(`/items/${t.collection}`, M)), s++;
145
145
  }
146
146
  }
147
- for (const x of S)
148
- await m.request(ge(`/items/${t.collection}/${x}`)), p++;
147
+ for (const y of v)
148
+ await m.request(ve(`/items/${t.collection}/${y}`)), h++;
149
149
  if (t.after_save) {
150
- const x = W(t.after_save.params ?? {}, c);
150
+ const y = Y(t.after_save.params ?? {}, i);
151
151
  await m.request(
152
- he(`/custom-queries/${t.after_save.query_slug}/execute`, { params: x })
152
+ he(`/custom-queries/${t.after_save.query_slug}/execute`, { params: y })
153
153
  );
154
154
  }
155
- w({}), $([]), C(/* @__PURE__ */ new Set()), await E.invalidateQueries({ queryKey: ["record-grid-rows", t.collection] }), z(
156
- `Saved — ${n} updated, ${s} created${p ? `, ${p} deleted` : ""}`
155
+ k({}), C([]), x(/* @__PURE__ */ new Set()), await _.invalidateQueries({ queryKey: ["record-grid-rows", t.collection] }), P(
156
+ `Saved — ${n} updated, ${s} created${h ? `, ${h} deleted` : ""}`
157
157
  );
158
- } catch (x) {
159
- const q = $e(x);
160
- q ? (Z(q), z(null)) : z(`Save failed: ${ve(x, "unknown error")}`);
158
+ } catch (y) {
159
+ const T = $e(y);
160
+ T ? (O(T), P(null)) : P(`Save failed: ${ge(y, "unknown error")}`);
161
161
  } finally {
162
- X(!1);
162
+ L(!1);
163
163
  }
164
164
  }
165
- const te = [
165
+ const re = [
166
166
  ...(t.month_sets ?? []).flatMap(
167
- (r) => J.map((s, n) => ({ field: `${s}${r.suffix}`, label: `${Se[n]} ${r.label}` }))
167
+ (r) => W.map((s, n) => ({ field: `${s}${r.suffix}`, label: `${Se[n]} ${r.label}` }))
168
168
  ),
169
169
  ...(t.columns ?? []).map((r) => ({ field: r.field, label: r.label ?? r.field }))
170
170
  ];
171
- return /* @__PURE__ */ i("div", { className: "flex h-full flex-col gap-3 overflow-auto p-3", children: [
171
+ return /* @__PURE__ */ c("div", { className: "flex h-full flex-col gap-3 overflow-auto p-3", children: [
172
172
  /* @__PURE__ */ l(
173
173
  _e,
174
174
  {
175
- challenge: oe,
176
- onCancel: () => Z(null),
175
+ challenge: z,
176
+ onCancel: () => O(null),
177
177
  onSubmit: (r) => {
178
- Z(null), A(r);
178
+ O(null), V(r);
179
179
  }
180
180
  }
181
181
  ),
182
- /* @__PURE__ */ i("div", { className: "flex flex-wrap items-end gap-3", children: [
182
+ /* @__PURE__ */ c("div", { className: "flex flex-wrap items-end gap-3", children: [
183
183
  (t.scope ?? []).map((r) => {
184
- const s = W(r.filter, c), n = s && !fe(s) ? s : void 0;
185
- return /* @__PURE__ */ i("div", { className: "w-52", children: [
186
- /* @__PURE__ */ l("p", { className: "mb-1 text-[11px] font-medium text-slate-500", children: r.label ?? r.field.replace(/_/g, " ").replace(/\b\w/g, (p) => p.toUpperCase()) }),
184
+ const s = Y(r.filter, i), n = s && !fe(s) ? s : void 0;
185
+ return /* @__PURE__ */ c("div", { className: "w-52", children: [
186
+ /* @__PURE__ */ l("p", { className: "mb-1 text-[11px] font-medium text-slate-500", children: r.label ?? r.field.replace(/_/g, " ").replace(/\b\w/g, (h) => h.toUpperCase()) }),
187
187
  /* @__PURE__ */ l(
188
188
  xe,
189
189
  {
190
190
  collection: r.collection,
191
- value: c[r.field] ?? null,
192
- onChange: (p) => {
193
- f((T) => ({ ...T, [r.field]: p })), w({}), $([]), C(/* @__PURE__ */ new Set());
191
+ value: i[r.field] ?? null,
192
+ onChange: (h) => {
193
+ p((A) => ({ ...A, [r.field]: h })), k({}), C([]), x(/* @__PURE__ */ new Set());
194
194
  },
195
195
  extraFilter: n,
196
196
  placeholder: "Select…"
@@ -198,31 +198,31 @@ function Ee({ config: t }) {
198
198
  )
199
199
  ] }, r.field);
200
200
  }),
201
- /* @__PURE__ */ i(
201
+ /* @__PURE__ */ c(
202
202
  "button",
203
203
  {
204
204
  type: "button",
205
- disabled: !v || !ee || H,
206
- onClick: () => void A(),
205
+ disabled: !q || !te || J,
206
+ onClick: () => void V(),
207
207
  className: "inline-flex h-9 items-center gap-1.5 rounded-md bg-nvr-cyan px-3 text-[13px] font-medium text-white hover:brightness-110 disabled:opacity-50",
208
208
  children: [
209
- H && /* @__PURE__ */ l(pe, { className: "h-3.5 w-3.5 animate-spin" }),
209
+ J && /* @__PURE__ */ l(pe, { className: "h-3.5 w-3.5 animate-spin" }),
210
210
  "Save changes"
211
211
  ]
212
212
  }
213
213
  ),
214
- t.allow_add && v && /* @__PURE__ */ l(
214
+ t.allow_add && q && /* @__PURE__ */ l(
215
215
  "button",
216
216
  {
217
217
  type: "button",
218
- onClick: () => $((r) => [...r, `new-${r.length}-${Math.random().toString(36).slice(2, 8)}`]),
218
+ onClick: () => C((r) => [...r, `new-${r.length}-${Math.random().toString(36).slice(2, 8)}`]),
219
219
  className: "inline-flex h-9 items-center rounded-md border border-slate-200 bg-white px-3 text-[13px] text-slate-700 hover:border-slate-400 dark:border-border dark:bg-card dark:text-slate-200",
220
220
  children: "+ Add row"
221
221
  }
222
222
  ),
223
223
  (t.toolbar_editors ?? []).map((r, s) => {
224
224
  const n = (r.require_scope ?? []).every(
225
- (p) => c[p] !== null && c[p] !== void 0 && c[p] !== ""
225
+ (h) => i[h] !== null && i[h] !== void 0 && i[h] !== ""
226
226
  );
227
227
  return /* @__PURE__ */ l(
228
228
  "button",
@@ -230,53 +230,53 @@ function Ee({ config: t }) {
230
230
  type: "button",
231
231
  disabled: !n,
232
232
  title: n ? void 0 : `Choose ${(r.require_scope ?? []).join(", ")} first`,
233
- onClick: () => h(s),
233
+ onClick: () => f(s),
234
234
  className: "inline-flex h-9 items-center rounded-md border border-slate-200 bg-white px-3 text-[13px] text-slate-700 hover:border-slate-400 disabled:opacity-50 dark:border-border dark:bg-card dark:text-slate-200",
235
235
  children: r.button_label
236
236
  },
237
237
  r.button_label
238
238
  );
239
239
  }),
240
- P && /* @__PURE__ */ l("span", { className: "pb-2 text-[12px] text-slate-500", children: P })
240
+ B && /* @__PURE__ */ l("span", { className: "pb-2 text-[12px] text-slate-500", children: B })
241
241
  ] }),
242
- j !== null && ((re = t.toolbar_editors) == null ? void 0 : re[j]) && /* @__PURE__ */ l(
242
+ E !== null && ((le = t.toolbar_editors) == null ? void 0 : le[E]) && /* @__PURE__ */ l(
243
243
  "div",
244
244
  {
245
245
  className: "fixed inset-0 z-[60] flex justify-end bg-black/30",
246
- onClick: () => h(null),
247
- children: /* @__PURE__ */ i(
246
+ onClick: () => f(null),
247
+ children: /* @__PURE__ */ c(
248
248
  "div",
249
249
  {
250
250
  className: "flex h-full flex-col border-l border-slate-200 bg-white shadow-2xl dark:border-border dark:bg-background",
251
251
  style: {
252
- width: typeof t.toolbar_editors[j].sheet_width == "number" ? `${t.toolbar_editors[j].sheet_width}px` : t.toolbar_editors[j].sheet_width ?? "70%",
252
+ width: typeof t.toolbar_editors[E].sheet_width == "number" ? `${t.toolbar_editors[E].sheet_width}px` : t.toolbar_editors[E].sheet_width ?? "70%",
253
253
  maxWidth: "96%"
254
254
  },
255
255
  onClick: (r) => r.stopPropagation(),
256
256
  children: [
257
- /* @__PURE__ */ i("div", { className: "flex shrink-0 items-center justify-between border-b border-slate-200 px-4 py-2.5 dark:border-border", children: [
258
- /* @__PURE__ */ l("p", { className: "text-[13px] font-semibold text-slate-700 dark:text-slate-200", children: t.toolbar_editors[j].button_label }),
257
+ /* @__PURE__ */ c("div", { className: "flex shrink-0 items-center justify-between border-b border-slate-200 px-4 py-2.5 dark:border-border", children: [
258
+ /* @__PURE__ */ l("p", { className: "text-[13px] font-semibold text-slate-700 dark:text-slate-200", children: t.toolbar_editors[E].button_label }),
259
259
  /* @__PURE__ */ l(
260
260
  "button",
261
261
  {
262
262
  type: "button",
263
- onClick: () => h(null),
263
+ onClick: () => f(null),
264
264
  className: "rounded px-2 py-1 text-[12px] text-slate-500 hover:bg-slate-100 hover:text-slate-700 dark:hover:bg-muted",
265
265
  children: "Close"
266
266
  }
267
267
  )
268
268
  ] }),
269
- /* @__PURE__ */ l("div", { className: "min-h-0 flex-1 overflow-auto", children: /* @__PURE__ */ l(Me, { config: t.toolbar_editors[j].json_map, scope: c }) })
269
+ /* @__PURE__ */ l("div", { className: "min-h-0 flex-1 overflow-auto", children: /* @__PURE__ */ l(Me, { config: t.toolbar_editors[E].json_map, scope: i }) })
270
270
  ]
271
271
  }
272
272
  )
273
273
  }
274
274
  ),
275
- v ? ne ? /* @__PURE__ */ i("div", { className: "flex items-center gap-2 text-[12px] text-slate-400", children: [
275
+ q ? ne ? /* @__PURE__ */ c("div", { className: "flex items-center gap-2 text-[12px] text-slate-400", children: [
276
276
  /* @__PURE__ */ l(pe, { className: "h-4 w-4 animate-spin" }),
277
277
  " Loading…"
278
- ] }) : /* @__PURE__ */ l("div", { className: "overflow-x-auto", children: /* @__PURE__ */ i("table", { className: "w-full text-[12px]", children: [
279
- /* @__PURE__ */ l("thead", { children: /* @__PURE__ */ i("tr", { className: "border-b border-slate-200 text-left dark:border-border", children: [
278
+ ] }) : /* @__PURE__ */ l("div", { className: "overflow-x-auto", children: /* @__PURE__ */ c("table", { className: "w-full text-[12px]", children: [
279
+ /* @__PURE__ */ l("thead", { children: /* @__PURE__ */ c("tr", { className: "border-b border-slate-200 text-left dark:border-border", children: [
280
280
  t.row_source && /* @__PURE__ */ l("th", { className: "py-1.5 pr-3 font-medium text-slate-500", children: t.row_source.label_field.replace(/_/g, " ") }),
281
281
  (t.key_columns ?? []).map((r) => /* @__PURE__ */ l(
282
282
  "th",
@@ -286,7 +286,7 @@ function Ee({ config: t }) {
286
286
  },
287
287
  r.field
288
288
  )),
289
- te.map((r) => /* @__PURE__ */ l(
289
+ re.map((r) => /* @__PURE__ */ l(
290
290
  "th",
291
291
  {
292
292
  className: "min-w-[86px] py-1.5 pr-2 text-right font-medium text-slate-500",
@@ -296,9 +296,9 @@ function Ee({ config: t }) {
296
296
  )),
297
297
  t.allow_delete && /* @__PURE__ */ l("th", { "aria-label": "Remove" })
298
298
  ] }) }),
299
- /* @__PURE__ */ i("tbody", { children: [
300
- _.map((r) => /* @__PURE__ */ i("tr", { className: "border-b border-slate-100 dark:border-border/50", children: [
301
- t.row_source && /* @__PURE__ */ i("td", { className: "whitespace-nowrap py-1 pr-3 font-medium text-slate-700 dark:text-slate-200", children: [
299
+ /* @__PURE__ */ c("tbody", { children: [
300
+ j.map((r) => /* @__PURE__ */ c("tr", { className: "border-b border-slate-100 dark:border-border/50", children: [
301
+ t.row_source && /* @__PURE__ */ c("td", { className: "whitespace-nowrap py-1 pr-3 font-medium text-slate-700 dark:text-slate-200", children: [
302
302
  r.sourceLabel,
303
303
  r.isNew && /* @__PURE__ */ l("span", { className: "ml-1.5 text-[10px] text-slate-400", children: "(new)" })
304
304
  ] }),
@@ -306,17 +306,21 @@ function Ee({ config: t }) {
306
306
  xe,
307
307
  {
308
308
  collection: s.collection,
309
- value: B(r, s.field) || null,
310
- onChange: (n) => k(r.key, s.field, n == null ? "" : String(n)),
309
+ value: I(r, s.field) || null,
310
+ onChange: (n) => w(r.key, s.field, n == null ? "" : String(n)),
311
311
  placeholder: "Select…"
312
312
  }
313
313
  ) }, s.field)),
314
- te.map((s) => /* @__PURE__ */ l("td", { className: "py-0.5 pr-2 text-right", children: /* @__PURE__ */ l(
314
+ re.map((s) => /* @__PURE__ */ l("td", { className: "py-0.5 pr-2 text-right", children: /* @__PURE__ */ l(
315
315
  "input",
316
316
  {
317
317
  type: "number",
318
- value: B(r, s.field),
319
- onChange: (n) => k(r.key, s.field, n.target.value),
318
+ min: t.allow_negative ? void 0 : 0,
319
+ value: I(r, s.field),
320
+ title: t.allow_negative ? void 0 : Ce,
321
+ onChange: (n) => {
322
+ !t.allow_negative && n.target.value.trim().startsWith("-") || w(r.key, s.field, n.target.value);
323
+ },
320
324
  className: "h-7 w-[84px] rounded border border-slate-200 bg-white px-1.5 text-right text-[12px] tabular-nums outline-none focus:border-nvr-cyan dark:border-border dark:bg-background"
321
325
  }
322
326
  ) }, s.field)),
@@ -325,10 +329,10 @@ function Ee({ config: t }) {
325
329
  {
326
330
  type: "button",
327
331
  onClick: () => {
328
- r.record ? C((s) => {
332
+ r.record ? x((s) => {
329
333
  var n;
330
334
  return new Set(s).add(String((n = r.record) == null ? void 0 : n.id));
331
- }) : $((s) => s.filter((n) => n !== r.key)), w((s) => {
335
+ }) : C((s) => s.filter((n) => n !== r.key)), k((s) => {
332
336
  const n = { ...s };
333
337
  return delete n[r.key], n;
334
338
  });
@@ -338,53 +342,82 @@ function Ee({ config: t }) {
338
342
  }
339
343
  ) })
340
344
  ] }, r.key)),
341
- _.length === 0 && /* @__PURE__ */ l("tr", { children: /* @__PURE__ */ l("td", { colSpan: 99, className: "py-3 text-center text-[12px] text-slate-400", children: "No rows" }) })
345
+ j.length === 0 && /* @__PURE__ */ l("tr", { children: /* @__PURE__ */ l("td", { colSpan: 99, className: "py-3 text-center text-[12px] text-slate-400", children: "No rows" }) })
342
346
  ] }),
343
- /* @__PURE__ */ l("tfoot", { children: /* @__PURE__ */ i("tr", { className: "border-t border-slate-300 font-semibold dark:border-border", children: [
347
+ /* @__PURE__ */ l("tfoot", { children: /* @__PURE__ */ c("tr", { className: "border-t border-slate-300 font-semibold dark:border-border", children: [
344
348
  t.row_source && /* @__PURE__ */ l("td", { className: "py-1.5 pr-3", children: "Total" }),
345
349
  (t.key_columns ?? []).map((r, s) => /* @__PURE__ */ l("td", { className: "py-1.5 pr-3", children: !t.row_source && s === 0 ? "Total" : "" }, r.field)),
346
- te.map((r) => /* @__PURE__ */ l("td", { className: "py-1.5 pr-2 text-right tabular-nums", children: _.reduce((s, n) => s + (Number(B(n, r.field)) || 0), 0).toLocaleString("en-US", { maximumFractionDigits: 2 }) }, r.field)),
350
+ re.map((r) => /* @__PURE__ */ l("td", { className: "py-1.5 pr-2 text-right tabular-nums", children: j.reduce((s, n) => s + (Number(I(n, r.field)) || 0), 0).toLocaleString("en-US", { maximumFractionDigits: 2 }) }, r.field)),
347
351
  t.allow_delete && /* @__PURE__ */ l("td", {})
348
352
  ] }) })
349
- ] }) }) : /* @__PURE__ */ i("p", { className: "text-[12px] text-slate-400", children: [
353
+ ] }) }) : /* @__PURE__ */ c("p", { className: "text-[12px] text-slate-400", children: [
350
354
  "Choose ",
351
355
  (t.scope ?? []).map((r) => r.label ?? r.field).join(", "),
352
356
  " to load rows."
353
357
  ] })
354
358
  ] });
355
359
  }
356
- const R = (t, m) => t == null || !Number.isFinite(t) || m != null && m.blankZero && t === 0 ? "—" : t.toLocaleString("en-US", { minimumFractionDigits: 2, maximumFractionDigits: 2 });
357
- function Le({
360
+ const K = (t, m) => t == null || !Number.isFinite(t) || m != null && m.blankZero && t === 0 ? "—" : t.toLocaleString("en-US", { minimumFractionDigits: 2, maximumFractionDigits: 2 }), Ce = "Enter an amount of zero or more";
361
+ function Le(t, m) {
362
+ const _ = t.replace(/[^\d.-]/g, "");
363
+ if (_.includes("-") && !m) return { value: null, refused: Ce };
364
+ const i = _.startsWith("-") ? "-" : "", p = _.replace(/-/g, ""), $ = p.indexOf("."), k = $ < 0 ? p : `${p.slice(0, $ + 1)}${p.slice($ + 1).replace(/\./g, "")}`;
365
+ return { value: `${i}${k}`, refused: null };
366
+ }
367
+ function ze({
358
368
  value: t,
359
369
  original: m,
360
- onChange: E,
361
- disabled: c
370
+ onChange: _,
371
+ disabled: i,
372
+ allowNegative: p = !1
362
373
  }) {
363
- const [f, O] = N(!1), w = t !== m, y = t === "" ? null : Number(t), $ = f || y == null || Number.isNaN(y) ? t : R(y), S = w && y != null && !Number.isNaN(y) ? y - (Number(m) || 0) : 0;
364
- return /* @__PURE__ */ l(
365
- "input",
366
- {
367
- type: "text",
368
- inputMode: "decimal",
369
- value: $,
370
- disabled: c,
371
- title: w ? `Was ${R(Number(m) || 0)} (${S >= 0 ? "+" : "−"}${R(Math.abs(S))})` : void 0,
372
- onFocus: () => O(!0),
373
- onBlur: () => O(!1),
374
- onChange: (C) => E(C.target.value.replace(/[^\d.-]/g, "")),
375
- className: G(
376
- "h-7 w-[92px] rounded-md border bg-white px-1.5 text-right text-[12px] tabular-nums outline-none transition-colors focus:border-nvr-cyan disabled:bg-transparent dark:bg-background",
377
- w ? "border-nvr-cyan bg-nvr-cyan/[0.06] dark:bg-nvr-cyan/10" : "border-slate-200 dark:border-border",
378
- !w && (y === 0 || y == null) && "text-slate-400"
379
- )
380
- }
381
- );
374
+ const [$, k] = N(!1), [S, C] = N(null), v = t !== m, x = t === "" ? null : Number(t), J = $ || x == null || Number.isNaN(x) ? t : K(x), L = v && x != null && !Number.isNaN(x) ? x - (Number(m) || 0) : 0;
375
+ return /* @__PURE__ */ c("span", { className: "relative inline-block", children: [
376
+ /* @__PURE__ */ l(
377
+ "input",
378
+ {
379
+ type: "text",
380
+ inputMode: "decimal",
381
+ value: J,
382
+ disabled: i,
383
+ "aria-invalid": S ? !0 : void 0,
384
+ title: S ?? (v ? `Was ${K(Number(m) || 0)} (${L >= 0 ? "+" : "−"}${K(Math.abs(L))})` : void 0),
385
+ onFocus: (z) => {
386
+ k(!0);
387
+ const O = z.currentTarget;
388
+ requestAnimationFrame(() => {
389
+ document.activeElement === O && O.select();
390
+ });
391
+ },
392
+ onBlur: () => {
393
+ k(!1), C(null);
394
+ },
395
+ onChange: (z) => {
396
+ const O = Le(z.target.value, p);
397
+ C(O.refused), O.value != null && _(O.value);
398
+ },
399
+ className: X(
400
+ "h-7 w-[92px] rounded-md border bg-white px-1.5 text-right text-[12px] tabular-nums outline-none transition-colors focus:border-nvr-cyan disabled:bg-transparent dark:bg-background",
401
+ S ? "border-red-400 focus:border-red-400" : v ? "border-nvr-cyan bg-nvr-cyan/[0.06] dark:bg-nvr-cyan/10" : "border-slate-200 dark:border-border",
402
+ !v && (x === 0 || x == null) && "text-slate-400"
403
+ )
404
+ }
405
+ ),
406
+ S && /* @__PURE__ */ l(
407
+ "span",
408
+ {
409
+ role: "alert",
410
+ className: "absolute right-0 top-full z-10 mt-0.5 whitespace-nowrap rounded bg-red-600 px-1.5 py-0.5 text-[10.5px] font-medium text-white shadow",
411
+ children: S
412
+ }
413
+ )
414
+ ] });
382
415
  }
383
- function Ae({ config: t }) {
384
- var ue, le;
385
- const m = ke(), E = Ne(), c = t.key_columns ?? [], [f, O] = N({}), [w, y] = N({}), [$, S] = N([]), [C, H] = N(/* @__PURE__ */ new Set()), [X, oe] = N(!1), [Z, P] = N(null), [z, j] = N(null), h = c.length > 0 && c.every((e) => f[e.field] != null && f[e.field] !== ""), v = I(() => {
416
+ function Re({ config: t }) {
417
+ var ue, ae;
418
+ const m = we(), _ = Ne(), i = t.key_columns ?? [], [p, $] = N({}), [k, S] = N({}), [C, v] = N([]), [x, J] = N(/* @__PURE__ */ new Set()), [L, z] = N(!1), [O, B] = N(null), [P, E] = N(null), f = i.length > 0 && i.every((e) => p[e.field] != null && p[e.field] !== ""), q = Z(() => {
386
419
  const e = (t.month_sets ?? []).flatMap(
387
- (a) => J.map((d, u) => ({
420
+ (a) => W.map((d, u) => ({
388
421
  field: `${d}${a.suffix}`,
389
422
  label: `${Se[u]}${a.label ? ` ${a.label}` : ""}`
390
423
  }))
@@ -393,170 +426,170 @@ function Ae({ config: t }) {
393
426
  label: a.label ?? a.field
394
427
  }));
395
428
  return [...e, ...o];
396
- }, [t.month_sets, t.columns]), g = (ue = t.month_sets) == null ? void 0 : ue[0], { data: de = [], isLoading: Y } = be({
429
+ }, [t.month_sets, t.columns]), g = (ue = t.month_sets) == null ? void 0 : ue[0], { data: de = [], isLoading: ee } = be({
397
430
  queryKey: ["record-grid-browse-rows", t.collection],
398
431
  queryFn: () => m.request(
399
- se(`/items/${t.collection}`, { limit: 5e3 })
432
+ oe(`/items/${t.collection}`, { limit: 5e3 })
400
433
  ).then((e) => e.data ?? []),
401
434
  staleTime: 1e4
402
435
  }), { data: ne = {} } = be({
403
- queryKey: ["record-grid-browse-labels", c.map((e) => e.collection).join(",")],
436
+ queryKey: ["record-grid-browse-labels", i.map((e) => e.collection).join(",")],
404
437
  queryFn: async () => {
405
438
  const e = {};
406
439
  return await Promise.all(
407
- c.map(async (o) => {
440
+ i.map(async (o) => {
408
441
  const a = await m.request(
409
- se(`/collections/${o.collection}`)
442
+ oe(`/collections/${o.collection}`)
410
443
  ).then((b) => b.data).catch(() => null), d = await m.request(
411
- se(`/items/${o.collection}`, { limit: 1e3 })
444
+ oe(`/items/${o.collection}`, { limit: 1e3 })
412
445
  ).then((b) => b.data ?? []).catch(() => []), u = /* @__PURE__ */ new Map();
413
446
  for (const b of d)
414
- u.set(String(b.id), Fe(a == null ? void 0 : a.display_template, b) || String(b.id));
447
+ u.set(String(b.id), Ae(a == null ? void 0 : a.display_template, b) || String(b.id));
415
448
  e[o.field] = u;
416
449
  })
417
450
  ), e;
418
451
  },
419
- enabled: c.length > 0,
452
+ enabled: i.length > 0,
420
453
  staleTime: 3e5
421
- }), L = Oe(
454
+ }), R = Te(
422
455
  (e, o) => {
423
456
  var a;
424
457
  return o == null ? "—" : ((a = ne[e]) == null ? void 0 : a.get(String(o))) ?? String(o);
425
458
  },
426
459
  [ne]
427
- ), _ = I(
460
+ ), j = Z(
428
461
  () => de.filter(
429
- (e) => c.every(
430
- (o) => f[o.field] == null || f[o.field] === "" || String(e[o.field]) === String(f[o.field])
462
+ (e) => i.every(
463
+ (o) => p[o.field] == null || p[o.field] === "" || String(e[o.field]) === String(p[o.field])
431
464
  )
432
465
  ),
433
- [de, c, f]
434
- ), B = (le = c[0]) == null ? void 0 : le.field, k = c.filter((e) => f[e.field] == null || f[e.field] === ""), ee = I(() => {
435
- if (h) return [];
466
+ [de, i, p]
467
+ ), I = (ae = i[0]) == null ? void 0 : ae.field, w = i.filter((e) => p[e.field] == null || p[e.field] === ""), te = Z(() => {
468
+ if (f) return [];
436
469
  const e = /* @__PURE__ */ new Map();
437
- for (const o of _) {
470
+ for (const o of j) {
438
471
  const a = {};
439
- for (const b of k) a[b.field] = o[b.field];
440
- const d = k.map((b) => String(o[b.field] ?? "")).join("|"), u = e.get(d) ?? { keyVals: a, sums: {}, count: 0 };
441
- for (const b of v)
472
+ for (const b of w) a[b.field] = o[b.field];
473
+ const d = w.map((b) => String(o[b.field] ?? "")).join("|"), u = e.get(d) ?? { keyVals: a, sums: {}, count: 0 };
474
+ for (const b of q)
442
475
  u.sums[b.field] = (u.sums[b.field] ?? 0) + (Number(o[b.field]) || 0);
443
476
  u.count++, e.set(d, u);
444
477
  }
445
478
  return [...e.values()].sort((o, a) => {
446
- for (const d of k) {
447
- const u = L(d.field, o.keyVals[d.field]).localeCompare(
448
- L(d.field, a.keyVals[d.field]),
479
+ for (const d of w) {
480
+ const u = R(d.field, o.keyVals[d.field]).localeCompare(
481
+ R(d.field, a.keyVals[d.field]),
449
482
  void 0,
450
483
  { numeric: !0 }
451
484
  );
452
- if (u) return d.field === B ? -u : u;
485
+ if (u) return d.field === I ? -u : u;
453
486
  }
454
487
  return 0;
455
488
  });
456
- }, [_, k, h, v, L, B]), A = I(() => h ? [
457
- ..._.filter((e) => !C.has(String(e.id))).map((e) => ({ key: `rec-${e.id}`, record: e, isNew: !1 })),
458
- ...$.map((e) => ({ key: e, record: null, isNew: !0 }))
459
- ] : [], [_, h, $, C]);
460
- Te(() => {
461
- h && _.length === 0 && $.length === 0 && C.size === 0 && S([`new-${Date.now()}`]);
462
- }, [h, _.length, $.length, C.size]);
489
+ }, [j, w, f, q, R, I]), V = Z(() => f ? [
490
+ ...j.filter((e) => !x.has(String(e.id))).map((e) => ({ key: `rec-${e.id}`, record: e, isNew: !1 })),
491
+ ...C.map((e) => ({ key: e, record: null, isNew: !0 }))
492
+ ] : [], [j, f, C, x]);
493
+ Ee(() => {
494
+ f && j.length === 0 && C.length === 0 && x.size === 0 && v([`new-${Date.now()}`]);
495
+ }, [f, j.length, C.length, x.size]);
463
496
  const ie = (e, o) => {
464
497
  var u, b;
465
- const a = (u = w[e.key]) == null ? void 0 : u[o];
498
+ const a = (u = k[e.key]) == null ? void 0 : u[o];
466
499
  if (a !== void 0) return a;
467
500
  const d = (b = e.record) == null ? void 0 : b[o];
468
501
  return d == null ? "" : String(d);
469
- }, te = (e, o) => {
502
+ }, re = (e, o) => {
470
503
  var d;
471
504
  const a = (d = e.record) == null ? void 0 : d[o];
472
505
  return a == null ? "" : String(a);
473
- }, ce = (e, o, a) => y((d) => ({ ...d, [e]: { ...d[e] ?? {}, [o]: a } })), re = (e) => g ? J.reduce((o, a) => o + (Number(ie(e, `${a}${g.suffix}`)) || 0), 0) : null, r = Object.values(w).some((e) => Object.keys(e).length > 0) || C.size > 0 || $.some((e) => Object.keys(w[e] ?? {}).length > 0), s = () => {
474
- y({}), S([]), H(/* @__PURE__ */ new Set());
506
+ }, ce = (e, o, a) => S((d) => ({ ...d, [e]: { ...d[e] ?? {}, [o]: a } })), le = (e) => g ? W.reduce((o, a) => o + (Number(ie(e, `${a}${g.suffix}`)) || 0), 0) : null, r = Object.values(k).some((e) => Object.keys(e).length > 0) || x.size > 0 || C.some((e) => Object.keys(k[e] ?? {}).length > 0), s = () => {
507
+ S({}), v([]), J(/* @__PURE__ */ new Set());
475
508
  }, n = (e) => {
476
- O((o) => ({ ...o, ...e })), s();
477
- }, p = (e, o) => {
478
- O((a) => ({ ...a, [e]: o })), s();
509
+ $((o) => ({ ...o, ...e })), s();
510
+ }, h = (e, o) => {
511
+ $((a) => ({ ...a, [e]: o })), s();
479
512
  };
480
- async function T(e) {
481
- oe(!0), j(null);
513
+ async function A(e) {
514
+ z(!0), E(null);
482
515
  let o = 0, a = 0, d = 0;
483
516
  try {
484
- for (const u of A) {
485
- const b = w[u.key] ?? {};
517
+ for (const u of V) {
518
+ const b = k[u.key] ?? {};
486
519
  if (Object.keys(b).length === 0) continue;
487
- const U = {};
488
- for (const [ae, me] of Object.entries(b))
489
- v.some((Ce) => Ce.field === ae) && (U[ae] = me === "" ? null : Number.isNaN(Number(me)) ? me : Number(me));
490
- if (t.computed_total_field && g && (U[t.computed_total_field] = re(u)), u.record)
491
- e && (U._change_reason = e), await m.request(we(`/items/${t.collection}/${u.record.id}`, U)), a++;
520
+ const H = {};
521
+ for (const [se, me] of Object.entries(b))
522
+ q.some((qe) => qe.field === se) && (H[se] = me === "" ? null : Number.isNaN(Number(me)) ? me : Number(me));
523
+ if (t.computed_total_field && g && (H[t.computed_total_field] = le(u)), u.record)
524
+ e && (H._change_reason = e), await m.request(ke(`/items/${t.collection}/${u.record.id}`, H)), a++;
492
525
  else {
493
- for (const ae of c) U[ae.field] = f[ae.field];
494
- await m.request(he(`/items/${t.collection}`, U)), o++;
526
+ for (const se of i) H[se.field] = p[se.field];
527
+ await m.request(he(`/items/${t.collection}`, H)), o++;
495
528
  }
496
529
  }
497
- for (const u of C)
498
- await m.request(ge(`/items/${t.collection}/${u}`)), d++;
530
+ for (const u of x)
531
+ await m.request(ve(`/items/${t.collection}/${u}`)), d++;
499
532
  if (t.after_save) {
500
- const u = W(t.after_save.params ?? {}, f);
533
+ const u = Y(t.after_save.params ?? {}, p);
501
534
  await m.request(
502
535
  he(`/custom-queries/${t.after_save.query_slug}/execute`, { params: u })
503
536
  );
504
537
  }
505
- s(), await E.invalidateQueries({ queryKey: ["record-grid-browse-rows", t.collection] }), j(
538
+ s(), await _.invalidateQueries({ queryKey: ["record-grid-browse-rows", t.collection] }), E(
506
539
  `Saved — ${a} updated, ${o} created${d ? `, ${d} deleted` : ""}`
507
540
  );
508
541
  } catch (u) {
509
542
  const b = $e(u);
510
- b ? P(b) : j(`Save failed: ${ve(u, "unknown error")}`);
543
+ b ? B(b) : E(`Save failed: ${ge(u, "unknown error")}`);
511
544
  } finally {
512
- oe(!1);
545
+ z(!1);
513
546
  }
514
547
  }
515
- const x = (e) => h ? A.reduce((o, a) => o + (Number(ie(a, e)) || 0), 0) : ee.reduce((o, a) => o + (a.sums[e] ?? 0), 0), q = (e) => g && e < 12 && e % 3 === 0 && e > 0, V = (e) => g && e < 12 && Math.floor(e / 3) % 2 === 1 ? "bg-slate-50/70 dark:bg-muted/30" : "", [F, M] = De("accent"), D = { "--qtc": F, "--qtcd": M }, K = "text-[color:var(--qtc)] dark:text-[color:var(--qtcd)]", Q = (e, o, a = "") => /* @__PURE__ */ l(
548
+ const y = (e) => f ? V.reduce((o, a) => o + (Number(ie(a, e)) || 0), 0) : te.reduce((o, a) => o + (a.sums[e] ?? 0), 0), T = (e) => g && e < 12 && e % 3 === 0 && e > 0, G = (e) => g && e < 12 && Math.floor(e / 3) % 2 === 1 ? "bg-slate-50/70 dark:bg-muted/30" : "", [M, F] = Fe("accent"), D = { "--qtc": M, "--qtcd": F }, U = "text-[color:var(--qtc)] dark:text-[color:var(--qtcd)]", Q = (e, o, a = "") => /* @__PURE__ */ l(
516
549
  "th",
517
550
  {
518
- className: G(
551
+ className: X(
519
552
  "whitespace-nowrap px-2 py-2 text-right text-[10.5px] font-semibold uppercase tracking-wide text-slate-400",
520
- q(o) && "border-l border-slate-200 dark:border-border",
521
- V(o),
553
+ T(o) && "border-l border-slate-200 dark:border-border",
554
+ G(o),
522
555
  a
523
556
  ),
524
557
  children: e
525
558
  },
526
559
  e + o
527
560
  );
528
- return /* @__PURE__ */ i("div", { className: "flex h-full min-h-0 flex-col", "data-record-grid-browse": !0, children: [
561
+ return /* @__PURE__ */ c("div", { className: "flex h-full min-h-0 flex-col", "data-record-grid-browse": !0, children: [
529
562
  /* @__PURE__ */ l(
530
563
  _e,
531
564
  {
532
- challenge: Z,
533
- onCancel: () => P(null),
565
+ challenge: O,
566
+ onCancel: () => B(null),
534
567
  onSubmit: (e) => {
535
- P(null), T(e);
568
+ B(null), A(e);
536
569
  }
537
570
  }
538
571
  ),
539
- /* @__PURE__ */ i("div", { className: "flex shrink-0 flex-wrap items-end gap-3 border-b border-slate-200 bg-white px-4 py-3 dark:border-border dark:bg-card", children: [
540
- c.map((e) => /* @__PURE__ */ i("div", { className: "w-52", children: [
572
+ /* @__PURE__ */ c("div", { className: "flex shrink-0 flex-wrap items-end gap-3 border-b border-slate-200 bg-white px-4 py-3 dark:border-border dark:bg-card", children: [
573
+ i.map((e) => /* @__PURE__ */ c("div", { className: "w-52", children: [
541
574
  /* @__PURE__ */ l("p", { className: "mb-1 text-[11px] font-medium text-slate-500 dark:text-slate-400", children: e.label ?? e.field }),
542
575
  /* @__PURE__ */ l(
543
576
  xe,
544
577
  {
545
578
  collection: e.collection,
546
- value: f[e.field] ?? null,
547
- onChange: (o) => p(e.field, o),
579
+ value: p[e.field] ?? null,
580
+ onChange: (o) => h(e.field, o),
548
581
  placeholder: "All",
549
582
  optionSort: e.collection === "funding_years" ? "-id" : void 0
550
583
  }
551
584
  )
552
585
  ] }, e.field)),
553
586
  /* @__PURE__ */ l("span", { className: "flex-1" }),
554
- z && /* @__PURE__ */ l("span", { className: "pb-2 text-[12px] text-slate-500", children: z }),
555
- h && t.allow_add && /* @__PURE__ */ l(
587
+ P && /* @__PURE__ */ l("span", { className: "pb-2 text-[12px] text-slate-500", children: P }),
588
+ f && t.allow_add && /* @__PURE__ */ l(
556
589
  "button",
557
590
  {
558
591
  type: "button",
559
- onClick: () => S((e) => [...e, `new-${Date.now()}`]),
592
+ onClick: () => v((e) => [...e, `new-${Date.now()}`]),
560
593
  className: "h-9 rounded-md border border-slate-200 bg-white px-3 text-[13px] text-slate-700 hover:border-slate-400 dark:border-border dark:bg-card dark:text-slate-200",
561
594
  children: "+ Add row"
562
595
  }
@@ -570,48 +603,48 @@ function Ae({ config: t }) {
570
603
  children: "Discard"
571
604
  }
572
605
  ),
573
- /* @__PURE__ */ i(
606
+ /* @__PURE__ */ c(
574
607
  "button",
575
608
  {
576
609
  type: "button",
577
- disabled: !h || !r || X,
578
- onClick: () => void T(),
610
+ disabled: !f || !r || L,
611
+ onClick: () => void A(),
579
612
  "data-record-grid-save": !0,
580
613
  className: "inline-flex h-9 items-center gap-1.5 rounded-md bg-nvr-cyan px-3.5 text-[13px] font-semibold text-[#172940] hover:bg-nvr-cyan-dark disabled:opacity-50",
581
614
  children: [
582
- X && /* @__PURE__ */ l(pe, { className: "h-3.5 w-3.5 animate-spin" }),
615
+ L && /* @__PURE__ */ l(pe, { className: "h-3.5 w-3.5 animate-spin" }),
583
616
  "Save changes"
584
617
  ]
585
618
  }
586
619
  )
587
620
  ] }),
588
- /* @__PURE__ */ i("div", { className: "flex shrink-0 items-center gap-2 border-b border-slate-200 bg-slate-50 px-4 py-1.5 text-[12px] text-slate-500 dark:border-border dark:bg-muted/40 dark:text-slate-400", children: [
589
- h ? /* @__PURE__ */ i("span", { children: [
621
+ /* @__PURE__ */ c("div", { className: "flex shrink-0 items-center gap-2 border-b border-slate-200 bg-slate-50 px-4 py-1.5 text-[12px] text-slate-500 dark:border-border dark:bg-muted/40 dark:text-slate-400", children: [
622
+ f ? /* @__PURE__ */ c("span", { children: [
590
623
  "Editing",
591
624
  " ",
592
- /* @__PURE__ */ l("strong", { className: "text-slate-700 dark:text-slate-200", children: c.map((e) => L(e.field, f[e.field])).join(" · ") }),
593
- A.length > 1 && ` — ${A.length} rows share this combination`
594
- ] }) : /* @__PURE__ */ i("span", { children: [
625
+ /* @__PURE__ */ l("strong", { className: "text-slate-700 dark:text-slate-200", children: i.map((e) => R(e.field, p[e.field])).join(" · ") }),
626
+ V.length > 1 && ` — ${V.length} rows share this combination`
627
+ ] }) : /* @__PURE__ */ c("span", { children: [
595
628
  "Totals across",
596
629
  " ",
597
- /* @__PURE__ */ l("strong", { className: "text-slate-700 dark:text-slate-200", children: _.length }),
630
+ /* @__PURE__ */ l("strong", { className: "text-slate-700 dark:text-slate-200", children: j.length }),
598
631
  " row",
599
- _.length === 1 ? "" : "s",
600
- k.length > 0 && /* @__PURE__ */ i(qe, { children: [
632
+ j.length === 1 ? "" : "s",
633
+ w.length > 0 && /* @__PURE__ */ c(je, { children: [
601
634
  ", by ",
602
- k.map((e) => e.label ?? e.field).join(" and "),
635
+ w.map((e) => e.label ?? e.field).join(" and "),
603
636
  " — pick",
604
637
  " ",
605
- k.map((e) => e.label ?? e.field).join(", "),
638
+ w.map((e) => e.label ?? e.field).join(", "),
606
639
  " to edit"
607
640
  ] })
608
641
  ] }),
609
- Object.keys(f).some((e) => f[e] != null && f[e] !== "") && /* @__PURE__ */ i(
642
+ Object.keys(p).some((e) => p[e] != null && p[e] !== "") && /* @__PURE__ */ c(
610
643
  "button",
611
644
  {
612
645
  type: "button",
613
646
  onClick: () => {
614
- O({}), s();
647
+ $({}), s();
615
648
  },
616
649
  className: "ml-auto inline-flex items-center gap-1 rounded px-1.5 py-0.5 text-[11.5px] text-slate-500 hover:bg-slate-200/60 hover:text-slate-700 dark:hover:bg-muted",
617
650
  children: [
@@ -621,12 +654,12 @@ function Ae({ config: t }) {
621
654
  }
622
655
  )
623
656
  ] }),
624
- /* @__PURE__ */ l("div", { className: "min-h-0 flex-1 overflow-auto", children: Y ? /* @__PURE__ */ i("div", { className: "flex items-center gap-2 p-4 text-[12px] text-slate-400", children: [
657
+ /* @__PURE__ */ l("div", { className: "min-h-0 flex-1 overflow-auto", children: ee ? /* @__PURE__ */ c("div", { className: "flex items-center gap-2 p-4 text-[12px] text-slate-400", children: [
625
658
  /* @__PURE__ */ l(pe, { className: "h-4 w-4 animate-spin" }),
626
659
  " Loading…"
627
- ] }) : /* @__PURE__ */ i("table", { className: "w-full text-[12px]", children: [
628
- /* @__PURE__ */ l("thead", { className: "sticky top-0 z-[1] bg-white dark:bg-card", children: /* @__PURE__ */ i("tr", { className: "border-b border-slate-200 dark:border-border", children: [
629
- (h ? [{ field: "__row", label: "" }] : k.map((e) => ({ field: e.field, label: e.label ?? e.field }))).map((e) => /* @__PURE__ */ l(
660
+ ] }) : /* @__PURE__ */ c("table", { className: "w-full text-[12px]", children: [
661
+ /* @__PURE__ */ l("thead", { className: "sticky top-0 z-[1] bg-white dark:bg-card", children: /* @__PURE__ */ c("tr", { className: "border-b border-slate-200 dark:border-border", children: [
662
+ (f ? [{ field: "__row", label: "" }] : w.map((e) => ({ field: e.field, label: e.label ?? e.field }))).map((e) => /* @__PURE__ */ l(
630
663
  "th",
631
664
  {
632
665
  className: "sticky left-0 z-[2] bg-white px-2 py-2 text-left text-[10.5px] font-semibold uppercase tracking-wide text-slate-400 dark:bg-card",
@@ -634,29 +667,30 @@ function Ae({ config: t }) {
634
667
  },
635
668
  e.field
636
669
  )),
637
- v.map((e, o) => Q(e.label, o)),
670
+ q.map((e, o) => Q(e.label, o)),
638
671
  g && Q("Total", 99, "border-l border-slate-200 dark:border-border"),
639
- h && t.allow_delete && /* @__PURE__ */ l("th", { "aria-label": "Remove", className: "w-8" })
672
+ f && t.allow_delete && /* @__PURE__ */ l("th", { "aria-label": "Remove", className: "w-8" })
640
673
  ] }) }),
641
- /* @__PURE__ */ i("tbody", { children: [
642
- h ? A.map((e) => {
674
+ /* @__PURE__ */ c("tbody", { children: [
675
+ f ? V.map((e) => {
643
676
  var o;
644
- return /* @__PURE__ */ i("tr", { className: "border-b border-slate-100 dark:border-border/50", children: [
677
+ return /* @__PURE__ */ c("tr", { className: "border-b border-slate-100 dark:border-border/50", children: [
645
678
  /* @__PURE__ */ l("td", { className: "sticky left-0 z-[1] bg-white px-3 py-1 text-slate-600 dark:bg-card dark:text-slate-300", children: e.isNew ? /* @__PURE__ */ l("span", { className: "rounded bg-nvr-cyan/10 px-1.5 py-0.5 text-[10.5px] font-medium text-nvr-navy dark:text-nvr-cyan", children: "New row" }) : `#${(o = e.record) == null ? void 0 : o.id}` }),
646
- v.map((a, d) => /* @__PURE__ */ l(
679
+ q.map((a, d) => /* @__PURE__ */ l(
647
680
  "td",
648
681
  {
649
- className: G(
682
+ className: X(
650
683
  "px-1 py-0.5 text-right",
651
- q(d) && "border-l border-slate-100 dark:border-border/50",
652
- V(d)
684
+ T(d) && "border-l border-slate-100 dark:border-border/50",
685
+ G(d)
653
686
  ),
654
687
  children: /* @__PURE__ */ l(
655
- Le,
688
+ ze,
656
689
  {
657
690
  value: ie(e, a.field),
658
- original: te(e, a.field),
659
- onChange: (u) => ce(e.key, a.field, u)
691
+ original: re(e, a.field),
692
+ onChange: (u) => ce(e.key, a.field, u),
693
+ allowNegative: !!t.allow_negative
660
694
  }
661
695
  )
662
696
  },
@@ -665,9 +699,9 @@ function Ae({ config: t }) {
665
699
  g && /* @__PURE__ */ l(
666
700
  "td",
667
701
  {
668
- className: `border-l border-slate-200 px-2 py-1 text-right font-semibold tabular-nums dark:border-border ${K}`,
702
+ className: `border-l border-slate-200 px-2 py-1 text-right font-semibold tabular-nums dark:border-border ${U}`,
669
703
  style: D,
670
- children: R(re(e))
704
+ children: K(le(e))
671
705
  }
672
706
  ),
673
707
  t.allow_delete && /* @__PURE__ */ l("td", { className: "py-1 pl-1", children: /* @__PURE__ */ l(
@@ -676,10 +710,10 @@ function Ae({ config: t }) {
676
710
  type: "button",
677
711
  "aria-label": "Remove row",
678
712
  onClick: () => {
679
- e.record ? H((a) => {
713
+ e.record ? J((a) => {
680
714
  var d;
681
715
  return new Set(a).add(String((d = e.record) == null ? void 0 : d.id));
682
- }) : S((a) => a.filter((d) => d !== e.key)), y((a) => {
716
+ }) : v((a) => a.filter((d) => d !== e.key)), S((a) => {
683
717
  const d = { ...a };
684
718
  return delete d[e.key], d;
685
719
  });
@@ -689,9 +723,9 @@ function Ae({ config: t }) {
689
723
  }
690
724
  ) })
691
725
  ] }, e.key);
692
- }) : ee.map((e) => {
693
- const o = k.map((a) => String(e.keyVals[a.field] ?? "")).join("|");
694
- return /* @__PURE__ */ i(
726
+ }) : te.map((e) => {
727
+ const o = w.map((a) => String(e.keyVals[a.field] ?? "")).join("|");
728
+ return /* @__PURE__ */ c(
695
729
  "tr",
696
730
  {
697
731
  className: "cursor-pointer border-b border-slate-100 hover:bg-slate-50 focus:outline-none focus-visible:bg-slate-50 dark:border-border/50 dark:hover:bg-muted/40",
@@ -702,17 +736,17 @@ function Ae({ config: t }) {
702
736
  tabIndex: 0,
703
737
  title: "Open this combination",
704
738
  children: [
705
- k.map((a, d) => /* @__PURE__ */ i(
739
+ w.map((a, d) => /* @__PURE__ */ c(
706
740
  "td",
707
741
  {
708
- className: G(
742
+ className: X(
709
743
  "whitespace-nowrap px-2 py-1.5 text-slate-700 dark:text-slate-200",
710
744
  d === 0 && "sticky left-0 z-[1] bg-white font-medium dark:bg-card"
711
745
  ),
712
746
  children: [
713
- d === 0 && /* @__PURE__ */ l(je, { className: "mr-1 inline h-3 w-3 text-slate-300" }),
714
- L(a.field, e.keyVals[a.field]),
715
- d === k.length - 1 && e.count > 1 && /* @__PURE__ */ i("span", { className: "ml-1.5 text-[10.5px] text-slate-400", children: [
747
+ d === 0 && /* @__PURE__ */ l(Oe, { className: "mr-1 inline h-3 w-3 text-slate-300" }),
748
+ R(a.field, e.keyVals[a.field]),
749
+ d === w.length - 1 && e.count > 1 && /* @__PURE__ */ c("span", { className: "ml-1.5 text-[10.5px] text-slate-400", children: [
716
750
  e.count,
717
751
  " rows"
718
752
  ] })
@@ -720,26 +754,26 @@ function Ae({ config: t }) {
720
754
  },
721
755
  a.field
722
756
  )),
723
- v.map((a, d) => /* @__PURE__ */ l(
757
+ q.map((a, d) => /* @__PURE__ */ l(
724
758
  "td",
725
759
  {
726
- className: G(
760
+ className: X(
727
761
  "whitespace-nowrap px-1.5 py-1.5 text-right tabular-nums",
728
- q(d) && "border-l border-slate-100 dark:border-border/50",
729
- V(d),
762
+ T(d) && "border-l border-slate-100 dark:border-border/50",
763
+ G(d),
730
764
  (e.sums[a.field] ?? 0) === 0 ? "text-slate-300 dark:text-slate-600" : "text-slate-700 dark:text-slate-200"
731
765
  ),
732
- children: R(e.sums[a.field], { blankZero: !0 })
766
+ children: K(e.sums[a.field], { blankZero: !0 })
733
767
  },
734
768
  a.field
735
769
  )),
736
770
  g && /* @__PURE__ */ l(
737
771
  "td",
738
772
  {
739
- className: `border-l border-slate-200 px-2 py-1.5 text-right font-semibold tabular-nums dark:border-border ${K}`,
773
+ className: `border-l border-slate-200 px-2 py-1.5 text-right font-semibold tabular-nums dark:border-border ${U}`,
740
774
  style: D,
741
- children: R(
742
- J.reduce(
775
+ children: K(
776
+ W.reduce(
743
777
  (a, d) => a + (e.sums[`${d}${g.suffix}`] ?? 0),
744
778
  0
745
779
  )
@@ -751,42 +785,45 @@ function Ae({ config: t }) {
751
785
  o
752
786
  );
753
787
  }),
754
- !h && ee.length === 0 && /* @__PURE__ */ l("tr", { children: /* @__PURE__ */ l("td", { colSpan: 99, className: "py-6 text-center text-[12px] text-slate-400", children: "No rows match" }) })
788
+ !f && te.length === 0 && /* @__PURE__ */ l("tr", { children: /* @__PURE__ */ l("td", { colSpan: 99, className: "py-6 text-center text-[12px] text-slate-400", children: "No rows match" }) })
755
789
  ] }),
756
- /* @__PURE__ */ l("tfoot", { className: "sticky bottom-0 bg-white dark:bg-card", children: /* @__PURE__ */ i("tr", { className: "border-t-2 border-slate-300 dark:border-border", children: [
790
+ /* @__PURE__ */ l("tfoot", { className: "sticky bottom-0 bg-white dark:bg-card", children: /* @__PURE__ */ c("tr", { className: "border-t-2 border-slate-300 dark:border-border", children: [
757
791
  /* @__PURE__ */ l(
758
792
  "td",
759
793
  {
760
- colSpan: h ? 1 : Math.max(1, k.length),
794
+ colSpan: f ? 1 : Math.max(1, w.length),
761
795
  className: "sticky left-0 z-[1] bg-white px-3 py-2 text-[12px] font-semibold text-slate-800 dark:bg-card dark:text-slate-100",
762
796
  children: "Total"
763
797
  }
764
798
  ),
765
- v.map((e, o) => /* @__PURE__ */ l(
799
+ q.map((e, o) => /* @__PURE__ */ l(
766
800
  "td",
767
801
  {
768
- className: G(
802
+ className: X(
769
803
  "px-2 py-2 text-right font-semibold tabular-nums text-slate-800 dark:text-slate-100",
770
- q(o) && "border-l border-slate-200 dark:border-border",
771
- V(o)
804
+ T(o) && "border-l border-slate-200 dark:border-border",
805
+ G(o)
772
806
  ),
773
- children: R(x(e.field))
807
+ children: K(y(e.field))
774
808
  },
775
809
  e.field
776
810
  )),
777
811
  g && /* @__PURE__ */ l(
778
812
  "td",
779
813
  {
780
- className: `border-l border-slate-200 px-2 py-2 text-right font-semibold tabular-nums dark:border-border ${K}`,
814
+ className: `border-l border-slate-200 px-2 py-2 text-right font-semibold tabular-nums dark:border-border ${U}`,
781
815
  style: D,
782
- children: R(J.reduce((e, o) => e + x(`${o}${g.suffix}`), 0))
816
+ children: K(W.reduce((e, o) => e + y(`${o}${g.suffix}`), 0))
783
817
  }
784
818
  ),
785
- h && t.allow_delete && /* @__PURE__ */ l("td", {})
819
+ f && t.allow_delete && /* @__PURE__ */ l("td", {})
786
820
  ] }) })
787
821
  ] }) })
788
822
  ] });
789
823
  }
790
824
  export {
791
- Xe as RecordGridEditor
825
+ Ce as NEGATIVE_AMOUNT_MESSAGE,
826
+ ze as NumberCell,
827
+ Ye as RecordGridEditor,
828
+ Le as sanitizeAmount
792
829
  };