Univer Boards API
Learn how to use Facade API in a Univer Boards application.
Facade API is the application-facing layer over Univer services and unit models. It covers the common Board operations: creating a board, reading the active page, adding elements, updating containers, and managing swimlanes.
Caution
Board mutations are synchronous and return either a boolean or a nullable handle. Check the return value before reading the result.
Enable the facade entry
Boards is distributed as Web SDK plugins. Import the facade entry for the Board capability that the application uses:
import { FUniver } from '@univerjs/core/facade'import '@univerjs-pro/boards/facade'The layout check and screenshot examples also require UniverBoardsUIPlugin and the import below.
import '@univerjs-pro/boards-ui/facade'Create the API object after the Univer instance and the required plugins have been registered:
const univerAPI = FUniver.newAPI(univer)Create and read a board
createBoard creates a Board unit through the facade. In lower-level setup code, create the unit with univer.createUnit(UniverInstanceType.UNIVER_BOARD, snapshot).
const board = univerAPI.createBoard({ id: 'board-demo', name: 'Board Demo',})const activeBoard = univerAPI.getActiveBoard()const sameBoard = univerAPI.getBoard(board.getId())Continue with core features
The returned FBoard object is the entry point to the active page and its content. The following guides describe the individual operations in detail:
- Elements covers reading, inserting, connecting, transforming, arranging, and removing Board elements.
- Containers & Swimlanes covers framed groups, membership, and swimlane structure.
Check a board’s layout and take screenshots
Run the following examples after the board is visible in the browser.
Find layout problems
analyzeRenderedLayout() reports problems such as crossing connectors or text that does not fit inside a shape. The call only reports the problems and leaves the layout unchanged. Each issue carries rule, which gives the type of problem, and focusBounds, which gives the area to inspect.
const board = univerAPI.getActiveBoard()if (!board) throw new Error('No active board')const analysis = board.analyzeRenderedLayout()if (!analysis) throw new Error('The board is not ready for layout inspection')for (const { rule, focusBounds } of analysis.issues) { console.log(rule, focusBounds)}Capture a specific element
To include an image of one flowchart step in a report, replace review-step with the element ID of that step. resolveCaptureBounds() calculates the area to capture. Pass that area to getScreenshot() to obtain a PNG data URL that can be used as an image source.
const board = univerAPI.getActiveBoard()if (!board) throw new Error('No active board')const target = board.resolveCaptureBounds({ elementIds: ['review-step'], padding: 16 })if (!target || !target.ok) throw new Error('Cannot locate the element to capture')const screenshot = await board.getScreenshot({ bounds: target.bounds })if (!screenshot) throw new Error('Cannot capture the selected area')console.log(screenshot.dataUrl)resolveCaptureBounds() · getScreenshot()
Reference
How is this guide?