Basic concepts
Univer Docs is composed of plugins, stores a document in a snapshot, applies changes through commands, and is normally driven through the Facade API. This page explains these four concepts. To run an editor, continue to installation and basic usage.
Basic concepts
The remaining pages use these four terms throughout:
- Plugin
- Snapshot
- Command
- Facade API
Plugins
Plugins provide every feature in Univer and constitute the smallest building block of the architecture. A Univer application consists of a set of plugins.
A plugin performs one of two roles:
- It implements a feature.
@univerjs/docs-hyper-link, for example, adds the hyperlink model and commands to Univer Docs. - It supplies a base capability.
@univerjs/engine-renderprovides rendering.
Include only the plugins your application needs, so that unused code is not loaded. When the available plugins do not cover a requirement, write a plugin to extend Univer.
Related links
- Hyperlinks explains how to add a Docs feature in preset mode or plugin mode.
- Univer Architecture describes the internal composition of Univer in more detail.
Snapshot
Univer Docs stores a document as IDocumentData. The snapshot describes the document body, document-level styles, headers and footers, drawings, lists, tables, and plugin resources.
Data defined by a plugin resides in the optional resources field.
Caution
A snapshot holds data only. It does not track document state while the editor is running. To save the current state as a snapshot, call the snapshot method on the Facade API.
Command
In Univer Docs, every change to content or formatting passes through a command. This design makes change tracking, undo, redo, and collaborative editing possible, and keeps related features consistent with one another.
The Facade API prepares the arguments and executes the corresponding Docs command.
Caution
Do not modify the snapshot directly. Such a write has no effect and leaves views and the UI out of date. Change data through commands or the Facade API.
Facade API
Office applications are inherently complex, and the architecture required to support them is complex as well. The Facade API removes the need to work at that level: it wraps Univer's first-party plugins and exposes simpler entry points.
The Facade API is still under active development. If you have questions or requirements, open an issue on GitHub.
It abstracts the underlying details, which suffices for everyday work. Complex features may still require an understanding of Univer's architecture and direct use of the low-level API.
Related links
Preset mode and plugin mode
A preset is a bundle of plugins that are already configured. When both modes include the same plugins, they provide the same capabilities. Presets reduce setup work; plugin mode leaves composition and loading to the application.
Keep every Univer dependency on the same version. If a preset already includes a plugin, do not register it a second time.
| Plugin mode | Preset mode |
|---|---|
| The application imports the Facade extensions itself | The preset includes the Facade extensions |
| The application controls plugin registration order | The preset manages the plugins it includes |
| Plugins are loaded on demand | Configured presets load during initialization |
How is this guide?