Skip to main content

API Reference

Public exports from @clepit/core. Each symbol below ships a typed signature and a minimal usage example.

Editor

The core editor class. Editor exposes two public static methods: create (the main factory) and destroy. The create() method returns an EditorAPI object through which all instance methods are accessible after the editor is mounted.

MethodSignatureDescription
Editor.createEditor.create(config: EditorConfig): EditorAPICreate a new editor instance and mount it into the DOM element with the supplied containerId.
Editor.destroyEditor.destroy(containerId: string): voidThe destroy() method on the EditorAPI object calls Editor.destroy() for this instance.
MethodSignatureDescription
data.extractdata.extract(): EditorDataExtract the current block data from an editor instance as a JSON-safe EditorData.
data.setdata.set(data: EditorData): voidReplace the entire block list with a new data payload. Triggers a full re-render.
data.cleardata.clear(): voidClears both the block content and the persisted state data.
data.clearContentdata.clearContent(): voidRemoves blocks only, leaving store data intact.
data.clearStoragedata.clearStorage(): voidClears store data only, leaving current blocks untouched.
blocks.insertblocks.insert<T extends BlockToolType>(type: T, data: Block<T>['data'], index: number): HTMLElement | nullInsert a block at the given index. Accepts the same data shape as the target block type.
blocks.convertblocks.convert(blockId: string, newType: BlockToolType): voidConvert a block to a new type in-place.
blocks.removeblocks.remove(index: number): voidRemove the block at the given index.
blocks.moveblocks.move(fromIndex: number, toIndex: number): voidMoves a block from one index to another.
blocks.updateblocks.update<T extends BlockToolType>(blockId: string, data: Block<T>['data']): voidUpdates an existing block's data in-place. The type is unchanged.
blocks.getblocks.get(blockId: string): EditorData['blocks'][number] | nullFetches a block by its ID. Returns null if not found.
blocks.getAllblocks.getAll(): EditorData['blocks']Returns data for all blocks as an array.
blocks.countblocks.count(): numberReturns the number of blocks in the editor.
focusfocus(): voidMoves focus into the editor, focusing the first block.
blurblur(): voidRemoves any active focus from within the editor.
destroydestroy(): voidThe destroy() method on the EditorAPI object calls Editor.destroy() for this instance.
selection.getselection.get(): Selection | nullReturns the window selection object or null.
selection.setselection.set(selection: Selection): voidSets the window selection to the provided Selection object.
selection.clearselection.clear(): voidRemoves all ranges from the window selection.
ui.showBlockMenuui.showBlockMenu(block: HTMLElement): voidShows the block type menu for the given block DOM element.
ui.hideBlockMenuui.hideBlockMenu(): voidHides the block type menu if it is open.
ui.showToolbarui.showToolbar(x: number, y: number): voidShows the inline toolbar at the provided x, y viewport coordinates.
ui.hideToolbarui.hideToolbar(): voidHides the inline toolbar if it is visible.
view.getCurrentViewview.getCurrentView(containerId: string): EditorView | nullReturns the current view (edit, preview, or json) for the given containerId.
view.switchViewview.switchView(containerId: string, view: EditorView): voidSwitches the editor to a specified view: edit, preview, or json.

Typical usage example

TypeScript
import { Editor } from '@clepit/core';

const editor = Editor.create({
  containerId: 'editor',
  theme: 'auto',
  placeholder: 'Start writing...',
  minHeight: 300,
});

// Insert a block
editor.blocks.insert('paragraph', { html: 'Hello world' }, 0);

// Extract data
const data = editor.data.extract();

// Switch view
editor.view.switchView('editor', 'preview');

// Tear down
editor.destroy();

Renderer

A class that converts saved block data into read-only HTML inside a DOM element. This class has one public static method: render().

MethodSignatureDescription
Renderer.renderRenderer.render(config: RendererConfig): HTMLElementRender saved block JSON into a container as read-only HTML. Use this anywhere you want to display content without editing affordances.

Typical usage example

TypeScript
import { Renderer } from '@clepit/core';

Renderer.render({
  containerId: 'output',
  data,
  theme: 'auto',
  margins: { bottom: 12, top: 0 },
});

StyleManager

A centralised class that manages the theme system. It exposes three useful public static methods for consumers: subscribe (for OS-level theme changes), getResolvedTheme (to read the current OS theme), and injectStyles (to inject custom CSS).

MethodSignatureDescription
StyleManager.subscribeStyleManager.subscribe(cb: (theme: 'light' | 'dark') => void): () => voidSubscribe to runtime theme token changes. The listener fires whenever theme or themeOverrides mutate.
StyleManager.getResolvedThemeStyleManager.getResolvedTheme(): 'light' | 'dark'Reads the current OS theme ("light" or "dark"). Returns "light" if matchMedia is unavailable.
StyleManager.injectStylesStyleManager.injectStyles(styleId: string, styles: string): booleanInjects a CSS string into document.head (use a unique styleId). Returns false if already present, true otherwise.

Typical usage example

TypeScript
import { StyleManager } from '@clepit/core';

// React to OS theme changes
const unsubscribe = StyleManager.subscribe(theme => {
  console.log('OS theme:', theme); // 'light' | 'dark'
});

// Read current OS theme
const current = StyleManager.getResolvedTheme();

// Inject custom CSS once
StyleManager.injectStyles('my-overrides', `
  .clepit-editor { font-family: 'Inter', sans-serif; }
`);

// Unsubscribe when done
unsubscribe();