tiptap-rs
Wasm Bindings for Tiptap โ Type-safe Rust bindings for the Tiptap headless rich text editor. This crate's API is designed to reflect Tiptap's original JavaScript API as faithfully as possible, while also providing a more idiomatic Rust experience.
๐ฆ Installation
Add to your Cargo.toml:
[]
= "0.1.2"
Setup
Add the following script to your HTML <head> tag to make Tiptap available to your Wasm module:
๐งช Usage
1. Basic Editor Setup
Create a Tiptap editor:
use *;
use *;
let document = document;
let element = document.query_selector.unwrap.unwrap;
let options = EditorOptions ;
let editor = new;
2. Using Chained Commands
Tiptap's original API is faithfully mirrored to provide a seamless transition from JS:
// Toggle bold formatting
editor.chain.focus.toggle_bold.run;
// Toggle italic formatting
editor.chain.focus.toggle_italic.run;
Some methods deviate from their original counterparts for ease of use, e.g.:
// Toggle heading level
// Note: One method per level, original is `.toggleHeading({ level: 1 })`
editor.chain.focus.toggle_h1.run;
3. Handling Button Events
Connect editor commands to UI buttons:
use *;
let editor_clone = editor.clone;
let callback = wrap;
let bold_button = document.query_selector.unwrap.unwrap;
bold_button.add_event_listener_with_callback.unwrap;
callback.forget;
4. Supported Extensions
The following Tiptap extensions have Rust bindings:
- Text Formatting: Bold, Italic, Strike-through
- Lists: Bullet lists, Ordered lists
- Headings: H1 through H6
- Basic Blocks: Paragraphs
- StarterKit: Complete bundle of common extensions
๐ API Reference
Editor
The main editor instance that wraps Tiptap's Editor class.
Editor::new(options: EditorOptions) -> Editor
Creates a new editor instance with the specified options.
EditorOptions
Configuration structure for instantiating an editor:
Chained Commands
Currently supported ChainedCommands:
toggle_bold()toggle_italic()toggle_strike()toggle_h1()throughtoggle_h6()toggle_bullet_list()toggle_ordered_list()focus()run()- Execute the command chain
๐ Examples
Run the examples:
This requires cargo-make to be installed.
The example demonstrates:
- Basic editor setup
- Formatting commands usage on UI events
- Extension usage with StarterKit
๐ Repo & Contributions
๐ฆ Crate: crates.io/crates/tiptap-rs ๐ ๏ธ Repo: github.com/dsplce-co/tiptap-rs
PRs welcome! ๐ค
๐ License
MIT or Apache-2.0, at your option.