FPageElement
The facade class for a slide page element.
Setup
Register @univerjs-pro/slides or a preset that includes it. In plugin mode, import @univerjs-pro/slides/facade. Additional methods below require their listed plugin packages. See Facade setup.
@univerjs-pro/slides
FPageElement.getData
Get the raw slide element data.
getData(): TReturns
The slide element data.
Examples
const fPresentation = univerAPI.getActivePresentation()const fSlide = fPresentation.getSlideByIndex(0)const element = fSlide.getElements()[0]if (element && 'getType' in element) { console.log(element.getData())}Package: @univerjs-pro/slides · Type definitions
FPageElement.getId
Get the element id.
getId(): stringReturns
The element id.
Examples
const fPresentation = univerAPI.getActivePresentation()const fSlide = fPresentation.getSlideByIndex(0)const elements = fSlide.getElements()console.log(elements[0]?.getId())Package: @univerjs-pro/slides · Type definitions
FPageElement.getPermission
Returns this ordinary Slide element's permission facade.
getPermission(): FSlideObjectPermissionReturns
Permission facade combining Presentation, Slide, and Element Edit points.
Examples
const element = univerAPI.getActivePresentation()?.getSlideByIndex(0)?.getElements()[0]if (!element) throw new Error('Slide element not found.')await element.getPermission().setReadOnly()Types: FSlideObjectPermission
Package: @univerjs-pro/slides · Type definitions
FPageElement.getRichText
Returns this element's text as a detached rich-text value.
Text and placeholder elements are supported. Legacy plain text is normalized to the same document model.
Shapes returned by FSlide.getElements() use the common Shape facade and expose rich text through
FShape.getText().getRichText(). Images, groups, and other non-text elements return null.
Call RichTextValue.copy before editing. The detached builder can update text-run lengths without changing
this slide until it is passed to setRichText.
getRichText(): RichTextValue | nullReturns
A detached rich-text value, or null when this element cannot contain text.
Examples
const presentation = univerAPI.getActivePresentation()if (!presentation) throw new Error('No active presentation')const slide = presentation.getSlideByIndex(0)if (!slide) throw new Error('The presentation has no slides')for (const element of slide.getElements()) { const richText = ( 'getType' in element ? element.getRichText() : element.getText().getRichText() )?.copy() if (!richText) continue for (const paragraph of richText.getParagraphs()) { for (const run of paragraph.getTextRuns()) { console.log(run.getText()) } }}Types: RichTextValue
Package: @univerjs-pro/slides · Type definitions
FPageElement.getTransform
Get the transform of this element.
getTransform(): ISlideDrawingTransformReturns
The transform data, including position, size, rotation, and flip state.
Examples
const fPresentation = univerAPI.getActivePresentation()const fSlide = fPresentation.getSlideByIndex(0)const element = fSlide.getElements()[0]console.log(element.getTransform())Types: ISlideDrawingTransform
Package: @univerjs-pro/slides · Type definitions
FPageElement.getType
Get the element type.
getType(): T['type']Returns
The slide element type.
Examples
const fPresentation = univerAPI.getActivePresentation()const fSlide = fPresentation.getSlideByIndex(0)const element = fSlide.getElements()[0]if (element && 'getType' in element) { console.log(element.getType())}Package: @univerjs-pro/slides · Type definitions
FPageElement.setDescription
Set the element description.
setDescription(description: string): thisParameters
description— Required. The element description, usually used as accessibility text.
Returns
This element, for chaining.
Examples
const fPresentation = univerAPI.getActivePresentation()const fSlide = fPresentation.getSlideByIndex(0)const element = fSlide.getElements()[0]element.setDescription('Company logo')Package: @univerjs-pro/slides · Type definitions
FPageElement.setName
Set the element name.
setName(name: string): thisParameters
name— Required. The element name.
Returns
This element, for chaining.
Examples
const fPresentation = univerAPI.getActivePresentation()const fSlide = fPresentation.getSlideByIndex(0)const element = fSlide.getElements()[0]element.setName('Title shape')Package: @univerjs-pro/slides · Type definitions
FPageElement.setPosition
Set the element position by absolute slide coordinates.
setPosition(left: number, top: number): thisParameters
left— Required. The x-coordinate of the element's top-left corner.top— Required. The y-coordinate of the element's top-left corner.
Returns
This element, for chaining.
Examples
const fPresentation = univerAPI.getActivePresentation()const fSlide = fPresentation.getSlideByIndex(0)const element = fSlide.getElements()[0]if (element && 'getType' in element) { element.setPosition(80, 120)}Package: @univerjs-pro/slides · Type definitions
FPageElement.setRichText
Replaces this element's text document with a detached rich-text value.
Only text content and its document metadata are replaced. The existing element transform, size, rotation, fill,
stroke, text-box padding, wrapping, direction, and auto-fit behavior are preserved. The live update is executed
through UpdateSlideDrawingCommand, so it participates in the standard Slide command/mutation and undo-redo path.
setRichText(richText: RichTextValue): thisParameters
richText— Required. Rich text normally obtained fromgetRichText().copy()oruniverAPI.newRichText().
Returns
This element for chaining.
Throws
When this element type cannot contain text.
Examples
const presentation = univerAPI.getActivePresentation()if (!presentation) throw new Error('No active presentation')const slide = presentation.getSlideByIndex(0)if (!slide) throw new Error('The presentation has no slides')for (const element of slide.getElements()) { const richText = ( 'getType' in element ? element.getRichText() : element.getText().getRichText() )?.copy() if (!richText) continue for (const paragraph of richText.getParagraphs()) { for (const run of paragraph.getTextRuns()) { // The agent supplies the new value directly. It may be longer or shorter. run.setText('New English text') } } if ('getType' in element) { element.setRichText(richText) } else { element.getText().setRichText(richText) }}Types: RichTextValue
Package: @univerjs-pro/slides · Type definitions
FPageElement.setSelectable
Set whether the element can be selected.
setSelectable(selectable: boolean): thisParameters
selectable— Required. Whether the element can be selected.
Returns
This element, for chaining.
Examples
const fPresentation = univerAPI.getActivePresentation()const fSlide = fPresentation.getSlideByIndex(0)const element = fSlide.getElements()[0]element.setSelectable(false)Package: @univerjs-pro/slides · Type definitions
FPageElement.setSize
Set the element size.
setSize(width: number, height: number): thisParameters
width— Required. The element width.height— Required. The element height.
Returns
This element, for chaining.
Examples
const fPresentation = univerAPI.getActivePresentation()const fSlide = fPresentation.getSlideByIndex(0)const element = fSlide.getElements()[0]element.setSize(320, 180)Package: @univerjs-pro/slides · Type definitions
FPageElement.setTransform
Update the transform of this element.
setTransform(transform: Partial<ISlideDrawingTransform>): thisParameters
transform— Required. The transform fields to update.
Returns
This element, for chaining.
Examples
const fPresentation = univerAPI.getActivePresentation()const fSlide = fPresentation.getSlideByIndex(0)const element = fSlide.getElements()[0]element.setTransform({ left: 80, top: 120, width: 320, height: 180 })Types: Partial · ISlideDrawingTransform
Package: @univerjs-pro/slides · Type definitions
FPageElement.setVisible
Set whether the element is visible.
setVisible(visible: boolean): thisParameters
visible— Required. Whether the element is visible.
Returns
This element, for chaining.
Examples
const fPresentation = univerAPI.getActivePresentation()const fSlide = fPresentation.getSlideByIndex(0)const element = fSlide.getElements()[0]element.setVisible(false)Package: @univerjs-pro/slides · Type definitions
@univerjs-pro/slides-thread-comment
FPageElement.createCommentAsync
Creates a comment anchored to this slide element.
createCommentAsync(content: ThreadComment.ThreadCommentContent, options?: ISlideCommentCreateOptions): Promise<boolean>Parameters
content— Required. Plain text or a Univer document body for rich comment content.options— Optional. Default:{}. Optional stable IDs, author, attachments, and creation time.
Returns
true when the create command succeeds; otherwise, false.
Throws
If the content is empty.
Examples
const element = univerAPI.getActivePresentation()?.getSlideByIndex(0)?.getElements()[0]await element?.createCommentAsync('Check this element.', { id: 'review-element-1' })Types: Promise · ThreadComment.ThreadCommentContent · ISlideCommentCreateOptions
Package: @univerjs-pro/slides-thread-comment · Type definitions
FPageElement.getComments
Returns locally loaded comments anchored to this slide element.
getComments(): ThreadComment.IFacadeThreadCommentInfo[]Returns
Matching comment threads for this exact element ID.
Examples
const element = univerAPI.getActivePresentation()?.getSlideByIndex(0)?.getElements()[0]console.log(element?.getComments().length ?? 0)Types: ThreadComment.IFacadeThreadCommentInfo
Package: @univerjs-pro/slides-thread-comment · Type definitions
FPageElement.listCommentsAsync
Synchronizes known threads and returns comments anchored to this slide element.
listCommentsAsync(): Promise<ThreadComment.IFacadeThreadCommentInfo[]>Returns
A promise resolving to matching synchronized comment threads.
Examples
const element = univerAPI.getActivePresentation()?.getSlideByIndex(0)?.getElements()[0]const comments = element ? await element.listCommentsAsync() : []console.log(comments.length)Types: ThreadComment.IFacadeThreadCommentInfo · Promise
Package: @univerjs-pro/slides-thread-comment · Type definitions
你觉得这篇文档如何?