Univer Slides API
The Slides Facade adds presentation and slide objects to FUniver. Import its side-effect entry before creating the API object:
import { FUniver } from '@univerjs/core/facade'import '@univerjs-pro/slides/facade'const univerAPI = FUniver.newAPI(univer)Create and find presentations
const presentation = univerAPI.createPresentation({ id: 'quarterly-review', name: 'Quarterly review',})const activePresentation = univerAPI.getActivePresentation()const samePresentation = univerAPI.getPresentation(presentation.getId())createPresentation() accepts a partial ISlideData snapshot. Pass a snapshot returned by save() to restore a presentation.
Work with the presentation unit
FPresentation exposes the unit identity, name, page size, slides, active slide, transitions, permissions, and detached snapshot:
presentation.setName('FY 2027 review')const opening = presentation.getSlideByIndex(0) ?? presentation.appendSlide({ name: 'Opening',})presentation.setActiveSlide(opening)const snapshot = presentation.save()Do not mutate snapshot to update a running presentation. Use Facade methods or commands so rendering and undo history remain synchronized.
Enter a slide
FSlide is the entry point for a slide’s background, speaker notes, transition, and elements:
const slide = presentation.getActiveSlide()if (slide) { const elements = slide.getElements() const notes = slide.getSpeakerNotes()}Continue with Slides and Layouts, Shapes and Text, and Images and Groups for focused operations.
Resolve command targets
Command event parameters may contain a presentation and slide identifier. Resolve them without relying on the current selection:
const listener = univerAPI.addEvent( univerAPI.Event.CommandExecuted, ({ params }) => { const target = univerAPI.getSlideCommandTarget(params) console.log(target?.presentation.getId(), target?.slide.getId()) })Dispose the listener when its host component is removed.
Dispose a presentation
Unload one Slides unit by ID when it is no longer needed. Dispose the root univer instance only when the whole application is being destroyed.
const presentation = univerAPI.getActivePresentation()if (presentation) { univerAPI.disposeUnit(presentation.getId())}How is this guide?