@nivaro/react 0.3.127 → 0.3.128

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 (39) hide show
  1. package/dist/full.css +1 -1
  2. package/dist/hooks/useSessionRecorder.js +1 -1
  3. package/dist/index.d.ts +20 -2
  4. package/dist/index.js +150 -147
  5. package/dist/shared/components/CollectionBrowserView.js +3259 -3211
  6. package/dist/shared/components/DataTable.js +406 -401
  7. package/dist/shared/components/ItemEditForm.js +4203 -4156
  8. package/dist/shared/components/MatrixEditor.js +548 -490
  9. package/dist/shared/components/MyWorkView.js +284 -274
  10. package/dist/shared/components/NotificationBell.js +264 -218
  11. package/dist/shared/components/RecordGridEditor.js +582 -472
  12. package/dist/shared/components/chat/chat-core.js +331 -346
  13. package/dist/shared/components/chat/chat-typing.js +25 -0
  14. package/dist/shared/components/command-center/CommandCenterView.js +1 -1
  15. package/dist/shared/components/command-center/PeekPanel.js +8 -1
  16. package/dist/shared/components/command-center/api.js +17 -9
  17. package/dist/shared/components/command-center/panels/AttentionPanel.js +4 -1
  18. package/dist/shared/components/command-center/panels/PartnersPanel.js +2 -1
  19. package/dist/shared/components/item-edit/GroupSection.js +1 -1
  20. package/dist/shared/components/item-edit/InlineTableField.js +432 -429
  21. package/dist/shared/components/item-edit/RecordLiveSync.js +115 -108
  22. package/dist/shared/components/item-edit/RecordViewersChip.js +17 -16
  23. package/dist/shared/components/item-edit/RowComments.js +33 -30
  24. package/dist/shared/components/item-edit/cascade-clear-notice.js +30 -28
  25. package/dist/shared/components/item-edit/live-related.js +29 -16
  26. package/dist/shared/components/item-edit/record-opened-live.js +86 -0
  27. package/dist/shared/components/panels/OwnerOpenedLine.js +24 -23
  28. package/dist/shared/components/panels/RecordIntegrityBanner.js +1 -1
  29. package/dist/shared/components/pipeline/TeamSuggestions.js +1 -1
  30. package/dist/shared/components/queue/QueueItemSheet.js +171 -130
  31. package/dist/shared/components/record-grid-guard.js +85 -0
  32. package/dist/shared/components/support/TicketDetailSheet.js +168 -151
  33. package/dist/shared/lib/at-risk-fields.js +14 -0
  34. package/dist/shared/lib/live-queries.js +9 -8
  35. package/dist/shared/lib/live-screen.js +77 -76
  36. package/dist/shared/lib/presence-hooks.js +190 -127
  37. package/dist/shared/lib/user-sync.js +78 -65
  38. package/dist/shared/lib/waiting-count.js +40 -29
  39. package/package.json +1 -1
