@nivaro/react 0.3.112 → 0.3.114

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
@@ -1,34 +1,34 @@
1
- import { jsxs as t, jsx as n } from "react/jsx-runtime";
2
- import { Sigma as p, ChevronDown as b, PenLine as h, Check as x } from "lucide-react";
3
- import { useState as g } from "react";
4
- import { cn as i } from "../../lib/utils.js";
1
+ import { jsxs as t, jsx as o } from "react/jsx-runtime";
2
+ import { Sigma as f, ChevronDown as b, PenLine as x, Check as g } from "lucide-react";
3
+ import { useState as h } from "react";
4
+ import { cn as a } from "../../lib/utils.js";
5
5
  import { Popover as v, PopoverTrigger as w, PopoverContent as N } from "../ui/popover.js";
6
6
  import { TOTAL_FNS as y } from "./column-totals.js";
7
7
  function j({
8
8
  label: u,
9
9
  selectedCount: r,
10
- onSetSelected: s,
11
- setUnavailable: a,
12
- totals: o
10
+ onSetSelected: l,
11
+ setUnavailable: i,
12
+ totals: e
13
13
  }) {
14
- const [m, c] = g(!1);
15
- if (!s && !o) return null;
16
- const l = (e) => e.stopPropagation(), d = !!(o != null && o.fn);
17
- return /* @__PURE__ */ t(v, { open: m, onOpenChange: c, children: [
18
- /* @__PURE__ */ n(w, { asChild: !0, children: /* @__PURE__ */ n(
14
+ const [d, s] = h(!1);
15
+ if (!l && !e) return null;
16
+ const c = (n) => n.stopPropagation(), m = !!(e != null && e.fn);
17
+ return /* @__PURE__ */ t(v, { open: d, onOpenChange: s, children: [
18
+ /* @__PURE__ */ o(w, { asChild: !0, children: /* @__PURE__ */ o(
19
19
  "button",
20
20
  {
21
21
  type: "button",
22
- onClick: l,
23
- onKeyDown: l,
22
+ onClick: c,
23
+ onKeyDown: c,
24
24
  "aria-label": `${u} column menu`,
25
25
  "data-cbv-col-menu": !0,
26
26
  "data-tip": "Column menu",
27
- className: i(
27
+ className: a(
28
28
  "ml-1 inline-flex h-4 w-4 items-center justify-center rounded align-middle transition-opacity focus-visible:opacity-100 focus-visible:outline-none focus-visible:ring-2 focus-visible:ring-nvr-cyan",
29
- m || d ? "text-[#00a5cc] opacity-100" : "text-slate-400 opacity-0 hover:text-slate-600 group-hover/hcell:opacity-100 dark:text-slate-500 dark:hover:text-slate-300"
29
+ d || m ? "text-[#00a5cc] opacity-100" : "text-slate-400 opacity-0 hover:text-slate-600 group-hover/hcell:opacity-100 dark:text-slate-500 dark:hover:text-slate-300"
30
30
  ),
31
- children: d ? /* @__PURE__ */ n(p, { className: "h-3 w-3" }) : /* @__PURE__ */ n(b, { className: "h-3 w-3" })
31
+ children: m ? /* @__PURE__ */ o(f, { className: "h-3 w-3" }) : /* @__PURE__ */ o(b, { className: "h-3 w-3" })
32
32
  }
33
33
  ) }),
34
34
  /* @__PURE__ */ t(
@@ -37,30 +37,30 @@ function j({
37
37
  align: "start",
38
38
  sideOffset: 6,
39
39
  className: "w-64 p-1 normal-case tracking-normal",
40
- onClick: l,
41
- onKeyDown: l,
42
- onCloseAutoFocus: (e) => e.preventDefault(),
40
+ onClick: c,
41
+ onKeyDown: c,
42
+ onCloseAutoFocus: (n) => n.preventDefault(),
43
43
  "data-cbv-col-menu-panel": !0,
44
44
  children: [
45
- s && /* @__PURE__ */ n("div", { className: i(o && "border-b border-border pb-1"), children: /* @__PURE__ */ t(
45
+ l && /* @__PURE__ */ o("div", { className: a(e && "border-b border-border pb-1"), children: /* @__PURE__ */ t(
46
46
  "button",
47
47
  {
48
48
  type: "button",
49
- disabled: r === 0 || !!a,
49
+ disabled: r === 0 || !!i,
50
50
  onClick: () => {
51
- c(!1), setTimeout(s, 0);
51
+ s(!1), setTimeout(l, 0);
52
52
  },
53
53
  "data-cbv-col-set": !0,
54
54
  className: "flex w-full items-start gap-2 rounded-sm px-2 py-1.5 text-left text-[12.5px] text-foreground hover:bg-muted focus-visible:bg-muted focus-visible:outline-none disabled:cursor-default disabled:hover:bg-transparent",
55
55
  children: [
56
- /* @__PURE__ */ n(h, { className: "mt-0.5 h-3.5 w-3.5 shrink-0 text-muted-foreground" }),
56
+ /* @__PURE__ */ o(x, { className: "mt-0.5 h-3.5 w-3.5 shrink-0 text-muted-foreground" }),
57
57
  /* @__PURE__ */ t("span", { className: "min-w-0", children: [
58
58
  /* @__PURE__ */ t(
59
59
  "span",
60
60
  {
61
- className: i(
61
+ className: a(
62
62
  "block",
63
- (r === 0 || a) && "text-muted-foreground"
63
+ (r === 0 || i) && "text-muted-foreground"
64
64
  ),
65
65
  children: [
66
66
  "Set ",
@@ -72,34 +72,51 @@ function j({
72
72
  ]
73
73
  }
74
74
  ),
75
- (a || r === 0) && /* @__PURE__ */ n("span", { className: "block text-[11px] leading-4 text-muted-foreground", children: a ?? "Tick the rows to change first." })
75
+ (i || r === 0) && /* @__PURE__ */ o("span", { className: "block text-[11px] leading-4 text-muted-foreground", children: i ?? "Tick the rows to change first." })
76
76
  ] })
77
77
  ]
78
78
  }
79
79
  ) }),
80
- o && /* @__PURE__ */ t("fieldset", { className: i("m-0 min-w-0 border-0 p-0", s && "pt-1"), children: [
81
- /* @__PURE__ */ n("legend", { className: "px-2 pb-0.5 pt-1 text-[10.5px] font-semibold uppercase tracking-wide text-muted-foreground", children: "Σ Totals row" }),
82
- [
80
+ e && /* @__PURE__ */ t("fieldset", { className: a("m-0 min-w-0 border-0 p-0", l && "pt-1"), children: [
81
+ /* @__PURE__ */ o("legend", { className: "px-2 pb-0.5 pt-1 text-[10.5px] font-semibold uppercase tracking-wide text-muted-foreground", children: "Σ Totals row" }),
82
+ e.unavailable ? /* @__PURE__ */ o(
83
+ "p",
84
+ {
85
+ "data-cbv-col-total-unavailable": !0,
86
+ "data-tip": e.unavailable,
87
+ className: "cursor-help px-2 py-1 text-[12px] leading-snug text-muted-foreground underline decoration-dotted underline-offset-2",
88
+ children: "No total for this column"
89
+ }
90
+ ) : null,
91
+ e.note && !e.unavailable ? /* @__PURE__ */ o(
92
+ "p",
93
+ {
94
+ "data-cbv-col-total-note": !0,
95
+ className: "px-2 pb-1 text-[11.5px] leading-snug text-muted-foreground",
96
+ children: e.note
97
+ }
98
+ ) : null,
99
+ (e.unavailable ? [] : [
83
100
  { fn: null, label: "Off" },
84
- ...y
85
- ].map((e) => {
86
- const f = (o.fn ?? null) === e.fn;
101
+ ...y.filter((n) => !e.only || e.only.includes(n.fn))
102
+ ]).map((n) => {
103
+ const p = (e.fn ?? null) === n.fn;
87
104
  return /* @__PURE__ */ t(
88
105
  "button",
89
106
  {
90
107
  type: "button",
91
- "aria-pressed": f,
92
- "data-cbv-col-total": e.fn ?? "off",
108
+ "aria-pressed": p,
109
+ "data-cbv-col-total": n.fn ?? "off",
93
110
  onClick: () => {
94
- o.onChange(e.fn), c(!1);
111
+ e.onChange(n.fn), s(!1);
95
112
  },
96
113
  className: "flex w-full items-center gap-2 rounded-sm px-2 py-1 text-left text-[12.5px] text-foreground hover:bg-muted focus-visible:bg-muted focus-visible:outline-none",
97
114
  children: [
98
- /* @__PURE__ */ n(x, { className: i("h-3.5 w-3.5 text-[#00a5cc]", !f && "invisible") }),
99
- e.label
115
+ /* @__PURE__ */ o(g, { className: a("h-3.5 w-3.5 text-[#00a5cc]", !p && "invisible") }),
116
+ n.label
100
117
  ]
101
118
  },
102
- e.fn ?? "off"
119
+ n.fn ?? "off"
103
120
  );
104
121
  })
105
122
  ] })
@@ -1,66 +1,171 @@
1
- import { formatValue as s } from "../../lib/format-value.js";
2
- const u = [
1
+ import { formatValue as S } from "../../lib/format-value.js";
2
+ const g = [
3
3
  { fn: "sum", label: "Sum", short: "Sum" },
4
4
  { fn: "avg", label: "Average", short: "Avg" },
5
5
  { fn: "min", label: "Minimum", short: "Min" },
6
6
  { fn: "max", label: "Maximum", short: "Max" },
7
7
  { fn: "count", label: "Count (filled in)", short: "Count" }
8
8
  ];
9
- function f(t) {
10
- return typeof t == "string" && u.some((e) => e.fn === t);
9
+ function b(e) {
10
+ return typeof e == "string" && g.some((n) => n.fn === e);
11
11
  }
12
- function m(t) {
13
- return /^[A-Za-z_][A-Za-z0-9_]*$/.test(t);
12
+ function v(e) {
13
+ return /^[A-Za-z_][A-Za-z0-9_]*$/.test(e);
14
14
  }
15
- function g(t, e, n) {
15
+ function w(e, n, t) {
16
16
  return {
17
- [e]: t,
18
- ...n.search ? { search: n.search } : {},
19
- ...n.conditions ? { conditions: n.conditions } : {}
17
+ [n]: e,
18
+ ...t.search ? { search: t.search } : {},
19
+ ...t.conditions ? { conditions: t.conditions } : {}
20
20
  };
21
21
  }
22
- function h(t, e, n) {
23
- var a, c, l;
24
- const o = (l = (c = (a = t == null ? void 0 : t.data) == null ? void 0 : a[0]) == null ? void 0 : c[n]) == null ? void 0 : l[e];
25
- if (o == null || o === "") return null;
26
- const r = Number(o);
27
- return Number.isFinite(r) ? r : null;
22
+ function M(e, n, t) {
23
+ var i, l, c;
24
+ const r = (c = (l = (i = e == null ? void 0 : e.data) == null ? void 0 : i[0]) == null ? void 0 : l[t]) == null ? void 0 : c[n];
25
+ if (r == null || r === "") return null;
26
+ const o = Number(r);
27
+ return Number.isFinite(o) ? o : null;
28
28
  }
29
- function b(t, e, n) {
30
- return e === "count" ? Math.round(t).toLocaleString("en-US") : (n == null ? void 0 : n.type) === "number" ? s(String(t), n) : (Math.round(t * 100) / 100).toLocaleString("en-US", { maximumFractionDigits: 2 });
29
+ function $(e, n, t) {
30
+ return n === "count" ? Math.round(e).toLocaleString("en-US") : (t == null ? void 0 : t.type) === "number" ? S(String(e), t) : (Math.round(e * 100) / 100).toLocaleString("en-US", { maximumFractionDigits: 2 });
31
31
  }
32
- const i = (t) => `nvr_cbv_totals_${t}`;
33
- function S(t) {
32
+ const p = (e) => `nvr_cbv_totals_${e}`, _ = (e) => e === "off" || b(e);
33
+ function k(e) {
34
+ return y(p(e), v);
35
+ }
36
+ function z(e, n) {
37
+ T(p(e), n);
38
+ }
39
+ function y(e, n) {
34
40
  try {
35
- const e = localStorage.getItem(i(t)), n = e ? JSON.parse(e) : null;
36
- if (!n || typeof n != "object") return {};
37
- const o = {};
38
- for (const [r, a] of Object.entries(n))
39
- m(r) && f(a) && (o[r] = a);
40
- return o;
41
+ const t = localStorage.getItem(e), r = t ? JSON.parse(t) : null;
42
+ if (!r || typeof r != "object") return {};
43
+ const o = r.v === 2 && r.o && typeof r.o == "object" ? r.o : r, i = {};
44
+ for (const [l, c] of Object.entries(o)) n(l) && _(c) && (i[l] = c);
45
+ return i;
41
46
  } catch {
42
47
  return {};
43
48
  }
44
49
  }
45
- function p(t, e) {
50
+ function T(e, n) {
46
51
  try {
47
- Object.keys(e).length === 0 ? localStorage.removeItem(i(t)) : localStorage.setItem(i(t), JSON.stringify(e));
52
+ Object.keys(n).length === 0 ? localStorage.removeItem(e) : localStorage.setItem(e, JSON.stringify({ v: 2, o: n }));
48
53
  } catch {
49
54
  }
50
55
  }
51
- function y(t, e, n) {
52
- var a;
53
- const o = ((a = u.find((c) => c.fn === t)) == null ? void 0 : a.label.toLowerCase()) ?? t, r = n == null ? "all matching records" : `all ${n.toLocaleString("en-US")} matching records`;
54
- return t === "count" ? `Records with ${e} filled in, across ${r}` : `${o.charAt(0).toUpperCase()}${o.slice(1)} of ${e} across ${r}`;
56
+ function j(e, n) {
57
+ const t = { ...e };
58
+ for (const [r, o] of Object.entries(n))
59
+ o === "off" ? delete t[r] : t[r] = o;
60
+ return t;
61
+ }
62
+ function N(e, n, t) {
63
+ return { ...e, [n]: t ?? "off" };
64
+ }
65
+ function Z(e, n) {
66
+ const t = {};
67
+ for (const [r, o] of Object.entries(e))
68
+ (o === "off" ? !n[r] : n[r] === o) || (t[r] = o);
69
+ return t;
70
+ }
71
+ function h(e) {
72
+ return !e.computed_formula || !!e.computed_store;
73
+ }
74
+ const A = /* @__PURE__ */ new Set(["integer", "bigInteger", "biginteger", "decimal", "float"]);
75
+ function O(e) {
76
+ const n = String(e ?? "").trim();
77
+ if (!n) return null;
78
+ let t = 0;
79
+ const r = () => {
80
+ for (; t < n.length && /\s/.test(n[t]); ) t++;
81
+ }, o = () => {
82
+ r();
83
+ const a = n.slice(t), s = /^item\.([A-Za-z_][A-Za-z0-9_]*)/.exec(a);
84
+ if (s)
85
+ return t += s[0].length, s[1];
86
+ const u = /^\{\{\s*([A-Za-z_][A-Za-z0-9_.]*)\s*\}\}/.exec(a);
87
+ if (u)
88
+ return t += u[0].length, u[1];
89
+ const f = /^coalesce\s*\(/i.exec(a);
90
+ if (f) {
91
+ t += f[0].length;
92
+ const d = o(), m = /^\s*,\s*0(?:\.0+)?\s*\)/.exec(n.slice(t));
93
+ return !d || !m ? null : (t += m[0].length, d);
94
+ }
95
+ return null;
96
+ }, i = /* @__PURE__ */ new Map(), l = (a) => {
97
+ let s = !0;
98
+ for (; ; ) {
99
+ r();
100
+ let u = a;
101
+ if (n[t] === "+" || n[t] === "-")
102
+ n[t] === "-" && (u = u === 1 ? -1 : 1), t++, r();
103
+ else if (!s) return !1;
104
+ if (s = !1, n[t] === "(") {
105
+ if (t++, !l(u) || (r(), n[t] !== ")")) return !1;
106
+ t++;
107
+ } else {
108
+ const f = o();
109
+ if (!f) return !1;
110
+ i.set(f, (i.get(f) ?? 0) + u);
111
+ }
112
+ if (r(), t >= n.length || n[t] === ")") return !0;
113
+ if (n[t] !== "+" && n[t] !== "-") return !1;
114
+ }
115
+ };
116
+ if (!l(1) || (r(), t !== n.length)) return null;
117
+ const c = [];
118
+ for (const [a, s] of i)
119
+ if (s === 1 || s === -1) c.push({ field: a, sign: s });
120
+ else if (s !== 0) return null;
121
+ return c.length ? c : null;
122
+ }
123
+ function C(e, n) {
124
+ if (h(e)) return { kind: "server" };
125
+ if (e.computed_type !== "rollup") {
126
+ const t = O(e.computed_formula ?? "");
127
+ if (t != null && t.every((r) => {
128
+ const o = n(r.field);
129
+ return !!o && h(o) && A.has(String(o.type ?? ""));
130
+ }))
131
+ return { kind: "derived", terms: t };
132
+ }
133
+ return {
134
+ kind: "none",
135
+ why: e.computed_type === "rollup" ? "Worked out from linked records each time the list is read, so it has no total." : "Calculated each time the list is read from a formula that does more than add and subtract stored columns, so it has no total."
136
+ };
137
+ }
138
+ function F(e, n) {
139
+ let t = 0;
140
+ for (const r of e) {
141
+ const o = n(r.field);
142
+ if (o == null) return null;
143
+ t += r.sign * o;
144
+ }
145
+ return Math.round(t * 1e6) / 1e6;
146
+ }
147
+ function L(e, n, t) {
148
+ var i;
149
+ const r = ((i = g.find((l) => l.fn === e)) == null ? void 0 : i.label.toLowerCase()) ?? e, o = t == null ? "all matching records" : `all ${t.toLocaleString("en-US")} matching records`;
150
+ return e === "count" ? `Records with ${n} filled in, across ${o}` : `${r.charAt(0).toUpperCase()}${r.slice(1)} of ${n} across ${o}`;
55
151
  }
56
152
  export {
57
- u as TOTAL_FNS,
58
- b as formatTotal,
59
- f as isTotalFn,
60
- S as loadRememberedTotals,
61
- h as readTotal,
62
- p as rememberTotals,
63
- y as totalTip,
64
- m as totalsEligibleKey,
65
- g as totalsParams
153
+ g as TOTAL_FNS,
154
+ F as combineTerms,
155
+ $ as formatTotal,
156
+ h as isStoredField,
157
+ b as isTotalFn,
158
+ O as linearSumTerms,
159
+ k as loadTotalOverrides,
160
+ y as loadTotalOverridesAt,
161
+ Z as overridesAfterSave,
162
+ M as readTotal,
163
+ z as rememberTotalOverrides,
164
+ T as rememberTotalOverridesAt,
165
+ N as setOverride,
166
+ j as shownTotals,
167
+ L as totalTip,
168
+ v as totalsEligibleKey,
169
+ w as totalsParams,
170
+ C as totalsSupport
66
171
  };