@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,557 +1,593 @@
1
- import { jsxs as b, jsx as d, Fragment as we } from "react/jsx-runtime";
2
- import { useQueryClient as ft, useQuery as re } from "@tanstack/react-query";
3
- import { Loader2 as rt, ChevronRight as lt } from "lucide-react";
4
- import { useState as le, useRef as de, useEffect as ve, useMemo as g } from "react";
5
- import { useNivaroClient as ht } from "../context.js";
6
- import { get as se, post as st, patch as xt } from "../lib/commands.js";
7
- import { evaluateNumeric as _t } from "../lib/expression.js";
8
- import { gridPageKey as yt, useGridPresence as kt, gridPresenceCell as vt } from "../lib/grid-presence.js";
9
- import { userErrorMessage as Nt } from "../lib/safe-error.js";
10
- import { cn as S } from "../lib/utils.js";
11
- import { GridPresenceLine as gt } from "./GridPresenceLine.js";
12
- import { RelationCombobox as wt } from "./item-edit/RelationCombobox.js";
13
- import { useRecordLabels as $t } from "./item-edit/useRecordLabels.js";
14
- import { colorPair as St } from "./QueryTable.js";
15
- const J = "__uncat__", V = "__bucket__";
16
- function Ne(t, _) {
1
+ import { jsxs as x, jsx as d, Fragment as Me } from "react/jsx-runtime";
2
+ import { useQueryClient as gt, useQuery as oe } from "@tanstack/react-query";
3
+ import { Loader2 as ut, ChevronRight as mt } from "lucide-react";
4
+ import { useState as Q, useRef as ie, useEffect as xe, useMemo as j } from "react";
5
+ import { useNivaroClient as wt } from "../context.js";
6
+ import { get as ce, post as pt } from "../lib/commands.js";
7
+ import { evaluateNumeric as $t } from "../lib/expression.js";
8
+ import { gridPageKey as St, useGridPresence as jt, gridPresenceCell as Ct } from "../lib/grid-presence.js";
9
+ import { liveQueryMeta as Ot } from "../lib/live-queries.js";
10
+ import { userErrorMessage as qt } from "../lib/safe-error.js";
11
+ import { cn as O } from "../lib/utils.js";
12
+ import { GridPresenceLine as Lt } from "./GridPresenceLine.js";
13
+ import { RelationCombobox as Mt } from "./item-edit/RelationCombobox.js";
14
+ import { useRecordLabels as Rt } from "./item-edit/useRecordLabels.js";
15
+ import { colorPair as Ft } from "./QueryTable.js";
16
+ import { GridRowGuard as Et, settleEditsAfterSave as Gt } from "./record-grid-guard.js";
17
+ const V = "__uncat__", B = "__bucket__";
18
+ function qe(t, _) {
17
19
  if (!t) return;
18
- const $ = (f) => typeof f == "string" && f.startsWith("$scope.") ? _[f.slice(7)] : Array.isArray(f) ? f.map($) : f && typeof f == "object" ? Object.fromEntries(
19
- Object.entries(f).map(([N, h]) => [N, $(h)])
20
- ) : f;
21
- return $(t);
20
+ const k = (p) => typeof p == "string" && p.startsWith("$scope.") ? _[p.slice(7)] : Array.isArray(p) ? p.map(k) : p && typeof p == "object" ? Object.fromEntries(
21
+ Object.entries(p).map(([w, b]) => [w, k(b)])
22
+ ) : p;
23
+ return k(t);
22
24
  }
23
- function $e(t) {
24
- return t === void 0 ? !0 : Array.isArray(t) ? t.some($e) : t && typeof t == "object" ? Object.values(t).some($e) : !1;
25
+ function Re(t) {
26
+ return t === void 0 ? !0 : Array.isArray(t) ? t.some(Re) : t && typeof t == "object" ? Object.values(t).some(Re) : !1;
25
27
  }
26
- function ae(t, _) {
28
+ function de(t, _) {
27
29
  if (t && typeof t == "object") {
28
- const N = _.replace(/\[\d+\]/g, "");
29
- if (N in t)
30
- return t[N] ?? null;
30
+ const w = _.replace(/\[\d+\]/g, "");
31
+ if (w in t)
32
+ return t[w] ?? null;
31
33
  }
32
- const $ = _.split(".").flatMap((N) => {
33
- const h = /^(\w+)\[(\d+)\]$/.exec(N);
34
- return h ? [h[1], Number(h[2])] : [N];
34
+ const k = _.split(".").flatMap((w) => {
35
+ const b = /^(\w+)\[(\d+)\]$/.exec(w);
36
+ return b ? [b[1], Number(b[2])] : [w];
35
37
  });
36
- let f = t;
37
- for (const N of $) {
38
- if (f == null || typeof f != "object") return null;
39
- f = f[N];
38
+ let p = t;
39
+ for (const w of k) {
40
+ if (p == null || typeof p != "object") return null;
41
+ p = p[w];
40
42
  }
41
- return f ?? null;
43
+ return p ?? null;
42
44
  }
43
- function ge(t, _) {
44
- return t.replace(/\{\{\s*([\w.[\]]+)\s*\}\}/g, ($, f) => {
45
- const N = ae(_, f);
46
- return N == null ? "" : String(N);
45
+ function Le(t, _) {
46
+ return t.replace(/\{\{\s*([\w.[\]]+)\s*\}\}/g, (k, p) => {
47
+ const w = de(_, p);
48
+ return w == null ? "" : String(w);
47
49
  });
48
50
  }
49
- function L(t, _) {
50
- const $ = Number(t);
51
- return t == null || t === "" || !Number.isFinite($) ? "—" : _ === "currency" ? $.toLocaleString("en-US", { style: "currency", currency: "USD" }) : $.toLocaleString("en-US", { maximumFractionDigits: 2 });
51
+ function R(t, _) {
52
+ const k = Number(t);
53
+ return t == null || t === "" || !Number.isFinite(k) ? "—" : _ === "currency" ? k.toLocaleString("en-US", { style: "currency", currency: "USD" }) : k.toLocaleString("en-US", { maximumFractionDigits: 2 });
52
54
  }
53
- function Ut({
55
+ function tr({
54
56
  config: t,
55
57
  initialScope: _,
56
- lockScope: $ = !1
58
+ lockScope: k = !1
57
59
  }) {
58
- var Be, Ie, He, Xe, Ye, Ze, et;
59
- const f = ht(), N = ft(), [h, ue] = le(_ ?? {}), Se = de(_);
60
- ve(() => {
61
- Se.current !== _ && (Se.current = _, _ && ue((e) => ({ ...e, ..._ })));
60
+ var st, lt, at, nt, ot, it, ct;
61
+ const p = wt(), w = gt(), [b, D] = Q(_ ?? {}), _e = ie(_);
62
+ xe(() => {
63
+ _e.current !== _ && (_e.current = _, _ && D((e) => ({ ...e, ..._ })));
62
64
  }, [_]);
63
- const [K, D] = le({}), [je, Ce] = le(!1), [qe, me] = le(null), [Oe, Le] = le(/* @__PURE__ */ new Set()), F = t.scope_fields.every(
64
- (e) => h[e.field] !== null && h[e.field] !== void 0 && h[e.field] !== ""
65
- ), Fe = de(null), M = t.scope_fields[0], Q = M && F ? String(h[M.field]) : null, nt = yt(
65
+ const [L, ee] = Q({}), Fe = ie(L);
66
+ Fe.current = L;
67
+ const [Ee, ue] = Q({}), [ye, ke] = Q({}), te = j(
68
+ () => new Et(p, t.target_collection),
69
+ [p, t.target_collection]
70
+ ), Ge = () => {
71
+ ee({}), ue({}), ke({}), te.release();
72
+ }, [ze, Te] = Q(!1), [Ae, ve] = Q(null), [Ue, Pe] = Q(/* @__PURE__ */ new Set()), F = t.scope_fields.every(
73
+ (e) => b[e.field] !== null && b[e.field] !== void 0 && b[e.field] !== ""
74
+ ), Ke = ie(null), E = t.scope_fields[0], I = E && F ? String(b[E.field]) : null, ft = St(
66
75
  "matrix",
67
76
  t.target_collection,
68
- ...t.scope_fields.slice(1).map((e) => String(h[e.field] ?? ""))
69
- ), Me = g(() => Q ? [Q] : [], [Q]), { editors: pe } = kt({
70
- page: nt,
71
- collection: M == null ? void 0 : M.collection,
72
- items: Me,
73
- containerRef: Fe,
74
- enabled: !!Q
75
- }), ot = $t(
76
- M == null ? void 0 : M.collection,
77
- Me,
78
- pe.length > 0
79
- ), Re = de(/* @__PURE__ */ new Map()), X = t.option_label ?? "name", T = JSON.stringify(h), m = t.group, ze = g(() => {
80
- var r, s;
77
+ ...t.scope_fields.slice(1).map((e) => String(b[e.field] ?? ""))
78
+ ), We = j(() => I ? [I] : [], [I]), { editors: Ne } = jt({
79
+ page: ft,
80
+ collection: E == null ? void 0 : E.collection,
81
+ items: We,
82
+ containerRef: Ke,
83
+ enabled: !!I
84
+ }), ht = Rt(
85
+ E == null ? void 0 : E.collection,
86
+ We,
87
+ Ne.length > 0
88
+ ), Je = ie(/* @__PURE__ */ new Map()), re = t.option_label ?? "name", T = JSON.stringify(b), f = t.group, Qe = j(() => {
89
+ var r, l;
81
90
  const e = [
82
91
  t.option_label_template,
83
92
  (r = t.option_section) == null ? void 0 : r.label_template,
84
- (s = t.option_section) == null ? void 0 : s.row_label_template
85
- ].filter((a) => !!a);
86
- if (e.length === 0) return `id,${X}`;
87
- const l = e.flatMap(
88
- (a) => [...a.matchAll(/\{\{\s*([\w.[\]]+)\s*\}\}/g)].map((o) => o[1].replace(/\[\d+\]/g, ""))
93
+ (l = t.option_section) == null ? void 0 : l.row_label_template
94
+ ].filter((o) => !!o);
95
+ if (e.length === 0) return `id,${re}`;
96
+ const s = e.flatMap(
97
+ (o) => [...o.matchAll(/\{\{\s*([\w.[\]]+)\s*\}\}/g)].map((n) => n[1].replace(/\[\d+\]/g, ""))
89
98
  );
90
- return t.option_label_template || l.push(X), ["id", ...new Set(l)].join(",");
91
- }, [t.option_label_template, t.option_section, X]), { data: Ke = [], isLoading: it } = re({
92
- queryKey: ["matrix-options", t.option_collection, ze, T],
99
+ return t.option_label_template || s.push(re), ["id", ...new Set(s)].join(",");
100
+ }, [t.option_label_template, t.option_section, re]), { data: Ve = [], isLoading: xt } = oe({
101
+ queryKey: ["matrix-options", t.option_collection, Qe, T],
93
102
  queryFn: () => {
94
- const e = Ne(t.option_filter, h);
95
- return f.request(
96
- se(`/items/${t.option_collection}`, {
103
+ const e = qe(t.option_filter, b);
104
+ return p.request(
105
+ ce(`/items/${t.option_collection}`, {
97
106
  limit: 500,
98
- fields: ze,
107
+ fields: Qe,
99
108
  ...e ? { filter: JSON.stringify(e) } : {}
100
109
  })
101
- ).then((l) => l.data ?? []);
110
+ ).then((s) => s.data ?? []);
102
111
  },
103
112
  enabled: F,
104
113
  staleTime: 3e4
105
- }), { data: E = [] } = re({
106
- queryKey: ["matrix-groups", m == null ? void 0 : m.collection, T],
114
+ }), { data: A = [] } = oe({
115
+ queryKey: ["matrix-groups", f == null ? void 0 : f.collection, T],
107
116
  queryFn: () => {
108
- const e = Ne(m == null ? void 0 : m.filter, h);
109
- return f.request(
110
- se(`/items/${m.collection}`, {
117
+ const e = qe(f == null ? void 0 : f.filter, b);
118
+ return p.request(
119
+ ce(`/items/${f.collection}`, {
111
120
  limit: 200,
112
121
  fields: [
113
122
  "id",
114
- m.label_field ?? "name",
123
+ f.label_field ?? "name",
115
124
  ...Object.values(t.group_seeds ?? {})
116
125
  ].join(","),
117
126
  ...e ? { filter: JSON.stringify(e) } : {}
118
127
  })
119
- ).then((l) => l.data ?? []);
128
+ ).then((s) => s.data ?? []);
120
129
  },
121
- enabled: F && !!m,
130
+ enabled: F && !!f,
122
131
  staleTime: 3e4
123
- }), ct = g(() => {
124
- var l;
132
+ }), _t = j(() => {
133
+ var s;
125
134
  const e = ["id", t.key_field, t.value_field];
126
- return m && e.push(m.field), (l = t.specials) != null && l.bucket && e.push(t.specials.bucket.flag_field), e.join(",");
127
- }, [t, m]), { data: Te = [], isLoading: be } = re({
135
+ return f && e.push(f.field), (s = t.specials) != null && s.bucket && e.push(t.specials.bucket.flag_field), e.join(",");
136
+ }, [t, f]), { data: me = [], isLoading: ge } = oe({
128
137
  queryKey: ["matrix-targets", t.target_collection, T],
129
138
  queryFn: () => {
130
139
  const e = {};
131
- for (const l of t.scope_fields) e[l.field] = { _eq: h[l.field] };
132
- return f.request(
133
- se(`/items/${t.target_collection}`, {
140
+ for (const s of t.scope_fields) e[s.field] = { _eq: b[s.field] };
141
+ return p.request(
142
+ ce(`/items/${t.target_collection}`, {
134
143
  limit: 2e3,
135
- fields: ct,
144
+ fields: _t,
136
145
  filter: JSON.stringify(e)
137
146
  })
138
- ).then((l) => l.data ?? []);
147
+ ).then((s) => s.data ?? []);
139
148
  },
140
149
  enabled: F,
141
- staleTime: 0
142
- }), Y = g(() => {
150
+ staleTime: 0,
151
+ // E11: another planner's save shows here; the person's typed cells stay on top of it.
152
+ meta: Ot({ reads: [t.target_collection], minGapMs: 2e3 })
153
+ });
154
+ xe(() => {
155
+ te.noteRows(me);
156
+ }, [te, me]);
157
+ const se = j(() => {
143
158
  var r;
144
- const e = /* @__PURE__ */ new Map(), l = (s) => {
145
- if (typeof s != "string") return;
146
- const a = /^\$(\w+)\.(.+)$/.exec(s);
147
- if (!a || a[1] === "scope") return;
148
- const o = e.get(a[1]) ?? /* @__PURE__ */ new Set();
149
- o.add(a[2].replace(/\[\d+\]/g, "")), e.set(a[1], o);
159
+ const e = /* @__PURE__ */ new Map(), s = (l) => {
160
+ if (typeof l != "string") return;
161
+ const o = /^\$(\w+)\.(.+)$/.exec(l);
162
+ if (!o || o[1] === "scope") return;
163
+ const n = e.get(o[1]) ?? /* @__PURE__ */ new Set();
164
+ n.add(o[2].replace(/\[\d+\]/g, "")), e.set(o[1], n);
150
165
  };
151
- for (const s of Object.values(t.scope_seeds ?? {})) l(s);
152
- for (const s of Object.values(t.scope_defaults ?? {})) l(s);
153
- for (const s of Object.values(((r = t.metrics) == null ? void 0 : r.params) ?? {})) l(s);
166
+ for (const l of Object.values(t.scope_seeds ?? {})) s(l);
167
+ for (const l of Object.values(t.scope_defaults ?? {})) s(l);
168
+ for (const l of Object.values(((r = t.metrics) == null ? void 0 : r.params) ?? {})) s(l);
154
169
  if (t.cap) {
155
- const s = e.get(t.cap.scope_field) ?? /* @__PURE__ */ new Set();
156
- s.add(t.cap.field), e.set(t.cap.scope_field, s);
170
+ const l = e.get(t.cap.scope_field) ?? /* @__PURE__ */ new Set();
171
+ l.add(t.cap.field), e.set(t.cap.scope_field, l);
157
172
  }
158
173
  return e;
159
- }, [t.scope_seeds, t.scope_defaults, t.metrics, t.cap]), { data: G = {} } = re({
160
- queryKey: ["matrix-scope-records", T, [...Y.keys()].join(",")],
174
+ }, [t.scope_seeds, t.scope_defaults, t.metrics, t.cap]), { data: U = {} } = oe({
175
+ queryKey: ["matrix-scope-records", T, [...se.keys()].join(",")],
161
176
  queryFn: async () => {
162
177
  const e = {};
163
- for (const [l, r] of Y) {
164
- const s = t.scope_fields.find((n) => n.field === l), a = h[l];
165
- if (!s || a == null) continue;
166
- const o = [...r].filter((n) => !n.includes(".")), i = [...r].filter((n) => n.includes(".")), u = await f.request(
167
- se(`/items/${s.collection}/${a}`, { fields: ["id", ...o].join(",") })
168
- ).then((n) => n.data).catch(() => null);
169
- if (u) {
170
- if (i.length > 0) {
171
- const n = await f.request(
172
- se(`/items/${s.collection}/${a}/resolve-paths`, { paths: i.join(",") })
173
- ).then((p) => p.data ?? {}).catch(() => ({}));
174
- for (const [p, c] of Object.entries(n))
175
- u[p] = c != null && c.ids && c.ids.length > 0 ? c.ids[0] : (c == null ? void 0 : c.value) ?? null;
178
+ for (const [s, r] of se) {
179
+ const l = t.scope_fields.find((a) => a.field === s), o = b[s];
180
+ if (!l || o == null) continue;
181
+ const n = [...r].filter((a) => !a.includes(".")), u = [...r].filter((a) => a.includes(".")), i = await p.request(
182
+ ce(`/items/${l.collection}/${o}`, { fields: ["id", ...n].join(",") })
183
+ ).then((a) => a.data).catch(() => null);
184
+ if (i) {
185
+ if (u.length > 0) {
186
+ const a = await p.request(
187
+ ce(`/items/${l.collection}/${o}/resolve-paths`, { paths: u.join(",") })
188
+ ).then((m) => m.data ?? {}).catch(() => ({}));
189
+ for (const [m, c] of Object.entries(a))
190
+ i[m] = c != null && c.ids && c.ids.length > 0 ? c.ids[0] : (c == null ? void 0 : c.value) ?? null;
176
191
  }
177
- e[l] = u;
192
+ e[s] = i;
178
193
  }
179
194
  }
180
195
  return e;
181
196
  },
182
197
  // Per-field, not scopeReady — scope_defaults must resolve while other
183
198
  // pickers are still empty (project → default sub type).
184
- enabled: Y.size > 0 && [...Y.keys()].some(
185
- (e) => h[e] !== null && h[e] !== void 0 && h[e] !== ""
199
+ enabled: se.size > 0 && [...se.keys()].some(
200
+ (e) => b[e] !== null && b[e] !== void 0 && b[e] !== ""
186
201
  ),
187
202
  staleTime: 3e4
188
203
  });
189
- ve(() => {
204
+ xe(() => {
190
205
  if (t.scope_defaults)
191
- for (const [e, l] of Object.entries(t.scope_defaults)) {
192
- if (h[e] != null && h[e] !== "") continue;
193
- const r = /^\$(\w+)\.(.+)$/.exec(l);
206
+ for (const [e, s] of Object.entries(t.scope_defaults)) {
207
+ if (b[e] != null && b[e] !== "") continue;
208
+ const r = /^\$(\w+)\.(.+)$/.exec(s);
194
209
  if (!r) continue;
195
- const s = ae(G[r[1]] ?? {}, r[2]);
196
- s != null && s !== "" && ue((a) => ({ ...a, [e]: s }));
210
+ const l = de(U[r[1]] ?? {}, r[2]);
211
+ l != null && l !== "" && D((o) => ({ ...o, [e]: l }));
197
212
  }
198
- }, [G, t.scope_defaults, h]);
199
- const { data: ne = [] } = re({
213
+ }, [U, t.scope_defaults, b]);
214
+ const { data: pe = [] } = oe({
200
215
  queryKey: [
201
216
  "matrix-metrics",
202
- (Be = t.metrics) == null ? void 0 : Be.query_slug,
217
+ (st = t.metrics) == null ? void 0 : st.query_slug,
203
218
  T,
204
- Object.keys(G).length
219
+ Object.keys(U).length
205
220
  ],
206
221
  queryFn: () => {
207
222
  var e;
208
- return f.request(
209
- st(`/custom-queries/${t.metrics.query_slug}/execute`, {
223
+ return p.request(
224
+ pt(`/custom-queries/${t.metrics.query_slug}/execute`, {
210
225
  params: Object.fromEntries(
211
- Object.entries(((e = t.metrics) == null ? void 0 : e.params) ?? {}).map(([l, r]) => {
226
+ Object.entries(((e = t.metrics) == null ? void 0 : e.params) ?? {}).map(([s, r]) => {
212
227
  if (typeof r == "string" && r.startsWith("$scope."))
213
- return [l, h[r.slice(7)]];
228
+ return [s, b[r.slice(7)]];
214
229
  if (typeof r == "string" && r.startsWith("$")) {
215
- const s = /^\$(\w+)\.(.+)$/.exec(r);
216
- if (s) return [l, ae(G[s[1]] ?? {}, s[2])];
230
+ const l = /^\$(\w+)\.(.+)$/.exec(r);
231
+ if (l) return [s, de(U[l[1]] ?? {}, l[2])];
217
232
  }
218
- return [l, r];
233
+ return [s, r];
219
234
  })
220
235
  )
221
236
  })
222
- ).then((l) => l.data ?? []);
237
+ ).then((s) => s.data ?? []);
223
238
  },
224
- enabled: F && !!t.metrics && (Y.size === 0 || Object.keys(G).length > 0),
239
+ enabled: F && !!t.metrics && (se.size === 0 || Object.keys(U).length > 0),
225
240
  staleTime: 3e4
226
- }), dt = (e) => {
227
- var a;
228
- const l = m ? String(e[m.field] ?? "") : "", r = (a = t.specials) == null ? void 0 : a.bucket;
241
+ }), yt = (e) => {
242
+ var o;
243
+ const s = f ? String(e[f.field] ?? "") : "", r = (o = t.specials) == null ? void 0 : o.bucket;
229
244
  if (r && (e[r.flag_field] === !0 || e[r.flag_field] === 1))
230
- return `${l}|${V}`;
231
- const s = e[t.key_field];
232
- return `${l}|${s == null ? J : String(s)}`;
233
- }, y = g(() => {
245
+ return `${s}|${B}`;
246
+ const l = e[t.key_field];
247
+ return `${s}|${l == null ? V : String(l)}`;
248
+ }, v = j(() => {
234
249
  const e = /* @__PURE__ */ new Map();
235
- for (const l of Te) {
236
- const r = dt(l), s = e.get(r) ?? { ids: [], total: 0 };
237
- s.ids.push(l.id), s.total += Number(l[t.value_field]) || 0, e.set(r, s);
250
+ for (const s of me) {
251
+ const r = yt(s), l = e.get(r) ?? { ids: [], total: 0 };
252
+ l.ids.push(s.id), l.total += Number(s[t.value_field]) || 0, e.set(r, l);
238
253
  }
239
254
  return e;
240
- }, [Te, t.value_field]), oe = (e, l) => {
241
- var o, i, u, n;
242
- const r = t.metrics, s = {};
243
- if (!r) return s;
244
- const a = l === J ? ((i = (o = t.specials) == null ? void 0 : o.uncategorized) == null ? void 0 : i.metric_value) ?? null : l === V ? ((n = (u = t.specials) == null ? void 0 : u.bucket) == null ? void 0 : n.metric_value) ?? null : l;
245
- for (const p of ne) {
246
- if (r.match_group_field && String(p[r.match_group_field] ?? "") !== e) continue;
247
- const c = p[r.match_option_field], k = a === null || a === 0 || a === "0", v = c == null || c === 0 || c === "0" || c === "";
248
- if (k ? v : String(c ?? "") === String(a))
249
- for (const x of r.columns)
250
- s[x.field] = (s[x.field] ?? 0) + (Number(p[x.field]) || 0);
255
+ }, [me, t.value_field]), be = (e, s) => {
256
+ var n, u, i, a;
257
+ const r = t.metrics, l = {};
258
+ if (!r) return l;
259
+ const o = s === V ? ((u = (n = t.specials) == null ? void 0 : n.uncategorized) == null ? void 0 : u.metric_value) ?? null : s === B ? ((a = (i = t.specials) == null ? void 0 : i.bucket) == null ? void 0 : a.metric_value) ?? null : s;
260
+ for (const m of pe) {
261
+ if (r.match_group_field && String(m[r.match_group_field] ?? "") !== e) continue;
262
+ const c = m[r.match_option_field], h = o === null || o === 0 || o === "0", $ = c == null || c === 0 || c === "0" || c === "";
263
+ if (h ? $ : String(c ?? "") === String(o))
264
+ for (const y of r.columns)
265
+ l[y.field] = (l[y.field] ?? 0) + (Number(m[y.field]) || 0);
251
266
  }
252
- return s;
253
- }, j = g(() => {
254
- const e = (r) => t.option_label_template ? ge(t.option_label_template, r) : String(r[X] ?? r.id), l = t.option_section;
255
- return [...Ke].map((r) => {
256
- const s = e(r), a = l ? ge(l.label_template, r) : "", o = l != null && l.row_label_template && ge(l.row_label_template, r) || s;
257
- return { key: String(r.id), label: l ? o : s, section: a };
258
- }).sort((r, s) => r.section.localeCompare(s.section) || r.label.localeCompare(s.label));
259
- }, [Ke, t.option_label_template, t.option_section, X]), ie = g(() => {
267
+ return l;
268
+ }, q = j(() => {
269
+ const e = (r) => t.option_label_template ? Le(t.option_label_template, r) : String(r[re] ?? r.id), s = t.option_section;
270
+ return [...Ve].map((r) => {
271
+ const l = e(r), o = s ? Le(s.label_template, r) : "", n = s != null && s.row_label_template && Le(s.row_label_template, r) || l;
272
+ return { key: String(r.id), label: s ? n : l, section: o };
273
+ }).sort((r, l) => r.section.localeCompare(l.section) || r.label.localeCompare(l.label));
274
+ }, [Ve, t.option_label_template, t.option_section, re]), fe = j(() => {
260
275
  if (!t.option_section) return [];
261
276
  const e = /* @__PURE__ */ new Map();
262
- for (const l of j) {
263
- const r = e.get(l.section) ?? [];
264
- r.push(l), e.set(l.section, r);
277
+ for (const s of q) {
278
+ const r = e.get(s.section) ?? [];
279
+ r.push(s), e.set(s.section, r);
265
280
  }
266
- return [...e.entries()].map(([l, r]) => ({ name: l, rows: r }));
267
- }, [j, t.option_section]), Ee = de(null);
268
- ve(() => {
269
- if (!m || E.length === 0 || be) return;
270
- const e = `${T}#${t.option_section && ie.length > 0 ? 1 : 0}`;
271
- if (Ee.current === e) return;
272
- Ee.current = e;
273
- const l = new Set([...y.keys()].map((s) => s.split("|")[0])), r = new Set(E.map((s) => String(s.id)).filter((s) => !l.has(s)));
281
+ return [...e.entries()].map(([s, r]) => ({ name: s, rows: r }));
282
+ }, [q, t.option_section]), Be = ie(null);
283
+ xe(() => {
284
+ if (!f || A.length === 0 || ge) return;
285
+ const e = `${T}#${t.option_section && fe.length > 0 ? 1 : 0}`;
286
+ if (Be.current === e) return;
287
+ Be.current = e;
288
+ const s = new Set([...v.keys()].map((l) => l.split("|")[0])), r = new Set(A.map((l) => String(l.id)).filter((l) => !s.has(l)));
274
289
  if (t.option_section) {
275
- const s = new Set(y.keys());
276
- for (const a of E) {
277
- const o = String(a.id);
278
- for (const i of ie)
279
- i.rows.some((u) => s.has(`${o}|${u.key}`)) || r.add(`s:${o}|${i.name}`);
290
+ const l = new Set(v.keys());
291
+ for (const o of A) {
292
+ const n = String(o.id);
293
+ for (const u of fe)
294
+ u.rows.some((i) => l.has(`${n}|${i.key}`)) || r.add(`s:${n}|${u.name}`);
280
295
  }
281
296
  }
282
- Le(r);
283
- }, [E, y, be, T, m, ie, t.option_section]);
284
- const q = g(() => m ? [...E].map((e) => ({ id: String(e.id), label: String(e[m.label_field ?? "name"] ?? e.id) })).sort((e, l) => e.label.localeCompare(l.label)) : [{ id: "", label: "" }], [E, m]), Ge = g(() => {
285
- var l, r;
297
+ Pe(r);
298
+ }, [A, v, ge, T, f, fe, t.option_section]);
299
+ const M = j(() => f ? [...A].map((e) => ({ id: String(e.id), label: String(e[f.label_field ?? "name"] ?? e.id) })).sort((e, s) => e.label.localeCompare(s.label)) : [{ id: "", label: "" }], [A, f]), De = j(() => {
300
+ var s, r;
286
301
  const e = /* @__PURE__ */ new Set();
287
- for (const s of q) {
288
- for (const a of j) e.add(`${s.id}|${a.key}`);
289
- (l = t.specials) != null && l.uncategorized && e.add(`${s.id}|${J}`), (r = t.specials) != null && r.bucket && e.add(`${s.id}|${V}`);
302
+ for (const l of M) {
303
+ for (const o of q) e.add(`${l.id}|${o.key}`);
304
+ (s = t.specials) != null && s.uncategorized && e.add(`${l.id}|${V}`), (r = t.specials) != null && r.bucket && e.add(`${l.id}|${B}`);
290
305
  }
291
306
  return e;
292
- }, [q, j, t.specials]), A = g(() => {
307
+ }, [M, q, t.specials]), P = j(() => {
293
308
  let e = 0;
294
- for (const [l, r] of y) Ge.has(l) || (e += r.total);
309
+ for (const [s, r] of v) De.has(s) || (e += r.total);
295
310
  return e;
296
- }, [y, Ge]), B = t.cap ? Number(ae(G[t.cap.scope_field] ?? {}, t.cap.field)) || 0 : null, fe = g(() => [...y.values()].reduce((e, l) => e + l.total, 0), [y]), Ae = g(() => {
297
- var l, r, s;
298
- let e = A;
299
- for (const a of q) {
300
- const o = [
301
- ...j.map((i) => i.key),
302
- ...(l = t.specials) != null && l.uncategorized ? [J] : [],
303
- ...(r = t.specials) != null && r.bucket ? [V] : []
311
+ }, [v, De]), H = t.cap ? Number(de(U[t.cap.scope_field] ?? {}, t.cap.field)) || 0 : null, we = j(() => [...v.values()].reduce((e, s) => e + s.total, 0), [v]), Ie = j(() => {
312
+ var s, r, l;
313
+ let e = P;
314
+ for (const o of M) {
315
+ const n = [
316
+ ...q.map((u) => u.key),
317
+ ...(s = t.specials) != null && s.uncategorized ? [V] : [],
318
+ ...(r = t.specials) != null && r.bucket ? [B] : []
304
319
  ];
305
- for (const i of o) {
306
- const u = `${a.id}|${i}`, n = K[u];
307
- n !== void 0 && n.trim() !== "" && !Number.isNaN(Number(n)) ? e += Number(n) : e += ((s = y.get(u)) == null ? void 0 : s.total) ?? 0;
320
+ for (const u of n) {
321
+ const i = `${o.id}|${u}`, a = L[i];
322
+ a !== void 0 && a.trim() !== "" && !Number.isNaN(Number(a)) ? e += Number(a) : e += ((l = v.get(i)) == null ? void 0 : l.total) ?? 0;
308
323
  }
309
324
  }
310
325
  return e;
311
- }, [K, y, q, j, A, t.specials]), he = B !== null ? B - Ae : null, Z = (e) => {
326
+ }, [L, v, M, q, P, t.specials]), $e = H !== null ? H - Ie : null, le = (e) => {
312
327
  var r;
313
- const l = K[e];
314
- return l !== void 0 && l.trim() !== "" && !Number.isNaN(Number(l)) ? Number(l) : ((r = y.get(e)) == null ? void 0 : r.total) ?? 0;
328
+ const s = L[e];
329
+ return s !== void 0 && s.trim() !== "" && !Number.isNaN(Number(s)) ? Number(s) : ((r = v.get(e)) == null ? void 0 : r.total) ?? 0;
315
330
  };
316
- function ut(e, l) {
317
- var o;
318
- const r = l.trim();
319
- if (r === "") {
320
- D((i) => ({ ...i, [e]: l }));
331
+ function kt(e, s) {
332
+ var u;
333
+ const r = v.get(e);
334
+ e in Ee || ((r == null ? void 0 : r.ids[0]) != null && te.pin(String(r.ids[0])), ue((i) => ({ ...i, [e]: (r == null ? void 0 : r.total) ?? 0 })));
335
+ const l = s.trim();
336
+ if (l === "") {
337
+ ee((i) => ({ ...i, [e]: s })), ke((i) => {
338
+ if (!(e in i)) return i;
339
+ const a = { ...i };
340
+ return delete a[e], a;
341
+ }), ue((i) => {
342
+ if (!(e in i)) return i;
343
+ const a = { ...i };
344
+ return delete a[e], a;
345
+ });
321
346
  return;
322
347
  }
323
- const s = /^[+-]/.test(r) && r !== "-" && r !== "+";
324
- let a = Number(r);
325
- if (Number.isNaN(a)) {
326
- D((i) => ({ ...i, [e]: l }));
348
+ const o = /^[+-]/.test(l) && l !== "-" && l !== "+";
349
+ let n = Number(l);
350
+ if (Number.isNaN(n)) {
351
+ ee((i) => ({ ...i, [e]: s }));
327
352
  return;
328
353
  }
329
- if (s && (a = (((o = y.get(e)) == null ? void 0 : o.total) ?? 0) + a), a < 0 && (a = 0), B !== null) {
330
- const i = Ae - Z(e), u = Math.max(0, B - i);
331
- a = Math.min(a, u);
354
+ if (o && (n = (((u = v.get(e)) == null ? void 0 : u.total) ?? 0) + n), n < 0 && (n = 0), H !== null) {
355
+ const i = Ie - le(e), a = Math.max(0, H - i);
356
+ n = Math.min(n, a);
332
357
  }
333
- D((i) => ({ ...i, [e]: s ? String(a) : l }));
358
+ ee((i) => ({ ...i, [e]: o ? String(n) : s }));
334
359
  }
335
- async function mt() {
336
- var r;
337
- Ce(!0), me(null);
338
- let e = 0, l = 0;
360
+ async function vt() {
361
+ var n, u;
362
+ Te(!0), ve(null);
363
+ let e = 0, s = 0;
364
+ const r = {}, l = {}, o = L;
339
365
  try {
340
- const s = {};
341
- for (const [a, o] of Object.entries(t.scope_seeds ?? {})) {
342
- const i = /^\$(\w+)\.(.+)$/.exec(o);
343
- i && (s[a] = ae(G[i[1]] ?? {}, i[2]));
366
+ const i = {};
367
+ for (const [m, c] of Object.entries(t.scope_seeds ?? {})) {
368
+ const h = /^\$(\w+)\.(.+)$/.exec(c);
369
+ h && (i[m] = de(U[h[1]] ?? {}, h[2]));
344
370
  }
345
- for (const [a, o] of Object.entries(K)) {
346
- if (o.trim() === "") continue;
347
- const i = Number(o);
348
- if (Number.isNaN(i) || i < 0) continue;
349
- const u = y.get(a);
350
- if (!(u && u.total === i))
351
- if (u)
352
- await f.request(
353
- xt(`/items/${t.target_collection}/${u.ids[0]}`, {
354
- [t.value_field]: i
355
- })
356
- ), e++;
357
- else {
358
- const [n, p] = a.split("|"), c = { [t.value_field]: i, ...s };
359
- for (const k of t.scope_fields) c[k.field] = h[k.field];
360
- if (m && n) {
361
- c[m.field] = n;
362
- const k = E.find((v) => String(v.id) === n);
363
- for (const [v, C] of Object.entries(t.group_seeds ?? {})) {
364
- const x = k == null ? void 0 : k[C];
365
- x != null && (c[v] = x);
371
+ for (const [m, c] of Object.entries(L)) {
372
+ if (c.trim() === "") continue;
373
+ const h = Number(c);
374
+ if (Number.isNaN(h) || h < 0) continue;
375
+ const $ = v.get(m);
376
+ if (!($ && $.total === h))
377
+ if ($) {
378
+ const S = await te.write(String($.ids[0]), { [t.value_field]: h });
379
+ S.ok ? (e++, l[m] = h) : r[m] = ((n = S.conflicts[0]) == null ? void 0 : n.current_value) ?? null;
380
+ } else {
381
+ const [S, y] = m.split("|"), N = { [t.value_field]: h, ...i };
382
+ for (const C of t.scope_fields) N[C.field] = b[C.field];
383
+ if (f && S) {
384
+ N[f.field] = S;
385
+ const C = A.find((Z) => String(Z.id) === S);
386
+ for (const [Z, g] of Object.entries(t.group_seeds ?? {})) {
387
+ const ne = C == null ? void 0 : C[g];
388
+ ne != null && (N[Z] = ne);
366
389
  }
367
390
  }
368
- p === V && ((r = t.specials) != null && r.bucket) ? (c[t.key_field] = null, c[t.specials.bucket.flag_field] = !0) : p === J ? c[t.key_field] = null : c[t.key_field] = p, await f.request(st(`/items/${t.target_collection}`, c)), l++;
391
+ y === B && ((u = t.specials) != null && u.bucket) ? (N[t.key_field] = null, N[t.specials.bucket.flag_field] = !0) : y === V ? N[t.key_field] = null : N[t.key_field] = y, await p.request(pt(`/items/${t.target_collection}`, N)), s++, l[m] = h;
369
392
  }
370
393
  }
371
- D({}), await N.invalidateQueries({ queryKey: ["matrix-targets", t.target_collection] }), me(`Saved — ${e} updated, ${l} created`);
372
- } catch (s) {
373
- me(`Save failed: ${Nt(s, "unknown error")}`);
394
+ const a = Gt(Fe.current, o, new Set(Object.keys(r)));
395
+ ee(a), ue((m) => {
396
+ const c = {};
397
+ for (const h of Object.keys(a))
398
+ h in l ? c[h] = l[h] : m[h] !== void 0 && (c[h] = m[h]);
399
+ return c;
400
+ }), ke(r), await w.invalidateQueries({ queryKey: ["matrix-targets", t.target_collection] }), ve(Tt(e, s, Object.keys(r).length));
401
+ } catch (i) {
402
+ ve(`Save failed: ${qt(i, "unknown error")}`);
374
403
  } finally {
375
- Ce(!1);
404
+ Te(!1);
376
405
  }
377
406
  }
378
- const Ue = Object.values(K).some((e) => e.trim() !== ""), R = ((Ie = t.metrics) == null ? void 0 : Ie.columns) ?? [], U = ((He = t.metrics) == null ? void 0 : He.derived) ?? [], Pe = t.value_label ?? t.value_field;
379
- 1 + R.length + U.length + 1;
380
- const P = "text-[color:var(--qtc)] dark:text-[color:var(--qtcd)]", W = (e, l, r) => {
381
- const a = r && typeof l == "number" && l < 0 ? r : e;
382
- if (!a) return;
383
- const [o, i] = St(a);
384
- return { "--qtc": o, "--qtcd": i };
385
- }, xe = t.value_color ?? "info", I = ((Xe = t.metrics) == null ? void 0 : Xe.unmatched) === !1 ? null : ((Ye = t.metrics) == null ? void 0 : Ye.unmatched) ?? {}, z = g(() => {
386
- var n, p;
387
- const e = /* @__PURE__ */ new Map(), l = {};
407
+ const He = Object.values(L).some((e) => e.trim() !== ""), G = ((lt = t.metrics) == null ? void 0 : lt.columns) ?? [], K = ((at = t.metrics) == null ? void 0 : at.derived) ?? [], Xe = t.value_label ?? t.value_field;
408
+ 1 + G.length + K.length + 1;
409
+ const W = "text-[color:var(--qtc)] dark:text-[color:var(--qtcd)]", J = (e, s, r) => {
410
+ const o = r && typeof s == "number" && s < 0 ? r : e;
411
+ if (!o) return;
412
+ const [n, u] = Ft(o);
413
+ return { "--qtc": n, "--qtcd": u };
414
+ }, Se = t.value_color ?? "info", X = ((nt = t.metrics) == null ? void 0 : nt.unmatched) === !1 ? null : ((ot = t.metrics) == null ? void 0 : ot.unmatched) ?? {}, z = j(() => {
415
+ var a, m;
416
+ const e = /* @__PURE__ */ new Map(), s = {};
388
417
  let r = 0;
389
- const s = t.metrics;
390
- if (!s || !I) return { perGroup: e, otherGroup: l, otherGroupCount: r };
391
- const a = new Set(q.map((c) => c.id)), o = new Set(j.map((c) => c.key)), i = /* @__PURE__ */ new Set(), u = (c) => c == null || c === 0 || c === "0" || c === "" ? "" : String(c);
392
- (n = t.specials) != null && n.uncategorized && i.add(u(t.specials.uncategorized.metric_value)), (p = t.specials) != null && p.bucket && i.add(u(t.specials.bucket.metric_value));
393
- for (const c of ne) {
394
- const k = s.match_group_field ? String(c[s.match_group_field] ?? "") : "", v = c[s.match_option_field], C = o.has(String(v ?? "")) || i.has(u(v)), x = !m || a.has(k) ? C ? null : e.get(k) ?? {} : l;
395
- if (x) {
396
- for (const O of s.columns)
397
- x[O.field] = (x[O.field] ?? 0) + (Number(c[O.field]) || 0);
398
- !m || a.has(k) ? e.set(k, x) : r++;
418
+ const l = t.metrics;
419
+ if (!l || !X) return { perGroup: e, otherGroup: s, otherGroupCount: r };
420
+ const o = new Set(M.map((c) => c.id)), n = new Set(q.map((c) => c.key)), u = /* @__PURE__ */ new Set(), i = (c) => c == null || c === 0 || c === "0" || c === "" ? "" : String(c);
421
+ (a = t.specials) != null && a.uncategorized && u.add(i(t.specials.uncategorized.metric_value)), (m = t.specials) != null && m.bucket && u.add(i(t.specials.bucket.metric_value));
422
+ for (const c of pe) {
423
+ const h = l.match_group_field ? String(c[l.match_group_field] ?? "") : "", $ = c[l.match_option_field], S = n.has(String($ ?? "")) || u.has(i($)), y = !f || o.has(h) ? S ? null : e.get(h) ?? {} : s;
424
+ if (y) {
425
+ for (const N of l.columns)
426
+ y[N.field] = (y[N.field] ?? 0) + (Number(c[N.field]) || 0);
427
+ !f || o.has(h) ? e.set(h, y) : r++;
399
428
  }
400
429
  }
401
- return { perGroup: e, otherGroup: l, otherGroupCount: r };
402
- }, [ne, t.metrics, t.specials, q, j, m, I]), We = (e, l, r) => U.map(
403
- (s) => _t(
404
- s.formula,
405
- { ...r, __current__: e, __new__: l },
430
+ return { perGroup: e, otherGroup: s, otherGroupCount: r };
431
+ }, [pe, t.metrics, t.specials, M, q, f, X]), Ye = (e, s, r) => K.map(
432
+ (l) => $t(
433
+ l.formula,
434
+ { ...r, __current__: e, __new__: s },
406
435
  { missing: "zero" }
407
436
  )
408
- ), _e = (e) => {
409
- const l = {};
437
+ ), je = (e) => {
438
+ const s = {};
410
439
  for (const r of e)
411
- for (const s of R) l[s.field] = (l[s.field] ?? 0) + (r[s.field] ?? 0);
412
- return l;
413
- }, Je = () => {
414
- var e, l;
440
+ for (const l of G) s[l.field] = (s[l.field] ?? 0) + (r[l.field] ?? 0);
441
+ return s;
442
+ }, Ze = () => {
443
+ var e, s;
415
444
  return [
416
- ...j.map((r) => r.key),
417
- ...(e = t.specials) != null && e.uncategorized ? [J] : [],
418
- ...(l = t.specials) != null && l.bucket ? [V] : []
445
+ ...q.map((r) => r.key),
446
+ ...(e = t.specials) != null && e.uncategorized ? [V] : [],
447
+ ...(s = t.specials) != null && s.bucket ? [B] : []
419
448
  ];
420
- }, H = g(() => {
421
- var s;
422
- let e = 0, l = 0;
449
+ }, Y = j(() => {
450
+ var l;
451
+ let e = 0, s = 0;
423
452
  const r = [];
424
- for (const a of q) {
425
- for (const i of Je()) {
426
- const u = `${a.id}|${i}`;
427
- e += ((s = y.get(u)) == null ? void 0 : s.total) ?? 0, l += Z(u), r.push(oe(a.id, i));
453
+ for (const o of M) {
454
+ for (const u of Ze()) {
455
+ const i = `${o.id}|${u}`;
456
+ e += ((l = v.get(i)) == null ? void 0 : l.total) ?? 0, s += le(i), r.push(be(o.id, u));
428
457
  }
429
- const o = z.perGroup.get(a.id);
430
- o && r.push(o);
458
+ const n = z.perGroup.get(o.id);
459
+ n && r.push(n);
431
460
  }
432
- return r.push(z.otherGroup), e += A, l += A, { current: e, next: l, metrics: _e(r) };
461
+ return r.push(z.otherGroup), e += P, s += P, { current: e, next: s, metrics: je(r) };
433
462
  }, [
463
+ M,
434
464
  q,
435
- j,
436
- y,
437
- K,
438
- ne,
439
- A,
465
+ v,
466
+ L,
467
+ pe,
468
+ P,
440
469
  z,
441
470
  t.specials
442
- ]), ee = (e, l, r) => {
443
- const s = r != null && r.tone ? void 0 : W(r == null ? void 0 : r.role, e, r == null ? void 0 : r.negRole);
471
+ ]), ae = (e, s, r) => {
472
+ const l = r != null && r.tone ? void 0 : J(r == null ? void 0 : r.role, e, r == null ? void 0 : r.negRole);
444
473
  return /* @__PURE__ */ d(
445
474
  "td",
446
475
  {
447
- className: S(
476
+ className: O(
448
477
  "py-1.5 pr-3 text-right tabular-nums",
449
478
  r != null && r.strong ? "font-semibold" : "",
450
- s ? P : r != null && r.strong ? "text-slate-800 dark:text-slate-100" : "text-slate-600 dark:text-slate-300",
479
+ l ? W : r != null && r.strong ? "text-slate-800 dark:text-slate-100" : "text-slate-600 dark:text-slate-300",
451
480
  (r == null ? void 0 : r.tone) === "muted" && "text-slate-400 dark:text-slate-500",
452
481
  (r == null ? void 0 : r.tone) === "neg" && "text-red-600 dark:text-red-400"
453
482
  ),
454
- style: s,
455
- children: L(e, l)
483
+ style: l,
484
+ children: R(e, s)
456
485
  }
457
486
  );
458
- }, ye = (e, l, r, s) => {
459
- const a = We(e, l, r);
460
- return /* @__PURE__ */ b(we, { children: [
461
- ee(e, t.value_format, { strong: s, role: xe }),
462
- R.map((o) => /* @__PURE__ */ d(
487
+ }, Ce = (e, s, r, l) => {
488
+ const o = Ye(e, s, r);
489
+ return /* @__PURE__ */ x(Me, { children: [
490
+ ae(e, t.value_format, { strong: l, role: Se }),
491
+ G.map((n) => /* @__PURE__ */ d(
463
492
  "td",
464
493
  {
465
- className: S(
494
+ className: O(
466
495
  "py-1.5 pr-3 text-right tabular-nums",
467
- s && "font-semibold",
468
- P
496
+ l && "font-semibold",
497
+ W
469
498
  ),
470
- style: W(o.color ?? "ink"),
471
- children: L(r[o.field], o.format)
499
+ style: J(n.color ?? "ink"),
500
+ children: R(r[n.field], n.format)
472
501
  },
473
- o.field
502
+ n.field
474
503
  )),
475
- U.map((o, i) => {
476
- const u = a[i];
504
+ K.map((n, u) => {
505
+ const i = o[u];
477
506
  return /* @__PURE__ */ d(
478
507
  "td",
479
508
  {
480
- className: S(
509
+ className: O(
481
510
  "py-1.5 pr-3 text-right tabular-nums",
482
- s && "font-semibold",
483
- P
511
+ l && "font-semibold",
512
+ W
484
513
  ),
485
- style: W(o.color ?? "positive", u, o.color_negative ?? "negative"),
486
- children: L(u, o.format ?? t.value_format)
514
+ style: J(n.color ?? "positive", i, n.color_negative ?? "negative"),
515
+ children: R(i, n.format ?? t.value_format)
487
516
  },
488
- o.label
517
+ n.label
489
518
  );
490
519
  }),
491
- ee(l, t.value_format, {
492
- strong: s,
493
- tone: l !== e ? void 0 : "muted"
520
+ ae(s, t.value_format, {
521
+ strong: l,
522
+ tone: s !== e ? void 0 : "muted"
494
523
  })
495
524
  ] });
496
- }, ce = (e, l, r, s = !1, a = 0) => {
497
- var O, te;
498
- const o = `${e}|${l}`, i = `${e}:${l}`, u = e ? (O = q.find((w) => w.id === e)) == null ? void 0 : O.label : null;
499
- Re.current.set(i, u ? `${u} · ${r}` : r);
500
- const n = ((te = y.get(o)) == null ? void 0 : te.total) ?? 0, p = oe(e, l), c = K[o] ?? "", k = Z(o), v = c.trim() !== "" && !Number.isNaN(Number(c)), C = v ? k - n : 0, x = We(n, k, p);
501
- return /* @__PURE__ */ b(
525
+ }, he = (e, s, r, l = !1, o = 0) => {
526
+ var C, Z;
527
+ const n = `${e}|${s}`, u = `${e}:${s}`, i = e ? (C = M.find((g) => g.id === e)) == null ? void 0 : C.label : null;
528
+ Je.current.set(u, i ? `${i} · ${r}` : r);
529
+ const a = ((Z = v.get(n)) == null ? void 0 : Z.total) ?? 0, m = be(e, s), c = L[n] ?? "", h = le(n), $ = c.trim() !== "" && !Number.isNaN(Number(c)), S = $ ? h - a : 0, y = zt(
530
+ n in ye,
531
+ ye[n],
532
+ Ee[n],
533
+ a,
534
+ c.trim() !== "",
535
+ (g) => R(g, t.value_format)
536
+ ), N = Ye(a, h, m);
537
+ return /* @__PURE__ */ x(
502
538
  "tr",
503
539
  {
504
- className: S(
540
+ className: O(
505
541
  "border-b border-slate-100 dark:border-border/50",
506
- v && "bg-nvr-cyan/[0.04]"
542
+ $ && "bg-nvr-cyan/[0.04]"
507
543
  ),
508
544
  children: [
509
545
  /* @__PURE__ */ d(
510
546
  "td",
511
547
  {
512
- className: S(
548
+ className: O(
513
549
  "py-1 pr-3 text-slate-700 dark:text-slate-200",
514
- s && "italic text-slate-500"
550
+ l && "italic text-slate-500"
515
551
  ),
516
- style: a ? { paddingLeft: a * 18 } : void 0,
552
+ style: o ? { paddingLeft: o * 18 } : void 0,
517
553
  children: r
518
554
  }
519
555
  ),
520
- ee(n, t.value_format, n === 0 ? { tone: "muted" } : { role: xe }),
521
- R.map((w) => ke(w.field, p[w.field], w.format, w.color ?? "ink")),
522
- U.map((w, bt) => {
523
- const tt = x[bt];
556
+ ae(a, t.value_format, a === 0 ? { tone: "muted" } : { role: Se }),
557
+ G.map((g) => Oe(g.field, m[g.field], g.format, g.color ?? "ink")),
558
+ K.map((g, ne) => {
559
+ const dt = N[ne];
524
560
  return /* @__PURE__ */ d(
525
561
  "td",
526
562
  {
527
- className: S("py-1.5 pr-3 text-right tabular-nums", P),
528
- style: W(w.color ?? "positive", tt, w.color_negative ?? "negative"),
529
- children: L(tt, w.format ?? t.value_format)
563
+ className: O("py-1.5 pr-3 text-right tabular-nums", W),
564
+ style: J(g.color ?? "positive", dt, g.color_negative ?? "negative"),
565
+ children: R(dt, g.format ?? t.value_format)
530
566
  },
531
- w.label
567
+ g.label
532
568
  );
533
569
  }),
534
- /* @__PURE__ */ d("td", { className: "py-1 pr-3 text-right", children: /* @__PURE__ */ b("span", { className: "inline-flex items-center justify-end gap-1.5", children: [
535
- v && C !== 0 && /* @__PURE__ */ b(
570
+ /* @__PURE__ */ d("td", { className: "py-1 pr-3 text-right", children: /* @__PURE__ */ x("span", { className: "inline-flex items-center justify-end gap-1.5", children: [
571
+ $ && S !== 0 && /* @__PURE__ */ x(
536
572
  "span",
537
573
  {
538
- className: S(
574
+ className: O(
539
575
  "rounded-full px-1.5 py-px text-[10.5px] font-medium tabular-nums",
540
- P,
576
+ W,
541
577
  "bg-[color-mix(in_srgb,var(--qtc)_12%,transparent)] dark:bg-[color-mix(in_srgb,var(--qtcd)_14%,transparent)]"
542
578
  ),
543
- style: W(C > 0 ? "positive" : "negative"),
579
+ style: J(S > 0 ? "positive" : "negative"),
544
580
  children: [
545
- C > 0 ? "+" : "−",
546
- L(Math.abs(C), t.value_format)
581
+ S > 0 ? "+" : "−",
582
+ R(Math.abs(S), t.value_format)
547
583
  ]
548
584
  }
549
585
  ),
550
- /* @__PURE__ */ b(
586
+ /* @__PURE__ */ x(
551
587
  "span",
552
588
  {
553
589
  className: "relative rounded-md",
554
- "data-grid-cell": Q ? vt(Q, i) : void 0,
590
+ "data-grid-cell": I ? Ct(I, u) : void 0,
555
591
  children: [
556
592
  t.value_format === "currency" && /* @__PURE__ */ d("span", { className: "pointer-events-none absolute left-2 top-1/2 -translate-y-1/2 text-[11px] text-slate-400", children: "$" }),
557
593
  /* @__PURE__ */ d(
@@ -560,18 +596,27 @@ function Ut({
560
596
  type: "text",
561
597
  inputMode: "decimal",
562
598
  value: c,
563
- placeholder: L(
564
- n,
599
+ placeholder: R(
600
+ a,
565
601
  t.value_format === "currency" ? "number" : t.value_format
566
602
  ),
567
- onChange: (w) => ut(o, w.target.value),
568
- title: "Type a new amount, or +500 / -250 to adjust the current one",
569
- className: S(
603
+ onChange: (g) => kt(n, g.target.value),
604
+ title: y ?? "Type a new amount, or +500 / -250 to adjust the current one",
605
+ "aria-invalid": n in ye || void 0,
606
+ className: O(
570
607
  "h-7 w-32 rounded-md border bg-white text-right text-[12px] tabular-nums outline-none transition-colors placeholder:text-slate-300 focus:border-nvr-cyan dark:bg-background dark:placeholder:text-slate-600",
571
608
  t.value_format === "currency" ? "pl-5 pr-2" : "px-2",
572
- v ? "border-nvr-cyan bg-nvr-cyan/[0.06]" : "border-slate-200 dark:border-border"
609
+ y ? "border-amber-500 ring-1 ring-amber-500/40" : $ ? "border-nvr-cyan bg-nvr-cyan/[0.06]" : "border-slate-200 dark:border-border"
573
610
  )
574
611
  }
612
+ ),
613
+ y && /* @__PURE__ */ d(
614
+ "span",
615
+ {
616
+ "data-matrix-changed": !0,
617
+ className: "absolute right-0 top-full z-10 mt-0.5 whitespace-nowrap rounded bg-amber-100 px-1.5 py-0.5 text-[10.5px] font-medium text-amber-900 shadow-sm dark:bg-amber-500/20 dark:text-amber-200",
618
+ children: "Changed by someone else"
619
+ }
575
620
  )
576
621
  ]
577
622
  }
@@ -579,52 +624,52 @@ function Ut({
579
624
  ] }) })
580
625
  ]
581
626
  },
582
- o
627
+ n
583
628
  );
584
- }, ke = (e, l, r, s) => /* @__PURE__ */ d(
629
+ }, Oe = (e, s, r, l) => /* @__PURE__ */ d(
585
630
  "td",
586
631
  {
587
- className: S(
632
+ className: O(
588
633
  "py-1.5 pr-3 text-right tabular-nums",
589
- s ? P : "text-slate-600 dark:text-slate-300"
634
+ l ? W : "text-slate-600 dark:text-slate-300"
590
635
  ),
591
- style: W(s),
592
- children: L(l, r)
636
+ style: J(l),
637
+ children: R(s, r)
593
638
  },
594
639
  e
595
- ), pt = (e) => {
596
- const l = z.perGroup.get(e);
597
- return !l || !I || !R.some((r) => (l[r.field] ?? 0) !== 0) ? null : /* @__PURE__ */ b("tr", { className: "border-b border-slate-100 dark:border-border/50", children: [
640
+ ), Nt = (e) => {
641
+ const s = z.perGroup.get(e);
642
+ return !s || !X || !G.some((r) => (s[r.field] ?? 0) !== 0) ? null : /* @__PURE__ */ x("tr", { className: "border-b border-slate-100 dark:border-border/50", children: [
598
643
  /* @__PURE__ */ d(
599
644
  "td",
600
645
  {
601
646
  className: "py-1 pr-3 pl-[18px] italic text-slate-400",
602
647
  title: "Spend and commitments on categories outside this project’s list — nothing to allocate here, but they count toward the project total",
603
- children: I.option_label ?? "Other categories"
648
+ children: X.option_label ?? "Other categories"
604
649
  }
605
650
  ),
606
- ee(null, t.value_format, { tone: "muted" }),
607
- R.map((r) => ke(r.field, l[r.field], r.format)),
608
- U.map((r) => /* @__PURE__ */ d("td", { className: "py-1.5 pr-3 text-right tabular-nums text-slate-400", children: "—" }, r.label)),
651
+ ae(null, t.value_format, { tone: "muted" }),
652
+ G.map((r) => Oe(r.field, s[r.field], r.format)),
653
+ K.map((r) => /* @__PURE__ */ d("td", { className: "py-1.5 pr-3 text-right tabular-nums text-slate-400", children: "—" }, r.label)),
609
654
  /* @__PURE__ */ d("td", {})
610
655
  ] }, `${e}|__other__`);
611
- }, Ve = (e) => e.label ?? e.field.replace(/_/g, " ").replace(/\b\w/g, (l) => l.toUpperCase()), De = new Set($ ? Object.keys(_ ?? {}) : []), Qe = (e) => Le((l) => {
612
- const r = new Set(l);
656
+ }, et = (e) => e.label ?? e.field.replace(/_/g, " ").replace(/\b\w/g, (s) => s.toUpperCase()), tt = new Set(k ? Object.keys(_ ?? {}) : []), rt = (e) => Pe((s) => {
657
+ const r = new Set(s);
613
658
  return r.has(e) ? r.delete(e) : r.add(e), r;
614
659
  });
615
- return /* @__PURE__ */ b("div", { ref: Fe, className: "flex h-full min-h-0 flex-col", "data-matrix-editor": !0, children: [
616
- /* @__PURE__ */ b("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: [
617
- t.scope_fields.filter((e) => !De.has(e.field)).map((e) => {
618
- const l = Ne(e.filter, h), r = l && !$e(l) ? l : void 0;
619
- return /* @__PURE__ */ b("div", { className: "w-56", children: [
620
- /* @__PURE__ */ d("p", { className: "mb-1 text-[11px] font-medium text-slate-500 dark:text-slate-400", children: Ve(e) }),
660
+ return /* @__PURE__ */ x("div", { ref: Ke, className: "flex h-full min-h-0 flex-col", "data-matrix-editor": !0, children: [
661
+ /* @__PURE__ */ x("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: [
662
+ t.scope_fields.filter((e) => !tt.has(e.field)).map((e) => {
663
+ const s = qe(e.filter, b), r = s && !Re(s) ? s : void 0;
664
+ return /* @__PURE__ */ x("div", { className: "w-56", children: [
665
+ /* @__PURE__ */ d("p", { className: "mb-1 text-[11px] font-medium text-slate-500 dark:text-slate-400", children: et(e) }),
621
666
  /* @__PURE__ */ d(
622
- wt,
667
+ Mt,
623
668
  {
624
669
  collection: e.collection,
625
- value: h[e.field] ?? null,
626
- onChange: (s) => {
627
- ue((a) => ({ ...a, [e.field]: s })), D({});
670
+ value: b[e.field] ?? null,
671
+ onChange: (l) => {
672
+ D((o) => ({ ...o, [e.field]: l })), Ge();
628
673
  },
629
674
  extraFilter: r,
630
675
  placeholder: "Select…"
@@ -632,91 +677,91 @@ function Ut({
632
677
  )
633
678
  ] }, e.field);
634
679
  }),
635
- pe.length > 0 ? /* @__PURE__ */ d(
636
- gt,
680
+ Ne.length > 0 ? /* @__PURE__ */ d(
681
+ Lt,
637
682
  {
638
683
  className: "min-w-[12rem] flex-1 pb-2",
639
- editors: pe,
640
- noun: ((Ze = t.presence_noun) == null ? void 0 : Ze.trim()) || t.target_collection.replace(/_/g, " ").toLowerCase(),
641
- rowLabel: (e) => ot.get(e),
642
- cellLabel: (e) => Re.current.get(e)
684
+ editors: Ne,
685
+ noun: ((it = t.presence_noun) == null ? void 0 : it.trim()) || t.target_collection.replace(/_/g, " ").toLowerCase(),
686
+ rowLabel: (e) => ht.get(e),
687
+ cellLabel: (e) => Je.current.get(e)
643
688
  }
644
689
  ) : /* @__PURE__ */ d("span", { className: "flex-1" }),
645
- qe && /* @__PURE__ */ d("span", { className: "pb-2 text-[12px] text-slate-500", children: qe }),
646
- Ue && /* @__PURE__ */ d(
690
+ Ae && /* @__PURE__ */ d("span", { className: "pb-2 text-[12px] text-slate-500", children: Ae }),
691
+ He && /* @__PURE__ */ d(
647
692
  "button",
648
693
  {
649
694
  type: "button",
650
- onClick: () => D({}),
695
+ onClick: Ge,
651
696
  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",
652
697
  children: "Discard"
653
698
  }
654
699
  ),
655
- /* @__PURE__ */ b(
700
+ /* @__PURE__ */ x(
656
701
  "button",
657
702
  {
658
703
  type: "button",
659
- disabled: !F || !Ue || je,
660
- onClick: () => void mt(),
704
+ disabled: !F || !He || ze,
705
+ onClick: () => void vt(),
661
706
  "data-matrix-save": !0,
662
707
  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",
663
708
  children: [
664
- je && /* @__PURE__ */ d(rt, { className: "h-3.5 w-3.5 animate-spin" }),
709
+ ze && /* @__PURE__ */ d(ut, { className: "h-3.5 w-3.5 animate-spin" }),
665
710
  "Save changes"
666
711
  ]
667
712
  }
668
713
  )
669
714
  ] }),
670
- B !== null && F && /* @__PURE__ */ d("div", { className: "grid shrink-0 grid-cols-2 gap-px border-b border-slate-200 bg-slate-200 dark:border-border dark:bg-border sm:grid-cols-4", children: [
715
+ H !== null && F && /* @__PURE__ */ d("div", { className: "grid shrink-0 grid-cols-2 gap-px border-b border-slate-200 bg-slate-200 dark:border-border dark:bg-border sm:grid-cols-4", children: [
671
716
  {
672
- label: ((et = t.cap) == null ? void 0 : et.label) ?? "Cap",
673
- value: B,
717
+ label: ((ct = t.cap) == null ? void 0 : ct.label) ?? "Cap",
718
+ value: H,
674
719
  tone: "plain",
675
720
  role: "accent"
676
721
  },
677
722
  {
678
723
  label: "Allocated",
679
- value: H.next,
680
- tone: H.next !== fe ? "edited" : "plain",
681
- role: xe,
682
- sub: H.next !== fe ? `was ${L(fe, "currency")}` : void 0
724
+ value: Y.next,
725
+ tone: Y.next !== we ? "edited" : "plain",
726
+ role: Se,
727
+ sub: Y.next !== we ? `was ${R(we, "currency")}` : void 0
683
728
  },
684
729
  {
685
730
  label: "Available to allocate",
686
- value: he,
687
- tone: he !== null && he < 0 ? "neg" : "ok"
731
+ value: $e,
732
+ tone: $e !== null && $e < 0 ? "neg" : "ok"
688
733
  },
689
734
  {
690
735
  label: "Misallocated",
691
- value: A,
692
- tone: A > 0 ? "neg" : "muted",
736
+ value: P,
737
+ tone: P > 0 ? "neg" : "muted",
693
738
  hint: "Allocations on categories or regions outside this project’s current lists"
694
739
  }
695
- ].map((e) => /* @__PURE__ */ b("div", { className: "bg-white px-4 py-2.5 dark:bg-card", title: e.hint, children: [
740
+ ].map((e) => /* @__PURE__ */ x("div", { className: "bg-white px-4 py-2.5 dark:bg-card", title: e.hint, children: [
696
741
  /* @__PURE__ */ d("p", { className: "text-[10px] font-semibold uppercase tracking-wide text-slate-400", children: e.label }),
697
742
  /* @__PURE__ */ d(
698
743
  "p",
699
744
  {
700
- className: S(
745
+ className: O(
701
746
  "mt-0.5 text-[17px] font-semibold tabular-nums tracking-[-0.01em]",
702
- e.tone === "muted" ? "text-slate-400" : P
747
+ e.tone === "muted" ? "text-slate-400" : W
703
748
  ),
704
- style: W(
749
+ style: J(
705
750
  e.tone === "neg" ? "negative" : e.tone === "ok" ? "positive" : e.tone === "edited" ? "accent" : e.role ?? "ink"
706
751
  ),
707
- children: L(e.value, "currency")
752
+ children: R(e.value, "currency")
708
753
  }
709
754
  ),
710
755
  e.sub && /* @__PURE__ */ d("p", { className: "text-[11px] text-slate-400", children: e.sub })
711
756
  ] }, e.label)) }),
712
- /* @__PURE__ */ d("div", { className: "min-h-0 flex-1 overflow-auto bg-slate-50/60 dark:bg-transparent", children: F ? it || be ? /* @__PURE__ */ b("div", { className: "flex items-center gap-2 p-4 text-[12px] text-slate-400", children: [
713
- /* @__PURE__ */ d(rt, { className: "h-4 w-4 animate-spin" }),
757
+ /* @__PURE__ */ d("div", { className: "min-h-0 flex-1 overflow-auto bg-slate-50/60 dark:bg-transparent", children: F ? xt || ge ? /* @__PURE__ */ x("div", { className: "flex items-center gap-2 p-4 text-[12px] text-slate-400", children: [
758
+ /* @__PURE__ */ d(ut, { className: "h-4 w-4 animate-spin" }),
714
759
  " Loading…"
715
- ] }) : /* @__PURE__ */ b("table", { className: "w-full text-[12px]", children: [
716
- /* @__PURE__ */ d("thead", { className: "sticky top-0 z-[1] bg-slate-50 dark:bg-background", children: /* @__PURE__ */ b("tr", { className: "border-b border-slate-200 text-left dark:border-border", children: [
760
+ ] }) : /* @__PURE__ */ x("table", { className: "w-full text-[12px]", children: [
761
+ /* @__PURE__ */ d("thead", { className: "sticky top-0 z-[1] bg-slate-50 dark:bg-background", children: /* @__PURE__ */ x("tr", { className: "border-b border-slate-200 text-left dark:border-border", children: [
717
762
  /* @__PURE__ */ d("th", { className: "px-3 py-2 text-[10.5px] font-semibold uppercase tracking-wide text-slate-400", children: t.option_collection.replace(/_/g, " ").replace(/\b\w/g, (e) => e.toUpperCase()) }),
718
- /* @__PURE__ */ d("th", { className: "w-32 py-2 pr-3 text-right text-[10.5px] font-semibold uppercase tracking-wide text-slate-400", children: Pe }),
719
- R.map((e) => /* @__PURE__ */ d(
763
+ /* @__PURE__ */ d("th", { className: "w-32 py-2 pr-3 text-right text-[10.5px] font-semibold uppercase tracking-wide text-slate-400", children: Xe }),
764
+ G.map((e) => /* @__PURE__ */ d(
720
765
  "th",
721
766
  {
722
767
  className: "w-32 py-2 pr-3 text-right text-[10.5px] font-semibold uppercase tracking-wide text-slate-400",
@@ -724,7 +769,7 @@ function Ut({
724
769
  },
725
770
  e.field
726
771
  )),
727
- U.map((e) => /* @__PURE__ */ d(
772
+ K.map((e) => /* @__PURE__ */ d(
728
773
  "th",
729
774
  {
730
775
  className: "w-32 py-2 pr-3 text-right text-[10.5px] font-semibold uppercase tracking-wide text-slate-400",
@@ -732,160 +777,173 @@ function Ut({
732
777
  },
733
778
  e.label
734
779
  )),
735
- /* @__PURE__ */ b("th", { className: "w-44 py-2 pr-3 text-right text-[10.5px] font-semibold uppercase tracking-wide text-slate-400", children: [
780
+ /* @__PURE__ */ x("th", { className: "w-44 py-2 pr-3 text-right text-[10.5px] font-semibold uppercase tracking-wide text-slate-400", children: [
736
781
  "New ",
737
- Pe
782
+ Xe
738
783
  ] })
739
784
  ] }) }),
740
- /* @__PURE__ */ b("tbody", { className: "bg-white dark:bg-transparent", children: [
741
- q.map((e) => {
742
- var i, u;
743
- const l = Oe.has(e.id), r = [...y.entries()].filter(([n]) => n.startsWith(`${e.id}|`)).reduce((n, [, p]) => n + p.total, 0), s = Je(), a = _e([
744
- ...s.map((n) => oe(e.id, n)),
785
+ /* @__PURE__ */ x("tbody", { className: "bg-white dark:bg-transparent", children: [
786
+ M.map((e) => {
787
+ var u, i;
788
+ const s = Ue.has(e.id), r = [...v.entries()].filter(([a]) => a.startsWith(`${e.id}|`)).reduce((a, [, m]) => a + m.total, 0), l = Ze(), o = je([
789
+ ...l.map((a) => be(e.id, a)),
745
790
  ...z.perGroup.get(e.id) ? [z.perGroup.get(e.id)] : []
746
- ]), o = s.reduce((n, p) => n + Z(`${e.id}|${p}`), 0) + (r - s.reduce((n, p) => {
791
+ ]), n = l.reduce((a, m) => a + le(`${e.id}|${m}`), 0) + (r - l.reduce((a, m) => {
747
792
  var c;
748
- return n + (((c = y.get(`${e.id}|${p}`)) == null ? void 0 : c.total) ?? 0);
793
+ return a + (((c = v.get(`${e.id}|${m}`)) == null ? void 0 : c.total) ?? 0);
749
794
  }, 0));
750
795
  return /* @__PURE__ */ d(
751
- at,
796
+ bt,
752
797
  {
753
- header: m ? /* @__PURE__ */ b(
798
+ header: f ? /* @__PURE__ */ x(
754
799
  "tr",
755
800
  {
756
801
  className: "cursor-pointer border-y border-slate-200 bg-slate-100/70 hover:bg-slate-100 dark:border-border dark:bg-muted/60",
757
- onClick: () => Qe(e.id),
802
+ onClick: () => rt(e.id),
758
803
  "data-matrix-group": e.id,
759
804
  children: [
760
- /* @__PURE__ */ d("td", { className: "px-3 py-1.5 text-[12px] font-semibold text-slate-700 dark:text-slate-200", children: /* @__PURE__ */ b("span", { className: "inline-flex items-center gap-1.5", children: [
805
+ /* @__PURE__ */ d("td", { className: "px-3 py-1.5 text-[12px] font-semibold text-slate-700 dark:text-slate-200", children: /* @__PURE__ */ x("span", { className: "inline-flex items-center gap-1.5", children: [
761
806
  /* @__PURE__ */ d(
762
- lt,
807
+ mt,
763
808
  {
764
- className: S(
809
+ className: O(
765
810
  "h-3.5 w-3.5 text-slate-400 transition-transform",
766
- !l && "rotate-90"
811
+ !s && "rotate-90"
767
812
  )
768
813
  }
769
814
  ),
770
815
  e.label
771
816
  ] }) }),
772
- ye(r, o, a, !0)
817
+ Ce(r, n, o, !0)
773
818
  ]
774
819
  }
775
820
  ) : null,
776
- children: !l && /* @__PURE__ */ b(we, { children: [
777
- t.option_section ? ie.map((n) => {
778
- const p = `s:${e.id}|${n.name}`, c = Oe.has(p), k = n.rows.reduce(
779
- (x, O) => {
780
- var te;
781
- return x + (((te = y.get(`${e.id}|${O.key}`)) == null ? void 0 : te.total) ?? 0);
821
+ children: !s && /* @__PURE__ */ x(Me, { children: [
822
+ t.option_section ? fe.map((a) => {
823
+ const m = `s:${e.id}|${a.name}`, c = Ue.has(m), h = a.rows.reduce(
824
+ (y, N) => {
825
+ var C;
826
+ return y + (((C = v.get(`${e.id}|${N.key}`)) == null ? void 0 : C.total) ?? 0);
782
827
  },
783
828
  0
784
- ), v = n.rows.reduce(
785
- (x, O) => x + Z(`${e.id}|${O.key}`),
829
+ ), $ = a.rows.reduce(
830
+ (y, N) => y + le(`${e.id}|${N.key}`),
786
831
  0
787
- ), C = _e(
788
- n.rows.map((x) => oe(e.id, x.key))
832
+ ), S = je(
833
+ a.rows.map((y) => be(e.id, y.key))
789
834
  );
790
835
  return /* @__PURE__ */ d(
791
- at,
836
+ bt,
792
837
  {
793
- header: /* @__PURE__ */ b(
838
+ header: /* @__PURE__ */ x(
794
839
  "tr",
795
840
  {
796
841
  className: "cursor-pointer border-b border-slate-100 bg-slate-50/80 hover:bg-slate-50 dark:border-border/50 dark:bg-muted/30",
797
- onClick: () => Qe(p),
842
+ onClick: () => rt(m),
798
843
  children: [
799
- /* @__PURE__ */ d("td", { className: "py-1 pr-3 pl-[22px] text-[11.5px] font-medium text-slate-600 dark:text-slate-300", children: /* @__PURE__ */ b("span", { className: "inline-flex items-center gap-1.5", children: [
844
+ /* @__PURE__ */ d("td", { className: "py-1 pr-3 pl-[22px] text-[11.5px] font-medium text-slate-600 dark:text-slate-300", children: /* @__PURE__ */ x("span", { className: "inline-flex items-center gap-1.5", children: [
800
845
  /* @__PURE__ */ d(
801
- lt,
846
+ mt,
802
847
  {
803
- className: S(
848
+ className: O(
804
849
  "h-3 w-3 text-slate-400 transition-transform",
805
850
  !c && "rotate-90"
806
851
  )
807
852
  }
808
853
  ),
809
- n.name || "—"
854
+ a.name || "—"
810
855
  ] }) }),
811
- ye(k, v, C, !1)
856
+ Ce(h, $, S, !1)
812
857
  ]
813
858
  }
814
859
  ),
815
- children: !c && n.rows.map(
816
- (x) => ce(e.id, x.key, x.label, !1, 2.4)
860
+ children: !c && a.rows.map(
861
+ (y) => he(e.id, y.key, y.label, !1, 2.4)
817
862
  )
818
863
  },
819
- p
864
+ m
820
865
  );
821
- }) : j.map((n) => ce(e.id, n.key, n.label, !1, 1)),
822
- ((i = t.specials) == null ? void 0 : i.uncategorized) && ce(
866
+ }) : q.map((a) => he(e.id, a.key, a.label, !1, 1)),
867
+ ((u = t.specials) == null ? void 0 : u.uncategorized) && he(
823
868
  e.id,
824
- J,
869
+ V,
825
870
  t.specials.uncategorized.label ?? "Uncategorized",
826
871
  !0,
827
872
  1
828
873
  ),
829
- ((u = t.specials) == null ? void 0 : u.bucket) && ce(
874
+ ((i = t.specials) == null ? void 0 : i.bucket) && he(
830
875
  e.id,
831
- V,
876
+ B,
832
877
  t.specials.bucket.label ?? "Inventory",
833
878
  !0,
834
879
  1
835
880
  ),
836
- pt(e.id)
881
+ Nt(e.id)
837
882
  ] })
838
883
  },
839
884
  e.id || "__all__"
840
885
  );
841
886
  }),
842
- I && m && z.otherGroupCount > 0 && /* @__PURE__ */ b(
887
+ X && f && z.otherGroupCount > 0 && /* @__PURE__ */ x(
843
888
  "tr",
844
889
  {
845
890
  className: "border-y border-slate-200 bg-slate-100/70 dark:border-border dark:bg-muted/60",
846
891
  title: "Spend and commitments on regions outside this project’s list",
847
892
  children: [
848
- /* @__PURE__ */ d("td", { className: "px-3 py-1.5 text-[12px] font-semibold italic text-slate-500", children: I.group_label ?? "Other regions" }),
849
- ee(null, t.value_format, { tone: "muted" }),
850
- R.map(
851
- (e) => ke(e.field, z.otherGroup[e.field], e.format)
893
+ /* @__PURE__ */ d("td", { className: "px-3 py-1.5 text-[12px] font-semibold italic text-slate-500", children: X.group_label ?? "Other regions" }),
894
+ ae(null, t.value_format, { tone: "muted" }),
895
+ G.map(
896
+ (e) => Oe(e.field, z.otherGroup[e.field], e.format)
852
897
  ),
853
- U.map((e) => /* @__PURE__ */ d("td", { className: "py-1.5 pr-3 text-right text-slate-400", children: "—" }, e.label)),
898
+ K.map((e) => /* @__PURE__ */ d("td", { className: "py-1.5 pr-3 text-right text-slate-400", children: "—" }, e.label)),
854
899
  /* @__PURE__ */ d("td", {})
855
900
  ]
856
901
  }
857
902
  )
858
903
  ] }),
859
- /* @__PURE__ */ d("tfoot", { className: "sticky bottom-0 bg-white dark:bg-card", children: /* @__PURE__ */ b("tr", { className: "border-t-2 border-slate-300 dark:border-border", children: [
904
+ /* @__PURE__ */ d("tfoot", { className: "sticky bottom-0 bg-white dark:bg-card", children: /* @__PURE__ */ x("tr", { className: "border-t-2 border-slate-300 dark:border-border", children: [
860
905
  /* @__PURE__ */ d("td", { className: "px-3 py-2 text-[12px] font-semibold text-slate-800 dark:text-slate-100", children: "Total" }),
861
- ye(H.current, H.next, H.metrics, !0)
906
+ Ce(Y.current, Y.next, Y.metrics, !0)
862
907
  ] }) })
863
- ] }) : /* @__PURE__ */ b("div", { className: "flex h-full flex-col items-center justify-center gap-1 p-8 text-center", children: [
864
- /* @__PURE__ */ b("p", { className: "text-[13px] font-medium text-slate-600 dark:text-slate-300", children: [
908
+ ] }) : /* @__PURE__ */ x("div", { className: "flex h-full flex-col items-center justify-center gap-1 p-8 text-center", children: [
909
+ /* @__PURE__ */ x("p", { className: "text-[13px] font-medium text-slate-600 dark:text-slate-300", children: [
865
910
  "Choose",
866
911
  " ",
867
- t.scope_fields.filter((e) => !De.has(e.field)).map(Ve).join(" and "),
912
+ t.scope_fields.filter((e) => !tt.has(e.field)).map(et).join(" and "),
868
913
  " ",
869
914
  "to load allocations"
870
915
  ] }),
871
- /* @__PURE__ */ b("p", { className: "text-[12px] text-slate-400", children: [
916
+ /* @__PURE__ */ x("p", { className: "text-[12px] text-slate-400", children: [
872
917
  "Amounts are grouped by",
873
918
  " ",
874
- m != null && m.label_field ? m.collection.replace(/_/g, " ") : "section",
919
+ f != null && f.label_field ? f.collection.replace(/_/g, " ") : "section",
875
920
  " and saved together."
876
921
  ] })
877
922
  ] }) })
878
923
  ] });
879
924
  }
880
- function at({
925
+ function bt({
881
926
  header: t,
882
927
  children: _
883
928
  }) {
884
- return /* @__PURE__ */ b(we, { children: [
929
+ return /* @__PURE__ */ x(Me, { children: [
885
930
  t,
886
931
  _
887
932
  ] });
888
933
  }
934
+ function zt(t, _, k, p, w, b) {
935
+ if (t) {
936
+ const D = Number(_);
937
+ return `Someone else saved ${_ == null ? "empty" : Number.isFinite(D) ? b(D) : String(_)} here since you started. Save again to keep yours, or clear the cell to take theirs.`;
938
+ }
939
+ return w && k !== void 0 && k !== p ? `Someone else changed this from ${b(k)} to ${b(p)} since you started.` : null;
940
+ }
941
+ function Tt(t, _, k) {
942
+ const p = `Saved — ${t} updated, ${_} created`;
943
+ return k === 0 ? p : `${p}. ${k} cell${k === 1 ? " was" : "s were"} changed by someone else — check the outlined cells.`;
944
+ }
889
945
  export {
890
- Ut as MatrixEditor
946
+ tr as MatrixEditor,
947
+ zt as matrixCellNote,
948
+ Tt as matrixSaveStatus
891
949
  };