Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Can this be implemented with Livewire #311

Closed
hussain-attari opened this issue Nov 25, 2021 · 21 comments
Closed

Can this be implemented with Livewire #311

hussain-attari opened this issue Nov 25, 2021 · 21 comments
Assignees
Labels
question Further information is requested

Comments

@hussain-attari
Copy link

Hi,

Trying to implement Drawflow in my Laravel+Livewire project.

Unable to get the desired results. In fact failing at the first attempt. I am sure I have missed a step or not doing it right. Could you show how its done or can it actually be done in a Livewire project.

Was planning to integrate Alpine JS later on to replace the vue code. But that is at a later stage. Currently just trying to get a mindmap functionality with Drawflow.

I have included the drawflow.min.css in my app.scss and drawflow.min.js in my app.js

Used the CDN links in my layouts.app
in the head
<link rel="stylesheet" href="https://cdn.jsdelivr.net/gh/jerosoler/Drawflow/dist/drawflow.min.css">

in the body
<script src="https://cdn.jsdelivr.net/gh/jerosoler/Drawflow/dist/drawflow.min.js"></script>

Created the blade file as this:


@extends('layouts.app')

@section('content')
    <section class="section">
        <div class="section-header">
            <h1 class="text-truncate">MindMap</h1>
        </div>
        <div class="section-body">
            <div class="row">
                <div class="drawflow col-3 mh-100 bg-primary text-white px-2 py-4">
                    <div class="drag-drawflow" draggable="true" ondragstart="drag(event)" data-node="facebook">
                        <i class="fab fa-facebook"></i><span> Facebook</span>
                    </div>
                </div>

                <div class="col-9 mh-100 bg-success text-black px-4 py-4">
                    <div id="drawflow" ondrop="drop(event)" ondragover="allowDrop(event)">
                        test
                    </div>
                </div>
            </div>
        </div>


        <script>
            var id = document.getElementById("drawflow");
        const editor = new Drawflow(facebook);
        editor.reroute = true;
        editor.drawflow = {"drawflow":{"Home":{"data":{"1":{"id":1,"name":"welcome","data":{},"class":"welcome","html":"\n    <div>\n      <div class=\"title-box\">👏 Welcome!!</div>\n      <div class=\"box\">\n        <p>Simple flow library <b>demo</b>\n        <a href=\"https://github.com/jerosoler/Drawflow\" target=\"_blank\">Drawflow</a> by <b>Jero Soler</b></p><br>\n\n        <p>Multiple input / outputs<br>\n           Data sync nodes<br>\n           Import / export<br>\n           Modules support<br>\n           Simple use<br>\n           Type: Fixed or Edit<br>\n           Events: view console<br>\n           Pure Javascript<br>\n        </p>\n        <br>\n        <p><b><u>Shortkeys:</u></b></p>\n        <p>🎹 <b>Delete</b> for remove selected<br>\n        💠 Mouse Left Click == Move<br>\n        ❌ Mouse Right == Delete Option<br>\n        🔍 Ctrl + Wheel == Zoom<br>\n        📱 Mobile support<br>\n        ...</p>\n      </div>\n    </div>\n    ","typenode": false, "inputs":{},"outputs":{},"pos_x":50,"pos_y":50},"2":{"id":2,"name":"slack","data":{},"class":"slack","html":"\n          <div>\n            <div class=\"title-box\"><i class=\"fab fa-slack\"></i> Slack chat message</div>\n          </div>\n          ","typenode": false, "inputs":{"input_1":{"connections":[{"node":"7","input":"output_1"}]}},"outputs":{},"pos_x":1028,"pos_y":87},"3":{"id":3,"name":"telegram","data":{"channel":"channel_2"},"class":"telegram","html":"\n          <div>\n            <div class=\"title-box\"><i class=\"fab fa-telegram-plane\"></i> Telegram bot</div>\n            <div class=\"box\">\n              <p>Send to telegram</p>\n              <p>select channel</p>\n              <select df-channel>\n                <option value=\"channel_1\">Channel 1</option>\n                <option value=\"channel_2\">Channel 2</option>\n                <option value=\"channel_3\">Channel 3</option>\n                <option value=\"channel_4\">Channel 4</option>\n              </select>\n            </div>\n          </div>\n          ","typenode": false, "inputs":{"input_1":{"connections":[{"node":"7","input":"output_1"}]}},"outputs":{},"pos_x":1032,"pos_y":184},"4":{"id":4,"name":"email","data":{},"class":"email","html":"\n            <div>\n              <div class=\"title-box\"><i class=\"fas fa-at\"></i> Send Email </div>\n            </div>\n            ","typenode": false, "inputs":{"input_1":{"connections":[{"node":"5","input":"output_1"}]}},"outputs":{},"pos_x":1033,"pos_y":439},"5":{"id":5,"name":"template","data":{"template":"Write your template"},"class":"template","html":"\n            <div>\n              <div class=\"title-box\"><i class=\"fas fa-code\"></i> Template</div>\n              <div class=\"box\">\n                Ger Vars\n                <textarea df-template></textarea>\n                Output template with vars\n              </div>\n            </div>\n            ","typenode": false, "inputs":{"input_1":{"connections":[{"node":"6","input":"output_1"}]}},"outputs":{"output_1":{"connections":[{"node":"4","output":"input_1"},{"node":"11","output":"input_1"}]}},"pos_x":607,"pos_y":304},"6":{"id":6,"name":"github","data":{"name":"https://github.com/jerosoler/Drawflow"},"class":"github","html":"\n          <div>\n            <div class=\"title-box\"><i class=\"fab fa-github \"></i> Github Stars</div>\n            <div class=\"box\">\n              <p>Enter repository url</p>\n            <input type=\"text\" df-name>\n            </div>\n          </div>\n          ","typenode": false, "inputs":{},"outputs":{"output_1":{"connections":[{"node":"5","output":"input_1"}]}},"pos_x":341,"pos_y":191},"7":{"id":7,"name":"facebook","data":{},"class":"facebook","html":"\n        <div>\n          <div class=\"title-box\"><i class=\"fab fa-facebook\"></i> Facebook Message</div>\n        </div>\n        ","typenode": false, "inputs":{},"outputs":{"output_1":{"connections":[{"node":"2","output":"input_1"},{"node":"3","output":"input_1"},{"node":"11","output":"input_1"}]}},"pos_x":347,"pos_y":87},"11":{"id":11,"name":"log","data":{},"class":"log","html":"\n            <div>\n              <div class=\"title-box\"><i class=\"fas fa-file-signature\"></i> Save log file </div>\n            </div>\n            ","typenode": false, "inputs":{"input_1":{"connections":[{"node":"5","input":"output_1"},{"node":"7","input":"output_1"}]}},"outputs":{},"pos_x":1031,"pos_y":363}}},"Other":{"data":{"8":{"id":8,"name":"personalized","data":{},"class":"personalized","html":"\n            <div>\n              Personalized\n            </div>\n            ","typenode": false, "inputs":{"input_1":{"connections":[{"node":"12","input":"output_1"},{"node":"12","input":"output_2"},{"node":"12","input":"output_3"},{"node":"12","input":"output_4"}]}},"outputs":{"output_1":{"connections":[{"node":"9","output":"input_1"}]}},"pos_x":764,"pos_y":227},"9":{"id":9,"name":"dbclick","data":{"name":"Hello World!!"},"class":"dbclick","html":"\n            <div>\n            <div class=\"title-box\"><i class=\"fas fa-mouse\"></i> Db Click</div>\n              <div class=\"box dbclickbox\" ondblclick=\"showpopup(event)\">\n                Db Click here\n                <div class=\"modal\" style=\"display:none\">\n                  <div class=\"modal-content\">\n                    <span class=\"close\" onclick=\"closemodal(event)\">&times;</span>\n                    Change your variable {name} !\n                    <input type=\"text\" df-name>\n                  </div>\n\n                </div>\n              </div>\n            </div>\n            ","typenode": false, "inputs":{"input_1":{"connections":[{"node":"8","input":"output_1"}]}},"outputs":{"output_1":{"connections":[{"node":"12","output":"input_2"}]}},"pos_x":209,"pos_y":38},"12":{"id":12,"name":"multiple","data":{},"class":"multiple","html":"\n            <div>\n              <div class=\"box\">\n                Multiple!\n              </div>\n            </div>\n            ","typenode": false, "inputs":{"input_1":{"connections":[]},"input_2":{"connections":[{"node":"9","input":"output_1"}]},"input_3":{"connections":[]}},"outputs":{"output_1":{"connections":[{"node":"8","output":"input_1"}]},"output_2":{"connections":[{"node":"8","output":"input_1"}]},"output_3":{"connections":[{"node":"8","output":"input_1"}]},"output_4":{"connections":[{"node":"8","output":"input_1"}]}},"pos_x":179,"pos_y":272}}}}}
        editor.start();

        /* DRAG EVENT */

        /* Mouse and Touch Actions */

        var elements = document.getElementsByClassName('drag-drawflow');
        for (var i = 0; i < elements.length; i++) {
        elements[i].addEventListener('touchend', drop, false);
        elements[i].addEventListener('touchmove', positionMobile, false);
        elements[i].addEventListener('touchstart', drag, false );
        }

        var mobile_item_selec = '';
        var mobile_last_move = null;
        function positionMobile(ev) {
        mobile_last_move = event;
        }

        function allowDrop(ev) {
        ev.preventDefault();
        }

        function drag(ev) {
        if (ev.type === "touchstart") {
            mobile_item_selec = ev.target.closest(".drag-drawflow").getAttribute('data-node');
        } else {
        ev.dataTransfer.setData("node", ev.target.getAttribute('data-node'));
        }
        }

        function drop(ev) {
        if (ev.type === "touchend") {
            var parentdrawflow = document.elementFromPoint( mobile_last_move.touches[0].clientX, mobile_last_move.touches[0].clientY).closest("#drawflow");
            if(parentdrawflow != null) {
            addNodeToDrawFlow(mobile_item_selec, mobile_last_move.touches[0].clientX, mobile_last_move.touches[0].clientY);
            }
            mobile_item_selec = '';
        } else {
            ev.preventDefault();
            var data = ev.dataTransfer.getData("node");
            addNodeToDrawFlow(data, ev.clientX, ev.clientY);
        }

        }

        function addNodeToDrawFlow(name, pos_x, pos_y) {
        if(editor.editor_mode === 'fixed') {
            return false;
        }
        pos_x = pos_x * ( editor.precanvas.clientWidth / (editor.precanvas.clientWidth * editor.zoom)) - (editor.precanvas.getBoundingClientRect().x * ( editor.precanvas.clientWidth / (editor.precanvas.clientWidth * editor.zoom)));
        pos_y = pos_y * ( editor.precanvas.clientHeight / (editor.precanvas.clientHeight * editor.zoom)) - (editor.precanvas.getBoundingClientRect().y * ( editor.precanvas.clientHeight / (editor.precanvas.clientHeight * editor.zoom)));

        switch (name) {
                case 'facebook':
                var facebook = `
                <div>
                  <div class="title-box"><i class="fab fa-facebook"></i> Facebook Message</div>
                </div>
                `;
                  editor.addNode('facebook', 0,  1, pos_x, pos_y, 'facebook', {}, facebook );
                  break;
                case 'slack':
                  var slackchat = `
                  <div>
                    <div class="title-box"><i class="fab fa-slack"></i> Slack chat message</div>
                  </div>
                  `
                  editor.addNode('slack', 1, 0, pos_x, pos_y, 'slack', {}, slackchat );
                  break;
                case 'github':
                  var githubtemplate = `
                  <div>
                    <div class="title-box"><i class="fab fa-github "></i> Github Stars</div>
                    <div class="box">
                      <p>Enter repository url</p>
                    <input type="text" df-name>
                    </div>
                  </div>
                  `;
                  editor.addNode('github', 0, 1, pos_x, pos_y, 'github', { "name": ''}, githubtemplate );
                  break;
                case 'telegram':
                  var telegrambot = `
                  <div>
                    <div class="title-box"><i class="fab fa-telegram-plane"></i> Telegram bot</div>
                    <div class="box">
                      <p>Send to telegram</p>
                      <p>select channel</p>
                      <select df-channel>
                        <option value="channel_1">Channel 1</option>
                        <option value="channel_2">Channel 2</option>
                        <option value="channel_3">Channel 3</option>
                        <option value="channel_4">Channel 4</option>
                      </select>
                    </div>
                  </div>
                  `;
                  editor.addNode('telegram', 1, 0, pos_x, pos_y, 'telegram', { "channel": 'channel_3'}, telegrambot );
                  break;
                case 'aws':
                  var aws = `
                  <div>
                    <div class="title-box"><i class="fab fa-aws"></i> Aws Save </div>
                    <div class="box">
                      <p>Save in aws</p>
                      <input type="text" df-db-dbname placeholder="DB name"><br><br>
                      <input type="text" df-db-key placeholder="DB key">
                      <p>Output Log</p>
                    </div>
                  </div>
                  `;
                  editor.addNode('aws', 1, 1, pos_x, pos_y, 'aws', { "db": { "dbname": '', "key": '' }}, aws );
                  break;
                case 'log':
                    var log = `
                    <div>
                      <div class="title-box"><i class="fas fa-file-signature"></i> Save log file </div>
                    </div>
                    `;
                    editor.addNode('log', 1, 0, pos_x, pos_y, 'log', {}, log );
                    break;
                  case 'google':
                    var google =
                    <div>
                      <div class="title-box"><i class="fab fa-google-drive"></i> Google Drive save </div>
                    </div>
                    ;
                    editor.addNode('google', 1, 0, pos_x, pos_y, 'google', {}, google );
                    break;
                  case 'email':
                    var email = 
                    <div>
                      <div class="title-box"><i class="fas fa-at"></i> Send Email </div>
                    </div>
                    ;
                    editor.addNode('email', 1, 0, pos_x, pos_y, 'email', {}, email );
                    break;

                  case 'template':
                    var template =
                    <div>
                      <div class="title-box"><i class="fas fa-code"></i> Template</div>
                      <div class="box">
                        Ger Vars
                        <textarea df-template></textarea>
                        Output template with vars
                      </div>
                    </div>
                    ;
                    editor.addNode('template', 1, 1, pos_x, pos_y, 'template', { "template": 'Write your template'}, template );
                    break;
                  case 'multiple':
                    var multiple =
                    <div>
                      <div class="box">
                        Multiple!
                      </div>
                    </div>
                    ;
                    editor.addNode('multiple', 3, 4, pos_x, pos_y, 'multiple', {}, multiple );
                    break;
                  case 'personalized':
                    var personalized =
                    <div>
                      Personalized
                    </div>
                    ;
                    editor.addNode('personalized', 1, 1, pos_x, pos_y, 'personalized', {}, personalized );
                    break;
                  case 'dbclick':
                    var dbclick = `
                    <div>
                    <div class="title-box"><i class="fas fa-mouse"></i> Db Click</div>
                      <div class="box dbclickbox" ondblclick="showpopup(event)">
                        Db Click here
                        <div class="modal" style="display:none">
                          <div class="modal-content">
                            <span class="close" onclick="closemodal(event)">&times;</span>
                            Change your variable {name} !
                            <input type="text" df-name>
                          </div>

                        </div>
                      </div>
                    </div>
                    `;
                    editor.addNode('dbclick', 1, 1, pos_x, pos_y, 'dbclick', { name: ''}, dbclick );
                    break;

                default:
            }
        }

        </script>
    </section>
