mroffice-slides
v0.2.0
Published
The MR Office presentation editor for React: slides with themes, layouts, shapes, tables, charts and SmartArt, in the browser.
Maintainers
Readme
mroffice-slides
The presentation editor of MR Office, as a React component. Slides with themes, layouts, shapes, tables, charts and SmartArt, in the browser.
- Opens .mrslides (the editor's own JSON); saves .mrslides.
- Runs in the browser on a file you hand it; nothing is sent anywhere.
npm i mroffice-slides mroffice-coreUse
import { EditorHostProvider, browserDownloadHost, type SavedFile } from "mroffice-core";
import slides from "mroffice-slides";
import "mroffice-slides/style.css";
const file = { id: "1", ...slides.newFile!() }; // or { id, name, bytes } of a file you have
let save: () => Promise<SavedFile> | SavedFile;
export default function Editor() {
return (
<div style={{ height: "100vh" }}>
<EditorHostProvider locale="en">
<slides.Component
file={file}
registerSave={(saver) => { save = saver; return () => {}; }}
onSaveRequest={async () => { const out = await save(); browserDownloadHost.saveFile({ name: out.name, type: out.type, data: new Blob([out.bytes as BlobPart], { type: out.type }) }); }}
/>
</EditorHostProvider>
</div>
);
}The editor fills its container: give it a height. registerSave receives a function that returns the current file ({ name, type, bytes }); onSaveRequest fires on the editor's own Save (ribbon, Ctrl/Cmd+S). EditorHostProvider takes the interface language (locale: en, de, es, fr, ja, ko, zh, ... see EDITOR_LOCALES) and a host (saveFile, notify) for what the editor hands out. The default export is an EditorDefinition (extensions, newFile, Component); the component is also exported by name.
What works in the open-source build, feature by feature: packages/slides/README.md.
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-slides/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).
