# @harshtalks/slash-tiptap 中文文档

规范地址：https://npmcn.com/package/%40harshtalks/slash-tiptap/

版本：1\.3\.0
npm 元数据更新时间：2024-09-25T11:42:55.676Z
中文译文更新时间：2026-11-17T10:40:10.047Z
软件包许可：MIT

本文由上游 README 翻译，可能存在偏差，请结合原文核对 API、命令与配置。版权与许可归原作者所有。

原始 npm 页面：https://www.npmjs.com/package/%40harshtalks/slash-tiptap
原文对照：https://npmcn.com/package/%40harshtalks/slash-tiptap/?lang=original
项目主页：https://github.com/harshtalks/tiptap-plugins#readme
源码仓库：https://github.com/harshtalks/tiptap-plugins

## 关键信息（来自 npm 元数据）

- 包体积（解压后）：41.1 kB，7 个文件
- 模块格式：ESM + CJS
- TypeScript 类型：包内自带
- 运行依赖：7 个
- 首次发布：2024-09-25T10:41:03.361Z
- 最新版本发布：2024-09-25T11:42:55.499Z
- 近 30 天下载量：17310（2026-10-18 至 2026-11-16，npm 官方下载统计）
- 已发布版本数：4（近 12 个月 0 个）

## 中文简介

概念像切入命令 React.js

## 安装

```sh
npm install @harshtalks/slash-tiptap
```

也可以使用：`pnpm add @harshtalks/slash-tiptap`、`yarn add @harshtalks/slash-tiptap`、`bun add @harshtalks/slash-tiptap`

## README

# React.js 的 Tiptap 斜线命令扩展

React 的简单平分扩展以添加像 slash 命令这样的概念到您的工程中 。 它提供了一个基于tittap建议扩展之上的灵活扩展,以及基于cmdk包的无头UI组件.

-   既使用编辑器钩又使用编辑器的工程
-   类型安全
-   Cmdk上方的无头UI
-   灵活易用

注释:

1.  确定将整个编辑器包入 `SlashCmdProvider` 组件.
2.  键盘导航,提供 `enableKeyboardNavigationc` 内 `editorProps` 手柄DOMEvents.

## 安装

使用 pnpm 安装软件包

```bash
  pnpm add @harshtalks/slash-tiptap
```

## 用法 :

1.  定义建议。 在斜线菜单中添加所有您想要的逗号 .

```ts
import { enableKeyboardNavigation } from "@harshtalks/slash-tiptap";

const suggestions = createSuggestionsItems([
  {
    title: "text",
    searchTerms: ["paragraph"],
    command: ({ editor, range }) => {
      editor
        .chain()
        .focus()
        .deleteRange(range)
        .toggleNode("paragraph", "paragraph")
        .run();
    },
  },
  {
    title: "Bullet List",
    searchTerms: ["unordered", "point"],
    command: ({ editor, range }) => {
      editor.chain().focus().deleteRange(range).toggleBulletList().run();
    },
  },
  {
    title: "Ordered List",
    searchTerms: ["ordered", "point", "numbers"],
    command: ({ editor, range }) => {
      editor.chain().focus().deleteRange(range).toggleOrderedList().run();
    },
  },
]);
```

2.  创建编辑器实例

```tsx
import {
  Slash,
  enableKeyboardNavigation,
} from "@harshtalks/slash-tiptap";


const editor = useEditor({
  extensions: [
    StarterKit,
    ImageExtension,
    Slash.configure({
      suggestion: {
        items: () => suggestions,
      },
    }),
    Placeholder.configure({
      // Use a placeholder:
      placeholder: "Press / to see available commands",
      // Use different placeholders depending on the node type:
      // placeholder: ({ node }) => {
      //   if (node.type.name === 'heading') {
      //     return 'What’s the title?'
      //   }

      //   return 'Can you add some further context?'
      // },
    }),
  ],
  editorProps: {
    handleDOMEvents: {
      keydown: (_, v) => enableKeyboardNavigation(v),
    },
    attributes: {
      class:
        "prose prose-sm sm:prose lg:prose-lg xl:prose-2xl mx-auto focus:outline-none",
    },
  },
  content: `
     <p>This is a basic example of usage. Press / to see available commands. Click on Image to resize and align.</p>
     <img src="https://placehold.co/800x400/6A00F5/white" />
   `,
});
```

3.  将编辑器包入 `SlashCmdProvider` 组件和添加 `SlashCmd` 组件到您的编辑器.

```tsx
import {
  SlashCmd
} from "@harshtalks/slash-tiptap";


export const Editor = () => {
  return (
  <SlashCmdProvider>
    <EditorContent editor={editor} />
    <SlashCmd.Root editor={editor}>
      <SlashCmd.Cmd>
        <SlashCmd.Empty>No commands available</SlashCmd.Empty>
        <SlashCmd.List>
          {suggestions.map((item) => {
            return (
              <SlashCmd.Item
                value={item.title}
                onCommand={(val) => {
                  item.command(val);
                }}
                key={item.title}
              >
                  <p>{item.title}</p>
              </SlashCmd.Item>
            );
          })}
        </SlashCmd.List>
      </SlashCmd.Cmd>
    </SlashCmd.Root>
  </SlashCmdProvider>
  );
}
```

## 常见问题

### @harshtalks/slash-tiptap 是什么？

概念像切入命令 React\.js

### 如何安装 @harshtalks/slash-tiptap？

在项目目录运行 npm install @harshtalks/slash-tiptap，或使用 pnpm add / yarn add / bun add。

### @harshtalks/slash-tiptap 支持 TypeScript 吗？

支持。包内自带 TypeScript 类型声明（package\.json 声明了 types 入口），安装后即可获得类型提示，无需再安装 @types 包。

### @harshtalks/slash-tiptap 支持 ESM 还是 CommonJS？

同时提供 ES Module 与 CommonJS 入口，import 和 require\(\) 都可以使用，打包工具会自动选择合适的版本。

### @harshtalks/slash-tiptap 可以商用吗？

@harshtalks/slash-tiptap 使用 MIT 许可。宽松许可：允许商业使用、修改和再分发，通常只需在分发时保留原版权与许可声明。以上为概括，不构成法律意见，请以许可原文为准。

### @harshtalks/slash-tiptap 的下载量有多少？

根据 npm 官方下载统计，@harshtalks/slash-tiptap 在 2026/10/18 – 2026/11/16 这 30 天内被下载 17,310 次，日均约 577 次。下载量会把 CI 构建、镜像同步和作为其他包依赖的安装一并计入，适合横向比较热度，不能直接等同于使用人数。

### @harshtalks/slash-tiptap 还在维护吗？

最新版本 1\.3\.0 发布于 2024/09/25（2 年前）；至今共发布 4 个版本，其中过去 12 个月发布了 0 个；首次发布于 2024/09/25。发布频率只是参考信号：功能稳定的工具可能很少需要更新，建议结合源码仓库的 issue 和提交记录判断。