@endsection

This is the Console error that I get in Firefox
Uncaught ReferenceError: Drawflow is not defined <anonymous> http://127.0.0.1:8000/mindmap:112

Get this error on launching the page

And, get this error on trying to drag

Uncaught ReferenceError: drag is not defined
    ondragstart http://127.0.0.1:8000/mindmap:1
@jerosoler
Copy link
Owner

I don't know livewire.
But I see some problems in the code.

Your code, facebook???

     var id = document.getElementById("drawflow");
        const editor = new Drawflow(facebook);

Change for:

     var id = document.getElementById("drawflow");
        const editor = new Drawflow(id);

Add to head or before your script.

<script src="https://cdn.jsdelivr.net/gh/jerosoler/Drawflow/dist/drawflow.min.js"></script>

Add to style do drawflow div

 #drawflow {
    position: relative;
    text-align:initial;
    width: 800px;
    height:800px;
}

@jerosoler jerosoler self-assigned this Nov 25, 2021
@jerosoler jerosoler added the question Further information is requested label Nov 25, 2021
@hussain-attari
Copy link
Author

Don't need the Facebook in particular I used that to for testing.

I only require the 'Template' but in various styles.

Will include your suggestions and post the results here.

@hussain-attari
Copy link
Author

Included your suggestions however no luck;

Here is the complete Drawflow CSS file:


.drawflow,
.drawflow .parent-node {
    position: relative
}

