Rebodocs

Editor API

The Editor is what everything else talks to. You get it from new Editor(element), from useDocs().editor, or from the handle of the React component (handle.editor).

This page lists what is used most. The class has more; its source, packages/editor/src/editor.ts, documents every public member.

Positions and the selection

A position is { para, offset }: the index of a paragraph, and of a character in it. The selection is an anchor and a focus.

editor.selection;                                   // { anchor, focus }
editor.range;                                       // { from, to }, in order
editor.collapsed;                                   // a caret, not a range
editor.selectedText;
editor.setSelection({ para: 2, offset: 0 }, { para: 2, offset: 12 });
editor.selectAll();

In a header or footer, positions are those of its own text: editor.area says which is being edited, and editor.setArea('header') goes into one.

The document

Member What it does
doc The document, as an immutable Doc.
load(doc), loadDocx(bytes) Open another document.
exportDocx() The document as a DOCX.
exportPdf(title?) As a PDF, page for page as shown. A promise.
exportMarkdown() Its text as Markdown.
print() The browser's print dialog, with the pages.
edit(change, reveal?) Changes the document as a whole from outside, as one step to undo: editor.edit((doc) => fillVariables(doc, values)).
onChange(listener) Called on every change of document or selection. Returns how to stop.
pageCount, currentPage

Editing

Member What it does
insertText(text), insertParagraphBreak(), insertPageBreak()
deleteBackward(), deleteForward()
toggleMark('bold' | 'italic' | 'underline' | 'strike')
setRunProps({ fontFamily, fontSize, color, highlight, … }) Character formatting of the selection, or of what is typed next.
setParagraphProps({ align, lineHeight, spacingBefore, indentLeft, … })
setParagraphStyle(id), styles, activeStyleId() Paragraph styles: Normal, Title, Heading 1…
toggleList('bullet' | 'number'), shiftListLevel(±1), shiftIndent(points)
undo(), redo(), canUndo, canRedo
activeRunProps(), activeParagraphProps() The formatting at the selection, fully resolved.
Member What it does
insertTable(rows, columns)
insertTableRow(below), insertTableColumn(right), deleteTableRow(), deleteTableColumn()
mergeTableCells(), splitTableCell(), setTableCellProps({ borders, shade }), setTableBorders(on)
insertImageFile(file), insertImageGrid(files, columns)
setPictureWrap(wrap), fitSelectedPicture(fraction)
setLink(address), removeLink(), activeLink
addNote(text), setNoteText(id, text), removeNote(id), notes Comments, as Word has them.
insertToc(), updateToc(), outline, goToHeading(para)

Templates

Member What it does
variables The names of the variables in the document.
insertVariable(name), selectVariable(name)
fillVariables(values) Replaces them, as one step to undo.
insertSignatures(titles) A block of signature lines.

The page

Member What it does
setPage({ width, height, marginTop, … }) Size and margins, in points.
setPageNumbering(numbering), pageNumbering
setFirstPageDifferent(on) A header and footer of its own for the first page.
hasLetterhead, letterhead, setLetterheadFile(file), fitLetterheadMargins(), removeLetterhead() See letterheads.

Finding

editor.find('deposit', { matchCase: false });   // how many it found
editor.findStep(1);                              // to the next one
editor.replaceFound('advance');
editor.replaceAllFound('advance');               // as one step to undo

The view

The view is the editor's, not the document's: it is not saved in the file.

Member What it does
zoom, setZoom(1.5) 0.25 to 4.
fit, setFit('width' | 'page') A zoom that follows the size of the window.
view, setView('column' | 'spread' | 'grid' | 'flow') One page, two across, a grid, or text as wide as the window.
setShowNotes(on) Comments in a margin beside the pages.
autoformat Whether typing # , - or **bold** formats as Markdown would. On by default.
focus() Gives the keyboard to the document.
element The element the pages scroll in.
destroy() Takes everything away.

Units

Everything is in points (1/72 of an inch), as in Word: page sizes, margins, indents, font sizes. A Letter page is 612 × 792.

Something wrong on this page? Edit it on GitHub.