# Writeon
> A framework-agnostic, headless, accessible rich text editor built on ProseMirror.
---
Source: /guide/getting-started.md
# Getting started
**Early development:**
Writeon is in early development (0.x). The API may still change before 1.0.
## Install
```sh [npm]
npm install @writeon/core
# and the adapter for your framework, if you use one
npm install @writeon/react # React 18+
npm install @writeon/vue # Vue 3.3+
```
```sh [pnpm]
pnpm add @writeon/core
# and the adapter for your framework, if you use one
pnpm add @writeon/react # React 18+
pnpm add @writeon/vue # Vue 3.3+
```
```sh [yarn]
# Yarn does not install peer dependencies: list them
yarn add @writeon/core prosemirror-commands prosemirror-history prosemirror-inputrules \
prosemirror-keymap prosemirror-model prosemirror-schema-list \
prosemirror-state prosemirror-transform prosemirror-view
# and the adapter for your framework, if you use one
yarn add @writeon/react # React 18+
yarn add @writeon/vue # Vue 3.3+
```
```sh [bun]
bun add @writeon/core
# and the adapter for your framework, if you use one
bun add @writeon/react # React 18+
bun add @writeon/vue # Vue 3.3+
```
ProseMirror packages are peer dependencies, so your app has one copy of each. npm (7+), pnpm and bun install them for you; with Yarn, add them yourself as shown.
## Your first editor
An editor is made of **extensions**. `basic()` gives paragraphs, headings, bold, italic, underline, strike, inline code, links, lists, blockquotes, line breaks and undo/redo.
Every editor needs a **label**: the accessible name screen readers announce for the editable area.
**Vanilla**
```ts
import { createEditor } from '@writeon/core'
import { toggleBold } from '@writeon/core/commands'
import { basic } from '@writeon/core/presets'
//
and
const element = document.querySelector('#editor')
if (!element) throw new Error('No #editor element')
const editor = createEditor({
element,
extensions: basic(),
// Required: screen readers announce the editor by this name.
label: 'Article text',
placeholder: 'Start writing…',
onChange: (editor) => console.log(editor.getJSON()),
})
// Commands are factories: call toggleBold(), then run the result.
document.querySelector('#bold')?.addEventListener('click', () => {
editor.run(toggleBold())
})
```
**React**
```tsx
import type { DocJSON } from '@writeon/core'
import { toggleBold } from '@writeon/core/commands'
import { basic } from '@writeon/core/presets'
import {
EditorContent,
useEditor,
useEditorState,
} from '@writeon/react'
// Create the extensions once, outside components.
const extensions = basic()
interface Props {
initial: DocJSON
onSave: (doc: DocJSON) => void
}
export function ArticleEditor({ initial, onSave }: Props) {
const editor = useEditor({
extensions,
content: initial,
label: 'Article text',
onChange: (editor) => onSave(editor.getJSON()),
})
// Re-renders only when this value changes.
const isBold = useEditorState(editor, (s) => s.marks.has('bold'))
return (
<>
>
)
}
```
**Vue**
```vue
```
## Styles
The core ships no styles. ProseMirror needs this one rule so spaces and line breaks show correctly:
```css
.ProseMirror {
white-space: pre-wrap;
word-wrap: break-word;
}
```
Or use the [default kit](/guide/kit.md): a themeable toolbar and content styles in one CSS file.
## Next
- [Core concepts](/guide/concepts.md): documents, extensions, commands and state.
- [Saving and loading](/guide/saving.md): store JSON, convert to HTML or Markdown.
- [Security](/guide/security.md): validate on the server before you store or render.
---
Source: /guide/concepts.md
# Core concepts
## The document is JSON
The editor's content is a `DocJSON` value: a tree of nodes (paragraphs, headings, list items…) with text and marks (bold, link…).
```json
{
"type": "doc",
"schemaVersion": 1,
"content": [
{
"type": "paragraph",
"content": [{ "type": "text", "text": "Hello", "marks": [{ "type": "bold" }] }]
}
]
}
```
- **Store this JSON.** It is lossless and does not depend on the browser. HTML and Markdown are derived from it (see [Saving and loading](/guide/saving.md)).
- `schemaVersion` is the version of the format itself. When it changes, `migrateDoc()` (run automatically on load) brings old documents up to date.
## Extensions define what a document may contain
An extension adds node or mark types to the schema, plus behaviour: keyboard shortcuts, input rules (Markdown-style shortcuts such as `## `), and ProseMirror plugins. Presets are just arrays of extensions:
```ts
import { basic } from '@writeon/core/presets'
basic() // everything
basic({ strike: false }) // without strikethrough
basic({ heading: { levels: [2, 3] } }) // only H2 and H3
basic({ link: { protocols: ['https'] } }) // https links only
```
Content the schema does not allow is dropped when a document is loaded or pasted. Use **the same extensions** on the server (see [Security](/guide/security.md)).
To write your own, see [Your own extension](/recipes/custom-extension.md).
## Commands change the document
Commands are **factories**: `toggleBold()` returns a command, which you pass to `editor.run()`. Commands live in `@writeon/core/commands` and in the packages that add features.
```ts
import type { Editor } from '@writeon/core'
import {
setHeading,
setLink,
toggleBold,
toggleBulletList,
} from '@writeon/core/commands'
export function examples(editor: Editor) {
// Commands are factories: call them, then run the result.
editor.run(toggleBold())
// can() asks without changing anything.
// Use it to disable buttons.
const canList = editor.can(toggleBulletList())
// Several commands, one undo step.
// Nothing is applied if one of them fails.
editor.transaction((tx) => {
tx.run(setHeading(2))
tx.run(setLink({ href: 'https://example.com' }))
})
// What is active at the selection.
const inHeading = editor.isActive('heading', { level: 2 })
// A snapshot for your UI; subscribe() says when it changed.
const off = editor.subscribe(() => {
const { marks, canUndo, block } = editor.getSnapshot()
console.log([...marks], canUndo, block.type)
})
return { canList, inHeading, off }
}
```
## State for your UI
`editor.getSnapshot()` returns an immutable object with what UI usually needs: active marks, the current block, selection, `canUndo`, `focused`, `editable`, `empty`. `editor.subscribe()` calls you when it changes (batched per microtask).
In React, `useEditorState(editor, selector)` re-renders only when the selected value changes; in Vue, it returns a ref.
## Lifecycle
- `createEditor({ element })` mounts at once; without `element`, call `editor.mount(el)` later. Document and history survive `unmount()` and `mount()`.
- `editor.destroy()` releases everything. The React and Vue adapters do this for you.
- `editor.pm` gives direct access to ProseMirror. It is **not a stable API**: it may change in any minor release.
---
Source: /guide/basic-and-advanced.md
# Basic and advanced
Most editors need only the basics. Task lists, code blocks, images, tables and mentions are **advanced** and live in `@writeon/advanced`.
Advanced is split in two so it costs nothing until it is used:
| Part | Package | Loaded |
| --------------------------------------------- | --------------------------- | -------------------- |
| Node types (schema) | `@writeon/advanced/schema` | Up front, about 2 KB |
| Behaviour (shortcuts, table editing, uploads) | `@writeon/advanced` | On demand |
Because the schema is always there, every document opens and displays correctly, even one with tables, before the behaviour is loaded.
```ts
import { advancedSchema } from '@writeon/advanced/schema'
import { createEditor } from '@writeon/core'
import { basic } from '@writeon/core/presets'
// The node types are small and loaded up front, so every document
// opens and renders before the advanced behaviour arrives.
export const extensions = [...basic(), advancedSchema()]
const editor = createEditor({ extensions, label: 'Notes' })
// Later, when the user needs it. Shortcuts, input rules, table editing
// and the rest come in a separate chunk.
// The document, undo history and selection are kept.
export async function turnOnAdvanced(): Promise {
await editor.enable(() => import('@writeon/advanced'))
}
```
`editor.enable()` adds behaviour to the running editor and keeps the document, undo history and selection. Extensions already added are skipped, so calling it twice is harmless.
If you do not need lazy loading, pass everything up front:
```ts
import { advanced, advancedSchema } from '@writeon/advanced'
createEditor({ extensions: [...basic(), advancedSchema(), ...advanced()], label: 'Notes' })
```
## What advanced adds
| Feature | Commands | Notes |
| ----------- | -------------------------------------------------- | ---------------------------------------------- |
| Task lists | `toggleTaskList()`, `toggleTaskChecked()` | `Mod-Shift-9`, `[ ] ` input rule |
| Code blocks | `toggleCodeBlock()`, `setCodeBlockLanguage()` | `Mod-Alt-c`, ` ``` ` input rule |
| Images | `insertImage()`, `updateImage()`, `uploadImages()` | `imageUpload()` for drop, paste and progress |
| Tables | `insertTable()`, `addRowAfter()`, `mergeCells()`… | Header row by default; Tab moves between cells |
| Mentions | `insertMention({ id, label })` | Use with a suggestion menu |
## Fonts, colours and alignment
`@writeon/advanced/formatting` (about 2 KB, loaded up front like the schema) adds three extensions configured with what your design allows:
| Extension | Stores | Renders |
| --- | --- | --- |
| `fontFamily({ fonts })` | `{ font: 'inter' }` mark, so one paragraph can mix fonts | `` |
| `textColor({ colors })` | `{ color: 'brand' }` mark | `` |
| `textAlign()` | `align` on paragraphs and headings (`null` is left) | `style="text-align: …"`; `Mod-Shift-l/e/r` |
```ts
import {
fontFamily,
setFontFamily,
setTextAlign,
setTextColor,
textAlign,
textColor,
} from '@writeon/advanced/formatting'
import { createEditor } from '@writeon/core'
import { basic } from '@writeon/core/presets'
// The values your design allows. Documents store only the ids.
export const extensions = [
...basic(),
fontFamily({
fonts: [
{ id: 'inter', label: 'Inter', css: 'Inter, sans-serif' },
{ id: 'serif', label: 'Serif', css: 'Georgia, serif' },
],
}),
textColor({
colors: [
{ id: 'brand', label: 'Red', value: '#C00414' },
{ id: 'muted', label: 'Gray', value: '#475467' },
],
}),
textAlign(),
]
const editor = createEditor({ extensions, label: 'Post' })
// On the selection, or on what is typed next.
editor.run(setFontFamily('serif'))
editor.run(setTextColor('brand'))
// On the selected paragraphs and headings.
editor.run(setTextAlign('center'))
// null removes the font or the colour.
editor.run(setFontFamily(null))
```
- **Only ids are stored.** An id that is not configured does not fit the schema, so `validate()` drops it, and `toHTML()` writes nothing but `text-align`, `font-family` and `color` with strict values.
- **Pasted text keeps** a font when its `font-family` starts with one of yours, a colour when it is exactly one of yours, and alignment.
- **Contrast:** `textColor()` warns while you develop when a colour is under 4.5:1 on the background (`background`, default white).
- **Markdown** has no fonts or colours: `toMarkdown()` keeps the text without them.
- For menus, `activeFontFamily(state)` and `activeTextColor(state)` give the current id, and `textAlignmentAt(state)` the alignment.
### Image addresses
Image `src` is checked by the schema: `http(s)` or relative URLs only. `data:` URLs are refused unless you allow raster ones with `advancedSchema({ image: { dataUrls: true } })`. SVG is never allowed, because an SVG served from your domain can run scripts.
### Alt text
An image's `alt` is `null` until someone describes it (the element gets `data-alt-missing`, so you can show a hint), or `""` when it is marked decorative. The kit's image dialog requires one of the two.
---
Source: /guide/saving.md
# Saving and loading
```ts
import { advancedSchema } from '@writeon/advanced/schema'
import {
createEditor,
type DocJSON,
debounce,
type Editor,
} from '@writeon/core'
import { basic } from '@writeon/core/presets'
import { fromHTML, toHTML } from '@writeon/html'
import { fromMarkdown, toMarkdown } from '@writeon/markdown'
const extensions = [...basic(), advancedSchema()]
declare function saveDraft(doc: DocJSON): Promise
declare const stored: DocJSON
// Save at most twice a second.
const save = debounce((editor: Editor) => {
return saveDraft(editor.getJSON())
}, 500)
const editor = createEditor({
extensions,
content: stored,
label: 'Draft',
onChange: save,
})
// And once more before the page goes away.
window.addEventListener('pagehide', () => save.flush())
// Replace the whole document (not added to the undo history).
editor.setContent(stored)
// Other formats, always with the same extensions.
const doc = editor.getJSON()
const html = toHTML(doc, { extensions })
const markdown = toMarkdown(doc, { extensions })
const fromOldHtml = fromHTML('
Hello world
', {
extensions,
})
const fromReadme = fromMarkdown('# Title\n\n- one\n- two', {
extensions,
})
export { fromOldHtml, fromReadme, html, markdown }
```
## onChange
`onChange` runs after **every** change. Serializing the document on each keystroke is cheap for small documents, but for saving use `debounce()` from `@writeon/core`: it has `flush()` for the last pending call (before navigating away) and `cancel()`.
## HTML
`@writeon/html` converts both ways:
- `toHTML(doc, { extensions })` renders semantic HTML. It runs on the server too (no DOM needed).
- `fromHTML(html, { extensions })` parses HTML inside an inert ``, so scripts and images in it never run or load. On the server, pass a `document` (for example from `linkedom` or `jsdom`).
`officePaste()` is an extension that cleans up pastes from Word and Google Docs.
**Rendering user content:**
`toHTML()` trusts the document it is given. For documents that came from a browser, validate them first, or use `toSafeHTML()` from `@writeon/server`. See [Security](/guide/security.md).
## Markdown
`@writeon/markdown` reads and writes GitHub-flavoured Markdown, including tables and task lists. Raw HTML in Markdown stays text. Underline has no Markdown syntax and is dropped.
`markdownPaste()` turns pasted Markdown into formatted content; the parser is loaded the first time the editor gets focus.
---
Source: /guide/ssr.md
# Server-side rendering
The core and the adapters run on the server without touching the DOM. The editor itself can only mount in the browser, so on the server `` renders an empty element, unless you give it the HTML to show.
Pass `html` made with `toHTML()` from the same document. The page shows the content immediately, and the editor takes over that element when it mounts. Only the first value is used.
**Next.js**
```tsx
'use client'
import type { DocJSON } from '@writeon/core'
import { basic } from '@writeon/core/presets'
import { toHTML } from '@writeon/html'
import { EditorContent, useEditor } from '@writeon/react'
const extensions = basic()
export function PostEditor({ doc }: { doc: DocJSON }) {
const editor = useEditor({
extensions,
content: doc,
label: 'Post',
})
// Rendered on the server: the text is visible before JavaScript
// runs. The editor takes over this element when it mounts.
const html = toHTML(doc, { extensions })
return
}
```
**Nuxt**
```vue
```
Things to know:
- Create `extensions` once (outside the component) and share the same array.
- `useEditor()` reads `content` and `label` once, on creation. Use `editor.setContent()` to replace the document later.
- The default kit's `` reserves its height before it mounts, so the page does not jump.
---
Source: /guide/security.md
# Security
**The backend never trusts editor output.** Anything the browser sends can be forged; it may not come from the editor at all. Validate before you store a document, and render stored documents with a function that only emits what the schema allows.
## validate() and toSafeHTML()
`@writeon/server` has both. Give it the same extensions as the editor:
```ts
import { advancedSchema } from '@writeon/advanced/schema'
import { basic } from '@writeon/core/presets'
import { toSafeHTML, validate } from '@writeon/server'
// The same extensions as the editor, in one shared array.
// The schema built from it is cached.
const extensions = [...basic(), advancedSchema()]
interface Posts {
save(id: string, doc: unknown, html: string): Promise
}
declare const db: { posts: Posts }
export async function savePost(
id: string,
body: unknown,
): Promise {
// Never trust what the browser sends.
// It may not come from the editor at all.
const result = validate(body, {
extensions,
limits: { maxBytes: 500_000 },
})
if (!result.ok) {
return Response.json({ errors: result.errors }, { status: 422 })
}
// Save the checked document, not the body.
// result.removed lists what was dropped (unknown nodes,
// javascript: links…).
const html = toSafeHTML(result.doc, { extensions })
await db.posts.save(id, result.doc, html)
return Response.json({ removed: result.removed })
}
```
`validate()`:
- checks the JSON shape and refuses `__proto__`, `constructor` and `prototype` keys;
- enforces limits: size (1 MB), depth (32) and node count (50 000) by default;
- removes unknown nodes, marks and attributes, invalid attribute values and content the schema does not allow;
- removes links and images whose address is not allowed (`javascript:`, `data:` and so on);
- in `'strip'` mode (default) returns the cleaned document and what was removed; in `'strict'` mode refuses the whole document instead.
`toSafeHTML()` renders only what the schema knows, escapes all text and checks every URL again.
## In the browser
- Link and image addresses are checked by the schema, so pasted or typed `javascript:` links never enter the document.
- `fromHTML()` and paste parse HTML inside an inert ``: no scripts run and no images load.
- Image uploads refuse SVG by default.
## Rendering stored documents
Prefer `toSafeHTML()` on the server. If you render on the client with `toHTML()`, render documents that were validated when they were saved.
---
Source: /guide/accessibility.md
# Accessibility
WCAG 2.2 AA is a design goal. What that means in practice:
## The editable area
- `label` is required: the editable area is a `role="textbox"` with `aria-multiline` and the name you give (`'Article text'` or `{ labelledBy: 'heading-id' }`).
- The placeholder is announced, not only shown.
- Tab is not trapped: it indents list items and moves between table cells, and leaves the editor everywhere else.
## The UI controllers
Everything in `@writeon/ui`, and the kit built on it, follows the WAI-ARIA Authoring Practices:
| Controller | Pattern | Keyboard |
| ---------------------- | ----------------------------- | ---------------------------------------------------- |
| `createToolbar` | Toolbar | One Tab stop, arrow keys, Home/End |
| `createMenu` | Menu button | Arrow keys, Enter/Space, Escape, type to jump |
| `createLinkPopover` | Dialog-like form | `Mod-k`, Escape |
| `createImageDialog` | Modal dialog | Focus moves in and is kept inside, Escape |
| `createBubbleMenu` | Toolbar next to the selection | `Alt-F10` to enter, Escape to return |
| `createSuggestionMenu` | Combobox with a listbox | Focus stays in the editor; arrows, Enter/Tab, Escape |
| `createTooltip` | Tooltip (WCAG 1.4.13) | Shows on focus, Escape dismisses, hoverable |
Toggle buttons use `aria-pressed`, shortcuts are announced with `aria-keyshortcuts`, and a suggestion list announces how many options there are in a polite live region.
## Images
Alt text is required unless the image is marked decorative (`alt=""`). Images without a description carry `data-alt-missing`, so you can point them out.
## Translations
UI texts are English by default. `@writeon/ui/locales/uz` and `@writeon/ui/locales/ru` are included; pass them as `messages`, or override single texts:
```ts
import uz from '@writeon/ui/locales/uz'
createToolbar(editor, { items, messages: uz })
createToolbar(editor, { items, messages: { bold: 'Strong' } })
```
---
Source: /guide/kit.md
# Default kit
`@writeon/kit` is a ready-made UI on top of the headless controllers: one CSS file, a toolbar, and the advanced UI.
## Use it
**React**
```tsx
import { fetchUploader } from '@writeon/advanced'
import { advancedSchema } from '@writeon/advanced/schema'
import { basic } from '@writeon/core/presets'
import '@writeon/kit/style.css'
import { Advanced, Toolbar } from '@writeon/kit/react'
import { EditorContent, useEditor } from '@writeon/react'
const extensions = [...basic(), advancedSchema()]
// Uploads go to your endpoint, which answers with { url }.
const upload = fetchUploader({ url: '/api/images' })
interface Person {
id: string
label: string
}
declare function searchPeople(query: string): Promise
export function Editor() {
const editor = useEditor({ extensions, label: 'Message' })
return (
{/* Loaded on demand, after mount. */}
)
}
```
**Vue**
```vue
```
**Vanilla**
```ts
import { advancedSchema } from '@writeon/advanced/schema'
import { createEditor } from '@writeon/core'
import { basic } from '@writeon/core/presets'
import '@writeon/kit/style.css'
import { mountToolbar } from '@writeon/kit'
//
//
//
//
const root = document.querySelector('.rte-root')
const toolbarHost = document.querySelector('#toolbar')
const element = document.querySelector('#editor')
if (!root || !toolbarHost || !element) {
throw new Error('Missing elements')
}
const editor = createEditor({
element,
extensions: [...basic(), advancedSchema()],
label: 'Notes',
})
mountToolbar(toolbarHost, editor)
// The advanced UI and its behaviour come in a separate chunk.
const { mountAdvanced } = await import('@writeon/kit/advanced')
mountAdvanced(root, editor, { slash: true })
```
- `.rte-root` is the frame; `.rte-content` styles the document (headings, lists, code, tables, task lists, images, mentions) without Tailwind Typography.
- `` / `mountToolbar()`: undo/redo, text style menu, marks, lists, quote, clear formatting, link, tooltips. Options: `messages`, `blockTypes`, `headingLevels`, `link`, `exclude`, `mobile`.
- `` / `mountAdvanced()` needs `advancedSchema()` in the editor. It turns on the advanced behaviour and adds:
- image, table, task list and code block buttons to the toolbar;
- the image dialog, and with `upload`, uploads from the device, drop and paste;
- the `/` command menu (`slash`), `@` mentions (`mentions`), and the selection bubble (`bubble`).
Its code is a separate chunk, loaded after mount.
## Theme
Every colour, radius and font is a CSS variable on `.rte-root`:
```css
.rte-root {
--rte-color-accent: #0d9488;
--rte-color-accent-soft: #ccfbf1;
--rte-color-accent-text: #115e59;
--rte-radius: 4px;
--rte-font: "Inter", sans-serif;
}
```
Dark mode follows the system. To choose explicitly, set `data-theme="dark"` or `data-theme="light"` on `.rte-root` or any ancestor.
Each kit rule has the specificity of one class, so CSS resets such as Tailwind's preflight do not undo it, and any rule of yours with one class overrides it.
## On phones
On touch screens the toolbar docks above the on-screen keyboard while the editor has focus, and scrolls sideways. The selection bubble is off there, because the system shows its own menu. Turn docking off with `mobile: false`.
## Size
About 3 KB of JavaScript and 3.5 KB of CSS (gzip) for the toolbar and styles; the advanced UI is about 11 KB, including Floating UI, loaded on demand.
---
Source: /guide/headless-ui.md
# Headless UI
`@writeon/ui` has the behaviour and accessibility of an editor UI, without any markup or styles. Each controller:
- keeps its state and tells you when it changes (`getState()`, `subscribe()`);
- gives **prop getters** (`getRootProps()`, `getItemProps(id)`…) with the attributes and event handlers to put on your elements;
- exposes state as `data-*` attributes (`data-state="on"`, `data-active`) to style against.
## Plain JavaScript
`applyProps(element, props)` applies prop getter output to a DOM element; call it again after each change.
```ts
import type { Editor } from '@writeon/core'
import {
applyProps,
basicToolbarItems,
createToolbar,
} from '@writeon/ui'
// Your markup, our behaviour: roving tabindex, arrow keys,
// aria-pressed, disabled state from editor.can(), shortcut hints.
export function renderToolbar(
root: HTMLElement,
editor: Editor,
): () => void {
const items = basicToolbarItems()
const toolbar = createToolbar(editor, { items })
// Create the buttons once.
const buttons = toolbar.items.map((item) => {
const button = document.createElement('button')
button.className = 'my-button'
button.textContent = item.label
root.append(button)
return { id: item.id, button }
})
// Apply the current attributes and handlers, on every change.
const render = (): void => {
applyProps(root, toolbar.getRootProps())
for (const { id, button } of buttons) {
applyProps(button, toolbar.getItemProps(id))
}
}
render()
return toolbar.subscribe(render)
}
```
## React and Vue
The adapters wrap each controller in a hook that returns framework props (`useToolbar`, `useMenu`, `useLinkPopover`, `useTooltip`, `useImageDialog`, `useBubbleMenu`, `useSuggestionMenu`).
```tsx
import type { Editor } from '@writeon/core'
import { useToolbar } from '@writeon/react'
import { basicToolbarItems } from '@writeon/ui'
// All the basic buttons, without underline.
const items = basicToolbarItems({ exclude: ['underline'] })
export function MyToolbar({ editor }: { editor: Editor }) {
const toolbar = useToolbar(editor, { items })
// The prop getters bring the ARIA and keyboard support;
// the classes are yours (Tailwind here).
return (
{toolbar.items.map((item) => (
))}
)
}
```
## Positioning
Controllers never position anything. Popups that follow the text (bubble, suggestion lists) expose a `reference` compatible with [Floating UI](https://floating-ui.com)'s virtual elements:
```ts
import { autoUpdate, computePosition, flip, offset, shift } from '@floating-ui/dom'
const stop = autoUpdate(bubble.reference, element, () =>
computePosition(bubble.reference, element, {
strategy: 'fixed',
placement: 'top',
middleware: [offset(8), flip(), shift({ padding: 8 })],
}).then(({ x, y }) => Object.assign(element.style, { left: `${x}px`, top: `${y}px` })),
)
```
See [Your own toolbar](/recipes/custom-toolbar.md) for a complete example.
---
Source: /guide/ai.md
# Working with AI assistants
The editor has no AI inside it. These docs are made to be read by coding assistants (Claude Code, Cursor, Copilot and others), so that the code they write for you uses the real API.
## Docs in plain text
| File | What it is |
| --- | --- |
| [`/llms.txt`](/llms.txt) | An index of every page, with a one-line summary each ([llmstxt.org](https://llmstxt.org) format) |
| [`/llms-full.txt`](/llms-full.txt) | The whole guide, the recipes and the full API reference in one file, with all code examples inlined |
| `node_modules/@writeon/core/llms-full.txt` | The same file, installed with the package: always the docs of the version you use, no site needed |
| `/.md` | Any page as clean Markdown: add `.md` to its address, e.g. [`/guide/kit.md`](/guide/kit.md) |
They are generated from the same sources as this site on every build (`pnpm docs:build`; not in `docs:dev`), so they never fall behind it. They are in English only.
Assistants that read `node_modules` find the installed copy on their own (every package's README points to it). Otherwise give your assistant `llms-full.txt`, or `llms.txt` when it can fetch pages itself.
Error messages are written for the same readers: each one says what to change, e.g. which extension to add or how to call a command.
## AGENTS.md
Assistants read a project file of standing instructions: `AGENTS.md`, `CLAUDE.md` or the equivalent of your tool. Copy this block into it, so every session starts with the rules that matter most:
```md
## Rich text editor: Writeon
This project uses Writeon (`@writeon/*`), a headless rich text editor on ProseMirror.
Full documentation for the installed version: `node_modules/@writeon/core/llms-full.txt`
(index: `llms.txt` next to it; also on the docs site). Read it before writing editor code;
do not guess the API. Error messages say how to fix the mistake: follow them.
Packages: `@writeon/core` (editor, `/presets`, `/commands`, `/extension`),
`@writeon/react`, `@writeon/vue`, `@writeon/ui` (headless controllers),
`@writeon/kit` (ready-made UI, `/react`, `/vue`, `/advanced`),
`@writeon/advanced` (+ `/schema`), `@writeon/html`, `@writeon/markdown`,
`@writeon/server`.
Rules:
- Store the document as JSON: `editor.getJSON()` (`DocJSON`). HTML and Markdown are
derived from it (`toHTML`, `toMarkdown`), never the other way round.
- Define the extensions once, in one shared array, and use the same array in the
editor, in `@writeon/server` and in `@writeon/html` / `@writeon/markdown`.
- Never trust what the browser sends: on the server, `validate(body, { extensions })`
first, save `result.doc`, render with `toSafeHTML(result.doc, { extensions })`.
- Every editor needs `label` (a string or `{ labelledBy }`): it names the field for
screen readers.
- Commands are factories: `editor.run(toggleBold())`, `editor.can(toggleBold())`;
several in one undo step with `editor.transaction((tx) => { … })`.
- Advanced features: include `advancedSchema()` in the extensions from the start;
load the behaviour later with `editor.enable(() => import('@writeon/advanced'))`,
or use the kit's `` / `mountAdvanced()`.
- `editor.pm` (raw ProseMirror) is not a stable API; prefer commands, snapshots
(`getSnapshot()`, `subscribe()`) and extensions (`defineExtension`).
- Save with `debounce()` from `@writeon/core` and call `.flush()` on `pagehide`.
```
Every rule in it is explained in this guide: [saving](/guide/saving.md), [security](/guide/security.md), [core concepts](/guide/concepts.md), [basic and advanced](/guide/basic-and-advanced.md).
## Types and JSDoc
Every public function, type and option has JSDoc, often with an example. Assistants that read your `node_modules` or use your editor's language server see it too, for the exact version you installed.
---
Source: /recipes/upload-s3.md
# Image uploads to S3
Uploading straight from the browser to object storage (S3, R2, GCS) keeps large files off your app server. Your backend only signs the upload.
```ts
import { imageUpload, presignedUploader } from '@writeon/advanced'
import type { Editor } from '@writeon/core'
interface SignedUpload {
uploadUrl: string
publicUrl: string
}
// Your backend checks the type and size, signs a PUT for one
// object key and says where the file can be loaded from later.
async function signUpload(
file: File,
signal: AbortSignal,
): Promise {
const response = await fetch('/api/images/sign', {
method: 'POST',
headers: { 'Content-Type': 'application/json' },
body: JSON.stringify({ type: file.type, size: file.size }),
signal,
})
if (!response.ok) throw new Error('Could not sign the upload')
return (await response.json()) as SignedUpload
}
export async function enableUploads(editor: Editor): Promise {
await editor.enable([
imageUpload({
upload: presignedUploader({ getTarget: signUpload }),
// 5 MB
maxSize: 5 * 1024 * 1024,
onError: (error) => console.warn(error.code, error.file.name),
}),
])
}
```
What happens:
1. The user drops, pastes or picks an image. `imageUpload()` checks the type (PNG, JPEG, GIF and WebP by default, never SVG) and size, and shows a placeholder with progress where the image will go.
2. `presignedUploader` asks your backend for a target, then `PUT`s the file there, reporting progress.
3. The placeholder is replaced by the image with `publicUrl`. Its alt text is `null`, so it is marked as needing a description.
On failure the placeholder disappears and `onError` gets an `ImageUploadError` with a `code` (`type`, `size`, `upload`, `src`) and the `file`. The default kit shows and announces these errors for you.
## The backend
Sign one object key per request, never a prefix, and check the type and size you are told against what you allow. Make the signature require the `Content-Type` header, so the stored object cannot be served as HTML.
A plain multipart endpoint works too: `fetchUploader({ url: '/api/images' })` expects a JSON response with `url`.
---
Source: /recipes/mentions.md
# Mentions from your backend
With the default kit, pass a search function as `mentions`:
```ts
import type { Editor } from '@writeon/core'
import type { KitMention } from '@writeon/kit'
interface Person {
id: string
name: string
title?: string
}
// Called with what was typed after "@".
// Answers to an older query are ignored, so a slow request
// never shows stale people.
export async function searchPeople(
query: string,
): Promise {
const q = encodeURIComponent(query)
const response = await fetch(`/api/people?q=${q}&limit=8`)
if (!response.ok) return []
const people = (await response.json()) as Person[]
return people.map((person) => ({
id: person.id,
label: person.name,
...(person.title ? { description: person.title } : {}),
}))
}
export async function mountWithMentions(
root: HTMLElement,
editor: Editor,
) {
const { mountAdvanced } = await import('@writeon/kit/advanced')
return mountAdvanced(root, editor, { mentions: searchPeople })
}
```
- The menu opens after `@` at the start of a word and closes on a space, Escape, or when nothing matches.
- Choosing a person inserts a mention node with `id` and `label`; the `id` is what you store and resolve later. Both are checked by the schema.
- Results are announced to screen readers ("5 suggestions"), and focus never leaves the editor.
Mentions are plain data in the document. To notify people, read the mention nodes from the validated document on the server:
```ts
import type { NodeJSON } from '@writeon/core'
function mentionedIds(node: NodeJSON, out = new Set()): Set {
if (node.type === 'mention' && typeof node.attrs?.id === 'string') out.add(node.attrs.id)
for (const child of node.content ?? []) mentionedIds(child, out)
return out
}
```
Without the kit, use `createSuggestionMenu(editor, { char: '@', items, label })` from `@writeon/ui` with `insertMention()` from `@writeon/advanced`.
---
Source: /recipes/custom-blocks.md
# Custom blocks
Some content is not text: a list of pickup branches, a product carousel, a map. Store it as a **custom block** (an embed) and let your front end render the component.
```ts
import {
embed,
insertEmbed,
updateEmbed,
} from '@writeon/advanced/embed'
import { createEditor } from '@writeon/core'
import { basic } from '@writeon/core/presets'
// The blocks your front end knows how to render.
export const extensions = [
...basic(),
embed({
kinds: [
{ id: 'pickup-branches', label: 'Pickup branches' },
{
id: 'product-list',
label: 'Products',
props: {
category: {
type: 'string',
label: 'Category',
required: true,
},
limit: {
type: 'number',
label: 'How many',
integer: true,
min: 1,
max: 24,
default: 8,
},
},
},
],
}),
]
const editor = createEditor({ extensions, label: 'Page' })
// Fails (returns false) while a required field is missing.
editor.run(insertEmbed('product-list', { category: 'drills' }))
// With the block selected: change its settings.
editor.run(updateEmbed({ category: 'saws', limit: 12 }))
```
- **The document stores** `{ type: 'embed', attrs: { kind: 'product-list', props: { category: 'drills', limit: 8 } } }`. The user cannot break it by typing: the editor shows it as a `[[Products]]` placeholder that can be selected, moved and deleted.
- **Your front end** finds the block by `kind`, in the JSON or in the HTML from `toHTML()`: `
[[Products]]
`. Replace that element with the component; the `[[Products]]` text is the fallback without JavaScript.
- **Settings** (`props`) are typed fields: `string`, `number` (with `min`, `max`, `integer`), `boolean` and `enum` (fixed `options`), each `required` or with a `default`. `embedPropsError(kind, props)` explains what is wrong, for your form.
- **On the server**, `validate()` removes a block whose kind is not configured or whose props do not fit it (unknown fields, wrong types, a missing required field). Props are always a flat object of plain values.
- **Markdown**: `[[product-list {"category":"drills","limit":8}]]` on its own line, read back by `fromMarkdown()`.
- **UI**: `embedKinds(state)` lists the kinds for your menu; `selectedEmbed(state)` gives the selected block for a settings form.
---
Source: /recipes/custom-extension.md
# Your own extension
An extension is a factory made with `defineExtension()`. This one adds a highlight mark with a command, a shortcut and a Markdown-style input rule:
```ts
import { type Command, createEditor } from '@writeon/core'
import { defineExtension, markInputRule } from '@writeon/core/extension'
import { basic } from '@writeon/core/presets'
import { toggleMark } from 'prosemirror-commands'
// Toggles the highlight mark.
// A factory, like every built-in command.
export function toggleHighlight(): Command {
return (state, dispatch) => {
const type = state.schema.marks.highlight
return type ? toggleMark(type)(state, dispatch) : false
}
}
// Typing ==text== highlights the text.
const doubleEquals = /(?:^|[^=])(==([^=\s](/recipes/?:[^=]*[^=\s].md)?)==)$/
// Highlighted text: in HTML, Mod-Shift-h or ==text==.
export const highlight = defineExtension(() => ({
name: 'highlight',
marks: {
highlight: {
parseDOM: [{ tag: 'mark' }],
toDOM: () => ['mark', 0],
},
},
keymap: () => ({ 'Mod-Shift-h': toggleHighlight() }),
inputRules: ({ schema }) => {
const type = schema.marks.highlight
return type ? [markInputRule(doubleEquals, type)] : []
},
}))
const editor = createEditor({
extensions: [...basic(), highlight()],
label: 'Notes',
})
editor.run(toggleHighlight())
```
The parts of an extension:
| Field | What it does |
| ----------------- | ------------------------------------------------------------- |
| `name` | Unique; two extensions with the same name are an error |
| `nodes`, `marks` | ProseMirror node and mark specs added to the schema |
| `keymap(ctx)` | Shortcuts to commands (`Mod` is Cmd on Apple, Ctrl elsewhere) |
| `inputRules(ctx)` | Typed patterns that trigger changes |
| `plugins(ctx)` | Any ProseMirror plugins |
| `requires` | Names of extensions that must also be present |
| `priority` | Higher runs first for keymaps and plugins (default 100) |
Remember:
- **Add it on the server too**, or `validate()` removes the new mark as unknown.
- Commands are factories returning a command, like the built-in ones, so `editor.run(toggleHighlight())` and `editor.can(toggleHighlight())` read the same.
- An extension with nodes or marks must be passed to `createEditor()`. `editor.enable()` only adds behaviour; for that, split the extension into a schema part and a behaviour part, like `@writeon/advanced` does.
---
Source: /recipes/custom-toolbar.md
# Your own toolbar
The kit is optional. With `@writeon/ui` you keep the keyboard support and ARIA and write your own markup, for example with Tailwind:
```tsx
import type { Editor } from '@writeon/core'
import { useToolbar } from '@writeon/react'
import { basicToolbarItems } from '@writeon/ui'
// All the basic buttons, without underline.
const items = basicToolbarItems({ exclude: ['underline'] })
export function MyToolbar({ editor }: { editor: Editor }) {
const toolbar = useToolbar(editor, { items })
// The prop getters bring the ARIA and keyboard support;
// the classes are yours (Tailwind here).
return (
{toolbar.items.map((item) => (
))}
)
}
```
What you get from `getItemProps()`: `type="button"`, `aria-label`, `aria-pressed` for toggles, `aria-keyshortcuts`, `disabled` when the command cannot run here, the roving `tabindex`, and handlers that keep the editor's selection when a button is clicked.
To add something that is not a command button (a link button, a menu trigger) to the arrow-key navigation, use `getCustomItemProps(id, props)`.
For plain JavaScript, see [Headless UI](/guide/headless-ui.md#plain-javascript).
---
Source: /api/index.md
# Packages
Each package links to its [API reference](/api/reference.md), generated from the same JSDoc your editor shows on hover. Every public subpath (such as `@writeon/core/commands`) has its own page.
| Package | What it is |
| -------------------- | --------------------------------------------------------------------------------------------------------------------- |
| [`@writeon/core`](/api/core/reference.md) | `createEditor`, the extension system, `basic()` preset (`/presets`), commands (`/commands`), `debounce`, `migrateDoc` |
| [`@writeon/react`](/api/react/reference.md) | `useEditor`, `useEditorState`, ``, UI hooks |
| [`@writeon/vue`](/api/vue/reference.md) | `useEditor`, `useEditorState`, ``, UI composables |
| [`@writeon/ui`](/api/ui/reference.md) | Headless controllers: toolbar, menu, link, tooltip, image dialog, bubble, suggestions; locales `uz`, `ru` |
| [`@writeon/kit`](/api/kit/reference.md) | Default kit: `style.css`, `mountToolbar`, `/advanced`, `/react`, `/vue` |
| [`@writeon/advanced`](/api/advanced/reference.md) | Task lists, code blocks, images and uploads, tables, mentions; `/schema` |
| [`@writeon/html`](/api/html/reference.md) | `toHTML`, `fromHTML`, `officePaste` |
| [`@writeon/markdown`](/api/markdown/reference.md) | `toMarkdown`, `fromMarkdown`, `/paste` |
| [`@writeon/server`](/api/server/reference.md) | `validate`, `toSafeHTML` |
---
Source: /api/advanced/reference.md
# @writeon/advanced
Advanced editing behaviour: task lists, code blocks, image uploads, tables
and mentions. Load it lazily and turn it on with
`editor.enable(advanced())`; the node types come from `@mfsv-
rte/advanced/schema`.
## Classes
- [ImageUploadError](classes/ImageUploadError.md)
## Interfaces
- [FetchUploaderOptions](interfaces/FetchUploaderOptions.md)
- [ImageAttrs](interfaces/ImageAttrs.md)
- [ImageUploadOptions](interfaces/ImageUploadOptions.md)
- [InsertTableOptions](interfaces/InsertTableOptions.md)
- [MentionAttrs](interfaces/MentionAttrs.md)
- [PresignedTarget](interfaces/PresignedTarget.md)
- [PresignedUploaderOptions](interfaces/PresignedUploaderOptions.md)
- [UploadContext](interfaces/UploadContext.md)
## Type Aliases
- [ImageUploadErrorCode](type-aliases/ImageUploadErrorCode.md)
- [UploadFn](type-aliases/UploadFn.md)
- [UploadResult](type-aliases/UploadResult.md)
## Variables
- [addColumnAfter](variables/addColumnAfter.md)
- [addColumnBefore](variables/addColumnBefore.md)
- [addRowAfter](variables/addRowAfter.md)
- [addRowBefore](variables/addRowBefore.md)
- [codeBlock](variables/codeBlock.md)
- [default](variables/default.md)
- [deleteColumn](variables/deleteColumn.md)
- [deleteRow](variables/deleteRow.md)
- [deleteTable](variables/deleteTable.md)
- [imageUpload](variables/imageUpload.md)
- [mergeCells](variables/mergeCells.md)
- [splitCell](variables/splitCell.md)
- [table](variables/table.md)
- [taskList](variables/taskList.md)
- [toggleHeaderRow](variables/toggleHeaderRow.md)
## Functions
- [advanced](functions/advanced.md)
- [fetchUploader](functions/fetchUploader.md)
- [insertImage](functions/insertImage.md)
- [insertMention](functions/insertMention.md)
- [insertTable](functions/insertTable.md)
- [presignedUploader](functions/presignedUploader.md)
- [setCodeBlockLanguage](functions/setCodeBlockLanguage.md)
- [toggleCodeBlock](functions/toggleCodeBlock.md)
- [toggleTaskChecked](functions/toggleTaskChecked.md)
- [toggleTaskList](functions/toggleTaskList.md)
- [updateImage](functions/updateImage.md)
- [uploadImages](functions/uploadImages.md)
## References
### advancedSchema
Re-exports [advancedSchema](schema/variables/advancedSchema.md)
***
### AdvancedSchemaOptions
Re-exports [AdvancedSchemaOptions](schema/interfaces/AdvancedSchemaOptions.md)
***
### ImageSourceOptions
Re-exports [ImageSourceOptions](schema/interfaces/ImageSourceOptions.md)
***
### isAllowedImageSrc
Re-exports [isAllowedImageSrc](schema/functions/isAllowedImageSrc.md)
---
Source: /api/advanced/classes/ImageUploadError.md
# Class: ImageUploadError
A refused or failed image upload, passed to `ImageUploadOptions.onError`.
## Extends
- `Error`
## Constructors
### Constructor
```ts
new ImageUploadError(
code,
file,
message,
options?
): ImageUploadError;
```
#### Parameters
| Parameter | Type |
| ------ | ------ |
| `code` | [`ImageUploadErrorCode`](../type-aliases/ImageUploadErrorCode.md) |
| `file` | `File` |
| `message` | `string` |
| `options?` | \{ `cause?`: `unknown`; \} |
| `options.cause?` | `unknown` |
#### Returns
`ImageUploadError`
#### Overrides
`Error.constructor`
## Properties
### code
```ts
readonly code: ImageUploadErrorCode;
```
Why the file was refused or failed.
***
### file
```ts
readonly file: File;
```
The file concerned.
---
Source: /api/advanced/interfaces/FetchUploaderOptions.md
# Interface: FetchUploaderOptions
Options for `fetchUploader()`.
## Properties
| Property | Type | Description |
| ------ | ------ | ------ |
| `field?` | `string` | Form field name for the file. Default "file". |
| `headers?` | `Record`\<`string`, `string`\> | Extra headers, e.g. a CSRF token. |
| `parse?` | (`json`) => [`UploadResult`](../type-aliases/UploadResult.md) | Read the URL from the JSON response. Default: `json.url`. |
| `url` | `string` | Endpoint that receives a multipart POST. |
| `withCredentials?` | `boolean` | Send cookies to another origin. Default false. |
---
Source: /api/advanced/interfaces/ImageAttrs.md
# Interface: ImageAttrs
Attributes of an image node.
## Properties
| Property | Type | Description |
| ------ | ------ | ------ |
| `alt?` | `string` \| `null` | Text alternative. `""` marks a decorative image; leave it out only if you will ask for it later. |
| `height?` | `number` \| `null` | Height in pixels (1–20000). |
| `src` | `string` | Image URL. Must pass `isAllowedImageSrc()`. |
| `title?` | `string` \| `null` | Optional `title` attribute. |
| `width?` | `number` \| `null` | Width in pixels (1–20000), so the page does not jump while loading. |
---
Source: /api/advanced/interfaces/ImageUploadOptions.md
# Interface: ImageUploadOptions
Options for `imageUpload()`.
## Properties
| Property | Type | Description |
| ------ | ------ | ------ |
| `accept?` | readonly `string`[] | Accepted MIME types. Default PNG, JPEG, GIF, WebP. SVG is left out on purpose: an SVG served from your domain can run scripts. |
| `label?` | `string` | Accessible name of the progress placeholder. Default "Uploading image". |
| `maxSize?` | `number` | Largest accepted file in bytes. Default 10 MB. |
| `onError?` | (`error`) => `void` | Called for every refused or failed file. The placeholder is already gone. |
| `upload` | [`UploadFn`](../type-aliases/UploadFn.md) | Your upload. See `fetchUploader()` and `presignedUploader()` for ready-made ones. |
---
Source: /api/advanced/interfaces/InsertTableOptions.md
# Interface: InsertTableOptions
Options for `insertTable()`.
## Properties
| Property | Type | Description |
| ------ | ------ | ------ |
| `cols?` | `number` | Default 3. |
| `rows?` | `number` | Default 3. |
| `withHeaderRow?` | `boolean` | First row as header cells (`
`). Default true: tables need headers for screen readers. |
---
Source: /api/advanced/interfaces/MentionAttrs.md
# Interface: MentionAttrs
Attributes of a mention node.
## Properties
| Property | Type | Description |
| ------ | ------ | ------ |
| `id` | `string` | Your stable identifier (user id, handle). Stored in the document. |
| `label` | `string` | What is shown after `@`. |
---
Source: /api/advanced/interfaces/PresignedTarget.md
# Interface: PresignedTarget
Upload target returned by `PresignedUploaderOptions.getTarget`.
## Properties
| Property | Type | Description |
| ------ | ------ | ------ |
| `headers?` | `Record`\<`string`, `string`\> | Headers the signature requires (e.g. Content-Type). |
| `method?` | `"PUT"` \| `"POST"` | Default "PUT". |
| `publicUrl` | `string` | Where the stored file can be loaded from afterwards. |
| `uploadUrl` | `string` | Where to send the file (e.g. an S3 presigned URL). |
---
Source: /api/advanced/interfaces/PresignedUploaderOptions.md
# Interface: PresignedUploaderOptions
Options for `presignedUploader()`.
## Properties
| Property | Type | Description |
| ------ | ------ | ------ |
| `getTarget` | (`file`, `signal`) => `Promise`\<[`PresignedTarget`](PresignedTarget.md)\> | Ask your backend for a signed target for this file. |
---
Source: /api/advanced/interfaces/UploadContext.md
# Interface: UploadContext
Passed to your `UploadFn` with each file.
## Properties
| Property | Type | Description |
| ------ | ------ | ------ |
| `onProgress` | (`fraction`) => `void` | Report progress between 0 and 1. |
| `signal` | `AbortSignal` | Aborted when the editor is destroyed or the upload is cancelled. |
---
Source: /api/advanced/type-aliases/ImageUploadErrorCode.md
# Type Alias: ImageUploadErrorCode
```ts
type ImageUploadErrorCode = "type" | "size" | "upload" | "src";
```
Why a file was refused or failed: `'type'` not an accepted MIME type,
`'size'` too large, `'upload'` the upload rejected, `'src'` the schema
refused the returned URL.
---
Source: /api/advanced/type-aliases/UploadFn.md
# Type Alias: UploadFn
```ts
type UploadFn = (file, context) => Promise;
```
Store a file and return where it can be loaded from.
## Parameters
| Parameter | Type |
| ------ | ------ |
| `file` | `File` |
| `context` | [`UploadContext`](../interfaces/UploadContext.md) |
## Returns
`Promise`\<[`UploadResult`](UploadResult.md)\>
---
Source: /api/advanced/type-aliases/UploadResult.md
# Type Alias: UploadResult
```ts
type UploadResult =
| string
| {
height?: number;
src: string;
width?: number;
};
```
What an upload resolves to: the stored file's URL, optionally with its size.
## Union Members
`string`
***
### Type Literal
```ts
{
height?: number;
src: string;
width?: number;
}
```
#### height?
```ts
height?: number;
```
Height in pixels. Default: measured from the file, if ready in time.
#### src
```ts
src: string;
```
URL of the stored file.
#### width?
```ts
width?: number;
```
Width in pixels. Default: measured from the file, if ready in time.
---
Source: /api/advanced/variables/addColumnAfter.md
# Variable: addColumnAfter
```ts
const addColumnAfter: () => Command;
```
Add a column right of the current one.
## Returns
[`Command`](../../core/type-aliases/Command.md)
---
Source: /api/advanced/variables/addColumnBefore.md
# Variable: addColumnBefore
```ts
const addColumnBefore: () => Command;
```
Add a column left of the current one.
## Returns
[`Command`](../../core/type-aliases/Command.md)
---
Source: /api/advanced/variables/addRowAfter.md
# Variable: addRowAfter
```ts
const addRowAfter: () => Command;
```
Add a row below the current one.
## Returns
[`Command`](../../core/type-aliases/Command.md)
---
Source: /api/advanced/variables/addRowBefore.md
# Variable: addRowBefore
```ts
const addRowBefore: () => Command;
```
Add a row above the current one.
## Returns
[`Command`](../../core/type-aliases/Command.md)
---
Source: /api/advanced/variables/codeBlock.md
# Variable: codeBlock
```ts
const codeBlock: () => Extension;
```
Code block behaviour: ```` ``` ```` (optionally with a language, ```` ```ts ````)
plus space starts one, `Mod-Alt-c` toggles, Enter adds a line, Enter on the
second empty line at the end or `Mod-Enter` leaves it. Tab is not captured,
so keyboard users can always move focus out of the editor.
## Returns
[`Extension`](../../core/interfaces/Extension.md)
---
Source: /api/advanced/variables/default.md
# Variable: default
```ts
const default: Extension[];
```
The default export, so `editor.enable(() => import('@writeon/advanced'))` works.
---
Source: /api/advanced/variables/deleteColumn.md
# Variable: deleteColumn
```ts
const deleteColumn: () => Command;
```
Delete the current column(s).
## Returns
[`Command`](../../core/type-aliases/Command.md)
---
Source: /api/advanced/variables/deleteRow.md
# Variable: deleteRow
```ts
const deleteRow: () => Command;
```
Delete the current row(s).
## Returns
[`Command`](../../core/type-aliases/Command.md)
---
Source: /api/advanced/variables/deleteTable.md
# Variable: deleteTable
```ts
const deleteTable: () => Command;
```
Delete the whole table.
## Returns
[`Command`](../../core/type-aliases/Command.md)
---
Source: /api/advanced/variables/imageUpload.md
# Variable: imageUpload
```ts
const imageUpload: (options) => Extension;
```
Upload images that are pasted, dropped or chosen with a file picker
(`uploadImages(editor, files)`), showing an accessible progress
placeholder (`[data-rte-upload]`, `role="progressbar"`, CSS variable
`--rte-upload-progress`) where each will appear. Requires `advancedSchema()`.
## Parameters
| Parameter | Type |
| ------ | ------ |
| `options` | [`ImageUploadOptions`](../interfaces/ImageUploadOptions.md) |
## Returns
[`Extension`](../../core/interfaces/Extension.md)
## Example
```ts
imageUpload({
upload: fetchUploader({ url: '/api/upload' }),
onError: (error) => toast(error.message),
})
```
---
Source: /api/advanced/variables/mergeCells.md
# Variable: mergeCells
```ts
const mergeCells: () => Command;
```
Merge the selected cells into one.
## Returns
[`Command`](../../core/type-aliases/Command.md)
---
Source: /api/advanced/variables/splitCell.md
# Variable: splitCell
```ts
const splitCell: () => Command;
```
Split a merged cell back into single cells.
## Returns
[`Command`](../../core/type-aliases/Command.md)
---
Source: /api/advanced/variables/table.md
# Variable: table
```ts
const table: () => Extension;
```
Table behaviour: cell selection (drag or Shift+arrows), Tab / Shift-Tab to
move between cells, and the table commands. Tab leaves the table from the
last cell as usual, so keyboard users are never trapped. Requires
`advancedSchema()`.
## Returns
[`Extension`](../../core/interfaces/Extension.md)
---
Source: /api/advanced/variables/taskList.md
# Variable: taskList
```ts
const taskList: () => Extension;
```
Task list behaviour: `[ ] ` or `[x] ` starts one, Enter adds an item,
Tab / Shift-Tab nest, `Mod-Enter` checks the current item, `Mod-Shift-9`
toggles the list. Checkboxes become clickable and are labelled by their
item's text.
## Returns
[`Extension`](../../core/interfaces/Extension.md)
---
Source: /api/advanced/variables/toggleHeaderRow.md
# Variable: toggleHeaderRow
```ts
const toggleHeaderRow: () => Command;
```
Turn the first row into header cells (`
`) or back.
## Returns
[`Command`](../../core/type-aliases/Command.md)
---
Source: /api/advanced/functions/advanced.md
# Function: advanced()
```ts
function advanced(): Extension[];
```
All advanced behaviour. Pair it with `advancedSchema()` in `createEditor()`.
## Returns
[`Extension`](../../core/interfaces/Extension.md)[]
## Example
```ts
// eager
createEditor({ extensions: [...basic(), advancedSchema(), ...advanced()], label })
// or on demand, keeping the document, undo history and selection
createEditor({ extensions: [...basic(), advancedSchema()], label })
await editor.enable(() => import('@writeon/advanced'))
```
---
Source: /api/advanced/functions/fetchUploader.md
# Function: fetchUploader()
```ts
function fetchUploader(options): UploadFn;
```
Upload as `multipart/form-data` POST and read the stored file's URL from
the JSON response (`{ "url": "…" }` by default). Reports progress.
## Parameters
| Parameter | Type |
| ------ | ------ |
| `options` | [`FetchUploaderOptions`](../interfaces/FetchUploaderOptions.md) |
## Returns
[`UploadFn`](../type-aliases/UploadFn.md)
## Example
```ts
imageUpload({ upload: fetchUploader({ url: '/api/images', headers: { 'X-CSRF-Token': token } }) })
```
---
Source: /api/advanced/functions/insertImage.md
# Function: insertImage()
```ts
function insertImage(attrs): Command;
```
Insert an image at the selection. Returns false when the schema refuses
the `src` (unsafe protocol, SVG data URL, base64 not enabled). Requires `advancedSchema()`.
## Parameters
| Parameter | Type |
| ------ | ------ |
| `attrs` | [`ImageAttrs`](../interfaces/ImageAttrs.md) |
## Returns
[`Command`](../../core/type-aliases/Command.md)
---
Source: /api/advanced/functions/insertMention.md
# Function: insertMention()
```ts
function insertMention(attrs): Command;
```
Insert a mention at the selection, followed by a space so typing can go
on. Use it as a suggestion item's command. Requires `advancedSchema()`.
## Parameters
| Parameter | Type |
| ------ | ------ |
| `attrs` | [`MentionAttrs`](../interfaces/MentionAttrs.md) |
## Returns
[`Command`](../../core/type-aliases/Command.md)
---
Source: /api/advanced/functions/insertTable.md
# Function: insertTable()
```ts
function insertTable(options?): Command;
```
Insert an empty table at the selection and put the cursor in its first
cell. Requires `advancedSchema()`.
## Parameters
| Parameter | Type |
| ------ | ------ |
| `options?` | [`InsertTableOptions`](../interfaces/InsertTableOptions.md) |
## Returns
[`Command`](../../core/type-aliases/Command.md)
---
Source: /api/advanced/functions/presignedUploader.md
# Function: presignedUploader()
```ts
function presignedUploader(options): UploadFn;
```
Upload straight to object storage (S3, R2, GCS…) with a presigned URL
from your backend, then use the returned public URL. Reports progress.
## Parameters
| Parameter | Type |
| ------ | ------ |
| `options` | [`PresignedUploaderOptions`](../interfaces/PresignedUploaderOptions.md) |
## Returns
[`UploadFn`](../type-aliases/UploadFn.md)
## Example
```ts
imageUpload({
upload: presignedUploader({
getTarget: (file) => api.post('/images/sign', { type: file.type, size: file.size }),
}),
})
```
---
Source: /api/advanced/functions/setCodeBlockLanguage.md
# Function: setCodeBlockLanguage()
```ts
function setCodeBlockLanguage(language): Command;
```
Change the language of the code block at the selection. Requires `advancedSchema()`.
## Parameters
| Parameter | Type |
| ------ | ------ |
| `language` | `string` \| `null` |
## Returns
[`Command`](../../core/type-aliases/Command.md)
---
Source: /api/advanced/functions/toggleCodeBlock.md
# Function: toggleCodeBlock()
```ts
function toggleCodeBlock(language?): Command;
```
Code block on/off; `language` sets its language (e.g. "ts") when turning
it on. Requires `advancedSchema()`.
## Parameters
| Parameter | Type | Default value |
| ------ | ------ | ------ |
| `language?` | `string` \| `null` | `null` |
## Returns
[`Command`](../../core/type-aliases/Command.md)
---
Source: /api/advanced/functions/toggleTaskChecked.md
# Function: toggleTaskChecked()
```ts
function toggleTaskChecked(pos?): Command;
```
Check or uncheck the task item at the selection (or at `pos`). Requires `advancedSchema()`.
## Parameters
| Parameter | Type |
| ------ | ------ |
| `pos?` | `number` |
## Returns
[`Command`](../../core/type-aliases/Command.md)
---
Source: /api/advanced/functions/toggleTaskList.md
# Function: toggleTaskList()
```ts
function toggleTaskList(): Command;
```
Task list on/off. Inside a bullet or numbered list it converts that list
(keeping the items); inside a task list it lifts the item out. Requires
`advancedSchema()`.
## Returns
[`Command`](../../core/type-aliases/Command.md)
---
Source: /api/advanced/functions/updateImage.md
# Function: updateImage()
```ts
function updateImage(attrs): Command;
```
Change attributes (e.g. `alt`) of the selected image. Requires `advancedSchema()`.
## Parameters
| Parameter | Type |
| ------ | ------ |
| `attrs` | `Partial`\<[`ImageAttrs`](../interfaces/ImageAttrs.md)\> |
## Returns
[`Command`](../../core/type-aliases/Command.md)
---
Source: /api/advanced/functions/uploadImages.md
# Function: uploadImages()
```ts
function uploadImages(editor, files): boolean;
```
Upload files chosen elsewhere (a file input, a button) at the selection,
through the editor's `imageUpload()` extension. Returns false when the
editor is not mounted or has no `imageUpload()`.
## Parameters
| Parameter | Type |
| ------ | ------ |
| `editor` | [`Editor`](../../core/interfaces/Editor.md) |
| `files` | readonly `File`[] \| `FileList` \| `null` |
## Returns
`boolean`
## Example
```ts
input.addEventListener('change', () => uploadImages(editor, input.files))
```
---
Source: /api/advanced/embed/reference.md
# @writeon/advanced/embed
Custom blocks ("embeds"): a block the editor shows as a placeholder and
your front end replaces with its own component, such as a list of pickup
branches. Documents store `{ type: 'embed', attrs: { kind, props } }`; the
kinds and their props are configured, so the server (`validate()`) drops
anything else. Small and eager: add `embed()` to the editor from the start.
## Interfaces
- [EmbedBooleanProp](interfaces/EmbedBooleanProp.md)
- [EmbedEnumProp](interfaces/EmbedEnumProp.md)
- [EmbedKind](interfaces/EmbedKind.md)
- [EmbedNumberProp](interfaces/EmbedNumberProp.md)
- [EmbedOption](interfaces/EmbedOption.md)
- [EmbedOptions](interfaces/EmbedOptions.md)
- [EmbedStringProp](interfaces/EmbedStringProp.md)
- [SelectedEmbed](interfaces/SelectedEmbed.md)
## Type Aliases
- [EmbedProps](type-aliases/EmbedProps.md)
- [EmbedPropSpec](type-aliases/EmbedPropSpec.md)
- [EmbedPropValue](type-aliases/EmbedPropValue.md)
## Variables
- [embed](variables/embed.md)
## Functions
- [embedDefaults](functions/embedDefaults.md)
- [embedKinds](functions/embedKinds.md)
- [embedPropsError](functions/embedPropsError.md)
- [insertEmbed](functions/insertEmbed.md)
- [selectedEmbed](functions/selectedEmbed.md)
- [updateEmbed](functions/updateEmbed.md)
---
Source: /api/advanced/embed/interfaces/EmbedBooleanProp.md
# Interface: EmbedBooleanProp
A yes/no field of an embed.
## Properties
| Property | Type | Description |
| ------ | ------ | ------ |
| `default?` | `boolean` | Value for a new embed. Default false. |
| `label` | `string` | Shown in the form. |
| `type` | `"boolean"` | A yes/no field. |
---
Source: /api/advanced/embed/interfaces/EmbedEnumProp.md
# Interface: EmbedEnumProp
A choice from fixed options.
## Properties
| Property | Type | Description |
| ------ | ------ | ------ |
| `default?` | `string` | Value for a new embed. |
| `label` | `string` | Shown in the form. |
| `options` | readonly [`EmbedOption`](EmbedOption.md)[] | The choices: the stored value and its label. |
| `required?` | `boolean` | Must be chosen. |
| `type` | `"enum"` | A choice from fixed options. |
---
Source: /api/advanced/embed/interfaces/EmbedKind.md
# Interface: EmbedKind
A kind of block the user can insert.
## Properties
| Property | Type | Description |
| ------ | ------ | ------ |
| `description?` | `string` | A second line in the menu. |
| `id` | `string` | Stored in the document, e.g. `'pickup-branches'`. Letters, digits, `-` and `_`. |
| `label` | `string` | Shown in the menu and in the editor, e.g. `'Olib ketish filiallari'`. |
| `props?` | `Readonly`\<`Record`\<`string`, [`EmbedPropSpec`](../type-aliases/EmbedPropSpec.md)\>\> | Settings the user fills in, by field name (letters, digits, `_`). |
---
Source: /api/advanced/embed/interfaces/EmbedNumberProp.md
# Interface: EmbedNumberProp
A number field of an embed.
## Properties
| Property | Type | Description |
| ------ | ------ | ------ |
| `default?` | `number` | Value for a new embed. |
| `integer?` | `boolean` | Whole numbers only. |
| `label` | `string` | Shown in the form. |
| `max?` | `number` | Largest value. |
| `min?` | `number` | Smallest value. |
| `required?` | `boolean` | Must be filled in. |
| `type` | `"number"` | A number field. |
---
Source: /api/advanced/embed/interfaces/EmbedOption.md
# Interface: EmbedOption
One choice of an `enum` field.
## Properties
| Property | Type | Description |
| ------ | ------ | ------ |
| `label` | `string` | Shown in the form. |
| `value` | `string` | Stored in the document. |
---
Source: /api/advanced/embed/interfaces/EmbedOptions.md
# Interface: EmbedOptions
Options for `embed()`.
## Properties
| Property | Type | Description |
| ------ | ------ | ------ |
| `kinds` | readonly [`EmbedKind`](EmbedKind.md)[] | The blocks the user can insert. |
---
Source: /api/advanced/embed/interfaces/EmbedStringProp.md
# Interface: EmbedStringProp
A text field of an embed.
## Properties
| Property | Type | Description |
| ------ | ------ | ------ |
| `default?` | `string` | Value for a new embed. |
| `label` | `string` | Shown in the form. |
| `maxLength?` | `number` | Longest value. Default 500. |
| `required?` | `boolean` | Must be filled in. |
| `type` | `"string"` | A text field. |
---
Source: /api/advanced/embed/interfaces/SelectedEmbed.md
# Interface: SelectedEmbed
The selected embed, from `selectedEmbed()`.
## Properties
| Property | Type | Description |
| ------ | ------ | ------ |
| `kind` | [`EmbedKind`](EmbedKind.md) | Its kind, as configured. |
| `pos` | `number` | Its position in the document. |
| `props` | [`EmbedProps`](../type-aliases/EmbedProps.md) | Its settings. |
---
Source: /api/advanced/embed/type-aliases/EmbedProps.md
# Type Alias: EmbedProps
```ts
type EmbedProps = Readonly>;
```
An embed's settings, by field name.
---
Source: /api/advanced/embed/type-aliases/EmbedPropSpec.md
# Type Alias: EmbedPropSpec
```ts
type EmbedPropSpec =
| EmbedStringProp
| EmbedNumberProp
| EmbedBooleanProp
| EmbedEnumProp;
```
One field of an embed's settings.
---
Source: /api/advanced/embed/type-aliases/EmbedPropValue.md
# Type Alias: EmbedPropValue
```ts
type EmbedPropValue = string | number | boolean;
```
A stored prop value.
---
Source: /api/advanced/embed/variables/embed.md
# Variable: embed
```ts
const embed: (options) => Extension;
```
Custom blocks your front end renders. Each kind is a block the user
inserts from a menu (and edits through a form when it has props); the
editor shows it as `[[Label]]`. HTML: `
[[Label]]
`; Markdown: `[[kind {"key":"value"}]]`.
## Parameters
| Parameter | Type |
| ------ | ------ |
| `options` | [`EmbedOptions`](../interfaces/EmbedOptions.md) |
## Returns
[`Extension`](../../../core/interfaces/Extension.md)
## Example
```ts
embed({
kinds: [
{ id: 'pickup-branches', label: 'Olib ketish filiallari' },
{
id: 'product-list',
label: 'Mahsulotlar',
props: {
category: { type: 'string', label: 'Kategoriya', required: true },
limit: { type: 'number', label: 'Soni', integer: true, min: 1, max: 24, default: 8 },
},
},
],
})
```
---
Source: /api/advanced/embed/functions/embedDefaults.md
# Function: embedDefaults()
```ts
function embedDefaults(kind, props?): EmbedProps;
```
The props of a new embed: the defaults, overridden by `props`, empty values dropped.
## Parameters
| Parameter | Type |
| ------ | ------ |
| `kind` | [`EmbedKind`](../interfaces/EmbedKind.md) |
| `props?` | [`EmbedProps`](../type-aliases/EmbedProps.md) |
## Returns
[`EmbedProps`](../type-aliases/EmbedProps.md)
---
Source: /api/advanced/embed/functions/embedKinds.md
# Function: embedKinds()
```ts
function embedKinds(state): readonly EmbedKind[];
```
The kinds configured with `embed()` in this editor's schema, or none.
## Parameters
| Parameter | Type |
| ------ | ------ |
| `state` | `EditorState` |
## Returns
readonly [`EmbedKind`](../interfaces/EmbedKind.md)[]
---
Source: /api/advanced/embed/functions/embedPropsError.md
# Function: embedPropsError()
```ts
function embedPropsError(kind, props): string | null;
```
Why `props` are not valid for `kind`, or null when they are. Missing
optional fields are fine; unknown fields, wrong types and values out of
range are not.
## Parameters
| Parameter | Type |
| ------ | ------ |
| `kind` | [`EmbedKind`](../interfaces/EmbedKind.md) |
| `props` | `unknown` |
## Returns
`string` \| `null`
---
Source: /api/advanced/embed/functions/insertEmbed.md
# Function: insertEmbed()
```ts
function insertEmbed(kind, props?): Command;
```
Insert an embed of `kind` with the defaults and `props`: in place of an
empty paragraph, after the paragraph holding the cursor (text is never
split) or after a selected node. The cursor ends in the paragraph below.
Fails (returns false) for an unknown kind, an unknown field or a value
that is not valid, e.g. a required field left out: ask for them first.
## Parameters
| Parameter | Type |
| ------ | ------ |
| `kind` | `string` |
| `props?` | [`EmbedProps`](../type-aliases/EmbedProps.md) |
## Returns
[`Command`](../../../core/type-aliases/Command.md)
---
Source: /api/advanced/embed/functions/selectedEmbed.md
# Function: selectedEmbed()
```ts
function selectedEmbed(state): SelectedEmbed | null;
```
The selected embed (its kind, props and position), or null.
## Parameters
| Parameter | Type |
| ------ | ------ |
| `state` | `EditorState` |
## Returns
[`SelectedEmbed`](../interfaces/SelectedEmbed.md) \| `null`
---
Source: /api/advanced/embed/functions/updateEmbed.md
# Function: updateEmbed()
```ts
function updateEmbed(props): Command;
```
Replace the props of the selected embed. Fails when they are not valid.
## Parameters
| Parameter | Type |
| ------ | ------ |
| `props` | [`EmbedProps`](../type-aliases/EmbedProps.md) |
## Returns
[`Command`](../../../core/type-aliases/Command.md)
---
Source: /api/advanced/formatting/reference.md
# @writeon/advanced/formatting
Font family, text colour and text alignment. Each is configured with the
values your design allows; documents store only their ids, so the server
(`validate()`) drops anything else and `toHTML()` writes only safe CSS.
Small and eager: add them to the editor from the start, like
`advancedSchema()`.
## Interfaces
- [ColorOption](interfaces/ColorOption.md)
- [FontFamilyOptions](interfaces/FontFamilyOptions.md)
- [FontOption](interfaces/FontOption.md)
- [TextAlignOptions](interfaces/TextAlignOptions.md)
- [TextColorOptions](interfaces/TextColorOptions.md)
## Type Aliases
- [TextAlignment](type-aliases/TextAlignment.md)
## Variables
- [fontFamily](variables/fontFamily.md)
- [textAlign](variables/textAlign.md)
- [textColor](variables/textColor.md)
## Functions
- [activeFontFamily](functions/activeFontFamily.md)
- [activeTextColor](functions/activeTextColor.md)
- [setFontFamily](functions/setFontFamily.md)
- [setTextAlign](functions/setTextAlign.md)
- [setTextColor](functions/setTextColor.md)
- [textAlignmentAt](functions/textAlignmentAt.md)
---
Source: /api/advanced/formatting/interfaces/ColorOption.md
# Interface: ColorOption
A colour the user can choose.
## Properties
| Property | Type | Description |
| ------ | ------ | ------ |
| `id` | `string` | Stored in the document, e.g. `'brand'`. Letters, digits, `-` and `_`. |
| `label` | `string` | Shown in the menu and announced, e.g. `'Red'`. |
| `value` | `string` | CSS colour: `#rgb`, `#rrggbb` (or with alpha), or `var(--name)`. |
---
Source: /api/advanced/formatting/interfaces/FontFamilyOptions.md
# Interface: FontFamilyOptions
Options for `fontFamily()`.
## Properties
| Property | Type | Description |
| ------ | ------ | ------ |
| `fonts` | readonly [`FontOption`](FontOption.md)[] | The fonts the user can choose. Text without a font uses the editor's own. |
---
Source: /api/advanced/formatting/interfaces/FontOption.md
# Interface: FontOption
A font the user can choose.
## Properties
| Property | Type | Description |
| ------ | ------ | ------ |
| `css` | `string` | The CSS `font-family` value, e.g. `'Inter, sans-serif'`. Letters, spaces, commas, quotes and `-`. |
| `id` | `string` | Stored in the document, e.g. `'inter'`. Letters, digits, `-` and `_`. |
| `label` | `string` | Shown in the menu, e.g. `'Inter'`. |
---
Source: /api/advanced/formatting/interfaces/TextAlignOptions.md
# Interface: TextAlignOptions
Options for `textAlign()`.
## Properties
| Property | Type | Description |
| ------ | ------ | ------ |
| `types?` | readonly `string`[] | Node types that can be aligned. Default: `['paragraph', 'heading']`. |
---
Source: /api/advanced/formatting/interfaces/TextColorOptions.md
# Interface: TextColorOptions
Options for `textColor()`.
## Properties
| Property | Type | Description |
| ------ | ------ | ------ |
| `background?` | `string` | Background the text is read on, for the contrast check (hex). Default `'#ffffff'`. A colour under 4.5:1 (WCAG AA) logs a warning while you develop. `var()` colours are not checked. |
| `colors` | readonly [`ColorOption`](ColorOption.md)[] | The colours the user can choose. Text without a colour uses the editor's own. |
---
Source: /api/advanced/formatting/type-aliases/TextAlignment.md
# Type Alias: TextAlignment
```ts
type TextAlignment = "left" | "center" | "right";
```
A text alignment. Left is the default and is stored as `null`.
---
Source: /api/advanced/formatting/variables/fontFamily.md
# Variable: fontFamily
```ts
const fontFamily: (options) => Extension;
```
Font family as a mark, so one paragraph can mix fonts. Stores
`{ font: id }`; renders ``.
Pasted text keeps a font when its `font-family` starts with one of yours.
## Parameters
| Parameter | Type |
| ------ | ------ |
| `options` | [`FontFamilyOptions`](../interfaces/FontFamilyOptions.md) |
## Returns
[`Extension`](../../../core/interfaces/Extension.md)
## Example
```ts
fontFamily({
fonts: [
{ id: 'inter', label: 'Inter', css: 'Inter, sans-serif' },
{ id: 'serif', label: 'Serif', css: 'Georgia, serif' },
],
})
```
---
Source: /api/advanced/formatting/variables/textAlign.md
# Variable: textAlign
```ts
const textAlign: (options?) => Extension;
```
Text alignment on paragraphs and headings: an `align` attribute (`null` =
left, `'center'`, `'right'`), rendered as `style="text-align: …"`.
Shortcuts: Mod-Shift-l, Mod-Shift-e, Mod-Shift-r.
## Parameters
| Parameter | Type |
| ------ | ------ |
| `options?` | [`TextAlignOptions`](../interfaces/TextAlignOptions.md) |
## Returns
[`Extension`](../../../core/interfaces/Extension.md)
## Example
```ts
createEditor({ extensions: [...basic(), textAlign()], label: 'Text' })
```
---
Source: /api/advanced/formatting/variables/textColor.md
# Variable: textColor
```ts
const textColor: (options) => Extension;
```
Text colour as a mark, from your palette. Stores `{ color: id }`; renders
``.
## Parameters
| Parameter | Type |
| ------ | ------ |
| `options` | [`TextColorOptions`](../interfaces/TextColorOptions.md) |
## Returns
[`Extension`](../../../core/interfaces/Extension.md)
## Example
```ts
textColor({
colors: [
{ id: 'brand', label: 'Red', value: '#C00414' },
{ id: 'muted', label: 'Gray', value: '#475467' },
],
})
```
---
Source: /api/advanced/formatting/functions/activeFontFamily.md
# Function: activeFontFamily()
```ts
function activeFontFamily(state): string | null;
```
The font at the selection: its id, or null for none or a mix.
## Parameters
| Parameter | Type |
| ------ | ------ |
| `state` | `EditorState` |
## Returns
`string` \| `null`
---
Source: /api/advanced/formatting/functions/activeTextColor.md
# Function: activeTextColor()
```ts
function activeTextColor(state): string | null;
```
The colour at the selection: its id, or null for none or a mix.
## Parameters
| Parameter | Type |
| ------ | ------ |
| `state` | `EditorState` |
## Returns
`string` \| `null`
---
Source: /api/advanced/formatting/functions/setFontFamily.md
# Function: setFontFamily()
```ts
function setFontFamily(id): Command;
```
Set the font of the selection (or of what is typed next); `null` removes it.
## Parameters
| Parameter | Type |
| ------ | ------ |
| `id` | `string` \| `null` |
## Returns
[`Command`](../../../core/type-aliases/Command.md)
---
Source: /api/advanced/formatting/functions/setTextAlign.md
# Function: setTextAlign()
```ts
function setTextAlign(alignment): Command;
```
Align the selected paragraphs and headings.
## Parameters
| Parameter | Type |
| ------ | ------ |
| `alignment` | [`TextAlignment`](../type-aliases/TextAlignment.md) |
## Returns
[`Command`](../../../core/type-aliases/Command.md)
---
Source: /api/advanced/formatting/functions/setTextColor.md
# Function: setTextColor()
```ts
function setTextColor(id): Command;
```
Set the colour of the selection (or of what is typed next); `null` removes it.
## Parameters
| Parameter | Type |
| ------ | ------ |
| `id` | `string` \| `null` |
## Returns
[`Command`](../../../core/type-aliases/Command.md)
---
Source: /api/advanced/formatting/functions/textAlignmentAt.md
# Function: textAlignmentAt()
```ts
function textAlignmentAt(state): TextAlignment | null;
```
The alignment of the block that holds the selection (`'left'` when unset).
## Parameters
| Parameter | Type |
| ------ | ------ |
| `state` | `EditorState` |
## Returns
[`TextAlignment`](../type-aliases/TextAlignment.md) \| `null`
---
Source: /api/advanced/schema/reference.md
# @writeon/advanced/schema
The node types of the advanced features (task list, code block, image,
table, mention) without their behaviour. Small and eager: include
`advancedSchema()` in the editor from the start, on the client and on the
server.
## Interfaces
- [AdvancedSchemaOptions](interfaces/AdvancedSchemaOptions.md)
- [ImageSourceOptions](interfaces/ImageSourceOptions.md)
## Variables
- [advancedSchema](variables/advancedSchema.md)
## Functions
- [isAllowedImageSrc](functions/isAllowedImageSrc.md)
---
Source: /api/advanced/schema/interfaces/AdvancedSchemaOptions.md
# Interface: AdvancedSchemaOptions
Options for `advancedSchema()`.
## Properties
| Property | Type | Description |
| ------ | ------ | ------ |
| `image?` | [`ImageSourceOptions`](ImageSourceOptions.md) | Which image sources are accepted. Default: http(s) and relative URLs, no `data:` URLs. |
---
Source: /api/advanced/schema/interfaces/ImageSourceOptions.md
# Interface: ImageSourceOptions
Which image sources the schema accepts.
## Properties
| Property | Type | Description |
| ------ | ------ | ------ |
| `dataUrls?` | `boolean` | Allow `data:` URLs (base64, only PNG, JPEG, GIF and WebP — never SVG, which can carry scripts). Off by default: base64 bloats stored documents; use an upload instead. |
---
Source: /api/advanced/schema/variables/advancedSchema.md
# Variable: advancedSchema
```ts
const advancedSchema: (options?) => Extension;
```
The node types of advanced mode, without their behaviour: task lists,
code blocks, images, tables and mentions. Add it to `createEditor()` so documents that use these nodes
load and display everywhere (in basic mode the content stays visible and
its text editable), then turn on the behaviour with
`editor.enable(() => import('@writeon/advanced'))`. Small, always loaded.
Use the same list on the server: `validate(doc, { extensions: [...basic(), advancedSchema()] })`.
## Parameters
| Parameter | Type |
| ------ | ------ |
| `options?` | [`AdvancedSchemaOptions`](../interfaces/AdvancedSchemaOptions.md) |
## Returns
[`Extension`](../../../core/interfaces/Extension.md)
---
Source: /api/advanced/schema/functions/isAllowedImageSrc.md
# Function: isAllowedImageSrc()
```ts
function isAllowedImageSrc(src, options?): boolean;
```
Whether `src` is acceptable for an image: http(s), a relative URL, or
(when enabled) a raster `data:` URL. The schema enforces this everywhere,
including on the server.
## Parameters
| Parameter | Type |
| ------ | ------ |
| `src` | `unknown` |
| `options?` | [`ImageSourceOptions`](../interfaces/ImageSourceOptions.md) |
## Returns
`boolean`
---
Source: /api/core/reference.md
# @writeon/core
The editor: `createEditor`, the document format (`DocJSON`) and its
migrations, URL rules and helpers.
## Interfaces
- [Debounced](interfaces/Debounced.md)
- [DocJSON](interfaces/DocJSON.md)
- [Editor](interfaces/Editor.md)
- [EditorOptions](interfaces/EditorOptions.md)
- [EditorSnapshot](interfaces/EditorSnapshot.md)
- [Extension](interfaces/Extension.md)
- [MarkJSON](interfaces/MarkJSON.md)
- [NodeJSON](interfaces/NodeJSON.md)
- [TransactionScope](interfaces/TransactionScope.md)
## Type Aliases
- [Command](type-aliases/Command.md)
- [EditorEnableSource](type-aliases/EditorEnableSource.md)
- [EditorLabel](type-aliases/EditorLabel.md)
## Variables
- [DEFAULT\_PROTOCOLS](variables/DEFAULT_PROTOCOLS.md)
- [SCHEMA\_VERSION](variables/SCHEMA_VERSION.md)
## Functions
- [createEditor](functions/createEditor.md)
- [debounce](functions/debounce.md)
- [isAllowedUrl](functions/isAllowedUrl.md)
- [migrateDoc](functions/migrateDoc.md)
---
Source: /api/core/interfaces/Debounced.md
# Interface: Debounced()\
A debounced function with explicit control over pending calls.
## Type Parameters
| Type Parameter |
| ------ |
| `Args` *extends* `unknown`[] |
```ts
Debounced(...args): void;
```
A debounced function with explicit control over pending calls.
## Parameters
| Parameter | Type |
| ------ | ------ |
| ...`args` | `Args` |
## Returns
`void`
## Properties
| Property | Modifier | Type | Description |
| ------ | ------ | ------ | ------ |
| `pending` | `readonly` | `boolean` | Whether a call is waiting to run. |
## Methods
### cancel()
```ts
cancel(): void;
```
Drop the pending call without running it.
#### Returns
`void`
***
### flush()
```ts
flush(): void;
```
Run the pending call now, if there is one.
#### Returns
`void`
---
Source: /api/core/interfaces/DocJSON.md
# Interface: DocJSON
The canonical, lossless document format. Store this in your database.
## Properties
| Property | Type | Description |
| ------ | ------ | ------ |
| `content` | [`NodeJSON`](NodeJSON.md)[] | Top-level block nodes. |
| `schemaVersion` | `number` | Version of the document format, used by `migrateDoc()` to upgrade older documents. |
| `type` | `"doc"` | Always `'doc'`. |
---
Source: /api/core/interfaces/Editor.md
# Interface: Editor
An editor instance, created by `createEditor()`.
## Properties
| Property | Modifier | Type | Description |
| ------ | ------ | ------ | ------ |
| `isEmpty` | `readonly` | `boolean` | Whether the document is a single empty text block. |
| `pm` | `readonly` | \{ `schema`: `Schema`; `state`: `EditorState`; `view`: `EditorView` \| `null`; \} | Direct access to ProseMirror. **Not a stable API**: it may change in any minor release. |
| `pm.schema` | `readonly` | `Schema` | The schema built from the extensions. |
| `pm.state` | `readonly` | `EditorState` | The current state. |
| `pm.view` | `readonly` | `EditorView` \| `null` | The view, or `null` while not mounted. |
## Methods
### blur()
```ts
blur(): void;
```
Remove focus from the editable area.
#### Returns
`void`
***
### can()
```ts
can(command): boolean;
```
Check whether a command applies, without running it.
#### Parameters
| Parameter | Type |
| ------ | ------ |
| `command` | [`Command`](../type-aliases/Command.md) |
#### Returns
`boolean`
***
### destroy()
```ts
destroy(): void;
```
Release everything. The editor cannot be used afterwards.
#### Returns
`void`
***
### enable()
```ts
enable(source): Promise;
```
Add behaviour (commands' keymaps, input rules, plugins) from more
extensions to the running editor, typically loaded on demand. The
document, undo history and selection are kept. Their nodes and marks
must already be in the schema: pass the schema extension (e.g.
`advancedSchema()`) to `createEditor()`. Extensions already added are skipped.
#### Parameters
| Parameter | Type |
| ------ | ------ |
| `source` | [`EditorEnableSource`](../type-aliases/EditorEnableSource.md) |
#### Returns
`Promise`\<`void`\>
#### Example
```ts
await editor.enable(() => import('@writeon/advanced'))
```
***
### focus()
```ts
focus(position?): void;
```
Focus the editable area, optionally moving the cursor to the start or end. Does nothing when not mounted.
#### Parameters
| Parameter | Type |
| ------ | ------ |
| `position?` | `"start"` \| `"end"` |
#### Returns
`void`
***
### getJSON()
```ts
getJSON(): DocJSON;
```
The document in the JSON format, stamped with the current `schemaVersion`.
#### Returns
[`DocJSON`](DocJSON.md)
***
### getSnapshot()
```ts
getSnapshot(): EditorSnapshot;
```
Current state for rendering UI. Returns the same frozen object until the state changes.
#### Returns
[`EditorSnapshot`](EditorSnapshot.md)
***
### isActive()
```ts
isActive(name, attrs?): boolean;
```
Whether a mark or node (optionally with matching attrs) is active at the selection.
#### Parameters
| Parameter | Type |
| ------ | ------ |
| `name` | `string` |
| `attrs?` | `Record`\<`string`, `unknown`\> |
#### Returns
`boolean`
***
### mount()
```ts
mount(element): void;
```
Attach to a DOM element. Document and history are kept across mount/unmount.
Throws if already mounted.
#### Parameters
| Parameter | Type |
| ------ | ------ |
| `element` | `HTMLElement` |
#### Returns
`void`
***
### run()
```ts
run(command): boolean;
```
Run a command. Returns `false` when it does not apply.
#### Parameters
| Parameter | Type |
| ------ | ------ |
| `command` | [`Command`](../type-aliases/Command.md) |
#### Returns
`boolean`
***
### setContent()
```ts
setContent(doc, options?): void;
```
Replace the document. Not added to undo history unless `addToHistory` is `true`.
#### Parameters
| Parameter | Type |
| ------ | ------ |
| `doc` | [`DocJSON`](DocJSON.md) |
| `options?` | \{ `addToHistory?`: `boolean`; \} |
| `options.addToHistory?` | `boolean` |
#### Returns
`void`
***
### setEditable()
```ts
setEditable(editable): void;
```
Switch between editable and read-only.
#### Parameters
| Parameter | Type |
| ------ | ------ |
| `editable` | `boolean` |
#### Returns
`void`
***
### subscribe()
```ts
subscribe(listener): () => void;
```
Listen for state changes. Calls are batched per microtask. Returns an unsubscribe function.
#### Parameters
| Parameter | Type |
| ------ | ------ |
| `listener` | () => `void` |
#### Returns
() => `void`
***
### transaction()
```ts
transaction(fn): boolean;
```
Run several commands as one undo step. If any command returns `false`,
nothing is applied and the result is `false`.
#### Parameters
| Parameter | Type |
| ------ | ------ |
| `fn` | (`tx`) => `void` |
#### Returns
`boolean`
***
### unmount()
```ts
unmount(): void;
```
Detach from the DOM. Does nothing when not mounted.
#### Returns
`void`
---
Source: /api/core/interfaces/EditorOptions.md
# Interface: EditorOptions
Options for `createEditor()`.
## Properties
| Property | Type | Description |
| ------ | ------ | ------ |
| `content?` | [`DocJSON`](DocJSON.md) \| `null` | Initial document. Omit for an empty document. |
| `editable?` | `boolean` | Whether the user can edit. Defaults to `true`. |
| `element?` | `HTMLElement` | Element to mount into. Omit to create the editor first and call `mount()` later. |
| `extensions` | [`Extension`](Extension.md)[] | Extensions that make up the editor, usually a preset such as `basic()`. |
| `label` | [`EditorLabel`](../type-aliases/EditorLabel.md) | Accessible name: an `aria-label` string or the id of a labelling element. |
| `onBlur?` | (`editor`) => `void` | Called when the editable area loses focus, also when it is unmounted while focused. |
| `onChange?` | (`editor`) => `void` | Called after every change to the document. |
| `onFocus?` | (`editor`) => `void` | Called when the editable area gains focus. |
| `placeholder?` | `string` | Text shown (and announced) while the document is empty. |
---
Source: /api/core/interfaces/EditorSnapshot.md
# Interface: EditorSnapshot
Immutable view of the editor state for rendering UI.
## Properties
| Property | Modifier | Type | Description |
| ------ | ------ | ------ | ------ |
| `block` | `readonly` | \{ `attrs`: `Readonly`\<`Record`\<`string`, `unknown`\>\>; `type`: `string`; \} | The text block that holds the selection head. |
| `block.attrs` | `readonly` | `Readonly`\<`Record`\<`string`, `unknown`\>\> | Node attributes, e.g. `level` for a heading. |
| `block.type` | `readonly` | `string` | Node type name, e.g. `'paragraph'` or `'heading'`. |
| `canRedo` | `readonly` | `boolean` | Whether there is a step to redo. |
| `canUndo` | `readonly` | `boolean` | Whether there is a step to undo. |
| `editable` | `readonly` | `boolean` | Whether the user can edit. |
| `empty` | `readonly` | `boolean` | Whether the document is a single empty text block. |
| `focused` | `readonly` | `boolean` | Whether the editable area has focus. |
| `marks` | `readonly` | `ReadonlySet`\<`string`\> | Marks active at the selection, e.g. `'bold'`. |
| `selection` | `readonly` | \{ `empty`: `boolean`; `from`: `number`; `to`: `number`; \} | The current selection as document positions. |
| `selection.empty` | `readonly` | `boolean` | Whether the selection is a collapsed cursor. |
| `selection.from` | `readonly` | `number` | Start position of the selection. |
| `selection.to` | `readonly` | `number` | End position of the selection. |
| `version` | `readonly` | `number` | Increases on every state change. |
---
Source: /api/core/interfaces/Extension.md
# Interface: Extension
Opaque extension value produced by a `defineExtension()` factory.
## Properties
| Property | Modifier | Type | Description |
| ------ | ------ | ------ | ------ |
| `name` | `readonly` | `string` | The extension's unique name. |
---
Source: /api/core/interfaces/MarkJSON.md
# Interface: MarkJSON
A mark in the JSON document format.
## Properties
| Property | Type | Description |
| ------ | ------ | ------ |
| `attrs?` | `Record`\<`string`, `unknown`\> | Mark attributes, e.g. `href` for a link. Omitted when the mark has none. |
| `type` | `string` | Mark type name, e.g. `'bold'` or `'link'`. |
---
Source: /api/core/interfaces/NodeJSON.md
# Interface: NodeJSON
A node in the JSON document format.
## Properties
| Property | Type | Description |
| ------ | ------ | ------ |
| `attrs?` | `Record`\<`string`, `unknown`\> | Node attributes, e.g. `level` for a heading. |
| `content?` | `NodeJSON`[] | Child nodes. Omitted for leaf nodes and empty blocks. |
| `marks?` | [`MarkJSON`](MarkJSON.md)[] | Marks applied to a `text` node. |
| `text?` | `string` | The text of a `text` node. |
| `type` | `string` | Node type name, e.g. `'paragraph'` or `'text'`. |
---
Source: /api/core/interfaces/TransactionScope.md
# Interface: TransactionScope
Handle passed to `editor.transaction()`; every command joins one undo step.
## Methods
### run()
```ts
run(command): boolean;
```
Run a command inside the transaction. Returns `false` when it does not apply; later calls then do nothing.
#### Parameters
| Parameter | Type |
| ------ | ------ |
| `command` | [`Command`](../type-aliases/Command.md) |
#### Returns
`boolean`
---
Source: /api/core/type-aliases/Command.md
# Type Alias: Command
```ts
type Command = (state, dispatch?, view?) => boolean;
```
A ProseMirror command. Command factories such as `toggleBold()` return one;
pass it to `editor.run()` or `editor.can()`.
## Parameters
| Parameter | Type |
| ------ | ------ |
| `state` | `EditorState` |
| `dispatch?` | (`tr`) => `void` |
| `view?` | `EditorView` |
## Returns
`boolean`
---
Source: /api/core/type-aliases/EditorEnableSource.md
# Type Alias: EditorEnableSource
```ts
type EditorEnableSource =
| readonly Extension[]
| (() => Promise<
| readonly Extension[]
| {
default: readonly Extension[];
}>);
```
Extensions to enable, or a loader for them (a module whose default export is the list works too).
---
Source: /api/core/type-aliases/EditorLabel.md
# Type Alias: EditorLabel
```ts
type EditorLabel =
| string
| {
labelledBy: string;
};
```
How the editable area is named for assistive technology. Required.
## Union Members
`string`
***
### Type Literal
```ts
{
labelledBy: string;
}
```
#### labelledBy
```ts
labelledBy: string;
```
Id of the element that labels the editor (`aria-labelledby`).
---
Source: /api/core/variables/DEFAULT_PROTOCOLS.md
# Variable: DEFAULT\_PROTOCOLS
```ts
const DEFAULT_PROTOCOLS: readonly string[];
```
Protocols allowed in links unless configured otherwise.
---
Source: /api/core/variables/SCHEMA_VERSION.md
# Variable: SCHEMA\_VERSION
```ts
const SCHEMA_VERSION: 1 = 1;
```
Version of the document format written by this release. It changes only
when the library changes how documents are stored; each change ships a
migration so documents saved by older versions keep loading.
---
Source: /api/core/functions/createEditor.md
# Function: createEditor()
```ts
function createEditor(options): Editor;
```
Create an editor.
## Parameters
| Parameter | Type |
| ------ | ------ |
| `options` | [`EditorOptions`](../interfaces/EditorOptions.md) |
## Returns
[`Editor`](../interfaces/Editor.md)
## Example
```ts
const editor = createEditor({
element: document.querySelector('#editor'),
extensions: basic(),
content: savedDoc,
label: 'Article text',
onChange: debounce((editor) => save(editor.getJSON()), 500),
})
```
---
Source: /api/core/functions/debounce.md
# Function: debounce()
```ts
function debounce(fn, wait): Debounced;
```
Delay `fn` until `wait` ms have passed without another call.
Only the arguments of the last call are used.
Use it to throttle expensive work such as saving from `onChange`:
## Type Parameters
| Type Parameter |
| ------ |
| `Args` *extends* `unknown`[] |
## Parameters
| Parameter | Type |
| ------ | ------ |
| `fn` | (...`args`) => `void` |
| `wait` | `number` |
## Returns
[`Debounced`](../interfaces/Debounced.md)\<`Args`\>
## Example
```ts
const save = debounce((editor: Editor) => api.save(editor.getJSON()), 500)
createEditor({ onChange: save, ... })
window.addEventListener('beforeunload', () => save.flush())
```
---
Source: /api/core/functions/isAllowedUrl.md
# Function: isAllowedUrl()
```ts
function isAllowedUrl(href, protocols?): boolean;
```
Whether `href` is safe to put in a link.
Absolute URLs must use one of `protocols`. Relative URLs (`/path`, `#id`,
`page.html`) are allowed. Control characters and whitespace are removed
before the check, because browsers ignore them in the scheme
(`java\tscript:` runs as `javascript:`).
## Parameters
| Parameter | Type | Default value |
| ------ | ------ | ------ |
| `href` | `string` | `undefined` |
| `protocols?` | readonly `string`[] | `DEFAULT_PROTOCOLS` |
## Returns
`boolean`
---
Source: /api/core/functions/migrateDoc.md
# Function: migrateDoc()
```ts
function migrateDoc(doc): DocJSON;
```
Bring a stored document up to the current `SCHEMA_VERSION`. Documents
without a version are treated as version 1. Throws for documents written by
a newer version of the library, which this release cannot read safely.
## Parameters
| Parameter | Type |
| ------ | ------ |
| `doc` | [`DocJSON`](../interfaces/DocJSON.md) |
## Returns
[`DocJSON`](../interfaces/DocJSON.md)
---
Source: /api/core/commands/reference.md
# @writeon/core/commands
Command factories for `editor.run()` and `editor.can()`: marks, block types,
lists, links, history.
## Interfaces
- [LinkAttrs](interfaces/LinkAttrs.md)
## Variables
- [toggleBold](variables/toggleBold.md)
- [toggleBulletList](variables/toggleBulletList.md)
- [toggleCode](variables/toggleCode.md)
- [toggleItalic](variables/toggleItalic.md)
- [toggleOrderedList](variables/toggleOrderedList.md)
- [toggleStrike](variables/toggleStrike.md)
- [toggleUnderline](variables/toggleUnderline.md)
## Functions
- [clearFormatting](functions/clearFormatting.md)
- [insertHardBreak](functions/insertHardBreak.md)
- [liftListItem](functions/liftListItem.md)
- [redo](functions/redo.md)
- [setHeading](functions/setHeading.md)
- [setLink](functions/setLink.md)
- [setParagraph](functions/setParagraph.md)
- [sinkListItem](functions/sinkListItem.md)
- [toggleBlockquote](functions/toggleBlockquote.md)
- [toggleHeading](functions/toggleHeading.md)
- [undo](functions/undo.md)
- [unsetLink](functions/unsetLink.md)
---
Source: /api/core/commands/interfaces/LinkAttrs.md
# Interface: LinkAttrs
Attributes for `setLink()`.
## Properties
| Property | Type | Description |
| ------ | ------ | ------ |
| `href` | `string` | Link target. Trimmed; must use an allowed protocol. |
| `title?` | `string` \| `null` | Optional `title` attribute. Default: none. |
---
Source: /api/core/commands/variables/toggleBold.md
# Variable: toggleBold
```ts
const toggleBold: () => Command;
```
Toggle bold on the selection. Requires the `bold` extension.
## Returns
[`Command`](../../type-aliases/Command.md)
---
Source: /api/core/commands/variables/toggleBulletList.md
# Variable: toggleBulletList
```ts
const toggleBulletList: () => Command;
```
Bullet list on/off, or switch an ordered list to bullets. Requires `list`.
## Returns
[`Command`](../../type-aliases/Command.md)
---
Source: /api/core/commands/variables/toggleCode.md
# Variable: toggleCode
```ts
const toggleCode: () => Command;
```
Toggle inline code on the selection. Requires the `code` extension.
## Returns
[`Command`](../../type-aliases/Command.md)
---
Source: /api/core/commands/variables/toggleItalic.md
# Variable: toggleItalic
```ts
const toggleItalic: () => Command;
```
Toggle italic on the selection. Requires the `italic` extension.
## Returns
[`Command`](../../type-aliases/Command.md)
---
Source: /api/core/commands/variables/toggleOrderedList.md
# Variable: toggleOrderedList
```ts
const toggleOrderedList: () => Command;
```
Ordered list on/off, or switch a bullet list to numbers. Requires `list`.
## Returns
[`Command`](../../type-aliases/Command.md)
---
Source: /api/core/commands/variables/toggleStrike.md
# Variable: toggleStrike
```ts
const toggleStrike: () => Command;
```
Toggle strikethrough on the selection. Requires the `strike` extension.
## Returns
[`Command`](../../type-aliases/Command.md)
---
Source: /api/core/commands/variables/toggleUnderline.md
# Variable: toggleUnderline
```ts
const toggleUnderline: () => Command;
```
Toggle underline on the selection. Requires the `underline` extension.
## Returns
[`Command`](../../type-aliases/Command.md)
---
Source: /api/core/commands/functions/clearFormatting.md
# Function: clearFormatting()
```ts
function clearFormatting(): Command;
```
Remove every mark from the selection (or from what is typed next).
## Returns
[`Command`](../../type-aliases/Command.md)
---
Source: /api/core/commands/functions/insertHardBreak.md
# Function: insertHardBreak()
```ts
function insertHardBreak(): Command;
```
Insert a line break inside the current block. Requires `hardBreak`.
## Returns
[`Command`](../../type-aliases/Command.md)
---
Source: /api/core/commands/functions/liftListItem.md
# Function: liftListItem()
```ts
function liftListItem(): Command;
```
Outdent the list item, leaving the list at the top level. Requires `list`.
## Returns
[`Command`](../../type-aliases/Command.md)
---
Source: /api/core/commands/functions/redo.md
# Function: redo()
```ts
function redo(): Command;
```
Redo the last undone change. Requires the `history` extension.
## Returns
[`Command`](../../type-aliases/Command.md)
---
Source: /api/core/commands/functions/setHeading.md
# Function: setHeading()
```ts
function setHeading(level): Command;
```
Turn the selected blocks into headings of `level`. Requires the `heading` extension.
## Parameters
| Parameter | Type |
| ------ | ------ |
| `level` | `number` |
## Returns
[`Command`](../../type-aliases/Command.md)
---
Source: /api/core/commands/functions/setLink.md
# Function: setLink()
```ts
function setLink(attrs): Command;
```
Link the selection to `href`. With an empty selection inside a link, the
whole link is updated; with an empty selection elsewhere, `href` is inserted
as linked text. Returns `false` for URLs with a protocol that is not allowed.
Requires the `link` extension.
## Parameters
| Parameter | Type |
| ------ | ------ |
| `attrs` | [`LinkAttrs`](../interfaces/LinkAttrs.md) |
## Returns
[`Command`](../../type-aliases/Command.md)
---
Source: /api/core/commands/functions/setParagraph.md
# Function: setParagraph()
```ts
function setParagraph(): Command;
```
Turn the selected blocks into paragraphs.
## Returns
[`Command`](../../type-aliases/Command.md)
---
Source: /api/core/commands/functions/sinkListItem.md
# Function: sinkListItem()
```ts
function sinkListItem(): Command;
```
Indent the list item (nest it under the previous one). Requires `list`.
## Returns
[`Command`](../../type-aliases/Command.md)
---
Source: /api/core/commands/functions/toggleBlockquote.md
# Function: toggleBlockquote()
```ts
function toggleBlockquote(): Command;
```
Wrap the selection in a blockquote, or lift it out of one. Requires `blockquote`.
## Returns
[`Command`](../../type-aliases/Command.md)
---
Source: /api/core/commands/functions/toggleHeading.md
# Function: toggleHeading()
```ts
function toggleHeading(level): Command;
```
Heading of `level` if the block is not one already, otherwise back to a paragraph.
## Parameters
| Parameter | Type |
| ------ | ------ |
| `level` | `number` |
## Returns
[`Command`](../../type-aliases/Command.md)
---
Source: /api/core/commands/functions/undo.md
# Function: undo()
```ts
function undo(): Command;
```
Undo the last change. Requires the `history` extension.
## Returns
[`Command`](../../type-aliases/Command.md)
---
Source: /api/core/commands/functions/unsetLink.md
# Function: unsetLink()
```ts
function unsetLink(): Command;
```
Remove the link from the selection, or the whole link the cursor is in.
## Returns
[`Command`](../../type-aliases/Command.md)
---
Source: /api/core/extension/reference.md
# @writeon/core/extension
Building blocks for writing your own extensions: `defineExtension`,
`createSchema`, `docFromJSON`, `markInputRule`.
## Interfaces
- [ExtensionContext](interfaces/ExtensionContext.md)
- [ExtensionSpec](interfaces/ExtensionSpec.md)
- [NodeAttribute](interfaces/NodeAttribute.md)
## Functions
- [createSchema](functions/createSchema.md)
- [defineExtension](functions/defineExtension.md)
- [docFromJSON](functions/docFromJSON.md)
- [markInputRule](functions/markInputRule.md)
## References
### Command
Re-exports [Command](../type-aliases/Command.md)
***
### Extension
Re-exports [Extension](../interfaces/Extension.md)
---
Source: /api/core/extension/interfaces/ExtensionContext.md
# Interface: ExtensionContext
Context passed to extension hooks once the schema exists.
## Properties
| Property | Modifier | Type | Description |
| ------ | ------ | ------ | ------ |
| `schema` | `readonly` | `Schema` | The editor's schema. |
---
Source: /api/core/extension/interfaces/ExtensionSpec.md
# Interface: ExtensionSpec
What an extension contributes. Returned by the factory given to `defineExtension()`.
## Properties
| Property | Type | Description |
| ------ | ------ | ------ |
| `attributes?` | [`NodeAttribute`](NodeAttribute.md)[] | Attributes added to node types defined by other extensions, such as text alignment on paragraphs and headings. Node types that are not in the schema are skipped. |
| `inputRules?` | (`ctx`) => `InputRule`[] | Input rules that turn typed text into formatting, e.g. `# ` into a heading. |
| `keymap?` | (`ctx`) => `Record`\<`string`, [`Command`](../../type-aliases/Command.md)\> | Key bindings, e.g. `{ 'Mod-b': toggleBold() }`. |
| `marks?` | `Record`\<`string`, `MarkSpec`\> | Mark types added to the schema, in order. |
| `name` | `string` | Unique name. Two extensions with the same name are an error. |
| `nodes?` | `Record`\<`string`, `NodeSpec`\> | Node types added to the schema, in order. |
| `plugins?` | (`ctx`) => `Plugin`\<`any`\>[] | Extra ProseMirror plugins. |
| `priority?` | `number` | Higher runs first for keymaps and plugins. Defaults to 100. |
| `requires?` | `string`[] | Names of extensions that must also be present. |
---
Source: /api/core/extension/interfaces/NodeAttribute.md
# Interface: NodeAttribute
An attribute an extension adds to other extensions' node types.
## Properties
| Property | Type | Description |
| ------ | ------ | ------ |
| `default` | `unknown` | Value when the attribute is not set. |
| `name` | `string` | Attribute name, e.g. `'align'`. |
| `parse` | (`element`) => `unknown` | Read the value from a pasted or parsed element; `undefined` means the default. |
| `render` | (`value`) => `Readonly`\<`Record`\<`string`, `string`\>\> \| `null` | DOM attributes for a value (a `style` is appended to the node's own), or null for none. |
| `types` | readonly `string`[] | Node type names, e.g. `['paragraph', 'heading']`. |
| `validate?` | (`value`) => `boolean` | Whether a value is allowed. A document with any other value does not fit the schema. |
---
Source: /api/core/extension/functions/createSchema.md
# Function: createSchema()
```ts
function createSchema(extensions): Schema;
```
Build the ProseMirror schema for a list of extensions, exactly as
`createEditor()` would. Use it on the server to validate or render documents
with the same configuration as the client. Throws on duplicate names,
missing requirements or conflicting node/mark names.
## Parameters
| Parameter | Type |
| ------ | ------ |
| `extensions` | readonly [`Extension`](../../interfaces/Extension.md)[] |
## Returns
`Schema`
---
Source: /api/core/extension/functions/defineExtension.md
# Function: defineExtension()
```ts
function defineExtension(factory): (...args) => Extension;
```
Define an extension. The factory receives the options the user passes and
returns what the extension contributes.
## Type Parameters
| Type Parameter |
| ------ |
| `Args` *extends* `unknown`[] |
## Parameters
| Parameter | Type |
| ------ | ------ |
| `factory` | (...`args`) => [`ExtensionSpec`](../interfaces/ExtensionSpec.md) |
## Returns
(...`args`) => [`Extension`](../../interfaces/Extension.md)
## Example
```ts
export const highlight = defineExtension((options: { color?: string } = {}) => ({
name: 'highlight',
marks: { highlight: { parseDOM: [{ tag: 'mark' }], toDOM: () => ['mark', 0] } },
}))
createEditor({ extensions: [...basic(), highlight({ color: 'yellow' })], label: 'Text' })
```
---
Source: /api/core/extension/functions/docFromJSON.md
# Function: docFromJSON()
```ts
function docFromJSON(schema, json): Node;
```
Turn a `DocJSON` into a ProseMirror document of `schema`: migrates older
format versions, accepts an empty document, and checks every node. Throws
an error that says how to fix the document (or the extensions) when it does
not fit the schema.
The editor, `toHTML()` and `toMarkdown()` load documents with it; use it in
code that builds on the schema directly.
## Parameters
| Parameter | Type |
| ------ | ------ |
| `schema` | `Schema` |
| `json` | [`DocJSON`](../../interfaces/DocJSON.md) |
## Returns
`Node`
## Example
```ts
const schema = createSchema(extensions)
const node = docFromJSON(schema, saved)
```
---
Source: /api/core/extension/functions/markInputRule.md
# Function: markInputRule()
```ts
function markInputRule(pattern, markType): InputRule;
```
Apply a mark when text matching `pattern` is typed, e.g. `**bold**`.
The pattern must end with `$` and have two groups: group 1 is the whole
delimited part (`**bold**`), group 2 the text that keeps the mark (`bold`).
Anything matched before group 1 (such as a leading space) is left alone.
Lookbehind is avoided on purpose: Safari before 16.4 does not support it.
## Parameters
| Parameter | Type |
| ------ | ------ |
| `pattern` | `RegExp` |
| `markType` | `MarkType` |
## Returns
`InputRule`
---
Source: /api/core/extensions/reference.md
# @writeon/core/extensions
The individual extensions behind the `basic()` preset (paragraph, heading,
lists, marks, link, history…), for picking them one by one.
## Interfaces
- [HeadingOptions](interfaces/HeadingOptions.md)
- [HistoryOptions](interfaces/HistoryOptions.md)
- [LinkOptions](interfaces/LinkOptions.md)
## Variables
- [blockquote](variables/blockquote.md)
- [bold](variables/bold.md)
- [code](variables/code.md)
- [hardBreak](variables/hardBreak.md)
- [heading](variables/heading.md)
- [history](variables/history.md)
- [italic](variables/italic.md)
- [link](variables/link.md)
- [list](variables/list.md)
- [strike](variables/strike.md)
- [underline](variables/underline.md)
---
Source: /api/core/extensions/interfaces/HeadingOptions.md
# Interface: HeadingOptions
Options for the `heading` extension.
## Properties
| Property | Type | Description |
| ------ | ------ | ------ |
| `levels?` | readonly `number`[] | Heading levels the user can create. Default `[1, 2, 3]`. |
---
Source: /api/core/extensions/interfaces/HistoryOptions.md
# Interface: HistoryOptions
Options for the `history` extension.
## Properties
| Property | Type | Description |
| ------ | ------ | ------ |
| `depth?` | `number` | How many undo steps to keep. Default 100. |
| `newGroupDelay?` | `number` | Changes closer together than this (ms) merge into one undo step. Default 500. |
---
Source: /api/core/extensions/interfaces/LinkOptions.md
# Interface: LinkOptions
Options for the `link` extension.
## Properties
| Property | Type | Description |
| ------ | ------ | ------ |
| `protocols?` | readonly `string`[] | Allowed URL protocols. Default: `http`, `https`, `mailto`, `tel`. |
---
Source: /api/core/extensions/variables/blockquote.md
# Variable: blockquote
```ts
const blockquote: () => Extension;
```
Block quotes. `Mod-Shift-b` or `> `.
## Returns
[`Extension`](../../interfaces/Extension.md)
---
Source: /api/core/extensions/variables/bold.md
# Variable: bold
```ts
const bold: () => Extension;
```
Bold text. `Mod-b`, `**text**` or `__text__`.
## Returns
[`Extension`](../../interfaces/Extension.md)
---
Source: /api/core/extensions/variables/code.md
# Variable: code
```ts
const code: () => Extension;
```
Inline code. `Mod-e` or `` `text` ``. No other marks inside code.
## Returns
[`Extension`](../../interfaces/Extension.md)
---
Source: /api/core/extensions/variables/hardBreak.md
# Variable: hardBreak
```ts
const hardBreak: () => Extension;
```
Line break inside a block. `Shift-Enter` or `Mod-Enter`.
## Returns
[`Extension`](../../interfaces/Extension.md)
---
Source: /api/core/extensions/variables/heading.md
# Variable: heading
```ts
const heading: (options?) => Extension;
```
Headings. `Mod-Alt-1…6`, `# ` … `###### `; `Mod-Alt-0` back to paragraph.
## Parameters
| Parameter | Type |
| ------ | ------ |
| `options?` | [`HeadingOptions`](../interfaces/HeadingOptions.md) |
## Returns
[`Extension`](../../interfaces/Extension.md)
---
Source: /api/core/extensions/variables/history.md
# Variable: history
```ts
const history: (options?) => Extension;
```
Undo and redo. `Mod-z`, `Mod-Shift-z` / `Mod-y`; `Backspace` right after a shortcut undoes it.
## Parameters
| Parameter | Type |
| ------ | ------ |
| `options?` | [`HistoryOptions`](../interfaces/HistoryOptions.md) |
## Returns
[`Extension`](../../interfaces/Extension.md)
---
Source: /api/core/extensions/variables/italic.md
# Variable: italic
```ts
const italic: () => Extension;
```
Italic text. `Mod-i`, `*text*` or `_text_`.
## Returns
[`Extension`](../../interfaces/Extension.md)
---
Source: /api/core/extensions/variables/link.md
# Variable: link
```ts
const link: (options?) => Extension;
```
Links. Unsafe URLs (such as `javascript:`) are dropped on paste and refused
by `setLink()`. Links never get `target="_blank"`: opening new windows
without warning is an accessibility problem.
## Parameters
| Parameter | Type |
| ------ | ------ |
| `options?` | [`LinkOptions`](../interfaces/LinkOptions.md) |
## Returns
[`Extension`](../../interfaces/Extension.md)
---
Source: /api/core/extensions/variables/list.md
# Variable: list
```ts
const list: () => Extension;
```
Bullet and ordered lists. `Mod-Shift-8` / `Mod-Shift-7`, `- ` / `1. `, `Tab` / `Shift-Tab` to nest.
## Returns
[`Extension`](../../interfaces/Extension.md)
---
Source: /api/core/extensions/variables/strike.md
# Variable: strike
```ts
const strike: () => Extension;
```
Strikethrough. `Mod-Shift-s` or `~~text~~`.
## Returns
[`Extension`](../../interfaces/Extension.md)
---
Source: /api/core/extensions/variables/underline.md
# Variable: underline
```ts
const underline: () => Extension;
```
Underlined text. `Mod-u`.
## Returns
[`Extension`](../../interfaces/Extension.md)
---
Source: /api/core/presets/reference.md
# @writeon/core/presets
The `basic()` preset: everything a typical text field needs, each part
configurable or switchable off.
## Interfaces
- [BasicOptions](interfaces/BasicOptions.md)
## Functions
- [basic](functions/basic.md)
---
Source: /api/core/presets/interfaces/BasicOptions.md
# Interface: BasicOptions
Per-extension settings for `basic()`. `false` leaves an extension out.
## Properties
| Property | Type | Description |
| ------ | ------ | ------ |
| `blockquote?` | `false` | Blockquotes. |
| `bold?` | `false` | Bold. |
| `code?` | `false` | Inline code. |
| `hardBreak?` | `false` | Line breaks (`Shift-Enter`). |
| `heading?` | \| `false` \| [`HeadingOptions`](../../extensions/interfaces/HeadingOptions.md) | Headings, or their options. |
| `history?` | \| `false` \| [`HistoryOptions`](../../extensions/interfaces/HistoryOptions.md) | Undo and redo, or their options. |
| `italic?` | `false` | Italic. |
| `link?` | `false` \| [`LinkOptions`](../../extensions/interfaces/LinkOptions.md) | Links, or their options. |
| `list?` | `false` | Bullet and ordered lists. |
| `strike?` | `false` | Strikethrough. |
| `underline?` | `false` | Underline. |
---
Source: /api/core/presets/functions/basic.md
# Function: basic()
```ts
function basic(options?): Extension[];
```
The basic editor: paragraphs, headings, bold, italic, underline, strike,
inline code, links, lists, blockquotes, line breaks and undo/redo.
## Parameters
| Parameter | Type |
| ------ | ------ |
| `options?` | [`BasicOptions`](../interfaces/BasicOptions.md) |
## Returns
[`Extension`](../../interfaces/Extension.md)[]
## Example
```ts
basic() // everything, defaults
basic({ strike: false }) // without strikethrough
basic({ heading: { levels: [2, 3] } }) // only H2 and H3
basic({ link: { protocols: ['https'] } }) // https links only
```
---
Source: /api/html/reference.md
# @writeon/html
Convert between `DocJSON` and HTML (`toHTML`, `fromHTML`) and clean up
pasted Word and Google Docs content (`officePaste`).
## Interfaces
- [FromHTMLOptions](interfaces/FromHTMLOptions.md)
- [ToHTMLOptions](interfaces/ToHTMLOptions.md)
## Variables
- [officePaste](variables/officePaste.md)
## Functions
- [cleanOfficeHTML](functions/cleanOfficeHTML.md)
- [fromHTML](functions/fromHTML.md)
- [toHTML](functions/toHTML.md)
---
Source: /api/html/interfaces/FromHTMLOptions.md
# Interface: FromHTMLOptions
Options for `fromHTML()`.
## Properties
| Property | Type | Description |
| ------ | ------ | ------ |
| `document?` | `Document` | A `Document` to parse with. Defaults to the global `document`, so this is only needed outside the browser, e.g. in Node with linkedom or jsdom: `fromHTML(html, { extensions, document: parseHTML('').document })`. |
| `extensions` | readonly [`Extension`](../../core/interfaces/Extension.md)[] | The same extensions the editor uses. |
---
Source: /api/html/interfaces/ToHTMLOptions.md
# Interface: ToHTMLOptions
Options for `toHTML()`.
## Properties
| Property | Type | Description |
| ------ | ------ | ------ |
| `extensions` | readonly [`Extension`](../../core/interfaces/Extension.md)[] | The same extensions the editor uses. |
| `urls?` | \{ `protocols?`: readonly `string`[]; \} | Allowed protocols for `href`/`src`. Default: http, https, mailto, tel. |
| `urls.protocols?` | readonly `string`[] | Allowed URL protocols, without the colon. |
---
Source: /api/html/variables/officePaste.md
# Variable: officePaste
```ts
const officePaste: () => Extension;
```
Paste from Microsoft Word with working lists: bulleted and numbered lists,
including nested ones, arrive as real lists instead of paragraphs with a
typed-out bullet. Opt-in; other pastes are untouched.
## Returns
[`Extension`](../../core/interfaces/Extension.md)
## Example
```ts
import { officePaste } from '@writeon/html'
createEditor({ extensions: [...basic(), officePaste()], label: 'Text' })
```
---
Source: /api/html/functions/cleanOfficeHTML.md
# Function: cleanOfficeHTML()
```ts
function cleanOfficeHTML(html, doc?): string;
```
Rewrite HTML pasted from Microsoft Word so it parses well: Word writes
lists as paragraphs styled `mso-list` with a typed-out marker, not as
`
`/``. Those become real, nested lists; Word-only markup (``,
conditional comments, marker spans) is removed. Other HTML is returned
unchanged. Needs a DOM (it runs in the browser, on paste).
## Parameters
| Parameter | Type | Default value |
| ------ | ------ | ------ |
| `html` | `string` | `undefined` |
| `doc?` | `Document` | `document` |
## Returns
`string`
---
Source: /api/html/functions/fromHTML.md
# Function: fromHTML()
```ts
function fromHTML(html, options): DocJSON;
```
Turn HTML (an import, a stored legacy value, pasted content) into a
document. Parsing happens in an inert template, so scripts never run and
images never load; the result keeps only what the extensions' schema
allows (unknown tags, `style`, event handlers and unsafe URLs are dropped).
## Parameters
| Parameter | Type |
| ------ | ------ |
| `html` | `string` |
| `options` | [`FromHTMLOptions`](../interfaces/FromHTMLOptions.md) |
## Returns
[`DocJSON`](../../core/interfaces/DocJSON.md)
## Example
```ts
const doc = fromHTML('
Hello world
', { extensions })
editor.setContent(doc)
```
---
Source: /api/html/functions/toHTML.md
# Function: toHTML()
```ts
function toHTML(doc, options): string;
```
Render a document to an HTML string without a DOM, in the browser, in Node
or during SSR. Safe by construction: only tags produced by the schema are
emitted, all text and attribute values are escaped, event handlers are
never written, `style` keeps only alignment, font family and colour
declarations with strict values, and URLs are checked again. A
document that does not fit the schema throws; on a server, run untrusted
input through `validate()` from `@writeon/server` first.
## Parameters
| Parameter | Type |
| ------ | ------ |
| `doc` | [`DocJSON`](../../core/interfaces/DocJSON.md) |
| `options` | [`ToHTMLOptions`](../interfaces/ToHTMLOptions.md) |
## Returns
`string`
## Example
```ts
const html = toHTML(editor.getJSON(), { extensions })
```
---
Source: /api/kit/reference.md
# @writeon/kit
The default kit: a ready-made toolbar on top of the headless controllers
(`mountToolbar`) styled by `@writeon/kit/style.css`.
## Interfaces
- [KitToolbar](interfaces/KitToolbar.md)
- [KitToolbarOptions](interfaces/KitToolbarOptions.md)
## Type Aliases
- [IconName](type-aliases/IconName.md)
## Variables
- [icons](variables/icons.md)
## Functions
- [mountToolbar](functions/mountToolbar.md)
## References
### KitAdvanced
Re-exports [KitAdvanced](advanced/interfaces/KitAdvanced.md)
***
### KitAdvancedOptions
Re-exports [KitAdvancedOptions](advanced/interfaces/KitAdvancedOptions.md)
***
### KitMention
Re-exports [KitMention](advanced/interfaces/KitMention.md)
---
Source: /api/kit/interfaces/KitToolbar.md
# Interface: KitToolbar
A mounted toolbar, returned by `mountToolbar()`.
## Methods
### destroy()
```ts
destroy(): void;
```
Remove the toolbar and stop listening to the editor.
#### Returns
`void`
---
Source: /api/kit/interfaces/KitToolbarOptions.md
# Interface: KitToolbarOptions
Options for `mountToolbar()`.
## Extended by
- [`ToolbarProps`](../react/interfaces/ToolbarProps.md)
- [`ToolbarProps`](../vue/interfaces/ToolbarProps.md)
## Properties
| Property | Type | Description |
| ------ | ------ | ------ |
| `blockTypes?` | `boolean` | Show the "Text style" menu (paragraph, headings). Default true. |
| `exclude?` | readonly `string`[] | Buttons to leave out, by id (e.g. `['underline', 'code']`). |
| `headingLevels?` | readonly `number`[] | Heading levels in that menu. Match `basic({ heading: { levels } })`. Default [1, 2, 3]. |
| `idPrefix?` | `string` | Prefix for element ids, needed when several editors share a page. Default: generated. |
| `link?` | `boolean` | Show the link button and form. Default true. Set `false` for the `Mod-k` shortcut too. |
| `messages?` | `Partial`\<[`Messages`](../../ui/interfaces/Messages.md)\> | UI texts, e.g. `uz` from `@writeon/ui/locales/uz`. Default English. |
| `mobile?` | `boolean` | On touch screens (`pointer: coarse`), dock the toolbar above the on-screen keyboard while the editor has focus, scrolling sideways. Default true. |
---
Source: /api/kit/type-aliases/IconName.md
# Type Alias: IconName
```ts
type IconName =
| "undo"
| "redo"
| "bold"
| "italic"
| "underline"
| "strike"
| "code"
| "bulletList"
| "orderedList"
| "blockquote"
| "clearFormatting"
| "link"
| "unlink"
| "chevronDown"
| "check"
| "image"
| "table"
| "taskList"
| "codeBlock"
| "heading1"
| "heading2"
| "heading3"
| "paragraph"
| "upload";
```
Names of the built-in toolbar icons.
---
Source: /api/kit/variables/icons.md
# Variable: icons
```ts
const icons: Readonly>;
```
Built-in icons (Lucide): the inner SVG markup of each 24×24 stroke icon, by name.
---
Source: /api/kit/functions/mountToolbar.md
# Function: mountToolbar()
```ts
function mountToolbar(
target,
editor,
options?
): KitToolbar;
```
Mount the default kit's toolbar into `target`: undo/redo, text style menu,
marks, lists, quote, clear formatting and link, with tooltips. Built on
`@writeon/ui`, so it has the same keyboard support and ARIA. Styles come
from `@writeon/kit/style.css`.
## Parameters
| Parameter | Type |
| ------ | ------ |
| `target` | `HTMLElement` |
| `editor` | [`Editor`](../../core/interfaces/Editor.md) |
| `options?` | [`KitToolbarOptions`](../interfaces/KitToolbarOptions.md) |
## Returns
[`KitToolbar`](../interfaces/KitToolbar.md)
## Example
```ts
import '@writeon/kit/style.css'
const toolbar = mountToolbar(document.querySelector('#toolbar'), editor, { messages: uz })
```
---
Source: /api/kit/advanced/reference.md
# @writeon/kit/advanced
Ready-made UI for the advanced features: image dialog and uploads, table
menu, slash commands, mentions and the selection bubble (`mountAdvanced`).
Loaded on demand.
## Interfaces
- [KitAdvanced](interfaces/KitAdvanced.md)
- [KitAdvancedOptions](interfaces/KitAdvancedOptions.md)
- [KitMention](interfaces/KitMention.md)
## Functions
- [mountAdvanced](functions/mountAdvanced.md)
---
Source: /api/kit/advanced/interfaces/KitAdvanced.md
# Interface: KitAdvanced
The mounted advanced UI, returned by `mountAdvanced()`.
## Properties
| Property | Modifier | Type | Description |
| ------ | ------ | ------ | ------ |
| `ready` | `readonly` | `Promise`\<`void`\> | Resolves once the advanced behaviour is turned on in the editor. |
## Methods
### destroy()
```ts
destroy(): void;
```
Remove the advanced UI. The editor keeps its advanced behaviour.
#### Returns
`void`
---
Source: /api/kit/advanced/interfaces/KitAdvancedOptions.md
# Interface: KitAdvancedOptions
Options for `mountAdvanced()`.
## Extended by
- [`AdvancedProps`](../../react/interfaces/AdvancedProps.md)
- [`AdvancedProps`](../../vue/interfaces/AdvancedProps.md)
## Properties
| Property | Type | Description |
| ------ | ------ | ------ |
| `accept?` | readonly `string`[] | Accepted image types for uploads. Default PNG, JPEG, GIF, WebP (never SVG). |
| `bubble?` | `boolean` | The formatting bubble next to selected text. Default: on, except on touch screens. |
| `idPrefix?` | `string` | Prefix for element ids, needed when several editors share a page. Default: generated. |
| `maxSize?` | `number` | Largest upload in bytes. Default 10 MB. |
| `mentions?` | (`query`) => \| readonly [`KitMention`](KitMention.md)[] \| `Promise`\ | People for `@` mentions, for what was typed after `@`. May be async. Off when left out. |
| `messages?` | `Partial`\<[`Messages`](../../../ui/interfaces/Messages.md)\> | UI texts, e.g. `uz` from `@writeon/ui/locales/uz`. Default English. |
| `onUploadError?` | (`error`) => `void` | Called for every refused or failed upload, after the kit has announced it. |
| `slash?` | \| `boolean` \| ((`defaults`) => readonly [`SuggestionItem`](../../../ui/interfaces/SuggestionItem.md)[]) | The `/` command menu. `true` (default) offers headings, lists, quote, code block, table and image; pass a function to change that list. |
| `toolbar?` | `boolean` | Add image, table, task list and code block buttons to the kit toolbar. Default true. |
| `upload?` | [`UploadFn`](../../../advanced/type-aliases/UploadFn.md) | Your image upload (see `fetchUploader()` / `presignedUploader()` in `@writeon/advanced`). Turns on drop, paste and "Upload from device". Without it, images are added by address only. |
---
Source: /api/kit/advanced/interfaces/KitMention.md
# Interface: KitMention
A person offered in the `@` mention list.
## Properties
| Property | Type | Description |
| ------ | ------ | ------ |
| `description?` | `string` | Extra line in the list, e.g. a job title. |
| `id` | `string` | Stored in the document (user id, handle). |
| `label` | `string` | Shown after `@`. |
---
Source: /api/kit/advanced/functions/mountAdvanced.md
# Function: mountAdvanced()
```ts
function mountAdvanced(
target,
editor,
options?
): KitAdvanced;
```
Mount the default kit's advanced UI: image dialog and uploads, table
actions, task list and code block buttons in the kit toolbar, the `/`
command menu, `@` mentions and the selection bubble. Also turns on the
advanced behaviour (`editor.enable()`), keeping the document and undo
history. The editor must have `advancedSchema()`. Load this module on
demand, so none of it is in your main bundle.
## Parameters
| Parameter | Type |
| ------ | ------ |
| `target` | `HTMLElement` |
| `editor` | [`Editor`](../../../core/interfaces/Editor.md) |
| `options?` | [`KitAdvancedOptions`](../interfaces/KitAdvancedOptions.md) |
## Returns
[`KitAdvanced`](../interfaces/KitAdvanced.md)
## Example
```ts
const { mountAdvanced } = await import('@writeon/kit/advanced')
mountAdvanced(document.querySelector('.rte-root'), editor, {
messages: uz,
upload: fetchUploader({ url: '/api/upload' }),
mentions: (query) => searchPeople(query),
})
```
---
Source: /api/kit/react/reference.md
# @writeon/kit/react
React components for the default kit: `` and ``.
## Interfaces
- [AdvancedProps](interfaces/AdvancedProps.md)
- [ToolbarProps](interfaces/ToolbarProps.md)
## Functions
- [Advanced](functions/Advanced.md)
- [Toolbar](functions/Toolbar.md)
---
Source: /api/kit/react/interfaces/AdvancedProps.md
# Interface: AdvancedProps
Props of ``: the editor plus `KitAdvancedOptions`.
## Extends
- [`KitAdvancedOptions`](../../advanced/interfaces/KitAdvancedOptions.md)
## Properties
| Property | Type | Description | Inherited from |
| ------ | ------ | ------ | ------ |
| `accept?` | readonly `string`[] | Accepted image types for uploads. Default PNG, JPEG, GIF, WebP (never SVG). | [`KitAdvancedOptions`](../../advanced/interfaces/KitAdvancedOptions.md).[`accept`](../../advanced/interfaces/KitAdvancedOptions.md#property-accept) |
| `bubble?` | `boolean` | The formatting bubble next to selected text. Default: on, except on touch screens. | [`KitAdvancedOptions`](../../advanced/interfaces/KitAdvancedOptions.md).[`bubble`](../../advanced/interfaces/KitAdvancedOptions.md#property-bubble) |
| `editor` | [`Editor`](../../../core/interfaces/Editor.md) | The editor to control. A different editor remounts the advanced UI. | - |
| `idPrefix?` | `string` | Prefix for element ids, needed when several editors share a page. Default: generated. | [`KitAdvancedOptions`](../../advanced/interfaces/KitAdvancedOptions.md).[`idPrefix`](../../advanced/interfaces/KitAdvancedOptions.md#property-idprefix) |
| `maxSize?` | `number` | Largest upload in bytes. Default 10 MB. | [`KitAdvancedOptions`](../../advanced/interfaces/KitAdvancedOptions.md).[`maxSize`](../../advanced/interfaces/KitAdvancedOptions.md#property-maxsize) |
| `mentions?` | (`query`) => \| readonly [`KitMention`](../../advanced/interfaces/KitMention.md)[] \| `Promise`\ | People for `@` mentions, for what was typed after `@`. May be async. Off when left out. | [`KitAdvancedOptions`](../../advanced/interfaces/KitAdvancedOptions.md).[`mentions`](../../advanced/interfaces/KitAdvancedOptions.md#property-mentions) |
| `messages?` | `Partial`\<[`Messages`](../../../ui/interfaces/Messages.md)\> | UI texts, e.g. `uz` from `@writeon/ui/locales/uz`. Default English. | [`KitAdvancedOptions`](../../advanced/interfaces/KitAdvancedOptions.md).[`messages`](../../advanced/interfaces/KitAdvancedOptions.md#property-messages) |
| `onUploadError?` | (`error`) => `void` | Called for every refused or failed upload, after the kit has announced it. | [`KitAdvancedOptions`](../../advanced/interfaces/KitAdvancedOptions.md).[`onUploadError`](../../advanced/interfaces/KitAdvancedOptions.md#property-onuploaderror) |
| `slash?` | \| `boolean` \| ((`defaults`) => readonly [`SuggestionItem`](../../../ui/interfaces/SuggestionItem.md)[]) | The `/` command menu. `true` (default) offers headings, lists, quote, code block, table and image; pass a function to change that list. | [`KitAdvancedOptions`](../../advanced/interfaces/KitAdvancedOptions.md).[`slash`](../../advanced/interfaces/KitAdvancedOptions.md#property-slash) |
| `toolbar?` | `boolean` | Add image, table, task list and code block buttons to the kit toolbar. Default true. | [`KitAdvancedOptions`](../../advanced/interfaces/KitAdvancedOptions.md).[`toolbar`](../../advanced/interfaces/KitAdvancedOptions.md#property-toolbar) |
| `upload?` | [`UploadFn`](../../../advanced/type-aliases/UploadFn.md) | Your image upload (see `fetchUploader()` / `presignedUploader()` in `@writeon/advanced`). Turns on drop, paste and "Upload from device". Without it, images are added by address only. | [`KitAdvancedOptions`](../../advanced/interfaces/KitAdvancedOptions.md).[`upload`](../../advanced/interfaces/KitAdvancedOptions.md#property-upload) |
---
Source: /api/kit/react/interfaces/ToolbarProps.md
# Interface: ToolbarProps
Props of ``: the editor plus `KitToolbarOptions`.
## Extends
- [`KitToolbarOptions`](../../interfaces/KitToolbarOptions.md)
## Properties
| Property | Type | Description | Inherited from |
| ------ | ------ | ------ | ------ |
| `blockTypes?` | `boolean` | Show the "Text style" menu (paragraph, headings). Default true. | [`KitToolbarOptions`](../../interfaces/KitToolbarOptions.md).[`blockTypes`](../../interfaces/KitToolbarOptions.md#property-blocktypes) |
| `editor` | [`Editor`](../../../core/interfaces/Editor.md) | The editor to control. A different editor remounts the toolbar. | - |
| `exclude?` | readonly `string`[] | Buttons to leave out, by id (e.g. `['underline', 'code']`). | [`KitToolbarOptions`](../../interfaces/KitToolbarOptions.md).[`exclude`](../../interfaces/KitToolbarOptions.md#property-exclude) |
| `headingLevels?` | readonly `number`[] | Heading levels in that menu. Match `basic({ heading: { levels } })`. Default [1, 2, 3]. | [`KitToolbarOptions`](../../interfaces/KitToolbarOptions.md).[`headingLevels`](../../interfaces/KitToolbarOptions.md#property-headinglevels) |
| `idPrefix?` | `string` | Prefix for element ids, needed when several editors share a page. Default: generated. | [`KitToolbarOptions`](../../interfaces/KitToolbarOptions.md).[`idPrefix`](../../interfaces/KitToolbarOptions.md#property-idprefix) |
| `link?` | `boolean` | Show the link button and form. Default true. Set `false` for the `Mod-k` shortcut too. | [`KitToolbarOptions`](../../interfaces/KitToolbarOptions.md).[`link`](../../interfaces/KitToolbarOptions.md#property-link) |
| `messages?` | `Partial`\<[`Messages`](../../../ui/interfaces/Messages.md)\> | UI texts, e.g. `uz` from `@writeon/ui/locales/uz`. Default English. | [`KitToolbarOptions`](../../interfaces/KitToolbarOptions.md).[`messages`](../../interfaces/KitToolbarOptions.md#property-messages) |
| `mobile?` | `boolean` | On touch screens (`pointer: coarse`), dock the toolbar above the on-screen keyboard while the editor has focus, scrolling sideways. Default true. | [`KitToolbarOptions`](../../interfaces/KitToolbarOptions.md).[`mobile`](../../interfaces/KitToolbarOptions.md#property-mobile) |
---
Source: /api/kit/react/functions/Advanced.md
# Function: Advanced()
```ts
function Advanced(__namedParameters): ReactElement;
```
The default kit's advanced UI for React: image dialog and uploads, table
actions, the `/` menu, `@` mentions and the selection bubble. Its code is
loaded on demand, after mount. Put it inside `.rte-root`, next to
``. Options are read once, on mount.
## Parameters
| Parameter | Type |
| ------ | ------ |
| `__namedParameters` | [`AdvancedProps`](../interfaces/AdvancedProps.md) |
## Returns
`ReactElement`
## Example
```tsx
```
---
Source: /api/kit/react/functions/Toolbar.md
# Function: Toolbar()
```ts
function Toolbar(__namedParameters): ReactElement;
```
The default kit toolbar for React. Options are read once, on mount.
## Parameters
| Parameter | Type |
| ------ | ------ |
| `__namedParameters` | [`ToolbarProps`](../interfaces/ToolbarProps.md) |
## Returns
`ReactElement`
## Example
```tsx
import '@writeon/kit/style.css'
import { Toolbar } from '@writeon/kit/react'
```
---
Source: /api/kit/vue/reference.md
# @writeon/kit/vue
Vue components for the default kit: `` and ``.
## Interfaces
- [AdvancedProps](interfaces/AdvancedProps.md)
- [ToolbarProps](interfaces/ToolbarProps.md)
## Variables
- [Advanced](variables/Advanced.md)
- [Toolbar](variables/Toolbar.md)
---
Source: /api/kit/vue/interfaces/AdvancedProps.md
# Interface: AdvancedProps
Props of ``: the editor plus `KitAdvancedOptions`.
## Extends
- [`KitAdvancedOptions`](../../advanced/interfaces/KitAdvancedOptions.md)
## Properties
| Property | Type | Description | Inherited from |
| ------ | ------ | ------ | ------ |
| `accept?` | readonly `string`[] | Accepted image types for uploads. Default PNG, JPEG, GIF, WebP (never SVG). | [`KitAdvancedOptions`](../../advanced/interfaces/KitAdvancedOptions.md).[`accept`](../../advanced/interfaces/KitAdvancedOptions.md#property-accept) |
| `bubble?` | `boolean` | The formatting bubble next to selected text. Default: on, except on touch screens. | [`KitAdvancedOptions`](../../advanced/interfaces/KitAdvancedOptions.md).[`bubble`](../../advanced/interfaces/KitAdvancedOptions.md#property-bubble) |
| `editor` | [`Editor`](../../../core/interfaces/Editor.md) | The editor to control. Read once, on mount. | - |
| `idPrefix?` | `string` | Prefix for element ids, needed when several editors share a page. Default: generated. | [`KitAdvancedOptions`](../../advanced/interfaces/KitAdvancedOptions.md).[`idPrefix`](../../advanced/interfaces/KitAdvancedOptions.md#property-idprefix) |
| `maxSize?` | `number` | Largest upload in bytes. Default 10 MB. | [`KitAdvancedOptions`](../../advanced/interfaces/KitAdvancedOptions.md).[`maxSize`](../../advanced/interfaces/KitAdvancedOptions.md#property-maxsize) |
| `mentions?` | (`query`) => \| readonly [`KitMention`](../../advanced/interfaces/KitMention.md)[] \| `Promise`\ | People for `@` mentions, for what was typed after `@`. May be async. Off when left out. | [`KitAdvancedOptions`](../../advanced/interfaces/KitAdvancedOptions.md).[`mentions`](../../advanced/interfaces/KitAdvancedOptions.md#property-mentions) |
| `messages?` | `Partial`\<[`Messages`](../../../ui/interfaces/Messages.md)\> | UI texts, e.g. `uz` from `@writeon/ui/locales/uz`. Default English. | [`KitAdvancedOptions`](../../advanced/interfaces/KitAdvancedOptions.md).[`messages`](../../advanced/interfaces/KitAdvancedOptions.md#property-messages) |
| `onUploadError?` | (`error`) => `void` | Called for every refused or failed upload, after the kit has announced it. | [`KitAdvancedOptions`](../../advanced/interfaces/KitAdvancedOptions.md).[`onUploadError`](../../advanced/interfaces/KitAdvancedOptions.md#property-onuploaderror) |
| `slash?` | \| `boolean` \| ((`defaults`) => readonly [`SuggestionItem`](../../../ui/interfaces/SuggestionItem.md)[]) | The `/` command menu. `true` (default) offers headings, lists, quote, code block, table and image; pass a function to change that list. | [`KitAdvancedOptions`](../../advanced/interfaces/KitAdvancedOptions.md).[`slash`](../../advanced/interfaces/KitAdvancedOptions.md#property-slash) |
| `toolbar?` | `boolean` | Add image, table, task list and code block buttons to the kit toolbar. Default true. | [`KitAdvancedOptions`](../../advanced/interfaces/KitAdvancedOptions.md).[`toolbar`](../../advanced/interfaces/KitAdvancedOptions.md#property-toolbar) |
| `upload?` | [`UploadFn`](../../../advanced/type-aliases/UploadFn.md) | Your image upload (see `fetchUploader()` / `presignedUploader()` in `@writeon/advanced`). Turns on drop, paste and "Upload from device". Without it, images are added by address only. | [`KitAdvancedOptions`](../../advanced/interfaces/KitAdvancedOptions.md).[`upload`](../../advanced/interfaces/KitAdvancedOptions.md#property-upload) |
---
Source: /api/kit/vue/interfaces/ToolbarProps.md
# Interface: ToolbarProps
Props of ``: the editor plus `KitToolbarOptions`.
## Extends
- [`KitToolbarOptions`](../../interfaces/KitToolbarOptions.md)
## Properties
| Property | Type | Description | Inherited from |
| ------ | ------ | ------ | ------ |
| `blockTypes?` | `boolean` | Show the "Text style" menu (paragraph, headings). Default true. | [`KitToolbarOptions`](../../interfaces/KitToolbarOptions.md).[`blockTypes`](../../interfaces/KitToolbarOptions.md#property-blocktypes) |
| `editor` | [`Editor`](../../../core/interfaces/Editor.md) | The editor to control. Read once, on mount. | - |
| `exclude?` | readonly `string`[] | Buttons to leave out, by id (e.g. `['underline', 'code']`). | [`KitToolbarOptions`](../../interfaces/KitToolbarOptions.md).[`exclude`](../../interfaces/KitToolbarOptions.md#property-exclude) |
| `headingLevels?` | readonly `number`[] | Heading levels in that menu. Match `basic({ heading: { levels } })`. Default [1, 2, 3]. | [`KitToolbarOptions`](../../interfaces/KitToolbarOptions.md).[`headingLevels`](../../interfaces/KitToolbarOptions.md#property-headinglevels) |
| `idPrefix?` | `string` | Prefix for element ids, needed when several editors share a page. Default: generated. | [`KitToolbarOptions`](../../interfaces/KitToolbarOptions.md).[`idPrefix`](../../interfaces/KitToolbarOptions.md#property-idprefix) |
| `link?` | `boolean` | Show the link button and form. Default true. Set `false` for the `Mod-k` shortcut too. | [`KitToolbarOptions`](../../interfaces/KitToolbarOptions.md).[`link`](../../interfaces/KitToolbarOptions.md#property-link) |
| `messages?` | `Partial`\<[`Messages`](../../../ui/interfaces/Messages.md)\> | UI texts, e.g. `uz` from `@writeon/ui/locales/uz`. Default English. | [`KitToolbarOptions`](../../interfaces/KitToolbarOptions.md).[`messages`](../../interfaces/KitToolbarOptions.md#property-messages) |
| `mobile?` | `boolean` | On touch screens (`pointer: coarse`), dock the toolbar above the on-screen keyboard while the editor has focus, scrolling sideways. Default true. | [`KitToolbarOptions`](../../interfaces/KitToolbarOptions.md).[`mobile`](../../interfaces/KitToolbarOptions.md#property-mobile) |
---
Source: /api/kit/vue/variables/Advanced.md
# Variable: Advanced
```ts
const Advanced: DefineSetupFnComponent;
```
The default kit's advanced UI for Vue: image dialog and uploads, table
actions, the `/` menu, `@` mentions and the selection bubble. Its code is
loaded on demand, after mount. Put it inside `.rte-root`, next to
``. Options are read once, on mount.
## Example
```vue
```
---
Source: /api/kit/vue/variables/Toolbar.md
# Variable: Toolbar
```ts
const Toolbar: DefineSetupFnComponent;
```
The default kit toolbar for Vue. Options are read once, on mount.
## Example
```vue
```
---
Source: /api/markdown/reference.md
# @writeon/markdown
Convert between `DocJSON` and Markdown (`toMarkdown`, `fromMarkdown`),
extensible with your own rules.
## Interfaces
- [FromMarkdownOptions](interfaces/FromMarkdownOptions.md)
- [MarkdownMarkSerializer](interfaces/MarkdownMarkSerializer.md)
- [MarkdownParseContext](interfaces/MarkdownParseContext.md)
- [MarkdownSerializeContext](interfaces/MarkdownSerializeContext.md)
- [ToMarkdownOptions](interfaces/ToMarkdownOptions.md)
## Type Aliases
- [MarkdownRule](type-aliases/MarkdownRule.md)
## Functions
- [fromMarkdown](functions/fromMarkdown.md)
- [toMarkdown](functions/toMarkdown.md)
---
Source: /api/markdown/interfaces/FromMarkdownOptions.md
# Interface: FromMarkdownOptions
Options for `fromMarkdown()`.
## Properties
| Property | Type | Description |
| ------ | ------ | ------ |
| `extensions` | readonly [`Extension`](../../core/interfaces/Extension.md)[] | The same extensions the editor uses. |
| `maxLength?` | `number` | Longest accepted input, in characters. Default 1,000,000; longer input throws. |
| `rules?` | `Readonly`\<`Record`\<`string`, [`MarkdownRule`](../type-aliases/MarkdownRule.md)\>\> | Custom handling per marked token type (e.g. `table`, `image`), checked before the built-ins. |
---
Source: /api/markdown/interfaces/MarkdownMarkSerializer.md
# Interface: MarkdownMarkSerializer
Delimiters written around text that has this mark.
## Properties
| Property | Type | Description |
| ------ | ------ | ------ |
| `close` | `string` \| ((`mark`) => `string`) | Text written after the marked text, or a function computing it from the mark (e.g. a link's `](href)`). |
| `open` | `string` \| ((`mark`) => `string`) | Text written before the marked text, or a function computing it from the mark. |
---
Source: /api/markdown/interfaces/MarkdownParseContext.md
# Interface: MarkdownParseContext
Helpers passed to custom rules, so a rule can convert nested tokens.
## Properties
| Property | Modifier | Type | Description |
| ------ | ------ | ------ | ------ |
| `schema` | `readonly` | `Schema` | The schema built from the extensions. |
## Methods
### blocks()
```ts
blocks(tokens): Node[];
```
Convert block-level tokens.
#### Parameters
| Parameter | Type |
| ------ | ------ |
| `tokens` | readonly `Token`[] |
#### Returns
`Node`[]
***
### inline()
```ts
inline(tokens, marks?): Node[];
```
Convert inline tokens, adding `marks` to every text node.
#### Parameters
| Parameter | Type |
| ------ | ------ |
| `tokens` | readonly `Token`[] |
| `marks?` | readonly `Mark`[] |
#### Returns
`Node`[]
---
Source: /api/markdown/interfaces/MarkdownSerializeContext.md
# Interface: MarkdownSerializeContext
Helpers passed to custom node serializers.
## Methods
### blocks()
```ts
blocks(node): string;
```
Serialize a node's block children, separated by blank lines.
#### Parameters
| Parameter | Type |
| ------ | ------ |
| `node` | `Node` |
#### Returns
`string`
***
### inline()
```ts
inline(node): string;
```
Serialize a textblock's inline content.
#### Parameters
| Parameter | Type |
| ------ | ------ |
| `node` | `Node` |
#### Returns
`string`
---
Source: /api/markdown/interfaces/ToMarkdownOptions.md
# Interface: ToMarkdownOptions
Options for `toMarkdown()`.
## Properties
| Property | Type | Description |
| ------ | ------ | ------ |
| `extensions` | readonly [`Extension`](../../core/interfaces/Extension.md)[] | The same extensions the editor uses. |
| `marks?` | `Readonly`\<`Record`\<`string`, [`MarkdownMarkSerializer`](MarkdownMarkSerializer.md)\>\> | Custom delimiters per mark name, checked before the built-ins. |
| `nodes?` | `Readonly`\<`Record`\<`string`, (`node`, `context`) => `string`\>\> | Custom output per node type name, checked before the built-ins. |
---
Source: /api/markdown/type-aliases/MarkdownRule.md
# Type Alias: MarkdownRule
```ts
type MarkdownRule = (token, context) => PMNode[] | null;
```
Convert one marked token. Return the nodes to insert (block nodes for a
block token, inline nodes for an inline token), or `null` to fall back to
the built-in handling.
## Parameters
| Parameter | Type |
| ------ | ------ |
| `token` | `Token` |
| `context` | [`MarkdownParseContext`](../interfaces/MarkdownParseContext.md) |
## Returns
`PMNode`[] \| `null`
---
Source: /api/markdown/functions/fromMarkdown.md
# Function: fromMarkdown()
```ts
function fromMarkdown(markdown, options): DocJSON;
```
Turn Markdown (CommonMark + GitHub tables, strikethrough, autolinks) into a
document. Works without a DOM, in the browser and on a server.
Raw HTML in the Markdown never becomes markup: it is kept as plain text.
Links with unsafe protocols lose the link and keep their text. Anything the
extensions' schema cannot hold degrades to plain content (a fenced code
block becomes code-formatted text when there is no code block node, an
image becomes its alt text, a horizontal rule is dropped).
## Parameters
| Parameter | Type |
| ------ | ------ |
| `markdown` | `string` |
| `options` | [`FromMarkdownOptions`](../interfaces/FromMarkdownOptions.md) |
## Returns
[`DocJSON`](../../core/interfaces/DocJSON.md)
## Example
```ts
const { fromMarkdown } = await import('@writeon/markdown')
editor.setContent(fromMarkdown('# Title\n\nHello **world**', { extensions }))
```
---
Source: /api/markdown/functions/toMarkdown.md
# Function: toMarkdown()
```ts
function toMarkdown(doc, options): string;
```
Write a document as Markdown (CommonMark + GitHub strikethrough). Works
without a DOM. Text is escaped so it reads back as the same text, never as
formatting or HTML. Formatting Markdown cannot express (underline) is left
out and its text kept; links with unsafe protocols keep only their text.
## Parameters
| Parameter | Type |
| ------ | ------ |
| `doc` | [`DocJSON`](../../core/interfaces/DocJSON.md) |
| `options` | [`ToMarkdownOptions`](../interfaces/ToMarkdownOptions.md) |
## Returns
`string`
## Example
```ts
const { toMarkdown } = await import('@writeon/markdown')
const markdown = toMarkdown(editor.getJSON(), { extensions })
```
---
Source: /api/markdown/paste/reference.md
# @writeon/markdown/paste
Paste plain-text Markdown as formatted content (`markdownPaste`). The parser
loads lazily.
## Interfaces
- [MarkdownPasteOptions](interfaces/MarkdownPasteOptions.md)
## Variables
- [markdownPaste](variables/markdownPaste.md)
## Functions
- [looksLikeMarkdown](functions/looksLikeMarkdown.md)
---
Source: /api/markdown/paste/interfaces/MarkdownPasteOptions.md
# Interface: MarkdownPasteOptions
Options for `markdownPaste()`.
## Properties
| Property | Type | Description |
| ------ | ------ | ------ |
| `preload?` | `false` \| `"focus"` \| `"now"` | When to load the parser: on the editor's first focus (default), right away, or never on its own (call nothing; pastes stay plain until another import of `@writeon/markdown` loads it). |
---
Source: /api/markdown/paste/variables/markdownPaste.md
# Variable: markdownPaste
```ts
const markdownPaste: (options?) => Extension;
```
Format Markdown pasted as plain text (from a chat, a terminal, a `.md`
file). Pastes that carry HTML are left to the normal HTML handling, and
paste-as-plain-text (Shift+Mod+V) is never formatted.
The parser (marked, ~19 KB gzip) is not part of your main bundle: it loads
in the background on the editor's first focus. A paste before it has
loaded goes in as plain text.
## Parameters
| Parameter | Type |
| ------ | ------ |
| `options?` | [`MarkdownPasteOptions`](../interfaces/MarkdownPasteOptions.md) |
## Returns
[`Extension`](../../../core/interfaces/Extension.md)
## Example
```ts
import { markdownPaste } from '@writeon/markdown/paste'
createEditor({ extensions: [...basic(), markdownPaste()], label: 'Text' })
```
---
Source: /api/markdown/paste/functions/looksLikeMarkdown.md
# Function: looksLikeMarkdown()
```ts
function looksLikeMarkdown(text): boolean;
```
Whether plain text looks like Markdown worth formatting on paste.
## Parameters
| Parameter | Type |
| ------ | ------ |
| `text` | `string` |
## Returns
`boolean`
---
Source: /api/react/reference.md
# @writeon/react
React bindings: `useEditor`, `useEditorState`, `` and hooks
for every headless UI controller.
## Interfaces
- [EditorContentProps](interfaces/EditorContentProps.md)
- [UseBubbleMenuResult](interfaces/UseBubbleMenuResult.md)
- [UseImageDialogResult](interfaces/UseImageDialogResult.md)
- [UseLinkPopoverResult](interfaces/UseLinkPopoverResult.md)
- [UseMenuResult](interfaces/UseMenuResult.md)
- [UseSuggestionMenuResult](interfaces/UseSuggestionMenuResult.md)
- [UseToolbarResult](interfaces/UseToolbarResult.md)
- [UseTooltipResult](interfaces/UseTooltipResult.md)
## Type Aliases
- [ReactProps](type-aliases/ReactProps.md)
- [UseEditorOptions](type-aliases/UseEditorOptions.md)
## Functions
- [EditorContent](functions/EditorContent.md)
- [mergeProps](functions/mergeProps.md)
- [toReactProps](functions/toReactProps.md)
- [useBubbleMenu](functions/useBubbleMenu.md)
- [useEditor](functions/useEditor.md)
- [useEditorState](functions/useEditorState.md)
- [useImageDialog](functions/useImageDialog.md)
- [useLinkPopover](functions/useLinkPopover.md)
- [useMenu](functions/useMenu.md)
- [useSuggestionMenu](functions/useSuggestionMenu.md)
- [useToolbar](functions/useToolbar.md)
- [useTooltip](functions/useTooltip.md)
---
Source: /api/react/interfaces/EditorContentProps.md
# Interface: EditorContentProps
Props for ``.
## Extends
- `HTMLAttributes`\<`HTMLDivElement`\>
## Properties
| Property | Type | Description |
| ------ | ------ | ------ |
| `editor` | [`Editor`](../../core/interfaces/Editor.md) | The editor to mount into the inner element; it is unmounted when the component unmounts. |
| `html?` | `string` | HTML shown until the editor mounts, so server-rendered pages (Next.js, Remix) show the content at once instead of an empty box. Make it with `toHTML()` from `@writeon/html`, from the same document you pass as `content`. Only the first value is used; the editor owns the DOM after mount. **Example** `` |
---
Source: /api/react/interfaces/UseBubbleMenuResult.md
# Interface: UseBubbleMenuResult
Returned by `useBubbleMenu()`.
## Properties
| Property | Modifier | Type | Description |
| ------ | ------ | ------ | ------ |
| `open` | `readonly` | `boolean` | The bubble should be shown. |
| `reference` | `readonly` | [`VirtualReference`](../../ui/interfaces/VirtualReference.md) | Where the selection is; give it to your positioning code (e.g. Floating UI). |
## Methods
### dismiss()
```ts
dismiss(): void;
```
Hide until the selection changes; focus goes back to the editor.
#### Returns
`void`
***
### focusFirst()
```ts
focusFirst(): void;
```
Move focus to the first control in the bubble (what the focus shortcut does).
#### Returns
`void`
***
### getBubbleProps()
```ts
getBubbleProps(): ReactProps;
```
Props for the bubble element: id and data-state (`open` or `closed`). Escape
dismisses it, and mousedown outside form fields is prevented to keep the selection.
#### Returns
[`ReactProps`](../type-aliases/ReactProps.md)
---
Source: /api/react/interfaces/UseImageDialogResult.md
# Interface: UseImageDialogResult
Returned by `useImageDialog()`: the controller state as fields, plus actions and prop getters.
## Extends
- [`ImageDialogState`](../../ui/interfaces/ImageDialogState.md)
## Properties
| Property | Modifier | Type | Description | Inherited from |
| ------ | ------ | ------ | ------ | ------ |
| `alt` | `readonly` | `string` | Current value of the alternative text field. | [`ImageDialogState`](../../ui/interfaces/ImageDialogState.md).[`alt`](../../ui/interfaces/ImageDialogState.md#property-alt) |
| `available` | `readonly` | `boolean` | Whether the editor can hold images at all (has `advancedSchema()`). | [`ImageDialogState`](../../ui/interfaces/ImageDialogState.md).[`available`](../../ui/interfaces/ImageDialogState.md#property-available) |
| `decorative` | `readonly` | `boolean` | Decorative images get `alt=""` and are skipped by screen readers. | [`ImageDialogState`](../../ui/interfaces/ImageDialogState.md).[`decorative`](../../ui/interfaces/ImageDialogState.md#property-decorative) |
| `error` | `readonly` | `string` \| `null` | Validation message, or null. | [`ImageDialogState`](../../ui/interfaces/ImageDialogState.md).[`error`](../../ui/interfaces/ImageDialogState.md#property-error) |
| `errorField` | `readonly` | `"src"` \| `"alt"` \| `null` | Which field the error belongs to. | [`ImageDialogState`](../../ui/interfaces/ImageDialogState.md).[`errorField`](../../ui/interfaces/ImageDialogState.md#property-errorfield) |
| `imageSelected` | `readonly` | `boolean` | Whether an image is selected, so the trigger opens in "edit" mode. | [`ImageDialogState`](../../ui/interfaces/ImageDialogState.md).[`imageSelected`](../../ui/interfaces/ImageDialogState.md#property-imageselected) |
| `mode` | `readonly` | `"insert"` \| `"edit"` | "insert" adds a new image by address; "edit" changes the selected image. | [`ImageDialogState`](../../ui/interfaces/ImageDialogState.md).[`mode`](../../ui/interfaces/ImageDialogState.md#property-mode) |
| `open` | `readonly` | `boolean` | The dialog is open. | [`ImageDialogState`](../../ui/interfaces/ImageDialogState.md).[`open`](../../ui/interfaces/ImageDialogState.md#property-open) |
| `src` | `readonly` | `string` | Current value of the address field. | [`ImageDialogState`](../../ui/interfaces/ImageDialogState.md).[`src`](../../ui/interfaces/ImageDialogState.md#property-src) |
## Methods
### close()
```ts
close(): void;
```
Close without applying and focus the editor. Does nothing while closed.
#### Returns
`void`
***
### getAltHintProps()
```ts
getAltHintProps(): ReactProps;
```
Props for the hint text the alt input's aria-describedby points to.
#### Returns
[`ReactProps`](../type-aliases/ReactProps.md)
***
### getAltInputProps()
```ts
getAltInputProps(): ReactProps;
```
Props for the alternative text input: id, value, aria-required, aria-describedby (hint, and
error when invalid). Disabled and empty while the image is marked decorative.
#### Returns
[`ReactProps`](../type-aliases/ReactProps.md)
***
### getBackdropProps()
```ts
getBackdropProps(): ReactProps;
```
An optional full-screen layer behind the panel; a press on it closes the dialog.
#### Returns
[`ReactProps`](../type-aliases/ReactProps.md)
***
### getCancelProps()
```ts
getCancelProps(): ReactProps;
```
Props for the Cancel button, which closes the dialog.
#### Returns
[`ReactProps`](../type-aliases/ReactProps.md)
***
### getDecorativeProps()
```ts
getDecorativeProps(): ReactProps;
```
Props for the "decorative image" checkbox.
#### Returns
[`ReactProps`](../type-aliases/ReactProps.md)
***
### getDialogProps()
```ts
getDialogProps(): ReactProps;
```
The modal panel. Traps Tab inside and closes on Escape.
#### Returns
[`ReactProps`](../type-aliases/ReactProps.md)
***
### getErrorProps()
```ts
getErrorProps(): ReactProps;
```
Props for the error message: role="alert", hidden while there is no error.
#### Returns
[`ReactProps`](../type-aliases/ReactProps.md)
***
### getFormProps()
```ts
getFormProps(): ReactProps;
```
Props for the form: submit validates and applies instead of submitting the page.
#### Returns
[`ReactProps`](../type-aliases/ReactProps.md)
***
### getSrcInputProps()
```ts
getSrcInputProps(): ReactProps;
```
Props for the address input: id, value, inputmode="url"; aria-invalid and aria-describedby on error.
#### Returns
[`ReactProps`](../type-aliases/ReactProps.md)
***
### getTitleProps()
```ts
getTitleProps(): ReactProps;
```
Props for the dialog title: the id the dialog's aria-labelledby points to.
#### Returns
[`ReactProps`](../type-aliases/ReactProps.md)
***
### getTriggerProps()
```ts
getTriggerProps(): ReactProps;
```
Props for the toolbar button: aria-label (add or edit image), aria-haspopup, aria-expanded,
data-state; disabled without image support. Click opens the dialog; mousedown is prevented
to keep the selection.
#### Returns
[`ReactProps`](../type-aliases/ReactProps.md)
***
### openDialog()
```ts
openDialog(): void;
```
Open for the selected image (edit) or a new one (insert).
#### Returns
`void`
---
Source: /api/react/interfaces/UseLinkPopoverResult.md
# Interface: UseLinkPopoverResult
Returned by `useLinkPopover()`: the controller state as fields, plus actions and prop getters.
## Extends
- [`LinkPopoverState`](../../ui/interfaces/LinkPopoverState.md)
## Properties
| Property | Modifier | Type | Description | Inherited from |
| ------ | ------ | ------ | ------ | ------ |
| `error` | `readonly` | `string` \| `null` | Validation message, or null. | [`LinkPopoverState`](../../ui/interfaces/LinkPopoverState.md).[`error`](../../ui/interfaces/LinkPopoverState.md#property-error) |
| `href` | `readonly` | `string` | Current value of the address field. | [`LinkPopoverState`](../../ui/interfaces/LinkPopoverState.md).[`href`](../../ui/interfaces/LinkPopoverState.md#property-href) |
| `isEditing` | `readonly` | `boolean` | Whether the cursor or selection is inside an existing link. | [`LinkPopoverState`](../../ui/interfaces/LinkPopoverState.md).[`isEditing`](../../ui/interfaces/LinkPopoverState.md#property-isediting) |
| `open` | `readonly` | `boolean` | The form is open. | [`LinkPopoverState`](../../ui/interfaces/LinkPopoverState.md).[`open`](../../ui/interfaces/LinkPopoverState.md#property-open) |
## Methods
### close()
```ts
close(options?): void;
```
Close without applying. Focuses the editor unless `focusEditor` is false.
#### Parameters
| Parameter | Type |
| ------ | ------ |
| `options?` | \{ `focusEditor?`: `boolean`; \} |
| `options.focusEditor?` | `boolean` |
#### Returns
`void`
***
### getErrorProps()
```ts
getErrorProps(): ReactProps;
```
Props for the error message: role="alert", hidden while there is no error.
#### Returns
[`ReactProps`](../type-aliases/ReactProps.md)
***
### getFormProps()
```ts
getFormProps(): ReactProps;
```
Props for the form: role="group", aria-label. Submit applies the address.
#### Returns
[`ReactProps`](../type-aliases/ReactProps.md)
***
### getInputProps()
```ts
getInputProps(): ReactProps;
```
Props for the address input: aria-label, value, aria-invalid on error. Escape closes.
#### Returns
[`ReactProps`](../type-aliases/ReactProps.md)
***
### getRemoveProps()
```ts
getRemoveProps(): ReactProps;
```
Props for the Remove button; hidden unless the selection is in a link.
#### Returns
[`ReactProps`](../type-aliases/ReactProps.md)
***
### getTriggerProps()
```ts
getTriggerProps(): ReactProps;
```
Props for the toolbar button: id, aria-label, title with the shortcut, aria-keyshortcuts,
aria-pressed (inside a link), aria-expanded, aria-controls. Click toggles the form.
#### Returns
[`ReactProps`](../type-aliases/ReactProps.md)
***
### openPopover()
```ts
openPopover(): void;
```
Open the form, filled with the current link's address or `https://`, and focus the field.
#### Returns
`void`
---
Source: /api/react/interfaces/UseMenuResult.md
# Interface: UseMenuResult
Returned by `useMenu()`: the controller state as fields, plus actions and prop getters.
## Extends
- [`MenuState`](../../ui/interfaces/MenuState.md)
## Properties
| Property | Modifier | Type | Description | Inherited from |
| ------ | ------ | ------ | ------ | ------ |
| `enabled` | `readonly` | `Readonly`\<`Record`\<`string`, `boolean`\>\> | Whether each item (by id) can run now. The checked item is always enabled. | [`MenuState`](../../ui/interfaces/MenuState.md).[`enabled`](../../ui/interfaces/MenuState.md#property-enabled) |
| `items` | `readonly` | readonly [`MenuItem`](../../ui/interfaces/MenuItem.md)[] | The items passed in `options`. | - |
| `open` | `readonly` | `boolean` | The menu is open. | [`MenuState`](../../ui/interfaces/MenuState.md).[`open`](../../ui/interfaces/MenuState.md#property-open) |
| `selected` | `readonly` | [`MenuItem`](../../ui/interfaces/MenuItem.md) \| `null` | The checked item (e.g. the current block type), or null. | [`MenuState`](../../ui/interfaces/MenuState.md).[`selected`](../../ui/interfaces/MenuState.md#property-selected) |
## Methods
### close()
```ts
close(options?): void;
```
Close and move focus to the trigger (default), the editor, or nowhere.
#### Parameters
| Parameter | Type |
| ------ | ------ |
| `options?` | \{ `focus?`: `"editor"` \| `"trigger"` \| `"none"`; \} |
| `options.focus?` | `"editor"` \| `"trigger"` \| `"none"` |
#### Returns
`void`
***
### getItemProps()
```ts
getItemProps(id): ReactProps;
```
Props for an item: role `menuitemradio` with aria-checked for choices, `menuitem` for actions;
aria-disabled when it cannot run. Click selects it. Throws for an unknown id.
#### Parameters
| Parameter | Type |
| ------ | ------ |
| `id` | `string` |
#### Returns
[`ReactProps`](../type-aliases/ReactProps.md)
***
### getMenuProps()
```ts
getMenuProps(): ReactProps;
```
Props for the menu: role="menu", aria-labelledby. Arrow keys, Home and End move focus, letters
jump by label, Enter and Space choose, Escape closes to the trigger, Tab closes.
#### Returns
[`ReactProps`](../type-aliases/ReactProps.md)
***
### getTriggerProps()
```ts
getTriggerProps(): ReactProps;
```
Props for the menu button: id, aria-label (menu label plus the checked item), aria-haspopup,
aria-expanded, aria-controls. Click toggles; ArrowDown, Enter and Space open the menu,
ArrowUp opens it on the last item.
#### Returns
[`ReactProps`](../type-aliases/ReactProps.md)
***
### openMenu()
```ts
openMenu(focus?): void;
```
Open and focus an enabled item: the checked one (default; else the first), the first or the last.
#### Parameters
| Parameter | Type |
| ------ | ------ |
| `focus?` | `"selected"` \| `"first"` \| `"last"` |
#### Returns
`void`
---
Source: /api/react/interfaces/UseSuggestionMenuResult.md
# Interface: UseSuggestionMenuResult
Returned by `useSuggestionMenu()`: the controller state as fields, plus actions and prop getters.
## Extends
- [`SuggestionMenuState`](../../ui/interfaces/SuggestionMenuState.md)
## Properties
| Property | Modifier | Type | Description | Inherited from |
| ------ | ------ | ------ | ------ | ------ |
| `activeId` | `readonly` | `string` \| `null` | Id of the highlighted option, or null. | [`SuggestionMenuState`](../../ui/interfaces/SuggestionMenuState.md).[`activeId`](../../ui/interfaces/SuggestionMenuState.md#property-activeid) |
| `items` | `readonly` | readonly [`SuggestionItem`](../../ui/interfaces/SuggestionItem.md)[] | The items for the current query. Empty while closed. | [`SuggestionMenuState`](../../ui/interfaces/SuggestionMenuState.md).[`items`](../../ui/interfaces/SuggestionMenuState.md#property-items) |
| `loading` | `readonly` | `boolean` | An async `items` call is still running. | [`SuggestionMenuState`](../../ui/interfaces/SuggestionMenuState.md).[`loading`](../../ui/interfaces/SuggestionMenuState.md#property-loading) |
| `open` | `readonly` | `boolean` | A trigger match is active and there is at least one item. | [`SuggestionMenuState`](../../ui/interfaces/SuggestionMenuState.md).[`open`](../../ui/interfaces/SuggestionMenuState.md#property-open) |
| `query` | `readonly` | `string` | What was typed after the trigger character. Empty while closed. | [`SuggestionMenuState`](../../ui/interfaces/SuggestionMenuState.md).[`query`](../../ui/interfaces/SuggestionMenuState.md#property-query) |
| `reference` | `readonly` | [`VirtualReference`](../../ui/interfaces/VirtualReference.md) | Where the trigger character is; give it to your positioning code. | - |
| `status` | `readonly` | `string` | What the status region says, e.g. "3 suggestions". Empty while closed. | [`SuggestionMenuState`](../../ui/interfaces/SuggestionMenuState.md).[`status`](../../ui/interfaces/SuggestionMenuState.md#property-status) |
## Methods
### dismiss()
```ts
dismiss(): void;
```
Close until the user types somewhere else.
#### Returns
`void`
***
### getListboxProps()
```ts
getListboxProps(): ReactProps;
```
Props for the list: id, role="listbox", aria-label. Mousedown is prevented to keep focus in the editor.
#### Returns
[`ReactProps`](../type-aliases/ReactProps.md)
***
### getOptionProps()
```ts
getOptionProps(id): ReactProps;
```
Props for an option: id, role="option", aria-selected, data-active when highlighted. Click chooses it.
#### Parameters
| Parameter | Type |
| ------ | ------ |
| `id` | `string` |
#### Returns
[`ReactProps`](../type-aliases/ReactProps.md)
***
### getStatusProps()
```ts
getStatusProps(): ReactProps;
```
A polite live region announcing how many options there are.
#### Returns
[`ReactProps`](../type-aliases/ReactProps.md)
***
### select()
```ts
select(id): void;
```
Remove the typed trigger and query, run the item's command in the same undo step, and
focus the editor. Does nothing for an unknown id or while closed.
#### Parameters
| Parameter | Type |
| ------ | ------ |
| `id` | `string` |
#### Returns
`void`
---
Source: /api/react/interfaces/UseToolbarResult.md
# Interface: UseToolbarResult
Returned by `useToolbar()`.
## Properties
| Property | Modifier | Type | Description |
| ------ | ------ | ------ | ------ |
| `items` | `readonly` | readonly [`ToolbarItem`](../../ui/interfaces/ToolbarItem.md)[] | The items passed in `options`. |
| `state` | `readonly` | [`ToolbarState`](../../ui/interfaces/ToolbarState.md) | The toolbar state; the component re-renders when it changes. |
## Methods
### getCustomItemProps()
```ts
getCustomItemProps(id, props): ReactProps;
```
Add your own element (e.g. the link trigger) to the toolbar's arrow-key navigation.
#### Parameters
| Parameter | Type |
| ------ | ------ |
| `id` | `string` |
| `props` | [`ReactProps`](../type-aliases/ReactProps.md) |
#### Returns
[`ReactProps`](../type-aliases/ReactProps.md)
***
### getItemProps()
```ts
getItemProps(id): ReactProps;
```
Props for an item's button: aria-label, title with the shortcut, aria-keyshortcuts,
aria-pressed and data-state for toggles, disabled, roving tabindex. Click runs the command
without taking focus from the editor. Throws for an unknown id.
#### Parameters
| Parameter | Type |
| ------ | ------ |
| `id` | `string` |
#### Returns
[`ReactProps`](../type-aliases/ReactProps.md)
***
### getRootProps()
```ts
getRootProps(): ReactProps;
```
Props for the toolbar element: role, aria-label, aria-orientation. Arrow keys, Home and End
move focus between enabled items.
#### Returns
[`ReactProps`](../type-aliases/ReactProps.md)
---
Source: /api/react/interfaces/UseTooltipResult.md
# Interface: UseTooltipResult
Returned by `useTooltip()`.
## Properties
| Property | Modifier | Type | Description |
| ------ | ------ | ------ | ------ |
| `activeId` | `readonly` | `string` \| `null` | Id of the trigger whose tooltip is visible, or null. |
## Methods
### getTooltipProps()
```ts
getTooltipProps(id): ReactProps;
```
Props for the tooltip of `id`: id, role="tooltip", aria-hidden, data-state (`open`/`closed`).
#### Parameters
| Parameter | Type |
| ------ | ------ |
| `id` | `string` |
#### Returns
[`ReactProps`](../type-aliases/ReactProps.md)
***
### getTriggerProps()
```ts
getTriggerProps(id, options?): ReactProps;
```
Props for a trigger: shows its tooltip on hover (not touch) and focus after the delay, hides
on pointer leave, blur and mousedown. Adds aria-describedby only with `describe`.
#### Parameters
| Parameter | Type |
| ------ | ------ |
| `id` | `string` |
| `options?` | [`TooltipTriggerOptions`](../../ui/interfaces/TooltipTriggerOptions.md) |
#### Returns
[`ReactProps`](../type-aliases/ReactProps.md)
***
### hide()
```ts
hide(): void;
```
Hide the visible tooltip at once.
#### Returns
`void`
***
### show()
```ts
show(id): void;
```
Show the tooltip for `id` at once, without the delay.
#### Parameters
| Parameter | Type |
| ------ | ------ |
| `id` | `string` |
#### Returns
`void`
---
Source: /api/react/type-aliases/ReactProps.md
# Type Alias: ReactProps
```ts
type ReactProps = Record;
```
Props to spread on a React element, with React names (`tabIndex`, `onKeyDown`).
---
Source: /api/react/type-aliases/UseEditorOptions.md
# Type Alias: UseEditorOptions
```ts
type UseEditorOptions = Omit;
```
Options for `useEditor()`. `element` is handled by ``.
---
Source: /api/react/functions/EditorContent.md
# Function: EditorContent()
```ts
function EditorContent(__namedParameters): ReactElement;
```
The editable area. Renders a wrapper `
` that receives your props
(`className`, `id`, `data-*`) and an inner `
` that the editor owns.
Keeping them separate stops React and ProseMirror from fighting over the
same element's attributes (ProseMirror adds `class="ProseMirror"`, `role`, ARIA).
## Parameters
| Parameter | Type |
| ------ | ------ |
| `__namedParameters` | [`EditorContentProps`](../interfaces/EditorContentProps.md) |
## Returns
`ReactElement`
---
Source: /api/react/functions/mergeProps.md
# Function: mergeProps()
```ts
function mergeProps(...all): ReactProps;
```
Combine React props from several hooks for one element, e.g. a toolbar
button with a tooltip. Later props win, except event handlers (`onX`):
handlers for the same event all run, in order.
## Parameters
| Parameter | Type |
| ------ | ------ |
| ...`all` | [`ReactProps`](../type-aliases/ReactProps.md)[] |
## Returns
[`ReactProps`](../type-aliases/ReactProps.md)
## Example
```tsx
```
---
Source: /api/react/functions/toReactProps.md
# Function: toReactProps()
```ts
function toReactProps(props): ReactProps;
```
Convert framework-neutral props from `@writeon/ui` to React props.
## Parameters
| Parameter | Type |
| ------ | ------ |
| `props` | [`ElementProps`](../../ui/interfaces/ElementProps.md) |
## Returns
[`ReactProps`](../type-aliases/ReactProps.md)
---
Source: /api/react/functions/useBubbleMenu.md
# Function: useBubbleMenu()
```ts
function useBubbleMenu(editor, options?): UseBubbleMenuResult;
```
A toolbar that appears next to selected text: shown for text selections in
a focused editor, reached with Alt-F10, left with Escape. Positioning is
yours: place the element at `reference`. Options are read once.
## Parameters
| Parameter | Type |
| ------ | ------ |
| `editor` | [`Editor`](../../core/interfaces/Editor.md) |
| `options?` | [`BubbleMenuOptions`](../../ui/interfaces/BubbleMenuOptions.md) |
## Returns
[`UseBubbleMenuResult`](../interfaces/UseBubbleMenuResult.md)
---
Source: /api/react/functions/useEditor.md
# Function: useEditor()
```ts
function useEditor(options): Editor;
```
Create an editor for the lifetime of the component.
- The editor is created once. `content` and `label` are read on creation
only; use `editor.setContent()` to replace the document later.
- `editable` is applied whenever it changes.
- `onChange`, `onFocus` and `onBlur` always call the latest callback.
- The editor is destroyed when the component unmounts.
## Parameters
| Parameter | Type |
| ------ | ------ |
| `options` | [`UseEditorOptions`](../type-aliases/UseEditorOptions.md) |
## Returns
[`Editor`](../../core/interfaces/Editor.md)
## Example
```tsx
const editor = useEditor({ extensions, content: initial, label: 'Article text' })
return
```
---
Source: /api/react/functions/useEditorState.md
# Function: useEditorState()
```ts
function useEditorState(
editor,
selector,
isEqual?
): T;
```
Read part of the editor state and re-render only when it changes.
## Type Parameters
| Type Parameter |
| ------ |
| `T` |
## Parameters
| Parameter | Type | Default value |
| ------ | ------ | ------ |
| `editor` | [`Editor`](../../core/interfaces/Editor.md) | `undefined` |
| `selector` | (`snapshot`) => `T` | `undefined` |
| `isEqual?` | (`a`, `b`) => `boolean` | `Object.is` |
## Returns
`T`
## Example
```tsx
const isBold = useEditorState(editor, (s) => s.marks.has('bold'))
const canUndo = useEditorState(editor, (s) => s.canUndo)
```
---
Source: /api/react/functions/useImageDialog.md
# Function: useImageDialog()
```ts
function useImageDialog(editor, options?): UseImageDialogResult;
```
Add an image by address or edit the selected image's alt text, in an
accessible modal dialog (focus trap, Escape, alt required unless marked
decorative). Needs `advancedSchema()` in the editor. Options are read once.
## Parameters
| Parameter | Type |
| ------ | ------ |
| `editor` | [`Editor`](../../core/interfaces/Editor.md) |
| `options?` | [`ImageDialogOptions`](../../ui/interfaces/ImageDialogOptions.md) |
## Returns
[`UseImageDialogResult`](../interfaces/UseImageDialogResult.md)
---
Source: /api/react/functions/useLinkPopover.md
# Function: useLinkPopover()
```ts
function useLinkPopover(editor, options?): UseLinkPopoverResult;
```
Link add/edit form behaviour: validation, Escape, focus handling and the
`Mod-k` shortcut (pass `shortcut: false` to turn it off). Options are read once.
## Parameters
| Parameter | Type |
| ------ | ------ |
| `editor` | [`Editor`](../../core/interfaces/Editor.md) |
| `options?` | [`LinkPopoverOptions`](../../ui/interfaces/LinkPopoverOptions.md) |
## Returns
[`UseLinkPopoverResult`](../interfaces/UseLinkPopoverResult.md)
---
Source: /api/react/functions/useMenu.md
# Function: useMenu()
```ts
function useMenu(editor, options): UseMenuResult;
```
Menu button with one checked choice (e.g. the block type picker). Options are read once.
## Parameters
| Parameter | Type |
| ------ | ------ |
| `editor` | [`Editor`](../../core/interfaces/Editor.md) |
| `options` | [`MenuOptions`](../../ui/interfaces/MenuOptions.md) |
## Returns
[`UseMenuResult`](../interfaces/UseMenuResult.md)
## Example
```tsx
const blockType = useMenu(editor, { items: basicBlockTypeItems(), label: 'Text style' })
```
---
Source: /api/react/functions/useSuggestionMenu.md
# Function: useSuggestionMenu()
```ts
function useSuggestionMenu(editor, options): UseSuggestionMenuResult;
```
An inline list opened by a typed character: slash commands (`/`) or
mentions (`@`). Focus stays in the editor; arrows, Enter/Tab and Escape
drive the list. Options are read once.
## Parameters
| Parameter | Type |
| ------ | ------ |
| `editor` | [`Editor`](../../core/interfaces/Editor.md) |
| `options` | [`SuggestionMenuOptions`](../../ui/interfaces/SuggestionMenuOptions.md) |
## Returns
[`UseSuggestionMenuResult`](../interfaces/UseSuggestionMenuResult.md)
---
Source: /api/react/functions/useToolbar.md
# Function: useToolbar()
```ts
function useToolbar(editor, options): UseToolbarResult;
```
Accessible toolbar behaviour. Options are read once, like `useEditor()`.
## Parameters
| Parameter | Type |
| ------ | ------ |
| `editor` | [`Editor`](../../core/interfaces/Editor.md) |
| `options` | [`ToolbarOptions`](../../ui/interfaces/ToolbarOptions.md) |
## Returns
[`UseToolbarResult`](../interfaces/UseToolbarResult.md)
## Example
```tsx
const toolbar = useToolbar(editor, { items: basicToolbarItems() })
{toolbar.items.map((item) => )}
```
---
Source: /api/react/functions/useTooltip.md
# Function: useTooltip()
```ts
function useTooltip(options?): UseTooltipResult;
```
Accessible tooltips (WCAG 1.4.13) for many triggers; one is visible at a
time. Combine trigger props with others using `mergeProps()`.
## Parameters
| Parameter | Type |
| ------ | ------ |
| `options?` | [`TooltipOptions`](../../ui/interfaces/TooltipOptions.md) |
## Returns
[`UseTooltipResult`](../interfaces/UseTooltipResult.md)
---
Source: /api/server/reference.md
# @writeon/server
Never trust editor output: `validate` checks a document against your schema
and limits, `toSafeHTML` renders it to safe HTML.
## Interfaces
- [Issue](interfaces/Issue.md)
- [ValidateLimits](interfaces/ValidateLimits.md)
- [ValidateOptions](interfaces/ValidateOptions.md)
## Type Aliases
- [IssueCode](type-aliases/IssueCode.md)
- [ToSafeHTMLOptions](type-aliases/ToSafeHTMLOptions.md)
- [ValidateResult](type-aliases/ValidateResult.md)
## Functions
- [toSafeHTML](functions/toSafeHTML.md)
- [validate](functions/validate.md)
---
Source: /api/server/interfaces/Issue.md
# Interface: Issue
Something that was wrong with the input. `path` points into the input, e.g. `content[2].marks[0]`.
## Properties
| Property | Type | Description |
| ------ | ------ | ------ |
| `code` | [`IssueCode`](../type-aliases/IssueCode.md) | Kind of problem. |
| `message` | `string` | Human-readable description, in English. |
| `path` | `string` | Where in the input the problem is; `''` for the document itself. |
---
Source: /api/server/interfaces/ValidateLimits.md
# Interface: ValidateLimits
Size limits for `validate()`. Exceeding any of them rejects the document.
## Properties
| Property | Type | Description |
| ------ | ------ | ------ |
| `maxBytes?` | `number` | Maximum size of the serialized input in bytes (UTF-8). Default 1 000 000. |
| `maxDepth?` | `number` | Maximum nesting depth. Default 32. |
| `maxNodes?` | `number` | Maximum number of nodes and marks. Default 50 000. |
---
Source: /api/server/interfaces/ValidateOptions.md
# Interface: ValidateOptions
Options for `validate()`.
## Properties
| Property | Type | Description |
| ------ | ------ | ------ |
| `extensions` | readonly [`Extension`](../../core/interfaces/Extension.md)[] | The same extensions the editor uses. Pass one shared array; its schema is cached. |
| `limits?` | [`ValidateLimits`](ValidateLimits.md) | Size limits. Defaults are listed on `ValidateLimits`. |
| `mode?` | `"strip"` \| `"strict"` | `'strip'` (default) removes what is invalid and reports it in `removed`. `'strict'` rejects the whole document if anything would be removed. Limit violations are always rejected. |
| `urls?` | \{ `protocols?`: readonly `string`[]; \} | Allowed protocols for every `href`/`src` attribute. Default: http, https, mailto, tel. |
| `urls.protocols?` | readonly `string`[] | Allowed URL protocols, without the colon. |
---
Source: /api/server/type-aliases/IssueCode.md
# Type Alias: IssueCode
```ts
type IssueCode =
| "invalid-json"
| "invalid-shape"
| "version"
| "limit"
| "forbidden-key"
| "unknown-node"
| "unknown-mark"
| "unknown-attr"
| "invalid-attr"
| "unsafe-url"
| "invalid-content";
```
Kind of problem reported in an `Issue`.
---
Source: /api/server/type-aliases/ToSafeHTMLOptions.md
# Type Alias: ToSafeHTMLOptions
```ts
type ToSafeHTMLOptions = ToHTMLOptions;
```
Options for `toSafeHTML()`; the same as `toHTML()` from `@writeon/html`.
---
Source: /api/server/type-aliases/ValidateResult.md
# Type Alias: ValidateResult
```ts
type ValidateResult =
| {
doc: DocJSON;
ok: true;
removed: Issue[];
}
| {
errors: Issue[];
ok: false;
};
```
Result of `validate()`: the clean document, or why it was rejected.
## Union Members
### Type Literal
```ts
{
doc: DocJSON;
ok: true;
removed: Issue[];
}
```
#### doc
```ts
doc: DocJSON;
```
The rebuilt document, migrated to the current `schemaVersion`.
#### ok
```ts
ok: true;
```
The document is accepted.
#### removed
```ts
removed: Issue[];
```
What was stripped from the input. Always empty in `'strict'` mode.
***
### Type Literal
```ts
{
errors: Issue[];
ok: false;
}
```
#### errors
```ts
errors: Issue[];
```
Why it was rejected.
#### ok
```ts
ok: false;
```
The document is rejected.
---
Source: /api/server/functions/toSafeHTML.md
# Function: toSafeHTML()
```ts
function toSafeHTML(doc, options): string;
```
Render a document to an HTML string without a DOM. Safe by construction:
only tags produced by the schema are emitted, all text and attribute values
are escaped, event-handler attributes are never written and URLs are checked
again. Pass a document that went through `validate()`; a document that does
not fit the schema throws. The same renderer as `toHTML()` in `@writeon/html`.
## Parameters
| Parameter | Type |
| ------ | ------ |
| `doc` | [`DocJSON`](../../core/interfaces/DocJSON.md) |
| `options` | [`ToHTMLOptions`](../../html/interfaces/ToHTMLOptions.md) |
## Returns
`string`
## Example
```ts
const html = toSafeHTML(storedDoc, { extensions })
```
---
Source: /api/server/functions/validate.md
# Function: validate()
```ts
function validate(input, options): ValidateResult;
```
Check a document received from a client before storing it. Never trust what
the editor sends: a request can be crafted by hand.
The input is never mutated or passed through: the result is rebuilt from
scratch using only what the schema allows.
## Parameters
| Parameter | Type |
| ------ | ------ |
| `input` | `unknown` |
| `options` | [`ValidateOptions`](../interfaces/ValidateOptions.md) |
## Returns
[`ValidateResult`](../type-aliases/ValidateResult.md)
## Example
```ts
const result = validate(req.body.doc, { extensions })
if (!result.ok) return res.status(400).json(result.errors)
await db.save(result.doc)
```
---
Source: /api/ui/reference.md
# @writeon/ui
Headless UI controllers: behaviour and accessibility as state and prop
getters for toolbars, menus, links, tooltips, the image dialog, the bubble
menu and suggestions. Renders nothing.
## Interfaces
- [BasicBlockTypeItemsOptions](interfaces/BasicBlockTypeItemsOptions.md)
- [BasicToolbarItemsOptions](interfaces/BasicToolbarItemsOptions.md)
- [BubbleMenu](interfaces/BubbleMenu.md)
- [BubbleMenuOptions](interfaces/BubbleMenuOptions.md)
- [BubbleMenuState](interfaces/BubbleMenuState.md)
- [ElementProps](interfaces/ElementProps.md)
- [ImageDialog](interfaces/ImageDialog.md)
- [ImageDialogOptions](interfaces/ImageDialogOptions.md)
- [ImageDialogState](interfaces/ImageDialogState.md)
- [LinkPopover](interfaces/LinkPopover.md)
- [LinkPopoverOptions](interfaces/LinkPopoverOptions.md)
- [LinkPopoverState](interfaces/LinkPopoverState.md)
- [Menu](interfaces/Menu.md)
- [MenuItem](interfaces/MenuItem.md)
- [MenuOptions](interfaces/MenuOptions.md)
- [MenuState](interfaces/MenuState.md)
- [Messages](interfaces/Messages.md)
- [SuggestionItem](interfaces/SuggestionItem.md)
- [SuggestionMenu](interfaces/SuggestionMenu.md)
- [SuggestionMenuOptions](interfaces/SuggestionMenuOptions.md)
- [SuggestionMenuState](interfaces/SuggestionMenuState.md)
- [Toolbar](interfaces/Toolbar.md)
- [ToolbarItem](interfaces/ToolbarItem.md)
- [ToolbarOptions](interfaces/ToolbarOptions.md)
- [ToolbarState](interfaces/ToolbarState.md)
- [Tooltip](interfaces/Tooltip.md)
- [TooltipOptions](interfaces/TooltipOptions.md)
- [TooltipState](interfaces/TooltipState.md)
- [TooltipTriggerOptions](interfaces/TooltipTriggerOptions.md)
- [UIEvent](interfaces/UIEvent.md)
- [VirtualReference](interfaces/VirtualReference.md)
## Type Aliases
- [BasicToolbarItemId](type-aliases/BasicToolbarItemId.md)
- [UIEventName](type-aliases/UIEventName.md)
## Variables
- [en](variables/en.md)
## Functions
- [applyProps](functions/applyProps.md)
- [ariaShortcut](functions/ariaShortcut.md)
- [basicBlockTypeItems](functions/basicBlockTypeItems.md)
- [basicToolbarItems](functions/basicToolbarItems.md)
- [createBubbleMenu](functions/createBubbleMenu.md)
- [createImageDialog](functions/createImageDialog.md)
- [createLinkPopover](functions/createLinkPopover.md)
- [createMenu](functions/createMenu.md)
- [createSuggestionMenu](functions/createSuggestionMenu.md)
- [createToolbar](functions/createToolbar.md)
- [createTooltip](functions/createTooltip.md)
- [displayShortcut](functions/displayShortcut.md)
- [filterSuggestions](functions/filterSuggestions.md)
- [format](functions/format.md)
- [isApplePlatform](functions/isApplePlatform.md)
- [matchesShortcut](functions/matchesShortcut.md)
- [mergeElementProps](functions/mergeElementProps.md)
- [resolveMessages](functions/resolveMessages.md)
---
Source: /api/ui/interfaces/BasicBlockTypeItemsOptions.md
# Interface: BasicBlockTypeItemsOptions
Options for `basicBlockTypeItems()`.
## Properties
| Property | Type | Description |
| ------ | ------ | ------ |
| `levels?` | readonly `number`[] | Heading levels to offer. Default `[1, 2, 3]`; match `basic({ heading: { levels } })`. |
| `messages?` | `Partial`\<[`Messages`](Messages.md)\> | Labels to override; English by default. |
---
Source: /api/ui/interfaces/BasicToolbarItemsOptions.md
# Interface: BasicToolbarItemsOptions
Options for `basicToolbarItems()`.
## Properties
| Property | Type | Description |
| ------ | ------ | ------ |
| `exclude?` | readonly [`BasicToolbarItemId`](../type-aliases/BasicToolbarItemId.md)[] | Items to leave out. |
| `messages?` | `Partial`\<[`Messages`](Messages.md)\> | Labels to override; English by default. |
---
Source: /api/ui/interfaces/BubbleMenu.md
# Interface: BubbleMenu
Controller returned by `createBubbleMenu()`.
## Properties
| Property | Modifier | Type | Description |
| ------ | ------ | ------ | ------ |
| `reference` | `readonly` | [`VirtualReference`](VirtualReference.md) | Where the selection is on screen; pass it to your positioning code. |
## Methods
### dismiss()
```ts
dismiss(): void;
```
Hide until the selection changes; focus goes back to the editor.
#### Returns
`void`
***
### focusFirst()
```ts
focusFirst(): void;
```
Move focus to the first control in the bubble (what the focus shortcut does).
#### Returns
`void`
***
### getBubbleProps()
```ts
getBubbleProps(): ElementProps;
```
Props for the bubble element: id and data-state (`open` or `closed`). Escape
dismisses it, and mousedown outside form fields is prevented to keep the selection.
#### Returns
[`ElementProps`](ElementProps.md)
***
### getState()
```ts
getState(): BubbleMenuState;
```
The current state; the same object until something changes.
#### Returns
[`BubbleMenuState`](BubbleMenuState.md)
***
### subscribe()
```ts
subscribe(listener): () => void;
```
Call `listener` on every state change; returns the unsubscribe function.
#### Parameters
| Parameter | Type |
| ------ | ------ |
| `listener` | () => `void` |
#### Returns
() => `void`
---
Source: /api/ui/interfaces/BubbleMenuOptions.md
# Interface: BubbleMenuOptions
Options for `createBubbleMenu()`.
## Properties
| Property | Type | Description |
| ------ | ------ | ------ |
| `focusShortcut?` | `string` \| `false` | Moves keyboard focus from the editor into the bubble. Default `Alt-F10`; `false` turns it off. |
| `idPrefix?` | `string` | Prefix for element ids. Default: generated. |
| `shouldShow?` | (`editor`) => `boolean` | When the bubble may show, on top of the built-in rules (text selected, editor editable and focused, pointer not still selecting). Default: not inside a code block. |
---
Source: /api/ui/interfaces/BubbleMenuState.md
# Interface: BubbleMenuState
Snapshot of a bubble menu.
## Properties
| Property | Modifier | Type | Description |
| ------ | ------ | ------ | ------ |
| `open` | `readonly` | `boolean` | The bubble should be shown. |
---
Source: /api/ui/interfaces/ElementProps.md
# Interface: ElementProps
Framework-neutral element props returned by prop getters. Adapters convert
them: React → `onClick`, `tabIndex`; Vue → `onClick`, `onKeydown`.
Attribute values of `undefined` or `false` mean "leave the attribute out".
## Properties
| Property | Type | Description |
| ------ | ------ | ------ |
| `attrs` | `Record`\<`string`, `string` \| `number` \| `boolean` \| `undefined`\> | Attributes by DOM name, e.g. `aria-expanded`, `tabindex`, `id`. |
| `on` | `Partial`\<`Record`\<[`UIEventName`](../type-aliases/UIEventName.md), (`event`) => `void`\>\> | Event handlers by DOM event name. |
---
Source: /api/ui/interfaces/ImageDialog.md
# Interface: ImageDialog
Controller returned by `createImageDialog()`.
## Methods
### apply()
```ts
apply(): boolean;
```
Validate and apply. Returns false and sets `error` when something is missing or refused.
#### Returns
`boolean`
***
### close()
```ts
close(): void;
```
Close without applying and focus the editor. Does nothing while closed.
#### Returns
`void`
***
### getAltHintProps()
```ts
getAltHintProps(): ElementProps;
```
Props for the hint text the alt input's aria-describedby points to.
#### Returns
[`ElementProps`](ElementProps.md)
***
### getAltInputProps()
```ts
getAltInputProps(): ElementProps;
```
Props for the alternative text input: id, value, aria-required, aria-describedby (hint, and
error when invalid). Disabled and empty while the image is marked decorative.
#### Returns
[`ElementProps`](ElementProps.md)
***
### getBackdropProps()
```ts
getBackdropProps(): ElementProps;
```
An optional full-screen layer behind the panel; a press on it closes the dialog.
#### Returns
[`ElementProps`](ElementProps.md)
***
### getCancelProps()
```ts
getCancelProps(): ElementProps;
```
Props for the Cancel button, which closes the dialog.
#### Returns
[`ElementProps`](ElementProps.md)
***
### getDecorativeProps()
```ts
getDecorativeProps(): ElementProps;
```
Props for the "decorative image" checkbox.
#### Returns
[`ElementProps`](ElementProps.md)
***
### getDialogProps()
```ts
getDialogProps(): ElementProps;
```
The modal panel. Traps Tab inside and closes on Escape.
#### Returns
[`ElementProps`](ElementProps.md)
***
### getErrorProps()
```ts
getErrorProps(): ElementProps;
```
Props for the error message: role="alert", hidden while there is no error.
#### Returns
[`ElementProps`](ElementProps.md)
***
### getFormProps()
```ts
getFormProps(): ElementProps;
```
Props for the form: submit calls `apply()` instead of submitting the page.
#### Returns
[`ElementProps`](ElementProps.md)
***
### getSrcInputProps()
```ts
getSrcInputProps(): ElementProps;
```
Props for the address input: id, value, inputmode="url"; aria-invalid and aria-describedby on error.
#### Returns
[`ElementProps`](ElementProps.md)
***
### getState()
```ts
getState(): ImageDialogState;
```
The current state; the same object until something changes.
#### Returns
[`ImageDialogState`](ImageDialogState.md)
***
### getTitleProps()
```ts
getTitleProps(): ElementProps;
```
Props for the dialog title: the id the dialog's aria-labelledby points to.
#### Returns
[`ElementProps`](ElementProps.md)
***
### getTriggerProps()
```ts
getTriggerProps(): ElementProps;
```
Props for the toolbar button: aria-label (add or edit image), aria-haspopup, aria-expanded,
data-state; disabled without image support. Click opens the dialog; mousedown is prevented
to keep the selection.
#### Returns
[`ElementProps`](ElementProps.md)
***
### openDialog()
```ts
openDialog(): void;
```
Open for the selected image (edit) or a new one (insert).
#### Returns
`void`
***
### setAlt()
```ts
setAlt(alt): void;
```
Set the alternative text field; clears an alt text error.
#### Parameters
| Parameter | Type |
| ------ | ------ |
| `alt` | `string` |
#### Returns
`void`
***
### setDecorative()
```ts
setDecorative(decorative): void;
```
Mark the image as decorative (stored with `alt=""`); turning it on clears an alt text error.
#### Parameters
| Parameter | Type |
| ------ | ------ |
| `decorative` | `boolean` |
#### Returns
`void`
***
### setSrc()
```ts
setSrc(src): void;
```
Set the address field; clears an address error.
#### Parameters
| Parameter | Type |
| ------ | ------ |
| `src` | `string` |
#### Returns
`void`
***
### subscribe()
```ts
subscribe(listener): () => void;
```
Call `listener` on every state change; returns the unsubscribe function.
#### Parameters
| Parameter | Type |
| ------ | ------ |
| `listener` | () => `void` |
#### Returns
() => `void`
---
Source: /api/ui/interfaces/ImageDialogOptions.md
# Interface: ImageDialogOptions
Options for `createImageDialog()`.
## Properties
| Property | Type | Description |
| ------ | ------ | ------ |
| `idPrefix?` | `string` | Prefix for element ids, needed when several editors share a page. Default: generated. |
| `messages?` | `Partial`\<[`Messages`](Messages.md)\> | Overrides for the trigger labels and error messages; English by default. |
---
Source: /api/ui/interfaces/ImageDialogState.md
# Interface: ImageDialogState
Snapshot of an image dialog.
## Extended by
- [`UseImageDialogResult`](../../react/interfaces/UseImageDialogResult.md)
## Properties
| Property | Modifier | Type | Description |
| ------ | ------ | ------ | ------ |
| `alt` | `readonly` | `string` | Current value of the alternative text field. |
| `available` | `readonly` | `boolean` | Whether the editor can hold images at all (has `advancedSchema()`). |
| `decorative` | `readonly` | `boolean` | Decorative images get `alt=""` and are skipped by screen readers. |
| `error` | `readonly` | `string` \| `null` | Validation message, or null. |
| `errorField` | `readonly` | `"src"` \| `"alt"` \| `null` | Which field the error belongs to. |
| `imageSelected` | `readonly` | `boolean` | Whether an image is selected, so the trigger opens in "edit" mode. |
| `mode` | `readonly` | `"insert"` \| `"edit"` | "insert" adds a new image by address; "edit" changes the selected image. |
| `open` | `readonly` | `boolean` | The dialog is open. |
| `src` | `readonly` | `string` | Current value of the address field. |
---
Source: /api/ui/interfaces/LinkPopover.md
# Interface: LinkPopover
Controller returned by `createLinkPopover()`.
## Methods
### apply()
```ts
apply(): boolean;
```
Apply the address with `setLink()` and close. An empty address removes the link. Returns
false and sets `error` when the address is refused.
#### Returns
`boolean`
***
### close()
```ts
close(options?): void;
```
Close without applying. Focuses the editor unless `focusEditor` is false.
#### Parameters
| Parameter | Type |
| ------ | ------ |
| `options?` | \{ `focusEditor?`: `boolean`; \} |
| `options.focusEditor?` | `boolean` |
#### Returns
`void`
***
### getErrorProps()
```ts
getErrorProps(): ElementProps;
```
Props for the error message: role="alert", hidden while there is no error.
#### Returns
[`ElementProps`](ElementProps.md)
***
### getFormProps()
```ts
getFormProps(): ElementProps;
```
Props for the form: role="group", aria-label. Submit calls `apply()`.
#### Returns
[`ElementProps`](ElementProps.md)
***
### getInputProps()
```ts
getInputProps(): ElementProps;
```
Props for the address input: aria-label, value, aria-invalid on error. Escape closes.
#### Returns
[`ElementProps`](ElementProps.md)
***
### getRemoveProps()
```ts
getRemoveProps(): ElementProps;
```
Props for the Remove button; hidden unless the selection is in a link.
#### Returns
[`ElementProps`](ElementProps.md)
***
### getState()
```ts
getState(): LinkPopoverState;
```
The current state; the same object until something changes.
#### Returns
[`LinkPopoverState`](LinkPopoverState.md)
***
### getTriggerProps()
```ts
getTriggerProps(): ElementProps;
```
Props for the toolbar button: id, aria-label, title with the shortcut, aria-keyshortcuts,
aria-pressed (inside a link), aria-expanded, aria-controls. Click toggles the form.
#### Returns
[`ElementProps`](ElementProps.md)
***
### openPopover()
```ts
openPopover(): void;
```
Open the form, filled with the current link's address or `https://`, and focus the field.
#### Returns
`void`
***
### remove()
```ts
remove(): void;
```
Remove the link at the selection and close.
#### Returns
`void`
***
### setHref()
```ts
setHref(href): void;
```
Set the address field; clears the error.
#### Parameters
| Parameter | Type |
| ------ | ------ |
| `href` | `string` |
#### Returns
`void`
***
### subscribe()
```ts
subscribe(listener): () => void;
```
Call `listener` on every state change; returns the unsubscribe function.
#### Parameters
| Parameter | Type |
| ------ | ------ |
| `listener` | () => `void` |
#### Returns
() => `void`
---
Source: /api/ui/interfaces/LinkPopoverOptions.md
# Interface: LinkPopoverOptions
Options for `createLinkPopover()`.
## Properties
| Property | Type | Description |
| ------ | ------ | ------ |
| `idPrefix?` | `string` | Prefix for element ids, needed when several editors share a page. Default: generated. |
| `messages?` | `Partial`\<[`Messages`](Messages.md)\> | Overrides for the labels and the error message; English by default. |
| `shortcut?` | `string` \| `false` | Shortcut that opens the popover from the editor. Default `Mod-k`; `false` turns it off. |
| `title?` | `boolean` | Set the native `title` tooltip on the trigger. Turn off when you use `createTooltip()`. Default true. |
---
Source: /api/ui/interfaces/LinkPopoverState.md
# Interface: LinkPopoverState
Snapshot of a link popover.
## Extended by
- [`UseLinkPopoverResult`](../../react/interfaces/UseLinkPopoverResult.md)
## Properties
| Property | Modifier | Type | Description |
| ------ | ------ | ------ | ------ |
| `error` | `readonly` | `string` \| `null` | Validation message, or null. |
| `href` | `readonly` | `string` | Current value of the address field. |
| `isEditing` | `readonly` | `boolean` | Whether the cursor or selection is inside an existing link. |
| `open` | `readonly` | `boolean` | The form is open. |
---
Source: /api/ui/interfaces/Menu.md
# Interface: Menu
Controller returned by `createMenu()`.
## Properties
| Property | Modifier | Type | Description |
| ------ | ------ | ------ | ------ |
| `items` | `readonly` | readonly [`MenuItem`](MenuItem.md)[] | The items passed in `options`. |
## Methods
### close()
```ts
close(options?): void;
```
Close and move focus to the trigger (default), the editor, or nowhere.
#### Parameters
| Parameter | Type |
| ------ | ------ |
| `options?` | \{ `focus?`: `"editor"` \| `"trigger"` \| `"none"`; \} |
| `options.focus?` | `"editor"` \| `"trigger"` \| `"none"` |
#### Returns
`void`
***
### getItemProps()
```ts
getItemProps(id): ElementProps;
```
Props for an item: role `menuitemradio` with aria-checked for choices, `menuitem` for actions;
aria-disabled when it cannot run. Click selects it. Throws for an unknown id.
#### Parameters
| Parameter | Type |
| ------ | ------ |
| `id` | `string` |
#### Returns
[`ElementProps`](ElementProps.md)
***
### getMenuProps()
```ts
getMenuProps(): ElementProps;
```
Props for the menu: role="menu", aria-labelledby. Arrow keys, Home and End move focus, letters
jump by label, Enter and Space choose, Escape closes to the trigger, Tab closes.
#### Returns
[`ElementProps`](ElementProps.md)
***
### getState()
```ts
getState(): MenuState;
```
The current state; the same object until something changes.
#### Returns
[`MenuState`](MenuState.md)
***
### getTriggerProps()
```ts
getTriggerProps(): ElementProps;
```
Props for the menu button: id, aria-label (menu label plus the checked item), aria-haspopup,
aria-expanded, aria-controls. Click toggles; ArrowDown, Enter and Space open the menu,
ArrowUp opens it on the last item.
#### Returns
[`ElementProps`](ElementProps.md)
***
### openMenu()
```ts
openMenu(focus?): void;
```
Open and focus an enabled item: the checked one (default; else the first), the first or the last.
#### Parameters
| Parameter | Type |
| ------ | ------ |
| `focus?` | `"selected"` \| `"first"` \| `"last"` |
#### Returns
`void`
***
### select()
```ts
select(id): void;
```
Close, focus the editor and run the item's command. Ignored for a disabled or unknown item.
#### Parameters
| Parameter | Type |
| ------ | ------ |
| `id` | `string` |
#### Returns
`void`
***
### subscribe()
```ts
subscribe(listener): () => void;
```
Call `listener` on every state change; returns the unsubscribe function.
#### Parameters
| Parameter | Type |
| ------ | ------ |
| `listener` | () => `void` |
#### Returns
() => `void`
---
Source: /api/ui/interfaces/MenuItem.md
# Interface: MenuItem
One entry in a menu.
## Properties
| Property | Type | Description |
| ------ | ------ | ------ |
| `command` | () => [`Command`](../../core/type-aliases/Command.md) | The command the item runs; also decides whether it is enabled (`editor.can()`). |
| `id` | `string` | Unique within the menu. |
| `isActive?` | (`editor`) => `boolean` | Makes the item a choice (`menuitemradio`); the checked item is the first whose `isActive` returns true. Leave it out for actions (`menuitem`), such as "Add row". |
| `label` | `string` | Text shown for the item; also used for type-ahead. |
---
Source: /api/ui/interfaces/MenuOptions.md
# Interface: MenuOptions
Options for `createMenu()`.
## Properties
| Property | Type | Description |
| ------ | ------ | ------ |
| `idPrefix?` | `string` | Prefix for element ids, needed when several menus share a page. Default: generated. |
| `items` | readonly [`MenuItem`](MenuItem.md)[] | The menu items, in display order. |
| `label` | `string` | Accessible name of the menu and its button. |
---
Source: /api/ui/interfaces/MenuState.md
# Interface: MenuState
Snapshot of a menu.
## Extended by
- [`UseMenuResult`](../../react/interfaces/UseMenuResult.md)
## Properties
| Property | Modifier | Type | Description |
| ------ | ------ | ------ | ------ |
| `enabled` | `readonly` | `Readonly`\<`Record`\<`string`, `boolean`\>\> | Whether each item (by id) can run now. The checked item is always enabled. |
| `open` | `readonly` | `boolean` | The menu is open. |
| `selected` | `readonly` | [`MenuItem`](MenuItem.md) \| `null` | The checked item (e.g. the current block type), or null. |
---
Source: /api/ui/interfaces/Messages.md
# Interface: Messages
Every text the UI shows or announces. English is built in; other languages are separate imports.
## Properties
| Property | Type | Description |
| ------ | ------ | ------ |
| `addColumnAfter` | `string` | Table menu item. |
| `addColumnBefore` | `string` | Table menu item. |
| `addRowAfter` | `string` | Table menu item. |
| `addRowBefore` | `string` | Table menu item. |
| `alignCenter` | `string` | Center button. |
| `alignLeft` | `string` | Align left button. |
| `alignRight` | `string` | Align right button. |
| `blockquote` | `string` | Quote button label. |
| `blockType` | `string` | Name of the block type menu. |
| `bold` | `string` | Bold button label. |
| `bulletList` | `string` | Bulleted list button label. |
| `cancel` | `string` | Cancel button in dialogs. |
| `clearFormatting` | `string` | Clear formatting button label. |
| `code` | `string` | Inline code button label. |
| `codeBlock` | `string` | Code block button label. |
| `commands` | `string` | Name of the slash command list. |
| `defaultColor` | `string` | The menu choice that removes the colour. |
| `defaultFont` | `string` | The menu choice that removes the font (the editor's own). |
| `deleteColumn` | `string` | Table menu item. |
| `deleteRow` | `string` | Table menu item. |
| `deleteTable` | `string` | Table menu item. |
| `fontFamily` | `string` | Font family menu. |
| `heading` | `string` | `{level}` is replaced with the heading level. |
| `image` | `string` | Trigger and dialog title when adding an image. |
| `imageAlt` | `string` | Label of the alternative text input. |
| `imageAltHint` | `string` | Hint under the alternative text input. |
| `imageAltRequired` | `string` | Error shown when there is no alternative text and the image is not marked decorative. |
| `imageDecorative` | `string` | Label of the "decorative image" checkbox. |
| `imageEdit` | `string` | Trigger and dialog title when an image is selected. |
| `imageFromUrl` | `string` | Menu item that opens the image dialog to add an image by address. |
| `imageInsert` | `string` | Submit button when adding an image. |
| `imageInvalid` | `string` | Error shown when the image address is not allowed. |
| `imageSave` | `string` | Submit button when editing an image. |
| `imageUpload` | `string` | Image menu item that opens the file picker. |
| `imageUploading` | `string` | Accessible label of the placeholder shown while an image uploads. |
| `imageUrl` | `string` | Label of the image address input. |
| `insertTable` | `string` | Label of the insert table button and slash command. |
| `italic` | `string` | Italic button label. |
| `link` | `string` | Link popover trigger label. |
| `linkApply` | `string` | Button that applies the link. |
| `linkDialog` | `string` | Accessible name of the link form. |
| `linkInvalid` | `string` | Error shown when the link address is not allowed. |
| `linkRemove` | `string` | Button that removes the link. |
| `linkUrl` | `string` | Label of the link address input. |
| `mentions` | `string` | Name of the mention list. |
| `mergeCells` | `string` | Table menu item. |
| `orderedList` | `string` | Numbered list button label. |
| `paragraph` | `string` | Block type menu item for a plain paragraph. |
| `redo` | `string` | Redo button label. |
| `selectionToolbar` | `string` | Name of the toolbar next to selected text. |
| `splitCell` | `string` | Table menu item. |
| `strike` | `string` | Strikethrough button label. |
| `suggestionCount` | `string` | `{count}` is replaced with the number of options in a suggestion list. |
| `table` | `string` | Name of the table actions menu. |
| `taskList` | `string` | Task list button label. |
| `textColor` | `string` | Text colour menu. |
| `toggleHeaderRow` | `string` | Table menu item that turns the header row on or off. |
| `toolbar` | `string` | Accessible name of the main toolbar. |
| `underline` | `string` | Underline button label. |
| `undo` | `string` | Undo button label. |
| `uploadFailed` | `string` | Error when an upload fails. `{name}` is replaced with the file name. |
| `uploadSize` | `string` | Error when a file is too large. `{name}` is replaced with the file name. |
| `uploadType` | `string` | `{name}` is replaced with the file name. |
---
Source: /api/ui/interfaces/SuggestionItem.md
# Interface: SuggestionItem
One option in a suggestion menu.
## Properties
| Property | Type | Description |
| ------ | ------ | ------ |
| `command` | () => [`Command`](../../core/type-aliases/Command.md) | Runs after the typed trigger and query are removed, in the same undo step. |
| `description?` | `string` | Extra line shown and announced with the option. |
| `id` | `string` | Unique within the list. |
| `keywords?` | readonly `string`[] | Extra words `filterSuggestions()` matches, e.g. `['h1', 'title']`. |
| `label` | `string` | Text shown for the option; `filterSuggestions()` matches it. |
---
Source: /api/ui/interfaces/SuggestionMenu.md
# Interface: SuggestionMenu
Controller returned by `createSuggestionMenu()`.
## Properties
| Property | Modifier | Type | Description |
| ------ | ------ | ------ | ------ |
| `reference` | `readonly` | [`VirtualReference`](VirtualReference.md) | Where the trigger character is on screen; pass it to your positioning code. |
## Methods
### dismiss()
```ts
dismiss(): void;
```
Close until the user types somewhere else.
#### Returns
`void`
***
### getListboxProps()
```ts
getListboxProps(): ElementProps;
```
Props for the list: id, role="listbox", aria-label. Mousedown is prevented to keep focus in the editor.
#### Returns
[`ElementProps`](ElementProps.md)
***
### getOptionProps()
```ts
getOptionProps(id): ElementProps;
```
Props for an option: id, role="option", aria-selected, data-active when highlighted. Click chooses it.
#### Parameters
| Parameter | Type |
| ------ | ------ |
| `id` | `string` |
#### Returns
[`ElementProps`](ElementProps.md)
***
### getState()
```ts
getState(): SuggestionMenuState;
```
The current state; the same object until something changes.
#### Returns
[`SuggestionMenuState`](SuggestionMenuState.md)
***
### getStatusProps()
```ts
getStatusProps(): ElementProps;
```
A polite live region announcing how many options there are.
#### Returns
[`ElementProps`](ElementProps.md)
***
### select()
```ts
select(id): void;
```
Remove the typed trigger and query, run the item's command in the same undo step, and
focus the editor. Does nothing for an unknown id or while closed.
#### Parameters
| Parameter | Type |
| ------ | ------ |
| `id` | `string` |
#### Returns
`void`
***
### subscribe()
```ts
subscribe(listener): () => void;
```
Call `listener` on every state change; returns the unsubscribe function.
#### Parameters
| Parameter | Type |
| ------ | ------ |
| `listener` | () => `void` |
#### Returns
() => `void`
---
Source: /api/ui/interfaces/SuggestionMenuOptions.md
# Interface: SuggestionMenuOptions
Options for `createSuggestionMenu()`.
## Properties
| Property | Type | Description |
| ------ | ------ | ------ |
| `char` | `string` | The character that opens the menu, e.g. `/` or `@`. |
| `idPrefix?` | `string` | Prefix for element ids. Default: generated. |
| `items` | (`query`) => \| readonly [`SuggestionItem`](SuggestionItem.md)[] \| `Promise`\ | The items for a query (what was typed after `char`). May be async. |
| `label` | `string` | Accessible name of the list, e.g. "Commands" or "People". |
| `maxQueryLength?` | `number` | Longest query that keeps the menu open. Default 50. |
| `messages?` | `Partial`\<[`Messages`](Messages.md)\> | Overrides for the status text (`suggestionCount`); English by default. |
---
Source: /api/ui/interfaces/SuggestionMenuState.md
# Interface: SuggestionMenuState
Snapshot of a suggestion menu.
## Extended by
- [`UseSuggestionMenuResult`](../../react/interfaces/UseSuggestionMenuResult.md)
## Properties
| Property | Modifier | Type | Description |
| ------ | ------ | ------ | ------ |
| `activeId` | `readonly` | `string` \| `null` | Id of the highlighted option, or null. |
| `items` | `readonly` | readonly [`SuggestionItem`](SuggestionItem.md)[] | The items for the current query. Empty while closed. |
| `loading` | `readonly` | `boolean` | An async `items` call is still running. |
| `open` | `readonly` | `boolean` | A trigger match is active and there is at least one item. |
| `query` | `readonly` | `string` | What was typed after the trigger character. Empty while closed. |
| `status` | `readonly` | `string` | What the status region says, e.g. "3 suggestions". Empty while closed. |
---
Source: /api/ui/interfaces/Toolbar.md
# Interface: Toolbar
Controller returned by `createToolbar()`.
## Properties
| Property | Modifier | Type | Description |
| ------ | ------ | ------ | ------ |
| `items` | `readonly` | readonly [`ToolbarItem`](ToolbarItem.md)[] | The items passed in `options`. |
## Methods
### getCustomItemProps()
```ts
getCustomItemProps(id, props): ElementProps;
```
Make an element that is not one of `items` (for example the link
popover's trigger) part of the toolbar's keyboard navigation. Its own
props are kept; the toolbar adds the roving tabindex and focus tracking.
#### Parameters
| Parameter | Type |
| ------ | ------ |
| `id` | `string` |
| `props` | [`ElementProps`](ElementProps.md) |
#### Returns
[`ElementProps`](ElementProps.md)
***
### getItemProps()
```ts
getItemProps(id): ElementProps;
```
Props for an item's button: aria-label, title with the shortcut, aria-keyshortcuts,
aria-pressed and data-state for toggles, disabled, roving tabindex. Click runs the command
without taking focus from the editor. Throws for an unknown id.
#### Parameters
| Parameter | Type |
| ------ | ------ |
| `id` | `string` |
#### Returns
[`ElementProps`](ElementProps.md)
***
### getRootProps()
```ts
getRootProps(): ElementProps;
```
Props for the toolbar element: role, aria-label, aria-orientation. Arrow keys, Home and End
move focus between enabled items.
#### Returns
[`ElementProps`](ElementProps.md)
***
### getState()
```ts
getState(): ToolbarState;
```
The current state; the same object until something changes.
#### Returns
[`ToolbarState`](ToolbarState.md)
***
### subscribe()
```ts
subscribe(listener): () => void;
```
Listen for state changes. The toolbar follows the editor only while someone listens.
#### Parameters
| Parameter | Type |
| ------ | ------ |
| `listener` | () => `void` |
#### Returns
() => `void`
---
Source: /api/ui/interfaces/ToolbarItem.md
# Interface: ToolbarItem
One button in a toolbar.
## Properties
| Property | Type | Description |
| ------ | ------ | ------ |
| `command` | () => [`Command`](../../core/type-aliases/Command.md) | Factory for the command the button runs. |
| `group?` | `string` | Items with the same group sit together; render a separator where it changes. |
| `id` | `string` | Unique within the toolbar. |
| `isActive?` | (`editor`) => `boolean` | Makes the button a toggle with `aria-pressed`. |
| `label` | `string` | Accessible name, also used in the tooltip. |
| `shortcut?` | `string` | ProseMirror-style shortcut, e.g. `Mod-b`. Announced via `aria-keyshortcuts`. |
---
Source: /api/ui/interfaces/ToolbarOptions.md
# Interface: ToolbarOptions
Options for `createToolbar()`.
## Properties
| Property | Type | Description |
| ------ | ------ | ------ |
| `items` | readonly [`ToolbarItem`](ToolbarItem.md)[] | The buttons, in display order. |
| `label?` | `string` | Accessible name of the toolbar. Default: `messages.toolbar` ("Formatting"). |
| `messages?` | `Partial`\<[`Messages`](Messages.md)\> | Overrides for the default toolbar label; English by default. |
| `orientation?` | `"horizontal"` \| `"vertical"` | Which arrow keys move between items, also set as `aria-orientation`. Default `'horizontal'`. |
| `title?` | `boolean` | Set the native `title` tooltip on items. Turn off when you use `createTooltip()`. Default true. |
---
Source: /api/ui/interfaces/ToolbarState.md
# Interface: ToolbarState
Snapshot of a toolbar.
## Properties
| Property | Modifier | Type | Description |
| ------ | ------ | ------ | ------ |
| `active` | `readonly` | `Readonly`\<`Record`\<`string`, `boolean`\>\> | Whether each toggle item (by id) is on. Only items with `isActive` have an entry. |
| `enabled` | `readonly` | `Readonly`\<`Record`\<`string`, `boolean`\>\> | Whether each item's command (by id) can run now (`editor.can()`). |
| `focusId` | `readonly` | `string` \| `null` | The item that holds the toolbar's single Tab stop. |
---
Source: /api/ui/interfaces/Tooltip.md
# Interface: Tooltip
Controller returned by `createTooltip()`.
## Methods
### getState()
```ts
getState(): TooltipState;
```
The current state; the same object until something changes.
#### Returns
[`TooltipState`](TooltipState.md)
***
### getTooltipProps()
```ts
getTooltipProps(id): ElementProps;
```
Props for the tooltip of `id`: id, role="tooltip", aria-hidden, data-state (`open`/`closed`).
#### Parameters
| Parameter | Type |
| ------ | ------ |
| `id` | `string` |
#### Returns
[`ElementProps`](ElementProps.md)
***
### getTriggerProps()
```ts
getTriggerProps(id, options?): ElementProps;
```
Props for a trigger: shows its tooltip on hover (not touch) and focus after the delay, hides
on pointer leave, blur and mousedown. Adds aria-describedby only with `describe`.
#### Parameters
| Parameter | Type |
| ------ | ------ |
| `id` | `string` |
| `options?` | [`TooltipTriggerOptions`](TooltipTriggerOptions.md) |
#### Returns
[`ElementProps`](ElementProps.md)
***
### hide()
```ts
hide(): void;
```
Hide the visible tooltip at once.
#### Returns
`void`
***
### show()
```ts
show(id): void;
```
Show the tooltip for `id` at once, without the delay.
#### Parameters
| Parameter | Type |
| ------ | ------ |
| `id` | `string` |
#### Returns
`void`
***
### subscribe()
```ts
subscribe(listener): () => void;
```
Call `listener` on every state change; returns the unsubscribe function.
#### Parameters
| Parameter | Type |
| ------ | ------ |
| `listener` | () => `void` |
#### Returns
() => `void`
---
Source: /api/ui/interfaces/TooltipOptions.md
# Interface: TooltipOptions
Options for `createTooltip()`.
## Properties
| Property | Type | Description |
| ------ | ------ | ------ |
| `closeDelay?` | `number` | Milliseconds before it hides after the pointer leaves (time to move onto it). Default 150. |
| `delay?` | `number` | Milliseconds before a tooltip appears on hover or focus. Default 500. |
| `idPrefix?` | `string` | Prefix for element ids. Default: generated. |
| `skipDelayWindow?` | `number` | After a tooltip closes, the next one within this window opens at once. Default 300. |
---
Source: /api/ui/interfaces/TooltipState.md
# Interface: TooltipState
Snapshot of a tooltip controller.
## Properties
| Property | Modifier | Type | Description |
| ------ | ------ | ------ | ------ |
| `activeId` | `readonly` | `string` \| `null` | Id of the trigger whose tooltip should be shown, or null. |
---
Source: /api/ui/interfaces/TooltipTriggerOptions.md
# Interface: TooltipTriggerOptions
Options for `Tooltip.getTriggerProps()`.
## Properties
| Property | Type | Description |
| ------ | ------ | ------ |
| `describe?` | `boolean` | Link the tooltip with `aria-describedby`. Leave off (default) when the tooltip repeats the trigger's accessible name and shortcut, so screen readers do not read it twice; turn on when it adds information. |
---
Source: /api/ui/interfaces/UIEvent.md
# Interface: UIEvent
The parts of a DOM event the controllers use. React's synthetic events and
native events both satisfy it, so adapters can pass either.
## Properties
| Property | Modifier | Type | Description |
| ------ | ------ | ------ | ------ |
| `altKey?` | `readonly` | `boolean` | The Alt (Option) key was held. |
| `ctrlKey?` | `readonly` | `boolean` | The Control key was held. |
| `currentTarget` | `readonly` | `EventTarget` \| `null` | The element the handler is attached to. |
| `key?` | `readonly` | `string` | For keyboard events: the key value, e.g. `Enter` or `ArrowDown`. |
| `metaKey?` | `readonly` | `boolean` | The Meta (Command) key was held. |
| `pointerType?` | `readonly` | `string` | For pointer events: 'mouse', 'pen' or 'touch'. |
| `shiftKey?` | `readonly` | `boolean` | The Shift key was held. |
| `target` | `readonly` | `EventTarget` \| `null` | The element the event started on. |
## Methods
### preventDefault()
```ts
preventDefault(): void;
```
Cancel the browser's default action.
#### Returns
`void`
---
Source: /api/ui/interfaces/VirtualReference.md
# Interface: VirtualReference
Something a positioning library can place a popup next to. Compatible with
Floating UI's virtual elements (`computePosition(reference, floating)`).
## Properties
| Property | Modifier | Type | Description |
| ------ | ------ | ------ | ------ |
| `contextElement?` | `readonly` | `Element` | The editor element, for scroll and clipping ancestors. |
## Methods
### getBoundingClientRect()
```ts
getBoundingClientRect(): DOMRect;
```
The rectangle to place the popup next to, in viewport coordinates.
#### Returns
`DOMRect`
---
Source: /api/ui/type-aliases/BasicToolbarItemId.md
# Type Alias: BasicToolbarItemId
```ts
type BasicToolbarItemId =
| "undo"
| "redo"
| "heading1"
| "heading2"
| "heading3"
| "bold"
| "italic"
| "underline"
| "strike"
| "code"
| "bulletList"
| "orderedList"
| "blockquote"
| "clearFormatting";
```
Ids of the items `basicToolbarItems()` returns.
---
Source: /api/ui/type-aliases/UIEventName.md
# Type Alias: UIEventName
```ts
type UIEventName =
| "click"
| "keydown"
| "mousedown"
| "focus"
| "blur"
| "focusin"
| "focusout"
| "submit"
| "input"
| "change"
| "pointerenter"
| "pointerleave";
```
The DOM events prop getters attach handlers for, in lower-case DOM names.
---
Source: /api/ui/variables/en.md
# Variable: en
```ts
const en: Messages;
```
The built-in English messages.
---
Source: /api/ui/functions/applyProps.md
# Function: applyProps()
```ts
function applyProps(element, props): void;
```
Apply prop-getter output to a DOM element, for use without a framework.
Call it again after every state change; old listeners are replaced.
## Parameters
| Parameter | Type |
| ------ | ------ |
| `element` | `HTMLElement` |
| `props` | [`ElementProps`](../interfaces/ElementProps.md) |
## Returns
`void`
## Example
```ts
const toolbar = createToolbar(editor, { items: basicToolbarItems() })
const render = () => {
applyProps(root, toolbar.getRootProps())
for (const item of toolbar.items) applyProps(buttons[item.id], toolbar.getItemProps(item.id))
}
toolbar.subscribe(render)
render()
```
---
Source: /api/ui/functions/ariaShortcut.md
# Function: ariaShortcut()
```ts
function ariaShortcut(shortcut, apple?): string;
```
`Mod-Shift-s` → `Meta+Shift+S` (Apple) or `Control+Shift+S`, for `aria-keyshortcuts`.
## Parameters
| Parameter | Type |
| ------ | ------ |
| `shortcut` | `string` |
| `apple?` | `boolean` |
## Returns
`string`
---
Source: /api/ui/functions/basicBlockTypeItems.md
# Function: basicBlockTypeItems()
```ts
function basicBlockTypeItems(options?): MenuItem[];
```
"Normal text" plus one entry per heading level, for `createMenu()`.
## Parameters
| Parameter | Type |
| ------ | ------ |
| `options?` | [`BasicBlockTypeItemsOptions`](../interfaces/BasicBlockTypeItemsOptions.md) |
## Returns
[`MenuItem`](../interfaces/MenuItem.md)[]
---
Source: /api/ui/functions/basicToolbarItems.md
# Function: basicToolbarItems()
```ts
function basicToolbarItems(options?): ToolbarItem[];
```
Toolbar items for the `basic()` preset, in display order with groups for
separators. Labels come from `messages` (English by default).
## Parameters
| Parameter | Type |
| ------ | ------ |
| `options?` | [`BasicToolbarItemsOptions`](../interfaces/BasicToolbarItemsOptions.md) |
## Returns
[`ToolbarItem`](../interfaces/ToolbarItem.md)[]
## Example
```ts
import uz from '@writeon/ui/locales/uz'
basicToolbarItems({ messages: uz, exclude: ['strike'] })
```
---
Source: /api/ui/functions/createBubbleMenu.md
# Function: createBubbleMenu()
```ts
function createBubbleMenu(editor, options?): BubbleMenu;
```
Behaviour for a "bubble" toolbar that appears next to selected text.
Shows only for a real text selection in a focused, editable editor and
not while the pointer is still selecting. Keyboard users reach it with
`Alt-F10` and leave with Escape, which returns focus (and the selection)
to the editor. Renders and positions nothing: put a toolbar inside the
element that gets `getBubbleProps()`, and place it at `reference`.
## Parameters
| Parameter | Type |
| ------ | ------ |
| `editor` | [`Editor`](../../core/interfaces/Editor.md) |
| `options?` | [`BubbleMenuOptions`](../interfaces/BubbleMenuOptions.md) |
## Returns
[`BubbleMenu`](../interfaces/BubbleMenu.md)
---
Source: /api/ui/functions/createImageDialog.md
# Function: createImageDialog()
```ts
function createImageDialog(editor, options?): ImageDialog;
```
Behaviour and accessibility for adding an image by address and editing
its text alternative (WAI-ARIA modal dialog pattern): focus moves into the
dialog and stays there (Tab cycles), Escape or Cancel closes it, focus
returns to the editor. Alt text is required unless the image is marked
decorative, which stores `alt=""` on purpose. Needs `advancedSchema()` in
the editor; the image's `src` is checked by the schema.
## Parameters
| Parameter | Type |
| ------ | ------ |
| `editor` | [`Editor`](../../core/interfaces/Editor.md) |
| `options?` | [`ImageDialogOptions`](../interfaces/ImageDialogOptions.md) |
## Returns
[`ImageDialog`](../interfaces/ImageDialog.md)
---
Source: /api/ui/functions/createLinkPopover.md
# Function: createLinkPopover()
```ts
function createLinkPopover(editor, options?): LinkPopover;
```
Behaviour and accessibility for adding and editing links: a trigger button,
a small non-modal form, validation through `setLink()` (unsafe URLs are
refused with a message), Escape to close, focus moved to the field on open
and back to the editor on close. A press outside the form and its button
(the page, another toolbar button) closes it and leaves focus there.
## Parameters
| Parameter | Type |
| ------ | ------ |
| `editor` | [`Editor`](../../core/interfaces/Editor.md) |
| `options?` | [`LinkPopoverOptions`](../interfaces/LinkPopoverOptions.md) |
## Returns
[`LinkPopover`](../interfaces/LinkPopover.md)
---
Source: /api/ui/functions/createMenu.md
# Function: createMenu()
```ts
function createMenu(editor, options): Menu;
```
Behaviour and accessibility for a menu button (WAI-ARIA menu button
pattern): either one checked choice (`menuitemradio`, items with
`isActive`), such as the block type picker, or a list of actions
(`menuitem`), such as table commands. Renders nothing — spread the props
on your own elements.
## Parameters
| Parameter | Type |
| ------ | ------ |
| `editor` | [`Editor`](../../core/interfaces/Editor.md) |
| `options` | [`MenuOptions`](../interfaces/MenuOptions.md) |
## Returns
[`Menu`](../interfaces/Menu.md)
---
Source: /api/ui/functions/createSuggestionMenu.md
# Function: createSuggestionMenu()
```ts
function createSuggestionMenu(editor, options): SuggestionMenu;
```
Behaviour and accessibility for an inline suggestion list opened by a
typed character: a slash command menu (`/`) or mentions (`@`). Focus stays
in the editor (combobox-style): ArrowUp/ArrowDown move the highlight,
Enter or Tab choose, Escape closes. The editor gets `aria-controls`,
`aria-activedescendant` and `aria-autocomplete="list"`, and a live region
announces the number of options. Renders and positions nothing.
## Parameters
| Parameter | Type |
| ------ | ------ |
| `editor` | [`Editor`](../../core/interfaces/Editor.md) |
| `options` | [`SuggestionMenuOptions`](../interfaces/SuggestionMenuOptions.md) |
## Returns
[`SuggestionMenu`](../interfaces/SuggestionMenu.md)
---
Source: /api/ui/functions/createToolbar.md
# Function: createToolbar()
```ts
function createToolbar(editor, options): Toolbar;
```
Behaviour and accessibility for a formatting toolbar (WAI-ARIA toolbar
pattern): one Tab stop, arrow keys between buttons, `aria-pressed` toggles,
`disabled` from `editor.can()`, platform-aware shortcut hints. Renders
nothing — spread the props on your own elements.
## Parameters
| Parameter | Type |
| ------ | ------ |
| `editor` | [`Editor`](../../core/interfaces/Editor.md) |
| `options` | [`ToolbarOptions`](../interfaces/ToolbarOptions.md) |
## Returns
[`Toolbar`](../interfaces/Toolbar.md)
---
Source: /api/ui/functions/createTooltip.md
# Function: createTooltip()
```ts
function createTooltip(options?): Tooltip;
```
Tooltips that meet WCAG 1.4.13 (content on hover or focus): shown on hover
and keyboard focus after a delay, dismissable with Escape without moving
focus, hoverable (moving onto the tooltip keeps it open), and persistent
until the pointer or focus leaves. Not shown for touch input. One
controller serves many triggers; one tooltip is visible at a time.
## Parameters
| Parameter | Type |
| ------ | ------ |
| `options?` | [`TooltipOptions`](../interfaces/TooltipOptions.md) |
## Returns
[`Tooltip`](../interfaces/Tooltip.md)
---
Source: /api/ui/functions/displayShortcut.md
# Function: displayShortcut()
```ts
function displayShortcut(shortcut, apple?): string;
```
`Mod-Shift-s` → `⌘⇧S` (Apple) or `Ctrl+Shift+S`, for tooltips.
## Parameters
| Parameter | Type |
| ------ | ------ |
| `shortcut` | `string` |
| `apple?` | `boolean` |
## Returns
`string`
---
Source: /api/ui/functions/filterSuggestions.md
# Function: filterSuggestions()
```ts
function filterSuggestions(
items,
query,
limit?
): SuggestionItem[];
```
Filter items by a query: label or keywords starting with (then
containing) it, case-insensitive. Use it in `items` for static lists.
## Parameters
| Parameter | Type | Default value |
| ------ | ------ | ------ |
| `items` | readonly [`SuggestionItem`](../interfaces/SuggestionItem.md)[] | `undefined` |
| `query` | `string` | `undefined` |
| `limit?` | `number` | `10` |
## Returns
[`SuggestionItem`](../interfaces/SuggestionItem.md)[]
---
Source: /api/ui/functions/format.md
# Function: format()
```ts
function format(message, values): string;
```
Fill `{name}` placeholders in a message.
## Parameters
| Parameter | Type |
| ------ | ------ |
| `message` | `string` |
| `values` | `Record`\<`string`, `string` \| `number`\> |
## Returns
`string`
---
Source: /api/ui/functions/isApplePlatform.md
# Function: isApplePlatform()
```ts
function isApplePlatform(): boolean;
```
Apple platforms use Cmd where others use Ctrl (ProseMirror's "Mod").
## Returns
`boolean`
---
Source: /api/ui/functions/matchesShortcut.md
# Function: matchesShortcut()
```ts
function matchesShortcut(
event,
shortcut,
apple?
): boolean;
```
Whether a keyboard event matches a ProseMirror-style shortcut such as `Mod-k`.
## Parameters
| Parameter | Type |
| ------ | ------ |
| `event` | \{ `altKey?`: `boolean`; `ctrlKey?`: `boolean`; `key?`: `string`; `metaKey?`: `boolean`; `shiftKey?`: `boolean`; \} |
| `event.altKey?` | `boolean` |
| `event.ctrlKey?` | `boolean` |
| `event.key?` | `string` |
| `event.metaKey?` | `boolean` |
| `event.shiftKey?` | `boolean` |
| `shortcut` | `string` |
| `apple?` | `boolean` |
## Returns
`boolean`
---
Source: /api/ui/functions/mergeElementProps.md
# Function: mergeElementProps()
```ts
function mergeElementProps(...all): ElementProps;
```
Combine props from several controllers for one element (e.g. a toolbar
button with a tooltip). Later attributes win; handlers for the same event
all run, in order.
## Parameters
| Parameter | Type |
| ------ | ------ |
| ...`all` | [`ElementProps`](../interfaces/ElementProps.md)[] |
## Returns
[`ElementProps`](../interfaces/ElementProps.md)
---
Source: /api/ui/functions/resolveMessages.md
# Function: resolveMessages()
```ts
function resolveMessages(messages?): Messages;
```
English with any given overrides.
## Parameters
| Parameter | Type |
| ------ | ------ |
| `messages?` | `Partial`\<[`Messages`](../interfaces/Messages.md)\> |
## Returns
[`Messages`](../interfaces/Messages.md)
---
Source: /api/ui/locales/ru/reference.md
# @writeon/ui/locales/ru
Russian messages for the UI controllers and the kit.
## Variables
- [default](variables/default.md)
---
Source: /api/ui/locales/ru/variables/default.md
# Variable: default
```ts
const default: Messages;
```
Русский.
---
Source: /api/ui/locales/uz/reference.md
# @writeon/ui/locales/uz
Uzbek (Latin) messages for the UI controllers and the kit.
## Variables
- [default](variables/default.md)
---
Source: /api/ui/locales/uz/variables/default.md
# Variable: default
```ts
const default: Messages;
```
O‘zbekcha (lotin).
---
Source: /api/vue/reference.md
# @writeon/vue
Vue bindings: `useEditor`, `useEditorState`, `` and
composables for every headless UI controller.
## Interfaces
- [EditorContentProps](interfaces/EditorContentProps.md)
- [UseBubbleMenuResult](interfaces/UseBubbleMenuResult.md)
- [UseEditorOptions](interfaces/UseEditorOptions.md)
- [UseImageDialogResult](interfaces/UseImageDialogResult.md)
- [UseLinkPopoverResult](interfaces/UseLinkPopoverResult.md)
- [UseMenuResult](interfaces/UseMenuResult.md)
- [UseSuggestionMenuResult](interfaces/UseSuggestionMenuResult.md)
- [UseToolbarResult](interfaces/UseToolbarResult.md)
- [UseTooltipResult](interfaces/UseTooltipResult.md)
## Type Aliases
- [VueProps](type-aliases/VueProps.md)
## Variables
- [EditorContent](variables/EditorContent.md)
## Functions
- [toVueProps](functions/toVueProps.md)
- [useBubbleMenu](functions/useBubbleMenu.md)
- [useEditor](functions/useEditor.md)
- [useEditorState](functions/useEditorState.md)
- [useImageDialog](functions/useImageDialog.md)
- [useLinkPopover](functions/useLinkPopover.md)
- [useMenu](functions/useMenu.md)
- [useSuggestionMenu](functions/useSuggestionMenu.md)
- [useToolbar](functions/useToolbar.md)
- [useTooltip](functions/useTooltip.md)
---
Source: /api/vue/interfaces/EditorContentProps.md
# Interface: EditorContentProps
Props for ``.
## Properties
| Property | Type | Description |
| ------ | ------ | ------ |
| `editor` | [`Editor`](../../core/interfaces/Editor.md) | The editor to mount into the inner element; it is unmounted when the component unmounts. |
| `html?` | `string` | HTML shown until the editor mounts, so server-rendered pages (Nuxt) show the content at once instead of an empty box. Make it with `toHTML()` from `@writeon/html`, from the same document you pass as `content`. Only the first value is used; the editor owns the DOM after mount. |
---
Source: /api/vue/interfaces/UseBubbleMenuResult.md
# Interface: UseBubbleMenuResult
Returned by `useBubbleMenu()`.
## Properties
| Property | Modifier | Type | Description |
| ------ | ------ | ------ | ------ |
| `reference` | `readonly` | [`VirtualReference`](../../ui/interfaces/VirtualReference.md) | Where the selection is; give it to your positioning code (e.g. Floating UI). |
| `state` | `readonly` | `Readonly`\<`ShallowRef`\<[`BubbleMenuState`](../../ui/interfaces/BubbleMenuState.md)\>\> | The controller state as a shallow ref; updated on the client while the scope is alive. |
## Methods
### dismiss()
```ts
dismiss(): void;
```
Hide until the selection changes; focus goes back to the editor.
#### Returns
`void`
***
### focusFirst()
```ts
focusFirst(): void;
```
Move focus to the first control in the bubble (what the focus shortcut does).
#### Returns
`void`
***
### getBubbleProps()
```ts
getBubbleProps(): VueProps;
```
Props for the bubble element: id and data-state (`open` or `closed`). Escape
dismisses it, and mousedown outside form fields is prevented to keep the selection.
#### Returns
[`VueProps`](../type-aliases/VueProps.md)
---
Source: /api/vue/interfaces/UseEditorOptions.md
# Interface: UseEditorOptions
Options for `useEditor()`. `element` is handled by ``; `editable` may be a ref.
## Extends
- `Omit`\<[`EditorOptions`](../../core/interfaces/EditorOptions.md), `"element"` \| `"editable"`\>
## Properties
| Property | Type | Description | Inherited from |
| ------ | ------ | ------ | ------ |
| `content?` | [`DocJSON`](../../core/interfaces/DocJSON.md) \| `null` | Initial document. Omit for an empty document. | [`EditorOptions`](../../core/interfaces/EditorOptions.md).[`content`](../../core/interfaces/EditorOptions.md#property-content) |
| `editable?` | `MaybeRefOrGetter`\<`boolean`\> | Whether the user can edit. A ref or getter is watched and applied on change. Default true. | - |
| `extensions` | [`Extension`](../../core/interfaces/Extension.md)[] | Extensions that make up the editor, usually a preset such as `basic()`. | [`EditorOptions`](../../core/interfaces/EditorOptions.md).[`extensions`](../../core/interfaces/EditorOptions.md#property-extensions) |
| `label` | [`EditorLabel`](../../core/type-aliases/EditorLabel.md) | Accessible name: an `aria-label` string or the id of a labelling element. | [`EditorOptions`](../../core/interfaces/EditorOptions.md).[`label`](../../core/interfaces/EditorOptions.md#property-label) |
| `onBlur?` | (`editor`) => `void` | Called when the editable area loses focus, also when it is unmounted while focused. | [`EditorOptions`](../../core/interfaces/EditorOptions.md).[`onBlur`](../../core/interfaces/EditorOptions.md#property-onblur) |
| `onChange?` | (`editor`) => `void` | Called after every change to the document. | [`EditorOptions`](../../core/interfaces/EditorOptions.md).[`onChange`](../../core/interfaces/EditorOptions.md#property-onchange) |
| `onFocus?` | (`editor`) => `void` | Called when the editable area gains focus. | [`EditorOptions`](../../core/interfaces/EditorOptions.md).[`onFocus`](../../core/interfaces/EditorOptions.md#property-onfocus) |
| `placeholder?` | `string` | Text shown (and announced) while the document is empty. | [`EditorOptions`](../../core/interfaces/EditorOptions.md).[`placeholder`](../../core/interfaces/EditorOptions.md#property-placeholder) |
---
Source: /api/vue/interfaces/UseImageDialogResult.md
# Interface: UseImageDialogResult
Returned by `useImageDialog()`.
## Properties
| Property | Modifier | Type | Description |
| ------ | ------ | ------ | ------ |
| `state` | `readonly` | `Readonly`\<`ShallowRef`\<[`ImageDialogState`](../../ui/interfaces/ImageDialogState.md)\>\> | The controller state as a shallow ref; updated on the client while the scope is alive. |
## Methods
### close()
```ts
close(): void;
```
Close without applying and focus the editor. Does nothing while closed.
#### Returns
`void`
***
### getAltHintProps()
```ts
getAltHintProps(): VueProps;
```
Props for the hint text the alt input's aria-describedby points to.
#### Returns
[`VueProps`](../type-aliases/VueProps.md)
***
### getAltInputProps()
```ts
getAltInputProps(): VueProps;
```
Props for the alternative text input: id, value, aria-required, aria-describedby (hint, and
error when invalid). Disabled and empty while the image is marked decorative.
#### Returns
[`VueProps`](../type-aliases/VueProps.md)
***
### getBackdropProps()
```ts
getBackdropProps(): VueProps;
```
An optional full-screen layer behind the panel; a press on it closes the dialog.
#### Returns
[`VueProps`](../type-aliases/VueProps.md)
***
### getCancelProps()
```ts
getCancelProps(): VueProps;
```
Props for the Cancel button, which closes the dialog.
#### Returns
[`VueProps`](../type-aliases/VueProps.md)
***
### getDecorativeProps()
```ts
getDecorativeProps(): VueProps;
```
Props for the "decorative image" checkbox.
#### Returns
[`VueProps`](../type-aliases/VueProps.md)
***
### getDialogProps()
```ts
getDialogProps(): VueProps;
```
The modal panel. Traps Tab inside and closes on Escape.
#### Returns
[`VueProps`](../type-aliases/VueProps.md)
***
### getErrorProps()
```ts
getErrorProps(): VueProps;
```
Props for the error message: role="alert", hidden while there is no error.
#### Returns
[`VueProps`](../type-aliases/VueProps.md)
***
### getFormProps()
```ts
getFormProps(): VueProps;
```
Props for the form: submit validates and applies instead of submitting the page.
#### Returns
[`VueProps`](../type-aliases/VueProps.md)
***
### getSrcInputProps()
```ts
getSrcInputProps(): VueProps;
```
Props for the address input: id, value, inputmode="url"; aria-invalid and aria-describedby on error.
#### Returns
[`VueProps`](../type-aliases/VueProps.md)
***
### getTitleProps()
```ts
getTitleProps(): VueProps;
```
Props for the dialog title: the id the dialog's aria-labelledby points to.
#### Returns
[`VueProps`](../type-aliases/VueProps.md)
***
### getTriggerProps()
```ts
getTriggerProps(): VueProps;
```
Props for the toolbar button: aria-label (add or edit image), aria-haspopup, aria-expanded,
data-state; disabled without image support. Click opens the dialog; mousedown is prevented
to keep the selection.
#### Returns
[`VueProps`](../type-aliases/VueProps.md)
***
### openDialog()
```ts
openDialog(): void;
```
Open for the selected image (edit) or a new one (insert).
#### Returns
`void`
---
Source: /api/vue/interfaces/UseLinkPopoverResult.md
# Interface: UseLinkPopoverResult
Returned by `useLinkPopover()`.
## Properties
| Property | Modifier | Type | Description |
| ------ | ------ | ------ | ------ |
| `state` | `readonly` | `Readonly`\<`ShallowRef`\<[`LinkPopoverState`](../../ui/interfaces/LinkPopoverState.md)\>\> | The controller state as a shallow ref; updated on the client while the scope is alive. |
## Methods
### close()
```ts
close(options?): void;
```
Close without applying. Focuses the editor unless `focusEditor` is false.
#### Parameters
| Parameter | Type |
| ------ | ------ |
| `options?` | \{ `focusEditor?`: `boolean`; \} |
| `options.focusEditor?` | `boolean` |
#### Returns
`void`
***
### getErrorProps()
```ts
getErrorProps(): VueProps;
```
Props for the error message: role="alert", hidden while there is no error.
#### Returns
[`VueProps`](../type-aliases/VueProps.md)
***
### getFormProps()
```ts
getFormProps(): VueProps;
```
Props for the form: role="group", aria-label. Submit applies the address.
#### Returns
[`VueProps`](../type-aliases/VueProps.md)
***
### getInputProps()
```ts
getInputProps(): VueProps;
```
Props for the address input: aria-label, value, aria-invalid on error. Escape closes.
#### Returns
[`VueProps`](../type-aliases/VueProps.md)
***
### getRemoveProps()
```ts
getRemoveProps(): VueProps;
```
Props for the Remove button; hidden unless the selection is in a link.
#### Returns
[`VueProps`](../type-aliases/VueProps.md)
***
### getTriggerProps()
```ts
getTriggerProps(): VueProps;
```
Props for the toolbar button: id, aria-label, title with the shortcut, aria-keyshortcuts,
aria-pressed (inside a link), aria-expanded, aria-controls. Click toggles the form.
#### Returns
[`VueProps`](../type-aliases/VueProps.md)
***
### openPopover()
```ts
openPopover(): void;
```
Open the form, filled with the current link's address or `https://`, and focus the field.
#### Returns
`void`
---
Source: /api/vue/interfaces/UseMenuResult.md
# Interface: UseMenuResult
Returned by `useMenu()`.
## Properties
| Property | Modifier | Type | Description |
| ------ | ------ | ------ | ------ |
| `items` | `readonly` | readonly [`MenuItem`](../../ui/interfaces/MenuItem.md)[] | The items passed in `options`. |
| `state` | `readonly` | `Readonly`\<`ShallowRef`\<[`MenuState`](../../ui/interfaces/MenuState.md)\>\> | The controller state as a shallow ref; updated on the client while the scope is alive. |
## Methods
### close()
```ts
close(options?): void;
```
Close and move focus to the trigger (default), the editor, or nowhere.
#### Parameters
| Parameter | Type |
| ------ | ------ |
| `options?` | \{ `focus?`: `"editor"` \| `"trigger"` \| `"none"`; \} |
| `options.focus?` | `"editor"` \| `"trigger"` \| `"none"` |
#### Returns
`void`
***
### getItemProps()
```ts
getItemProps(id): VueProps;
```
Props for an item: role `menuitemradio` with aria-checked for choices, `menuitem` for actions;
aria-disabled when it cannot run. Click selects it. Throws for an unknown id.
#### Parameters
| Parameter | Type |
| ------ | ------ |
| `id` | `string` |
#### Returns
[`VueProps`](../type-aliases/VueProps.md)
***
### getMenuProps()
```ts
getMenuProps(): VueProps;
```
Props for the menu: role="menu", aria-labelledby. Arrow keys, Home and End move focus, letters
jump by label, Enter and Space choose, Escape closes to the trigger, Tab closes.
#### Returns
[`VueProps`](../type-aliases/VueProps.md)
***
### getTriggerProps()
```ts
getTriggerProps(): VueProps;
```
Props for the menu button: id, aria-label (menu label plus the checked item), aria-haspopup,
aria-expanded, aria-controls. Click toggles; ArrowDown, Enter and Space open the menu,
ArrowUp opens it on the last item.
#### Returns
[`VueProps`](../type-aliases/VueProps.md)
***
### openMenu()
```ts
openMenu(focus?): void;
```
Open and focus an enabled item: the checked one (default; else the first), the first or the last.
#### Parameters
| Parameter | Type |
| ------ | ------ |
| `focus?` | `"selected"` \| `"first"` \| `"last"` |
#### Returns
`void`
---
Source: /api/vue/interfaces/UseSuggestionMenuResult.md
# Interface: UseSuggestionMenuResult
Returned by `useSuggestionMenu()`.
## Properties
| Property | Modifier | Type | Description |
| ------ | ------ | ------ | ------ |
| `reference` | `readonly` | [`VirtualReference`](../../ui/interfaces/VirtualReference.md) | Where the trigger character is; give it to your positioning code. |
| `state` | `readonly` | `Readonly`\<`ShallowRef`\<[`SuggestionMenuState`](../../ui/interfaces/SuggestionMenuState.md)\>\> | The controller state as a shallow ref; updated on the client while the scope is alive. |
## Methods
### dismiss()
```ts
dismiss(): void;
```
Close until the user types somewhere else.
#### Returns
`void`
***
### getListboxProps()
```ts
getListboxProps(): VueProps;
```
Props for the list: id, role="listbox", aria-label. Mousedown is prevented to keep focus in the editor.
#### Returns
[`VueProps`](../type-aliases/VueProps.md)
***
### getOptionProps()
```ts
getOptionProps(id): VueProps;
```
Props for an option: id, role="option", aria-selected, data-active when highlighted. Click chooses it.
#### Parameters
| Parameter | Type |
| ------ | ------ |
| `id` | `string` |
#### Returns
[`VueProps`](../type-aliases/VueProps.md)
***
### getStatusProps()
```ts
getStatusProps(): VueProps;
```
A polite live region announcing how many options there are.
#### Returns
[`VueProps`](../type-aliases/VueProps.md)
***
### select()
```ts
select(id): void;
```
Remove the typed trigger and query, run the item's command in the same undo step, and
focus the editor. Does nothing for an unknown id or while closed.
#### Parameters
| Parameter | Type |
| ------ | ------ |
| `id` | `string` |
#### Returns
`void`
---
Source: /api/vue/interfaces/UseToolbarResult.md
# Interface: UseToolbarResult
Returned by `useToolbar()`.
## Properties
| Property | Modifier | Type | Description |
| ------ | ------ | ------ | ------ |
| `items` | `readonly` | readonly [`ToolbarItem`](../../ui/interfaces/ToolbarItem.md)[] | The items passed in `options`. |
| `state` | `readonly` | `Readonly`\<`ShallowRef`\<[`ToolbarState`](../../ui/interfaces/ToolbarState.md)\>\> | The controller state as a shallow ref; updated on the client while the scope is alive. |
## Methods
### getCustomItemProps()
```ts
getCustomItemProps(id, props): VueProps;
```
Add your own element (e.g. the link trigger) to the toolbar's arrow-key navigation.
#### Parameters
| Parameter | Type |
| ------ | ------ |
| `id` | `string` |
| `props` | [`VueProps`](../type-aliases/VueProps.md) |
#### Returns
[`VueProps`](../type-aliases/VueProps.md)
***
### getItemProps()
```ts
getItemProps(id): VueProps;
```
Props for an item's button: aria-label, title with the shortcut, aria-keyshortcuts,
aria-pressed and data-state for toggles, disabled, roving tabindex. Click runs the command
without taking focus from the editor. Throws for an unknown id.
#### Parameters
| Parameter | Type |
| ------ | ------ |
| `id` | `string` |
#### Returns
[`VueProps`](../type-aliases/VueProps.md)
***
### getRootProps()
```ts
getRootProps(): VueProps;
```
Props for the toolbar element: role, aria-label, aria-orientation. Arrow keys, Home and End
move focus between enabled items.
#### Returns
[`VueProps`](../type-aliases/VueProps.md)
---
Source: /api/vue/interfaces/UseTooltipResult.md
# Interface: UseTooltipResult
Returned by `useTooltip()`.
## Properties
| Property | Modifier | Type | Description |
| ------ | ------ | ------ | ------ |
| `state` | `readonly` | `Readonly`\<`ShallowRef`\<[`TooltipState`](../../ui/interfaces/TooltipState.md)\>\> | The controller state as a shallow ref; updated on the client while the scope is alive. |
## Methods
### getTooltipProps()
```ts
getTooltipProps(id): VueProps;
```
Props for the tooltip of `id`: id, role="tooltip", aria-hidden, data-state (`open`/`closed`).
#### Parameters
| Parameter | Type |
| ------ | ------ |
| `id` | `string` |
#### Returns
[`VueProps`](../type-aliases/VueProps.md)
***
### getTriggerProps()
```ts
getTriggerProps(id, options?): VueProps;
```
Props for a trigger: shows its tooltip on hover (not touch) and focus after the delay, hides
on pointer leave, blur and mousedown. Adds aria-describedby only with `describe`.
#### Parameters
| Parameter | Type |
| ------ | ------ |
| `id` | `string` |
| `options?` | [`TooltipTriggerOptions`](../../ui/interfaces/TooltipTriggerOptions.md) |
#### Returns
[`VueProps`](../type-aliases/VueProps.md)
***
### hide()
```ts
hide(): void;
```
Hide the visible tooltip at once.
#### Returns
`void`
***
### show()
```ts
show(id): void;
```
Show the tooltip for `id` at once, without the delay.
#### Parameters
| Parameter | Type |
| ------ | ------ |
| `id` | `string` |
#### Returns
`void`
---
Source: /api/vue/type-aliases/VueProps.md
# Type Alias: VueProps
```ts
type VueProps = Record;
```
Props for `v-bind` on a Vue element, with Vue event names (`onKeydown`).
---
Source: /api/vue/variables/EditorContent.md
# Variable: EditorContent
```ts
const EditorContent: DefineSetupFnComponent;
```
The editable area. Renders a wrapper `
` that receives fallthrough
attributes (`class`, `id`, `data-*`) and an inner `
` that the editor
owns, so Vue and ProseMirror never patch the same element's attributes.
---
Source: /api/vue/functions/toVueProps.md
# Function: toVueProps()
```ts
function toVueProps(props): VueProps;
```
Convert framework-neutral props from `@writeon/ui` to Vue props (`onKeydown`, not `onKeyDown`).
## Parameters
| Parameter | Type |
| ------ | ------ |
| `props` | [`ElementProps`](../../ui/interfaces/ElementProps.md) |
## Returns
[`VueProps`](../type-aliases/VueProps.md)
---
Source: /api/vue/functions/useBubbleMenu.md
# Function: useBubbleMenu()
```ts
function useBubbleMenu(editor, options?): UseBubbleMenuResult;
```
A toolbar that appears next to selected text: shown for text selections in
a focused editor, reached with Alt-F10, left with Escape. Positioning is
yours: place the element at `reference`. Options are read once.
## Parameters
| Parameter | Type |
| ------ | ------ |
| `editor` | [`Editor`](../../core/interfaces/Editor.md) |
| `options?` | [`BubbleMenuOptions`](../../ui/interfaces/BubbleMenuOptions.md) |
## Returns
[`UseBubbleMenuResult`](../interfaces/UseBubbleMenuResult.md)
---
Source: /api/vue/functions/useEditor.md
# Function: useEditor()
```ts
function useEditor(options): Editor;
```
Create an editor for the lifetime of the component (or effect scope).
- `content` and `label` are read on creation only; use `editor.setContent()` later.
- `editable` can be a ref or getter and is applied whenever it changes.
- The editor is destroyed when the scope is disposed (component unmount).
## Parameters
| Parameter | Type |
| ------ | ------ |
| `options` | [`UseEditorOptions`](../interfaces/UseEditorOptions.md) |
## Returns
[`Editor`](../../core/interfaces/Editor.md)
## Example
```ts
const editor = useEditor({ extensions, content: props.initial, label: 'Article text' })
```
---
Source: /api/vue/functions/useEditorState.md
# Function: useEditorState()
```ts
function useEditorState(
editor,
selector,
isEqual?
): Readonly>;
```
Read part of the editor state as a ref that updates only when the value changes.
## Type Parameters
| Type Parameter |
| ------ |
| `T` |
## Parameters
| Parameter | Type | Default value |
| ------ | ------ | ------ |
| `editor` | [`Editor`](../../core/interfaces/Editor.md) | `undefined` |
| `selector` | (`snapshot`) => `T` | `undefined` |
| `isEqual?` | (`a`, `b`) => `boolean` | `Object.is` |
## Returns
`Readonly`\<`ShallowRef`\<`T`\>\>
## Example
```ts
const isBold = useEditorState(editor, (s) => s.marks.has('bold'))
```
---
Source: /api/vue/functions/useImageDialog.md
# Function: useImageDialog()
```ts
function useImageDialog(editor, options?): UseImageDialogResult;
```
Add an image by address or edit the selected image's alt text, in an
accessible modal dialog (focus trap, Escape, alt required unless marked
decorative). Needs `advancedSchema()` in the editor. Options are read once.
## Parameters
| Parameter | Type |
| ------ | ------ |
| `editor` | [`Editor`](../../core/interfaces/Editor.md) |
| `options?` | [`ImageDialogOptions`](../../ui/interfaces/ImageDialogOptions.md) |
## Returns
[`UseImageDialogResult`](../interfaces/UseImageDialogResult.md)
---
Source: /api/vue/functions/useLinkPopover.md
# Function: useLinkPopover()
```ts
function useLinkPopover(editor, options?): UseLinkPopoverResult;
```
Link add/edit form behaviour: validation, Escape, focus handling and the
`Mod-k` shortcut (pass `shortcut: false` to turn it off). Options are read once.
## Parameters
| Parameter | Type |
| ------ | ------ |
| `editor` | [`Editor`](../../core/interfaces/Editor.md) |
| `options?` | [`LinkPopoverOptions`](../../ui/interfaces/LinkPopoverOptions.md) |
## Returns
[`UseLinkPopoverResult`](../interfaces/UseLinkPopoverResult.md)
---
Source: /api/vue/functions/useMenu.md
# Function: useMenu()
```ts
function useMenu(editor, options): UseMenuResult;
```
Menu button with one checked choice (e.g. the block type picker). Options are read once.
## Parameters
| Parameter | Type |
| ------ | ------ |
| `editor` | [`Editor`](../../core/interfaces/Editor.md) |
| `options` | [`MenuOptions`](../../ui/interfaces/MenuOptions.md) |
## Returns
[`UseMenuResult`](../interfaces/UseMenuResult.md)
## Example
```ts
const blockType = useMenu(editor, { items: basicBlockTypeItems(), label: 'Text style' })
```
---
Source: /api/vue/functions/useSuggestionMenu.md
# Function: useSuggestionMenu()
```ts
function useSuggestionMenu(editor, options): UseSuggestionMenuResult;
```
An inline list opened by a typed character: slash commands (`/`) or
mentions (`@`). Focus stays in the editor; arrows, Enter/Tab and Escape
drive the list. Options are read once.
## Parameters
| Parameter | Type |
| ------ | ------ |
| `editor` | [`Editor`](../../core/interfaces/Editor.md) |
| `options` | [`SuggestionMenuOptions`](../../ui/interfaces/SuggestionMenuOptions.md) |
## Returns
[`UseSuggestionMenuResult`](../interfaces/UseSuggestionMenuResult.md)
---
Source: /api/vue/functions/useToolbar.md
# Function: useToolbar()
```ts
function useToolbar(editor, options): UseToolbarResult;
```
Accessible toolbar behaviour. Options are read once, like `useEditor()`.
## Parameters
| Parameter | Type |
| ------ | ------ |
| `editor` | [`Editor`](../../core/interfaces/Editor.md) |
| `options` | [`ToolbarOptions`](../../ui/interfaces/ToolbarOptions.md) |
## Returns
[`UseToolbarResult`](../interfaces/UseToolbarResult.md)
## Example
```vue
```
---
Source: /api/vue/functions/useTooltip.md
# Function: useTooltip()
```ts
function useTooltip(options?): UseTooltipResult;
```
Accessible tooltips (WCAG 1.4.13) for many triggers; one is visible at a
time. Combine trigger props with others using Vue's `mergeProps()`.
## Parameters
| Parameter | Type |
| ------ | ------ |
| `options?` | [`TooltipOptions`](../../ui/interfaces/TooltipOptions.md) |
## Returns
[`UseTooltipResult`](../interfaces/UseTooltipResult.md)
---
Source: /api/reference.md
# API reference
## Modules
- [@writeon/advanced](advanced/reference.md)
- [@writeon/advanced/embed](advanced/embed/reference.md)
- [@writeon/advanced/formatting](advanced/formatting/reference.md)
- [@writeon/advanced/schema](advanced/schema/reference.md)
- [@writeon/core](core/reference.md)
- [@writeon/core/commands](core/commands/reference.md)
- [@writeon/core/extension](core/extension/reference.md)
- [@writeon/core/extensions](core/extensions/reference.md)
- [@writeon/core/presets](core/presets/reference.md)
- [@writeon/html](html/reference.md)
- [@writeon/kit](kit/reference.md)
- [@writeon/kit/advanced](kit/advanced/reference.md)
- [@writeon/kit/react](kit/react/reference.md)
- [@writeon/kit/vue](kit/vue/reference.md)
- [@writeon/markdown](markdown/reference.md)
- [@writeon/markdown/paste](markdown/paste/reference.md)
- [@writeon/react](react/reference.md)
- [@writeon/server](server/reference.md)
- [@writeon/ui](ui/reference.md)
- [@writeon/ui/locales/ru](ui/locales/ru/reference.md)
- [@writeon/ui/locales/uz](ui/locales/uz/reference.md)
- [@writeon/vue](vue/reference.md)