@commentkit/comment-kit 0.7.6 → 1.0.0-beta.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 (109) hide show
  1. package/CHANGELOG.md +30 -0
  2. package/README.md +108 -762
  3. package/SECURITY.md +19 -14
  4. package/dist/npm/THIRD_PARTY_NOTICES.txt +73 -0
  5. package/dist/npm/chunks/anchor-DT-Ynhh1.js +270 -0
  6. package/dist/npm/chunks/client-D1vrh_5G.js +590 -0
  7. package/dist/{shared/capture-colors-D0uLr-vZ.js → npm/chunks/colors-CX-IPjvb.js} +2 -0
  8. package/dist/npm/chunks/html2canvas-_mjSRP3G.js +4011 -0
  9. package/dist/npm/chunks/mount-Ce1MZrcm.js +2485 -0
  10. package/dist/{shared/pusher-BUaiCkDJ.js → npm/chunks/pusher-DRKlokR8.js} +224 -222
  11. package/dist/npm/chunks/realtime-5SvAvTUU.js +23 -0
  12. package/dist/npm/chunks/rolldown-runtime-VHNaYcLd.js +13 -0
  13. package/dist/npm/chunks/src-DJjfvVsa.js +330 -0
  14. package/dist/npm/element.js +24 -0
  15. package/dist/npm/headless.js +3 -0
  16. package/dist/npm/index.js +3 -0
  17. package/dist/npm/react.js +17 -0
  18. package/dist/npm/svelte.js +8 -0
  19. package/dist/npm/types/adapters/react.d.ts +9 -0
  20. package/dist/npm/types/adapters/svelte.d.ts +9 -0
  21. package/dist/npm/types/adapters/vue.d.ts +46 -0
  22. package/dist/npm/types/anchor/index.d.ts +49 -0
  23. package/dist/npm/types/core/api.d.ts +29 -0
  24. package/dist/npm/types/core/auth.d.ts +48 -0
  25. package/dist/npm/types/core/client.d.ts +100 -0
  26. package/dist/npm/types/core/store.d.ts +7 -0
  27. package/dist/npm/types/core/types.d.ts +278 -0
  28. package/dist/npm/types/element.d.ts +10 -0
  29. package/dist/npm/types/headless.d.ts +7 -0
  30. package/dist/npm/types/index.d.ts +30 -0
  31. package/dist/npm/vue.js +32 -0
  32. package/package.json +65 -173
  33. package/dist/THIRD_PARTY_NOTICES.txt +0 -284
  34. package/dist/angular.es.js +0 -321
  35. package/dist/comment-kit.es.js +0 -218
  36. package/dist/demo.es.js +0 -483
  37. package/dist/headless.es.js +0 -4
  38. package/dist/preact.es.js +0 -117
  39. package/dist/qwik.es.js +0 -1
  40. package/dist/qwik.qwik.mjs +0 -114
  41. package/dist/react.es.js +0 -98
  42. package/dist/shared/ShadowRootContext-DD6a0QaI.js +0 -11
  43. package/dist/shared/annotation-icons-Dh-bmNYK.js +0 -172
  44. package/dist/shared/annotation-toolbar-RSrb0Nku.js +0 -1086
  45. package/dist/shared/attachment-refresh-CSTYwRW-.js +0 -94
  46. package/dist/shared/bridge-CJoGYngu.js +0 -177
  47. package/dist/shared/button-D4GHW6oZ.js +0 -474
  48. package/dist/shared/button-group-BVR7iT-S.js +0 -91
  49. package/dist/shared/capture-privacy-DUROnio5.js +0 -77
  50. package/dist/shared/comment-drawing-canvas-DbuXP54N.js +0 -124
  51. package/dist/shared/comment-icon-D8JTCEJ7.js +0 -607
  52. package/dist/shared/comment-image-lightbox-zlIGEVA-.js +0 -190
  53. package/dist/shared/comment-images-content-aYbJb79_.js +0 -214
  54. package/dist/shared/comment-kit-core-B0k7XsMz.js +0 -3680
  55. package/dist/shared/comment-kit-ui-BXLJcZYQ.js +0 -19391
  56. package/dist/shared/comment-screenshot-annotator-ChWwYJzO.js +0 -151
  57. package/dist/shared/comment-screenshot-overlay-Bufg3rHz.js +0 -205
  58. package/dist/shared/comment-shortcut-groups-CfEmkitU.js +0 -153
  59. package/dist/shared/createReactComponent-BZHeRbD0.js +0 -45
  60. package/dist/shared/dev-export-panel-DAZenvgD.js +0 -207
  61. package/dist/shared/dev-grab-O8q25zar.js +0 -197
  62. package/dist/shared/dist-D9A5k-N4.js +0 -617
  63. package/dist/shared/dom-Bhf4WFtY.js +0 -223
  64. package/dist/shared/element-selector-CYkwzfEr.js +0 -902
  65. package/dist/shared/error-boundary-D3PD74vI.js +0 -21
  66. package/dist/shared/errors-Bu5ajEmB.js +0 -22
  67. package/dist/shared/icons-nzMOLzrm.js +0 -266
  68. package/dist/shared/input-UPtAj0M6.js +0 -111
  69. package/dist/shared/mount-ui-BKaWBhKq.js +0 -208
  70. package/dist/shared/realtime-C0Z8dXXH.js +0 -334
  71. package/dist/shared/realtime-recovery-BjlV-ewc.js +0 -162
  72. package/dist/shared/request-activity-DQrAUwfA.js +0 -11
  73. package/dist/shared/screenshot-B-ZfFItT.js +0 -199
  74. package/dist/shared/separator-UhJb0Row.js +0 -3955
  75. package/dist/shared/shadow-root-Cd3SLHyj.js +0 -133
  76. package/dist/shared/styles-CnYsLS2f.js +0 -2
  77. package/dist/shared/text-B4HHZNaa.js +0 -23
  78. package/dist/shared/token-session-DplW5QDx.js +0 -25
  79. package/dist/shared/useLabelableId-8n0QmH8N.js +0 -154
  80. package/dist/shared/useRender-Uxk1OPK-.js +0 -5
  81. package/dist/shared/useValueChanged-DKq5cMot.js +0 -92
  82. package/dist/shared/validation-3wbbbuX0.js +0 -70
  83. package/dist/shared/websocket-manager-798cRDyL.js +0 -381
  84. package/dist/solid.es.js +0 -98
  85. package/dist/svelte.es.js +0 -130
  86. package/dist/types/adapters/bridge.d.ts +0 -122
  87. package/dist/types/angular/index.d.ts +0 -145
  88. package/dist/types/core/agent-context.d.ts +0 -17
  89. package/dist/types/core/api-client.d.ts +0 -155
  90. package/dist/types/core/comment-kit-core.d.ts +0 -254
  91. package/dist/types/core/local-demo.d.ts +0 -60
  92. package/dist/types/core/types.d.ts +0 -770
  93. package/dist/types/core/websocket-manager.d.ts +0 -125
  94. package/dist/types/core/write-access.d.ts +0 -11
  95. package/dist/types/demo.d.ts +0 -17
  96. package/dist/types/headless.d.ts +0 -8
  97. package/dist/types/index.d.ts +0 -87
  98. package/dist/types/preact/index.d.ts +0 -25
  99. package/dist/types/qwik/index.d.ts +0 -73
  100. package/dist/types/react/client.d.ts +0 -31
  101. package/dist/types/react/index.d.ts +0 -4
  102. package/dist/types/solid/index.d.ts +0 -37
  103. package/dist/types/svelte/index.d.ts +0 -55
  104. package/dist/types/utils/dom.d.ts +0 -59
  105. package/dist/types/utils/event-emitter.d.ts +0 -11
  106. package/dist/types/vue/index.d.ts +0 -87
  107. package/dist/vue.es.js +0 -148
  108. package/docs/api-reference.md +0 -405
  109. package/docs/local-demo.md +0 -60
