Installation & Basic Usage
Univer is built from plugins. Each feature ships as a separate module, so the same core can be assembled into electronic document applications of very different kinds. This flexibility also carries a cost: on first use, an application must determine which plugins it needs.
Univer therefore provides two ways to integrate it: plugin mode and preset mode. A preset is a bundle of plugins that has already been configured. Without complex extensions, both modes provide the same capabilities.
Caution
- In both modes, every dependency must use the same version number.
- If a preset already includes a plugin, do not import that plugin separately. Registering both can cause plugin conflicts or features that do not behave as expected.
The two modes differ as follows:
| Plugin Mode | Preset Mode |
|---|---|
| Facade packages are imported manually | Facade packages are provided by the preset |
| Registration order must be managed for plugins that provide the same kind of feature | The preset manages registration order for the features it includes |
| Plugins can be lazy-loaded on demand | Presets load synchronously during initialization |
For deep customization or extensions, choose plugin mode, in which each plugin is combined and configured individually. Preset mode provides a faster start because the bundle is already assembled.
Setting up via plugin mode
Univer provides its features as plugins. Some core plugins are required for the product to function, and the remaining plugins are added only when needed. The example below is a minimal Univer Docs application, assembled and installed plugin by plugin.
Unlike preset mode, plugin mode does not include the Facade API1 by default. The examples below use the Facade API, so import the corresponding facade packages before creating the API instance.
Using package manager
Installation
Univer renders its interface with React and processes its data streams with RxJS; it can also be embedded in a Vue or Angular application. Ensure that the react, react-dom, and rxjs peer dependencies2 are installed. The Yarn command below includes them explicitly.
All @univerjs/* and @univerjs-pro/* packages must use the same version.
pnpm add @univerjs/core @univerjs/design @univerjs/docs @univerjs/docs-ui @univerjs/engine-formula @univerjs/engine-render @univerjs/uinpm install @univerjs/core @univerjs/design @univerjs/docs @univerjs/docs-ui @univerjs/engine-formula @univerjs/engine-render @univerjs/uiyarn add @univerjs/core @univerjs/design @univerjs/docs @univerjs/docs-ui @univerjs/engine-formula @univerjs/engine-render @univerjs/ui react react-dom rxjsbun add @univerjs/core @univerjs/design @univerjs/docs @univerjs/docs-ui @univerjs/engine-formula @univerjs/engine-render @univerjs/uiUsage
Create the container with an explicit height before initializing Univer:
<div id="app" style="height: 600px"></div>Import the facade entries used by the examples before calling FUniver.newAPI(univer). Load the styles in the order @univerjs/design, @univerjs/ui, then the product CSS.
Caution
- Not every plugin includes facade packages, language packs, and style files; the documentation for each feature states which of them it provides.
- The order of style imports matters: load the
@univerjs/designand@univerjs/uiCSS before the styles of any other plugin.
First, import Univer's style files, language packs, and the plugins the application requires:
TypeScriptimport { LocaleType, mergeLocales, Univer } from '@univerjs/core'import { FUniver } from '@univerjs/core/facade'import DesignEnUS from '@univerjs/design/locale/en-US'import { UniverDocsPlugin } from '@univerjs/docs'import { UniverDocsUIPlugin } from '@univerjs/docs-ui'import DocsUIEnUS from '@univerjs/docs-ui/locale/en-US'import { UniverFormulaEnginePlugin } from '@univerjs/engine-formula'import { UniverRenderEnginePlugin } from '@univerjs/engine-render'import { UniverUIPlugin } from '@univerjs/ui'import UIEnUS from '@univerjs/ui/locale/en-US'import '@univerjs/design/lib/index.css'import '@univerjs/ui/lib/index.css'import '@univerjs/docs-ui/lib/index.css'Next, import the facade packages used by the example:
TypeScriptimport '@univerjs/engine-formula/facade'import '@univerjs/ui/facade'import '@univerjs/docs/facade'import '@univerjs/docs-ui/facade'Then, create a Univer instance and register these plugins:
TypeScriptconst univer = new Univer({ locale: LocaleType.EN_US, locales: { [LocaleType.EN_US]: mergeLocales( DesignEnUS, UIEnUS, DocsUIEnUS, ), },})univer.registerPlugin(UniverRenderEnginePlugin)univer.registerPlugin(UniverFormulaEnginePlugin)univer.registerPlugin(UniverUIPlugin, { container: 'app',})univer.registerPlugin(UniverDocsPlugin)univer.registerPlugin(UniverDocsUIPlugin)const univerAPI = FUniver.newAPI(univer)univerAPI.createDocument({})
Plugin configuration
UniverUIPlugin
containerstring | HTMLElementThe element into which the editor is mounted, or its DOM ID.
UniverWatermarkPlugin
textWatermarkSettingsobjectText watermark settings.contentstringDefault:''Text to display.fontSizenumberDefault:16Font size in pixels.
univer.registerPlugin and univer.registerPlugins methods
univer.registerPlugin registers one plugin on the Univer instance and must be called after the instance has been created.
The signature is univer.registerPlugin(Plugin, options), where Plugin is the plugin to register and options is optional configuration defined by each plugin.
To register several plugins at once, pass an array to univer.registerPlugins. This is convenient when plugins are managed in one place.
univer.registerPlugins([ UniverRenderEnginePlugin, UniverFormulaEnginePlugin, [UniverUIPlugin, { container: 'app', }], UniverDocsPlugin, UniverDocsUIPlugin,])Lazy loading plugins
Plugin mode allows the loading time of each plugin to be controlled. A common approach loads only the essential plugins at application start and defers the remaining plugins until the first render has completed.
// ...const univerAPI = FUniver.newAPI(univer)univerAPI.createDocument({})import('@univerjs/watermark').then(({ UniverWatermarkPlugin }) => { univer.registerPlugin(UniverWatermarkPlugin, { textWatermarkSettings: { content: 'Hello, Univer!', fontSize: 36, }, })})Import from CDN
To avoid a package manager, or to evaluate Univer quickly, the resources can be loaded from a CDN. See Using Univer via CDN.
Mobile support
These examples require SDK packages that export the mobile plugins listed below. Keep all @univerjs/* and @univerjs-pro/* dependencies on the same version.
1.0.0-rc.0 does not export UniverDocsMobileUIPlugin; use a build that includes this mobile entry before running the example.
For touch controls in Univer Docs, register the mobile UI plugins.3 The UI mode must be chosen before the editor is created.
In the plugin-mode example above, replace the UI imports and registrations below, and do so before createUnit(); do not add them to a desktop editor that has already been initialized. Keep the model plugins, engines, locale files, CSS, and Facade imports unchanged. The desktop and mobile classes are named exports from the same package entry.
UniverMobileUIPlugin
containerstring | HTMLElementThe element into which the editor is mounted, or its DOM ID.disableAutoFocustrueDefault:truePrevents the editor from taking focus at startup.
import { UniverDocsMobileUIPlugin } from '@univerjs/docs-ui'import { UniverMobileUIPlugin } from '@univerjs/ui'univer.registerPlugin(UniverMobileUIPlugin, { container: 'app' })univer.registerPlugin(UniverDocsMobileUIPlugin)UniverSheetsCorePreset and UniverDocsCorePreset currently register desktop UI plugins and provide no mobile: true option. On mobile, the plugins must be assembled individually; adding mobile plugins after a desktop preset does not replace its UI.
Plugin mapping
Register only the features that are used, and keep their model plugins and required dependencies. A mobile UI export does not imply that desktop and mobile expose the same controls. Pro features still require the appropriate license. Features that need a backend must be integrated in the application through Univer Server SDK.
| Package | Desktop registration | Mobile registration |
|---|---|---|
@univerjs/ui | UniverUIPlugin | UniverMobileUIPlugin |
@univerjs/docs-ui | UniverDocsUIPlugin | UniverDocsMobileUIPlugin |
@univerjs/drawing-ui | UniverDrawingUIPlugin | UniverDrawingMobileUIPlugin |
@univerjs/thread-comment-ui | UniverThreadCommentUIPlugin | UniverThreadCommentMobileUIPlugin |
@univerjs-pro/shape-editor-ui | UniverShapeEditorUIPlugin | UniverShapeEditorMobileUIPlugin |
@univerjs-pro/chart-ui | UniverChartUIPlugin | UniverChartMobileUIPlugin |
@univerjs-pro/exchange-client | UniverExchangeClientPlugin | UniverExchangeClientMobileUIPlugin |
@univerjs/docs-drawing-ui | UniverDocsDrawingUIPlugin | UniverDocsDrawingMobileUIPlugin |
@univerjs/docs-hyper-link-ui | UniverDocsHyperLinkUIPlugin | UniverDocsHyperLinkMobileUIPlugin |
@univerjs/docs-thread-comment-ui | UniverDocsThreadCommentUIPlugin | UniverDocsThreadCommentMobileUIPlugin |
@univerjs-pro/docs-callout-ui | UniverDocsCalloutUIPlugin | UniverDocsCalloutMobileUIPlugin |
@univerjs-pro/docs-chart-ui | UniverDocsChartUIPlugin | UniverDocsChartMobileUIPlugin |
@univerjs-pro/docs-code-ui | UniverDocsCodeUIPlugin | UniverDocsCodeMobileUIPlugin |
@univerjs-pro/docs-column-ui | UniverDocsColumnUIPlugin | UniverDocsColumnMobileUIPlugin |
@univerjs-pro/docs-formula-ui | UniverDocsFormulaUIPlugin | UniverDocsFormulaMobileUIPlugin |
@univerjs-pro/docs-latex-ui | UniverDocsLatexUIPlugin | UniverDocsLatexMobileUIPlugin |
@univerjs-pro/docs-list-ui | UniverDocsListUIPlugin | UniverDocsListMobileUIPlugin |
@univerjs-pro/docs-quote-ui | UniverDocsQuoteUIPlugin | UniverDocsQuoteMobileUIPlugin |
@univerjs-pro/docs-shape-ui | UniverDocsShapeUIPlugin | UniverDocsShapeMobileUIPlugin |
@univerjs-pro/docs-table-ui | UniverDocsTableUIPlugin | UniverDocsTableMobileUIPlugin |
Container and touch interaction
Set an explicit height on the container and configure the page viewport. 100dvh follows the dynamic viewport height. In the target mobile browsers, test scrolling, pinch zoom, text selection, clipboard access, and the on-screen keyboard. Resizing a desktop editor does not switch it to mobile plugins.
UniverMobileUIPlugin defaults to disableAutoFocus: true, so the editor does not take focus automatically during initialization.
<meta name="viewport" content="width=device-width, initial-scale=1" /><div id="app" style="height: 100dvh"></div>Setting up via preset mode
Preset mode starts a Univer Docs application with fewer than twenty lines of code.
Using package manager
If the project already uses modern front-end tooling, adding Univer is straightforward. Build Univer applications with a tool that supports ES Modules well, such as Vite, esbuild, or Webpack 5. Other tools, Webpack 4 for instance, may require additional configuration.
Installation
Install @univerjs/presets with the package manager used by the project:
pnpm add @univerjs/presets @univerjs/preset-docs-corenpm install @univerjs/presets @univerjs/preset-docs-coreyarn add @univerjs/presets @univerjs/preset-docs-corebun add @univerjs/presets @univerjs/preset-docs-coreUsage
If the build tool does not support the exports field in package.json (common in Webpack 4), the mapped paths must be changed to the actual paths manually.
The following code starts a Univer Docs application:
<div id="app" style="height: 600px"></div>import { UniverDocsCorePreset } from '@univerjs/preset-docs-core'import UniverPresetDocsCoreEnUS from '@univerjs/preset-docs-core/locales/en-US'import { createUniver, LocaleType, mergeLocales } from '@univerjs/presets'import '@univerjs/preset-docs-core/lib/index.css'const { univer, univerAPI } = createUniver({ locale: LocaleType.EN_US, locales: { [LocaleType.EN_US]: mergeLocales( UniverPresetDocsCoreEnUS, ), }, presets: [ UniverDocsCorePreset({ container: 'app', }), ],})univerAPI.createDocument({})The returned univerAPI object is the Univer Facade API, and most of the functionality that Univer provides is called through it.
UniverDocsCorePreset can also be imported from @univerjs/presets/preset-docs-core, provided that the build tool supports the exports field in package.json.
Preset configuration
UniverDocsCorePreset
containerstring | HTMLElementDefault:'app'The element into which the editor is mounted, or its DOM ID.
createUniver method
createUniver accepts a configuration object that describes the instance, including the language, theme, and plugins. It returns an object that contains the Univer instance and the Facade API instance.
The most commonly used properties are:
locale: the language environment, as aLocaleTypeenumeration value.locales: language packs, keyed by language environment, each value a language pack object.theme: an optional theme object.presets: the presets to register, such asUniverDocsCorePreset.plugins: plugins to register in addition to the presets.
Use the plugins property for a plugin that no preset package includes, or for a plugin implemented by the application. Plugins can also be registered with univer.registerPlugin after the Univer instance is obtained.
See API Reference / createUniver for the complete set of options.
Import from CDN
To avoid a package manager, or to evaluate Univer quickly, the resources can be loaded from a CDN. See Using Univer via CDN.
Other releases
Alongside the stable releases, Univer publishes alpha / beta and nightly channels, which provide early access to features that have not been officially released. More features also carry more risk: these builds may contain bugs, incomplete functionality, or unstable features. Avoid them in production environments where possible.
Alpha / beta release
When the Univer development team completes a new feature or a significant change, it may pre-release the package to the alpha or beta channel. Install an alpha or beta build with the following command:
pnpm add @univerjs/<package-name>@alpha # Alpha version
pnpm add @univerjs/<package-name>@beta # Beta versionnpm install @univerjs/<package-name>@alpha # Alpha version
npm install @univerjs/<package-name>@beta # Beta versionyarn add @univerjs/<package-name>@alpha # Alpha version
yarn add @univerjs/<package-name>@beta # Beta versionbun add @univerjs/<package-name>@alpha # Alpha version
bun add @univerjs/<package-name>@beta # Beta versionProblems and feedback related to a pre-release can be reported to the development team through GitHub Issues. Feedback on these early builds is welcome.
Next steps
- Basic Concepts explains the concepts that Univer is built on.
- Features describes Univer features and how to modify document data.
Footnotes
-
Facade is the application-facing API over registered plugins. Importing a Facade entry adds API methods; it does not register the feature plugin itself. ↩
-
peerDependenciesdeclare dependencies that the host application must provide with compatible versions. They let Univer share libraries such as React instead of bundling a separate copy. ↩ -
A mobile UI plugin selects touch controls and mobile services during initialization. It does not automatically detect the device or switch an existing instance when the window is resized. To change modes, preserve the document state, dispose of the old instance and initialize the chosen plugin set. ↩
How is this guide?