@mdbase-dev/ui 0.1.0-beta.172 → 0.1.0-beta.174
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/css/comments.css +33 -1
- package/dist/CommentsPanel.d.ts +18 -2
- package/dist/CommentsPanel.js +304 -58
- package/dist/comments.d.ts +4 -0
- package/dist/comments.js +5 -0
- package/dist/locales/de/messages.json +1 -1
- package/dist/locales/en/messages.json +1 -1
- package/dist/locales/es/messages.json +1 -1
- package/dist/locales/fr/messages.json +1 -1
- package/dist/locales/it/messages.json +1 -1
- package/dist/locales/ja/messages.json +1 -1
- package/dist/locales/ko/messages.json +1 -1
- package/dist/locales/pt/messages.json +1 -1
- package/dist/locales/ru/messages.json +1 -1
- package/dist/locales/zh/messages.json +1 -1
- package/package.json +2 -2
package/css/comments.css
CHANGED
|
@@ -41,6 +41,23 @@
|
|
|
41
41
|
.mdbase-thread-action:focus-visible { outline: var(--focus-ring); outline-offset: 1px; }
|
|
42
42
|
.mdbase-comments-count { color: var(--color-text-muted); font-variant-numeric: tabular-nums; }
|
|
43
43
|
|
|
44
|
+
.mdbase-comments-who .mdbase-select { width: 100%; }
|
|
45
|
+
|
|
46
|
+
/* More rows than a page holds: a quiet button fetches the next page. */
|
|
47
|
+
.mdbase-comments-more {
|
|
48
|
+
justify-self: start;
|
|
49
|
+
min-height: 28px;
|
|
50
|
+
padding: 0 8px;
|
|
51
|
+
border: 0;
|
|
52
|
+
border-radius: var(--radius-sm);
|
|
53
|
+
color: var(--color-text-muted);
|
|
54
|
+
background: none;
|
|
55
|
+
font: inherit;
|
|
56
|
+
cursor: pointer;
|
|
57
|
+
}
|
|
58
|
+
.mdbase-comments-more:hover { color: var(--color-text); background: var(--color-surface-subtle); }
|
|
59
|
+
.mdbase-comments-more:focus-visible { outline: var(--focus-ring); outline-offset: 1px; }
|
|
60
|
+
|
|
44
61
|
.mdbase-comments-note,
|
|
45
62
|
.mdbase-comments-empty p,
|
|
46
63
|
.mdbase-comments-error { margin: 0; }
|
|
@@ -88,6 +105,20 @@
|
|
|
88
105
|
.mdbase-threads > .mdbase-thread.is-active + .mdbase-thread { border-top-color: transparent; }
|
|
89
106
|
.mdbase-thread.mdbase-comment-composer { margin: 0; padding: 12px; border: 1px solid var(--color-border-strong); }
|
|
90
107
|
|
|
108
|
+
/* The record a run of threads is on, when the panel covers several. */
|
|
109
|
+
.mdbase-threads-record h3 {
|
|
110
|
+
margin: 0;
|
|
111
|
+
padding: 12px 8px 4px;
|
|
112
|
+
overflow: hidden;
|
|
113
|
+
color: var(--color-text-muted);
|
|
114
|
+
font-size: var(--font-size-caption);
|
|
115
|
+
font-weight: 600;
|
|
116
|
+
text-overflow: ellipsis;
|
|
117
|
+
white-space: nowrap;
|
|
118
|
+
}
|
|
119
|
+
.mdbase-threads-record:first-child h3 { padding-top: 0; }
|
|
120
|
+
.mdbase-thread-new { color: var(--color-accent); font-size: var(--font-size-caption); font-weight: 600; }
|
|
121
|
+
|
|
91
122
|
.mdbase-thread-anchor {
|
|
92
123
|
display: grid;
|
|
93
124
|
gap: 4px;
|
|
@@ -127,7 +158,8 @@ blockquote.mdbase-thread-quote::after { content: "”"; }
|
|
|
127
158
|
.mdbase-thread-suggestion ins { background: color-mix(in oklch, var(--color-success) 12%, transparent); }
|
|
128
159
|
|
|
129
160
|
.mdbase-thread-actions { display: flex; flex-wrap: wrap; align-items: center; gap: 6px 12px; }
|
|
130
|
-
.mdbase-thread-reply
|
|
161
|
+
.mdbase-thread-reply,
|
|
162
|
+
.mdbase-comment-composer-field { display: grid; gap: 6px; }
|
|
131
163
|
.mdbase-thread textarea.mdbase-field { width: 100%; resize: vertical; }
|
|
132
164
|
|
|
133
165
|
/* A quiet text action: reply, resolve, withdraw. */
|
package/dist/CommentsPanel.d.ts
CHANGED
|
@@ -10,7 +10,16 @@ export type CommentResult = {
|
|
|
10
10
|
/** A comment being written: on `quote`, at a point in the text (an empty quote), or on the whole record. */
|
|
11
11
|
export interface PendingComment {
|
|
12
12
|
readonly quote?: string;
|
|
13
|
+
/** A suggested edit to the passage (or an insertion at the point), not a comment on it. */
|
|
14
|
+
readonly suggest?: boolean;
|
|
15
|
+
/** Where it is, such as a chapter's title, when the panel covers several records. */
|
|
16
|
+
readonly on?: string;
|
|
13
17
|
}
|
|
18
|
+
/** Replies being written, by thread, so they outlast the panel being closed. */
|
|
19
|
+
export type CommentDrafts = Map<string, {
|
|
20
|
+
reply: string;
|
|
21
|
+
replying: boolean;
|
|
22
|
+
}>;
|
|
14
23
|
interface CommentsPanelProps {
|
|
15
24
|
readonly threads: readonly PlacedThread[];
|
|
16
25
|
readonly people: CommentPeople;
|
|
@@ -29,7 +38,8 @@ interface CommentsPanelProps {
|
|
|
29
38
|
/** Shown above the threads, such as why new comments will not be signed. */
|
|
30
39
|
readonly notice?: ReactNode;
|
|
31
40
|
readonly onSelect: (placed: PlacedThread) => void;
|
|
32
|
-
|
|
41
|
+
/** `replacement` is the suggested text when `pending.suggest`. */
|
|
42
|
+
readonly onSubmit: (text: string, replacement?: string) => Promise<CommentResult>;
|
|
33
43
|
readonly onCancel: () => void;
|
|
34
44
|
readonly onReply?: ((thread: CommentThread, text: string) => Promise<CommentResult>) | undefined;
|
|
35
45
|
readonly onChange?: ((comment: CommentRecord, change: CommentChange) => Promise<CommentResult>) | undefined;
|
|
@@ -37,8 +47,14 @@ interface CommentsPanelProps {
|
|
|
37
47
|
readonly onAccept?: ((placed: PlacedThread) => Promise<CommentResult>) | undefined;
|
|
38
48
|
/** Opens a comment's own record. */
|
|
39
49
|
readonly onOpenRecord?: ((path: string) => void) | undefined;
|
|
50
|
+
/** Heads each record's threads with its title, when the threads are on several records. */
|
|
51
|
+
readonly recordTitle?: ((record: string) => string) | undefined;
|
|
52
|
+
/** When this was last open here, for marking what others have written since. */
|
|
53
|
+
readonly since?: string | undefined;
|
|
54
|
+
/** Kept by the app when replies in progress should outlast this panel. */
|
|
55
|
+
readonly drafts?: CommentDrafts | undefined;
|
|
40
56
|
}
|
|
41
|
-
export declare function CommentsPanel({ threads, people, loading, problem, onRetry, active, pending, onStart, hint, notice, onSelect, onSubmit, onCancel, onReply, onChange, onAccept, onOpenRecord }: CommentsPanelProps): JSX.Element;
|
|
57
|
+
export declare function CommentsPanel({ threads, people, loading, problem, onRetry, active, pending, onStart, hint, notice, onSelect, onSubmit, onCancel, onReply, onChange, onAccept, onOpenRecord, recordTitle, since, drafts: providedDrafts }: CommentsPanelProps): JSX.Element;
|
|
42
58
|
/** "3 open comments", for a control that opens them. */
|
|
43
59
|
export declare function openCommentCount(threads: readonly PlacedThread[]): string;
|
|
44
60
|
export {};
|
package/dist/CommentsPanel.js
CHANGED
|
@@ -1,13 +1,48 @@
|
|
|
1
1
|
import { Fragment as _Fragment, jsx as _jsx, jsxs as _jsxs } from "react/jsx-runtime";
|
|
2
|
-
// The comments on
|
|
3
|
-
//
|
|
4
|
-
//
|
|
5
|
-
// `@mdbase-dev/ui/comments.css`.
|
|
2
|
+
// The comments on a record, or on the several records of one piece of
|
|
3
|
+
// writing: threads in reading order, with replies, resolving, and suggested
|
|
4
|
+
// edits to accept or reject. A new comment or suggestion starts from a passage
|
|
5
|
+
// the app hands in (`pending`). Style with `@mdbase-dev/ui/comments.css`.
|
|
6
6
|
import { i18n as _i18n } from "@lingui/core";
|
|
7
|
-
import { memo, useEffect, useRef, useState } from "react";
|
|
8
|
-
import { clipPassage, inlinePieces, personName, plainPassage, when as relativeTime, writtenByMe } from "./comments.js";
|
|
7
|
+
import { memo, useCallback, useEffect, useMemo, useRef, useState } from "react";
|
|
8
|
+
import { clipPassage, inlinePieces, personKey, personName, plainPassage, threadIsNew, when as relativeTime, writtenByMe } from "./comments.js";
|
|
9
9
|
import { i18n, useLocaleRevision } from "./i18n.js";
|
|
10
|
+
import { Select } from "./Select.js";
|
|
10
11
|
const when = iso => relativeTime(iso, i18n.locale);
|
|
12
|
+
const PAGE = 50;
|
|
13
|
+
/** Rows a page at a time; revealing a distant row opens its page, not everything before it. */
|
|
14
|
+
function useRowWindow() {
|
|
15
|
+
const [range, setRange] = useState({
|
|
16
|
+
from: 0,
|
|
17
|
+
size: PAGE
|
|
18
|
+
});
|
|
19
|
+
const reveal = useCallback(rank => {
|
|
20
|
+
if (rank < 0) return;
|
|
21
|
+
setRange(r => rank >= r.from && rank < r.from + r.size ? r : {
|
|
22
|
+
from: Math.floor(rank / PAGE) * PAGE,
|
|
23
|
+
size: PAGE
|
|
24
|
+
});
|
|
25
|
+
}, []);
|
|
26
|
+
const reset = useCallback(() => setRange({
|
|
27
|
+
from: 0,
|
|
28
|
+
size: PAGE
|
|
29
|
+
}), []);
|
|
30
|
+
const more = useCallback(() => setRange(r => ({
|
|
31
|
+
...r,
|
|
32
|
+
size: r.size + PAGE
|
|
33
|
+
})), []);
|
|
34
|
+
const previous = useCallback(() => setRange(r => ({
|
|
35
|
+
from: Math.max(0, r.from - PAGE),
|
|
36
|
+
size: PAGE
|
|
37
|
+
})), []);
|
|
38
|
+
return {
|
|
39
|
+
...range,
|
|
40
|
+
reveal,
|
|
41
|
+
reset,
|
|
42
|
+
more,
|
|
43
|
+
previous
|
|
44
|
+
};
|
|
45
|
+
}
|
|
11
46
|
export function CommentsPanel({
|
|
12
47
|
threads,
|
|
13
48
|
people,
|
|
@@ -25,27 +60,71 @@ export function CommentsPanel({
|
|
|
25
60
|
onReply,
|
|
26
61
|
onChange,
|
|
27
62
|
onAccept,
|
|
28
|
-
onOpenRecord
|
|
63
|
+
onOpenRecord,
|
|
64
|
+
recordTitle,
|
|
65
|
+
since,
|
|
66
|
+
drafts: providedDrafts
|
|
29
67
|
}) {
|
|
30
68
|
useLocaleRevision();
|
|
31
69
|
const [filter, setFilter] = useState("open");
|
|
70
|
+
// Whose threads: everyone's, what is new since the last visit, one's own, or one person's.
|
|
71
|
+
const [who, setWho] = useState("all");
|
|
32
72
|
const panel = useRef(null);
|
|
73
|
+
const ownDrafts = useRef(new Map());
|
|
74
|
+
const drafts = providedDrafts ?? ownDrafts.current;
|
|
75
|
+
const rows = useRowWindow();
|
|
76
|
+
const me = people.me ? personKey(people.me.link) : undefined;
|
|
77
|
+
const isNew = p => threadIsNew(p.thread, since, people);
|
|
78
|
+
const authors = useMemo(() => {
|
|
79
|
+
const names = new Map();
|
|
80
|
+
for (const p of threads) for (const c of [p.thread.root, ...p.thread.replies]) {
|
|
81
|
+
if (!c.createdBy) continue;
|
|
82
|
+
const key = personKey(c.createdBy);
|
|
83
|
+
if (!names.has(key)) names.set(key, personName(c.createdBy, people) ?? c.createdBy);
|
|
84
|
+
}
|
|
85
|
+
return [...names].sort((a, b) => a[1].localeCompare(b[1]));
|
|
86
|
+
}, [threads, people]);
|
|
87
|
+
const wanted = p => {
|
|
88
|
+
if (who === "all") return true;
|
|
89
|
+
if (who === "new") return isNew(p);
|
|
90
|
+
const key = who === "mine" ? me : who;
|
|
91
|
+
return [p.thread.root, ...p.thread.replies].some(c => c.createdBy !== undefined && personKey(c.createdBy) === key);
|
|
92
|
+
};
|
|
93
|
+
const newCount = threads.filter(p => p.thread.root.status === "open" && isNew(p)).length;
|
|
33
94
|
const groups = {
|
|
34
|
-
open: threads.filter(p => p.thread.root.status === "open"),
|
|
35
|
-
resolved: threads.filter(p => p.thread.root.status === "resolved")
|
|
95
|
+
open: threads.filter(p => p.thread.root.status === "open" && wanted(p)),
|
|
96
|
+
resolved: threads.filter(p => p.thread.root.status === "resolved" && wanted(p))
|
|
97
|
+
};
|
|
98
|
+
const logical = groups[filter];
|
|
99
|
+
const shown = logical.slice(rows.from, rows.from + rows.size);
|
|
100
|
+
// Arrow keys (or j and k) move between threads from their passage.
|
|
101
|
+
const onListKey = e => {
|
|
102
|
+
const target = e.target;
|
|
103
|
+
if (!target.matches(".mdbase-thread-anchor")) return;
|
|
104
|
+
const path = target.closest("[data-thread]")?.dataset["thread"];
|
|
105
|
+
const rank = logical.findIndex(p => p.thread.root.path === path);
|
|
106
|
+
const direction = e.key === "ArrowDown" || e.key === "j" ? 1 : e.key === "ArrowUp" || e.key === "k" ? -1 : 0;
|
|
107
|
+
const next = logical[rank + direction];
|
|
108
|
+
if (!direction || !next) return;
|
|
109
|
+
e.preventDefault();
|
|
110
|
+
rows.reveal(rank + direction);
|
|
111
|
+
requestAnimationFrame(() => panel.current?.querySelector(`[data-thread="${CSS.escape(next.thread.root.path)}"] .mdbase-thread-anchor`)?.focus());
|
|
36
112
|
};
|
|
37
|
-
const shown = groups[filter];
|
|
38
113
|
// A thread selected in the editor comes into view (and shows, even when resolved).
|
|
39
114
|
useEffect(() => {
|
|
40
115
|
if (!active) return;
|
|
41
116
|
const hit = threads.find(p => p.thread.root.path === active);
|
|
42
|
-
if (hit)
|
|
117
|
+
if (hit) {
|
|
118
|
+
setFilter(hit.thread.root.status);
|
|
119
|
+
rows.reveal(groups[hit.thread.root.status].indexOf(hit));
|
|
120
|
+
}
|
|
43
121
|
const frame = requestAnimationFrame(() => panel.current?.querySelector(`[data-thread="${CSS.escape(active)}"]`)?.scrollIntoView({
|
|
44
122
|
block: "nearest"
|
|
45
123
|
}));
|
|
46
124
|
return () => cancelAnimationFrame(frame);
|
|
47
125
|
// eslint-disable-next-line react-hooks/exhaustive-deps -- only a new selection moves the list
|
|
48
126
|
}, [active]);
|
|
127
|
+
let lastRecord;
|
|
49
128
|
return _jsxs("section", {
|
|
50
129
|
ref: panel,
|
|
51
130
|
className: "mdbase-comments",
|
|
@@ -55,6 +134,7 @@ export function CommentsPanel({
|
|
|
55
134
|
id: "VbyRUy",
|
|
56
135
|
message: "Comments"
|
|
57
136
|
}),
|
|
137
|
+
onKeyDown: onListKey,
|
|
58
138
|
children: [_jsxs("div", {
|
|
59
139
|
className: "mdbase-comments-bar",
|
|
60
140
|
children: [_jsx("div", {
|
|
@@ -69,7 +149,10 @@ export function CommentsPanel({
|
|
|
69
149
|
children: ["open", "resolved"].map(f => _jsxs("button", {
|
|
70
150
|
type: "button",
|
|
71
151
|
"aria-pressed": filter === f,
|
|
72
|
-
onClick: () =>
|
|
152
|
+
onClick: () => {
|
|
153
|
+
setFilter(f);
|
|
154
|
+
rows.reset();
|
|
155
|
+
},
|
|
73
156
|
children: [f === "open" ? _i18n._(
|
|
74
157
|
/** i18n */
|
|
75
158
|
{
|
|
@@ -99,12 +182,58 @@ export function CommentsPanel({
|
|
|
99
182
|
message: "New comment"
|
|
100
183
|
})
|
|
101
184
|
})]
|
|
185
|
+
}), threads.length > 0 && (authors.length > 1 || newCount > 0) && _jsx("div", {
|
|
186
|
+
className: "mdbase-comments-who",
|
|
187
|
+
children: _jsx(Select, {
|
|
188
|
+
"aria-label": _i18n._(
|
|
189
|
+
/** i18n */
|
|
190
|
+
{
|
|
191
|
+
id: "OoNq_l",
|
|
192
|
+
message: "Whose comments"
|
|
193
|
+
}),
|
|
194
|
+
value: who,
|
|
195
|
+
onChange: value => {
|
|
196
|
+
setWho(value);
|
|
197
|
+
rows.reset();
|
|
198
|
+
},
|
|
199
|
+
options: [{
|
|
200
|
+
value: "all",
|
|
201
|
+
label: _i18n._(
|
|
202
|
+
/** i18n */
|
|
203
|
+
{
|
|
204
|
+
id: "PsQmAw",
|
|
205
|
+
message: "Everyone"
|
|
206
|
+
})
|
|
207
|
+
}, ...(newCount > 0 || who === "new" ? [{
|
|
208
|
+
value: "new",
|
|
209
|
+
label: _i18n._(
|
|
210
|
+
/** i18n */
|
|
211
|
+
{
|
|
212
|
+
id: "g_et_N",
|
|
213
|
+
message: "New since last visit ({newCount})",
|
|
214
|
+
values: {
|
|
215
|
+
newCount: newCount
|
|
216
|
+
}
|
|
217
|
+
})
|
|
218
|
+
}] : []), ...(me ? [{
|
|
219
|
+
value: "mine",
|
|
220
|
+
label: _i18n._(
|
|
221
|
+
/** i18n */
|
|
222
|
+
{
|
|
223
|
+
id: "oSrMRT",
|
|
224
|
+
message: "Mine"
|
|
225
|
+
})
|
|
226
|
+
}] : []), ...authors.map(([value, label]) => ({
|
|
227
|
+
value,
|
|
228
|
+
label
|
|
229
|
+
}))]
|
|
230
|
+
})
|
|
102
231
|
}), notice, pending && _jsx(Composer, {
|
|
103
232
|
pending: pending,
|
|
104
233
|
signer: people.signing?.kind === "linked" ? people.me?.name : undefined,
|
|
105
234
|
onSubmit: onSubmit,
|
|
106
235
|
onCancel: onCancel
|
|
107
|
-
}, pending.quote ?? "\0whole"), loading && _jsx("p", {
|
|
236
|
+
}, `${pending.on ?? ""}\0${pending.quote ?? "\0whole"}\0${pending.suggest ? "suggest" : ""}`), loading && _jsx("p", {
|
|
108
237
|
className: "mdbase-comments-note",
|
|
109
238
|
role: "status",
|
|
110
239
|
children: _i18n._(
|
|
@@ -159,16 +288,51 @@ export function CommentsPanel({
|
|
|
159
288
|
})
|
|
160
289
|
}), _jsx("ul", {
|
|
161
290
|
className: "mdbase-threads",
|
|
162
|
-
children: shown.map(p =>
|
|
163
|
-
|
|
164
|
-
|
|
165
|
-
|
|
166
|
-
|
|
167
|
-
|
|
168
|
-
|
|
169
|
-
|
|
170
|
-
|
|
171
|
-
|
|
291
|
+
children: shown.map(p => {
|
|
292
|
+
const heading = recordTitle && p.record !== undefined && p.record !== lastRecord ? _jsx("li", {
|
|
293
|
+
className: "mdbase-threads-record",
|
|
294
|
+
children: _jsx("h3", {
|
|
295
|
+
title: recordTitle(p.record),
|
|
296
|
+
children: recordTitle(p.record)
|
|
297
|
+
})
|
|
298
|
+
}, `\0${p.record}`) : null;
|
|
299
|
+
lastRecord = p.record;
|
|
300
|
+
return [heading, _jsx(Thread, {
|
|
301
|
+
placed: p,
|
|
302
|
+
people: people,
|
|
303
|
+
drafts: drafts,
|
|
304
|
+
isNew: isNew(p),
|
|
305
|
+
active: p.thread.root.path === active,
|
|
306
|
+
onSelect: onSelect,
|
|
307
|
+
onReply: onReply,
|
|
308
|
+
onChange: onChange,
|
|
309
|
+
onAccept: onAccept,
|
|
310
|
+
onOpenRecord: onOpenRecord
|
|
311
|
+
}, p.thread.root.path)];
|
|
312
|
+
})
|
|
313
|
+
}), rows.from > 0 && _jsx("button", {
|
|
314
|
+
type: "button",
|
|
315
|
+
className: "mdbase-comments-more",
|
|
316
|
+
onClick: rows.previous,
|
|
317
|
+
children: _i18n._(
|
|
318
|
+
/** i18n */
|
|
319
|
+
{
|
|
320
|
+
id: "oloFds",
|
|
321
|
+
message: "Show previous 50 comments"
|
|
322
|
+
})
|
|
323
|
+
}), logical.length > rows.from + rows.size && _jsx("button", {
|
|
324
|
+
type: "button",
|
|
325
|
+
className: "mdbase-comments-more",
|
|
326
|
+
onClick: rows.more,
|
|
327
|
+
children: _i18n._(
|
|
328
|
+
/** i18n */
|
|
329
|
+
{
|
|
330
|
+
id: "9kjAUP",
|
|
331
|
+
message: "Show 50 more comments \xB7 {0}",
|
|
332
|
+
values: {
|
|
333
|
+
0: logical.length
|
|
334
|
+
}
|
|
335
|
+
})
|
|
172
336
|
})]
|
|
173
337
|
});
|
|
174
338
|
}
|
|
@@ -197,16 +361,28 @@ function Composer({
|
|
|
197
361
|
onSubmit,
|
|
198
362
|
onCancel
|
|
199
363
|
}) {
|
|
364
|
+
const quote = pending.quote ?? "";
|
|
365
|
+
const suggest = pending.suggest === true;
|
|
200
366
|
const [text, setText] = useState("");
|
|
201
|
-
const
|
|
367
|
+
const [replacement, setReplacement] = useState(quote);
|
|
368
|
+
const first = useRef(null);
|
|
202
369
|
const {
|
|
203
370
|
busy,
|
|
204
371
|
error,
|
|
205
372
|
run
|
|
206
373
|
} = useAction();
|
|
207
|
-
useEffect(() =>
|
|
208
|
-
const empty = !text.trim();
|
|
209
|
-
const submit = () => void run(() => onSubmit(text));
|
|
374
|
+
useEffect(() => first.current?.focus(), []);
|
|
375
|
+
const empty = suggest ? replacement === quote : !text.trim();
|
|
376
|
+
const submit = () => void run(() => onSubmit(text, suggest ? replacement : undefined));
|
|
377
|
+
const by = [signer ? _i18n._(
|
|
378
|
+
/** i18n */
|
|
379
|
+
{
|
|
380
|
+
id: "Iy_6Bk",
|
|
381
|
+
message: "as {signer}",
|
|
382
|
+
values: {
|
|
383
|
+
signer: signer
|
|
384
|
+
}
|
|
385
|
+
}) : "", pending.on ?? ""].filter(Boolean).join(" · ");
|
|
210
386
|
return _jsxs("form", {
|
|
211
387
|
className: "mdbase-thread mdbase-comment-composer",
|
|
212
388
|
onSubmit: e => {
|
|
@@ -225,52 +401,87 @@ function Composer({
|
|
|
225
401
|
children: [_jsxs("p", {
|
|
226
402
|
className: "mdbase-comment-composer-title",
|
|
227
403
|
children: [_jsx("strong", {
|
|
228
|
-
children: _i18n._(
|
|
404
|
+
children: suggest ? _i18n._(
|
|
229
405
|
/** i18n */
|
|
230
406
|
{
|
|
231
|
-
id: "
|
|
232
|
-
message: "
|
|
233
|
-
})
|
|
234
|
-
}), signer && _jsx("span", {
|
|
235
|
-
children: _i18n._(
|
|
407
|
+
id: "qxRyTp",
|
|
408
|
+
message: "Suggest an edit"
|
|
409
|
+
}) : _i18n._(
|
|
236
410
|
/** i18n */
|
|
237
411
|
{
|
|
238
|
-
id: "
|
|
239
|
-
message: "
|
|
240
|
-
values: {
|
|
241
|
-
signer: signer
|
|
242
|
-
}
|
|
412
|
+
id: "ASnGmQ",
|
|
413
|
+
message: "New comment"
|
|
243
414
|
})
|
|
415
|
+
}), by && _jsx("span", {
|
|
416
|
+
title: by,
|
|
417
|
+
children: by
|
|
244
418
|
})]
|
|
245
|
-
}),
|
|
419
|
+
}), quote ? _jsx("blockquote", {
|
|
246
420
|
className: "mdbase-thread-quote",
|
|
247
|
-
children: plainPassage(
|
|
421
|
+
children: plainPassage(quote)
|
|
248
422
|
}) : _jsx("p", {
|
|
249
423
|
className: "mdbase-thread-whole",
|
|
250
|
-
children: pending.quote ===
|
|
424
|
+
children: pending.quote === undefined ? _i18n._(
|
|
251
425
|
/** i18n */
|
|
252
426
|
{
|
|
253
|
-
id: "
|
|
254
|
-
message: "
|
|
427
|
+
id: "Po8746",
|
|
428
|
+
message: "Whole text"
|
|
429
|
+
}) : suggest ? _i18n._(
|
|
430
|
+
/** i18n */
|
|
431
|
+
{
|
|
432
|
+
id: "GH75zx",
|
|
433
|
+
message: "Insert at the cursor"
|
|
255
434
|
}) : _i18n._(
|
|
256
435
|
/** i18n */
|
|
257
436
|
{
|
|
258
|
-
id: "
|
|
259
|
-
message: "
|
|
437
|
+
id: "ZDLF2F",
|
|
438
|
+
message: "At the cursor"
|
|
260
439
|
})
|
|
440
|
+
}), suggest && _jsxs("label", {
|
|
441
|
+
className: "mdbase-comment-composer-field",
|
|
442
|
+
children: [_jsx("span", {
|
|
443
|
+
children: _i18n._(
|
|
444
|
+
/** i18n */
|
|
445
|
+
{
|
|
446
|
+
id: "7Vdedt",
|
|
447
|
+
message: "Replace with"
|
|
448
|
+
})
|
|
449
|
+
}), _jsx("textarea", {
|
|
450
|
+
ref: first,
|
|
451
|
+
className: "mdbase-field",
|
|
452
|
+
rows: 3,
|
|
453
|
+
value: replacement,
|
|
454
|
+
onChange: e => setReplacement(e.target.value),
|
|
455
|
+
"aria-label": _i18n._(
|
|
456
|
+
/** i18n */
|
|
457
|
+
{
|
|
458
|
+
id: "nyNI6f",
|
|
459
|
+
message: "Suggested text"
|
|
460
|
+
})
|
|
461
|
+
})]
|
|
261
462
|
}), _jsx("textarea", {
|
|
262
|
-
ref:
|
|
463
|
+
ref: suggest ? undefined : first,
|
|
263
464
|
className: "mdbase-field",
|
|
264
465
|
rows: 3,
|
|
265
466
|
value: text,
|
|
266
467
|
onChange: e => setText(e.target.value),
|
|
267
|
-
placeholder: _i18n._(
|
|
468
|
+
placeholder: suggest ? _i18n._(
|
|
469
|
+
/** i18n */
|
|
470
|
+
{
|
|
471
|
+
id: "6W1QoD",
|
|
472
|
+
message: "Why (optional)"
|
|
473
|
+
}) : _i18n._(
|
|
268
474
|
/** i18n */
|
|
269
475
|
{
|
|
270
476
|
id: "NBdIgR",
|
|
271
477
|
message: "Comment"
|
|
272
478
|
}),
|
|
273
|
-
"aria-label": _i18n._(
|
|
479
|
+
"aria-label": suggest ? _i18n._(
|
|
480
|
+
/** i18n */
|
|
481
|
+
{
|
|
482
|
+
id: "sKTbyg",
|
|
483
|
+
message: "Reason for the suggestion"
|
|
484
|
+
}) : _i18n._(
|
|
274
485
|
/** i18n */
|
|
275
486
|
{
|
|
276
487
|
id: "NBdIgR",
|
|
@@ -286,7 +497,12 @@ function Composer({
|
|
|
286
497
|
type: "submit",
|
|
287
498
|
className: "mdbase-button is-primary",
|
|
288
499
|
disabled: busy || empty,
|
|
289
|
-
children: _i18n._(
|
|
500
|
+
children: suggest ? _i18n._(
|
|
501
|
+
/** i18n */
|
|
502
|
+
{
|
|
503
|
+
id: "L3-fF1",
|
|
504
|
+
message: "Suggest"
|
|
505
|
+
}) : _i18n._(
|
|
290
506
|
/** i18n */
|
|
291
507
|
{
|
|
292
508
|
id: "NBdIgR",
|
|
@@ -310,6 +526,8 @@ function Composer({
|
|
|
310
526
|
const Thread = memo(function Thread({
|
|
311
527
|
placed,
|
|
312
528
|
people,
|
|
529
|
+
drafts,
|
|
530
|
+
isNew,
|
|
313
531
|
active,
|
|
314
532
|
onSelect,
|
|
315
533
|
onReply,
|
|
@@ -324,8 +542,15 @@ const Thread = memo(function Thread({
|
|
|
324
542
|
const {
|
|
325
543
|
root
|
|
326
544
|
} = thread;
|
|
327
|
-
const [reply, setReply] = useState("");
|
|
328
|
-
const [replying, setReplying] = useState(false);
|
|
545
|
+
const [reply, setReply] = useState(() => drafts.get(root.path)?.reply ?? "");
|
|
546
|
+
const [replying, setReplying] = useState(() => drafts.get(root.path)?.replying ?? false);
|
|
547
|
+
useEffect(() => {
|
|
548
|
+
drafts.set(root.path, {
|
|
549
|
+
reply,
|
|
550
|
+
replying
|
|
551
|
+
});
|
|
552
|
+
}, [drafts, root.path, reply, replying]);
|
|
553
|
+
const [repliesShown, setRepliesShown] = useState(PAGE);
|
|
329
554
|
const {
|
|
330
555
|
busy,
|
|
331
556
|
error,
|
|
@@ -390,10 +615,18 @@ const Thread = memo(function Thread({
|
|
|
390
615
|
}) : _i18n._(
|
|
391
616
|
/** i18n */
|
|
392
617
|
{
|
|
393
|
-
id: "
|
|
394
|
-
message: "Show in the
|
|
618
|
+
id: "D-ue9X",
|
|
619
|
+
message: "Show in the editor"
|
|
395
620
|
}),
|
|
396
|
-
children: [
|
|
621
|
+
children: [isNew && _jsx("span", {
|
|
622
|
+
className: "mdbase-thread-new",
|
|
623
|
+
children: _i18n._(
|
|
624
|
+
/** i18n */
|
|
625
|
+
{
|
|
626
|
+
id: "SNiqj2",
|
|
627
|
+
message: "New since your last visit"
|
|
628
|
+
})
|
|
629
|
+
}), suggestion ? _jsx(Suggestion, {
|
|
397
630
|
root: root
|
|
398
631
|
}) : root.target ? _jsx("blockquote", {
|
|
399
632
|
className: "mdbase-thread-quote",
|
|
@@ -408,8 +641,8 @@ const Thread = memo(function Thread({
|
|
|
408
641
|
children: _i18n._(
|
|
409
642
|
/** i18n */
|
|
410
643
|
{
|
|
411
|
-
id: "
|
|
412
|
-
message: "
|
|
644
|
+
id: "Po8746",
|
|
645
|
+
message: "Whole text"
|
|
413
646
|
})
|
|
414
647
|
}), at === null && _jsx("span", {
|
|
415
648
|
className: "mdbase-thread-detached",
|
|
@@ -423,12 +656,25 @@ const Thread = memo(function Thread({
|
|
|
423
656
|
}), _jsx(Comment, {
|
|
424
657
|
comment: root,
|
|
425
658
|
people: people
|
|
426
|
-
}), thread.replies.map(r => _jsx(Comment, {
|
|
659
|
+
}), thread.replies.slice(0, repliesShown).map(r => _jsx(Comment, {
|
|
427
660
|
comment: r,
|
|
428
661
|
people: people,
|
|
429
662
|
reply: true,
|
|
430
663
|
children: withdraw(r)
|
|
431
|
-
}, r.path)),
|
|
664
|
+
}, r.path)), thread.replies.length > repliesShown && _jsx("button", {
|
|
665
|
+
type: "button",
|
|
666
|
+
className: "mdbase-comments-more",
|
|
667
|
+
onClick: () => setRepliesShown(n => n + PAGE),
|
|
668
|
+
children: _i18n._(
|
|
669
|
+
/** i18n */
|
|
670
|
+
{
|
|
671
|
+
id: "0IfD81",
|
|
672
|
+
message: "Show 50 more replies \xB7 {0}",
|
|
673
|
+
values: {
|
|
674
|
+
0: thread.replies.length
|
|
675
|
+
}
|
|
676
|
+
})
|
|
677
|
+
}), resolvedNote && _jsx("p", {
|
|
432
678
|
className: "mdbase-thread-resolved",
|
|
433
679
|
children: resolvedNote
|
|
434
680
|
}), error && _jsx("p", {
|
package/dist/comments.d.ts
CHANGED
|
@@ -104,6 +104,8 @@ export declare function editorTarget(target: CommentTarget): CommentTarget;
|
|
|
104
104
|
export declare function applySuggestion(body: string, target: CommentTarget, replacement: string): string | null;
|
|
105
105
|
export interface PlacedThread {
|
|
106
106
|
readonly thread: CommentThread;
|
|
107
|
+
/** The record it is on, for a panel that shows the threads of several. */
|
|
108
|
+
readonly record?: string;
|
|
107
109
|
/** Where its passage is now: "whole" for a comment on the whole record, null when detached. */
|
|
108
110
|
readonly at: Located | "whole" | null;
|
|
109
111
|
}
|
|
@@ -176,6 +178,8 @@ export declare const personKey: (pathOrLink: string) => string;
|
|
|
176
178
|
export declare function personName(link: string | undefined, people: CommentPeople): string | undefined;
|
|
177
179
|
/** Whether `comment` was written by the signed-in account's person. */
|
|
178
180
|
export declare function writtenByMe(comment: CommentRecord, people: CommentPeople): boolean;
|
|
181
|
+
/** Whether anyone else has written in the thread since `since` (a thread only of one's own is never new). */
|
|
182
|
+
export declare function threadIsNew(thread: CommentThread, since: string | undefined, people: CommentPeople): boolean;
|
|
179
183
|
/**
|
|
180
184
|
* A passage of Markdown as it reads: emphasis, code and link markup dropped,
|
|
181
185
|
* soft line breaks as spaces ("*modal picture*" → "modal picture").
|
package/dist/comments.js
CHANGED
|
@@ -419,6 +419,11 @@ export function personName(link, people) {
|
|
|
419
419
|
export function writtenByMe(comment, people) {
|
|
420
420
|
return Boolean(people.me && comment.createdBy && personKey(comment.createdBy) === personKey(people.me.link));
|
|
421
421
|
}
|
|
422
|
+
/** Whether anyone else has written in the thread since `since` (a thread only of one's own is never new). */
|
|
423
|
+
export function threadIsNew(thread, since, people) {
|
|
424
|
+
if (!since) return false;
|
|
425
|
+
return [thread.root, ...thread.replies].some(c => !c.deletedAt && !writtenByMe(c, people) && c.createdAt > since);
|
|
426
|
+
}
|
|
422
427
|
/**
|
|
423
428
|
* A passage of Markdown as it reads: emphasis, code and link markup dropped,
|
|
424
429
|
* soft line breaks as spaces ("*modal picture*" → "modal picture").
|