|
| 1 | + |
| 2 | +export interface IPowerBiElement extends HTMLElement { |
| 3 | + powerBiEmbed: Embed; |
| 4 | +} |
| 5 | +export interface IPowerBiConfiguration { |
| 6 | + autoEmbedOnContentLoaded?: boolean; |
| 7 | + onError?: (error: any) => any; |
| 8 | +} |
| 9 | + |
| 10 | +export default class PowerBi { |
| 11 | + /** |
| 12 | + * List of components this service can embed. |
| 13 | + */ |
| 14 | + private static components; |
| 15 | + /** |
| 16 | + * Mapping of event names from iframe postMessage to their name percieved by parent DOM. |
| 17 | + * Example: User clicks on embeded report which is inside iframe. The iframe code resends |
| 18 | + * event as postMessage with { event: 'reportClicked', ... } and this name is converted to hyphenated |
| 19 | + * name and dispatched from the parent element of the iframe to simulate the event bubbling through two |
| 20 | + * different windows / DOMs |
| 21 | + */ |
| 22 | + private static eventMap; |
| 23 | + /** |
| 24 | + * Default configuration for service. |
| 25 | + */ |
| 26 | + private static defaultConfig; |
| 27 | + /** Save access token as fallback/global token to use when local token for report/tile is not provided. */ |
| 28 | + accessToken: string; |
| 29 | + /** Configuration object */ |
| 30 | + private config; |
| 31 | + /** List of components (Reports/Tiles) that have been embedded using this service instance. */ |
| 32 | + private embeds; |
| 33 | + constructor(config?: IPowerBiConfiguration); |
| 34 | + /** |
| 35 | + * Handler for DOMContentLoaded which searches DOM for elements having 'powerbi-embed' attribute |
| 36 | + * and automatically attempts to embed a powerbi component based on information from the attributes. |
| 37 | + * Only runs if `config.autoEmbedOnContentLoaded` is true when the service is created. |
| 38 | + */ |
| 39 | + init(container: HTMLElement): void; |
| 40 | + /** |
| 41 | + * Given an html element embed component based on configuration. |
| 42 | + * If component has already been created and attached to eleemnt simply return it to prevent creating duplicate components for same element. |
| 43 | + */ |
| 44 | + embed(element: IPowerBiElement, config?: IEmbedOptions): Embed; |
| 45 | + /** |
| 46 | + * Remove component from the list of embedded components. |
| 47 | + */ |
| 48 | + remove(component: Embed): void; |
| 49 | + /** |
| 50 | + * Handler for window message event. |
| 51 | + * Parses event data as json and if it came from an iframe that matches one from an existing embeded component re-dispatches the event on the iframe's parent element |
| 52 | + * to simulate the event bubbling through the two separate windows / DOMs. |
| 53 | + * |
| 54 | + * If an error occurs when parsing event.data call error handler provided during configuration. |
| 55 | + */ |
| 56 | + onReceiveMessage(event: MessageEvent): void; |
| 57 | +} |
| 58 | + |
| 59 | + |
| 60 | +export interface IEmbedOptions { |
| 61 | + type?: string; |
| 62 | + id?: string; |
| 63 | + accessToken?: string; |
| 64 | + loadAction?: string; |
| 65 | + embedUrl?: string; |
| 66 | + webUrl?: string; |
| 67 | + name?: string; |
| 68 | + filterPaneEnabled?: boolean; |
| 69 | + getGlobalAccessToken?: () => string; |
| 70 | + overwrite?: boolean; |
| 71 | +} |
| 72 | +declare abstract class Embed { |
| 73 | + /** |
| 74 | + * Default options for embeddable component. |
| 75 | + */ |
| 76 | + private static defaultOptions; |
| 77 | + element: HTMLElement; |
| 78 | + iframe: HTMLIFrameElement; |
| 79 | + options: IEmbedOptions; |
| 80 | + constructor(element: HTMLElement, options: IEmbedOptions); |
| 81 | + /** |
| 82 | + * Handler for when the iframe has finished loading the powerbi placeholder page. |
| 83 | + * This is used to inject configuration options such as access token, loadAction, etc |
| 84 | + * which allow iframe to load the actual report with authentication. |
| 85 | + */ |
| 86 | + private load(); |
| 87 | + /** |
| 88 | + * Get access token from first available location: options, attribute, global. |
| 89 | + */ |
| 90 | + private getAccessToken(); |
| 91 | + /** |
| 92 | + * Get embed url from first available location: options, attribute. |
| 93 | + */ |
| 94 | + protected getEmbedUrl(): string; |
| 95 | + /** |
| 96 | + * Request the browser to make the components iframe fullscreen. |
| 97 | + */ |
| 98 | + fullscreen(): void; |
| 99 | + /** |
| 100 | + * Exit fullscreen. |
| 101 | + */ |
| 102 | + exitFullscreen(): void; |
| 103 | + /** |
| 104 | + * Return true if iframe is fullscreen, |
| 105 | + * otherwise return false |
| 106 | + */ |
| 107 | + private isFullscreen(iframe); |
| 108 | +} |
| 109 | + |
| 110 | +export class Report extends Embed { |
| 111 | + static attribute: string; |
| 112 | + constructor(element: HTMLElement, options: IEmbedOptions); |
| 113 | + getEmbedUrl(): string; |
| 114 | +} |
| 115 | + |
| 116 | +export class Tile extends Embed { |
| 117 | + static attribute: string; |
| 118 | + constructor(element: HTMLElement, options: IEmbedOptions); |
| 119 | + getEmbedUrl(): string; |
| 120 | +} |
| 121 | + |
0 commit comments