From 6528cb1c8a99fc9977c8c3ea99bd215c5a94b839 Mon Sep 17 00:00:00 2001 From: tyeth Date: Fri, 24 Oct 2025 17:33:01 +0100 Subject: [PATCH] add(block): Trigger Compare block --- app/blocks/logic/current_trigger.js | 52 +++++++++++++++++++++++++++++ app/toolbox/logic.js | 1 + 2 files changed, 53 insertions(+) create mode 100644 app/blocks/logic/current_trigger.js diff --git a/app/blocks/logic/current_trigger.js b/app/blocks/logic/current_trigger.js new file mode 100644 index 0000000..39c425f --- /dev/null +++ b/app/blocks/logic/current_trigger.js @@ -0,0 +1,52 @@ + +/** @type {import('#types').BlockDefinitionRaw} */ +export default { + type: "current_trigger", + name: "Trigger Compare", + bytecodeKey: "current_trigger", + colour: 60, + description: "Returns a boolean expression indicating whether the Action was triggered by the same trigger as this block.", + + connections: { + mode: "value", + output: "expression", + }, + + template: "Current Trigger: %INPUT_A", + + inputs: { + INPUT_A: { + description: "The trigger block to compare with the Actions triggers, returning true if the action was triggered by the same trigger.", + check: "trigger", + type: "statement", + shadow: { + type: 'when_data', + fields: { FEED_KEY: "" } + } + } + }, + + generators: { + json: (block, generator) => { + const payload = { + current_trigger: { + trigger: JSON.parse(generator.statementToCode(block, 'INPUT_A') || null) + } + } + + return JSON.stringify(payload) + } + }, + + regenerators: { + json: (blockObject, helpers) => { + const payload = blockObject.current_trigger + return { + type: 'current_trigger', + inputs: { + INPUT_A: helpers.expressionToBlock(payload.trigger, { shadow: 'when_data' }) + } + } + } + } +} diff --git a/app/toolbox/logic.js b/app/toolbox/logic.js index 7a1b020..6845658 100644 --- a/app/toolbox/logic.js +++ b/app/toolbox/logic.js @@ -8,5 +8,6 @@ export default { "io_logic_negate", "io_logic_compare", "text_compare", + "current_trigger" ] }