Facade API
In order to meet complex requirements, the architecture of Univer is also complex, which may cause some difficulties for users. Therefore, we provide a simpler and easier-to-use panel API (Facade API).
This chapter will show in detail how to add Facade API to your application. In the following “Features” chapter, we will list the main Facade API of each feature. If you want to see all the Facade API, please refer to the API reference of each plugin.
Starting from version 0.5.0, the @univerjs/facade
package has been marked as deprecated and is planned to be removed in version 0.6.0. If you are a user before version 0.5.0, please refer to the “Piecemeal Installation” section below to modify the way you import Facade API.
Please note that some APIs in Univer are asynchronous, especially the APIs that modify data, most of which will return a Promise
. If you need to get data immediately after modifying it, please use await
or .then()
, otherwise you may get unexpected results. To find out which APIs return a Promise
, please refer to the corresponding API reference manual.
Presets Installation
If you use Presets, it will automatically import the Facade API of the included features, and return a corresponding Facade API instance univerAPI
when you create a Univer instance, which can be used directly.
Piecemeal Installation
Installation
Starting from version 0.5.0, the implementation of Facade API has been distributed to various plugins and mounted on the global Facade API root class. This means that for those plugins that provide Facade API, you need to import their corresponding Facade API implementation.
We will introduce whether it provides Facade API implementation on each feature page, and you need to import their corresponding Facade API according to the features you actually use:
import '@univerjs/sheets/facade';
import '@univerjs/ui/facade';
import '@univerjs/docs-ui/facade';
import '@univerjs/sheets-ui/facade';
import '@univerjs/sheets-data-validation/facade';
import '@univerjs/engine-formula/facade';
import '@univerjs/sheets-filter/facade';
import '@univerjs/sheets-formula/facade';
import '@univerjs/sheets-numfmt/facade';
import '@univerjs/sheets-hyper-link-ui/facade';
If you use Univer’s pro features, you don’t need to use @univerjs-pro/facade
anymore. The way to import the Facade API of pro features is now the same as the way to import the Facade API of open-source features, for example:
import '@univerjs-pro/sheets-pivot/facade';
import '@univerjs-pro/exchange-client/facade';
Usage
Facade API is a wrapper for the Univer
instance, so you need to wrap this instance with FUniver
after creating the Univer
instance:
import { FUniver } from "@univerjs/core";
const univerAPI = FUniver.newAPI(univer);