Developer Guide

MNBEditor

A browser-based rich text editor with a document-style workspace, configurable toolbars, visual/code/preview modes, font management, page ruler controls, built-in AI assistance, API-backed spellchecking, alerts, modal forms, and an extensible tool system.

Overview

Toolbar presets

minimal, basic, and full.

Editing modes

Visual editing, code view, and preview mode.

Font system

Built-in fonts, external web fonts, and uploaded custom font files.

AI assistance

Modal-driven writing help with provider selection, prompt controls, multiple actions, and document insertion modes.

Spellchecker

API-backed spellchecking with language selection, inline highlights, suggestions, ignore, and clear-all controls.

Extension model

Plain-object tools using buttonTool(...) and selectTool(...).

Source layout

mnb-editor/
├─ mnb-editor.main.js          # high-level mount API and toolbar presets
├─ core/
│  ├─ editor-core.js           # MNBEditor class and runtime/editor logic
│  └─ toolkit.js               # tool helper wrappers
└─ tools/
   ├─ 01-undo.js
   ├─ 02-redo.js
   ├─ 03-logs.js
   ├─ ...
   └─ 66-print.js

Installation

The provided source is set up as directly imported modules. In the snapshot you shared, there is no package manifest or published package metadata, so the cleanest documented path is source-based integration.

Use the source files directly

<div id="editor"></div>
<script type="module">
  import { mountMNBEditor } from './mnb-editor.main.js';

  const editor = mountMNBEditor('#editor', {
    value: '<p>Hello MNBEditor</p>',
    placeholder: 'Start typing here...',
    toolbar: 'full',
    theme: 'light',
    width: 1200,
    height: 760,
  });

  window.editor = editor;
</script>

Entry points

mountMNBEditor(target, options)

Recommended application entry point. It resolves toolbar presets or custom tool lists, creates the core editor, applies dimensions, ruler visibility, branding, content limits, sticky toolbar offsets, and toolbar collapse behavior.

tools toolbar ruler width height contentLimit branding toolbarCollapsible toolbarCollapsed collapseToolbarBelow collapsedToolbarRows

createEditor(target, options)

Lower-level entry point that creates a raw MNBEditor instance for custom integrations.

Toolbar presets

minimal

Undo/redo, block styles, size, core formatting, alignment, link, image, preview, export.

basic

Ruler, history, text controls, formatting, layout, tables, comments, preview/code/fullscreen, print, export.

full

Margin ruler plus the full built-in tool collection imported by mnb-editor.main.js.

Quick start

import { mountMNBEditor } from './mnb-editor.main.js';

const editor = mountMNBEditor('#editor', {
  value: '<p>Hello world</p>',
  placeholder: 'Start typing here...',
  theme: 'light',
  toolbar: 'full',
  width: 1200,
  height: 760,
});

Core API

Commonly useful methods:

setHTML, getHTML, getText, toggleCodeView, togglePreview, updatePreview, insertHTML, insertText, surroundSelection, applyBlockStyle, toggleBlockClass, executeTool, saveHistory, undo, redo, alert, form, pickFiles, setTheme, setFontFamily, registerFontFace, registerExternalFont, insertTable, addTableRow, addTableColumn, deleteTableRow, deleteTableColumn, mergeCellRight, removeTable, setTableBorderMode, download, print, toggleFullscreen.

Tool authoring

import { buttonTool } from '../core/toolkit.js';

export default buttonTool({
  id: 'hello',
  label: 'Hello',
  icon: '👋',
  title: 'Insert greeting',
  async run(editor) {
    editor.insertText('Hello');
    editor.alert('Greeting inserted.', 'success');
  },
});

Common tool fields include id, label, title, icon, kind, group, groupLabel, area, toolbarLabel, toolbarVariant, options/items/choices, shortcut, run(editor, value), and onRendered(editor, element).

Fonts

MNBEditor supports default fonts, external web fonts, and uploaded local font files.

mountMNBEditor('#editor', {
  webFonts: [
    {
      label: 'Poppins',
      href: 'https://fonts.googleapis.com/css2?family=Poppins:wght@400;600&display=swap',
      value: 'Poppins, sans-serif',
    },
  ],
});

Accepted uploaded formats: .ttf, .otf, .woff, .woff2.