@@ -1,19 +1,21 @@
1
- import { jsx as l, jsxs as c, Fragment as Ae } from "react/jsx-runtime";
2
- import { useQueryClient as _e, useQuery as ue } from "@tanstack/react-query";
3
- import { Loader2 as me, X as ve, ChevronRight as Me } from "lucide-react";
4
- import { useState as N, useMemo as I, useCallback as Fe, useRef as Re, useEffect as De } from "react";
5
- import { useNivaroClient as $e } from "../context.js";
6
- import { get as oe, patch as Se, post as be, del as Ce } from "../lib/commands.js";
7
- import { useGridPresence as ze, gridPageKey as Pe, gridPresenceCell as Ve } from "../lib/grid-presence.js";
8
- import { userErrorMessage as qe } from "../lib/safe-error.js";
9
- import { cn as X } from "../lib/utils.js";
10
- import { GridPresenceLine as Ke } from "./GridPresenceLine.js";
11
- import { ChangeReasonDialog as je, changeReasonChallenge as Oe } from "./item-edit/ChangeReasonDialog.js";
12
- import { applyDisplayTemplate as Ge } from "./item-edit/helpers.js";
13
- import { RelationCombobox as ye } from "./item-edit/RelationCombobox.js";
14
- import { JsonMapEditor as Je } from "./JsonMapEditor.js";
15
- import { colorPair as Ie } from "./QueryTable.js";
16
- const U = [
1
+ import { jsx as l, jsxs as u, Fragment as He } from "react/jsx-runtime";
2
+ import { useQueryClient as Re, useQuery as ve, keepPreviousData as Xe } from "@tanstack/react-query";
3
+ import { Loader2 as _e, X as Me, ChevronRight as Ze } from "lucide-react";
4
+ import { useState as k, useMemo as Q, useCallback as Ye, useRef as et, useEffect as je } from "react";
5
+ import { useNivaroClient as Ae } from "../context.js";
6
+ import { get as xe, post as Se, del as Ee } from "../lib/commands.js";
7
+ import { useGridPresence as tt, gridPageKey as rt, gridPresenceCell as lt } from "../lib/grid-presence.js";
8
+ import { liveQueryMeta as Fe } from "../lib/live-queries.js";
9
+ import { userErrorMessage as Le } from "../lib/safe-error.js";
10
+ import { cn as Y } from "../lib/utils.js";
11
+ import { GridPresenceLine as at } from "./GridPresenceLine.js";
12
+ import { ChangeReasonDialog as De, changeReasonChallenge as ze } from "./item-edit/ChangeReasonDialog.js";
13
+ import { applyDisplayTemplate as st } from "./item-edit/helpers.js";
14
+ import { RelationCombobox as qe } from "./item-edit/RelationCombobox.js";
15
+ import { JsonMapEditor as ot } from "./JsonMapEditor.js";
16
+ import { colorPair as nt } from "./QueryTable.js";
17
+ import { GridRowGuard as Pe, takeTheirs as Ge, gridRowPatch as Ke, conflictsOf as Ve, settleDraftAfterSave as Je } from "./record-grid-guard.js";
18
+ const ee = [
17
19
  "january",
18
20
  "february",
19
21
  "march",
@@ -26,7 +28,7 @@ const U = [
26
28
  "october",
27
29
  "november",
28
30
  "december"
29
- ], Te = [
31
+ ], Ue = [
30
32
  "Jan",
31
33
  "Feb",
32
34
  "Mar",
@@ -40,661 +42,766 @@ const U = [
40
42
  "Nov",
41
43
  "Dec"
42
44
  ];
43
- function Z(t, m) {
44
- return typeof t == "string" && t.startsWith("$scope.") ? m[t.slice(7)] : Array.isArray(t) ? t.map(($) => Z($, m)) : t && typeof t == "object" ? Object.fromEntries(
45
- Object.entries(t).map(([$, i]) => [
46
- $,
47
- Z(i, m)
45
+ function pe(t, i) {
46
+ return typeof t == "string" && t.startsWith("$scope.") ? i[t.slice(7)] : Array.isArray(t) ? t.map((g) => pe(g, i)) : t && typeof t == "object" ? Object.fromEntries(
47
+ Object.entries(t).map(([g, c]) => [
48
+ g,
49
+ pe(c, i)
48
50
  ])
49
51
  ) : t;
50
52
  }
51
- function pe(t) {
52
- return t === void 0 ? !0 : Array.isArray(t) ? t.some(pe) : t && typeof t == "object" ? Object.values(t).some(pe) : !1;
53
+ function $e(t) {
54
+ return t === void 0 ? !0 : Array.isArray(t) ? t.some($e) : t && typeof t == "object" ? Object.values(t).some($e) : !1;
53
55
  }
54
- function ut({ config: t }) {
55
- return t.browse ? /* @__PURE__ */ l(Qe, { config: t }) : /* @__PURE__ */ l(Ue, { config: t });
56
+ function Be(t) {
57
+ const i = Number(t);
58
+ return `Someone else saved ${t == null || t === "" ? "empty" : Number.isFinite(i) ? i.toLocaleString("en-US", { maximumFractionDigits: 2 }) : String(t)} here since you started. Save again to keep yours, or take theirs.`;
59
+ }
60
+ function Ie(t, i, g, c) {
61
+ const m = `Saved — ${t} updated, ${i} created${g ? `, ${g} deleted` : ""}`, x = Object.keys(c).length;
62
+ return x === 0 ? m : `${m}. ${x} row${x === 1 ? " was" : "s were"} changed by someone else — check the outlined cells.`;
63
+ }
64
+ function Qe({ count: t, onClick: i }) {
65
+ return /* @__PURE__ */ u(
66
+ "button",
67
+ {
68
+ type: "button",
69
+ onClick: i,
70
+ "data-record-grid-take-theirs": !0,
71
+ className: "h-9 rounded-md border border-amber-400 bg-amber-50 px-3 text-[13px] font-medium text-amber-800 hover:bg-amber-100 dark:border-amber-500/60 dark:bg-amber-500/10 dark:text-amber-200 dark:hover:bg-amber-500/20",
72
+ children: [
73
+ "Take theirs (",
74
+ t,
75
+ ")"
76
+ ]
77
+ }
78
+ );
56
79
  }
57
- function Ue({ config: t }) {
58
- var re, le;
59
- const m = $e(), $ = _e(), [i, p] = N({}), [S, g] = N({}), [C, q] = N([]), [k, y] = N(/* @__PURE__ */ new Set()), [G, z] = N(!1), [P, O] = N(null), [W, J] = N(null), [T, h] = N(null), v = (t.scope ?? []).every(
60
- (r) => i[r.field] !== null && i[r.field] !== void 0 && i[r.field] !== ""
61
- ), _ = JSON.stringify(i), de = I(() => {
80
+ function qt({ config: t }) {
81
+ return t.browse ? /* @__PURE__ */ l(ut, { config: t }) : /* @__PURE__ */ l(dt, { config: t });
82
+ }
83
+ function dt({ config: t }) {
84
+ var ue, we;
85
+ const i = Ae(), g = Re(), [c, m] = k({}), [x, C] = k({}), [M, w] = k([]), [O, v] = k(/* @__PURE__ */ new Set()), [j, re] = k(!1), [le, U] = k(null), [R, ae] = k(null), [z, W] = k(null), [K, B] = k({}), p = Q(
86
+ () => new Pe(i, t.collection),
87
+ [i, t.collection]
88
+ ), T = (t.scope ?? []).every(
89
+ (r) => c[r.field] !== null && c[r.field] !== void 0 && c[r.field] !== ""
90
+ ), _ = JSON.stringify(c), ye = Q(() => {
62
91
  const r = [];
63
- for (const o of t.month_sets ?? []) for (const n of U) r.push(`${n}${o.suffix}`);
92
+ for (const o of t.month_sets ?? []) for (const d of ee) r.push(`${d}${o.suffix}`);
64
93
  for (const o of t.columns ?? []) r.push(o.field);
65
94
  return r;
66
- }, [t]), { data: Y = [], isLoading: ne } = ue({
95
+ }, [t]), {
96
+ data: se = [],
97
+ isLoading: ke,
98
+ isPlaceholderData: L
99
+ } = ve({
67
100
  queryKey: ["record-grid-rows", t.collection, _],
68
101
  queryFn: () => {
69
102
  const r = {};
70
- for (const o of t.scope ?? []) r[o.field] = { _eq: i[o.field] };
71
- return m.request(
72
- oe(`/items/${t.collection}`, {
103
+ for (const o of t.scope ?? []) r[o.field] = { _eq: c[o.field] };
104
+ return i.request(
105
+ xe(`/items/${t.collection}`, {
73
106
  limit: 2e3,
74
107
  ...Object.keys(r).length ? { filter: JSON.stringify(r) } : {}
75
108
  })
76
109
  ).then((o) => o.data ?? []);
77
110
  },
78
- enabled: v,
79
- staleTime: 1e4
80
- }), { data: D = [] } = ue({
81
- queryKey: ["record-grid-source", (re = t.row_source) == null ? void 0 : re.collection, _],
111
+ enabled: T,
112
+ staleTime: 1e4,
113
+ // R1: someone else's save shows up here (the draft stays on top of it).
114
+ meta: Fe({ reads: [t.collection], minGapMs: 2e3 }),
115
+ // A new scope keeps the old rows (dimmed, not editable) until its own arrive — no blank grid.
116
+ placeholderData: Xe
117
+ });
118
+ je(() => {
119
+ L || p.noteRows(se);
120
+ }, [p, se, L]);
121
+ const { data: P = [] } = ve({
122
+ queryKey: ["record-grid-source", (ue = t.row_source) == null ? void 0 : ue.collection, _],
82
123
  queryFn: () => {
83
124
  const r = t.row_source;
84
125
  if (!r) return Promise.resolve([]);
85
- const o = Z(r.filter, i), n = o && !pe(o) ? o : void 0;
86
- return m.request(
87
- oe(`/items/${r.collection}`, {
126
+ const o = pe(r.filter, c), d = o && !$e(o) ? o : void 0;
127
+ return i.request(
128
+ xe(`/items/${r.collection}`, {
88
129
  limit: 1e3,
89
130
  ...r.sort ? { sort: r.sort } : {},
90
- ...n ? { filter: JSON.stringify(n) } : {}
131
+ ...d ? { filter: JSON.stringify(d) } : {}
91
132
  })
92
133
  ).then((f) => f.data ?? []);
93
134
  },
94
- enabled: v && !!t.row_source,
135
+ enabled: T && !!t.row_source,
95
136
  staleTime: 3e4
96
- }), j = I(() => {
137
+ }), oe = Q(() => {
97
138
  if (t.row_source) {
98
139
  const r = t.row_source;
99
- return D.map((o) => {
100
- const n = Y.find((f) => String(f[r.fk_field]) === String(o.id)) ?? null;
140
+ return P.map((o) => {
141
+ const d = se.find((f) => String(f[r.fk_field]) === String(o.id)) ?? null;
101
142
  return {
102
143
  key: `src-${o.id}`,
103
- record: n,
144
+ record: d,
104
145
  sourceId: o.id,
105
146
  sourceLabel: String(o[r.label_field] ?? o.id),
106
- isNew: !n
147
+ isNew: !d
107
148
  };
108
149
  });
109
150
  }
110
151
  return [
111
- ...Y.filter((r) => !k.has(String(r.id))).map((r) => ({ key: `rec-${r.id}`, record: r, isNew: !1 })),
112
- ...C.map((r) => ({ key: r, record: null, isNew: !0 }))
152
+ ...se.filter((r) => !O.has(String(r.id))).map((r) => ({ key: `rec-${r.id}`, record: r, isNew: !1 })),
153
+ ...M.map((r) => ({ key: r, record: null, isNew: !0 }))
113
154
  ];
114
- }, [t.row_source, D, Y, C, k]), B = (r, o) => {
115
- var F, x;
116
- const n = (F = S[r.key]) == null ? void 0 : F[o];
117
- if (n !== void 0) return n;
118
- const f = (x = r.record) == null ? void 0 : x[o];
155
+ }, [t.row_source, P, se, M, O]), S = (r, o) => {
156
+ var N, H;
157
+ const d = (N = x[r.key]) == null ? void 0 : N[o];
158
+ if (d !== void 0) return d;
159
+ const f = (H = r.record) == null ? void 0 : H[o];
119
160
  return f == null ? "" : String(f);
120
- }, w = (r, o, n) => g((f) => ({ ...f, [r]: { ...f[r] ?? {}, [o]: n } })), ee = Object.values(S).some((r) => Object.keys(r).length > 0) || C.length > 0 || k.size > 0;
121
- async function E(r) {
122
- var F;
123
- z(!0), J(null);
124
- let o = 0, n = 0, f = 0;
161
+ }, ie = (r, o, d) => {
162
+ var f;
163
+ ((f = r.record) == null ? void 0 : f.id) != null && p.pin(String(r.record.id)), C((N) => ({ ...N, [r.key]: { ...N[r.key] ?? {}, [o]: d } }));
164
+ }, D = Object.values(x).some((r) => Object.keys(r).length > 0) || M.length > 0 || O.size > 0, fe = Object.values(K).reduce((r, o) => r + Object.keys(o).length, 0);
165
+ async function ge(r) {
166
+ var he;
167
+ re(!0), ae(null);
168
+ let o = 0, d = 0, f = 0;
169
+ const N = {}, H = (q) => ye.includes(q) || (t.key_columns ?? []).some((G) => G.field === q), Ne = (he = t.month_sets) == null ? void 0 : he[0], ne = t.computed_total_field && Ne ? {
170
+ field: t.computed_total_field,
171
+ of: ee.map((q) => `${q}${Ne.suffix}`)
172
+ } : null;
125
173
  try {
126
- for (const x of j) {
127
- const R = S[x.key] ?? {}, ie = Object.keys(R).length > 0;
128
- if (!x.record && !ie) continue;
129
- const L = {};
130
- for (const [A, M] of Object.entries(R))
131
- !de.includes(A) && !(t.key_columns ?? []).some((V) => V.field === A) || (L[A] = M === "" ? null : Number.isNaN(Number(M)) ? M : Number(M));
132
- if (t.computed_total_field && ((F = t.month_sets) != null && F.length)) {
133
- const A = t.month_sets[0];
134
- L[t.computed_total_field] = U.reduce((M, V) => {
135
- var Q;
136
- const ae = `${V}${A.suffix}`, he = R[ae] !== void 0 ? Number(R[ae]) || 0 : Number((Q = x.record) == null ? void 0 : Q[ae]) || 0;
137
- return M + he;
138
- }, 0);
139
- }
140
- if (x.record) {
141
- if (Object.keys(L).length === 0) continue;
142
- r && (L._change_reason = r), await m.request(Se(`/items/${t.collection}/${x.record.id}`, L)), n++;
143
- } else {
144
- if (!ie) continue;
145
- for (const A of t.scope ?? []) L[A.field] = i[A.field];
146
- t.row_source && (L[t.row_source.fk_field] = x.sourceId), await m.request(be(`/items/${t.collection}`, L)), o++;
147
- }
174
+ for (const y of oe) {
175
+ const A = x[y.key] ?? {}, X = Object.keys(A).length > 0;
176
+ if (!(!y.record && !X))
177
+ if (y.record) {
178
+ const E = Ke(A, y.record, H, ne);
179
+ if (!E) continue;
180
+ r && (E._change_reason = r);
181
+ const F = await p.write(String(y.record.id), E);
182
+ F.ok ? d++ : Object.assign(N, Ve(y.key, F.conflicts));
183
+ } else {
184
+ const E = {};
185
+ for (const [F, I] of Object.entries(A))
186
+ H(F) && (E[F] = I === "" ? null : Number.isNaN(Number(I)) ? I : Number(I));
187
+ if (ne && (E[ne.field] = ne.of.reduce((F, I) => F + (Number(A[I]) || 0), 0)), !X) continue;
188
+ for (const F of t.scope ?? []) E[F.field] = c[F.field];
189
+ t.row_source && (E[t.row_source.fk_field] = y.sourceId), await i.request(Se(`/items/${t.collection}`, E)), o++;
190
+ }
148
191
  }
149
- for (const x of k)
150
- await m.request(Ce(`/items/${t.collection}/${x}`)), f++;
151
- if (t.after_save) {
152
- const x = Z(t.after_save.params ?? {}, i);
153
- await m.request(
154
- be(`/custom-queries/${t.after_save.query_slug}/execute`, { params: x })
192
+ for (const y of O)
193
+ await i.request(Ee(`/items/${t.collection}/${y}`)), f++;
194
+ if (t.after_save && d + o + f > 0) {
195
+ const y = pe(t.after_save.params ?? {}, c);
196
+ await i.request(
197
+ Se(`/custom-queries/${t.after_save.query_slug}/execute`, { params: y })
155
198
  );
156
199
  }
157
- g({}), q([]), y(/* @__PURE__ */ new Set()), await $.invalidateQueries({ queryKey: ["record-grid-rows", t.collection] }), J(
158
- `Saved — ${n} updated, ${o} created${f ? `, ${f} deleted` : ""}`
159
- );
160
- } catch (x) {
161
- const R = Oe(x);
162
- R ? (O(R), J(null)) : J(`Save failed: ${qe(x, "unknown error")}`);
200
+ const q = new Set(M), G = new Set(O);
201
+ C((y) => {
202
+ const A = Je(y, x, new Set(Object.keys(N)));
203
+ for (const X of q) delete A[X];
204
+ return A;
205
+ }), B(N), w((y) => y.filter((A) => !q.has(A))), v((y) => new Set([...y].filter((A) => !G.has(A)))), await g.invalidateQueries({ queryKey: ["record-grid-rows", t.collection] }), ae(Ie(d, o, f, N));
206
+ } catch (q) {
207
+ const G = ze(q);
208
+ G ? (U(G), ae(null)) : ae(`Save failed: ${Le(q, "unknown error")}`);
163
209
  } finally {
164
- z(!1);
210
+ re(!1);
165
211
  }
166
212
  }
167
- const te = [
213
+ const ce = [
168
214
  ...(t.month_sets ?? []).flatMap(
169
- (r) => U.map((o, n) => ({ field: `${o}${r.suffix}`, label: `${Te[n]} ${r.label}` }))
215
+ (r) => ee.map((o, d) => ({ field: `${o}${r.suffix}`, label: `${Ue[d]} ${r.label}` }))
170
216
  ),
171
217
  ...(t.columns ?? []).map((r) => ({ field: r.field, label: r.label ?? r.field }))
172
218
  ];
173
- return /* @__PURE__ */ c("div", { className: "flex h-full flex-col gap-3 overflow-auto p-3", children: [
219
+ return /* @__PURE__ */ u("div", { className: "flex h-full flex-col gap-3 overflow-auto p-3", children: [
174
220
  /* @__PURE__ */ l(
175
- je,
221
+ De,
176
222
  {
177
- challenge: P,
178
- onCancel: () => O(null),
223
+ challenge: le,
224
+ onCancel: () => U(null),
179
225
  onSubmit: (r) => {
180
- O(null), E(r);
226
+ U(null), ge(r);
181
227
  }
182
228
  }
183
229
  ),
184
- /* @__PURE__ */ c("div", { className: "flex flex-wrap items-end gap-3", children: [
230
+ /* @__PURE__ */ u("div", { className: "flex flex-wrap items-end gap-3", children: [
185
231
  (t.scope ?? []).map((r) => {
186
- const o = Z(r.filter, i), n = o && !pe(o) ? o : void 0;
187
- return /* @__PURE__ */ c("div", { className: "w-52", children: [
232
+ const o = pe(r.filter, c), d = o && !$e(o) ? o : void 0;
233
+ return /* @__PURE__ */ u("div", { className: "w-52", children: [
188
234
  /* @__PURE__ */ l("p", { className: "mb-1 text-[11px] font-medium text-slate-500", children: r.label ?? r.field.replace(/_/g, " ").replace(/\b\w/g, (f) => f.toUpperCase()) }),
189
235
  /* @__PURE__ */ l(
190
- ye,
236
+ qe,
191
237
  {
192
238
  collection: r.collection,
193
- value: i[r.field] ?? null,
239
+ value: c[r.field] ?? null,
194
240
  onChange: (f) => {
195
- p((F) => ({ ...F, [r.field]: f })), g({}), q([]), y(/* @__PURE__ */ new Set());
241
+ m((N) => ({ ...N, [r.field]: f })), C({}), w([]), v(/* @__PURE__ */ new Set()), B({}), p.release();
196
242
  },
197
- extraFilter: n,
243
+ extraFilter: d,
198
244
  placeholder: "Select…"
199
245
  }
200
246
  )
201
247
  ] }, r.field);
202
248
  }),
203
- /* @__PURE__ */ c(
249
+ /* @__PURE__ */ u(
204
250
  "button",
205
251
  {
206
252
  type: "button",
207
- disabled: !v || !ee || G,
208
- onClick: () => void E(),
253
+ disabled: !T || !D || j,
254
+ onClick: () => void ge(),
209
255
  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",
210
256
  children: [
211
- G && /* @__PURE__ */ l(me, { className: "h-3.5 w-3.5 animate-spin" }),
257
+ j && /* @__PURE__ */ l(_e, { className: "h-3.5 w-3.5 animate-spin" }),
212
258
  "Save changes"
213
259
  ]
214
260
  }
215
261
  ),
216
- t.allow_add && v && /* @__PURE__ */ l(
262
+ t.allow_add && T && /* @__PURE__ */ l(
217
263
  "button",
218
264
  {
219
265
  type: "button",
220
- onClick: () => q((r) => [...r, `new-${r.length}-${Math.random().toString(36).slice(2, 8)}`]),
266
+ onClick: () => w((r) => [...r, `new-${r.length}-${Math.random().toString(36).slice(2, 8)}`]),
221
267
  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",
222
268
  children: "+ Add row"
223
269
  }
224
270
  ),
225
271
  (t.toolbar_editors ?? []).map((r, o) => {
226
- const n = (r.require_scope ?? []).every(
227
- (f) => i[f] !== null && i[f] !== void 0 && i[f] !== ""
272
+ const d = (r.require_scope ?? []).every(
273
+ (f) => c[f] !== null && c[f] !== void 0 && c[f] !== ""
228
274
  );
229
275
  return /* @__PURE__ */ l(
230
276
  "button",
231
277
  {
232
278
  type: "button",
233
- disabled: !n,
234
- title: n ? void 0 : `Choose ${(r.require_scope ?? []).join(", ")} first`,
235
- onClick: () => h(o),
279
+ disabled: !d,
280
+ title: d ? void 0 : `Choose ${(r.require_scope ?? []).join(", ")} first`,
281
+ onClick: () => W(o),
236
282
  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",
237
283
  children: r.button_label
238
284
  },
239
285
  r.button_label
240
286
  );
241
287
  }),
242
- W && /* @__PURE__ */ l("span", { className: "pb-2 text-[12px] text-slate-500", children: W })
288
+ R && /* @__PURE__ */ l("span", { className: "pb-2 text-[12px] text-slate-500", children: R }),
289
+ fe > 0 && /* @__PURE__ */ l(
290
+ Qe,
291
+ {
292
+ count: fe,
293
+ onClick: () => {
294
+ C((r) => Ge(r, K)), B({});
295
+ }
296
+ }
297
+ )
243
298
  ] }),
244
- T !== null && ((le = t.toolbar_editors) == null ? void 0 : le[T]) && /* @__PURE__ */ l(
299
+ z !== null && ((we = t.toolbar_editors) == null ? void 0 : we[z]) && /* @__PURE__ */ l(
245
300
  "div",
246
301
  {
247
302
  className: "fixed inset-0 z-[60] flex justify-end bg-black/30",
248
- onClick: () => h(null),
249
- children: /* @__PURE__ */ c(
303
+ onClick: () => W(null),
304
+ children: /* @__PURE__ */ u(
250
305
  "div",
251
306
  {
252
307
  className: "flex h-full flex-col border-l border-slate-200 bg-white shadow-2xl dark:border-border dark:bg-background",
253
308
  style: {
254
- width: typeof t.toolbar_editors[T].sheet_width == "number" ? `${t.toolbar_editors[T].sheet_width}px` : t.toolbar_editors[T].sheet_width ?? "70%",
309
+ width: typeof t.toolbar_editors[z].sheet_width == "number" ? `${t.toolbar_editors[z].sheet_width}px` : t.toolbar_editors[z].sheet_width ?? "70%",
255
310
  maxWidth: "96%"
256
311
  },
257
312
  onClick: (r) => r.stopPropagation(),
258
313
  children: [
259
- /* @__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: [
260
- /* @__PURE__ */ l("p", { className: "text-[13px] font-semibold text-slate-700 dark:text-slate-200", children: t.toolbar_editors[T].button_label }),
314
+ /* @__PURE__ */ u("div", { className: "flex shrink-0 items-center justify-between border-b border-slate-200 px-4 py-2.5 dark:border-border", children: [
315
+ /* @__PURE__ */ l("p", { className: "text-[13px] font-semibold text-slate-700 dark:text-slate-200", children: t.toolbar_editors[z].button_label }),
261
316
  /* @__PURE__ */ l(
262
317
  "button",
263
318
  {
264
319
  type: "button",
265
- onClick: () => h(null),
320
+ onClick: () => W(null),
266
321
  className: "rounded px-2 py-1 text-[12px] text-slate-500 hover:bg-slate-100 hover:text-slate-700 dark:hover:bg-muted",
267
322
  children: "Close"
268
323
  }
269
324
  )
270
325
  ] }),
271
- /* @__PURE__ */ l("div", { className: "min-h-0 flex-1 overflow-auto", children: /* @__PURE__ */ l(Je, { config: t.toolbar_editors[T].json_map, scope: i }) })
326
+ /* @__PURE__ */ l("div", { className: "min-h-0 flex-1 overflow-auto", children: /* @__PURE__ */ l(ot, { config: t.toolbar_editors[z].json_map, scope: c }) })
272
327
  ]
273
328
  }
274
329
  )
275
330
  }
276
331
  ),
277
- v ? ne ? /* @__PURE__ */ c("div", { className: "flex items-center gap-2 text-[12px] text-slate-400", children: [
278
- /* @__PURE__ */ l(me, { className: "h-4 w-4 animate-spin" }),
332
+ T ? ke ? /* @__PURE__ */ u("div", { className: "flex items-center gap-2 text-[12px] text-slate-400", children: [
333
+ /* @__PURE__ */ l(_e, { className: "h-4 w-4 animate-spin" }),
279
334
  " Loading…"
280
- ] }) : /* @__PURE__ */ l("div", { className: "overflow-x-auto", children: /* @__PURE__ */ c("table", { className: "w-full text-[12px]", children: [
281
- /* @__PURE__ */ l("thead", { children: /* @__PURE__ */ c("tr", { className: "border-b border-slate-200 text-left dark:border-border", children: [
282
- 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, " ") }),
283
- (t.key_columns ?? []).map((r) => /* @__PURE__ */ l(
284
- "th",
285
- {
286
- className: "min-w-[140px] py-1.5 pr-3 font-medium text-slate-500",
287
- children: r.label ?? r.field
288
- },
289
- r.field
290
- )),
291
- te.map((r) => /* @__PURE__ */ l(
292
- "th",
293
- {
294
- className: "min-w-[86px] py-1.5 pr-2 text-right font-medium text-slate-500",
295
- children: r.label
296
- },
297
- r.field
298
- )),
299
- t.allow_delete && /* @__PURE__ */ l("th", { "aria-label": "Remove" })
300
- ] }) }),
301
- /* @__PURE__ */ c("tbody", { children: [
302
- j.map((r) => /* @__PURE__ */ c("tr", { className: "border-b border-slate-100 dark:border-border/50", children: [
303
- t.row_source && /* @__PURE__ */ c("td", { className: "whitespace-nowrap py-1 pr-3 font-medium text-slate-700 dark:text-slate-200", children: [
304
- r.sourceLabel,
305
- r.isNew && /* @__PURE__ */ l("span", { className: "ml-1.5 text-[10px] text-slate-400", children: "(new)" })
306
- ] }),
307
- (t.key_columns ?? []).map((o) => /* @__PURE__ */ l("td", { className: "py-1 pr-3", children: /* @__PURE__ */ l(
308
- ye,
309
- {
310
- collection: o.collection,
311
- value: B(r, o.field) || null,
312
- onChange: (n) => w(r.key, o.field, n == null ? "" : String(n)),
313
- placeholder: "Select…"
314
- }
315
- ) }, o.field)),
316
- te.map((o) => /* @__PURE__ */ l("td", { className: "py-0.5 pr-2 text-right", children: /* @__PURE__ */ l(
317
- "input",
318
- {
319
- type: "number",
320
- min: t.allow_negative ? void 0 : 0,
321
- value: B(r, o.field),
322
- title: t.allow_negative ? void 0 : Ee,
323
- onChange: (n) => {
324
- !t.allow_negative && n.target.value.trim().startsWith("-") || w(r.key, o.field, n.target.value);
335
+ ] }) : /* @__PURE__ */ l(
336
+ "div",
337
+ {
338
+ className: Y("overflow-x-auto transition-opacity", L && "opacity-60"),
339
+ "aria-busy": L || void 0,
340
+ children: /* @__PURE__ */ u("table", { className: "w-full text-[12px]", children: [
341
+ /* @__PURE__ */ l("thead", { children: /* @__PURE__ */ u("tr", { className: "border-b border-slate-200 text-left dark:border-border", children: [
342
+ 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, " ") }),
343
+ (t.key_columns ?? []).map((r) => /* @__PURE__ */ l(
344
+ "th",
345
+ {
346
+ className: "min-w-[140px] py-1.5 pr-3 font-medium text-slate-500",
347
+ children: r.label ?? r.field
325
348
  },
326
- 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"
327
- }
328
- ) }, o.field)),
329
- t.allow_delete && /* @__PURE__ */ l("td", { className: "py-1 pl-2", children: /* @__PURE__ */ l(
330
- "button",
331
- {
332
- type: "button",
333
- onClick: () => {
334
- r.record ? y((o) => {
335
- var n;
336
- return new Set(o).add(String((n = r.record) == null ? void 0 : n.id));
337
- }) : q((o) => o.filter((n) => n !== r.key)), g((o) => {
338
- const n = { ...o };
339
- return delete n[r.key], n;
340
- });
349
+ r.field
350
+ )),
351
+ ce.map((r) => /* @__PURE__ */ l(
352
+ "th",
353
+ {
354
+ className: "min-w-[86px] py-1.5 pr-2 text-right font-medium text-slate-500",
355
+ children: r.label
341
356
  },
342
- className: "rounded px-1.5 text-[12px] text-slate-400 hover:text-red-600",
343
- children: "✕"
344
- }
345
- ) })
346
- ] }, r.key)),
347
- 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" }) })
348
- ] }),
349
- /* @__PURE__ */ l("tfoot", { children: /* @__PURE__ */ c("tr", { className: "border-t border-slate-300 font-semibold dark:border-border", children: [
350
- t.row_source && /* @__PURE__ */ l("td", { className: "py-1.5 pr-3", children: "Total" }),
351
- (t.key_columns ?? []).map((r, o) => /* @__PURE__ */ l("td", { className: "py-1.5 pr-3", children: !t.row_source && o === 0 ? "Total" : "" }, r.field)),
352
- te.map((r) => /* @__PURE__ */ l("td", { className: "py-1.5 pr-2 text-right tabular-nums", children: j.reduce((o, n) => o + (Number(B(n, r.field)) || 0), 0).toLocaleString("en-US", { maximumFractionDigits: 2 }) }, r.field)),
353
- t.allow_delete && /* @__PURE__ */ l("td", {})
354
- ] }) })
355
- ] }) }) : /* @__PURE__ */ c("p", { className: "text-[12px] text-slate-400", children: [
357
+ r.field
358
+ )),
359
+ t.allow_delete && /* @__PURE__ */ l("th", { "aria-label": "Remove" })
360
+ ] }) }),
361
+ /* @__PURE__ */ u("tbody", { children: [
362
+ oe.map((r) => /* @__PURE__ */ u("tr", { className: "border-b border-slate-100 dark:border-border/50", children: [
363
+ t.row_source && /* @__PURE__ */ u("td", { className: "whitespace-nowrap py-1 pr-3 font-medium text-slate-700 dark:text-slate-200", children: [
364
+ r.sourceLabel,
365
+ r.isNew && /* @__PURE__ */ l("span", { className: "ml-1.5 text-[10px] text-slate-400", children: "(new)" })
366
+ ] }),
367
+ (t.key_columns ?? []).map((o) => /* @__PURE__ */ l("td", { className: "py-1 pr-3", children: /* @__PURE__ */ l(
368
+ qe,
369
+ {
370
+ collection: o.collection,
371
+ value: S(r, o.field) || null,
372
+ onChange: (d) => ie(r, o.field, d == null ? "" : String(d)),
373
+ placeholder: "Select…"
374
+ }
375
+ ) }, o.field)),
376
+ ce.map((o) => /* @__PURE__ */ l("td", { className: "py-0.5 pr-2 text-right", children: /* @__PURE__ */ l(
377
+ "input",
378
+ {
379
+ type: "number",
380
+ min: t.allow_negative ? void 0 : 0,
381
+ value: S(r, o.field),
382
+ disabled: L,
383
+ "aria-invalid": o.field in (K[r.key] ?? {}) || void 0,
384
+ title: o.field in (K[r.key] ?? {}) ? Be(K[r.key][o.field]) : t.allow_negative ? void 0 : We,
385
+ onChange: (d) => {
386
+ !t.allow_negative && d.target.value.trim().startsWith("-") || ie(r, o.field, d.target.value);
387
+ },
388
+ className: Y(
389
+ "h-7 w-[84px] rounded border bg-white px-1.5 text-right text-[12px] tabular-nums outline-none focus:border-nvr-cyan dark:bg-background",
390
+ o.field in (K[r.key] ?? {}) ? "border-amber-500 ring-1 ring-amber-500/40" : "border-slate-200 dark:border-border"
391
+ )
392
+ }
393
+ ) }, o.field)),
394
+ t.allow_delete && /* @__PURE__ */ l("td", { className: "py-1 pl-2", children: /* @__PURE__ */ l(
395
+ "button",
396
+ {
397
+ type: "button",
398
+ onClick: () => {
399
+ r.record ? v((o) => {
400
+ var d;
401
+ return new Set(o).add(String((d = r.record) == null ? void 0 : d.id));
402
+ }) : w((o) => o.filter((d) => d !== r.key)), C((o) => {
403
+ const d = { ...o };
404
+ return delete d[r.key], d;
405
+ });
406
+ },
407
+ className: "rounded px-1.5 text-[12px] text-slate-400 hover:text-red-600",
408
+ children: "✕"
409
+ }
410
+ ) })
411
+ ] }, r.key)),
412
+ oe.length === 0 && /* @__PURE__ */ l("tr", { children: /* @__PURE__ */ l("td", { colSpan: 99, className: "py-3 text-center text-[12px] text-slate-400", children: "No rows" }) })
413
+ ] }),
414
+ /* @__PURE__ */ l("tfoot", { children: /* @__PURE__ */ u("tr", { className: "border-t border-slate-300 font-semibold dark:border-border", children: [
415
+ t.row_source && /* @__PURE__ */ l("td", { className: "py-1.5 pr-3", children: "Total" }),
416
+ (t.key_columns ?? []).map((r, o) => /* @__PURE__ */ l("td", { className: "py-1.5 pr-3", children: !t.row_source && o === 0 ? "Total" : "" }, r.field)),
417
+ ce.map((r) => /* @__PURE__ */ l("td", { className: "py-1.5 pr-2 text-right tabular-nums", children: oe.reduce((o, d) => o + (Number(S(d, r.field)) || 0), 0).toLocaleString("en-US", { maximumFractionDigits: 2 }) }, r.field)),
418
+ t.allow_delete && /* @__PURE__ */ l("td", {})
419
+ ] }) })
420
+ ] })
421
+ }
422
+ ) : /* @__PURE__ */ u("p", { className: "text-[12px] text-slate-400", children: [
356
423
  "Choose ",
357
424
  (t.scope ?? []).map((r) => r.label ?? r.field).join(", "),
358
425
  " to load rows."
359
426
  ] })
360
427
  ] });
361
428
  }
362
- const K = (t, m) => t == null || !Number.isFinite(t) || m != null && m.blankZero && t === 0 ? "—" : t.toLocaleString("en-US", { minimumFractionDigits: 2, maximumFractionDigits: 2 }), Ee = "Enter an amount of zero or more";
363
- function We(t, m) {
364
- const $ = t.replace(/[^\d.-]/g, "");
365
- if ($.includes("-") && !m) return { value: null, refused: Ee };
366
- const i = $.startsWith("-") ? "-" : "", p = $.replace(/-/g, ""), S = p.indexOf("."), g = S < 0 ? p : `${p.slice(0, S + 1)}${p.slice(S + 1).replace(/\./g, "")}`;
367
- return { value: `${i}${g}`, refused: null };
429
+ const te = (t, i) => t == null || !Number.isFinite(t) || i != null && i.blankZero && t === 0 ? "—" : t.toLocaleString("en-US", { minimumFractionDigits: 2, maximumFractionDigits: 2 }), We = "Enter an amount of zero or more";
430
+ function it(t, i) {
431
+ const g = t.replace(/[^\d.-]/g, "");
432
+ if (g.includes("-") && !i) return { value: null, refused: We };
433
+ const c = g.startsWith("-") ? "-" : "", m = g.replace(/-/g, ""), x = m.indexOf("."), C = x < 0 ? m : `${m.slice(0, x + 1)}${m.slice(x + 1).replace(/\./g, "")}`;
434
+ return { value: `${c}${C}`, refused: null };
368
435
  }
369
- function Be({
436
+ function ct({
370
437
  value: t,
371
- original: m,
372
- onChange: $,
373
- disabled: i,
374
- allowNegative: p = !1
438
+ original: i,
439
+ onChange: g,
440
+ disabled: c,
441
+ allowNegative: m = !1,
442
+ conflict: x
375
443
  }) {
376
- const [S, g] = N(!1), [C, q] = N(null), k = t !== m, y = t === "" ? null : Number(t), G = S || y == null || Number.isNaN(y) ? t : K(y), z = k && y != null && !Number.isNaN(y) ? y - (Number(m) || 0) : 0;
377
- return /* @__PURE__ */ c("span", { className: "relative inline-block", children: [
444
+ const [C, M] = k(!1), [w, O] = k(null), v = t !== i, j = t === "" ? null : Number(t), re = C || j == null || Number.isNaN(j) ? t : te(j), le = v && j != null && !Number.isNaN(j) ? j - (Number(i) || 0) : 0;
445
+ return /* @__PURE__ */ u("span", { className: "relative inline-block", children: [
378
446
  /* @__PURE__ */ l(
379
447
  "input",
380
448
  {
381
449
  type: "text",
382
450
  inputMode: "decimal",
383
- value: G,
384
- disabled: i,
385
- "aria-invalid": C ? !0 : void 0,
386
- title: C ?? (k ? `Was ${K(Number(m) || 0)} (${z >= 0 ? "+" : "−"}${K(Math.abs(z))})` : void 0),
387
- onFocus: (P) => {
388
- g(!0);
389
- const O = P.currentTarget;
451
+ value: re,
452
+ disabled: c,
453
+ "aria-invalid": w || x ? !0 : void 0,
454
+ title: w ?? x ?? (v ? `Was ${te(Number(i) || 0)} (${le >= 0 ? "+" : "−"}${te(Math.abs(le))})` : void 0),
455
+ onFocus: (U) => {
456
+ M(!0);
457
+ const R = U.currentTarget;
390
458
  requestAnimationFrame(() => {
391
- document.activeElement === O && O.select();
459
+ document.activeElement === R && R.select();
392
460
  });
393
461
  },
394
462
  onBlur: () => {
395
- g(!1), q(null);
463
+ M(!1), O(null);
396
464
  },
397
- onChange: (P) => {
398
- const O = We(P.target.value, p);
399
- q(O.refused), O.value != null && $(O.value);
465
+ onChange: (U) => {
466
+ const R = it(U.target.value, m);
467
+ O(R.refused), R.value != null && g(R.value);
400
468
  },
401
- className: X(
469
+ className: Y(
402
470
  "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",
403
- C ? "border-red-400 focus:border-red-400" : k ? "border-nvr-cyan bg-nvr-cyan/[0.06] dark:bg-nvr-cyan/10" : "border-slate-200 dark:border-border",
404
- !k && (y === 0 || y == null) && "text-slate-400"
471
+ w ? "border-red-400 focus:border-red-400" : x ? "border-amber-500 ring-1 ring-amber-500/40" : v ? "border-nvr-cyan bg-nvr-cyan/[0.06] dark:bg-nvr-cyan/10" : "border-slate-200 dark:border-border",
472
+ !v && (j === 0 || j == null) && "text-slate-400"
405
473
  )
406
474
  }
407
475
  ),
408
- C && /* @__PURE__ */ l(
476
+ w && /* @__PURE__ */ l(
409
477
  "span",
410
478
  {
411
479
  role: "alert",
412
480
  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",
413
- children: C
481
+ children: w
414
482
  }
415
483
  )
416
484
  ] });
417
485
  }
418
- function Qe({ config: t }) {
419
- var we, ge, ke;
420
- const m = $e(), $ = _e(), i = t.key_columns ?? [], [p, S] = N({}), [g, C] = N({}), [q, k] = N([]), [y, G] = N(/* @__PURE__ */ new Set()), [z, P] = N(!1), [O, W] = N(null), [J, T] = N(null), h = i.length > 0 && i.every((e) => p[e.field] != null && p[e.field] !== ""), v = I(() => {
486
+ function ut({ config: t }) {
487
+ var I, Oe, Te;
488
+ const i = Ae(), g = Re(), c = t.key_columns ?? [], [m, x] = k({}), [C, M] = k({}), [w, O] = k([]), [v, j] = k(/* @__PURE__ */ new Set()), [re, le] = k(!1), [U, R] = k(null), [ae, z] = k(null), [W, K] = k({}), B = Q(
489
+ () => new Pe(i, t.collection),
490
+ [i, t.collection]
491
+ ), p = c.length > 0 && c.every((e) => m[e.field] != null && m[e.field] !== ""), T = Q(() => {
421
492
  const e = (t.month_sets ?? []).flatMap(
422
- (a) => U.map((d, u) => ({
423
- field: `${d}${a.suffix}`,
424
- label: `${Te[u]}${a.label ? ` ${a.label}` : ""}`
493
+ (s) => ee.map((n, b) => ({
494
+ field: `${n}${s.suffix}`,
495
+ label: `${Ue[b]}${s.label ? ` ${s.label}` : ""}`
425
496
  }))
426
- ), s = (t.columns ?? []).map((a) => ({
427
- field: a.field,
428
- label: a.label ?? a.field
497
+ ), a = (t.columns ?? []).map((s) => ({
498
+ field: s.field,
499
+ label: s.label ?? s.field
429
500
  }));
430
- return [...e, ...s];
431
- }, [t.month_sets, t.columns]), _ = (we = t.month_sets) == null ? void 0 : we[0], { data: de = [], isLoading: Y } = ue({
501
+ return [...e, ...a];
502
+ }, [t.month_sets, t.columns]), _ = (I = t.month_sets) == null ? void 0 : I[0], { data: ye = [], isLoading: se } = ve({
432
503
  queryKey: ["record-grid-browse-rows", t.collection],
433
- queryFn: () => m.request(
434
- oe(`/items/${t.collection}`, { limit: 5e3 })
504
+ queryFn: () => i.request(
505
+ xe(`/items/${t.collection}`, { limit: 5e3 })
435
506
  ).then((e) => e.data ?? []),
436
- staleTime: 1e4
437
- }), { data: ne = {} } = ue({
438
- queryKey: ["record-grid-browse-labels", i.map((e) => e.collection).join(",")],
507
+ staleTime: 1e4,
508
+ // R1: another planner's saved values appear here; the person's own draft stays on top.
509
+ meta: Fe({ reads: [t.collection], minGapMs: 2e3 })
510
+ }), { data: ke = {} } = ve({
511
+ queryKey: ["record-grid-browse-labels", c.map((e) => e.collection).join(",")],
439
512
  queryFn: async () => {
440
513
  const e = {};
441
514
  return await Promise.all(
442
- i.map(async (s) => {
443
- const a = await m.request(
444
- oe(`/collections/${s.collection}`)
445
- ).then((b) => b.data).catch(() => null), d = await m.request(
446
- oe(`/items/${s.collection}`, { limit: 1e3 })
447
- ).then((b) => b.data ?? []).catch(() => []), u = /* @__PURE__ */ new Map();
448
- for (const b of d)
449
- u.set(String(b.id), Ge(a == null ? void 0 : a.display_template, b) || String(b.id));
450
- e[s.field] = u;
515
+ c.map(async (a) => {
516
+ const s = await i.request(
517
+ xe(`/collections/${a.collection}`)
518
+ ).then((h) => h.data).catch(() => null), n = await i.request(
519
+ xe(`/items/${a.collection}`, { limit: 1e3 })
520
+ ).then((h) => h.data ?? []).catch(() => []), b = /* @__PURE__ */ new Map();
521
+ for (const h of n)
522
+ b.set(String(h.id), st(s == null ? void 0 : s.display_template, h) || String(h.id));
523
+ e[a.field] = b;
451
524
  })
452
525
  ), e;
453
526
  },
454
- enabled: i.length > 0,
527
+ enabled: c.length > 0,
455
528
  staleTime: 3e5
456
- }), D = Fe(
457
- (e, s) => {
458
- var a;
459
- return s == null ? "—" : ((a = ne[e]) == null ? void 0 : a.get(String(s))) ?? String(s);
529
+ }), L = Ye(
530
+ (e, a) => {
531
+ var s;
532
+ return a == null ? "—" : ((s = ke[e]) == null ? void 0 : s.get(String(a))) ?? String(a);
460
533
  },
461
- [ne]
462
- ), j = I(
463
- () => de.filter(
464
- (e) => i.every(
465
- (s) => p[s.field] == null || p[s.field] === "" || String(e[s.field]) === String(p[s.field])
534
+ [ke]
535
+ ), P = Q(
536
+ () => ye.filter(
537
+ (e) => c.every(
538
+ (a) => m[a.field] == null || m[a.field] === "" || String(e[a.field]) === String(m[a.field])
466
539
  )
467
540
  ),
468
- [de, i, p]
469
- ), B = (ge = i[0]) == null ? void 0 : ge.field, w = i.filter((e) => p[e.field] == null || p[e.field] === ""), ee = I(() => {
470
- if (h) return [];
541
+ [ye, c, m]
542
+ ), oe = (Oe = c[0]) == null ? void 0 : Oe.field, S = c.filter((e) => m[e.field] == null || m[e.field] === ""), ie = Q(() => {
543
+ if (p) return [];
471
544
  const e = /* @__PURE__ */ new Map();
472
- for (const s of j) {
473
- const a = {};
474
- for (const b of w) a[b.field] = s[b.field];
475
- const d = w.map((b) => String(s[b.field] ?? "")).join("|"), u = e.get(d) ?? { keyVals: a, sums: {}, count: 0 };
476
- for (const b of v)
477
- u.sums[b.field] = (u.sums[b.field] ?? 0) + (Number(s[b.field]) || 0);
478
- u.count++, e.set(d, u);
545
+ for (const a of P) {
546
+ const s = {};
547
+ for (const h of S) s[h.field] = a[h.field];
548
+ const n = S.map((h) => String(a[h.field] ?? "")).join("|"), b = e.get(n) ?? { keyVals: s, sums: {}, count: 0 };
549
+ for (const h of T)
550
+ b.sums[h.field] = (b.sums[h.field] ?? 0) + (Number(a[h.field]) || 0);
551
+ b.count++, e.set(n, b);
479
552
  }
480
- return [...e.values()].sort((s, a) => {
481
- for (const d of w) {
482
- const u = D(d.field, s.keyVals[d.field]).localeCompare(
483
- D(d.field, a.keyVals[d.field]),
553
+ return [...e.values()].sort((a, s) => {
554
+ for (const n of S) {
555
+ const b = L(n.field, a.keyVals[n.field]).localeCompare(
556
+ L(n.field, s.keyVals[n.field]),
484
557
  void 0,
485
558
  { numeric: !0 }
486
559
  );
487
- if (u) return d.field === B ? -u : u;
560
+ if (b) return n.field === oe ? -b : b;
488
561
  }
489
562
  return 0;
490
563
  });
491
- }, [j, w, h, v, D, B]), E = I(() => h ? [
492
- ...j.filter((e) => !y.has(String(e.id))).map((e) => ({ key: `rec-${e.id}`, record: e, isNew: !1 })),
493
- ...q.map((e) => ({ key: e, record: null, isNew: !0 }))
494
- ] : [], [j, h, q, y]), fe = Re(null), te = I(
495
- () => E.filter((e) => {
496
- var s;
497
- return ((s = e.record) == null ? void 0 : s.id) != null;
564
+ }, [P, S, p, T, L, oe]), D = Q(() => p ? [
565
+ ...P.filter((e) => !v.has(String(e.id))).map((e) => ({ key: `rec-${e.id}`, record: e, isNew: !1 })),
566
+ ...w.map((e) => ({ key: e, record: null, isNew: !0 }))
567
+ ] : [], [P, p, w, v]), fe = et(null), ge = Q(
568
+ () => D.filter((e) => {
569
+ var a;
570
+ return ((a = e.record) == null ? void 0 : a.id) != null;
498
571
  }).map((e) => {
499
- var s;
500
- return String((s = e.record) == null ? void 0 : s.id);
572
+ var a;
573
+ return String((a = e.record) == null ? void 0 : a.id);
501
574
  }),
502
- [E]
503
- ), { editors: re } = ze({
504
- page: Pe(
575
+ [D]
576
+ ), { editors: Ce } = tt({
577
+ page: rt(
505
578
  "rgrid",
506
579
  t.collection,
507
- ...i.map((e) => String(p[e.field] ?? ""))
580
+ ...c.map((e) => String(m[e.field] ?? ""))
508
581
  ),
509
582
  collection: t.collection,
510
- items: te,
583
+ items: ge,
511
584
  containerRef: fe,
512
- enabled: h
513
- }), le = i.map((e) => D(e.field, p[e.field])).join(" · ");
514
- De(() => {
515
- h && j.length === 0 && q.length === 0 && y.size === 0 && k([`new-${Date.now()}`]);
516
- }, [h, j.length, q.length, y.size]);
517
- const r = (e, s) => {
518
- var u, b;
519
- const a = (u = g[e.key]) == null ? void 0 : u[s];
520
- if (a !== void 0) return a;
521
- const d = (b = e.record) == null ? void 0 : b[s];
522
- return d == null ? "" : String(d);
523
- }, o = (e, s) => {
524
- var d;
525
- const a = (d = e.record) == null ? void 0 : d[s];
526
- return a == null ? "" : String(a);
527
- }, n = (e, s, a) => C((d) => ({ ...d, [e]: { ...d[e] ?? {}, [s]: a } })), f = (e) => _ ? U.reduce((s, a) => s + (Number(r(e, `${a}${_.suffix}`)) || 0), 0) : null, F = Object.values(g).some((e) => Object.keys(e).length > 0) || y.size > 0 || q.some((e) => Object.keys(g[e] ?? {}).length > 0), x = () => {
528
- C({}), k([]), G(/* @__PURE__ */ new Set());
529
- }, R = (e) => {
530
- S((s) => ({ ...s, ...e })), x();
531
- }, ie = (e, s) => {
532
- S((a) => ({ ...a, [e]: s })), x();
585
+ enabled: p
586
+ });
587
+ je(() => {
588
+ const e = D.flatMap((a) => a.record ? [a.record] : []);
589
+ e.length > 0 && B.noteRows(e);
590
+ }, [B, D]);
591
+ const ce = c.map((e) => L(e.field, m[e.field])).join(" · ");
592
+ je(() => {
593
+ p && P.length === 0 && w.length === 0 && v.size === 0 && O([`new-${Date.now()}`]);
594
+ }, [p, P.length, w.length, v.size]);
595
+ const ue = (e, a) => {
596
+ var b, h;
597
+ const s = (b = C[e.key]) == null ? void 0 : b[a];
598
+ if (s !== void 0) return s;
599
+ const n = (h = e.record) == null ? void 0 : h[a];
600
+ return n == null ? "" : String(n);
601
+ }, we = (e, a) => {
602
+ var n;
603
+ const s = (n = e.record) == null ? void 0 : n[a];
604
+ return s == null ? "" : String(s);
605
+ }, r = (e, a, s) => {
606
+ var n;
607
+ ((n = e.record) == null ? void 0 : n.id) != null && B.pin(String(e.record.id)), M((b) => ({ ...b, [e.key]: { ...b[e.key] ?? {}, [a]: s } }));
608
+ }, o = Object.values(W).reduce((e, a) => e + Object.keys(a).length, 0), d = (e) => _ ? ee.reduce((a, s) => a + (Number(ue(e, `${s}${_.suffix}`)) || 0), 0) : null, f = Object.values(C).some((e) => Object.keys(e).length > 0) || v.size > 0 || w.some((e) => Object.keys(C[e] ?? {}).length > 0), N = () => {
609
+ M({}), O([]), j(/* @__PURE__ */ new Set()), K({}), B.release();
610
+ }, H = (e) => {
611
+ x((a) => ({ ...a, ...e })), N();
612
+ }, Ne = (e, a) => {
613
+ x((s) => ({ ...s, [e]: a })), N();
533
614
  };
534
- async function L(e) {
535
- P(!0), T(null);
536
- let s = 0, a = 0, d = 0;
615
+ async function ne(e) {
616
+ le(!0), z(null);
617
+ let a = 0, s = 0, n = 0;
618
+ const b = {}, h = (de) => T.some((me) => me.field === de);
537
619
  try {
538
- for (const u of E) {
539
- const b = g[u.key] ?? {};
540
- if (Object.keys(b).length === 0) continue;
541
- const H = {};
542
- for (const [se, ce] of Object.entries(b))
543
- v.some((Le) => Le.field === se) && (H[se] = ce === "" ? null : Number.isNaN(Number(ce)) ? ce : Number(ce));
544
- if (t.computed_total_field && _ && (H[t.computed_total_field] = f(u)), u.record)
545
- e && (H._change_reason = e), await m.request(Se(`/items/${t.collection}/${u.record.id}`, H)), a++;
546
- else {
547
- for (const se of i) H[se.field] = p[se.field];
548
- await m.request(be(`/items/${t.collection}`, H)), s++;
549
- }
620
+ for (const $ of D) {
621
+ const V = C[$.key] ?? {};
622
+ if (Object.keys(V).length !== 0)
623
+ if ($.record) {
624
+ const J = Ke(
625
+ V,
626
+ $.record,
627
+ h,
628
+ t.computed_total_field && _ ? {
629
+ field: t.computed_total_field,
630
+ of: ee.map((be) => `${be}${_.suffix}`)
631
+ } : null
632
+ );
633
+ if (!J) continue;
634
+ e && (J._change_reason = e);
635
+ const Z = await B.write(String($.record.id), J);
636
+ Z.ok ? s++ : Object.assign(b, Ve($.key, Z.conflicts));
637
+ } else {
638
+ const J = {};
639
+ for (const [Z, be] of Object.entries(V))
640
+ h(Z) && (J[Z] = be === "" ? null : Number.isNaN(Number(be)) ? be : Number(be));
641
+ t.computed_total_field && _ && (J[t.computed_total_field] = d($));
642
+ for (const Z of c) J[Z.field] = m[Z.field];
643
+ await i.request(Se(`/items/${t.collection}`, J)), a++;
644
+ }
550
645
  }
551
- for (const u of y)
552
- await m.request(Ce(`/items/${t.collection}/${u}`)), d++;
553
- if (t.after_save) {
554
- const u = Z(t.after_save.params ?? {}, p);
555
- await m.request(
556
- be(`/custom-queries/${t.after_save.query_slug}/execute`, { params: u })
646
+ for (const $ of v)
647
+ await i.request(Ee(`/items/${t.collection}/${$}`)), n++;
648
+ if (t.after_save && s + a + n > 0) {
649
+ const $ = pe(t.after_save.params ?? {}, m);
650
+ await i.request(
651
+ Se(`/custom-queries/${t.after_save.query_slug}/execute`, { params: $ })
557
652
  );
558
653
  }
559
- x(), await $.invalidateQueries({ queryKey: ["record-grid-browse-rows", t.collection] }), T(
560
- `Saved — ${a} updated, ${s} created${d ? `, ${d} deleted` : ""}`
561
- );
562
- } catch (u) {
563
- const b = Oe(u);
564
- b ? W(b) : T(`Save failed: ${qe(u, "unknown error")}`);
654
+ const de = new Set(w), me = new Set(v);
655
+ M(($) => {
656
+ const V = Je($, C, new Set(Object.keys(b)));
657
+ for (const J of de) delete V[J];
658
+ return V;
659
+ }), O(($) => $.filter((V) => !de.has(V))), j(($) => new Set([...$].filter((V) => !me.has(V)))), K(b), await g.invalidateQueries({ queryKey: ["record-grid-browse-rows", t.collection] }), z(Ie(s, a, n, b));
660
+ } catch (de) {
661
+ const me = ze(de);
662
+ me ? R(me) : z(`Save failed: ${Le(de, "unknown error")}`);
565
663
  } finally {
566
- P(!1);
664
+ le(!1);
567
665
  }
568
666
  }
569
- const A = (e) => h ? E.reduce((s, a) => s + (Number(r(a, e)) || 0), 0) : ee.reduce((s, a) => s + (a.sums[e] ?? 0), 0), M = (e) => _ && e < 12 && e % 3 === 0 && e > 0, V = (e) => _ && e < 12 && Math.floor(e / 3) % 2 === 1 ? "bg-slate-50/70 dark:bg-muted/30" : "", [ae, he] = Ie("accent"), Q = { "--qtc": ae, "--qtcd": he }, xe = "text-[color:var(--qtc)] dark:text-[color:var(--qtcd)]", Ne = (e, s, a = "") => /* @__PURE__ */ l(
667
+ const he = (e) => p ? D.reduce((a, s) => a + (Number(ue(s, e)) || 0), 0) : ie.reduce((a, s) => a + (s.sums[e] ?? 0), 0), q = (e) => _ && e < 12 && e % 3 === 0 && e > 0, G = (e) => _ && e < 12 && Math.floor(e / 3) % 2 === 1 ? "bg-slate-50/70 dark:bg-muted/30" : "", [y, A] = nt("accent"), X = { "--qtc": y, "--qtcd": A }, E = "text-[color:var(--qtc)] dark:text-[color:var(--qtcd)]", F = (e, a, s = "") => /* @__PURE__ */ l(
570
668
  "th",
571
669
  {
572
- className: X(
670
+ className: Y(
573
671
  "whitespace-nowrap px-2 py-2 text-right text-[10.5px] font-semibold uppercase tracking-wide text-slate-400",
574
- M(s) && "border-l border-slate-200 dark:border-border",
575
- V(s),
576
- a
672
+ q(a) && "border-l border-slate-200 dark:border-border",
673
+ G(a),
674
+ s
577
675
  ),
578
676
  children: e
579
677
  },
580
- e + s
678
+ e + a
581
679
  );
582
- return /* @__PURE__ */ c("div", { ref: fe, className: "flex h-full min-h-0 flex-col", "data-record-grid-browse": !0, children: [
680
+ return /* @__PURE__ */ u("div", { ref: fe, className: "flex h-full min-h-0 flex-col", "data-record-grid-browse": !0, children: [
583
681
  /* @__PURE__ */ l(
584
- je,
682
+ De,
585
683
  {
586
- challenge: O,
587
- onCancel: () => W(null),
684
+ challenge: U,
685
+ onCancel: () => R(null),
588
686
  onSubmit: (e) => {
589
- W(null), L(e);
687
+ R(null), ne(e);
590
688
  }
591
689
  }
592
690
  ),
593
- /* @__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: [
594
- i.map((e) => /* @__PURE__ */ c("div", { className: "w-52", children: [
691
+ /* @__PURE__ */ u("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: [
692
+ c.map((e) => /* @__PURE__ */ u("div", { className: "w-52", children: [
595
693
  /* @__PURE__ */ l("p", { className: "mb-1 text-[11px] font-medium text-slate-500 dark:text-slate-400", children: e.label ?? e.field }),
596
694
  /* @__PURE__ */ l(
597
- ye,
695
+ qe,
598
696
  {
599
697
  collection: e.collection,
600
- value: p[e.field] ?? null,
601
- onChange: (s) => ie(e.field, s),
698
+ value: m[e.field] ?? null,
699
+ onChange: (a) => Ne(e.field, a),
602
700
  placeholder: "All",
603
701
  optionSort: e.collection === "funding_years" ? "-id" : void 0
604
702
  }
605
703
  )
606
704
  ] }, e.field)),
607
705
  /* @__PURE__ */ l("span", { className: "flex-1" }),
608
- J && /* @__PURE__ */ l("span", { className: "pb-2 text-[12px] text-slate-500", children: J }),
609
- h && t.allow_add && /* @__PURE__ */ l(
706
+ ae && /* @__PURE__ */ l("span", { className: "pb-2 text-[12px] text-slate-500", children: ae }),
707
+ o > 0 && /* @__PURE__ */ l(
708
+ Qe,
709
+ {
710
+ count: o,
711
+ onClick: () => {
712
+ M((e) => Ge(e, W)), K({});
713
+ }
714
+ }
715
+ ),
716
+ p && t.allow_add && /* @__PURE__ */ l(
610
717
  "button",
611
718
  {
612
719
  type: "button",
613
- onClick: () => k((e) => [...e, `new-${Date.now()}`]),
720
+ onClick: () => O((e) => [...e, `new-${Date.now()}`]),
614
721
  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",
615
722
  children: "+ Add row"
616
723
  }
617
724
  ),
618
- F && /* @__PURE__ */ l(
725
+ f && /* @__PURE__ */ l(
619
726
  "button",
620
727
  {
621
728
  type: "button",
622
- onClick: x,
729
+ onClick: N,
623
730
  className: "h-9 rounded-md px-3 text-[13px] font-medium text-slate-600 hover:bg-slate-100 dark:text-slate-300 dark:hover:bg-muted",
624
731
  children: "Discard"
625
732
  }
626
733
  ),
627
- /* @__PURE__ */ c(
734
+ /* @__PURE__ */ u(
628
735
  "button",
629
736
  {
630
737
  type: "button",
631
- disabled: !h || !F || z,
632
- onClick: () => void L(),
738
+ disabled: !p || !f || re,
739
+ onClick: () => void ne(),
633
740
  "data-record-grid-save": !0,
634
741
  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",
635
742
  children: [
636
- z && /* @__PURE__ */ l(me, { className: "h-3.5 w-3.5 animate-spin" }),
743
+ re && /* @__PURE__ */ l(_e, { className: "h-3.5 w-3.5 animate-spin" }),
637
744
  "Save changes"
638
745
  ]
639
746
  }
640
747
  )
641
748
  ] }),
642
- /* @__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: [
643
- h ? /* @__PURE__ */ c("span", { children: [
749
+ /* @__PURE__ */ u("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: [
750
+ p ? /* @__PURE__ */ u("span", { children: [
644
751
  "Editing",
645
752
  " ",
646
- /* @__PURE__ */ l("strong", { className: "text-slate-700 dark:text-slate-200", children: i.map((e) => D(e.field, p[e.field])).join(" · ") }),
647
- E.length > 1 && ` — ${E.length} rows share this combination`
753
+ /* @__PURE__ */ l("strong", { className: "text-slate-700 dark:text-slate-200", children: c.map((e) => L(e.field, m[e.field])).join(" · ") }),
754
+ D.length > 1 && ` — ${D.length} rows share this combination`
648
755
  ] }) : null,
649
- h && re.length > 0 ? /* @__PURE__ */ l(
650
- Ke,
756
+ p && Ce.length > 0 ? /* @__PURE__ */ l(
757
+ at,
651
758
  {
652
759
  className: "ml-3 border-l border-slate-200 pl-3 dark:border-border",
653
- editors: re,
654
- noun: ((ke = t.presence_noun) == null ? void 0 : ke.trim()) || t.collection.replace(/_/g, " ").toLowerCase(),
655
- rowLabel: (e) => E.length > 1 ? `${le} (#${e})` : le || `#${e}`,
760
+ editors: Ce,
761
+ noun: ((Te = t.presence_noun) == null ? void 0 : Te.trim()) || t.collection.replace(/_/g, " ").toLowerCase(),
762
+ rowLabel: (e) => D.length > 1 ? `${ce} (#${e})` : ce || `#${e}`,
656
763
  cellLabel: (e) => {
657
- var s;
658
- return (s = v.find((a) => a.field === e)) == null ? void 0 : s.label;
764
+ var a;
765
+ return (a = T.find((s) => s.field === e)) == null ? void 0 : a.label;
659
766
  }
660
767
  }
661
768
  ) : null,
662
- h ? null : /* @__PURE__ */ c("span", { children: [
769
+ p ? null : /* @__PURE__ */ u("span", { children: [
663
770
  "Totals across",
664
771
  " ",
665
- /* @__PURE__ */ l("strong", { className: "text-slate-700 dark:text-slate-200", children: j.length }),
772
+ /* @__PURE__ */ l("strong", { className: "text-slate-700 dark:text-slate-200", children: P.length }),
666
773
  " row",
667
- j.length === 1 ? "" : "s",
668
- w.length > 0 && /* @__PURE__ */ c(Ae, { children: [
774
+ P.length === 1 ? "" : "s",
775
+ S.length > 0 && /* @__PURE__ */ u(He, { children: [
669
776
  ", by ",
670
- w.map((e) => e.label ?? e.field).join(" and "),
777
+ S.map((e) => e.label ?? e.field).join(" and "),
671
778
  " — pick",
672
779
  " ",
673
- w.map((e) => e.label ?? e.field).join(", "),
780
+ S.map((e) => e.label ?? e.field).join(", "),
674
781
  " to edit"
675
782
  ] })
676
783
  ] }),
677
- Object.keys(p).some((e) => p[e] != null && p[e] !== "") && /* @__PURE__ */ c(
784
+ Object.keys(m).some((e) => m[e] != null && m[e] !== "") && /* @__PURE__ */ u(
678
785
  "button",
679
786
  {
680
787
  type: "button",
681
788
  onClick: () => {
682
- S({}), x();
789
+ x({}), N();
683
790
  },
684
791
  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",
685
792
  children: [
686
- /* @__PURE__ */ l(ve, { className: "h-3 w-3" }),
793
+ /* @__PURE__ */ l(Me, { className: "h-3 w-3" }),
687
794
  " Clear"
688
795
  ]
689
796
  }
690
797
  )
691
798
  ] }),
692
- /* @__PURE__ */ l("div", { className: "min-h-0 flex-1 overflow-auto", children: Y ? /* @__PURE__ */ c("div", { className: "flex items-center gap-2 p-4 text-[12px] text-slate-400", children: [
693
- /* @__PURE__ */ l(me, { className: "h-4 w-4 animate-spin" }),
799
+ /* @__PURE__ */ l("div", { className: "min-h-0 flex-1 overflow-auto", children: se ? /* @__PURE__ */ u("div", { className: "flex items-center gap-2 p-4 text-[12px] text-slate-400", children: [
800
+ /* @__PURE__ */ l(_e, { className: "h-4 w-4 animate-spin" }),
694
801
  " Loading…"
695
- ] }) : /* @__PURE__ */ c("table", { className: "w-full text-[12px]", children: [
696
- /* @__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: [
697
- (h ? [{ field: "__row", label: "" }] : w.map((e) => ({ field: e.field, label: e.label ?? e.field }))).map((e) => /* @__PURE__ */ l(
802
+ ] }) : /* @__PURE__ */ u("table", { className: "w-full text-[12px]", children: [
803
+ /* @__PURE__ */ l("thead", { className: "sticky top-0 z-[1] bg-white dark:bg-card", children: /* @__PURE__ */ u("tr", { className: "border-b border-slate-200 dark:border-border", children: [
804
+ (p ? [{ field: "__row", label: "" }] : S.map((e) => ({ field: e.field, label: e.label ?? e.field }))).map((e) => /* @__PURE__ */ l(
698
805
  "th",
699
806
  {
700
807
  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",
@@ -702,45 +809,46 @@ function Qe({ config: t }) {
702
809
  },
703
810
  e.field
704
811
  )),
705
- v.map((e, s) => Ne(e.label, s)),
706
- _ && Ne("Total", 99, "border-l border-slate-200 dark:border-border"),
707
- h && t.allow_delete && /* @__PURE__ */ l("th", { "aria-label": "Remove", className: "w-8" })
812
+ T.map((e, a) => F(e.label, a)),
813
+ _ && F("Total", 99, "border-l border-slate-200 dark:border-border"),
814
+ p && t.allow_delete && /* @__PURE__ */ l("th", { "aria-label": "Remove", className: "w-8" })
708
815
  ] }) }),
709
- /* @__PURE__ */ c("tbody", { children: [
710
- h ? E.map((e) => {
711
- var s;
712
- return /* @__PURE__ */ c("tr", { className: "border-b border-slate-100 dark:border-border/50", children: [
713
- /* @__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" }) : `#${(s = e.record) == null ? void 0 : s.id}` }),
714
- v.map((a, d) => {
715
- var u;
816
+ /* @__PURE__ */ u("tbody", { children: [
817
+ p ? D.map((e) => {
818
+ var a;
819
+ return /* @__PURE__ */ u("tr", { className: "border-b border-slate-100 dark:border-border/50", children: [
820
+ /* @__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" }) : `#${(a = e.record) == null ? void 0 : a.id}` }),
821
+ T.map((s, n) => {
822
+ var b;
716
823
  return /* @__PURE__ */ l(
717
824
  "td",
718
825
  {
719
- "data-grid-cell": ((u = e.record) == null ? void 0 : u.id) != null ? Ve(String(e.record.id), a.field) : void 0,
720
- className: X(
826
+ "data-grid-cell": ((b = e.record) == null ? void 0 : b.id) != null ? lt(String(e.record.id), s.field) : void 0,
827
+ className: Y(
721
828
  "px-1 py-0.5 text-right",
722
- M(d) && "border-l border-slate-100 dark:border-border/50",
723
- V(d)
829
+ q(n) && "border-l border-slate-100 dark:border-border/50",
830
+ G(n)
724
831
  ),
725
832
  children: /* @__PURE__ */ l(
726
- Be,
833
+ ct,
727
834
  {
728
- value: r(e, a.field),
729
- original: o(e, a.field),
730
- onChange: (b) => n(e.key, a.field, b),
731
- allowNegative: !!t.allow_negative
835
+ value: ue(e, s.field),
836
+ original: we(e, s.field),
837
+ onChange: (h) => r(e, s.field, h),
838
+ allowNegative: !!t.allow_negative,
839
+ conflict: s.field in (W[e.key] ?? {}) ? Be(W[e.key][s.field]) : void 0
732
840
  }
733
841
  )
734
842
  },
735
- a.field
843
+ s.field
736
844
  );
737
845
  }),
738
846
  _ && /* @__PURE__ */ l(
739
847
  "td",
740
848
  {
741
- className: `border-l border-slate-200 px-2 py-1 text-right font-semibold tabular-nums dark:border-border ${xe}`,
742
- style: Q,
743
- children: K(f(e))
849
+ className: `border-l border-slate-200 px-2 py-1 text-right font-semibold tabular-nums dark:border-border ${E}`,
850
+ style: X,
851
+ children: te(d(e))
744
852
  }
745
853
  ),
746
854
  t.allow_delete && /* @__PURE__ */ l("td", { className: "py-1 pl-1", children: /* @__PURE__ */ l(
@@ -749,71 +857,71 @@ function Qe({ config: t }) {
749
857
  type: "button",
750
858
  "aria-label": "Remove row",
751
859
  onClick: () => {
752
- e.record ? G((a) => {
753
- var d;
754
- return new Set(a).add(String((d = e.record) == null ? void 0 : d.id));
755
- }) : k((a) => a.filter((d) => d !== e.key)), C((a) => {
756
- const d = { ...a };
757
- return delete d[e.key], d;
860
+ e.record ? j((s) => {
861
+ var n;
862
+ return new Set(s).add(String((n = e.record) == null ? void 0 : n.id));
863
+ }) : O((s) => s.filter((n) => n !== e.key)), M((s) => {
864
+ const n = { ...s };
865
+ return delete n[e.key], n;
758
866
  });
759
867
  },
760
868
  className: "rounded p-1 text-slate-400 hover:text-red-600",
761
- children: /* @__PURE__ */ l(ve, { className: "h-3.5 w-3.5" })
869
+ children: /* @__PURE__ */ l(Me, { className: "h-3.5 w-3.5" })
762
870
  }
763
871
  ) })
764
872
  ] }, e.key);
765
- }) : ee.map((e) => {
766
- const s = w.map((a) => String(e.keyVals[a.field] ?? "")).join("|");
767
- return /* @__PURE__ */ c(
873
+ }) : ie.map((e) => {
874
+ const a = S.map((s) => String(e.keyVals[s.field] ?? "")).join("|");
875
+ return /* @__PURE__ */ u(
768
876
  "tr",
769
877
  {
770
878
  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",
771
- onClick: () => R(e.keyVals),
772
- onKeyDown: (a) => {
773
- (a.key === "Enter" || a.key === " ") && (a.preventDefault(), R(e.keyVals));
879
+ onClick: () => H(e.keyVals),
880
+ onKeyDown: (s) => {
881
+ (s.key === "Enter" || s.key === " ") && (s.preventDefault(), H(e.keyVals));
774
882
  },
775
883
  tabIndex: 0,
776
884
  title: "Open this combination",
777
885
  children: [
778
- w.map((a, d) => /* @__PURE__ */ c(
886
+ S.map((s, n) => /* @__PURE__ */ u(
779
887
  "td",
780
888
  {
781
- className: X(
889
+ className: Y(
782
890
  "whitespace-nowrap px-2 py-1.5 text-slate-700 dark:text-slate-200",
783
- d === 0 && "sticky left-0 z-[1] bg-white font-medium dark:bg-card"
891
+ n === 0 && "sticky left-0 z-[1] bg-white font-medium dark:bg-card"
784
892
  ),
785
893
  children: [
786
- d === 0 && /* @__PURE__ */ l(Me, { className: "mr-1 inline h-3 w-3 text-slate-300" }),
787
- D(a.field, e.keyVals[a.field]),
788
- d === w.length - 1 && e.count > 1 && /* @__PURE__ */ c("span", { className: "ml-1.5 text-[10.5px] text-slate-400", children: [
894
+ n === 0 && /* @__PURE__ */ l(Ze, { className: "mr-1 inline h-3 w-3 text-slate-300" }),
895
+ L(s.field, e.keyVals[s.field]),
896
+ n === S.length - 1 && e.count > 1 && /* @__PURE__ */ u("span", { className: "ml-1.5 text-[10.5px] text-slate-400", children: [
789
897
  e.count,
790
898
  " rows"
791
899
  ] })
792
900
  ]
793
901
  },
794
- a.field
902
+ s.field
795
903
  )),
796
- v.map((a, d) => /* @__PURE__ */ l(
904
+ T.map((s, n) => /* @__PURE__ */ l(
797
905
  "td",
798
906
  {
799
- className: X(
907
+ className: Y(
800
908
  "whitespace-nowrap px-1.5 py-1.5 text-right tabular-nums",
801
- M(d) && "border-l border-slate-100 dark:border-border/50",
802
- V(d),
803
- (e.sums[a.field] ?? 0) === 0 ? "text-slate-300 dark:text-slate-600" : "text-slate-700 dark:text-slate-200"
909
+ q(n) && "border-l border-slate-100 dark:border-border/50",
910
+ G(n),
911
+ (e.sums[s.field] ?? 0) === 0 ? "text-slate-300 dark:text-slate-600" : "text-slate-700 dark:text-slate-200"
804
912
  ),
805
- children: K(e.sums[a.field], { blankZero: !0 })
913
+ children: te(e.sums[s.field], { blankZero: !0 })
806
914
  },
807
- a.field
915
+ s.field
808
916
  )),
809
917
  _ && /* @__PURE__ */ l(
810
918
  "td",
811
919
  {
812
- className: `border-l border-slate-200 px-2 py-1.5 text-right font-semibold tabular-nums dark:border-border ${xe}`,
813
- style: Q,
814
- children: K(
815
- U.reduce(
816
- (a, d) => a + (e.sums[`${d}${_.suffix}`] ?? 0),
920
+ className: `border-l border-slate-200 px-2 py-1.5 text-right font-semibold tabular-nums dark:border-border ${E}`,
921
+ style: X,
922
+ children: te(
923
+ ee.reduce(
924
+ (s, n) => s + (e.sums[`${n}${_.suffix}`] ?? 0),
817
925
  0
818
926
  )
819
927
  )
@@ -821,48 +929,50 @@ function Qe({ config: t }) {
821
929
  )
822
930
  ]
823
931
  },
824
- s
932
+ a
825
933
  );
826
934
  }),
827
- !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" }) })
935
+ !p && ie.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" }) })
828
936
  ] }),
829
- /* @__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: [
937
+ /* @__PURE__ */ l("tfoot", { className: "sticky bottom-0 bg-white dark:bg-card", children: /* @__PURE__ */ u("tr", { className: "border-t-2 border-slate-300 dark:border-border", children: [
830
938
  /* @__PURE__ */ l(
831
939
  "td",
832
940
  {
833
- colSpan: h ? 1 : Math.max(1, w.length),
941
+ colSpan: p ? 1 : Math.max(1, S.length),
834
942
  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",
835
943
  children: "Total"
836
944
  }
837
945
  ),
838
- v.map((e, s) => /* @__PURE__ */ l(
946
+ T.map((e, a) => /* @__PURE__ */ l(
839
947
  "td",
840
948
  {
841
- className: X(
949
+ className: Y(
842
950
  "px-2 py-2 text-right font-semibold tabular-nums text-slate-800 dark:text-slate-100",
843
- M(s) && "border-l border-slate-200 dark:border-border",
844
- V(s)
951
+ q(a) && "border-l border-slate-200 dark:border-border",
952
+ G(a)
845
953
  ),
846
- children: K(A(e.field))
954
+ children: te(he(e.field))
847
955
  },
848
956
  e.field
849
957
  )),
850
958
  _ && /* @__PURE__ */ l(
851
959
  "td",
852
960
  {
853
- className: `border-l border-slate-200 px-2 py-2 text-right font-semibold tabular-nums dark:border-border ${xe}`,
854
- style: Q,
855
- children: K(U.reduce((e, s) => e + A(`${s}${_.suffix}`), 0))
961
+ className: `border-l border-slate-200 px-2 py-2 text-right font-semibold tabular-nums dark:border-border ${E}`,
962
+ style: X,
963
+ children: te(ee.reduce((e, a) => e + he(`${a}${_.suffix}`), 0))
856
964
  }
857
965
  ),
858
- h && t.allow_delete && /* @__PURE__ */ l("td", {})
966
+ p && t.allow_delete && /* @__PURE__ */ l("td", {})
859
967
  ] }) })
860
968
  ] }) })
861
969
  ] });
862
970
  }
863
971
  export {
864
- Ee as NEGATIVE_AMOUNT_MESSAGE,
865
- Be as NumberCell,
866
- ut as RecordGridEditor,
867
- We as sanitizeAmount
972
+ We as NEGATIVE_AMOUNT_MESSAGE,
973
+ ct as NumberCell,
974
+ qt as RecordGridEditor,
975
+ Be as conflictTip,
976
+ it as sanitizeAmount,
977
+ Ie as saveStatus
868
978
  };