@nivaro/react 0.3.133 → 0.3.134

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.
@@ -0,0 +1,290 @@
1
+ import { jsxs as i, jsx as r } from "react/jsx-runtime";
2
+ import { ChevronsUpDown as v, Check as m, X as N, ArrowUpRight as w, ArrowDownRight as y } from "lucide-react";
3
+ import { createContext as C, useState as $, useContext as f } from "react";
4
+ import { cn as c } from "../../lib/utils.js";
5
+ import { Command as O, CommandInput as S, CommandList as P, CommandEmpty as _, CommandItem as x } from "../ui/command.js";
6
+ import { Popover as E, PopoverTrigger as M, PopoverContent as T } from "../ui/popover.js";
7
+ import { fmtInt as b } from "./url.js";
8
+ const p = C(() => {
9
+ });
10
+ function X({
11
+ cell: e,
12
+ label: t,
13
+ children: l,
14
+ className: a,
15
+ tip: o,
16
+ sort: d
17
+ }) {
18
+ const u = f(p), s = l ?? b((e == null ? void 0 : e.n) ?? 0);
19
+ return !e || e.n === 0 ? /* @__PURE__ */ r(
20
+ "span",
21
+ {
22
+ className: c("tabular-nums", a, "text-slate-400 dark:text-muted-foreground/70"),
23
+ children: s
24
+ }
25
+ ) : /* @__PURE__ */ r(
26
+ "button",
27
+ {
28
+ type: "button",
29
+ "data-da-num": e.n,
30
+ "data-tip": o ?? `Show the ${b(e.n)} ${e.n === 1 ? "row" : "rows"} behind this`,
31
+ onClick: (n) => {
32
+ n.stopPropagation(), u(e, t, d ? { sort: d } : void 0);
33
+ },
34
+ className: c(
35
+ "rounded-sm tabular-nums decoration-slate-300 decoration-dotted underline-offset-[3px] hover:underline hover:decoration-solid focus-visible:outline-none focus-visible:ring-2 focus-visible:ring-nvr-cyan/50 dark:decoration-muted-foreground/40",
36
+ a
37
+ ),
38
+ children: s
39
+ }
40
+ );
41
+ }
42
+ function q({
43
+ title: e,
44
+ hint: t,
45
+ actions: l,
46
+ children: a,
47
+ className: o,
48
+ id: d
49
+ }) {
50
+ return /* @__PURE__ */ i(
51
+ "section",
52
+ {
53
+ "data-da-panel": d,
54
+ "aria-label": e,
55
+ className: c(
56
+ "min-w-0 rounded-lg border border-slate-200 bg-white dark:border-border dark:bg-card",
57
+ o
58
+ ),
59
+ children: [
60
+ /* @__PURE__ */ i("header", { className: "flex flex-wrap items-center gap-x-3 gap-y-1 border-b border-slate-100 px-4 py-2.5 dark:border-border/60", children: [
61
+ /* @__PURE__ */ i("div", { className: "min-w-0 flex-1", children: [
62
+ /* @__PURE__ */ r("h3", { className: "text-[13px] font-semibold text-slate-800 dark:text-slate-100", children: e }),
63
+ t && /* @__PURE__ */ r("p", { className: "mt-0.5 text-[11.5px] leading-snug text-slate-500 dark:text-muted-foreground", children: t })
64
+ ] }),
65
+ l
66
+ ] }),
67
+ a
68
+ ]
69
+ }
70
+ );
71
+ }
72
+ function z({
73
+ cur: e,
74
+ prev: t,
75
+ label: l,
76
+ goodWhen: a = "neutral",
77
+ periodLabel: o
78
+ }) {
79
+ const d = f(p);
80
+ if (t.n === 0 && e === 0) return null;
81
+ const u = t.n === 0 ? null : (e - t.n) / t.n, s = e > t.n, n = e === t.n, h = n || a === "neutral" ? "text-slate-500 dark:text-muted-foreground" : s && a === "up" || !s && a === "down" ? "text-green-700 dark:text-[#9fbf8a]" : "text-red-700 dark:text-[#e08383]", g = s ? w : y, k = u == null ? "new" : n ? "no change" : `${Math.abs(Math.round(u * 100))}%`;
82
+ return /* @__PURE__ */ i(
83
+ "button",
84
+ {
85
+ type: "button",
86
+ "data-da-delta": "",
87
+ "data-tip": `${b(t.n)} in the ${o} — show them`,
88
+ disabled: t.n === 0,
89
+ onClick: () => d(t, `${l} · previous period`),
90
+ className: c(
91
+ "inline-flex items-center gap-0.5 rounded-sm text-[11px] font-medium tabular-nums enabled:hover:underline focus-visible:outline-none focus-visible:ring-2 focus-visible:ring-nvr-cyan/50",
92
+ h
93
+ ),
94
+ children: [
95
+ !n && u != null && /* @__PURE__ */ r(g, { className: "h-3 w-3", "aria-hidden": !0 }),
96
+ k,
97
+ /* @__PURE__ */ i("span", { className: "font-normal text-slate-500 dark:text-muted-foreground", children: [
98
+ " vs ",
99
+ b(t.n)
100
+ ] })
101
+ ]
102
+ }
103
+ );
104
+ }
105
+ function G({
106
+ value: e,
107
+ options: t,
108
+ onChange: l,
109
+ ariaLabel: a,
110
+ prefix: o
111
+ }) {
112
+ return (
113
+ // biome-ignore lint/a11y/useSemanticElements: a toolbar toggle group, not a form fieldset
114
+ /* @__PURE__ */ i(
115
+ "div",
116
+ {
117
+ role: "group",
118
+ "aria-label": a,
119
+ className: "inline-flex shrink-0 items-center rounded-md border border-slate-200 bg-white p-0.5 dark:border-border dark:bg-card",
120
+ children: [
121
+ o && /* @__PURE__ */ r("span", { className: "px-2 text-[12px] text-slate-500 dark:text-muted-foreground", children: o }),
122
+ t.map((d) => /* @__PURE__ */ r(
123
+ "button",
124
+ {
125
+ type: "button",
126
+ "aria-pressed": e === d.value,
127
+ "data-tip": d.tip,
128
+ onClick: () => l(d.value),
129
+ className: c(
130
+ "rounded px-2.5 py-1 text-[12px] font-medium transition-colors focus-visible:outline-none focus-visible:ring-2 focus-visible:ring-nvr-cyan/50",
131
+ e === d.value ? "bg-slate-900 text-white dark:bg-nvr-cyan dark:text-[#172940]" : "text-slate-600 hover:bg-slate-100 dark:text-muted-foreground dark:hover:bg-muted"
132
+ ),
133
+ children: d.label
134
+ },
135
+ String(d.value)
136
+ ))
137
+ ]
138
+ }
139
+ )
140
+ );
141
+ }
142
+ function H({
143
+ label: e,
144
+ value: t,
145
+ options: l,
146
+ onChange: a,
147
+ allLabel: o
148
+ }) {
149
+ const [d, u] = $(!1), s = l.find((n) => n.value === t);
150
+ return /* @__PURE__ */ i("div", { className: "inline-flex shrink-0 items-center", children: [
151
+ /* @__PURE__ */ i(E, { open: d, onOpenChange: u, children: [
152
+ /* @__PURE__ */ r(M, { asChild: !0, children: /* @__PURE__ */ i(
153
+ "button",
154
+ {
155
+ type: "button",
156
+ "data-da-filter": e,
157
+ "aria-label": `${e}: ${(s == null ? void 0 : s.label) ?? t ?? o}`,
158
+ className: c(
159
+ "inline-flex h-8 max-w-[220px] items-center gap-1.5 border px-2.5 text-[12px] focus-visible:outline-none focus-visible:ring-2 focus-visible:ring-nvr-cyan/50",
160
+ t ? "rounded-l-md border-nvr-cyan/60 bg-nvr-cyan/10 text-slate-900 dark:text-foreground" : "rounded-md border-slate-200 bg-white text-slate-600 hover:bg-slate-50 dark:border-border dark:bg-card dark:text-muted-foreground dark:hover:bg-muted"
161
+ ),
162
+ children: [
163
+ /* @__PURE__ */ r("span", { className: "text-slate-500 dark:text-muted-foreground", children: e }),
164
+ /* @__PURE__ */ r("span", { className: "min-w-0 truncate font-medium", children: t ? (s == null ? void 0 : s.label) ?? t : o }),
165
+ /* @__PURE__ */ r(v, { className: "h-3 w-3 shrink-0 opacity-50", "aria-hidden": !0 })
166
+ ]
167
+ }
168
+ ) }),
169
+ /* @__PURE__ */ r(T, { className: "w-[260px] p-0", align: "start", children: /* @__PURE__ */ i(O, { children: [
170
+ /* @__PURE__ */ r(
171
+ S,
172
+ {
173
+ placeholder: `Find a ${e.toLowerCase()}…`,
174
+ className: "h-9 text-[12.5px]"
175
+ }
176
+ ),
177
+ /* @__PURE__ */ i(P, { children: [
178
+ /* @__PURE__ */ r(_, { children: "Nothing matches." }),
179
+ /* @__PURE__ */ i(
180
+ x,
181
+ {
182
+ value: `__all__ ${o}`,
183
+ onSelect: () => {
184
+ a(null), u(!1);
185
+ },
186
+ className: "text-[12.5px]",
187
+ children: [
188
+ /* @__PURE__ */ r(m, { className: c("mr-2 h-3.5 w-3.5", t ? "opacity-0" : "opacity-100") }),
189
+ o
190
+ ]
191
+ }
192
+ ),
193
+ l.map((n) => /* @__PURE__ */ i(
194
+ x,
195
+ {
196
+ value: `${n.label} ${n.value}`,
197
+ onSelect: () => {
198
+ a(n.value), u(!1);
199
+ },
200
+ className: "text-[12.5px]",
201
+ children: [
202
+ /* @__PURE__ */ r(
203
+ m,
204
+ {
205
+ className: c(
206
+ "mr-2 h-3.5 w-3.5",
207
+ t === n.value ? "opacity-100" : "opacity-0"
208
+ )
209
+ }
210
+ ),
211
+ /* @__PURE__ */ r("span", { className: "min-w-0 flex-1 truncate", children: n.label }),
212
+ n.count != null && /* @__PURE__ */ r("span", { className: "ml-2 text-[11px] tabular-nums text-slate-400", children: b(n.count) })
213
+ ]
214
+ },
215
+ n.value
216
+ ))
217
+ ] })
218
+ ] }) })
219
+ ] }),
220
+ t && /* @__PURE__ */ r(
221
+ "button",
222
+ {
223
+ type: "button",
224
+ "aria-label": `Clear the ${e.toLowerCase()} filter`,
225
+ "data-tip": "Clear",
226
+ onClick: () => a(null),
227
+ className: "inline-flex h-8 items-center rounded-r-md border border-l-0 border-nvr-cyan/60 bg-nvr-cyan/10 px-1.5 text-slate-500 hover:text-slate-900 focus-visible:outline-none focus-visible:ring-2 focus-visible:ring-nvr-cyan/50 dark:hover:text-foreground",
228
+ children: /* @__PURE__ */ r(N, { className: "h-3 w-3" })
229
+ }
230
+ )
231
+ ] });
232
+ }
233
+ const D = {
234
+ delivered: "border-green-200 bg-green-50 text-green-800 dark:border-[#9fbf8a]/30 dark:bg-[#9fbf8a]/10 dark:text-[#b9d3a6]",
235
+ failed: "border-red-200 bg-red-50 text-red-800 dark:border-[#e08383]/30 dark:bg-[#e08383]/10 dark:text-[#eaa3a3]",
236
+ deferred: "border-sky-200 bg-sky-50 text-sky-800 dark:border-[#8fa6c9]/30 dark:bg-[#8fa6c9]/10 dark:text-[#b3c4dd]",
237
+ dropped: "border-amber-200 bg-amber-50 text-amber-800 dark:border-[#d4936a]/30 dark:bg-[#d4936a]/10 dark:text-[#e2b192]",
238
+ suppressed: "border-amber-200 bg-amber-50 text-amber-800 dark:border-[#d4936a]/30 dark:bg-[#d4936a]/10 dark:text-[#e2b192]",
239
+ test: "border-violet-200 bg-violet-50 text-violet-800 dark:border-border dark:bg-muted dark:text-muted-foreground"
240
+ }, I = "border-slate-200 bg-slate-50 text-slate-700 dark:border-border dark:bg-muted dark:text-muted-foreground";
241
+ function J({
242
+ outcome: e,
243
+ children: t
244
+ }) {
245
+ return /* @__PURE__ */ r(
246
+ "span",
247
+ {
248
+ "data-da-outcome": e,
249
+ className: c(
250
+ "inline-flex items-center whitespace-nowrap rounded-full border px-2 py-px text-[10.5px] font-medium",
251
+ D[e] ?? I
252
+ ),
253
+ children: t
254
+ }
255
+ );
256
+ }
257
+ function K({
258
+ value: e,
259
+ max: t,
260
+ tone: l = "accent"
261
+ }) {
262
+ const a = t > 0 ? Math.max(e > 0 ? 3 : 0, Math.round(e / t * 100)) : 0;
263
+ return /* @__PURE__ */ r(
264
+ "span",
265
+ {
266
+ className: "block h-1 w-full overflow-hidden rounded-full bg-slate-100 dark:bg-muted",
267
+ "aria-hidden": !0,
268
+ children: /* @__PURE__ */ r(
269
+ "span",
270
+ {
271
+ className: c(
272
+ "block h-full rounded-full",
273
+ l === "bad" ? "bg-red-500/70 dark:bg-[#e08383]/70" : "bg-nvr-cyan/70"
274
+ ),
275
+ style: { width: `${a}%` }
276
+ }
277
+ )
278
+ }
279
+ );
280
+ }
281
+ export {
282
+ z as Delta,
283
+ p as DrillContext,
284
+ H as FilterPicker,
285
+ X as Num,
286
+ J as OutcomeChip,
287
+ q as Panel,
288
+ G as Segmented,
289
+ K as ShareBar
290
+ };
@@ -0,0 +1,105 @@
1
+ import { useState as d, useCallback as l } from "react";
2
+ const f = ["d", "dw", "dp", "dl", "ds", "dby", "leaf"];
3
+ function p(e, t) {
4
+ const [o, n] = d(() => new URLSearchParams()), r = e ?? o, c = l(
5
+ (i, a = {}) => {
6
+ const s = new URLSearchParams(r);
7
+ i(s), t ? t(s, a) : n(s);
8
+ },
9
+ [r, t]
10
+ );
11
+ return [r, c];
12
+ }
13
+ const u = ([e, t]) => `${e}:${t.map(encodeURIComponent).join(",")}`;
14
+ function m(e) {
15
+ const t = e.indexOf(":");
16
+ if (t <= 0) return null;
17
+ try {
18
+ return [
19
+ e.slice(0, t),
20
+ e.slice(t + 1).split(",").map(decodeURIComponent)
21
+ ];
22
+ } catch {
23
+ return null;
24
+ }
25
+ }
26
+ function S(e) {
27
+ const t = e.get("leaf"), o = t == null ? void 0 : t.match(/^([nm]):(\d+)$/), n = o ? { source: o[1], id: Number(o[2]) } : null, r = e.get("d");
28
+ if (r !== "n" && r !== "m" && r !== "x")
29
+ return n ? {
30
+ source: n.source,
31
+ where: [],
32
+ prev: !1,
33
+ label: null,
34
+ sort: "time",
35
+ splitBy: null,
36
+ leaf: n
37
+ } : null;
38
+ const c = e.get("ds");
39
+ return {
40
+ source: r,
41
+ where: e.getAll("dw").map(m).filter((i) => !!i),
42
+ prev: e.get("dp") === "1",
43
+ label: e.get("dl"),
44
+ sort: c === "ttr" || c === "time-asc" ? c : "time",
45
+ splitBy: e.get("dby"),
46
+ leaf: n
47
+ };
48
+ }
49
+ function h(e) {
50
+ for (const t of f) e.delete(t);
51
+ }
52
+ function v(e, t, o) {
53
+ h(e), e.set("d", t.s);
54
+ for (const n of t.w) e.append("dw", u(n));
55
+ t.win === "prev" && e.set("dp", "1"), e.set("dl", o);
56
+ }
57
+ function D(e, t, o) {
58
+ const n = new URLSearchParams();
59
+ n.set("source", t.source), n.set("from", t.prev ? o.prev_from : o.from), n.set("to", t.prev ? o.prev_to : o.to), n.set("asof", o.asof), n.set("acted_hours", String(o.acted_hours));
60
+ for (const r of ["category", "channel", "collection", "sender"]) {
61
+ const c = e.get(r);
62
+ c && n.set(r, c);
63
+ }
64
+ for (const r of t.where) n.append("w", u(r));
65
+ return n;
66
+ }
67
+ const L = (e) => e == null || Number.isNaN(e) ? "–" : e.toLocaleString("en-US"), $ = (e, t) => t > 0 ? `${Math.round(e / t * 100)}%` : "–";
68
+ function w(e) {
69
+ return e == null || Number.isNaN(e) ? "–" : e < 1 ? `${Math.max(1, Math.round(e * 60))}s` : e < 60 ? `${Math.round(e)}m` : e < 1440 ? `${(e / 60).toFixed(1)}h` : `${(e / 1440).toFixed(1)}d`;
70
+ }
71
+ function b(e) {
72
+ if (!e) return "–";
73
+ const t = new Date(e);
74
+ return Number.isNaN(t.getTime()) ? "–" : t.toLocaleString(void 0, {
75
+ month: "short",
76
+ day: "numeric",
77
+ hour: "numeric",
78
+ minute: "2-digit"
79
+ });
80
+ }
81
+ function y(e, t) {
82
+ const o = new Date(e), n = new Date(t), r = { month: "short", day: "numeric" };
83
+ return n.getTime() - o.getTime() <= 2 * 864e5 ? `${o.toLocaleString(void 0, { ...r, hour: "numeric", minute: "2-digit" })} – ${n.toLocaleString(void 0, { ...r, hour: "numeric", minute: "2-digit" })}` : `${o.toLocaleDateString(void 0, r)} – ${n.toLocaleDateString(void 0, r)}`;
84
+ }
85
+ function N(e, t) {
86
+ return t === "hour" ? (/* @__PURE__ */ new Date(`${e}:00:00.000Z`)).toLocaleTimeString(void 0, { hour: "numeric" }) : (/* @__PURE__ */ new Date(`${e}T00:00:00.000Z`)).toLocaleDateString(void 0, { month: "short", day: "numeric", timeZone: "UTC" });
87
+ }
88
+ const U = (e) => e === "(none)" ? "None" : e.replace(/[_-]+/g, " ").replace(/^\w/, (t) => t.toUpperCase());
89
+ export {
90
+ f as DRILL_KEYS,
91
+ N as bucketLabel,
92
+ h as clearDrill,
93
+ m as decodeCond,
94
+ D as drillQuery,
95
+ u as encodeCond,
96
+ L as fmtInt,
97
+ y as fmtRange,
98
+ b as fmtWhen,
99
+ w as mins,
100
+ $ as pct,
101
+ S as readDrill,
102
+ U as titleize,
103
+ p as useParamState,
104
+ v as writeDrill
105
+ };
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@nivaro/react",
3
- "version": "0.3.133",
3
+ "version": "0.3.134",
4
4
  "description": "React hooks and components for Nivaro CMS forms",
5
5
  "type": "module",
6
6
  "main": "./dist/index.js",