@mdbase-dev/ui 0.1.0-beta.172 → 0.1.0-beta.176

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 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 { display: grid; gap: 6px; }
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. */
@@ -145,7 +177,8 @@ blockquote.mdbase-thread-quote::after { content: "”"; }
145
177
  .mdbase-thread-action.is-quiet { color: var(--color-text-muted); }
146
178
 
147
179
  .mdbase-comment-composer-title { display: flex; align-items: baseline; gap: 6px; margin: 0; }
148
- .mdbase-comment-composer-title span { overflow: hidden; color: var(--color-text-muted); text-overflow: ellipsis; white-space: nowrap; }
180
+ .mdbase-comment-composer-title strong { flex: none; white-space: nowrap; }
181
+ .mdbase-comment-composer-title span { min-width: 0; overflow: hidden; color: var(--color-text-muted); text-overflow: ellipsis; white-space: nowrap; }
149
182
 
150
183
  /* A comment: who and when, the text beneath; replies are indented under the first. */
151
184
  .mdbase-comment { display: grid; gap: 2px; }
@@ -169,6 +202,24 @@ blockquote.mdbase-thread-quote::after { content: "”"; }
169
202
  border-left: 2px solid var(--color-warning);
170
203
  vertical-align: text-bottom;
171
204
  }
205
+ /* The margin mark on a commented line (commentAnchors with `margin`). */
206
+ .cm-comment-gutter { width: 16px; }
207
+ .cm-comment-gutter .cm-gutterElement { display: flex; align-items: center; justify-content: center; }
208
+ .cm-comment-marker {
209
+ width: 12px;
210
+ min-width: 12px;
211
+ height: 12px;
212
+ padding: 0;
213
+ border: 0;
214
+ border-radius: 50%;
215
+ color: var(--color-text);
216
+ background: color-mix(in oklch, var(--color-warning) 70%, transparent);
217
+ font-size: 9px;
218
+ line-height: 12px;
219
+ cursor: pointer;
220
+ }
221
+ .cm-comment-marker:hover,
222
+ .cm-comment-marker.is-active { background: var(--color-warning); }
172
223
  :is(.cm-suggest-delete, .cm-suggest-insert).is-active { border-radius: var(--radius-sm); background: var(--color-selected); }
173
224
  .cm-tooltip .cm-comment-tip { display: grid; gap: 2px; max-width: 320px; padding: 8px 10px; font-size: var(--font-size-ui); }
174
225
  .cm-comment-who { color: var(--color-text-muted); font-size: var(--font-size-caption); }
@@ -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
- readonly onSubmit: (text: string) => Promise<CommentResult>;
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,21 @@ 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;
58
+ /** The form a new comment or suggested edit is written in, for an app that also shows it beside the text. */
59
+ export declare function CommentComposer({ pending, signer, onSubmit, onCancel }: {
60
+ pending: PendingComment;
61
+ signer: string | undefined;
62
+ onSubmit(text: string, replacement?: string): Promise<CommentResult>;
63
+ onCancel(): void;
64
+ }): JSX.Element;
42
65
  /** "3 open comments", for a control that opens them. */
43
66
  export declare function openCommentCount(threads: readonly PlacedThread[]): string;
44
67
  export {};
@@ -1,13 +1,48 @@
1
1
  import { Fragment as _Fragment, jsx as _jsx, jsxs as _jsxs } from "react/jsx-runtime";
2
- // The comments on one record: threads in reading order, with replies,
3
- // resolving, and suggested edits to accept or reject. A new comment starts
4
- // from a passage the app hands in (`pending`). Style with
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) setFilter(hit.thread.root.status);
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: () => setFilter(f),
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
  })]
102
- }), notice, pending && _jsx(Composer, {
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
+ })
231
+ }), notice, pending && _jsx(CommentComposer, {
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 => _jsx(Thread, {
163
- placed: p,
164
- people: people,
165
- active: p.thread.root.path === active,
166
- onSelect: onSelect,
167
- onReply: onReply,
168
- onChange: onChange,
169
- onAccept: onAccept,
170
- onOpenRecord: onOpenRecord
171
- }, p.thread.root.path))
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
  }
@@ -191,22 +355,35 @@ function useAction() {
191
355
  };
192
356
  }
193
357
  const submitsOnModEnter = event => event.key === "Enter" && (event.metaKey || event.ctrlKey);
