{
  "$schema": "https://ui.shadcn.com/schema/registry-item.json",
  "name": "saved-facts-drawer",
  "title": "Saved Facts Drawer",
  "description": "A memory drawer with searchable categorized facts, add and edit forms, reversible deletion and keyboard-accessible modal controls.",
  "dependencies": [
    "motion",
    "lucide-react",
    "clsx",
    "tailwind-merge",
    "radix-ui"
  ],
  "files": [
    {
      "path": "registry/new-york/saved-facts-drawer/saved-facts-drawer.tsx",
      "content": "\"use client\";\n\nimport * as React from \"react\";\nimport { motion, useReducedMotion } from \"motion/react\";\nimport { clsx } from \"clsx\";\nimport { twMerge } from \"tailwind-merge\";\nimport { Dialog } from \"radix-ui\";\nimport { ArrowUpRight, Bookmark, Check, Pencil, Plus, Search, Trash2, X } from \"lucide-react\";\n\nexport interface SavedFact { id: string; text: string; category: \"Personal\" | \"Work\" | \"Preferences\" }\nexport interface SavedFactsDrawerProps {\n  initialFacts?: SavedFact[];\n  defaultOpen?: boolean;\n  onFactsChange?: (facts: SavedFact[]) => void;\n  theme?: \"dark\" | \"light\";\n  className?: string;\n}\nconst seed: SavedFact[] = [\n  { id: \"1\", text: \"Keep replies clear, concise and easy to scan.\", category: \"Preferences\" },\n  { id: \"2\", text: \"Our design review happens every Friday.\", category: \"Work\" },\n  { id: \"3\", text: \"Use the Europe/Istanbul time zone for schedules.\", category: \"Personal\" },\n  { id: \"4\", text: \"The current project is the workspace redesign.\", category: \"Work\" },\n];\nconst SHEEN = \"linear-gradient(115deg,rgba(255,255,255,.08),rgba(255,255,255,.02) 30%,transparent 48%,rgba(255,255,255,.04) 74%,transparent),linear-gradient(180deg,rgba(255,255,255,.05),transparent 60%)\";\nfunction Island({ children, theme, active = false, warm = false, className }: { children: React.ReactNode; theme: \"dark\" | \"light\"; active?: boolean; warm?: boolean; className?: string }) {\n  const reduce = useReducedMotion();\n  return <motion.div layout={!reduce} transition={{ type: \"spring\", stiffness: 260, damping: 30 }} className={twMerge(clsx(\"relative isolate w-full rounded-[32px] border font-sans antialiased [font-family:Inter,ui-sans-serif,system-ui,sans-serif]\", theme === \"dark\" ? \"border-white/[0.09] bg-[#0E0E10] text-[#EDEDED]\" : \"border-black/[0.09] bg-[#f7f7f8] text-[#202023]\", className))} style={{ backgroundImage: SHEEN, boxShadow: theme === \"dark\" ? \"inset 0 1px 0 #ffffff1f,0 16px 48px #00000025\" : \"inset 0 1px 0 #ffffff,0 16px 48px #00000008\" }}>\n    <motion.div aria-hidden=\"true\" className=\"pointer-events-none absolute -inset-px rounded-[inherit]\" animate={{ opacity: active && !reduce ? [0.35, 0.8, 0.35] : active ? 0.5 : 0.18 }} transition={{ duration: 3, repeat: active && !reduce ? Infinity : 0 }} style={{ padding: 1, background: warm ? \"conic-gradient(from 40deg,transparent 10%,#FF7BD5 32%,#FFB86B 45%,transparent 65%)\" : \"conic-gradient(from 40deg,transparent 10%,#7CF3FF 32%,#6EA8FF 45%,#9B7BFF 55%,transparent 75%)\", mask: \"linear-gradient(#fff 0 0) content-box,linear-gradient(#fff 0 0)\", maskComposite: \"exclude\", WebkitMaskComposite: \"xor\" }} />\n    {children}\n  </motion.div>;\n}\nfunction Orb({ active = false, warm = false, size = 40 }: { active?: boolean; warm?: boolean; size?: number }) {\n  const reduce = useReducedMotion();\n  return <span aria-hidden=\"true\" className=\"relative inline-flex shrink-0 items-center justify-center\" style={{ width: size, height: size }}>\n    <motion.span className=\"absolute inset-0 rounded-full blur-md\" style={{ background: warm ? \"radial-gradient(circle,#ffb86b55,transparent 70%)\" : \"radial-gradient(circle,#9b7bff55,transparent 70%)\" }} animate={{ opacity: active && !reduce ? [0.3, 0.9, 0.3] : 0.3 }} transition={{ duration: 2.5, repeat: active && !reduce ? Infinity : 0 }} />\n    <motion.svg viewBox=\"0 0 40 40\" className=\"relative size-full\" animate={active && !reduce ? { rotate: [0, 12, 0] } : { rotate: 0 }} transition={{ duration: 5, repeat: active && !reduce ? Infinity : 0 }}>{Array.from({ length: 81 }, (_, i) => { const x = i % 9 - 4; const y = Math.floor(i / 9) - 4; const d = Math.hypot(x, y); return d <= 4.1 ? <circle key={i} cx={20 + x * 3.9} cy={20 + y * 3.9} r={Number((1 - d * .13).toFixed(3))} fill=\"currentColor\" opacity={Number((.95 - d * .16).toFixed(3))} /> : null; })}</motion.svg>\n  </span>;\n}\nconst action = \"inline-flex min-h-10 shrink-0 items-center justify-center gap-2 rounded-full border border-current/[0.12] px-4 text-[11px] transition-colors hover:bg-current/[0.06] focus-visible:outline-2 focus-visible:outline-offset-2 focus-visible:outline-[#9B7BFF] disabled:cursor-not-allowed disabled:opacity-35 motion-reduce:transition-none [&_svg]:shrink-0\";\n\n\nexport function SavedFactsDrawer({ initialFacts = seed, defaultOpen = false, onFactsChange, theme = \"dark\", className }: SavedFactsDrawerProps) {\n  const [facts, setFacts] = React.useState(initialFacts);\n  const [open, setOpen] = React.useState(defaultOpen);\n  const [query, setQuery] = React.useState(\"\");\n  const [category, setCategory] = React.useState(\"All\");\n  const [editing, setEditing] = React.useState<string | null>(null);\n  const [draft, setDraft] = React.useState(\"\");\n  const [draftCategory, setDraftCategory] = React.useState<SavedFact[\"category\"]>(\"Preferences\");\n  const [notice, setNotice] = React.useState(\"\");\n  const [deleted, setDeleted] = React.useState<{ fact: SavedFact; index: number } | null>(null);\n  const current = React.useRef(facts);\n  const editor = React.useRef<HTMLTextAreaElement>(null);\n  const searchId = React.useId();\n  React.useEffect(() => { if (editing !== null) editor.current?.focus(); }, [editing]);\n  function update(next: SavedFact[]) { current.current = next; setFacts(next); onFactsChange?.(next); }\n  function edit(fact?: SavedFact) { setEditing(fact?.id ?? \"new\"); setDraft(fact?.text ?? \"\"); setDraftCategory(fact?.category ?? \"Preferences\"); }\n  function save(e: React.FormEvent) {\n    e.preventDefault(); if (!draft.trim()) return;\n    const next: SavedFact = { id: editing === \"new\" ? crypto.randomUUID() : editing!, text: draft.trim(), category: draftCategory };\n    update(editing === \"new\" ? [...current.current, next] : current.current.map(f => f.id === editing ? next : f));\n    setEditing(null); setNotice(editing === \"new\" ? \"Fact added.\" : \"Fact updated.\");\n  }\n  const filtered = facts.filter(f => (category === \"All\" || f.category === category) && `${f.text} ${f.category}`.toLowerCase().includes(query.toLowerCase()));\n  return <div className={twMerge(\"mx-auto w-full max-w-[460px]\", className)}><Dialog.Root open={open} onOpenChange={value => { setOpen(value); if (!value) setEditing(null); }}>\n    <Island theme={theme} className=\"p-6\"><header className=\"flex items-center gap-3\"><Orb size={44} /><div><h3 className=\"text-[15px] font-medium tracking-[-0.025em]\">The little things, remembered.</h3><p className=\"mt-1 text-[11px] opacity-45\">Context that makes every conversation yours.</p></div></header><div className=\"mt-5 space-y-3\">{facts.slice(0, 2).map(f => <div key={f.id} className=\"flex items-start gap-3 rounded-2xl border border-current/[0.08] bg-current/[0.025] p-3.5\"><Bookmark size={17} className=\"mt-0.5 shrink-0 opacity-40\" /><p className=\"text-[12px] leading-6 opacity-65\">{f.text}</p></div>)}{!facts.length && <p className=\"py-4 text-xs opacity-45\">No saved facts yet. Add something worth remembering.</p>}</div><footer className=\"mt-5 flex items-center justify-between gap-3 border-t border-current/[0.08] pt-4\"><span className=\"text-[11px] opacity-40\">{facts.length} saved facts</span><Dialog.Trigger asChild><button type=\"button\" className={action}>Manage memory<ArrowUpRight size={17} /></button></Dialog.Trigger></footer></Island>\n    <Dialog.Portal><Dialog.Overlay className=\"fixed inset-0 z-50 bg-black/55 backdrop-blur-sm\" /><Dialog.Content aria-describedby={searchId + \"-description\"} className=\"fixed bottom-2 right-2 top-2 z-50 w-[440px] max-w-[calc(100%-16px)] outline-none\">\n      <Island theme={theme} className=\"flex h-full flex-col overflow-hidden rounded-[28px]\">\n        <header className=\"flex shrink-0 items-start gap-3 border-b border-current/[0.08] p-5\"><Orb size={40} /><div className=\"min-w-0 flex-1\"><Dialog.Title className=\"text-[16px] font-medium tracking-[-0.025em]\">Saved facts</Dialog.Title><Dialog.Description id={searchId + \"-description\"} className=\"mt-1 text-[11px] leading-5 opacity-45\">You choose what stays in the conversation.</Dialog.Description></div><Dialog.Close asChild><button type=\"button\" aria-label=\"Close saved facts\" className={action + \" size-10 p-0\"}><X size={18} /></button></Dialog.Close></header>\n        <div className=\"shrink-0 px-5 pt-5\"><label htmlFor={searchId} className=\"sr-only\">Search saved facts</label><div className=\"flex items-center gap-2 rounded-2xl border border-current/10 px-3 focus-within:border-[#9B7BFF]/50\"><Search size={17} className=\"shrink-0 opacity-35\" /><input id={searchId} value={query} onChange={e => setQuery(e.target.value)} placeholder=\"Find a fact…\" className=\"min-h-11 min-w-0 flex-1 bg-transparent text-xs outline-none\" /></div><div role=\"group\" aria-label=\"Fact category\" className=\"mt-3 flex flex-wrap gap-1\">{[\"All\", \"Personal\", \"Work\", \"Preferences\"].map(c => <button type=\"button\" key={c} aria-pressed={category === c} onClick={() => setCategory(c)} className={clsx(\"rounded-full px-3 py-2 text-[10px] outline-none focus-visible:ring-2 focus-visible:ring-[#9B7BFF]\", category === c ? \"bg-current/[0.09]\" : \"opacity-40 hover:bg-current/[0.04]\")}>{c}</button>)}</div></div>\n        <div className=\"min-h-0 flex-1 overflow-y-auto p-5\">\n          {editing !== null && <form onSubmit={save} className=\"mb-4 rounded-2xl border border-[#9B7BFF]/30 bg-current/[0.025] p-4\"><label htmlFor={searchId + \"-edit\"} className=\"text-[11px] opacity-50\">{editing === \"new\" ? \"Something to remember\" : \"Edit fact\"}</label><textarea id={searchId + \"-edit\"} ref={editor} maxLength={500} value={draft} onChange={e => setDraft(e.target.value)} className=\"mt-3 min-h-24 w-full resize-y rounded-lg bg-transparent text-[13px] leading-6 outline-none focus-visible:ring-1 focus-visible:ring-[#9B7BFF]\" /><label htmlFor={searchId + \"-category\"} className=\"sr-only\">New fact category</label><select id={searchId + \"-category\"} value={draftCategory} onChange={e => setDraftCategory(e.target.value as SavedFact[\"category\"])} className={clsx(\"mb-4 min-h-9 w-full rounded-xl border border-current/10 px-3 text-xs\", theme === \"dark\" ? \"bg-[#18181b]\" : \"bg-white\")}>{[\"Personal\", \"Work\", \"Preferences\"].map(c => <option key={c}>{c}</option>)}</select><div className=\"flex gap-2\"><button type=\"submit\" disabled={!draft.trim()} className={action}><Check size={17} />Save fact</button><button type=\"button\" onClick={() => setEditing(null)} className={action}>Cancel</button></div></form>}\n          <ul className=\"space-y-3\">{filtered.map(f => <li key={f.id} className=\"rounded-2xl border border-current/[0.08] bg-current/[0.02] p-4\"><span className=\"text-[9px] uppercase tracking-wider opacity-35\">{f.category}</span><p className=\"mt-2 break-words text-[13px] leading-6 opacity-80\">{f.text}</p><div className=\"mt-3 flex justify-end gap-1\"><button type=\"button\" aria-label={`Edit fact: ${f.text}`} onClick={() => edit(f)} className={action + \" size-9 min-h-9 border-transparent p-0\"}><Pencil size={16} /></button><button type=\"button\" aria-label={`Delete fact: ${f.text}`} onClick={() => { setDeleted({ fact: f, index: current.current.findIndex(item => item.id === f.id) }); update(current.current.filter(item => item.id !== f.id)); if (editing === f.id) setEditing(null); setNotice(\"Fact deleted.\"); }} className={action + \" size-9 min-h-9 border-transparent p-0\"}><Trash2 size={16} /></button></div></li>)}</ul>{!filtered.length && <p className=\"py-12 text-center text-xs opacity-40\">{facts.length ? \"No facts match this view.\" : \"A fresh start. Add your first fact.\"}</p>}\n        </div>\n        <footer className=\"shrink-0 border-t border-current/[0.08] p-5\"><div className=\"mb-3 flex items-center justify-between gap-3\"><p role=\"status\" className=\"text-[11px] opacity-50\">{notice || `${facts.length} facts · stored in this session`}</p>{deleted && <button type=\"button\" className=\"text-[11px] underline underline-offset-4\" onClick={() => { const next = [...current.current]; next.splice(Math.min(deleted.index, next.length), 0, deleted.fact); update(next); setDeleted(null); setNotice(\"Fact restored.\"); }}>Undo delete</button>}</div><button type=\"button\" onClick={() => edit()} className={action + \" w-full\"}><Plus size={18} />Add a fact</button></footer>\n      </Island>\n    </Dialog.Content></Dialog.Portal>\n  </Dialog.Root></div>;\n}\nexport default SavedFactsDrawer;\n",
      "type": "registry:component"
    }
  ],
  "type": "registry:component"
}