From 765bf3102bffb498e5cd68f2bb0b7cb000050ac3 Mon Sep 17 00:00:00 2001 From: Matt Mazzola Date: Thu, 26 May 2016 13:48:01 -0700 Subject: [PATCH 1/2] Add gulp dts task which generates single .d.ts from multiple files as workaround. This uses concatenation which means we can use default exports. --- dist/powerbi.d.ts | 199 +++++++++++++++++++++++++++----------------- dist/powerbi.js | 51 +++++------- dist/powerbi.js.map | 2 +- dist/powerbi.min.js | 4 +- gulpfile.js | 33 ++++---- package.json | 1 + src/core.ts | 10 +-- src/embed.ts | 8 +- src/powerbi.d.ts | 134 ----------------------------- src/powerbi.ts | 13 ++- src/report.ts | 4 +- src/tile.ts | 4 +- src/util.ts | 2 +- test/embed.spec.ts | 2 +- 14 files changed, 191 insertions(+), 276 deletions(-) delete mode 100644 src/powerbi.d.ts diff --git a/dist/powerbi.d.ts b/dist/powerbi.d.ts index 522b263d..13a0c87b 100644 --- a/dist/powerbi.d.ts +++ b/dist/powerbi.d.ts @@ -1,3 +1,105 @@ +export declare class Utils { + static raiseCustomEvent(element: HTMLElement, eventName: string, eventData: any): void; + static findIndex(predicate: (T) => boolean, xs: T[]): number; + static find(predicate: (T) => boolean, xs: T[]): T; + static remove(predicate: (T) => boolean, xs: T[]): void; + static assign: (...args: any[]) => any; +} + +declare global { + interface Document { + mozCancelFullScreen: Function; + msExitFullscreen: Function; + } + interface HTMLIFrameElement { + mozRequestFullScreen: Function; + msRequestFullscreen: Function; + } +} +export interface ILoadMessage { + action: string; + accessToken: string; +} +export interface IEmbedOptions { + type?: string; + id?: string; + accessToken?: string; + embedUrl?: string; + webUrl?: string; + name?: string; + filterPaneEnabled?: boolean; + getGlobalAccessToken?: () => string; +} +export interface IEmbedConstructor { + new (...args: any[]): Embed; +} +export declare abstract class Embed { + static embedUrlAttribute: string; + static accessTokenAttribute: string; + static typeAttribute: string; + /** + * Attribute used to specify type of visual. + * Example: `
` + */ + static name: string; + /** + * Default options for embeddable component. + */ + private static defaultOptions; + element: HTMLElement; + iframe: HTMLIFrameElement; + options: IEmbedOptions; + constructor(element: HTMLElement, options: IEmbedOptions); + /** + * Handler for when the iframe has finished loading the powerbi placeholder page. + * This is used to inject configuration options such as access token, loadAction, etc + * which allow iframe to load the actual report with authentication. + */ + load(options: IEmbedOptions, requireId?: boolean, message?: ILoadMessage): void; + /** + * Get access token from first available location: options, attribute, global. + */ + private getAccessToken(); + /** + * Get embed url from first available location: options, attribute. + */ + protected getEmbedUrl(): string; + /** + * Request the browser to make the components iframe fullscreen. + */ + fullscreen(): void; + /** + * Exit fullscreen. + */ + exitFullscreen(): void; + /** + * Return true if iframe is fullscreen, + * otherwise return false + */ + private isFullscreen(iframe); +} +export {}; + + +export interface IReportLoadMessage extends ILoadMessage { + reportId: string; +} +export declare class Report extends Embed { + static name: string; + getEmbedUrl(): string; + load(options: IEmbedOptions, requireId?: boolean): void; +} + + +export interface ITileLoadMessage extends ILoadMessage { + tileId: string; +} +export declare class Tile extends Embed { + static name: string; + getEmbedUrl(): string; + load(options: IEmbedOptions, requireId?: boolean): void; +} + export interface IPowerBiElement extends HTMLElement { powerBiEmbed: Embed; @@ -6,15 +108,7 @@ export interface IPowerBiConfiguration { autoEmbedOnContentLoaded?: boolean; onError?: (error: any) => any; } - -declare global { - interface Window { - Powerbi: typeof PowerBi; - powerbi: PowerBi; - } -} - -export class PowerBi { +export declare class PowerBi { /** * List of components this service can embed. */ @@ -39,16 +133,23 @@ export class PowerBi { private embeds; constructor(config?: IPowerBiConfiguration); /** - * Handler for DOMContentLoaded which searches DOM for elements having 'powerbi-embed' attribute + * Handler for DOMContentLoaded which searches DOM for elements having 'powerbi-embed-url' attribute * and automatically attempts to embed a powerbi component based on information from the attributes. * Only runs if `config.autoEmbedOnContentLoaded` is true when the service is created. */ - init(container: HTMLElement): void; + init(container?: HTMLElement): void; /** * Given an html element embed component based on configuration. - * If component has already been created and attached to eleemnt simply return it to prevent creating duplicate components for same element. + * If component has already been created and attached to element re-use component instance and existing iframe, + * otherwise create a new component instance */ embed(element: HTMLElement, config?: IEmbedOptions): Embed; + /** + * Given an html element embed component base configuration. + * Save component instance on element for later lookup. + */ + private embedNew(element, config); + private embedExisting(element, config); /** * Adds event handler for DOMContentLoaded which finds all elements in DOM with attribute powerbi-embed-url * then attempts to initiate the embed process based on data from other powerbi-* attributes. @@ -56,7 +157,11 @@ export class PowerBi { */ enableAutoEmbed(): void; /** - * Remove component from the list of embedded components. + * Returns instance of component associated with element. + */ + get(element: HTMLElement): Embed; + /** + * Given an html element which has component embedded within it, remove the component from list of embeds, remove association with component, and remove the iframe. */ reset(element: HTMLElement): void; /** @@ -66,69 +171,13 @@ export class PowerBi { * * If an error occurs when parsing event.data call error handler provided during configuration. */ - private onReceiveMessage(event: MessageEvent): void; -} - -export interface IEmbedOptions { - type?: string; - id?: string; - accessToken?: string; - embedUrl?: string; - webUrl?: string; - name?: string; - filter?: any; - filterPaneEnabled?: boolean; - getGlobalAccessToken?: () => string; -} - -declare abstract class Embed { - public static embedUrlAttribute: string; - public static accessTokenAttribute: string; - public static typeAttribute: string; - /** - * Default options for embeddable component. - */ - private static defaultOptions; - element: HTMLElement; - iframe: HTMLIFrameElement; - options: IEmbedOptions; - constructor(element: HTMLElement, options: IEmbedOptions); - /** - * Handler for when the iframe has finished loading the powerbi placeholder page. - * This is used to inject configuration options such as access token, action, etc - * which allow iframe to load the actual report with authentication. - */ - load(options: IEmbedOptions, requireId: boolean, message: IEmbedOptions); - /** - * Get access token from first available location: options, attribute, global. - */ - private getAccessToken(); - /** - * Get embed url from first available location: options, attribute. - */ - protected getEmbedUrl(): string; - /** - * Request the browser to make the components iframe fullscreen. - */ - fullscreen(): void; - /** - * Exit fullscreen. - */ - exitFullscreen(): void; - /** - * Return true if iframe is fullscreen, - * otherwise return false - */ - private isFullscreen(iframe); + private onReceiveMessage(event); } -export class Report extends Embed { - constructor(element: HTMLElement, options: IEmbedOptions); - getEmbedUrl(): string; -} -export class Tile extends Embed { - constructor(element: HTMLElement, options: IEmbedOptions); - getEmbedUrl(): string; +declare global { + interface Window { + Powerbi: typeof PowerBi; + powerbi: PowerBi; + } } - diff --git a/dist/powerbi.js b/dist/powerbi.js index b772dc04..3a4ef626 100644 --- a/dist/powerbi.js +++ b/dist/powerbi.js @@ -50,8 +50,8 @@ * Save class to allow creating an instance of the service. * Create instance of class with default config for normal usage. */ - window.Powerbi = core_1.default; - window.powerbi = new core_1.default(); + window.Powerbi = core_1.PowerBi; + window.powerbi = new core_1.PowerBi(); /***/ }, @@ -68,7 +68,7 @@ this.embeds = []; window.addEventListener('message', this.onReceiveMessage.bind(this), false); // TODO: Change when Object.assign is available. - this.config = util_1.default.assign({}, PowerBi.defaultConfig, config); + this.config = util_1.Utils.assign({}, PowerBi.defaultConfig, config); if (this.config.autoEmbedOnContentLoaded) { this.enableAutoEmbed(); } @@ -81,7 +81,7 @@ PowerBi.prototype.init = function (container) { var _this = this; container = (container && container instanceof HTMLElement) ? container : document.body; - var elements = Array.prototype.slice.call(container.querySelectorAll("[" + embed_1.default.embedUrlAttribute + "]")); + var elements = Array.prototype.slice.call(container.querySelectorAll("[" + embed_1.Embed.embedUrlAttribute + "]")); elements.forEach(function (element) { return _this.embed(element); }); }; /** @@ -107,13 +107,13 @@ */ PowerBi.prototype.embedNew = function (element, config) { var _this = this; - var componentType = config.type || element.getAttribute(embed_1.default.typeAttribute); + var componentType = config.type || element.getAttribute(embed_1.Embed.typeAttribute); if (!componentType) { - throw new Error("Attempted to embed using config " + JSON.stringify(config) + " on element " + element.outerHTML + ", but could not determine what type of component to embed. You must specify a type in the configuration or as an attribute such as '" + embed_1.default.typeAttribute + "=\"" + report_1.default.name.toLowerCase() + "\"'."); + throw new Error("Attempted to embed using config " + JSON.stringify(config) + " on element " + element.outerHTML + ", but could not determine what type of component to embed. You must specify a type in the configuration or as an attribute such as '" + embed_1.Embed.typeAttribute + "=\"" + report_1.Report.name.toLowerCase() + "\"'."); } // Save type on configuration so it can be referenced later at known location config.type = componentType; - var Component = util_1.default.find(function (component) { return componentType === component.name.toLowerCase(); }, PowerBi.components); + var Component = util_1.Utils.find(function (component) { return componentType === component.name.toLowerCase(); }, PowerBi.components); if (!Component) { throw new Error("Attempted to embed component of type: " + componentType + " but did not find any matching component. Please verify the type you specified is intended."); } @@ -127,7 +127,7 @@ return component; }; PowerBi.prototype.embedExisting = function (element, config) { - var component = util_1.default.find(function (x) { return x.element === element; }, this.embeds); + var component = util_1.Utils.find(function (x) { return x.element === element; }, this.embeds); if (!component) { throw new Error("Attempted to embed using config " + JSON.stringify(config) + " on element " + element.outerHTML + " which already has embedded comopnent associated, but could not find the existing comopnent in the list of active components. This could indicate the embeds list is out of sync with the DOM, or the component is referencing the incorrect HTML element."); } @@ -162,7 +162,7 @@ return; } /** Remove component from internal list */ - util_1.default.remove(function (x) { return x === powerBiElement.powerBiEmbed; }, this.embeds); + util_1.Utils.remove(function (x) { return x === powerBiElement.powerBiEmbed; }, this.embeds); /** Delete property from html element */ delete powerBiElement.powerBiEmbed; /** Remove iframe from element */ @@ -184,10 +184,10 @@ } try { // Only raise the event on the embed that matches the post message origin - var embed = util_1.default.find(function (embed) { return event.source === embed.iframe.contentWindow; }, this.embeds); + var embed = util_1.Utils.find(function (embed) { return event.source === embed.iframe.contentWindow; }, this.embeds); if (embed) { var messageData = typeof event.data === 'string' ? JSON.parse(event.data) : event.data; - util_1.default.raiseCustomEvent(embed.element, PowerBi.eventMap[messageData.event], messageData); + util_1.Utils.raiseCustomEvent(embed.element, PowerBi.eventMap[messageData.event], messageData); } } catch (e) { @@ -203,8 +203,8 @@ * List of components this service can embed. */ PowerBi.components = [ - tile_1.default, - report_1.default + tile_1.Tile, + report_1.Report ]; /** * Mapping of event names from iframe postMessage to their name percieved by parent DOM. @@ -234,8 +234,7 @@ return PowerBi; }()); exports.PowerBi = PowerBi; - Object.defineProperty(exports, "__esModule", { value: true }); - exports.default = PowerBi; + // export default PowerBi; /***/ }, @@ -248,7 +247,7 @@ var _this = this; this.element = element; // TODO: Change when Object.assign is available. - this.options = util_1.default.assign({}, Embed.defaultOptions, options); + this.options = util_1.Utils.assign({}, Embed.defaultOptions, options); this.options.accessToken = this.getAccessToken(); this.options.embedUrl = this.getEmbedUrl(); var iframeHtml = ""; @@ -270,11 +269,11 @@ var baseMessage = { accessToken: options.accessToken }; - util_1.default.assign(message, baseMessage); + util_1.Utils.assign(message, baseMessage); var event = { message: message }; - util_1.default.raiseCustomEvent(this.element, event.message.action, event); + util_1.Utils.raiseCustomEvent(this.element, event.message.action, event); this.iframe.contentWindow.postMessage(JSON.stringify(event.message), '*'); }; /** @@ -333,8 +332,7 @@ }; return Embed; }()); - Object.defineProperty(exports, "__esModule", { value: true }); - exports.default = Embed; + exports.Embed = Embed; /***/ }, @@ -417,8 +415,7 @@ }; return Utils; }()); - Object.defineProperty(exports, "__esModule", { value: true }); - exports.default = Utils; + exports.Utils = Utils; /***/ }, @@ -460,9 +457,8 @@ }; Report.name = "Report"; return Report; - }(embed_1.default)); - Object.defineProperty(exports, "__esModule", { value: true }); - exports.default = Report; + }(embed_1.Embed)); + exports.Report = Report; /***/ }, @@ -498,9 +494,8 @@ }; Tile.name = "Tile"; return Tile; - }(embed_1.default)); - Object.defineProperty(exports, "__esModule", { value: true }); - exports.default = Tile; + }(embed_1.Embed)); + exports.Tile = Tile; /***/ } diff --git a/dist/powerbi.js.map b/dist/powerbi.js.map index 76327119..0ab3147d 100644 --- a/dist/powerbi.js.map +++ b/dist/powerbi.js.map @@ -1 +1 @@ -{"version":3,"sources":["webpack:///webpack/bootstrap df06ebbae0c5bb7efe7b","webpack:///./src/powerbi.ts","webpack:///./src/core.ts","webpack:///./src/embed.ts","webpack:///./src/util.ts","webpack:///./src/report.ts","webpack:///./src/tile.ts"],"names":[],"mappings":";AAAA;AACA;;AAEA;AACA;;AAEA;AACA;AACA;;AAEA;AACA;AACA,uBAAe;AACf;AACA;AACA;;AAEA;AACA;;AAEA;AACA;;AAEA;AACA;AACA;;;AAGA;AACA;;AAEA;AACA;;AAEA;AACA;;AAE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AC,IAAI,YAAC,OAAO,EAAE,SAAS,EAAE,OAAO,CAAC,CAAC;KAC5C,CAAC;KApBM,SAAI,GAAG,MAAM,CAAC;KAqBzB,WAAC;AAAD,EAAC,CAtBiC,eAAK,GAsBtC;AAtBD;uBAsBC","file":"powerbi.js","sourcesContent":[" \t// The module cache\n \tvar installedModules = {};\n\n \t// The require function\n \tfunction __webpack_require__(moduleId) {\n\n \t\t// Check if module is in cache\n \t\tif(installedModules[moduleId])\n \t\t\treturn installedModules[moduleId].exports;\n\n \t\t// Create a new module (and put it into the cache)\n \t\tvar module = installedModules[moduleId] = {\n \t\t\texports: {},\n \t\t\tid: moduleId,\n \t\t\tloaded: false\n \t\t};\n\n \t\t// Execute the module function\n \t\tmodules[moduleId].call(module.exports, module, module.exports, __webpack_require__);\n\n \t\t// Flag the module as loaded\n \t\tmodule.loaded = true;\n\n \t\t// Return the exports of the module\n \t\treturn module.exports;\n \t}\n\n\n \t// expose the modules object (__webpack_modules__)\n \t__webpack_require__.m = modules;\n\n \t// expose the module cache\n \t__webpack_require__.c = installedModules;\n\n \t// __webpack_public_path__\n \t__webpack_require__.p = \"\";\n\n \t// Load entry module and return exports\n \treturn __webpack_require__(0);\n\n\n\n/** WEBPACK FOOTER **\n ** webpack/bootstrap df06ebbae0c5bb7efe7b\n **/","import PowerBi from './core';\r\n\r\n/**\r\n * Make PowerBi available on global object for use in apps without module loading support.\r\n * Save class to allow creating an instance of the service.\r\n * Create instance of class with default config for normal usage.\r\n */\r\n(window).Powerbi = PowerBi;\r\n(window).powerbi = new PowerBi();\n\n\n/** WEBPACK FOOTER **\n ** ./src/powerbi.ts\n **/","import { default as Embed, IEmbedConstructor, IEmbedOptions } from './embed';\r\nimport Report from './report';\r\nimport Tile from './tile';\r\nimport Utils from './util';\r\n\r\nexport interface IPowerBiElement extends HTMLElement {\r\n powerBiEmbed: Embed;\r\n}\r\n\r\nexport interface IPowerBiConfiguration {\r\n autoEmbedOnContentLoaded?: boolean;\r\n onError?: (error: any) => any;\r\n}\r\n\r\nexport class PowerBi {\r\n /**\r\n * List of components this service can embed.\r\n */\r\n private static components: IEmbedConstructor[] = [\r\n Tile,\r\n Report\r\n ];\r\n /**\r\n * Mapping of event names from iframe postMessage to their name percieved by parent DOM.\r\n * Example: User clicks on embeded report which is inside iframe. The iframe code resends \r\n * event as postMessage with { event: 'reportClicked', ... } and this name is converted to hyphenated\r\n * name and dispatched from the parent element of the iframe to simulate the event bubbling through two\r\n * different windows / DOMs\r\n */\r\n private static eventMap = {\r\n 'tileClicked': 'tile-click',\r\n 'tileLoaded': 'tile-load',\r\n 'reportPageLoaded': 'report-load'\r\n };\r\n \r\n /**\r\n * Default configuration for service.\r\n */\r\n private static defaultConfig: IPowerBiConfiguration = {\r\n autoEmbedOnContentLoaded: false,\r\n onError: (...args) => console.log(args[0], args.slice(1))\r\n };\r\n\r\n /** Save access token as fallback/global token to use when local token for report/tile is not provided. */\r\n accessToken: string;\r\n \r\n /** Configuration object */\r\n private config: IPowerBiConfiguration;\r\n \r\n /** List of components (Reports/Tiles) that have been embedded using this service instance. */\r\n private embeds: Embed[];\r\n \r\n constructor(config: IPowerBiConfiguration = {}) {\r\n this.embeds = [];\r\n window.addEventListener('message', this.onReceiveMessage.bind(this), false);\r\n \r\n // TODO: Change when Object.assign is available.\r\n this.config = Utils.assign({}, PowerBi.defaultConfig, config);\r\n \r\n if (this.config.autoEmbedOnContentLoaded) {\r\n this.enableAutoEmbed();\r\n }\r\n }\r\n \r\n /**\r\n * Handler for DOMContentLoaded which searches DOM for elements having 'powerbi-embed-url' attribute\r\n * and automatically attempts to embed a powerbi component based on information from the attributes.\r\n * Only runs if `config.autoEmbedOnContentLoaded` is true when the service is created.\r\n */\r\n init(container?: HTMLElement): void {\r\n container = (container && container instanceof HTMLElement) ? container : document.body;\r\n \r\n const elements = Array.prototype.slice.call(container.querySelectorAll(`[${Embed.embedUrlAttribute}]`));\r\n elements.forEach(element => this.embed(element));\r\n }\r\n \r\n /**\r\n * Given an html element embed component based on configuration.\r\n * If component has already been created and attached to element re-use component instance and existing iframe,\r\n * otherwise create a new component instance\r\n */\r\n embed(element: HTMLElement, config: IEmbedOptions = {}): Embed {\r\n let component: Embed;\r\n let powerBiElement = element;\r\n \r\n if (powerBiElement.powerBiEmbed) {\r\n component = this.embedExisting(powerBiElement, config);\r\n }\r\n else {\r\n component = this.embedNew(powerBiElement, config);\r\n }\r\n \r\n return component;\r\n }\r\n \r\n /**\r\n * Given an html element embed component base configuration.\r\n * Save component instance on element for later lookup. \r\n */\r\n private embedNew(element: IPowerBiElement, config: IEmbedOptions): Embed {\r\n const componentType = config.type || element.getAttribute(Embed.typeAttribute);\r\n if (!componentType) {\r\n throw new Error(`Attempted to embed using config ${JSON.stringify(config)} on element ${element.outerHTML}, but could not determine what type of component to embed. You must specify a type in the configuration or as an attribute such as '${Embed.typeAttribute}=\"${Report.name.toLowerCase()}\"'.`);\r\n }\r\n \r\n // Save type on configuration so it can be referenced later at known location\r\n config.type = componentType;\r\n \r\n const Component = Utils.find(component => componentType === component.name.toLowerCase(), PowerBi.components);\r\n if (!Component) {\r\n throw new Error(`Attempted to embed component of type: ${componentType} but did not find any matching component. Please verify the type you specified is intended.`);\r\n }\r\n \r\n // TODO: Consider removing in favor of passing reference to `this` in constructor\r\n // The getGlobalAccessToken function is only here so that the components (Tile | Report) can get the global access token without needing reference\r\n // to the service that they are registered within becaues it creates circular dependencies\r\n config.getGlobalAccessToken = () => this.accessToken;\r\n \r\n const component = new Component(element, config);\r\n element.powerBiEmbed = component;\r\n this.embeds.push(component);\r\n \r\n return component;\r\n }\r\n \r\n private embedExisting(element: IPowerBiElement, config: IEmbedOptions): Embed {\r\n const component = Utils.find(x => x.element === element, this.embeds);\r\n if (!component) {\r\n throw new Error(`Attempted to embed using config ${JSON.stringify(config)} on element ${element.outerHTML} which already has embedded comopnent associated, but could not find the existing comopnent in the list of active components. This could indicate the embeds list is out of sync with the DOM, or the component is referencing the incorrect HTML element.`);\r\n }\r\n \r\n component.load(config, true);\r\n \r\n return component;\r\n }\r\n \r\n /**\r\n * Adds event handler for DOMContentLoaded which finds all elements in DOM with attribute powerbi-embed-url\r\n * then attempts to initiate the embed process based on data from other powerbi-* attributes.\r\n * (This is usually only useful for applications rendered on by the server since all the data needed will be available by the time the handler is called.)\r\n */\r\n enableAutoEmbed() {\r\n window.addEventListener('DOMContentLoaded', (event: Event) => this.init(document.body), false);\r\n }\r\n \r\n /**\r\n * Returns instance of component associated with element.\r\n */\r\n get(element: HTMLElement) {\r\n const powerBiElement = element;\r\n \r\n if (!powerBiElement.powerBiEmbed) {\r\n throw new Error(`You attempted to get an instance of powerbi component associated with element: ${element.outerHTML} but there was no associated instance.`);\r\n }\r\n \r\n return powerBiElement.powerBiEmbed;\r\n }\r\n \r\n /**\r\n * Given an html element which has component embedded within it, remove the component from list of embeds, remove association with component, and remove the iframe.\r\n */\r\n reset(element: HTMLElement) {\r\n const powerBiElement = element;\r\n \r\n if (!powerBiElement.powerBiEmbed) {\r\n return;\r\n }\r\n \r\n /** Remove component from internal list */\r\n Utils.remove(x => x === powerBiElement.powerBiEmbed, this.embeds);\r\n /** Delete property from html element */\r\n delete powerBiElement.powerBiEmbed;\r\n /** Remove iframe from element */\r\n const iframe = element.querySelector('iframe');\r\n if(iframe) {\r\n iframe.remove();\r\n }\r\n }\r\n \r\n /**\r\n * Handler for window message event.\r\n * 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\r\n * to simulate the event bubbling through the two separate windows / DOMs.\r\n * \r\n * If an error occurs when parsing event.data call error handler provided during configuration.\r\n */\r\n private onReceiveMessage(event: MessageEvent): void {\r\n if (!event) {\r\n return;\r\n }\r\n\r\n try {\r\n // Only raise the event on the embed that matches the post message origin\r\n const embed = Utils.find(embed => event.source === embed.iframe.contentWindow, this.embeds);\r\n if(embed) {\r\n let messageData = typeof event.data === 'string' ? JSON.parse(event.data) : event.data;\r\n Utils.raiseCustomEvent(embed.element, PowerBi.eventMap[messageData.event], messageData);\r\n }\r\n }\r\n catch (e) {\r\n if (typeof this.config.onError === 'function') {\r\n this.config.onError.call(window, e);\r\n }\r\n else {\r\n throw e;\r\n }\r\n }\r\n }\r\n}\r\n\r\nexport default PowerBi;\n\n\n/** WEBPACK FOOTER **\n ** ./src/core.ts\n **/","import Utils from './util';\r\n\r\ndeclare global {\r\n interface Document {\r\n // Mozilla Fullscreen\r\n mozCancelFullScreen: Function;\r\n \r\n // Ms Fullscreen\r\n msExitFullscreen: Function;\r\n }\r\n \r\n interface HTMLIFrameElement {\r\n // Mozilla Fullscreen\r\n mozRequestFullScreen: Function;\r\n \r\n // Ms Fullscreen\r\n msRequestFullscreen: Function;\r\n }\r\n}\r\n\r\nexport interface ILoadMessage {\r\n action: string;\r\n accessToken: string;\r\n}\r\n\r\nexport interface IEmbedOptions {\r\n type?: string;\r\n id?: string;\r\n accessToken?: string;\r\n embedUrl?: string;\r\n webUrl?: string;\r\n name?: string;\r\n filterPaneEnabled?: boolean;\r\n getGlobalAccessToken?: () => string;\r\n}\r\n\r\nexport interface IEmbedConstructor {\r\n new(...args: any[]): Embed;\r\n}\r\n\r\nabstract class Embed {\r\n public static embedUrlAttribute = 'powerbi-embed-url';\r\n public static accessTokenAttribute = 'powerbi-access-token';\r\n public static typeAttribute = 'powerbi-type';\r\n \r\n /**\r\n * Attribute used to specify type of visual.\r\n * Example: `
`\r\n */\r\n public static name: string;\r\n /**\r\n * Default options for embeddable component.\r\n */\r\n private static defaultOptions: IEmbedOptions = {\r\n filterPaneEnabled: true\r\n };\r\n \r\n element: HTMLElement;\r\n iframe: HTMLIFrameElement;\r\n options: IEmbedOptions;\r\n \r\n constructor(element: HTMLElement, options: IEmbedOptions) {\r\n this.element = element;\r\n \r\n // TODO: Change when Object.assign is available.\r\n this.options = Utils.assign({}, Embed.defaultOptions, options);\r\n this.options.accessToken = this.getAccessToken();\r\n this.options.embedUrl = this.getEmbedUrl();\r\n \r\n const iframeHtml = ``;\r\n \r\n this.element.innerHTML = iframeHtml;\r\n this.iframe = this.element.childNodes[0];\r\n this.iframe.addEventListener('load', () => this.load(this.options, false), false);\r\n }\r\n \r\n /**\r\n * Handler for when the iframe has finished loading the powerbi placeholder page.\r\n * This is used to inject configuration options such as access token, loadAction, etc\r\n * which allow iframe to load the actual report with authentication.\r\n */\r\n load(options: IEmbedOptions, requireId: boolean = false, message: ILoadMessage = null) {\r\n if(!message) {\r\n throw new Error(`You called load without providing message properties from the concrete embeddable class.`);\r\n }\r\n \r\n const baseMessage = {\r\n accessToken: options.accessToken\r\n };\r\n \r\n Utils.assign(message, baseMessage);\r\n \r\n const event = {\r\n message\r\n };\r\n \r\n Utils.raiseCustomEvent(this.element, event.message.action, event);\r\n this.iframe.contentWindow.postMessage(JSON.stringify(event.message), '*');\r\n }\r\n \r\n /**\r\n * Get access token from first available location: options, attribute, global.\r\n */\r\n private getAccessToken(): string {\r\n const accessToken = this.options.accessToken || this.element.getAttribute(Embed.accessTokenAttribute) || this.options.getGlobalAccessToken();\r\n \r\n if (!accessToken) {\r\n throw new Error(`No access token was found for element. You must specify an access token directly on the element using attribute '${Embed.accessTokenAttribute}' or specify a global token at: powerbi.accessToken.`);\r\n }\r\n \r\n return accessToken;\r\n }\r\n \r\n /**\r\n * Get embed url from first available location: options, attribute.\r\n */\r\n protected getEmbedUrl(): string {\r\n const embedUrl = this.options.embedUrl || this.element.getAttribute(Embed.embedUrlAttribute);\r\n \r\n if(typeof embedUrl !== 'string' || embedUrl.length === 0) {\r\n throw new Error(`Embed Url is required, but it was not found. You must provide an embed url either as part of embed configuration or as attribute '${Embed.embedUrlAttribute}'.`);\r\n }\r\n \r\n return embedUrl; \r\n }\r\n\r\n /**\r\n * Request the browser to make the components iframe fullscreen.\r\n */\r\n fullscreen(): void {\r\n const requestFullScreen = this.iframe.requestFullscreen || this.iframe.msRequestFullscreen || this.iframe.mozRequestFullScreen || this.iframe.webkitRequestFullscreen;\r\n requestFullScreen.call(this.iframe);\r\n }\r\n \r\n /**\r\n * Exit fullscreen.\r\n */\r\n exitFullscreen(): void {\r\n if (!this.isFullscreen(this.iframe)) {\r\n return;\r\n }\r\n\r\n const exitFullscreen = document.exitFullscreen || document.mozCancelFullScreen || document.webkitExitFullscreen || document.msExitFullscreen;\r\n exitFullscreen.call(document);\r\n }\r\n \r\n /**\r\n * Return true if iframe is fullscreen,\r\n * otherwise return false \r\n */\r\n private isFullscreen(iframe: HTMLIFrameElement): boolean {\r\n const options = ['fullscreenElement', 'webkitFullscreenElement', 'mozFullscreenScreenElement', 'msFullscreenElement'];\r\n \r\n return options.some(option => document[option] === iframe);\r\n }\r\n}\r\n\r\nexport default Embed;\n\n\n/** WEBPACK FOOTER **\n ** ./src/embed.ts\n **/","export default class Utils {\r\n static raiseCustomEvent(element: HTMLElement, eventName: string, eventData: any) {\r\n let customEvent;\r\n if (typeof CustomEvent === 'function') {\r\n customEvent = new CustomEvent(eventName, {\r\n detail: eventData,\r\n bubbles: true,\r\n cancelable: true\r\n });\r\n } else {\r\n customEvent = document.createEvent('CustomEvent');\r\n customEvent.initCustomEvent(eventName, true, true, eventData);\r\n }\r\n\r\n element.dispatchEvent(customEvent);\r\n if (customEvent.defaultPrevented || !customEvent.returnValue) {\r\n return;\r\n }\r\n\r\n // TODO: Remove this? Should be better way to handle events than using eval?\r\n // What is use case?
\r\n const inlineEventAttr = 'on' + eventName.replace('-', '');\r\n const inlineScript = element.getAttribute(inlineEventAttr);\r\n if (inlineScript) {\r\n eval.call(element, inlineScript);\r\n }\r\n }\r\n \r\n static findIndex(predicate: (T) => boolean, xs: T[]): number {\r\n if(!Array.isArray(xs)) {\r\n throw new Error(`You attempted to call find with second parameter that was not an array. You passed: ${xs}`);\r\n }\r\n \r\n let index;\r\n xs.some((x, i) => {\r\n if(predicate(x)) {\r\n index = i;\r\n return true;\r\n }\r\n });\r\n \r\n return index;\r\n }\r\n \r\n static find(predicate: (T) => boolean, xs: T[]): T {\r\n const index = Utils.findIndex(predicate, xs);\r\n return xs[index];\r\n }\r\n \r\n static remove(predicate: (T) => boolean, xs: T[]): void {\r\n const index = Utils.findIndex(predicate, xs);\r\n xs.splice(index, 1);\r\n }\r\n \r\n // See: https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Object/assign\r\n // TODO: replace in favor of using polyfill\r\n static assign = function (...args) {\r\n var target = args[0];\r\n \r\n 'use strict';\r\n if (target === undefined || target === null) {\r\n throw new TypeError('Cannot convert undefined or null to object');\r\n }\r\n\r\n var output = Object(target);\r\n for (var index = 1; index < arguments.length; index++) {\r\n var source = arguments[index];\r\n if (source !== undefined && source !== null) {\r\n for (var nextKey in source) {\r\n if (source.hasOwnProperty(nextKey)) {\r\n output[nextKey] = source[nextKey];\r\n }\r\n }\r\n }\r\n }\r\n return output;\r\n };\r\n}\n\n\n/** WEBPACK FOOTER **\n ** ./src/util.ts\n **/","import { default as Embed, IEmbedOptions, ILoadMessage } from './embed';\r\n\r\nexport interface IReportLoadMessage extends ILoadMessage {\r\n reportId: string\r\n}\r\n\r\nexport default class Report extends Embed {\r\n static name = \"Report\";\r\n \r\n getEmbedUrl(): string {\r\n let embedUrl = super.getEmbedUrl();\r\n \r\n // TODO: Need safe way to add url parameters.\r\n // We are assuming embedUrls use query parameters to supply id of visual\r\n // so must prefix with '&'.\r\n if(!this.options.filterPaneEnabled) {\r\n embedUrl += `&filterPaneEnabled=false`;\r\n }\r\n\r\n return embedUrl;\r\n }\r\n\r\n load(options: IEmbedOptions, requireId: boolean = false) {\r\n if(requireId && typeof options.id !== 'string') {\r\n throw new Error(`id must be specified when loading reports on existing elements.`);\r\n }\r\n \r\n const message: IReportLoadMessage = {\r\n action: 'loadReport',\r\n reportId: options.id,\r\n accessToken: null\r\n };\r\n \r\n super.load(options, requireId, message);\r\n }\r\n}\n\n\n/** WEBPACK FOOTER **\n ** ./src/report.ts\n **/","import { default as Embed, IEmbedOptions, ILoadMessage } from './embed';\r\n\r\nexport interface ITileLoadMessage extends ILoadMessage {\r\n tileId: string\r\n}\r\n\r\nexport default class Tile extends Embed {\r\n static name = \"Tile\";\r\n \r\n getEmbedUrl(): string {\r\n const embedUrl = super.getEmbedUrl();\r\n\r\n return embedUrl;\r\n }\r\n \r\n load(options: IEmbedOptions, requireId: boolean = false) {\r\n if(requireId && typeof options.id !== 'string') {\r\n throw new Error(`id must be specified when loading reports on existing elements.`);\r\n }\r\n \r\n const message = {\r\n action: 'loadTile',\r\n tileId: options.id,\r\n accessToken: null\r\n };\r\n \r\n super.load(options, requireId, message);\r\n }\r\n}\n\n\n/** WEBPACK FOOTER **\n ** ./src/tile.ts\n **/"],"sourceRoot":""} \ No newline at end of file +{"version":3,"sources":["webpack:///webpack/bootstrap 799f4067f0d6c9ffe0d6","webpack:///./src/powerbi.ts","webpack:///./src/core.ts","webpack:///./src/embed.ts","webpack:///./src/util.ts","webpack:///./src/report.ts","webpack:///./src/tile.ts"],"names":[],"mappings":";AAAA;AACA;;AAEA;AACA;;AAEA;AACA;AACA;;AAEA;AACA;AACA,uBAAe;AACf;AACA;AACA;;AAEA;AACA;;AAEA;AACA;;AAEA;AACA;AACA;;;AAGA;AACA;;AAEA;AACA;;AAEA;AACA;;AAEA;AACA;;;;;;;ACtCA,kCAAwB,CAAQ,CAAC;AASjC;;;;IAIG;AACH,OAAM,CAAC,OAAO,GAAG,cAAO,CAAC;AACzB,OAAM,CAAC,OAAO,GAAG,IAAI,cAAO,EAAE,CAAC;;;;;;;ACf/B,mCAAwD,CAAS,CAAC;AAClE,oCAAuB,CAAU,CAAC;AAClC,kCAAqB,CAAQ,CAAC;AAC9B,kCAAsB,CAAQ,CAAC;AAW/B;KAsCI,iBAAY,MAAkC;SAAlC,sBAAkC,GAAlC,WAAkC;SAC1C,IAAI,CAAC,MAAM,GAAG,EAAE,CAAC;SACjB,MAAM,CAAC,gBAAgB,CAAC,SAAS,EAAE,IAAI,CAAC,gBAAgB,CAAC,IAAI,CAAC,IAAI,CAAC,EAAE,KAAK,CAAC,CAAC;SAE5E,gD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,EAAE,OAAO,CAAC,CAAC;KAC5C,CAAC;KA3BM,WAAI,GAAG,QAAQ,CAAC;KA4B3B,aAAC;AAAD,EAAC,CA7B2B,aAAK,GA6BhC;AA7BY,eAAM,SA6BlB;;;;;;;;;;;;ACnCD,mCAAmD,CAAS,CAAC;AAM7D;KAA0B,wBAAK;KAA/B;SAA0B,8BAAK;KAsB/B,CAAC;KAnBG,0BAAW,GAAX;SACI,IAAM,QAAQ,GAAG,gBAAK,CAAC,WAAW,WAAE,CAAC;SAErC,MAAM,CAAC,QAAQ,CAAC;KACpB,CAAC;KAED,mBAAI,GAAJ,UAAK,OAAsB,EAAE,SAA0B;SAA1B,yBAA0B,GAA1B,iBAA0B;SACnD,EAAE,EAAC,SAAS,IAAI,OAAO,OAAO,CAAC,EAAE,KAAK,QAAQ,CAAC,CAAC,CAAC;aAC7C,MAAM,IAAI,KAAK,CAAC,iEAAiE,CAAC,CAAC;SACvF,CAAC;SAED,IAAM,OAAO,GAAG;aACZ,MAAM,EAAE,UAAU;aAClB,MAAM,EAAE,OAAO,CAAC,EAAE;aAClB,WAAW,EAAE,IAAI;UACpB,CAAC;SAEF,gBAAK,CAAC,IAAI,YAAC,OAAO,EAAE,SAAS,EAAE,OAAO,CAAC,CAAC;KAC5C,CAAC;KApBM,SAAI,GAAG,MAAM,CAAC;KAqBzB,WAAC;AAAD,EAAC,CAtByB,aAAK,GAsB9B;AAtBY,aAAI,OAsBhB","file":"powerbi.js","sourcesContent":[" \t// The module cache\n \tvar installedModules = {};\n\n \t// The require function\n \tfunction __webpack_require__(moduleId) {\n\n \t\t// Check if module is in cache\n \t\tif(installedModules[moduleId])\n \t\t\treturn installedModules[moduleId].exports;\n\n \t\t// Create a new module (and put it into the cache)\n \t\tvar module = installedModules[moduleId] = {\n \t\t\texports: {},\n \t\t\tid: moduleId,\n \t\t\tloaded: false\n \t\t};\n\n \t\t// Execute the module function\n \t\tmodules[moduleId].call(module.exports, module, module.exports, __webpack_require__);\n\n \t\t// Flag the module as loaded\n \t\tmodule.loaded = true;\n\n \t\t// Return the exports of the module\n \t\treturn module.exports;\n \t}\n\n\n \t// expose the modules object (__webpack_modules__)\n \t__webpack_require__.m = modules;\n\n \t// expose the module cache\n \t__webpack_require__.c = installedModules;\n\n \t// __webpack_public_path__\n \t__webpack_require__.p = \"\";\n\n \t// Load entry module and return exports\n \treturn __webpack_require__(0);\n\n\n\n/** WEBPACK FOOTER **\n ** webpack/bootstrap 799f4067f0d6c9ffe0d6\n **/","import { PowerBi } from './core';\r\n\r\ndeclare global {\r\n interface Window {\r\n Powerbi: typeof PowerBi;\r\n powerbi: PowerBi;\r\n }\r\n}\r\n\r\n/**\r\n * Make PowerBi available on global object for use in apps without module loading support.\r\n * Save class to allow creating an instance of the service.\r\n * Create instance of class with default config for normal usage.\r\n */\r\nwindow.Powerbi = PowerBi;\r\nwindow.powerbi = new PowerBi();\n\n\n/** WEBPACK FOOTER **\n ** ./src/powerbi.ts\n **/","import { Embed, IEmbedConstructor, IEmbedOptions } from './embed';\r\nimport { Report } from './report';\r\nimport { Tile } from './tile';\r\nimport { Utils } from './util';\r\n\r\nexport interface IPowerBiElement extends HTMLElement {\r\n powerBiEmbed: Embed;\r\n}\r\n\r\nexport interface IPowerBiConfiguration {\r\n autoEmbedOnContentLoaded?: boolean;\r\n onError?: (error: any) => any;\r\n}\r\n\r\nexport class PowerBi {\r\n /**\r\n * List of components this service can embed.\r\n */\r\n private static components: IEmbedConstructor[] = [\r\n Tile,\r\n Report\r\n ];\r\n /**\r\n * Mapping of event names from iframe postMessage to their name percieved by parent DOM.\r\n * Example: User clicks on embeded report which is inside iframe. The iframe code resends \r\n * event as postMessage with { event: 'reportClicked', ... } and this name is converted to hyphenated\r\n * name and dispatched from the parent element of the iframe to simulate the event bubbling through two\r\n * different windows / DOMs\r\n */\r\n private static eventMap = {\r\n 'tileClicked': 'tile-click',\r\n 'tileLoaded': 'tile-load',\r\n 'reportPageLoaded': 'report-load'\r\n };\r\n \r\n /**\r\n * Default configuration for service.\r\n */\r\n private static defaultConfig: IPowerBiConfiguration = {\r\n autoEmbedOnContentLoaded: false,\r\n onError: (...args) => console.log(args[0], args.slice(1))\r\n };\r\n\r\n /** Save access token as fallback/global token to use when local token for report/tile is not provided. */\r\n accessToken: string;\r\n \r\n /** Configuration object */\r\n private config: IPowerBiConfiguration;\r\n \r\n /** List of components (Reports/Tiles) that have been embedded using this service instance. */\r\n private embeds: Embed[];\r\n \r\n constructor(config: IPowerBiConfiguration = {}) {\r\n this.embeds = [];\r\n window.addEventListener('message', this.onReceiveMessage.bind(this), false);\r\n \r\n // TODO: Change when Object.assign is available.\r\n this.config = Utils.assign({}, PowerBi.defaultConfig, config);\r\n \r\n if (this.config.autoEmbedOnContentLoaded) {\r\n this.enableAutoEmbed();\r\n }\r\n }\r\n \r\n /**\r\n * Handler for DOMContentLoaded which searches DOM for elements having 'powerbi-embed-url' attribute\r\n * and automatically attempts to embed a powerbi component based on information from the attributes.\r\n * Only runs if `config.autoEmbedOnContentLoaded` is true when the service is created.\r\n */\r\n init(container?: HTMLElement): void {\r\n container = (container && container instanceof HTMLElement) ? container : document.body;\r\n \r\n const elements = Array.prototype.slice.call(container.querySelectorAll(`[${Embed.embedUrlAttribute}]`));\r\n elements.forEach(element => this.embed(element));\r\n }\r\n \r\n /**\r\n * Given an html element embed component based on configuration.\r\n * If component has already been created and attached to element re-use component instance and existing iframe,\r\n * otherwise create a new component instance\r\n */\r\n embed(element: HTMLElement, config: IEmbedOptions = {}): Embed {\r\n let component: Embed;\r\n let powerBiElement = element;\r\n \r\n if (powerBiElement.powerBiEmbed) {\r\n component = this.embedExisting(powerBiElement, config);\r\n }\r\n else {\r\n component = this.embedNew(powerBiElement, config);\r\n }\r\n \r\n return component;\r\n }\r\n \r\n /**\r\n * Given an html element embed component base configuration.\r\n * Save component instance on element for later lookup. \r\n */\r\n private embedNew(element: IPowerBiElement, config: IEmbedOptions): Embed {\r\n const componentType = config.type || element.getAttribute(Embed.typeAttribute);\r\n if (!componentType) {\r\n throw new Error(`Attempted to embed using config ${JSON.stringify(config)} on element ${element.outerHTML}, but could not determine what type of component to embed. You must specify a type in the configuration or as an attribute such as '${Embed.typeAttribute}=\"${Report.name.toLowerCase()}\"'.`);\r\n }\r\n \r\n // Save type on configuration so it can be referenced later at known location\r\n config.type = componentType;\r\n \r\n const Component = Utils.find(component => componentType === component.name.toLowerCase(), PowerBi.components);\r\n if (!Component) {\r\n throw new Error(`Attempted to embed component of type: ${componentType} but did not find any matching component. Please verify the type you specified is intended.`);\r\n }\r\n \r\n // TODO: Consider removing in favor of passing reference to `this` in constructor\r\n // The getGlobalAccessToken function is only here so that the components (Tile | Report) can get the global access token without needing reference\r\n // to the service that they are registered within becaues it creates circular dependencies\r\n config.getGlobalAccessToken = () => this.accessToken;\r\n \r\n const component = new Component(element, config);\r\n element.powerBiEmbed = component;\r\n this.embeds.push(component);\r\n \r\n return component;\r\n }\r\n \r\n private embedExisting(element: IPowerBiElement, config: IEmbedOptions): Embed {\r\n const component = Utils.find(x => x.element === element, this.embeds);\r\n if (!component) {\r\n throw new Error(`Attempted to embed using config ${JSON.stringify(config)} on element ${element.outerHTML} which already has embedded comopnent associated, but could not find the existing comopnent in the list of active components. This could indicate the embeds list is out of sync with the DOM, or the component is referencing the incorrect HTML element.`);\r\n }\r\n \r\n component.load(config, true);\r\n \r\n return component;\r\n }\r\n \r\n /**\r\n * Adds event handler for DOMContentLoaded which finds all elements in DOM with attribute powerbi-embed-url\r\n * then attempts to initiate the embed process based on data from other powerbi-* attributes.\r\n * (This is usually only useful for applications rendered on by the server since all the data needed will be available by the time the handler is called.)\r\n */\r\n enableAutoEmbed() {\r\n window.addEventListener('DOMContentLoaded', (event: Event) => this.init(document.body), false);\r\n }\r\n \r\n /**\r\n * Returns instance of component associated with element.\r\n */\r\n get(element: HTMLElement) {\r\n const powerBiElement = element;\r\n \r\n if (!powerBiElement.powerBiEmbed) {\r\n throw new Error(`You attempted to get an instance of powerbi component associated with element: ${element.outerHTML} but there was no associated instance.`);\r\n }\r\n \r\n return powerBiElement.powerBiEmbed;\r\n }\r\n \r\n /**\r\n * Given an html element which has component embedded within it, remove the component from list of embeds, remove association with component, and remove the iframe.\r\n */\r\n reset(element: HTMLElement) {\r\n const powerBiElement = element;\r\n \r\n if (!powerBiElement.powerBiEmbed) {\r\n return;\r\n }\r\n \r\n /** Remove component from internal list */\r\n Utils.remove(x => x === powerBiElement.powerBiEmbed, this.embeds);\r\n /** Delete property from html element */\r\n delete powerBiElement.powerBiEmbed;\r\n /** Remove iframe from element */\r\n const iframe = element.querySelector('iframe');\r\n if(iframe) {\r\n iframe.remove();\r\n }\r\n }\r\n \r\n /**\r\n * Handler for window message event.\r\n * 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\r\n * to simulate the event bubbling through the two separate windows / DOMs.\r\n * \r\n * If an error occurs when parsing event.data call error handler provided during configuration.\r\n */\r\n private onReceiveMessage(event: MessageEvent): void {\r\n if (!event) {\r\n return;\r\n }\r\n\r\n try {\r\n // Only raise the event on the embed that matches the post message origin\r\n const embed = Utils.find(embed => event.source === embed.iframe.contentWindow, this.embeds);\r\n if(embed) {\r\n let messageData = typeof event.data === 'string' ? JSON.parse(event.data) : event.data;\r\n Utils.raiseCustomEvent(embed.element, PowerBi.eventMap[messageData.event], messageData);\r\n }\r\n }\r\n catch (e) {\r\n if (typeof this.config.onError === 'function') {\r\n this.config.onError.call(window, e);\r\n }\r\n else {\r\n throw e;\r\n }\r\n }\r\n }\r\n}\r\n\r\n// export default PowerBi;\n\n\n/** WEBPACK FOOTER **\n ** ./src/core.ts\n **/","import { Utils } from './util';\r\n\r\ndeclare global {\r\n interface Document {\r\n // Mozilla Fullscreen\r\n mozCancelFullScreen: Function;\r\n \r\n // Ms Fullscreen\r\n msExitFullscreen: Function;\r\n }\r\n \r\n interface HTMLIFrameElement {\r\n // Mozilla Fullscreen\r\n mozRequestFullScreen: Function;\r\n \r\n // Ms Fullscreen\r\n msRequestFullscreen: Function;\r\n }\r\n}\r\n\r\nexport interface ILoadMessage {\r\n action: string;\r\n accessToken: string;\r\n}\r\n\r\nexport interface IEmbedOptions {\r\n type?: string;\r\n id?: string;\r\n accessToken?: string;\r\n embedUrl?: string;\r\n webUrl?: string;\r\n name?: string;\r\n filterPaneEnabled?: boolean;\r\n getGlobalAccessToken?: () => string;\r\n}\r\n\r\nexport interface IEmbedConstructor {\r\n new(...args: any[]): Embed;\r\n}\r\n\r\nexport abstract class Embed {\r\n public static embedUrlAttribute = 'powerbi-embed-url';\r\n public static accessTokenAttribute = 'powerbi-access-token';\r\n public static typeAttribute = 'powerbi-type';\r\n \r\n /**\r\n * Attribute used to specify type of visual.\r\n * Example: `
`\r\n */\r\n public static name: string;\r\n /**\r\n * Default options for embeddable component.\r\n */\r\n private static defaultOptions: IEmbedOptions = {\r\n filterPaneEnabled: true\r\n };\r\n \r\n element: HTMLElement;\r\n iframe: HTMLIFrameElement;\r\n options: IEmbedOptions;\r\n \r\n constructor(element: HTMLElement, options: IEmbedOptions) {\r\n this.element = element;\r\n \r\n // TODO: Change when Object.assign is available.\r\n this.options = Utils.assign({}, Embed.defaultOptions, options);\r\n this.options.accessToken = this.getAccessToken();\r\n this.options.embedUrl = this.getEmbedUrl();\r\n \r\n const iframeHtml = ``;\r\n \r\n this.element.innerHTML = iframeHtml;\r\n this.iframe = this.element.childNodes[0];\r\n this.iframe.addEventListener('load', () => this.load(this.options, false), false);\r\n }\r\n \r\n /**\r\n * Handler for when the iframe has finished loading the powerbi placeholder page.\r\n * This is used to inject configuration options such as access token, loadAction, etc\r\n * which allow iframe to load the actual report with authentication.\r\n */\r\n load(options: IEmbedOptions, requireId: boolean = false, message: ILoadMessage = null) {\r\n if(!message) {\r\n throw new Error(`You called load without providing message properties from the concrete embeddable class.`);\r\n }\r\n \r\n const baseMessage = {\r\n accessToken: options.accessToken\r\n };\r\n \r\n Utils.assign(message, baseMessage);\r\n \r\n const event = {\r\n message\r\n };\r\n \r\n Utils.raiseCustomEvent(this.element, event.message.action, event);\r\n this.iframe.contentWindow.postMessage(JSON.stringify(event.message), '*');\r\n }\r\n \r\n /**\r\n * Get access token from first available location: options, attribute, global.\r\n */\r\n private getAccessToken(): string {\r\n const accessToken = this.options.accessToken || this.element.getAttribute(Embed.accessTokenAttribute) || this.options.getGlobalAccessToken();\r\n \r\n if (!accessToken) {\r\n throw new Error(`No access token was found for element. You must specify an access token directly on the element using attribute '${Embed.accessTokenAttribute}' or specify a global token at: powerbi.accessToken.`);\r\n }\r\n \r\n return accessToken;\r\n }\r\n \r\n /**\r\n * Get embed url from first available location: options, attribute.\r\n */\r\n protected getEmbedUrl(): string {\r\n const embedUrl = this.options.embedUrl || this.element.getAttribute(Embed.embedUrlAttribute);\r\n \r\n if(typeof embedUrl !== 'string' || embedUrl.length === 0) {\r\n throw new Error(`Embed Url is required, but it was not found. You must provide an embed url either as part of embed configuration or as attribute '${Embed.embedUrlAttribute}'.`);\r\n }\r\n \r\n return embedUrl; \r\n }\r\n\r\n /**\r\n * Request the browser to make the components iframe fullscreen.\r\n */\r\n fullscreen(): void {\r\n const requestFullScreen = this.iframe.requestFullscreen || this.iframe.msRequestFullscreen || this.iframe.mozRequestFullScreen || this.iframe.webkitRequestFullscreen;\r\n requestFullScreen.call(this.iframe);\r\n }\r\n \r\n /**\r\n * Exit fullscreen.\r\n */\r\n exitFullscreen(): void {\r\n if (!this.isFullscreen(this.iframe)) {\r\n return;\r\n }\r\n\r\n const exitFullscreen = document.exitFullscreen || document.mozCancelFullScreen || document.webkitExitFullscreen || document.msExitFullscreen;\r\n exitFullscreen.call(document);\r\n }\r\n \r\n /**\r\n * Return true if iframe is fullscreen,\r\n * otherwise return false \r\n */\r\n private isFullscreen(iframe: HTMLIFrameElement): boolean {\r\n const options = ['fullscreenElement', 'webkitFullscreenElement', 'mozFullscreenScreenElement', 'msFullscreenElement'];\r\n \r\n return options.some(option => document[option] === iframe);\r\n }\r\n}\n\n\n/** WEBPACK FOOTER **\n ** ./src/embed.ts\n **/","export class Utils {\r\n static raiseCustomEvent(element: HTMLElement, eventName: string, eventData: any) {\r\n let customEvent;\r\n if (typeof CustomEvent === 'function') {\r\n customEvent = new CustomEvent(eventName, {\r\n detail: eventData,\r\n bubbles: true,\r\n cancelable: true\r\n });\r\n } else {\r\n customEvent = document.createEvent('CustomEvent');\r\n customEvent.initCustomEvent(eventName, true, true, eventData);\r\n }\r\n\r\n element.dispatchEvent(customEvent);\r\n if (customEvent.defaultPrevented || !customEvent.returnValue) {\r\n return;\r\n }\r\n\r\n // TODO: Remove this? Should be better way to handle events than using eval?\r\n // What is use case?
\r\n const inlineEventAttr = 'on' + eventName.replace('-', '');\r\n const inlineScript = element.getAttribute(inlineEventAttr);\r\n if (inlineScript) {\r\n eval.call(element, inlineScript);\r\n }\r\n }\r\n \r\n static findIndex(predicate: (T) => boolean, xs: T[]): number {\r\n if(!Array.isArray(xs)) {\r\n throw new Error(`You attempted to call find with second parameter that was not an array. You passed: ${xs}`);\r\n }\r\n \r\n let index;\r\n xs.some((x, i) => {\r\n if(predicate(x)) {\r\n index = i;\r\n return true;\r\n }\r\n });\r\n \r\n return index;\r\n }\r\n \r\n static find(predicate: (T) => boolean, xs: T[]): T {\r\n const index = Utils.findIndex(predicate, xs);\r\n return xs[index];\r\n }\r\n \r\n static remove(predicate: (T) => boolean, xs: T[]): void {\r\n const index = Utils.findIndex(predicate, xs);\r\n xs.splice(index, 1);\r\n }\r\n \r\n // See: https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Object/assign\r\n // TODO: replace in favor of using polyfill\r\n static assign = function (...args) {\r\n var target = args[0];\r\n \r\n 'use strict';\r\n if (target === undefined || target === null) {\r\n throw new TypeError('Cannot convert undefined or null to object');\r\n }\r\n\r\n var output = Object(target);\r\n for (var index = 1; index < arguments.length; index++) {\r\n var source = arguments[index];\r\n if (source !== undefined && source !== null) {\r\n for (var nextKey in source) {\r\n if (source.hasOwnProperty(nextKey)) {\r\n output[nextKey] = source[nextKey];\r\n }\r\n }\r\n }\r\n }\r\n return output;\r\n };\r\n}\n\n\n/** WEBPACK FOOTER **\n ** ./src/util.ts\n **/","import { Embed, IEmbedOptions, ILoadMessage } from './embed';\r\n\r\nexport interface IReportLoadMessage extends ILoadMessage {\r\n reportId: string\r\n}\r\n\r\nexport class Report extends Embed {\r\n static name = \"Report\";\r\n \r\n getEmbedUrl(): string {\r\n let embedUrl = super.getEmbedUrl();\r\n \r\n // TODO: Need safe way to add url parameters.\r\n // We are assuming embedUrls use query parameters to supply id of visual\r\n // so must prefix with '&'.\r\n if(!this.options.filterPaneEnabled) {\r\n embedUrl += `&filterPaneEnabled=false`;\r\n }\r\n\r\n return embedUrl;\r\n }\r\n\r\n load(options: IEmbedOptions, requireId: boolean = false) {\r\n if(requireId && typeof options.id !== 'string') {\r\n throw new Error(`id must be specified when loading reports on existing elements.`);\r\n }\r\n \r\n const message: IReportLoadMessage = {\r\n action: 'loadReport',\r\n reportId: options.id,\r\n accessToken: null\r\n };\r\n \r\n super.load(options, requireId, message);\r\n }\r\n}\n\n\n/** WEBPACK FOOTER **\n ** ./src/report.ts\n **/","import { Embed, IEmbedOptions, ILoadMessage } from './embed';\r\n\r\nexport interface ITileLoadMessage extends ILoadMessage {\r\n tileId: string\r\n}\r\n\r\nexport class Tile extends Embed {\r\n static name = \"Tile\";\r\n \r\n getEmbedUrl(): string {\r\n const embedUrl = super.getEmbedUrl();\r\n\r\n return embedUrl;\r\n }\r\n \r\n load(options: IEmbedOptions, requireId: boolean = false) {\r\n if(requireId && typeof options.id !== 'string') {\r\n throw new Error(`id must be specified when loading reports on existing elements.`);\r\n }\r\n \r\n const message = {\r\n action: 'loadTile',\r\n tileId: options.id,\r\n accessToken: null\r\n };\r\n \r\n super.load(options, requireId, message);\r\n }\r\n}\n\n\n/** WEBPACK FOOTER **\n ** ./src/tile.ts\n **/"],"sourceRoot":""} \ No newline at end of file diff --git a/dist/powerbi.min.js b/dist/powerbi.min.js index f72fc292..30926747 100644 --- a/dist/powerbi.min.js +++ b/dist/powerbi.min.js @@ -1,2 +1,2 @@ -!function(e){function t(o){if(n[o])return n[o].exports;var r=n[o]={exports:{},id:o,loaded:!1};return e[o].call(r.exports,r,r.exports,t),r.loaded=!0,r.exports}var n={};return t.m=e,t.c=n,t.p="",t(0)}([function(e,t,n){var o=n(1);window.Powerbi=o["default"],window.powerbi=new o["default"]},function(e,t,n){var o=n(2),r=n(4),i=n(5),s=n(3),a=function(){function e(t){void 0===t&&(t={}),this.embeds=[],window.addEventListener("message",this.onReceiveMessage.bind(this),!1),this.config=s["default"].assign({},e.defaultConfig,t),this.config.autoEmbedOnContentLoaded&&this.enableAutoEmbed()}return e.prototype.init=function(e){var t=this;e=e&&e instanceof HTMLElement?e:document.body;var n=Array.prototype.slice.call(e.querySelectorAll("["+o["default"].embedUrlAttribute+"]"));n.forEach(function(e){return t.embed(e)})},e.prototype.embed=function(e,t){void 0===t&&(t={});var n,o=e;return n=o.powerBiEmbed?this.embedExisting(o,t):this.embedNew(o,t)},e.prototype.embedNew=function(t,n){var i=this,a=n.type||t.getAttribute(o["default"].typeAttribute);if(!a)throw new Error("Attempted to embed using config "+JSON.stringify(n)+" on element "+t.outerHTML+", but could not determine what type of component to embed. You must specify a type in the configuration or as an attribute such as '"+o["default"].typeAttribute+'="'+r["default"].name.toLowerCase()+"\"'.");n.type=a;var u=s["default"].find(function(e){return a===e.name.toLowerCase()},e.components);if(!u)throw new Error("Attempted to embed component of type: "+a+" but did not find any matching component. Please verify the type you specified is intended.");n.getGlobalAccessToken=function(){return i.accessToken};var l=new u(t,n);return t.powerBiEmbed=l,this.embeds.push(l),l},e.prototype.embedExisting=function(e,t){var n=s["default"].find(function(t){return t.element===e},this.embeds);if(!n)throw new Error("Attempted to embed using config "+JSON.stringify(t)+" on element "+e.outerHTML+" which already has embedded comopnent associated, but could not find the existing comopnent in the list of active components. This could indicate the embeds list is out of sync with the DOM, or the component is referencing the incorrect HTML element.");return n.load(t,!0),n},e.prototype.enableAutoEmbed=function(){var e=this;window.addEventListener("DOMContentLoaded",function(t){return e.init(document.body)},!1)},e.prototype.get=function(e){var t=e;if(!t.powerBiEmbed)throw new Error("You attempted to get an instance of powerbi component associated with element: "+e.outerHTML+" but there was no associated instance.");return t.powerBiEmbed},e.prototype.reset=function(e){var t=e;if(t.powerBiEmbed){s["default"].remove(function(e){return e===t.powerBiEmbed},this.embeds),delete t.powerBiEmbed;var n=e.querySelector("iframe");n&&n.remove()}},e.prototype.onReceiveMessage=function(t){if(t)try{var n=s["default"].find(function(e){return t.source===e.iframe.contentWindow},this.embeds);if(n){var o="string"==typeof t.data?JSON.parse(t.data):t.data;s["default"].raiseCustomEvent(n.element,e.eventMap[o.event],o)}}catch(r){if("function"!=typeof this.config.onError)throw r;this.config.onError.call(window,r)}},e.components=[i["default"],r["default"]],e.eventMap={tileClicked:"tile-click",tileLoaded:"tile-load",reportPageLoaded:"report-load"},e.defaultConfig={autoEmbedOnContentLoaded:!1,onError:function(){for(var e=[],t=0;t';this.element.innerHTML=i,this.iframe=this.element.childNodes[0],this.iframe.addEventListener("load",function(){return r.load(r.options,!1)},!1)}return e.prototype.load=function(e,t,n){if(void 0===t&&(t=!1),void 0===n&&(n=null),!n)throw new Error("You called load without providing message properties from the concrete embeddable class.");var r={accessToken:e.accessToken};o["default"].assign(n,r);var i={message:n};o["default"].raiseCustomEvent(this.element,i.message.action,i),this.iframe.contentWindow.postMessage(JSON.stringify(i.message),"*")},e.prototype.getAccessToken=function(){var t=this.options.accessToken||this.element.getAttribute(e.accessTokenAttribute)||this.options.getGlobalAccessToken();if(!t)throw new Error("No access token was found for element. You must specify an access token directly on the element using attribute '"+e.accessTokenAttribute+"' or specify a global token at: powerbi.accessToken.");return t},e.prototype.getEmbedUrl=function(){var t=this.options.embedUrl||this.element.getAttribute(e.embedUrlAttribute);if("string"!=typeof t||0===t.length)throw new Error("Embed Url is required, but it was not found. You must provide an embed url either as part of embed configuration or as attribute '"+e.embedUrlAttribute+"'.");return t},e.prototype.fullscreen=function(){var e=this.iframe.requestFullscreen||this.iframe.msRequestFullscreen||this.iframe.mozRequestFullScreen||this.iframe.webkitRequestFullscreen;e.call(this.iframe)},e.prototype.exitFullscreen=function(){if(this.isFullscreen(this.iframe)){var e=document.exitFullscreen||document.mozCancelFullScreen||document.webkitExitFullscreen||document.msExitFullscreen;e.call(document)}},e.prototype.isFullscreen=function(e){var t=["fullscreenElement","webkitFullscreenElement","mozFullscreenScreenElement","msFullscreenElement"];return t.some(function(t){return document[t]===e})},e.embedUrlAttribute="powerbi-embed-url",e.accessTokenAttribute="powerbi-access-token",e.typeAttribute="powerbi-type",e.defaultOptions={filterPaneEnabled:!0},e}();Object.defineProperty(t,"__esModule",{value:!0}),t["default"]=r},function(e,t){var n=function(){function e(){}return e.raiseCustomEvent=function(e,t,n){var o;if("function"==typeof CustomEvent?o=new CustomEvent(t,{detail:n,bubbles:!0,cancelable:!0}):(o=document.createEvent("CustomEvent"),o.initCustomEvent(t,!0,!0,n)),e.dispatchEvent(o),!o.defaultPrevented&&o.returnValue){var r="on"+t.replace("-",""),i=e.getAttribute(r);i&&eval.call(e,i)}},e.findIndex=function(e,t){if(!Array.isArray(t))throw new Error("You attempted to call find with second parameter that was not an array. You passed: "+t);var n;return t.some(function(t,o){return e(t)?(n=o,!0):void 0}),n},e.find=function(t,n){var o=e.findIndex(t,n);return n[o]},e.remove=function(t,n){var o=e.findIndex(t,n);n.splice(o,1)},e.assign=function(){for(var e=[],t=0;t';this.element.innerHTML=i,this.iframe=this.element.childNodes[0],this.iframe.addEventListener("load",function(){return r.load(r.options,!1)},!1)}return e.prototype.load=function(e,t,n){if(void 0===t&&(t=!1),void 0===n&&(n=null),!n)throw new Error("You called load without providing message properties from the concrete embeddable class.");var r={accessToken:e.accessToken};o.Utils.assign(n,r);var i={message:n};o.Utils.raiseCustomEvent(this.element,i.message.action,i),this.iframe.contentWindow.postMessage(JSON.stringify(i.message),"*")},e.prototype.getAccessToken=function(){var t=this.options.accessToken||this.element.getAttribute(e.accessTokenAttribute)||this.options.getGlobalAccessToken();if(!t)throw new Error("No access token was found for element. You must specify an access token directly on the element using attribute '"+e.accessTokenAttribute+"' or specify a global token at: powerbi.accessToken.");return t},e.prototype.getEmbedUrl=function(){var t=this.options.embedUrl||this.element.getAttribute(e.embedUrlAttribute);if("string"!=typeof t||0===t.length)throw new Error("Embed Url is required, but it was not found. You must provide an embed url either as part of embed configuration or as attribute '"+e.embedUrlAttribute+"'.");return t},e.prototype.fullscreen=function(){var e=this.iframe.requestFullscreen||this.iframe.msRequestFullscreen||this.iframe.mozRequestFullScreen||this.iframe.webkitRequestFullscreen;e.call(this.iframe)},e.prototype.exitFullscreen=function(){if(this.isFullscreen(this.iframe)){var e=document.exitFullscreen||document.mozCancelFullScreen||document.webkitExitFullscreen||document.msExitFullscreen;e.call(document)}},e.prototype.isFullscreen=function(e){var t=["fullscreenElement","webkitFullscreenElement","mozFullscreenScreenElement","msFullscreenElement"];return t.some(function(t){return document[t]===e})},e.embedUrlAttribute="powerbi-embed-url",e.accessTokenAttribute="powerbi-access-token",e.typeAttribute="powerbi-type",e.defaultOptions={filterPaneEnabled:!0},e}();t.Embed=r},function(e,t){var n=function(){function e(){}return e.raiseCustomEvent=function(e,t,n){var o;if("function"==typeof CustomEvent?o=new CustomEvent(t,{detail:n,bubbles:!0,cancelable:!0}):(o=document.createEvent("CustomEvent"),o.initCustomEvent(t,!0,!0,n)),e.dispatchEvent(o),!o.defaultPrevented&&o.returnValue){var r="on"+t.replace("-",""),i=e.getAttribute(r);i&&eval.call(e,i)}},e.findIndex=function(e,t){if(!Array.isArray(t))throw new Error("You attempted to call find with second parameter that was not an array. You passed: "+t);var n;return t.some(function(t,o){return e(t)?(n=o,!0):void 0}),n},e.find=function(t,n){var o=e.findIndex(t,n);return n[o]},e.remove=function(t,n){var o=e.findIndex(t,n);n.splice(o,1)},e.assign=function(){for(var e=[],t=0;t document[option] === iframe); } -} - -export default Embed; \ No newline at end of file +} \ No newline at end of file diff --git a/src/powerbi.d.ts b/src/powerbi.d.ts deleted file mode 100644 index 522b263d..00000000 --- a/src/powerbi.d.ts +++ /dev/null @@ -1,134 +0,0 @@ - -export interface IPowerBiElement extends HTMLElement { - powerBiEmbed: Embed; -} -export interface IPowerBiConfiguration { - autoEmbedOnContentLoaded?: boolean; - onError?: (error: any) => any; -} - -declare global { - interface Window { - Powerbi: typeof PowerBi; - powerbi: PowerBi; - } -} - -export class PowerBi { - /** - * List of components this service can embed. - */ - private static components; - /** - * Mapping of event names from iframe postMessage to their name percieved by parent DOM. - * Example: User clicks on embeded report which is inside iframe. The iframe code resends - * event as postMessage with { event: 'reportClicked', ... } and this name is converted to hyphenated - * name and dispatched from the parent element of the iframe to simulate the event bubbling through two - * different windows / DOMs - */ - private static eventMap; - /** - * Default configuration for service. - */ - private static defaultConfig; - /** Save access token as fallback/global token to use when local token for report/tile is not provided. */ - accessToken: string; - /** Configuration object */ - private config; - /** List of components (Reports/Tiles) that have been embedded using this service instance. */ - private embeds; - constructor(config?: IPowerBiConfiguration); - /** - * Handler for DOMContentLoaded which searches DOM for elements having 'powerbi-embed' attribute - * and automatically attempts to embed a powerbi component based on information from the attributes. - * Only runs if `config.autoEmbedOnContentLoaded` is true when the service is created. - */ - init(container: HTMLElement): void; - /** - * Given an html element embed component based on configuration. - * If component has already been created and attached to eleemnt simply return it to prevent creating duplicate components for same element. - */ - embed(element: HTMLElement, config?: IEmbedOptions): Embed; - /** - * Adds event handler for DOMContentLoaded which finds all elements in DOM with attribute powerbi-embed-url - * then attempts to initiate the embed process based on data from other powerbi-* attributes. - * (This is usually only useful for applications rendered on by the server since all the data needed will be available by the time the handler is called.) - */ - enableAutoEmbed(): void; - /** - * Remove component from the list of embedded components. - */ - reset(element: HTMLElement): void; - /** - * Handler for window message event. - * 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 - * to simulate the event bubbling through the two separate windows / DOMs. - * - * If an error occurs when parsing event.data call error handler provided during configuration. - */ - private onReceiveMessage(event: MessageEvent): void; -} - -export interface IEmbedOptions { - type?: string; - id?: string; - accessToken?: string; - embedUrl?: string; - webUrl?: string; - name?: string; - filter?: any; - filterPaneEnabled?: boolean; - getGlobalAccessToken?: () => string; -} - -declare abstract class Embed { - public static embedUrlAttribute: string; - public static accessTokenAttribute: string; - public static typeAttribute: string; - /** - * Default options for embeddable component. - */ - private static defaultOptions; - element: HTMLElement; - iframe: HTMLIFrameElement; - options: IEmbedOptions; - constructor(element: HTMLElement, options: IEmbedOptions); - /** - * Handler for when the iframe has finished loading the powerbi placeholder page. - * This is used to inject configuration options such as access token, action, etc - * which allow iframe to load the actual report with authentication. - */ - load(options: IEmbedOptions, requireId: boolean, message: IEmbedOptions); - /** - * Get access token from first available location: options, attribute, global. - */ - private getAccessToken(); - /** - * Get embed url from first available location: options, attribute. - */ - protected getEmbedUrl(): string; - /** - * Request the browser to make the components iframe fullscreen. - */ - fullscreen(): void; - /** - * Exit fullscreen. - */ - exitFullscreen(): void; - /** - * Return true if iframe is fullscreen, - * otherwise return false - */ - private isFullscreen(iframe); -} - -export class Report extends Embed { - constructor(element: HTMLElement, options: IEmbedOptions); - getEmbedUrl(): string; -} - -export class Tile extends Embed { - constructor(element: HTMLElement, options: IEmbedOptions); - getEmbedUrl(): string; -} - diff --git a/src/powerbi.ts b/src/powerbi.ts index 8fd06de1..d93feebf 100644 --- a/src/powerbi.ts +++ b/src/powerbi.ts @@ -1,9 +1,16 @@ -import PowerBi from './core'; +import { PowerBi } from './core'; + +declare global { + interface Window { + Powerbi: typeof PowerBi; + powerbi: PowerBi; + } +} /** * Make PowerBi available on global object for use in apps without module loading support. * Save class to allow creating an instance of the service. * Create instance of class with default config for normal usage. */ -(window).Powerbi = PowerBi; -(window).powerbi = new PowerBi(); \ No newline at end of file +window.Powerbi = PowerBi; +window.powerbi = new PowerBi(); \ No newline at end of file diff --git a/src/report.ts b/src/report.ts index 2f99adc1..45ad6b12 100644 --- a/src/report.ts +++ b/src/report.ts @@ -1,10 +1,10 @@ -import { default as Embed, IEmbedOptions, ILoadMessage } from './embed'; +import { Embed, IEmbedOptions, ILoadMessage } from './embed'; export interface IReportLoadMessage extends ILoadMessage { reportId: string } -export default class Report extends Embed { +export class Report extends Embed { static name = "Report"; getEmbedUrl(): string { diff --git a/src/tile.ts b/src/tile.ts index 2aed00dd..5da6f835 100644 --- a/src/tile.ts +++ b/src/tile.ts @@ -1,10 +1,10 @@ -import { default as Embed, IEmbedOptions, ILoadMessage } from './embed'; +import { Embed, IEmbedOptions, ILoadMessage } from './embed'; export interface ITileLoadMessage extends ILoadMessage { tileId: string } -export default class Tile extends Embed { +export class Tile extends Embed { static name = "Tile"; getEmbedUrl(): string { diff --git a/src/util.ts b/src/util.ts index 5ed0af78..334e8337 100644 --- a/src/util.ts +++ b/src/util.ts @@ -1,4 +1,4 @@ -export default class Utils { +export class Utils { static raiseCustomEvent(element: HTMLElement, eventName: string, eventData: any) { let customEvent; if (typeof CustomEvent === 'function') { diff --git a/test/embed.spec.ts b/test/embed.spec.ts index 619a7828..ab9f8865 100644 --- a/test/embed.spec.ts +++ b/test/embed.spec.ts @@ -1,4 +1,4 @@ -import PowerBi from '../src/core'; +import { PowerBi } from '../src/core'; declare var powerbi: PowerBi; From 3bc1ac4bd4a982bdd8f4bd1e0082a777d6a8501b Mon Sep 17 00:00:00 2001 From: Matt Mazzola Date: Thu, 26 May 2016 14:00:26 -0700 Subject: [PATCH 2/2] Clean up gulp file --- gulpfile.js | 50 +++++++++++++++----------------------------------- 1 file changed, 15 insertions(+), 35 deletions(-) diff --git a/gulpfile.js b/gulpfile.js index 3a2a0eb1..8a9f829d 100644 --- a/gulpfile.js +++ b/gulpfile.js @@ -28,6 +28,7 @@ gulp.task('lint', 'Lints all files', function (done) { done ); }); + gulp.task('test', 'Runs all tests', function (done) { runSequence( 'clean', @@ -36,11 +37,12 @@ gulp.task('test', 'Runs all tests', function (done) { done ); }); + gulp.task('build', 'Runs a full build', function (done) { runSequence( 'lint', 'clean', - ['compile:ts', 'dts'], + ['compile:ts', 'compile:dts'], 'min:js', done ); @@ -50,24 +52,6 @@ gulp.task('clean', 'Cleans destination folder', function(done) { rimraf(paths.jsDest, done); }); -gulp.task('dts', 'Generate single dts file from modules', function (done) { - var tsResult = gulp.src(['./src/**/*.ts']) - .pipe(ts({ - outDir: 'dts', - declaration: true - })); - - return tsResult.dts - .pipe(replace(/import[^;]+;/, '')) - .pipe(concat('powerbi.d.ts')) - .pipe(gulp.dest('dist/')); -}); - -gulp.task('copy', 'Copy .d.ts from src to dist', function() { - return gulp.src('./src/**/*.d.ts') - .pipe(gulp.dest('dist/')); -}); - gulp.task('lint:ts', 'Lints all TypeScript', function() { return gulp.src(['./src/**/*.ts', './test/**/*.ts']) .pipe(tslint()) @@ -92,26 +76,22 @@ gulp.task('test:js', 'Runs unit tests', function(done) { }); gulp.task('compile:ts', 'Compile typescript for powerbi library', function() { - var webpackBundle = gulp.src(['./src/powerbi.ts']) + return gulp.src(['./src/powerbi.ts']) .pipe(webpack(webpackConfig)) .pipe(gulp.dest('dist/')); +}); - // TODO: No easy way to generate single declaration (.d.ts) files from multiple es6 modules - // Current process is to produce individual .d.ts files with tsc -d and then manually concatenate - // and remove invalid import statements - // See: https://github.com/Microsoft/TypeScript/issues/2568 - - // var tsResult = gulp.src(['./src/**/*.ts']) - // .pipe(ts({ - // declaration: true - // })); - - // return merge([ - // webpackBundle, - // tsResult.dts.pipe(gulp.dest('dist/')) - // ]); +gulp.task('compile:dts', 'Generate single dts file from modules', function (done) { + var tsResult = gulp.src(['./src/**/*.ts']) + .pipe(ts({ + outDir: 'dts', + declaration: true + })); - return webpackBundle; + return tsResult.dts + .pipe(replace(/import[^;]+;/, '')) + .pipe(concat('powerbi.d.ts')) + .pipe(gulp.dest('dist/')); }); gulp.task('compile:spec', 'Compile typescript for tests', function () {