General API

The Facade APIs available to an application depend on the current unit type and on the plugins that are registered. This page covers the APIs that a Univer Bases application commonly uses.

Importing

TypeScript
import { FUniver } from '@univerjs/core/facade'import '@univerjs-pro/bases/facade'import '@univerjs/ui/facade'const univerAPI = FUniver.newAPI(univer)

Commands

Most operations in Univer go through the command system. Because every operation follows the same path, undo, redo, and collaboration can cover all of them.

For the design behind it, see the Univer command system.

Listening to commands

Use Event.BeforeCommandExecute to run code before a command executes, and Event.CommandExecuted to run code after it finishes.

TypeScript
const beforeDisposable = univerAPI.addEvent(univerAPI.Event.BeforeCommandExecute, ({ id, params }) => {  console.log('Before command:', id, params)})const afterDisposable = univerAPI.addEvent(univerAPI.Event.CommandExecuted, ({ id, params }) => {  console.log('Command executed:', id, params)})

To prevent a command from running, set event.cancel to true inside a BeforeCommandExecute listener.

TypeScript
const disposable = univerAPI.addEvent(univerAPI.Event.BeforeCommandExecute, (event) => {  if (event.id === 'base.command.set-base-name') {    event.cancel = true  }})

Both listeners return an IDisposable. Dispose of the returned objects when they are no longer needed.

TypeScript
beforeDisposable.dispose()afterDisposable.dispose()disposable.dispose()

Executing commands

When a command ID and its parameters are known, FUniver.executeCommand runs the command directly. The following Bases command renames the active Base:

TypeScript
const base = univerAPI.getActiveBase()if (base) {  await univerAPI.executeCommand('base.command.set-base-name', {    unitId: base.getId(),    name: 'Product Tracker',  })}

Events API

The events on univerAPI.Event come from Univer core and from the plugins registered in the current application. Core provides the command and unit events that every product shares; the Bases plugins add events for tables, fields, records, views, and other Base changes. Before using an event, confirm that the plugin providing it is registered.

The Facade Events reference lists the event names and parameter types available in the current release.

Subscribe with addEvent, then dispose of the returned object to unsubscribe:

TypeScript
const disposable = univerAPI.addEvent(univerAPI.Event.CommandExecuted, ({ id }) => {  if (id === 'base.command.set-base-name') {    console.log('The Base name changed')  }})// Remove the listener when it is no longer neededdisposable.dispose()

Undo and redo

TypeScript
await univerAPI.undo()await univerAPI.redo()

System clipboard

After the Bases UI plugin is registered, copy and paste operate on the current Base selection and caret position.

TypeScript
await univerAPI.copy()await univerAPI.paste()

Copy and paste use the browser's native clipboard API. They can fail when the page does not have focus, when the call does not originate from a user action, or when clipboard permission is unavailable. See the MDN clipboard documentation.

UI

To extend menus, the toolbar, and other areas of the Bases interface, see Bases UI components.

WebSocket

To use the WebSocket APIs, install @univerjs/network, register UniverNetworkPlugin, and import its Facade extension.

TypeScript
import { UniverNetworkPlugin } from '@univerjs/network'import '@univerjs/network/facade'univer.registerPlugin(UniverNetworkPlugin)

The application can then subscribe to socket events, send messages, and close the connection:

TypeScript
const socket = univerAPI.createSocket('wss://example.com/bases')socket.open$.subscribe(() => {  socket.send('hello')})socket.message$.subscribe((message) => {  console.log('WebSocket message:', message.data)})socket.error$.subscribe((error) => {  console.error('WebSocket error:', error)})socket.close()

Enum API

Facade exposes common enum types on univerAPI.Enum:

TypeScript
console.log(univerAPI.Enum.UniverInstanceType.UNIVER_BASE)console.log(univerAPI.Enum.BaseFieldType.Text)

Utility method API

Shared utility methods are exposed on univerAPI.Util:

TypeScript
console.log(univerAPI.Util.tools.isString('Univer Bases')) // true

How is this guide?

© 2026 DreamNum Co., Ltd.