Skip to content

SDK reference ​

Published path for apps: on-codemerge/sdk (bundled into the product package).

Standalone low-level package: @codemerge/sdk (same API; do not install both into one app bundle — dual instances). Workspace sources still resolve via Vite alias @codemerge/sdk.

Plugins and host apps that need UI primitives, commands, or publish helpers import from here — not from on-codemerge/kernel inside a plugin, and not from deep src/utils/* paths.

ts
import {
  definePlugin,
  core,
  h,
  mount,
  insertAtomAfter,
  composePublishedDocument,
} from 'on-codemerge/sdk';

The Editor class and headless HTML/Markdown IO live on the package root (on-codemerge) — see Editor API. This page lists what on-codemerge/sdk exports.

Packages ​

ImportRole
on-codemergeProduct: Editor, plugins, CSS, importHTML / exportMarkdown, …
on-codemerge/sdkPlugin authoring + UI + publish helpers (compat subpath)
on-codemerge/kernelPure doc/ops via product subpath
on-codemerge/viewViewSpec DOM runtime (product subpath)
@codemerge/sdkSame SDK as a standalone npm package (plugin authors / headless)
@codemerge/kernelSame kernel standalone
@codemerge/viewZero-dep h / mount / portals (also re-exported from sdk)
@codemerge/mermaidSync Mermaid-subset SVG — see Mermaid
@codemerge/hunspellSpell engine without the editor
@codemerge/collaboration-serverAuthoritative collab server (ops op-log, presence, REST)

Plugin authoring ​

ExportRole
definePlugin(def)Seal a plugin descriptor
collectPublishNodes(plugins)Map data-node → PublishNodeDefinition
isDeclarativeWidgetType guard for widget defs
createPluginContextBuild PluginContext (normally Editor-owned)
DisposableScope / OwnedSlot / teardownOwnableLifetime helpers

PluginDefinition may include commands, hotkeys, widgets, publish, setup(ctx), locales, etc. See Authoring plugins.

Publish hooks ​

ts
definePlugin({
  name: 'timer',
  publish: {
    node: 'timer',
    runtime: 'timer', // id in dist/public.js
    render: (attrs) => h('div', { class: 'timer-widget', attrs: { … } }, […]),
  },
});
ExportRole
definePublishRuntime / registerPublishRuntimeDefine / register a page runtime
publishRuntimes / PublishRuntimeRegistryBoot [data-ocm-runtime] hosts
readOcmConfig / setOcmConfigdata-ocm-config JSON
neededRuntimeIds(html|root)Which runtimes a fragment needs
composePublishedDocument({ bodyHtml, cssHref, jsHref })Full HTML document string
publishedCssHref / publishedJsHrefDefault CDN/dist asset URLs
OCM_RUNTIME_ATTR / OCM_CONFIG_ATTRAttribute name constants
PUBLISHED_CONTENT_CLASSWrapper class for published body

Pair with Editor: getPublishedHTML() / getPublishedDocument() / getPublishedJS().

ViewSpec UI (h / mount) ​

Build plugin UI with ViewSpec — no document.createElement / innerHTML in plugins.

ExportRole
hHyperscript elements (string/number children = text)
foreignEscape hatch (still mount children with h)
img / video / iframe / canvasTyped element helpers
mount / renderDetachedAttach / detached root (handle.update to refresh)
viewToHtmlSerialize ViewSpec → HTML string (export boundary)
downloadUrl / downloadBlob / pickFileFile download / picker portals

Portals ​

ExportRole
createPortal / teleport / isTeleportMount outside the editor host
getPortalRoot / setPortalRoot / clearPortalRootNamed roots (body, menu, popup, notify)

Required for shadow DOM / iframe hosts — see Chrome & host.

Chrome services ​

ExportRole
ToolbarPanelCore toolbar panel (Editor owns an instance)
PopupService / PopupControllerModal / popup stack
ContextMenuServiceContext menus
NotifyServiceToasts / confirms
placeRoot / placeSubmenu / applyPlaceRoot / applyPlaceSubmenuMenu positioning
studioPaneTabs / syncStudioPanelMulti-pane studio mobile tabs (Charts/Forms/…)
editorChromeTvTailwind-variants tokens for chrome

Types: ToolbarButton, ToolbarMenuDef, PopupOptions, MenuItem, NotifyOptions, …

Commands & core ​

ExportRole
coreKernel facade (toggleMark, insertText, applyOps, …)
insertAtomAfter / insertBlockNearSelectionInsert blocks/atoms
setMarkAttrs / setBlockAttrMark / block attrs
replaceBlockType / convertBlockType / wrapInListStructure
withMarkTargetExpand caret to word before mark ops
attrStringSafe string coerce for attrs
findAncestorPath / resolveInsertSitePath helpers

EditorAPI (type) ​

Plugins receive ctx.editor: EditorAPI. Document boundaries on that surface:

MethodRole
getJSON / setJSONSoT
getHTML / setHTMLSemantic HTML
getMarkdown / setMarkdownMarkdown
getPublishedHTML / getPublishedJS / getPublishedDocumentPublished page
command / run / dispatchCommands
toolbar / ui.popup / ui.menu / notifyChrome
t / setLocale / …i18n

Full usage examples: Editor API.

CSS entry points (package) ​

ImportRole
on-codemerge/index.cssEditor chrome (includes SDK + plugin styles)
on-codemerge/public.cssPublished atom skins + prose
@codemerge/sdk/sdk.cssSDK chrome alone (optional; already in index.css)
on-codemerge/public.jsPublished runtimes bootstrap (timer, calendar, mermaid hydrate, …)

Released under the MIT License.