@rapidmx/web-client 0.6.0 → 0.7.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/apps/shared/components/admin/settings/BrandingForm.tsx +398 -385
- package/apps/shared/components/admin/settings/EncryptionPolicyForm.tsx +119 -112
- package/apps/shared/components/admin/settings/MailboxPolicyForm.tsx +159 -152
- package/apps/shared/components/admin/settings/PluginsManager.tsx +1288 -1235
- package/apps/shared/components/admin/settings/RetentionPolicyForm.tsx +9 -1
- package/apps/shared/components/admin/setup/EscrowSetupStep.tsx +288 -290
- package/apps/shared/components/admin/setup/SetupWizard.tsx +443 -416
- package/apps/shared/components/layout/AppShell.tsx +288 -288
- package/apps/shared/components/mail/ConversationList.tsx +225 -33
- package/apps/shared/components/mail/ConversationThreadPane.tsx +434 -216
- package/apps/shared/components/mail/MailListToolbar.tsx +265 -0
- package/apps/shared/components/mail/MailSelectionBar.tsx +222 -0
- package/apps/shared/components/mail/MenuButton.tsx +384 -0
- package/apps/shared/components/mail/MessageDetailPane.tsx +280 -215
- package/apps/shared/components/mail/MoveToFolderDialog.tsx +263 -0
- package/apps/shared/components/mail/compose/ComposeContext.tsx +29 -2
- package/apps/shared/components/mail/compose/ComposeWindow.tsx +1700 -1652
- package/apps/shared/components/mail/compose/RecipientInput.tsx +356 -0
- package/apps/shared/components/mail/compose/RichTextEditor.tsx +38 -3
- package/apps/shared/components/mail/compose/quotedBody.ts +100 -0
- package/apps/shared/components/mail/compose/recipients.ts +104 -0
- package/apps/shared/components/mail/labelMenu.tsx +278 -0
- package/apps/shared/components/mail/layout/MailShell.tsx +445 -420
- package/apps/shared/components/mail/listPreferences.ts +228 -0
- package/apps/shared/components/settings/layout/SettingsShell.tsx +0 -1
- package/apps/shared/styles/app.css +28 -5
- package/apps/www/index.tsx +1854 -1314
- package/apps/www/messages/[uid].tsx +5 -4
- package/dist/apps/shared/components/admin/settings/BrandingForm.d.ts +7 -3
- package/dist/apps/shared/components/admin/settings/BrandingForm.js +6 -5
- package/dist/apps/shared/components/admin/settings/EncryptionPolicyForm.d.ts +4 -1
- package/dist/apps/shared/components/admin/settings/EncryptionPolicyForm.js +2 -2
- package/dist/apps/shared/components/admin/settings/MailboxPolicyForm.d.ts +4 -1
- package/dist/apps/shared/components/admin/settings/MailboxPolicyForm.js +2 -2
- package/dist/apps/shared/components/admin/settings/PluginsManager.d.ts +8 -1
- package/dist/apps/shared/components/admin/settings/PluginsManager.js +33 -14
- package/dist/apps/shared/components/admin/settings/RetentionPolicyForm.d.ts +4 -1
- package/dist/apps/shared/components/admin/settings/RetentionPolicyForm.js +2 -2
- package/dist/apps/shared/components/admin/setup/EscrowSetupStep.js +1 -1
- package/dist/apps/shared/components/admin/setup/SetupWizard.js +14 -10
- package/dist/apps/shared/components/mail/ConversationList.d.ts +42 -6
- package/dist/apps/shared/components/mail/ConversationList.js +84 -10
- package/dist/apps/shared/components/mail/ConversationThreadPane.d.ts +52 -13
- package/dist/apps/shared/components/mail/ConversationThreadPane.js +217 -60
- package/dist/apps/shared/components/mail/MailListToolbar.d.ts +55 -0
- package/dist/apps/shared/components/mail/MailListToolbar.js +149 -0
- package/dist/apps/shared/components/mail/MailSelectionBar.d.ts +59 -0
- package/dist/apps/shared/components/mail/MailSelectionBar.js +48 -0
- package/dist/apps/shared/components/mail/MenuButton.d.ts +71 -0
- package/dist/apps/shared/components/mail/MenuButton.js +211 -0
- package/dist/apps/shared/components/mail/MessageDetailPane.d.ts +27 -19
- package/dist/apps/shared/components/mail/MessageDetailPane.js +126 -129
- package/dist/apps/shared/components/mail/MoveToFolderDialog.d.ts +57 -0
- package/dist/apps/shared/components/mail/MoveToFolderDialog.js +138 -0
- package/dist/apps/shared/components/mail/compose/ComposeContext.d.ts +16 -1
- package/dist/apps/shared/components/mail/compose/ComposeContext.js +3 -1
- package/dist/apps/shared/components/mail/compose/ComposeWindow.js +52 -20
- package/dist/apps/shared/components/mail/compose/RecipientInput.d.ts +36 -0
- package/dist/apps/shared/components/mail/compose/RecipientInput.js +203 -0
- package/dist/apps/shared/components/mail/compose/RichTextEditor.d.ts +10 -1
- package/dist/apps/shared/components/mail/compose/RichTextEditor.js +21 -3
- package/dist/apps/shared/components/mail/compose/quotedBody.d.ts +37 -0
- package/dist/apps/shared/components/mail/compose/quotedBody.js +85 -0
- package/dist/apps/shared/components/mail/compose/recipients.d.ts +24 -0
- package/dist/apps/shared/components/mail/compose/recipients.js +87 -0
- package/dist/apps/shared/components/mail/labelMenu.d.ts +97 -0
- package/dist/apps/shared/components/mail/labelMenu.js +134 -0
- package/dist/apps/shared/components/mail/layout/MailShell.d.ts +8 -0
- package/dist/apps/shared/components/mail/layout/MailShell.js +15 -3
- package/dist/apps/shared/components/mail/listPreferences.d.ts +101 -0
- package/dist/apps/shared/components/mail/listPreferences.js +186 -0
- package/dist/apps/shared/components/settings/layout/SettingsShell.js +0 -1
- package/dist/apps/shared/styles/app.css +28 -5
- package/dist/apps/www/index.js +506 -112
- package/dist/apps/www/messages/[uid].js +2 -3
- package/package.json +2 -2
- package/apps/www/settings/focused-inbox/index.tsx +0 -150
- package/dist/apps/www/settings/focused-inbox/index.d.ts +0 -4
- package/dist/apps/www/settings/focused-inbox/index.js +0 -71
|
@@ -0,0 +1,356 @@
|
|
|
1
|
+
///////////////////////////////////////////////////////////////////////////////
|
|
2
|
+
// Copyright (C) 2026 Jean-Philippe Steinmetz
|
|
3
|
+
// SPDX-License-Identifier: MPL-2.0
|
|
4
|
+
///////////////////////////////////////////////////////////////////////////////
|
|
5
|
+
import React, { ChangeEvent, KeyboardEvent, useEffect, useLayoutEffect, useRef, useState } from "react";
|
|
6
|
+
import { createPortal } from "react-dom";
|
|
7
|
+
import { HiOutlineXMark } from "react-icons/hi2";
|
|
8
|
+
import {
|
|
9
|
+
fetchRecipientSuggestions,
|
|
10
|
+
RECIPIENT_SUGGESTION_MIN_QUERY_LENGTH,
|
|
11
|
+
type ContactSuggestionOptions,
|
|
12
|
+
type RecipientSuggestion,
|
|
13
|
+
type RecipientSuggestionKind,
|
|
14
|
+
} from "@rapidmx/react-shared/mail/directoryApi.js";
|
|
15
|
+
import { formatRecipient, isValidRecipientAddress, parseRecipient, splitRecipientList, splitTypedRecipients } from "./recipients.js";
|
|
16
|
+
|
|
17
|
+
/** How long typing must pause before suggestions are requested. */
|
|
18
|
+
export const RECIPIENT_SUGGESTION_DEBOUNCE_MS = 150;
|
|
19
|
+
|
|
20
|
+
const KIND_LABELS: Record<RecipientSuggestionKind, string> = {
|
|
21
|
+
contact: "Contact",
|
|
22
|
+
user: "Person",
|
|
23
|
+
shared: "Shared mailbox",
|
|
24
|
+
room: "Room",
|
|
25
|
+
equipment: "Equipment",
|
|
26
|
+
list: "Group",
|
|
27
|
+
};
|
|
28
|
+
|
|
29
|
+
export interface RecipientInputProps {
|
|
30
|
+
/** The input's id, which the field's `<label htmlFor>` names. Also prefixes the listbox and option ids. */
|
|
31
|
+
id: string;
|
|
32
|
+
/** The field's name ("To", "Cc", "Bcc"), used in the recipient list's and suggestions' accessible names. */
|
|
33
|
+
label: string;
|
|
34
|
+
/** The field's text: recipients separated by commas, as `parseRecipientList()` reads it. */
|
|
35
|
+
value: string;
|
|
36
|
+
onChange: (value: string) => void;
|
|
37
|
+
/** Called with the field's text when focus leaves the input. */
|
|
38
|
+
onBlur?: (value: string) => void;
|
|
39
|
+
/** Called with the field's text after a suggestion is picked (focus stays in the input). */
|
|
40
|
+
onCommit?: (value: string) => void;
|
|
41
|
+
/** The mailbox being composed from, whose contacts are suggested too. */
|
|
42
|
+
mailboxUid?: string;
|
|
43
|
+
/** Loads suggestions; defaults to react-shared's `fetchRecipientSuggestions()`. */
|
|
44
|
+
fetchSuggestions?: (query: string, options: ContactSuggestionOptions) => Promise<RecipientSuggestion[]>;
|
|
45
|
+
debounceMs?: number;
|
|
46
|
+
disabled?: boolean;
|
|
47
|
+
/** Focuses the input when it mounts - a new message starts in To. */
|
|
48
|
+
autoFocus?: boolean;
|
|
49
|
+
}
|
|
50
|
+
|
|
51
|
+
interface DropdownPosition {
|
|
52
|
+
left: number;
|
|
53
|
+
width: number;
|
|
54
|
+
top?: number;
|
|
55
|
+
bottom?: number;
|
|
56
|
+
maxHeight: number;
|
|
57
|
+
}
|
|
58
|
+
|
|
59
|
+
/** Where the suggestions go: under the field (or above it when there's much more room there), as wide as the field. */
|
|
60
|
+
function dropdownPosition(anchor: HTMLElement): DropdownPosition {
|
|
61
|
+
const rect = anchor.getBoundingClientRect();
|
|
62
|
+
const margin = 8;
|
|
63
|
+
const width = Math.min(Math.max(rect.width, 260), window.innerWidth - margin * 2);
|
|
64
|
+
const left = Math.min(Math.max(rect.left, margin), window.innerWidth - width - margin);
|
|
65
|
+
const below = window.innerHeight - rect.bottom - margin;
|
|
66
|
+
const above = rect.top - margin;
|
|
67
|
+
if (below < 160 && above > below) {
|
|
68
|
+
return { left, width, bottom: window.innerHeight - rect.top + 2, maxHeight: Math.min(320, above) };
|
|
69
|
+
}
|
|
70
|
+
return { left, width, top: rect.bottom + 2, maxHeight: Math.max(120, Math.min(320, below)) };
|
|
71
|
+
}
|
|
72
|
+
|
|
73
|
+
/**
|
|
74
|
+
* A To/Cc/Bcc field: committed recipients as removable chips, and a WAI-ARIA combobox for the one being typed that
|
|
75
|
+
* suggests the caller's contacts and the server directory (contacts first, one entry per address). The field's value is
|
|
76
|
+
* still plain text (recipients separated by commas), so drafts, autosave and sending read it as before.
|
|
77
|
+
*
|
|
78
|
+
* Typing a comma or semicolon (outside a quoted name or angle brackets), pressing Enter, or leaving the field turns the
|
|
79
|
+
* typed text into a chip; pasted lists split the same way. Suggestions load `debounceMs` after typing pauses, for at
|
|
80
|
+
* least two characters, and a newer query aborts an older request. Arrow keys move through them, Enter or Tab picks
|
|
81
|
+
* one (as `Name <address>`), Escape closes them, and Backspace in an empty input removes the last chip.
|
|
82
|
+
*/
|
|
83
|
+
export default function RecipientInput({
|
|
84
|
+
id,
|
|
85
|
+
label,
|
|
86
|
+
value,
|
|
87
|
+
onChange,
|
|
88
|
+
onBlur,
|
|
89
|
+
onCommit,
|
|
90
|
+
mailboxUid,
|
|
91
|
+
fetchSuggestions = fetchRecipientSuggestions,
|
|
92
|
+
debounceMs = RECIPIENT_SUGGESTION_DEBOUNCE_MS,
|
|
93
|
+
disabled,
|
|
94
|
+
autoFocus,
|
|
95
|
+
}: RecipientInputProps) {
|
|
96
|
+
const [pending, setPending] = useState("");
|
|
97
|
+
const [suggestions, setSuggestions] = useState<RecipientSuggestion[]>([]);
|
|
98
|
+
const [open, setOpen] = useState(false);
|
|
99
|
+
const [activeIndex, setActiveIndex] = useState(0);
|
|
100
|
+
const [position, setPosition] = useState<DropdownPosition | null>(null);
|
|
101
|
+
const anchorRef = useRef<HTMLDivElement>(null);
|
|
102
|
+
const inputRef = useRef<HTMLInputElement>(null);
|
|
103
|
+
const fetchRef = useRef(fetchSuggestions);
|
|
104
|
+
fetchRef.current = fetchSuggestions;
|
|
105
|
+
|
|
106
|
+
const tokens = splitRecipientList(value);
|
|
107
|
+
const pendingText = pending.trim();
|
|
108
|
+
// The typed text is the value's last recipient; a value changed from outside that doesn't end with it drops it.
|
|
109
|
+
const pendingActive = pendingText !== "" && tokens[tokens.length - 1] === pendingText;
|
|
110
|
+
const chips = pendingActive ? tokens.slice(0, -1) : tokens;
|
|
111
|
+
const inputValue = pendingActive ? pending : "";
|
|
112
|
+
const query = pendingActive ? pendingText : "";
|
|
113
|
+
const listboxId = `${id}-suggestions`;
|
|
114
|
+
const optionId = (index: number) => `${id}-suggestion-${index}`;
|
|
115
|
+
|
|
116
|
+
useEffect(() => {
|
|
117
|
+
if (pending !== "" && !pendingActive) {
|
|
118
|
+
setPending("");
|
|
119
|
+
}
|
|
120
|
+
}, [pending, pendingActive]);
|
|
121
|
+
|
|
122
|
+
const committedAddresses = new Set(chips.map((chip) => parseRecipient(chip).address.toLowerCase()));
|
|
123
|
+
const visible = suggestions.filter((suggestion) => !committedAddresses.has(suggestion.address.toLowerCase()));
|
|
124
|
+
const expanded = open && visible.length > 0 && query.length >= RECIPIENT_SUGGESTION_MIN_QUERY_LENGTH;
|
|
125
|
+
const active = Math.min(activeIndex, visible.length - 1);
|
|
126
|
+
|
|
127
|
+
useEffect(() => {
|
|
128
|
+
if (query.length < RECIPIENT_SUGGESTION_MIN_QUERY_LENGTH) {
|
|
129
|
+
setSuggestions([]);
|
|
130
|
+
return;
|
|
131
|
+
}
|
|
132
|
+
const controller = new AbortController();
|
|
133
|
+
const timer = setTimeout(() => {
|
|
134
|
+
fetchRef.current(query, { mailboxUid, signal: controller.signal }).then(
|
|
135
|
+
(result) => {
|
|
136
|
+
if (!controller.signal.aborted) {
|
|
137
|
+
setSuggestions(result);
|
|
138
|
+
setActiveIndex(0);
|
|
139
|
+
}
|
|
140
|
+
},
|
|
141
|
+
() => {
|
|
142
|
+
if (!controller.signal.aborted) {
|
|
143
|
+
setSuggestions([]);
|
|
144
|
+
}
|
|
145
|
+
},
|
|
146
|
+
);
|
|
147
|
+
}, debounceMs);
|
|
148
|
+
return () => {
|
|
149
|
+
clearTimeout(timer);
|
|
150
|
+
controller.abort();
|
|
151
|
+
};
|
|
152
|
+
}, [query, mailboxUid, debounceMs]);
|
|
153
|
+
|
|
154
|
+
useLayoutEffect(() => {
|
|
155
|
+
if (!expanded) {
|
|
156
|
+
return;
|
|
157
|
+
}
|
|
158
|
+
const anchor = anchorRef.current!;
|
|
159
|
+
const update = () => setPosition(dropdownPosition(anchor));
|
|
160
|
+
update();
|
|
161
|
+
window.addEventListener("resize", update);
|
|
162
|
+
window.addEventListener("scroll", update, true);
|
|
163
|
+
return () => {
|
|
164
|
+
window.removeEventListener("resize", update);
|
|
165
|
+
window.removeEventListener("scroll", update, true);
|
|
166
|
+
};
|
|
167
|
+
}, [expanded]);
|
|
168
|
+
|
|
169
|
+
useEffect(() => {
|
|
170
|
+
if (expanded) {
|
|
171
|
+
document.getElementById(optionId(active))?.scrollIntoView?.({ block: "nearest" });
|
|
172
|
+
}
|
|
173
|
+
});
|
|
174
|
+
|
|
175
|
+
function emit(nextChips: string[], nextPending: string) {
|
|
176
|
+
onChange([...nextChips, nextPending.trim()].filter((part) => part.length > 0).join(", "));
|
|
177
|
+
}
|
|
178
|
+
|
|
179
|
+
function handleInputChange(e: ChangeEvent<HTMLInputElement>) {
|
|
180
|
+
const { finished, rest } = splitTypedRecipients(e.target.value);
|
|
181
|
+
const nextPending = rest.replace(/^\s+/, "");
|
|
182
|
+
setPending(nextPending);
|
|
183
|
+
setOpen(true);
|
|
184
|
+
emit([...chips, ...finished], nextPending);
|
|
185
|
+
}
|
|
186
|
+
|
|
187
|
+
function commitPending(): string {
|
|
188
|
+
const next = [...chips, pendingText].filter((part) => part.length > 0).join(", ");
|
|
189
|
+
setPending("");
|
|
190
|
+
setOpen(false);
|
|
191
|
+
return next;
|
|
192
|
+
}
|
|
193
|
+
|
|
194
|
+
function select(suggestion: RecipientSuggestion) {
|
|
195
|
+
const next = [...chips, formatRecipient({ address: suggestion.address, displayName: suggestion.displayName || undefined })].join(", ");
|
|
196
|
+
setPending("");
|
|
197
|
+
setOpen(false);
|
|
198
|
+
setSuggestions([]);
|
|
199
|
+
onChange(next);
|
|
200
|
+
onCommit?.(next);
|
|
201
|
+
}
|
|
202
|
+
|
|
203
|
+
function removeChip(index: number) {
|
|
204
|
+
emit(
|
|
205
|
+
chips.filter((_, i) => i !== index),
|
|
206
|
+
inputValue,
|
|
207
|
+
);
|
|
208
|
+
inputRef.current?.focus();
|
|
209
|
+
}
|
|
210
|
+
|
|
211
|
+
function handleKeyDown(e: KeyboardEvent<HTMLInputElement>) {
|
|
212
|
+
switch (e.key) {
|
|
213
|
+
case "ArrowDown":
|
|
214
|
+
case "ArrowUp": {
|
|
215
|
+
if (visible.length === 0) {
|
|
216
|
+
return;
|
|
217
|
+
}
|
|
218
|
+
e.preventDefault();
|
|
219
|
+
if (!expanded) {
|
|
220
|
+
setOpen(true);
|
|
221
|
+
setActiveIndex(e.key === "ArrowDown" ? 0 : visible.length - 1);
|
|
222
|
+
return;
|
|
223
|
+
}
|
|
224
|
+
const step = e.key === "ArrowDown" ? 1 : -1;
|
|
225
|
+
setActiveIndex((active + step + visible.length) % visible.length);
|
|
226
|
+
return;
|
|
227
|
+
}
|
|
228
|
+
case "Enter":
|
|
229
|
+
if (expanded) {
|
|
230
|
+
e.preventDefault();
|
|
231
|
+
select(visible[active]);
|
|
232
|
+
} else if (pendingText) {
|
|
233
|
+
e.preventDefault();
|
|
234
|
+
const next = commitPending();
|
|
235
|
+
onCommit?.(next);
|
|
236
|
+
}
|
|
237
|
+
return;
|
|
238
|
+
case "Tab":
|
|
239
|
+
if (expanded && !e.shiftKey) {
|
|
240
|
+
e.preventDefault();
|
|
241
|
+
select(visible[active]);
|
|
242
|
+
}
|
|
243
|
+
return;
|
|
244
|
+
case "Escape":
|
|
245
|
+
if (expanded) {
|
|
246
|
+
e.preventDefault();
|
|
247
|
+
e.stopPropagation();
|
|
248
|
+
setOpen(false);
|
|
249
|
+
}
|
|
250
|
+
return;
|
|
251
|
+
case "Backspace":
|
|
252
|
+
if (inputValue === "" && chips.length > 0) {
|
|
253
|
+
e.preventDefault();
|
|
254
|
+
emit(chips.slice(0, -1), "");
|
|
255
|
+
}
|
|
256
|
+
return;
|
|
257
|
+
}
|
|
258
|
+
}
|
|
259
|
+
|
|
260
|
+
function handleBlur() {
|
|
261
|
+
const next = commitPending();
|
|
262
|
+
onBlur?.(next);
|
|
263
|
+
}
|
|
264
|
+
|
|
265
|
+
return (
|
|
266
|
+
<div ref={anchorRef} className="flex-1 min-w-0 flex flex-wrap items-center gap-1">
|
|
267
|
+
{chips.length > 0 && (
|
|
268
|
+
<ul role="list" aria-label={`${label} recipients`} className="contents">
|
|
269
|
+
{chips.map((chip, index) => {
|
|
270
|
+
const recipient = parseRecipient(chip);
|
|
271
|
+
const valid = isValidRecipientAddress(recipient.address);
|
|
272
|
+
const name = recipient.displayName || recipient.address;
|
|
273
|
+
return (
|
|
274
|
+
<li
|
|
275
|
+
key={`${index}-${chip}`}
|
|
276
|
+
title={chip}
|
|
277
|
+
className={`flex items-center gap-1 max-w-full min-w-0 rounded-pill border pl-2 pr-0.5 py-px text-xs ${
|
|
278
|
+
valid ? "bg-surface-alt border-border text-text" : "bg-danger-bg border-danger text-danger"
|
|
279
|
+
}`}
|
|
280
|
+
>
|
|
281
|
+
<span className="truncate">{name}</span>
|
|
282
|
+
{!valid && <span className="sr-only"> (not a valid email address)</span>}
|
|
283
|
+
<button
|
|
284
|
+
type="button"
|
|
285
|
+
tabIndex={-1}
|
|
286
|
+
aria-label={`Remove ${recipient.address}`}
|
|
287
|
+
disabled={disabled}
|
|
288
|
+
onMouseDown={(e) => e.preventDefault()}
|
|
289
|
+
onClick={() => removeChip(index)}
|
|
290
|
+
className="shrink-0 w-4 h-4 flex items-center justify-center rounded-pill text-text-muted hover:bg-border hover:text-text"
|
|
291
|
+
>
|
|
292
|
+
<HiOutlineXMark size={10} />
|
|
293
|
+
</button>
|
|
294
|
+
</li>
|
|
295
|
+
);
|
|
296
|
+
})}
|
|
297
|
+
</ul>
|
|
298
|
+
)}
|
|
299
|
+
<input
|
|
300
|
+
ref={inputRef}
|
|
301
|
+
id={id}
|
|
302
|
+
type="text"
|
|
303
|
+
role="combobox"
|
|
304
|
+
autoComplete="off"
|
|
305
|
+
aria-autocomplete="list"
|
|
306
|
+
aria-expanded={expanded}
|
|
307
|
+
aria-controls={listboxId}
|
|
308
|
+
aria-activedescendant={expanded ? optionId(active) : undefined}
|
|
309
|
+
disabled={disabled}
|
|
310
|
+
autoFocus={autoFocus}
|
|
311
|
+
className="flex-1 min-w-[6rem] text-sm bg-transparent outline-none py-0.5"
|
|
312
|
+
value={inputValue}
|
|
313
|
+
onChange={handleInputChange}
|
|
314
|
+
onKeyDown={handleKeyDown}
|
|
315
|
+
onBlur={handleBlur}
|
|
316
|
+
/>
|
|
317
|
+
<span className="sr-only" aria-live="polite">
|
|
318
|
+
{expanded ? `${visible.length} ${visible.length === 1 ? "suggestion" : "suggestions"}` : ""}
|
|
319
|
+
</span>
|
|
320
|
+
{expanded &&
|
|
321
|
+
position &&
|
|
322
|
+
createPortal(
|
|
323
|
+
<ul
|
|
324
|
+
id={listboxId}
|
|
325
|
+
role="listbox"
|
|
326
|
+
aria-label={`${label} suggestions`}
|
|
327
|
+
onMouseDown={(e) => e.preventDefault()}
|
|
328
|
+
style={{ position: "fixed", left: position.left, width: position.width, top: position.top, bottom: position.bottom, maxHeight: position.maxHeight }}
|
|
329
|
+
className="z-[60] overflow-y-auto bg-surface border border-border rounded-md shadow-modal py-1"
|
|
330
|
+
>
|
|
331
|
+
{visible.map((suggestion, index) => (
|
|
332
|
+
<li
|
|
333
|
+
key={`${index}-${suggestion.address}`}
|
|
334
|
+
id={optionId(index)}
|
|
335
|
+
role="option"
|
|
336
|
+
aria-selected={index === active}
|
|
337
|
+
onMouseDown={(e) => e.preventDefault()}
|
|
338
|
+
onMouseEnter={() => setActiveIndex(index)}
|
|
339
|
+
onClick={() => select(suggestion)}
|
|
340
|
+
className={`flex items-center gap-2 px-3 py-1.5 cursor-pointer ${index === active ? "bg-primary/10" : ""}`}
|
|
341
|
+
>
|
|
342
|
+
<span className="flex-1 min-w-0">
|
|
343
|
+
<span className="block truncate text-sm text-text">{suggestion.displayName || suggestion.address}</span>
|
|
344
|
+
{suggestion.displayName && <span className="block truncate text-xs text-text-muted">{suggestion.address}</span>}
|
|
345
|
+
</span>
|
|
346
|
+
<span className="shrink-0 text-[11px] leading-4 px-1.5 rounded-pill bg-surface-alt text-text-muted">
|
|
347
|
+
{KIND_LABELS[suggestion.kind] ?? "Directory"}
|
|
348
|
+
</span>
|
|
349
|
+
</li>
|
|
350
|
+
))}
|
|
351
|
+
</ul>,
|
|
352
|
+
document.body,
|
|
353
|
+
)}
|
|
354
|
+
</div>
|
|
355
|
+
);
|
|
356
|
+
}
|
|
@@ -2,7 +2,7 @@
|
|
|
2
2
|
// Copyright (C) 2026 Jean-Philippe Steinmetz
|
|
3
3
|
// SPDX-License-Identifier: MPL-2.0
|
|
4
4
|
///////////////////////////////////////////////////////////////////////////////
|
|
5
|
-
import React, { useRef } from "react";
|
|
5
|
+
import React, { useRef, useState } from "react";
|
|
6
6
|
import { EditorContent, useEditor } from "@tiptap/react";
|
|
7
7
|
import StarterKit from "@tiptap/starter-kit";
|
|
8
8
|
import { TextStyleKit } from "@tiptap/extension-text-style";
|
|
@@ -23,6 +23,15 @@ export interface RichTextEditorProps {
|
|
|
23
23
|
fill?: boolean;
|
|
24
24
|
/** Passed straight through to `ComposeToolbar` — see its own doc comment on this prop. */
|
|
25
25
|
onUploadImage: (file: File) => Promise<string | null>;
|
|
26
|
+
/** Focuses the editor with the caret at the very start of the document once it mounts - a reply or forward, whose
|
|
27
|
+
* body starts with an empty paragraph above the signature and quote, so typing goes above them. Only read when
|
|
28
|
+
* the editor is created. */
|
|
29
|
+
autoFocusStart?: boolean;
|
|
30
|
+
/** Called once the editor is ready, with `value` as the editor itself serializes it: TipTap drops what its schema
|
|
31
|
+
* doesn't hold (e.g. a blockquote's `style`) and adds an empty paragraph after a trailing non-paragraph node (a
|
|
32
|
+
* quote). That normalization happens on the editor's first transaction - even one that only moves the caret -
|
|
33
|
+
* and isn't reported through `onChange`, so a caller can compare later edits against this instead of `value`. */
|
|
34
|
+
onInitialized?: (value: string) => void;
|
|
26
35
|
}
|
|
27
36
|
|
|
28
37
|
/**
|
|
@@ -46,9 +55,24 @@ export interface RichTextEditorProps {
|
|
|
46
55
|
* sufficient here since TipTap (unlike Monaco) never touches the DOM at module-evaluation time, only when
|
|
47
56
|
* an editor view actually mounts.
|
|
48
57
|
*/
|
|
49
|
-
export default function RichTextEditor({
|
|
58
|
+
export default function RichTextEditor({
|
|
59
|
+
value,
|
|
60
|
+
onChange,
|
|
61
|
+
height = "360px",
|
|
62
|
+
fill = false,
|
|
63
|
+
onUploadImage,
|
|
64
|
+
autoFocusStart = false,
|
|
65
|
+
onInitialized,
|
|
66
|
+
}: RichTextEditorProps) {
|
|
50
67
|
const onChangeRef = useRef(onChange);
|
|
51
68
|
onChangeRef.current = onChange;
|
|
69
|
+
const onInitializedRef = useRef(onInitialized);
|
|
70
|
+
onInitializedRef.current = onInitialized;
|
|
71
|
+
// Transactions before `create` (the autofocus, and the normalizing one below) aren't edits.
|
|
72
|
+
const initializedRef = useRef(false);
|
|
73
|
+
// Held for this editor's lifetime: TipTap focuses a tick after creating the editor, and a re-render passing a
|
|
74
|
+
// different value in between would replace the option (via `setOptions`) before it's read.
|
|
75
|
+
const [autofocus] = useState<"start" | false>(autoFocusStart ? "start" : false);
|
|
52
76
|
|
|
53
77
|
const editor = useEditor({
|
|
54
78
|
extensions: [
|
|
@@ -61,8 +85,19 @@ export default function RichTextEditor({ value, onChange, height = "360px", fill
|
|
|
61
85
|
Placeholder.configure({ placeholder: "Write your message…" }),
|
|
62
86
|
],
|
|
63
87
|
content: value,
|
|
88
|
+
autofocus,
|
|
64
89
|
immediatelyRender: false,
|
|
65
|
-
|
|
90
|
+
onCreate: ({ editor: created }) => {
|
|
91
|
+
// An empty transaction runs the schema's append-transaction normalization now, before any edit.
|
|
92
|
+
created.view.dispatch(created.state.tr);
|
|
93
|
+
initializedRef.current = true;
|
|
94
|
+
onInitializedRef.current?.(created.getHTML());
|
|
95
|
+
},
|
|
96
|
+
onUpdate: ({ editor: updated }) => {
|
|
97
|
+
if (initializedRef.current) {
|
|
98
|
+
onChangeRef.current(updated.getHTML());
|
|
99
|
+
}
|
|
100
|
+
},
|
|
66
101
|
});
|
|
67
102
|
|
|
68
103
|
return (
|
|
@@ -0,0 +1,100 @@
|
|
|
1
|
+
///////////////////////////////////////////////////////////////////////////////
|
|
2
|
+
// Copyright (C) 2026 Jean-Philippe Steinmetz
|
|
3
|
+
// SPDX-License-Identifier: MPL-2.0
|
|
4
|
+
///////////////////////////////////////////////////////////////////////////////
|
|
5
|
+
import { apiUrl } from "@rapidmx/react-shared/util/api.js";
|
|
6
|
+
import { Message, Recipient, getMessageRawContent } from "@rapidmx/react-shared/mail/mailApi.js";
|
|
7
|
+
import type { QuotedBody } from "@rapidmx/react-shared/mail/compose/composeQuoting.js";
|
|
8
|
+
import type { MessageSecurityResult } from "@rapidmx/react-shared/crypto/messageSecurity.js";
|
|
9
|
+
import { decodeHeaderText, extractDisplayBody, parseMimeEntity } from "@rapidmx/react-shared/crypto/mime.js";
|
|
10
|
+
import { parseRecipientList } from "./recipients.js";
|
|
11
|
+
|
|
12
|
+
/** What a Reply/Reply All/Forward needs from the message being answered, beyond what its `Message` record holds. */
|
|
13
|
+
export interface OriginalMessage {
|
|
14
|
+
/** The body to quote. Empty when none could be loaded - the quote builders then fall back to `bodyPreview`. */
|
|
15
|
+
body: QuotedBody;
|
|
16
|
+
/** The original To and Cc recipients, recovered from the message's own headers - `undefined` when they couldn't
|
|
17
|
+
* be. Only asked for by Reply All (see `loadOriginalMessage()`). */
|
|
18
|
+
recipients?: Recipient[];
|
|
19
|
+
}
|
|
20
|
+
|
|
21
|
+
/** The recipients one address-list header names, RFC 2047-decoded, with their display names. */
|
|
22
|
+
function headerRecipients(value: string | undefined, type: "to" | "cc"): Recipient[] {
|
|
23
|
+
if (!value) {
|
|
24
|
+
return [];
|
|
25
|
+
}
|
|
26
|
+
return parseRecipientList(decodeHeaderText(value))
|
|
27
|
+
.filter((recipient) => recipient.address.includes("@"))
|
|
28
|
+
.map((recipient) => ({ address: recipient.address, ...(recipient.displayName ? { displayName: recipient.displayName } : {}), type }));
|
|
29
|
+
}
|
|
30
|
+
|
|
31
|
+
/**
|
|
32
|
+
* Loads what a Reply/Reply All/Forward needs from `message`: the full body to quote - the same content
|
|
33
|
+
* `MessageDetailPane` shows, never the truncated `bodyPreview` unless nothing else can be had - and, with
|
|
34
|
+
* `options.recipients`, who the message was originally addressed to. Never rejects.
|
|
35
|
+
*
|
|
36
|
+
* Content the pane recovered client-side (`security.text`/`security.html`: a decrypted or verified body) is used as
|
|
37
|
+
* is. For an encrypted message that's the plaintext, so the caller must keep the reply encrypted (see
|
|
38
|
+
* `MessageDetailPane`'s reply handlers).
|
|
39
|
+
*
|
|
40
|
+
* An encrypted message without recovered content (locked keys, a failed decrypt, evaluation still running) quotes
|
|
41
|
+
* nothing: the server only holds ciphertext, which is never fetched or quoted.
|
|
42
|
+
*
|
|
43
|
+
* Otherwise the server's sanitized HTML body (`GET /mail/messages/:id/content`) is used. That route falls back to the
|
|
44
|
+
* preview for a message without an HTML part, so a `text/plain` answer is replaced by the text part of the message's
|
|
45
|
+
* raw MIME.
|
|
46
|
+
*
|
|
47
|
+
* The recipients come from the verified message's protected headers when it has them, else from the raw message's own
|
|
48
|
+
* `To`/`Cc` headers - restapi records only the envelope recipient of a delivered message (`ScanQueueJob`), so
|
|
49
|
+
* `message.recipients` alone would reduce every Reply All to a plain reply. Unprotected headers are the sender's own
|
|
50
|
+
* claim, exactly as in every other mail client's Reply All.
|
|
51
|
+
*
|
|
52
|
+
* The quote builders sanitize whatever HTML this returns (`sanitizeQuotedHtml()`), whichever source it came from.
|
|
53
|
+
*/
|
|
54
|
+
export async function loadOriginalMessage(
|
|
55
|
+
message: Message,
|
|
56
|
+
security: MessageSecurityResult | null,
|
|
57
|
+
options: { recipients?: boolean } = {},
|
|
58
|
+
): Promise<OriginalMessage> {
|
|
59
|
+
const recovered: QuotedBody | undefined =
|
|
60
|
+
security?.text !== undefined ? { text: security.text } : security?.html !== undefined ? { html: security.html } : undefined;
|
|
61
|
+
const protectedHeaders = security?.protectedHeaders;
|
|
62
|
+
const protectedRecipients = protectedHeaders
|
|
63
|
+
? [...headerRecipients(protectedHeaders.to, "to"), ...headerRecipients(protectedHeaders.cc, "cc")]
|
|
64
|
+
: [];
|
|
65
|
+
const result: OriginalMessage = { body: recovered ?? {}, ...(protectedRecipients.length > 0 ? { recipients: protectedRecipients } : {}) };
|
|
66
|
+
if (message.encrypted) {
|
|
67
|
+
return result;
|
|
68
|
+
}
|
|
69
|
+
let needsRaw = !!options.recipients && result.recipients === undefined;
|
|
70
|
+
if (!recovered) {
|
|
71
|
+
try {
|
|
72
|
+
const res = await fetch(apiUrl(`/mail/messages/${encodeURIComponent(message.uid)}/content`), { credentials: "include" });
|
|
73
|
+
if (res.ok && (res.headers.get("content-type") ?? "").includes("text/html")) {
|
|
74
|
+
result.body = { html: await res.text() };
|
|
75
|
+
} else {
|
|
76
|
+
needsRaw = true;
|
|
77
|
+
}
|
|
78
|
+
} catch {
|
|
79
|
+
// The raw message below is the other way to the body.
|
|
80
|
+
needsRaw = true;
|
|
81
|
+
}
|
|
82
|
+
}
|
|
83
|
+
try {
|
|
84
|
+
if (needsRaw) {
|
|
85
|
+
const entity = parseMimeEntity(await getMessageRawContent(message.uid));
|
|
86
|
+
if (!recovered && result.body.html === undefined) {
|
|
87
|
+
const body = extractDisplayBody(entity);
|
|
88
|
+
result.body = body.html !== undefined ? { html: body.html } : body.text !== undefined ? { text: body.text } : {};
|
|
89
|
+
}
|
|
90
|
+
const headers = [...headerRecipients(entity.headers["to"], "to"), ...headerRecipients(entity.headers["cc"], "cc")];
|
|
91
|
+
if (options.recipients && result.recipients === undefined && headers.length > 0) {
|
|
92
|
+
result.recipients = headers;
|
|
93
|
+
}
|
|
94
|
+
}
|
|
95
|
+
} catch {
|
|
96
|
+
// Whatever was loaded before the failure stands: the quote falls back to the preview, Reply All to the
|
|
97
|
+
// message's own recipients.
|
|
98
|
+
}
|
|
99
|
+
return result;
|
|
100
|
+
}
|
|
@@ -0,0 +1,104 @@
|
|
|
1
|
+
///////////////////////////////////////////////////////////////////////////////
|
|
2
|
+
// Copyright (C) 2026 Jean-Philippe Steinmetz
|
|
3
|
+
// SPDX-License-Identifier: MPL-2.0
|
|
4
|
+
///////////////////////////////////////////////////////////////////////////////
|
|
5
|
+
/**
|
|
6
|
+
* Parsing and formatting of the To/Cc/Bcc fields' text. A field's value is a list of recipients separated by commas or
|
|
7
|
+
* semicolons, each either a bare address or `Display Name <address>` (the name optionally quoted, so it can hold a comma
|
|
8
|
+
* or semicolon itself). Separators inside quotes or angle brackets don't split.
|
|
9
|
+
*/
|
|
10
|
+
import type { ComposeRecipientInput } from "@rapidmx/react-shared/mail/mailApi.js";
|
|
11
|
+
|
|
12
|
+
/** One plain address: something, one `@`, something - no whitespace, brackets, quotes or separators. */
|
|
13
|
+
const ADDRESS_PATTERN = /^[^\s@<>()",;]+@[^\s@<>()",;]+$/;
|
|
14
|
+
|
|
15
|
+
/** Characters that make a display name need quoting. */
|
|
16
|
+
const NAME_SPECIALS = /[",;<>@()\\]/;
|
|
17
|
+
|
|
18
|
+
/** Splits at commas and semicolons outside quotes and angle brackets, keeping every part as is (empty ones too). An
|
|
19
|
+
* unterminated quote or bracket runs to the end of the text. */
|
|
20
|
+
function splitRaw(value: string): string[] {
|
|
21
|
+
const parts: string[] = [];
|
|
22
|
+
let current = "";
|
|
23
|
+
let quoted = false;
|
|
24
|
+
let bracketed = false;
|
|
25
|
+
for (let i = 0; i < value.length; i++) {
|
|
26
|
+
const ch = value[i];
|
|
27
|
+
if (quoted && ch === "\\" && i + 1 < value.length) {
|
|
28
|
+
current += ch + value[i + 1];
|
|
29
|
+
i++;
|
|
30
|
+
continue;
|
|
31
|
+
}
|
|
32
|
+
if (ch === '"' && !bracketed) {
|
|
33
|
+
quoted = !quoted;
|
|
34
|
+
} else if (ch === "<" && !quoted) {
|
|
35
|
+
bracketed = true;
|
|
36
|
+
} else if (ch === ">" && !quoted) {
|
|
37
|
+
bracketed = false;
|
|
38
|
+
} else if ((ch === "," || ch === ";") && !quoted && !bracketed) {
|
|
39
|
+
parts.push(current);
|
|
40
|
+
current = "";
|
|
41
|
+
continue;
|
|
42
|
+
}
|
|
43
|
+
current += ch;
|
|
44
|
+
}
|
|
45
|
+
parts.push(current);
|
|
46
|
+
return parts;
|
|
47
|
+
}
|
|
48
|
+
|
|
49
|
+
/** Splits a field's text into trimmed, non-empty recipient strings - see `splitRaw()`. */
|
|
50
|
+
export function splitRecipientList(value: string): string[] {
|
|
51
|
+
return splitRaw(value)
|
|
52
|
+
.map((part) => part.trim())
|
|
53
|
+
.filter((part) => part.length > 0);
|
|
54
|
+
}
|
|
55
|
+
|
|
56
|
+
/** Splits text typed into a field: the recipients finished by a separator, and the text after the last separator
|
|
57
|
+
* (untrimmed; the whole text when there is no separator). */
|
|
58
|
+
export function splitTypedRecipients(text: string): { finished: string[]; rest: string } {
|
|
59
|
+
const parts = splitRaw(text);
|
|
60
|
+
const rest = parts.pop()!;
|
|
61
|
+
return { finished: parts.map((part) => part.trim()).filter((part) => part.length > 0), rest };
|
|
62
|
+
}
|
|
63
|
+
|
|
64
|
+
function unquote(name: string): string {
|
|
65
|
+
const trimmed = name.trim();
|
|
66
|
+
if (trimmed.length >= 2 && trimmed.startsWith('"') && trimmed.endsWith('"')) {
|
|
67
|
+
return trimmed.slice(1, -1).replace(/\\(.)/g, "$1").trim();
|
|
68
|
+
}
|
|
69
|
+
return trimmed;
|
|
70
|
+
}
|
|
71
|
+
|
|
72
|
+
/** Parses one recipient string: `Name <address>`, `"Name" <address>`, `<address>` or a bare address. Anything else is
|
|
73
|
+
* kept whole as the address (so it's still sent, and flagged as invalid by the field). */
|
|
74
|
+
export function parseRecipient(text: string): ComposeRecipientInput {
|
|
75
|
+
const trimmed = text.trim();
|
|
76
|
+
const match = /^(.*)<([^<>]*)>\s*$/.exec(trimmed);
|
|
77
|
+
if (match) {
|
|
78
|
+
const address = match[2].trim();
|
|
79
|
+
const displayName = unquote(match[1]);
|
|
80
|
+
return displayName ? { address, displayName } : { address };
|
|
81
|
+
}
|
|
82
|
+
return { address: trimmed };
|
|
83
|
+
}
|
|
84
|
+
|
|
85
|
+
/** Every recipient in a field's text. */
|
|
86
|
+
export function parseRecipientList(value: string): ComposeRecipientInput[] {
|
|
87
|
+
return splitRecipientList(value).map(parseRecipient);
|
|
88
|
+
}
|
|
89
|
+
|
|
90
|
+
/** Formats a recipient for a field: `Name <address>` (the name quoted when it holds a special character), or the bare
|
|
91
|
+
* address without a name. */
|
|
92
|
+
export function formatRecipient(recipient: ComposeRecipientInput): string {
|
|
93
|
+
const name = recipient.displayName?.trim();
|
|
94
|
+
if (!name) {
|
|
95
|
+
return recipient.address;
|
|
96
|
+
}
|
|
97
|
+
const safeName = NAME_SPECIALS.test(name) ? `"${name.replace(/(["\\])/g, "\\$1")}"` : name;
|
|
98
|
+
return `${safeName} <${recipient.address}>`;
|
|
99
|
+
}
|
|
100
|
+
|
|
101
|
+
/** Whether `address` looks like one plain email address. */
|
|
102
|
+
export function isValidRecipientAddress(address: string): boolean {
|
|
103
|
+
return ADDRESS_PATTERN.test(address);
|
|
104
|
+
}
|