.parent-drawflow {
    display: flex;
    overflow: hidden;
    touch-action: none;
    outline: 0
}

.drawflow {
    position: relative;
    text-align: initial;
    width: 100%;
    height: 100%;
    user-select: none;
    perspective: 0
}

.drawflow .drawflow-node {
    display: flex;
    align-items: center;
    position: absolute;
    background: #0ff;
    width: 160px;
    min-height: 40px;
    border-radius: 4px;
    border: 2px solid #000;
    color: #000;
    z-index: 2;
    padding: 15px
}

.drawflow .drawflow-node.selected {
    background: red
}

.drawflow .drawflow-node:hover {
    cursor: move
}

.drawflow .drawflow-node .inputs,
.drawflow .drawflow-node .outputs {
    width: 0
}

.drawflow .drawflow-node .drawflow_content_node {
    width: 100%;
    display: block
}

.drawflow .drawflow-node .input,
.drawflow .drawflow-node .output {
    position: relative;
    width: 20px;
    height: 20px;
    background: #fff;
    border-radius: 50%;
    border: 2px solid #000;
    cursor: crosshair;
    z-index: 1;
    margin-bottom: 5px
}

.drawflow .drawflow-node .input {
    left: -27px;
    top: 2px;
    background: #ff0
}

.drawflow .drawflow-node .output {
    right: -3px;
    top: 2px
}

.drawflow svg {
    z-index: 0;
    position: absolute;
    overflow: visible !important
}

.drawflow .connection {
    position: absolute;
    pointer-events: none
}

.drawflow .connection .main-path {
    fill: none;
    stroke-width: 5px;
    stroke: #4682b4;
    pointer-events: all
}

.drawflow .connection .main-path:hover {
    stroke: #1266ab;
    cursor: pointer
}

.drawflow .connection .main-path.selected {
    stroke: #43b993
}

.drawflow .connection .point {
    cursor: move;
    stroke: #000;
    stroke-width: 2;
    fill: #fff;
    pointer-events: all
}

.drawflow .connection .point.selected,
.drawflow .connection .point:hover {
    fill: #1266ab
}

.drawflow .main-path {
    fill: none;
    stroke-width: 5px;
    stroke: #4682b4
}

.drawflow-delete {
    position: absolute;
    display: block;
    width: 30px;
    height: 30px;
    background: #000;
    color: #fff;
    z-index: 4;
    border: 2px solid #fff;
    line-height: 30px;
    font-weight: 700;
    text-align: center;
    border-radius: 50%;
    font-family: monospace;
    cursor: pointer
}

.drawflow>.drawflow-delete {
    margin-left: -15px;
    margin-top: 15px
}

.parent-node .drawflow-delete {
    right: -15px;
    top: -15px
}

Included the <script src="https://cdn.jsdelivr.net/gh/jerosoler/Drawflow/dist/drawflow.min.js"></script> in the head tag

Here is the revised Layout file


@extends('layouts.app')

