{
  "$schema": "https://ui.shadcn.com/schema/registry-item.json",
  "name": "fill-in-prompts",
  "type": "registry:component",
  "title": "Fill-in Prompts",
  "description": "Saved prompts you fill in right inside the sentence, each blank growing with its text in its own colour, with quick picks for common answers and a Use button that waits until every gap is filled.",
  "categories": [
    "component",
    "Conversation"
  ],
  "dependencies": [
    "lucide-react",
    "motion"
  ],
  "registryDependencies": [
    "utils",
    "https://coss.com/ui/r/button.json"
  ],
  "files": [
    {
      "path": "registry/devl/fill-in-prompts.tsx",
      "type": "registry:component",
      "content": "\"use client\";\n\nimport { ArrowRightIcon, BugIcon, CheckIcon, type LucideIcon, MailIcon, NotebookPenIcon, RotateCcwIcon } from \"lucide-react\";\nimport { AnimatePresence, motion, useReducedMotion } from \"motion/react\";\nimport { type KeyboardEvent, useEffect, useId, useMemo, useRef, useState } from \"react\";\nimport { Button } from \"@/components/ui/button\";\nimport { cn } from \"@/lib/utils\";\n\nexport interface PromptTemplate {\n  id: string;\n  title: string;\n  icon?: LucideIcon;\n  template: string;\n}\n\nexport interface FillInPromptsProps {\n  templates?: PromptTemplate[];\n  onUse?: (prompt: string, values: Record<string, string>) => void;\n  className?: string;\n}\n\nconst defaultTemplates: PromptTemplate[] = [\n  {\n    id: \"email\",\n    title: \"Cold email\",\n    icon: MailIcon,\n    template:\n      \"Write a {tone:warm|direct|playful} email to {name} at {company} about {topic}, under {count:80|120|200} words.\",\n  },\n  {\n    id: \"bug\",\n    title: \"Bug report\",\n    icon: BugIcon,\n    template:\n      \"Turn this into a bug report for {team:web|mobile|platform}: when I {action}, I expected {expected} but got {actual}.\",\n  },\n  {\n    id: \"recap\",\n    title: \"Meeting recap\",\n    icon: NotebookPenIcon,\n    template: \"Summarise my notes from the {meeting} into {count:3|5|7} decisions and owners, in a {tone:crisp|friendly} tone.\",\n  },\n];\n\ntype Part = { kind: \"text\"; text: string } | { kind: \"var\"; name: string; options: string[]; slot: number };\n\nfunction parse(template: string): Part[] {\n  const parts: Part[] = [];\n  const re = /\\{([\\w ]+?)(?::([^}]+))?\\}/g;\n  let last = 0;\n  let slot = 0;\n  for (const m of template.matchAll(re)) {\n    const at = m.index ?? 0;\n    if (at > last) parts.push({ kind: \"text\", text: template.slice(last, at) });\n    parts.push({ kind: \"var\", name: m[1] ?? \"\", options: m[2] ? m[2].split(\"|\") : [], slot: slot++ });\n    last = at + m[0].length;\n  }\n  if (last < template.length) parts.push({ kind: \"text\", text: template.slice(last) });\n  return parts;\n}\n\nconst tones = [\n  { chip: \"bg-violet-500/15\", dot: \"bg-violet-500\" },\n  { chip: \"bg-sky-500/15\", dot: \"bg-sky-500\" },\n  { chip: \"bg-amber-500/20\", dot: \"bg-amber-500\" },\n  { chip: \"bg-emerald-500/15\", dot: \"bg-emerald-500\" },\n  { chip: \"bg-rose-500/15\", dot: \"bg-rose-500\" },\n] as const;\nconst toneOf = (slot: number) => tones[slot % tones.length] ?? tones[0];\nconst spring = { type: \"spring\", stiffness: 460, damping: 36 } as const;\nconst easeOut = [0.23, 1, 0.32, 1] as const;\nconst press = \"transition-[background-color,color,border-color,scale] duration-150 ease-out active:scale-[0.97]\";\nconst blank = \"rounded-md border px-1.5 font-medium leading-7\";\n\ntype Piece = { kind: \"text\"; text: string } | { kind: \"var\"; part: Extract<Part, { kind: \"var\" }>; trail: string };\nfunction pieces(parts: Part[]): Piece[] {\n  const out: Piece[] = [];\n  for (const p of parts) {\n    const prev = out.at(-1);\n    if (p.kind === \"text\" && prev?.kind === \"var\") {\n      const m = /^[.,;:!?]+/.exec(p.text);\n      if (m) {\n        prev.trail = m[0];\n        const rest = p.text.slice(m[0].length);\n        if (rest) out.push({ kind: \"text\", text: rest });\n        continue;\n      }\n    }\n    out.push(p.kind === \"text\" ? p : { kind: \"var\", part: p, trail: \"\" });\n  }\n  return out;\n}\n\nexport function FillInPrompts({ templates = defaultTemplates, onUse, className }: FillInPromptsProps) {\n  const reduce = useReducedMotion();\n  const uid = useId();\n  const [activeId, setActiveId] = useState(templates[0]?.id ?? \"\");\n  const [values, setValues] = useState<Record<string, Record<string, string>>>({});\n  const [focused, setFocused] = useState<string | null>(null);\n  const [used, setUsed] = useState(false);\n  const inputs = useRef<(HTMLInputElement | null)[]>([]);\n  const usedTimer = useRef<ReturnType<typeof setTimeout> | undefined>(undefined);\n  useEffect(() => () => clearTimeout(usedTimer.current), []);\n\n  const active = templates.find((t) => t.id === activeId) ?? templates[0];\n  const parts = useMemo(() => parse(active?.template ?? \"\"), [active]);\n  const vars = parts.filter((p): p is Extract<Part, { kind: \"var\" }> => p.kind === \"var\");\n  const current = values[activeId] ?? {};\n  const filled = vars.filter((v) => current[v.name]?.trim()).length;\n  const ready = vars.length > 0 && filled === vars.length;\n  const focusedVar = vars.find((v) => v.name === focused);\n  inputs.current.length = vars.length;\n\n  const set = (name: string, value: string) =>\n    setValues((all) => ({ ...all, [activeId]: { ...(all[activeId] ?? {}), [name]: value } }));\n\n  const assembled = parts\n    .map((p) => (p.kind === \"text\" ? p.text : current[p.name]?.trim() || `{${p.name}}`))\n    .join(\"\");\n\n  const onKey = (e: KeyboardEvent<HTMLInputElement>, slot: number) => {\n    if (e.key === \"Enter\") {\n      e.preventDefault();\n      const next = inputs.current[slot + 1];\n      if (next) next.focus();\n      else if (ready) use();\n    }\n  };\n\n  const use = () => {\n    if (!ready) return;\n    onUse?.(assembled, current);\n    setUsed(true);\n    clearTimeout(usedTimer.current);\n    usedTimer.current = setTimeout(() => setUsed(false), 1600);\n  };\n\n  return (\n    <div className={cn(\"w-full max-w-lg rounded-2xl border bg-card text-sm shadow-xs/5\", className)}>\n      <div className=\"flex items-center gap-1 overflow-x-auto border-b p-1.5 [scrollbar-width:none]\" role=\"tablist\">\n        {templates.map((t) => {\n          const on = t.id === activeId;\n          const Icon = t.icon;\n          return (\n            <button\n              aria-selected={on}\n              className={cn(\n                \"relative flex h-8 shrink-0 cursor-pointer items-center gap-1.5 rounded-lg px-2.5 text-xs outline-none focus-visible:ring-2 focus-visible:ring-ring\",\n                press,\n                on ? \"text-foreground\" : \"text-muted-foreground hover:text-foreground\",\n              )}\n              key={t.id}\n              onClick={() => {\n                setActiveId(t.id);\n                setFocused(null);\n                setUsed(false);\n              }}\n              role=\"tab\"\n              type=\"button\"\n            >\n              {on && (\n                <motion.span\n                  className=\"absolute inset-0 rounded-lg bg-accent\"\n                  layoutId={`${uid}-tab`}\n                  transition={reduce ? { duration: 0 } : spring}\n                />\n              )}\n              {Icon && <Icon className=\"relative size-3.5\" />}\n              <span className=\"relative font-medium\">{t.title}</span>\n            </button>\n          );\n        })}\n      </div>\n\n      <div className=\"grid *:col-start-1 *:row-start-1\">\n        {templates.map((t) => (\n          <p aria-hidden className=\"invisible mb-10 px-4 pt-4 text-[15px] leading-9\" key={t.id}>\n            {pieces(parse(t.template)).map((p, i) =>\n              p.kind === \"text\" ? (\n                <span key={i}>{p.text}</span>\n              ) : (\n                <span className=\"whitespace-nowrap\" key={i}>\n                  <span className={cn(blank, \"inline-block\")}>{p.part.name}</span>\n                  {p.trail}\n                </span>\n              ),\n            )}\n          </p>\n        ))}\n      <AnimatePresence initial={false} mode=\"wait\">\n        <motion.div\n          animate={{ opacity: 1, y: 0 }}\n          exit={{ opacity: 0, y: -4, transition: { duration: 0.1 } }}\n          initial={reduce ? false : { opacity: 0, y: 4 }}\n          key={activeId}\n          role=\"tabpanel\"\n          transition={{ duration: 0.18, ease: easeOut }}\n        >\n          <p className=\"px-4 pt-4 text-[15px] text-foreground leading-9\">\n            {pieces(parts).map((piece, i) =>\n              piece.kind === \"text\" ? (\n                <span key={i}>{piece.text}</span>\n              ) : (\n                <span className=\"whitespace-nowrap\" key={`${activeId}-${piece.part.name}`}>\n                <InlineVar\n                  inputRef={(el) => {\n                    inputs.current[piece.part.slot] = el;\n                  }}\n                  name={piece.part.name}\n                  onBlur={() => setFocused((f) => (f === piece.part.name ? null : f))}\n                  onChange={(v) => set(piece.part.name, v)}\n                  onFocus={() => setFocused(piece.part.name)}\n                  onKeyDown={(e) => onKey(e, piece.part.slot)}\n                  slot={piece.part.slot}\n                  value={current[piece.part.name] ?? \"\"}\n                />\n                {piece.trail}\n                </span>\n              ),\n            )}\n          </p>\n\n          <div className=\"h-10 px-4 pt-2\">\n            <AnimatePresence initial={false} mode=\"popLayout\">\n              {focusedVar && focusedVar.options.length > 0 ? (\n                <motion.div\n                  animate={{ opacity: 1, y: 0 }}\n                  className=\"flex items-center gap-1.5\"\n                  exit={{ opacity: 0, y: -4, transition: { duration: 0.1 } }}\n                  initial={reduce ? { opacity: 0 } : { opacity: 0, y: 4 }}\n                  key={focusedVar.name}\n                  transition={{ duration: 0.18, ease: easeOut }}\n                >\n                  <span className=\"text-muted-foreground text-xs\">Try</span>\n                  {focusedVar.options.map((o) => (\n                    <button\n                      className={cn(\n                        \"relative h-6 cursor-pointer rounded-full border px-2 text-xs outline-none after:absolute after:-inset-1 hover:bg-accent focus-visible:ring-2 focus-visible:ring-ring\",\n                        press,\n                        current[focusedVar.name] === o && \"border-transparent bg-accent\",\n                      )}\n                      key={o}\n                      onClick={() => {\n                        set(focusedVar.name, o);\n                        inputs.current[focusedVar.slot + 1]?.focus();\n                      }}\n                      onMouseDown={(e) => e.preventDefault()}\n                      type=\"button\"\n                    >\n                      {o}\n                    </button>\n                  ))}\n                </motion.div>\n              ) : (\n                <motion.p\n                  animate={{ opacity: 1, y: 0 }}\n                  className=\"text-muted-foreground text-xs leading-6\"\n                  exit={{ opacity: 0, y: -4, transition: { duration: 0.1 } }}\n                  initial={reduce ? { opacity: 0 } : { opacity: 0, y: 4 }}\n                  key=\"hint\"\n                  transition={{ duration: 0.18, ease: easeOut }}\n                >\n                  {ready ? \"All blanks filled. Ready to use.\" : \"Type into the blanks. Enter jumps to the next one.\"}\n                </motion.p>\n              )}\n            </AnimatePresence>\n          </div>\n\n        </motion.div>\n      </AnimatePresence>\n      </div>\n\n      <div className=\"mt-2 flex items-center gap-3 border-t px-4 py-3\">\n        <div aria-label={`${filled} of ${vars.length} filled`} className=\"flex items-center gap-1\" role=\"img\">\n          {vars.map((v) => (\n            <motion.span\n              animate={{ width: current[v.name]?.trim() ? 16 : 6 }}\n              className={cn(\n                \"h-1.5 rounded-full transition-colors duration-300\",\n                current[v.name]?.trim() ? toneOf(v.slot).dot : \"bg-muted-foreground/25\",\n              )}\n              initial={false}\n              key={`${activeId}-${v.name}`}\n              transition={spring}\n            />\n          ))}\n        </div>\n        <span className=\"text-muted-foreground text-xs tabular-nums\">\n          {filled}/{vars.length}\n        </span>\n        <AnimatePresence initial={false}>\n          {filled > 0 && (\n            <motion.button\n              animate={{ opacity: 1 }}\n              className={cn(\n                \"inline-flex h-7 cursor-pointer items-center gap-1 rounded-md px-1.5 text-muted-foreground text-xs outline-none hover:bg-accent hover:text-foreground focus-visible:ring-2 focus-visible:ring-ring\",\n                press,\n              )}\n              exit={{ opacity: 0, transition: { duration: 0.1 } }}\n              initial={{ opacity: 0 }}\n              transition={{ duration: 0.15 }}\n              onClick={() => setValues((all) => ({ ...all, [activeId]: {} }))}\n              type=\"button\"\n            >\n              <RotateCcwIcon className=\"size-3\" />\n              Clear\n            </motion.button>\n          )}\n        </AnimatePresence>\n        <Button\n          className=\"ms-auto overflow-hidden rounded-full transition-[box-shadow,opacity,scale] duration-150 ease-out before:rounded-full active:scale-[0.97]\"\n          disabled={!ready}\n          onClick={use}\n          size=\"sm\"\n        >\n          <AnimatePresence initial={false} mode=\"popLayout\">\n            <motion.span\n              animate={{ y: 0, opacity: 1 }}\n              className=\"inline-flex items-center gap-1.5\"\n              exit={reduce ? { opacity: 0 } : { y: -14, opacity: 0 }}\n              initial={reduce ? { opacity: 0 } : { y: 14, opacity: 0 }}\n              key={used ? \"used\" : \"use\"}\n              transition={{ duration: 0.22, ease: easeOut }}\n            >\n              {used ? (\n                <>\n                  <CheckIcon className=\"size-3.5\" />\n                  Added\n                </>\n              ) : (\n                <>\n                  Use prompt\n                  <ArrowRightIcon className=\"size-3.5\" />\n                </>\n              )}\n            </motion.span>\n          </AnimatePresence>\n        </Button>\n      </div>\n    </div>\n  );\n}\n\nfunction InlineVar({\n  name,\n  value,\n  slot,\n  onChange,\n  onFocus,\n  onBlur,\n  onKeyDown,\n  inputRef,\n}: {\n  name: string;\n  value: string;\n  slot: number;\n  onChange: (v: string) => void;\n  onFocus: () => void;\n  onBlur: () => void;\n  onKeyDown: (e: KeyboardEvent<HTMLInputElement>) => void;\n  inputRef: (el: HTMLInputElement | null) => void;\n}) {\n  const filled = value.trim().length > 0;\n  const tone = toneOf(slot);\n  return (\n    <span\n      className={cn(\n        \"relative inline-grid rounded-md border align-baseline leading-7 transition-[background-color,border-color,box-shadow] duration-150 focus-within:border-ring focus-within:ring-2 focus-within:ring-ring/20\",\n        filled ? cn(tone.chip, \"border-transparent\") : \"border-muted-foreground/35 border-dashed\",\n      )}\n    >\n      <span aria-hidden className=\"invisible col-start-1 row-start-1 whitespace-pre px-1.5 font-medium\">\n        {value || name}\n      </span>\n      <input\n        aria-label={name}\n        autoComplete=\"off\"\n        className=\"col-start-1 row-start-1 w-full min-w-0 bg-transparent px-1.5 font-medium text-foreground outline-none placeholder:font-normal placeholder:text-muted-foreground\"\n        onBlur={onBlur}\n        onChange={(e) => onChange(e.target.value)}\n        onFocus={onFocus}\n        onKeyDown={onKeyDown}\n        placeholder={name}\n        ref={inputRef}\n        size={1}\n        spellCheck={false}\n        value={value}\n      />\n    </span>\n  );\n}\n"
    }
  ]
}