--- name: word-processor-expert description: Expert guide for building professional word processors with Tiptap/ProseMirror. Use for text editor features, document formatting, export functionality, and achieving Word/Pages/Docs feature parity. --- # Word Processor Expert Skill ## Overview This skill provides rapid guidance for implementing professional word processor features in id8composer using Tiptap (ProseMirror). Get you to Microsoft Word, Apple Pages, and Google Docs quality with modern web technologies. ## Current Stack (id8composer) - **Editor**: Tiptap v3.10.7 (ProseMirror-based) - **Framework**: Next.js 15.5.6 + React 19 - **State**: Zustand - **Export**: `docx` v9.5.1, `jspdf` v3.0.3 ## Quick Reference: Missing Features ### ❌ Not Yet Implemented - Text alignment (left/center/right/justify) - Font family/size controls - Heading styles (H1-H6 with styling) - Line spacing (1.0, 1.5, 2.0) - Paragraph spacing - Indentation controls - Find & Replace - Page breaks - Headers/Footers - Page setup (margins, orientation) - Proper DOCX/PDF export - Styles/Templates - Comments/Track changes ### ✅ Already Working - Bold, italic, underline - Lists (bullet, ordered) - Tables - Images, links - Color & highlight - Undo/Redo - Auto-save - Character/word count ## Essential Tiptap Extensions ### Install Missing Extensions ```bash npm install @tiptap/extension-text-align npm install @tiptap/extension-font-family npm install @tiptap/extension-heading npm install @tiptap/extension-hard-break ``` ### Text Alignment ```typescript // Add to editor extensions import { TextAlign } from '@tiptap/extension-text-align' const editor = useEditor({ extensions: [ TextAlign.configure({ types: ['heading', 'paragraph'], alignments: ['left', 'center', 'right', 'justify'], defaultAlignment: 'left', }), // ... other extensions ], }) // Toolbar buttons ``` ### Font Family & Size ```typescript import { FontFamily } from '@tiptap/extension-font-family' import { TextStyle } from '@tiptap/extension-text-style' // Already installed // Custom Font Size extension import { Extension } from '@tiptap/core' export const FontSize = Extension.create({ name: 'fontSize', addOptions() { return { types: ['textStyle'], } }, addGlobalAttributes() { return [ { types: this.options.types, attributes: { fontSize: { default: null, parseHTML: element => element.style.fontSize.replace('px', ''), renderHTML: attributes => { if (!attributes.fontSize) return {} return { style: `font-size: ${attributes.fontSize}px`, } }, }, }, }, ] }, addCommands() { return { setFontSize: (fontSize: string) => ({ chain }) => { return chain().setMark('textStyle', { fontSize }).run() }, unsetFontSize: () => ({ chain }) => { return chain().setMark('textStyle', { fontSize: null }).run() }, } }, }) // Usage in editor const editor = useEditor({ extensions: [ TextStyle, // Required FontFamily.configure({ types: ['textStyle'], }), FontSize, // ... ], }) // Dropdowns in toolbar ``` ### Line Spacing ```typescript // Custom Line Height extension import { Extension } from '@tiptap/core' export const LineHeight = Extension.create({ name: 'lineHeight', addOptions() { return { types: ['paragraph', 'heading'], defaultLineHeight: '1.5', } }, addGlobalAttributes() { return [ { types: this.options.types, attributes: { lineHeight: { default: this.options.defaultLineHeight, parseHTML: element => element.style.lineHeight || this.options.defaultLineHeight, renderHTML: attributes => { if (!attributes.lineHeight) return {} return { style: `line-height: ${attributes.lineHeight}` } }, }, }, }, ] }, addCommands() { return { setLineHeight: (lineHeight: string) => ({ commands }) => { return this.options.types.every((type: string) => commands.updateAttributes(type, { lineHeight }) ) }, } }, }) // Toolbar dropdown ``` ### Indentation ```typescript // Install @tiptap/extension-indent if available, or create custom export const Indent = Extension.create({ name: 'indent', addOptions() { return { types: ['paragraph', 'heading'], minIndent: 0, maxIndent: 10, } }, addGlobalAttributes() { return [ { types: this.options.types, attributes: { indent: { default: 0, parseHTML: element => { const indent = element.style.paddingLeft return indent ? parseInt(indent) / 40 : 0 }, renderHTML: attributes => { if (!attributes.indent) return {} return { style: `padding-left: ${attributes.indent * 40}px` } }, }, }, }, ] }, addCommands() { return { indent: () => ({ commands, state }) => { const { indent = 0 } = state.selection.$from.node().attrs if (indent >= this.options.maxIndent) return false return this.options.types.every((type: string) => commands.updateAttributes(type, { indent: indent + 1 }) ) }, outdent: () => ({ commands, state }) => { const { indent = 0 } = state.selection.$from.node().attrs if (indent <= this.options.minIndent) return false return this.options.types.every((type: string) => commands.updateAttributes(type, { indent: indent - 1 }) ) }, } }, addKeyboardShortcuts() { return { Tab: () => this.editor.commands.indent(), 'Shift-Tab': () => this.editor.commands.outdent(), } }, }) // Toolbar buttons ``` ### Page Breaks ```typescript // Custom Page Break node import { Node, mergeAttributes } from '@tiptap/core' export const PageBreak = Node.create({ name: 'pageBreak', group: 'block', parseHTML() { return [{ tag: 'div.page-break' }] }, renderHTML({ HTMLAttributes }) { return ['div', mergeAttributes(HTMLAttributes, { class: 'page-break' }), ['hr']] }, addCommands() { return { setPageBreak: () => ({ commands }) => { return commands.insertContent({ type: this.name }) }, } }, }) // CSS for page breaks /* styles/editor.css */ .page-break { page-break-after: always; break-after: page; margin: 2rem 0; border: none; border-top: 2px dashed #ccc; text-align: center; } .page-break::after { content: "Page Break"; display: inline-block; position: relative; top: -0.7em; padding: 0 1em; background: white; color: #999; font-size: 0.8em; } // Toolbar button ``` ### Find & Replace ```typescript 'use client' import { useState } from 'react' export function FindReplace({ editor }: { editor: Editor }) { const [searchTerm, setSearchTerm] = useState('') const [replaceTerm, setReplaceTerm] = useState('') const [caseSensitive, setCaseSensitive] = useState(false) const findNext = () => { const content = editor.getText() const flags = caseSensitive ? 'g' : 'gi' const regex = new RegExp(searchTerm, flags) const matches = [...content.matchAll(regex)] if (matches.length > 0) { // Highlight first match const match = matches[0] // Implementation: Use Tiptap's TextSelection to highlight } } const replaceNext = () => { const { from, to } = editor.state.selection const selectedText = editor.state.doc.textBetween(from, to) if (selectedText === searchTerm || (!caseSensitive && selectedText.toLowerCase() === searchTerm.toLowerCase())) { editor.chain().focus().insertContentAt({ from, to }, replaceTerm).run() findNext() } } const replaceAll = () => { const content = editor.getHTML() const flags = caseSensitive ? 'g' : 'gi' const regex = new RegExp(searchTerm, flags) const newContent = content.replace(regex, replaceTerm) editor.commands.setContent(newContent) } return (