@commentkit/comment-kit 0.7.0 → 0.7.1

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 (45) hide show
  1. package/CHANGELOG.md +27 -0
  2. package/dist/angular.es.js +2 -2
  3. package/dist/comment-kit.es.js +5 -5
  4. package/dist/demo.es.js +4 -3
  5. package/dist/headless.es.js +3 -3
  6. package/dist/preact.es.js +2 -2
  7. package/dist/qwik.qwik.mjs +2 -2
  8. package/dist/react.es.js +2 -2
  9. package/dist/shared/{annotation-toolbar-B9SxYqoF.js → annotation-toolbar-cGC1p-SP.js} +379 -379
  10. package/dist/shared/attachment-refresh-CzQFXHkL.js +94 -0
  11. package/dist/shared/{button-group-Cl9CrvvU.js → button-group-CWdKaOlC.js} +14 -16
  12. package/dist/shared/capture-colors-CxSLsU5-.js +74 -0
  13. package/dist/shared/{comment-drawing-canvas-Dzb5YoFw.js → comment-drawing-canvas-DdXlMgbF.js} +2 -2
  14. package/dist/shared/{comment-utils-BycYTSxA.js → comment-icon-Dg9ZWpz-.js} +29 -23
  15. package/dist/shared/comment-image-lightbox-B7iHjnAz.js +190 -0
  16. package/dist/shared/comment-images-content-D7YNUgo5.js +214 -0
  17. package/dist/shared/{comment-kit-core-BaSuMzp9.js → comment-kit-core-C862uNAm.js} +998 -778
  18. package/dist/shared/{comment-kit-ui-CzfdAZs2.js → comment-kit-ui-0vd-DY4S.js} +5206 -5410
  19. package/dist/shared/{comment-screenshot-annotator-C7X-_bm6.js → comment-screenshot-annotator-DcaSSuWB.js} +5 -5
  20. package/dist/shared/{comment-screenshot-overlay-wIrZrcRy.js → comment-screenshot-overlay-D_nFoJmM.js} +6 -5
  21. package/dist/shared/{dev-export-panel-FwFVdady.js → dev-export-panel-pWBlhlse.js} +7 -7
  22. package/dist/shared/dev-grab-eQ9EgEGY.js +210 -0
  23. package/dist/shared/{element-selector-BhJm-NSs.js → element-selector-DC-_XJ0k.js} +311 -272
  24. package/dist/shared/{mount-ui--ijs8pWT.js → mount-ui-B68j8r6I.js} +4 -4
  25. package/dist/shared/{pusher-ipHMJnO_.js → pusher-C1FHQGXV.js} +1 -1
  26. package/dist/shared/realtime-Diqz7G_y.js +317 -0
  27. package/dist/shared/realtime-recovery-DJ_adc-H.js +135 -0
  28. package/dist/shared/{shadow-root-C5v-T8lQ.js → shadow-root-CrO75sED.js} +1 -1
  29. package/dist/shared/{styles-D3yMtaec.js → styles-C9Jwvm0Q.js} +1 -1
  30. package/dist/shared/useRender-D1z_X_BY.js +5 -0
  31. package/dist/shared/{validation-C7QG8j7Z.js → validation-D-8u4M7I.js} +14 -1
  32. package/dist/shared/{websocket-manager-DhLWh3Jr.js → websocket-manager-CFak_YHy.js} +148 -89
  33. package/dist/solid.es.js +2 -2
  34. package/dist/svelte.es.js +2 -2
  35. package/dist/types/core/api-client.d.ts +8 -1
  36. package/dist/types/core/comment-kit-core.d.ts +9 -0
  37. package/dist/types/core/types.d.ts +35 -0
  38. package/dist/types/core/websocket-manager.d.ts +12 -0
  39. package/dist/types/core/write-access.d.ts +9 -0
  40. package/dist/vue.es.js +2 -2
  41. package/docs/api-reference.md +6 -0
  42. package/package.json +3 -2
  43. package/dist/shared/comment-image-lightbox-BPYJT1sB.js +0 -183
  44. package/dist/shared/dev-grab-DDqg0LQf.js +0 -203
  45. package/dist/shared/realtime-Dk41VwKg.js +0 -302
