Repository: alyssaxuu/flowy Branch: master Commit: e977380e3a84 Files: 9 Total size: 83.2 KB Directory structure: gitextract_biqyvohl/ ├── .gitattributes ├── .github/ │ └── FUNDING.yml ├── LICENSE ├── README.md ├── demo/ │ ├── index.html │ ├── main.js │ └── styles.css └── engine/ ├── flowy.css └── flowy.js ================================================ FILE CONTENTS ================================================ ================================================ FILE: .gitattributes ================================================ # Auto detect text files and perform LF normalization * text=auto ================================================ FILE: .github/FUNDING.yml ================================================ # These are supported funding model platforms github: alyssaxuu ================================================ FILE: LICENSE ================================================ MIT License Copyright (c) 2019 Alyssa X Permission is hereby granted, free of charge, to any person obtaining a copy of this software and associated documentation files (the "Software"), to deal in the Software without restriction, including without limitation the rights to use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies of the Software, and to permit persons to whom the Software is furnished to do so, subject to the following conditions: The above copyright notice and this permission notice shall be included in all copies or substantial portions of the Software. THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. ================================================ FILE: README.md ================================================ # Flowy ![Demo](https://media.giphy.com/media/dv1C56OywrP7Cn20nr/giphy.gif)
A javascript library to create pretty flowcharts with ease ✨ [Dribbble](https://dribbble.com/shots/8576286-Flowy-Flowchart-Engine) | [Twitter](https://twitter.com/alyssaxuu/status/1199724989353730048) | [Live demo](https://alyssax.com/x/flowy) Flowy makes creating WebApps with flowchart functionality an incredibly simple task. Build automation software, mind mapping tools, or simple programming platforms in minutes by implementing the library into your project. > You can support this project (and many others) through [GitHub Sponsors](https://github.com/sponsors/alyssaxuu)! ❤️ Made by [Alyssa X](https://alyssax.com) ## Table of contents - [Features](#features) - [Installation](#installation) - [Running Flowy](#running-flowy) - [Initialization](#initialization) - [Example](#example) - [Callbacks](#callbacks) - [On grab](#on-grab) - [On release](#on-release) - [On snap](#on-snap) - [On rearrange](#on-rearrange) - [Methods](#methods) - [Get the flowchart data](#get-the-flowchart-data) - [Import the flowchart data](#import-the-flowchart-data) - [Delete all blocks](#delete-all-blocks) ## Features Currently, Flowy supports the following: - [x] Responsive drag and drop - [x] Automatic snapping - [x] Automatic scrolling - [x] Block rearrangement - [x] Delete blocks - [x] Automatic block centering - [x] Conditional snapping - [x] Conditional block removal - [x] Import saved files - [x] Mobile support - [x] Vanilla javascript (no dependencies) - [ ] [npm install](https://github.com/alyssaxuu/flowy/issues/10) You can suggest new features [here](https://github.com/alyssaxuu/flowy/issues) ## Installation Adding Flowy to your WebApp is incredibly simple: 1. Link `flowy.min.js` and `flowy.min.css` to your project. Through jsDelivr: ```html ``` 2. Create a canvas element that will contain the flowchart (for example, `
`) 3. Create the draggable blocks with the `.create-flowy` class (for example, `
Grab me
`) ## Running Flowy ### Initialization ```javascript flowy(canvas, ongrab, onrelease, onsnap, onrearrange, spacing_x, spacing_y); ``` Parameter | Type | Description --- | --- | --- `canvas` | *javascript DOM element* | The element that will contain the blocks `ongrab` | *function* (optional) | Function that gets triggered when a block is dragged `onrelease` | *function* (optional) | Function that gets triggered when a block is released `onsnap` | *function* (optional) | Function that gets triggered when a block snaps with another one `onrearrange` | *function* (optional) | Function that gets triggered when blocks are rearranged `spacing_x` | *integer* (optional) | Horizontal spacing between blocks (default 20px) `spacing_y` | *integer* (optional) | Vertical spacing between blocks (default 80px) To define the blocks that can be dragged, you need to add the class `.create-flowy` ### Example **HTML** ```html
The block to be dragged
``` **Javascript** ```javascript var spacing_x = 40; var spacing_y = 100; // Initialize Flowy flowy(document.getElementById("canvas"), onGrab, onRelease, onSnap, onRearrange, spacing_x, spacing_y); function onGrab(block){ // When the user grabs a block } function onRelease(){ // When the user releases a block } function onSnap(block, first, parent){ // When a block snaps with another one } function onRearrange(block, parent){ // When a block is rearranged } ``` ## Callbacks In order to use callbacks, you need to add the functions when initializing Flowy, as explained before. ### On grab ```javascript function onGrab(block){ // When the user grabs a block } ``` Gets triggered when a user grabs a block with the class `create-flowy` Parameter | Type | Description --- | --- | --- `block` | *javascript DOM element* | The block that has been grabbed ### On release ```javascript function onRelease(){ // When the user lets go of a block } ``` Gets triggered when a user lets go of a block, regardless of whether it attaches or even gets released in the canvas. ### On snap ```javascript function onSnap(block, first, parent){ // When a block can attach to a parent return true; } ``` Gets triggered when a block can attach to another parent block. You can either prevent the attachment, or allow it by using `return true;` Parameter | Type | Description --- | --- | --- `block` | *javascript DOM element* | The block that has been grabbed `first` | *boolean* | If true, the block that has been dragged is the first one in the canvas `parent` | *javascript DOM element* | The parent the block can attach to ### On rearrange ```javascript function onRearrange(block, parent){ // When a block is rearranged return true; } ``` Gets triggered when blocks are rearranged and are dropped anywhere in the canvas, without a parent to attach to. You can either allow the blocks to be deleted, or prevent it and thus have them re-attach to their previous parent using `return true;` Parameter | Type | Description --- | --- | --- `block` | *javascript DOM element* | The block that has been grabbed `parent` | *javascript DOM element* | The parent the block can attach to ## Methods ### Get the flowchart data ```javascript // As an object flowy.output(); // As a JSON string JSON.stringify(flowy.output()); ``` The JSON object that gets outputted looks like this: ```json { "html": "", "blockarr": [], "blocks": [ { "id": 1, "parent": 0, "data": [ { "name": "blockid", "value": "1" } ], "attr": [ { "id": "block-id", "class": "block-class" } ] } ] } ``` Here's what each property means: Key | Value type | Description --- | --- | --- `html` | *string* | Contains the canvas data `blockarr` | *array* | Contains the block array generated by the library (for import purposes) `blocks` | *array* | Contains the readable block array `id` | *integer* | Unique value that identifies a block `parent` | *integer* | The `id` of the parent a block is attached to (-1 means the block has no parent) `data` | *array of objects* | An array of all the inputs within a certain block `name` | *string* | The name attribute of the input `value` | *string* | The value attribute of the input `attr` | *array of objects* | Contains all the data attributes of a certain block ### Import the flowchart data ```javascript flowy.import(output) ``` Allows you to import entire flowcharts initially exported using the previous method, `flowy.output()` Parameter | Type | Description --- | --- | --- `output` | *javascript DOM element* | The data from `flowy.output()` #### Warning This method accepts raw HTML and does **not** sanitize it, therefore this method is vulnerable to [XSS](https://owasp.org/www-community/attacks/DOM_Based_XSS). The _only_ safe use for this method is when the input is **absolutely** trusted, if the input is _not_ to be trusted the use this method can introduce a vulnerability in your system. ### Delete all blocks To remove all blocks at once use: ```javascript flowy.deleteBlocks() ``` Currently there is no method to individually remove blocks. The only way to go about it is by splitting branches manually. # Feel free to reach out to me through email at hi@alyssax.com or [on Twitter](https://twitter.com/alyssaxuu) if you have any questions or feedback! Hope you find this useful 💜 ================================================ FILE: demo/index.html ================================================ Flowy - The simple flowchart engine

New visitor

Triggers when somebody visits a specified page

Action is performed

Triggers when somebody performs a specified action

Time has passed

Triggers after a specified amount of time

Error prompt

Triggers when a specified error happens

Properties

Data
Alerts
Logs

Select database

Database 1

Check properties

All

Log on successful performance

Give priority to this block

Delete blocks
================================================ FILE: demo/main.js ================================================ document.addEventListener("DOMContentLoaded", function(){ var rightcard = false; var tempblock; var tempblock2; document.getElementById("blocklist").innerHTML = '

New visitor

Triggers when somebody visits a specified page

Action is performed

Triggers when somebody performs a specified action

Time has passed

Triggers after a specified amount of time

Error prompt

Triggers when a specified error happens

'; flowy(document.getElementById("canvas"), drag, release, snapping); function addEventListenerMulti(type, listener, capture, selector) { var nodes = document.querySelectorAll(selector); for (var i = 0; i < nodes.length; i++) { nodes[i].addEventListener(type, listener, capture); } } function snapping(drag, first) { var grab = drag.querySelector(".grabme"); grab.parentNode.removeChild(grab); var blockin = drag.querySelector(".blockin"); blockin.parentNode.removeChild(blockin); if (drag.querySelector(".blockelemtype").value == "1") { drag.innerHTML += "

New visitor

When a new visitor goes to Site 1
"; } else if (drag.querySelector(".blockelemtype").value == "2") { drag.innerHTML += "

Action is performed

When Action 1 is performed
"; } else if (drag.querySelector(".blockelemtype").value == "3") { drag.innerHTML += "

Time has passed

When 10 seconds have passed
"; } else if (drag.querySelector(".blockelemtype").value == "4") { drag.innerHTML += "

Error prompt

When Error 1 is triggered
"; } else if (drag.querySelector(".blockelemtype").value == "5") { drag.innerHTML += "

New database entry

Add Data object to Database 1
"; } else if (drag.querySelector(".blockelemtype").value == "6") { drag.innerHTML += "

Update database

Update Database 1
"; } else if (drag.querySelector(".blockelemtype").value == "7") { drag.innerHTML += "

Perform an action

Perform Action 1
"; } else if (drag.querySelector(".blockelemtype").value == "8") { drag.innerHTML += "

Make a tweet

Tweet Query 1 with the account @alyssaxuu
"; } else if (drag.querySelector(".blockelemtype").value == "9") { drag.innerHTML += "

Add new log entry

Add new success log entry
"; } else if (drag.querySelector(".blockelemtype").value == "10") { drag.innerHTML += "

Update logs

Edit Log Entry 1
"; } else if (drag.querySelector(".blockelemtype").value == "11") { drag.innerHTML += "

Prompt an error

Trigger Error 1
"; } return true; } function drag(block) { block.classList.add("blockdisabled"); tempblock2 = block; } function release() { if (tempblock2) { tempblock2.classList.remove("blockdisabled"); } } var disabledClick = function(){ document.querySelector(".navactive").classList.add("navdisabled"); document.querySelector(".navactive").classList.remove("navactive"); this.classList.add("navactive"); this.classList.remove("navdisabled"); if (this.getAttribute("id") == "triggers") { document.getElementById("blocklist").innerHTML = '

New visitor

Triggers when somebody visits a specified page

Action is performed

Triggers when somebody performs a specified action

Time has passed

Triggers after a specified amount of time

Error prompt

Triggers when a specified error happens

'; } else if (this.getAttribute("id") == "actions") { document.getElementById("blocklist").innerHTML = '

New database entry

Adds a new entry to a specified database

Update database

Edits and deletes database entries and properties

Perform an action

Performs or edits a specified action

Make a tweet

Makes a tweet with a specified query

'; } else if (this.getAttribute("id") == "loggers") { document.getElementById("blocklist").innerHTML = '

Add new log entry

Adds a new log entry to this project

Update logs

Edits and deletes log entries in this project

Prompt an error

Triggers a specified error

'; } } addEventListenerMulti("click", disabledClick, false, ".side"); document.getElementById("close").addEventListener("click", function(){ if (rightcard) { rightcard = false; document.getElementById("properties").classList.remove("expanded"); setTimeout(function(){ document.getElementById("propwrap").classList.remove("itson"); }, 300); tempblock.classList.remove("selectedblock"); } }); document.getElementById("removeblock").addEventListener("click", function(){ flowy.deleteBlocks(); }); var aclick = false; var noinfo = false; var beginTouch = function (event) { aclick = true; noinfo = false; if (event.target.closest(".create-flowy")) { noinfo = true; } } var checkTouch = function (event) { aclick = false; } var doneTouch = function (event) { if (event.type === "mouseup" && aclick && !noinfo) { if (!rightcard && event.target.closest(".block") && !event.target.closest(".block").classList.contains("dragging")) { tempblock = event.target.closest(".block"); rightcard = true; document.getElementById("properties").classList.add("expanded"); document.getElementById("propwrap").classList.add("itson"); tempblock.classList.add("selectedblock"); } } } addEventListener("mousedown", beginTouch, false); addEventListener("mousemove", checkTouch, false); addEventListener("mouseup", doneTouch, false); addEventListenerMulti("touchstart", beginTouch, false, ".block"); }); ================================================ FILE: demo/styles.css ================================================ body, html { margin: 0px; padding: 0px; overflow: hidden; background-image: url(assets/tile.png); background-repeat: repeat; background-size: 30px 30px; background-color: #FBFBFB; height: 100%; } #navigation { height: 71px; background-color: #FFF; border: 1px solid #E8E8EF; width: 100%; display: table; box-sizing: border-box; position: fixed; top: 0; z-index: 9 } #back { width: 40px; height: 40px; border-radius: 100px; background-color: #F1F4FC; text-align: center; display: inline-block; vertical-align: top; margin-top: 12px; margin-right: 10px } #back img { margin-top: 13px; } #names { display: inline-block; vertical-align: top; } #title { font-family: Roboto; font-weight: 500; font-size: 16px; color: #393C44; margin-bottom: 0px; } #subtitle { font-family: Roboto; color: #808292; font-size: 14px; margin-top: 5px; } #leftside { display: inline-block; vertical-align: middle; margin-left: 20px; } #centerswitch { position: absolute; width: 222px; left: 50%; margin-left: -111px; top: 15px; } #leftswitch { border: 1px solid #E8E8EF; background-color: #FBFBFB; width: 111px; height: 39px; line-height: 39px; border-radius: 5px 0px 0px 5px; font-family: Roboto; color: #393C44; display: inline-block; font-size: 14px; text-align: center; } #rightswitch { font-family: Roboto; color: #808292; border-radius: 0px 5px 5px 0px; border: 1px solid #E8E8EF; height: 39px; width: 102px; display: inline-block; font-size: 14px; line-height: 39px; text-align: center; margin-left: -5px; } #discard { font-family: Roboto; font-weight: 500; font-size: 14px; color: #A6A6B3; width: 95px; height: 38px; border: 1px solid #E8E8EF; border-radius: 5px; text-align: center; line-height: 38px; display: inline-block; vertical-align: top; transition: all .2s cubic-bezier(.05,.03,.35,1); } #discard:hover { cursor: pointer; opacity: .7; } #publish { font-family: Roboto; font-weight: 500; font-size: 14px; color: #FFF; background-color: #217CE8; border-radius: 5px; width: 143px; height: 38px; margin-left: 10px; display: inline-block; vertical-align: top; text-align: center; line-height: 38px; margin-right: 20px; transition: all .2s cubic-bezier(.05,.03,.35,1); } #publish:hover { cursor: pointer; opacity: .7; } #buttonsright { float: right; margin-top: 15px; } #leftcard { width: 363px; background-color: #FFF; border: 1px solid #E8E8EF; box-sizing: border-box; padding-top: 85px; padding-left: 20px; height: 100%; position: absolute; z-index: 2; } #search input { width: 318px; height: 40px; background-color: #FFF; border: 1px solid #E8E8EF; box-sizing: border-box; box-shadow: 0px 2px 8px rgba(34,34,87,0.05); border-radius: 5px; text-indent: 35px; font-family: Roboto; font-size: 16px; } ::-webkit-input-placeholder { /* Edge */ color: #C9C9D5; } :-ms-input-placeholder { /* Internet Explorer 10-11 */ color: #C9C9D5 } ::placeholder { color: #C9C9D5; } #search img { position: absolute; margin-top: 10px; width: 18px; margin-left: 12px; } #header { font-size: 20px; font-family: Roboto; font-weight: bold; color: #393C44; } #subnav { border-bottom: 1px solid #E8E8EF; width: calc(100% + 20px); margin-left: -20px; margin-top: 10px; } .navdisabled { transition: all .3s cubic-bezier(.05,.03,.35,1); } .navdisabled:hover { cursor: pointer; opacity: .5; } .navactive { color: #393C44!important; } #triggers { margin-left: 20px; font-family: Roboto; font-weight: 500; font-size: 14px; text-align: center; color: #808292; width: calc(88% / 3); height: 48px; line-height: 48px; display: inline-block; float: left; } .navactive:after { display: block; content: ""; width: 100%; height: 4px; background-color: #217CE8; margin-top: -4px; } #actions { display: inline-block; font-family: Roboto; font-weight: 500; color: #808292; font-size: 14px; height: 48px; line-height: 48px; width: calc(88% / 3); text-align: center; float: left; } #loggers { width: calc(88% / 3); display: inline-block; font-family: Roboto; font-weight: 500; color: #808292; font-size: 14px; height: 48px; line-height: 48px; text-align: center; } #footer { position: absolute; left: 0; padding-left: 20px; line-height: 40px; bottom: 0; width: 362px; border: 1px solid #E8E8EF; height: 67px; box-sizing: border-box; background-color: #FFF; font-family: Roboto; font-size: 14px; } #footer a { text-decoration: none; color: #393C44; transition: all .2s cubic-bezier(.05,.03,.35,1); } #footer a:hover { opacity: .5; } #footer span { color: #808292; } #footer p { display: inline-block; color: #808292; } #footer img { margin-left: 5px; margin-right: 5px; } .blockelem:first-child { margin-top: 20px } .blockelem { padding-top: 10px; width: 318px; border: 1px solid transparent; transition-property: box-shadow, height; transition-duration: .2s; transition-timing-function: cubic-bezier(.05,.03,.35,1); border-radius: 5px; box-shadow: 0px 0px 30px rgba(22, 33, 74, 0); box-sizing: border-box; } .blockelem:hover { box-shadow: 0px 4px 30px rgba(22, 33, 74, 0.08); border-radius: 5px; background-color: #FFF; cursor: pointer; } .grabme, .blockico { display: inline-block; } .grabme { margin-top: 10px; margin-left: 10px; margin-bottom: -14px; width: 15px; } #blocklist { height: calc(100% - 220px); overflow: auto; } #proplist { height: calc(100% - 305px); overflow: auto; margin-top: -30px; padding-top: 30px; } .blockin { display: inline-block; vertical-align: top; margin-left: 12px; } .blockico { width: 36px; height: 36px; background-color: #F1F4FC; border-radius: 5px; text-align: center; white-space: nowrap; } .blockico span { height: 100%; width: 0px; display: inline-block; vertical-align: middle; } .blockico img { vertical-align: middle; margin-left: auto; margin-right: auto; display: inline-block; } .blocktext { display: inline-block; width: 220px; vertical-align: top; margin-left: 12px } .blocktitle { margin: 0px!important; padding: 0px!important; font-family: Roboto; font-weight: 500; font-size: 16px; color: #393C44; } .blockdesc { margin-top: 5px; font-family: Roboto; color: #808292; font-size: 14px; line-height: 21px; } .blockdisabled { background-color: #F0F2F9; opacity: .5; } #closecard { position: absolute; margin-left: 340px; background-color: #FFF; border-radius: 0px 5px 5px 0px; border-bottom: 1px solid #E8E8EF; border-right: 1px solid #E8E8EF; border-top: 1px solid #E8E8EF; width: 53px; height: 53px; text-align: center; z-index: 10; } #closecard img { margin-top: 15px } #canvas { position: absolute; width: calc(100% - 361px); height: calc(100% - 71px); top: 71px; left: 361px; z-index: 0; overflow: auto; } #propwrap { position: absolute; right: 0; top: 0; width: 311px; height: 100%; padding-left: 20px; overflow: hidden; z-index: -2; } #properties { position: absolute; height: 100%; width: 311px; background-color: #FFF; right: -150px; opacity: 0; z-index: 2; top: 0px; box-shadow: -4px 0px 40px rgba(26, 26, 73, 0); padding-left: 20px; transition: all .25s cubic-bezier(.05,.03,.35,1); } .itson { z-index: 2!important; } .expanded { right: 0!important; opacity: 1!important; box-shadow: -4px 0px 40px rgba(26, 26, 73, 0.05); z-index: 2; } #header2 { font-size: 20px; font-family: Roboto; font-weight: bold; color: #393C44; margin-top: 101px; } #close { margin-top: 100px; position: absolute; right: 20px; z-index: 9999; transition: all .25s cubic-bezier(.05,.03,.35,1); } #close:hover { cursor: pointer; opacity: .7; } #propswitch { border-bottom: 1px solid #E8E8EF; width: 331px; margin-top: 10px; margin-left: -20px; margin-bottom: 30px; } #dataprop { font-family: Roboto; font-weight: 500; font-size: 14px; text-align: center; color: #393C44; width: calc(88% / 3); height: 48px; line-height: 48px; display: inline-block; float: left; margin-left: 20px; } #dataprop:after { display: block; content: ""; width: 100%; height: 4px; background-color: #217CE8; margin-top: -4px; } #alertprop { display: inline-block; font-family: Roboto; font-weight: 500; color: #808292; font-size: 14px; height: 48px; line-height: 48px; width: calc(88% / 3); text-align: center; float: left; } #logsprop { width: calc(88% / 3); display: inline-block; font-family: Roboto; font-weight: 500; color: #808292; font-size: 14px; height: 48px; line-height: 48px; text-align: center; } .inputlabel { font-family: Roboto; font-size: 14px; color: #253134; } .dropme { background-color: #FFF; border-radius: 5px; border: 1px solid #E8E8EF; box-shadow: 0px 2px 8px rgba(34, 34, 87, 0.05); font-family: Roboto; font-size: 14px; color: #253134; text-indent: 20px; height: 40px; line-height: 40px; width: 287px; margin-bottom: 25px; } .dropme img { margin-top: 17px; float: right; margin-right: 15px; } .checkus { margin-bottom: 10px; } .checkus img { display: inline-block; vertical-align: middle; } .checkus p { display: inline-block; font-family: Roboto; font-size: 14px; vertical-align: middle; margin-left: 10px; } #divisionthing { height: 1px; width: 100%; background-color: #E8E8EF; position: absolute; right: 0px; bottom: 80; } #removeblock { border-radius: 5px; position: absolute; bottom: 20px; font-family: Roboto; font-size: 14px; text-align: center; width: 287px; height: 38px; line-height: 38px; color: #253134; border: 1px solid #E8E8EF; transition: all .3s cubic-bezier(.05,.03,.35,1); } #removeblock:hover { cursor: pointer; opacity: .5; } .noselect { -webkit-touch-callout: none; /* iOS Safari */ -webkit-user-select: none; /* Safari */ -khtml-user-select: none; /* Konqueror HTML */ -moz-user-select: none; /* Old versions of Firefox */ -ms-user-select: none; /* Internet Explorer/Edge */ user-select: none; /* Non-prefixed version, currently supported by Chrome, Opera and Firefox */ } .blockyname { font-family: Roboto; font-weight: 500; color: #253134; display: inline-block; vertical-align: middle; margin-left: 8px; font-size: 16px; } .blockyleft img { display: inline-block; vertical-align: middle; } .blockyright { display: inline-block; float: right; vertical-align: middle; margin-right: 20px; margin-top: 10px; width: 28px; height: 28px; border-radius: 5px; text-align: center; background-color: #FFF; transition: all .3s cubic-bezier(.05,.03,.35,1); z-index: 10; } .blockyright:hover { background-color: #F1F4FC; cursor: pointer; } .blockyright img { margin-top: 12px; } .blockyleft { display: inline-block; margin-left: 20px; } .blockydiv { width: 100%; height: 1px; background-color: #E9E9EF; } .blockyinfo { font-family: Roboto; font-size: 14px; color: #808292; margin-top: 15px; text-indent: 20px; margin-bottom: 20px; } .blockyinfo span { color: #253134; font-weight: 500; display: inline-block; border-bottom: 1px solid #D3DCEA; line-height: 20px; text-indent: 0px; } .block { background-color: #FFF; margin-top: 0px!important; box-shadow: 0px 4px 30px rgba(22, 33, 74, 0.05); } .selectedblock { border: 2px solid #217CE8; box-shadow: 0px 4px 30px rgba(22, 33, 74, 0.08); } @media only screen and (max-width: 832px) { #centerswitch { display: none; } } @media only screen and (max-width: 560px) { #names { display: none; } } ================================================ FILE: engine/flowy.css ================================================ .dragging{z-index:111!important}.block{position:absolute;z-index:9}.indicator{width:12px;height:12px;border-radius:60px;background-color:#217ce8;margin-top:-5px;opacity:1;transition:all .3s cubic-bezier(.05,.03,.35,1);transform:scale(1);position:absolute;z-index:2}.invisible{opacity:0!important;transform:scale(0)}.indicator:after{content:"";display:block;width:12px;height:12px;background-color:#217ce8;transform:scale(1.7);opacity:.2;border-radius:60px}.arrowblock{position:absolute;width:100%;overflow:visible;pointer-events:none}.arrowblock svg{width: -webkit-fill-available;overflow: visible;} ================================================ FILE: engine/flowy.js ================================================ var flowy = function(canvas, grab, release, snapping, rearrange, spacing_x, spacing_y) { if (!grab) { grab = function() {}; } if (!release) { release = function() {}; } if (!snapping) { snapping = function() { return true; } } if (!rearrange) { rearrange = function() { return false; } } if (!spacing_x) { spacing_x = 20; } if (!spacing_y) { spacing_y = 80; } if (!Element.prototype.matches) { Element.prototype.matches = Element.prototype.msMatchesSelector || Element.prototype.webkitMatchesSelector; } if (!Element.prototype.closest) { Element.prototype.closest = function(s) { var el = this; do { if (Element.prototype.matches.call(el, s)) return el; el = el.parentElement || el.parentNode; } while (el !== null && el.nodeType === 1); return null; }; } var loaded = false; flowy.load = function() { if (!loaded) loaded = true; else return; var blocks = []; var blockstemp = []; var canvas_div = canvas; var absx = 0; var absy = 0; if (window.getComputedStyle(canvas_div).position == "absolute" || window.getComputedStyle(canvas_div).position == "fixed") { absx = canvas_div.getBoundingClientRect().left; absy = canvas_div.getBoundingClientRect().top; } var active = false; var paddingx = spacing_x; var paddingy = spacing_y; var offsetleft = 0; var rearrange = false; var drag, dragx, dragy, original; var mouse_x, mouse_y; var dragblock = false; var prevblock = 0; var el = document.createElement("DIV"); el.classList.add('indicator'); el.classList.add('invisible'); canvas_div.appendChild(el); flowy.import = function(output) { canvas_div.innerHTML = output.html; for (var a = 0; a < output.blockarr.length; a++) { blocks.push({ childwidth: parseFloat(output.blockarr[a].childwidth), parent: parseFloat(output.blockarr[a].parent), id: parseFloat(output.blockarr[a].id), x: parseFloat(output.blockarr[a].x), y: parseFloat(output.blockarr[a].y), width: parseFloat(output.blockarr[a].width), height: parseFloat(output.blockarr[a].height) }) } if (blocks.length > 1) { rearrangeMe(); checkOffset(); } } flowy.output = function() { var html_ser = canvas_div.innerHTML; var json_data = { html: html_ser, blockarr: blocks, blocks: [] }; if (blocks.length > 0) { for (var i = 0; i < blocks.length; i++) { json_data.blocks.push({ id: blocks[i].id, parent: blocks[i].parent, data: [], attr: [] }); var blockParent = document.querySelector(".blockid[value='" + blocks[i].id + "']").parentNode; blockParent.querySelectorAll("input").forEach(function(block) { var json_name = block.getAttribute("name"); var json_value = block.value; json_data.blocks[i].data.push({ name: json_name, value: json_value }); }); Array.prototype.slice.call(blockParent.attributes).forEach(function(attribute) { var jsonobj = {}; jsonobj[attribute.name] = attribute.value; json_data.blocks[i].attr.push(jsonobj); }); } return json_data; } } flowy.deleteBlocks = function() { blocks = []; canvas_div.innerHTML = ""; } flowy.beginDrag = function(event) { if (window.getComputedStyle(canvas_div).position == "absolute" || window.getComputedStyle(canvas_div).position == "fixed") { absx = canvas_div.getBoundingClientRect().left; absy = canvas_div.getBoundingClientRect().top; } if (event.targetTouches) { mouse_x = event.changedTouches[0].clientX; mouse_y = event.changedTouches[0].clientY; } else { mouse_x = event.clientX; mouse_y = event.clientY; } if (event.which != 3 && event.target.closest(".create-flowy")) { original = event.target.closest(".create-flowy"); var newNode = event.target.closest(".create-flowy").cloneNode(true); event.target.closest(".create-flowy").classList.add("dragnow"); newNode.classList.add("block"); newNode.classList.remove("create-flowy"); if (blocks.length === 0) { newNode.innerHTML += ""; document.body.appendChild(newNode); drag = document.querySelector(".blockid[value='" + blocks.length + "']").parentNode; } else { newNode.innerHTML += ""; document.body.appendChild(newNode); drag = document.querySelector(".blockid[value='" + (parseInt(Math.max.apply(Math, blocks.map(a => a.id))) + 1) + "']").parentNode; } blockGrabbed(event.target.closest(".create-flowy")); drag.classList.add("dragging"); active = true; dragx = mouse_x - (event.target.closest(".create-flowy").getBoundingClientRect().left); dragy = mouse_y - (event.target.closest(".create-flowy").getBoundingClientRect().top); drag.style.left = mouse_x - dragx + "px"; drag.style.top = mouse_y - dragy + "px"; } } flowy.endDrag = function(event) { if (event.which != 3 && (active || rearrange)) { dragblock = false; blockReleased(); if (!document.querySelector(".indicator").classList.contains("invisible")) { document.querySelector(".indicator").classList.add("invisible"); } if (active) { original.classList.remove("dragnow"); drag.classList.remove("dragging"); } if (parseInt(drag.querySelector(".blockid").value) === 0 && rearrange) { firstBlock("rearrange") } else if (active && blocks.length == 0 && (drag.getBoundingClientRect().top + window.scrollY) > (canvas_div.getBoundingClientRect().top + window.scrollY) && (drag.getBoundingClientRect().left + window.scrollX) > (canvas_div.getBoundingClientRect().left + window.scrollX)) { firstBlock("drop"); } else if (active && blocks.length == 0) { removeSelection(); } else if (active) { var blocko = blocks.map(a => a.id); for (var i = 0; i < blocks.length; i++) { if (checkAttach(blocko[i])) { active = false; if (blockSnap(drag, false, document.querySelector(".blockid[value='" + blocko[i] + "']").parentNode)) { snap(drag, i, blocko); } else { active = false; removeSelection(); } break; } else if (i == blocks.length - 1) { active = false; removeSelection(); } } } else if (rearrange) { var blocko = blocks.map(a => a.id); for (var i = 0; i < blocks.length; i++) { if (checkAttach(blocko[i])) { active = false; drag.classList.remove("dragging"); snap(drag, i, blocko); break; } else if (i == blocks.length - 1) { if (beforeDelete(drag, blocks.filter(id => id.id == blocko[i])[0])) { active = false; drag.classList.remove("dragging"); snap(drag, blocko.indexOf(prevblock), blocko); break; } else { rearrange = false; blockstemp = []; active = false; removeSelection(); break; } } } } } } function checkAttach(id) { const xpos = (drag.getBoundingClientRect().left + window.scrollX) + (parseInt(window.getComputedStyle(drag).width) / 2) + canvas_div.scrollLeft - canvas_div.getBoundingClientRect().left; const ypos = (drag.getBoundingClientRect().top + window.scrollY) + canvas_div.scrollTop - canvas_div.getBoundingClientRect().top; if (xpos >= blocks.filter(a => a.id == id)[0].x - (blocks.filter(a => a.id == id)[0].width / 2) - paddingx && xpos <= blocks.filter(a => a.id == id)[0].x + (blocks.filter(a => a.id == id)[0].width / 2) + paddingx && ypos >= blocks.filter(a => a.id == id)[0].y - (blocks.filter(a => a.id == id)[0].height / 2) && ypos <= blocks.filter(a => a.id == id)[0].y + blocks.filter(a => a.id == id)[0].height) { return true; } else { return false; } } function removeSelection() { canvas_div.appendChild(document.querySelector(".indicator")); drag.parentNode.removeChild(drag); } function firstBlock(type) { if (type == "drop") { blockSnap(drag, true, undefined); active = false; drag.style.top = (drag.getBoundingClientRect().top + window.scrollY) - (absy + window.scrollY) + canvas_div.scrollTop + "px"; drag.style.left = (drag.getBoundingClientRect().left + window.scrollX) - (absx + window.scrollX) + canvas_div.scrollLeft + "px"; canvas_div.appendChild(drag); blocks.push({ parent: -1, childwidth: 0, id: parseInt(drag.querySelector(".blockid").value), x: (drag.getBoundingClientRect().left + window.scrollX) + (parseInt(window.getComputedStyle(drag).width) / 2) + canvas_div.scrollLeft - canvas_div.getBoundingClientRect().left, y: (drag.getBoundingClientRect().top + window.scrollY) + (parseInt(window.getComputedStyle(drag).height) / 2) + canvas_div.scrollTop - canvas_div.getBoundingClientRect().top, width: parseInt(window.getComputedStyle(drag).width), height: parseInt(window.getComputedStyle(drag).height) }); } else if (type == "rearrange") { drag.classList.remove("dragging"); rearrange = false; for (var w = 0; w < blockstemp.length; w++) { if (blockstemp[w].id != parseInt(drag.querySelector(".blockid").value)) { const blockParent = document.querySelector(".blockid[value='" + blockstemp[w].id + "']").parentNode; const arrowParent = document.querySelector(".arrowid[value='" + blockstemp[w].id + "']").parentNode; blockParent.style.left = (blockParent.getBoundingClientRect().left + window.scrollX) - (window.scrollX) + canvas_div.scrollLeft - 1 - absx + "px"; blockParent.style.top = (blockParent.getBoundingClientRect().top + window.scrollY) - (window.scrollY) + canvas_div.scrollTop - absy - 1 + "px"; arrowParent.style.left = (arrowParent.getBoundingClientRect().left + window.scrollX) - (window.scrollX) + canvas_div.scrollLeft - absx - 1 + "px"; arrowParent.style.top = (arrowParent.getBoundingClientRect().top + window.scrollY) + canvas_div.scrollTop - 1 - absy + "px"; canvas_div.appendChild(blockParent); canvas_div.appendChild(arrowParent); blockstemp[w].x = (blockParent.getBoundingClientRect().left + window.scrollX) + (parseInt(blockParent.offsetWidth) / 2) + canvas_div.scrollLeft - canvas_div.getBoundingClientRect().left - 1; blockstemp[w].y = (blockParent.getBoundingClientRect().top + window.scrollY) + (parseInt(blockParent.offsetHeight) / 2) + canvas_div.scrollTop - canvas_div.getBoundingClientRect().top - 1; } } blockstemp.filter(a => a.id == 0)[0].x = (drag.getBoundingClientRect().left + window.scrollX) + (parseInt(window.getComputedStyle(drag).width) / 2) + canvas_div.scrollLeft - canvas_div.getBoundingClientRect().left; blockstemp.filter(a => a.id == 0)[0].y = (drag.getBoundingClientRect().top + window.scrollY) + (parseInt(window.getComputedStyle(drag).height) / 2) + canvas_div.scrollTop - canvas_div.getBoundingClientRect().top; blocks = blocks.concat(blockstemp); blockstemp = []; } } function drawArrow(arrow, x, y, id) { if (x < 0) { canvas_div.innerHTML += '
'; document.querySelector('.arrowid[value="' + drag.querySelector(".blockid").value + '"]').parentNode.style.left = (arrow.x - 5) - (absx + window.scrollX) + canvas_div.scrollLeft + canvas_div.getBoundingClientRect().left + "px"; } else { canvas_div.innerHTML += '
'; document.querySelector('.arrowid[value="' + parseInt(drag.querySelector(".blockid").value) + '"]').parentNode.style.left = blocks.filter(a => a.id == id)[0].x - 20 - (absx + window.scrollX) + canvas_div.scrollLeft + canvas_div.getBoundingClientRect().left + "px"; } document.querySelector('.arrowid[value="' + parseInt(drag.querySelector(".blockid").value) + '"]').parentNode.style.top = blocks.filter(a => a.id == id)[0].y + (blocks.filter(a => a.id == id)[0].height / 2) + canvas_div.getBoundingClientRect().top - absy + "px"; } function updateArrow(arrow, x, y, children) { if (x < 0) { document.querySelector('.arrowid[value="' + children.id + '"]').parentNode.style.left = (arrow.x - 5) - (absx + window.scrollX) + canvas_div.getBoundingClientRect().left + "px"; document.querySelector('.arrowid[value="' + children.id + '"]').parentNode.innerHTML = ''; } else { document.querySelector('.arrowid[value="' + children.id + '"]').parentNode.style.left = blocks.filter(id => id.id == children.parent)[0].x - 20 - (absx + window.scrollX) + canvas_div.getBoundingClientRect().left + "px"; document.querySelector('.arrowid[value="' + children.id + '"]').parentNode.innerHTML = ''; } } function snap(drag, i, blocko) { if (!rearrange) { canvas_div.appendChild(drag); } var totalwidth = 0; var totalremove = 0; var maxheight = 0; for (var w = 0; w < blocks.filter(id => id.parent == blocko[i]).length; w++) { var children = blocks.filter(id => id.parent == blocko[i])[w]; if (children.childwidth > children.width) { totalwidth += children.childwidth + paddingx; } else { totalwidth += children.width + paddingx; } } totalwidth += parseInt(window.getComputedStyle(drag).width); for (var w = 0; w < blocks.filter(id => id.parent == blocko[i]).length; w++) { var children = blocks.filter(id => id.parent == blocko[i])[w]; if (children.childwidth > children.width) { document.querySelector(".blockid[value='" + children.id + "']").parentNode.style.left = blocks.filter(a => a.id == blocko[i])[0].x - (totalwidth / 2) + totalremove + (children.childwidth / 2) - (children.width / 2) + "px"; children.x = blocks.filter(id => id.parent == blocko[i])[0].x - (totalwidth / 2) + totalremove + (children.childwidth / 2); totalremove += children.childwidth + paddingx; } else { document.querySelector(".blockid[value='" + children.id + "']").parentNode.style.left = blocks.filter(a => a.id == blocko[i])[0].x - (totalwidth / 2) + totalremove + "px"; children.x = blocks.filter(id => id.parent == blocko[i])[0].x - (totalwidth / 2) + totalremove + (children.width / 2); totalremove += children.width + paddingx; } } drag.style.left = blocks.filter(id => id.id == blocko[i])[0].x - (totalwidth / 2) + totalremove - (window.scrollX + absx) + canvas_div.scrollLeft + canvas_div.getBoundingClientRect().left + "px"; drag.style.top = blocks.filter(id => id.id == blocko[i])[0].y + (blocks.filter(id => id.id == blocko[i])[0].height / 2) + paddingy - (window.scrollY + absy) + canvas_div.getBoundingClientRect().top + "px"; if (rearrange) { blockstemp.filter(a => a.id == parseInt(drag.querySelector(".blockid").value))[0].x = (drag.getBoundingClientRect().left + window.scrollX) + (parseInt(window.getComputedStyle(drag).width) / 2) + canvas_div.scrollLeft - canvas_div.getBoundingClientRect().left; blockstemp.filter(a => a.id == parseInt(drag.querySelector(".blockid").value))[0].y = (drag.getBoundingClientRect().top + window.scrollY) + (parseInt(window.getComputedStyle(drag).height) / 2) + canvas_div.scrollTop - canvas_div.getBoundingClientRect().top; blockstemp.filter(a => a.id == drag.querySelector(".blockid").value)[0].parent = blocko[i]; for (var w = 0; w < blockstemp.length; w++) { if (blockstemp[w].id != parseInt(drag.querySelector(".blockid").value)) { const blockParent = document.querySelector(".blockid[value='" + blockstemp[w].id + "']").parentNode; const arrowParent = document.querySelector(".arrowid[value='" + blockstemp[w].id + "']").parentNode; blockParent.style.left = (blockParent.getBoundingClientRect().left + window.scrollX) - (window.scrollX + canvas_div.getBoundingClientRect().left) + canvas_div.scrollLeft + "px"; blockParent.style.top = (blockParent.getBoundingClientRect().top + window.scrollY) - (window.scrollY + canvas_div.getBoundingClientRect().top) + canvas_div.scrollTop + "px"; arrowParent.style.left = (arrowParent.getBoundingClientRect().left + window.scrollX) - (window.scrollX + canvas_div.getBoundingClientRect().left) + canvas_div.scrollLeft + 20 + "px"; arrowParent.style.top = (arrowParent.getBoundingClientRect().top + window.scrollY) - (window.scrollY + canvas_div.getBoundingClientRect().top) + canvas_div.scrollTop + "px"; canvas_div.appendChild(blockParent); canvas_div.appendChild(arrowParent); blockstemp[w].x = (blockParent.getBoundingClientRect().left + window.scrollX) + (parseInt(window.getComputedStyle(blockParent).width) / 2) + canvas_div.scrollLeft - canvas_div.getBoundingClientRect().left; blockstemp[w].y = (blockParent.getBoundingClientRect().top + window.scrollY) + (parseInt(window.getComputedStyle(blockParent).height) / 2) + canvas_div.scrollTop - canvas_div.getBoundingClientRect().top; } } blocks = blocks.concat(blockstemp); blockstemp = []; } else { blocks.push({ childwidth: 0, parent: blocko[i], id: parseInt(drag.querySelector(".blockid").value), x: (drag.getBoundingClientRect().left + window.scrollX) + (parseInt(window.getComputedStyle(drag).width) / 2) + canvas_div.scrollLeft - canvas_div.getBoundingClientRect().left, y: (drag.getBoundingClientRect().top + window.scrollY) + (parseInt(window.getComputedStyle(drag).height) / 2) + canvas_div.scrollTop - canvas_div.getBoundingClientRect().top, width: parseInt(window.getComputedStyle(drag).width), height: parseInt(window.getComputedStyle(drag).height) }); } var arrowblock = blocks.filter(a => a.id == parseInt(drag.querySelector(".blockid").value))[0]; var arrowx = arrowblock.x - blocks.filter(a => a.id == blocko[i])[0].x + 20; var arrowy = paddingy; drawArrow(arrowblock, arrowx, arrowy, blocko[i]); if (blocks.filter(a => a.id == blocko[i])[0].parent != -1) { var flag = false; var idval = blocko[i]; while (!flag) { if (blocks.filter(a => a.id == idval)[0].parent == -1) { flag = true; } else { var zwidth = 0; for (var w = 0; w < blocks.filter(id => id.parent == idval).length; w++) { var children = blocks.filter(id => id.parent == idval)[w]; if (children.childwidth > children.width) { if (w == blocks.filter(id => id.parent == idval).length - 1) { zwidth += children.childwidth; } else { zwidth += children.childwidth + paddingx; } } else { if (w == blocks.filter(id => id.parent == idval).length - 1) { zwidth += children.width; } else { zwidth += children.width + paddingx; } } } blocks.filter(a => a.id == idval)[0].childwidth = zwidth; idval = blocks.filter(a => a.id == idval)[0].parent; } } blocks.filter(id => id.id == idval)[0].childwidth = totalwidth; } if (rearrange) { rearrange = false; drag.classList.remove("dragging"); } rearrangeMe(); checkOffset(); } function touchblock(event) { dragblock = false; if (hasParentClass(event.target, "block")) { var theblock = event.target.closest(".block"); if (event.targetTouches) { mouse_x = event.targetTouches[0].clientX; mouse_y = event.targetTouches[0].clientY; } else { mouse_x = event.clientX; mouse_y = event.clientY; } if (event.type !== "mouseup" && hasParentClass(event.target, "block")) { if (event.which != 3) { if (!active && !rearrange) { dragblock = true; drag = theblock; dragx = mouse_x - (drag.getBoundingClientRect().left + window.scrollX); dragy = mouse_y - (drag.getBoundingClientRect().top + window.scrollY); } } } } } function hasParentClass(element, classname) { if (element.className) { if (element.className.split(' ').indexOf(classname) >= 0) return true; } return element.parentNode && hasParentClass(element.parentNode, classname); } flowy.moveBlock = function(event) { if (event.targetTouches) { mouse_x = event.targetTouches[0].clientX; mouse_y = event.targetTouches[0].clientY; } else { mouse_x = event.clientX; mouse_y = event.clientY; } if (dragblock) { rearrange = true; drag.classList.add("dragging"); var blockid = parseInt(drag.querySelector(".blockid").value); prevblock = blocks.filter(a => a.id == blockid)[0].parent; blockstemp.push(blocks.filter(a => a.id == blockid)[0]); blocks = blocks.filter(function(e) { return e.id != blockid }); if (blockid != 0) { document.querySelector(".arrowid[value='" + blockid + "']").parentNode.remove(); } var layer = blocks.filter(a => a.parent == blockid); var flag = false; var foundids = []; var allids = []; while (!flag) { for (var i = 0; i < layer.length; i++) { if (layer[i] != blockid) { blockstemp.push(blocks.filter(a => a.id == layer[i].id)[0]); const blockParent = document.querySelector(".blockid[value='" + layer[i].id + "']").parentNode; const arrowParent = document.querySelector(".arrowid[value='" + layer[i].id + "']").parentNode; blockParent.style.left = (blockParent.getBoundingClientRect().left + window.scrollX) - (drag.getBoundingClientRect().left + window.scrollX) + "px"; blockParent.style.top = (blockParent.getBoundingClientRect().top + window.scrollY) - (drag.getBoundingClientRect().top + window.scrollY) + "px"; arrowParent.style.left = (arrowParent.getBoundingClientRect().left + window.scrollX) - (drag.getBoundingClientRect().left + window.scrollX) + "px"; arrowParent.style.top = (arrowParent.getBoundingClientRect().top + window.scrollY) - (drag.getBoundingClientRect().top + window.scrollY) + "px"; drag.appendChild(blockParent); drag.appendChild(arrowParent); foundids.push(layer[i].id); allids.push(layer[i].id); } } if (foundids.length == 0) { flag = true; } else { layer = blocks.filter(a => foundids.includes(a.parent)); foundids = []; } } for (var i = 0; i < blocks.filter(a => a.parent == blockid).length; i++) { var blocknumber = blocks.filter(a => a.parent == blockid)[i]; blocks = blocks.filter(function(e) { return e.id != blocknumber }); } for (var i = 0; i < allids.length; i++) { var blocknumber = allids[i]; blocks = blocks.filter(function(e) { return e.id != blocknumber }); } if (blocks.length > 1) { rearrangeMe(); } dragblock = false; } if (active) { drag.style.left = mouse_x - dragx + "px"; drag.style.top = mouse_y - dragy + "px"; } else if (rearrange) { drag.style.left = mouse_x - dragx - (window.scrollX + absx) + canvas_div.scrollLeft + "px"; drag.style.top = mouse_y - dragy - (window.scrollY + absy) + canvas_div.scrollTop + "px"; blockstemp.filter(a => a.id == parseInt(drag.querySelector(".blockid").value)).x = (drag.getBoundingClientRect().left + window.scrollX) + (parseInt(window.getComputedStyle(drag).width) / 2) + canvas_div.scrollLeft; blockstemp.filter(a => a.id == parseInt(drag.querySelector(".blockid").value)).y = (drag.getBoundingClientRect().top + window.scrollY) + (parseInt(window.getComputedStyle(drag).height) / 2) + canvas_div.scrollTop; } if (active || rearrange) { if (mouse_x > canvas_div.getBoundingClientRect().width + canvas_div.getBoundingClientRect().left - 10 && mouse_x < canvas_div.getBoundingClientRect().width + canvas_div.getBoundingClientRect().left + 10) { canvas_div.scrollLeft += 10; } else if (mouse_x < canvas_div.getBoundingClientRect().left + 10 && mouse_x > canvas_div.getBoundingClientRect().left - 10) { canvas_div.scrollLeft -= 10; } else if (mouse_y > canvas_div.getBoundingClientRect().height + canvas_div.getBoundingClientRect().top - 10 && mouse_y < canvas_div.getBoundingClientRect().height + canvas_div.getBoundingClientRect().top + 10) { canvas_div.scrollTop += 10; } else if (mouse_y < canvas_div.getBoundingClientRect().top + 10 && mouse_y > canvas_div.getBoundingClientRect().top - 10) { canvas_div.scrollLeft -= 10; } var xpos = (drag.getBoundingClientRect().left + window.scrollX) + (parseInt(window.getComputedStyle(drag).width) / 2) + canvas_div.scrollLeft - canvas_div.getBoundingClientRect().left; var ypos = (drag.getBoundingClientRect().top + window.scrollY) + canvas_div.scrollTop - canvas_div.getBoundingClientRect().top; var blocko = blocks.map(a => a.id); for (var i = 0; i < blocks.length; i++) { if (checkAttach(blocko[i])) { document.querySelector(".blockid[value='" + blocko[i] + "']").parentNode.appendChild(document.querySelector(".indicator")); document.querySelector(".indicator").style.left = (document.querySelector(".blockid[value='" + blocko[i] + "']").parentNode.offsetWidth / 2) - 5 + "px"; document.querySelector(".indicator").style.top = document.querySelector(".blockid[value='" + blocko[i] + "']").parentNode.offsetHeight + "px"; document.querySelector(".indicator").classList.remove("invisible"); break; } else if (i == blocks.length - 1) { if (!document.querySelector(".indicator").classList.contains("invisible")) { document.querySelector(".indicator").classList.add("invisible"); } } } } } function checkOffset() { offsetleft = blocks.map(a => a.x); var widths = blocks.map(a => a.width); var mathmin = offsetleft.map(function(item, index) { return item - (widths[index] / 2); }) offsetleft = Math.min.apply(Math, mathmin); if (offsetleft < (canvas_div.getBoundingClientRect().left + window.scrollX - absx)) { var blocko = blocks.map(a => a.id); for (var w = 0; w < blocks.length; w++) { document.querySelector(".blockid[value='" + blocks.filter(a => a.id == blocko[w])[0].id + "']").parentNode.style.left = blocks.filter(a => a.id == blocko[w])[0].x - (blocks.filter(a => a.id == blocko[w])[0].width / 2) - offsetleft + canvas_div.getBoundingClientRect().left - absx + 20 + "px"; if (blocks.filter(a => a.id == blocko[w])[0].parent != -1) { var arrowblock = blocks.filter(a => a.id == blocko[w])[0]; var arrowx = arrowblock.x - blocks.filter(a => a.id == blocks.filter(a => a.id == blocko[w])[0].parent)[0].x; if (arrowx < 0) { document.querySelector('.arrowid[value="' + blocko[w] + '"]').parentNode.style.left = (arrowblock.x - offsetleft + 20 - 5) + canvas_div.getBoundingClientRect().left - absx + "px"; } else { document.querySelector('.arrowid[value="' + blocko[w] + '"]').parentNode.style.left = blocks.filter(id => id.id == blocks.filter(a => a.id == blocko[w])[0].parent)[0].x - 20 - offsetleft + canvas_div.getBoundingClientRect().left - absx + 20 + "px"; } } } for (var w = 0; w < blocks.length; w++) { blocks[w].x = (document.querySelector(".blockid[value='" + blocks[w].id + "']").parentNode.getBoundingClientRect().left + window.scrollX) + (canvas_div.scrollLeft) + (parseInt(window.getComputedStyle(document.querySelector(".blockid[value='" + blocks[w].id + "']").parentNode).width) / 2) - 20 - canvas_div.getBoundingClientRect().left; } } } function rearrangeMe() { var result = blocks.map(a => a.parent); for (var z = 0; z < result.length; z++) { if (result[z] == -1) { z++; } var totalwidth = 0; var totalremove = 0; var maxheight = 0; for (var w = 0; w < blocks.filter(id => id.parent == result[z]).length; w++) { var children = blocks.filter(id => id.parent == result[z])[w]; if (blocks.filter(id => id.parent == children.id).length == 0) { children.childwidth = 0; } if (children.childwidth > children.width) { if (w == blocks.filter(id => id.parent == result[z]).length - 1) { totalwidth += children.childwidth; } else { totalwidth += children.childwidth + paddingx; } } else { if (w == blocks.filter(id => id.parent == result[z]).length - 1) { totalwidth += children.width; } else { totalwidth += children.width + paddingx; } } } if (result[z] != -1) { blocks.filter(a => a.id == result[z])[0].childwidth = totalwidth; } for (var w = 0; w < blocks.filter(id => id.parent == result[z]).length; w++) { var children = blocks.filter(id => id.parent == result[z])[w]; const r_block = document.querySelector(".blockid[value='" + children.id + "']").parentNode; const r_array = blocks.filter(id => id.id == result[z]); r_block.style.top = r_array.y + paddingy + canvas_div.getBoundingClientRect().top - absy + "px"; r_array.y = r_array.y + paddingy; if (children.childwidth > children.width) { r_block.style.left = r_array[0].x - (totalwidth / 2) + totalremove + (children.childwidth / 2) - (children.width / 2) - (absx + window.scrollX) + canvas_div.getBoundingClientRect().left + "px"; children.x = r_array[0].x - (totalwidth / 2) + totalremove + (children.childwidth / 2); totalremove += children.childwidth + paddingx; } else { r_block.style.left = r_array[0].x - (totalwidth / 2) + totalremove - (absx + window.scrollX) + canvas_div.getBoundingClientRect().left + "px"; children.x = r_array[0].x - (totalwidth / 2) + totalremove + (children.width / 2); totalremove += children.width + paddingx; } var arrowblock = blocks.filter(a => a.id == children.id)[0]; var arrowx = arrowblock.x - blocks.filter(a => a.id == children.parent)[0].x + 20; var arrowy = paddingy; updateArrow(arrowblock, arrowx, arrowy, children); } } } document.addEventListener("mousedown", flowy.beginDrag); document.addEventListener("mousedown", touchblock, false); document.addEventListener("touchstart", flowy.beginDrag); document.addEventListener("touchstart", touchblock, false); document.addEventListener("mouseup", touchblock, false); document.addEventListener("mousemove", flowy.moveBlock, false); document.addEventListener("touchmove", flowy.moveBlock, false); document.addEventListener("mouseup", flowy.endDrag, false); document.addEventListener("touchend", flowy.endDrag, false); } function blockGrabbed(block) { grab(block); } function blockReleased() { release(); } function blockSnap(drag, first, parent) { return snapping(drag, first, parent); } function beforeDelete(drag, parent) { return rearrange(drag, parent); } function addEventListenerMulti(type, listener, capture, selector) { var nodes = document.querySelectorAll(selector); for (var i = 0; i < nodes.length; i++) { nodes[i].addEventListener(type, listener, capture); } } function removeEventListenerMulti(type, listener, capture, selector) { var nodes = document.querySelectorAll(selector); for (var i = 0; i < nodes.length; i++) { nodes[i].removeEventListener(type, listener, capture); } } flowy.load(); }