mroffice-core
v0.2.0
Published
The shared layer of the MR Office editors (the host adapter, ribbon, fonts and text measurement, themes, charts, SmartArt, equations); every editor package uses it.
Maintainers
Readme
mroffice-core
The shared layer of the MR Office editors, which every editor package depends on: the host adapter through which a page embeds an editor, the Office-style ribbon, fonts and text measurement, themes, charts, SmartArt and equations, and the interface text.
| Package | Editor |
|---|---|
| mroffice-docs | document editor |
| mroffice-sheets | spreadsheet editor |
| mroffice-slides | presentation editor |
| mroffice-pdf | PDF editor |
| mroffice-code | code editor |
npm i mroffice-core mroffice-docsThe host adapter
import { EditorHostProvider, type EditorHost } from "mroffice-core";
const host: EditorHost = {
saveFile({ name, data }) { /* a file the editor hands out (an export, a download) */ },
notify({ title, description }) { /* a toast */ },
};
<EditorHostProvider host={host} locale="en" fallback={<p>Loading…</p>}>
{/* an editor: <docs.Component file={...} registerSave={...} onSaveRequest={...} /> */}
</EditorHostProvider>EditorHostProvider: the host (saveFile,notify; by default files are downloaded) and the interface language (EDITOR_LOCALES).- Every editor package's default export is an
EditorDefinition:extensionsit opens,newFile(), andComponenttaking{ file, registerSave, onSaveRequest, onDirty? }(EditorProps). configureEditors({ assetsBaseUrl, sandboxOrigin }): where the assets are fetched from (below) and the origin of the Python sandbox page.import "mroffice-core/style.css": the editors' stylesheet (each editor package carries the same file as<editor>/style.css). It includes a CSS reset of the page (Tailwind's preflight), as the editors expect; load it on the pages that show an editor.
The workspace, accounts, collaboration and AI of MR Office are not part of the open-source editors: where an editor would reach them it reaches the host, and a feature the host does not provide is absent.
Word, Excel and PowerPoint files
These packages are the open-source editors: they open and save their own formats (and HTML, Markdown, CSV, PDF). To open and save .docx, .xlsx and .pptx with full fidelity in your site, use the hosted MR Office editor: mroffice.ai/developers and the npm package mroffice-embed. The free desktop app opens them on a computer.
Next.js, webpack, Vite
The packages are ES modules with their types and a prebuilt stylesheet: no Tailwind, PostCSS or bundler settings needed. React 19 is a peer dependency.
In Next.js (App Router) the editors run in the browser only: load the component above without server rendering.
// app/editor/page.tsx
"use client";
import dynamic from "next/dynamic";
const Editor = dynamic(() => import("./Editor"), { ssr: false });
export default function Page() { return <Editor />; }With webpack, the stylesheet import needs a CSS loader (css-loader + style-loader or mini-css-extract-plugin). Import mroffice-core/style.css once; every editor package's style.css is the same stylesheet.
Assets (fonts, PDF worker, dictionaries)
The installed packages hold the code and the stylesheet. The heavy files the editors fetch as they need them (the fonts that stand in for Office's, the PDF worker and its data, spelling dictionaries, the code runners' WebAssembly, the interface text in languages other than English) are the package mroffice-assets, fetched by default from jsDelivr: https://cdn.jsdelivr.net/npm/[email protected]/. Nothing to configure.
To serve them from your own site instead:
npm i -D [email protected]
cp -R node_modules/mroffice-assets public/mroffice-assets// in a module imported before the editors
import { configureEditors } from "mroffice-core";
configureEditors({ assetsBaseUrl: "/mroffice-assets/" });and import style.self-hosted.css in place of style.css (it leaves out the font declarations, which then come from /mroffice-assets/fonts.css; put <link rel="stylesheet" href="/mroffice-assets/fonts.css"> in the page's <head> to have them from the first paint).
License
AGPL-3.0-only with the additional terms in NOTICE.md: a copy or modified version that shows a user interface keeps a reasonable attribution to the original work (the text "MR Office" linking to https://mroffice.ai), and the names "MR Office" and "MR Note" are not licensed as trademarks. The bundled third-party code and its licenses are listed in THIRD_PARTY_NOTICES.md. A commercial license is available: [email protected].
The source is https://github.com/XinaTian/MROffice (packages/, built with npm run pack:npm).