@section('content')
<section class="section">
    <div class="section-header">
        <h1 class="text-truncate">MindMap</h1>
    </div>
    <div class="section-body">
        <div class="row">
            <div class="drawflow col-3 mh-100 bg-primary text-white px-2 py-4">
                <div class="drag-drawflow" draggable="true" ondragstart="drag(event)" data-node="template">
                <i class="fas fa-code"></i><span> Template</span>
              </div>
            </div>

            <div class="col-9 mh-100 bg-success text-black px-4 py-4">
                <div id="drawflow" ondrop="drop(event)" ondragover="allowDrop(event)">
                    test
                </div>
            </div>
        </div>
    </div>

    <script>
        var id = document.getElementById("drawflow");
        const editor = new Drawflow(facebook);
        editor.reroute = true;
        editor.drawflow = {
            "drawflow": {
                "Home": {
                    "data": {
                        "1": {
                            "id": 1
                            , "name": "welcome"
                            , "data": {}
                            , "class": "welcome"
                            , "html": "\n    <div>\n      <div class=\"title-box\">👏 Welcome!!</div>\n      <div class=\"box\">\n        <p>Simple flow library <b>demo</b>\n        <a href=\"https://github.com/jerosoler/Drawflow\" target=\"_blank\">Drawflow</a> by <b>Jero Soler</b></p><br>\n\n        <p>Multiple input / outputs<br>\n           Data sync nodes<br>\n           Import / export<br>\n           Modules support<br>\n           Simple use<br>\n           Type: Fixed or Edit<br>\n           Events: view console<br>\n           Pure Javascript<br>\n        </p>\n        <br>\n        <p><b><u>Shortkeys:</u></b></p>\n        <p>🎹 <b>Delete</b> for remove selected<br>\n        💠 Mouse Left Click == Move<br>\n        ❌ Mouse Right == Delete Option<br>\n        🔍 Ctrl + Wheel == Zoom<br>\n        📱 Mobile support<br>\n        ...</p>\n      </div>\n    </div>\n    "
                            , "typenode": false
                            , "inputs": {}
                            , "outputs": {}
                            , "pos_x": 50
                            , "pos_y": 50
                        }
                        , "2": {
                            "id": 2
                            , "name": "slack"
                            , "data": {}
                            , "class": "slack"
                            , "html": "\n          <div>\n            <div class=\"title-box\"><i class=\"fab fa-slack\"></i> Slack chat message</div>\n          </div>\n          "
                            , "typenode": false
                            , "inputs": {
                                "input_1": {
                                    "connections": [{
                                        "node": "7"
                                        , "input": "output_1"
                                    }]
                                }
                            }
                            , "outputs": {}
                            , "pos_x": 1028
                            , "pos_y": 87
                        }
                        , "3": {
                            "id": 3
                            , "name": "telegram"
                            , "data": {
                                "channel": "channel_2"
                            }
                            , "class": "telegram"
                            , "html": "\n          <div>\n            <div class=\"title-box\"><i class=\"fab fa-telegram-plane\"></i> Telegram bot</div>\n            <div class=\"box\">\n              <p>Send to telegram</p>\n              <p>select channel</p>\n              <select df-channel>\n                <option value=\"channel_1\">Channel 1</option>\n                <option value=\"channel_2\">Channel 2</option>\n                <option value=\"channel_3\">Channel 3</option>\n                <option value=\"channel_4\">Channel 4</option>\n              </select>\n            </div>\n          </div>\n          "
                            , "typenode": false
                            , "inputs": {
                                "input_1": {
                                    "connections": [{
                                        "node": "7"
                                        , "input": "output_1"
                                    }]
                                }
                            }
                            , "outputs": {}
                            , "pos_x": 1032
                            , "pos_y": 184
                        }
                        , "4": {
                            "id": 4
                            , "name": "email"
                            , "data": {}
                            , "class": "email"
                            , "html": "\n            <div>\n              <div class=\"title-box\"><i class=\"fas fa-at\"></i> Send Email </div>\n            </div>\n            "
                            , "typenode": false
                            , "inputs": {
                                "input_1": {
                                    "connections": [{
                                        "node": "5"
                                        , "input": "output_1"
                                    }]
                                }
                            }
                            , "outputs": {}
                            , "pos_x": 1033
                            , "pos_y": 439
                        }
                        , "5": {
                            "id": 5
                            , "name": "template"
                            , "data": {
                                "template": "Write your template"
                            }
                            , "class": "template"
                            , "html": "\n            <div>\n              <div class=\"title-box\"><i class=\"fas fa-code\"></i> Template</div>\n              <div class=\"box\">\n                Ger Vars\n                <textarea df-template></textarea>\n                Output template with vars\n              </div>\n            </div>\n            "
                            , "typenode": false
                            , "inputs": {
                                "input_1": {
                                    "connections": [{
                                        "node": "6"
                                        , "input": "output_1"
                                    }]
                                }
                            }
                            , "outputs": {
                                "output_1": {
                                    "connections": [{
                                        "node": "4"
                                        , "output": "input_1"
                                    }, {
                                        "node": "11"
                                        , "output": "input_1"
                                    }]
                                }
                            }
                            , "pos_x": 607
                            , "pos_y": 304
                        }
                        , "6": {
                            "id": 6
                            , "name": "github"
                            , "data": {
                                "name": "https://github.com/jerosoler/Drawflow"
                            }
                            , "class": "github"
                            , "html": "\n          <div>\n            <div class=\"title-box\"><i class=\"fab fa-github \"></i> Github Stars</div>\n            <div class=\"box\">\n              <p>Enter repository url</p>\n            <input type=\"text\" df-name>\n            </div>\n          </div>\n          "
                            , "typenode": false
                            , "inputs": {}
                            , "outputs": {
                                "output_1": {
                                    "connections": [{
                                        "node": "5"
                                        , "output": "input_1"
                                    }]
                                }
                            }
                            , "pos_x": 341
                            , "pos_y": 191
                        }
                        , "7": {
                            "id": 7
                            , "name": "facebook"
                            , "data": {}
                            , "class": "facebook"
                            , "html": "\n        <div>\n          <div class=\"title-box\"><i class=\"fab fa-facebook\"></i> Facebook Message</div>\n        </div>\n        "
                            , "typenode": false
                            , "inputs": {}
                            , "outputs": {
                                "output_1": {
                                    "connections": [{
                                        "node": "2"
                                        , "output": "input_1"
                                    }, {
                                        "node": "3"
                                        , "output": "input_1"
                                    }, {
                                        "node": "11"
                                        , "output": "input_1"
                                    }]
                                }
                            }
                            , "pos_x": 347
                            , "pos_y": 87
                        }
                        , "11": {
                            "id": 11
                            , "name": "log"
                            , "data": {}
                            , "class": "log"
                            , "html": "\n            <div>\n              <div class=\"title-box\"><i class=\"fas fa-file-signature\"></i> Save log file </div>\n            </div>\n            "
                            , "typenode": false
                            , "inputs": {
                                "input_1": {
                                    "connections": [{
                                        "node": "5"
                                        , "input": "output_1"
                                    }, {
                                        "node": "7"
                                        , "input": "output_1"
                                    }]
                                }
                            }
                            , "outputs": {}
                            , "pos_x": 1031
                            , "pos_y": 363
                        }
                    }
                }
                , "Other": {
                    "data": {
                        "8": {
                            "id": 8
                            , "name": "personalized"
                            , "data": {}
                            , "class": "personalized"
                            , "html": "\n            <div>\n              Personalized\n            </div>\n            "
                            , "typenode": false
                            , "inputs": {
                                "input_1": {
                                    "connections": [{
                                        "node": "12"
                                        , "input": "output_1"
                                    }, {
                                        "node": "12"
                                        , "input": "output_2"
                                    }, {
                                        "node": "12"
                                        , "input": "output_3"
                                    }, {
                                        "node": "12"
                                        , "input": "output_4"
                                    }]
                                }
                            }
                            , "outputs": {
                                "output_1": {
                                    "connections": [{
                                        "node": "9"
                                        , "output": "input_1"
                                    }]
                                }
                            }
                            , "pos_x": 764
                            , "pos_y": 227
                        }
                        , "9": {
                            "id": 9
                            , "name": "dbclick"
                            , "data": {
                                "name": "Hello World!!"
                            }
                            , "class": "dbclick"
                            , "html": "\n            <div>\n            <div class=\"title-box\"><i class=\"fas fa-mouse\"></i> Db Click</div>\n              <div class=\"box dbclickbox\" ondblclick=\"showpopup(event)\">\n                Db Click here\n                <div class=\"modal\" style=\"display:none\">\n                  <div class=\"modal-content\">\n                    <span class=\"close\" onclick=\"closemodal(event)\">&times;</span>\n                    Change your variable {name} !\n                    <input type=\"text\" df-name>\n                  </div>\n\n                </div>\n              </div>\n            </div>\n            "
                            , "typenode": false
                            , "inputs": {
                                "input_1": {
                                    "connections": [{
                                        "node": "8"
                                        , "input": "output_1"
                                    }]
                                }
                            }
                            , "outputs": {
                                "output_1": {
                                    "connections": [{
                                        "node": "12"
                                        , "output": "input_2"
                                    }]
                                }
                            }
                            , "pos_x": 209
                            , "pos_y": 38
                        }
                        , "12": {
                            "id": 12
                            , "name": "multiple"
                            , "data": {}
                            , "class": "multiple"
                            , "html": "\n            <div>\n              <div class=\"box\">\n                Multiple!\n              </div>\n            </div>\n            "
                            , "typenode": false
                            , "inputs": {
                                "input_1": {
                                    "connections": []
                                }
                                , "input_2": {
                                    "connections": [{
                                        "node": "9"
                                        , "input": "output_1"
                                    }]
                                }
                                , "input_3": {
                                    "connections": []
                                }
                            }
                            , "outputs": {
                                "output_1": {
                                    "connections": [{
                                        "node": "8"
                                        , "output": "input_1"
                                    }]
                                }
                                , "output_2": {
                                    "connections": [{
                                        "node": "8"
                                        , "output": "input_1"
                                    }]
                                }
                                , "output_3": {
                                    "connections": [{
                                        "node": "8"
                                        , "output": "input_1"
                                    }]
                                }
                                , "output_4": {
                                    "connections": [{
                                        "node": "8"
                                        , "output": "input_1"
                                    }]
                                }
                            }
                            , "pos_x": 179
                            , "pos_y": 272
                        }
                    }
                }
            }
        }
        editor.start();

        /* DRAG EVENT */

        /* Mouse and Touch Actions */

        var elements = document.getElementsByClassName('drag-drawflow');
        for (var i = 0; i < elements.length; i++) {
            elements[i].addEventListener('touchend', drop, false);
            elements[i].addEventListener('touchmove', positionMobile, false);
            elements[i].addEventListener('touchstart', drag, false);
        }

        var mobile_item_selec = '';
        var mobile_last_move = null;

        function positionMobile(ev) {
            mobile_last_move = event;
        }

        function allowDrop(ev) {
            ev.preventDefault();
        }

        function drag(ev) {
            if (ev.type === "touchstart") {
                mobile_item_selec = ev.target.closest(".drag-drawflow").getAttribute('data-node');
            } else {
                ev.dataTransfer.setData("node", ev.target.getAttribute('data-node'));
            }
        }

        function drop(ev) {
            if (ev.type === "touchend") {
                var parentdrawflow = document.elementFromPoint(mobile_last_move.touches[0].clientX, mobile_last_move.touches[0].clientY).closest("#drawflow");
                if (parentdrawflow != null) {
                    addNodeToDrawFlow(mobile_item_selec, mobile_last_move.touches[0].clientX, mobile_last_move.touches[0].clientY);
                }
                mobile_item_selec = '';
            } else {
                ev.preventDefault();
                var data = ev.dataTransfer.getData("node");
                addNodeToDrawFlow(data, ev.clientX, ev.clientY);
            }

        }

        function addNodeToDrawFlow(name, pos_x, pos_y) {
            if (editor.editor_mode === 'fixed') {
                return false;
            }
            pos_x = pos_x * (editor.precanvas.clientWidth / (editor.precanvas.clientWidth * editor.zoom)) - (editor.precanvas.getBoundingClientRect().x * (editor.precanvas.clientWidth / (editor.precanvas.clientWidth * editor.zoom)));
            pos_y = pos_y * (editor.precanvas.clientHeight / (editor.precanvas.clientHeight * editor.zoom)) - (editor.precanvas.getBoundingClientRect().y * (editor.precanvas.clientHeight / (editor.precanvas.clientHeight * editor.zoom)));

            switch (name) {
                case 'facebook':
                    var facebook = `
                <div>
                  <div class="title-box"><i class="fab fa-facebook"></i> Facebook Message</div>
                </div>
                `;
                    editor.addNode('facebook', 0, 1, pos_x, pos_y, 'facebook', {}, facebook);
                    break;
                case 'slack':
                    var slackchat = `
                  <div>
                    <div class="title-box"><i class="fab fa-slack"></i> Slack chat message</div>
                  </div>
                  `
                    editor.addNode('slack', 1, 0, pos_x, pos_y, 'slack', {}, slackchat);
                    break;
                case 'github':
                    var githubtemplate = `
                  <div>
                    <div class="title-box"><i class="fab fa-github "></i> Github Stars</div>
                    <div class="box">
                      <p>Enter repository url</p>
                    <input type="text" df-name>
                    </div>
                  </div>
                  `;
                    editor.addNode('github', 0, 1, pos_x, pos_y, 'github', {
                        "name": ''
                    }, githubtemplate);
                    break;
                case 'telegram':
                    var telegrambot = `
                  <div>
                    <div class="title-box"><i class="fab fa-telegram-plane"></i> Telegram bot</div>
                    <div class="box">
                      <p>Send to telegram</p>
                      <p>select channel</p>
                      <select df-channel>
                        <option value="channel_1">Channel 1</option>
                        <option value="channel_2">Channel 2</option>
                        <option value="channel_3">Channel 3</option>
                        <option value="channel_4">Channel 4</option>
                      </select>
                    </div>
                  </div>
                  `;
                    editor.addNode('telegram', 1, 0, pos_x, pos_y, 'telegram', {
                        "channel": 'channel_3'
                    }, telegrambot);
                    break;
                case 'aws':
                    var aws = `
                  <div>
                    <div class="title-box"><i class="fab fa-aws"></i> Aws Save </div>
                    <div class="box">
                      <p>Save in aws</p>
                      <input type="text" df-db-dbname placeholder="DB name"><br><br>
                      <input type="text" df-db-key placeholder="DB key">
                      <p>Output Log</p>
                    </div>
                  </div>
                  `;
                    editor.addNode('aws', 1, 1, pos_x, pos_y, 'aws', {
                        "db": {
                            "dbname": ''
                            , "key": ''
                        }
                    }, aws);
                    break;
                case 'log':
                    var log = `
                    <div>
                      <div class="title-box"><i class="fas fa-file-signature"></i> Save log file </div>
                    </div>
                    `;
                    editor.addNode('log', 1, 0, pos_x, pos_y, 'log', {}, log);
                    break;
                case 'google':
                    var google =
                        <div>
                      <div class="title-box"><i class="fab fa-google-drive"></i> Google Drive save </div>
                    </div>;
                    editor.addNode('google', 1, 0, pos_x, pos_y, 'google', {}, google);
                    break;
                case 'email':
                    var email =
                        <div>
                      <div class="title-box"><i class="fas fa-at"></i> Send Email </div>
                    </div>;
                    editor.addNode('email', 1, 0, pos_x, pos_y, 'email', {}, email);
                    break;

                case 'template':
                    var template =
                        <div>
                      <div class="title-box"><i class="fas fa-code"></i> Template</div>
                      <div class="box">
                        Ger Vars
                        <textarea df-template></textarea>
                        Output template with vars
                      </div>
                    </div>;
                    editor.addNode('template', 1, 1, pos_x, pos_y, 'template', {
                        "template": 'Write your template'
                    }, template);
                    break;
                case 'multiple':
                    var multiple =
                        <div>
                      <div class="box">
                        Multiple!
                      </div>
                    </div>;
                    editor.addNode('multiple', 3, 4, pos_x, pos_y, 'multiple', {}, multiple);
                    break;
                case 'personalized':
                    var personalized =
                        <div>
                      Personalized
                    </div>;
                    editor.addNode('personalized', 1, 1, pos_x, pos_y, 'personalized', {}, personalized);
                    break;
                case 'dbclick':
                    var dbclick = `
                    <div>
                    <div class="title-box"><i class="fas fa-mouse"></i> Db Click</div>
                      <div class="box dbclickbox" ondblclick="showpopup(event)">
                        Db Click here
                        <div class="modal" style="display:none">
                          <div class="modal-content">
                            <span class="close" onclick="closemodal(event)">&times;</span>
                            Change your variable {name} !
                            <input type="text" df-name>
                          </div>

                        </div>
                      </div>
                    </div>
                    `;
                    editor.addNode('dbclick', 1, 1, pos_x, pos_y, 'dbclick', {
                        name: ''
                    }, dbclick);
                    break;

                default:
            }
        }

    </script>
