@keboola/flow-builder
Advanced tools
Comparing version 0.8.1 to 0.8.2
@@ -1,2 +0,2 @@ | ||
"use strict";var e=require("react");class t{constructor(e,t){this.x=e,this.y=t}subtract(e){return new t(this.x-e.x,this.y-e.y)}dist(e){return Math.hypot(e.x-this.x,e.y-this.y)}css(){return{left:`${this.x}px`,top:`${this.y}px`}}array(){return[this.x,this.y]}}const n=(e=0,n=0)=>new t(e,n);n.from=e=>e instanceof MouseEvent?new t(e.clientX,e.clientY):new t(e[0],e[1]),n.offsetOf=e=>new t(e.left,e.top);const r=(...e)=>e.map((e=>"string"==typeof e?e:e[1]?e[0]:null)).filter((e=>null!==e)).join(" "),l=(e,t)=>{let n=[];for(let r=0,l=e.length;r<l;++r){const l=e[r];t(l,r,e)?n.push(l):e[r-n.length]=l}return e.length-=n.length,n};function o(...e){return t=>{for(let n=0;n<e.length;++n){const r=e[n];r&&("function"==typeof r?r(t):r.current=t)}}}function a(e){let t;return function(n){cancelAnimationFrame(t),t=requestAnimationFrame((()=>e(n)))}}const s=t=>{const n=e.Children.toArray(t);return{remainder:n,inputs:l(n,(e=>{var t;return null===(t=null==e?void 0:e.type)||void 0===t?void 0:t._$isInput})).map((e=>e.props)),outputs:l(n,(e=>{var t;return null===(t=null==e?void 0:e.type)||void 0===t?void 0:t._$isOutput})).map((e=>e.props))}},i=e=>null,u=e=>null;i._$isInput=!0,u._$isOutput=!0;const c=e.createContext({parent:null});const d=e.forwardRef(((t,l)=>{if(!t.children)return null;const i=e.useContext(c),{inputs:u,outputs:d,remainder:m}=s(t.children);"Group"===i.parent&&(u.length>0||d.length>0)&&console.warn("flow-builder: Inputs/Outputs on Nodes within Groups are ignored");const[p,f]=function({onDragStart:t,onDragMove:r,onDragEnd:l,onSelect:o}){const s=[t,r,l,o],[i]=e.useState({start:null,current:null,node:null,container:null}),u=()=>i.container?n.offsetOf(i.container.getBoundingClientRect()):n();return e.useEffect((()=>{const e=a((e=>{if(!i.start)return;e.preventDefault();const l=n.from(e),o=l.subtract(u());i.current?(i.current=o,null==r||r(o.array(),l.array())):i.start.dist(l)>20&&(i.current=o,null==t||t(o.array()))})),s=e=>{(i.current||i.start)&&e.preventDefault(),i.current?null==l||l(n.from(e).subtract(u()).array()):i.start&&(null==o||o()),i.start=null,i.current=null};return window.addEventListener("mousemove",e),window.addEventListener("mouseup",s),()=>{window.removeEventListener("mousemove",e),window.removeEventListener("mouseup",s)}}),s),[e.useCallback((e=>{e&&i.node!==e&&(i.node=e,i.container=function(e,t){for(const n of function*(e){let t=e.parentElement;for(;t;)yield t,t=t.parentElement}(e))if(t(n))return n;return null}(e,(e=>"div"===e.tagName.toLowerCase()&&"graph"===e.dataset.type&&e.classList.contains("flow-builder"))))}),s),e.useCallback((e=>{0===e.button&&(i.start=n(e.clientX,e.clientY))}),s)]}(t.draggable?t:{onSelect:t.onSelect});return e.createElement("div",{ref:o(p,l),"data-type":"node","data-name":t.name,className:r("flow-builder--node",[t.className,!!t.className]),style:Object.assign(Object.assign({},t.style),t.position?n.from(t.position).css():{}),onMouseDown:f,tabIndex:t.onSelect&&0,onKeyDown:e=>{var n;return"Enter"===e.key&&(null===(n=t.onSelect)||void 0===n?void 0:n.call(t))},role:t.onSelect&&"button"},e.createElement("div",{className:"flow-builder--content"},m),e.createElement("div",{className:"flow-builder--io flow-builder--io-top"},"Group"!==i.parent&&u.map((({name:n,children:r,style:l})=>e.createElement("div",{className:"flow-builder--io-port",key:n,"data-name":`${t.name}.${n}`,style:l},r)))),e.createElement("div",{className:"flow-builder--io flow-builder--io-bottom"},"Group"!==i.parent&&d.map((({name:n,children:r,style:l})=>e.createElement("div",{className:"flow-builder--io-port",key:n,"data-name":`${t.name}.${n}`,style:l},r)))))}));exports.Graph=({children:t})=>t?e.createElement("div",{"data-type":"graph",className:"flow-builder"},t):null,exports.Group=t=>{if(!t.children)return null;const{inputs:l,outputs:o,remainder:i}=s(t.children),u=[t.onMouseEnter,t.onMouseLeave],d=e.useRef(null),[m]=e.useState({value:!1});return e.useEffect((()=>{const e=a((e=>{var n,r,l;const o=null===(n=d.current)||void 0===n?void 0:n.getBoundingClientRect();if(!o)return!1;const a=e.clientX,s=e.clientY,i=o.x<a&&o.y<s&&o.x+o.width>a&&o.y+o.height>s;i!==m.value&&(m.value=i,m.value?null===(r=t.onMouseEnter)||void 0===r||r.call(t):null===(l=t.onMouseLeave)||void 0===l||l.call(t))}));return window.addEventListener("mousemove",e,{passive:!0}),()=>window.removeEventListener("mousemove",e)}),u),e.createElement(c.Provider,{value:{parent:"Group"}},e.createElement("div",{ref:d,"data-type":"group","data-name":t.name,className:r("flow-builder--group",[t.className,!!t.className]),style:Object.assign(Object.assign({},t.style),t.position?n.from(t.position).css():{})},e.createElement("div",{className:"flow-builder--content"},i),e.createElement("div",{className:"flow-builder--io flow-builder--io-top"},l.map((({name:n,children:r,style:l})=>e.createElement("div",{className:"flow-builder--io-port",key:n,"data-name":`${t.name}.${n}`,style:l},r)))),e.createElement("div",{className:"flow-builder--io flow-builder--io-bottom"},o.map((({name:n,children:r,style:l})=>e.createElement("div",{className:"flow-builder--io-port",key:n,"data-name":`${t.name}.${n}`,style:l},r))))))},exports.Input=i,exports.Node=d,exports.Output=u; | ||
"use strict";var e=require("react");class t{constructor(e,t){this.x=e,this.y=t}subtract(e){return new t(this.x-e.x,this.y-e.y)}dist(e){return Math.hypot(e.x-this.x,e.y-this.y)}css(){return{left:`${this.x}px`,top:`${this.y}px`}}array(){return[this.x,this.y]}}const n=(e=0,n=0)=>new t(e,n);n.from=e=>e instanceof MouseEvent?new t(e.clientX,e.clientY):new t(e[0],e[1]),n.offsetOf=e=>new t(e.left,e.top);const r=(...e)=>e.map((e=>"string"==typeof e?e:e[1]?e[0]:null)).filter((e=>null!==e)).join(" "),l=(e,t)=>{let n=[];for(let r=0,l=e.length;r<l;++r){const l=e[r];t(l,r,e)?n.push(l):e[r-n.length]=l}return e.length-=n.length,n};function o(...e){return t=>{for(let n=0;n<e.length;++n){const r=e[n];r&&("function"==typeof r?r(t):r.current=t)}}}const a=t=>{const n=e.Children.toArray(t);return{remainder:n,inputs:l(n,(e=>{var t;return null===(t=null==e?void 0:e.type)||void 0===t?void 0:t._$isInput})).map((e=>e.props)),outputs:l(n,(e=>{var t;return null===(t=null==e?void 0:e.type)||void 0===t?void 0:t._$isOutput})).map((e=>e.props))}},s=e=>null,i=e=>null;s._$isInput=!0,i._$isOutput=!0;const u=e.createContext({parent:null});const c=e.forwardRef(((t,l)=>{if(!t.children)return null;const s=e.useContext(u),{inputs:i,outputs:c,remainder:d}=a(t.children);"Group"===s.parent&&(i.length>0||c.length>0)&&console.warn("flow-builder: Inputs/Outputs on Nodes within Groups are ignored");const[m,p]=function({onDragStart:t,onDragMove:r,onDragEnd:l,onSelect:o}){const a=[t,r,l,o],[s]=e.useState({start:null,current:null,node:null,container:null}),i=()=>s.container?n.offsetOf(s.container.getBoundingClientRect()):n();return e.useEffect((()=>{const e=e=>{if(!s.start)return;e.preventDefault();const l=n.from(e),o=l.subtract(i());s.current?(s.current=o,null==r||r(o.array(),l.array())):s.start.dist(l)>20&&(s.current=o,null==t||t(o.array()))},a=e=>{(s.current||s.start)&&e.preventDefault(),s.current?null==l||l(n.from(e).subtract(i()).array()):s.start&&(null==o||o()),s.start=null,s.current=null};return window.addEventListener("mousemove",e),window.addEventListener("mouseup",a),()=>{window.removeEventListener("mousemove",e),window.removeEventListener("mouseup",a)}}),a),[e.useCallback((e=>{e&&s.node!==e&&(s.node=e,s.container=function(e,t){for(const n of function*(e){let t=e.parentElement;for(;t;)yield t,t=t.parentElement}(e))if(t(n))return n;return null}(e,(e=>"div"===e.tagName.toLowerCase()&&"graph"===e.dataset.type&&e.classList.contains("flow-builder"))))}),a),e.useCallback((e=>{0===e.button&&(s.start=n(e.clientX,e.clientY))}),a)]}(t.draggable?t:{onSelect:t.onSelect});return e.createElement("div",{ref:o(m,l),"data-type":"node","data-name":t.name,className:r("flow-builder--node",[t.className,!!t.className]),style:Object.assign(Object.assign({},t.style),t.position?n.from(t.position).css():{}),onMouseDown:p,tabIndex:t.onSelect&&0,onKeyDown:e=>{var n;return"Enter"===e.key&&(null===(n=t.onSelect)||void 0===n?void 0:n.call(t))},role:t.onSelect&&"button"},e.createElement("div",{className:"flow-builder--content"},d),e.createElement("div",{className:"flow-builder--io flow-builder--io-top"},"Group"!==s.parent&&i.map((({name:n,children:r,style:l})=>e.createElement("div",{className:"flow-builder--io-port",key:n,"data-name":`${t.name}.${n}`,style:l},r)))),e.createElement("div",{className:"flow-builder--io flow-builder--io-bottom"},"Group"!==s.parent&&c.map((({name:n,children:r,style:l})=>e.createElement("div",{className:"flow-builder--io-port",key:n,"data-name":`${t.name}.${n}`,style:l},r)))))}));exports.Graph=({children:t})=>t?e.createElement("div",{"data-type":"graph",className:"flow-builder"},t):null,exports.Group=t=>{if(!t.children)return null;const{inputs:l,outputs:o,remainder:s}=a(t.children),i=[t.onMouseEnter,t.onMouseLeave],c=e.useRef(null),[d]=e.useState({value:!1});return e.useEffect((()=>{const e=function(e){let t;return function(n){cancelAnimationFrame(t),t=requestAnimationFrame((()=>e(n)))}}((e=>{var n,r,l;const o=null===(n=c.current)||void 0===n?void 0:n.getBoundingClientRect();if(!o)return!1;const a=e.clientX,s=e.clientY,i=o.x<a&&o.y<s&&o.x+o.width>a&&o.y+o.height>s;i!==d.value&&(d.value=i,d.value?null===(r=t.onMouseEnter)||void 0===r||r.call(t):null===(l=t.onMouseLeave)||void 0===l||l.call(t))}));return window.addEventListener("mousemove",e,{passive:!0}),()=>window.removeEventListener("mousemove",e)}),i),e.createElement(u.Provider,{value:{parent:"Group"}},e.createElement("div",{ref:c,"data-type":"group","data-name":t.name,className:r("flow-builder--group",[t.className,!!t.className]),style:Object.assign(Object.assign({},t.style),t.position?n.from(t.position).css():{})},e.createElement("div",{className:"flow-builder--content"},s),e.createElement("div",{className:"flow-builder--io flow-builder--io-top"},l.map((({name:n,children:r,style:l})=>e.createElement("div",{className:"flow-builder--io-port",key:n,"data-name":`${t.name}.${n}`,style:l},r)))),e.createElement("div",{className:"flow-builder--io flow-builder--io-bottom"},o.map((({name:n,children:r,style:l})=>e.createElement("div",{className:"flow-builder--io-port",key:n,"data-name":`${t.name}.${n}`,style:l},r))))))},exports.Input=s,exports.Node=c,exports.Output=i; | ||
//# sourceMappingURL=index.cjs.js.map |
@@ -1,2 +0,2 @@ | ||
import e,{Children as t,createContext as n,useState as r,useEffect as l,useCallback as o,useContext as a,useRef as i}from"react";class s{constructor(e,t){this.x=e,this.y=t}subtract(e){return new s(this.x-e.x,this.y-e.y)}dist(e){return Math.hypot(e.x-this.x,e.y-this.y)}css(){return{left:`${this.x}px`,top:`${this.y}px`}}array(){return[this.x,this.y]}}const u=(e=0,t=0)=>new s(e,t);u.from=e=>e instanceof MouseEvent?new s(e.clientX,e.clientY):new s(e[0],e[1]),u.offsetOf=e=>new s(e.left,e.top);const c=(...e)=>e.map((e=>"string"==typeof e?e:e[1]?e[0]:null)).filter((e=>null!==e)).join(" "),d=(e,t)=>{let n=[];for(let r=0,l=e.length;r<l;++r){const l=e[r];t(l,r,e)?n.push(l):e[r-n.length]=l}return e.length-=n.length,n};function m(...e){return t=>{for(let n=0;n<e.length;++n){const r=e[n];r&&("function"==typeof r?r(t):r.current=t)}}}function p(e){let t;return function(n){cancelAnimationFrame(t),t=requestAnimationFrame((()=>e(n)))}}const f=e=>{const n=t.toArray(e);return{remainder:n,inputs:d(n,(e=>{var t;return null===(t=null==e?void 0:e.type)||void 0===t?void 0:t._$isInput})).map((e=>e.props)),outputs:d(n,(e=>{var t;return null===(t=null==e?void 0:e.type)||void 0===t?void 0:t._$isOutput})).map((e=>e.props))}},v=e=>null,w=e=>null;v._$isInput=!0,w._$isOutput=!0;const y=n({parent:null});const h=e.forwardRef(((t,n)=>{if(!t.children)return null;const i=a(y),{inputs:s,outputs:d,remainder:v}=f(t.children);"Group"===i.parent&&(s.length>0||d.length>0)&&console.warn("flow-builder: Inputs/Outputs on Nodes within Groups are ignored");const[w,h]=function({onDragStart:e,onDragMove:t,onDragEnd:n,onSelect:a}){const i=[e,t,n,a],[s]=r({start:null,current:null,node:null,container:null}),c=()=>s.container?u.offsetOf(s.container.getBoundingClientRect()):u();return l((()=>{const r=p((n=>{if(!s.start)return;n.preventDefault();const r=u.from(n),l=r.subtract(c());s.current?(s.current=l,null==t||t(l.array(),r.array())):s.start.dist(r)>20&&(s.current=l,null==e||e(l.array()))})),l=e=>{(s.current||s.start)&&e.preventDefault(),s.current?null==n||n(u.from(e).subtract(c()).array()):s.start&&(null==a||a()),s.start=null,s.current=null};return window.addEventListener("mousemove",r),window.addEventListener("mouseup",l),()=>{window.removeEventListener("mousemove",r),window.removeEventListener("mouseup",l)}}),i),[o((e=>{e&&s.node!==e&&(s.node=e,s.container=function(e,t){for(const n of function*(e){let t=e.parentElement;for(;t;)yield t,t=t.parentElement}(e))if(t(n))return n;return null}(e,(e=>"div"===e.tagName.toLowerCase()&&"graph"===e.dataset.type&&e.classList.contains("flow-builder"))))}),i),o((e=>{0===e.button&&(s.start=u(e.clientX,e.clientY))}),i)]}(t.draggable?t:{onSelect:t.onSelect});return e.createElement("div",{ref:m(w,n),"data-type":"node","data-name":t.name,className:c("flow-builder--node",[t.className,!!t.className]),style:Object.assign(Object.assign({},t.style),t.position?u.from(t.position).css():{}),onMouseDown:h,tabIndex:t.onSelect&&0,onKeyDown:e=>{var n;return"Enter"===e.key&&(null===(n=t.onSelect)||void 0===n?void 0:n.call(t))},role:t.onSelect&&"button"},e.createElement("div",{className:"flow-builder--content"},v),e.createElement("div",{className:"flow-builder--io flow-builder--io-top"},"Group"!==i.parent&&s.map((({name:n,children:r,style:l})=>e.createElement("div",{className:"flow-builder--io-port",key:n,"data-name":`${t.name}.${n}`,style:l},r)))),e.createElement("div",{className:"flow-builder--io flow-builder--io-bottom"},"Group"!==i.parent&&d.map((({name:n,children:r,style:l})=>e.createElement("div",{className:"flow-builder--io-port",key:n,"data-name":`${t.name}.${n}`,style:l},r)))))})),b=t=>{if(!t.children)return null;const{inputs:n,outputs:o,remainder:a}=f(t.children),s=[t.onMouseEnter,t.onMouseLeave],d=i(null),[m]=r({value:!1});return l((()=>{const e=p((e=>{var n,r,l;const o=null===(n=d.current)||void 0===n?void 0:n.getBoundingClientRect();if(!o)return!1;const a=e.clientX,i=e.clientY,s=o.x<a&&o.y<i&&o.x+o.width>a&&o.y+o.height>i;s!==m.value&&(m.value=s,m.value?null===(r=t.onMouseEnter)||void 0===r||r.call(t):null===(l=t.onMouseLeave)||void 0===l||l.call(t))}));return window.addEventListener("mousemove",e,{passive:!0}),()=>window.removeEventListener("mousemove",e)}),s),e.createElement(y.Provider,{value:{parent:"Group"}},e.createElement("div",{ref:d,"data-type":"group","data-name":t.name,className:c("flow-builder--group",[t.className,!!t.className]),style:Object.assign(Object.assign({},t.style),t.position?u.from(t.position).css():{})},e.createElement("div",{className:"flow-builder--content"},a),e.createElement("div",{className:"flow-builder--io flow-builder--io-top"},n.map((({name:n,children:r,style:l})=>e.createElement("div",{className:"flow-builder--io-port",key:n,"data-name":`${t.name}.${n}`,style:l},r)))),e.createElement("div",{className:"flow-builder--io flow-builder--io-bottom"},o.map((({name:n,children:r,style:l})=>e.createElement("div",{className:"flow-builder--io-port",key:n,"data-name":`${t.name}.${n}`,style:l},r))))))},g=({children:t})=>t?e.createElement("div",{"data-type":"graph",className:"flow-builder"},t):null;export{g as Graph,b as Group,v as Input,h as Node,w as Output}; | ||
import e,{Children as t,createContext as n,useState as r,useEffect as l,useCallback as o,useContext as a,useRef as i}from"react";class s{constructor(e,t){this.x=e,this.y=t}subtract(e){return new s(this.x-e.x,this.y-e.y)}dist(e){return Math.hypot(e.x-this.x,e.y-this.y)}css(){return{left:`${this.x}px`,top:`${this.y}px`}}array(){return[this.x,this.y]}}const u=(e=0,t=0)=>new s(e,t);u.from=e=>e instanceof MouseEvent?new s(e.clientX,e.clientY):new s(e[0],e[1]),u.offsetOf=e=>new s(e.left,e.top);const c=(...e)=>e.map((e=>"string"==typeof e?e:e[1]?e[0]:null)).filter((e=>null!==e)).join(" "),d=(e,t)=>{let n=[];for(let r=0,l=e.length;r<l;++r){const l=e[r];t(l,r,e)?n.push(l):e[r-n.length]=l}return e.length-=n.length,n};function m(...e){return t=>{for(let n=0;n<e.length;++n){const r=e[n];r&&("function"==typeof r?r(t):r.current=t)}}}const p=e=>{const n=t.toArray(e);return{remainder:n,inputs:d(n,(e=>{var t;return null===(t=null==e?void 0:e.type)||void 0===t?void 0:t._$isInput})).map((e=>e.props)),outputs:d(n,(e=>{var t;return null===(t=null==e?void 0:e.type)||void 0===t?void 0:t._$isOutput})).map((e=>e.props))}},f=e=>null,v=e=>null;f._$isInput=!0,v._$isOutput=!0;const w=n({parent:null});const y=e.forwardRef(((t,n)=>{if(!t.children)return null;const i=a(w),{inputs:s,outputs:d,remainder:f}=p(t.children);"Group"===i.parent&&(s.length>0||d.length>0)&&console.warn("flow-builder: Inputs/Outputs on Nodes within Groups are ignored");const[v,y]=function({onDragStart:e,onDragMove:t,onDragEnd:n,onSelect:a}){const i=[e,t,n,a],[s]=r({start:null,current:null,node:null,container:null}),c=()=>s.container?u.offsetOf(s.container.getBoundingClientRect()):u();return l((()=>{const r=n=>{if(!s.start)return;n.preventDefault();const r=u.from(n),l=r.subtract(c());s.current?(s.current=l,null==t||t(l.array(),r.array())):s.start.dist(r)>20&&(s.current=l,null==e||e(l.array()))},l=e=>{(s.current||s.start)&&e.preventDefault(),s.current?null==n||n(u.from(e).subtract(c()).array()):s.start&&(null==a||a()),s.start=null,s.current=null};return window.addEventListener("mousemove",r),window.addEventListener("mouseup",l),()=>{window.removeEventListener("mousemove",r),window.removeEventListener("mouseup",l)}}),i),[o((e=>{e&&s.node!==e&&(s.node=e,s.container=function(e,t){for(const n of function*(e){let t=e.parentElement;for(;t;)yield t,t=t.parentElement}(e))if(t(n))return n;return null}(e,(e=>"div"===e.tagName.toLowerCase()&&"graph"===e.dataset.type&&e.classList.contains("flow-builder"))))}),i),o((e=>{0===e.button&&(s.start=u(e.clientX,e.clientY))}),i)]}(t.draggable?t:{onSelect:t.onSelect});return e.createElement("div",{ref:m(v,n),"data-type":"node","data-name":t.name,className:c("flow-builder--node",[t.className,!!t.className]),style:Object.assign(Object.assign({},t.style),t.position?u.from(t.position).css():{}),onMouseDown:y,tabIndex:t.onSelect&&0,onKeyDown:e=>{var n;return"Enter"===e.key&&(null===(n=t.onSelect)||void 0===n?void 0:n.call(t))},role:t.onSelect&&"button"},e.createElement("div",{className:"flow-builder--content"},f),e.createElement("div",{className:"flow-builder--io flow-builder--io-top"},"Group"!==i.parent&&s.map((({name:n,children:r,style:l})=>e.createElement("div",{className:"flow-builder--io-port",key:n,"data-name":`${t.name}.${n}`,style:l},r)))),e.createElement("div",{className:"flow-builder--io flow-builder--io-bottom"},"Group"!==i.parent&&d.map((({name:n,children:r,style:l})=>e.createElement("div",{className:"flow-builder--io-port",key:n,"data-name":`${t.name}.${n}`,style:l},r)))))})),h=t=>{if(!t.children)return null;const{inputs:n,outputs:o,remainder:a}=p(t.children),s=[t.onMouseEnter,t.onMouseLeave],d=i(null),[m]=r({value:!1});return l((()=>{const e=function(e){let t;return function(n){cancelAnimationFrame(t),t=requestAnimationFrame((()=>e(n)))}}((e=>{var n,r,l;const o=null===(n=d.current)||void 0===n?void 0:n.getBoundingClientRect();if(!o)return!1;const a=e.clientX,i=e.clientY,s=o.x<a&&o.y<i&&o.x+o.width>a&&o.y+o.height>i;s!==m.value&&(m.value=s,m.value?null===(r=t.onMouseEnter)||void 0===r||r.call(t):null===(l=t.onMouseLeave)||void 0===l||l.call(t))}));return window.addEventListener("mousemove",e,{passive:!0}),()=>window.removeEventListener("mousemove",e)}),s),e.createElement(w.Provider,{value:{parent:"Group"}},e.createElement("div",{ref:d,"data-type":"group","data-name":t.name,className:c("flow-builder--group",[t.className,!!t.className]),style:Object.assign(Object.assign({},t.style),t.position?u.from(t.position).css():{})},e.createElement("div",{className:"flow-builder--content"},a),e.createElement("div",{className:"flow-builder--io flow-builder--io-top"},n.map((({name:n,children:r,style:l})=>e.createElement("div",{className:"flow-builder--io-port",key:n,"data-name":`${t.name}.${n}`,style:l},r)))),e.createElement("div",{className:"flow-builder--io flow-builder--io-bottom"},o.map((({name:n,children:r,style:l})=>e.createElement("div",{className:"flow-builder--io-port",key:n,"data-name":`${t.name}.${n}`,style:l},r))))))},b=({children:t})=>t?e.createElement("div",{"data-type":"graph",className:"flow-builder"},t):null;export{b as Graph,h as Group,f as Input,y as Node,v as Output}; | ||
//# sourceMappingURL=index.esm.js.map |
@@ -1,2 +0,2 @@ | ||
!function(e,t){"object"==typeof exports&&"undefined"!=typeof module?t(exports,require("react")):"function"==typeof define&&define.amd?define(["exports","react"],t):t((e="undefined"!=typeof globalThis?globalThis:e||self).Flow={},e.React)}(this,(function(e,t){"use strict";class n{constructor(e,t){this.x=e,this.y=t}subtract(e){return new n(this.x-e.x,this.y-e.y)}dist(e){return Math.hypot(e.x-this.x,e.y-this.y)}css(){return{left:`${this.x}px`,top:`${this.y}px`}}array(){return[this.x,this.y]}}const r=(e=0,t=0)=>new n(e,t);r.from=e=>e instanceof MouseEvent?new n(e.clientX,e.clientY):new n(e[0],e[1]),r.offsetOf=e=>new n(e.left,e.top);const o=(...e)=>e.map((e=>"string"==typeof e?e:e[1]?e[0]:null)).filter((e=>null!==e)).join(" "),l=(e,t)=>{let n=[];for(let r=0,o=e.length;r<o;++r){const o=e[r];t(o,r,e)?n.push(o):e[r-n.length]=o}return e.length-=n.length,n};function a(...e){return t=>{for(let n=0;n<e.length;++n){const r=e[n];r&&("function"==typeof r?r(t):r.current=t)}}}function s(e){let t;return function(n){cancelAnimationFrame(t),t=requestAnimationFrame((()=>e(n)))}}const i=e=>{const n=t.Children.toArray(e);return{remainder:n,inputs:l(n,(e=>{var t;return null===(t=null==e?void 0:e.type)||void 0===t?void 0:t._$isInput})).map((e=>e.props)),outputs:l(n,(e=>{var t;return null===(t=null==e?void 0:e.type)||void 0===t?void 0:t._$isOutput})).map((e=>e.props))}},u=e=>null,c=e=>null;u._$isInput=!0,c._$isOutput=!0;const d=t.createContext({parent:null});const m=t.forwardRef(((e,n)=>{if(!e.children)return null;const l=t.useContext(d),{inputs:u,outputs:c,remainder:m}=i(e.children);"Group"===l.parent&&(u.length>0||c.length>0)&&console.warn("flow-builder: Inputs/Outputs on Nodes within Groups are ignored");const[p,f]=function({onDragStart:e,onDragMove:n,onDragEnd:o,onSelect:l}){const a=[e,n,o,l],[i]=t.useState({start:null,current:null,node:null,container:null}),u=()=>i.container?r.offsetOf(i.container.getBoundingClientRect()):r();return t.useEffect((()=>{const t=s((t=>{if(!i.start)return;t.preventDefault();const o=r.from(t),l=o.subtract(u());i.current?(i.current=l,null==n||n(l.array(),o.array())):i.start.dist(o)>20&&(i.current=l,null==e||e(l.array()))})),a=e=>{(i.current||i.start)&&e.preventDefault(),i.current?null==o||o(r.from(e).subtract(u()).array()):i.start&&(null==l||l()),i.start=null,i.current=null};return window.addEventListener("mousemove",t),window.addEventListener("mouseup",a),()=>{window.removeEventListener("mousemove",t),window.removeEventListener("mouseup",a)}}),a),[t.useCallback((e=>{e&&i.node!==e&&(i.node=e,i.container=function(e,t){for(const n of function*(e){let t=e.parentElement;for(;t;)yield t,t=t.parentElement}(e))if(t(n))return n;return null}(e,(e=>"div"===e.tagName.toLowerCase()&&"graph"===e.dataset.type&&e.classList.contains("flow-builder"))))}),a),t.useCallback((e=>{0===e.button&&(i.start=r(e.clientX,e.clientY))}),a)]}(e.draggable?e:{onSelect:e.onSelect});return t.createElement("div",{ref:a(p,n),"data-type":"node","data-name":e.name,className:o("flow-builder--node",[e.className,!!e.className]),style:Object.assign(Object.assign({},e.style),e.position?r.from(e.position).css():{}),onMouseDown:f,tabIndex:e.onSelect&&0,onKeyDown:t=>{var n;return"Enter"===t.key&&(null===(n=e.onSelect)||void 0===n?void 0:n.call(e))},role:e.onSelect&&"button"},t.createElement("div",{className:"flow-builder--content"},m),t.createElement("div",{className:"flow-builder--io flow-builder--io-top"},"Group"!==l.parent&&u.map((({name:n,children:r,style:o})=>t.createElement("div",{className:"flow-builder--io-port",key:n,"data-name":`${e.name}.${n}`,style:o},r)))),t.createElement("div",{className:"flow-builder--io flow-builder--io-bottom"},"Group"!==l.parent&&c.map((({name:n,children:r,style:o})=>t.createElement("div",{className:"flow-builder--io-port",key:n,"data-name":`${e.name}.${n}`,style:o},r)))))}));e.Graph=({children:e})=>e?t.createElement("div",{"data-type":"graph",className:"flow-builder"},e):null,e.Group=e=>{if(!e.children)return null;const{inputs:n,outputs:l,remainder:a}=i(e.children),u=[e.onMouseEnter,e.onMouseLeave],c=t.useRef(null),[m]=t.useState({value:!1});return t.useEffect((()=>{const t=s((t=>{var n,r,o;const l=null===(n=c.current)||void 0===n?void 0:n.getBoundingClientRect();if(!l)return!1;const a=t.clientX,s=t.clientY,i=l.x<a&&l.y<s&&l.x+l.width>a&&l.y+l.height>s;i!==m.value&&(m.value=i,m.value?null===(r=e.onMouseEnter)||void 0===r||r.call(e):null===(o=e.onMouseLeave)||void 0===o||o.call(e))}));return window.addEventListener("mousemove",t,{passive:!0}),()=>window.removeEventListener("mousemove",t)}),u),t.createElement(d.Provider,{value:{parent:"Group"}},t.createElement("div",{ref:c,"data-type":"group","data-name":e.name,className:o("flow-builder--group",[e.className,!!e.className]),style:Object.assign(Object.assign({},e.style),e.position?r.from(e.position).css():{})},t.createElement("div",{className:"flow-builder--content"},a),t.createElement("div",{className:"flow-builder--io flow-builder--io-top"},n.map((({name:n,children:r,style:o})=>t.createElement("div",{className:"flow-builder--io-port",key:n,"data-name":`${e.name}.${n}`,style:o},r)))),t.createElement("div",{className:"flow-builder--io flow-builder--io-bottom"},l.map((({name:n,children:r,style:o})=>t.createElement("div",{className:"flow-builder--io-port",key:n,"data-name":`${e.name}.${n}`,style:o},r))))))},e.Input=u,e.Node=m,e.Output=c})); | ||
!function(e,t){"object"==typeof exports&&"undefined"!=typeof module?t(exports,require("react")):"function"==typeof define&&define.amd?define(["exports","react"],t):t((e="undefined"!=typeof globalThis?globalThis:e||self).Flow={},e.React)}(this,(function(e,t){"use strict";class n{constructor(e,t){this.x=e,this.y=t}subtract(e){return new n(this.x-e.x,this.y-e.y)}dist(e){return Math.hypot(e.x-this.x,e.y-this.y)}css(){return{left:`${this.x}px`,top:`${this.y}px`}}array(){return[this.x,this.y]}}const r=(e=0,t=0)=>new n(e,t);r.from=e=>e instanceof MouseEvent?new n(e.clientX,e.clientY):new n(e[0],e[1]),r.offsetOf=e=>new n(e.left,e.top);const o=(...e)=>e.map((e=>"string"==typeof e?e:e[1]?e[0]:null)).filter((e=>null!==e)).join(" "),l=(e,t)=>{let n=[];for(let r=0,o=e.length;r<o;++r){const o=e[r];t(o,r,e)?n.push(o):e[r-n.length]=o}return e.length-=n.length,n};function a(...e){return t=>{for(let n=0;n<e.length;++n){const r=e[n];r&&("function"==typeof r?r(t):r.current=t)}}}const s=e=>{const n=t.Children.toArray(e);return{remainder:n,inputs:l(n,(e=>{var t;return null===(t=null==e?void 0:e.type)||void 0===t?void 0:t._$isInput})).map((e=>e.props)),outputs:l(n,(e=>{var t;return null===(t=null==e?void 0:e.type)||void 0===t?void 0:t._$isOutput})).map((e=>e.props))}},i=e=>null,u=e=>null;i._$isInput=!0,u._$isOutput=!0;const c=t.createContext({parent:null});const d=t.forwardRef(((e,n)=>{if(!e.children)return null;const l=t.useContext(c),{inputs:i,outputs:u,remainder:d}=s(e.children);"Group"===l.parent&&(i.length>0||u.length>0)&&console.warn("flow-builder: Inputs/Outputs on Nodes within Groups are ignored");const[m,p]=function({onDragStart:e,onDragMove:n,onDragEnd:o,onSelect:l}){const a=[e,n,o,l],[s]=t.useState({start:null,current:null,node:null,container:null}),i=()=>s.container?r.offsetOf(s.container.getBoundingClientRect()):r();return t.useEffect((()=>{const t=t=>{if(!s.start)return;t.preventDefault();const o=r.from(t),l=o.subtract(i());s.current?(s.current=l,null==n||n(l.array(),o.array())):s.start.dist(o)>20&&(s.current=l,null==e||e(l.array()))},a=e=>{(s.current||s.start)&&e.preventDefault(),s.current?null==o||o(r.from(e).subtract(i()).array()):s.start&&(null==l||l()),s.start=null,s.current=null};return window.addEventListener("mousemove",t),window.addEventListener("mouseup",a),()=>{window.removeEventListener("mousemove",t),window.removeEventListener("mouseup",a)}}),a),[t.useCallback((e=>{e&&s.node!==e&&(s.node=e,s.container=function(e,t){for(const n of function*(e){let t=e.parentElement;for(;t;)yield t,t=t.parentElement}(e))if(t(n))return n;return null}(e,(e=>"div"===e.tagName.toLowerCase()&&"graph"===e.dataset.type&&e.classList.contains("flow-builder"))))}),a),t.useCallback((e=>{0===e.button&&(s.start=r(e.clientX,e.clientY))}),a)]}(e.draggable?e:{onSelect:e.onSelect});return t.createElement("div",{ref:a(m,n),"data-type":"node","data-name":e.name,className:o("flow-builder--node",[e.className,!!e.className]),style:Object.assign(Object.assign({},e.style),e.position?r.from(e.position).css():{}),onMouseDown:p,tabIndex:e.onSelect&&0,onKeyDown:t=>{var n;return"Enter"===t.key&&(null===(n=e.onSelect)||void 0===n?void 0:n.call(e))},role:e.onSelect&&"button"},t.createElement("div",{className:"flow-builder--content"},d),t.createElement("div",{className:"flow-builder--io flow-builder--io-top"},"Group"!==l.parent&&i.map((({name:n,children:r,style:o})=>t.createElement("div",{className:"flow-builder--io-port",key:n,"data-name":`${e.name}.${n}`,style:o},r)))),t.createElement("div",{className:"flow-builder--io flow-builder--io-bottom"},"Group"!==l.parent&&u.map((({name:n,children:r,style:o})=>t.createElement("div",{className:"flow-builder--io-port",key:n,"data-name":`${e.name}.${n}`,style:o},r)))))}));e.Graph=({children:e})=>e?t.createElement("div",{"data-type":"graph",className:"flow-builder"},e):null,e.Group=e=>{if(!e.children)return null;const{inputs:n,outputs:l,remainder:a}=s(e.children),i=[e.onMouseEnter,e.onMouseLeave],u=t.useRef(null),[d]=t.useState({value:!1});return t.useEffect((()=>{const t=function(e){let t;return function(n){cancelAnimationFrame(t),t=requestAnimationFrame((()=>e(n)))}}((t=>{var n,r,o;const l=null===(n=u.current)||void 0===n?void 0:n.getBoundingClientRect();if(!l)return!1;const a=t.clientX,s=t.clientY,i=l.x<a&&l.y<s&&l.x+l.width>a&&l.y+l.height>s;i!==d.value&&(d.value=i,d.value?null===(r=e.onMouseEnter)||void 0===r||r.call(e):null===(o=e.onMouseLeave)||void 0===o||o.call(e))}));return window.addEventListener("mousemove",t,{passive:!0}),()=>window.removeEventListener("mousemove",t)}),i),t.createElement(c.Provider,{value:{parent:"Group"}},t.createElement("div",{ref:u,"data-type":"group","data-name":e.name,className:o("flow-builder--group",[e.className,!!e.className]),style:Object.assign(Object.assign({},e.style),e.position?r.from(e.position).css():{})},t.createElement("div",{className:"flow-builder--content"},a),t.createElement("div",{className:"flow-builder--io flow-builder--io-top"},n.map((({name:n,children:r,style:o})=>t.createElement("div",{className:"flow-builder--io-port",key:n,"data-name":`${e.name}.${n}`,style:o},r)))),t.createElement("div",{className:"flow-builder--io flow-builder--io-bottom"},l.map((({name:n,children:r,style:o})=>t.createElement("div",{className:"flow-builder--io-port",key:n,"data-name":`${e.name}.${n}`,style:o},r))))))},e.Input=i,e.Node=d,e.Output=u})); | ||
//# sourceMappingURL=index.umd.js.map |
{ | ||
"name": "@keboola/flow-builder", | ||
"description": "Flow graph rendering", | ||
"version": "0.8.1", | ||
"version": "0.8.2", | ||
"license": "MIT", | ||
@@ -6,0 +6,0 @@ "repository": { |
Sorry, the diff of this file is not supported yet
Sorry, the diff of this file is not supported yet
Sorry, the diff of this file is not supported yet
License Policy Violation
LicenseThis package is not allowed per your license policy. Review the package's license to ensure compliance.
Found 1 instance in 1 package
License Policy Violation
LicenseThis package is not allowed per your license policy. Review the package's license to ensure compliance.
Found 1 instance in 1 package
47394