UNPKG

@microsoft/sp-webpart-base

Version:

SharePoint Framework support for building web parts

139 lines 6.59 kB
import { type DisplayMode } from '@microsoft/sp-core-library'; import type { PageContext } from '@microsoft/sp-page-context'; import type { _PropertyPaneAction as PropertyPaneAction } from '@microsoft/sp-property-pane'; import { type IReadonlyTheme } from '@microsoft/sp-component-base'; import type IWebPartHost from '../../components/host/IWebPartHost'; import type IWebPartData from '../../core/IWebPartData'; import type IWebPartManagerContext from '../../core/IWebPartManagerContext'; import type { IIsolatedAdaptiveCardExtensionWebPart } from '../../core/iframedInterfaces/IIsolatedAdaptiveCardExtensionWebPart'; /** * A schema for the data send in 'Window.postMessage'. * If this interface is changed then you must also change the listener in * 'sp-webpart-application:SpWebPartApplication._propertyPaneEventListener()'. */ export interface IPropertyPaneEventCallback { action: PropertyPaneAction; webPartInstanceId: string; } export default class IframedWebPartController { private _iframeSrcUrl; private _iframedWebparts; private _ppIframeElement; private _pageContentElement; private _iframedPropertyPaneContainer; private _host; private _iframeContextMap; private _iframedPropertyPaneWebPartInstanceId; constructor(host: IWebPartHost); /** * Delete references an iframed web part. */ deleteWebPart(instanceId: string): void; /** * Get the instanceId's of all the iframed webparts. */ getAllInstanceIds(): string[]; /** * Send a message to the iframed webpart to notify that their container * has been resized. */ notifyContainerResize(instanceId: string): void; startDirtyBitTimer(instanceId: string): void; /** * @param domainUrl - the domain from which the web part should be loaded. * Returns an iframe that points to a SpWebApplication that loads the webpart. * @param pageContext - Page context reference. * @param webPartManagerContext - web part manager context. */ loadWebPart(domainUrl: string, pageContext: PageContext, webPartManagerContext: IWebPartManagerContext, isIsolatedACEWP: boolean): void; assignIsolatedACEWP(instanceId: string, isolatedACEWP: IIsolatedAdaptiveCardExtensionWebPart): void; /** * To open a property pane for a web part that has been loaded into an iframe, we create a sibling dom element on the * page and render the property pane into it. We use the same method of loading an iframe with the addition of a * query parameter, 'openPropertyPane=true'. By default 'openPropertyPane' is undefined and thus false. * @param propertyPaneState - the desired state of the property pane. * @param instanceId - the instanceId of the corresponding web part. */ requestPropertyPaneAction(propertyPaneState: PropertyPaneAction, instanceId?: string): void; /** * Returns the most recently saved WebPartData for the web part associated * with the 'instanceId'. */ serialize(instanceId: string): IWebPartData; /** * Handles the ClientSideWebPartManager's request to set the displayMode for a web part * in an iframe. (Saves the displayMode and sends a message to the iframe window). */ setDisplayMode(displayMode: DisplayMode, instanceId: string): void; /** * Handles requests to set the theme for a web part in an iframe. */ setTheme(theme: IReadonlyTheme, instanceId: string): void; /** * Returns the url that loads the webpart with instanceId and componentId on the 'webPartManagerContext'. * @param domainUrl - the domain from which the web part should be loaded. * @param pageContext - Page context reference. * @param webPartManagerContext - web part manager context. */ private _generateIframeSrcUrl; /** * Creates an iframe HTML element, sets the source url to load an application that will * display the property pane associated with the given parameters, and add the iframed * element as a child to the page chrome. This method will not show the property pane by * default, 'showPropertyPane' should be called after. */ private _createPropertyPaneElement; /** * Event listener that takes actions on behalf of iframed webparts. */ private _iframeEventListener; private _updateThemeInfo; private _tryGetTheme; private _updateParentHost; /** * Sends a message to an iframed webpart requesting the 'displayMode' set by the ClientSideWebPartManager. * * When an iframe loads a webpart in an iframe it has the context of the webpart's 'displayMode', but the * iframe does not. Thus, after a webpart loads in an iframed, we send a message to the IframedWebPartController * asking for the display mode, which is then sent to the iframe via a window message. * */ private _updateWebPartDisplayMode; /** * Sends a message to the iframed web part to update it's web part data if the incoming * webPartData differs from the currently saved reference. * There are two scenarios: * 1. the property pane has been updated and is sending a message to the rendered web part * 2. the rendered web part has been updated and is sending a message to the property pane * - we use the param 'action' to differentiate the difference and use the correct element id * of the property pane or the web part. * * @param instanceId - web part instance id * @param webPartData - the incoming web part data. */ private _updateWebPartData; private _updateAudiences; private _refreshPropertyPane; private _hidePropertyPane; /** * Adds and removes the neccessary styles to show the iframed property pane container. * Also posts a message to the window element so that the PropertyPaneController * can show the property pane content. * @param webPartInstanceId - instanceId so we know which property pane to open */ private _showPropertyPane; private _setOboToken; /** * Adds the non-reserved query params from the host page to the iframe url. * * @param url - current iframe url. */ private _addFilteredQueryParamsFromHostPage; private _getCurrentIframeWebPartContentWindow; /** * @param instanceId - Web part to check * @returns - A boolean indicating whether the web part is being rendered in the Dashboard Web Part */ private _isHostDashboardWebPart; } //# sourceMappingURL=IframedWebPartController.d.ts.map