</section>
@endsection

Still getting this error on page load
Uncaught SyntaxError: expected expression, got '<'

And, this error on drag

Uncaught ReferenceError: drag is not defined
    ondragstart http://127.0.0.1:8000/mindmap:1

Can I remove the huge chunk of code and start with the basics? what do I need to do?

Just drag a div from the left-hand side to right-hand side. And, then build up further by dragging multiple divs and connecting the nodes to them.

Probably will be able to rectify my error in that manner.

@jerosoler
Copy link
Owner

This line:

Uncaught SyntaxError: expected expression, got '<'

It tells you that you have an error in the code.

I see this has not changed:

     var id = document.getElementById("drawflow");
        const editor = new Drawflow(facebook);

For:

     var id = document.getElementById("drawflow");
        const editor = new Drawflow(id);

View a simple example in html file:

<!DOCTYPE html>
<html lang="en">
<head>
  <meta charset="UTF-8">
  <meta name="viewport" content="width=device-width, initial-scale=1.0">
  <meta http-equiv="X-UA-Compatible" content="ie=edge">
  <title>Document</title>
  <link rel="stylesheet" href="https://cdn.jsdelivr.net/gh/jerosoler/Drawflow/dist/drawflow.min.css"/>
  <script src="https://cdn.jsdelivr.net/gh/jerosoler/Drawflow/dist/drawflow.min.js"></script>
</head>
<body>
<div id="drawflow"></div>
  <style>
    #drawflow { 
      position: relative;
      text-align:initial;
      width: 100%;
      height: 800px;
      border: 1px solid red;
    }
</style>
<script>
    var id = document.getElementById("drawflow");
    const editor = new Drawflow(id);
    editor.start();

    editor.addNode('aaa', 0, 1, 100, 300, 'aaa', {}, 'aaa' );
    editor.addNode('bbb', 1, 0, 200, 400, 'bbb', {}, 'bbb' );
    editor.addNode('ccc', 1, 0, 500, 500, 'ccc', {}, 'ccc' );
</script>
</body>
</html>

@hussain-attari
Copy link
Author

Okay, the sample code works perfectly fine! Thanks.

Will play around with creating my custom divs and post here if required.

Thanks once again.

@hussain-attari
Copy link
Author

Where do I customise these?

editor.addNode('aaa', 0, 1, 100, 300, 'aaa', {}, 'aaa' );

Also is there a right click functionality to add nodes? Instead of drag drop

@jerosoler
Copy link
Owner

You can customise with class (6 parameter)

editor.addNode(name, inputs, outputs, posx, posy, class, data, html);

There is no context menu. But you can develop an example here with a node. #187 (comment)

@hussain-attari
Copy link
Author

Hi,

I created a test text node by using this code

var html = '<div><input type="text" df-text></div>';
        var data = {"text": ''};
        editor.addNode('text', 1, 1, 75, 175, 'text', data, html );

However, the text box overflows the node div.

Also, I inserted editor.line_path = 1; before editor.start() but the thickness of the line doesn't change.

What I am trying to achieve is something similar to the Template node with custom colors and layout.

How do I achieve this?

@jerosoler
Copy link
Owner

For the line connection try css:

.drawflow .connection .main-path {
      stroke-width: 1px;
    }

You just have to modify css to adapt the theme.
We also have a theme generator to generate the css for you.
https://jerosoler.github.io/drawflow-theme-generator/

@hussain-attari
Copy link
Author

I used the Theme Generator to create a custom style and added it to my app.css.

However, the only thing that changed is the size of the node div and nothing else.

So i did the following:
Removed
<link rel="stylesheet" href="https://cdn.jsdelivr.net/gh/jerosoler/Drawflow/dist/drawflow.min.css"/>

and added the stylesheet for custom theme
<link rel="stylesheet" href="{{ asset('css/_drawflow') }}">

The theme and color scheme were updated however it messed up the layout completely.

@jerosoler
Copy link
Owner

You don't have to remove the drawflow.min.css.

@hussain-attari
Copy link
Author

Oops.

So I just append the customised theme code to the default drawflow.min.css?

@jerosoler
Copy link
Owner

<link rel="stylesheet" href="https://cdn.jsdelivr.net/gh/jerosoler/Drawflow/dist/drawflow.min.css"/>
<link rel="stylesheet" href="YOUR CSS FILE"/>

You will also need to add the drawflow css.

 #drawflow { 
      position: relative;
      text-align:initial;
      width: 100%;
      height: 800px;
      border: 1px solid red;
    }

@hussain-attari
Copy link
Author

hussain-attari commented Nov 26, 2021

Have done this. However no luck.

The thing is that certain custom features are being shown but not all of them.

Like in the current scenario the hover style is being displayed however unable to override the Selected style, the node styles among others.

PS: Thank you for patiently replying to all my messages :-)

Edit: Yes I am adding the #drawflow as well to the code. Actually appending it to my custom theme generated code so it looks like this now:

#drawflow {
    background: var(--dfBackgroundColor);
    background-size: var(--dfBackgroundSize) var(--dfBackgroundSize);
    background-image: var(--dfBackgroundImage);
    position: relative;
    text-align: initial;
    width: 100%;
    height: 1000px;
    border: 1px solid black;
  }

@jerosoler
Copy link
Owner

In themas generator.
You also have to modify whether the node is hovered or selected.

@hussain-attari
Copy link
Author

