API Reference
@likhaeditor/likhaeditor
createEditor(options)
Creates a new editor instance with toolbar.
Parameters
typescript
interface CreateEditorOptions {
/** Element to mount editor (required) */
element: HTMLElement;
/** Toolbar container element (optional) */
toolbarContainer?: HTMLElement | string;
/** Initial HTML content (optional) */
content?: string;
/** Placeholder text when editor is empty (optional) */
placeholder?: string;
/** Enable/disable editing (optional, default: true) */
editable?: boolean;
/** Show/hide toolbar (optional, default: true) */
toolbar?: boolean;
/** Callback when content changes (optional) */
onChange?: (html: string) => void;
}Returns
typescript
interface EditorInstance {
/** Core editor instance */
editor: Editor;
/** Toolbar instance */
toolbar: Toolbar | null;
/** Get current HTML content */
getContent: () => string;
/** Set HTML content */
setContent: (html: string) => void;
/** Destroy editor and cleanup */
destroy: () => void;
}Example
javascript
import { createEditor } from '@likhaeditor/likhaeditor';
const instance = createEditor({
element: document.getElementById('editor'),
toolbarContainer: '#toolbar',
content: '<p>Hello world</p>',
placeholder: 'Start typing...',
onChange: (html) => {
console.log('Content:', html);
}
});
// Get content
const html = instance.getContent();
// Set content
instance.setContent('<h1>New content</h1>');
// Cleanup
instance.destroy();@likhaeditor/core
Editor
Core editor class.
Constructor
typescript
new Editor(options: EditorOptions)
interface EditorOptions {
element: HTMLElement;
content?: string;
placeholder?: string;
editable?: boolean;
plugins?: Plugin[];
onChange?: (html: string) => void;
}Methods
Content Management
getHTML(): string- Get editor content as HTMLgetJSON(): any- Get editor content as JSONsetContent(html: string): void- Set editor content from HTMLclear(): void- Clear all content
Formatting Commands
bold(): boolean- Toggle bolditalic(): boolean- Toggle italicunderline(): boolean- Toggle underlinetoggleHeading(level: 1-6): boolean- Toggle heading
Command Execution
executeCommand(name: string, ...args: any[]): boolean- Execute any registered command
State
view: EditorView- ProseMirror view instancestate: EditorState- Current editor state
Example
javascript
import { Editor } from '@likhaeditor/core';
import { BoldPlugin, ItalicPlugin } from '@likhaeditor/plugins';
const editor = new Editor({
element: document.getElementById('editor'),
plugins: [new BoldPlugin(), new ItalicPlugin()],
onChange: (html) => {
console.log(html);
}
});
// Use commands
editor.bold();
editor.italic();
editor.toggleHeading(2);
// Execute plugin commands
editor.executeCommand('toggleBulletList');@likhaeditor/ui
Toolbar
Toolbar component for editor controls.
Constructor
typescript
new Toolbar(options: ToolbarOptions)
interface ToolbarOptions {
container: HTMLElement;
sticky?: boolean;
}Methods
addButton(button: HTMLElement): void- Add button to toolbaraddGroup(buttons: HTMLElement[]): void- Add button groupaddSeparator(): void- Add separatorclear(): void- Remove all buttonsdestroy(): void- Cleanup toolbar
Button
Button component.
Constructor
typescript
new Button(options: ButtonOptions)
interface ButtonOptions {
icon?: string;
text?: string;
title?: string;
onClick?: (e: MouseEvent) => void;
isActive?: () => boolean;
}Methods
getElement(): HTMLElement- Get button DOM elementsetActive(active: boolean): void- Set active state
@likhaeditor/plugins
All plugins extend the base Plugin class:
typescript
abstract class Plugin {
abstract name: string;
commands?(): Record<string, Function>;
keymap?(): Record<string, Function>;
prosemirrorPlugins?(): ProsemirrorPlugin[];
init?(editor: Editor): void;
}Available Plugins
PlaceholderPlugin- Placeholder textCharacterCountPlugin- Character countingHeadingPlugin- Headings (H1-H6)BulletListPlugin- Bullet listsOrderedListPlugin- Numbered listsBlockquotePlugin- BlockquotesTextAlignmentPlugin- Text alignmentLinkPlugin- HyperlinksImagePlugin- ImagesTablePlugin- TablesHorizontalRulePlugin- Horizontal rulesCodeBlockPlugin- Code blocksTextColorPlugin- Text colorHighlightPlugin- Text highlightStrikethroughPlugin- StrikethroughSubscriptPlugin- SubscriptSuperscriptPlugin- SuperscriptClearFormattingPlugin- Clear formattingHTMLSourceViewPlugin- HTML source view
See Plugins Documentation for detailed usage.