@rapidmx/web-client 0.5.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.
Files changed (224) hide show
  1. package/README.md +88 -0
  2. package/apps/shared/components/admin/layout/AdminShell.tsx +25 -8
  3. package/apps/shared/components/admin/settings/BrandingForm.tsx +398 -385
  4. package/apps/shared/components/admin/settings/EncryptionPolicyForm.tsx +119 -112
  5. package/apps/shared/components/admin/settings/MailboxPolicyForm.tsx +159 -152
  6. package/apps/shared/components/admin/settings/PluginsManager.tsx +1288 -1235
  7. package/apps/shared/components/admin/settings/RetentionPolicyForm.tsx +9 -1
  8. package/apps/shared/components/admin/setup/EscrowSetupStep.tsx +288 -290
  9. package/apps/shared/components/admin/setup/SetupWizard.tsx +443 -416
  10. package/apps/shared/components/calendar/layout/CalendarShell.tsx +194 -192
  11. package/apps/shared/components/contacts/layout/ContactsShell.tsx +199 -197
  12. package/apps/shared/components/layout/AppShell.tsx +288 -270
  13. package/apps/shared/components/mail/ConversationList.tsx +225 -33
  14. package/apps/shared/components/mail/ConversationThreadPane.tsx +434 -216
  15. package/apps/shared/components/mail/MailListToolbar.tsx +265 -0
  16. package/apps/shared/components/mail/MailSelectionBar.tsx +222 -0
  17. package/apps/shared/components/mail/MenuButton.tsx +384 -0
  18. package/apps/shared/components/mail/MessageDetailPane.tsx +280 -215
  19. package/apps/shared/components/mail/MoveToFolderDialog.tsx +263 -0
  20. package/apps/shared/components/mail/compose/ComposeContext.tsx +29 -2
  21. package/apps/shared/components/mail/compose/ComposeWindow.tsx +1700 -1652
  22. package/apps/shared/components/mail/compose/RecipientInput.tsx +356 -0
  23. package/apps/shared/components/mail/compose/RichTextEditor.tsx +38 -3
  24. package/apps/shared/components/mail/compose/quotedBody.ts +100 -0
  25. package/apps/shared/components/mail/compose/recipients.ts +104 -0
  26. package/apps/shared/components/mail/labelMenu.tsx +278 -0
  27. package/apps/shared/components/mail/layout/MailShell.tsx +31 -4
  28. package/apps/shared/components/mail/listPreferences.ts +228 -0
  29. package/apps/shared/components/settings/layout/SettingsShell.tsx +23 -10
  30. package/apps/shared/components/tasks/layout/TasksShell.tsx +201 -199
  31. package/apps/shared/plugins/pluginNav.ts +73 -0
  32. package/apps/shared/search/localIndexRpcClient.ts +3 -1
  33. package/apps/shared/styles/app.css +28 -5
  34. package/apps/www/index.tsx +1854 -1314
  35. package/apps/www/messages/[uid].tsx +5 -4
  36. package/dist/apps/admin/_404.d.ts +2 -0
  37. package/dist/apps/admin/_500.d.ts +2 -0
  38. package/dist/apps/admin/_layout.d.ts +8 -0
  39. package/dist/apps/admin/audit-log/index.d.ts +11 -0
  40. package/dist/apps/admin/branding/index.d.ts +3 -0
  41. package/dist/apps/admin/data-requests/index.d.ts +3 -0
  42. package/dist/apps/admin/distribution-lists/[uid].d.ts +7 -0
  43. package/dist/apps/admin/distribution-lists/index.d.ts +3 -0
  44. package/dist/apps/admin/distribution-lists/new/index.d.ts +3 -0
  45. package/dist/apps/admin/domains/[uid].d.ts +7 -0
  46. package/dist/apps/admin/domains/index.d.ts +3 -0
  47. package/dist/apps/admin/domains/new/index.d.ts +3 -0
  48. package/dist/apps/admin/encryption-policy/index.d.ts +3 -0
  49. package/dist/apps/admin/escrow-scopes/[uid].d.ts +21 -0
  50. package/dist/apps/admin/escrow-scopes/index.d.ts +3 -0
  51. package/dist/apps/admin/escrow-scopes/new/index.d.ts +3 -0
  52. package/dist/apps/admin/index.d.ts +3 -0
  53. package/dist/apps/admin/ingest-queue/index.d.ts +4 -0
  54. package/dist/apps/admin/mailbox-policy/index.d.ts +3 -0
  55. package/dist/apps/admin/mailboxes/[uid].d.ts +7 -0
  56. package/dist/apps/admin/mailboxes/new/index.d.ts +3 -0
  57. package/dist/apps/admin/plugins/index.d.ts +3 -0
  58. package/dist/apps/admin/quarantine/index.d.ts +6 -0
  59. package/dist/apps/admin/retention-policy/index.d.ts +3 -0
  60. package/dist/apps/admin/setup/index.d.ts +3 -0
  61. package/dist/apps/admin/transport-rules/[uid].d.ts +7 -0
  62. package/dist/apps/admin/transport-rules/_transportRuleConfig.d.ts +21 -0
  63. package/dist/apps/admin/transport-rules/index.d.ts +3 -0
  64. package/dist/apps/admin/transport-rules/new/index.d.ts +3 -0
  65. package/dist/apps/escrow/_layout.d.ts +10 -0
  66. package/dist/apps/escrow/audit-log/index.d.ts +9 -0
  67. package/dist/apps/escrow/index.d.ts +3 -0
  68. package/dist/apps/escrow/matters/[uid].d.ts +7 -0
  69. package/dist/apps/escrow/matters/new/index.d.ts +3 -0
  70. package/dist/apps/shared/components/admin/distributionLists/MemberListCard.d.ts +17 -0
  71. package/dist/apps/shared/components/admin/escrowScopes/EscrowScopeKeyAndHoldersFields.d.ts +32 -0
  72. package/dist/apps/shared/components/admin/layout/AdminShell.d.ts +32 -0
  73. package/dist/apps/shared/components/admin/layout/AdminShell.js +12 -5
  74. package/dist/apps/shared/components/admin/mailboxes/EscrowScopeCard.d.ts +12 -0
  75. package/dist/apps/shared/components/admin/mailboxes/MailboxTable.d.ts +6 -0
  76. package/dist/apps/shared/components/admin/mailboxes/ResourceSettingsCard.d.ts +19 -0
  77. package/dist/apps/shared/components/admin/mailboxes/ShareAccessCard.d.ts +12 -0
  78. package/dist/apps/shared/components/admin/settings/BrandingForm.d.ts +13 -0
  79. package/dist/apps/shared/components/admin/settings/BrandingForm.js +6 -5
  80. package/dist/apps/shared/components/admin/settings/DomainDnsSetup.d.ts +12 -0
  81. package/dist/apps/shared/components/admin/settings/EncryptionPolicyForm.d.ts +15 -0
  82. package/dist/apps/shared/components/admin/settings/EncryptionPolicyForm.js +2 -2
  83. package/dist/apps/shared/components/admin/settings/LoadedSettingsForm.d.ts +9 -0
  84. package/dist/apps/shared/components/admin/settings/MailboxCreateForm.d.ts +19 -0
  85. package/dist/apps/shared/components/admin/settings/MailboxPolicyForm.d.ts +13 -0
  86. package/dist/apps/shared/components/admin/settings/MailboxPolicyForm.js +2 -2
  87. package/dist/apps/shared/components/admin/settings/PluginsManager.d.ts +11 -0
  88. package/dist/apps/shared/components/admin/settings/PluginsManager.js +33 -14
  89. package/dist/apps/shared/components/admin/settings/RetentionPolicyForm.d.ts +12 -0
  90. package/dist/apps/shared/components/admin/settings/RetentionPolicyForm.js +2 -2
  91. package/dist/apps/shared/components/admin/setup/EscrowSetupStep.d.ts +14 -0
  92. package/dist/apps/shared/components/admin/setup/EscrowSetupStep.js +1 -1
  93. package/dist/apps/shared/components/admin/setup/SetupWizard.d.ts +36 -0
  94. package/dist/apps/shared/components/admin/setup/SetupWizard.js +14 -10
  95. package/dist/apps/shared/components/admin/signOut.d.ts +23 -0
  96. package/dist/apps/shared/components/admin/usePagedList.d.ts +39 -0
  97. package/dist/apps/shared/components/calendar/CalendarListSidebar.d.ts +26 -0
  98. package/dist/apps/shared/components/calendar/EventModal.d.ts +46 -0
  99. package/dist/apps/shared/components/calendar/MonthView.d.ts +15 -0
  100. package/dist/apps/shared/components/calendar/RecurrenceEditor.d.ts +20 -0
  101. package/dist/apps/shared/components/calendar/ResourcePicker.d.ts +19 -0
  102. package/dist/apps/shared/components/calendar/SplitDayView.d.ts +28 -0
  103. package/dist/apps/shared/components/calendar/TimeGridView.d.ts +17 -0
  104. package/dist/apps/shared/components/calendar/allDay.d.ts +51 -0
  105. package/dist/apps/shared/components/calendar/layout/CalendarShell.d.ts +40 -0
  106. package/dist/apps/shared/components/calendar/layout/CalendarShell.js +2 -2
  107. package/dist/apps/shared/components/contacts/ContactDetailPane.d.ts +23 -0
  108. package/dist/apps/shared/components/contacts/ContactForm.d.ts +20 -0
  109. package/dist/apps/shared/components/contacts/ContactsSidebar.d.ts +40 -0
  110. package/dist/apps/shared/components/contacts/ContactsToolbar.d.ts +25 -0
  111. package/dist/apps/shared/components/contacts/KeyChangeReview.d.ts +40 -0
  112. package/dist/apps/shared/components/contacts/contactKeys.d.ts +29 -0
  113. package/dist/apps/shared/components/contacts/layout/ContactsShell.d.ts +21 -0
  114. package/dist/apps/shared/components/contacts/layout/ContactsShell.js +2 -2
  115. package/dist/apps/shared/components/escrow/layout/EscrowShell.d.ts +25 -0
  116. package/dist/apps/shared/components/forms/StringListField.d.ts +22 -0
  117. package/dist/apps/shared/components/layout/AppShell.d.ts +49 -0
  118. package/dist/apps/shared/components/layout/AppShell.js +15 -13
  119. package/dist/apps/shared/components/layout/BrandingChrome.d.ts +18 -0
  120. package/dist/apps/shared/components/layout/KeyEnrollmentGate.d.ts +51 -0
  121. package/dist/apps/shared/components/layout/MailboxProvisioning.d.ts +13 -0
  122. package/dist/apps/shared/components/layout/RecoveryCodeUnlock.d.ts +66 -0
  123. package/dist/apps/shared/components/layout/UnlockPromptProvider.d.ts +45 -0
  124. package/dist/apps/shared/components/layout/UserMenu.d.ts +23 -0
  125. package/dist/apps/shared/components/mail/ConversationList.d.ts +47 -0
  126. package/dist/apps/shared/components/mail/ConversationList.js +84 -10
  127. package/dist/apps/shared/components/mail/ConversationThreadPane.d.ts +62 -0
  128. package/dist/apps/shared/components/mail/ConversationThreadPane.js +217 -60
  129. package/dist/apps/shared/components/mail/MailListToolbar.d.ts +55 -0
  130. package/dist/apps/shared/components/mail/MailListToolbar.js +149 -0
  131. package/dist/apps/shared/components/mail/MailSelectionBar.d.ts +59 -0
  132. package/dist/apps/shared/components/mail/MailSelectionBar.js +48 -0
  133. package/dist/apps/shared/components/mail/MenuButton.d.ts +71 -0
  134. package/dist/apps/shared/components/mail/MenuButton.js +211 -0
  135. package/dist/apps/shared/components/mail/MessageDetailPane.d.ts +101 -0
  136. package/dist/apps/shared/components/mail/MessageDetailPane.js +126 -129
  137. package/dist/apps/shared/components/mail/MoveToFolderDialog.d.ts +57 -0
  138. package/dist/apps/shared/components/mail/MoveToFolderDialog.js +138 -0
  139. package/dist/apps/shared/components/mail/compose/ComposeContext.d.ts +73 -0
  140. package/dist/apps/shared/components/mail/compose/ComposeContext.js +3 -1
  141. package/dist/apps/shared/components/mail/compose/ComposeToolbar.d.ts +15 -0
  142. package/dist/apps/shared/components/mail/compose/ComposeWindow.d.ts +37 -0
  143. package/dist/apps/shared/components/mail/compose/ComposeWindow.js +52 -20
  144. package/dist/apps/shared/components/mail/compose/EmojiPicker.d.ts +14 -0
  145. package/dist/apps/shared/components/mail/compose/GifPicker.d.ts +13 -0
  146. package/dist/apps/shared/components/mail/compose/RecipientInput.d.ts +36 -0
  147. package/dist/apps/shared/components/mail/compose/RecipientInput.js +203 -0
  148. package/dist/apps/shared/components/mail/compose/RichTextEditor.d.ts +43 -0
  149. package/dist/apps/shared/components/mail/compose/RichTextEditor.js +21 -3
  150. package/dist/apps/shared/components/mail/compose/ScheduleSendPicker.d.ts +16 -0
  151. package/dist/apps/shared/components/mail/compose/composeFlushRegistry.d.ts +27 -0
  152. package/dist/apps/shared/components/mail/compose/quotedBody.d.ts +37 -0
  153. package/dist/apps/shared/components/mail/compose/quotedBody.js +85 -0
  154. package/dist/apps/shared/components/mail/compose/recipients.d.ts +24 -0
  155. package/dist/apps/shared/components/mail/compose/recipients.js +87 -0
  156. package/dist/apps/shared/components/mail/labelMenu.d.ts +97 -0
  157. package/dist/apps/shared/components/mail/labelMenu.js +134 -0
  158. package/dist/apps/shared/components/mail/layout/MailShell.d.ts +65 -0
  159. package/dist/apps/shared/components/mail/layout/MailShell.js +17 -5
  160. package/dist/apps/shared/components/mail/listPreferences.d.ts +101 -0
  161. package/dist/apps/shared/components/mail/listPreferences.js +186 -0
  162. package/dist/apps/shared/components/mail/pinnedSigners.d.ts +33 -0
  163. package/dist/apps/shared/components/mail/verificationSeals.d.ts +22 -0
  164. package/dist/apps/shared/components/mail/writableMailboxes.d.ts +15 -0
  165. package/dist/apps/shared/components/rules/RuleBuilder.d.ts +70 -0
  166. package/dist/apps/shared/components/settings/layout/SettingsShell.d.ts +41 -0
  167. package/dist/apps/shared/components/settings/layout/SettingsShell.js +19 -10
  168. package/dist/apps/shared/components/tasks/TasksSidebar.d.ts +41 -0
  169. package/dist/apps/shared/components/tasks/TasksToolbar.d.ts +14 -0
  170. package/dist/apps/shared/components/tasks/layout/TasksShell.d.ts +24 -0
  171. package/dist/apps/shared/components/tasks/layout/TasksShell.js +2 -2
  172. package/dist/apps/shared/mail/findWellKnownFolderUid.d.ts +5 -0
  173. package/dist/apps/shared/mail/listAllPages.d.ts +17 -0
  174. package/dist/apps/shared/plugins/pluginNav.d.ts +39 -0
  175. package/dist/apps/shared/plugins/pluginNav.js +33 -0
  176. package/dist/apps/shared/search/LocalIndexLifecycle.d.ts +13 -0
  177. package/dist/apps/shared/search/localIndexBlockCipher.d.ts +36 -0
  178. package/dist/apps/shared/search/localIndexBuilder.d.ts +85 -0
  179. package/dist/apps/shared/search/localIndexKey.d.ts +4 -0
  180. package/dist/apps/shared/search/localIndexRpcClient.d.ts +71 -0
  181. package/dist/apps/shared/search/localIndexRpcClient.js +3 -1
  182. package/dist/apps/shared/search/localIndexSchema.d.ts +111 -0
  183. package/dist/apps/shared/search/localIndexSizePreference.d.ts +27 -0
  184. package/dist/apps/shared/search/localIndexStorage.d.ts +28 -0
  185. package/dist/apps/shared/search/localIndexVFS.d.ts +101 -0
  186. package/dist/apps/shared/search/localIndexWorker.d.ts +145 -0
  187. package/dist/apps/shared/search/searchTier2.d.ts +30 -0
  188. package/dist/apps/shared/styles/app.css +28 -5
  189. package/dist/apps/www/_404.d.ts +2 -0
  190. package/dist/apps/www/_500.d.ts +2 -0
  191. package/dist/apps/www/_layout.d.ts +14 -0
  192. package/dist/apps/www/calendar/index.d.ts +3 -0
  193. package/dist/apps/www/contacts/[uid].d.ts +13 -0
  194. package/dist/apps/www/contacts/index.d.ts +3 -0
  195. package/dist/apps/www/index.d.ts +3 -0
  196. package/dist/apps/www/index.js +506 -112
  197. package/dist/apps/www/messages/[uid].d.ts +11 -0
  198. package/dist/apps/www/messages/[uid].js +2 -3
  199. package/dist/apps/www/settings/auto-reply/index.d.ts +4 -0
  200. package/dist/apps/www/settings/encryption/index.d.ts +7 -0
  201. package/dist/apps/www/settings/filters/[uid].d.ts +8 -0
  202. package/dist/apps/www/settings/filters/_mailFilterRuleConfig.d.ts +11 -0
  203. package/dist/apps/www/settings/filters/index.d.ts +4 -0
  204. package/dist/apps/www/settings/filters/new/index.d.ts +4 -0
  205. package/dist/apps/www/settings/labels/index.d.ts +4 -0
  206. package/dist/apps/www/settings/privacy/index.d.ts +4 -0
  207. package/dist/apps/www/settings/read-receipts/index.d.ts +4 -0
  208. package/dist/apps/www/settings/sharing/index.d.ts +4 -0
  209. package/dist/apps/www/settings/signatures/[uid].d.ts +8 -0
  210. package/dist/apps/www/settings/signatures/index.d.ts +4 -0
  211. package/dist/apps/www/settings/signatures/new/index.d.ts +4 -0
  212. package/dist/apps/www/settings/signatures/signatureDefaults.d.ts +10 -0
  213. package/dist/apps/www/tasks/index.d.ts +3 -0
  214. package/package.json +3 -3
  215. package/apps/shared/components/booking/AvailabilityEditor.tsx +0 -118
  216. package/apps/www/settings/booking-types/[uid].tsx +0 -306
  217. package/apps/www/settings/booking-types/index.tsx +0 -98
  218. package/apps/www/settings/booking-types/new/index.tsx +0 -212
  219. package/apps/www/settings/focused-inbox/index.tsx +0 -150
  220. package/dist/apps/shared/components/booking/AvailabilityEditor.js +0 -45
  221. package/dist/apps/www/settings/booking-types/[uid].js +0 -134
  222. package/dist/apps/www/settings/booking-types/index.js +0 -29
  223. package/dist/apps/www/settings/booking-types/new/index.js +0 -86
  224. package/dist/apps/www/settings/focused-inbox/index.js +0 -71