194
- function Composer({
358
+ /** The form a new comment or suggested edit is written in, for an app that also shows it beside the text. */
359
+ export function CommentComposer({
195
360
  pending,
196
361
  signer,
197
362
  onSubmit,
198
363
  onCancel
199
364
  }) {
365
+ const quote = pending.quote ?? "";
366
+ const suggest = pending.suggest === true;
200
367
  const [text, setText] = useState("");
201
- const field = useRef(null);
368
+ const [replacement, setReplacement] = useState(quote);
369
+ const first = useRef(null);
202
370
  const {
203
371
  busy,
204
372
  error,
205
373
  run
206
374
  } = useAction();
207
- useEffect(() => field.current?.focus(), []);
208
- const empty = !text.trim();
209
- const submit = () => void run(() => onSubmit(text));
375
+ useEffect(() => first.current?.focus(), []);
376
+ const empty = suggest ? replacement === quote : !text.trim();
377
+ const submit = () => void run(() => onSubmit(text, suggest ? replacement : undefined));
378
+ const by = [signer ? _i18n._(
379
+ /** i18n */
380
+ {
381
+ id: "Iy_6Bk",
382
+ message: "as {signer}",
383
+ values: {
384
+ signer: signer
385
+ }
386
+ }) : "", pending.on ?? ""].filter(Boolean).join(" · ");
210
387
  return _jsxs("form", {
211
388
  className: "mdbase-thread mdbase-comment-composer",
212
389
  onSubmit: e => {
@@ -225,52 +402,87 @@ function Composer({
225
402
  children: [_jsxs("p", {
226
403
  className: "mdbase-comment-composer-title",
227
404
  children: [_jsx("strong", {
228
- children: _i18n._(
405
+ children: suggest ? _i18n._(
229
406
  /** i18n */
230
407
  {
231
- id: "ASnGmQ",
232
- message: "New comment"
233
- })
234
- }), signer && _jsx("span", {
235
- children: _i18n._(
408
+ id: "qxRyTp",
409
+ message: "Suggest an edit"
410
+ }) : _i18n._(
236
411
  /** i18n */
237
412
  {
238
- id: "Iy_6Bk",
239
- message: "as {signer}",
240
- values: {
241
- signer: signer
242
- }
413
+ id: "ASnGmQ",
414
+ message: "New comment"
243
415
  })
416
+ }), by && _jsx("span", {
417
+ title: by,
418
+ children: by
244
419
  })]
245
- }), pending.quote ? _jsx("blockquote", {
420
+ }), quote ? _jsx("blockquote", {
246
421
  className: "mdbase-thread-quote",
247
- children: plainPassage(pending.quote)
422
+ children: plainPassage(quote)
248
423
  }) : _jsx("p", {
249
424
  className: "mdbase-thread-whole",
250
- children: pending.quote === "" ? _i18n._(
425
+ children: pending.quote === undefined ? _i18n._(
251
426
  /** i18n */
252
427
  {
253
- id: "ZDLF2F",
254
- message: "At the cursor"
428
+ id: "Po8746",
429
+ message: "Whole text"
430
+ }) : suggest ? _i18n._(
431
+ /** i18n */
432
+ {
433
+ id: "GH75zx",
434
+ message: "Insert at the cursor"
255
435
  }) : _i18n._(
256
436
  /** i18n */
257
437
  {
258
- id: "9-gb1N",
259
- message: "On the whole note"
438
+ id: "ZDLF2F",
439
+ message: "At the cursor"
260
440
  })
441
+ }), suggest && _jsxs("label", {
442
+ className: "mdbase-comment-composer-field",
443
+ children: [_jsx("span", {
444
+ children: _i18n._(
445
+ /** i18n */
446
+ {
447
+ id: "7Vdedt",
448
+ message: "Replace with"
449
+ })
450
+ }), _jsx("textarea", {
451
+ ref: first,
452
+ className: "mdbase-field",
453
+ rows: 3,
454
+ value: replacement,
455
+ onChange: e => setReplacement(e.target.value),
456
+ "aria-label": _i18n._(
457
+ /** i18n */
458
+ {
459
+ id: "nyNI6f",
460
+ message: "Suggested text"
461
+ })
462
+ })]
261
463
  }), _jsx("textarea", {
262
- ref: field,
464
+ ref: suggest ? undefined : first,
263
465
  className: "mdbase-field",
264
466
  rows: 3,
265
467
  value: text,
266
468
  onChange: e => setText(e.target.value),
267
- placeholder: _i18n._(
469
+ placeholder: suggest ? _i18n._(
470
+ /** i18n */
471
+ {
472
+ id: "6W1QoD",
473
+ message: "Why (optional)"
474
+ }) : _i18n._(
268
475
  /** i18n */
269
476
  {
270
477
  id: "NBdIgR",
271
478
  message: "Comment"
272
479
  }),
273
- "aria-label": _i18n._(
480
+ "aria-label": suggest ? _i18n._(
481
+ /** i18n */
482
+ {
483
+ id: "sKTbyg",
484
+ message: "Reason for the suggestion"
485
+ }) : _i18n._(
274
486
  /** i18n */
275
487
  {
276
488
  id: "NBdIgR",
@@ -286,7 +498,12 @@ function Composer({
286
498
  type: "submit",
287
499
  className: "mdbase-button is-primary",
288
500
  disabled: busy || empty,
289
- children: _i18n._(
501
+ children: suggest ? _i18n._(
502
+ /** i18n */
503
+ {
504
+ id: "L3-fF1",
505
+ message: "Suggest"
506
+ }) : _i18n._(
290
507
  /** i18n */
291
508
  {
292
509
  id: "NBdIgR",
@@ -310,6 +527,8 @@ function Composer({
310
527
  const Thread = memo(function Thread({
311
528
  placed,
312
529
  people,
530
+ drafts,
531
+ isNew,
313
532
  active,
314
533
  onSelect,
315
534
  onReply,
@@ -324,8 +543,15 @@ const Thread = memo(function Thread({
324
543
  const {
325
544
  root
326
545
  } = thread;
327
- const [reply, setReply] = useState("");
328
- const [replying, setReplying] = useState(false);
546
+ const [reply, setReply] = useState(() => drafts.get(root.path)?.reply ?? "");
547
+ const [replying, setReplying] = useState(() => drafts.get(root.path)?.replying ?? false);
548
+ useEffect(() => {
549
+ drafts.set(root.path, {
550
+ reply,
551
+ replying
552
+ });
553
+ }, [drafts, root.path, reply, replying]);
554
+ const [repliesShown, setRepliesShown] = useState(PAGE);
329
555
  const {
330
556
  busy,
331
557
  error,
@@ -390,10 +616,18 @@ const Thread = memo(function Thread({
390
616
  }) : _i18n._(
391
617
  /** i18n */
392
618
  {
393
- id: "tZaM-o",
394
- message: "Show in the note"
619
+ id: "D-ue9X",
620
+ message: "Show in the editor"
395
621
  }),
396
- children: [suggestion ? _jsx(Suggestion, {
622
+ children: [isNew && _jsx("span", {
623
+ className: "mdbase-thread-new",
624
+ children: _i18n._(
625
+ /** i18n */
626
+ {
627
+ id: "SNiqj2",
628
+ message: "New since your last visit"
629
+ })
630
+ }), suggestion ? _jsx(Suggestion, {
397
631
  root: root
398
632
  }) : root.target ? _jsx("blockquote", {
399
633
  className: "mdbase-thread-quote",
@@ -408,8 +642,8 @@ const Thread = memo(function Thread({
408
642
  children: _i18n._(
409
643
  /** i18n */
410
644
  {
411
- id: "9-gb1N",
412
- message: "On the whole note"
645
+ id: "Po8746",
646
+ message: "Whole text"
413
647
  })
414
648
  }), at === null && _jsx("span", {
415
649
  className: "mdbase-thread-detached",
@@ -423,12 +657,25 @@ const Thread = memo(function Thread({
423
657
  }), _jsx(Comment, {
424
658
  comment: root,
425
659
  people: people
426
- }), thread.replies.map(r => _jsx(Comment, {
660
+ }), thread.replies.slice(0, repliesShown).map(r => _jsx(Comment, {
427
661
  comment: r,
428
662
  people: people,
429
663
  reply: true,
430
664
  children: withdraw(r)
431
- }, r.path)), resolvedNote && _jsx("p", {
665
+ }, r.path)), thread.replies.length > repliesShown && _jsx("button", {
666
+ type: "button",
667
+ className: "mdbase-comments-more",
668
+ onClick: () => setRepliesShown(n => n + PAGE),
669
+ children: _i18n._(
670
+ /** i18n */
671
+ {
672
+ id: "0IfD81",
673
+ message: "Show 50 more replies \xB7 {0}",
674
+ values: {
675
+ 0: thread.replies.length
676
+ }
677
+ })
678
+ }), resolvedNote && _jsx("p", {
432
679
  className: "mdbase-thread-resolved",
433
680
  children: resolvedNote
434
681
  }), error && _jsx("p", {
@@ -20,9 +20,12 @@ export interface CommentAnchorCard {
20
20
  }
21
21
  /**
22
22
  * Anchors, a click on one (its thread's id), and a card on hover saying who
23
- * said what. Call `showCommentAnchors` whenever the threads change.
23
+ * said what. With `margin`, each commented line also has a mark in the
24
+ * editor's margin. Call `showCommentAnchors` whenever the threads change.
24
25
  */
25
- export declare function commentAnchors(onAnchor: (id: string) => void, card?: (id: string) => CommentAnchorCard | null): Extension;
26
+ export declare function commentAnchors(onAnchor: (id: string) => void, card?: (id: string) => CommentAnchorCard | null, { margin }?: {
27
+ readonly margin?: boolean;
28
+ }): Extension;
26
29
  export declare function showCommentAnchors(view: EditorView, anchors: readonly CommentAnchor[], active: string | null): void;
27
30
  /** Where the anchor of thread `id` is in the editor's text now, or null when it is not shown. */
28
31
  export declare function commentAnchorRange(view: EditorView, id: string): {