UNPKG

@joshfarrant/shortcuts-js

Version:
61 lines 1.94 kB
"use strict"; Object.defineProperty(exports, "__esModule", { value: true }); const uuidv4 = require("uuid/v4"); const utils_1 = require("../utils"); /** * @action Choose from Menu * @section Actions > Scripting > Control Flow * @icon Scripting * * Presents a menu and runs different actions based on which menu item was chosen. * * ```js * chooseFromMenu({ * items: [{ * label: 'Blue', * // An array of actions to perform if 'blue' is selected * actions: [], * }, { * label: 'Green', * // An array of actions to perform if 'green' is selected * actions: [], * }], * prompt: 'Which of these is your favourite colour?', * }); * ``` */ const chooseFromMenu = ({ items = [], prompt = '', }) => { const groupingIdentifier = uuidv4(); return [ { WFWorkflowActionIdentifier: 'is.workflow.actions.choosefrommenu', WFWorkflowActionParameters: { WFMenuPrompt: prompt, WFControlFlowMode: 0, WFMenuItems: items.map(item => item.label), GroupingIdentifier: groupingIdentifier, }, }, ...items.reduce((a, item) => ([ ...a, { WFWorkflowActionIdentifier: 'is.workflow.actions.choosefrommenu', WFWorkflowActionParameters: { WFMenuItemTitle: item.label, GroupingIdentifier: groupingIdentifier, WFControlFlowMode: 1, }, }, ...item.actions, ]), []), { WFWorkflowActionIdentifier: 'is.workflow.actions.choosefrommenu', WFWorkflowActionParameters: { GroupingIdentifier: groupingIdentifier, WFControlFlowMode: 2, }, }, ]; }; exports.default = utils_1.withActionOutput(chooseFromMenu); //# sourceMappingURL=chooseFromMenu.js.map