@friendofsvelte/tipex

中文文档
0.3.1发布于 2026/09/23MITTypeScriptES Module近 30 天下载 3.1万

Tipex stands as an advanced rich text editor tailored for Svelte, meticulously engineered with the robust frameworks Tiptap and Prosemirror. It empowers developers to effortlessly craft rich text editors,

原始使用文档
文档目录23 节
  1. Key Features
  2. Installation
  3. Basic Usage
  4. Core Concepts
  5. Control System
  6. Extension System
  7. Floating Menu
  8. Focus Management
  9. Modern Theming with Tailwind CSS v4
  10. Available CSS Custom Properties
  11. Advanced Usage
  12. Custom Head and Foot Sections
  13. Extending Default Controls
  14. Custom Control Component
  15. No Controls (Minimal Editor)
  16. Enter Key Behavior (Single vs Double Line Spacing)
  17. Props & Configuration
  18. Boolean Props with Negation
  19. Getting Editor Content
  20. Documentation
  21. About Friend Of Svelte
  22. Join the Community
  23. License

Tipex

Tipex stands as an advanced rich text editor tailored for Svelte, meticulously engineered with the robust frameworks Tiptap and Prosemirror. It empowers developers to effortlessly craft rich text editors, liberating them from the intricacies of underlying technologies, style management, and related complexities.

Svelte 5 and runes mode activated! ✨🔮

Key Features

  • 🚀 Svelte 5 Ready: Built with Svelte 5's latest features including runes, snippets, and modern reactivity
  • 🎨 Smart Control System: Automatically detects whether to show default or custom controls based on controlComponent prop
  • 🔌 Extensible Architecture: Fully extensible through Tiptap's extension system with default extensions included
  • 📱 Mobile Responsive: Optimized for both desktop and mobile with touch-friendly interactions
  • 🎯 Context-Aware Floating Menu: Intelligent floating toolbar that appears on text selection
  • 🔗 Advanced Link Management: Built-in link editing with clipboard integration and visual feedback
  • ✅ Task Lists: Native support for interactive checkboxes and task management
  • 🎭 Modern Theming: Built with Tailwind CSS v4 using OKLCH colors and CSS custom properties
  • ⚡ Performance Optimized: Leverages Svelte's reactivity and efficient DOM updates
  • 💼 Full TypeScript Support: Complete type safety with comprehensive type definitions
  • 🎨 Focus Management: Smart focus detection with visual feedback and accessibility support

Installation

Install the package from NPM:

npm install "@friendofsvelte/tipex"

Tiptap v3 is a peer dependency. npm 7+ and pnpm install it automatically; otherwise install it alongside:

npm install @tiptap/core @tiptap/pm @tiptap/starter-kit @tiptap/extensions @tiptap/extension-list @tiptap/extension-image @tiptap/extension-code-block @tiptap/extension-code-block-lowlight @tiptap/extension-floating-menu

Check out Tipex Editor Variants and its live preview for examples showcasing what you can build with the Tipex Svelte text editor, including multiple themes and configurations.

Basic Usage

Import the component and styles, then use it in your Svelte component:

<script lang="ts">
    import { Tipex } from '@friendofsvelte/tipex';
    import '@friendofsvelte/tipex/styles/index.css';

    let body = `<h1>My Project Notes</h1>
    <p>I've been working on this <strong>new feature</strong> for the past few days. 
    It's been quite <em>challenging</em> but I think I'm making good progress.</p>
    
    <h2>Things I need to do</h2>
    <ul data-type="taskList">
        <li data-type="taskItem" data-checked="true">Set up the development environment</li>
        <li data-type="taskItem" data-checked="false">Write the core functionality</li>
        <li data-type="taskItem" data-checked="false">Add error handling</li>
    </ul>
    
    <p>Check out the <a href="https://tiptap.dev/">TipTap documentation</a> for more features!</p>`;
</script>

<Tipex
    {body}
    floating
    focal
    style="margin-top: 1rem; margin-bottom: 0;"
    class="h-[70vh] border border-neutral-200/80"
/>

Core Concepts

