{
  "$schema": "https://ui.shadcn.com/schema/registry-item.json",
  "name": "inline-edit-demo",
  "title": "Inline Edit Demo",
  "description": "A worked example of Inline Edit: Select a span of a document, say how it should change, and watch the replacement stream in beside the struck-out original. Nothing changes until you accept it.",
  "registryDependencies": [
    "https://ui.tinkererslabs.com/r/inline-edit.json"
  ],
  "files": [
    {
      "path": "components/demos/inline-edit-demo.tsx",
      "content": "\"use client\"\n\nimport * as React from \"react\"\n\nimport {\n  InlineEdit,\n  type InlineEditRequest,\n} from \"@/registry/default/inline-edit/inline-edit\"\n\nconst initial =\n  \"We just wanted to let you know that exports were actually failing for some workspaces between 09:00 and 11:30 UTC on Tuesday. It was really caused by a timeout in the step that zips large files. We have raised the limit and run every failed export again, so you do not need to do anything. If a download still looks incomplete, reply to this email and we will look at it.\"\n\nconst prepared: Record<string, string> = {\n  \"We just wanted to let you know that exports were actually failing for some workspaces between 09:00 and 11:30 UTC on Tuesday.\":\n    \"Between 09:00 and 11:30 UTC on Tuesday, exports failed for some workspaces.\",\n  \"It was really caused by a timeout in the step that zips large files.\":\n    \"A timeout in the step that zips large files caused it.\",\n}\n\nconst filler = /\\b(just|actually|really|very|simply)\\s+/gi\n\nfunction rewrite({ selection, instruction }: InlineEditRequest) {\n  const text = selection.text.trim()\n  const tightened = prepared[text] ?? text.replace(filler, \"\")\n\n  if (/upper|caps|shout/i.test(instruction)) return tightened.toUpperCase()\n  return tightened\n}\n\nasync function* streamRewrite(request: InlineEditRequest) {\n  const words = rewrite(request).split(/(?<=\\s)/)\n\n  for (const word of words) {\n    await new Promise((resolve) => setTimeout(resolve, 45))\n    if (request.signal.aborted) return\n    yield word\n  }\n}\n\nexport function InlineEditDemo() {\n  const [text, setText] = React.useState(initial)\n\n  return (\n    <div className=\"bg-background border-border grid w-full max-w-[36rem] gap-3 rounded-[1.25rem] border p-5 shadow-sm\">\n      <div className=\"flex items-baseline justify-between gap-3\">\n        <h3 className=\"text-sm font-semibold\">Incident note</h3>\n        <button\n          type=\"button\"\n          onClick={() => setText(initial)}\n          disabled={text === initial}\n          className=\"text-muted-foreground hover:text-foreground focus-visible:ring-ring rounded-md px-1.5 text-xs transition-colors focus-visible:ring-2 focus-visible:outline-none disabled:opacity-40 motion-reduce:transition-none\"\n        >\n          Reset\n        </button>\n      </div>\n\n      <InlineEdit\n        label=\"Incident note\"\n        onChange={setText}\n        onRequestEdit={streamRewrite}\n        value={text}\n      />\n\n      <p className=\"text-muted-foreground text-xs leading-relaxed\">\n        Select a sentence and ask for it to be tighter. The rewrites in this\n        example are prepared in the page; in an app, onRequestEdit streams them\n        from your model.\n      </p>\n    </div>\n  )\n}\n",
      "type": "registry:example"
    }
  ],
  "type": "registry:example"
}