Merge pull request #29111 from mscharlock/michelle-officeruntime

Re-adding Office-runtime type
This commit is contained in:
Nathan Shively-Sanders
2018-09-21 16:21:30 -07:00
committed by GitHub
4 changed files with 158 additions and 146 deletions
+104 -96
View File
@@ -9,109 +9,117 @@ 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<Dialog>;
/**
* Asynchronous, global, and persistent key-value storage that can be used by Excel Custom Functions.
*/
const AsyncStorage: AsyncStorage;
// tslint:disable-next-line:interface-name
/*
* 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.
*/
getItem(key: string, callback?: (error?: Error, result?: string) => void): Promise<string>;
/*
* @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<void>;
/*
* @beta
* Removes an item for specified key and invokes a callback when finished. Returns a Promise.
*/
removeItem(key: string, callback?: (error?: Error) => void): Promise<void>;
/*
* @beta
* Erases all AsyncStorage. Returns a Promise.
*/
clear(callback?: (error?: Error) => void): Promise<void>;
/*
* @beta
* Returns a Promise with all keys.
*/
getAllKeys(callback?: (error?: Error, keys?: string[]) => void): Promise<string[]>;
/*
* @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<void>;
/*
* @beta
* Deletes a batch of keys, specified in the `keys` array.
*/
multiRemove(keys: string[], callback?: (errors?: Error[]) => void): Promise<void>;
/*
* @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<string[][]>;
/**
* @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<string>;
/**
* @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<void>;
/**
* @beta
* Removes an item for specified key and invokes a callback when finished. Returns a Promise.
*/
removeItem(key: string, callback?: (error?: Error) => void): Promise<void>;
/**
* @beta
* Erases all AsyncStorage. Returns a Promise.
*/
clear(callback?: (error?: Error) => void): Promise<void>;
/**
* @beta
* Returns a Promise with all keys.
*/
getAllKeys(callback?: (error?: Error, keys?: string[]) => void): Promise<string[]>;
/**
* @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<void>;
/**
* @beta
* Deletes a batch of keys, specified in the `keys` array.
*/
multiRemove(keys: string[], callback?: (errors?: Error[]) => void): Promise<void>;
/**
* @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<string[][]>;
}
/*
* @beta
* Object representing the dialog box.
*/
* @beta
* Object representing the dialog box.
*/
interface Dialog {
/*
* @beta
* Method that closes a dialog box.
*/
close(): Promise<void>;
/**
* @beta
* Method that closes a dialog box.
*/
close(): Promise<void>;
}
/*
* 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.
*/
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;
/**
* @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;
}
}
}
+51 -50
View File
@@ -4,58 +4,59 @@ 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.getItem("foo").then(value => console.log(value));
OfficeRuntime.AsyncStorage.getAllKeys().then(keys => {
keys.forEach(item => console.log(item));
});
OfficeRuntime.AsyncStorage.setItem("foo", "bar");
OfficeRuntime.AsyncStorage.setItem("foo", "bar").then(error => console.log(error));
OfficeRuntime.AsyncStorage.getAllKeys((error, keys) => {
if (error) {
console.error(error);
} else {
keys.forEach(item => console.log(item));
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");
}
});
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");
}
});
});
+2
View File
@@ -11,6 +11,7 @@
"strictFunctionTypes": true,
"baseUrl": "../",
"typeRoots": ["../"],
"types": [],
"noEmit": true,
"forceConsistentCasingInFileNames": true,
@@ -21,3 +22,4 @@
"office-runtime-tests.ts"
]
}
+1
View File
@@ -1,3 +1,4 @@
{
"extends": "dtslint/dt.json"
}