AgentSkillsCN

rte-usage

从@abaktiar/rich-text-editor中引入RichTextEditor与RichTextViewer组件。当您需要实现富文本编辑功能,或展示格式化后的内容时,这一功能将为您带来极大便利。

SKILL.md
--- frontmatter
name: rte-usage
description: Use RichTextEditor and RichTextViewer components from @abaktiar/rich-text-editor. Use when implementing rich text editing or displaying formatted content.

Rich Text Editor Usage

Installation

bash
npx shadcn@latest add https://abaktiar.github.io/rich-text-editor/r/rich-text-editor.json

Basic Usage

tsx
import { RichTextEditor, RichTextViewer } from '@/components/ui/editor'

// Editable
<RichTextEditor
  content="<p>Hello world</p>"
  onChange={(content) => console.log(content.html)}
  placeholder="Type '/' for commands..."
/>

// Read-only
<RichTextViewer content={savedHtml} />

RichTextEditor Props

PropTypeDefaultDescription
contentstring | object-Initial HTML or JSON
onChange(content) => void-Content change callback
editablebooleantrueEnable editing
placeholderstring"Type '/' for commands..."Placeholder text
autoFocusbooleanfalseFocus on mount
classNamestring-CSS classes
showToolbarbooleantrueShow toolbar
minHeightstring | number'200px'Min height
codeBlockMaxHeightstring | number-Code block max height
calloutTypesCalloutTypeConfig[]defaultsCustom callouts
pluginsEditorPlugin[][]Custom plugins

RichTextViewer Props

PropTypeDescription
contentstring | objectHTML or JSON to display
classNamestringCSS classes
onMentionClick(item, event) => voidMention click handler
codeBlockMaxHeightstring | numberCode block max height

Ref API

tsx
import { useRef } from 'react'
import { RichTextEditor, type RichTextEditorRef } from '@/components/ui/editor'

function MyEditor() {
  const ref = useRef<RichTextEditorRef>(null)

  return (
    <>
      <RichTextEditor ref={ref} />
      <button onClick={() => console.log(ref.current?.getContent('html'))}>
        Get HTML
      </button>
    </>
  )
}
MethodReturnsDescription
getContent(format)string | objectGet as 'html', 'json', 'text'
setContent(content)voidSet HTML or JSON
focus()voidFocus editor
blur()voidBlur editor
isEmpty()booleanCheck if empty
clear()voidClear content
getEditor()EditorGet Tiptap instance

onChange Content

tsx
interface EditorContent {
  html: string   // HTML string
  json: object   // Tiptap JSON
  text: string   // Plain text
}

All Exports

tsx
// Components
import {
  RichTextEditor,
  RichTextViewer,
  BubbleMenu,
  CommandMenu,
  Toolbar,
} from '@/components/ui/editor'

// Plugins
import {
  createFileUploadPlugin,
  createMentionPlugin,
} from '@/components/ui/editor'

// Utilities
import {
  defaultSlashCommands,
  filterCommands,
  groupCommands,
  commandGroups,
  createExtensions,
} from '@/components/ui/editor'

// Types
import type {
  RichTextEditorRef,
  RichTextEditorProps,
  EditorPlugin,
  SlashCommand,
  ToolbarAction,
  MentionItem,
  CalloutTypeConfig,
} from '@/components/ui/editor'