Spanish Total.js
English
Documentation For AI agents
Contents

Component file reference

The exports properties and functions of the server code of a component.

.md GitHub
On this page

The server code in <script total> describes the component with properties of exports. Flow reads the file when the component is installed. For the other parts of the file, see The component file.

API

property

exports.id = 'uppercase';

The id of the component inside a FlowStream.

Installing a file with an id that is already installed replaces that component. Without an id, the designer generates one. Write it on one line that ends with a semicolon.

property

exports.name = 'Uppercase';

The name in the list of components, on the node and in the catalogue.

Required to install the component from a URL address or a catalogue.

property

exports.group = 'Demo';

The group under which the designer lists the component.
property

exports.icon = 'ti ti-font';

The icon of the component.

A class of the Total.js icon font, for example ti ti-print. Required to install the component from a URL address or a catalogue.

property

exports.version = '1';

The version of the component, as a string.

Required to install the component from a URL address or a catalogue. The Download components window compares it with the version in the catalogue and shows an update badge when the catalogue has a higher one.

property

exports.author = 'Jane Doe';

The author of the component.

The catalogue copies it. An author that does not contain Total.js gets a Community badge in the Download components window.

property

exports.color = '#E73323';

A color for the icon of the component.

The catalogue copies it, and the Download components window uses it as the background of the icon.

property

exports.kind = 'trigger';

A label for the kind of component.

The official components use trigger, action and output. The catalogue copies it.

property

exports.config = { greeting: 'Hello', uppercase: false };

The default configuration of a new node.

Each node gets a copy. The settings form edits it, and exports.make receives it as config. See Configuration and the settings form.

property

exports.inputs = [{ id: 'input', name: 'Input' }];

The inputs of the node.

Each input has an id, which messages report in $.input, and a name, which the node shows. See Inputs, outputs and messages.

property

exports.outputs = [{ id: 'output', name: 'Output' }, { id: 'error', name: 'Error' }];

The outputs of the node.

Each output has an id, which you pass to $.send(), and a name, which the node shows. A node can change its outputs with instance.outputs and instance.save().

property

exports.npm = ['qrcode'];

npm packages that the component needs.

Flow installs each package when the component is added to a FlowStream. A package can have a version, for example mongodb@4.0.0. Load it in exports.make with require().

Use a package
exports.npm = ['qrcode'];

exports.make = function(instance, config) {
	var QRCode = require('qrcode');
};
property

exports.meta = { singleton: true, settingswidth: 1200 };

Options for the designer.
OptionWhat it does
settingswidthThe width of the settings window in pixels. The default is 800.
singletonA FlowStream can hold only one node of the component. The designer refuses a second one.
hiddenThe node is drawn transparent on the canvas.
readonlyThe designer does not offer Edit source code, Copy node or Clone, and Flow refuses to read or save its source.
protectedThe component cannot be removed from the FlowStream.
event

exports.make = function(instance, config) {}

Creates a node.
ParameterTypeDescription
instance Object The node. See Instance reference.
config Object The configuration of the node. It stays the same object when the user changes the settings.

Flow calls it once for each node of the component: when the design is applied, when the FlowStream starts and when the component changes. Define the handlers of the instance here.

A component that forwards messages
exports.make = function(instance, config) {
	instance.message = function($) {
		$.send('output');
	};
};
event

exports.install = function(com) {}

Runs once when the component is added to a FlowStream.
ParameterTypeDescription
com Object The component.

Flow calls it when it registers the component for the first time in the FlowStream process, before the nodes are created. com.main is the FlowStream and com.config the default configuration.

event

exports.uninstall = function(com) {}

Runs when the component is removed from a FlowStream.
ParameterTypeDescription
com Object The component.

Flow calls it after it has closed all nodes of the component.

event

exports.call = function(data, callback) {}

Answers a call from the browser script that is not bound to one node.
ParameterTypeDescription
data Object The data from the browser.
callback Function Call it with the answer.

this is the FlowStream. The browser script calls it with exports.call(data, callback, true). The Publish and Subscribe components use it to list the nodes of other FlowStreams.

Answer with the id of the FlowStream
exports.call = function(data, callback) {
	callback({ flowstream: this.id });
};
Made in Europe