@@ -0,0 +1,203 @@
1
+ import { jsx as _jsx, jsxs as _jsxs } from "react/jsx-runtime";
2
+ ///////////////////////////////////////////////////////////////////////////////
3
+ // Copyright (C) 2026 Jean-Philippe Steinmetz
4
+ // SPDX-License-Identifier: MPL-2.0
5
+ ///////////////////////////////////////////////////////////////////////////////
6
+ import { useEffect, useLayoutEffect, useRef, useState } from "react";
7
+ import { createPortal } from "react-dom";
8
+ import { HiOutlineXMark } from "react-icons/hi2";
9
+ import { fetchRecipientSuggestions, RECIPIENT_SUGGESTION_MIN_QUERY_LENGTH, } from "@rapidmx/react-shared/mail/directoryApi.js";
10
+ import { formatRecipient, isValidRecipientAddress, parseRecipient, splitRecipientList, splitTypedRecipients } from "./recipients.js";
11
+ /** How long typing must pause before suggestions are requested. */
12
+ export const RECIPIENT_SUGGESTION_DEBOUNCE_MS = 150;
13
+ const KIND_LABELS = {
14
+ contact: "Contact",
15
+ user: "Person",
16
+ shared: "Shared mailbox",
17
+ room: "Room",
18
+ equipment: "Equipment",
19
+ list: "Group",
20
+ };
21
+ /** Where the suggestions go: under the field (or above it when there's much more room there), as wide as the field. */
22
+ function dropdownPosition(anchor) {
23
+ const rect = anchor.getBoundingClientRect();
24
+ const margin = 8;
25
+ const width = Math.min(Math.max(rect.width, 260), window.innerWidth - margin * 2);
26
+ const left = Math.min(Math.max(rect.left, margin), window.innerWidth - width - margin);
27
+ const below = window.innerHeight - rect.bottom - margin;
28
+ const above = rect.top - margin;
29
+ if (below < 160 && above > below) {
30
+ return { left, width, bottom: window.innerHeight - rect.top + 2, maxHeight: Math.min(320, above) };
31
+ }
32
+ return { left, width, top: rect.bottom + 2, maxHeight: Math.max(120, Math.min(320, below)) };
33
+ }
34
+ /**
35
+ * A To/Cc/Bcc field: committed recipients as removable chips, and a WAI-ARIA combobox for the one being typed that
36
+ * suggests the caller's contacts and the server directory (contacts first, one entry per address). The field's value is
37
+ * still plain text (recipients separated by commas), so drafts, autosave and sending read it as before.
38
+ *
39
+ * Typing a comma or semicolon (outside a quoted name or angle brackets), pressing Enter, or leaving the field turns the
40
+ * typed text into a chip; pasted lists split the same way. Suggestions load `debounceMs` after typing pauses, for at
41
+ * least two characters, and a newer query aborts an older request. Arrow keys move through them, Enter or Tab picks
42
+ * one (as `Name <address>`), Escape closes them, and Backspace in an empty input removes the last chip.
43
+ */
44
+ export default function RecipientInput({ id, label, value, onChange, onBlur, onCommit, mailboxUid, fetchSuggestions = fetchRecipientSuggestions, debounceMs = RECIPIENT_SUGGESTION_DEBOUNCE_MS, disabled, autoFocus, }) {
45
+ const [pending, setPending] = useState("");
46
+ const [suggestions, setSuggestions] = useState([]);
47
+ const [open, setOpen] = useState(false);
48
+ const [activeIndex, setActiveIndex] = useState(0);
49
+ const [position, setPosition] = useState(null);
50
+ const anchorRef = useRef(null);
51
+ const inputRef = useRef(null);
52
+ const fetchRef = useRef(fetchSuggestions);
53
+ fetchRef.current = fetchSuggestions;
54
+ const tokens = splitRecipientList(value);
55
+ const pendingText = pending.trim();
56
+ // The typed text is the value's last recipient; a value changed from outside that doesn't end with it drops it.
57
+ const pendingActive = pendingText !== "" && tokens[tokens.length - 1] === pendingText;
58
+ const chips = pendingActive ? tokens.slice(0, -1) : tokens;
59
+ const inputValue = pendingActive ? pending : "";
60
+ const query = pendingActive ? pendingText : "";
61
+ const listboxId = `${id}-suggestions`;
62
+ const optionId = (index) => `${id}-suggestion-${index}`;
63
+ useEffect(() => {
64
+ if (pending !== "" && !pendingActive) {
65
+ setPending("");
66
+ }
67
+ }, [pending, pendingActive]);
68
+ const committedAddresses = new Set(chips.map((chip) => parseRecipient(chip).address.toLowerCase()));
69
+ const visible = suggestions.filter((suggestion) => !committedAddresses.has(suggestion.address.toLowerCase()));
70
+ const expanded = open && visible.length > 0 && query.length >= RECIPIENT_SUGGESTION_MIN_QUERY_LENGTH;
71
+ const active = Math.min(activeIndex, visible.length - 1);
72
+ useEffect(() => {
73
+ if (query.length < RECIPIENT_SUGGESTION_MIN_QUERY_LENGTH) {
74
+ setSuggestions([]);
75
+ return;
76
+ }
77
+ const controller = new AbortController();
78
+ const timer = setTimeout(() => {
79
+ fetchRef.current(query, { mailboxUid, signal: controller.signal }).then((result) => {
80
+ if (!controller.signal.aborted) {
81
+ setSuggestions(result);
82
+ setActiveIndex(0);
83
+ }
84
+ }, () => {
85
+ if (!controller.signal.aborted) {
86
+ setSuggestions([]);
87
+ }
88
+ });
89
+ }, debounceMs);
90
+ return () => {
91
+ clearTimeout(timer);
92
+ controller.abort();
93
+ };
94
+ }, [query, mailboxUid, debounceMs]);
95
+ useLayoutEffect(() => {
96
+ if (!expanded) {
97
+ return;
98
+ }
99
+ const anchor = anchorRef.current;
100
+ const update = () => setPosition(dropdownPosition(anchor));
101
+ update();
102
+ window.addEventListener("resize", update);
103
+ window.addEventListener("scroll", update, true);
104
+ return () => {
105
+ window.removeEventListener("resize", update);
106
+ window.removeEventListener("scroll", update, true);
107
+ };
108
+ }, [expanded]);
109
+ useEffect(() => {
110
+ if (expanded) {
111
+ document.getElementById(optionId(active))?.scrollIntoView?.({ block: "nearest" });
112
+ }
113
+ });
114
+ function emit(nextChips, nextPending) {
115
+ onChange([...nextChips, nextPending.trim()].filter((part) => part.length > 0).join(", "));
116
+ }
117
+ function handleInputChange(e) {
118
+ const { finished, rest } = splitTypedRecipients(e.target.value);
119
+ const nextPending = rest.replace(/^\s+/, "");
120
+ setPending(nextPending);
121
+ setOpen(true);
122
+ emit([...chips, ...finished], nextPending);
123
+ }
124
+ function commitPending() {
125
+ const next = [...chips, pendingText].filter((part) => part.length > 0).join(", ");
126
+ setPending("");
127
+ setOpen(false);
128
+ return next;
129
+ }
130
+ function select(suggestion) {
131
+ const next = [...chips, formatRecipient({ address: suggestion.address, displayName: suggestion.displayName || undefined })].join(", ");
132
+ setPending("");
133
+ setOpen(false);
134
+ setSuggestions([]);
135
+ onChange(next);
136
+ onCommit?.(next);
137
+ }
138
+ function removeChip(index) {
139
+ emit(chips.filter((_, i) => i !== index), inputValue);
140
+ inputRef.current?.focus();
141
+ }
142
+ function handleKeyDown(e) {
143
+ switch (e.key) {
144
+ case "ArrowDown":
145
+ case "ArrowUp": {
146
+ if (visible.length === 0) {
147
+ return;
148
+ }
149
+ e.preventDefault();
150
+ if (!expanded) {
151
+ setOpen(true);
152
+ setActiveIndex(e.key === "ArrowDown" ? 0 : visible.length - 1);
153
+ return;
154
+ }
155
+ const step = e.key === "ArrowDown" ? 1 : -1;
156
+ setActiveIndex((active + step + visible.length) % visible.length);
157
+ return;
158
+ }
159
+ case "Enter":
160
+ if (expanded) {
161
+ e.preventDefault();
162
+ select(visible[active]);
163
+ }
164
+ else if (pendingText) {
165
+ e.preventDefault();
166
+ const next = commitPending();
167
+ onCommit?.(next);
168
+ }
169
+ return;
170
+ case "Tab":
171
+ if (expanded && !e.shiftKey) {
172
+ e.preventDefault();
173
+ select(visible[active]);
174
+ }
175
+ return;
176
+ case "Escape":
177
+ if (expanded) {
178
+ e.preventDefault();
179
+ e.stopPropagation();
180
+ setOpen(false);
181
+ }
182
+ return;
183
+ case "Backspace":
184
+ if (inputValue === "" && chips.length > 0) {
185
+ e.preventDefault();
186
+ emit(chips.slice(0, -1), "");
187
+ }
188
+ return;
189
+ }
190
+ }
191
+ function handleBlur() {
192
+ const next = commitPending();
193
+ onBlur?.(next);
194
+ }
195
+ return (_jsxs("div", { ref: anchorRef, className: "flex-1 min-w-0 flex flex-wrap items-center gap-1", children: [chips.length > 0 && (_jsx("ul", { role: "list", "aria-label": `${label} recipients`, className: "contents", children: chips.map((chip, index) => {
196
+ const recipient = parseRecipient(chip);
197
+ const valid = isValidRecipientAddress(recipient.address);
198
+ const name = recipient.displayName || recipient.address;
199
+ return (_jsxs("li", { title: chip, className: `flex items-center gap-1 max-w-full min-w-0 rounded-pill border pl-2 pr-0.5 py-px text-xs ${valid ? "bg-surface-alt border-border text-text" : "bg-danger-bg border-danger text-danger"}`, children: [_jsx("span", { className: "truncate", children: name }), !valid && _jsx("span", { className: "sr-only", children: " (not a valid email address)" }), _jsx("button", { type: "button", tabIndex: -1, "aria-label": `Remove ${recipient.address}`, disabled: disabled, onMouseDown: (e) => e.preventDefault(), onClick: () => removeChip(index), className: "shrink-0 w-4 h-4 flex items-center justify-center rounded-pill text-text-muted hover:bg-border hover:text-text", children: _jsx(HiOutlineXMark, { size: 10 }) })] }, `${index}-${chip}`));
200
+ }) })), _jsx("input", { ref: inputRef, id: id, type: "text", role: "combobox", autoComplete: "off", "aria-autocomplete": "list", "aria-expanded": expanded, "aria-controls": listboxId, "aria-activedescendant": expanded ? optionId(active) : undefined, disabled: disabled, autoFocus: autoFocus, className: "flex-1 min-w-[6rem] text-sm bg-transparent outline-none py-0.5", value: inputValue, onChange: handleInputChange, onKeyDown: handleKeyDown, onBlur: handleBlur }), _jsx("span", { className: "sr-only", "aria-live": "polite", children: expanded ? `${visible.length} ${visible.length === 1 ? "suggestion" : "suggestions"}` : "" }), expanded &&
201
+ position &&
202
+ createPortal(_jsx("ul", { id: listboxId, role: "listbox", "aria-label": `${label} suggestions`, onMouseDown: (e) => e.preventDefault(), style: { position: "fixed", left: position.left, width: position.width, top: position.top, bottom: position.bottom, maxHeight: position.maxHeight }, className: "z-[60] overflow-y-auto bg-surface border border-border rounded-md shadow-modal py-1", children: visible.map((suggestion, index) => (_jsxs("li", { id: optionId(index), role: "option", "aria-selected": index === active, onMouseDown: (e) => e.preventDefault(), onMouseEnter: () => setActiveIndex(index), onClick: () => select(suggestion), className: `flex items-center gap-2 px-3 py-1.5 cursor-pointer ${index === active ? "bg-primary/10" : ""}`, children: [_jsxs("span", { className: "flex-1 min-w-0", children: [_jsx("span", { className: "block truncate text-sm text-text", children: suggestion.displayName || suggestion.address }), suggestion.displayName && _jsx("span", { className: "block truncate text-xs text-text-muted", children: suggestion.address })] }), _jsx("span", { className: "shrink-0 text-[11px] leading-4 px-1.5 rounded-pill bg-surface-alt text-text-muted", children: KIND_LABELS[suggestion.kind] ?? "Directory" })] }, `${index}-${suggestion.address}`))) }), document.body)] }));
203
+ }
@@ -0,0 +1,43 @@
1
+ import React from "react";
2
+ export interface RichTextEditorProps {
3
+ value: string;
4
+ onChange: (value: string) => void;
5
+ height?: string;
6
+ /** When true, the editor fills its parent's height via flexbox instead of a fixed `height` — for
7
+ * embedding inside a flex-column container of variable height (the floating Compose window) where
8
+ * a literal pixel height can't be computed up front. `height` is ignored when this is set. */
9
+ fill?: boolean;
10
+ /** Passed straight through to `ComposeToolbar` — see its own doc comment on this prop. */
11
+ onUploadImage: (file: File) => Promise<string | null>;
12
+ /** Focuses the editor with the caret at the very start of the document once it mounts - a reply or forward, whose
13
+ * body starts with an empty paragraph above the signature and quote, so typing goes above them. Only read when
14
+ * the editor is created. */
15
+ autoFocusStart?: boolean;
16
+ /** Called once the editor is ready, with `value` as the editor itself serializes it: TipTap drops what its schema
17
+ * doesn't hold (e.g. a blockquote's `style`) and adds an empty paragraph after a trailing non-paragraph node (a
18
+ * quote). That normalization happens on the editor's first transaction - even one that only moves the caret -
19
+ * and isn't reported through `onChange`, so a caller can compare later edits against this instead of `value`. */
20
+ onInitialized?: (value: string) => void;
21
+ }
22
+ /**
23
+ * A WYSIWYG rich-text editor for the Compose window's message body — replaces `MonacoHtmlEditor` (an HTML
24
+ * *source* editor) with a real Outlook-Home-tab-style formatting experience, built on TipTap/ProseMirror.
25
+ * Used by `ComposeWindow` (the floating overlay, not a dedicated page — see `ComposeContext.tsx`'s doc
26
+ * comment).
27
+ *
28
+ * `value` seeds the editor's initial content only — like `MonacoHtmlEditor`, this never re-syncs from a
29
+ * later `value` prop change; TipTap owns its own document once created. Live edits flow out as HTML (via
30
+ * `editor.getHTML()`) through `onChange`.
31
+ *
32
+ * `immediatelyRender: false` is required for this framework's SSR: the page embedding `ComposeWindow` is
33
+ * rendered server-side under plain Node before hydration (see `ReactRoute`), and TipTap's default
34
+ * (`immediatelyRender: true`) tries to mount its ProseMirror view during that very first render, which
35
+ * both can't work without a real DOM and produces a hydration mismatch. With it `false`, `useEditor`
36
+ * returns `null` until the editor actually mounts client-side after hydration — `ComposeToolbar`/
37
+ * `EditorContent` both already handle a `null` editor by rendering their disabled/empty state, so this
38
+ * needs no extra loading-placeholder logic here. Unlike `MonacoHtmlEditor`, no dynamic `import()` is
39
+ * needed to defer loading TipTap's modules off the SSR path — `immediatelyRender: false` alone is
40
+ * sufficient here since TipTap (unlike Monaco) never touches the DOM at module-evaluation time, only when
41
+ * an editor view actually mounts.
42
+ */
43
+ export default function RichTextEditor({ value, onChange, height, fill, onUploadImage, autoFocusStart, onInitialized, }: RichTextEditorProps): React.JSX.Element;
@@ -3,7 +3,7 @@ import { jsx as _jsx, jsxs as _jsxs } from "react/jsx-runtime";
3
3
  // Copyright (C) 2026 Jean-Philippe Steinmetz