Control System

Tipex features a simple and flexible control system:

  1. Default Controls (automatic when no controlComponent is provided):

    • Pre-built formatting toolbar with essential editing tools
    • Built-in utility buttons (copy, link management)
    • Perfect for quick implementation
  2. Custom Controls (when controlComponent snippet is provided):

    • Full control over the editor interface
    • Complete customization freedom
    • Can extend default controls or create entirely new interfaces
    • Ideal for specialized use cases
  3. No Controls (when controlComponent={null} is explicitly set):

    • Completely hides all control elements
    • Provides a clean, minimal editor interface
    • Perfect for read-only or embedded scenarios

This simple approach provides maximum flexibility while maintaining ease of use.

Extension System

Tipex leverages Tiptap's extension system for enhanced functionality. The extensions prop fully replaces the default extensions (including StarterKit). To extend the defaults, spread defaultExtensions and add your own:

<script lang="ts">
    import { Tipex, defaultExtensions } from '@friendofsvelte/tipex';
    import { TextAlign } from '@tiptap/extension-text-align';
    import { Highlight } from '@tiptap/extension-highlight';

    // Extend default extensions
    const customExtensions = [
        ...defaultExtensions,
        TextAlign.configure({
            types: ['heading', 'paragraph'],
            alignments: ['left', 'center', 'right', 'justify']
        }),
        Highlight.configure({
            multicolor: true
        })
    ];

    let body = '';
</script>

<Tipex {body} extensions={customExtensions} />

If you pass a fully custom extensions array, none of the defaults are kept — supply everything the editor needs (document, paragraph and text nodes, e.g. via your own StarterKit).

Floating Menu

The floating menu provides context-aware formatting options that appear when text is selected:

<Tipex floating /> <!-- Enables the floating menu -->

Focus Management

Tipex includes smart focus detection with visual feedback:

<Tipex focal />
<!-- Default: shows focus ring -->
<Tipex !focal />
<!-- Disables focus ring -->

Modern Theming with Tailwind CSS v4

Tipex is built with Tailwind CSS v4 and uses modern OKLCH colors for better color accuracy and consistency. The theming system uses CSS custom properties that you can override:

@import '@friendofsvelte/tipex/styles/index.css';

@theme {
    /* Override Tipex colors */
    --color-tipex-primary-500: oklch(0.65 0.11 285); /* Custom purple */
    --color-tipex-success-500: oklch(0.647 0.208 142.425); /* Custom green */

    /* Custom spacing */
    --spacing-tipex-md: 1.25rem;
    --spacing-tipex-lg: 2rem;
}

Available CSS Custom Properties

  • Colors: --color-tipex-{50-950}, --color-tipex-primary-{50-950}, --color-tipex-success-{50-950}
  • Spacing: --spacing-tipex-{xs,sm,md,lg,xl,2xl}
  • Sizing: --size-tipex-{1-12}
  • Typography: --text-tipex-{xs,sm,base,lg,xl,2xl}
  • Border Radius: --radius-tipex-{sm,md}
  • Z-Index: --z-tipex-{floating,controls}

Advanced Usage

Custom Head and Foot Sections

Add custom components above or below the editor using Svelte 5 snippets:

<script lang="ts">
    import { Tipex } from '@friendofsvelte/tipex';

    let body = '';
</script>

