feat(plugins) : add onRecipientChipsChange hook

This commit is contained in:
Paulhenry Saux
2026-07-20 20:23:11 +02:00
committed by Linus Rath
parent 0a30b2fb3a
commit 2cb5c739b4
3 changed files with 67 additions and 1 deletions
+23
View File
@@ -1,5 +1,7 @@
import { isValidEmail } from "@/lib/validation";
import { htmlToPlainText } from "@/lib/html-to-text";
import { emailHooks } from "./plugin-hooks";
import { Ellipsis, Lock, TriangleAlert } from "lucide-react";
const HTML_ESCAPE_MAP = {
"&": "&",
@@ -109,6 +111,17 @@ export function extractUserAuthoredText(
return text;
}
/**
* Used for hook to let plugins enrich recipient chips with colors and icons.
* The icon is a key into ICON_MAP, which maps to a lucide-react component.
*/
export const ICON_MAP = {
'lock': Lock,
'triangle-alert': TriangleAlert,
'ellipsis': Ellipsis,
};
type IconName = keyof typeof ICON_MAP;
/**
* A composer recipient. Display name is optional; email is required - except
* for contact-group chips, which carry their already-resolved members and an
@@ -119,6 +132,16 @@ export type Recipient = {
name?: string;
email: string;
group?: { members: Array<{ name?: string; email: string }> };
extra?: {
color?: "success" | "destructive" | "warning"; // optional color for display purposes. May be populated by plugins via the onRecipientChipsChange hook.
icon?: IconName; // optional icon for display purposes. May be populated by plugins via the onRecipientChipsChange hook.
enriched?: boolean; // optional flag to indicate if the recipient has been enriched by plugins via the onRecipientChipsChange hook.
};
};
/** Enriches recipient chips with colors and icons. */
export async function enrichChipsWithColorsAndIcons(chips: Recipient[]): Promise<Recipient[]> {
return await emailHooks.onRecipientChipsChange.transform(chips);
};
/**
+4
View File
@@ -276,6 +276,10 @@ export const emailHooks = {
// lets plugin edit emails before they are shown in row. Used to populate preview
// field for encryption plugins.
onEmailsFetched: new HookBus(),
// Transform hook - lets plugins edit the recipient chips in composer fields.
// They can add, remove, or modify chips (e.g. rewrite addresses, add colors/icons).
// Take Recipient[] as argument.
onRecipientChipsChange: new HookBus(),
};
// §7.2 Calendar Hooks