Branding

mountMNBEditor('#editor', {
  branding: {
    text: 'My Product',
    href: 'https://example.com',
    target: '_blank',
    position: 'status-right',
  },
});

Branding can also be disabled with false, or set with a simple string. A floating pill-style badge is also supported.

Content limits

mountMNBEditor('#editor', {
  contentLimit: {
    max: 300,
    type: 'words',
    mode: 'soft',
    showCounter: true,
  },
});

type supports chars and words. mode supports hard and soft.

Views

MNBEditor supports visual mode, code mode, and preview mode. Preview is rendered inside an isolated iframe and receives external font links, generated @font-face CSS, and editor content.

Writing assistance

MNBEditor can expose two writing-help tools in the toolbar: an AI command for generation and rewriting workflows, and a spellcheck command for language-aware typo detection and correction.

AI assistance

The AI tool is implemented as a buttonTool(...) with the id ai-integration. When activated, it opens a modal where the user chooses a provider, action, temperature, optional prompt, and how the result should be inserted back into the document.

Supported actions

improve, rewrite, summarize, continue, translate, and custom.

Insert modes

replace-selection, insert-below, and append-end.

Providers

Anthropic, OpenAI, Google, OpenRouter, Fireworks, Baseten, and Ollama.

  • If options.ai.endpoint is configured, the tool runs in backend mode and posts the request to your server endpoint.
  • If no endpoint is configured, the tool runs in direct browser mode and calls the selected provider directly.
  • The modal can optionally include the full document text as context in addition to the current selection.
  • Results are inserted directly into the editor and then synced through history, status, and input updates.
mountMNBEditor('#editor', {
  ai: {
    endpoint: '',
    defaultProvider: 'openai',
    defaultAction: 'improve',
    defaultApplyMode: 'replace-selection',
    includeDocumentDefault: false,
    providers: [
      { label: 'Anthropic', value: 'anthropic' },
      { label: 'OpenAI', value: 'openai' },
      { label: 'Google', value: 'google' },
      { label: 'OpenRouter', value: 'openrouter' },
      { label: 'Fireworks', value: 'fireworks' },
      { label: 'Baseten', value: 'baseten' },
      { label: 'Ollama', value: 'ollama' },
    ],
  },
});
In direct browser mode, most providers require both an API key and a model name. Ollama allows a local flow and treats the API key as optional.

Spellchecker

The spellchecker is implemented as a selectTool(...) with the id spellcheck. Choosing a language immediately runs the spellcheck request and highlights misspelled words inline inside the editor surface.

Language-aware

Starts with fallback languages such as English, Hindi, Telugu, Tamil, French, German, Spanish, Portuguese, Russian, Ukrainian, and Vietnamese, and can load more from the API.

Inline review

Misspelled words are wrapped with a red wavy underline and a hoverable/clickable mark.

Correction flow

Clicking a marked word opens a popover with suggestions plus Ignore and Clear all actions.

  • The tool posts the current plain text content to a spellcheck API endpoint together with the selected language code.
  • Each accepted suggestion replaces the marked word and refreshes editor history, preview, and status state.
  • Ignored words are unwrapped from the highlight layer without changing their text.
  • The selected language is also applied to the editing surface so browser and assistive tools can inherit the document language.
selectTool({
  id: 'spellcheck',
  label: 'Spellcheck',
  value: 'en',
  usage: 'Choose spellcheck language from the dropdown. Selecting a language runs the PHP spellcheck API immediately.',
});
This is more than passive browser spellcheck: the shared source implements a custom API-backed review flow with highlight rendering, suggestion popovers, ignore handling, and a clear-all command.

Tables

editor.insertTable(3, 4);
editor.addTableRow();
editor.addTableColumn();
editor.mergeCellRight();
editor.setTableBorderMode('outside');

The border mode is stored on table.dataset.borderMode, which lets your CSS interpret modes such as none, all, outside, inside, top, bottom, left, and right.

Practical notes

  • Some formatting still relies on document.execCommand(...).
  • Preview styles are isolated inside the iframe.
  • Code view should stay in sync with visual mode.
  • Select-style tools should provide options, items, or choices.

No license file or package metadata was included in the source snapshot, so add your own packaging and distribution details if you want to publish MNBEditor as a package.