Skip to main content

Configuration

EditorConfig and RendererConfig are the entry points for every customisation. Pass either to Editor.create() or Renderer.render() respectively. Only containerId (and data for the renderer) are required; all other options have safe defaults.

EditorConfig

Pass EditorConfig as the sole argument to Editor.create(). The required containerId must match an existing DOM element id.

OptionTypeRequiredDescription
containerIdstringYesID of the DOM element that will host the editor. Must exist in the DOM before Editor.create() is called.
maxHeightnumberNoMaximum height of the editor in pixels. Set to 0 (the default) for no height limit.
minHeightnumberNoMinimum height of the editor in pixels. Defaults to 300.
onChange(data: EditorData) => voidNoCallback fired whenever the document changes. Receives the full EditorData snapshot.
onReady() => voidNoCallback fired once the editor is fully initialised and ready to accept API calls.
placeholderstringNoPlaceholder text shown when the editor is empty. Defaults to 'Start writing...'.
initialDataEditorDataNoPre-populated EditorData to load when the editor mounts.
initialView'edit' | 'preview' | 'json'NoStarting view mode. One of: edit, preview, json. Defaults to 'edit'.
allowJsonViewEditingbooleanNoWhen true, the JSON view is editable and changes propagate back into the document. Defaults to false.
marginsBlockMarginsNoGlobal top and bottom margin (in pixels) applied to every block. Per-block configs take precedence.
stylesEditorStylesNoEditorStyles object for fine-grained CSS customisation of editor chrome (toolbars, dialogs, controls).
classNamesEditorClassNamesNoEditorClassNames object to attach CSS class names to editor chrome elements.
imageUploaderUploadFunctionNoAsync function that uploads an image file and returns a public URL string.
audioUploaderUploadFunctionNoAsync function that uploads an audio file and returns a public URL string.
videoUploaderUploadFunctionNoAsync function that uploads a video file and returns a public URL string.
theme'auto' | 'light' | 'dark'NoColour scheme. One of: auto (follows system), light, dark. Defaults to auto.
themeOverrides{ light?: ThemeTokens; dark?: ThemeTokens }NoPer-mode token overrides. Supply light and/or dark token maps to customise colours without replacing the full theme.
TypeScript
import { Editor } from '@clepit/core';

const editor = Editor.create({
  containerId: 'editor',
  minHeight: 400,
  placeholder: 'Start writing...',
  theme: 'auto',
  onChange: data => console.log(data),
  onReady: () => console.log('Editor ready'),
  imageUploader: async file => {
    const form = new FormData();
    form.append('file', file);
    const res = await fetch('/api/upload', { body: form, method: 'POST' });
    const { url } = await res.json();
    return url;
  },
});

RendererConfig

Pass RendererConfig as the sole argument to Renderer.render(). Both containerId and data are required.

OptionTypeRequiredDescription
containerIdstringYesID of the DOM element where the rendered output will be injected.
dataEditorDataYesThe EditorData document to render. Required.
marginsBlockMarginsNoGlobal top and bottom margin (in pixels) applied to every rendered block.
stylesBlockStylesNoBlockStyles map for per-block-type CSS customisation of rendered output.
classNamesBlockClassNamesNoBlockClassNames map for per-block-type CSS class names on rendered output.
editorClassNamesEditorClassNamesNoEditorClassNames passed through to blocks that render interactive components (e.g. tooltip classNames for paragraphs).
configsPartial<BlockTypeOutputConfigs>NoPartial map of per-block OutputConfig objects. Each entry can set block-level margins and tooltip class names.
theme'auto' | 'light' | 'dark'NoColour scheme. One of: auto, light, dark.
themeOverrides{ light?: ThemeTokens; dark?: ThemeTokens }NoPer-mode token overrides for the rendered output.
TypeScript
import { Renderer } from '@clepit/core';
import type { EditorData } from '@clepit/core';

const data: EditorData = await fetch('/api/content/123').then(r => r.json());

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

Block-level styling

Both EditorConfig and RendererConfig accept styles, classNames, and configs keyed by block type. Use these for targeted overrides; see the Themes page for the complete per-token reference.

TypeScript
import { Editor, Renderer } from '@clepit/core';
import type { BlockStyles, BlockClassNames, EditorStyles } from '@clepit/core';

const editorStyles: EditorStyles = {
  blockToolbar: { container: { borderRadius: '8px' } },
};

const blockStyles: BlockStyles = {
  header: { h1: { fontFamily: 'Georgia, serif' } },
  paragraph: { lineHeight: '1.75' },
  table: { cell: { padding: '8px 12px' } },
};

const blockClassNames: BlockClassNames = {
  paragraph: 'prose-paragraph',
  header: { h1: 'prose-h1', h2: 'prose-h2' },
  alert: { info: 'alert-info', error: 'alert-error' },
};

Editor.create({
  containerId: 'editor',
  styles: editorStyles,
});

Renderer.render({
  containerId: 'output',
  data,
  styles: blockStyles,
  classNames: blockClassNames,
});