npm package discovery and stats viewer.

Discover Tips

  • General search

    [free text search, go nuts!]

  • Package details

    pkg:[package-name]

  • User packages

    @[username]

Sponsor

Optimize Toolset

I’ve always been into building performant and accessible sites, but lately I’ve been taking it extremely seriously. So much so that I’ve been building a tool to help me optimize and monitor the sites that I build to make sure that I’m making an attempt to offer the best experience to those who visit them. If you’re into performant, accessible and SEO friendly sites, you might like it too! You can check it out at Optimize Toolset.

About

Hi, 👋, I’m Ryan Hefner  and I built this site for me, and you! The goal of this site was to provide an easy way for me to check the stats on my npm packages, both for prioritizing issues and updates, and to give me a little kick in the pants to keep up on stuff.

As I was building it, I realized that I was actually using the tool to build the tool, and figured I might as well put this out there and hopefully others will find it to be a fast and useful way to search and browse npm packages as I have.

If you’re interested in other things I’m working on, follow me on Twitter or check out the open source projects I’ve been publishing on GitHub.

I am also working on a Twitter bot for this site to tweet the most popular, newest, random packages from npm. Please follow that account now and it will start sending out packages soon–ish.

Open Software & Tools

This site wouldn’t be possible without the immense generosity and tireless efforts from the people who make contributions to the world and share their work via open source initiatives. Thank you 🙏

© 2025 – Pkg Stats / Ryan Hefner

next-ai-editor

v0.1.3

Published

AI-powered React component editor for Next.js - edit your components with natural language in development mode

Readme

Next AI Editor

AI-powered React component editor for Next.js - edit your components with natural language in development mode

Features

  • 🎯 Click-to-Edit: Click any component in your Next.js app to edit it with AI
  • 🤖 Natural Language: Describe changes in plain English - "make this button blue with rounded corners"
  • 🔍 Smart Detection: Automatically finds the exact component and element in your source code
  • 📍 Source Maps: Works with both Server Components and Client Components using Turbopack source maps
  • 🎨 Syntax Highlighting: Beautiful code preview with theme-aware syntax highlighting
  • 📝 Edit History: Track multiple edits in a session with undo support
  • 🔄 Live Reload: See changes immediately in your browser
  • 🛡️ Safe: Only works in development mode, restricted to your project directory

Installation

npm install next-ai-editor
# or
pnpm add next-ai-editor
# or
yarn add next-ai-editor

Setup

1. Environment Variables

Add your Anthropic API key to .env.local:

ANTHROPIC_API_KEY=sk-ant-api03-...

2. Wrap Your App

Wrap your root layout with the AIEditorProvider:

// app/layout.tsx
import { AIEditorProvider } from "next-ai-editor/client";

export default function RootLayout({
  children,
}: {
  children: React.ReactNode;
}) {
  return (
    <html lang="en">
      <body>
        <AIEditorProvider theme="dark">
          {children}
        </AIEditorProvider>
      </body>
    </html>
  );
}

3. Add API Route

Create a catch-all route handler for the AI editor API:

// app/api/ai-editor/[...path]/route.ts
import { handleAIEditorRequest } from "next-ai-editor/server";

export const GET = handleAIEditorRequest;
export const POST = handleAIEditorRequest;

Usage

  1. Enable AI Editor: Press Ctrl+Shift+E (or Cmd+Shift+E on Mac)
  2. Select Component: Hover over any component to see its source location
  3. Click to Edit: Click the component to open the editor modal
  4. Describe Changes: Type what you want to change (e.g., "make the background blue")
  5. Apply: Press Ctrl+Enter (or Cmd+Enter) or click "Apply Changes"
  6. Continue Editing: Make more edits to the same component, or click "Finish & Reload"

API Reference

Client

AIEditorProvider

Wraps your app to enable the AI editor.

import { AIEditorProvider } from "next-ai-editor/client";

<AIEditorProvider theme="dark" | "light">
  {children}
</AIEditorProvider>

Props:

  • theme?: "dark" | "light" - UI theme (default: "dark")
  • children: ReactNode - Your app content

Server

handleAIEditorRequest

Catch-all handler for all AI editor endpoints.

import { handleAIEditorRequest } from "next-ai-editor/server";

export const GET = handleAIEditorRequest;
export const POST = handleAIEditorRequest;

Individual Handlers (Advanced)

For advanced use cases, you can import individual handlers:

import {
  handleEdit,
  handleRead,
  handleResolve,
  handleUndo,
  handleAbsolutePath,
  handleValidateSession
} from "next-ai-editor/server";

How It Works

  1. Component Detection: Uses React Fiber's _debugStack to capture component hierarchy
  2. Source Mapping: Resolves compiled positions to original source using Turbopack source maps
  3. AST Parsing: Uses Babel to parse files and locate exact elements by tag, class, text, etc.
  4. AI Generation: Claude Sonnet 4.5 generates the edited code with full component context
  5. Smart Replacement: Replaces either the target element or full component based on the edit scope

Requirements

  • Next.js: 15.0.0 or higher
  • React: 18.0.0 or higher
  • Node.js: 18.0.0 or higher
  • Anthropic API Key: Required for AI functionality

Development Only

This package is designed for development only. All API endpoints return errors in production (NODE_ENV=production), and file operations are restricted to your project directory.

Examples

Simple Style Changes

"make this button blue"
"add rounded corners"
"increase the font size to 18px"

Layout Adjustments

"center this vertically"
"make this a flex row"
"add 20px padding around this"

Content Updates

"change the text to 'Hello World'"
"add a subtitle under this heading"
"make this bold"

Complex Changes

"add hover effect that changes background to blue"
"wrap this in a card with shadow"
"make this responsive with mobile breakpoint"

Troubleshooting

Component Not Detected

  • Make sure you're running Next.js dev server (npm run dev)
  • Only React components are editable (not plain HTML)
  • Server Components and Client Components are both supported

Source Mapping Issues

  • Ensure .next/dev/ directory exists with source maps
  • Turbopack generates .map files automatically in development

API Key Issues

  • Verify ANTHROPIC_API_KEY is set in .env.local
  • Restart your dev server after adding environment variables

Contributing

Contributions are welcome! Please feel free to submit a Pull Request.

License

MIT © Jesse Halpern

Links