Univer Slides API
The Slides Facade adds presentation and slide objects to FUniver. Import the 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. To restore a previously saved presentation, pass the snapshot returned by save().
Work with the presentation unit
FPresentation exposes the unit identity, name, page size, slides, active slide, transitions, permissions, and a 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 that rendering and the undo history stay synchronized.
Enter a slide
Use FSlide to work with the background, speaker notes, transition, and elements of a slide:
const slide = presentation.getActiveSlide()if (slide) { const elements = slide.getElements() const notes = slide.getSpeakerNotes()}For specific operations, see Slides and Layouts, Shapes and Text, and Images and Groups.
Resolve command targets
Command event parameters can carry a presentation identifier and a slide identifier. Resolve them from the parameters instead of 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 the component that owns it is removed.
Dispose a presentation
Unload a Slides unit by ID when it is no longer needed. Dispose the root univer instance only when the entire application is being destroyed.
const presentation = univerAPI.getActivePresentation()if (presentation) { univerAPI.disposeUnit(presentation.getId())}How is this guide?