Handbook · Scripts
Scripts
Where in the UI. Scripts tab (Blockly + generated JS). Structure wires from element/layout/component handles to script nodes. Lifecycle events on element inspectors.
Blockly is how you author behavior. The JS tab is a check: it is generated, sandboxed, and not the place to invent APIs.
Blockly vs generated JS
Treat Blockly as the source of truth. The JS view is what the js-interpreter sandbox runs. Do not invent host APIs there — only methods in host methods exist, and each needs a capability. If you edit JS until it no longer matches the blocks, the editor will ask you to confirm; that can invalidate the Blockly graph. Prefer fixing blocks, not hand-writing JS. The JSON tab stores the same script payload the app loads.
When a script runs
- Lifecycle — onCreated, onEdited (optionally filtered), onDeleted, layout shown, … See the element inspector.
- Gestures — button press, toggle change (component handles).
- Class API — another script calls a class-exported function.
- Item UI pack — context menu / header actions.
Toolbox map
Stock: Logic, Loops, Math, Text, Lists, Variables, Functions. Containd categories: Dialogs, Text helpers, Navigation, Tree, Layouts, Data, Table, Class, Relatives, DateTime, Units, Statistics, Device, Canvas, Graph, Media, Files, Items, AI, System, Actions, Shared, Advanced. Indexes: Blockly, host methods.
Tasks
- Create a script; in Blockly show an alert with ContaindText (not a stock English string if users will see it).
- Wire a button press to that script.
- Preview: tap the button. If policy complains, read the capability on the block.