From 7c2f91816bcbecc0748574fe22a86d4ca88525c7 Mon Sep 17 00:00:00 2001 From: Brandon Jordan Date: Thu, 23 Nov 2023 17:07:31 -0500 Subject: [PATCH] Add output action --- src/actions.ts | 2 ++ src/actions/output.ts | 39 +++++++++++++++++++++++++++++++++++++++ 2 files changed, 41 insertions(+) create mode 100644 src/actions/output.ts diff --git a/src/actions.ts b/src/actions.ts index f439ebc..5e6002e 100644 --- a/src/actions.ts +++ b/src/actions.ts @@ -23,6 +23,7 @@ import AskForInput from "~/actions/ask-for-input"; import SplitText from "~/actions/split-text"; import GetFromList from "~/actions/get-from-list"; import SetName from "~/actions/set-name"; +import Output from "~/actions/output"; interface ActionDefinitions { [key: string]: ActionDefinition @@ -67,6 +68,7 @@ export let actions: ActionDefinitions = { 'delay': Wait, 'exit': Stop, 'setitemname': SetName, + 'output': Output, }; export function actionText(value: string): HTMLElement { diff --git a/src/actions/output.ts b/src/actions/output.ts new file mode 100644 index 0000000..8264a03 --- /dev/null +++ b/src/actions/output.ts @@ -0,0 +1,39 @@ +import {renderActionHeader} from "~/render"; +import {actions} from "~/actions"; +import {renderValue} from "~/value"; + +interface ShowAlertParameters { + WFOutput: string | object + WFNoOutputSurfaceBehavior: string + WFResponse: string | object +} + +export default { + title: "Stop and output", + icon: "square_arrow_left", + background: "#007aff", + render: (container: HTMLElement, params: ShowAlertParameters) => { + container.classList.add('sp-output-action'); + const action = renderActionHeader(actions['output'], renderValue(params['WFOutput'], 'Output')); + + const outputSurfaceBehavior = document.createElement('div'); + outputSurfaceBehavior.innerText = 'If there\'s nowhere to output:'; + outputSurfaceBehavior.className = 'sp-output-surface-behavior'; + action.appendChild(outputSurfaceBehavior); + + const flexbox = document.createElement('div'); + flexbox.style.display = 'flex'; + flexbox.style.gap = '10px'; + flexbox.style.alignItems = 'center'; + flexbox.style.margin = '0 16px'; + flexbox.style.height = '3rem'; + + flexbox.appendChild(renderValue(params['WFNoOutputSurfaceBehavior'] ?? 'Do Nothing', 'Behavior')); + if (params['WFResponse']) { + flexbox.appendChild(renderValue(params['WFResponse'] ?? null, 'Result')); + } + action.appendChild(flexbox); + + return action; + } +}