@rpcbase/ui 0.260.0 → 0.262.0

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 (261) hide show
  1. package/dist/assets/sha256.worker-BEf4_Y9w.js.map +1 -0
  2. package/dist/components/FilesUploadField/index.d.ts +19 -6
  3. package/dist/components/FilesUploadField/index.d.ts.map +1 -1
  4. package/dist/components/FilesUploadField/sha256.d.ts +5 -0
  5. package/dist/components/FilesUploadField/sha256.d.ts.map +1 -0
  6. package/dist/components/FilesUploadField/sha256.worker.d.ts +4 -0
  7. package/dist/components/FilesUploadField/sha256.worker.d.ts.map +1 -0
  8. package/dist/components/ImagesField/index.d.ts +4 -2
  9. package/dist/components/ImagesField/index.d.ts.map +1 -1
  10. package/dist/index.js +10 -10
  11. package/dist/index298.js +11 -803
  12. package/dist/index298.js.map +1 -1
  13. package/dist/index299.js +865 -28
  14. package/dist/index299.js.map +1 -1
  15. package/dist/index300.js +26 -510
  16. package/dist/index300.js.map +1 -1
  17. package/dist/index301.js +481 -755
  18. package/dist/index301.js.map +1 -1
  19. package/dist/index302.js +786 -7428
  20. package/dist/index302.js.map +1 -1
  21. package/dist/index303.js +7429 -7
  22. package/dist/index303.js.map +1 -1
  23. package/dist/index304.js +6 -12
  24. package/dist/index304.js.map +1 -1
  25. package/dist/index305.js +12 -5
  26. package/dist/index305.js.map +1 -1
  27. package/dist/index306.js +3 -3
  28. package/dist/index306.js.map +1 -1
  29. package/dist/index307.js +5 -469
  30. package/dist/index307.js.map +1 -1
  31. package/dist/index308.js +464 -32
  32. package/dist/index308.js.map +1 -1
  33. package/dist/index309.js +36 -18
  34. package/dist/index309.js.map +1 -1
  35. package/dist/index310.js +17 -28
  36. package/dist/index310.js.map +1 -1
  37. package/dist/index311.js +30 -4
  38. package/dist/index311.js.map +1 -1
  39. package/dist/index312.js +4 -59
  40. package/dist/index312.js.map +1 -1
  41. package/dist/index313.js +59 -9
  42. package/dist/index313.js.map +1 -1
  43. package/dist/index314.js +9 -5
  44. package/dist/index314.js.map +1 -1
  45. package/dist/index315.js +5 -9
  46. package/dist/index315.js.map +1 -1
  47. package/dist/index316.js +9 -12
  48. package/dist/index316.js.map +1 -1
  49. package/dist/index317.js +13 -3
  50. package/dist/index317.js.map +1 -1
  51. package/dist/index318.js +3 -17
  52. package/dist/index318.js.map +1 -1
  53. package/dist/index319.js +14 -23
  54. package/dist/index319.js.map +1 -1
  55. package/dist/index320.js +23 -39
  56. package/dist/index320.js.map +1 -1
  57. package/dist/index321.js +41 -5
  58. package/dist/index321.js.map +1 -1
  59. package/dist/index322.js +5 -25
  60. package/dist/index322.js.map +1 -1
  61. package/dist/index323.js +24 -18
  62. package/dist/index323.js.map +1 -1
  63. package/dist/index324.js +17 -32
  64. package/dist/index324.js.map +1 -1
  65. package/dist/index325.js +34 -5
  66. package/dist/index325.js.map +1 -1
  67. package/dist/index326.js +5 -9
  68. package/dist/index326.js.map +1 -1
  69. package/dist/index327.js +8 -7
  70. package/dist/index327.js.map +1 -1
  71. package/dist/index328.js +8 -9
  72. package/dist/index328.js.map +1 -1
  73. package/dist/index329.js +9 -10
  74. package/dist/index329.js.map +1 -1
  75. package/dist/index330.js +10 -7
  76. package/dist/index330.js.map +1 -1
  77. package/dist/index331.js +7 -75
  78. package/dist/index331.js.map +1 -1
  79. package/dist/index332.js +66 -153
  80. package/dist/index332.js.map +1 -1
  81. package/dist/index333.js +147 -99
  82. package/dist/index333.js.map +1 -1
  83. package/dist/index334.js +113 -13
  84. package/dist/index334.js.map +1 -1
  85. package/dist/index335.js +12 -78
  86. package/dist/index335.js.map +1 -1
  87. package/dist/index336.js +57 -23
  88. package/dist/index336.js.map +1 -1
  89. package/dist/index337.js +45 -12
  90. package/dist/index337.js.map +1 -1
  91. package/dist/index338.js +13 -16
  92. package/dist/index338.js.map +1 -1
  93. package/dist/index339.js +15 -100
  94. package/dist/index339.js.map +1 -1
  95. package/dist/index340.js +95 -50
  96. package/dist/index340.js.map +1 -1
  97. package/dist/index341.js +5 -57
  98. package/dist/index341.js.map +1 -1
  99. package/dist/index342.js +78 -41
  100. package/dist/index342.js.map +1 -1
  101. package/dist/index343.js +58 -100
  102. package/dist/index343.js.map +1 -1
  103. package/dist/index344.js +104 -46
  104. package/dist/index344.js.map +1 -1
  105. package/dist/index345.js +51 -39
  106. package/dist/index345.js.map +1 -1
  107. package/dist/index346.js +42 -142
  108. package/dist/index346.js.map +1 -1
  109. package/dist/index347.js +123 -120
  110. package/dist/index347.js.map +1 -1
  111. package/dist/index348.js +108 -224
  112. package/dist/index348.js.map +1 -1
  113. package/dist/index349.js +174 -158
  114. package/dist/index349.js.map +1 -1
  115. package/dist/index350.js +144 -213
  116. package/dist/index350.js.map +1 -1
  117. package/dist/index351.js +309 -5
  118. package/dist/index351.js.map +1 -1
  119. package/dist/index352.js +5 -6
  120. package/dist/index352.js.map +1 -1
  121. package/dist/index353.js +6 -7
  122. package/dist/index353.js.map +1 -1
  123. package/dist/index354.js +5 -4
  124. package/dist/index354.js.map +1 -1
  125. package/dist/index355.js +4 -4
  126. package/dist/index355.js.map +1 -1
  127. package/dist/index356.js +6 -21
  128. package/dist/index356.js.map +1 -1
  129. package/dist/index357.js +21 -10
  130. package/dist/index357.js.map +1 -1
  131. package/dist/index358.js +10 -128
  132. package/dist/index358.js.map +1 -1
  133. package/dist/index359.js +122 -36
  134. package/dist/index359.js.map +1 -1
  135. package/dist/index360.js +38 -64
  136. package/dist/index360.js.map +1 -1
  137. package/dist/index361.js +66 -115
  138. package/dist/index361.js.map +1 -1
  139. package/dist/index362.js +112 -485
  140. package/dist/index362.js.map +1 -1
  141. package/dist/index363.js +490 -13
  142. package/dist/index363.js.map +1 -1
  143. package/dist/index364.js +13 -4
  144. package/dist/index364.js.map +1 -1
  145. package/dist/index365.js +4 -47
  146. package/dist/index365.js.map +1 -1
  147. package/dist/index366.js +44 -15
  148. package/dist/index366.js.map +1 -1
  149. package/dist/index367.js +19 -5
  150. package/dist/index367.js.map +1 -1
  151. package/dist/index368.js +5 -27
  152. package/dist/index368.js.map +1 -1
  153. package/dist/index369.js +27 -48
  154. package/dist/index369.js.map +1 -1
  155. package/dist/index370.js +46 -27
  156. package/dist/index370.js.map +1 -1
  157. package/dist/index371.js +27 -16
  158. package/dist/index371.js.map +1 -1
  159. package/dist/index372.js +16 -41
  160. package/dist/index372.js.map +1 -1
  161. package/dist/index373.js +42 -14
  162. package/dist/index373.js.map +1 -1
  163. package/dist/index374.js +14 -10
  164. package/dist/index374.js.map +1 -1
  165. package/dist/index375.js +9 -51
  166. package/dist/index375.js.map +1 -1
  167. package/dist/index376.js +53 -43
  168. package/dist/index376.js.map +1 -1
  169. package/dist/index377.js +43 -16
  170. package/dist/index377.js.map +1 -1
  171. package/dist/index378.js +15 -4
  172. package/dist/index378.js.map +1 -1
  173. package/dist/index379.js +4 -4
  174. package/dist/index379.js.map +1 -1
  175. package/dist/index380.js +4 -9
  176. package/dist/index380.js.map +1 -1
  177. package/dist/index381.js +9 -340
  178. package/dist/index381.js.map +1 -1
  179. package/dist/index382.js +339 -4
  180. package/dist/index382.js.map +1 -1
  181. package/dist/index383.js +5 -16
  182. package/dist/index383.js.map +1 -1
  183. package/dist/index384.js +16 -111
  184. package/dist/index384.js.map +1 -1
  185. package/dist/index385.js +109 -19
  186. package/dist/index385.js.map +1 -1
  187. package/dist/index386.js +18 -18
  188. package/dist/index386.js.map +1 -1
  189. package/dist/index387.js +21 -5
  190. package/dist/index387.js.map +1 -1
  191. package/dist/index388.js +5 -20
  192. package/dist/index388.js.map +1 -1
  193. package/dist/index389.js +19 -13
  194. package/dist/index389.js.map +1 -1
  195. package/dist/index390.js +13 -84
  196. package/dist/index390.js.map +1 -1
  197. package/dist/index391.js +84 -7
  198. package/dist/index391.js.map +1 -1
  199. package/dist/index392.js +9 -29
  200. package/dist/index392.js.map +1 -1
  201. package/dist/index393.js +28 -9
  202. package/dist/index393.js.map +1 -1
  203. package/dist/index394.js +9 -5
  204. package/dist/index394.js.map +1 -1
  205. package/dist/index395.js +6 -252
  206. package/dist/index395.js.map +1 -1
  207. package/dist/index396.js +250 -10
  208. package/dist/index396.js.map +1 -1
  209. package/dist/index397.js +11 -10
  210. package/dist/index397.js.map +1 -1
  211. package/dist/index398.js +10 -6
  212. package/dist/index398.js.map +1 -1
  213. package/dist/index399.js +6 -22
  214. package/dist/index399.js.map +1 -1
  215. package/dist/index400.js +21 -21
  216. package/dist/index400.js.map +1 -1
  217. package/dist/index401.js +21 -107
  218. package/dist/index401.js.map +1 -1
  219. package/dist/index402.js +109 -15
  220. package/dist/index402.js.map +1 -1
  221. package/dist/index403.js +15 -12
  222. package/dist/index403.js.map +1 -1
  223. package/dist/index404.js +10 -8
  224. package/dist/index404.js.map +1 -1
  225. package/dist/index405.js +8 -242
  226. package/dist/index405.js.map +1 -1
  227. package/dist/index406.js +238 -25
  228. package/dist/index406.js.map +1 -1
  229. package/dist/index407.js +29 -51
  230. package/dist/index407.js.map +1 -1
  231. package/dist/index408.js +51 -10
  232. package/dist/index408.js.map +1 -1
  233. package/dist/index409.js +11 -128
  234. package/dist/index409.js.map +1 -1
  235. package/dist/index410.js +124 -35
  236. package/dist/index410.js.map +1 -1
  237. package/dist/index411.js +36 -23
  238. package/dist/index411.js.map +1 -1
  239. package/dist/index412.js +26 -11
  240. package/dist/index412.js.map +1 -1
  241. package/dist/index413.js +11 -23
  242. package/dist/index413.js.map +1 -1
  243. package/dist/index414.js +19 -13
  244. package/dist/index414.js.map +1 -1
  245. package/dist/index415.js +14 -13
  246. package/dist/index415.js.map +1 -1
  247. package/dist/index416.js +14 -322
  248. package/dist/index416.js.map +1 -1
  249. package/dist/index417.js +323 -61
  250. package/dist/index417.js.map +1 -1
  251. package/dist/index418.js +63 -4
  252. package/dist/index418.js.map +1 -1
  253. package/dist/index419.js +4 -28
  254. package/dist/index419.js.map +1 -1
  255. package/dist/index420.js +25 -468
  256. package/dist/index420.js.map +1 -1
  257. package/dist/index421.js +452 -250
  258. package/dist/index421.js.map +1 -1
  259. package/dist/index422.js +272 -0
  260. package/dist/index422.js.map +1 -0
  261. package/package.json +2 -1
