@handled-ai/design-system 0.18.39 → 0.18.40

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.
@@ -20,9 +20,9 @@ var __spreadValues = (a, b) => {
20
20
  return a;
21
21
  };
22
22
  var __spreadProps = (a, b) => __defProps(a, __getOwnPropDescs(b));
23
- import { jsx, jsxs } from "react/jsx-runtime";
23
+ import { Fragment, jsx, jsxs } from "react/jsx-runtime";
24
24
  import * as React from "react";
25
- import { createPortal } from "react-dom";
25
+ import { Popover as PopoverPrimitive } from "radix-ui";
26
26
  import {
27
27
  Check,
28
28
  ChevronDown,
@@ -90,70 +90,13 @@ function RecipientChipPill({
90
90
  )
91
91
  ] });
92
92
  }
93
- function ContactPickerPopover({
94
- triggerRef,
93
+ function ContactPickerContents({
95
94
  contacts,
96
95
  addedEmails,
97
96
  onSelect,
98
- onAddEmail,
99
- onClose
97
+ onAddEmail
100
98
  }) {
101
- const containerRef = React.useRef(null);
102
- const searchRef = React.useRef(null);
103
99
  const [query, setQuery] = React.useState("");
104
- const [style, setStyle] = React.useState({
105
- position: "fixed",
106
- top: -9999,
107
- left: -9999
108
- });
109
- React.useEffect(() => {
110
- const trigger = triggerRef.current;
111
- if (!trigger) return;
112
- const rect = trigger.getBoundingClientRect();
113
- const width = Math.min(448, window.innerWidth - 32);
114
- let left = rect.left;
115
- if (left + width > window.innerWidth - 16) {
116
- left = window.innerWidth - 16 - width;
117
- }
118
- if (left < 16) left = 16;
119
- const popoverHeight = 280;
120
- const spaceBelow = window.innerHeight - rect.bottom - 4;
121
- const spaceAbove = rect.top - 4;
122
- const placeAbove = spaceBelow < popoverHeight && spaceAbove > spaceBelow;
123
- let top = placeAbove ? rect.top - popoverHeight - 4 : rect.bottom + 4;
124
- if (top < 16) top = 16;
125
- setStyle({ position: "fixed", top, left, width });
126
- }, [triggerRef]);
127
- React.useEffect(() => {
128
- var _a;
129
- (_a = searchRef.current) == null ? void 0 : _a.focus();
130
- const trigger = triggerRef.current;
131
- return () => {
132
- if (trigger && typeof trigger.focus === "function") {
133
- trigger.focus();
134
- }
135
- };
136
- }, [triggerRef]);
137
- React.useEffect(() => {
138
- function handleMouseDown(event) {
139
- var _a;
140
- if (containerRef.current && !containerRef.current.contains(event.target) && !((_a = triggerRef.current) == null ? void 0 : _a.contains(event.target))) {
141
- onClose();
142
- }
143
- }
144
- function handleKeyDown2(event) {
145
- if (event.key === "Escape") {
146
- event.stopPropagation();
147
- onClose();
148
- }
149
- }
150
- document.addEventListener("mousedown", handleMouseDown);
151
- document.addEventListener("keydown", handleKeyDown2);
152
- return () => {
153
- document.removeEventListener("mousedown", handleMouseDown);
154
- document.removeEventListener("keydown", handleKeyDown2);
155
- };
156
- }, [onClose, triggerRef]);
157
100
  const normalizedQuery = query.trim().toLowerCase();
158
101
  const filtered = normalizedQuery ? contacts.filter((contact) => {
159
102
  var _a;
@@ -168,82 +111,73 @@ function ContactPickerPopover({
168
111
  setQuery("");
169
112
  }
170
113
  }
171
- return createPortal(
172
- /* @__PURE__ */ jsxs(
173
- "div",
174
- {
175
- ref: containerRef,
176
- style,
177
- className: "bg-background border rounded-lg shadow-xl z-50 pointer-events-auto",
178
- children: [
179
- /* @__PURE__ */ jsxs("div", { className: "flex items-center gap-2 px-3 py-2.5 border-b border-border/50", children: [
180
- /* @__PURE__ */ jsx(Search, { className: "size-4 text-muted-foreground shrink-0" }),
181
- /* @__PURE__ */ jsx(
182
- "input",
183
- {
184
- ref: searchRef,
185
- autoFocus: true,
186
- value: query,
187
- onChange: (event) => setQuery(event.target.value),
188
- onKeyDown: handleKeyDown,
189
- className: "flex-1 text-[13px] bg-transparent outline-none",
190
- placeholder: "Search contacts..."
191
- }
192
- )
193
- ] }),
194
- /* @__PURE__ */ jsx("div", { role: "listbox", className: "max-h-[208px] overflow-y-auto p-1", children: filtered.length === 0 ? /* @__PURE__ */ jsxs("div", { className: "px-3 py-4 text-center text-[13px] text-muted-foreground", children: [
195
- /* @__PURE__ */ jsxs("div", { children: [
196
- "No contact matches \u2018",
197
- query,
198
- "\u2019."
114
+ return /* @__PURE__ */ jsxs(Fragment, { children: [
115
+ /* @__PURE__ */ jsxs("div", { className: "flex items-center gap-2 px-3 py-2.5 border-b border-border/50", children: [
116
+ /* @__PURE__ */ jsx(Search, { className: "size-4 text-muted-foreground shrink-0" }),
117
+ /* @__PURE__ */ jsx(
118
+ "input",
119
+ {
120
+ autoFocus: true,
121
+ value: query,
122
+ onChange: (event) => setQuery(event.target.value),
123
+ onKeyDown: handleKeyDown,
124
+ className: "flex-1 text-[13px] bg-transparent outline-none",
125
+ placeholder: "Search contacts..."
126
+ }
127
+ )
128
+ ] }),
129
+ /* @__PURE__ */ jsx("div", { role: "listbox", className: "max-h-[208px] overflow-y-auto p-1", children: contacts.length === 0 ? /* @__PURE__ */ jsxs("div", { className: "px-3 py-5 text-center text-[13px] text-muted-foreground", children: [
130
+ /* @__PURE__ */ jsx("div", { className: "font-medium text-foreground/80", children: "No contacts for this account" }),
131
+ /* @__PURE__ */ jsx("div", { className: "mt-1", children: "Type an email address above and press Enter to add a recipient." })
132
+ ] }) : filtered.length === 0 ? /* @__PURE__ */ jsxs("div", { className: "px-3 py-4 text-center text-[13px] text-muted-foreground", children: [
133
+ /* @__PURE__ */ jsxs("div", { children: [
134
+ "No contact matches \u2018",
135
+ query,
136
+ "\u2019."
137
+ ] }),
138
+ queryIsEmail ? /* @__PURE__ */ jsxs("div", { className: "mt-1", children: [
139
+ "Press Enter to add ",
140
+ query,
141
+ "."
142
+ ] }) : null
143
+ ] }) : filtered.map((contact, index) => {
144
+ const email = contactEmail(contact);
145
+ const noEmail = !email || !isValidEmail(email);
146
+ const alreadyAdded = email ? addedEmails.has(email.toLowerCase()) : false;
147
+ const disabled = noEmail || alreadyAdded;
148
+ return /* @__PURE__ */ jsxs(
149
+ "div",
150
+ {
151
+ role: "option",
152
+ "aria-selected": false,
153
+ "aria-disabled": disabled,
154
+ onClick: () => {
155
+ if (!disabled) onSelect(contact);
156
+ },
157
+ className: cn(
158
+ "flex items-center gap-2.5 px-2 py-1.5 rounded-md cursor-pointer hover:bg-muted/60",
159
+ disabled && "opacity-45 pointer-events-none"
160
+ ),
161
+ children: [
162
+ /* @__PURE__ */ jsx("div", { className: "flex size-7 shrink-0 items-center justify-center rounded-[7px] bg-muted text-[11px] font-medium text-muted-foreground", children: getInitials(contact.name, email != null ? email : "?") }),
163
+ /* @__PURE__ */ jsxs("div", { className: "min-w-0 flex-1", children: [
164
+ /* @__PURE__ */ jsxs("div", { className: "flex items-center gap-1.5", children: [
165
+ /* @__PURE__ */ jsx("span", { className: "truncate text-[13px] font-medium text-foreground", children: contact.name }),
166
+ /* @__PURE__ */ jsx("span", { className: "truncate text-[11px] text-muted-foreground", children: contact.role })
167
+ ] }),
168
+ email ? /* @__PURE__ */ jsx("div", { className: "truncate text-[11px] text-muted-foreground", children: email }) : null
199
169
  ] }),
200
- queryIsEmail ? /* @__PURE__ */ jsxs("div", { className: "mt-1", children: [
201
- "Press Enter to add ",
202
- query,
203
- "."
204
- ] }) : null
205
- ] }) : filtered.map((contact, index) => {
206
- const email = contactEmail(contact);
207
- const noEmail = !email || !isValidEmail(email);
208
- const alreadyAdded = email ? addedEmails.has(email.toLowerCase()) : false;
209
- const disabled = noEmail || alreadyAdded;
210
- return /* @__PURE__ */ jsxs(
211
- "div",
212
- {
213
- role: "option",
214
- "aria-selected": false,
215
- "aria-disabled": disabled,
216
- onClick: () => {
217
- if (!disabled) onSelect(contact);
218
- },
219
- className: cn(
220
- "flex items-center gap-2.5 px-2 py-1.5 rounded-md cursor-pointer hover:bg-muted/60",
221
- disabled && "opacity-45 pointer-events-none"
222
- ),
223
- children: [
224
- /* @__PURE__ */ jsx("div", { className: "flex size-7 shrink-0 items-center justify-center rounded-[7px] bg-muted text-[11px] font-medium text-muted-foreground", children: getInitials(contact.name, email != null ? email : "?") }),
225
- /* @__PURE__ */ jsxs("div", { className: "min-w-0 flex-1", children: [
226
- /* @__PURE__ */ jsxs("div", { className: "flex items-center gap-1.5", children: [
227
- /* @__PURE__ */ jsx("span", { className: "truncate text-[13px] font-medium text-foreground", children: contact.name }),
228
- /* @__PURE__ */ jsx("span", { className: "truncate text-[11px] text-muted-foreground", children: contact.role })
229
- ] }),
230
- email ? /* @__PURE__ */ jsx("div", { className: "truncate text-[11px] text-muted-foreground", children: email }) : null
231
- ] }),
232
- alreadyAdded ? /* @__PURE__ */ jsx("span", { className: "shrink-0 text-[10.5px] font-medium text-muted-foreground", children: "Added" }) : noEmail ? /* @__PURE__ */ jsx("span", { className: "shrink-0 text-[10.5px] font-medium text-muted-foreground", children: "No email" }) : null
233
- ]
234
- },
235
- `${contact.name}-${email != null ? email : index}`
236
- );
237
- }) }),
238
- /* @__PURE__ */ jsxs("div", { className: "flex items-center gap-1.5 px-3 py-2 border-t border-border/50 text-[11px] text-muted-foreground", children: [
239
- /* @__PURE__ */ jsx(CornerDownLeft, { className: "size-3 shrink-0" }),
240
- /* @__PURE__ */ jsx("span", { children: "Type an address and press Enter to add someone not listed." })
241
- ] })
242
- ]
243
- }
244
- ),
245
- document.body
246
- );
170
+ alreadyAdded ? /* @__PURE__ */ jsx("span", { className: "shrink-0 text-[10.5px] font-medium text-muted-foreground", children: "Added" }) : noEmail ? /* @__PURE__ */ jsx("span", { className: "shrink-0 text-[10.5px] font-medium text-muted-foreground", children: "No email" }) : null
171
+ ]
172
+ },
173
+ `${contact.name}-${email != null ? email : index}`
174
+ );
175
+ }) }),
176
+ /* @__PURE__ */ jsxs("div", { className: "flex items-center gap-1.5 px-3 py-2 border-t border-border/50 text-[11px] text-muted-foreground", children: [
177
+ /* @__PURE__ */ jsx(CornerDownLeft, { className: "size-3 shrink-0" }),
178
+ /* @__PURE__ */ jsx("span", { children: "Type an address and press Enter to add someone not listed." })
179
+ ] })
180
+ ] });
247
181
  }
248
182
  function EmailRecipientField({
249
183
  label,
@@ -261,7 +195,6 @@ function EmailRecipientField({
261
195
  }) {
262
196
  const [value, setValue] = React.useState("");
263
197
  const [pickerOpen, setPickerOpen] = React.useState(false);
264
- const contactsTriggerRef = React.useRef(null);
265
198
  const hasUnconfirmed = recipients.some((r) => !r.confirmed);
266
199
  const state = amber && hasUnconfirmed ? "amber" : "default";
267
200
  const amberRow = state === "amber";
@@ -351,20 +284,42 @@ function EmailRecipientField({
351
284
  )
352
285
  ] }),
353
286
  showPicker || showCcBcc ? /* @__PURE__ */ jsxs("div", { className: "flex gap-1.5 mt-2", children: [
354
- showPicker ? /* @__PURE__ */ jsxs(
355
- "button",
356
- {
357
- ref: contactsTriggerRef,
358
- type: "button",
359
- onClick: () => setPickerOpen((open) => !open),
360
- className: "inline-flex items-center gap-1 h-6 px-2.5 rounded-md border border-border bg-background text-[11px] font-medium text-muted-foreground hover:bg-muted/60 hover:text-foreground transition-colors duration-[120ms]",
361
- children: [
362
- /* @__PURE__ */ jsx(Users, { className: "size-3" }),
363
- "Contacts",
364
- /* @__PURE__ */ jsx(ChevronDown, { className: "size-3" })
365
- ]
366
- }
367
- ) : null,
287
+ showPicker ? /* @__PURE__ */ jsxs(PopoverPrimitive.Root, { open: pickerOpen, onOpenChange: setPickerOpen, children: [
288
+ /* @__PURE__ */ jsx(PopoverPrimitive.Trigger, { asChild: true, children: /* @__PURE__ */ jsxs(
289
+ "button",
290
+ {
291
+ type: "button",
292
+ className: "inline-flex items-center gap-1 h-6 px-2.5 rounded-md border border-border bg-background text-[11px] font-medium text-muted-foreground hover:bg-muted/60 hover:text-foreground transition-colors duration-[120ms]",
293
+ children: [
294
+ /* @__PURE__ */ jsx(Users, { className: "size-3" }),
295
+ "Contacts",
296
+ /* @__PURE__ */ jsx(ChevronDown, { className: "size-3" })
297
+ ]
298
+ }
299
+ ) }),
300
+ /* @__PURE__ */ jsx(PopoverPrimitive.Portal, { children: /* @__PURE__ */ jsx(
301
+ PopoverPrimitive.Content,
302
+ {
303
+ side: "bottom",
304
+ align: "start",
305
+ sideOffset: 4,
306
+ collisionPadding: 16,
307
+ className: "z-50 w-[min(448px,calc(100vw-2rem))] rounded-lg border bg-background shadow-xl p-0",
308
+ children: /* @__PURE__ */ jsx(
309
+ ContactPickerContents,
310
+ {
311
+ contacts,
312
+ addedEmails: added,
313
+ onSelect: selectContact,
314
+ onAddEmail: (email) => {
315
+ addEmail(email);
316
+ setPickerOpen(false);
317
+ }
318
+ }
319
+ )
320
+ }
321
+ ) })
322
+ ] }) : null,
368
323
  showCcBcc ? /* @__PURE__ */ jsxs(
369
324
  "button",
370
325
  {
@@ -377,21 +332,7 @@ function EmailRecipientField({
377
332
  ]
378
333
  }
379
334
  ) : null
380
- ] }) : null,
381
- pickerOpen ? /* @__PURE__ */ jsx(
382
- ContactPickerPopover,
383
- {
384
- triggerRef: contactsTriggerRef,
385
- contacts,
386
- addedEmails: added,
387
- onSelect: selectContact,
388
- onAddEmail: (email) => {
389
- addEmail(email);
390
- setPickerOpen(false);
391
- },
392
- onClose: () => setPickerOpen(false)
393
- }
394
- ) : null
335
+ ] }) : null
395
336
  ] })
396
337
  ]
397
338
  }
@@ -1 +1 @@
1
- {"version":3,"sources":["../../src/components/email-recipient-field.tsx"],"sourcesContent":["\"use client\"\n\nimport * as React from \"react\"\nimport { createPortal } from \"react-dom\"\nimport {\n Check,\n ChevronDown,\n CornerDownLeft,\n Plus,\n Search,\n Users,\n X,\n} from \"lucide-react\"\n\nimport { cn } from \"../lib/utils\"\nimport type { SuggestedContact } from \"./suggested-actions\"\n\nconst EMAIL_REGEX = /^[^\\s@]+@[^\\s@]+\\.[^\\s@]+$/\n\nfunction isValidEmail(value: string): boolean {\n return EMAIL_REGEX.test(value.trim())\n}\n\nfunction contactEmail(contact: SuggestedContact): string | undefined {\n return contact.email ?? contact.emails?.[0]\n}\n\nfunction getInitials(name: string, fallback: string): string {\n const source = name?.trim() || fallback\n return source\n .split(/[\\s@.]+/)\n .map((part) => part[0])\n .filter(Boolean)\n .slice(0, 2)\n .join(\"\")\n .toUpperCase()\n}\n\nexport interface RecipientChip {\n id: string\n email: string\n name: string\n confirmed: boolean\n}\n\nexport interface EmailRecipientFieldProps {\n label: string\n recipients: RecipientChip[]\n onRecipientsChange: (recipients: RecipientChip[]) => void\n amber?: boolean\n contacts?: SuggestedContact[]\n showPicker?: boolean\n showCcBcc?: boolean\n ccBccOpen?: boolean\n onCcBccToggle?: () => void\n addedEmails?: Set<string>\n placeholder?: string\n contactToRecipient?: (contact: SuggestedContact) => RecipientChip\n}\n\nfunction RecipientChipPill({\n recipient,\n onConfirm,\n onRemove,\n}: {\n recipient: RecipientChip\n onConfirm: () => void\n onRemove: () => void\n}) {\n const display = recipient.name || recipient.email\n\n if (!recipient.confirmed) {\n return (\n <span className=\"inline-flex items-center gap-1 h-6 px-2 rounded-md text-xs border border-amber-300 bg-amber-50 text-amber-900\">\n <span className=\"truncate max-w-[180px]\">{display}</span>\n <button\n type=\"button\"\n onClick={onConfirm}\n className=\"text-[10.5px] font-semibold px-[7px] py-0.5 rounded bg-amber-300/50 hover:bg-amber-300/85\"\n >\n Confirm\n </button>\n <button\n type=\"button\"\n aria-label={`Remove ${display}`}\n onClick={onRemove}\n className=\"inline-flex items-center justify-center size-[17px] rounded text-amber-700/80 hover:bg-amber-300/40\"\n >\n <X className=\"size-3\" />\n </button>\n </span>\n )\n }\n\n return (\n <span className=\"inline-flex items-center gap-1 h-6 px-2 rounded-md text-xs border border-border bg-muted/50 text-foreground\">\n <span className=\"inline-flex items-center justify-center size-[17px] rounded bg-emerald-50 text-emerald-700\">\n <Check className=\"size-3\" />\n </span>\n <span className=\"truncate max-w-[180px]\">{display}</span>\n <button\n type=\"button\"\n aria-label={`Remove ${display}`}\n onClick={onRemove}\n className=\"inline-flex items-center justify-center size-[17px] rounded text-muted-foreground hover:bg-muted\"\n >\n <X className=\"size-3\" />\n </button>\n </span>\n )\n}\n\nfunction ContactPickerPopover({\n triggerRef,\n contacts,\n addedEmails,\n onSelect,\n onAddEmail,\n onClose,\n}: {\n triggerRef: React.RefObject<HTMLElement | null>\n contacts: SuggestedContact[]\n addedEmails: Set<string>\n onSelect: (contact: SuggestedContact) => void\n onAddEmail: (email: string) => void\n onClose: () => void\n}) {\n const containerRef = React.useRef<HTMLDivElement>(null)\n const searchRef = React.useRef<HTMLInputElement>(null)\n const [query, setQuery] = React.useState(\"\")\n const [style, setStyle] = React.useState<React.CSSProperties>({\n position: \"fixed\",\n top: -9999,\n left: -9999,\n })\n\n React.useEffect(() => {\n const trigger = triggerRef.current\n if (!trigger) return\n const rect = trigger.getBoundingClientRect()\n const width = Math.min(448, window.innerWidth - 32)\n let left = rect.left\n if (left + width > window.innerWidth - 16) {\n left = window.innerWidth - 16 - width\n }\n if (left < 16) left = 16\n const popoverHeight = 280\n const spaceBelow = window.innerHeight - rect.bottom - 4\n const spaceAbove = rect.top - 4\n const placeAbove = spaceBelow < popoverHeight && spaceAbove > spaceBelow\n let top = placeAbove ? rect.top - popoverHeight - 4 : rect.bottom + 4\n if (top < 16) top = 16\n setStyle({ position: \"fixed\", top, left, width })\n }, [triggerRef])\n\n React.useEffect(() => {\n searchRef.current?.focus()\n const trigger = triggerRef.current\n return () => {\n if (trigger && typeof trigger.focus === \"function\") {\n trigger.focus()\n }\n }\n }, [triggerRef])\n\n React.useEffect(() => {\n function handleMouseDown(event: MouseEvent) {\n if (\n containerRef.current &&\n !containerRef.current.contains(event.target as Node) &&\n !triggerRef.current?.contains(event.target as Node)\n ) {\n onClose()\n }\n }\n function handleKeyDown(event: KeyboardEvent) {\n if (event.key === \"Escape\") {\n event.stopPropagation()\n onClose()\n }\n }\n document.addEventListener(\"mousedown\", handleMouseDown)\n document.addEventListener(\"keydown\", handleKeyDown)\n return () => {\n document.removeEventListener(\"mousedown\", handleMouseDown)\n document.removeEventListener(\"keydown\", handleKeyDown)\n }\n }, [onClose, triggerRef])\n\n const normalizedQuery = query.trim().toLowerCase()\n const filtered = normalizedQuery\n ? contacts.filter((contact) => {\n const email = contactEmail(contact) ?? \"\"\n return (\n contact.name.toLowerCase().includes(normalizedQuery) ||\n contact.role.toLowerCase().includes(normalizedQuery) ||\n email.toLowerCase().includes(normalizedQuery)\n )\n })\n : contacts\n\n const queryIsEmail = isValidEmail(query)\n\n function handleKeyDown(event: React.KeyboardEvent<HTMLInputElement>) {\n if (event.key === \"Enter\" && queryIsEmail) {\n event.preventDefault()\n onAddEmail(query.trim())\n setQuery(\"\")\n }\n }\n\n return createPortal(\n <div\n ref={containerRef}\n style={style}\n className=\"bg-background border rounded-lg shadow-xl z-50 pointer-events-auto\"\n >\n <div className=\"flex items-center gap-2 px-3 py-2.5 border-b border-border/50\">\n <Search className=\"size-4 text-muted-foreground shrink-0\" />\n <input\n ref={searchRef}\n autoFocus\n value={query}\n onChange={(event) => setQuery(event.target.value)}\n onKeyDown={handleKeyDown}\n className=\"flex-1 text-[13px] bg-transparent outline-none\"\n placeholder=\"Search contacts...\"\n />\n </div>\n\n <div role=\"listbox\" className=\"max-h-[208px] overflow-y-auto p-1\">\n {filtered.length === 0 ? (\n <div className=\"px-3 py-4 text-center text-[13px] text-muted-foreground\">\n <div>No contact matches &lsquo;{query}&rsquo;.</div>\n {queryIsEmail ? (\n <div className=\"mt-1\">Press Enter to add {query}.</div>\n ) : null}\n </div>\n ) : (\n filtered.map((contact, index) => {\n const email = contactEmail(contact)\n const noEmail = !email || !isValidEmail(email)\n const alreadyAdded = email\n ? addedEmails.has(email.toLowerCase())\n : false\n const disabled = noEmail || alreadyAdded\n\n return (\n <div\n key={`${contact.name}-${email ?? index}`}\n role=\"option\"\n aria-selected={false}\n aria-disabled={disabled}\n onClick={() => {\n if (!disabled) onSelect(contact)\n }}\n className={cn(\n \"flex items-center gap-2.5 px-2 py-1.5 rounded-md cursor-pointer hover:bg-muted/60\",\n disabled && \"opacity-45 pointer-events-none\",\n )}\n >\n <div className=\"flex size-7 shrink-0 items-center justify-center rounded-[7px] bg-muted text-[11px] font-medium text-muted-foreground\">\n {getInitials(contact.name, email ?? \"?\")}\n </div>\n <div className=\"min-w-0 flex-1\">\n <div className=\"flex items-center gap-1.5\">\n <span className=\"truncate text-[13px] font-medium text-foreground\">\n {contact.name}\n </span>\n <span className=\"truncate text-[11px] text-muted-foreground\">\n {contact.role}\n </span>\n </div>\n {email ? (\n <div className=\"truncate text-[11px] text-muted-foreground\">\n {email}\n </div>\n ) : null}\n </div>\n {alreadyAdded ? (\n <span className=\"shrink-0 text-[10.5px] font-medium text-muted-foreground\">\n Added\n </span>\n ) : noEmail ? (\n <span className=\"shrink-0 text-[10.5px] font-medium text-muted-foreground\">\n No email\n </span>\n ) : null}\n </div>\n )\n })\n )}\n </div>\n\n <div className=\"flex items-center gap-1.5 px-3 py-2 border-t border-border/50 text-[11px] text-muted-foreground\">\n <CornerDownLeft className=\"size-3 shrink-0\" />\n <span>Type an address and press Enter to add someone not listed.</span>\n </div>\n </div>,\n document.body,\n )\n}\n\nexport function EmailRecipientField({\n label,\n recipients,\n onRecipientsChange,\n amber = false,\n contacts = [],\n showPicker = false,\n showCcBcc = false,\n ccBccOpen = false,\n onCcBccToggle,\n addedEmails,\n placeholder,\n contactToRecipient,\n}: EmailRecipientFieldProps) {\n const [value, setValue] = React.useState(\"\")\n const [pickerOpen, setPickerOpen] = React.useState(false)\n const contactsTriggerRef = React.useRef<HTMLButtonElement>(null)\n\n const hasUnconfirmed = recipients.some((r) => !r.confirmed)\n const state: \"default\" | \"amber\" =\n amber && hasUnconfirmed ? \"amber\" : \"default\"\n const amberRow = state === \"amber\"\n\n const added = addedEmails ?? new Set<string>()\n\n const resolvedPlaceholder =\n placeholder ?? (recipients.length > 0 ? \"Add another...\" : \"Add email...\")\n\n function addEmail(email: string) {\n const trimmed = email.trim()\n if (!isValidEmail(trimmed)) return\n if (added.has(trimmed.toLowerCase())) return\n onRecipientsChange([\n ...recipients,\n { id: trimmed, email: trimmed, name: \"\", confirmed: false },\n ])\n setValue(\"\")\n }\n\n function handleKeyDown(event: React.KeyboardEvent<HTMLInputElement>) {\n if ((event.key === \"Enter\" || event.key === \",\") && isValidEmail(value)) {\n event.preventDefault()\n addEmail(value)\n return\n }\n if (event.key === \"Backspace\" && value === \"\" && recipients.length > 0) {\n event.preventDefault()\n onRecipientsChange(recipients.slice(0, -1))\n }\n }\n\n function confirmRecipient(id: string) {\n onRecipientsChange(\n recipients.map((r) => (r.id === id ? { ...r, confirmed: true } : r)),\n )\n }\n\n function removeRecipient(id: string) {\n onRecipientsChange(recipients.filter((r) => r.id !== id))\n }\n\n function selectContact(contact: SuggestedContact) {\n const recipient =\n contactToRecipient?.(contact) ??\n ({\n id: contactEmail(contact) ?? contact.name,\n email: contactEmail(contact) ?? \"\",\n name: contact.name,\n confirmed: true,\n } satisfies RecipientChip)\n onRecipientsChange([...recipients, recipient])\n setPickerOpen(false)\n }\n\n return (\n <div\n className={cn(\n \"grid grid-cols-[60px_1fr] gap-2 px-[18px] py-[9px] border-b border-border/70 items-start text-sm\",\n amberRow && \"bg-amber-50/35 border-amber-200/80\",\n )}\n >\n <div\n className={cn(\n \"text-[11px] font-semibold uppercase tracking-wide text-muted-foreground pt-[7px]\",\n amberRow && \"text-amber-700\",\n )}\n >\n {label}\n </div>\n\n <div className=\"min-w-0\">\n <div className=\"flex flex-wrap gap-1.5 items-center\">\n {recipients.map((recipient) => (\n <RecipientChipPill\n key={recipient.id}\n recipient={recipient}\n onConfirm={() => confirmRecipient(recipient.id)}\n onRemove={() => removeRecipient(recipient.id)}\n />\n ))}\n <input\n value={value}\n onChange={(event) => setValue(event.target.value)}\n onKeyDown={handleKeyDown}\n onBlur={() => {\n // Commit any valid pending email so it is not silently dropped\n // when the user clicks Send without pressing Enter/comma first.\n if (isValidEmail(value)) addEmail(value)\n }}\n placeholder={resolvedPlaceholder}\n className=\"min-w-[130px] flex-1 h-6 text-[13px] bg-transparent border-0 outline-none placeholder:text-muted-foreground\"\n />\n </div>\n\n {showPicker || showCcBcc ? (\n <div className=\"flex gap-1.5 mt-2\">\n {showPicker ? (\n <button\n ref={contactsTriggerRef}\n type=\"button\"\n onClick={() => setPickerOpen((open) => !open)}\n className=\"inline-flex items-center gap-1 h-6 px-2.5 rounded-md border border-border bg-background text-[11px] font-medium text-muted-foreground hover:bg-muted/60 hover:text-foreground transition-colors duration-[120ms]\"\n >\n <Users className=\"size-3\" />\n Contacts\n <ChevronDown className=\"size-3\" />\n </button>\n ) : null}\n {showCcBcc ? (\n <button\n type=\"button\"\n onClick={onCcBccToggle}\n className=\"inline-flex items-center gap-1 h-6 px-2.5 rounded-md border border-border bg-background text-[11px] font-medium text-muted-foreground hover:bg-muted/60 hover:text-foreground transition-colors duration-[120ms]\"\n >\n <Plus className=\"size-3\" />\n {ccBccOpen ? \"Hide Cc/Bcc\" : \"Add Cc/Bcc\"}\n </button>\n ) : null}\n </div>\n ) : null}\n\n {pickerOpen ? (\n <ContactPickerPopover\n triggerRef={contactsTriggerRef}\n contacts={contacts}\n addedEmails={added}\n onSelect={selectContact}\n onAddEmail={(email) => {\n addEmail(email)\n setPickerOpen(false)\n }}\n onClose={() => setPickerOpen(false)}\n />\n ) : null}\n </div>\n </div>\n )\n}\n"],"mappings":";;;;;;;;;;;;;;;;;;;;AAyEM,SACE,KADF;AAvEN,YAAY,WAAW;AACvB,SAAS,oBAAoB;AAC7B;AAAA,EACE;AAAA,EACA;AAAA,EACA;AAAA,EACA;AAAA,EACA;AAAA,EACA;AAAA,EACA;AAAA,OACK;AAEP,SAAS,UAAU;AAGnB,MAAM,cAAc;AAEpB,SAAS,aAAa,OAAwB;AAC5C,SAAO,YAAY,KAAK,MAAM,KAAK,CAAC;AACtC;AAEA,SAAS,aAAa,SAA+C;AAvBrE;AAwBE,UAAO,aAAQ,UAAR,aAAiB,aAAQ,WAAR,mBAAiB;AAC3C;AAEA,SAAS,YAAY,MAAc,UAA0B;AAC3D,QAAM,UAAS,6BAAM,WAAU;AAC/B,SAAO,OACJ,MAAM,SAAS,EACf,IAAI,CAAC,SAAS,KAAK,CAAC,CAAC,EACrB,OAAO,OAAO,EACd,MAAM,GAAG,CAAC,EACV,KAAK,EAAE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,gBACL,MAAK;AAAA,gBACL,SAAS,MAAM,cAAc,CAAC,SAAS,CAAC,IAAI;AAAA,gBAC5C,WAAU;AAAA,gBAEV;AAAA,sCAAC,SAAM,WAAU,UAAS;AAAA,kBAAE;AAAA,kBAE5B,oBAAC,eAAY,WAAU,UAAS;AAAA;AAAA;AAAA,YAClC,IACE;AAAA,YACH,YACC;AAAA,cAAC;AAAA;AAAA,gBACC,MAAK;AAAA,gBACL,SAAS;AAAA,gBACT,WAAU;AAAA,gBAEV;AAAA,sCAAC,QAAK,WAAU,UAAS;AAAA,kBACxB,YAAY,gBAAgB;AAAA;AAAA;AAAA,YAC/B,IACE;AAAA,aACN,IACE;AAAA,UAEH,aACC;AAAA,YAAC;AAAA;AAAA,cACC,YAAY;AAAA,cACZ;AAAA,cACA,aAAa;AAAA,cACb,UAAU;AAAA,cACV,YAAY,CAAC,UAAU;AACrB,yBAAS,KAAK;AACd,8BAAc,KAAK;AAAA,cACrB;AAAA,cACA,SAAS,MAAM,cAAc,KAAK;AAAA;AAAA,UACpC,IACE;AAAA,WACN;AAAA;AAAA;AAAA,EACF;AAEJ;","names":["handleKeyDown"]}
1
+ {"version":3,"sources":["../../src/components/email-recipient-field.tsx"],"sourcesContent":["\"use client\"\n\nimport * as React from \"react\"\nimport { Popover as PopoverPrimitive } from \"radix-ui\"\nimport {\n Check,\n ChevronDown,\n CornerDownLeft,\n Plus,\n Search,\n Users,\n X,\n} from \"lucide-react\"\n\nimport { cn } from \"../lib/utils\"\nimport type { SuggestedContact } from \"./suggested-actions\"\n\nconst EMAIL_REGEX = /^[^\\s@]+@[^\\s@]+\\.[^\\s@]+$/\n\nfunction isValidEmail(value: string): boolean {\n return EMAIL_REGEX.test(value.trim())\n}\n\nfunction contactEmail(contact: SuggestedContact): string | undefined {\n return contact.email ?? contact.emails?.[0]\n}\n\nfunction getInitials(name: string, fallback: string): string {\n const source = name?.trim() || fallback\n return source\n .split(/[\\s@.]+/)\n .map((part) => part[0])\n .filter(Boolean)\n .slice(0, 2)\n .join(\"\")\n .toUpperCase()\n}\n\nexport interface RecipientChip {\n id: string\n email: string\n name: string\n confirmed: boolean\n}\n\nexport interface EmailRecipientFieldProps {\n label: string\n recipients: RecipientChip[]\n onRecipientsChange: (recipients: RecipientChip[]) => void\n amber?: boolean\n contacts?: SuggestedContact[]\n showPicker?: boolean\n showCcBcc?: boolean\n ccBccOpen?: boolean\n onCcBccToggle?: () => void\n addedEmails?: Set<string>\n placeholder?: string\n contactToRecipient?: (contact: SuggestedContact) => RecipientChip\n}\n\nfunction RecipientChipPill({\n recipient,\n onConfirm,\n onRemove,\n}: {\n recipient: RecipientChip\n onConfirm: () => void\n onRemove: () => void\n}) {\n const display = recipient.name || recipient.email\n\n if (!recipient.confirmed) {\n return (\n <span className=\"inline-flex items-center gap-1 h-6 px-2 rounded-md text-xs border border-amber-300 bg-amber-50 text-amber-900\">\n <span className=\"truncate max-w-[180px]\">{display}</span>\n <button\n type=\"button\"\n onClick={onConfirm}\n className=\"text-[10.5px] font-semibold px-[7px] py-0.5 rounded bg-amber-300/50 hover:bg-amber-300/85\"\n >\n Confirm\n </button>\n <button\n type=\"button\"\n aria-label={`Remove ${display}`}\n onClick={onRemove}\n className=\"inline-flex items-center justify-center size-[17px] rounded text-amber-700/80 hover:bg-amber-300/40\"\n >\n <X className=\"size-3\" />\n </button>\n </span>\n )\n }\n\n return (\n <span className=\"inline-flex items-center gap-1 h-6 px-2 rounded-md text-xs border border-border bg-muted/50 text-foreground\">\n <span className=\"inline-flex items-center justify-center size-[17px] rounded bg-emerald-50 text-emerald-700\">\n <Check className=\"size-3\" />\n </span>\n <span className=\"truncate max-w-[180px]\">{display}</span>\n <button\n type=\"button\"\n aria-label={`Remove ${display}`}\n onClick={onRemove}\n className=\"inline-flex items-center justify-center size-[17px] rounded text-muted-foreground hover:bg-muted\"\n >\n <X className=\"size-3\" />\n </button>\n </span>\n )\n}\n\n// Contents of the contact picker dropdown. Rendered inside a Radix\n// `Popover.Content` so its focus scope pushes onto the focus-scope stack and\n// PAUSES any parent modal's scope (e.g. the quick-action Dialog). This is what\n// makes the search input typeable: a plain `createPortal(..., document.body)`\n// element renders outside the Dialog's `DialogContent`, so the Dialog's\n// FocusScope kept yanking focus back (input un-typeable) and its modal\n// `pointer-events: none` on <body> left the portal click-dead. A stacked Radix\n// Popover layer gets `pointer-events: auto` and its own (paused-parent) focus\n// scope, fixing both. See WIT-800 / WIT-770.\nfunction ContactPickerContents({\n contacts,\n addedEmails,\n onSelect,\n onAddEmail,\n}: {\n contacts: SuggestedContact[]\n addedEmails: Set<string>\n onSelect: (contact: SuggestedContact) => void\n onAddEmail: (email: string) => void\n}) {\n const [query, setQuery] = React.useState(\"\")\n\n const normalizedQuery = query.trim().toLowerCase()\n const filtered = normalizedQuery\n ? contacts.filter((contact) => {\n const email = contactEmail(contact) ?? \"\"\n return (\n contact.name.toLowerCase().includes(normalizedQuery) ||\n contact.role.toLowerCase().includes(normalizedQuery) ||\n email.toLowerCase().includes(normalizedQuery)\n )\n })\n : contacts\n\n const queryIsEmail = isValidEmail(query)\n\n function handleKeyDown(event: React.KeyboardEvent<HTMLInputElement>) {\n if (event.key === \"Enter\" && queryIsEmail) {\n event.preventDefault()\n onAddEmail(query.trim())\n setQuery(\"\")\n }\n }\n\n return (\n <>\n <div className=\"flex items-center gap-2 px-3 py-2.5 border-b border-border/50\">\n <Search className=\"size-4 text-muted-foreground shrink-0\" />\n <input\n autoFocus\n value={query}\n onChange={(event) => setQuery(event.target.value)}\n onKeyDown={handleKeyDown}\n className=\"flex-1 text-[13px] bg-transparent outline-none\"\n placeholder=\"Search contacts...\"\n />\n </div>\n\n <div role=\"listbox\" className=\"max-h-[208px] overflow-y-auto p-1\">\n {contacts.length === 0 ? (\n <div className=\"px-3 py-5 text-center text-[13px] text-muted-foreground\">\n <div className=\"font-medium text-foreground/80\">\n No contacts for this account\n </div>\n <div className=\"mt-1\">\n Type an email address above and press Enter to add a recipient.\n </div>\n </div>\n ) : filtered.length === 0 ? (\n <div className=\"px-3 py-4 text-center text-[13px] text-muted-foreground\">\n <div>No contact matches &lsquo;{query}&rsquo;.</div>\n {queryIsEmail ? (\n <div className=\"mt-1\">Press Enter to add {query}.</div>\n ) : null}\n </div>\n ) : (\n filtered.map((contact, index) => {\n const email = contactEmail(contact)\n const noEmail = !email || !isValidEmail(email)\n const alreadyAdded = email\n ? addedEmails.has(email.toLowerCase())\n : false\n const disabled = noEmail || alreadyAdded\n\n return (\n <div\n key={`${contact.name}-${email ?? index}`}\n role=\"option\"\n aria-selected={false}\n aria-disabled={disabled}\n onClick={() => {\n if (!disabled) onSelect(contact)\n }}\n className={cn(\n \"flex items-center gap-2.5 px-2 py-1.5 rounded-md cursor-pointer hover:bg-muted/60\",\n disabled && \"opacity-45 pointer-events-none\",\n )}\n >\n <div className=\"flex size-7 shrink-0 items-center justify-center rounded-[7px] bg-muted text-[11px] font-medium text-muted-foreground\">\n {getInitials(contact.name, email ?? \"?\")}\n </div>\n <div className=\"min-w-0 flex-1\">\n <div className=\"flex items-center gap-1.5\">\n <span className=\"truncate text-[13px] font-medium text-foreground\">\n {contact.name}\n </span>\n <span className=\"truncate text-[11px] text-muted-foreground\">\n {contact.role}\n </span>\n </div>\n {email ? (\n <div className=\"truncate text-[11px] text-muted-foreground\">\n {email}\n </div>\n ) : null}\n </div>\n {alreadyAdded ? (\n <span className=\"shrink-0 text-[10.5px] font-medium text-muted-foreground\">\n Added\n </span>\n ) : noEmail ? (\n <span className=\"shrink-0 text-[10.5px] font-medium text-muted-foreground\">\n No email\n </span>\n ) : null}\n </div>\n )\n })\n )}\n </div>\n\n <div className=\"flex items-center gap-1.5 px-3 py-2 border-t border-border/50 text-[11px] text-muted-foreground\">\n <CornerDownLeft className=\"size-3 shrink-0\" />\n <span>Type an address and press Enter to add someone not listed.</span>\n </div>\n </>\n )\n}\n\nexport function EmailRecipientField({\n label,\n recipients,\n onRecipientsChange,\n amber = false,\n contacts = [],\n showPicker = false,\n showCcBcc = false,\n ccBccOpen = false,\n onCcBccToggle,\n addedEmails,\n placeholder,\n contactToRecipient,\n}: EmailRecipientFieldProps) {\n const [value, setValue] = React.useState(\"\")\n const [pickerOpen, setPickerOpen] = React.useState(false)\n\n const hasUnconfirmed = recipients.some((r) => !r.confirmed)\n const state: \"default\" | \"amber\" =\n amber && hasUnconfirmed ? \"amber\" : \"default\"\n const amberRow = state === \"amber\"\n\n const added = addedEmails ?? new Set<string>()\n\n const resolvedPlaceholder =\n placeholder ?? (recipients.length > 0 ? \"Add another...\" : \"Add email...\")\n\n function addEmail(email: string) {\n const trimmed = email.trim()\n if (!isValidEmail(trimmed)) return\n if (added.has(trimmed.toLowerCase())) return\n onRecipientsChange([\n ...recipients,\n { id: trimmed, email: trimmed, name: \"\", confirmed: false },\n ])\n setValue(\"\")\n }\n\n function handleKeyDown(event: React.KeyboardEvent<HTMLInputElement>) {\n if ((event.key === \"Enter\" || event.key === \",\") && isValidEmail(value)) {\n event.preventDefault()\n addEmail(value)\n return\n }\n if (event.key === \"Backspace\" && value === \"\" && recipients.length > 0) {\n event.preventDefault()\n onRecipientsChange(recipients.slice(0, -1))\n }\n }\n\n function confirmRecipient(id: string) {\n onRecipientsChange(\n recipients.map((r) => (r.id === id ? { ...r, confirmed: true } : r)),\n )\n }\n\n function removeRecipient(id: string) {\n onRecipientsChange(recipients.filter((r) => r.id !== id))\n }\n\n function selectContact(contact: SuggestedContact) {\n const recipient =\n contactToRecipient?.(contact) ??\n ({\n id: contactEmail(contact) ?? contact.name,\n email: contactEmail(contact) ?? \"\",\n name: contact.name,\n confirmed: true,\n } satisfies RecipientChip)\n onRecipientsChange([...recipients, recipient])\n setPickerOpen(false)\n }\n\n return (\n <div\n className={cn(\n \"grid grid-cols-[60px_1fr] gap-2 px-[18px] py-[9px] border-b border-border/70 items-start text-sm\",\n amberRow && \"bg-amber-50/35 border-amber-200/80\",\n )}\n >\n <div\n className={cn(\n \"text-[11px] font-semibold uppercase tracking-wide text-muted-foreground pt-[7px]\",\n amberRow && \"text-amber-700\",\n )}\n >\n {label}\n </div>\n\n <div className=\"min-w-0\">\n <div className=\"flex flex-wrap gap-1.5 items-center\">\n {recipients.map((recipient) => (\n <RecipientChipPill\n key={recipient.id}\n recipient={recipient}\n onConfirm={() => confirmRecipient(recipient.id)}\n onRemove={() => removeRecipient(recipient.id)}\n />\n ))}\n <input\n value={value}\n onChange={(event) => setValue(event.target.value)}\n onKeyDown={handleKeyDown}\n onBlur={() => {\n // Commit any valid pending email so it is not silently dropped\n // when the user clicks Send without pressing Enter/comma first.\n if (isValidEmail(value)) addEmail(value)\n }}\n placeholder={resolvedPlaceholder}\n className=\"min-w-[130px] flex-1 h-6 text-[13px] bg-transparent border-0 outline-none placeholder:text-muted-foreground\"\n />\n </div>\n\n {showPicker || showCcBcc ? (\n <div className=\"flex gap-1.5 mt-2\">\n {showPicker ? (\n <PopoverPrimitive.Root open={pickerOpen} onOpenChange={setPickerOpen}>\n <PopoverPrimitive.Trigger asChild>\n <button\n type=\"button\"\n className=\"inline-flex items-center gap-1 h-6 px-2.5 rounded-md border border-border bg-background text-[11px] font-medium text-muted-foreground hover:bg-muted/60 hover:text-foreground transition-colors duration-[120ms]\"\n >\n <Users className=\"size-3\" />\n Contacts\n <ChevronDown className=\"size-3\" />\n </button>\n </PopoverPrimitive.Trigger>\n <PopoverPrimitive.Portal>\n <PopoverPrimitive.Content\n side=\"bottom\"\n align=\"start\"\n sideOffset={4}\n collisionPadding={16}\n className=\"z-50 w-[min(448px,calc(100vw-2rem))] rounded-lg border bg-background shadow-xl p-0\"\n >\n <ContactPickerContents\n contacts={contacts}\n addedEmails={added}\n onSelect={selectContact}\n onAddEmail={(email) => {\n addEmail(email)\n setPickerOpen(false)\n }}\n />\n </PopoverPrimitive.Content>\n </PopoverPrimitive.Portal>\n </PopoverPrimitive.Root>\n ) : null}\n {showCcBcc ? (\n <button\n type=\"button\"\n onClick={onCcBccToggle}\n className=\"inline-flex items-center gap-1 h-6 px-2.5 rounded-md border border-border bg-background text-[11px] font-medium text-muted-foreground hover:bg-muted/60 hover:text-foreground transition-colors duration-[120ms]\"\n >\n <Plus className=\"size-3\" />\n {ccBccOpen ? \"Hide Cc/Bcc\" : \"Add Cc/Bcc\"}\n </button>\n ) : null}\n </div>\n ) : null}\n </div>\n </div>\n )\n}\n"],"mappings":";;;;;;;;;;;;;;;;;;;;AAyEM,SAoFF,UAnFI,KADF;AAvEN,YAAY,WAAW;AACvB,SAAS,WAAW,wBAAwB;AAC5C;AAAA,EACE;AAAA,EACA;AAAA,EACA;AAAA,EACA;AAAA,EACA;AAAA,EACA;AAAA,EACA;AAAA,OACK;AAEP,SAAS,UAAU;AAGnB,MAAM,cAAc;AAEpB,SAAS,aAAa,OAAwB;AAC5C,SAAO,YAAY,KAAK,MAAM,KAAK,CAAC;AACtC;AAEA,SAAS,aAAa,SAA+C;AAvBrE;AAwBE,UAAO,aAAQ,UAAR,aAAiB,aAAQ,WAAR,mBAAiB;AAC3C;AAEA,SAAS,YAAY,MAAc,UAA0B;AAC3D,QAAM,UAAS,6BAAM,WAAU;AAC/B,SAAO,OACJ,MAAM,SAAS,EACf,IAAI,CAAC,SAAS,KAAK,CAAC,CAAC,EACrB,OAAO,OAAO,EACd,MAAM,GAAG,CAAC,EACV,KAAK,EAAE,EACP,YAAY;AACjB;AAwBA,SAAS,kBAAkB;AAAA,EACzB;AAAA,EACA;AAAA,EACA;AACF,GAIG;AACD,QAAM,UAAU,UAAU,QAAQ,UAAU;AAE5C,MAAI,CAAC,UAAU,WAAW;AACxB,WACE,qBAAC,UAAK,WAAU,iHACd;AAAA,0BAAC,UAAK,WAAU,0BAA0B,mBAAQ;AAAA,MAClD;AAAA,QAAC;AAAA;AAAA,UACC,MAAK;AAAA,UACL,SAAS;AAAA,UACT,WAAU;AAAA,UACX;AAAA;AAAA,MAED;AAAA,MACA;AAAA,QAAC;AAAA;AAAA,UACC,MAAK;AAAA,UACL,cAAY,UAAU,OAAO;AAAA,UAC7B,SAAS;AAA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;AAAA;AAAA;AAAA,EACF;AAEJ;","names":[]}
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@handled-ai/design-system",
3
- "version": "0.18.39",
3
+ "version": "0.18.40",
4
4
  "description": "Handled UI component library (shadcn-style, New York)",
5
5
  "type": "module",
6
6
  "packageManager": "pnpm@9.12.0",
@@ -1,11 +1,16 @@
1
1
  import { describe, it, expect, vi, afterEach } from "vitest"
2
2
  import React from "react"
3
- import { render, screen, fireEvent, cleanup } from "@testing-library/react"
3
+ import { render, screen, fireEvent, cleanup, within } from "@testing-library/react"
4
4
 
5
5
  import {
6
6
  EmailRecipientField,
7
7
  type RecipientChip,
8
8
  } from "../email-recipient-field"
9
+ import {
10
+ Dialog,
11
+ DialogContent,
12
+ DialogTitle,
13
+ } from "../dialog"
9
14
  import type { SuggestedContact } from "../suggested-actions"
10
15
 
11
16
  afterEach(() => {
@@ -253,4 +258,114 @@ describe("EmailRecipientField", () => {
253
258
  expect(noEmailRow.className).toContain("pointer-events-none")
254
259
  expect(noEmailRow.textContent).toContain("No email")
255
260
  })
261
+
262
+ it("autofocuses the search input when the picker opens", () => {
263
+ render(
264
+ <EmailRecipientField
265
+ label="To"
266
+ recipients={[]}
267
+ onRecipientsChange={vi.fn()}
268
+ showPicker
269
+ contacts={contacts}
270
+ />,
271
+ )
272
+
273
+ fireEvent.click(screen.getByRole("button", { name: /Contacts/ }))
274
+ const search = screen.getByPlaceholderText("Search contacts...")
275
+ expect(document.activeElement).toBe(search)
276
+ })
277
+
278
+ it("accepts typing in the search box and filters the list", () => {
279
+ render(
280
+ <EmailRecipientField
281
+ label="To"
282
+ recipients={[]}
283
+ onRecipientsChange={vi.fn()}
284
+ showPicker
285
+ contacts={contacts}
286
+ />,
287
+ )
288
+
289
+ fireEvent.click(screen.getByRole("button", { name: /Contacts/ }))
290
+ const search = screen.getByPlaceholderText("Search contacts...") as HTMLInputElement
291
+
292
+ fireEvent.change(search, { target: { value: "Bea" } })
293
+ expect(search.value).toBe("Bea")
294
+ expect(screen.getByText("Bea Buyer")).toBeTruthy()
295
+ expect(screen.queryByText("Alex Admin")).toBeNull()
296
+ })
297
+
298
+ it("adds a typed email from the picker search box on Enter", () => {
299
+ const onChange = vi.fn()
300
+ render(
301
+ <EmailRecipientField
302
+ label="To"
303
+ recipients={[]}
304
+ onRecipientsChange={onChange}
305
+ showPicker
306
+ contacts={contacts}
307
+ />,
308
+ )
309
+
310
+ fireEvent.click(screen.getByRole("button", { name: /Contacts/ }))
311
+ const search = screen.getByPlaceholderText("Search contacts...")
312
+
313
+ fireEvent.change(search, { target: { value: "typed@example.com" } })
314
+ fireEvent.keyDown(search, { key: "Enter" })
315
+
316
+ expect(onChange).toHaveBeenCalledWith([
317
+ { id: "typed@example.com", email: "typed@example.com", name: "", confirmed: false },
318
+ ])
319
+ })
320
+
321
+ it("shows a clear empty state when there are no contacts", () => {
322
+ render(
323
+ <EmailRecipientField
324
+ label="To"
325
+ recipients={[]}
326
+ onRecipientsChange={vi.fn()}
327
+ showPicker
328
+ contacts={[]}
329
+ />,
330
+ )
331
+
332
+ fireEvent.click(screen.getByRole("button", { name: /Contacts/ }))
333
+ expect(screen.getByText("No contacts for this account")).toBeTruthy()
334
+ // The empty state guides the user to type an address instead of looking broken.
335
+ expect(
336
+ screen.getByText(/Type an email address above and press Enter/),
337
+ ).toBeTruthy()
338
+ })
339
+
340
+ it("remains typeable when rendered inside a modal Dialog (WIT-800 focus trap)", () => {
341
+ // Reproduces the staging bug: the picker used to render via
342
+ // createPortal(document.body), outside the Dialog's FocusScope, so the
343
+ // search input could not hold focus. The Radix Popover rebuild keeps the
344
+ // input inside its own (parent-pausing) focus scope.
345
+ render(
346
+ <Dialog open>
347
+ <DialogContent aria-describedby={undefined}>
348
+ <DialogTitle>Compose</DialogTitle>
349
+ <EmailRecipientField
350
+ label="To"
351
+ recipients={[]}
352
+ onRecipientsChange={vi.fn()}
353
+ showPicker
354
+ contacts={contacts}
355
+ />
356
+ </DialogContent>
357
+ </Dialog>,
358
+ )
359
+
360
+ fireEvent.click(screen.getByRole("button", { name: /Contacts/ }))
361
+ const search = screen.getByPlaceholderText("Search contacts...") as HTMLInputElement
362
+
363
+ search.focus()
364
+ expect(document.activeElement).toBe(search)
365
+
366
+ fireEvent.change(search, { target: { value: "Alex" } })
367
+ expect(search.value).toBe("Alex")
368
+ const listbox = screen.getByRole("listbox")
369
+ expect(within(listbox).getByText("Alex Admin")).toBeTruthy()
370
+ })
256
371
  })
@@ -1,7 +1,7 @@
1
1
  "use client"
2
2
 
3
3
  import * as React from "react"
4
- import { createPortal } from "react-dom"
4
+ import { Popover as PopoverPrimitive } from "radix-ui"
5
5
  import {
6
6
  Check,
7
7
  ChevronDown,
@@ -110,82 +110,27 @@ function RecipientChipPill({
110
110
  )
111
111
  }
112
112
 
113
- function ContactPickerPopover({
114
- triggerRef,
113
+ // Contents of the contact picker dropdown. Rendered inside a Radix
114
+ // `Popover.Content` so its focus scope pushes onto the focus-scope stack and
115
+ // PAUSES any parent modal's scope (e.g. the quick-action Dialog). This is what
116
+ // makes the search input typeable: a plain `createPortal(..., document.body)`
117
+ // element renders outside the Dialog's `DialogContent`, so the Dialog's
118
+ // FocusScope kept yanking focus back (input un-typeable) and its modal
119
+ // `pointer-events: none` on <body> left the portal click-dead. A stacked Radix
120
+ // Popover layer gets `pointer-events: auto` and its own (paused-parent) focus
121
+ // scope, fixing both. See WIT-800 / WIT-770.
122
+ function ContactPickerContents({
115
123
  contacts,
116
124
  addedEmails,
117
125
  onSelect,
118
126
  onAddEmail,
119
- onClose,
120
127
  }: {
121
- triggerRef: React.RefObject<HTMLElement | null>
122
128
  contacts: SuggestedContact[]
123
129
  addedEmails: Set<string>
124
130
  onSelect: (contact: SuggestedContact) => void
125
131
  onAddEmail: (email: string) => void
126
- onClose: () => void
127
132
  }) {
128
- const containerRef = React.useRef<HTMLDivElement>(null)
129
- const searchRef = React.useRef<HTMLInputElement>(null)
130
133
  const [query, setQuery] = React.useState("")
131
- const [style, setStyle] = React.useState<React.CSSProperties>({
132
- position: "fixed",
133
- top: -9999,
134
- left: -9999,
135
- })
136
-
137
- React.useEffect(() => {
138
- const trigger = triggerRef.current
139
- if (!trigger) return
140
- const rect = trigger.getBoundingClientRect()
141
- const width = Math.min(448, window.innerWidth - 32)
142
- let left = rect.left
143
- if (left + width > window.innerWidth - 16) {
144
- left = window.innerWidth - 16 - width
145
- }
146
- if (left < 16) left = 16
147
- const popoverHeight = 280
148
- const spaceBelow = window.innerHeight - rect.bottom - 4
149
- const spaceAbove = rect.top - 4
150
- const placeAbove = spaceBelow < popoverHeight && spaceAbove > spaceBelow
151
- let top = placeAbove ? rect.top - popoverHeight - 4 : rect.bottom + 4
152
- if (top < 16) top = 16
153
- setStyle({ position: "fixed", top, left, width })
154
- }, [triggerRef])
155
-
156
- React.useEffect(() => {
157
- searchRef.current?.focus()
158
- const trigger = triggerRef.current
159
- return () => {
160
- if (trigger && typeof trigger.focus === "function") {
161
- trigger.focus()
162
- }
163
- }
164
- }, [triggerRef])
165
-
166
- React.useEffect(() => {
167
- function handleMouseDown(event: MouseEvent) {
168
- if (
169
- containerRef.current &&
170
- !containerRef.current.contains(event.target as Node) &&
171
- !triggerRef.current?.contains(event.target as Node)
172
- ) {
173
- onClose()
174
- }
175
- }
176
- function handleKeyDown(event: KeyboardEvent) {
177
- if (event.key === "Escape") {
178
- event.stopPropagation()
179
- onClose()
180
- }
181
- }
182
- document.addEventListener("mousedown", handleMouseDown)
183
- document.addEventListener("keydown", handleKeyDown)
184
- return () => {
185
- document.removeEventListener("mousedown", handleMouseDown)
186
- document.removeEventListener("keydown", handleKeyDown)
187
- }
188
- }, [onClose, triggerRef])
189
134
 
190
135
  const normalizedQuery = query.trim().toLowerCase()
191
136
  const filtered = normalizedQuery
@@ -209,16 +154,11 @@ function ContactPickerPopover({
209
154
  }
210
155
  }
211
156
 
212
- return createPortal(
213
- <div
214
- ref={containerRef}
215
- style={style}
216
- className="bg-background border rounded-lg shadow-xl z-50 pointer-events-auto"
217
- >
157
+ return (
158
+ <>
218
159
  <div className="flex items-center gap-2 px-3 py-2.5 border-b border-border/50">
219
160
  <Search className="size-4 text-muted-foreground shrink-0" />
220
161
  <input
221
- ref={searchRef}
222
162
  autoFocus
223
163
  value={query}
224
164
  onChange={(event) => setQuery(event.target.value)}
@@ -229,7 +169,16 @@ function ContactPickerPopover({
229
169
  </div>
230
170
 
231
171
  <div role="listbox" className="max-h-[208px] overflow-y-auto p-1">
232
- {filtered.length === 0 ? (
172
+ {contacts.length === 0 ? (
173
+ <div className="px-3 py-5 text-center text-[13px] text-muted-foreground">
174
+ <div className="font-medium text-foreground/80">
175
+ No contacts for this account
176
+ </div>
177
+ <div className="mt-1">
178
+ Type an email address above and press Enter to add a recipient.
179
+ </div>
180
+ </div>
181
+ ) : filtered.length === 0 ? (
233
182
  <div className="px-3 py-4 text-center text-[13px] text-muted-foreground">
234
183
  <div>No contact matches &lsquo;{query}&rsquo;.</div>
235
184
  {queryIsEmail ? (
@@ -296,8 +245,7 @@ function ContactPickerPopover({
296
245
  <CornerDownLeft className="size-3 shrink-0" />
297
246
  <span>Type an address and press Enter to add someone not listed.</span>
298
247
  </div>
299
- </div>,
300
- document.body,
248
+ </>
301
249
  )
302
250
  }
303
251
 
@@ -317,7 +265,6 @@ export function EmailRecipientField({
317
265
  }: EmailRecipientFieldProps) {
318
266
  const [value, setValue] = React.useState("")
319
267
  const [pickerOpen, setPickerOpen] = React.useState(false)
320
- const contactsTriggerRef = React.useRef<HTMLButtonElement>(null)
321
268
 
322
269
  const hasUnconfirmed = recipients.some((r) => !r.confirmed)
323
270
  const state: "default" | "amber" =
@@ -418,16 +365,37 @@ export function EmailRecipientField({
418
365
  {showPicker || showCcBcc ? (
419
366
  <div className="flex gap-1.5 mt-2">
420
367
  {showPicker ? (
421
- <button
422
- ref={contactsTriggerRef}
423
- type="button"
424
- onClick={() => setPickerOpen((open) => !open)}
425
- className="inline-flex items-center gap-1 h-6 px-2.5 rounded-md border border-border bg-background text-[11px] font-medium text-muted-foreground hover:bg-muted/60 hover:text-foreground transition-colors duration-[120ms]"
426
- >
427
- <Users className="size-3" />
428
- Contacts
429
- <ChevronDown className="size-3" />
430
- </button>
368
+ <PopoverPrimitive.Root open={pickerOpen} onOpenChange={setPickerOpen}>
369
+ <PopoverPrimitive.Trigger asChild>
370
+ <button
371
+ type="button"
372
+ className="inline-flex items-center gap-1 h-6 px-2.5 rounded-md border border-border bg-background text-[11px] font-medium text-muted-foreground hover:bg-muted/60 hover:text-foreground transition-colors duration-[120ms]"
373
+ >
374
+ <Users className="size-3" />
375
+ Contacts
376
+ <ChevronDown className="size-3" />
377
+ </button>
378
+ </PopoverPrimitive.Trigger>
379
+ <PopoverPrimitive.Portal>
380
+ <PopoverPrimitive.Content
381
+ side="bottom"
382
+ align="start"
383
+ sideOffset={4}
384
+ collisionPadding={16}
385
+ className="z-50 w-[min(448px,calc(100vw-2rem))] rounded-lg border bg-background shadow-xl p-0"
386
+ >
387
+ <ContactPickerContents
388
+ contacts={contacts}
389
+ addedEmails={added}
390
+ onSelect={selectContact}
391
+ onAddEmail={(email) => {
392
+ addEmail(email)
393
+ setPickerOpen(false)
394
+ }}
395
+ />
396
+ </PopoverPrimitive.Content>
397
+ </PopoverPrimitive.Portal>
398
+ </PopoverPrimitive.Root>
431
399
  ) : null}
432
400
  {showCcBcc ? (
433
401
  <button
@@ -441,20 +409,6 @@ export function EmailRecipientField({
441
409
  ) : null}
442
410
  </div>
443
411
  ) : null}
444
-
445
- {pickerOpen ? (
446
- <ContactPickerPopover
447
- triggerRef={contactsTriggerRef}
448
- contacts={contacts}
449
- addedEmails={added}
450
- onSelect={selectContact}
451
- onAddEmail={(email) => {
452
- addEmail(email)
453
- setPickerOpen(false)
454
- }}
455
- onClose={() => setPickerOpen(false)}
456
- />
457
- ) : null}
458
412
  </div>
459
413
  </div>
460
414
  )