<Tipex {body}>
    {#snippet head(editor)}
        <CustomHeader {editor} />
    {/snippet}

    {#snippet foot(editor)}
        <CustomFooter {editor} />
    {/snippet}
</Tipex>

Extending Default Controls

Add custom utilities while keeping the default toolbar:

<script lang="ts">
    import { Tipex, Controls } from '@friendofsvelte/tipex';

    let body = '';
</script>

<Tipex {body}>
    {#snippet controlComponent(tipex)}
        <Controls {tipex}>
            <!-- Built-in utilities: copy HTML and link editing with clipboard integration -->
            <!-- Add custom utilities here -->
            <button class="tipex-edit-button tipex-button-rigid" aria-label="Export PDF">
                📄 Export
            </button>
        </Controls>
    {/snippet}
</Tipex>

Custom Control Component

Create a completely custom control interface:

<script lang="ts">
    import { Tipex } from '@friendofsvelte/tipex';

    let body = '';
</script>

<Tipex {body}>
    {#snippet controlComponent(tipex)}
        <div class="my-custom-controls">
            <button onclick={() => tipex.commands.toggleBold()}>
                <strong>B</strong>
            </button>
            <button onclick={() => tipex.commands.toggleItalic()}>
                <em>I</em>
            </button>
            <button onclick={() => tipex.commands.toggleTaskList()}> ✅ Tasks </button>
        </div>
    {/snippet}
</Tipex>

No Controls (Minimal Editor)

Hide all controls for a clean, minimal editor interface:

<script lang="ts">
    import { Tipex } from '@friendofsvelte/tipex';

    let body = '';
</script>

<!-- Editor with no controls - perfect for embedded or read-only scenarios -->
<Tipex {body} controlComponent={null} />

Enter Key Behavior (Single vs Double Line Spacing)

Pressing Enter starts a new paragraph (<p>), while Shift+Enter inserts a hard break (<br>) within the current paragraph. This is standard ProseMirror/Tiptap behavior and matches how most rich text editors work.

New paragraphs can look "double spaced" because Tipex's default styles give each paragraph a bottom margin: the rule .tipex-editor-section .ProseMirror p applies margin-bottom: var(--spacing-tipex-md) (1rem by default). Depending on what you want, there are two ways to change this:

Option A: Keep paragraphs, remove the visual gap (CSS)

Override the paragraph margin in your own stylesheet:

@import '@friendofsvelte/tipex/styles/index.css';

.tipex-editor .ProseMirror p {
    margin-bottom: 0;
}

This keeps the default Enter = new paragraph semantics (better for structured content) and only removes the spacing between paragraphs.

Option B: Make Enter insert a hard break instead of a new paragraph

Add a small extension that remaps Enter to a hard break:

<script lang="ts">
    import { Tipex, defaultExtensions } from '@friendofsvelte/tipex';
    import { Extension } from '@tiptap/core';

    const HardBreakOnEnter = Extension.create({
        name: 'hardBreakOnEnter',
        addKeyboardShortcuts() {
            return {
                Enter: () => this.editor.commands.setHardBreak()
            };
        }
    });

    let body = '';
</script>

<Tipex {body} extensions={[...defaultExtensions, HardBreakOnEnter]} />

With this extension, typing a, pressing Enter, then typing b produces <p>a<br>b</p> instead of two paragraphs. Note that this changes the document structure: all content stays in a single paragraph, so prefer Option A if you still want semantic paragraphs.

Props & Configuration

Based on the actual TipexProps interface, here are all available properties:

PropTypeDefaultDescription
bodystring''Initial HTML content for the editor
tipexTipexEditor (bindable)undefinedThe editor instance - bind to access editor methods
extensionsAnyExtension[] (bindable)defaultExtensionsArray of Tiptap extensions to use
floatingbooleanfalseEnable floating menu on text selection
focalbooleantrueEnable focus ring styling
focusedboolean (bindable)falseWhether the editor is currently focused
autofocusbooleantrueAuto-focus the editor on mount
classstring''Additional CSS classes for the editor container
stylestring''Inline styles for the editor container
ctxIdstring'_tipex'Context ID for the editor instance
headSnippet<[TipexEditor]>undefinedContent rendered above the editor
footSnippet<[TipexEditor]>undefinedContent rendered below the editor
controlComponentSnippet<[TipexEditor]> | nullundefinedCustom control component (replaces default controls). Set to null to hide all controls.
oncreate(props: EditorEvents['create']) => void() => {}Callback when editor is created
ondestroy(props: EditorEvents['destroy']) => void() => {}Callback when editor is destroyed
onupdate(props: EditorEvents['update']) => void() => {}Callback when editor content updates

Boolean Props with Negation

You can disable boolean props using the ! prefix:

<Tipex !focal !floating /> <!-- Disables focus ring and floating menu -->

Getting Editor Content

Access the editor instance and its content using Svelte 5 runes:

<script lang="ts">
    import { Tipex } from '@friendofsvelte/tipex';
    import type { Editor } from '@tiptap/core';

    let body = '';
    let editor: Editor | undefined = $state();

    // Reactive HTML content
    const htmlContent = $derived(editor?.getHTML() ?? '');

    // Reactive text content (no HTML tags)
    const textContent = $derived(editor?.getText() ?? '');

    // Reactive word count
    const wordCount = $derived(
        editor
            ?.getText()
            .split(/\s+/)
            .filter((word) => word.length > 0).length ?? 0
    );
</script>

<Tipex {body} bind:tipex={editor} />

<div class="editor-stats">
    <p>Words: {wordCount}</p>
    <p>Characters: {textContent.length}</p>
</div>

<details>
    <summary>HTML Output</summary>
    <pre>{htmlContent}</pre>
</details>

Documentation

For comprehensive documentation, visit tipex.pages.dev.

About Friend Of Svelte

Friend Of Svelte Logo

Friend Of Svelte is a community-driven project to help Svelte developers find and develop awesome Svelte resources. Our mission is to create high-quality, maintainable, and accessible tools for the Svelte ecosystem.

Join the Community

  • 🌟 Star our repositories
  • 🤝 Contribute to projects
  • 📢 Share your ideas
  • 👥 Open memberships for everyone

If you like this project, you can be one of the friends by contributing to the project. Memberships are open for everyone.

License

MIT Licensed. Copyright (c) 2023-2024 Friend of Svelte.

版本与发布记录

@friendofsvelte/tipex 共发布 70 个版本,首次发布于 2023/09/01;过去 12 个月发布了 5 个版本。

版本发布日期距今
0.3.1latest2026/09/231 个月前
0.3.02026/09/231 个月前
0.2.02026/07/124 个月前
0.1.12026/01/289 个月前
0.1.02026/01/1310 个月前
0.0.92025/09/131.2 年前

其他发布通道:dev1 → 0.0.9-dev.1,dev2 → 0.0.9-dev.2,dev3 → 0.0.9-dev.3。

关于 @friendofsvelte/tipex 的常见问题

@friendofsvelte/tipex 是什么?

Tipex stands as an advanced rich text editor tailored for Svelte, meticulously engineered with the robust frameworks Tiptap and Prosemirror. It empowers developers to effortlessly craft rich text editors,

如何安装 @friendofsvelte/tipex?

在项目目录运行 npm install @friendofsvelte/tipex,或使用 pnpm add / yarn add / bun add。它还需要宿主项目提供 peer 依赖:svelte(^5.0.0)、@tiptap/pm(^3.31.0)、@tiptap/core(^3.31.0)、@tiptap/extensions(^3.31.0)、@tiptap/starter-kit(^3.31.0)、@tiptap/extension-list(^3.31.0)、@tiptap/extension-image(^3.31.0)、@tiptap/extension-code-block(^3.31.0)、@tiptap/extension-floating-menu(^3.31.0)、@tiptap/extension-code-block-lowlight(^3.31.0)。npm 7 及以上与 pnpm 8 及以上默认会自动安装必需的 peer 依赖,Yarn 需要手动安装。

@friendofsvelte/tipex 支持 TypeScript 吗?

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

@friendofsvelte/tipex 支持 ESM 还是 CommonJS?

以 ES Module 形式发布,推荐使用 import 引入。在 CommonJS 项目中,Node.js 20.19+ / 22.12+ 可以直接 require() 不含顶层 await 的 ES Module,更早的版本需要改用动态 import()。

@friendofsvelte/tipex 可以商用吗?

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

@friendofsvelte/tipex 的下载量有多少?

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

@friendofsvelte/tipex 还在维护吗?

最新版本 0.3.1 发布于 2026/09/23(1 个月前);至今共发布 70 个版本,其中过去 12 个月发布了 5 个;首次发布于 2023/09/01。发布频率只是参考信号:功能稳定的工具可能很少需要更新,建议结合源码仓库的 issue 和提交记录判断。