Aa 0.14.1

Options

createEditor(host, options) takes one object, EditorOptions. Every field can be left out: an editor given nothing is an empty document that can be written in, with the menus on and the toolbar off.

import { createEditor, imageAtom } from '@0001-labs/aa'const editor = createEditor(host, {  value: '# A note',  placeholder: 'Write',  toolbar: true,  atoms: [imageAtom],  onChange: markdown => save(markdown),  onFiles: files => upload(files),})

The options are read once, when the editor is made. value, readOnly, placeholder and correcting can be changed afterwards on the editor itself (see Methods and events); for the rest, destroy the editor and make another.

OptionTypeDefaultWhat it does
valuestring''The Markdown the editor starts with.
readOnlybooleanfalseThe text can be read, selected and copied, not changed. The toolbar and the slash menu stay closed, commands do not run, captions cannot be written in, and undo() and redo() do nothing.
placeholderstring''What an empty document says: one block with nothing in it. It is also given to screen readers as aria-placeholder.
onChange(value: string) => voidnoneCalled with the whole document as Markdown after every change a person makes, every correction, every undo and redo, and every change an atom hands back. A value set from outside does not call it.

Read-only

The words can be selected and copied, not changed.

What it stores

OptionTypeDefaultWhat it does
toolbarboolean | readonly ToolbarAction[]falseThe bar over selected words. true shows it with Aa’s own buttons; an array shows it with these actions after them. On touch it is docked above the keyboard. See Toolbar.
commandsreadonly Command[]noneThe product’s commands in the slash menu, after the block kinds and what the atoms insert. On touch they are under More in Insert block.
blockCommandsreadonly Command[]noneThe product’s commands in the block menu (⌘/), after Aa’s own and before the counts.
menusbooleantruefalse turns off the slash menu, the block menu (⌘/), the line an empty block says, a table’s menu on a right click, and moving blocks by dragging them.
blockPlaceholderstringNothingWhat an empty line with the caret in it says. '' says nothing. Never shown with menus: false or in a read-only editor.

Actions and commands are { id, label, icon, run(editor) }; see Commands.

Placeholders

An empty editor says its placeholder. Write a line and press Enter: the empty line with the caret says how to reach the commands.

What it stores

OptionTypeDefaultWhat it does
atomsreadonly Atom[][imageAtom]The pieces of text drawn as one thing. The array replaces the default, so keep imageAtom in it to keep pictures. Equations and columns are always read. See Atoms.
onFiles(files: File[]) => voidnoneReceives the files pasted or dropped into the editor, and those chosen with Image or file in the slash menu, which is only offered with it. Without it, files are ignored. Aa never keeps a file itself.
drawEquation(element: HTMLElement, source: string, display: boolean) => void | (() => void)noneDraws an equation into element: source is the TeX without its $ signs, and display is true for a $$ block. What it returns is called when the equation leaves the page. Without it, the TeX is shown as written.
import katex from 'katex'createEditor(host, {  drawEquation: (element, tex, display) => katex.render(tex, element, { displayMode: display, throwOnError: false }),})

The product makes every call; Aa holds no model and no key.

OptionTypeDefaultWhat it does
promptPrompternoneAsks AI where the words are: Space in an empty block opens a prompt, Enter sends it. A diagram’s board asks it too. Without it, Space is a space. See Asking AI.
correctCorrectornoneCorrects a block’s words in place once they rest, one step to undo. Without it, nothing is corrected. See Correction while writing.
correctingbooleantrueWhether correct starts on. editor.correcting turns it on and off later.
type Prompter = (prompt: string, context: PromptContext) => Promise<string | PromptAnswer>type Corrector = (text: string, context: CorrectionContext) => Promise<string>
OptionTypeDefaultWhat it does
commentsCommentStorenoneThe product’s store of threads, people and permissions. Aa marks the commented words, keeps the anchors right as the text changes, and draws the threads. It adds Comment to the toolbar and editor.comments. Without it, nothing is commented. See Comments.

<aa-editor> takes the same object as its options property, set before the element is connected. Its attributes win over three of the fields:

FieldOn the element
valueThe value property, or the value attribute when it is connected
readOnlyThe readonly attribute
placeholderThe placeholder attribute
toolbaroptions.toolbar, or the toolbar attribute when that is left out
correctingOff when options.correcting is false or the element has correct="off"

onChange is still called, and the element fires input beside it.

import { defineAaEditor, imageAtom, type AaEditorElement } from '@0001-labs/aa'defineAaEditor()const element = document.createElement('aa-editor') as AaEditorElementelement.options = { atoms: [imageAtom], onFiles: files => upload(files) }element.setAttribute('toolbar', '')document.body.append(element)