@nanocollective/roster 0.1.0-beta.12 → 0.1.0-beta.13

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.
package/dist/cli.js CHANGED
@@ -6995,6 +6995,7 @@ var THREAD_QUERY = `
6995
6995
  query($owner:String!, $name:String!, $number:Int!) {
6996
6996
  repository(owner:$owner, name:$name) {
6997
6997
  issueOrPullRequest(number:$number) {
6998
+ __typename
6998
6999
  ... on Issue {
6999
7000
  number title body url state createdAt updatedAt ${ROW_EXTRAS}
7000
7001
  author { login }
@@ -7229,6 +7230,7 @@ async function fetchThread(gh, repo, number, kind) {
7229
7230
  if (!res.ok) throw new Error(res.error);
7230
7231
  const n = res.data?.repository?.issueOrPullRequest;
7231
7232
  if (!n) throw new Error(`${repo}#${number} was not found in ${repo}`);
7233
+ if (n.__typename) kind = n.__typename === "PullRequest" ? "pr" : "issue";
7232
7234
  const item = shape(n, repo, "", kind);
7233
7235
  if (kind === "pr") {
7234
7236
  item.draft = n.isDraft;
@@ -60,6 +60,27 @@ pre.yaml{color:var(--ink)}
60
60
  .ref.pr{color:var(--measured)}
61
61
  .ref.pr:hover{border-color:var(--measured);background:color-mix(in srgb,var(--measured) 14%,transparent)}
62
62
 
63
+ /* What a chip is, on hover. In the top layer as a popover, so it shows over a side sheet too;
64
+ the UA's popover styles (inset, margin, border) are reset for that reason. */
65
+ .refcard{position:fixed;inset:auto;margin:0;z-index:60;width:340px;max-width:calc(100vw - 24px);
66
+ padding:12px 14px;background:var(--bg-elev);color:var(--ink);border:1px solid var(--border-strong);
67
+ border-radius:var(--r);box-shadow:var(--shadow-lg);font:13px/1.45 var(--sans);
68
+ opacity:0;transform:translateY(-2px);transition:opacity .12s var(--ease),transform .12s var(--ease)}
69
+ .refcard.on{opacity:1;transform:none}
70
+ .refcard[hidden]{display:none}
71
+ .refcard .rcmeta{display:flex;align-items:center;gap:8px;font:11.5px var(--mono);color:var(--ink-dim)}
72
+ .refcard .rcstate{display:inline-flex;align-items:center;gap:4px;font:600 11px var(--sans);
73
+ padding:1px 8px 1px 6px;border-radius:20px;--ic:12px}
74
+ .refcard .rcstate.open{color:var(--accent);background:var(--accent-soft)}
75
+ .refcard .rcstate.closed,.refcard .rcstate.merged{color:var(--derived);
76
+ background:color-mix(in srgb,var(--derived) 15%,transparent)}
77
+ .refcard .rctitle{margin-top:8px;font:600 14px/1.35 var(--sans);letter-spacing:-.005em}
78
+ .refcard .rcbody{margin:6px 0 0;color:var(--ink-dim);display:-webkit-box;-webkit-line-clamp:3;
79
+ -webkit-box-orient:vertical;overflow:hidden}
80
+ .refcard .rclabels{display:flex;flex-wrap:wrap;gap:4px;margin-top:8px}
81
+ .refcard .rcfoot{margin-top:10px;font-size:11.5px;color:var(--ink-faint)}
82
+ .refcard .sk{margin-top:8px}
83
+
63
84
  /* @cto and @you are how work is handed between people here, so they are marked
64
85
  rather than left as prose. `.you` is anyone on this org's roster; a stranger stays plain. */
65
86
  .at{display:inline-block;font:11.5px var(--mono);color:var(--ink-dim);background:var(--panel-2);
@@ -13,6 +13,7 @@ import {
13
13
  stampLoaded,
14
14
  syncNotice,
15
15
  } from "./refresh.js";
16
+ import { installRefs } from "./refcard.js";
16
17
  import { onRender } from "./router.js";
17
18
  import { ORG_WIDE, S, VIEWS, applyHash, humanLabel, readHash, writeHash } from "./state.js";
18
19
  import { viewBrain } from "./views/brain.js";
@@ -92,6 +93,7 @@ export async function boot() {
92
93
  /* Before the first render, and once: it is delegated, so it covers every image any screen
93
94
  draws from here on, including the setup screen. */
94
95
  installLightbox();
96
+ installRefs();
95
97
 
96
98
  /* Before there is a tenant the server answers every data route with `mode: setup`. That is
97
99
  not an error state: it is the first thing a new user ever sees, and the whole page becomes
@@ -0,0 +1,216 @@
1
+ /* What a #175 is, without leaving the page.
2
+ *
3
+ * Half of a status report is issue numbers, and the only way to find out what one was used to
4
+ * be a click through to GitHub, which is a new tab and the end of whatever you were reading.
5
+ * Hovering one now shows a card with its title, state and opening lines, the way GitHub does,
6
+ * and clicking it opens the thread in a side sheet over the page you were on.
7
+ *
8
+ * Only for the org's own repos: the server reads nothing else, so a chip pointing anywhere
9
+ * else stays a plain link. ⌘-click and middle-click still go to GitHub, as a link should.
10
+ */
11
+
12
+ import { getRepos, getThread } from "./api.js";
13
+ import { ago, el, esc } from "./dom.js";
14
+ import { iconHTML } from "./icons.js";
15
+ import { openThread } from "./views/home.js";
16
+ import { tone } from "./views/inbox.js";
17
+
18
+ const REF_HREF = /^https:\/\/github\.com\/([\w.-]+\/[\w.-]+)\/(?:issues|pull)\/(\d+)/;
19
+ const SHOW_AFTER = 350;
20
+ const HIDE_AFTER = 200;
21
+ // Long enough to hover the same few numbers on a report without asking again; short enough
22
+ // that a card is not an hour out of date.
23
+ const FRESH_FOR = 5 * 60_000;
24
+
25
+ let known = null;
26
+ const cache = new Map();
27
+ let card = null;
28
+ let showing = null;
29
+ let showTimer = 0;
30
+ let hideTimer = 0;
31
+
32
+ export function installRefs() {
33
+ /* Read once, off disk. A failure leaves every chip a plain link, which is what they were. */
34
+ getRepos()
35
+ .then((r) => {
36
+ known = new Set((r?.repos ?? []).map((x) => x.owner + "/" + x.name));
37
+ })
38
+ .catch(() => {});
39
+
40
+ document.addEventListener?.("click", (e) => {
41
+ const ref = refOf(e.target);
42
+ if (!ref || e.button !== 0 || e.metaKey || e.ctrlKey || e.shiftKey || e.altKey) return;
43
+ e.preventDefault();
44
+ hide();
45
+ openThread(ref);
46
+ });
47
+
48
+ document.addEventListener?.("pointerover", (e) => {
49
+ if (e.pointerType === "touch") return;
50
+ if (card?.contains(e.target)) {
51
+ clearTimeout(hideTimer);
52
+ return;
53
+ }
54
+ const a = e.target?.closest?.("a.ref");
55
+ const ref = refOf(e.target);
56
+ if (!ref) return;
57
+ clearTimeout(hideTimer);
58
+ if (showing === a) return;
59
+ // The card says everything the native tooltip did, and both at once is clutter.
60
+ a.removeAttribute("title");
61
+ clearTimeout(showTimer);
62
+ showTimer = setTimeout(() => show(a, ref), SHOW_AFTER);
63
+ });
64
+
65
+ document.addEventListener?.("pointerout", (e) => {
66
+ const from = e.target?.closest?.("a.ref, .refcard");
67
+ if (!from || from.contains(e.relatedTarget)) return;
68
+ clearTimeout(showTimer);
69
+ hideTimer = setTimeout(hide, HIDE_AFTER);
70
+ });
71
+
72
+ addEventListener?.("keydown", (e) => e.key === "Escape" && hide());
73
+ addEventListener?.("scroll", hide, true);
74
+ addEventListener?.("hashchange", hide);
75
+ }
76
+
77
+ /** The repo and number a chip points at, if it is one of the org's own. */
78
+ function refOf(target) {
79
+ const a = target?.closest?.("a.ref");
80
+ if (!a || !known) return null;
81
+ const m = REF_HREF.exec(a.getAttribute("href") ?? "");
82
+ if (!m || !known.has(m[1])) return null;
83
+ return { repo: m[1], number: Number(m[2]), kind: a.classList.contains("pr") ? "pr" : undefined };
84
+ }
85
+
86
+ function peek(ref) {
87
+ const key = ref.repo + "#" + ref.number;
88
+ const hit = cache.get(key);
89
+ if (hit && Date.now() - hit.at < FRESH_FOR) return hit.p;
90
+ const p = getThread(ref.repo, ref.number, ref.kind ?? "").then((t) => {
91
+ if (!t || t.error) throw new Error(t?.error ?? "could not read it");
92
+ return t;
93
+ });
94
+ // A failure is not kept: the next hover asks again.
95
+ p.catch(() => cache.delete(key));
96
+ cache.set(key, { at: Date.now(), p });
97
+ return p;
98
+ }
99
+
100
+ function show(a, ref) {
101
+ if (!a.isConnected) return;
102
+ showing = a;
103
+ ensureCard();
104
+ card.replaceChildren(
105
+ el("div", { className: "rcmeta", textContent: ref.repo + " #" + ref.number }),
106
+ el("div", { className: "sk sk-line" }),
107
+ el("div", { className: "sk sk-line" }),
108
+ );
109
+ open(a);
110
+ peek(ref)
111
+ .then((t) => {
112
+ if (showing === a) {
113
+ fill(t);
114
+ place(a);
115
+ }
116
+ })
117
+ .catch((e) => {
118
+ if (showing !== a) return;
119
+ card.replaceChildren(
120
+ el("div", { className: "rcmeta", textContent: ref.repo + " #" + ref.number }),
121
+ el("p", {
122
+ className: "rcbody",
123
+ // A bare #213 is read as this repo's, and the writer often meant another one.
124
+ textContent: /could not resolve|not found/i.test(e.message)
125
+ ? "There is no #" + ref.number + " in " + ref.repo + "."
126
+ : "Couldn't read it: " + e.message,
127
+ }),
128
+ );
129
+ });
130
+ }
131
+
132
+ function fill(t) {
133
+ const merged = t.state === "MERGED";
134
+ const shut = t.state !== "OPEN";
135
+ const glyph = merged ? "merged" : t.draft ? "draft" : shut ? "issue-closed" : "issue-open";
136
+ const word = merged ? "Merged" : shut ? "Closed" : t.draft ? "Draft" : "Open";
137
+ const excerpt = plain(t.body);
138
+ const comments = t.commentCount ?? t.comments?.length ?? 0;
139
+
140
+ card.innerHTML =
141
+ '<div class="rcmeta">' +
142
+ '<span class="rcstate ' + (merged ? "merged" : shut ? "closed" : "open") + '">' +
143
+ iconHTML(glyph) + word + "</span>" +
144
+ "<span>" + esc(t.repo) + " " + (t.kind === "pr" ? "PR " : "") + "#" + t.number + "</span>" +
145
+ "</div>" +
146
+ '<div class="rctitle">' + esc(t.title) + "</div>" +
147
+ (excerpt ? '<p class="rcbody">' + esc(excerpt) + "</p>" : "") +
148
+ (t.labels?.length
149
+ ? '<div class="rclabels">' +
150
+ t.labels.map((l) => '<span class="chip ' + tone(l) + '">' + esc(l) + "</span>").join("") +
151
+ "</div>"
152
+ : "") +
153
+ '<div class="rcfoot">' +
154
+ esc(t.author) + " · updated " + ago(t.updatedAt) +
155
+ (comments ? " · " + comments + (comments === 1 ? " comment" : " comments") : "") +
156
+ "</div>";
157
+ }
158
+
159
+ /** The opening of a body as a sentence: no headings, tables, images or link syntax. */
160
+ function plain(body) {
161
+ const text = String(body ?? "")
162
+ .replace(/<!--[\s\S]*?-->/g, "")
163
+ .replace(/```[\s\S]*?```/g, " ")
164
+ .replace(/!\[[^\]]*\]\([^)]*\)/g, "")
165
+ .replace(/\[([^\]]*)\]\([^)]*\)/g, "$1")
166
+ .split("\n")
167
+ .map((l) => l.replace(/^\s*(#{1,6}\s+|>\s?|[-*+]\s+(\[[ x]\]\s+)?|\d+\.\s+)/i, "").trim())
168
+ .filter((l) => l && !/^\|/.test(l) && !/^[-|:\s]+$/.test(l))
169
+ .join(" ")
170
+ .replace(/[*_`]/g, "")
171
+ .replace(/\s+/g, " ")
172
+ .trim();
173
+ return text.length > 220 ? text.slice(0, 219).trimEnd() + "…" : text;
174
+ }
175
+
176
+ function ensureCard() {
177
+ if (card) return;
178
+ card = el("div", { className: "refcard", role: "tooltip" });
179
+ /* A popover goes in the top layer, so the card shows over an open side sheet too. A plain
180
+ fixed div would sit underneath a modal <dialog> however high its z-index. */
181
+ if (typeof card.showPopover === "function") card.setAttribute("popover", "manual");
182
+ document.body.append(card);
183
+ }
184
+
185
+ function open(a) {
186
+ // The top layer is ordered by when things were shown. Reopening puts the card above a
187
+ // sheet that opened after it last showed.
188
+ if (card.matches?.(":popover-open")) card.hidePopover();
189
+ if (typeof card.showPopover === "function") card.showPopover();
190
+ else card.hidden = false;
191
+ card.classList.add("on");
192
+ place(a);
193
+ }
194
+
195
+ /** Under the chip, or above it when there is no room below; never off the side. */
196
+ function place(a) {
197
+ const r = a.getBoundingClientRect();
198
+ const w = card.offsetWidth;
199
+ const h = card.offsetHeight;
200
+ const gap = 8;
201
+ const left = Math.max(12, Math.min(r.left, innerWidth - w - 12));
202
+ const below = r.bottom + gap + h <= innerHeight - 12;
203
+ const top = below ? r.bottom + gap : Math.max(12, r.top - gap - h);
204
+ card.style.left = left + "px";
205
+ card.style.top = top + "px";
206
+ }
207
+
208
+ function hide() {
209
+ clearTimeout(showTimer);
210
+ clearTimeout(hideTimer);
211
+ showing = null;
212
+ if (!card) return;
213
+ card.classList.remove("on");
214
+ if (card.matches?.(":popover-open")) card.hidePopover();
215
+ else if (typeof card.showPopover !== "function") card.hidden = true;
216
+ }
@@ -26,7 +26,7 @@ const LABEL_TONE = {
26
26
  * which coloured exactly one org's and left every other org's looking like an ordinary tag.
27
27
  * It comes off org.yaml now, so it is right wherever this runs.
28
28
  */
29
- function tone(label) {
29
+ export function tone(label) {
30
30
  if (LABEL_TONE[label]) return LABEL_TONE[label];
31
31
  const name = String(label).toLowerCase();
32
32
  return humansOf().some(
@@ -125,7 +125,13 @@ export function threadInto(host, ref) {
125
125
  THREADS.delete(item.repo + "#" + item.number);
126
126
  item.partial = true;
127
127
  }
128
- host.append(inboxScreen(el("div"), { prs: ref.kind === "pr", only: ref }));
128
+ /* A #175 in a report is as likely to be closed, or in a repo nobody watches, as it is to be
129
+ in the inbox. It is read on its own and kept beside the inbox rather than added to it,
130
+ where it would turn up as a row on Trackers. */
131
+ const stray = item
132
+ ? null
133
+ : { repo: ref.repo, number: ref.number, kind: ref.kind ?? "issue", labels: [], partial: true };
134
+ host.append(inboxScreen(el("div"), { prs: ref.kind === "pr", only: ref, stray }));
129
135
  }
130
136
 
131
137
  function inboxScreen(m, opts) {
@@ -385,11 +391,14 @@ function inboxScreen(m, opts) {
385
391
  }
386
392
  }
387
393
 
394
+ function find(ref) {
395
+ const same = (i) => i.repo === ref.repo && i.number === ref.number;
396
+ return (S.inbox?.items ?? []).find(same) ?? (opts.stray && same(opts.stray) ? opts.stray : null);
397
+ }
398
+
388
399
  /* Everything is already loaded, so opening a thread is a render, not a request. */
389
400
  function openThread(ref) {
390
- const item = (S.inbox?.items ?? []).find(
391
- (i) => i.repo === ref.repo && i.number === ref.number,
392
- );
401
+ const item = find(ref);
393
402
  if (!item) {
394
403
  viewer.replaceChildren(
395
404
  el("p", { className: "empty", textContent: "That one is no longer open. Refresh." }),
@@ -849,6 +858,8 @@ function inboxScreen(m, opts) {
849
858
  THREADS.set(item.repo + "#" + item.number, fresh);
850
859
  // A single thread does not know which part of the org it is in, or whether it is unread.
851
860
  S.inbox.items[at] = { ...old, ...fresh, role: old.role, unread: old.unread, partial: false };
861
+ } else if (opts.stray && find(item) === opts.stray) {
862
+ Object.assign(opts.stray, fresh, { partial: false });
852
863
  }
853
864
  }
854
865
  } catch {