@@ -1,334 +0,0 @@
1
- import { i as e, n as t, r as n, t as r } from "./websocket-manager-798cRDyL.js";
2
- import { a as i, d as a, i as o, l as s, o as c } from "./validation-3wbbbuX0.js";
3
- import { s as l } from "./comment-kit-core-B0k7XsMz.js";
4
- import { o as u } from "./dom-Bhf4WFtY.js";
5
- import { i as d } from "./text-B4HHZNaa.js";
6
- var f = l.ID, p = l.CONTENT, m = l.NAME, h = l.EMAIL, g = l.PAGE, _ = l.EMOJI, v = l.ONLINE_USERS, y = l.REACTION_COUNT, b = 33, x = 1e3, S = l.CURSOR_EMITS_PER_SEC;
7
- function C(e) {
8
- let t = e.config.realtime, n = t?.maxRenderedCursors;
9
- return {
10
- cursors: t?.cursors !== !1,
11
- presence: t?.presence !== !1,
12
- maxRenderedCursors: typeof n == "number" && Number.isFinite(n) && n >= 0 ? Math.min(Math.floor(n), v) : l.RENDERED_CURSORS
13
- };
14
- }
15
- var w = /* @__PURE__ */ new Set([
16
- "pin",
17
- "highlight",
18
- "drawing"
19
- ]), T = /* @__PURE__ */ new Set([
20
- "open",
21
- "resolved",
22
- "complete"
23
- ]), E = /* @__PURE__ */ new Set([
24
- "low",
25
- "medium",
26
- "high",
27
- "urgent"
28
- ]), D = /* @__PURE__ */ new Set([
29
- "path",
30
- "line",
31
- "rectangle",
32
- "circle",
33
- "text"
34
- ]);
35
- function O(e, t) {
36
- return s(e, t);
37
- }
38
- function k(e) {
39
- return O(e, f);
40
- }
41
- function A(e) {
42
- if (!O(e, h)) return !1;
43
- let t = e.trim(), n = t.indexOf("@");
44
- return n > 0 && n === t.lastIndexOf("@") && n < t.length - 1 && !/\s/.test(t);
45
- }
46
- function j(e) {
47
- return c(e) && k(e.id) && O(e.name, m) && A(e.email) && a(e.avatar, g) && a(e.organizationId, f);
48
- }
49
- function M(e) {
50
- return {
51
- id: e.id.trim(),
52
- name: e.name.trim(),
53
- email: e.email.trim(),
54
- ...e.avatar ? { avatar: e.avatar.trim() } : {},
55
- ...e.organizationId ? { organizationId: e.organizationId.trim() } : {}
56
- };
57
- }
58
- function N(t) {
59
- if (!Array.isArray(t)) return null;
60
- let n = [], r = /* @__PURE__ */ new Set();
61
- for (let i of t) {
62
- if (n.length >= v) break;
63
- let t = e(i);
64
- if (!j(t)) continue;
65
- let a = M(t);
66
- r.has(a.id) || (r.add(a.id), n.push(a));
67
- }
68
- return n;
69
- }
70
- function P(e) {
71
- return c(e) ? i(e.x) && i(e.y) : !1;
72
- }
73
- function F(e) {
74
- return c(e) && O(e.url, g) && O(e.path, g) && typeof e.title == "string" && a(e.title, g);
75
- }
76
- function I(e) {
77
- return c(e) && U(e.emoji) && Number.isInteger(e.count) && e.count >= 0 && e.count <= y && typeof e.reacted == "boolean";
78
- }
79
- function L(e, t) {
80
- if (Array.isArray(e)) return e.filter(I).map((e) => {
81
- if (!Array.isArray(e.userIds)) return e;
82
- let n = e.userIds.filter(k);
83
- return {
84
- ...e,
85
- userIds: n,
86
- reacted: !!t && n.includes(t)
87
- };
88
- });
89
- }
90
- function R(e, t) {
91
- return {
92
- ...e,
93
- replies: Array.isArray(e.replies) ? e.replies.flatMap((e) => {
94
- let n = B(e, t);
95
- return n ? [n] : [];
96
- }) : [],
97
- ...e.reactions === void 0 ? {} : { reactions: L(e.reactions, t) }
98
- };
99
- }
100
- function z(e, n) {
101
- return e = t(e), !c(e) || !k(e.id) || !w.has(e.type) || !O(e.content, p) || !P(e.position) || !T.has(e.status) || !E.has(e.priority) || !j(e.author) || !k(e.userId) || !O(e.createdAt, g) || !O(e.updatedAt, g) || !F(e.page) || !Array.isArray(e.replies) || !Array.isArray(e.attachments) ? null : R(structuredClone(e), n);
102
- }
103
- function B(e, t) {
104
- if (e = n(e), !c(e) || !k(e.id) || !O(e.content, p) || !j(e.author) || !O(e.createdAt, g)) return null;
105
- let r = structuredClone(e);
106
- return r.reactions &&= L(r.reactions, t), r;
107
- }
108
- function V(t) {
109
- if (!c(t)) return null;
110
- let n = e(t.user);
111
- return !j(n) || !o(t.x) || t.x < 0 || t.x > 100 || !o(t.y) || t.y < 0 || t.y > 100 || !O(t.page, g) ? null : {
112
- x: t.x,
113
- y: t.y,
114
- page: t.page.trim(),
115
- user: M(n)
116
- };
117
- }
118
- function H(e) {
119
- return c(e) ? O(e.type, l.DRAWING_TYPE) && D.has(e.type) && O(e.stroke, l.COLOR) && o(e.strokeWidth) && e.strokeWidth >= 0 && O(e.fill, l.COLOR) && a(e.d, l.DRAWING_PATH_DATA) && a(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;
120
- }
121
- function U(e) {
122
- return O(e, _);
123
- }
124
- function W(e) {
125
- try {
126
- e();
127
- } catch {}
128
- }
129
- function G(e, t) {
130
- return e.wsManager === t;
131
- }
132
- function K(e, t) {
133
- e.setState({ comments: e.getState().comments.map((e) => e.id === t.id ? t : e) });
134
- }
135
- function q(t, n, i) {
136
- if (t.config.features?.realtime === !1 || !t.config.reverb?.host || !t.config.reverb?.key) return;
137
- if (n.wsManager) {
138
- for (let e of n.wsUnsubscribers) W(e);
139
- n.wsUnsubscribers = [], J(n);
140
- try {
141
- n.wsManager.destroy();
142
- } catch {}
143
- n.wsManager = null;
144
- }
145
- let a = t.config.baseUrl || "https://api.commentkit.dev/api", o = t.getState().currentUser, s = C(t);
146
- try {
147
- n.wsManager = new r({
148
- key: t.config.reverb.key,
149
- wsHost: t.config.reverb.host,
150
- wsPort: t.config.reverb.port ?? 443,
151
- forceTLS: (t.config.reverb.scheme ?? "wss") === "wss",
152
- /* v8 ignore next -- projectId always provided in config */
153
- projectId: t.config.projectId || "",
154
- apiKey: t.config.apiKey,
155
- authEndpoint: `${a}/broadcasting/auth`,
156
- authorizeChannel: (e, n) => t.apiClient.authorizeChannel(e, n),
157
- userEmail: o?.email,
158
- userInfo: o ? {
159
- id: o.id,
160
- name: o.name,
161
- email: o.email
162
- } : void 0
163
- });
164
- } catch (e) {
165
- t.setState({ connectionStatus: "error" }), t.handleError(e);
166
- return;
167
- }
168
- let l = n.wsUnsubscribers, f = n.wsManager, p, m, h = !1, g = () => m ??= import("./realtime-recovery-BjlV-ewc.js").then((e) => {
169
- if (!h && i && G(n, f)) return p = e.createRealtimeRecovery(t, i, () => G(n, f), z), p;
170
- }).catch((e) => {
171
- m = void 0, h || t.handleError(e);
172
- }), _ = (e, n) => {
173
- g().then((r) => {
174
- t.getState().commentQuery ? r?.refreshWindow() : r?.refreshThread({
175
- commentId: e,
176
- event: n
177
- });
178
- });
179
- };
180
- l.push(() => {
181
- h = !0, p?.dispose();
182
- }), l.push(f.on("subscribed", () => {
183
- G(n, f) && i && g().then((e) => e?.refreshWindow());
184
- })), l.push(f.on("comment:refresh", (e) => {
185
- G(n, f) && i && g().then((t) => t?.refreshThread(e));
186
- })), l.push(f.on("connected", () => {
187
- G(n, f) && (t.setState({ connectionStatus: "connected" }), n.wsManager?.requestPresence());
188
- })), l.push(f.on("disconnected", () => {
189
- G(n, f) && t.setState({ connectionStatus: "disconnected" });
190
- })), l.push(f.on("reconnecting", () => {
191
- G(n, f) && t.setState({ connectionStatus: "connecting" });
192
- })), l.push(f.on("error", () => {
193
- G(n, f) && t.setState({ connectionStatus: "error" });
194
- })), l.push(f.on("comment:resolved", (e) => {
195
- if (!G(n, f)) return;
196
- let r = z(e, t.getState().currentUser?.id);
197
- r && (i ? _(r.id, "comment:updated") : (K(t, r), t.emit("comment:resolved", r)));
198
- })), l.push(f.on("comment:completed", (e) => {
199
- if (!G(n, f)) return;
200
- let r = z(e, t.getState().currentUser?.id);
201
- r && (i ? _(r.id, "comment:updated") : (K(t, r), t.emit("comment:completed", r)));
202
- })), l.push(f.on("comment:created", (e) => {
203
- if (!G(n, f)) return;
204
- let r = z(e, t.getState().currentUser?.id);
205
- if (!r) return;
206
- if (i) {
207
- _(r.id, "comment:created");
208
- return;
209
- }
210
- let a = t.getState().activeBranch;
211
- a && r.branch !== a || t.getState().comments.find((e) => e.id === r.id) || (t.setState({ comments: [...t.getState().comments, r] }), t.emit("comment:created", r));
212
- })), l.push(f.on("comment:updated", (e) => {
213
- if (!G(n, f)) return;
214
- let r = z(e, t.getState().currentUser?.id);
215
- r && (i ? _(r.id, "comment:updated") : (K(t, r), t.emit("comment:updated", r)));
216
- })), l.push(f.on("comment:deleted", (e) => {
217
- if (!G(n, f) || !c(e) || !k(e.id)) return;
218
- let r = e.id.trim();
219
- t.setState({
220
- comments: t.getState().comments.filter((e) => e.id !== r),
221
- selectedComment: t.getState().selectedComment?.id === r ? null : t.getState().selectedComment
222
- }), t.emit("comment:deleted", { id: r });
223
- })), l.push(f.on("reply:added", (e) => {
224
- if (!G(n, f) || !c(e) || !k(e.commentId)) return;
225
- let r = B(e.reply, t.getState().currentUser?.id);
226
- if (!r) return;
227
- let a = e.commentId.trim();
228
- if (i) {
229
- _(a, "comment:updated");
230
- return;
231
- }
232
- let o = t.getState().comments.map((e) => e.id !== a || e.replies.some((e) => e.id === r.id) ? e : {
233
- ...e,
234
- status: "open",
235
- resolvedAt: void 0,
236
- completedAt: void 0,
237
- replies: [...e.replies, r]
238
- });
239
- t.setState({ comments: o });
240
- let s = o.find((e) => e.id === a);
241
- s && t.emit("comment:updated", s);
242
- }));
243
- let v = (e, t, n) => {
244
- let r = (e ?? []).filter((e) => U(e.emoji) && Number.isInteger(e.count) && e.count >= 0 && e.count <= y), i = r.findIndex((e) => e.emoji === t);
245
- if (i !== -1) {
246
- let e = r[i];
247
- r[i] = n ? {
248
- ...e,
249
- reacted: !0
250
- } : {
251
- ...e,
252
- count: Math.min(e.count + 1, y),
253
- reacted: e.reacted
254
- };
255
- } else r.push({
256
- emoji: t,
257
- count: 1,
258
- reacted: n
259
- });
260
- return r;
261
- }, w = (e, t, n) => (e ?? []).filter((e) => U(e.emoji) && Number.isInteger(e.count) && e.count > 0 && e.count <= y).map((e) => e.emoji === t ? {
262
- ...e,
263
- count: n ? e.count : e.count - 1,
264
- reacted: !n && e.reacted
265
- } : e).filter((e) => e.count > 0), T = (e, r) => {
266
- if (!G(n, f) || !c(e) || !k(e.commentId) || !U(e.emoji) || !k(e.userId)) return;
267
- let a = e.commentId.trim(), o = k(e.replyId) ? e.replyId.trim() : null, s = e.emoji.trim(), l = e.userId.trim() === t.getState().currentUser?.id;
268
- i ? _(a, "comment:updated") : t.setState({ comments: t.getState().comments.map((e) => e.id === a ? o === null ? {
269
- ...e,
270
- reactions: r(e.reactions, s, l)
271
- } : {
272
- ...e,
273
- replies: e.replies.map((e) => e.id === o ? {
274
- ...e,
275
- reactions: r(e.reactions, s, l)
276
- } : e)
277
- } : e) });
278
- };
279
- l.push(f.on("reaction:added", (e) => T(e, v))), l.push(f.on("reaction:removed", (e) => T(e, w)));
280
- let E = /* @__PURE__ */ new Map(), D = 0, O = 0;
281
- l.push(f.on("cursor:move", (e) => {
282
- if (!G(n, f) || !s.cursors) return;
283
- let r = V(e);
284
- if (!r) return;
285
- let i = Date.now(), a = r.user.id, o = E.get(a);
286
- if (o === void 0 && E.size >= s.maxRenderedCursors) {
287
- let e, t = Infinity;
288
- for (let [n, r] of E) r < t && (t = r, e = n);
289
- if (e !== void 0 && i - t >= b) E.delete(e);
290
- else return;
291
- }
292
- o !== void 0 && i - o < b || (i - D >= x && (D = i, O = 0), !(O >= S) && (O++, E.set(a, i), t.emit("cursor:move", r)));
293
- })), l.push(f.on("cursor:leave", (e) => {
294
- G(n, f) && c(e) && k(e.userId) && (E.delete(e.userId.trim()), t.emit("cursor:leave", { userId: e.userId.trim() }));
295
- })), l.push(f.on("user:joined", (r) => {
296
- let i = e(r);
297
- G(n, f) && j(i) && t.emit("user:joined", M(i));
298
- })), l.push(f.on("user:left", (e) => {
299
- G(n, f) && c(e) && k(e.userId) && t.emit("user:left", { userId: e.userId.trim() });
300
- })), l.push(f.on("presence:update", (e) => {
301
- if (!G(n, f) || !s.presence || !c(e)) return;
302
- let r = N(e.users);
303
- if (!r) return;
304
- let i = { users: r };
305
- t.setState({ onlineUsers: r }), t.emit("presence:update", i);
306
- })), l.push(f.on("drawing:stroke", (e) => {
307
- G(n, f) && c(e) && k(e.userId) && H(e.path) && t.emit("drawing:stroke", {
308
- userId: e.userId.trim(),
309
- path: structuredClone(e.path)
310
- });
311
- }));
312
- try {
313
- t.setState({ connectionStatus: "connecting" });
314
- let e = f.connect();
315
- e && typeof e.catch == "function" && e.catch((e) => {
316
- t.setState({ connectionStatus: "error" }), t.handleError(e);
317
- });
318
- } catch (e) {
319
- t.setState({ connectionStatus: "error" }), t.handleError(e);
320
- return;
321
- }
322
- /* v8 ignore next -- SSR guard unreachable in jsdom */
323
- typeof document < "u" && typeof window < "u" && s.cursors && (n.mouseMoveHandler = (e) => {
324
- if (t.getState().isOverlayVisible && n.wsManager?.isConnected()) {
325
- if (window.innerWidth <= 0 || window.innerHeight <= 0) return;
326
- 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));
327
- n.wsManager.sendCursorMove(t, r, d(u().url));
328
- }
329
- }, document.addEventListener("mousemove", n.mouseMoveHandler));
330
- }
331
- function J(e) {
332
- typeof window < "u" && typeof document < "u" && e.mouseMoveHandler && (document.removeEventListener("mousemove", e.mouseMoveHandler), e.mouseMoveHandler = null);
333
- }
334
- export { q as initializeWebSocket, J as removeMouseMoveListener };
@@ -1,162 +0,0 @@
1
- import { n as e } from "./request-activity-DQrAUwfA.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 && JSON.stringify(n.commentQuery) === JSON.stringify(t.getState().commentQuery), 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, t, n) {
18
- let r = t.comments.find((e) => e.id === n), i = r?.detailLoaded === !1 && t.selectedComment?.id !== n, a = i ? 1 : Math.max(50, r?.replies.length ?? 0), o = _(await e.apiClient.getComment(n, { repliesLimit: Math.min(100, a) }), t), s = o.repliesPagination?.nextCursor;
19
- for (; !i && s && o.replies.length < a && h(e, t);) {
20
- let r = _(await e.apiClient.getComment(n, {
21
- repliesLimit: Math.min(100, a - o.replies.length),
22
- repliesBefore: s
23
- }), t);
24
- o = {
25
- ...o,
26
- replies: [...r.replies, ...o.replies],
27
- repliesPagination: r.repliesPagination
28
- };
29
- let i = r.repliesPagination?.nextCursor;
30
- if (i === s) break;
31
- s = i;
32
- }
33
- return i ? {
34
- ...o,
35
- detailLoaded: !1,
36
- replies: []
37
- } : o;
38
- }
39
- async function S(e, n) {
40
- let r = Math.max(1, n.pagination?.page ?? 1), i = n.pagination?.limit ?? 50, a = /* @__PURE__ */ new Map(), o = n.pagination, s, l = n.commentQuery;
41
- for (let t = 1; t <= r; t++) {
42
- let r = await e.apiClient.getComments(l?.pagePath, l?.status ?? "all", t, i, void 0, n.activeBranch, {
43
- ...l,
44
- pagination: "cursor",
45
- view: "summary",
46
- cursor: s
47
- });
48
- if (!h(e, n)) return;
49
- if (!g(n)) {
50
- c = !0;
51
- return;
52
- }
53
- for (let e of r.comments) {
54
- let t = _(e, n);
55
- v(t, n) && a.set(t.id, t);
56
- }
57
- if (o = r.pagination, s = r.pagination.nextCursor, !o.hasMore) break;
58
- }
59
- let u = n.selectedComment?.id, d = u ? a.get(u) ?? null : null;
60
- if (u && (!d || d.detailLoaded === !1)) try {
61
- let t = await x(e, n, u);
62
- if (t.id !== u) throw Error("Invalid comment refresh response");
63
- v(t, n) && (d = t, a.set(t.id, t));
64
- } catch (e) {
65
- if (!y(e)) throw e;
66
- }
67
- if (!h(e, n)) return;
68
- if (!g(n)) {
69
- c = !0;
70
- return;
71
- }
72
- let f = t.getState();
73
- e.setState({
74
- comments: [...a.values()],
75
- pagination: o,
76
- ...f.selectedComment?.id === u ? { selectedComment: d } : {}
77
- });
78
- }
79
- async function C(e, n, r, i) {
80
- let a;
81
- try {
82
- if (a = await x(e, n, r), a.id !== r) throw Error("Invalid comment refresh response");
83
- } catch (e) {
84
- if (!y(e)) throw e;
85
- a = null;
86
- }
87
- if (!h(e, n)) return;
88
- if (!g(n)) {
89
- for (let e of i) E({
90
- commentId: r,
91
- event: e
92
- });
93
- return;
94
- }
95
- let o = t.getState(), s = o.comments.some((e) => e.id === r);
96
- if (a && !v(a, n)) return;
97
- let c = o.comments.filter((e) => e.id !== r);
98
- if (a && (s || i.has("comment:created"))) {
99
- let e = o.comments.findIndex((e) => e.id === r);
100
- c.splice(e < 0 ? c.length : e, 0, a);
101
- }
102
- if (e.setState({
103
- comments: c,
104
- ...o.selectedComment?.id === r ? { selectedComment: a } : {}
105
- }), !a) s && e.emit("comment:deleted", { id: r });
106
- else for (let t of i) (t !== "comment:created" || !s) && e.emit(t, a);
107
- }
108
- async function w() {
109
- if (s = !1, !p() || o || !c && !f.size) return;
110
- if (m()) {
111
- e(t.apiClient) && !l && (l = setTimeout(() => {
112
- l = void 0, T();
113
- }, 100));
114
- return;
115
- }
116
- o = !0;
117
- let r = n.capture(), i = t.getState(), a = c, g = a ? void 0 : f.entries().next().value, _ = a ? "window" : `thread:${g?.[0]}`;
118
- try {
119
- if (a) c = !1, await S(r, i);
120
- else if (g) {
121
- let [e, t] = g;
122
- f.delete(e), await C(r, i, e, t);
123
- }
124
- d.delete(_);
125
- } catch (e) {
126
- if (h(r, i)) {
127
- let t = d.get(_) ?? 0;
128
- b(e) && t < 2 ? (d.set(_, t + 1), u = setTimeout(() => {
129
- if (u = void 0, h(r, i)) {
130
- if (a) c = !0;
131
- else if (g) for (let e of g[1]) E({
132
- commentId: g[0],
133
- event: e
134
- });
135
- } else d.delete(_);
136
- T();
137
- }, 1e3 * 2 ** t)) : (d.delete(_), r.handleError(e));
138
- }
139
- } finally {
140
- o = !1, T();
141
- }
142
- }
143
- function T() {
144
- !p() || s || o || u || !c && !f.size || (s = !0, Promise.resolve().then(w));
145
- }
146
- function E({ commentId: e, event: t }) {
147
- if (!p()) return;
148
- let n = f.get(e) ?? /* @__PURE__ */ new Set();
149
- n.add(t), f.size < 256 || f.has(e) ? f.set(e, n) : c = !0, T();
150
- }
151
- let D = n.subscribe(T);
152
- return {
153
- refreshThread: E,
154
- refreshWindow() {
155
- p() && (c = !0, T());
156
- },
157
- dispose() {
158
- a = !0, l && clearTimeout(l), u && clearTimeout(u), d.clear(), f.clear(), D();
159
- }
160
- };
161
- }
162
- export { t as createRealtimeRecovery };
@@ -1,11 +0,0 @@
1
- var e = /* @__PURE__ */ new WeakMap();
2
- function t(t) {
3
- return (e.get(t) ?? 0) > 0;
4
- }
5
- function n(t) {
6
- return e.set(t, (e.get(t) ?? 0) + 1), () => {
7
- let n = (e.get(t) ?? 1) - 1;
8
- n ? e.set(t, n) : e.delete(t);
9
- };
10
- }
11
- export { t as n, n as t };