package/dist/index421.js CHANGED
@@ -1,272 +1,474 @@
1
1
  import { cn as e } from "./index12.js";
2
- import { useEffect as t, useMemo as n, useState as r } from "react";
3
- import { Loader2 as i } from "lucide-react";
4
- import { jsx as a, jsxs as o } from "react/jsx-runtime";
5
- //#region src/components/Notifications/NotificationsSettings.tsx
6
- var s = [
7
- {
8
- value: "off",
9
- label: "Off"
10
- },
11
- {
12
- value: "daily",
13
- label: "Daily"
14
- },
15
- {
16
- value: "weekly",
17
- label: "Weekly"
2
+ import { DialogBackdrop as t } from "./index199.js";
3
+ import { DialogClose as n } from "./index210.js";
4
+ import { DialogPopup as r } from "./index280.js";
5
+ import { DialogPortal as i } from "./index283.js";
6
+ import { DialogRoot as a } from "./index288.js";
7
+ import { DialogTitle as o } from "./index289.js";
8
+ import { c as s } from "react/compiler-runtime";
9
+ import { createContext as c, useCallback as l, useContext as u, useEffect as d, useMemo as f, useRef as p, useState as m } from "react";
10
+ import { Loader2 as h, MoreVertical as g, X as _ } from "lucide-react";
11
+ import { jsx as v, jsxs as y } from "react/jsx-runtime";
12
+ //#region src/components/Notifications/NotificationsDrawer.tsx
13
+ var b = (e) => {
14
+ let t = Date.parse(e);
15
+ return Number.isFinite(t) ? t : 0;
16
+ }, x = (e) => {
17
+ let t = new Date(b(e));
18
+ return Number.isFinite(t.getTime()) ? `${t.getFullYear()}-${String(t.getMonth() + 1).padStart(2, "0")}-${String(t.getDate()).padStart(2, "0")}` : "unknown";
19
+ }, S = (e) => {
20
+ if (e === "unknown") return "Unknown date";
21
+ let [t, n, r] = e.split("-"), i = Number(t), a = Number(n), o = Number(r);
22
+ if (!Number.isFinite(i) || !Number.isFinite(a) || !Number.isFinite(o)) return "Unknown date";
23
+ let s = new Date(i, a - 1, o);
24
+ if (!Number.isFinite(s.getTime())) return "Unknown date";
25
+ let c = (/* @__PURE__ */ new Date()).getFullYear() !== i;
26
+ return s.toLocaleDateString(void 0, c ? {
27
+ weekday: "short",
28
+ month: "short",
29
+ day: "numeric",
30
+ year: "numeric"
31
+ } : {
32
+ weekday: "short",
33
+ month: "short",
34
+ day: "numeric"
35
+ });
36
+ }, C = (e) => {
37
+ let t = e.data?.link?.trim();
38
+ if (t) return t;
39
+ let n = e.platform?.webpush;
40
+ if (!n || typeof n != "object" || Array.isArray(n)) return "";
41
+ let r = n.fcmOptions;
42
+ if (!r || typeof r != "object" || Array.isArray(r)) return "";
43
+ let i = r.link;
44
+ return typeof i == "string" ? i.trim() : "";
45
+ }, w = (e) => e.data?.linkMode === "merge_current_search" ? "merge_current_search" : "navigate", T = (e) => {
46
+ let t = C(e);
47
+ return t ? {
48
+ link: t,
49
+ mode: w(e)
50
+ } : null;
51
+ }, E = (e) => e ? e.mode === "merge_current_search" ? "Open" : e.link : "", D = (e) => {
52
+ window.history.pushState(window.history.state, "", e), window.dispatchEvent(new PopStateEvent("popstate", { state: window.history.state }));
53
+ }, O = (e) => {
54
+ if (e.mode === "merge_current_search") {
55
+ let t = new URL(window.location.href), n = new URL(e.link, t);
56
+ n.searchParams.forEach((e, n) => {
57
+ t.searchParams.set(n, e);
58
+ }), n.hash && (t.hash = n.hash), D(`${t.pathname}${t.search}${t.hash}`);
59
+ return;
18
60
  }
19
- ], c = (e) => {
20
- let t = e?.digestFrequency;
21
- return {
22
- digestFrequency: t === "off" || t === "daily" || t === "weekly" ? t : "weekly",
23
- topicPreferences: Array.isArray(e?.topicPreferences) ? e.topicPreferences.map((e) => ({
24
- topic: typeof e.topic == "string" ? e.topic.trim() : "",
25
- inApp: e.inApp === !0,
26
- emailDigest: e.emailDigest === !0,
27
- push: e.push === !0
28
- })).filter((e) => e.topic.length > 0) : [],
29
- ...typeof e?.lastDigestSentAt == "string" ? { lastDigestSentAt: e.lastDigestSentAt } : {}
30
- };
31
- }, l = (e) => {
32
- if (!Array.isArray(e)) return [];
33
- let t = /* @__PURE__ */ new Set();
34
- return e.map((e) => ({
35
- topic: typeof e.topic == "string" ? e.topic.trim() : "",
36
- title: typeof e.title == "string" ? e.title.trim() : "",
37
- description: typeof e.description == "string" ? e.description.trim() : void 0
38
- })).filter((e) => e.topic.length > 0).filter((e) => t.has(e.topic) ? !1 : (t.add(e.topic), !0));
39
- }, u = (e, t) => {
40
- let n = {
41
- topic: "",
42
- inApp: !0,
43
- emailDigest: !0,
44
- push: !1
45
- }, r = new Map(e.topicPreferences.map((e) => [e.topic, e]));
46
- return {
47
- ...e,
48
- topicPreferences: t.map((e) => {
49
- let t = r.get(e.topic);
50
- return t ? {
51
- topic: e.topic,
52
- inApp: t.inApp === !0,
53
- emailDigest: t.emailDigest === !0,
54
- push: t.push === !0
55
- } : {
56
- ...n,
57
- topic: e.topic
58
- };
59
- })
60
- };
61
- };
62
- function d({ className: d, topics: f }) {
63
- let [p, m] = r(!0), [h, g] = r(!1), [_, v] = r(null), [y, b] = r(() => c({
64
- digestFrequency: "weekly",
65
- topicPreferences: []
66
- })), x = n(() => l(f), [f]), S = async () => {
67
- m(!0), v(null);
61
+ window.location.href = e.link;
62
+ }, k = (e) => {
63
+ let t = [], n = null;
64
+ for (let r of e) {
65
+ let e = x(r.createdAt);
66
+ e !== n && (n = e, t.push({
67
+ key: e,
68
+ label: S(e),
69
+ items: []
70
+ })), t[t.length - 1].items.push(r);
71
+ }
72
+ return t;
73
+ }, A = () => typeof window > "u" || !("Notification" in window) ? "unsupported" : window.Notification.permission, j = c(null);
74
+ function M({ open: s, onOpenChange: c, className: p, limit: g = 50, defaultUnreadOnly: b = !1, realtimeContext: x }) {
75
+ let S = u(x ?? j), [C, w] = m([]), [T, E] = m(0), [D, O] = m(0), [M, F] = m(!1), [I, L] = m(null), [R, z] = m(b), [B, V] = m(() => A()), [H, U] = m(!1), W = S?.notifications ?? C, G = S?.unreadCount ?? T, K = S?.unseenCount ?? D, ee = S?.loading ?? M, q = S?.error ? S.error instanceof Error ? S.error.message : String(S.error) : I, J = f(() => W.slice(0, g), [g, W]), Y = f(() => J.filter((e) => !e.readAt), [J]), X = f(() => J.filter((e) => !!e.readAt), [J]), Z = f(() => k(Y), [Y]), te = f(() => k(X), [X]), Q = l(async ({ unreadOnly: e, markSeen: t }) => {
76
+ F(!0), L(null);
68
77
  try {
69
- let e = await fetch("/api/rb/notifications/settings", {
70
- method: "GET",
71
- credentials: "include"
72
- }), t = await e.json().catch(() => null);
73
- if (!e.ok || !t?.ok) {
74
- v(t?.error || "Unable to load notification settings.");
78
+ let n = await fetch("/api/rb/notifications", {
79
+ method: "POST",
80
+ headers: { "Content-Type": "application/json" },
81
+ credentials: "include",
82
+ body: JSON.stringify({
83
+ limit: g,
84
+ unreadOnly: e,
85
+ markSeen: t
86
+ })
87
+ }), r = await n.json().catch(() => null);
88
+ if (!n.ok || !r?.ok) {
89
+ L(r?.error || "Unable to load notifications.");
90
+ return;
91
+ }
92
+ let i = Array.isArray(r.notifications) ? r.notifications : [];
93
+ w(i), E(Number.isFinite(r.unreadCount) ? Math.max(0, Math.floor(r.unreadCount ?? 0)) : 0), O(Number.isFinite(r.unseenCount) ? Math.max(0, Math.floor(r.unseenCount ?? 0)) : 0);
94
+ } catch {
95
+ L("Unable to load notifications.");
96
+ } finally {
97
+ F(!1);
98
+ }
99
+ }, [g]);
100
+ d(() => {
101
+ if (s) {
102
+ if (S) {
103
+ (async () => {
104
+ try {
105
+ await fetch("/api/rb/notifications", {
106
+ method: "POST",
107
+ headers: { "Content-Type": "application/json" },
108
+ credentials: "include",
109
+ keepalive: !0,
110
+ body: JSON.stringify({
111
+ limit: 1,
112
+ markSeen: !0
113
+ })
114
+ });
115
+ } catch {
116
+ return;
117
+ }
118
+ })();
75
119
  return;
76
120
  }
77
- let n = c(t.settings);
78
- b(x.length > 0 ? u(n, x) : n);
121
+ Q({
122
+ unreadOnly: R,
123
+ markSeen: !0
124
+ });
125
+ }
126
+ }, [
127
+ s,
128
+ S,
129
+ Q,
130
+ R
131
+ ]), d(() => {
132
+ s && (S || Q({
133
+ unreadOnly: R,
134
+ markSeen: !1
135
+ }));
136
+ }, [
137
+ s,
138
+ S,
139
+ Q,
140
+ R
141
+ ]), d(() => {
142
+ if (!s || (V(A()), typeof navigator > "u" || !navigator.permissions?.query)) return;
143
+ let e = null, t = !1, n = () => {
144
+ V(A());
145
+ };
146
+ try {
147
+ navigator.permissions.query({ name: "notifications" }).then((r) => {
148
+ t || (e = r, n(), r.addEventListener("change", n));
149
+ }).catch(() => {});
150
+ } catch {
151
+ return;
152
+ }
153
+ return () => {
154
+ t = !0, e?.removeEventListener("change", n);
155
+ };
156
+ }, [s]);
157
+ let ne = async () => {
158
+ if (typeof window > "u" || !("Notification" in window)) {
159
+ V("unsupported");
160
+ return;
161
+ }
162
+ U(!0);
163
+ try {
164
+ let e = await window.Notification.requestPermission();
165
+ V(e);
79
166
  } catch {
80
- v("Unable to load notification settings.");
167
+ V(A());
81
168
  } finally {
82
- m(!1);
169
+ U(!1);
83
170
  }
84
- }, C = async (e) => {
85
- g(!0), v(null);
171
+ }, re = async (e) => {
86
172
  try {
87
- let t = await fetch("/api/rb/notifications/settings", {
88
- method: "PUT",
173
+ let t = await fetch(`/api/rb/notifications/${encodeURIComponent(e)}/read`, {
174
+ method: "POST",
89
175
  headers: { "Content-Type": "application/json" },
90
176
  credentials: "include",
91
- body: JSON.stringify({
92
- digestFrequency: e.digestFrequency,
93
- topicPreferences: e.topicPreferences
94
- })
177
+ keepalive: !0,
178
+ body: "{}"
95
179
  }), n = await t.json().catch(() => null);
96
- if (!t.ok || !n?.ok) {
97
- v(n?.error || "Unable to save notification settings.");
98
- return;
99
- }
100
- let r = c(n.settings);
101
- b(x.length > 0 ? u(r, x) : r);
180
+ if (!t.ok || !n?.ok) return;
181
+ let r = (/* @__PURE__ */ new Date()).toISOString();
182
+ if (S) return;
183
+ w((t) => {
184
+ let n = t.find((t) => t.id === e);
185
+ return n && !n.readAt && E((e) => Math.max(0, e - 1)), n && !n.seenAt && O((e) => Math.max(0, e - 1)), t.map((t) => t.id === e && !t.readAt ? {
186
+ ...t,
187
+ readAt: r,
188
+ ...t.seenAt ? {} : { seenAt: r }
189
+ } : t);
190
+ });
102
191
  } catch {
103
- v("Unable to save notification settings.");
104
- } finally {
105
- g(!1);
192
+ return;
106
193
  }
194
+ }, ie = async (e) => {
195
+ try {
196
+ let t = await fetch(`/api/rb/notifications/${encodeURIComponent(e)}/archive`, {
197
+ method: "POST",
198
+ headers: { "Content-Type": "application/json" },
199
+ credentials: "include",
200
+ body: "{}"
201
+ }), n = await t.json().catch(() => null);
202
+ if (!t.ok || !n?.ok || S) return;
203
+ w((t) => {
204
+ let n = t.find((t) => t.id === e);
205
+ return n && !n.readAt && E((e) => Math.max(0, e - 1)), n && !n.seenAt && O((e) => Math.max(0, e - 1)), t.filter((t) => t.id !== e);
206
+ });
207
+ } catch {
208
+ return;
209
+ }
210
+ }, $ = () => {
211
+ c(!1);
107
212
  };
108
- t(() => {
109
- S();
110
- }, []), t(() => {
111
- x.length !== 0 && b((e) => u(e, x));
112
- }, [x]);
113
- let w = (e, t) => {
114
- let n = y.topicPreferences.some((t) => t.topic === e) ? y.topicPreferences.map((n) => n.topic === e ? t(n) : n) : [...y.topicPreferences, t({
115
- topic: e,
116
- inApp: !0,
117
- emailDigest: !0,
118
- push: !1
119
- })], r = c({
120
- ...y,
121
- topicPreferences: n
122
- });
123
- b(r), C(r);
124
- };
125
- return p ? /* @__PURE__ */ a("div", {
126
- className: e("flex items-center justify-center py-10 text-muted-foreground", d),
127
- children: /* @__PURE__ */ a(i, { className: "h-4 w-4 animate-spin" })
128
- }) : /* @__PURE__ */ o("div", {
129
- className: e("space-y-4", d),
130
- children: [/* @__PURE__ */ a("div", {
131
- className: "rounded-md border bg-background p-4",
132
- children: /* @__PURE__ */ o("div", {
133
- className: "flex items-start justify-between gap-3",
134
- children: [/* @__PURE__ */ o("div", { children: [/* @__PURE__ */ a("div", {
135
- className: "text-sm font-semibold",
136
- children: "Email digest"
137
- }), /* @__PURE__ */ a("div", {
138
- className: "mt-1 text-xs text-muted-foreground",
139
- children: "Choose how often we email you a summary."
140
- })] }), /* @__PURE__ */ a("select", {
141
- value: y.digestFrequency,
142
- onChange: (e) => {
143
- let t = e.target.value, n = c({
144
- ...y,
145
- digestFrequency: t
146
- });
147
- b(n), C(n);
148
- },
149
- className: "h-9 rounded-md border bg-background px-2 text-sm",
150
- children: s.map((e) => /* @__PURE__ */ a("option", {
151
- value: e.value,
213
+ return /* @__PURE__ */ v(a, {
214
+ open: s,
215
+ onOpenChange: (e) => {
216
+ if (e) {
217
+ c(!0);
218
+ return;
219
+ }
220
+ $();
221
+ },
222
+ children: /* @__PURE__ */ y(i, { children: [/* @__PURE__ */ v(t, {
223
+ className: "fixed inset-0 z-50 bg-black/50",
224
+ onClick: $
225
+ }), /* @__PURE__ */ y(r, {
226
+ className: e("fixed right-0 top-0 z-50 flex h-full w-full max-w-md flex-col border-l bg-background shadow-xl outline-none", p),
227
+ children: [/* @__PURE__ */ y("header", {
228
+ className: "flex items-center justify-between gap-2 border-b px-4 py-3",
229
+ children: [/* @__PURE__ */ y("div", {
230
+ className: "flex min-w-0 flex-col",
231
+ children: [/* @__PURE__ */ v(o, {
232
+ className: "text-sm font-semibold",
233
+ children: "Notifications"
234
+ }), /* @__PURE__ */ v("span", {
235
+ className: "text-xs text-muted-foreground",
236
+ children: G > 0 ? `${G} unread` : K > 0 ? `${K} new` : "All caught up"
237
+ })]
238
+ }), /* @__PURE__ */ y("div", {
239
+ className: "flex items-center gap-2",
240
+ children: [/* @__PURE__ */ v("button", {
241
+ type: "button",
242
+ onClick: () => z((e) => !e),
243
+ className: e("rounded-md border px-2 py-1 text-xs", R ? "bg-accent text-foreground" : "bg-background text-muted-foreground hover:bg-accent"),
244
+ children: R ? "Unread" : "All"
245
+ }), /* @__PURE__ */ v(n, {
246
+ type: "button",
247
+ "aria-label": "Close notifications",
248
+ className: "inline-flex h-8 w-8 items-center justify-center rounded-md hover:bg-accent",
249
+ onClick: $,
250
+ children: /* @__PURE__ */ v(_, { className: "h-4 w-4" })
251
+ })]
252
+ })]
253
+ }), /* @__PURE__ */ y("div", {
254
+ className: "flex-1 overflow-y-auto px-4 pb-3",
255
+ children: [/* @__PURE__ */ v(N, {
256
+ permission: B,
257
+ requesting: H,
258
+ onEnable: ne
259
+ }), ee ? /* @__PURE__ */ v("div", {
260
+ className: "flex items-center justify-center py-10 text-muted-foreground",
261
+ children: /* @__PURE__ */ v(h, { className: "h-4 w-4 animate-spin" })
262
+ }) : q ? /* @__PURE__ */ v("div", {
263
+ className: "py-10 text-center text-sm text-muted-foreground",
264
+ children: q
265
+ }) : J.length === 0 ? /* @__PURE__ */ v("div", {
266
+ className: "py-10 text-center text-sm text-muted-foreground",
267
+ children: "No notifications."
268
+ }) : /* @__PURE__ */ y("div", {
269
+ className: "flex flex-col gap-4",
270
+ children: [/* @__PURE__ */ y("div", { children: [/* @__PURE__ */ v("div", {
271
+ className: "sticky top-0 z-20 -mx-4 flex h-8 items-center border-b bg-background px-4 text-xs font-semibold text-muted-foreground",
272
+ children: "Unread notifications"
273
+ }), Z.length === 0 ? /* @__PURE__ */ v("div", {
274
+ className: "py-6 text-center text-sm text-muted-foreground",
275
+ children: "No unread notifications."
276
+ }) : Z.map((e) => /* @__PURE__ */ y("div", { children: [/* @__PURE__ */ v("div", {
277
+ className: "sticky top-8 z-10 -mx-4 flex h-7 items-center bg-background px-4 text-[11px] font-semibold text-muted-foreground",
278
+ children: e.label
279
+ }), /* @__PURE__ */ v("div", {
280
+ className: "-mx-4 flex flex-col divide-y divide-border",
281
+ children: e.items.map((e) => /* @__PURE__ */ v(P, {
282
+ notification: e,
283
+ onMarkRead: re,
284
+ onArchive: ie,
285
+ onAction: $
286
+ }, e.id))
287
+ })] }, `unread:${e.key}`))] }), R ? null : /* @__PURE__ */ y("div", { children: [/* @__PURE__ */ v("div", {
288
+ className: "sticky top-0 z-20 -mx-4 flex h-8 items-center border-b bg-background px-4 text-xs font-semibold text-muted-foreground",
289
+ children: "Previous notifications"
290
+ }), te.length === 0 ? /* @__PURE__ */ v("div", {
291
+ className: "py-6 text-center text-sm text-muted-foreground",
292
+ children: "No previous notifications."
293
+ }) : te.map((e) => /* @__PURE__ */ y("div", { children: [/* @__PURE__ */ v("div", {
294
+ className: "sticky top-8 z-10 -mx-4 flex h-7 items-center bg-background px-4 text-[11px] font-semibold text-muted-foreground",
152
295
  children: e.label
153
- }, e.value))
296
+ }), /* @__PURE__ */ v("div", {
297
+ className: "-mx-4 flex flex-col divide-y divide-border",
298
+ children: e.items.map((e) => /* @__PURE__ */ v(P, {
299
+ notification: e,
300
+ onMarkRead: re,
301
+ onArchive: ie,
302
+ onAction: $
303
+ }, e.id))
304
+ })] }, `previous:${e.key}`))] })]
154
305
  })]
155
- })
156
- }), /* @__PURE__ */ o("div", {
157
- className: "rounded-md border bg-background p-4",
158
- children: [
159
- /* @__PURE__ */ a("div", {
160
- className: "flex items-start justify-between gap-3",
161
- children: /* @__PURE__ */ o("div", { children: [/* @__PURE__ */ a("div", {
162
- className: "text-sm font-semibold",
163
- children: "Topics"
164
- }), /* @__PURE__ */ a("div", {
165
- className: "mt-1 text-xs text-muted-foreground",
166
- children: "Choose where you receive each topic."
167
- })] })
168
- }),
169
- x.length === 0 ? /* @__PURE__ */ a("div", {
170
- className: "mt-4 text-sm text-muted-foreground",
171
- children: "No topics configured."
172
- }) : /* @__PURE__ */ a("div", {
173
- className: "mt-4 overflow-x-auto",
174
- children: /* @__PURE__ */ o("table", {
175
- className: "w-full text-sm",
176
- children: [/* @__PURE__ */ a("thead", { children: /* @__PURE__ */ o("tr", {
177
- className: "text-left text-xs text-muted-foreground",
178
- children: [
179
- /* @__PURE__ */ a("th", {
180
- className: "py-2 pr-4 font-medium",
181
- children: "Topic"
182
- }),
183
- /* @__PURE__ */ a("th", {
184
- className: "py-2 pr-4 font-medium",
185
- children: "In-app"
186
- }),
187
- /* @__PURE__ */ a("th", {
188
- className: "py-2 pr-4 font-medium",
189
- children: "Email digest"
190
- }),
191
- /* @__PURE__ */ a("th", {
192
- className: "py-2 pr-4 font-medium",
193
- children: "Push"
194
- })
195
- ]
196
- }) }), /* @__PURE__ */ a("tbody", { children: y.topicPreferences.map((e) => {
197
- let t = x.find((t) => t.topic === e.topic);
198
- return /* @__PURE__ */ o("tr", {
199
- className: "border-t align-top",
200
- children: [
201
- /* @__PURE__ */ a("td", {
202
- className: "py-3 pr-4",
203
- children: /* @__PURE__ */ o("div", {
204
- className: "flex flex-col gap-1",
205
- children: [
206
- /* @__PURE__ */ a("span", {
207
- className: "font-medium",
208
- children: t?.title || e.topic
209
- }),
210
- t?.description ? /* @__PURE__ */ a("span", {
211
- className: "text-xs text-muted-foreground",
212
- children: t.description
213
- }) : null,
214
- /* @__PURE__ */ a("span", {
215
- className: "text-[11px] text-muted-foreground",
216
- children: e.topic
217
- })
218
- ]
219
- })
220
- }),
221
- /* @__PURE__ */ a("td", {
222
- className: "py-3 pr-4",
223
- children: /* @__PURE__ */ a("input", {
224
- type: "checkbox",
225
- checked: e.inApp,
226
- onChange: (t) => w(e.topic, (e) => ({
227
- ...e,
228
- inApp: t.target.checked
229
- }))
230
- })
231
- }),
232
- /* @__PURE__ */ a("td", {
233
- className: "py-3 pr-4",
234
- children: /* @__PURE__ */ a("input", {
235
- type: "checkbox",
236
- checked: e.emailDigest,
237
- onChange: (t) => w(e.topic, (e) => ({
238
- ...e,
239
- emailDigest: t.target.checked
240
- }))
241
- })
242
- }),
243
- /* @__PURE__ */ a("td", {
244
- className: "py-3 pr-4",
245
- children: /* @__PURE__ */ a("input", {
246
- type: "checkbox",
247
- checked: e.push,
248
- disabled: !0,
249
- className: "opacity-50",
250
- "aria-label": "Push notifications (coming soon)"
251
- })
252
- })
253
- ]
254
- }, e.topic);
255
- }) })]
256
- })
257
- }),
258
- _ ? /* @__PURE__ */ a("div", {
259
- className: "mt-3 text-sm text-destructive",
260
- children: _
261
- }) : h ? /* @__PURE__ */ a("div", {
262
- className: "mt-3 text-xs text-muted-foreground",
263
- children: "Saving…"
264
- }) : null
265
- ]
266
- })]
306
+ })]
307
+ })] })
267
308
  });
268
309
  }
310
+ function N(e) {
311
+ let t = s(13), { permission: n, requesting: r, onEnable: i } = e;
312
+ if (n === "granted") return null;
313
+ if (n === "unsupported") {
314
+ let e;
315
+ return t[0] === Symbol.for("react.memo_cache_sentinel") ? (e = /* @__PURE__ */ v("div", {
316
+ className: "mt-3 rounded-md border bg-muted/40 p-3 text-sm text-muted-foreground",
317
+ children: "Browser notifications are not supported by this browser."
318
+ }), t[0] = e) : e = t[0], e;
319
+ }
320
+ let a = n === "denied", o = a ? "Browser notifications are blocked." : "Browser notifications are not enabled.", c;
321
+ t[1] === o ? c = t[2] : (c = /* @__PURE__ */ v("div", {
322
+ className: "text-sm font-medium",
323
+ children: o
324
+ }), t[1] = o, t[2] = c);
325
+ let l = a ? "Enable notifications for this site in your browser settings, then click again." : "Enable browser notifications to receive important alerts.", u;
326
+ t[3] === l ? u = t[4] : (u = /* @__PURE__ */ v("div", {
327
+ className: "mt-1 text-xs text-muted-foreground",
328
+ children: l
329
+ }), t[3] = l, t[4] = u);
330
+ let d = r ? "Enabling..." : "Enable browser notifications", f;
331
+ t[5] !== i || t[6] !== r || t[7] !== d ? (f = /* @__PURE__ */ v("button", {
332
+ type: "button",
333
+ className: "mt-3 inline-flex h-8 items-center rounded-md border bg-background px-2.5 text-xs font-medium hover:bg-accent disabled:pointer-events-none disabled:opacity-50",
334
+ disabled: r,
335
+ onClick: i,
336
+ children: d
337
+ }), t[5] = i, t[6] = r, t[7] = d, t[8] = f) : f = t[8];
338
+ let p;
339
+ return t[9] !== c || t[10] !== u || t[11] !== f ? (p = /* @__PURE__ */ y("div", {
340
+ className: "mt-3 rounded-md border bg-muted/40 p-3",
341
+ children: [
342
+ c,
343
+ u,
344
+ f
345
+ ]
346
+ }), t[9] = c, t[10] = u, t[11] = f, t[12] = p) : p = t[12], p;
347
+ }
348
+ function P(t) {
349
+ let n = s(49), { notification: r, onMarkRead: i, onArchive: a, onAction: o } = t, [c, l] = m(!1), u = p(null), f = p(null), h = !r.readAt, _, x;
350
+ n[0] === r ? (_ = n[1], x = n[2]) : (_ = T(r), x = E(_), n[0] = r, n[1] = _, n[2] = x);
351
+ let S = x, C;
352
+ if (n[3] !== r.createdAt) {
353
+ bb0: {
354
+ let e = new Date(b(r.createdAt));
355
+ if (!Number.isFinite(e.getTime())) {
356
+ C = "";
357
+ break bb0;
358
+ }
359
+ C = e.toLocaleString();
360
+ }
361
+ n[3] = r.createdAt, n[4] = C;
362
+ } else C = n[4];
363
+ let w = C, D, k;
364
+ n[5] === c ? (D = n[6], k = n[7]) : (D = () => {
365
+ if (!c) return;
366
+ let e = (e) => {
367
+ let t = e.target;
368
+ t instanceof Node && (u.current?.contains(t) || f.current?.contains(t) || l(!1));
369
+ }, t = (e) => {
370
+ e.key === "Escape" && (l(!1), f.current?.focus());
371
+ };
372
+ return document.addEventListener("pointerdown", e), document.addEventListener("keydown", t), () => {
373
+ document.removeEventListener("pointerdown", e), document.removeEventListener("keydown", t);
374
+ };
375
+ }, k = [c], n[5] = c, n[6] = D, n[7] = k), d(D, k);
376
+ let A = h ? "bg-primary/5" : "bg-background", j;
377
+ n[8] === A ? j = n[9] : (j = e("group flex w-full gap-3 px-4 py-3 hover:bg-accent/40", A), n[8] = A, n[9] = j);
378
+ let M;
379
+ n[10] !== _ || n[11] !== h || n[12] !== r.id || n[13] !== o || n[14] !== i ? (M = () => {
380
+ h && i(r.id), _ && (o(), O(_));
381
+ }, n[10] = _, n[11] = h, n[12] = r.id, n[13] = o, n[14] = i, n[15] = M) : M = n[15];
382
+ let N;
383
+ n[16] === r.title ? N = n[17] : (N = /* @__PURE__ */ v("div", {
384
+ className: "truncate text-sm font-semibold",
385
+ children: r.title
386
+ }), n[16] = r.title, n[17] = N);
387
+ let P;
388
+ n[18] === r.body ? P = n[19] : (P = r.body ? /* @__PURE__ */ v("div", {
389
+ className: "mt-0.5 line-clamp-2 text-xs text-muted-foreground",
390
+ children: r.body
391
+ }) : null, n[18] = r.body, n[19] = P);
392
+ let I;
393
+ n[20] !== N || n[21] !== P ? (I = /* @__PURE__ */ y("div", {
394
+ className: "min-w-0",
395
+ children: [N, P]
396
+ }), n[20] = N, n[21] = P, n[22] = I) : I = n[22];
397
+ let L;
398
+ n[23] === S ? L = n[24] : (L = S ? /* @__PURE__ */ v("div", {
399
+ className: "mt-2 truncate text-xs text-primary",
400
+ children: S
401
+ }) : null, n[23] = S, n[24] = L);
402
+ let R;
403
+ n[25] === w ? R = n[26] : (R = w ? /* @__PURE__ */ v("div", {
404
+ className: "mt-2 text-[11px] text-muted-foreground",
405
+ children: w
406
+ }) : null, n[25] = w, n[26] = R);
407
+ let z;
408
+ n[27] !== I || n[28] !== L || n[29] !== R || n[30] !== M ? (z = /* @__PURE__ */ y("button", {
409
+ type: "button",
410
+ className: "min-w-0 flex-1 text-left",
411
+ onClick: M,
412
+ children: [
413
+ I,
414
+ L,
415
+ R
416
+ ]
417
+ }), n[27] = I, n[28] = L, n[29] = R, n[30] = M, n[31] = z) : z = n[31];
418
+ let B, V;
419
+ n[32] === Symbol.for("react.memo_cache_sentinel") ? (B = () => {
420
+ l(F);
421
+ }, V = /* @__PURE__ */ v(g, { className: "h-4 w-4" }), n[32] = B, n[33] = V) : (B = n[32], V = n[33]);
422
+ let H;
423
+ n[34] === c ? H = n[35] : (H = /* @__PURE__ */ v("button", {
424
+ ref: f,
425
+ type: "button",
426
+ className: "inline-flex h-8 w-8 items-center justify-center rounded-md hover:bg-accent",
427
+ "aria-label": "Notification options",
428
+ "aria-haspopup": "menu",
429
+ "aria-expanded": c,
430
+ onClick: B,
431
+ children: V
432
+ }), n[34] = c, n[35] = H);
433
+ let U;
434
+ n[36] !== h || n[37] !== c || n[38] !== r.id || n[39] !== a || n[40] !== i ? (U = c ? /* @__PURE__ */ y("div", {
435
+ ref: u,
436
+ role: "menu",
437
+ className: e("absolute right-0 top-full z-50 mt-1 min-w-[10rem] overflow-hidden rounded-md border bg-popover p-1 text-popover-foreground shadow-md", "animate-in fade-in-0 zoom-in-95"),
438
+ children: [/* @__PURE__ */ v("button", {
439
+ type: "button",
440
+ role: "menuitem",
441
+ className: "relative flex w-full cursor-default select-none items-center gap-2 rounded-sm px-2 py-1.5 text-left text-sm outline-none transition-colors hover:bg-accent focus:bg-accent focus:text-accent-foreground",
442
+ onClick: () => {
443
+ l(!1), a(r.id);
444
+ },
445
+ children: "Archive"
446
+ }), /* @__PURE__ */ v("button", {
447
+ type: "button",
448
+ role: "menuitem",
449
+ className: "relative flex w-full cursor-default select-none items-center gap-2 rounded-sm px-2 py-1.5 text-left text-sm outline-none transition-colors hover:bg-accent focus:bg-accent focus:text-accent-foreground disabled:pointer-events-none disabled:opacity-50",
450
+ disabled: !h,
451
+ onClick: () => {
452
+ l(!1), i(r.id);
453
+ },
454
+ children: "Mark as read"
455
+ })]
456
+ }) : null, n[36] = h, n[37] = c, n[38] = r.id, n[39] = a, n[40] = i, n[41] = U) : U = n[41];
457
+ let W;
458
+ n[42] !== H || n[43] !== U ? (W = /* @__PURE__ */ y("div", {
459
+ className: "relative flex items-start",
460
+ children: [H, U]
461
+ }), n[42] = H, n[43] = U, n[44] = W) : W = n[44];
462
+ let G;
463
+ return n[45] !== z || n[46] !== W || n[47] !== j ? (G = /* @__PURE__ */ y("div", {
464
+ className: j,
465
+ children: [z, W]
466
+ }), n[45] = z, n[46] = W, n[47] = j, n[48] = G) : G = n[48], G;
467
+ }
468
+ function F(e) {
469
+ return !e;
470
+ }
269
471
  //#endregion
270
- export { d as NotificationsSettings };
472
+ export { M as NotificationsDrawer };
271
473
 
272
474
  //# sourceMappingURL=index421.js.map