Skip to content

Write a widget package

The Template widget covers one-off components written in the flow. When a widget is meant to be reused, shared on npm or is heavy (a 3D view, a map, a big charting library), ship it as an extension package: a regular Node-RED module that adds its own widget types to Tessera.

An extension widget behaves like a built-in one:

  • It follows the same message contract: msg.payload sets the value, msg.ui changes props, outputs carry msg._client. Tessera stores the last value and replays it to new browsers.
  • It appears in the visual builder palette, under Extensions (or the category you choose), with a live preview and inspector fields.
  • Dashboards download its code only when a page shows it: it adds nothing to Tessera’s size.

The repository has a complete example, a knob, in extensions/example-knob. This guide walks through it.

node-red-tessera-example-knob/
├── package.json
├── knob.js the node's runtime (Node.js)
├── knob.html the node's editor definition
└── client/
└── knob.js the browser module

package.json declares the node like any Node-RED module, with Tessera as a peer dependency:

{
"name": "node-red-tessera-example-knob",
"node-red": { "nodes": { "example-knob": "knob.js" } },
"peerDependencies": { "@fgjcarlos/node-red-tessera": ">=0.4.0" }
}

The node file gets Tessera’s API from the package and defines the widget with defineWidget(type, spec), the same function the built-in widgets use:

module.exports = function (RED) {
const tessera = require('@fgjcarlos/node-red-tessera')(RED);
tessera.defineWidget('example-knob', {
client: require.resolve('./client/knob.js'),
catalog: {
label: 'Knob',
icon: 'circle-gauge',
size: [3, 2],
props: { label: 'Knob', min: 0, max: 100, step: 1, unit: '' },
sample: { value: 40 },
fields: [
{ key: 'label', label: 'Label', type: 'text', group: 'Content' },
{ key: 'max', label: 'Max', type: 'number', group: 'Behaviour' },
],
},
props: (config) => ({ label: config.label || '', min: tessera.num(config.min, 0), max: tessera.num(config.max, 100) }),
initial: () => null,
input(msg, w) {
w.setState({ value: Number(msg.payload) }, msg);
},
event(ev, value, w, clientId) {
if (ev === 'change') w.emit(value, clientId);
},
});
};

The type is the Node-RED node type: it starts with a lowercase letter, then lowercase letters, digits and dashes, unique among all installed nodes. Prefix it with your package’s name; tessera- is reserved for Tessera’s own widgets.

Spec
client Required. Absolute path of the browser module. Its folder is served by the dashboard at /<path>/ext/<type>/, so the module can import files next to it with relative URLs.
catalog The builder palette entry, below.
props(config) Node config → the props the browser gets. Anything in msg.ui later overrides them.
initial(config) The state before any message, usually null.
input(msg, w) Handles msg.payload: call w.setState(state, msg) to store the state and send it to the browsers. msg._client messages go to that browser only and aren’t stored.
event(ev, value, w, clientId) Handles what the browser module emits. w.emit(payload, clientId) sends a message from the node’s output; w.setState(state) stores the state and sends it to every browser, the sender included (its echo corrects an older init that arrived after its local change).

Without event, the module’s send(payload) is sent from the output as is.

For a widget that follows several tags instead of the single tag field, add two optional members:

Member
tags(config) Returns the full tag names (<node name>/<key>) the widget follows. Each one is bound like config.tag: every change reaches input() as { payload, topic: name }, and values already in the table are fed when the node starts. Duplicates and blank names are ignored. If it is defined, it wins over config.tag.
quality(w, name, quality) Called when the quality of one of those tags changes: quality is 'bad', 'stale' or null (back to normal). Keep it in your state: with tags() the runtime never sets the whole-tile props.quality veil, so one tag that falls does not dim the rest. Without quality(), quality changes are ignored.
catalog Default
label Widget Palette name.
icon puzzle A Lucide icon name.
category extensions A palette section: indicators, charts, data, controls, inputs, media, advanced or extensions.
description, tags Shown and searched in the palette.
size [3, 2] Default width × height, in the normal 12-column grid (scaled for other grids, 4–48 columns).
props {} Default props of a widget added in the builder.
sample null The state shown in the builder preview, before any message.
fields label and icon Inspector fields: { key, label, type, group } with type one of text, number, toggle, select or segmented (with options: [{ value, label }]), icon, code. key is the node config property.
outputs, messages For tools that read catalog.json: number of outputs and { input, output } descriptions.
style [] Builder: the visual props that copy / paste style (Ctrl+Alt+C / Ctrl+Alt+V) carries to other widgets, e.g. ['color', 'size']: keys of props, never data, topic or geometry. A widget of another type takes only the keys it has.
inline [] Builder: the text props edited in place (double-click, or Enter on the selected widget; the first key is the one Enter edits), e.g. ['label']. Keys of props that hold plain text. The tile’s header shows label and is the target of the double-click; other keys are edited in a box at the tile’s top left.

