0.4.2 • Published 2 years ago

rete-module-plugin v0.4.2

Weekly downloads
149
License
MIT
Repository
github
Last release
2 years ago

Rete module plugin

Rete.js plugin

Live example

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);
    }
}
0.4.2

2 years ago

0.4.1

4 years ago

0.4.0

4 years ago

0.3.1

5 years ago

0.3.0

5 years ago

0.2.0

6 years ago

0.1.5

6 years ago

0.1.4

6 years ago

0.1.3

6 years ago

0.1.2

6 years ago

0.1.1

6 years ago

0.1.0

6 years ago