@parallelworks/tandem-web 0.179.2 → 0.181.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.
@@ -1,27 +1,28 @@
1
1
  import { api as e, unwrap as t } from "../api/client.js";
2
2
  import { docQuery as n, docsQuery as r, knowledgeQuery as i, membersQuery as a, teamsQuery as o } from "../api/queries.js";
3
- import { docLooks as s } from "../lib/docLooks.js";
4
- import { docKey as c, docRef as l } from "../lib/docs.js";
5
- import { glossary as u, headingAnchor as d } from "../lib/glossary.js";
6
- import { issueRefs as f } from "../lib/issueRefs.js";
7
- import { useTermRefs as p } from "../lib/knowledge.js";
8
- import { termRef as m } from "../lib/knowledgeKinds.js";
9
- import { mentionable as h } from "../lib/mentions.js";
10
- import { Link as g, useNavigate as _ } from "../lib/router.js";
11
- import { teamNames as v } from "../lib/teamNames.js";
12
- import { DocIcon as y } from "./DocIcon.js";
13
- import { termCaretEvent as b } from "./editorPlugins.js";
14
- import { FileTextIcon as x } from "./icons.js";
15
- import { PersonCard as S } from "./PersonHoverCard.js";
16
- import { HoverCard as C, Loader as w } from "@parallelworks/ui";
17
- import { useEffect as T, useRef as E, useState as D } from "react";
18
- import { useTranslations as O } from "use-intl";
19
- import { Fragment as k, jsx as A, jsxs as j } from "react/jsx-runtime";
20
- import { useQuery as M, useQueryClient as N } from "@tanstack/react-query";
3
+ import { appPath as s } from "../lib/base.js";
4
+ import { docLooks as c } from "../lib/docLooks.js";
5
+ import { docKey as l, docRef as u } from "../lib/docs.js";
6
+ import { glossary as d, headingAnchor as f } from "../lib/glossary.js";
7
+ import { issueRefs as p } from "../lib/issueRefs.js";
8
+ import { useTermRefs as m } from "../lib/knowledge.js";
9
+ import { termRef as h } from "../lib/knowledgeKinds.js";
10
+ import { mentionable as g } from "../lib/mentions.js";
11
+ import { Link as _, useNavigate as v } from "../lib/router.js";
12
+ import { teamNames as y } from "../lib/teamNames.js";
13
+ import { DocIcon as b } from "./DocIcon.js";
14
+ import { termCaretEvent as x } from "./editorPlugins.js";
15
+ import { FileTextIcon as S } from "./icons.js";
16
+ import { PersonCard as C } from "./PersonHoverCard.js";
17
+ import { HoverCard as w, Loader as T } from "@parallelworks/ui";
18
+ import { useEffect as E, useRef as D, useState as O } from "react";
19
+ import { useTranslations as k } from "use-intl";
20
+ import { Fragment as A, jsx as j, jsxs as M } from "react/jsx-runtime";
21
+ import { useQuery as N, useQueryClient as P } from "@tanstack/react-query";
21
22
  // src/components/HoverCards.tsx