@@ -1,4 +1,4 @@
1
- import { r as e } from "./websocket-manager-DhLWh3Jr.js";
1
+ import { o as e } from "./websocket-manager-CFak_YHy.js";
2
2
  import { n as t } from "./errors-Bu5ajEmB.js";
3
3
  var n = null, r = /* @__PURE__ */ new Set();
4
4
  function i() {
@@ -134,10 +134,10 @@ async function y(e, n = {}) {
134
134
  let [t, r, c, l, u, f] = await Promise.all([
135
135
  import("react"),
136
136
  import("react-dom/client"),
137
- import("./styles-D3yMtaec.js"),
138
- import("./shadow-root-C5v-T8lQ.js"),
137
+ import("./styles-C9Jwvm0Q.js"),
138
+ import("./shadow-root-CrO75sED.js"),
139
139
  import("./error-boundary-D3PD74vI.js"),
140
- import("./comment-kit-ui-CzfdAZs2.js").then((e) => e.t)
140
+ import("./comment-kit-ui-0vd-DY4S.js").then((e) => e.t)
141
141
  ]);
142
142
  if (!s || n !== b) return;
143
143
  let p = h(t, "createElement"), g = h(r, "createRoot"), _ = l.ShadowContainer, v = u.ErrorBoundary;
@@ -1,4 +1,4 @@
1
- import { n as e } from "./websocket-manager-DhLWh3Jr.js";
1
+ import { a as e } from "./websocket-manager-CFak_YHy.js";
2
2
  var t = /* @__PURE__ */ e(((e, t) => {
3
3
  (function(n, r) {
4
4
  typeof e == "object" && typeof t == "object" ? t.exports = r() : typeof define == "function" && define.amd ? define([], r) : typeof e == "object" ? e.Pusher = r() : n.Pusher = r();
@@ -0,0 +1,317 @@
1
+ import { i as e, n as t, r as n, t as r } from "./websocket-manager-CFak_YHy.js";
2
+ import { a as i, c as a, i as o, l as s, o as c } from "./validation-D-8u4M7I.js";
3
+ import { i as l } from "./comment-kit-core-C862uNAm.js";
4
+ import { o as u } from "./dom-Bhf4WFtY.js";
5
+ var d = l.ID, f = l.CONTENT, p = l.NAME, m = l.EMAIL, h = l.PAGE, g = l.EMOJI, _ = l.ONLINE_USERS, v = l.REACTION_COUNT, y = 33, b = 1e3, x = l.CURSOR_EMITS_PER_SEC;
6
+ function S(e) {
7
+ let t = e.config.realtime, n = t?.maxRenderedCursors;
8
+ return {
9
+ cursors: t?.cursors !== !1,
10
+ presence: t?.presence !== !1,
11
+ maxRenderedCursors: typeof n == "number" && Number.isFinite(n) && n >= 0 ? Math.min(Math.floor(n), _) : l.RENDERED_CURSORS
12
+ };
13
+ }
14
+ var C = /* @__PURE__ */ new Set([
15
+ "pin",
16
+ "highlight",
17
+ "drawing"
18
+ ]), w = /* @__PURE__ */ new Set([
19
+ "open",
20
+ "resolved",
21
+ "complete"
22
+ ]), T = /* @__PURE__ */ new Set([
23
+ "low",
24
+ "medium",
25
+ "high",
26
+ "urgent"
27
+ ]), E = /* @__PURE__ */ new Set([
28
+ "path",
29
+ "line",
30
+ "rectangle",
31
+ "circle",
32
+ "text"
33
+ ]);
34
+ function D(e, t) {
35
+ return a(e, t);
36
+ }
37
+ function O(e) {
38
+ return D(e, d);
39
+ }
40
+ function k(e) {
41
+ if (!D(e, m)) return !1;
42
+ let t = e.trim(), n = t.indexOf("@");
43
+ return n > 0 && n === t.lastIndexOf("@") && n < t.length - 1 && !/\s/.test(t);
44
+ }
45
+ function A(e) {
46
+ return c(e) && O(e.id) && D(e.name, p) && k(e.email) && s(e.avatar, h) && s(e.organizationId, d);
47
+ }
48
+ function j(e) {
49
+ return {
50
+ id: e.id.trim(),
51
+ name: e.name.trim(),
52
+ email: e.email.trim(),
53
+ ...e.avatar ? { avatar: e.avatar.trim() } : {},
54
+ ...e.organizationId ? { organizationId: e.organizationId.trim() } : {}
55
+ };
56
+ }
57
+ function M(t) {
58
+ if (!Array.isArray(t)) return null;
59
+ let n = [], r = /* @__PURE__ */ new Set();
60
+ for (let i of t) {
61
+ if (n.length >= _) break;
62
+ let t = e(i);
63
+ if (!A(t)) continue;
64
+ let a = j(t);
65
+ r.has(a.id) || (r.add(a.id), n.push(a));
66
+ }
67
+ return n;
68
+ }
69
+ function N(e) {
70
+ return c(e) ? i(e.x) && i(e.y) : !1;
71
+ }
72
+ function P(e) {
73
+ return c(e) && D(e.url, h) && D(e.path, h) && typeof e.title == "string" && s(e.title, h);
74
+ }
75
+ function F(e) {
76
+ return c(e) && H(e.emoji) && Number.isInteger(e.count) && e.count >= 0 && e.count <= v && typeof e.reacted == "boolean";
77
+ }
78
+ function I(e, t) {
79
+ if (Array.isArray(e)) return e.filter(F).map((e) => {
80
+ if (!Array.isArray(e.userIds)) return e;
81
+ let n = e.userIds.filter(O);
82
+ return {
83
+ ...e,
84
+ userIds: n,
85
+ reacted: !!t && n.includes(t)
86
+ };
87
+ });
88
+ }
89
+ function L(e, t) {
90
+ return {
91
+ ...e,
92
+ replies: Array.isArray(e.replies) ? e.replies.flatMap((e) => {
93
+ let n = z(e, t);
94
+ return n ? [n] : [];
95
+ }) : [],
96
+ ...e.reactions === void 0 ? {} : { reactions: I(e.reactions, t) }
97
+ };
98
+ }
99
+ function R(e, n) {
100
+ return e = t(e), !c(e) || !O(e.id) || !C.has(e.type) || !D(e.content, f) || !N(e.position) || !w.has(e.status) || !T.has(e.priority) || !A(e.author) || !O(e.userId) || !D(e.createdAt, h) || !D(e.updatedAt, h) || !P(e.page) || !Array.isArray(e.replies) || !Array.isArray(e.attachments) ? null : L(structuredClone(e), n);
101
+ }
102
+ function z(e, t) {
103
+ if (e = n(e), !c(e) || !O(e.id) || !D(e.content, f) || !A(e.author) || !D(e.createdAt, h)) return null;
104
+ let r = structuredClone(e);
105
+ return r.reactions &&= I(r.reactions, t), r;
106
+ }
107
+ function B(t) {
108
+ if (!c(t)) return null;
109
+ let n = e(t.user);
110
+ return !A(n) || !o(t.x) || t.x < 0 || t.x > 100 || !o(t.y) || t.y < 0 || t.y > 100 || !D(t.page, h) ? null : {
111
+ x: t.x,
112
+ y: t.y,
113
+ page: t.page.trim(),
114
+ user: j(n)
115
+ };
116
+ }
117
+ function V(e) {
118
+ return c(e) ? D(e.type, l.DRAWING_TYPE) && E.has(e.type) && D(e.stroke, l.COLOR) && o(e.strokeWidth) && e.strokeWidth >= 0 && D(e.fill, l.COLOR) && s(e.d, l.DRAWING_PATH_DATA) && s(e.text, l.DRAWING_TEXT) && (e.x === void 0 || o(e.x)) && (e.y === void 0 || o(e.y)) && (e.width === void 0 || o(e.width)) && (e.height === void 0 || o(e.height)) : !1;
119
+ }
120
+ function H(e) {
121
+ return D(e, g);
122
+ }
123
+ function U(e) {
124
+ try {
125
+ e();
126
+ } catch {}
127
+ }
128
+ function W(e, t) {
129
+ return e.wsManager === t;
130
+ }
131
+ function G(e, t) {
132
+ e.setState({ comments: e.getState().comments.map((e) => e.id === t.id ? t : e) });
133
+ }
134
+ function K(t, n, i) {
135
+ if (t.config.features?.realtime === !1 || !t.config.reverb?.host || !t.config.reverb?.key) return;
136
+ if (n.wsManager) {
137
+ for (let e of n.wsUnsubscribers) U(e);
138
+ n.wsUnsubscribers = [], q(n);
139
+ try {
140
+ n.wsManager.destroy();
141
+ } catch {}
142
+ n.wsManager = null;
143
+ }
144
+ let a = t.config.baseUrl || "https://api.commentkit.dev/api", o = t.getState().currentUser, s = S(t);
145
+ try {
146
+ n.wsManager = new r({
147
+ key: t.config.reverb.key,
148
+ wsHost: t.config.reverb.host,
149
+ wsPort: t.config.reverb.port ?? 443,
150
+ forceTLS: (t.config.reverb.scheme ?? "wss") === "wss",
151
+ /* v8 ignore next -- projectId always provided in config */
152
+ projectId: t.config.projectId || "",
153
+ apiKey: t.config.apiKey,
154
+ authEndpoint: `${a}/broadcasting/auth`,
155
+ authorizeChannel: (e, n) => t.apiClient.authorizeChannel(e, n),
156
+ userEmail: o?.email,
157
+ userInfo: o ? {
158
+ id: o.id,
159
+ name: o.name,
160
+ email: o.email
161
+ } : void 0
162
+ });
163
+ } catch (e) {
164
+ t.setState({ connectionStatus: "error" }), t.handleError(e);
165
+ return;
166
+ }
167
+ let l = n.wsUnsubscribers, d = n.wsManager, f, p, m = !1, h = () => p ??= import("./realtime-recovery-DJ_adc-H.js").then((e) => {
168
+ if (!m && i && W(n, d)) return f = e.createRealtimeRecovery(t, i, () => W(n, d), R), f;
169
+ }).catch((e) => {
170
+ p = void 0, m || t.handleError(e);
171
+ });
172
+ l.push(() => {
173
+ m = !0, f?.dispose();
174
+ }), l.push(d.on("subscribed", () => {
175
+ W(n, d) && i && h().then((e) => e?.refreshWindow());
176
+ })), l.push(d.on("comment:refresh", (e) => {
177
+ W(n, d) && i && h().then((t) => t?.refreshThread(e));
178
+ })), l.push(d.on("connected", () => {
179
+ W(n, d) && (t.setState({ connectionStatus: "connected" }), n.wsManager?.requestPresence());
180
+ })), l.push(d.on("disconnected", () => {
181
+ W(n, d) && t.setState({ connectionStatus: "disconnected" });
182
+ })), l.push(d.on("reconnecting", () => {
183
+ W(n, d) && t.setState({ connectionStatus: "connecting" });
184
+ })), l.push(d.on("error", () => {
185
+ W(n, d) && t.setState({ connectionStatus: "error" });
186
+ })), l.push(d.on("comment:resolved", (e) => {
187
+ if (!W(n, d)) return;
188
+ let r = R(e, t.getState().currentUser?.id);
189
+ r && (G(t, r), t.emit("comment:resolved", r));
190
+ })), l.push(d.on("comment:completed", (e) => {
191
+ if (!W(n, d)) return;
192
+ let r = R(e, t.getState().currentUser?.id);
193
+ r && (G(t, r), t.emit("comment:completed", r));
194
+ })), l.push(d.on("comment:created", (e) => {
195
+ if (!W(n, d)) return;
196
+ let r = R(e, t.getState().currentUser?.id);
197
+ if (!r) return;
198
+ let i = t.getState().activeBranch;
199
+ i && r.branch !== i || t.getState().comments.find((e) => e.id === r.id) || (t.setState({ comments: [...t.getState().comments, r] }), t.emit("comment:created", r));
200
+ })), l.push(d.on("comment:updated", (e) => {
201
+ if (!W(n, d)) return;
202
+ let r = R(e, t.getState().currentUser?.id);
203
+ r && (G(t, r), t.emit("comment:updated", r));
204
+ })), l.push(d.on("comment:deleted", (e) => {
205
+ if (!W(n, d) || !c(e) || !O(e.id)) return;
206
+ let r = e.id.trim();
207
+ t.setState({
208
+ comments: t.getState().comments.filter((e) => e.id !== r),
209
+ selectedComment: t.getState().selectedComment?.id === r ? null : t.getState().selectedComment
210
+ }), t.emit("comment:deleted", { id: r });
211
+ })), l.push(d.on("reply:added", (e) => {
212
+ if (!W(n, d) || !c(e) || !O(e.commentId)) return;
213
+ let r = z(e.reply, t.getState().currentUser?.id);
214
+ if (!r) return;
215
+ let i = e.commentId.trim(), a = t.getState().comments.map((e) => e.id !== i || e.replies.some((e) => e.id === r.id) ? e : {
216
+ ...e,
217
+ status: "open",
218
+ resolvedAt: void 0,
219
+ completedAt: void 0,
220
+ replies: [...e.replies, r]
221
+ });
222
+ t.setState({ comments: a });
223
+ let o = a.find((e) => e.id === i);
224
+ o && t.emit("comment:updated", o);
225
+ }));
226
+ let g = (e, t, n) => {
227
+ let r = (e ?? []).filter((e) => H(e.emoji) && Number.isInteger(e.count) && e.count >= 0 && e.count <= v), i = r.findIndex((e) => e.emoji === t);
228
+ if (i !== -1) {
229
+ let e = r[i];
230
+ r[i] = n ? {
231
+ ...e,
232
+ reacted: !0
233
+ } : {
234
+ ...e,
235
+ count: Math.min(e.count + 1, v),
236
+ reacted: e.reacted
237
+ };
238
+ } else r.push({
239
+ emoji: t,
240
+ count: 1,
241
+ reacted: n
242
+ });
243
+ return r;
244
+ }, _ = (e, t, n) => (e ?? []).filter((e) => H(e.emoji) && Number.isInteger(e.count) && e.count > 0 && e.count <= v).map((e) => e.emoji === t ? {
245
+ ...e,
246
+ count: n ? e.count : e.count - 1,
247
+ reacted: !n && e.reacted
248
+ } : e).filter((e) => e.count > 0), C = (e, r) => {
249
+ if (!W(n, d) || !c(e) || !O(e.commentId) || !H(e.emoji) || !O(e.userId)) return;
250
+ let i = e.commentId.trim(), a = O(e.replyId) ? e.replyId.trim() : null, o = e.emoji.trim(), s = e.userId.trim() === t.getState().currentUser?.id;
251
+ t.setState({ comments: t.getState().comments.map((e) => e.id === i ? a === null ? {
252
+ ...e,
253
+ reactions: r(e.reactions, o, s)
254
+ } : {
255
+ ...e,
256
+ replies: e.replies.map((e) => e.id === a ? {
257
+ ...e,
258
+ reactions: r(e.reactions, o, s)
259
+ } : e)
260
+ } : e) });
261
+ };
262
+ l.push(d.on("reaction:added", (e) => C(e, g))), l.push(d.on("reaction:removed", (e) => C(e, _)));
263
+ let w = /* @__PURE__ */ new Map(), T = 0, E = 0;
264
+ l.push(d.on("cursor:move", (e) => {
265
+ if (!W(n, d) || !s.cursors) return;
266
+ let r = B(e);
267
+ if (!r) return;
268
+ let i = Date.now(), a = r.user.id, o = w.get(a);
269
+ if (o === void 0 && w.size >= s.maxRenderedCursors) {
270
+ let e, t = Infinity;
271
+ for (let [n, r] of w) r < t && (t = r, e = n);
272
+ if (e !== void 0 && i - t >= y) w.delete(e);
273
+ else return;
274
+ }
275
+ o !== void 0 && i - o < y || (i - T >= b && (T = i, E = 0), !(E >= x) && (E++, w.set(a, i), t.emit("cursor:move", r)));
276
+ })), l.push(d.on("cursor:leave", (e) => {
277
+ W(n, d) && c(e) && O(e.userId) && (w.delete(e.userId.trim()), t.emit("cursor:leave", { userId: e.userId.trim() }));
278
+ })), l.push(d.on("user:joined", (r) => {
279
+ let i = e(r);
280
+ W(n, d) && A(i) && t.emit("user:joined", j(i));
281
+ })), l.push(d.on("user:left", (e) => {
282
+ W(n, d) && c(e) && O(e.userId) && t.emit("user:left", { userId: e.userId.trim() });
283
+ })), l.push(d.on("presence:update", (e) => {
284
+ if (!W(n, d) || !s.presence || !c(e)) return;
285
+ let r = M(e.users);
286
+ if (!r) return;
287
+ let i = { users: r };
288
+ t.setState({ onlineUsers: r }), t.emit("presence:update", i);
289
+ })), l.push(d.on("drawing:stroke", (e) => {
290
+ W(n, d) && c(e) && O(e.userId) && V(e.path) && t.emit("drawing:stroke", {
291
+ userId: e.userId.trim(),
292
+ path: structuredClone(e.path)
293
+ });
294
+ }));
295
+ try {
296
+ t.setState({ connectionStatus: "connecting" });
297
+ let e = d.connect();
298
+ e && typeof e.catch == "function" && e.catch((e) => {
299
+ t.setState({ connectionStatus: "error" }), t.handleError(e);
300
+ });
301
+ } catch (e) {
302
+ t.setState({ connectionStatus: "error" }), t.handleError(e);
303
+ return;
304
+ }
305
+ /* v8 ignore next -- SSR guard unreachable in jsdom */
306
+ typeof document < "u" && typeof window < "u" && s.cursors && (n.mouseMoveHandler = (e) => {
307
+ if (t.getState().isOverlayVisible && n.wsManager?.isConnected()) {
308
+ if (window.innerWidth <= 0 || window.innerHeight <= 0) return;
309
+ let t = Math.max(0, Math.min(100, e.clientX / window.innerWidth * 100)), r = Math.max(0, Math.min(100, e.clientY / window.innerHeight * 100));
310
+ n.wsManager.sendCursorMove(t, r, u().url);
311
+ }
312
+ }, document.addEventListener("mousemove", n.mouseMoveHandler));
313
+ }
314
+ function q(e) {
315
+ typeof window < "u" && typeof document < "u" && e.mouseMoveHandler && (document.removeEventListener("mousemove", e.mouseMoveHandler), e.mouseMoveHandler = null);
316
+ }
317
+ export { K as initializeWebSocket, q as removeMouseMoveListener };
@@ -0,0 +1,135 @@
1
+ import { b as e } from "./comment-kit-core-C862uNAm.js";
2
+ function t(t, n, r, i) {
3
+ let a = !1, o = !1, s = !1, c = !1, l, u, d = /* @__PURE__ */ new Map(), f = /* @__PURE__ */ new Map(), p = () => !a && r() && t.getState().isAuthenticated, m = () => {
4
+ let n = t.getState();
5
+ return n.isLoading || n.pendingMutations.length > 0 || e(t.apiClient);
6
+ }, h = (e, n) => p() && e.isCurrent?.() !== !1 && n.activeBranch === t.getState().activeBranch, g = (e) => {
7
+ let n = t.getState();
8
+ return !m() && e.comments === n.comments && e.pagination === n.pagination && e.selectedComment?.id === n.selectedComment?.id;
9
+ }, _ = (e, t) => {
10
+ let n = i(e, t.currentUser?.id);
11
+ if (!n) throw Error("Invalid comment refresh response");
12
+ return n;
13
+ }, v = (e, t) => !t.activeBranch || e.branch === t.activeBranch, y = (e) => typeof e == "object" && !!e && "code" in e && e.code === 404, b = (e) => {
14
+ let t = typeof e == "object" && e && "code" in e ? e.code : null;
15
+ return typeof t == "number" && (t === 0 || t === 408 || t === 429 || t >= 500 && t <= 599);
16
+ };
17
+ async function x(e, n) {
18
+ let r = Math.max(1, n.pagination?.page ?? 1), i = n.pagination?.limit ?? 50, a = /* @__PURE__ */ new Map(), o = n.pagination;
19
+ for (let t = 1; t <= r; t++) {
20
+ let r = await e.apiClient.getComments(void 0, "all", t, i, void 0, n.activeBranch);
21
+ if (!h(e, n)) return;
22
+ if (!g(n)) {
23
+ c = !0;
24
+ return;
25
+ }
26
+ for (let e of r.comments) {
27
+ let t = _(e, n);
28
+ v(t, n) && a.set(t.id, t);
29
+ }
30
+ if (o = r.pagination, !o.hasMore) break;
31
+ }
32
+ let s = n.selectedComment?.id, l = s ? a.get(s) ?? null : null;
33
+ if (s && !l) try {
34
+ let t = _(await e.apiClient.getComment(s), n);
35
+ if (t.id !== s) throw Error("Invalid comment refresh response");
36
+ v(t, n) && (l = t, a.set(t.id, t));
37
+ } catch (e) {
38
+ if (!y(e)) throw e;
39
+ }
40
+ if (!h(e, n)) return;
41
+ if (!g(n)) {
42
+ c = !0;
43
+ return;
44
+ }
45
+ let u = t.getState();
46
+ e.setState({
47
+ comments: [...a.values()],
48
+ pagination: o,
49
+ ...u.selectedComment?.id === s ? { selectedComment: l } : {}
50
+ });
51
+ }
52
+ async function S(e, n, r, i) {
53
+ let a;
54
+ try {
55
+ if (a = _(await e.apiClient.getComment(r), n), a.id !== r) throw Error("Invalid comment refresh response");
56
+ } catch (e) {
57
+ if (!y(e)) throw e;
58
+ a = null;
59
+ }
60
+ if (!h(e, n)) return;
61
+ if (!g(n)) {
62
+ for (let e of i) T({
63
+ commentId: r,
64
+ event: e
65
+ });
66
+ return;
67
+ }
68
+ let o = t.getState(), s = o.comments.some((e) => e.id === r);
69
+ if (a && !v(a, n)) return;
70
+ let c = o.comments.filter((e) => e.id !== r);
71
+ if (a && (s || i.has("comment:created"))) {
72
+ let e = o.comments.findIndex((e) => e.id === r);
73
+ c.splice(e < 0 ? c.length : e, 0, a);
74
+ }
75
+ if (e.setState({
76
+ comments: c,
77
+ ...o.selectedComment?.id === r ? { selectedComment: a } : {}
78
+ }), !a) s && e.emit("comment:deleted", { id: r });
79
+ else for (let t of i) (t !== "comment:created" || !s) && e.emit(t, a);
80
+ }
81
+ async function C() {
82
+ if (s = !1, !p() || o || !c && !f.size) return;
83
+ if (m()) {
84
+ e(t.apiClient) && !l && (l = setTimeout(() => {
85
+ l = void 0, w();
86
+ }, 100));
87
+ return;
88
+ }
89
+ o = !0;
90
+ let r = n.capture(), i = t.getState(), a = c, g = a ? void 0 : f.entries().next().value, _ = a ? "window" : `thread:${g?.[0]}`;
91
+ try {
92
+ if (a) c = !1, await x(r, i);
93
+ else if (g) {
94
+ let [e, t] = g;
95
+ f.delete(e), await S(r, i, e, t);
96
+ }
97
+ d.delete(_);
98
+ } catch (e) {
99
+ if (h(r, i)) {
100
+ let t = d.get(_) ?? 0;
101
+ b(e) && t < 2 ? (d.set(_, t + 1), u = setTimeout(() => {
102
+ if (u = void 0, h(r, i)) {
103
+ if (a) c = !0;
104
+ else if (g) for (let e of g[1]) T({
105
+ commentId: g[0],
106
+ event: e
107
+ });
108
+ } else d.delete(_);
109
+ w();
110
+ }, 1e3 * 2 ** t)) : (d.delete(_), r.handleError(e));
111
+ }
112
+ } finally {
113
+ o = !1, w();
114
+ }
115
+ }
116
+ function w() {
117
+ !p() || s || o || u || !c && !f.size || (s = !0, Promise.resolve().then(C));
118
+ }
119
+ function T({ commentId: e, event: t }) {
120
+ if (!p()) return;
121
+ let n = f.get(e) ?? /* @__PURE__ */ new Set();
122
+ n.add(t), f.size < 256 || f.has(e) ? f.set(e, n) : c = !0, w();
123
+ }
124
+ let E = n.subscribe(w);
125
+ return {
126
+ refreshThread: T,
127
+ refreshWindow() {
128
+ p() && (c = !0, w());
129
+ },
130
+ dispose() {
131
+ a = !0, l && clearTimeout(l), u && clearTimeout(u), d.clear(), f.clear(), E();
132
+ }
133
+ };
134
+ }
135
+ export { t as createRealtimeRecovery };
@@ -1,4 +1,4 @@
1
- import { o as e, r as t } from "./mount-ui--ijs8pWT.js";
1
+ import { o as e, r as t } from "./mount-ui-B68j8r6I.js";
2
2
  import { r as n, t as r } from "./ShadowRootContext-Bv-4aElu.js";
3
3
  import * as i from "react";
4
4
  import { useCallback as a, useEffect as o, useMemo as s, useRef as c, useState as l } from "react";