"use client"; import React from "react"; import { Plus, X } from "lucide-react"; /** The addresses in a stored value ("a@x.org, b@x.org"). */ export const emailsOf = (value: string | null | undefined) => String(value || "").split(/[\s,;]+/).map(s => s.trim()).filter(Boolean); /** * Hub 2.12.0: one or more email addresses, one per row, with + to add another. The value is the * comma-separated list the API stores ("a@x.org, b@x.org"); empty rows are dropped when saved. */ export function EmailList({ id, label, value, onChange, placeholder, max = 10 }: { id: string; label: string; value: string; onChange: (v: string) => void; placeholder?: string; max?: number; }) { // Keep an empty row while typing: split on commas only, so a half-typed address stays put. const rows = value === "" ? [""] : value.split(",").map(s => s.trim()); const set = (next: string[]) => onChange(next.join(", ")); return (
{rows.map((r, i) => (
set(rows.map((x, j) => (j === i ? e.target.value.replace(/[,;\s]/g, "") : x)))} /> {rows.length > 1 && ( )}
))}
{rows.length < max && ( )}
); }