Update root.js

This commit is contained in:
Tyler Cooper 2025-08-07 15:34:13 -05:00 committed by GitHub
parent 4b2b8705f7
commit 51def7dafc
No known key found for this signature in database
GPG key ID: B5690EEEBB952194

View file

@ -1,46 +1,37 @@
import mutator from './action_settings/mutator.js' import mutator from './action_settings/mutator.js'
/** @type {import('#types').BlockDefinitionRaw} */ /** @type {import('#types').BlockDefinitionRaw} */
export default { export default {
type: "action_root", type: "action_root",
name: "Root", name: "Root",
colour: "0", colour: "0",
description: "Add Triggers to determine when this Action runs. Add Actions to determine what this Action does.", description: "The foundation of every Adafruit IO Action. Connect Triggers (like 'when temperature > 80°F' or 'every morning at 8 AM') to define when your Action runs, then attach Action blocks (like 'send email', 'publish to feed', or 'if/then logic') to define what happens when triggered.",
connections: {}, connections: {},
mutator, mutator,
template: ` template: `
Triggers: |LEFT Triggers: |LEFT
%TRIGGERS %TRIGGERS
Actions: |LEFT Actions: |LEFT
%EXPRESSIONS %EXPRESSIONS
\u3164 \u3164
`, `,
inputs: { inputs: {
TRIGGERS: { TRIGGERS: {
description: "Connect trigger blocks here to define WHEN your Action should run. Choose from Reactive triggers (respond to feed updates), Scheduled triggers (run at specific times), or Timer triggers (delayed responses). Multiple triggers can be chained together.",
type: 'statement', type: 'statement',
check: 'trigger' check: 'trigger'
}, },
EXPRESSIONS: { EXPRESSIONS: {
description: "Connect action blocks here to define WHAT happens when your triggers activate. This can include sending emails, publishing values to feeds, conditional if/then logic, mathematical operations, or webhook calls. Actions execute in sequence from top to bottom.",
type: 'statement', type: 'statement',
check: 'expression' check: 'expression'
} }
}, },
generators: { generators: {
json: (block, generator) => { json: (block, generator) => {
const parseStatementToCodeAsJson = statementInputName => { const parseStatementToCodeAsJson = statementInputName => {
let expressions = [] let expressions = []
try { try {
let expressionsJson = generator.statementToCode(block, statementInputName) let expressionsJson = generator.statementToCode(block, statementInputName)
try { try {
expressions = JSON.parse(`[${expressionsJson}]`) expressions = JSON.parse(`[${expressionsJson}]`)
} catch(e) { } catch(e) {
@ -51,10 +42,8 @@ export default {
console.error(`Error calling statementToCode on root input ${statementInputName}:`) console.error(`Error calling statementToCode on root input ${statementInputName}:`)
console.error(e) console.error(e)
} }
return expressions return expressions
} }
const const
// @ts-ignore // @ts-ignore
seconds = block.delaySeconds, seconds = block.delaySeconds,
@ -63,7 +52,6 @@ export default {
delay = (seconds > 0) delay = (seconds > 0)
? { seconds, mode } ? { seconds, mode }
: undefined : undefined
return JSON.stringify({ return JSON.stringify({
version: "1.0.0-beta.1", version: "1.0.0-beta.1",
settings: { delay }, settings: { delay },
@ -72,11 +60,9 @@ export default {
}, null, 2) }, null, 2)
} }
}, },
regenerators: { regenerators: {
json: (blockObject, helpers) => { json: (blockObject, helpers) => {
const { triggers, expressions, settings } = blockObject const { triggers, expressions, settings } = blockObject
return { return {
type: "action_root", type: "action_root",
movable: false, movable: false,