@nivaro/react 0.3.128 → 0.3.129

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.
@@ -1,95 +1,118 @@
1
- import { jsxs as n, jsx as e, Fragment as O } from "react/jsx-runtime";
2
- import { useState as o, useRef as D, useEffect as k, useCallback as P } from "react";
3
- import { get as $, post as V, del as A, patch as F } from "../../lib/commands.js";
4
- import { useOptionalNivaroClient as G } from "../../shared/context.js";
5
- function J(r) {
6
- var d, l, i, a;
7
- return r && ([(d = r.first_name) == null ? void 0 : d[0], (l = r.last_name) == null ? void 0 : l[0]].filter(Boolean).join("").toUpperCase() || ((a = (i = r.email) == null ? void 0 : i[0]) == null ? void 0 : a.toUpperCase())) || "?";
1
+ import { jsxs as n, jsx as e, Fragment as A } from "react/jsx-runtime";
2
+ import { useState as o, useRef as D, useEffect as b, useCallback as F } from "react";
3
+ import { get as k, post as J, del as K, patch as Q } from "../../lib/commands.js";
4
+ import { useOptionalNivaroClient as X } from "../../shared/context.js";
5
+ function Y(a) {
6
+ var i, s, d, r;
7
+ return a && ([(i = a.first_name) == null ? void 0 : i[0], (s = a.last_name) == null ? void 0 : s[0]].filter(Boolean).join("").toUpperCase() || ((r = (d = a.email) == null ? void 0 : d[0]) == null ? void 0 : r.toUpperCase())) || "?";
8
8
  }
9
- function K(r) {
10
- return r ? [r.first_name, r.last_name].filter(Boolean).join(" ") || r.email : "Unknown";
9
+ function Z(a) {
10
+ return a ? [a.first_name, a.last_name].filter(Boolean).join(" ") || a.email : "Unknown";
11
11
  }
12
- function Q(r) {
13
- const d = Date.now() - new Date(r).getTime(), l = Math.floor(d / 6e4);
14
- if (l < 1) return "just now";
15
- if (l < 60) return `${l}m ago`;
16
- const i = Math.floor(l / 60);
17
- return i < 24 ? `${i}h ago` : `${Math.floor(i / 24)}d ago`;
12
+ function I(a) {
13
+ const i = Date.now() - new Date(a).getTime(), s = Math.floor(i / 6e4);
14
+ if (s < 1) return "just now";
15
+ if (s < 60) return `${s}m ago`;
16
+ const d = Math.floor(s / 60);
17
+ return d < 24 ? `${d}h ago` : `${Math.floor(d / 24)}d ago`;
18
18
  }
19
- function et({
20
- collection: r,
21
- itemId: d,
22
- labelOverride: l,
23
- defaultExpanded: i
19
+ function at({
20
+ collection: a,
21
+ itemId: i,
22
+ labelOverride: s,
23
+ defaultExpanded: d
24
24
  }) {
25
- const a = G(), [f, w] = o(!1), [u, C] = o([]), [q, x] = o(!1), [h, _] = o(""), [g, L] = o(!1), [U, b] = o(null), [p, v] = o(""), [M, j] = o(null), [S, E] = o(null), [W, H] = o(!1), s = D(!0), B = D(!1);
26
- k(() => (s.current = !0, () => {
27
- s.current = !1;
28
- }), []), k(() => {
29
- !B.current && i !== void 0 && (B.current = !0, w(i));
30
- }, [i]);
31
- const m = P(async () => {
32
- if (!(!a || !d)) {
33
- x(!0);
25
+ const r = X(), [u, x] = o(!1), [f, _] = o([]), [G, L] = o(!1), [p, M] = o(""), [w, S] = o(!1), [U, C] = o(null), [v, y] = o(""), [j, $] = o(null), [q, E] = o(null), [T, H] = o(!1), l = D(!0), W = D(!1);
26
+ b(() => (l.current = !0, () => {
27
+ l.current = !1;
28
+ }), []), b(() => {
29
+ !W.current && d !== void 0 && (W.current = !0, x(d));
30
+ }, [d]);
31
+ const h = F(async () => {
32
+ if (!(!r || !i)) {
33
+ L(!0);
34
34
  try {
35
- const t = await a.request(
36
- $("/comments", { collection: r, item: String(d) })
35
+ const t = await r.request(
36
+ k("/comments", { collection: a, item: String(i) })
37
37
  );
38
- s.current && C(t.data ?? []);
38
+ l.current && _(t.data ?? []);
39
39
  } catch {
40
- s.current && C([]);
40
+ l.current && _([]);
41
41
  } finally {
42
- s.current && x(!1);
42
+ l.current && L(!1);
43
43
  }
44
44
  }
45
- }, [a, r, d]);
46
- k(() => {
47
- m();
48
- }, [m]);
49
- async function T(t) {
50
- if (t.preventDefault(), !(!a || !h.trim() || g)) {
51
- L(!0);
45
+ }, [r, a, i]);
46
+ b(() => {
47
+ h();
48
+ }, [h]);
49
+ const [N, R] = o(!1);
50
+ b(() => {
51
+ if (!u || !r || !i) return;
52
+ let t = !0;
53
+ return (async () => {
54
+ var c;
52
55
  try {
53
- await a.request(
54
- V("/comments", { collection: r, item: String(d), text: h.trim() })
55
- ), _(""), await m();
56
+ if (!((c = (await r.request(
57
+ k("/trackers/feature/public")
58
+ )).data) != null && c.enabled)) return;
59
+ const g = await r.request(
60
+ k("/trackers/links/for", {
61
+ source_kind: "record",
62
+ source_id: `${a}:${i}`
63
+ })
64
+ );
65
+ t && R((g.data ?? []).length > 0);
66
+ } catch {
67
+ }
68
+ })(), () => {
69
+ t = !1;
70
+ };
71
+ }, [u, r, a, i]);
72
+ async function z(t) {
73
+ if (t.preventDefault(), !(!r || !p.trim() || w)) {
74
+ S(!0);
75
+ try {
76
+ await r.request(
77
+ J("/comments", { collection: a, item: String(i), text: p.trim() })
78
+ ), M(""), await h();
56
79
  } catch {
57
80
  } finally {
58
- s.current && L(!1);
81
+ l.current && S(!1);
59
82
  }
60
83
  }
61
84
  }
62
- async function N(t) {
63
- if (!(!a || !p.trim()))
85
+ async function O(t) {
86
+ if (!(!r || !v.trim()))
64
87
  try {
65
- await a.request(F(`/comments/${t}`, { text: p.trim() })), b(null), v(""), await m();
88
+ await r.request(Q(`/comments/${t}`, { text: v.trim() })), C(null), y(""), await h();
66
89
  } catch {
67
90
  }
68
91
  }
69
- async function R(t) {
70
- if (a) {
71
- if (M === t) {
72
- j(null);
92
+ async function P(t) {
93
+ if (r) {
94
+ if (j === t) {
95
+ $(null);
73
96
  return;
74
97
  }
75
- j(t), E(null), H(!1);
98
+ $(t), E(null), H(!1);
76
99
  try {
77
- const y = await a.request($(`/comments/${t}/history`));
78
- s.current && E(y.data ?? []);
100
+ const c = await r.request(k(`/comments/${t}/history`));
101
+ l.current && E(c.data ?? []);
79
102
  } catch {
80
- s.current && H(!0);
103
+ l.current && H(!0);
81
104
  }
82
105
  }
83
106
  }
84
- async function z(t) {
85
- if (a)
107
+ async function V(t) {
108
+ if (r)
86
109
  try {
87
- await a.request(A(`/comments/${t}`)), await m();
110
+ await r.request(K(`/comments/${t}`)), await h();
88
111
  } catch {
89
112
  }
90
113
  }
91
- return /* @__PURE__ */ n("div", { "data-nf-slot": "__comments__", "data-nf-slot-open": f ? "true" : "false", children: [
92
- /* @__PURE__ */ n("button", { type: "button", onClick: () => w((t) => !t), "data-nf-slot-toggle": !0, children: [
114
+ return /* @__PURE__ */ n("div", { "data-nf-slot": "__comments__", "data-nf-slot-open": u ? "true" : "false", children: [
115
+ /* @__PURE__ */ n("button", { type: "button", onClick: () => x((t) => !t), "data-nf-slot-toggle": !0, children: [
93
116
  /* @__PURE__ */ e(
94
117
  "svg",
95
118
  {
@@ -106,11 +129,11 @@ function et({
106
129
  children: /* @__PURE__ */ e("path", { d: "M21 15a2 2 0 0 1-2 2H7l-4 4V5a2 2 0 0 1 2-2h14a2 2 0 0 1 2 2z" })
107
130
  }
108
131
  ),
109
- /* @__PURE__ */ e("span", { "data-nf-slot-label": !0, children: l ?? "Comments" }),
110
- !f && u.some((t) => !t.deleted) && /* @__PURE__ */ n("span", { "data-nf-slot-count": !0, children: [
111
- u.filter((t) => !t.deleted).length,
132
+ /* @__PURE__ */ e("span", { "data-nf-slot-label": !0, children: s ?? "Comments" }),
133
+ !u && f.some((t) => !t.deleted) && /* @__PURE__ */ n("span", { "data-nf-slot-count": !0, children: [
134
+ f.filter((t) => !t.deleted).length,
112
135
  " comment",
113
- u.filter((t) => !t.deleted).length !== 1 ? "s" : ""
136
+ f.filter((t) => !t.deleted).length !== 1 ? "s" : ""
114
137
  ] }),
115
138
  /* @__PURE__ */ e(
116
139
  "svg",
@@ -124,19 +147,20 @@ function et({
124
147
  strokeWidth: "2",
125
148
  strokeLinecap: "round",
126
149
  strokeLinejoin: "round",
127
- style: { transform: f ? "rotate(180deg)" : void 0 },
150
+ style: { transform: u ? "rotate(180deg)" : void 0 },
128
151
  "aria-hidden": "true",
129
152
  children: /* @__PURE__ */ e("polyline", { points: "6 9 12 15 18 9" })
130
153
  }
131
154
  )
132
155
  ] }),
133
- f && /* @__PURE__ */ n("div", { "data-nf-slot-content": !0, children: [
134
- /* @__PURE__ */ n("form", { onSubmit: (t) => void T(t), "data-nf-comment-form": !0, children: [
156
+ u && /* @__PURE__ */ n("div", { "data-nf-slot-content": !0, children: [
157
+ /* @__PURE__ */ n("form", { onSubmit: (t) => void z(t), "data-nf-comment-form": !0, children: [
158
+ N && /* @__PURE__ */ e("p", { "data-nf-comment-hint": !0, "data-nf-comment-gitlab-shared": !0, children: "Comments here are shared with GitLab." }),
135
159
  /* @__PURE__ */ e(
136
160
  "textarea",
137
161
  {
138
- value: h,
139
- onChange: (t) => _(t.target.value),
162
+ value: p,
163
+ onChange: (t) => M(t.target.value),
140
164
  placeholder: "Write a comment…",
141
165
  rows: 3,
142
166
  "data-nf-comment-textarea": !0
@@ -144,29 +168,34 @@ function et({
144
168
  ),
145
169
  /* @__PURE__ */ n("div", { "data-nf-comment-form-footer": !0, children: [
146
170
  /* @__PURE__ */ e("span", { "data-nf-comment-hint": !0, children: "Use @ to mention a teammate." }),
147
- /* @__PURE__ */ e("button", { type: "submit", "data-nf-btn-primary": !0, disabled: !h.trim() || g, children: g ? "Posting…" : "Comment" })
171
+ /* @__PURE__ */ e("button", { type: "submit", "data-nf-btn-primary": !0, disabled: !p.trim() || w, children: w ? "Posting…" : "Comment" })
148
172
  ] })
149
173
  ] }),
150
174
  /* @__PURE__ */ e("div", { "data-nf-divider": !0 }),
151
- q ? /* @__PURE__ */ e("div", { "data-nf-comment-list": !0, children: [0, 1].map((t) => /* @__PURE__ */ n("div", { "data-nf-comment-skeleton": !0, children: [
175
+ G ? /* @__PURE__ */ e("div", { "data-nf-comment-list": !0, children: [0, 1].map((t) => /* @__PURE__ */ n("div", { "data-nf-comment-skeleton": !0, children: [
152
176
  /* @__PURE__ */ e("div", { "data-nf-skeleton-avatar": !0 }),
153
177
  /* @__PURE__ */ n("div", { "data-nf-skeleton-lines": !0, children: [
154
178
  /* @__PURE__ */ e("div", { "data-nf-skeleton-line": !0, style: { width: "30%" } }),
155
179
  /* @__PURE__ */ e("div", { "data-nf-skeleton-line": !0, style: { width: "100%" } })
156
180
  ] })
157
- ] }, t)) }) : u.length === 0 ? /* @__PURE__ */ e("p", { "data-nf-empty": !0, children: "No comments yet." }) : /* @__PURE__ */ e("div", { "data-nf-comment-list": !0, children: [...u].reverse().map((t) => {
158
- const y = U === t.id;
181
+ ] }, t)) }) : f.length === 0 ? /* @__PURE__ */ e("p", { "data-nf-empty": !0, children: "No comments yet." }) : /* @__PURE__ */ e("div", { "data-nf-comment-list": !0, children: [...f].reverse().map((t) => {
182
+ var g;
183
+ const c = U === t.id;
159
184
  if (t.deleted)
160
185
  return /* @__PURE__ */ e("div", { "data-nf-comment": !0, "data-nf-comment-deleted": !0, children: /* @__PURE__ */ e("div", { "data-nf-comment-body": !0, children: /* @__PURE__ */ e("p", { "data-nf-comment-text": !0, children: /* @__PURE__ */ n("em", { children: [
161
186
  "Comment deleted by ",
162
187
  t.deleted_by_name ?? "unknown"
163
188
  ] }) }) }) }, t.id);
164
- const I = !!t.edited;
189
+ const B = !!t.edited;
165
190
  return /* @__PURE__ */ n("div", { "data-nf-comment": !0, children: [
166
- /* @__PURE__ */ e("div", { "data-nf-avatar": !0, children: J(t.user) }),
191
+ /* @__PURE__ */ e("div", { "data-nf-avatar": !0, children: Y(t.user) }),
167
192
  /* @__PURE__ */ n("div", { "data-nf-comment-body": !0, children: [
168
193
  /* @__PURE__ */ n("div", { "data-nf-comment-header": !0, children: [
169
- /* @__PURE__ */ e("span", { "data-nf-comment-author": !0, children: K(t.user) }),
194
+ t.tracker ? /* @__PURE__ */ n("span", { "data-nf-comment-author": !0, "data-nf-comment-gitlab": !0, children: [
195
+ /* @__PURE__ */ e("span", { "data-nf-comment-gitlab-badge": !0, children: "GitLab" }),
196
+ " ",
197
+ ((g = t.tracker.author) == null ? void 0 : g.trim()) || "Someone on GitLab"
198
+ ] }) : /* @__PURE__ */ e("span", { "data-nf-comment-author": !0, children: Z(t.user) }),
170
199
  t.via_agent && /* @__PURE__ */ e(
171
200
  "span",
172
201
  {
@@ -175,18 +204,18 @@ function et({
175
204
  children: t.via_agent
176
205
  }
177
206
  ),
178
- /* @__PURE__ */ e("span", { "data-nf-comment-time": !0, children: Q(t.created_at) }),
179
- I && /* @__PURE__ */ e(
207
+ /* @__PURE__ */ e("span", { "data-nf-comment-time": !0, children: I(t.created_at) }),
208
+ B && /* @__PURE__ */ e(
180
209
  "button",
181
210
  {
182
211
  type: "button",
183
212
  "data-nf-comment-edited": !0,
184
213
  title: "Show earlier versions",
185
- onClick: () => void R(t.id),
214
+ onClick: () => void P(t.id),
186
215
  children: "(edited)"
187
216
  }
188
217
  ),
189
- /* @__PURE__ */ e("div", { "data-nf-comment-actions": !0, children: !y && /* @__PURE__ */ n(O, { children: [
218
+ /* @__PURE__ */ e("div", { "data-nf-comment-actions": !0, children: !c && /* @__PURE__ */ n(A, { children: [
190
219
  /* @__PURE__ */ e(
191
220
  "button",
192
221
  {
@@ -194,7 +223,7 @@ function et({
194
223
  "data-nf-icon-btn": !0,
195
224
  title: "Edit",
196
225
  onClick: () => {
197
- b(t.id), v(t.text);
226
+ C(t.id), y(t.text);
198
227
  },
199
228
  children: /* @__PURE__ */ n(
200
229
  "svg",
@@ -223,7 +252,7 @@ function et({
223
252
  "data-nf-icon-btn": !0,
224
253
  "data-nf-icon-btn-danger": !0,
225
254
  title: "Delete",
226
- onClick: () => void z(t.id),
255
+ onClick: () => void V(t.id),
227
256
  children: /* @__PURE__ */ n(
228
257
  "svg",
229
258
  {
@@ -247,12 +276,12 @@ function et({
247
276
  )
248
277
  ] }) })
249
278
  ] }),
250
- y ? /* @__PURE__ */ n("div", { "data-nf-comment-edit": !0, children: [
279
+ c ? /* @__PURE__ */ n("div", { "data-nf-comment-edit": !0, children: [
251
280
  /* @__PURE__ */ e(
252
281
  "textarea",
253
282
  {
254
- value: p,
255
- onChange: (c) => v(c.target.value),
283
+ value: v,
284
+ onChange: (m) => y(m.target.value),
256
285
  rows: 3,
257
286
  "data-nf-comment-textarea": !0
258
287
  }
@@ -263,8 +292,8 @@ function et({
263
292
  {
264
293
  type: "button",
265
294
  "data-nf-btn-primary": !0,
266
- disabled: !p.trim(),
267
- onClick: () => void N(t.id),
295
+ disabled: !v.trim(),
296
+ onClick: () => void O(t.id),
268
297
  children: "✓ Save"
269
298
  }
270
299
  ),
@@ -274,21 +303,21 @@ function et({
274
303
  type: "button",
275
304
  "data-nf-btn-ghost": !0,
276
305
  onClick: () => {
277
- b(null), v("");
306
+ C(null), y("");
278
307
  },
279
308
  children: "✕ Cancel"
280
309
  }
281
310
  )
282
311
  ] })
283
312
  ] }) : /* @__PURE__ */ e("p", { "data-nf-comment-text": !0, children: t.text }),
284
- M === t.id && /* @__PURE__ */ e("div", { "data-nf-comment-history": !0, role: "menu", children: W ? /* @__PURE__ */ e("p", { "data-nf-empty": !0, children: "Edit history isn't available to you." }) : S === null ? /* @__PURE__ */ e("p", { "data-nf-empty": !0, children: "Loading…" }) : S.map((c) => /* @__PURE__ */ n("div", { "data-nf-comment-version": !0, role: "menuitem", children: [
313
+ j === t.id && /* @__PURE__ */ e("div", { "data-nf-comment-history": !0, role: "menu", children: T ? /* @__PURE__ */ e("p", { "data-nf-empty": !0, children: "Edit history isn't available to you." }) : q === null ? /* @__PURE__ */ e("p", { "data-nf-empty": !0, children: "Loading…" }) : q.map((m) => /* @__PURE__ */ n("div", { "data-nf-comment-version": !0, role: "menuitem", children: [
285
314
  /* @__PURE__ */ n("div", { children: [
286
- /* @__PURE__ */ e("span", { "data-nf-comment-author": !0, children: c.user_name ?? "Unknown" }),
315
+ /* @__PURE__ */ e("span", { "data-nf-comment-author": !0, children: m.user_name ?? "Unknown" }),
287
316
  " ",
288
- /* @__PURE__ */ e("span", { "data-nf-comment-time": !0, children: new Date(c.created_at).toLocaleString() })
317
+ /* @__PURE__ */ e("span", { "data-nf-comment-time": !0, children: new Date(m.created_at).toLocaleString() })
289
318
  ] }),
290
- /* @__PURE__ */ e("p", { "data-nf-comment-text": !0, children: c.text })
291
- ] }, c.version)) })
319
+ /* @__PURE__ */ e("p", { "data-nf-comment-text": !0, children: m.text })
320
+ ] }, m.version)) })
292
321
  ] })
293
322
  ] }, t.id);
294
323
  }) })
@@ -296,5 +325,5 @@ function et({
296
325
  ] });
297
326
  }
298
327
  export {
299
- et as CommentsSlot
328
+ at as CommentsSlot
300
329
  };