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 🙏

© 2026 – Pkg Stats / Ryan Hefner

react-prompt-editor

v1.0.9

Published

A powerful tree-structured prompt editor for complex AI workflows, featuring Markdown editing, AI optimization with streaming responses, dependency management, and node execution tracking.

Readme

React Prompt Editor

树形 Prompt 编辑器 React 组件,适用于复杂 AI 工作流、节点编排和多段内容协作编辑。

当前 npm 版本基于 Ant Design UI 体系构建,宿主项目需要提供 antd@ant-design/x。后续会逐步提供其他 UI 库版本。

  • 官网文档: https://www.rpeditor.asia
  • npm: https://www.npmjs.com/package/react-prompt-editor
  • GitHub: https://github.com/SquabbyZ/react-prompt-editor

安装

pnpm add react-prompt-editor antd @ant-design/x

reactreact-domantd@ant-design/xpeerDependencies。其中 React 应由你的应用本身提供,当前 UI 版本需要你额外安装 antd@ant-design/x

快速开始

import { PromptEditor } from 'react-prompt-editor';
import 'react-prompt-editor/styles/index.css';

const initialValue = [
  {
    id: 'root-1',
    title: 'System Prompt',
    content: '# Role\n\nYou are a helpful assistant.',
    children: [],
    isLocked: false,
    hasRun: false,
    dependencies: [],
  },
];

export default function App() {
  return (
    <PromptEditor
      initialValue={initialValue}
      onChange={(data) => {
        console.log('tree changed:', data);
      }}
      theme="system"
      draggable
    />
  );
}

常用 Props

| Prop | 说明 | | --- | --- | | initialValue | 非受控初始树数据 | | value | 受控模式数据 | | onChange | 树数据变化回调 | | onRunRequest | 节点运行请求回调 | | optimizeConfig | 内置 AI 优化配置 | | onOptimizeRequest | 自定义 AI 优化流程 | | previewMode | 只读预览模式 | | previewRenderMode | 预览渲染模式,支持 readonly-editormarkdown | | draggable | 是否启用拖拽排序 | | theme | 主题模式,支持 system / light / dark | | locale | 国际化语言包 | | renderToolbar | 自定义顶部工具栏渲染函数 | | dataSelector | 数据选择器组件,支持 @ 变量插入功能 |

额外导出

import { enUS, zhCN } from 'react-prompt-editor';

主要特性

🔖 数据选择器(变量插入)

支持通过 @ 符号触发数据选择器,在编辑器中插入变量标签。变量在编辑器中以高亮 Tag 样式显示,并在运行节点时自动替换为实际值:

import { PromptEditor } from 'react-prompt-editor';
import { SimpleDataSelector } from './MyDataSelector';

const App = () => (
  <PromptEditor
    initialValue={initialValue}
    dataSelector={SimpleDataSelector}
    onRunRequest={(request) => {
      // request.content 中的变量标签已被自动替换为实际值(如 {{user.name}})
      console.log('处理后的内容:', request.content);
      // 执行异步请求...
      request.meta?.onNodeRun?.(request.nodeId, { result: '✅ 成功' });
    }}
  />
);

多选模式

数据选择器支持多选模式,允许用户一次性选择多个变量并批量插入到编辑器中:

import { PromptEditor } from 'react-prompt-editor';
import { MultiSelectDataSelector } from './MultiSelectDataSelector';

const App = () => (
  <PromptEditor
    initialValue={initialValue}
    dataSelector={MultiSelectDataSelector} // 支持多选的选择器组件
  />
);

🔗 节点依赖管理

通过 dependencies 字段建立节点间的依赖关系。运行节点时,onRunRequest 回调的 dependenciesContent 会自动包含所有依赖节点的详细信息(包括 id、标号、标题、内容和运行状态):

const [value, setValue] = useState<TaskNode[]>([
  {
    id: 'role',
    title: '角色定义',
    content: '# Role\n\nYou are a helpful assistant.',
    hasRun: true,
    dependencies: [],
  },
  {
    id: 'task',
    title: '当前任务',
    content: '基于角色定义完成任务...',
    dependencies: ['role'], // 依赖 "角色定义" 节点
  },
]);

<PromptEditor
  value={value}
  onChange={setValue}
  onRunRequest={(request) => {
    // request.dependenciesContent 包含依赖节点的完整信息
    console.log('依赖节点:', request.dependenciesContent.map(d => ({
      id: d.nodeId,
      number: d.nodeNumber, // 节点标号,如 "1", "1.1"
      title: d.title,
      content: d.content,
      hasRun: d.hasRun,
    })));
  }}
/>

🎨 自定义工具栏

使用 renderToolbar 完全控制顶部工具栏的内容和布局:

<PromptEditor
  initialValue={initialValue}
  renderToolbar={(actions) => (
    <div style={{ display: 'flex', gap: '8px' }}>
      <span>📝 我的 Prompt 工作区</span>
      <button onClick={() => actions.addRootNode()}>添加节点</button>
    </div>
  )}
/>

👁️ 预览模式

提供两种预览渲染方式:

// 只读编辑器模式
<PromptEditor
  previewMode
  previewRenderMode="readonly-editor"
/>

// Markdown 阅读模式
<PromptEditor
  previewMode
  previewRenderMode="markdown"
/>

文档

  • 完整使用文档与示例: https://www.rpeditor.asia
  • 问题反馈: https://github.com/SquabbyZ/react-prompt-editor/issues

License

MIT