Yes yes. I have customised the whole thing right to the delete button and copy pasted the generated code in my drawflow.css file.

But only the hover commands are working.

I have customised the Node Selected option but my custom theme doesn't show instead the default red color for selected node shows.

I shall copy paste my entire generated theme code if required.

@jerosoler
Copy link
Owner

Maybe the generator is some versions below. But I think you can see how the css is modified to customize it.

@hussain-attari
Copy link
Author

hussain-attari commented Nov 28, 2021

Hi,

I have tried the following things:

  • Using your original drawflow.min.css given in the dist folder of this package and updated the background-color
  • Used the theme generator
  • Used the theme generator code and edited only the selected node stylesheet by manually entering the color codes and custom layout.

None of these options work.

Here is my custom theme generated code from the Theme generator link

:root {
    --dfBackgroundColor: rgba(250, 253, 251, 1);
    --dfBackgroundSize: 0px;
    --dfBackgroundImage: none;

    --dfNodeType: flex;
    --dfNodeTypeFloat: none;
    --dfNodeBackgroundColor: rgba(255, 255, 255, 1);
    --dfNodeTextColor: rgba(0, 0, 0, 1);
    --dfNodeBorderSize: 1px;
    --dfNodeBorderColor: rgba(0, 0, 0, 1);
    --dfNodeBorderRadius: 4px;
    --dfNodeMinHeight: 35px;
    --dfNodeMinWidth: 210px;
    --dfNodePaddingTop: 15px;
    --dfNodePaddingBottom: 15px;
    --dfNodeBoxShadowHL: 0px;
    --dfNodeBoxShadowVL: 0px;
    --dfNodeBoxShadowBR: 0px;
    --dfNodeBoxShadowS: 0px;
    --dfNodeBoxShadowColor: #000000;

    --dfNodeHoverBackgroundColor: rgba(255, 255, 255, 1);
    --dfNodeHoverTextColor: #000000;
    --dfNodeHoverBorderSize: 2px;
    --dfNodeHoverBorderColor: rgba(0, 65, 208, 1);
    --dfNodeHoverBorderRadius: 4px;

    --dfNodeHoverBoxShadowHL: 0px;
    --dfNodeHoverBoxShadowVL: 0px;
    --dfNodeHoverBoxShadowBR: 0px;
    --dfNodeHoverBoxShadowS: 0px;
    --dfNodeHoverBoxShadowColor: #4ea9ff;

    --dfNodeSelectedBackgroundColor: rgba(207, 239, 250, 1);
    --dfNodeSelectedTextColor: rgba(0, 65, 208, 1);
    --dfNodeSelectedBorderSize: 1px;
    --dfNodeSelectedBorderColor: rgba(0, 65, 208, 1);
    --dfNodeSelectedBorderRadius: 4px;

    --dfNodeSelectedBoxShadowHL: 0px;
    --dfNodeSelectedBoxShadowVL: 2px;
    --dfNodeSelectedBoxShadowBR: 15px;
    --dfNodeSelectedBoxShadowS: 1px;
    --dfNodeSelectedBoxShadowColor: rgba(78, 169, 255, 0.5);

    --dfInputBackgroundColor: rgba(255, 255, 255, 1);
    --dfInputBorderSize: 1px;
    --dfInputBorderColor: #000000;
    --dfInputBorderRadius: 50px;
    --dfInputLeft: -24px;
    --dfInputHeight: 14px;
    --dfInputWidth: 14px;

    --dfInputHoverBackgroundColor: #ffffff;
    --dfInputHoverBorderSize: 2px;
    --dfInputHoverBorderColor: #000000;
    --dfInputHoverBorderRadius: 50px;

    --dfOutputBackgroundColor: rgba(255, 193, 7, 1);
    --dfOutputBorderSize: 1px;
    --dfOutputBorderColor: #000000;
    --dfOutputBorderRadius: 50px;
    --dfOutputRight: -7px;
    --dfOutputHeight: 14px;
    --dfOutputWidth: 14px;

    --dfOutputHoverBackgroundColor: rgba(255, 193, 7, 1);
    --dfOutputHoverBorderSize: 2px;
    --dfOutputHoverBorderColor: #000000;
    --dfOutputHoverBorderRadius: 50px;

    --dfLineWidth: 3px;
    --dfLineColor: rgba(0, 65, 208, 1);
    --dfLineHoverColor: rgba(0, 77, 247, 1);
    --dfLineSelectedColor: rgba(71, 193, 25, 1);

    --dfRerouteBorderWidth: 2px;
    --dfRerouteBorderColor: #000000;
    --dfRerouteBackgroundColor: #ffffff;

    --dfRerouteHoverBorderWidth: 2px;
    --dfRerouteHoverBorderColor: #000000;
    --dfRerouteHoverBackgroundColor: #ffffff;

    --dfDeleteDisplay: block;
    --dfDeleteColor: rgba(0, 65, 208, 1);
    --dfDeleteBackgroundColor: rgba(250, 253, 251, 1);
    --dfDeleteBorderSize: 1px;
    --dfDeleteBorderColor: rgba(0, 65, 208, 1);
    --dfDeleteBorderRadius: 50px;
    --dfDeleteTop: -15px;

    --dfDeleteHoverColor: rgba(0, 65, 208, 1);
    --dfDeleteHoverBackgroundColor: #ffffff;
    --dfDeleteHoverBorderSize: 2px;
    --dfDeleteHoverBorderColor: rgba(0, 65, 208, 1);
    --dfDeleteHoverBorderRadius: 50px;

  }

  #drawflow {
    background: var(--dfBackgroundColor);
    background-size: var(--dfBackgroundSize) var(--dfBackgroundSize);
    background-image: var(--dfBackgroundImage);
    position: relative;
    text-align: initial;
    width: 100%;
    height: 1000px;
    border: 1px solid black;
  }

  .drawflow .drawflow-node {
    display: var(--dfNodeType);
    background: var(--dfNodeBackgroundColor);
    color: var(--dfNodeTextColor);
    border: var(--dfNodeBorderSize)  solid var(--dfNodeBorderColor);
    border-radius: var(--dfNodeBorderRadius);
    min-height: var(--dfNodeMinHeight);
    width: auto;
    min-width: var(--dfNodeMinWidth);
    padding-top: var(--dfNodePaddingTop);
    padding-bottom: var(--dfNodePaddingBottom);
    -webkit-box-shadow: var(--dfNodeBoxShadowHL) var(--dfNodeBoxShadowVL) var(--dfNodeBoxShadowBR) var(--dfNodeBoxShadowS) var(--dfNodeBoxShadowColor);
    box-shadow:  var(--dfNodeBoxShadowHL) var(--dfNodeBoxShadowVL) var(--dfNodeBoxShadowBR) var(--dfNodeBoxShadowS) var(--dfNodeBoxShadowColor);
  }

  .drawflow .drawflow-node:hover {
    background: var(--dfNodeHoverBackgroundColor);
    color: var(--dfNodeHoverTextColor);
    border: var(--dfNodeHoverBorderSize)  solid var(--dfNodeHoverBorderColor);
    border-radius: var(--dfNodeHoverBorderRadius);
    -webkit-box-shadow: var(--dfNodeHoverBoxShadowHL) var(--dfNodeHoverBoxShadowVL) var(--dfNodeHoverBoxShadowBR) var(--dfNodeHoverBoxShadowS) var(--dfNodeHoverBoxShadowColor);
    box-shadow:  var(--dfNodeHoverBoxShadowHL) var(--dfNodeHoverBoxShadowVL) var(--dfNodeHoverBoxShadowBR) var(--dfNodeHoverBoxShadowS) var(--dfNodeHoverBoxShadowColor);
  }

  .drawflow .drawflow-node.selected {
    background: var(--dfNodeSelectedBackgroundColor);
    color: var(--dfNodeSelectedTextColor);
    border: var(--dfNodeSelectedBorderSize)  solid var(--dfNodeSelectedBorderColor);
    border-radius: var(--dfNodeSelectedBorderRadius);
    -webkit-box-shadow: var(--dfNodeSelectedBoxShadowHL) var(--dfNodeSelectedBoxShadowVL) var(--dfNodeSelectedBoxShadowBR) var(--dfNodeSelectedBoxShadowS) var(--dfNodeSelectedBoxShadowColor);
    box-shadow:  var(--dfNodeSelectedBoxShadowHL) var(--dfNodeSelectedBoxShadowVL) var(--dfNodeSelectedBoxShadowBR) var(--dfNodeSelectedBoxShadowS) var(--dfNodeSelectedBoxShadowColor);
  }

  .drawflow .drawflow-node .input {
    left: var(--dfInputLeft);
    background: var(--dfInputBackgroundColor);
    border: var(--dfInputBorderSize)  solid var(--dfInputBorderColor);
    border-radius: var(--dfInputBorderRadius);
    height: var(--dfInputHeight);
    width: var(--dfInputWidth);
  }

  .drawflow .drawflow-node .input:hover {
    background: var(--dfInputHoverBackgroundColor);
    border: var(--dfInputHoverBorderSize)  solid var(--dfInputHoverBorderColor);
    border-radius: var(--dfInputHoverBorderRadius);
  }

  .drawflow .drawflow-node .outputs {
    float: var(--dfNodeTypeFloat);
  }

  .drawflow .drawflow-node .output {
    right: var(--dfOutputRight);
    background: var(--dfOutputBackgroundColor);
    border: var(--dfOutputBorderSize)  solid var(--dfOutputBorderColor);
    border-radius: var(--dfOutputBorderRadius);
    height: var(--dfOutputHeight);
    width: var(--dfOutputWidth);
  }

  .drawflow .drawflow-node .output:hover {
    background: var(--dfOutputHoverBackgroundColor);
    border: var(--dfOutputHoverBorderSize)  solid var(--dfOutputHoverBorderColor);
    border-radius: var(--dfOutputHoverBorderRadius);
  }

  .drawflow .connection .main-path {
    stroke-width: var(--dfLineWidth);
    stroke: var(--dfLineColor);
  }

  .drawflow .connection .main-path:hover {
    stroke: var(--dfLineHoverColor);
  }

  .drawflow .connection .main-path.selected {
    stroke: var(--dfLineSelectedColor);
  }

  .drawflow .connection .point {
    stroke: var(--dfRerouteBorderColor);
    stroke-width: var(--dfRerouteBorderWidth);
    fill: var(--dfRerouteBackgroundColor);
  }

  .drawflow .connection .point:hover {
    stroke: var(--dfRerouteHoverBorderColor);
    stroke-width: var(--dfRerouteHoverBorderWidth);
    fill: var(--dfRerouteHoverBackgroundColor);
  }

  .drawflow-delete {
    display: var(--dfDeleteDisplay);
    color: var(--dfDeleteColor);
    background: var(--dfDeleteBackgroundColor);
    border: var(--dfDeleteBorderSize) solid var(--dfDeleteBorderColor);
    border-radius: var(--dfDeleteBorderRadius);
  }

  .parent-node .drawflow-delete {
    top: var(--dfDeleteTop);
  }

  .drawflow-delete:hover {
    color: var(--dfDeleteHoverColor);
    background: var(--dfDeleteHoverBackgroundColor);
    border: var(--dfDeleteHoverBorderSize) solid var(--dfDeleteHoverBorderColor);
    border-radius: var(--dfDeleteHoverBorderRadius);
  }

