{
  "$schema": "https://ui.shadcn.com/schema/registry-item.json",
  "name": "margin-notes-panel",
  "title": "Margin Notes Panel",
  "description": "A document with anchored margin notes, section highlighting, contextual replies and open/resolved note workflows.",
  "dependencies": [
    "lucide-react",
    "clsx",
    "tailwind-merge"
  ],
  "files": [
    {
      "path": "registry/new-york/margin-notes-panel/margin-notes-panel.tsx",
      "content": "\"use client\";\n\nimport * as React from \"react\";\nimport { Layers, Plus, FileText, MessageSquare, Check } from \"lucide-react\";\nimport { clsx } from \"clsx\";\nimport { twMerge } from \"tailwind-merge\";\n\nfunction Frame({\n  name,\n  title,\n  description,\n  theme,\n  className,\n  toolbar,\n  sidebar,\n  children,\n}: {\n  name: string;\n  title: string;\n  description: string;\n  theme: \"dark\" | \"light\";\n  className?: string;\n  toolbar?: React.ReactNode;\n  sidebar?: React.ReactNode;\n  children: React.ReactNode;\n}) {\n  const dark = theme === \"dark\";\n  return (\n    <section\n      aria-label={name}\n      className={twMerge(\n        clsx(\n          \"mx-auto w-full max-w-[1100px] overflow-hidden rounded-xl border font-sans antialiased shadow-[0_12px_60px_#00000012]\",\n          className,\n        ),\n      )}\n      style={\n        {\n          background: dark ? \"#151517\" : \"#fff\",\n          color: dark ? \"#e9e9ed\" : \"#28282d\",\n          borderColor: dark ? \"#ffffff14\" : \"#18181b18\",\n          \"--board-panel\": dark ? \"#1b1b1f\" : \"#fafafa\",\n          \"--board-canvas\": dark ? \"#151517\" : \"#ffffff\",\n          \"--board-input\": dark ? \"#242428\" : \"#f1f1f3\",\n          \"--board-accent\": dark ? \"#aaa1ee\" : \"#6854b5\",\n        } as React.CSSProperties\n      }\n    >\n      <header className=\"flex h-12 items-center justify-between gap-3 border-b border-current/[0.07] px-4 text-[11px]\">\n        <div className=\"flex items-center gap-2\">\n          <span className=\"flex size-5 items-center justify-center rounded bg-[#6e67d4] text-[10px] font-semibold text-white\">\n            a\n          </span>\n          <span className=\"font-medium\">Acme</span>\n          <span className=\"px-2 opacity-20\">/</span>\n          <Layers size={12} className=\"opacity-45\" />\n          <span className=\"opacity-65\">{name}</span>\n        </div>\n        <div className=\"flex items-center gap-2\">\n          <span className=\"hidden text-[10px] opacity-35 sm:block\">\n            Product workspace\n          </span>\n          <span className=\"flex size-5 items-center justify-center rounded-full bg-current/5 text-[8px] opacity-60\">\n            AL\n          </span>\n        </div>\n      </header>\n      <div\n        className={\n          sidebar\n            ? \"grid min-w-0 md:grid-cols-[184px_minmax(0,1fr)]\"\n            : \"min-w-0\"\n        }\n      >\n        {sidebar && (\n          <aside className=\"border-b border-current/[0.07] bg-black/[0.025] px-3 py-4 md:border-b-0 md:border-r\">\n            {sidebar}\n          </aside>\n        )}\n        <div className=\"min-w-0\">\n          <div className=\"px-5 pb-4 pt-5 sm:px-7\">\n            <h2 className=\"text-[17px] font-semibold tracking-[-0.025em]\">\n              {title}\n            </h2>\n            <p className=\"mt-1 text-[11px] leading-relaxed opacity-45\">\n              {description}\n            </p>\n          </div>\n          {toolbar && (\n            <div className=\"flex flex-wrap items-center justify-between gap-2 border-b border-current/[0.07] px-5 pb-3 sm:px-7\">\n              {toolbar}\n            </div>\n          )}\n          {children}\n        </div>\n      </div>\n    </section>\n  );\n}\nconst button =\n  \"inline-flex items-center justify-center gap-1.5 rounded-md border border-current/10 px-2.5 py-1.5 text-[11px] transition-colors hover:bg-current/5 focus-visible:outline-2 focus-visible:outline-offset-2 disabled:cursor-not-allowed disabled:opacity-25\";\nconst primary =\n  \"inline-flex items-center justify-center gap-1.5 rounded-md border border-white/15 bg-[#6e67d4] px-3 py-1.5 text-[11px] font-medium text-white hover:bg-[#7a73df] disabled:cursor-not-allowed disabled:opacity-40 focus-visible:outline-2 focus-visible:outline-offset-2\";\nconst input =\n  \"min-w-0 rounded-md border border-current/10 bg-[var(--board-input)] px-3 py-2 text-xs outline-none focus:border-[#9690da]\";\n\nfunction Avatar({ name, color = \"#9690da\" }: { name: string; color?: string }) {\n  return (\n    <span\n      aria-hidden=\"true\"\n      className=\"flex size-7 shrink-0 items-center justify-center rounded-md border text-[9px] font-medium\"\n      style={{ color, background: `${color}18`, borderColor: `${color}20` }}\n    >\n      {name\n        .split(\" \")\n        .map((part) => part[0])\n        .slice(0, 2)\n        .join(\"\")}\n    </span>\n  );\n}\n\nexport interface MarginSection {\n  id: string;\n  title: string;\n  text: string;\n}\nexport interface MarginReply {\n  id: string;\n  author: string;\n  text: string;\n}\nexport interface MarginNote {\n  id: string;\n  sectionId: string;\n  author: string;\n  text: string;\n  resolved?: boolean;\n  replies?: MarginReply[];\n}\nexport interface MarginNotesPanelProps {\n  title?: string;\n  theme?: \"dark\" | \"light\";\n  sections?: MarginSection[];\n  initialNotes?: MarginNote[];\n  onNotesChange?: (notes: MarginNote[]) => void;\n  currentUser?: string;\n  className?: string;\n}\nconst document: MarginSection[] = [\n  {\n    id: \"intent\",\n    title: \"01 / The intent\",\n    text: \"We want the first session to feel like an invitation, not a checklist. A new workspace should offer a clear next step while leaving room for people to make it their own.\",\n  },\n  {\n    id: \"principles\",\n    title: \"02 / A quieter foundation\",\n    text: \"Let content lead. Keep secondary controls in the background, use color with intention, and make the path through the product easy to understand. Every interaction should reduce uncertainty.\",\n  },\n  {\n    id: \"scope\",\n    title: \"03 / Start with the essential\",\n    text: \"The first release focuses on shared project spaces, a simpler navigation model and one place for decisions. Everything else can earn its place through what we learn.\",\n  },\n  {\n    id: \"success\",\n    title: \"04 / What progress looks like\",\n    text: \"A person can create a project, invite a teammate and find their way back without needing instructions. Measure completion, but listen closely to the moments where people hesitate.\",\n  },\n];\nconst seed: MarginNote[] = [\n  {\n    id: \"n1\",\n    sectionId: \"intent\",\n    author: \"Sofia Kim\",\n    text: \"This is the right starting point. Can we make the invitation more specific for someone joining an existing team?\",\n    replies: [\n      {\n        id: \"r1\",\n        author: \"Maya Chen\",\n        text: \"Yes. A small team context card could help.\",\n      },\n    ],\n  },\n  {\n    id: \"n2\",\n    sectionId: \"scope\",\n    author: \"James Davis\",\n    text: \"Let's define the smallest useful version of shared spaces before we estimate the work.\",\n    replies: [],\n  },\n  {\n    id: \"n3\",\n    sectionId: \"principles\",\n    author: \"Alex Lee\",\n    text: \"The revised navigation follows these principles. Ready for the next review.\",\n    resolved: true,\n    replies: [],\n  },\n];\nexport function MarginNotesPanel({\n  title = \"Workspace direction\",\n  theme = \"dark\",\n  sections = document,\n  initialNotes = seed,\n  onNotesChange,\n  currentUser = \"You\",\n  className,\n}: MarginNotesPanelProps) {\n  const [notes, setNotes] = React.useState<MarginNote[]>(() =>\n    initialNotes.map((note) => ({\n      ...note,\n      replies: note.replies?.map((reply) => ({ ...reply })),\n    })),\n  );\n  const [filter, setFilter] = React.useState(\"Open\");\n  const [sectionId, setSectionId] = React.useState<string | null>(null);\n  const [selected, setSelected] = React.useState<string | null>(null);\n  const [adding, setAdding] = React.useState(false);\n  const [anchor, setAnchor] = React.useState(sections[0]?.id ?? \"\");\n  const [draft, setDraft] = React.useState(\"\");\n  const [replyTo, setReplyTo] = React.useState<string | null>(null);\n  const [reply, setReply] = React.useState(\"\");\n  const current = React.useRef(notes);\n  const refs = React.useRef(new Map<string, HTMLElement>());\n  const update = (next: MarginNote[]) => {\n    current.current = next;\n    setNotes(next);\n    onNotesChange?.(next);\n  };\n  const patch = (id: string, values: Partial<MarginNote>) =>\n    update(\n      current.current.map((note) =>\n        note.id === id ? { ...note, ...values } : note,\n      ),\n    );\n  const visible = notes.filter(\n    (note) =>\n      (!sectionId || note.sectionId === sectionId) &&\n      (filter === \"All\" ||\n        (filter === \"Open\" ? !note.resolved : note.resolved)),\n  );\n  const focusNote = (note: MarginNote) => {\n    setSelected(selected === note.id ? null : note.id);\n    refs.current.get(note.sectionId)?.scrollIntoView({\n      block: \"nearest\",\n      behavior: window.matchMedia(\"(prefers-reduced-motion: reduce)\").matches\n        ? \"instant\"\n        : \"smooth\",\n    });\n  };\n  const begin = (id: string) => {\n    setAnchor(id);\n    setAdding(true);\n    setSectionId(id);\n    setFilter(\"Open\");\n    setDraft(\"\");\n  };\n  return (\n    <Frame\n      name=\"Document notes\"\n      title={title}\n      description=\"Product / Documents · A shared direction for Workspace v2\"\n      theme={theme}\n      className={className}\n      toolbar={\n        <>\n          <div className=\"flex items-center gap-2 text-[10px]\">\n            <FileText size={13} className=\"opacity-45\" />\n            <span>Workspace direction</span>\n            <span className=\"rounded border border-current/10 px-1.5 py-0.5 opacity-40\">\n              Draft\n            </span>\n          </div>\n          <button\n            className={primary}\n            disabled={!sections.length}\n            onClick={() => begin(sectionId ?? sections[0].id)}\n          >\n            <Plus size={12} /> Add margin note\n          </button>\n        </>\n      }\n    >\n      <div className=\"grid bg-[var(--board-canvas)] lg:grid-cols-[minmax(0,1fr)_308px]\">\n        <div className=\"px-6 py-9 sm:px-10\">\n          <div className=\"mb-7 border-b border-current/[0.07] pb-5\">\n            <p className=\"text-[9px] tracking-[0.12em] opacity-30\">\n              PRODUCT / DIRECTION\n            </p>\n            <h3 className=\"mt-3 text-[25px] font-semibold leading-tight tracking-[-0.035em]\">\n              A workspace that gets out of the way.\n            </h3>\n            <p className=\"mt-2 text-[10px] opacity-35\">\n              A working document · Open for discussion\n            </p>\n          </div>\n          <div className=\"space-y-9\">\n            {sections.map((section) => {\n              const count = notes.filter(\n                (note) => note.sectionId === section.id && !note.resolved,\n              ).length;\n              const highlighted =\n                notes.find((note) => note.id === selected)?.sectionId ===\n                  section.id || sectionId === section.id;\n              return (\n                <article\n                  key={section.id}\n                  ref={(element) => {\n                    if (element) refs.current.set(section.id, element);\n                    else refs.current.delete(section.id);\n                  }}\n                  className=\"scroll-mt-5 border-l-2 pl-4 transition-colors\"\n                  style={{\n                    borderColor: highlighted ? \"#9690da\" : \"transparent\",\n                  }}\n                >\n                  <div className=\"flex items-center justify-between gap-3\">\n                    <button\n                      aria-label={`Show notes for ${section.title}`}\n                      aria-pressed={sectionId === section.id}\n                      className=\"text-left text-[11px] font-medium\"\n                      onClick={() => {\n                        setSectionId(section.id);\n                        setFilter(\"All\");\n                      }}\n                    >\n                      {section.title}\n                    </button>\n                    <button\n                      aria-label={`Add note to ${section.title}`}\n                      onClick={() => begin(section.id)}\n                      className=\"flex items-center gap-1 rounded border border-current/10 px-1.5 py-1 text-[9px] text-[var(--board-accent)]\"\n                    >\n                      <MessageSquare size={11} />\n                      {count || \"+\"}\n                    </button>\n                  </div>\n                  <p className=\"mt-3 text-[13px] leading-[1.9] opacity-65\">\n                    {section.text}\n                  </p>\n                </article>\n              );\n            })}\n            {!sections.length && (\n              <p className=\"text-xs opacity-40\">\n                Add document sections to start annotating.\n              </p>\n            )}\n          </div>\n        </div>\n        <aside\n          aria-label=\"Margin notes\"\n          className=\"border-t border-current/[0.07] bg-[var(--board-panel)] lg:border-l lg:border-t-0\"\n        >\n          <div className=\"border-b border-current/[0.07] p-4\">\n            <div className=\"mb-3 flex items-center justify-between\">\n              <h3 className=\"text-xs font-medium\">\n                Margin notes{\" \"}\n                <span className=\"ml-1 text-[10px] opacity-35\">\n                  {notes.length}\n                </span>\n              </h3>\n              {sectionId && (\n                <button\n                  className=\"text-[9px] text-[var(--board-accent)]\"\n                  onClick={() => {\n                    setSectionId(null);\n                    setSelected(null);\n                  }}\n                >\n                  All sections\n                </button>\n              )}\n            </div>\n            <div role=\"group\" aria-label=\"Note status\" className=\"flex gap-1\">\n              {[\"Open\", \"Resolved\", \"All\"].map((value) => (\n                <button\n                  key={value}\n                  className={button}\n                  aria-pressed={filter === value}\n                  onClick={() => setFilter(value)}\n                  style={{\n                    background:\n                      filter === value ? \"var(--board-input)\" : undefined,\n                  }}\n                >\n                  {value}\n                </button>\n              ))}\n            </div>\n            {sectionId && (\n              <p className=\"mt-3 text-[9px] opacity-35\">\n                {sections.find((section) => section.id === sectionId)?.title ??\n                  \"Unknown section\"}\n              </p>\n            )}\n          </div>\n          {adding && (\n            <form\n              className=\"space-y-2 border-b border-current/10 p-4\"\n              onSubmit={(event) => {\n                event.preventDefault();\n                if (\n                  !draft.trim() ||\n                  !sections.some((section) => section.id === anchor)\n                )\n                  return;\n                const id = crypto.randomUUID();\n                update([\n                  ...current.current,\n                  {\n                    id,\n                    sectionId: anchor,\n                    author: currentUser,\n                    text: draft.trim(),\n                    replies: [],\n                  },\n                ]);\n                setSelected(id);\n                setSectionId(anchor);\n                setFilter(\"Open\");\n                setAdding(false);\n                setDraft(\"\");\n              }}\n            >\n              <select\n                aria-label=\"Note anchor\"\n                className={input + \" w-full\"}\n                value={anchor}\n                onChange={(event) => setAnchor(event.target.value)}\n              >\n                {sections.map((section) => (\n                  <option key={section.id} value={section.id}>\n                    {section.title}\n                  </option>\n                ))}\n              </select>\n              <textarea\n                aria-label=\"Margin note text\"\n                className={input + \" min-h-20 w-full resize-y\"}\n                required\n                maxLength={1000}\n                placeholder=\"A thought on this section…\"\n                value={draft}\n                onChange={(event) => setDraft(event.target.value)}\n              />\n              <div className=\"flex gap-2\">\n                <button className={primary} type=\"submit\">\n                  Post note\n                </button>\n                <button\n                  className={button}\n                  type=\"button\"\n                  onClick={() => setAdding(false)}\n                >\n                  Cancel\n                </button>\n              </div>\n            </form>\n          )}\n          <div className=\"max-h-[690px] divide-y divide-current/[0.07] overflow-y-auto px-4\">\n            {visible.map((note) => (\n              <article\n                key={note.id}\n                className=\"border-l-2 px-3 py-5\"\n                style={{\n                  borderColor: selected === note.id ? \"#9690da\" : \"transparent\",\n                  background: selected === note.id ? \"#9690da07\" : undefined,\n                }}\n              >\n                <button\n                  aria-label={`Locate note by ${note.author}`}\n                  aria-pressed={selected === note.id}\n                  className=\"mb-3 block w-full rounded bg-current/[0.025] px-2 py-2 text-left text-[9px] text-[var(--board-accent)]\"\n                  onClick={() => focusNote(note)}\n                >\n                  {sections.find((section) => section.id === note.sectionId)\n                    ?.title ?? \"Unlinked section\"}\n                </button>\n                <div className=\"flex items-center gap-2\">\n                  <Avatar name={note.author} />\n                  <span className=\"text-[10px] font-medium\">{note.author}</span>\n                  <button\n                    aria-label={`${note.resolved ? \"Reopen\" : \"Resolve\"} note by ${note.author}`}\n                    aria-pressed={Boolean(note.resolved)}\n                    className=\"ml-auto rounded border border-current/10 p-1\"\n                    style={{ color: note.resolved ? \"#79a798\" : undefined }}\n                    onClick={() => patch(note.id, { resolved: !note.resolved })}\n                  >\n                    <Check size={12} />\n                  </button>\n                </div>\n                <p className=\"mt-3 whitespace-pre-wrap break-words text-[11px] leading-relaxed opacity-70\">\n                  {note.text}\n                </p>\n                {(note.replies ?? []).map((message) => (\n                  <div\n                    key={message.id}\n                    className=\"mt-3 border-l border-current/10 pl-3\"\n                  >\n                    <p className=\"text-[9px] font-medium opacity-60\">\n                      {message.author}\n                    </p>\n                    <p className=\"mt-1 whitespace-pre-wrap break-words text-[10px] leading-relaxed opacity-50\">\n                      {message.text}\n                    </p>\n                  </div>\n                ))}\n                {replyTo === note.id ? (\n                  <form\n                    className=\"mt-3 space-y-2\"\n                    onSubmit={(event) => {\n                      event.preventDefault();\n                      if (!reply.trim()) return;\n                      patch(note.id, {\n                        replies: [\n                          ...(note.replies ?? []),\n                          {\n                            id: crypto.randomUUID(),\n                            author: currentUser,\n                            text: reply.trim(),\n                          },\n                        ],\n                      });\n                      setReplyTo(null);\n                      setReply(\"\");\n                    }}\n                  >\n                    <textarea\n                      aria-label=\"Note reply\"\n                      className={input + \" w-full resize-y\"}\n                      required\n                      maxLength={1000}\n                      placeholder=\"Add context…\"\n                      value={reply}\n                      onChange={(event) => setReply(event.target.value)}\n                    />\n                    <div className=\"flex gap-2\">\n                      <button type=\"submit\" className={primary}>\n                        Send reply\n                      </button>\n                      <button\n                        type=\"button\"\n                        className={button}\n                        onClick={() => setReplyTo(null)}\n                      >\n                        Cancel\n                      </button>\n                    </div>\n                  </form>\n                ) : (\n                  <div className=\"mt-3 flex items-center gap-3\">\n                    <button\n                      disabled={note.resolved}\n                      className=\"text-[9px] opacity-45 disabled:opacity-20\"\n                      onClick={() => {\n                        setReplyTo(note.id);\n                        setReply(\"\");\n                      }}\n                    >\n                      Reply to note\n                    </button>\n                    {note.author === currentUser && (\n                      <button\n                        className=\"text-[9px] opacity-35\"\n                        onClick={() => {\n                          update(\n                            current.current.filter(\n                              (item) => item.id !== note.id,\n                            ),\n                          );\n                          if (selected === note.id) setSelected(null);\n                        }}\n                      >\n                        Delete note\n                      </button>\n                    )}\n                  </div>\n                )}\n              </article>\n            ))}\n            {!visible.length && (\n              <p className=\"py-8 text-center text-[11px] opacity-35\">\n                No {filter === \"All\" ? \"\" : filter.toLowerCase() + \" \"}notes in\n                this view.\n              </p>\n            )}\n          </div>\n        </aside>\n      </div>\n      <footer\n        role=\"status\"\n        className=\"flex flex-wrap justify-between gap-2 border-t border-current/[0.07] px-5 py-3 text-[10px] opacity-40\"\n      >\n        <span>\n          {notes.filter((note) => !note.resolved).length} open ·{\" \"}\n          {notes.filter((note) => note.resolved).length} resolved\n        </span>\n        <span>Context belongs beside the work.</span>\n      </footer>\n    </Frame>\n  );\n}\nexport default MarginNotesPanel;\n",
      "type": "registry:component"
    }
  ],
  "type": "registry:component"
}