@milesroxas/design-hub 0.4.3 → 0.6.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.
- package/dist/scripts/cli.js +2 -0
- package/dist/scripts/commands.js +2 -0
- package/dist/scripts/hook.d.ts +1 -1
- package/dist/scripts/hook.js +4 -1
- package/dist/scripts/lib/update.d.ts +71 -0
- package/dist/scripts/lib/update.js +83 -0
- package/dist/scripts/skills.d.ts +7 -2
- package/dist/scripts/skills.js +19 -3
- package/dist/scripts/upgrade.d.ts +25 -0
- package/dist/scripts/upgrade.js +166 -0
- package/kit/prefs.ts +32 -6
- package/kit/ui/Menu.tsx +28 -4
- package/kit/ui/index.ts +9 -1
- package/package.json +2 -2
- package/shell/review/Bar.tsx +156 -0
- package/shell/review/Card.tsx +106 -0
- package/shell/review/Field.tsx +99 -0
- package/shell/review/Launcher.tsx +180 -0
- package/shell/review/People.tsx +168 -0
- package/shell/review/PickLayer.tsx +130 -0
- package/shell/review/Pins.tsx +97 -0
- package/shell/review/Review.tsx +282 -902
- package/shell/review/ThreadCard.tsx +498 -0
- package/shell/review/anchor.ts +2 -1
- package/shell/review/client.ts +3 -0
- package/shell/review/place.test.ts +72 -0
- package/shell/review/place.ts +78 -0
- package/shell/review/review.css +504 -205
- package/shell/review/sheet.ts +107 -0
- package/shell/review/snap.test.ts +44 -0
- package/shell/review/snap.ts +59 -0
- package/shell/review/view.test.ts +155 -0
- package/shell/review/view.ts +101 -0
|
@@ -0,0 +1,168 @@
|
|
|
1
|
+
// The People card, for editors: invite someone, hand over their link, and see
|
|
2
|
+
// who can comment.
|
|
3
|
+
import { Button, Select } from '@kit/ui';
|
|
4
|
+
import { type FormEvent, useId, useRef, useState } from 'react';
|
|
5
|
+
import { INVITE_DAYS, LIMITS, type Role } from '../../core/review/model';
|
|
6
|
+
import { Action } from './Card';
|
|
7
|
+
import { act, type Me, type ReviewStore } from './client';
|
|
8
|
+
|
|
9
|
+
type Link = { name: string; href: string };
|
|
10
|
+
|
|
11
|
+
const ROLES: { value: Role; label: string }[] = [
|
|
12
|
+
{ value: 'reviewer', label: 'Reviewer: comments and replies' },
|
|
13
|
+
{ value: 'editor', label: 'Editor: also resolves, sorts and invites' },
|
|
14
|
+
];
|
|
15
|
+
|
|
16
|
+
function InviteForm({ store, onLink }: { store: ReviewStore; onLink: (link: Link) => void }) {
|
|
17
|
+
const [role, setRole] = useState<Role>('reviewer');
|
|
18
|
+
const [busy, setBusy] = useState(false);
|
|
19
|
+
const roleLabel = useId();
|
|
20
|
+
const invite = (e: FormEvent<HTMLFormElement>) => {
|
|
21
|
+
e.preventDefault();
|
|
22
|
+
const form = e.currentTarget;
|
|
23
|
+
const f = new FormData(form);
|
|
24
|
+
const name = String(f.get('name') ?? '');
|
|
25
|
+
setBusy(true);
|
|
26
|
+
act(
|
|
27
|
+
store
|
|
28
|
+
.invite(name, String(f.get('team') ?? ''), role)
|
|
29
|
+
.then((href) => {
|
|
30
|
+
onLink({ name, href });
|
|
31
|
+
form.reset();
|
|
32
|
+
})
|
|
33
|
+
.finally(() => setBusy(false)),
|
|
34
|
+
);
|
|
35
|
+
};
|
|
36
|
+
return (
|
|
37
|
+
<form className="rv-invite" onSubmit={invite}>
|
|
38
|
+
<label className="field">
|
|
39
|
+
<span className="field-label">Name</span>
|
|
40
|
+
<input
|
|
41
|
+
className="input"
|
|
42
|
+
name="name"
|
|
43
|
+
required
|
|
44
|
+
maxLength={LIMITS.name}
|
|
45
|
+
autoComplete="off"
|
|
46
|
+
data-autofocus=""
|
|
47
|
+
/>
|
|
48
|
+
</label>
|
|
49
|
+
<label className="field">
|
|
50
|
+
<span className="field-label">Team</span>
|
|
51
|
+
<input
|
|
52
|
+
className="input"
|
|
53
|
+
name="team"
|
|
54
|
+
required
|
|
55
|
+
maxLength={LIMITS.team}
|
|
56
|
+
autoComplete="off"
|
|
57
|
+
placeholder="Studio, or the client’s company"
|
|
58
|
+
/>
|
|
59
|
+
</label>
|
|
60
|
+
<div className="field">
|
|
61
|
+
<span id={roleLabel} className="field-label">
|
|
62
|
+
Role
|
|
63
|
+
</span>
|
|
64
|
+
<Select
|
|
65
|
+
labelId={roleLabel}
|
|
66
|
+
menuClassName="rv-menu"
|
|
67
|
+
value={role}
|
|
68
|
+
options={ROLES}
|
|
69
|
+
onChange={(next) => setRole(next as Role)}
|
|
70
|
+
/>
|
|
71
|
+
</div>
|
|
72
|
+
<Button type="submit" kind="primary" size={null} label="Create invite link" busy={busy} />
|
|
73
|
+
</form>
|
|
74
|
+
);
|
|
75
|
+
}
|
|
76
|
+
|
|
77
|
+
function ShareLink({ link }: { link: Link }) {
|
|
78
|
+
const [copied, setCopied] = useState(false);
|
|
79
|
+
const field = useRef<HTMLInputElement>(null);
|
|
80
|
+
const copy = () =>
|
|
81
|
+
navigator.clipboard.writeText(link.href).then(
|
|
82
|
+
() => setCopied(true),
|
|
83
|
+
// No clipboard access (an insecure origin, a denied permission): select the link to copy by hand.
|
|
84
|
+
() => field.current?.select(),
|
|
85
|
+
);
|
|
86
|
+
return (
|
|
87
|
+
<div className="rv-share" role="status">
|
|
88
|
+
<p>
|
|
89
|
+
Send this link to {link.name}. It works for {INVITE_DAYS} days, and a new link replaces it.
|
|
90
|
+
</p>
|
|
91
|
+
<div className="rv-share-row">
|
|
92
|
+
<input
|
|
93
|
+
ref={field}
|
|
94
|
+
className="input"
|
|
95
|
+
readOnly
|
|
96
|
+
value={link.href}
|
|
97
|
+
aria-label={`Invite link for ${link.name}`}
|
|
98
|
+
onFocus={(e) => e.currentTarget.select()}
|
|
99
|
+
/>
|
|
100
|
+
<Button size={null} className="rv-copy" label={copied ? 'Copied' : 'Copy'} onClick={copy} />
|
|
101
|
+
</div>
|
|
102
|
+
</div>
|
|
103
|
+
);
|
|
104
|
+
}
|
|
105
|
+
|
|
106
|
+
function PersonRow({
|
|
107
|
+
person,
|
|
108
|
+
store,
|
|
109
|
+
onLink,
|
|
110
|
+
}: {
|
|
111
|
+
person: Me;
|
|
112
|
+
store: ReviewStore;
|
|
113
|
+
onLink: (link: Link) => void;
|
|
114
|
+
}) {
|
|
115
|
+
const [confirming, setConfirming] = useState(false);
|
|
116
|
+
return (
|
|
117
|
+
<div className="rv-row rv-acts">
|
|
118
|
+
{confirming ? (
|
|
119
|
+
<>
|
|
120
|
+
<span className="rv-confirm">Remove {person.name}’s access?</span>
|
|
121
|
+
<Action
|
|
122
|
+
label="Revoke"
|
|
123
|
+
danger
|
|
124
|
+
onClick={() => act(store.revoke(person.id).then(() => setConfirming(false)))}
|
|
125
|
+
/>
|
|
126
|
+
<Action label="Keep" onClick={() => setConfirming(false)} />
|
|
127
|
+
</>
|
|
128
|
+
) : (
|
|
129
|
+
<>
|
|
130
|
+
<Action
|
|
131
|
+
label="New link"
|
|
132
|
+
onClick={() => act(store.reissue(person.id).then((href) => onLink({ name: person.name, href })))}
|
|
133
|
+
/>
|
|
134
|
+
<Action label="Revoke" onClick={() => setConfirming(true)} />
|
|
135
|
+
</>
|
|
136
|
+
)}
|
|
137
|
+
</div>
|
|
138
|
+
);
|
|
139
|
+
}
|
|
140
|
+
|
|
141
|
+
export function People({ store, me, people }: { store: ReviewStore; me: Me | null; people: Me[] | null }) {
|
|
142
|
+
const [link, setLink] = useState<Link | null>(null);
|
|
143
|
+
return (
|
|
144
|
+
<div className="rv-body">
|
|
145
|
+
<InviteForm store={store} onLink={setLink} />
|
|
146
|
+
{/* Keyed by the link, so a second one starts on Copy again. */}
|
|
147
|
+
{link && <ShareLink key={link.href} link={link} />}
|
|
148
|
+
{people === null ? (
|
|
149
|
+
<p className="rv-muted">Loading people…</p>
|
|
150
|
+
) : (
|
|
151
|
+
<ul className="rv-people">
|
|
152
|
+
{people.map((p) => (
|
|
153
|
+
<li key={p.id} data-revoked={p.revokedAt ? '' : undefined}>
|
|
154
|
+
<div className="rv-person">
|
|
155
|
+
<strong>{p.name}</strong>
|
|
156
|
+
<span className="rv-muted">
|
|
157
|
+
{p.team} · {p.role}
|
|
158
|
+
{p.revokedAt && ' · revoked'}
|
|
159
|
+
</span>
|
|
160
|
+
</div>
|
|
161
|
+
{p.id !== me?.id && !p.revokedAt && <PersonRow person={p} store={store} onLink={setLink} />}
|
|
162
|
+
</li>
|
|
163
|
+
))}
|
|
164
|
+
</ul>
|
|
165
|
+
)}
|
|
166
|
+
</div>
|
|
167
|
+
);
|
|
168
|
+
}
|
|
@@ -0,0 +1,130 @@
|
|
|
1
|
+
// Comment mode's hold on the page. No surface goes over it: a click or tap
|
|
2
|
+
// on the page is caught at the document before the page sees it, so the page
|
|
3
|
+
// and every panel in it still scroll natively, by wheel or by finger. A mouse
|
|
4
|
+
// gets an outline on the element under it; a keyboard comments on the focused
|
|
5
|
+
// element with Enter.
|
|
6
|
+
import { useEffect, useRef } from 'react';
|
|
7
|
+
import { isHarness } from './anchor';
|
|
8
|
+
import { nearest } from './place';
|
|
9
|
+
import type { Draft } from './view';
|
|
10
|
+
|
|
11
|
+
/** How close, in px, a click must land to a pin's edge to open it rather than start a new comment. */
|
|
12
|
+
const PIN_REACH = 16;
|
|
13
|
+
|
|
14
|
+
/** The pin a point lands on or near, by its thread id. */
|
|
15
|
+
function pinAt(x: number, y: number): HTMLElement | null {
|
|
16
|
+
const pins = [...document.querySelectorAll<HTMLElement>('.rv-pin[data-pin]:not([hidden])')].map((el) => {
|
|
17
|
+
const r = el.getBoundingClientRect();
|
|
18
|
+
return { el, left: r.left, top: r.top, right: r.right, bottom: r.bottom };
|
|
19
|
+
});
|
|
20
|
+
return nearest(x, y, pins, PIN_REACH)?.el ?? null;
|
|
21
|
+
}
|
|
22
|
+
|
|
23
|
+
/** Marks the pin a mouse is near, so it lifts and the cursor says a click opens it. */
|
|
24
|
+
function markNear(pin: HTMLElement | null) {
|
|
25
|
+
for (const el of document.querySelectorAll('.rv-pin[data-near]'))
|
|
26
|
+
if (el !== pin) delete (el as HTMLElement).dataset.near;
|
|
27
|
+
if (pin) pin.dataset.near = '';
|
|
28
|
+
if (pin) document.documentElement.dataset.rvNear = '';
|
|
29
|
+
else delete document.documentElement.dataset.rvNear;
|
|
30
|
+
}
|
|
31
|
+
|
|
32
|
+
const isPage = (t: EventTarget | null): t is Element =>
|
|
33
|
+
t instanceof Element && !isHarness(t) && t !== document.body && t !== document.documentElement;
|
|
34
|
+
|
|
35
|
+
function outline(box: HTMLElement | null, el: Element | null) {
|
|
36
|
+
if (!box) return;
|
|
37
|
+
box.hidden = !el;
|
|
38
|
+
if (!el) return;
|
|
39
|
+
const r = el.getBoundingClientRect();
|
|
40
|
+
box.style.transform = `translate(${r.left}px, ${r.top}px)`;
|
|
41
|
+
box.style.width = `${r.width}px`;
|
|
42
|
+
box.style.height = `${r.height}px`;
|
|
43
|
+
}
|
|
44
|
+
|
|
45
|
+
const fraction = (v: number, size: number) => (size ? Math.min(1, Math.max(0, v / size)) : 0.5);
|
|
46
|
+
|
|
47
|
+
/** Where on the element the click landed; the middle for a keyboard click, which has no point. */
|
|
48
|
+
function offsetOf(el: Element, e: MouseEvent) {
|
|
49
|
+
if (e.detail === 0) return { x: 0.5, y: 0.5 };
|
|
50
|
+
const r = el.getBoundingClientRect();
|
|
51
|
+
return { x: fraction(e.clientX - r.left, r.width), y: fraction(e.clientY - r.top, r.height) };
|
|
52
|
+
}
|
|
53
|
+
|
|
54
|
+
/** Where a draft's marker sits now, in viewport pixels, or null for the whole page. */
|
|
55
|
+
export function draftPoint(d: Draft): { x: number; y: number } | null {
|
|
56
|
+
if (!d.target || !d.offset || !d.target.isConnected) return null;
|
|
57
|
+
const r = d.target.getBoundingClientRect();
|
|
58
|
+
return { x: r.left + r.width * d.offset.x, y: r.top + r.height * d.offset.y };
|
|
59
|
+
}
|
|
60
|
+
|
|
61
|
+
/** What a comment is about, in words: the element's label or its first words. */
|
|
62
|
+
export const describe = (el: Element | null) => {
|
|
63
|
+
if (!el) return 'the whole page';
|
|
64
|
+
// biome-ignore lint/performance/useDomNodeTextContent: innerText keeps the spaces between a row's parts; textContent runs them together
|
|
65
|
+
const text = (el.getAttribute('aria-label') || (el as HTMLElement).innerText || el.textContent || '')
|
|
66
|
+
.trim()
|
|
67
|
+
.replace(/\s+/g, ' ');
|
|
68
|
+
return text ? `“${text.length > 40 ? `${text.slice(0, 40)}…` : text}”` : `a ${el.localName} element`;
|
|
69
|
+
};
|
|
70
|
+
|
|
71
|
+
export function PickLayer({
|
|
72
|
+
onPick,
|
|
73
|
+
onOpen,
|
|
74
|
+
}: {
|
|
75
|
+
onPick: (draft: Draft) => void;
|
|
76
|
+
onOpen: (id: string) => void;
|
|
77
|
+
}) {
|
|
78
|
+
const box = useRef<HTMLDivElement>(null);
|
|
79
|
+
const pick = useRef(onPick);
|
|
80
|
+
pick.current = onPick;
|
|
81
|
+
const open = useRef(onOpen);
|
|
82
|
+
open.current = onOpen;
|
|
83
|
+
|
|
84
|
+
useEffect(() => {
|
|
85
|
+
const root = document.documentElement;
|
|
86
|
+
root.dataset.rvCommenting = '';
|
|
87
|
+
// Pressing the page must not press its controls: a menu that opens on pointerdown stays shut.
|
|
88
|
+
const hold = (e: Event) => {
|
|
89
|
+
if (!isPage(e.target)) return;
|
|
90
|
+
e.stopPropagation();
|
|
91
|
+
if (e.type !== 'pointerdown') e.preventDefault();
|
|
92
|
+
};
|
|
93
|
+
const onClick = (e: MouseEvent) => {
|
|
94
|
+
const t = e.target;
|
|
95
|
+
if (!(t instanceof Element) || isHarness(t)) return;
|
|
96
|
+
// A click near a pin opens it, wherever the press began or ended: a near miss is not a new comment.
|
|
97
|
+
const pin = e.detail ? pinAt(e.clientX, e.clientY) : null;
|
|
98
|
+
if (!pin && !isPage(t)) return;
|
|
99
|
+
e.preventDefault();
|
|
100
|
+
e.stopPropagation();
|
|
101
|
+
outline(box.current, null);
|
|
102
|
+
if (pin?.dataset.pin) open.current(pin.dataset.pin);
|
|
103
|
+
else if (isPage(t)) pick.current({ target: t, offset: offsetOf(t, e) });
|
|
104
|
+
};
|
|
105
|
+
const onMove = (e: PointerEvent) => {
|
|
106
|
+
if (e.pointerType !== 'mouse') return;
|
|
107
|
+
const pin = pinAt(e.clientX, e.clientY);
|
|
108
|
+
markNear(pin);
|
|
109
|
+
outline(box.current, !pin && isPage(e.target) ? e.target : null);
|
|
110
|
+
};
|
|
111
|
+
const onScroll = () => outline(box.current, null);
|
|
112
|
+
const opts = { capture: true };
|
|
113
|
+
document.addEventListener('pointerdown', hold, opts);
|
|
114
|
+
document.addEventListener('mousedown', hold, opts);
|
|
115
|
+
document.addEventListener('click', onClick, opts);
|
|
116
|
+
document.addEventListener('pointermove', onMove, { capture: true, passive: true });
|
|
117
|
+
addEventListener('scroll', onScroll, { capture: true, passive: true });
|
|
118
|
+
return () => {
|
|
119
|
+
delete root.dataset.rvCommenting;
|
|
120
|
+
markNear(null);
|
|
121
|
+
document.removeEventListener('pointerdown', hold, opts);
|
|
122
|
+
document.removeEventListener('mousedown', hold, opts);
|
|
123
|
+
document.removeEventListener('click', onClick, opts);
|
|
124
|
+
document.removeEventListener('pointermove', onMove, opts);
|
|
125
|
+
removeEventListener('scroll', onScroll, opts);
|
|
126
|
+
};
|
|
127
|
+
}, []);
|
|
128
|
+
|
|
129
|
+
return <div ref={box} className="rv-pick-box" hidden />;
|
|
130
|
+
}
|
|
@@ -0,0 +1,97 @@
|
|
|
1
|
+
// Pins on the elements comments are about, and the marker for one being
|
|
2
|
+
// written. In comment mode they are the way into a thread, so each is a real
|
|
3
|
+
// button in the tab order. The button is the hit area and never changes size;
|
|
4
|
+
// the face inside it is what presses and lifts, so a press near the edge
|
|
5
|
+
// still ends on the pin. An open thread's pin is solid and numbered; a
|
|
6
|
+
// resolved one is pale and carries a check.
|
|
7
|
+
import { Icon } from '@kit/Icon';
|
|
8
|
+
import { useEffect, useRef } from 'react';
|
|
9
|
+
import type { Comment } from '../../core/review/model';
|
|
10
|
+
import { pinPoint } from './anchor';
|
|
11
|
+
import { draftPoint } from './PickLayer';
|
|
12
|
+
import type { Draft } from './view';
|
|
13
|
+
|
|
14
|
+
const moveTo = (el: HTMLElement, at: { x: number; y: number } | null) => {
|
|
15
|
+
el.hidden = !at;
|
|
16
|
+
if (at) el.style.transform = `translate(${at.x}px, ${at.y}px)`;
|
|
17
|
+
};
|
|
18
|
+
|
|
19
|
+
export function Pins({
|
|
20
|
+
comments,
|
|
21
|
+
number,
|
|
22
|
+
active,
|
|
23
|
+
draft,
|
|
24
|
+
onOpen,
|
|
25
|
+
}: {
|
|
26
|
+
comments: Comment[];
|
|
27
|
+
number: Map<string, number>;
|
|
28
|
+
active: string | null;
|
|
29
|
+
draft: Draft | null;
|
|
30
|
+
onOpen: (id: string) => void;
|
|
31
|
+
}) {
|
|
32
|
+
const layer = useRef<HTMLDivElement>(null);
|
|
33
|
+
|
|
34
|
+
// Positions are written straight to the pins' transforms on scroll, resize
|
|
35
|
+
// and DOM changes, at most once a frame, so a scroll re-renders nothing.
|
|
36
|
+
useEffect(() => {
|
|
37
|
+
let frame = 0;
|
|
38
|
+
const place = () => {
|
|
39
|
+
frame = 0;
|
|
40
|
+
for (const pin of layer.current?.querySelectorAll<HTMLElement>('[data-pin]') ?? []) {
|
|
41
|
+
const c = comments.find((x) => x.id === pin.dataset.pin);
|
|
42
|
+
moveTo(pin, c?.anchor ? pinPoint(c.anchor) : null);
|
|
43
|
+
}
|
|
44
|
+
const d = layer.current?.querySelector<HTMLElement>('[data-draft]');
|
|
45
|
+
if (d && draft) moveTo(d, draftPoint(draft));
|
|
46
|
+
};
|
|
47
|
+
const schedule = () => {
|
|
48
|
+
if (!frame) frame = requestAnimationFrame(place);
|
|
49
|
+
};
|
|
50
|
+
place();
|
|
51
|
+
const observer = new MutationObserver(schedule);
|
|
52
|
+
observer.observe(document.body, {
|
|
53
|
+
subtree: true,
|
|
54
|
+
childList: true,
|
|
55
|
+
attributes: true,
|
|
56
|
+
attributeFilter: ['class', 'style', 'hidden'],
|
|
57
|
+
});
|
|
58
|
+
addEventListener('scroll', schedule, { capture: true, passive: true });
|
|
59
|
+
addEventListener('resize', schedule);
|
|
60
|
+
return () => {
|
|
61
|
+
cancelAnimationFrame(frame);
|
|
62
|
+
observer.disconnect();
|
|
63
|
+
removeEventListener('scroll', schedule, { capture: true });
|
|
64
|
+
removeEventListener('resize', schedule);
|
|
65
|
+
};
|
|
66
|
+
}, [comments, draft]);
|
|
67
|
+
|
|
68
|
+
return (
|
|
69
|
+
<div ref={layer} className="rv-pins">
|
|
70
|
+
{comments.map((c) => {
|
|
71
|
+
const n = number.get(c.id);
|
|
72
|
+
const resolved = c.status === 'resolved';
|
|
73
|
+
return (
|
|
74
|
+
<button
|
|
75
|
+
key={c.id}
|
|
76
|
+
type="button"
|
|
77
|
+
className="rv-pin"
|
|
78
|
+
data-pin={c.id}
|
|
79
|
+
data-resolved={resolved ? '' : undefined}
|
|
80
|
+
data-active={active === c.id ? '' : undefined}
|
|
81
|
+
aria-label={`Comment ${n}${resolved ? ', resolved,' : ''} by ${c.author.name}`}
|
|
82
|
+
aria-pressed={active === c.id}
|
|
83
|
+
hidden
|
|
84
|
+
onClick={() => onOpen(c.id)}
|
|
85
|
+
>
|
|
86
|
+
<span className="rv-pin-face">{resolved ? <Icon name="check" size={12} /> : n}</span>
|
|
87
|
+
</button>
|
|
88
|
+
);
|
|
89
|
+
})}
|
|
90
|
+
{draft?.offset && (
|
|
91
|
+
<span className="rv-pin" data-draft="" data-new="" aria-hidden="true" hidden>
|
|
92
|
+
<span className="rv-pin-face" />
|
|
93
|
+
</span>
|
|
94
|
+
)}
|
|
95
|
+
</div>
|
|
96
|
+
);
|
|
97
|
+
}
|