@nivaro/react 0.3.94 → 0.3.96

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.
@@ -9,7 +9,7 @@ import { noteReplayEvent as _e, createReplayCheckoutState as De } from "../share
9
9
  import { emitReplayTap as Te, setReplayRecorderMode as N, registerReplayCapture as qe, clipEndOffset as Le, withClipKind as Pe } from "../shared/lib/replay-capture.js";
10
10
  import { instrumentConsole as Ne, instrumentRequests as Fe, redactSecrets as Me } from "../shared/lib/replay-context.js";
11
11
  import { instrumentSocket as Oe } from "../shared/lib/replay-socket.js";
12
- const Ue = "nivaro-react@0.3.94", j = 1e4, We = 150, He = 3e3, Ke = 600, $e = (n) => `nvr_replay_resume${n ? `:${n}` : ""}`, G = () => typeof navigator > "u" || navigator.onLine !== !1;
12
+ const Ue = "nivaro-react@0.3.96", j = 1e4, We = 150, He = 3e3, Ke = 600, $e = (n) => `nvr_replay_resume${n ? `:${n}` : ""}`, G = () => typeof navigator > "u" || navigator.onLine !== !1;
13
13
  function Be(n) {
14
14
  return typeof n.url != "string" || typeof fetch != "function" ? null : (f, a) => {
15
15
  const u = typeof n.getToken == "function" ? n.getToken() : void 0, d = { "Content-Type": "application/json" };
@@ -248,7 +248,7 @@ function mt({
248
248
  subscriptionsPath: ue,
249
249
  rulesPath: me,
250
250
  onNavigate: te,
251
- className: `-mt-1 pb-2 pr-3 ${l ? "pl-[46px]" : "pl-[30px]"}`
251
+ className: `pb-3 pr-3 ${l ? "pl-[46px]" : "pl-[30px]"}`
252
252
  }
253
253
  )
254
254
  ] }, e.id);
