@microsoft/sp-webpart-base
Version:
SharePoint Framework support for building web parts
107 lines • 5.16 kB
TypeScript
import type { ServiceScope } from '@microsoft/sp-core-library';
import type { _PropertyPaneAction as PropertyPaneAction, _PropertyPaneLifeCycleEvent as PropertyPaneLifeCycleEvent } from '@microsoft/sp-property-pane';
import type { ISDKs } from '../../core/ISDKs';
import type IWebPartData from '../../core/IWebPartData';
import type IWebPartLoadContext from '../../core/IWebPartManagerContext';
/**
* A web part host is a component, control or a page that hosts client-side web parts.
* The web part infrastructure provides many features inbuilt e.g. an HttpClient to make
* server requests and the SPPageContext. The purpose of this interface is not to replicate
* those feature. This interface outlines the services and features where there needs to be
* a direct interaction between the host and the web part infrastructure. This interface also
* outlines some services where the web part host may want to override the default
* implementations provided by the infrastructure. Let us discuss some examples:
*
* - APIs like setDirty, PropertyPaneLifeCycleEventCallback help the web part infrastructure
* communicate the fact that some web part is in a dirty state or web part communication
* events to the host.
*
* - In future we expect that this interface will be used to provide services where the host
* might want to override the default implementations. e.g.
*
* - the web part status rendering service. The default implementation of this service
* provides an office fabric spinny. But a certain host could easily want to show a
* different spinny.
*
* - The event aggregation service. Currently the web part manager hosts a single event
* event aggregator. But there are possibilities when a page can have multiple hosts
* and each host may want to scope its event aggregation service.
*
* @internal
*/
export default interface IWebPartHost {
/**
* The current ServiceScope.
*/
readonly serviceScope: ServiceScope;
/**
* For different host types to easily identify themselves.
* Should be set to name of implementing class if used.
*/
readonly hostType?: string;
/**
* API for the web part to mark the containing host as dirty.
*/
setDirty?: (instanceId: string, data?: any) => void;
/**
* API for the web part to tell the host to show or hide the web part.
*/
onAfterWebPartVisibilityChanged?: (instanceId: string, isVisible: boolean) => void;
/**
* Callback for a Property pane life cycle event.
*/
propertyPaneLifeCycleEventCallback?: IPropertyPaneLifeCycleEventCallback;
/**
* Optionally provide additional context properties.
* The additional properties still need to be exposed by the WebPartContext API.
*/
getAdditionalContextProperties?: () => {};
/**
* Currently the webpart lifecycle is blocked until the TeamsAwareHost is able to load the SDK regardless of whether the SDKs are actually consumed by the webparts.
* This moves the sdk consumption to on-demand and makes the app more performant
*/
getAdditionalContextPropertiesAsync?: () => Promise<ISDKs>;
onBeforeWebPartLoad(options: Readonly<IWebPartLoadContext>): void;
onAfterWebPartLoad(options: Readonly<IWebPartLoadContext>): void;
onAfterWebPartLoadFailed(options: Readonly<IWebPartLoadContext>, error: Error): void;
onBeforeWebPartInitializeOld(options: Readonly<IWebPartLoadContext>): void;
onBeforeWebPartInitialize(options: Readonly<IWebPartLoadContext>): Promise<void>;
onAfterWebPartInitialize(options: Readonly<IWebPartLoadContext>): void;
onAfterWebPartInitializeFailed(options: Readonly<IWebPartLoadContext>, error: Error): void;
onBeforeWebPartRender(options: Readonly<IWebPartLoadContext>): void;
onAfterWebPartRender(options: Readonly<IWebPartLoadContext>): void;
onAfterWebPartRenderFailed(options: Readonly<IWebPartLoadContext>, error: Error): void;
/**
* Allows to inject into property pane action flow. For example, notify parent window from isolated web part.
*
* @returns true if the action is handled by the host.
*/
requestPropertyPaneAction?(instanceId: string, propertyPaneAction: PropertyPaneAction, renderedByWebPart?: boolean, context?: any): boolean;
/**
* Callback function for when the audiences that can view the web part have been updated.
*/
onAudiencesChanged?(instanceId: string, audiences: string[]): void;
}
/**
* Data returned by the web part to the host when invoking the propertyPaneLifeCycleEventCallback.
* @alpha
*/
export interface IPropertyPaneLifeCycleEventData {
/**
* Serialized web part data.
*/
webPartData: IWebPartData;
/**
* Indicates whether the property pane associated with the web part is reactive or not.
*/
isPropertyPaneReactive: boolean;
}
/**
* Callback for the property pane life cycle event.
*
* @alpha
*/
export interface IPropertyPaneLifeCycleEventCallback {
(event: PropertyPaneLifeCycleEvent, data: IPropertyPaneLifeCycleEventData): void;
}
//# sourceMappingURL=IWebPartHost.d.ts.map