# rete-module-plugin

> Rete module plugin ==== #### Rete.js plugin

Latest version **0.4.2** (published 2021-12-16) · MIT license · 0 weekly downloads

## Install

```sh
npm install rete-module-plugin
pnpm add rete-module-plugin
yarn add rete-module-plugin
bun add rete-module-plugin
```

## Health

**Score 20/100 (F)** — status: abandoned.

Positive: esm support; no vulnerabilities.

Warnings: low downloads; no types; pre 1.0.

Negative: abandoned; low maintenance score.

## Facts

| | |
|---|---|
| Version | 0.4.2 |
| Published | 2021-12-16 |
| First published | 2018-06-05 |
| Weekly downloads | 0 |
| License | MIT |
| TypeScript types | none |
| Module format | ESM + CommonJS |
| Dependencies | 0 |
| Unpacked size | 80.4 KB |
| Known vulnerabilities | 0 |
| Install scripts | no |
| Author | Vitaliy Stoliarov |
| Maintainers | ni55an |

## Links

- npm: https://www.npmjs.com/package/rete-module-plugin
- Repository: https://github.com/retejs/module-plugin
- Homepage: https://github.com/retejs/module-plugin#readme
- Issues: https://github.com/retejs/module-plugin/issues
- npm.io page: https://npm.io/package/rete-module-plugin

## Recent versions

- 0.4.2 (latest) — 2021-12-16
- 0.4.1 — 2020-01-27
- 0.4.0 — 2019-12-04
- 0.3.1 — 2019-10-12
- 0.3.0 — 2019-03-04
- 0.2.0 — 2018-10-19
- 0.1.5 — 2018-10-19
- 0.1.4 — 2018-08-14
- 0.1.3 — 2018-07-18
- 0.1.2 — 2018-07-09
- 0.1.1 — 2018-07-06
- 0.1.0 — 2018-06-05

## README

Rete module plugin
====
#### Rete.js plugin

[Live example](https://codepen.io/Ni55aN/pen/QOEbEW)

```js
import ModulePlugin from 'rete-module-plugin';

const modules = {
    moduleName: { data: defaultData() }
}

editor.use(ModulePlugin, { engine, modules });

class InputNumber extends Component {
    constructor() {
        super('Input number');
        this.module = {
            nodeType: 'input',
            socket: sockets.num,
            // or
            socket(node) {
                return sockets[node.data.socketType];
            }
        }
    }

    builder(node) {
        var out = new Output('output', 'Number', sockets.num); // the key must be 'output'
        var ctrl = new FieldControl(this.editor, 'name', {value: ''}); // the key must be 'name'
        var ctrl2 = new FieldControl(this.editor, 'number', {type: 'number', value: 1});
        
        return node
            .addControl(ctrl)
            .addControl(ctrl2)
            .addOutput(out);
    }

    async worker(node, inputs, outputs) {
        if (!outputs['num'])
            outputs['num'] = node.data.number; // here you can modify received outputs of Input node
    }
};

export default class ModuleComponent extends Component {

    constructor() {
        super("Module");
        this.module = {
            nodeType: 'module'
        }
    }

    builder(node) {
        var ctrl = new FieldControl(this.editor, 'module', {value: 'Module name..'}); // the key must be 'module'
        ctrl.onChange = () => {
            this.updateModuleSockets(node);
            node.update();
        }
        return node.addControl(ctrl);
    }

    change(node, item) {
        node.data.module = item;
        this.editor.trigger('process');
    }
}

class OutputNumber extends Component {
    constructor() {
        super('Output number');
        this.module = {
            nodeType: 'output',
            socket: sockets.num,
            // or
            socket(node) {
                return sockets[node.data.socketType];
            }
        }
    }

    builder(node) {
        var inp = new Input('input', 'Number', sockets.num); // the key must be 'input'
        var ctrl = new FieldControl(this.editor, 'name', {value: 'num'}); // the key must be 'name'

        return node
            .addControl(ctrl)
            .addInput(inp);
    }
}
```

---
_Source: https://npm.io/package/rete-module-plugin · Machine-readable twin of the npm.io package page. Health data is recomputed on every publish._