@@ -0,0 +1,248 @@
1
+ import { jsx as r, jsxs as o, Fragment as H } from "react/jsx-runtime";
2
+ import { MessageSquare as K, X as O, Check as j, CornerDownLeft as A } from "lucide-react";
3
+ import { useState as p, useRef as k, useEffect as q } from "react";
4
+ import { toast as _ } from "sonner";
5
+ import { htmlToText as B } from "../../lib/sanitize-html.js";
6
+ import { cn as P } from "../../lib/utils.js";
7
+ const U = 3e4, V = 1e4, l = /* @__PURE__ */ new Map(), C = (e) => `nvr-chat-card:${e}`;
8
+ function se(e, s, i) {
9
+ const t = l.get(e.room);
10
+ if (t != null && t.messages.some((c) => c.id === s.id)) return;
11
+ const a = [...(t == null ? void 0 : t.messages) ?? [], s].slice(-3), d = {
12
+ room: { ...e, mentioned: e.mentioned || !!(t != null && t.room.mentioned) },
13
+ messages: a,
14
+ actions: i,
15
+ total: ((t == null ? void 0 : t.total) ?? 0) + 1,
16
+ pinned: (t == null ? void 0 : t.pinned) ?? !1
17
+ };
18
+ l.set(e.room, d), S(e.room);
19
+ }
20
+ function X(e) {
21
+ l.has(e) && (l.delete(e), _.dismiss(C(e)));
22
+ }
23
+ function Y(e) {
24
+ return e.pinned ? Number.POSITIVE_INFINITY : e.room.kind === "dm" || e.room.mentioned ? U : V;
25
+ }
26
+ function S(e) {
27
+ const s = l.get(e);
28
+ s && _.custom(
29
+ () => /* @__PURE__ */ r(
30
+ Q,
31
+ {
32
+ state: s,
33
+ onPin: () => {
34
+ const i = l.get(e);
35
+ !i || i.pinned || (i.pinned = !0, S(e));
36
+ },
37
+ onClose: () => X(e)
38
+ }
39
+ ),
40
+ {
41
+ id: C(e),
42
+ duration: Y(s),
43
+ unstyled: !0,
44
+ // Top right, under the header: clear of the chat composer and the page's
45
+ // own bottom-right toasts (Rob, 2026-11-11).
46
+ position: "top-right",
47
+ onDismiss: () => l.delete(e),
48
+ onAutoClose: () => l.delete(e)
49
+ }
50
+ );
51
+ }
52
+ function z(e) {
53
+ var i, t;
54
+ const s = (e ?? "").trim().split(/\s+/).filter(Boolean);
55
+ return ((((i = s[0]) == null ? void 0 : i[0]) ?? "") + (((t = s[1]) == null ? void 0 : t[0]) ?? "")).toUpperCase() || "?";
56
+ }
57
+ function G(e) {
58
+ return B(String(e ?? "")).replace(/\s+\n/g, `
59
+ `).trim();
60
+ }
61
+ function J(e) {
62
+ const s = new Date(e);
63
+ return Number.isNaN(s.getTime()) ? "" : (Date.now() - s.getTime()) / 1e3 < 60 ? "now" : s.toLocaleTimeString([], { hour: "numeric", minute: "2-digit" });
64
+ }
65
+ function Q({
66
+ state: e,
67
+ onPin: s,
68
+ onClose: i
69
+ }) {
70
+ var N;
71
+ const { room: t, messages: a, actions: d, total: c } = e, f = a[a.length - 1], m = ((N = f.sender_name) == null ? void 0 : N.trim()) || "Someone", h = c - a.length, [u, D] = p(!1), [g, x] = p(""), [E, I] = p(!1), R = k(null), b = k(null), [T, $] = p(!1);
72
+ q(() => {
73
+ const n = b.current;
74
+ n && $(n.scrollHeight > n.clientHeight + 2);
75
+ }, [a.length, u]);
76
+ const M = t.kind === "dm" ? "Direct message" : t.kind === "entity" ? t.label : `#${t.label.replace(/^#/, "")}`, v = () => {
77
+ const n = g.trim();
78
+ n && (d.reply(n), x(""), I(!0), window.setTimeout(i, 1100));
79
+ }, F = (n) => {
80
+ n.key === "Enter" && !n.shiftKey ? (n.preventDefault(), v()) : n.key === "Escape" && (n.preventDefault(), i());
81
+ };
82
+ return /* @__PURE__ */ o(
83
+ "section",
84
+ {
85
+ "data-chat-card": t.room,
86
+ "aria-label": `${c > 1 ? `${c} new messages` : "New message"} from ${m}`,
87
+ onPointerDown: s,
88
+ className: "nvr-chat-card pointer-events-auto mt-7 w-[min(360px,calc(100vw-32px))] overflow-hidden rounded-xl border border-border bg-popover text-popover-foreground shadow-[0_10px_30px_-12px_rgba(15,23,42,0.35),0_2px_6px_-2px_rgba(15,23,42,0.12)]",
89
+ children: [
90
+ /* @__PURE__ */ o("header", { className: "flex items-start gap-3 px-3.5 pb-2 pt-3", children: [
91
+ /* @__PURE__ */ o("span", { className: "relative mt-0.5 shrink-0", children: [
92
+ /* @__PURE__ */ r(
93
+ "span",
94
+ {
95
+ "aria-hidden": !0,
96
+ className: "grid h-9 w-9 place-items-center rounded-full bg-nvr-cyan/15 text-[12.5px] font-semibold text-sky-800 dark:text-nvr-cyan",
97
+ children: z(f.sender_name)
98
+ }
99
+ ),
100
+ /* @__PURE__ */ r(
101
+ "span",
102
+ {
103
+ "aria-hidden": !0,
104
+ className: "absolute -bottom-0.5 -right-0.5 grid h-4 w-4 place-items-center rounded-full bg-nvr-cyan text-white ring-2 ring-popover",
105
+ children: /* @__PURE__ */ r(K, { className: "h-2.5 w-2.5" })
106
+ }
107
+ )
108
+ ] }),
109
+ /* @__PURE__ */ o("div", { className: "min-w-0 flex-1", children: [
110
+ /* @__PURE__ */ o("div", { className: "flex items-baseline gap-2", children: [
111
+ /* @__PURE__ */ r("p", { className: "truncate text-[13.5px] font-semibold leading-tight", children: m }),
112
+ /* @__PURE__ */ r("span", { className: "shrink-0 text-[11px] tabular-nums text-muted-foreground", children: J(f.date_created) })
113
+ ] }),
114
+ /* @__PURE__ */ o("p", { className: "mt-0.5 flex items-center gap-1.5 truncate text-[11.5px] text-muted-foreground", children: [
115
+ /* @__PURE__ */ r("span", { className: "truncate", children: M }),
116
+ t.mentioned && t.kind !== "dm" && /* @__PURE__ */ r("span", { className: "shrink-0 rounded-full bg-amber-100 px-1.5 text-[10.5px] font-medium text-amber-800 dark:bg-amber-500/15 dark:text-amber-300", children: "mentioned you" }),
117
+ c > 1 && /* @__PURE__ */ o("span", { className: "shrink-0 rounded-full bg-muted px-1.5 text-[10.5px] font-medium tabular-nums text-foreground", children: [
118
+ c,
119
+ " new"
120
+ ] })
121
+ ] })
122
+ ] }),
123
+ /* @__PURE__ */ r(
124
+ "button",
125
+ {
126
+ type: "button",
127
+ "aria-label": "Dismiss",
128
+ onClick: i,
129
+ className: "-mr-1 -mt-0.5 rounded-md p-1 text-muted-foreground hover:bg-muted hover:text-foreground focus-visible:outline-none focus-visible:ring-2 focus-visible:ring-nvr-cyan/50",
130
+ children: /* @__PURE__ */ r(O, { className: "h-3.5 w-3.5" })
131
+ }
132
+ )
133
+ ] }),
134
+ /* @__PURE__ */ o("div", { className: "px-3.5", children: [
135
+ h > 0 && /* @__PURE__ */ o("p", { className: "mb-1 text-[11px] text-muted-foreground", children: [
136
+ h,
137
+ " earlier ",
138
+ h === 1 ? "message" : "messages"
139
+ ] }),
140
+ /* @__PURE__ */ r(
141
+ "div",
142
+ {
143
+ ref: b,
144
+ className: P(
145
+ "space-y-1.5 text-[13px] leading-snug",
146
+ u ? "max-h-56 overflow-y-auto overscroll-contain pr-1" : "max-h-[5.6em] overflow-hidden"
147
+ ),
148
+ children: a.map((n, y) => {
149
+ var w;
150
+ const L = t.kind !== "dm" && y > 0 && ((w = a[y - 1]) == null ? void 0 : w.sender) !== n.sender;
151
+ return /* @__PURE__ */ o("p", { className: "whitespace-pre-wrap break-words", children: [
152
+ L && /* @__PURE__ */ o("span", { className: "font-medium text-foreground", children: [
153
+ n.sender_name ?? "Someone",
154
+ ":",
155
+ " "
156
+ ] }),
157
+ G(n.message) || /* @__PURE__ */ r("span", { className: "italic text-muted-foreground", children: "Sent a file" })
158
+ ] }, n.id);
159
+ })
160
+ }
161
+ ),
162
+ (T || u) && /* @__PURE__ */ r(
163
+ "button",
164
+ {
165
+ type: "button",
166
+ onClick: () => {
167
+ s(), D((n) => !n);
168
+ },
169
+ className: "mt-1 text-[11.5px] font-medium text-sky-700 hover:underline focus-visible:outline-none focus-visible:ring-2 focus-visible:ring-nvr-cyan/50 dark:text-nvr-cyan",
170
+ children: u ? "Show less" : "Show more"
171
+ }
172
+ )
173
+ ] }),
174
+ /* @__PURE__ */ r("footer", { className: "mt-2.5 border-t border-border bg-muted/40 px-2.5 py-2", children: E ? /* @__PURE__ */ o(
175
+ "p",
176
+ {
177
+ role: "status",
178
+ className: "flex items-center gap-1.5 px-1 py-1 text-[12.5px] font-medium text-emerald-700 dark:text-emerald-400",
179
+ children: [
180
+ /* @__PURE__ */ r(j, { className: "h-3.5 w-3.5", "aria-hidden": !0 }),
181
+ "Reply sent"
182
+ ]
183
+ }
184
+ ) : /* @__PURE__ */ o("div", { className: "flex items-center gap-1.5", children: [
185
+ /* @__PURE__ */ o("label", { className: "sr-only", htmlFor: `chat-card-reply-${t.room}`, children: [
186
+ "Reply to ",
187
+ m
188
+ ] }),
189
+ /* @__PURE__ */ r(
190
+ "input",
191
+ {
192
+ id: `chat-card-reply-${t.room}`,
193
+ ref: R,
194
+ value: g,
195
+ onChange: (n) => x(n.target.value),
196
+ onFocus: s,
197
+ onKeyDown: F,
198
+ placeholder: t.kind === "dm" ? `Reply to ${m.split(" ")[0]}…` : "Reply…",
199
+ autoComplete: "off",
200
+ className: "h-8 min-w-0 flex-1 rounded-md border border-border bg-background px-2.5 text-[12.5px] placeholder:text-muted-foreground focus-visible:border-nvr-cyan focus-visible:outline-none focus-visible:ring-2 focus-visible:ring-nvr-cyan/30"
201
+ }
202
+ ),
203
+ g.trim() ? /* @__PURE__ */ o(
204
+ "button",
205
+ {
206
+ type: "button",
207
+ onClick: v,
208
+ "aria-label": "Send reply",
209
+ className: "inline-flex h-8 items-center gap-1 rounded-md bg-nvr-cyan px-2.5 text-[12px] font-medium text-white hover:brightness-95 focus-visible:outline-none focus-visible:ring-2 focus-visible:ring-nvr-cyan/50",
210
+ children: [
211
+ /* @__PURE__ */ r(A, { className: "h-3.5 w-3.5", "aria-hidden": !0 }),
212
+ "Send"
213
+ ]
214
+ }
215
+ ) : /* @__PURE__ */ o(H, { children: [
216
+ /* @__PURE__ */ r(
217
+ "button",
218
+ {
219
+ type: "button",
220
+ onClick: () => {
221
+ d.markRead(), i();
222
+ },
223
+ className: "h-8 shrink-0 rounded-md px-2 text-[12px] font-medium text-muted-foreground hover:bg-muted hover:text-foreground focus-visible:outline-none focus-visible:ring-2 focus-visible:ring-nvr-cyan/50",
224
+ children: "Mark read"
225
+ }
226
+ ),
227
+ d.open && /* @__PURE__ */ r(
228
+ "button",
229
+ {
230
+ type: "button",
231
+ onClick: () => {
232
+ var n;
233
+ (n = d.open) == null || n.call(d), i();
234
+ },
235
+ className: "h-8 shrink-0 rounded-md border border-border bg-background px-2.5 text-[12px] font-medium hover:bg-muted focus-visible:outline-none focus-visible:ring-2 focus-visible:ring-nvr-cyan/50",
236
+ children: "Open"
237
+ }
238
+ )
239
+ ] })
240
+ ] }) })
241
+ ]
242
+ }
243
+ );
244
+ }
245
+ export {
246
+ X as dismissChatCard,
247
+ se as showChatMessageCard
248
+ };