4
4
  // SPDX-License-Identifier: MPL-2.0
5
5
  ///////////////////////////////////////////////////////////////////////////////
6
- import { useRef } from "react";
6
+ import { useRef, useState } from "react";
7
7
  import { EditorContent, useEditor } from "@tiptap/react";
8
8
  import StarterKit from "@tiptap/starter-kit";
9
9
  import { TextStyleKit } from "@tiptap/extension-text-style";
@@ -34,9 +34,16 @@ import ComposeToolbar from "./ComposeToolbar.js";
34
34
  * sufficient here since TipTap (unlike Monaco) never touches the DOM at module-evaluation time, only when
35
35
  * an editor view actually mounts.
36
36
  */
37
- export default function RichTextEditor({ value, onChange, height = "360px", fill = false, onUploadImage }) {
37
+ export default function RichTextEditor({ value, onChange, height = "360px", fill = false, onUploadImage, autoFocusStart = false, onInitialized, }) {
38
38
  const onChangeRef = useRef(onChange);
39
39
  onChangeRef.current = onChange;
40
+ const onInitializedRef = useRef(onInitialized);
41
+ onInitializedRef.current = onInitialized;
42
+ // Transactions before `create` (the autofocus, and the normalizing one below) aren't edits.
43
+ const initializedRef = useRef(false);
44
+ // Held for this editor's lifetime: TipTap focuses a tick after creating the editor, and a re-render passing a
45
+ // different value in between would replace the option (via `setOptions`) before it's read.
46
+ const [autofocus] = useState(autoFocusStart ? "start" : false);
40
47
  const editor = useEditor({
41
48
  extensions: [
42
49
  StarterKit.configure({ link: { openOnClick: false } }),
@@ -48,8 +55,19 @@ export default function RichTextEditor({ value, onChange, height = "360px", fill
48
55
  Placeholder.configure({ placeholder: "Write your message…" }),
49
56
  ],
50
57
  content: value,
58
+ autofocus,
51
59
  immediatelyRender: false,
52
- onUpdate: ({ editor: updated }) => onChangeRef.current(updated.getHTML()),
60
+ onCreate: ({ editor: created }) => {
61
+ // An empty transaction runs the schema's append-transaction normalization now, before any edit.
62
+ created.view.dispatch(created.state.tr);
63
+ initializedRef.current = true;
64
+ onInitializedRef.current?.(created.getHTML());
65
+ },
66
+ onUpdate: ({ editor: updated }) => {
67
+ if (initializedRef.current) {
68
+ onChangeRef.current(updated.getHTML());
69
+ }
70
+ },
53
71
  });
54
72
  return (_jsxs("div", { className: ["border border-border rounded-sm overflow-hidden", fill ? "h-full flex flex-col" : ""].filter(Boolean).join(" "), children: [_jsx(ComposeToolbar, { editor: editor, onUploadImage: onUploadImage }), _jsx(EditorContent, { editor: editor, style: fill ? undefined : { height }, className: [
55
73
  "overflow-y-auto px-3 py-2 text-sm [&_.tiptap]:outline-none [&_.tiptap]:h-full",
@@ -0,0 +1,16 @@
1
+ import React, { RefObject } from "react";
2
+ export interface ScheduleSendPickerProps {
3
+ anchorRef: RefObject<HTMLElement | null>;
4
+ onClose: () => void;
5
+ /** Called with the chosen instant as a UTC ISO string, already validated to be in the future. */
6
+ onSchedule: (scheduledSendTimeIso: string) => void;
7
+ }
8
+ /**
9
+ * The "Send later" popover next to Compose's Send button — same `PopoverPortal` shell
10
+ * `EmojiPicker`/`GifPicker`/`ResourcePicker` already use, just holding a single `datetime-local` input
11
+ * instead of a grid/list. Validates the chosen time is genuinely in the future before calling
12
+ * `onSchedule` — `@rapidmx/restapi`'s own `send()` only defers when `scheduledSendTime` is strictly
13
+ * later than "now", so a past/immediate pick here would silently send right away instead of scheduling,
14
+ * which would surprise a reader expecting the picker's own choice to be honored.
15
+ */
16
+ export default function ScheduleSendPicker({ anchorRef, onClose, onSchedule }: ScheduleSendPickerProps): React.JSX.Element;
@@ -0,0 +1,27 @@
1
+ /** Saves a compose window's unsaved edits (or waits for a save already on the wire), resolving to `false` when
2
+ * something the window holds is still unsaved afterwards (any other value counts as saved). Never rejects. */
3
+ export type ComposeFlush = () => Promise<unknown>;
4
+ /**
5
+ * Marks the app as signing out (explicitly, or forced by a sign-out in another tab), so compose windows stop
6
+ * asking the browser to confirm leaving the page - the "Leave site?" prompt would otherwise let the user cancel
7
+ * the sign-out's own navigation and stay on a page whose session is being ended. Call it before flushing drafts
8
+ * and navigating. `clearSigningOut()` undoes it (a sign-out that didn't leave the page after all).
9
+ */
10
+ export declare function markSigningOut(): void;
11
+ /** Undoes `markSigningOut()`. */
12
+ export declare function clearSigningOut(): void;
13
+ /** Whether `markSigningOut()` has been called (and not cleared). */
14
+ export declare function isSigningOut(): boolean;
15
+ /**
16
+ * Registers an open compose window's draft flush, so leaving the app on purpose (Sign Out) can save the
17
+ * last edits still waiting on the autosave debounce before the session ends. Returns the unregister
18
+ * function. Module-level rather than React context: `AppShell` (the sign-out handler) renders the
19
+ * `ComposeProvider` itself, so it can't read that provider's context.
20
+ */
21
+ export declare function registerComposeFlush(flush: ComposeFlush): () => void;
22
+ /**
23
+ * Runs every registered flush and waits for all of them, but no longer than `timeoutMs`. Resolves to `true`
24
+ * only when every window reported its content saved in time (a window whose save failed also shows the user
25
+ * why, with Discard / Keep editing). Never rejects.
26
+ */
27
+ export declare function flushComposeDrafts(timeoutMs: number): Promise<boolean>;
@@ -0,0 +1,37 @@
1
+ import { Message, Recipient } from "@rapidmx/react-shared/mail/mailApi.js";
2
+ import type { QuotedBody } from "@rapidmx/react-shared/mail/compose/composeQuoting.js";
3
+ import type { MessageSecurityResult } from "@rapidmx/react-shared/crypto/messageSecurity.js";
4
+ /** What a Reply/Reply All/Forward needs from the message being answered, beyond what its `Message` record holds. */
5
+ export interface OriginalMessage {
6
+ /** The body to quote. Empty when none could be loaded - the quote builders then fall back to `bodyPreview`. */
7
+ body: QuotedBody;
8
+ /** The original To and Cc recipients, recovered from the message's own headers - `undefined` when they couldn't
9
+ * be. Only asked for by Reply All (see `loadOriginalMessage()`). */
10
+ recipients?: Recipient[];
11
+ }
12
+ /**
13
+ * Loads what a Reply/Reply All/Forward needs from `message`: the full body to quote - the same content
14
+ * `MessageDetailPane` shows, never the truncated `bodyPreview` unless nothing else can be had - and, with
15
+ * `options.recipients`, who the message was originally addressed to. Never rejects.
16
+ *
17
+ * Content the pane recovered client-side (`security.text`/`security.html`: a decrypted or verified body) is used as
18
+ * is. For an encrypted message that's the plaintext, so the caller must keep the reply encrypted (see
19
+ * `MessageDetailPane`'s reply handlers).
20
+ *
21
+ * An encrypted message without recovered content (locked keys, a failed decrypt, evaluation still running) quotes
22
+ * nothing: the server only holds ciphertext, which is never fetched or quoted.
23
+ *
24
+ * Otherwise the server's sanitized HTML body (`GET /mail/messages/:id/content`) is used. That route falls back to the
25
+ * preview for a message without an HTML part, so a `text/plain` answer is replaced by the text part of the message's
26
+ * raw MIME.
27
+ *
28
+ * The recipients come from the verified message's protected headers when it has them, else from the raw message's own
29
+ * `To`/`Cc` headers - restapi records only the envelope recipient of a delivered message (`ScanQueueJob`), so
30
+ * `message.recipients` alone would reduce every Reply All to a plain reply. Unprotected headers are the sender's own
31
+ * claim, exactly as in every other mail client's Reply All.
32
+ *
33
+ * The quote builders sanitize whatever HTML this returns (`sanitizeQuotedHtml()`), whichever source it came from.
34
+ */
35
+ export declare function loadOriginalMessage(message: Message, security: MessageSecurityResult | null, options?: {
36
+ recipients?: boolean;
37
+ }): Promise<OriginalMessage>;
@@ -0,0 +1,85 @@
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 { getMessageRawContent } from "@rapidmx/react-shared/mail/mailApi.js";
7
+ import { decodeHeaderText, extractDisplayBody, parseMimeEntity } from "@rapidmx/react-shared/crypto/mime.js";
8
+ import { parseRecipientList } from "./recipients.js";
9
+ /** The recipients one address-list header names, RFC 2047-decoded, with their display names. */
10
+ function headerRecipients(value, type) {
11
+ if (!value) {
12
+ return [];
13
+ }
14
+ return parseRecipientList(decodeHeaderText(value))
15
+ .filter((recipient) => recipient.address.includes("@"))
16
+ .map((recipient) => ({ address: recipient.address, ...(recipient.displayName ? { displayName: recipient.displayName } : {}), type }));
17
+ }
18
+ /**
19
+ * Loads what a Reply/Reply All/Forward needs from `message`: the full body to quote - the same content
20
+ * `MessageDetailPane` shows, never the truncated `bodyPreview` unless nothing else can be had - and, with
21
+ * `options.recipients`, who the message was originally addressed to. Never rejects.
22
+ *
23
+ * Content the pane recovered client-side (`security.text`/`security.html`: a decrypted or verified body) is used as
24
+ * is. For an encrypted message that's the plaintext, so the caller must keep the reply encrypted (see
25
+ * `MessageDetailPane`'s reply handlers).
26
+ *
27
+ * An encrypted message without recovered content (locked keys, a failed decrypt, evaluation still running) quotes
28
+ * nothing: the server only holds ciphertext, which is never fetched or quoted.
29
+ *
30
+ * Otherwise the server's sanitized HTML body (`GET /mail/messages/:id/content`) is used. That route falls back to the
31
+ * preview for a message without an HTML part, so a `text/plain` answer is replaced by the text part of the message's
32
+ * raw MIME.
33
+ *
34
+ * The recipients come from the verified message's protected headers when it has them, else from the raw message's own
35
+ * `To`/`Cc` headers - restapi records only the envelope recipient of a delivered message (`ScanQueueJob`), so
36
+ * `message.recipients` alone would reduce every Reply All to a plain reply. Unprotected headers are the sender's own
37
+ * claim, exactly as in every other mail client's Reply All.
38
+ *
39
+ * The quote builders sanitize whatever HTML this returns (`sanitizeQuotedHtml()`), whichever source it came from.
40
+ */
41
+ export async function loadOriginalMessage(message, security, options = {}) {
42
+ const recovered = security?.text !== undefined ? { text: security.text } : security?.html !== undefined ? { html: security.html } : undefined;
43
+ const protectedHeaders = security?.protectedHeaders;
44
+ const protectedRecipients = protectedHeaders
45
+ ? [...headerRecipients(protectedHeaders.to, "to"), ...headerRecipients(protectedHeaders.cc, "cc")]
46
+ : [];
47
+ const result = { body: recovered ?? {}, ...(protectedRecipients.length > 0 ? { recipients: protectedRecipients } : {}) };
48
+ if (message.encrypted) {
49
+ return result;
50
+ }
51
+ let needsRaw = !!options.recipients && result.recipients === undefined;
52
+ if (!recovered) {
53
+ try {
54
+ const res = await fetch(apiUrl(`/mail/messages/${encodeURIComponent(message.uid)}/content`), { credentials: "include" });
55
+ if (res.ok && (res.headers.get("content-type") ?? "").includes("text/html")) {
56
+ result.body = { html: await res.text() };
57
+ }
58
+ else {
59
+ needsRaw = true;
60
+ }
61
+ }
62
+ catch {
63
+ // The raw message below is the other way to the body.
64
+ needsRaw = true;
65
+ }
66
+ }
67
+ try {
68
+ if (needsRaw) {
69
+ const entity = parseMimeEntity(await getMessageRawContent(message.uid));
70
+ if (!recovered && result.body.html === undefined) {
71
+ const body = extractDisplayBody(entity);
72
+ result.body = body.html !== undefined ? { html: body.html } : body.text !== undefined ? { text: body.text } : {};
73
+ }
74
+ const headers = [...headerRecipients(entity.headers["to"], "to"), ...headerRecipients(entity.headers["cc"], "cc")];
75
+ if (options.recipients && result.recipients === undefined && headers.length > 0) {
76
+ result.recipients = headers;
77
+ }
78
+ }
79
+ }
80
+ catch {
81
+ // Whatever was loaded before the failure stands: the quote falls back to the preview, Reply All to the
82
+ // message's own recipients.
83
+ }
84
+ return result;
85
+ }
@@ -0,0 +1,24 @@
1
+ /**
2
+ * Parsing and formatting of the To/Cc/Bcc fields' text. A field's value is a list of recipients separated by commas or
3
+ * semicolons, each either a bare address or `Display Name <address>` (the name optionally quoted, so it can hold a comma
4
+ * or semicolon itself). Separators inside quotes or angle brackets don't split.
5
+ */
6
+ import type { ComposeRecipientInput } from "@rapidmx/react-shared/mail/mailApi.js";
7
+ /** Splits a field's text into trimmed, non-empty recipient strings - see `splitRaw()`. */
8
+ export declare function splitRecipientList(value: string): string[];
9
+ /** Splits text typed into a field: the recipients finished by a separator, and the text after the last separator
10
+ * (untrimmed; the whole text when there is no separator). */
11
+ export declare function splitTypedRecipients(text: string): {
12
+ finished: string[];
13
+ rest: string;
14
+ };
15
+ /** Parses one recipient string: `Name <address>`, `"Name" <address>`, `<address>` or a bare address. Anything else is
16
+ * kept whole as the address (so it's still sent, and flagged as invalid by the field). */
17
+ export declare function parseRecipient(text: string): ComposeRecipientInput;
18
+ /** Every recipient in a field's text. */
19
+ export declare function parseRecipientList(value: string): ComposeRecipientInput[];
20
+ /** Formats a recipient for a field: `Name <address>` (the name quoted when it holds a special character), or the bare
21
+ * address without a name. */
22
+ export declare function formatRecipient(recipient: ComposeRecipientInput): string;
23
+ /** Whether `address` looks like one plain email address. */
24
+ export declare function isValidRecipientAddress(address: string): boolean;
@@ -0,0 +1,87 @@
1
+ /** One plain address: something, one `@`, something - no whitespace, brackets, quotes or separators. */
2
+ const ADDRESS_PATTERN = /^[^\s@<>()",;]+@[^\s@<>()",;]+$/;
3
+ /** Characters that make a display name need quoting. */
4
+ const NAME_SPECIALS = /[",;<>@()\\]/;
5
+ /** Splits at commas and semicolons outside quotes and angle brackets, keeping every part as is (empty ones too). An
6
+ * unterminated quote or bracket runs to the end of the text. */
7
+ function splitRaw(value) {
8
+ const parts = [];
9
+ let current = "";
10
+ let quoted = false;
11
+ let bracketed = false;
12
+ for (let i = 0; i < value.length; i++) {
13
+ const ch = value[i];
14
+ if (quoted && ch === "\\" && i + 1 < value.length) {
15
+ current += ch + value[i + 1];
16
+ i++;
17
+ continue;
18
+ }
19
+ if (ch === '"' && !bracketed) {
20
+ quoted = !quoted;
21
+ }
22
+ else if (ch === "<" && !quoted) {
23
+ bracketed = true;
24
+ }
25
+ else if (ch === ">" && !quoted) {
26
+ bracketed = false;
27
+ }
28
+ else if ((ch === "," || ch === ";") && !quoted && !bracketed) {
29
+ parts.push(current);
30
+ current = "";
31
+ continue;
32
+ }
33
+ current += ch;
34
+ }
35
+ parts.push(current);
36
+ return parts;
37
+ }
38
+ /** Splits a field's text into trimmed, non-empty recipient strings - see `splitRaw()`. */
39
+ export function splitRecipientList(value) {
40
+ return splitRaw(value)
41
+ .map((part) => part.trim())
42
+ .filter((part) => part.length > 0);
43
+ }
44
+ /** Splits text typed into a field: the recipients finished by a separator, and the text after the last separator
45
+ * (untrimmed; the whole text when there is no separator). */
46
+ export function splitTypedRecipients(text) {
47
+ const parts = splitRaw(text);
48
+ const rest = parts.pop();
49
+ return { finished: parts.map((part) => part.trim()).filter((part) => part.length > 0), rest };
50
+ }
51
+ function unquote(name) {
52
+ const trimmed = name.trim();
53
+ if (trimmed.length >= 2 && trimmed.startsWith('"') && trimmed.endsWith('"')) {
54
+ return trimmed.slice(1, -1).replace(/\\(.)/g, "$1").trim();
55
+ }
56
+ return trimmed;
57
+ }
58
+ /** Parses one recipient string: `Name <address>`, `"Name" <address>`, `<address>` or a bare address. Anything else is
59
+ * kept whole as the address (so it's still sent, and flagged as invalid by the field). */
60
+ export function parseRecipient(text) {
61
+ const trimmed = text.trim();
62
+ const match = /^(.*)<([^<>]*)>\s*$/.exec(trimmed);
63
+ if (match) {
64
+ const address = match[2].trim();
65
+ const displayName = unquote(match[1]);
66
+ return displayName ? { address, displayName } : { address };
67
+ }
68
+ return { address: trimmed };
69
+ }
70
+ /** Every recipient in a field's text. */
71
+ export function parseRecipientList(value) {
72
+ return splitRecipientList(value).map(parseRecipient);
73
+ }
74
+ /** Formats a recipient for a field: `Name <address>` (the name quoted when it holds a special character), or the bare
75
+ * address without a name. */
76
+ export function formatRecipient(recipient) {
77
+ const name = recipient.displayName?.trim();
78
+ if (!name) {
79
+ return recipient.address;
80
+ }
81
+ const safeName = NAME_SPECIALS.test(name) ? `"${name.replace(/(["\\])/g, "\\$1")}"` : name;
82
+ return `${safeName} <${recipient.address}>`;
83
+ }
84
+ /** Whether `address` looks like one plain email address. */
85
+ export function isValidRecipientAddress(address) {
86
+ return ADDRESS_PATTERN.test(address);
87
+ }