From d6eb684fc2ac9741399e5dc875a0e3e074250794 Mon Sep 17 00:00:00 2001 From: mscharlock Date: Fri, 21 Sep 2018 13:50:08 -0700 Subject: [PATCH 1/3] putting runtime back in --- types/office-runtime/index.d.ts | 125 +++++++++++++++++++ types/office-runtime/office-runtime-tests.ts | 61 +++++++++ types/office-runtime/tsconfig.json | 25 ++++ types/office-runtime/tslint.json | 3 + 4 files changed, 214 insertions(+) create mode 100644 types/office-runtime/index.d.ts create mode 100644 types/office-runtime/office-runtime-tests.ts create mode 100644 types/office-runtime/tsconfig.json create mode 100644 types/office-runtime/tslint.json diff --git a/types/office-runtime/index.d.ts b/types/office-runtime/index.d.ts new file mode 100644 index 0000000000..174229a04a --- /dev/null +++ b/types/office-runtime/index.d.ts @@ -0,0 +1,125 @@ +// Type definitions for office-runtime 1.0 +// Project: http://dev.office.com/ +// Definitions by: Michael Zlatskovsky , Michelle Scharlock +// Definitions: https://github.com/DefinitelyTyped/DefinitelyTyped +// Typescript Version: 2.4 + +/* +office-runtime +Copyright (c) Microsoft Corporation +*/ + +/** Office Runtime namespace */ +declare namespace OfficeRuntime { + /** + * Enables you to pop up a web dialog box. + * @param url + * @param options + */ + function displayWebDialog(url: string, options: DisplayWebDialogOptions): Promise; + /** + * Asynchronous, global, and persistent key-value storage that can be used by Excel Custom Functions. + */ + const AsyncStorage: AsyncStorage; + /** + * Asynchronous, global, and persistent key-value storage that can be used by Excel Custom Functions. + * @beta + * + * @remarks + * Each add-in instance has its own storage partition, unique to a user and their device. + * + * The default amount of total storage allowed per add-in is 5MB. + * + * Each method listed below returns a Promise object. + * + */ + interface AsyncStorage { + /** + * @beta + * Retrieves an object based on a key and invokes a callback when finished. Returns a Promise. + */ + getItem(key: string, callback?: (error?: Error, result?: string) => void): Promise; + /** + * @beta + * Assigns the value for a key-value pair and invokes a callback when finished. Returns a Promise. + */ + setItem(key: string, value: string, callback?: (error?: Error) => void): Promise; + /** + * @beta + * Removes an item for specified key and invokes a callback when finished. Returns a Promise. + */ + removeItem(key: string, callback?: (error?: Error) => void): Promise; + /** + * @beta + * Erases all AsyncStorage. Returns a Promise. + */ + clear(callback?: (error?: Error) => void): Promise; + /** + * @beta + * Returns a Promise with all keys. + */ + getAllKeys(callback?: (error?: Error, keys?: string[]) => void): Promise; + /** + * @beta + * Stores multiple key-value pairs in one batch. Returns a Promise. When a key doesn't exist, returns null. + */ + multiSet(keyValuePairs: string[][], callback?: (errors?: Error[]) => void): Promise; + /** + * @beta + * Deletes a batch of keys, specified in the `keys` array. + */ + multiRemove(keys: string[], callback?: (errors?: Error[]) => void): Promise; + /** + * @beta + * Fetches a batch of keys, specified in the `keys` array. When a key doesn't exist, returns null. + */ + multiGet(keys: string[], callback?: (errors?: Error[], result?: string[][]) => void): Promise; + } + /* + * @beta + * Object representing the dialog box. + */ + interface Dialog { + /** + * @beta + * Method that closes a dialog box. + */ + close(): Promise; + } + + /** + * Provides options for how a dialog is displayed. + */ + interface DisplayWebDialogOptions { + /** + * @beta + * Determines whether the dialog box displays as a popup (false) or within an IFrame (true). This setting is only applicable to custom functions running on Excel Online. + */ + displayInIFrame?: boolean; + /** + * @beta + * Defines the height of the dialog box as a percentage of the current display. + */ + height?: string; + /** + * @beta + * Defines the width of the dialog box as a percentage of the current display. + */ + width?: string; + /** + * @beta + * True if title is hidden from the dialog box. + */ + hideTitle?: boolean; + /* + * @beta + * Callback that is run when the dialog box is closed. + */ + onClose?: () => void; + /* + * @beta + * Callback that is run when the dialog box sends an error. + */ + onMessage?(message: string, dialog?: Dialog): void; + } +} \ No newline at end of file diff --git a/types/office-runtime/office-runtime-tests.ts b/types/office-runtime/office-runtime-tests.ts new file mode 100644 index 0000000000..f36d50f9af --- /dev/null +++ b/types/office-runtime/office-runtime-tests.ts @@ -0,0 +1,61 @@ +/* +office-runtime +Copyright (c) Microsoft Corporation +*/ + +OfficeRuntime.AsyncStorage.getItem("foo", () => { + // perform an action + }); + OfficeRuntime.AsyncStorage.getItem("foo").then(value => console.log(value)); + + OfficeRuntime.AsyncStorage.setItem("foo", "bar"); + OfficeRuntime.AsyncStorage.setItem("foo", "bar").then(error => console.log(error)); + + OfficeRuntime.AsyncStorage.removeItem("foo"); + OfficeRuntime.AsyncStorage.removeItem("foo", () => { + // perform an action + }); + + OfficeRuntime.AsyncStorage.clear(); + OfficeRuntime.AsyncStorage.clear(() => { + // perform an action + }); + + OfficeRuntime.AsyncStorage.getAllKeys().then(keys => { + keys.forEach(item => console.log(item)); + }); + + OfficeRuntime.AsyncStorage.getAllKeys((error, keys) => { + if (error) { + console.error(error); + } else { + keys.forEach(item => console.log(item)); + } + }); + + OfficeRuntime.AsyncStorage.multiSet( + [["username", "foo"], ["yearOfBirth", "2001"]], + errors => { + errors.filter(error => error != null).forEach(error => console.log(error)); + } + ); + + OfficeRuntime.AsyncStorage.multiRemove(["foo", "bar"]); + OfficeRuntime.AsyncStorage.multiRemove(["foo", "bar"]).then(value => console.log(value)); + + OfficeRuntime.AsyncStorage.multiGet(["username", "yearOfBirth"]).then( + values => { + console.log(values[0][1]); + console.log(values[1][1]); + } + ); + + OfficeRuntime.displayWebDialog("https://localhost:3000", { + displayInIFrame: false + }); + + OfficeRuntime.displayWebDialog("https://localhost:3000", { + onClose: () => { + console.log("closed"); + } + }); diff --git a/types/office-runtime/tsconfig.json b/types/office-runtime/tsconfig.json new file mode 100644 index 0000000000..36d2c95261 --- /dev/null +++ b/types/office-runtime/tsconfig.json @@ -0,0 +1,25 @@ +{ + "compilerOptions": { + "module": "commonjs", + "lib": [ + "es6", + "dom" + ], + "noImplicitAny": true, + "noImplicitThis": true, + "strictNullChecks": false, + "strictFunctionTypes": true, + "baseUrl": "../", + "typeRoots": [ + "../" + ], + "types": [], + "noEmit": true, + "forceConsistentCasingInFileNames": true, + "target": "es6" + }, + "files": [ + "index.d.ts", + "office-runtime-tests.ts" + ] +} \ No newline at end of file diff --git a/types/office-runtime/tslint.json b/types/office-runtime/tslint.json new file mode 100644 index 0000000000..e60c15844f --- /dev/null +++ b/types/office-runtime/tslint.json @@ -0,0 +1,3 @@ +{ + "extends": "dtslint/dt.json" +} \ No newline at end of file From 18a85c52de28aff3e6155ccfdeacc24a7198ecf5 Mon Sep 17 00:00:00 2001 From: mscharlock Date: Fri, 21 Sep 2018 13:57:27 -0700 Subject: [PATCH 2/3] * fixes --- types/office-runtime/index.d.ts | 102 ++++++++++++++++---------------- 1 file changed, 51 insertions(+), 51 deletions(-) diff --git a/types/office-runtime/index.d.ts b/types/office-runtime/index.d.ts index 174229a04a..ae86c01bcb 100644 --- a/types/office-runtime/index.d.ts +++ b/types/office-runtime/index.d.ts @@ -13,8 +13,8 @@ Copyright (c) Microsoft Corporation declare namespace OfficeRuntime { /** * Enables you to pop up a web dialog box. - * @param url - * @param options + * @param url + * @param options */ function displayWebDialog(url: string, options: DisplayWebDialogOptions): Promise; /** @@ -22,22 +22,22 @@ declare namespace OfficeRuntime { */ const AsyncStorage: AsyncStorage; /** - * Asynchronous, global, and persistent key-value storage that can be used by Excel Custom Functions. - * @beta - * - * @remarks - * Each add-in instance has its own storage partition, unique to a user and their device. - * - * The default amount of total storage allowed per add-in is 5MB. - * - * Each method listed below returns a Promise object. - * - */ + * Asynchronous, global, and persistent key-value storage that can be used by Excel Custom Functions. + * @beta + * + * @remarks + * Each add-in instance has its own storage partition, unique to a user and their device. + * + * The default amount of total storage allowed per add-in is 5MB. + * + * Each method listed below returns a Promise object. + * + */ interface AsyncStorage { /** - * @beta - * Retrieves an object based on a key and invokes a callback when finished. Returns a Promise. - */ + * @beta + * Retrieves an object based on a key and invokes a callback when finished. Returns a Promise. + */ getItem(key: string, callback?: (error?: Error, result?: string) => void): Promise; /** * @beta @@ -45,29 +45,29 @@ declare namespace OfficeRuntime { */ setItem(key: string, value: string, callback?: (error?: Error) => void): Promise; /** - * @beta - * Removes an item for specified key and invokes a callback when finished. Returns a Promise. - */ + * @beta + * Removes an item for specified key and invokes a callback when finished. Returns a Promise. + */ removeItem(key: string, callback?: (error?: Error) => void): Promise; /** - * @beta - * Erases all AsyncStorage. Returns a Promise. - */ + * @beta + * Erases all AsyncStorage. Returns a Promise. + */ clear(callback?: (error?: Error) => void): Promise; /** - * @beta - * Returns a Promise with all keys. - */ + * @beta + * Returns a Promise with all keys. + */ getAllKeys(callback?: (error?: Error, keys?: string[]) => void): Promise; /** - * @beta - * Stores multiple key-value pairs in one batch. Returns a Promise. When a key doesn't exist, returns null. - */ + * @beta + * Stores multiple key-value pairs in one batch. Returns a Promise. When a key doesn't exist, returns null. + */ multiSet(keyValuePairs: string[][], callback?: (errors?: Error[]) => void): Promise; /** - * @beta - * Deletes a batch of keys, specified in the `keys` array. - */ + * @beta + * Deletes a batch of keys, specified in the `keys` array. + */ multiRemove(keys: string[], callback?: (errors?: Error[]) => void): Promise; /** * @beta @@ -76,25 +76,25 @@ declare namespace OfficeRuntime { multiGet(keys: string[], callback?: (errors?: Error[], result?: string[][]) => void): Promise; } /* - * @beta - * Object representing the dialog box. - */ + * @beta + * Object representing the dialog box. + */ interface Dialog { /** * @beta * Method that closes a dialog box. - */ + */ close(): Promise; } /** - * Provides options for how a dialog is displayed. - */ + * Provides options for how a dialog is displayed. + */ interface DisplayWebDialogOptions { /** - * @beta - * Determines whether the dialog box displays as a popup (false) or within an IFrame (true). This setting is only applicable to custom functions running on Excel Online. - */ + * @beta + * Determines whether the dialog box displays as a popup (false) or within an IFrame (true). This setting is only applicable to custom functions running on Excel Online. + */ displayInIFrame?: boolean; /** * @beta @@ -104,22 +104,22 @@ declare namespace OfficeRuntime { /** * @beta * Defines the width of the dialog box as a percentage of the current display. - */ + */ width?: string; /** - * @beta - * True if title is hidden from the dialog box. - */ + * @beta + * True if title is hidden from the dialog box. + */ hideTitle?: boolean; /* - * @beta - * Callback that is run when the dialog box is closed. - */ + * @beta + * Callback that is run when the dialog box is closed. + */ onClose?: () => void; /* - * @beta - * Callback that is run when the dialog box sends an error. - */ + * @beta + * Callback that is run when the dialog box sends an error. + */ onMessage?(message: string, dialog?: Dialog): void; } -} \ No newline at end of file +} From 6c6ee286a027fdeb431443e2a55fb4266f67ff10 Mon Sep 17 00:00:00 2001 From: mscharlock Date: Fri, 21 Sep 2018 16:14:15 -0700 Subject: [PATCH 3/3] fix lines --- types/office-runtime/index.d.ts | 1 - 1 file changed, 1 deletion(-) diff --git a/types/office-runtime/index.d.ts b/types/office-runtime/index.d.ts index 81c145784b..ae86c01bcb 100644 --- a/types/office-runtime/index.d.ts +++ b/types/office-runtime/index.d.ts @@ -123,4 +123,3 @@ declare namespace OfficeRuntime { onMessage?(message: string, dialog?: Dialog): void; } } -