152 lines
4.8 KiB
JavaScript
152 lines
4.8 KiB
JavaScript
// copyright (c) Microsoft Corporation. All rights reserved.
|
|
// licensed under the MIT license.
|
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
exports.toOfficeApp = exports.parseOfficeApps = exports.parseOfficeApp = exports.getOfficeAppsForManifestHosts = exports.getOfficeApps = exports.getOfficeAppNames = exports.getOfficeAppName = exports.getOfficeAppForManifestHost = exports.OfficeApp = void 0;
|
|
/**
|
|
* The Office apps which can host Office Add-ins.
|
|
*/
|
|
var OfficeApp;
|
|
(function (OfficeApp) {
|
|
// the string values should be lowercase
|
|
OfficeApp["Excel"] = "excel";
|
|
OfficeApp["OneNote"] = "onenote";
|
|
OfficeApp["Outlook"] = "outlook";
|
|
OfficeApp["PowerPoint"] = "powerpoint";
|
|
OfficeApp["Project"] = "project";
|
|
OfficeApp["Word"] = "word";
|
|
// when adding new entries, update the toOfficeApp() function
|
|
// since there isn't an automatic reverse mapping from string to enum values
|
|
})(OfficeApp = exports.OfficeApp || (exports.OfficeApp = {}));
|
|
// initialized once since this list won't change
|
|
const officeApps = Object.keys(OfficeApp).map((key) => parseOfficeApp(key));
|
|
/**
|
|
* Get the Office app for the manifest Host name
|
|
* @param host Host name
|
|
*/
|
|
function getOfficeAppForManifestHost(host) {
|
|
switch (host.toLowerCase()) {
|
|
case "document":
|
|
return OfficeApp.Word;
|
|
case "mail":
|
|
return OfficeApp.Outlook;
|
|
case "mailbox":
|
|
return OfficeApp.Outlook;
|
|
case "notebook":
|
|
return OfficeApp.OneNote;
|
|
case "presentation":
|
|
return OfficeApp.PowerPoint;
|
|
case "project":
|
|
return OfficeApp.Project;
|
|
case "workbook":
|
|
return OfficeApp.Excel;
|
|
default:
|
|
return undefined;
|
|
}
|
|
}
|
|
exports.getOfficeAppForManifestHost = getOfficeAppForManifestHost;
|
|
/**
|
|
* Gets the Office application name suitable for display.
|
|
* @param app Office app
|
|
*/
|
|
function getOfficeAppName(app) {
|
|
switch (app) {
|
|
case OfficeApp.Excel:
|
|
return "Excel";
|
|
case OfficeApp.OneNote:
|
|
return "OneNote";
|
|
case OfficeApp.Outlook:
|
|
return "Outlook";
|
|
case OfficeApp.PowerPoint:
|
|
return "PowerPoint";
|
|
case OfficeApp.Project:
|
|
return "Project";
|
|
case OfficeApp.Word:
|
|
return "Word";
|
|
default:
|
|
throw new Error(`Unable to provide name for Office app "${app}"`);
|
|
}
|
|
}
|
|
exports.getOfficeAppName = getOfficeAppName;
|
|
/**
|
|
* Gets the Office application names suitable for display.
|
|
* @param apps Office apps
|
|
*/
|
|
function getOfficeAppNames(apps) {
|
|
return apps.map((app) => getOfficeAppName(app));
|
|
}
|
|
exports.getOfficeAppNames = getOfficeAppNames;
|
|
/**
|
|
* Returns the Office apps that support Office add-ins.
|
|
*/
|
|
function getOfficeApps() {
|
|
return officeApps;
|
|
}
|
|
exports.getOfficeApps = getOfficeApps;
|
|
/**
|
|
* Get the Office apps for the manifest Host names.
|
|
* @param hosts Host names specified in the manifest.
|
|
*/
|
|
function getOfficeAppsForManifestHosts(hosts) {
|
|
const apps = [];
|
|
if (hosts) {
|
|
hosts.forEach((host) => {
|
|
const app = getOfficeAppForManifestHost(host);
|
|
if (app) {
|
|
apps.push(app);
|
|
}
|
|
});
|
|
}
|
|
return apps;
|
|
}
|
|
exports.getOfficeAppsForManifestHosts = getOfficeAppsForManifestHosts;
|
|
/**
|
|
* Converts the string to the OfficeApp enum value.
|
|
* @param value string
|
|
* @throws Error if the value is not a valid Office app.
|
|
*/
|
|
function parseOfficeApp(value) {
|
|
const officeApp = toOfficeApp(value);
|
|
if (!officeApp) {
|
|
throw new Error(`"${value}" is not a valid Office app.`);
|
|
}
|
|
return officeApp;
|
|
}
|
|
exports.parseOfficeApp = parseOfficeApp;
|
|
/**
|
|
* Converts the strings to the OfficeApp enum values.
|
|
* @param input "all" for all Office apps, or a comma-separated list of one or more Office apps.
|
|
* @throws Error if a value is not a valid Office app.
|
|
*/
|
|
function parseOfficeApps(input) {
|
|
if (input.trim().toLowerCase() === "all") {
|
|
return getOfficeApps();
|
|
}
|
|
else {
|
|
return input.split(",").map((appString) => parseOfficeApp(appString));
|
|
}
|
|
}
|
|
exports.parseOfficeApps = parseOfficeApps;
|
|
/**
|
|
* Returns the OfficeApp enum for the value, or undefined if not valid.
|
|
* @param value Office app string
|
|
*/
|
|
function toOfficeApp(value) {
|
|
switch (value ? value.trim().toLowerCase() : value) {
|
|
case OfficeApp.Excel:
|
|
return OfficeApp.Excel;
|
|
case OfficeApp.OneNote:
|
|
return OfficeApp.OneNote;
|
|
case OfficeApp.Outlook:
|
|
return OfficeApp.Outlook;
|
|
case OfficeApp.PowerPoint:
|
|
return OfficeApp.PowerPoint;
|
|
case OfficeApp.Project:
|
|
return OfficeApp.Project;
|
|
case OfficeApp.Word:
|
|
return OfficeApp.Word;
|
|
default:
|
|
return undefined;
|
|
}
|
|
}
|
|
exports.toOfficeApp = toOfficeApp;
|
|
//# sourceMappingURL=officeApp.js.map
|