Skip to main content

QWidget functions and TypeScript

Function lets you write TypeScript logic inside a widget. Scripts run in an isolated sandbox iframe with no DOM, network, localStorage, or import; they can read inputs, return a plain object, and read/write the current widget’s visual properties through Host.

Minimal example

Call it:

Structure

Function

Function.Interface

Field types: String / Number / Bool / DateTime / Json / Binary, or another Struct name.

Function.Input

The element text is the script variable name (default Input).

Function.Output

Results become {Results.<Function>.<Output>}.

Function.Script

TypeScript source; CDATA is recommended:
Scripts must return JSON-serializable values; Date is serialized as an ISO string. Top-level await is supported, so scripts can wait for Host calls directly.

Input sources

Input is built in this order:
  1. Arguments JSON from CallFunction (supports binding interpolation).
  2. Otherwise, values from Inputs matched to the input Struct field names.

Script globals

Host

All Host methods are asynchronous and return a Promise; you may await them or ignore the result.

Writable properties

Every visual node addressed by Target exposes its XML visual attributes, for example:
  • Text: Value, Size, Weight, Color, Clamp, Align
  • Button / Link: Text, Variant, Size, Url
  • TextBox / CheckBox / Slider / Select / ColorPicker / FilePicker: Value, Checked, Options, etc.
  • List: Items (an array is accepted directly), Gap, EmptyText
  • Container / Row / Column / Grid: Gap, Padding, Border, Background, Radius, Align, Justify
  • Image / Media: Src, Alt, Source, Volume, Muted, etc.
  • All visual nodes: Visible, plus the content alias Content (Text → Value, Button → Text, List → Items, etc.)
Host.SetProperty cannot change structural or action attributes such as Target, Name, OnClick, OnChange, Function, Arguments, Command, WorkingDirectory, Timeout, PluginId, or Method.

Invoke methods

Example

Host.Invoke("RefreshButton", "Click") runs the button’s action again; invoking the button from its own script recurses, so only invoke other buttons or guard with a condition. Scripts still cannot execute commands or call plugin APIs directly; those remain button/trigger actions.

Triggers

  • Loaded: once after mount.
  • DataChanged: after the named data source loads.
  • Click: when a control with the matching Name is clicked.
  • Timer: every Interval ms, minimum 1000.
  • Resize: 150ms after the grid or pixel size changes; use Loaded for the initial layout.
  • Rate limit: 20 executions per second.

Run in the editor

Open the Functions tab, select a function, and click Run:
  • Executes with current Inputs and sample data.
  • Shows returned JSON below the editor.
  • Syntax errors are reported from sucrase.
  • Run only verifies inputs/outputs; Host.SetProperty / Host.Invoke UI changes apply when the widget runs on the dashboard, not to the editor preview.

Sandbox and security

  • Scripts run in a sandbox iframe with CSP blocking network, images, media, frames, and workers.
  • No window, document, localStorage, fetch, XMLHttpRequest, import, or require.
  • On timeout the iframe is destroyed and recreated.
  • Outputs are validated against Function.Output.
  • Remote widgets can contain scripts and update silently; only use widgets you trust.

Debugging

  1. Use Run to verify inputs/outputs.
  2. Put intermediate values into outputs or Host.Log.
  3. Avoid infinite loops; the sandbox is destroyed on timeout.
  4. Fetch external data with Data first; scripts only process loaded data.