Giter Club home page Giter Club logo

module-plugin's Introduction

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

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.