Open source · MIT · 62 stars
Text Editor React
A Word-like editor for the web, with real A4 pages and pagination that never touches the document.
Open source · MIT · 62 stars
A Word-like editor for the web, with real A4 pages and pagination that never touches the document.
A Word-like editor for the web with real A4 pages. Contenteditable has no concept of a page, TipTap's own Pages extension is paid, and the community ones injected global CSS. So I built pagination that never touches the document.

getHTML() has to stay clean, so pages cannot be document nodes. Instead, measure() reads the height and margins of each top-level block, and computeBreaks(), a pure function with no DOM access, returns where spacers go and how tall they are. Those spacers render as ProseMirror widget decorations, each filling the rest of the page, the bottom margin, the grey gap and the next top margin.
Layout re-runs on document changes and on ResizeObserver, throttled by requestAnimationFrame. It dispatches only if the breaks actually changed, and it stays out of undo history.
The first layout worked from getBoundingClientRect positions. Once spacers existed, they shifted those positions, which changed the layout, which moved the spacers, forever. Working from heights instead fixed the loop and made the layout a pure function that 13 unit tests can exercise without a browser. The price is handling margin collapse and floats explicitly.
The spacer inside a table is a real table row with one cell, placed between rows. The whole table moves only if its first row group does not fit. Its colSpan must be the exact width from the table map: a larger value added phantom columns under fixed table layout.
Rowspan needed its own rule, and it arrived as a bug fix, after a spacer landed inside a rowspan and broke the layout. A row whose cell continues from above now merges into the previous group, and breaks only fall between groups. A header repeats only if every cell in the first row is a header and that row is the first group alone. The repeat is a static clone with measured cell widths, placed inside the spacer.
Pages zoom with a CSS transform. A transform changes what getBoundingClientRect reports, so scale is recovered as the rendered width over offsetWidth, and every measurement is divided by it. Layout always runs in unscaled pixels, so breaks stay identical from 50% to 200%.
Sharing uses Yjs over WebRTC, with IndexedDB in each browser. A new room gets a random name and key, and the key sits in the URL fragment, which browsers never send to a server. The honest caveat: WebRTC still needs a signalling server. The public one became unreachable, so the repo now ships a small one.
PDF clones the editor, sets a page break on the block after each spacer, removes the spacers, moves header rows into a real thead, and prints through a hidden iframe. Puppeteer stays as an optional path. Browser print means no server, at the cost of a print dialog and a dependency on recent Chrome for margin boxes.