diff --git a/package-lock.json b/package-lock.json index 0d4301f..c915d4c 100644 --- a/package-lock.json +++ b/package-lock.json @@ -1,6 +1,6 @@ { "name": "@microsoft/office-js-helpers", - "version": "1.0.1", + "version": "2.0.0", "lockfileVersion": 1, "requires": true, "dependencies": { diff --git a/package.json b/package.json index f8b6cc7..63e6efe 100644 --- a/package.json +++ b/package.json @@ -1,7 +1,7 @@ { "name": "@microsoft/office-js-helpers", "description": "A collection of helpers to simplify development of Office Add-ins & Microsoft Teams Tabs", - "version": "1.0.2", + "version": "2.0.0", "repository": { "type": "git", "url": "git+https://github.com/OfficeDev/office-js-helpers.git" diff --git a/src/helpers/dialog.ts b/src/helpers/dialog.ts index 9ffa5c5..242f5f7 100644 --- a/src/helpers/dialog.ts +++ b/src/helpers/dialog.ts @@ -74,6 +74,9 @@ export class Dialog { else if (Utilities.isAddin) { this._result = this._addinDialog(); } + else if (Utilities.isEdge) { + this._result = this._edgeDialog(); + } else { this._result = this._webDialog(); } @@ -124,7 +127,7 @@ export class Dialog { try { const options = 'width=' + this.size.width + ',height=' + this.size.height + this._windowFeatures; window.open(this.url, this.url, options); - if (Utilities.isIEOrEdge) { + if (Utilities.isIE) { this._pollLocalStorageForToken(resolve, reject); } else { @@ -143,6 +146,30 @@ export class Dialog { }); } + private _edgeDialog(): Promise { + return new Promise((resolve, reject) => { + Office.context.ui.displayDialogAsync(this.url, { width: this.size.width$, height: this.size.height$ }, (result: Office.AsyncResult) => { + if (result.status === Office.AsyncResultStatus.Failed) { + reject(new DialogError(result.error.message, result.error)); + } + else { + const dialog = result.value as Office.DialogHandler; + + dialog.addEventHandler(Office.EventType.DialogMessageReceived, args => { + let result = this._safeParse(args.message) as T; + resolve(result); + dialog.close(); + }); + + dialog.addEventHandler(Office.EventType.DialogEventReceived, args => { + reject(new DialogError(args.message, args.error)); + dialog.close(); + }); + } + }); + }); + } + private _pollLocalStorageForToken(resolve: (value: T) => void, reject: (reason: DialogError) => void) { localStorage.removeItem(Dialog.key); const POLL_INTERVAL = 400; @@ -185,11 +212,11 @@ export class Dialog { microsoftTeams.initialize(); microsoftTeams.authentication.notifySuccess(JSON.stringify({ parse, value })); } - else if (Utilities.isAddin) { + else if (Utilities.isAddin || Utilities.isEdge) { Office.context.ui.messageParent(JSON.stringify({ parse, value })); } else { - if (Utilities.isIEOrEdge) { + if (Utilities.isIE) { localStorage.setItem(Dialog.key, JSON.stringify({ parse, value })); } else if (window.opener) { diff --git a/src/helpers/utilities.ts b/src/helpers/utilities.ts index eca8f7a..95158c2 100644 --- a/src/helpers/utilities.ts +++ b/src/helpers/utilities.ts @@ -181,14 +181,28 @@ export class Utilities { * Utility to check if the code is running inside of an add-in. */ static get isAddin() { - return Utilities.host !== HostType.WEB; + return Utilities.host !== HostType.WEB && !Utilities.isEdge; + } + + /** + * Utility to check if the browser is IE11. + */ + static get isIE() { + return /Trident\//gi.test(window.navigator.userAgent); + } + + /** + * Utility to check if the browser is Edge. + */ + static get isEdge() { + return /Edge\//gi.test(window.navigator.userAgent); } /** * Utility to check if the browser is IE11 or Edge. */ static get isIEOrEdge() { - return /Edge\/|Trident\//gi.test(window.navigator.userAgent); + return Utilities.isIE || Utilities.isEdge; } /**