RebodocsDocs
Start3
What is Rebodocs
Getting started
Demos to run
Put it in your app8
React component
Headless: your own UI
A complete interface
Without a framework
Only to read: the viewer
Styling and Tailwind
Phones and touch
Accessibility
Documents8
Templates and variables
On a server: DOCX and PDF
Documents in an S3 bucket
Letterheads
Versions
Tracked changes
Fonts
Languages
Together2
Real-time collaboration
AI assistants (MCP)
Reference5
Packages
Components and hooks
Editor API
How it works
Status and roadmap
↑↓ to move↵ to openEsc to close26 pages

Put it in your app A complete interface

A complete interface

The repository has an application that uses @rebodocs/react the way yours would: apps/demo. It shows a document two ways: the editor as it comes (DocsEditor), and an interface built from nothing on the hooks, dark and laid out like a design tool. The second does everything the first does, so it is the place to copy from.

tip: this is the second one, running: try the panels at its right
Live

Your own interface, running

The component of apps/demo/src/HeadlessEditor.tsx, imported here as it is, on the contract it opens with: a template in English with headings, variables with a type, a table, text in two columns, places to sign, a header and a page number. The interface opens in the language of this page; the selector in its status bar changes it.

Opening the editor…

Both tabs, full screen, with a DOCX of your own: rebodocs.com/demo (/demo/#full opens on the included one).

Run

Run it

It runs the package from its source, so a change in packages/react shows at once. That is the one line of its vite.config.ts a copy in a project of yours leaves out: there, @rebodocs/react comes from npm.

git clone https://github.com/JFranciscoRobles/rebodocs
cd rebodocs
npm install
npm run demo        # http://localhost:5175, and /#headless for the second tab

Open a .docx opens a file in both tabs; there is no backend, so saving downloads it.

Files

What is where

src/App.tsx
The two tabs, opening a file, and the sample it starts with. Holds the docx both editors are given.
src/FullEditor.tsx
DocsEditor, in a dozen lines.
src/HeadlessEditor.tsx
The provider and the layout: title bar, formatting bar, insert rail, find bar, ruler, pages, status bar.
src/headless/Panels.tsx
The side panel and its four tabs: format, page, content, notes.
src/headless/texts.ts
The interface’s own words, in Spanish and English, and useTexts, which draws a component again when the language changes.
src/headless/Icon.tsx · options.ts
The icons, and the lists offered: sizes, zooms, line heights, highlights, cell shades.
src/download.ts
Handing a file to the person: there is no backend, so saving downloads the DOCX.
src/HeadlessEditor.css
All of its look. Every rule is under .hd, so it touches nothing else; the colours of what the library puts in the body are set on body:has(.hd).
scripts/sample.ts
Writes the sample agreement with the engine, without a browser, in English.
Hooks

Which piece uses what

Each hook is on the page Components and hooks, with what it takes and gives.

Name, unsaved mark, save, export to Word, PDF and Markdown, print
useDocs: state.name, state.dirty, docs.save(), docs.download(), editor.exportPdf(), editor.exportMarkdown(), commands.print()
Undo, style, font, size, bold…, colour, alignment, lists, indent, zoom
useDocs, useDocsStyles, fontFamilies, useDocsValue for the indent
Table, pictures, signatures, page break
commands.insertTable, insertImageFile, insertImageGrid, insertSignatures, insertPageBreak
Link, variable and note buttons, and ⌘K
useDocsBubble: bubble.ask(…), with <DocsProvider bubble>; useDocsLink, useDocsVariables and useDocsNotes say when each is on
Find and replace, and ⌘F
useDocsFind, opened by onFindKey
Ruler
DocsRuler, coloured with --dx-ruler…
Format tab: highlight, spacing, the cells of a table
useDocs, useDocsValue for activeParagraphProps(), activeCellProps() and tableBorders()
Page tab: size, margins, columns, letterhead, header and footer, page number
useDocsPage, useDocsValue for the columns, commands.setArea
Content tab: table of contents, outline to drag, variables with a type
useDocsOutline, useDocsVariables, commands.insertToc
Notes tab
useDocsNotes, NOTE_COLORS, docs.setAuthor
Status bar: page, style and font, words and characters, saved, language, view, notes, zoom
useDocs, useDocsStyles, useDocsCount, setLocale, commands.setView, setShowNotes, setZoom
A narrow window
useDocsResponsive, and a media query for the layout
Skeleton

The skeleton

Everything hangs from one provider. What a key must reach (⌘F opens the find bar) is above it; the rest is inside. This is the end of HeadlessEditor.tsx, read from the file.

/** What is inside the provider: the layout, and what a narrow window asks of it. */
function Shell({ finding, setFinding }: { finding: boolean; setFinding: (finding: boolean) => void }) {
  const tr = useTexts();
  const [panels, setPanels] = useState(false);
  const locale = useSyncExternalStore(onLocaleChange, getLocale);
  // The layout follows the window. The library fits the pages to the room they are left, and says how much the keyboard of the screen covers.
  const narrow = useSyncExternalStore(watchNarrow, () => window.matchMedia(NARROW).matches);
  const { keyboard } = useDocsResponsive();

  return (
    <div className={`hd ${narrow ? 'narrow' : ''}`} style={{ paddingBottom: keyboard || undefined }}>
      <TitleBar panels={panels} onPanels={() => setPanels(!panels)} />
      <Toolbar />
      <div className="hd-body">
        <Rail finding={finding} onFind={() => setFinding(!finding)} />
        <main className="hd-main">
          {finding && <FindBar onClose={() => setFinding(false)} />}
          {/* Made again in another language: what its markers are called is read when it is made. A narrow window has no room for it. */}
          {!narrow && <DocsRuler key={locale} />}
          <DocsSurface className="hd-surface" />
        </main>
        {narrow && panels && <button className="hd-scrim" aria-label={tr('Cerrar paneles')} onClick={() => setPanels(false)} />}
        <Panels open={panels} onClose={() => setPanels(false)} />
      </div>
      <StatusBar />
    </div>
  );
}

export function HeadlessEditor({ docx, name }: Props) {
  // Up here, where the provider is given who answers ⌘F.
  const [finding, setFinding] = useState(false);

  return (
    <DocsProvider docx={docx} name={name} author="Demo" onSave={download} bubble slash variableSuggestions forms spellcheck={spellcheck} onFindKey={() => setFinding(true)}>
      <Shell finding={finding} setFinding={setFinding} />
    </DocsProvider>
  );
}

The column the pages are in is display: flex; flex-direction: column; min-width: 0, and the surface flex: 1; min-height: 0: that is what gives it the height it needs and lets it scroll. Under 900 pixels of window a media query lays it out again: the bars become one row each that slides, the insert rail lies down, the panels open over the document from a button, and the ruler goes.

Details

Things it had to get right

One value for docx

App keeps the bytes in state and gives the same Uint8Array at every render. A new array each time would open the document again and lose what was typed.

Buttons that keep the selection

Every command gives the keyboard back to the document, so buttons need nothing. A select or an input takes it while it is used, and the command it ends in gives it back.

Colours as the editor has them

state.color is hex without #; a colour input wants one with it: options.ts has the line between them. A highlight is one of Word’s fifteen, so it is offered as swatches.

The list, with what is there now

A document may use a size or a zoom that is not in the list offered. withCurrent adds the present one, so a select never shows something it is not.

Indent or level

The two indent buttons change the level of an item in a list (shiftListLevel) and the indent of a paragraph outside one (shiftIndent), as the included toolbar does.

Language

The selector calls setLocale: the library’s own words change (the bar, the ruler, the names of styles), and useTexts draws the demo’s again. The ruler is made again, with a key, to take its words.

The library’s own pieces take its colours from variables, not from rules that reach into their classes: the ruler from --dx-ruler… set on .hd; the bar beside the selection, and the rest the library puts in document.body outside .hd, from the --dx-ui-… variables set on body:has(.hd), while the interface is on the page.

Show it

Using it for a demonstration

  • rebodocs.com/demo has it online, with nothing to install.
  • npm run demo and open /#headless for your own interface, or / for the included one.
  • Open a .docx shows a real document of the person you are showing it to, in both.
  • npm run build:demo writes apps/demo/dist, a static site to put anywhere.
  • To change what it opens with, edit scripts/sample.ts: npm run sample -w @rebodocs/demo writes the file again.