The .html file registers the node as usual, plus tessera: true so the builder can create, move and edit it. Keep the geometry defaults as they are:

RED.nodes.registerType('example-knob', {
category: 'tessera',
color: '#2dd4bf',
tessera: true,
defaults: {
name: { value: '' },
page: { value: '', type: 'tessera-page', required: true },
order: { value: 0 },
col: { value: '' },
row: { value: '' },
hideOn: { value: [] },
phoneOrder: { value: '' },
phoneHeight: { value: '' },
width: { value: 3 },
height: { value: 2 },
region: { value: 'main' },
label: { value: 'Knob' },
uiIcon: { value: '' },
topic: { value: '' },
tag: { value: '' }, // lets the widget be bound to a tag (see below)
// …your own properties
},
inputs: 1,
outputs: 1,
icon: 'font-awesome/fa-dot-circle-o',
});

Add tag to the defaults to let a flow bind the widget to a tag: the runtime feeds it through input() like a wire, but the editor drops a property that is not in defaults when it saves, deploys or imports. If your dialog uses TesseraEditor.commonRows, that is all: the Tag row (with autocomplete) appears automatically once tag is in the defaults. Only a dialog that does not use commonRows (like example-knob) needs the manual route: put <input type="text" id="node-input-tag"> in the dialog and call window.TesseraEditor.tagField('node-input-tag') from oneditprepare (only there: the core file may load later). Never both: the id would be duplicated.

Name the widget’s icon property uiIcon (Node-RED reserves icon): the dashboard gets it as the icon prop.

A plain ES module whose default export mounts the widget. It runs in the dashboard with no build step and any framework, or none:

export default function mount(el, ctx) {
el.innerHTML = '<div class="value"></div>';
const style = document.createElement('style');
style.textContent = '.value { font-size: 32px; color: var(--accent); }';
ctx.root.append(style);
const show = (state) => (el.querySelector('.value').textContent = state?.value ?? '–');
show(ctx.state);
return {
message(state) { show(state); }, // every new state
props(props) { /* msg.ui or the inspector changed the props */ },
destroy() { /* timers, listeners… */ },
};
}
ctx
root The widget’s shadow root: add your <style> here. Styles don’t leak in or out; the theme tokens (var(--accent), var(--fg), var(--surface-2)…) are inherited, so the widget follows the dark and light themes.
props The current props.
state The current state, or null.
emit(event, value) Sends an event to the runtime’s event().
send(payload) emit('send', payload).

mount may be async. Errors show in the tile. The tile draws the frame and the label/icon header; set the frame prop to false to draw your own card, and :host { --tile-pad: 0 } to go edge to edge.

Dashboards often run offline, on plant networks: bundle what the module needs (a library in the client folder, imported with a relative URL) instead of loading it from a CDN.

A package can also ship symbols for the synoptic widget: a folder of <name>.svg + <name>.json pairs, registered from the node file with defineSymbolPack(id, { dir }):

tessera.defineSymbolPack('acme', { dir: path.join(__dirname, 'symbols') });

Diagrams cite them as acme/<name>, and GET /tessera/symbols/index.json lists them next to the core ones (core/tank, core/pump, core/valve). id uses lowercase letters, digits and dashes, and core is reserved.

The SVG has one <svg viewBox>, strokes in currentColor, the state colour only through var(--sym-state, var(--hmi-normal)), no <style>, scripts or animations, and weighs at most 4 KB. Mark the parts the viewer animates with data-part (body, fill, level, rotor, flow or value). The manifest:

{
"id": "gauge",
"label": "Gauge",
"category": "instruments",
"tags": ["pressure"],
"size": [60, 60],
"ports": [{ "id": "in", "x": 0.5, "y": 1, "dir": "s" }],
"props": [{ "name": "value", "type": "text" }]
}

id is the file name; category is shapes, lines, equipment, instruments, states, values or commands; size is in canvas units; ports are positions from 0 to 1 with a direction (n, e, s, w); props are the bindable properties (boolean, number or text).

Each manifest is validated and each SVG is sanitised when the pack is registered: a pair that fails is skipped with a warning in the Node-RED log, and the sanitised copy is what browsers get.

Copy the package folder into the node_modules folder of your Node-RED user directory (~/.node-red), next to @fgjcarlos/node-red-tessera, or npm install it there once published. Restart Node-RED: the node appears in the editor palette, and in the builder under Extensions.