@nivaro/react 0.3.68 → 0.3.69

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,94 @@
1
+ import { jsxs as i, jsx as r } from "react/jsx-runtime";
2
+ import { useQuery as u } from "@tanstack/react-query";
3
+ import { Users as p } from "lucide-react";
4
+ import { useId as h } from "react";
5
+ import { useNivaroClient as x, useItemEditAuth as f } from "../../context.js";
6
+ import { get as w } from "../../lib/commands.js";
7
+ import { formatRelative as g, formatDateTime as b } from "../../lib/utils.js";
8
+ import { Popover as $, PopoverTrigger as k, PopoverContent as y } from "../ui/popover.js";
9
+ function S(t, o, l, n) {
10
+ const a = x(), { isAdmin: e } = f(), d = [...new Set(l.filter(Boolean))].sort(), s = o != null ? String(o) : "", m = e && n && !!t && !!s && s !== "new" && d.length > 0;
11
+ return u({
12
+ queryKey: ["file-download-stats", t, s, ...d],
13
+ queryFn: () => a.request(
14
+ w("/file-downloads/on-record", { collection: t, item: s, ids: d.join(",") })
15
+ ).then((c) => c.data ?? {}),
16
+ enabled: m,
17
+ staleTime: 6e4,
18
+ retry: !1
19
+ });
20
+ }
21
+ function N(t) {
22
+ if (!t || t.count === 0) return "Not downloaded from this record yet";
23
+ const o = `Downloaded ${t.count} time${t.count === 1 ? "" : "s"}`, l = t.people.slice(0, 4).map((a) => `${a.name} (${a.count})`), n = t.people.length > 4 ? `, +${t.people.length - 4} more` : "";
24
+ return `${o}: ${l.join(", ")}${n}`;
25
+ }
26
+ function A({
27
+ fileId: t,
28
+ stat: o
29
+ }) {
30
+ const l = h(), n = (o == null ? void 0 : o.count) ?? 0;
31
+ if (n === 0) return null;
32
+ const a = N(o);
33
+ return /* @__PURE__ */ i($, { children: [
34
+ /* @__PURE__ */ r(k, { asChild: !0, children: /* @__PURE__ */ i(
35
+ "button",
36
+ {
37
+ type: "button",
38
+ "data-file-downloads-open": t,
39
+ "data-tip": a,
40
+ "aria-label": `${n} download${n === 1 ? "" : "s"}: ${a}`,
41
+ onClick: (e) => e.stopPropagation(),
42
+ className: "inline-flex h-6 shrink-0 items-center gap-1 rounded px-1.5 text-[11px] tabular-nums text-slate-600 transition-colors hover:bg-slate-500/10 hover:text-slate-900 dark:text-slate-300 dark:hover:text-white",
43
+ children: [
44
+ /* @__PURE__ */ r(p, { className: "h-3 w-3", "aria-hidden": "true" }),
45
+ /* @__PURE__ */ r("span", { "data-file-downloads-count": n, children: n })
46
+ ]
47
+ }
48
+ ) }),
49
+ /* @__PURE__ */ i(
50
+ y,
51
+ {
52
+ align: "end",
53
+ "aria-labelledby": l,
54
+ className: "w-[300px] p-2 text-[12px]",
55
+ onClick: (e) => e.stopPropagation(),
56
+ children: [
57
+ /* @__PURE__ */ r(
58
+ "p",
59
+ {
60
+ id: l,
61
+ className: "mb-1 px-1 text-[11px] font-medium text-slate-600 dark:text-slate-300",
62
+ children: "Downloaded from this record"
63
+ }
64
+ ),
65
+ /* @__PURE__ */ r("ul", { className: "max-h-72 space-y-0.5 overflow-y-auto", children: o.people.map((e) => /* @__PURE__ */ i(
66
+ "li",
67
+ {
68
+ "data-file-download-person": e.user,
69
+ className: "flex items-baseline gap-2 rounded px-1 py-1 hover:bg-muted",
70
+ children: [
71
+ /* @__PURE__ */ r("span", { className: "min-w-0 flex-1 truncate text-slate-800 dark:text-foreground", children: e.name }),
72
+ /* @__PURE__ */ r("span", { className: "shrink-0 tabular-nums text-slate-600 dark:text-slate-300", children: e.count === 1 ? "once" : `${e.count} times` }),
73
+ /* @__PURE__ */ r(
74
+ "span",
75
+ {
76
+ className: "shrink-0 text-[11px] text-slate-600 dark:text-slate-300",
77
+ "data-tip": b(e.last),
78
+ children: g(e.last)
79
+ }
80
+ )
81
+ ]
82
+ },
83
+ e.user || e.name
84
+ )) })
85
+ ]
86
+ }
87
+ )
88
+ ] });
89
+ }
90
+ export {
91
+ A as FileDownloadCount,
92
+ N as downloadTip,
93
+ S as useFileDownloadStats
94
+ };