22
- var P = ".kb-term, .person-mention, .prose-issue a[href*=\"/docs/\"]", F = 300, I = 200;
23
- function L(e) {
24
- let t = e?.closest(P);
23
+ var F = ".kb-term, .person-mention, .prose-issue a[href*=\"/docs/\"]", I = 300, L = 200;
24
+ function R(e) {
25
+ let t = e?.closest(F);
25
26
  if (!t) return null;
26
27
  if (t.classList.contains("kb-term")) {
27
28
  let e = t.dataset.term;
@@ -43,79 +44,88 @@ function L(e) {
43
44
  return r?.[1] ? {
44
45
  kind: "doc",
45
46
  el: t,
46
- key: c(r[1])
47
+ key: l(r[1])
47
48
  } : null;
48
49
  }
49
- function R({ workspace: n }) {
50
- let [c, l] = D(null), d = E(null), p = E(void 0), { data: g } = M(i(n)), y = _(), x = E((e) => {});
51
- x.current = (e) => {
52
- let t = g?.find((t) => t.id === e);
53
- y({
50
+ function z(e) {
51
+ if (!e.closest(".ProseMirror")) return null;
52
+ let t = new URL(e.getAttribute("href") ?? "", location.href);
53
+ if (t.origin !== location.origin) return null;
54
+ let n = s(t.pathname);
55
+ return /^\/[^/]+\/docs\/(?!space\/)[^/]+\/?$/.test(n) ? n + t.hash : null;
56
+ }
57
+ function B({ workspace: n }) {
58
+ let [s, l] = O(null), u = D(null), f = D(void 0), { data: m } = N(i(n)), _ = v(), b = D((e) => {});
59
+ b.current = (e) => {
60
+ let t = m?.find((t) => t.id === e);
61
+ _({
54
62
  to: "/$workspace/knowledge/$term",
55
63
  params: {
56
64
  workspace: n,
57
- term: t ? m(t) : e
65
+ term: t ? h(t) : e
58
66
  }
59
67
  });
60
- }, T(() => {
61
- u.set(g ?? []);
62
- }, [g]), T(() => () => u.set([]), []);
63
- let { data: w } = M(r(n));
64
- T(() => {
65
- s.set(w ?? []);
66
- }, [w]), T(() => () => s.set([]), []);
67
- let { data: O } = M(a(n));
68
- T(() => {
69
- h.set((O ?? []).map((e) => e.user.username));
70
- }, [O]), T(() => () => h.set([]), []);
71
- let { data: k } = M(o(n));
72
- T(() => {
73
- v.set(k ?? []);
74
- }, [k]), T(() => () => v.set([]), []);
75
- let j = N();
76
- T(() => {
77
- f.set(n, async (r) => {
68
+ }, E(() => {
69
+ d.set(m ?? []);
70
+ }, [m]), E(() => () => d.set([]), []);
71
+ let { data: S } = N(r(n));
72
+ E(() => {
73
+ c.set(S ?? []);
74
+ }, [S]), E(() => () => c.set([]), []);
75
+ let { data: T } = N(a(n));
76
+ E(() => {
77
+ g.set((T ?? []).map((e) => e.user.username));
78
+ }, [T]), E(() => () => g.set([]), []);
79
+ let { data: k } = N(o(n));
80
+ E(() => {
81
+ y.set(k ?? []);
82
+ }, [k]), E(() => () => y.set([]), []);
83
+ let A = P();
84
+ E(() => {
85
+ p.set(n, async (r) => {
78
86
  let { issues: i } = t(await e.POST("/api/v1/workspaces/{workspace}/issue-refs", {
79
87
  params: { path: { workspace: n } },
80
88
  body: { identifiers: r }
81
89
  }));
82
90
  return new Map(i.map((e) => [e.identifier, e.issue]));
83
91
  });
84
- let r, i = j.getQueryCache().subscribe((e) => {
85
- e.type === "updated" && e.query.queryKey[2] === "issues" && (clearTimeout(r), r = setTimeout(() => f.refresh(), 1e3));
92
+ let r, i = A.getQueryCache().subscribe((e) => {
93
+ e.type === "updated" && e.query.queryKey[2] === "issues" && (clearTimeout(r), r = setTimeout(() => p.refresh(), 1e3));
86
94
  });
87
95
  return () => {
88
- clearTimeout(r), i(), f.set("", void 0);
96
+ clearTimeout(r), i(), p.set("", void 0);
89
97
  };
90
- }, [n, j]);
91
- let P = E((e) => {});
92
- P.current = (e) => y({
98
+ }, [n, A]);
99
+ let M = D((e) => {});
100
+ M.current = (e) => _({
93
101
  to: "/$workspace/issues/$identifier",
94
102
  params: {
95
103
  workspace: n,
96
104
  identifier: e
97
105
  }
98
106
  });
99
- let R = E((e) => {});
100
- R.current = (e) => y({
107
+ let F = D((e) => {});
108
+ F.current = (e) => _({ href: e });
109
+ let B = D((e) => {});
110
+ B.current = (e) => _({
101
111
  to: "/$workspace/teams/$key/issues",
102
112
  params: {
103
113
  workspace: n,
104
114
  key: e
105
115
  }
106
- }), T(() => {
116
+ }), E(() => {
107
117
  let e = (e, t) => {
108
- clearTimeout(p.current), p.current = setTimeout(e, t);
118
+ clearTimeout(f.current), f.current = setTimeout(e, t);
109
119
  }, t = (t) => {
110
120
  if (t.pointerType === "touch") return;
111
- let n = L(t.target);
112
- n && e(() => l(n), F);
121
+ let n = R(t.target);
122
+ n && e(() => l(n), I);
113
123
  }, n = (t) => {
114
124
  let n = t.relatedTarget;
115
- n && d.current?.contains(n) || L(t.target) && e(() => l(null), I);
125
+ n && u.current?.contains(n) || R(t.target) && e(() => l(null), L);
116
126
  }, r = (e) => {
117
- let t = L(e.target);
118
- t && (clearTimeout(p.current), l(t));
127
+ let t = R(e.target);
128
+ t && (clearTimeout(f.current), l(t));
119
129
  }, i = (e) => {
120
130
  e.target.matches?.(".kb-term[tabindex], .prose-issue a[href*=\"/docs/\"]") && r(e);
121
131
  }, a = (e) => {
@@ -126,96 +136,101 @@ function R({ workspace: n }) {
126
136
  return;
127
137
  }
128
138
  if (!t.closest("[contenteditable=\"true\"]")) {
129
- e.preventDefault(), P.current(n);
139
+ e.preventDefault(), M.current(n);
130
140
  return;
131
141
  }
132
142
  }
133
- let a = e.target.closest?.(".team-mention"), o = a?.dataset.team;
134
- if (a && o && (!a.closest("[contenteditable=\"true\"]") || e.metaKey || e.ctrlKey)) {
135
- e.preventDefault(), R.current(o);
143
+ let a = e.target.closest?.("a[href]"), o = a && e.button === 0 ? z(a) : null;
144
+ if (a && o) {
145
+ e.preventDefault(), l(null), e.metaKey || e.ctrlKey || e.shiftKey ? window.open(a.href, "_blank", "noopener") : F.current(o);
146
+ return;
147
+ }
148
+ let s = e.target.closest?.(".team-mention"), c = s?.dataset.team;
149
+ if (s && c && (!s.closest("[contenteditable=\"true\"]") || e.metaKey || e.ctrlKey)) {
150
+ e.preventDefault(), B.current(c);
136
151
  return;
137
152
  }
138
- let s = e.target.closest?.(".kb-term");
139
- if (!s) return;
140
- let c = s.dataset.term;
141
- c && (!s.closest("[contenteditable=\"true\"]") || e.metaKey || e.ctrlKey) ? (e.preventDefault(), l(null), x.current(c)) : r(e);
153
+ let u = e.target.closest?.(".kb-term");
154
+ if (!u) return;
155
+ let d = u.dataset.term;
156
+ d && (!u.closest("[contenteditable=\"true\"]") || e.metaKey || e.ctrlKey) ? (e.preventDefault(), l(null), b.current(d)) : r(e);
142
157
  }, o = (e) => {
143
158
  if (e.button !== 1) return;
144
- let t = e.target.closest?.("a.issue-mention[href]");
145
- t?.closest("[contenteditable=\"true\"]") && (e.preventDefault(), window.open(t.href, "_blank", "noopener"));
159
+ let t = e.target.closest?.("a[href]");
160
+ t?.closest("[contenteditable=\"true\"]") && (t.classList.contains("issue-mention") || z(t)) && (e.preventDefault(), window.open(t.href, "_blank", "noopener"));
146
161
  }, s = (e) => {
147
- e.key === "Escape" && d.current?.isConnected && (e.stopPropagation(), e.preventDefault(), l((e) => (e?.el.tabIndex === 0 && e.el.focus(), null)));
162
+ e.key === "Escape" && u.current?.isConnected && (e.stopPropagation(), e.preventDefault(), l((e) => (e?.el.tabIndex === 0 && e.el.focus(), null)));
148
163
  };
149
- return document.addEventListener("pointerover", t), document.addEventListener("pointerout", n), document.addEventListener("focusin", i), document.addEventListener("click", a), document.addEventListener("auxclick", o), document.addEventListener(b, r), document.addEventListener("keydown", s, !0), () => {
150
- clearTimeout(p.current), document.removeEventListener("pointerover", t), document.removeEventListener("pointerout", n), document.removeEventListener("focusin", i), document.removeEventListener("click", a), document.removeEventListener("auxclick", o), document.removeEventListener(b, r), document.removeEventListener("keydown", s, !0);
164
+ return document.addEventListener("pointerover", t), document.addEventListener("pointerout", n), document.addEventListener("focusin", i), document.addEventListener("click", a), document.addEventListener("auxclick", o), document.addEventListener(x, r), document.addEventListener("keydown", s, !0), () => {
165
+ clearTimeout(f.current), document.removeEventListener("pointerover", t), document.removeEventListener("pointerout", n), document.removeEventListener("focusin", i), document.removeEventListener("click", a), document.removeEventListener("auxclick", o), document.removeEventListener(x, r), document.removeEventListener("keydown", s, !0);
151
166
  };
152
- }, []), T(() => {
153
- if (!c) return;
167
+ }, []), E(() => {
168
+ if (!s) return;
154
169
  let e = (e) => {
155
170
  let t = e.target;
156
- !d.current?.contains(t) && !c.el.contains(t) && l(null);
171
+ !u.current?.contains(t) && !s.el.contains(t) && l(null);
157
172
  };
158
173
  return document.addEventListener("pointerdown", e), () => document.removeEventListener("pointerdown", e);
159
- }, [c]);
160
- let B = c?.el.isConnected ? c : null;
161
- return /* @__PURE__ */ A(C, {
162
- at: B?.el ?? null,
163
- open: !!B,
174
+ }, [s]);
175
+ let H = s?.el.isConnected ? s : null;
176
+ return /* @__PURE__ */ j(w, {
177
+ at: H?.el ?? null,
178
+ open: !!H,
164
179
  onOpenChange: (e) => {
165
180
  e || l(null);
166
181
  },
167
- onPointerEnter: () => clearTimeout(p.current),
182
+ onPointerEnter: () => clearTimeout(f.current),
168
183
  onPointerLeave: () => {
169
- clearTimeout(p.current), p.current = setTimeout(() => l(null), I);
184
+ clearTimeout(f.current), f.current = setTimeout(() => l(null), L);
170
185
  },
171
- card: B && /* @__PURE__ */ A("div", {
172
- ref: d,
186
+ card: H && /* @__PURE__ */ j("div", {
187
+ ref: u,
173
188
  role: "dialog",
174
- "aria-label": B.kind === "doc" ? B.key : B.kind === "person" ? B.username : void 0,
175
- className: B.kind === "person" ? "" : "w-80 max-w-[calc(100vw-16px)] p-3 text-sm",
176
- children: B.kind === "term" ? /* @__PURE__ */ A(z, {
189
+ "aria-label": H.kind === "doc" ? H.key : H.kind === "person" ? H.username : void 0,
190
+ className: H.kind === "person" ? "" : "w-80 max-w-[calc(100vw-16px)] p-3 text-sm",
191
+ children: H.kind === "term" ? /* @__PURE__ */ j(V, {
177
192
  workspace: n,
178
- entry: g?.find((e) => e.id === B.id)
179
- }) : B.kind === "person" ? /* @__PURE__ */ A(S, {
193
+ entry: m?.find((e) => e.id === H.id)
194
+ }) : H.kind === "person" ? /* @__PURE__ */ j(C, {
180
195
  workspace: n,
181
- handle: B.username
182
- }) : /* @__PURE__ */ A(V, {
196
+ handle: H.username
197
+ }) : /* @__PURE__ */ j(U, {
183
198
  workspace: n,
184
- docKey: B.key
199
+ docKey: H.key
185
200
  })
186
201
  })
187
202
  });
188
203
  }
189
- function z({ workspace: e, entry: t }) {
190
- let n = O("knowledge"), r = p(e);
191
- if (!t) return /* @__PURE__ */ A("p", {
204
+ function V({ workspace: e, entry: t }) {
205
+ let n = k("knowledge"), r = m(e);
206
+ if (!t) return /* @__PURE__ */ j("p", {
192
207
  className: "text-muted-foreground",
193
208
  children: n("gone")
194
209
  });
195
210
  let i = t.source.doc;
196
- return /* @__PURE__ */ j(k, { children: [
197
- /* @__PURE__ */ j("p", {
211
+ return /* @__PURE__ */ M(A, { children: [
212
+ /* @__PURE__ */ M("p", {
198
213
  className: "flex items-center gap-2",
199
- children: [/* @__PURE__ */ A(g, {
214
+ children: [/* @__PURE__ */ j(_, {
200
215
  to: "/$workspace/knowledge/$term",
201
216
  params: {
202
217
  workspace: e,
203
- term: m(t)
218
+ term: h(t)
204
219
  },
205
220
  className: "font-semibold hover:underline",
206
221
  children: t.name
207
- }), /* @__PURE__ */ A("span", {
222
+ }), /* @__PURE__ */ j("span", {
208
223
  className: "text-xs text-muted-foreground",
209
224
  children: n(`kind.${t.kind}`)
210
225
  })]
211
226
  }),
212
- /* @__PURE__ */ A("p", {
227
+ /* @__PURE__ */ j("p", {
213
228
  className: "mt-1.5 text-foreground",
214
229
  children: t.definition
215
230
  }),
216
- t.supersededBy && /* @__PURE__ */ A("p", {
231
+ t.supersededBy && /* @__PURE__ */ j("p", {
217
232
  className: "mt-1.5 text-xs",
218
- children: /* @__PURE__ */ A(g, {
233
+ children: /* @__PURE__ */ j(_, {
219
234
  to: "/$workspace/knowledge/$term",
220
235
  params: {
221
236
  workspace: e,
@@ -225,21 +240,21 @@ function z({ workspace: e, entry: t }) {
225
240
  children: n("supersededBy", { name: t.supersededByName ?? "" })
226
241
  })
227
242
  }),
228
- (i || t.source.identifier) && /* @__PURE__ */ j("p", {
243
+ (i || t.source.identifier) && /* @__PURE__ */ M("p", {
229
244
  className: "mt-2 flex flex-wrap gap-x-3 gap-y-1 text-xs text-muted-foreground",
230
- children: [i && /* @__PURE__ */ j(g, {
245
+ children: [i && /* @__PURE__ */ M(_, {
231
246
  to: "/$workspace/docs/$doc",
232
247
  params: {
233
248
  workspace: e,
234
- doc: l(i)
249
+ doc: u(i)
235
250
  },
236
- ...t.source.section && { hash: d(t.source.section) },
251
+ ...t.source.section && { hash: f(t.source.section) },
237
252
  className: "inline-flex items-center gap-1 hover:text-foreground",
238
- children: [/* @__PURE__ */ A(x, { className: "size-3" }), t.source.section ? n("sourceSection", {
253
+ children: [/* @__PURE__ */ j(S, { className: "size-3" }), t.source.section ? n("sourceSection", {
239
254
  doc: i.title,
240
255
  section: t.source.section
241
256
  }) : i.title]
242
- }), t.source.identifier && /* @__PURE__ */ A(g, {
257
+ }), t.source.identifier && /* @__PURE__ */ j(_, {
243
258
  to: "/$workspace/issues/$identifier",
244
259
  params: {
245
260
  workspace: e,
@@ -249,41 +264,41 @@ function z({ workspace: e, entry: t }) {
249
264
  children: t.source.identifier
250
265
  })]
251
266
  }),
252
- /* @__PURE__ */ A(g, {
267
+ /* @__PURE__ */ j(_, {
253
268
  to: "/$workspace/knowledge/$term",
254
269
  params: {
255
270
  workspace: e,
256
- term: m(t)
271
+ term: h(t)
257
272
  },
258
273
  className: "mt-2 block text-xs text-primary hover:underline",
259
274
  children: n("openEntry")
260
275
  })
261
276
  ] });
262
277
  }
263
- function B(e) {
278
+ function H(e) {
264
279
  return e.split("\n").map((e) => e.replace(/^#{1,6}\s+|^[-*>]\s+|^\d+\.\s+|\[[ x]\]\s*/g, "").replace(/[*_`]/g, "")).filter((e) => e.trim()).slice(0, 4).join(" ").slice(0, 280);
265
280
  }
266
- function V({ workspace: e, docKey: t }) {
267
- let r = O("docLinks"), { data: i, isError: a } = M({
281
+ function U({ workspace: e, docKey: t }) {
282
+ let r = k("docLinks"), { data: i, isError: a } = N({
268
283
  ...n(e, t),
269
284
  retry: !1
270
285
  });
271
- return a ? /* @__PURE__ */ A("p", {
286
+ return a ? /* @__PURE__ */ j("p", {
272
287
  className: "text-muted-foreground",
273
288
  children: r("unavailable")
274
- }) : i ? /* @__PURE__ */ j(k, { children: [/* @__PURE__ */ j("p", {
289
+ }) : i ? /* @__PURE__ */ M(A, { children: [/* @__PURE__ */ M("p", {
275
290
  className: "flex items-center gap-2 font-semibold",
276
- children: [/* @__PURE__ */ A(y, {
291
+ children: [/* @__PURE__ */ j(b, {
277
292
  icon: i.icon,
278
293
  className: "size-3.5",
279
294
  emojiClassName: "text-xs"
280
- }), /* @__PURE__ */ A("span", {
295
+ }), /* @__PURE__ */ j("span", {
281
296
  className: "truncate",
282
297
  children: i.title
283
298
  })]
284
- }), /* @__PURE__ */ A("p", {
299
+ }), /* @__PURE__ */ j("p", {
285
300
  className: "mt-1.5 line-clamp-4 text-muted-foreground",
286
- children: B(i.body ?? "") || r("empty")
287
- })] }) : /* @__PURE__ */ A(w, { size: 16 });
301
+ children: H(i.body ?? "") || r("empty")
302
+ })] }) : /* @__PURE__ */ j(T, { size: 16 });
288
303
  }
289
- export { R as HoverCards };
304
+ export { B as HoverCards };
@@ -128,6 +128,7 @@ function x({ source: x, doc: S }) {
128
128
  }, k.data.key)
129
129
  ]
130
130
  }), /* @__PURE__ */ v(s, {
131
+ body: k.data?.body ?? "",
131
132
  editor: j,
132
133
  scroller: N
133
134
  })]