my main app contains the information

<link rel="stylesheet" href="https://cdn.jsdelivr.net/gh/jerosoler/Drawflow/dist/drawflow.min.css"/>
<link rel="stylesheet" href="app/_drawflow"/>

The hover style works but the node selected style reverts to your it being red color:

This is my drawflow layout file:

@extends('layouts.app')

@section('content')
<section class="section">
    <div class="section-header">
        <h1 class="text-truncate">MindMap</h1>
    </div>
    <div class="section-body">
    <div id="drawflow"></div>
    <script>
        var id = document.getElementById("drawflow");
        const editor = new Drawflow(id);
        editor.start();

        editor.addNode('aaa', 1, 1, 100, 300, 'aaa', {}, 'aaa' );
        editor.addNode('bbb', 0, 1, 150, 350, 'bbb', {}, 'bbb' );
        editor.addNode('ccc', 1, 0, 500, 500, 'ccc', {}, 'ccc' );

        var html = '\n <div>\n <div class=\"title-box\"><i class=\"fas fa-code\ mr-1"></i>Template</div>\n <div class=\"box\">\n \n <textarea df-template></textarea></div>\n </div>\n';

        var data = {"text": ''};
        editor.addNode('text', 1, 1, 75, 175, 'text', data, html );

        var html = document.createElement("div");
        html.innerHTML = "Hello User!!";
        editor.registerNode('test', html);

        editor.addNode('test', 1, 1, 275, 75, 'test', data, 'test', true);

    </script>
</section>
@endsection

@jerosoler
Copy link
Owner

With you code:

image

Test in html

<!DOCTYPE html>
<html lang="en">
<head>
  <meta charset="UTF-8">
  <meta name="viewport" content="width=device-width, initial-scale=1.0">
  <meta http-equiv="X-UA-Compatible" content="ie=edge">
  <title>Document</title>
  <link rel="stylesheet" href="https://cdn.jsdelivr.net/gh/jerosoler/Drawflow/dist/drawflow.min.css"/>
  <script src="https://cdn.jsdelivr.net/gh/jerosoler/Drawflow/dist/drawflow.min.js"></script>
