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

@ctzhian/tiptap

v2.9.4

Published

基于 Tiptap 二次开发的编辑器组件

Readme

@ctzhian/tiptap

NPM version NPM downloads

基于 Tiptap v3 二次开发的 React 富文本编辑器组件集,内置工具栏、主题、结构化 Diff、高亮、表格、附件/音视频/数学等常用扩展,开箱即用。

  • 核心能力:useTiptapEditorEditorToolbarEditorDiff
  • 技术栈:React 18、Tiptap v3、MUI v7、Emotion 11

安装

pnpm add @ctzhian/tiptap
# 同时安装 peer 依赖
pnpm add @mui/material @mui/icons-material @emotion/react @emotion/styled

样式(必须):

import '@ctzhian/tiptap/dist/index.css';

快速开始

import React from 'react';
import {
  EditorThemeProvider,
  EditorToolbar,
  Editor,
  useTiptap,
} from '@ctzhian/tiptap';
import '@ctzhian/tiptap/dist/index.css';

export default function Demo() {
  const { editor } = useTiptap({
    editable: true,
    content: '<p>Hello Tiptap</p>',
    exclude: ['invisibleCharacters'],
    onSave: (ed) => console.log('save:', ed.getHTML()),
  });

  return (
    <EditorThemeProvider mode="light">
      <div
        style={{
          border: '1px solid #eee',
          borderRadius: 10,
          padding: '0 10px 10px',
        }}
      >
        <div style={{ borderBottom: '1px solid #eee', marginBottom: 30 }}>
          <EditorToolbar editor={editor} />
        </div>
        <Editor editor={editor} />
      </div>
    </EditorThemeProvider>
  );
}

模块说明

useTiptap(核心 Hook)

创建并管理 Tiptap 实例,统一扩展与回调。

  • 常用入参:
    • editable?: boolean 是否可编辑(默认 true)
    • content?: string | JSON 初始内容
    • exclude?: string[] 需要禁用的内置扩展名
    • extensions?: Extension[] 自定义扩展
    • mentionItems?: string[]onMentionFilter?: ({ query }) => Promise<string[]>
    • onSave?(editor)onError?(error)
    • onUpload?(file, onProgress) 自定义上传,返回可访问地址
    • onTocUpdate?(toc)onAiWritingGetSuggestion?({ prefix, suffix }) => Promise<string>
  • 返回:{ editor, getText, getHTML, getJSON, getMarkdownByJSON }
const { editor } = useTiptap({
  editable: true,
  onSave: (ed) => console.log(ed.getHTML()),
  onUpload: async (file, onProgress) => {
    onProgress?.({ progress: 1 });
    return 'https://example.com/file/url';
  },
});

EditorToolbar(工具栏)

editor 绑定的可视化工具栏:撤销/重做、标题/字号、加粗/斜体/上下标、颜色、列表、对齐、链接、更多菜单,以及 AI 伴写开关。

  • Props:{ editor: Editor; menuInToolbarMore?: ToolbarItemType[] }
<EditorToolbar
  editor={editor}
  menuInToolbarMore={[{ id: 'my-action', label: '自定义' }]}
/>

Editor(编辑区)

渲染编辑区域,包含文字选择气泡菜单与拖拽锚点菜单。

  • Props:{ editor: Editor; menuInDragHandle?: MenuItem[]; menuInBubbleMenu?: MenuItem[]; onTip?: (type, tip) => void }
<Editor editor={editor} />

EditorDiff(结构化对比)

以只读方式展示两段 HTML 的结构化差异。

  • Props:{ oldHtml: string; newHtml: string }
<EditorDiff oldHtml={'<p>old</p>'} newHtml={'<p><strong>new</strong></p>'} />

Development

# install dependencies
pnpm install

# develop library by docs demo
pnpm start

# build library source code
pnpm run build

# build library source code in watch mode
pnpm run build:watch

# build docs
pnpm run docs:build

# Locally preview the production build.
pnpm run docs:preview

# check your project for potential problems
pnpm run doctor

LICENSE

MIT