</head>
<body>
<div id="drawflow"></div>
  <style>
    #drawflow { 
      position: relative;
      text-align:initial;
      width: 100%;
      height: 800px;
      border: 1px solid red;
    }

    :root {
    --dfBackgroundColor: rgba(250, 253, 251, 1);
    --dfBackgroundSize: 0px;
    --dfBackgroundImage: none;

    --dfNodeType: flex;
    --dfNodeTypeFloat: none;
    --dfNodeBackgroundColor: rgba(255, 255, 255, 1);
    --dfNodeTextColor: rgba(0, 0, 0, 1);
    --dfNodeBorderSize: 1px;
    --dfNodeBorderColor: rgba(0, 0, 0, 1);
    --dfNodeBorderRadius: 4px;
    --dfNodeMinHeight: 35px;
    --dfNodeMinWidth: 210px;
    --dfNodePaddingTop: 15px;
    --dfNodePaddingBottom: 15px;
    --dfNodeBoxShadowHL: 0px;
    --dfNodeBoxShadowVL: 0px;
    --dfNodeBoxShadowBR: 0px;
    --dfNodeBoxShadowS: 0px;
    --dfNodeBoxShadowColor: #000000;

    --dfNodeHoverBackgroundColor: rgba(255, 255, 255, 1);
    --dfNodeHoverTextColor: #000000;
    --dfNodeHoverBorderSize: 2px;
    --dfNodeHoverBorderColor: rgba(0, 65, 208, 1);
    --dfNodeHoverBorderRadius: 4px;

    --dfNodeHoverBoxShadowHL: 0px;
    --dfNodeHoverBoxShadowVL: 0px;
    --dfNodeHoverBoxShadowBR: 0px;
    --dfNodeHoverBoxShadowS: 0px;
    --dfNodeHoverBoxShadowColor: #4ea9ff;

    --dfNodeSelectedBackgroundColor: rgba(207, 239, 250, 1);
    --dfNodeSelectedTextColor: rgba(0, 65, 208, 1);
    --dfNodeSelectedBorderSize: 1px;
    --dfNodeSelectedBorderColor: rgba(0, 65, 208, 1);
    --dfNodeSelectedBorderRadius: 4px;

    --dfNodeSelectedBoxShadowHL: 0px;
    --dfNodeSelectedBoxShadowVL: 2px;
    --dfNodeSelectedBoxShadowBR: 15px;
    --dfNodeSelectedBoxShadowS: 1px;
    --dfNodeSelectedBoxShadowColor: rgba(78, 169, 255, 0.5);

    --dfInputBackgroundColor: rgba(255, 255, 255, 1);
    --dfInputBorderSize: 1px;
    --dfInputBorderColor: #000000;
    --dfInputBorderRadius: 50px;
    --dfInputLeft: -24px;
    --dfInputHeight: 14px;
    --dfInputWidth: 14px;

    --dfInputHoverBackgroundColor: #ffffff;
    --dfInputHoverBorderSize: 2px;
    --dfInputHoverBorderColor: #000000;
    --dfInputHoverBorderRadius: 50px;

    --dfOutputBackgroundColor: rgba(255, 193, 7, 1);
    --dfOutputBorderSize: 1px;
    --dfOutputBorderColor: #000000;
    --dfOutputBorderRadius: 50px;
    --dfOutputRight: -7px;
    --dfOutputHeight: 14px;
    --dfOutputWidth: 14px;

    --dfOutputHoverBackgroundColor: rgba(255, 193, 7, 1);
    --dfOutputHoverBorderSize: 2px;
    --dfOutputHoverBorderColor: #000000;
    --dfOutputHoverBorderRadius: 50px;

    --dfLineWidth: 3px;
    --dfLineColor: rgba(0, 65, 208, 1);
    --dfLineHoverColor: rgba(0, 77, 247, 1);
    --dfLineSelectedColor: rgba(71, 193, 25, 1);

    --dfRerouteBorderWidth: 2px;
    --dfRerouteBorderColor: #000000;
    --dfRerouteBackgroundColor: #ffffff;

    --dfRerouteHoverBorderWidth: 2px;
    --dfRerouteHoverBorderColor: #000000;
    --dfRerouteHoverBackgroundColor: #ffffff;

    --dfDeleteDisplay: block;
    --dfDeleteColor: rgba(0, 65, 208, 1);
    --dfDeleteBackgroundColor: rgba(250, 253, 251, 1);
    --dfDeleteBorderSize: 1px;
    --dfDeleteBorderColor: rgba(0, 65, 208, 1);
    --dfDeleteBorderRadius: 50px;
    --dfDeleteTop: -15px;

    --dfDeleteHoverColor: rgba(0, 65, 208, 1);
    --dfDeleteHoverBackgroundColor: #ffffff;
    --dfDeleteHoverBorderSize: 2px;
    --dfDeleteHoverBorderColor: rgba(0, 65, 208, 1);
    --dfDeleteHoverBorderRadius: 50px;

  }

  #drawflow {
    background: var(--dfBackgroundColor);
    background-size: var(--dfBackgroundSize) var(--dfBackgroundSize);
    background-image: var(--dfBackgroundImage);
    position: relative;
    text-align: initial;
    width: 100%;
    height: 1000px;
    border: 1px solid black;
  }

  .drawflow .drawflow-node {
    display: var(--dfNodeType);
    background: var(--dfNodeBackgroundColor);
    color: var(--dfNodeTextColor);
    border: var(--dfNodeBorderSize)  solid var(--dfNodeBorderColor);
    border-radius: var(--dfNodeBorderRadius);
    min-height: var(--dfNodeMinHeight);
    width: auto;
    min-width: var(--dfNodeMinWidth);
    padding-top: var(--dfNodePaddingTop);
    padding-bottom: var(--dfNodePaddingBottom);
    -webkit-box-shadow: var(--dfNodeBoxShadowHL) var(--dfNodeBoxShadowVL) var(--dfNodeBoxShadowBR) var(--dfNodeBoxShadowS) var(--dfNodeBoxShadowColor);
    box-shadow:  var(--dfNodeBoxShadowHL) var(--dfNodeBoxShadowVL) var(--dfNodeBoxShadowBR) var(--dfNodeBoxShadowS) var(--dfNodeBoxShadowColor);
  }

  .drawflow .drawflow-node:hover {
    background: var(--dfNodeHoverBackgroundColor);
    color: var(--dfNodeHoverTextColor);
    border: var(--dfNodeHoverBorderSize)  solid var(--dfNodeHoverBorderColor);
    border-radius: var(--dfNodeHoverBorderRadius);
    -webkit-box-shadow: var(--dfNodeHoverBoxShadowHL) var(--dfNodeHoverBoxShadowVL) var(--dfNodeHoverBoxShadowBR) var(--dfNodeHoverBoxShadowS) var(--dfNodeHoverBoxShadowColor);
    box-shadow:  var(--dfNodeHoverBoxShadowHL) var(--dfNodeHoverBoxShadowVL) var(--dfNodeHoverBoxShadowBR) var(--dfNodeHoverBoxShadowS) var(--dfNodeHoverBoxShadowColor);
  }

  .drawflow .drawflow-node.selected {
    background: var(--dfNodeSelectedBackgroundColor);
    color: var(--dfNodeSelectedTextColor);
    border: var(--dfNodeSelectedBorderSize)  solid var(--dfNodeSelectedBorderColor);
    border-radius: var(--dfNodeSelectedBorderRadius);
    -webkit-box-shadow: var(--dfNodeSelectedBoxShadowHL) var(--dfNodeSelectedBoxShadowVL) var(--dfNodeSelectedBoxShadowBR) var(--dfNodeSelectedBoxShadowS) var(--dfNodeSelectedBoxShadowColor);
    box-shadow:  var(--dfNodeSelectedBoxShadowHL) var(--dfNodeSelectedBoxShadowVL) var(--dfNodeSelectedBoxShadowBR) var(--dfNodeSelectedBoxShadowS) var(--dfNodeSelectedBoxShadowColor);
  }

  .drawflow .drawflow-node .input {
    left: var(--dfInputLeft);
    background: var(--dfInputBackgroundColor);
    border: var(--dfInputBorderSize)  solid var(--dfInputBorderColor);
    border-radius: var(--dfInputBorderRadius);
    height: var(--dfInputHeight);
    width: var(--dfInputWidth);
  }

  .drawflow .drawflow-node .input:hover {
    background: var(--dfInputHoverBackgroundColor);
    border: var(--dfInputHoverBorderSize)  solid var(--dfInputHoverBorderColor);
    border-radius: var(--dfInputHoverBorderRadius);
  }

  .drawflow .drawflow-node .outputs {
    float: var(--dfNodeTypeFloat);
  }

  .drawflow .drawflow-node .output {
    right: var(--dfOutputRight);
    background: var(--dfOutputBackgroundColor);
    border: var(--dfOutputBorderSize)  solid var(--dfOutputBorderColor);
    border-radius: var(--dfOutputBorderRadius);
    height: var(--dfOutputHeight);
    width: var(--dfOutputWidth);
  }

  .drawflow .drawflow-node .output:hover {
    background: var(--dfOutputHoverBackgroundColor);
    border: var(--dfOutputHoverBorderSize)  solid var(--dfOutputHoverBorderColor);
    border-radius: var(--dfOutputHoverBorderRadius);
  }

  .drawflow .connection .main-path {
    stroke-width: var(--dfLineWidth);
    stroke: var(--dfLineColor);
  }

  .drawflow .connection .main-path:hover {
    stroke: var(--dfLineHoverColor);
  }

  .drawflow .connection .main-path.selected {
    stroke: var(--dfLineSelectedColor);
  }

  .drawflow .connection .point {
    stroke: var(--dfRerouteBorderColor);
    stroke-width: var(--dfRerouteBorderWidth);
    fill: var(--dfRerouteBackgroundColor);
  }

  .drawflow .connection .point:hover {
    stroke: var(--dfRerouteHoverBorderColor);
    stroke-width: var(--dfRerouteHoverBorderWidth);
    fill: var(--dfRerouteHoverBackgroundColor);
  }

  .drawflow-delete {
    display: var(--dfDeleteDisplay);
    color: var(--dfDeleteColor);
    background: var(--dfDeleteBackgroundColor);
    border: var(--dfDeleteBorderSize) solid var(--dfDeleteBorderColor);
    border-radius: var(--dfDeleteBorderRadius);
  }

  .parent-node .drawflow-delete {
    top: var(--dfDeleteTop);
  }

  .drawflow-delete:hover {
    color: var(--dfDeleteHoverColor);
    background: var(--dfDeleteHoverBackgroundColor);
    border: var(--dfDeleteHoverBorderSize) solid var(--dfDeleteHoverBorderColor);
    border-radius: var(--dfDeleteHoverBorderRadius);
  }


</style>
<script>
    var id = document.getElementById("drawflow");
    const editor = new Drawflow(id);
    editor.line_path = 1;
    editor.start();
    

    editor.addNode('aaa', 0, 1, 100, 300, 'aaa', {}, 'aaa' );
    editor.addNode('bbb', 1, 0, 200, 400, 'bbb', {}, 'bbb' );
    editor.addNode('ccc', 1, 0, 500, 500, 'ccc', {}, 'ccc' );

</script>
</body>
</html>

@hussain-attari
Copy link
Author

hussain-attari commented Nov 28, 2021

Yes, this works perfectly fine.

So why isn't it working by inserting the custom style in the drawflow.min.css stylesheet?

Also, there are issues only for certain custom styling. Like I said the hover works perfectly fine. but the display and selected node don't work.

Another question. How can I add more nodes? is it through the class method? and fix their positioning through their class method?

@jerosoler
Copy link
Owner

I don't know how you will be adding in the css. But the min file should not be touched.

Another question. How can I add more nodes? is it through the class method? and fix their positioning through their class method?
With medthod editor.addNode(...)

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
question Further information is requested
Projects
None yet
Development

No branches or pull requests

2 participants