@babsey/code-graph 0.0.16 → 0.0.17
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/dist/code-graph.css +1 -1
- package/dist/code-graph.js +563 -502
- package/dist/code-graph.umd.cjs +1 -1
- package/dist/code.d.ts +2 -0
- package/dist/codeNode/codeNode.d.ts +4 -2
- package/dist/codeNode/defineCodeNode.d.ts +1 -0
- package/dist/codeNode/dynamicCodeNode.d.ts +1 -0
- package/dist/codeNodeInterfaces/baseStringInterface.d.ts +1 -0
- package/dist/codeNodeInterfaces/checkbox/checkboxInterface.d.ts +1 -0
- package/dist/codeNodeInterfaces/codeNode/codeNodeInterface.d.ts +1 -0
- package/dist/codeNodeInterfaces/index.d.ts +2 -0
- package/dist/codeNodeInterfaces/integer/integerInterface.d.ts +0 -2
- package/dist/codeNodeInterfaces/listInput/listInputInterface.d.ts +5 -0
- package/dist/codeNodeInterfaces/select/selectInterface.d.ts +0 -2
- package/dist/codeNodeInterfaces/slider/sliderInterface.d.ts +1 -2
- package/dist/codeNodeInterfaces/textInput/textInputInterface.d.ts +0 -2
- package/dist/codeNodeInterfaces/textareaInput/textareaInputInterface.d.ts +0 -2
- package/dist/codeNodeInterfaces/tupleInput/tupleInputInterface.d.ts +5 -0
- package/dist/components/node/CodeGraphNode.vue.d.ts +4 -4
- package/dist/icons/DotsVertical.vue.d.ts +2 -0
- package/dist/icons/TransitionBottom.vue.d.ts +2 -0
- package/dist/icons/index.d.ts +3 -1
- package/dist/interfaceTypes/default.d.ts +1 -0
- package/package.json +2 -1
- /package/dist/icons/{VerticalDots.vue.d.ts → CodeVariable.vue.d.ts} +0 -0
package/dist/code-graph.umd.cjs
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
(function(d,r){typeof exports=="object"&&typeof module<"u"?r(exports,require("baklavajs"),require("mustache"),require("vue"),require("toposort"),require("uuid"),require("@vueuse/core")):typeof define=="function"&&define.amd?define(["exports","baklavajs","mustache","vue","toposort","uuid","@vueuse/core"],r):(d=typeof globalThis<"u"?globalThis:d||self,r(d["@babsey/code-graph"]={},d.baklavajs,d.mustache,d.Vue,d.toposort,d.uuid,d["@vueuse/core"]))})(this,(function(d,r,M,e,ae,ie,re){"use strict";M.escape=o=>o;class U extends r.AbstractNode{state;code;isCodeNode=!0;codeTemplate=()=>"{{ outputs.code }}";inputs={};outputs={};constructor(){super(),this.initializeIo(),this.width=400,this.twoColumn=!0,this.state=e.reactive({codeTemplate:"",hidden:!1,integrated:!1,modules:[],script:"",variableName:""})}get codeNodeInputs(){return Object.fromEntries(Object.entries(this.inputs).filter(([t,n])=>n.type!="node"))}get idx(){return this.code?.codeNodes.filter(t=>!t.state.integrated).indexOf(this)??-1}get idxByVariableNames(){return this.code?.getNodesBySameVariableNames(this.state.variableName).indexOf(this)??-1}get optionalInputs(){return Object.fromEntries(Object.entries(this.codeNodeInputs).filter(([t,n])=>n.optional))}get requiredInputs(){return Object.fromEntries(Object.entries(this.codeNodeInputs).filter(([t,n])=>!n.optional))}get script(){return this.state.script}get shortId(){return this.id.slice(0,6)}get subgraph(){}get variableName(){return this.state.variableName?this.state.variableName+(this.idxByVariableNames+1):""}getConnectedNodes(t){let n=[];if(t!=="inputs"){const s=this.graph?.connections.filter(a=>a.from.name!=="_node").filter(a=>a.from.nodeId===this.id).map(a=>a.to.nodeId);s&&(n=n.concat(s))}if(t!=="outputs"){const s=this.graph?.connections.filter(a=>a.from.name!=="_node").filter(a=>a.to.nodeId===this.id).map(a=>a.from.nodeId);s&&(n=n.concat(s))}return!n||n.length==0?[]:n.map(s=>this.graph?.findNodeById(s))}registerCode(t){this.code=t}renderCode(){this.state.codeTemplate=this.codeTemplate.call(this);const t={};Object.keys(this.inputs).forEach(s=>{if(s==="_node")return;const a=this.inputs[s],i=A(a);a&&a.state&&(t[s]=a.state.script.length>0?a.state.script:i)});const n={};Object.keys(this.outputs).forEach(s=>{if(s==="_node")return;const a=this.outputs[s],i=A(a);a&&a.state&&(n[s]=i)}),this.state.script=M.render(this.state.codeTemplate,{inputs:t,outputs:n}),this.outputs.code&&(this.outputs.code.state.script=this.state.script)}updateCodeNodeInputInterfaces(){if(!this.graph)return;const{connectionsFromNode:t}=r.sortTopologically(this.graph);t.has(this)&&t.get(this).forEach(n=>{const s=this.graph?.findNodeById(n.from.nodeId);s&&(s.renderCode(),n.from.isCodeNode&&n.to.isCodeNode&&(n.to.state.script=n.from.script))})}updateOutputVariableName(){this.outputs.code&&(this.outputs.code.name=this.variableName)}}class v extends U{calculate;load(t){super.load(t),L(this.graph,t)}save(){const t=super.save();return F(this.graph,t),t}updateModules(t){if(t)this.state.modules=t;else if(this.type.includes(".")){const n=this.type.split(".");this.state.modules.push(n.slice(0,n.length-1).join("."))}}}const de=o=>{const t=[],n=Object.keys(o);return n.forEach(s=>{if(o[s]?.hidden)return;const i=t.length<n.indexOf(s)?`${s}=`:"";t.push(`${i}{{ inputs.${s} }}`)}),t},L=(o,t)=>{if(!o)return;const n=o.findNodeById(t.id);if(!n||n.subgraph)return;const s=n;s.state&&(s.state.integrated=t.integrated,s.state.modules=t.modules,s.state.props=t.props),Object.entries(t.inputs).forEach(([a,i])=>{a!=="_node"&&s.inputs[a]&&(s.inputs[a].hidden=i.hidden)}),Object.entries(t.outputs).forEach(([a,i])=>{a!=="_node"&&s.outputs[a]&&(s.outputs[a].hidden=i.hidden)})},F=(o,t)=>{if(!o)return;const n=o.findNodeById(t.id);if(!n||n.subgraph)return;const s=n;s.state&&(t.integrated=s.state.integrated,t.modules=s.state.modules),Object.entries(t.inputs).forEach(([a,i])=>{a!=="_node"&&s.inputs[a]&&(i.hidden=s.inputs[a].hidden)}),Object.entries(t.outputs).forEach(([a,i])=>{a!=="_node"&&s.outputs[a]&&(i.hidden=s.outputs[a].hidden)})},A=o=>{let t;if(o.value==null)return"None";switch(o.type){case"boolean":t=o.value?"True":"False";break;case"string":t=`'${o.value}'`;break;case void 0:t="None";break;default:t=`${o.value}`}return t},le=["title"],R=e.defineComponent({__name:"CodeNodeInterface",props:{intf:{}},setup(o){return(t,n)=>(e.openBlock(),e.createElementBlock("div",{title:o.intf.state?.script},e.toDisplayString(o.intf.name),9,le))}});class x extends r.NodeInterface{isCodeNode=!0;code;state;type=null;constructor(t,n){super(t,n),this.setComponent(e.markRaw(R)),this.state=e.reactive({optional:!1,script:""})}get optional(){return this.state.optional}get shortId(){return this.id.slice(0,6)}}const ce=(o,t)=>{o.state.optional=t,o.setHidden(!0)};class O extends x{constructor(t="",n){super(t,n),this.setComponent(e.markRaw(R)),this.use(r.displayInSidebar,!0)}get value(){return super.value}set value(t){super.value=t,this.name!=="_node"&&this.setHidden(!1)}}const D=new r.NodeInterfaceType("boolean"),H=new r.NodeInterfaceType("dict"),W=new r.NodeInterfaceType("list"),V=new r.NodeInterfaceType("node"),S=new r.NodeInterfaceType("number"),$=new r.NodeInterfaceType("string"),pe=o=>{new r.BaklavaInterfaceTypes(o.editor,{viewPlugin:o}).addTypes(D,H,W,V,S,$)};class ue extends O{constructor(t,n){super(t,n),this.setComponent(e.markRaw(r.CheckboxInterfaceComponent)),this.use(r.setType,D)}}class X extends x{isCodeNodeOutput=!0;constructor(t="",n=""){super(t,n),this.setComponent(e.markRaw(R))}get script(){return this.name.length>0?this.name:this.state.script}}class P extends O{min;max;constructor(t,n,s,a){super(t,n),this.min=s,this.max=a,this.use(r.setType,S)}validate(t){return(this.min===void 0||t>=this.min)&&(this.max===void 0||t<=this.max)}}class he extends P{component=e.markRaw(r.IntegerInterfaceComponent);validate(t){return Number.isInteger(t)&&super.validate(t)}}class me extends P{component=e.markRaw(r.NumberInterfaceComponent)}class G extends O{constructor(t,n){super(t,n),this.use(r.setType,$)}}class fe extends G{component=e.markRaw(r.SelectInterfaceComponent);items;constructor(t,n,s){super(t,n),this.items=s}}class ge extends P{component=e.markRaw(r.SliderInterfaceComponent);min;max;constructor(t,n,s,a){super(t,n,s,a),this.min=s,this.max=a}}class ye extends G{component=e.markRaw(r.TextInputInterfaceComponent)}class Ne extends G{component=e.markRaw(r.TextareaInputInterfaceComponent)}function _e(o){return class extends v{type=o.type;inputs={};outputs={};constructor(){super(),this._title=o.title??o.type,this.updateModules(o.modules),o.variableName&&(this.state.variableName=o.variableName),o.codeTemplate&&(this.codeTemplate=o.codeTemplate),this.addInput("_node",new x("",[]).use(r.setType,V).use(r.allowMultipleConnections).setHidden(!0)),this.addOutput("_node",new x("",[]).use(r.setType,V).use(r.allowMultipleConnections).setHidden(!0)),this.executeFactory("input",o.inputs),this.executeFactory("output",o.outputs),o.onCreate?.call(this)}onPlaced(){o.onPlaced?.call(this)}onDestroy(){o.onDestroy?.call(this)}onCodeUpdate(){o.onCodeUpdate?.call(this)}executeFactory(t,n){Object.keys(n||{}).forEach(s=>{const a=n[s]();t==="input"?this.addInput(s,a):this.addOutput(s,a)})}}}class q extends v{calculate}function be(o){return class extends q{type=o.type;inputs={};outputs={};calculate;preventUpdate=!1;staticInputKeys=Object.keys(o.inputs??{});staticOutputKeys=Object.keys(o.outputs??{});constructor(){super(),this._title=o.title??o.type,this.updateModules(o.modules),o.codeTemplate&&(this.codeTemplate=o.codeTemplate),o.variableName&&(this.state.variableName=o.variableName),this.addInput("_node",new x("",[]).use(r.setType,V).use(r.allowMultipleConnections).setHidden(!0)),this.addOutput("_node",new x("",[]).use(r.setType,V).use(r.allowMultipleConnections).setHidden(!0)),this.staticInputKeys.push("_node"),this.staticOutputKeys.push("_node"),this.executeFactory("input",o.inputs),this.executeFactory("output",o.outputs),o.onCreate?.call(this)}onPlaced(){this.events.update.subscribe(this,t=>{t&&(t.type==="input"&&this.staticInputKeys.includes(t.name)||t.type==="output"&&this.staticOutputKeys.includes(t.name))&&this.onUpdate()}),this.onUpdate(),o.onPlaced?.call(this)}onDestroy(){o.onDestroy?.call(this)}onCodeUpdate(){o.onCodeUpdate?.call(this)}load(t){this.preventUpdate=!0,this.hooks.beforeLoad.execute(t),this.id=t.id,this.title=t.title;for(const n of this.staticInputKeys)this.inputs[n].load(t.inputs[n]),this.inputs[n].nodeId=this.id,n!=="_node"&&(this.inputs[n].hidden=t.inputs[n].hidden);for(const n of this.staticOutputKeys)this.outputs[n].load(t.outputs[n]),this.outputs[n].nodeId=this.id,n!=="_node"&&(this.outputs[n].hidden=t.outputs[n].hidden);this.preventUpdate=!1,this.onUpdate(),this.preventUpdate=!0;for(const n of Object.keys(t.inputs))if(!this.staticInputKeys.includes(n)){if(!this.inputs[n]){const s=t.inputs[n].value;let a;typeof s=="number"?a=new r.IntegerInterface(n,s).use(r.setType,S):a=new r.TextInputInterface(n,JSON.stringify(s)).use(r.setType,$),a.use(r.displayInSidebar,!0),this.addInput(n,a)}this.inputs[n]&&(this.inputs[n].load(t.inputs[n]),this.inputs[n].nodeId=this.id)}for(const n of Object.keys(t.outputs))if(!this.staticOutputKeys.includes(n)){if(!this.outputs[n]){const s=new X(n);this.addOutput(n,s)}this.outputs[n]&&(this.outputs[n].load(t.outputs[n]),this.outputs[n].nodeId=this.id)}L(this.graph,t),this.preventUpdate=!1,this.events.loaded.emit(this)}onUpdate(){if(this.preventUpdate)return;this.graph&&this.graph.activeTransactions++;const t=this.getStaticValues(this.staticInputKeys,this.inputs),n=this.getStaticValues(this.staticOutputKeys,this.outputs),s=o.onUpdate.call(this,t,n);this.updateInterfaces("input",s.inputs??{},s.forceUpdateInputs??[]),this.updateInterfaces("output",s.outputs??{},s.forceUpdateOutputs??[]),this.graph&&this.graph.activeTransactions--}getStaticValues(t,n){const s={};for(const a of t)s[a]=n[a].value;return s}updateInterfaces(t,n,s){const a=t==="input"?this.staticInputKeys:this.staticOutputKeys,i=t==="input"?this.inputs:this.outputs;for(const c of Object.keys(i))a.includes(c)||n[c]&&!s.includes(c)||(t==="input"?this.removeInput(c):this.removeOutput(c));for(const c of Object.keys(n)){if(i[c])continue;const l=n[c]();t==="input"?this.addInput(c,l):this.addOutput(c,l)}}executeFactory(t,n){Object.keys(n||{}).forEach(s=>{const a=n[s]();t==="input"?this.addInput(s,a):this.addOutput(s,a)})}}}M.escape=o=>o;class Y{_id;_viewModel;_state;constructor(t){this._id=ie.v4(),this._viewModel=t,this._state=e.reactive({autosort:!1,modules:{},script:"",token:null,template:""})}get codeNodes(){return z(this.graph)}get connections(){return this.graph.connections}set connections(t){this.graph._connections=t}get graph(){return this.viewModel.displayedGraph}get id(){return this._id}get modules(){let t=[];return this.codeNodes.filter(n=>n.state.modules?.length>0).forEach(n=>{t=t.concat(n.state.modules)}),t?(t.sort(),Array.from(new Set(t.map(n=>this.viewModel.state.modules[n])))):[]}get nodeIds(){return this.codeNodes.map(t=>t.id)}get nodes(){return this.graph.nodes}set nodes(t){this.graph._nodes=t}get scriptedCodeNodes(){return z(this.graph).filter(t=>t.state?.script.length>0)}get shortId(){return this.id.slice(0,6)}get state(){return this._state}get viewModel(){return this._viewModel}get visibleNodes(){return this.codeNodes.filter(t=>!t.state?.hidden)}addNode(t,n){return t.code||(t.code=this),n&&(t.state.props=n),this.graph.addNode(t)}addNodeAtCoordinates=(t,n={x:0,y:0},s)=>(this.addNode(t,s),t.position&&(t.position=n),t);addConnection(t,n){t.name!=="_node"&&(t.hidden=!1),n.name!=="_node"&&(n.hidden=!1),this.graph.addConnection(t,n)}clear(){this.state.modules={},this.nodes=[],this.connections=[],this.state.script=""}findNodeById(t){return this.graph.findNodeById(t)}findNodeByType(t){return this.codeNodes.find(n=>n.type===t)}getNodesBySameType(t){return this.codeNodes.filter(n=>n.type===t)}getNodesBySameVariableNames(t){return this.codeNodes.filter(n=>n.state.variableName===t)}hasConnection(t,n){return this.connections.some(s=>s.from.id===t.id&&s.to.id===n.id)}loadTemplate(t){t.then(n=>{this._state.template=n.default??""})}onCodeUpdate(){this.codeNodes.forEach(t=>t.onCodeUpdate())}removeConnection(t){this.graph.removeConnection(t)}removeNode(t){this.graph.removeNode(t)}renderNodeCodes(){this.codeNodes.length!==0&&this.codeNodes.forEach(t=>t.renderCode())}renderCode(){this.state.script=M.render(this.state.template||"",this)}save(){this.state.autosort&&this.sortNodes();const t=this.viewModel.editor.save();return t.graph.id=this.id,this.saveNodeStates(t.graph.nodes),JSON.parse(JSON.stringify(t))}saveNodeStates(t){t.forEach((n,s)=>{const a=this.nodes[s];Object.entries(n.inputs).forEach(([i,c])=>{n.inputs&&a.inputs[i]&&(c.hidden=a.inputs[i].hidden)}),Object.entries(n.outputs).forEach(([i,c])=>{n.outputs&&a.outputs[i]&&(c.hidden=a.outputs[i].hidden)})})}sortNodes(){if(!(this.nodes.length===0||this.connections.length===0))try{const t=this.connections.map(i=>[i.to.nodeId,i.from.nodeId]);let n=[...this.nodeIds];n.reverse(),n=ae.array(n,t),n.reverse();const s=this.graph.nodes.map(i=>i.id).filter(i=>!n.includes(i));n=n.concat(s);const a=n.map(i=>this.findNodeById(i));a&&(this.nodes=a)}catch{console.warn("Failed to sort nodes.")}}updateOutputVariableNames(){this.codeNodes.forEach(t=>t.updateOutputVariableName())}}const z=o=>{let t=[];return o.nodes.forEach(n=>{n.subgraph?t=t.concat(z(n.subgraph)):n.isCodeNode&&t.push(n)}),t},Ce=(o=0,t=100)=>({x:o*420,y:t}),ke=o=>{const t={...o.position};return t.x-=400,t.y+=50,t},we=o=>{const{calculationOrder:t,connectionsFromNode:n}=r.sortTopologically(o);t.forEach(s=>{if(!s.isCodeNode)return;const a=s;n.has(a)&&n.get(a).forEach(i=>{i.to.state&&i.from.script&&(i.to.state.script=i.from.script)})})},Ie=["id"],Ee={class:"align-middle"},J=e.defineComponent({__name:"CodeGraphNodeInterface",props:{node:{},intf:{}},setup(o){const t=o,{viewModel:n}=r.useViewModel(),{hoveredOver:s,temporaryConnection:a}=r.useTemporaryConnection(),i=e.ref(null),c=e.computed(()=>t.intf.connectionCount>0),l=e.computed(()=>({"--connected":c.value})),m=()=>{s(t.intf)},N=()=>{s(void 0)},_=()=>{i.value&&n.value.hooks.renderInterface.execute({intf:t.intf,el:i.value})};return e.onMounted(_),e.onUpdated(_),(I,B)=>(e.openBlock(),e.createElementBlock("div",{id:o.intf.id,ref_key:"el",ref:i,class:e.normalizeClass(["baklava-node-interface",l.value])},[o.intf.port?(e.openBlock(),e.createElementBlock("div",{key:0,class:e.normalizeClass(["__port",{"--selected":e.unref(a)?.from===o.intf}]),onPointerover:m,onPointerout:N},null,34)):e.createCommentVNode("",!0),e.createElementVNode("span",Ee,[e.renderSlot(I.$slots,"default")])],10,Ie))}}),E=(o,t)=>{const n=o.__vccOpts||o;for(const[s,a]of t)n[s]=a;return n},Be={},xe={xmlns:"http://www.w3.org/2000/svg",width:"24",height:"24",viewBox:"0 0 24 24",fill:"currentColor",class:"baklava-icon icon icon-tabler icons-tabler-filled icon-tabler-layout-sidebar-left-collapse"};function Ve(o,t){return e.openBlock(),e.createElementBlock("svg",xe,[...t[0]||(t[0]=[e.createElementVNode("path",{stroke:"none",d:"M0 0h24v24H0z",fill:"none"},null,-1),e.createElementVNode("path",{d:"M18 3a3 3 0 0 1 2.995 2.824l.005 .176v12a3 3 0 0 1 -2.824 2.995l-.176 .005h-12a3 3 0 0 1 -2.995 -2.824l-.005 -.176v-12a3 3 0 0 1 2.824 -2.995l.176 -.005h12zm0 2h-9v14h9a1 1 0 0 0 .993 -.883l.007 -.117v-12a1 1 0 0 0 -.883 -.993l-.117 -.007zm-2.293 4.293a1 1 0 0 1 .083 1.32l-.083 .094l-1.292 1.293l1.292 1.293a1 1 0 0 1 .083 1.32l-.083 .094a1 1 0 0 1 -1.32 .083l-.094 -.083l-2 -2a1 1 0 0 1 -.083 -1.32l.083 -.094l2 -2a1 1 0 0 1 1.414 0z"},null,-1)])])}const Te=E(Be,[["render",Ve]]),Me={},Oe={xmlns:"http://www.w3.org/2000/svg",width:"24",height:"24",viewBox:"0 0 24 24",fill:"currentColor",class:"baklava-icon icon icon-tabler icons-tabler-filled icon-tabler-layout-sidebar-left-expand"};function Se(o,t){return e.openBlock(),e.createElementBlock("svg",Oe,[...t[0]||(t[0]=[e.createElementVNode("path",{stroke:"none",d:"M0 0h24v24H0z",fill:"none"},null,-1),e.createElementVNode("path",{d:"M18 3a3 3 0 0 1 2.995 2.824l.005 .176v12a3 3 0 0 1 -2.824 2.995l-.176 .005h-12a3 3 0 0 1 -2.995 -2.824l-.005 -.176v-12a3 3 0 0 1 2.824 -2.995l.176 -.005h12zm0 2h-9v14h9a1 1 0 0 0 .993 -.883l.007 -.117v-12a1 1 0 0 0 -.883 -.993l-.117 -.007zm-4.387 4.21l.094 .083l2 2a1 1 0 0 1 .083 1.32l-.083 .094l-2 2a1 1 0 0 1 -1.497 -1.32l.083 -.094l1.292 -1.293l-1.292 -1.293a1 1 0 0 1 -.083 -1.32l.083 -.094a1 1 0 0 1 1.32 -.083z"},null,-1)])])}const $e=E(Me,[["render",Se]]),ze={},ve={xmlns:"http://www.w3.org/2000/svg",width:"24",height:"24",viewBox:"0 0 24 24",fill:"currentColor",class:"balkava-icon icon icon-tabler icons-tabler-filled icon-tabler-layout-sidebar-right"};function Le(o,t){return e.openBlock(),e.createElementBlock("svg",ve,[...t[0]||(t[0]=[e.createElementVNode("path",{stroke:"none",d:"M0 0h24v24H0z",fill:"none"},null,-1),e.createElementVNode("path",{d:"M6 21a3 3 0 0 1 -3 -3v-12a3 3 0 0 1 3 -3h12a3 3 0 0 1 3 3v12a3 3 0 0 1 -3 3zm8 -16h-8a1 1 0 0 0 -1 1v12a1 1 0 0 0 1 1h8z"},null,-1)])])}const Re=E(ze,[["render",Le]]),De={},Pe={xmlns:"http://www.w3.org/2000/svg",width:"24",height:"24",viewBox:"0 0 24 24",fill:"currentColor",class:"baklava-icon icon icon-tabler icons-tabler-filled icon-tabler-layout-sidebar-right-collapse"};function Ge(o,t){return e.openBlock(),e.createElementBlock("svg",Pe,[...t[0]||(t[0]=[e.createElementVNode("path",{stroke:"none",d:"M0 0h24v24H0z",fill:"none"},null,-1),e.createElementVNode("path",{d:"M18 3a3 3 0 0 1 2.995 2.824l.005 .176v12a3 3 0 0 1 -2.824 2.995l-.176 .005h-12a3 3 0 0 1 -2.995 -2.824l-.005 -.176v-12a3 3 0 0 1 2.824 -2.995l.176 -.005h12zm-3 2h-9a1 1 0 0 0 -.993 .883l-.007 .117v12a1 1 0 0 0 .883 .993l.117 .007h9v-14zm-5.387 4.21l.094 .083l2 2a1 1 0 0 1 .083 1.32l-.083 .094l-2 2a1 1 0 0 1 -1.497 -1.32l.083 -.094l1.292 -1.293l-1.292 -1.293a1 1 0 0 1 -.083 -1.32l.083 -.094a1 1 0 0 1 1.32 -.083z"},null,-1)])])}const Ue=E(De,[["render",Ge]]),Fe={},Ae={xmlns:"http://www.w3.org/2000/svg",width:"24",height:"24",viewBox:"0 0 24 24",fill:"currentColor",class:"baklava-icon icon icon-tabler icons-tabler-filled icon-tabler-layout-sidebar-right-expand"};function He(o,t){return e.openBlock(),e.createElementBlock("svg",Ae,[...t[0]||(t[0]=[e.createElementVNode("path",{stroke:"none",d:"M0 0h24v24H0z",fill:"none"},null,-1),e.createElementVNode("path",{d:"M18 3a3 3 0 0 1 2.995 2.824l.005 .176v12a3 3 0 0 1 -2.824 2.995l-.176 .005h-12a3 3 0 0 1 -2.995 -2.824l-.005 -.176v-12a3 3 0 0 1 2.824 -2.995l.176 -.005h12zm-3 2h-9a1 1 0 0 0 -.993 .883l-.007 .117v12a1 1 0 0 0 .883 .993l.117 .007h9v-14zm-3.293 4.293a1 1 0 0 1 .083 1.32l-.083 .094l-1.292 1.293l1.292 1.293a1 1 0 0 1 .083 1.32l-.083 .094a1 1 0 0 1 -1.32 .083l-.094 -.083l-2 -2a1 1 0 0 1 -.083 -1.32l.083 -.094l2 -2a1 1 0 0 1 1.414 0z"},null,-1)])])}const We=E(Fe,[["render",He]]),Xe={},qe={xmlns:"http://www.w3.org/2000/svg",class:"baklava-icon",width:"24",height:"24",viewBox:"0 0 24 24",fill:"none",stroke:"currentColor","stroke-width":"2","stroke-linecap":"round","stroke-linejoin":"round"};function Ye(o,t){return e.openBlock(),e.createElementBlock("svg",qe,[...t[0]||(t[0]=[e.createStaticVNode('<path stroke="none" d="M0 0h24v24H0z" fill="none"></path><path d="M5 2h5v4h-5z"></path><path d="M15 10h5v4h-5z"></path><path d="M5 18h5v4h-5z"></path><path d="M5 10h5v4h-5z"></path><path d="M10 12h5"></path><path d="M7.5 6v4"></path><path d="M7.5 14v4"></path>',8)])])}const Je=E(Xe,[["render",Ye]]),Ke={},Qe={xmlns:"http://www.w3.org/2000/svg",class:"baklava-icon",width:"24",height:"24",viewBox:"0 0 24 24",fill:"none",stroke:"currentColor","stroke-width":"2","stroke-linecap":"round","stroke-linejoin":"round"};function Ze(o,t){return e.openBlock(),e.createElementBlock("svg",Qe,[...t[0]||(t[0]=[e.createStaticVNode('<path stroke="none" d="M0 0h24v24H0z" fill="none"></path><path d="M6 2h4v4m-4 0h-1v-1"></path><path d="M15 11v-1h5v4h-2"></path><path d="M5 18h5v4h-5z"></path><path d="M5 10h5v4h-5z"></path><path d="M10 12h2"></path><path d="M7.5 7.5v2.5"></path><path d="M7.5 14v4"></path><path d="M3 3l18 18"></path>',9)])])}const je=E(Ke,[["render",Ze]]),et={},tt={xmlns:"http://www.w3.org/2000/svg",class:"baklava-icon",width:"24",height:"24",viewBox:"0 0 24 24",fill:"none",stroke:"currentColor","stroke-width":"2","stroke-linecap":"round","stroke-linejoin":"round"};function nt(o,t){return e.openBlock(),e.createElementBlock("svg",tt,[...t[0]||(t[0]=[e.createStaticVNode('<path stroke="none" d="M0 0h24v24H0z" fill="none"></path><path d="M3 3l18 18"></path><path d="M4 7h3m4 0h9"></path><path d="M10 11l0 6"></path><path d="M14 14l0 3"></path><path d="M5 7l1 12a2 2 0 0 0 2 2h8a2 2 0 0 0 2 -2l.077 -.923"></path><path d="M18.384 14.373l.616 -7.373"></path><path d="M9 5v-1a1 1 0 0 1 1 -1h4a1 1 0 0 1 1 1v3"></path>',8)])])}const ot=E(et,[["render",nt]]),st={},at={xmlns:"http://www.w3.org/2000/svg",class:"baklava-icon",width:"16",height:"16",viewBox:"0 0 24 24","stroke-width":"2",stroke:"currentColor",fill:"none","stroke-linecap":"round","stroke-linejoin":"round"};function it(o,t){return e.openBlock(),e.createElementBlock("svg",at,[...t[0]||(t[0]=[e.createElementVNode("path",{stroke:"none",d:"M0 0h24v24H0z",fill:"none"},null,-1),e.createElementVNode("circle",{cx:"12",cy:"12",r:"1"},null,-1),e.createElementVNode("circle",{cx:"12",cy:"19",r:"1"},null,-1),e.createElementVNode("circle",{cx:"12",cy:"5",r:"1"},null,-1)])])}const rt=E(st,[["render",it]]),dt=["id","data-node-type"],lt={class:"__title-label",style:{"flex-grow":"1"}},ct={key:0},pt={class:"__menu",style:{display:"flex"}},ut={class:"__outputs"},ht={key:0},mt=["id","title"],ft={class:"__inputs"},gt={key:0},yt=["id","title"],Nt=e.defineComponent({__name:"CodeGraphNode",props:{node:{},selected:{type:Boolean,default:!1},dragging:{type:Boolean}},emits:["select","start-drag","update"],setup(o,{emit:t}){const n=r.Components.ContextMenu,s=r.Components.NodeInterface,a=o,i=e.computed(()=>a.node),c=t,{viewModel:l}=r.useViewModel(),{graph:m,switchGraph:N}=r.useGraph(),_=e.ref(null),I=e.ref(!1),B=e.ref(""),b=e.ref(null),f=e.ref(!1);let g=0,h=0;const u=e.ref(!1),C=e.computed(()=>{const p=[{value:"edit",label:"Edit"},{value:"rename",label:"Rename"},{value:"delete",label:"Delete"}];return a.node.type.startsWith(r.GRAPH_NODE_TYPE_PREFIX)&&p.push({value:"editSubgraph",label:"Edit Subgraph"}),p}),w=e.computed(()=>({"--selected":a.selected,"--dragging":a.dragging,"--two-column":!!a.node.twoColumn,"--hidden":i.value.state?.hidden})),Pt=e.computed(()=>({"--reverse-y":a.node.reverseY??l.value.settings.nodes.reverseY})),Gt=e.computed(()=>({top:`${a.node.position?.y??0}px`,left:`${a.node.position?.x??0}px`,"--width":`${a.node.width??l.value.settings.nodes.defaultWidth}px`})),Ut=e.computed(()=>Object.values(a.node.inputs).filter(p=>!p.hidden)),Ft=e.computed(()=>Object.values(a.node.outputs).filter(p=>!p.hidden)),Z=()=>{c("select")},At=p=>{a.selected||Z(),c("start-drag",p)},j=()=>{u.value=!0},Ht=()=>{const p=l.value.displayedGraph.sidebar;p.nodeId="",p.visible=!1},ee=()=>{const p=l.value.displayedGraph.sidebar;p.nodeId=a.node.id,p.visible=!0},Wt=()=>{const p=l.value.displayedGraph.sidebar;p.nodeId=a.node.id},Xt=async p=>{switch(p){case"edit":ee();break;case"delete":m.value.removeNode(a.node);break;case"rename":B.value=a.node.title,I.value=!0,await e.nextTick(),b.value?.focus();break;case"editSubgraph":N(a.node.template);break}},te=()=>{a.node.title=B.value,I.value=!1},ne=()=>{_.value&&l.value.hooks.renderNode.execute({node:a.node,el:_.value})},qt=p=>{f.value=!0,g=a.node.width,h=p.clientX,p.preventDefault()},oe=p=>{if(!f.value)return;const k=p.clientX-h,y=g+k/m.value.scaling,Yt=l.value.settings.nodes.minWidth,Jt=l.value.settings.nodes.maxWidth;a.node.width=Math.max(Yt,Math.min(Jt,y))},se=()=>{f.value=!1};return e.onMounted(()=>{ne(),window.addEventListener("mousemove",oe),window.addEventListener("mouseup",se)}),e.onUpdated(ne),e.onBeforeUnmount(()=>{window.removeEventListener("mousemove",oe),window.removeEventListener("mouseup",se)}),(p,k)=>(e.openBlock(),e.createElementBlock("div",{id:i.value.id,ref_key:"el",ref:_,class:e.normalizeClass([w.value,"baklava-node"]),"data-node-type":i.value.type,style:e.normalizeStyle(Gt.value),onPointerdown:Z},[e.unref(l).settings.nodes.resizable?(e.openBlock(),e.createElementBlock("div",{key:0,class:"__resize-handle",onMousedown:qt},null,32)):e.createCommentVNode("",!0),e.createElementVNode("div",{class:"__title",onPointerdown:e.withModifiers(At,["self","stop"]),onContextmenu:e.withModifiers(j,["prevent"])},[i.value.inputs._node?(e.openBlock(),e.createBlock(J,{key:0,node:i.value,intf:i.value.inputs._node,class:"--input","data-interface-type":"node",style:{"flex-grow":"0"}},null,8,["node","intf"])):e.createCommentVNode("",!0),I.value?e.withDirectives((e.openBlock(),e.createElementBlock("input",{key:2,ref_key:"renameInputEl",ref:b,"onUpdate:modelValue":k[1]||(k[1]=y=>B.value=y),class:"baklava-input",placeholder:"Node Name",style:{"flex-grow":"1"},type:"text",onBlur:te,onKeydown:e.withKeys(te,["enter"])},null,544)),[[e.vModelText,B.value]]):(e.openBlock(),e.createElementBlock(e.Fragment,{key:1},[e.createElementVNode("div",lt,[i.value.idx>-1?(e.openBlock(),e.createElementBlock("span",ct,e.toDisplayString(i.value.idx+1)+" - ",1)):e.createCommentVNode("",!0),e.createTextVNode(e.toDisplayString(i.value.title)+" ("+e.toDisplayString(i.value.shortId)+") ",1)]),e.createElementVNode("div",pt,[i.value.subgraph?e.createCommentVNode("",!0):(e.openBlock(),e.createElementBlock(e.Fragment,{key:0},[!e.unref(l).displayedGraph.sidebar.visible&&e.unref(l).displayedGraph.sidebar.nodeId!==i.value.id?(e.openBlock(),e.createBlock(e.unref(We),{key:0,class:"--clickable mx-1",onClick:ee})):e.unref(l).displayedGraph.sidebar.visible&&e.unref(l).displayedGraph.sidebar.nodeId!==i.value.id?(e.openBlock(),e.createBlock(e.unref(Re),{key:1,class:"--clickable mx-1",onClick:Wt})):(e.openBlock(),e.createBlock(e.unref(Ue),{key:2,class:"--clickable mx-1",onClick:Ht}))],64)),e.createVNode(e.unref(rt),{class:"--clickable mx-1",onClick:j}),e.createVNode(e.unref(n),{modelValue:u.value,"onUpdate:modelValue":k[0]||(k[0]=y=>u.value=y),x:0,y:0,items:C.value,onClick:Xt},null,8,["modelValue","items"])])],64)),i.value.outputs._node?(e.openBlock(),e.createBlock(J,{key:3,node:i.value,intf:i.value.outputs._node,class:"--output","data-interface-type":"node"},null,8,["node","intf"])):e.createCommentVNode("",!0)],32),e.createElementVNode("div",{class:e.normalizeClass(["__content",Pt.value]),onKeydown:k[2]||(k[2]=e.withKeys(e.withModifiers(()=>{},["stop"]),["delete"])),onContextmenu:k[3]||(k[3]=e.withModifiers(()=>{},["prevent"]))},[e.createElementVNode("div",ut,[(e.openBlock(!0),e.createElementBlock(e.Fragment,null,e.renderList(Ft.value,y=>(e.openBlock(),e.createElementBlock(e.Fragment,{key:y.id},[i.value.state?.hidden?(e.openBlock(),e.createElementBlock("div",ht,[y.port?(e.openBlock(),e.createElementBlock("div",{key:0,id:y.id,title:y.name,class:"baklava-node-interface --output --connected"},[...k[4]||(k[4]=[e.createElementVNode("div",{class:"__port"},null,-1)])],8,mt)):e.createCommentVNode("",!0)])):e.renderSlot(p.$slots,"nodeInterface",{key:1,type:"output",node:i.value,intf:y},()=>[e.createVNode(e.unref(s),{node:i.value,intf:y},null,8,["node","intf"])])],64))),128))]),e.createElementVNode("div",ft,[(e.openBlock(!0),e.createElementBlock(e.Fragment,null,e.renderList(Ut.value,y=>(e.openBlock(),e.createElementBlock(e.Fragment,{key:y.id},[i.value.state?.hidden?(e.openBlock(),e.createElementBlock("div",gt,[y.port?(e.openBlock(),e.createElementBlock("div",{key:0,id:y.id,title:y.name,class:"baklava-node-interface --input --connected"},[...k[5]||(k[5]=[e.createElementVNode("div",{class:"__port"},null,-1)])],8,yt)):e.createCommentVNode("",!0)])):e.renderSlot(p.$slots,"nodeInterface",{key:1,node:i.value,intf:y,type:"input"},()=>[e.createVNode(e.unref(s),{node:i.value,intf:y,title:y.name},null,8,["node","intf","title"])])],64))),128))])],34)],46,dt))}}),_t=["title"],bt={key:0,class:"__label"},Ct=e.defineComponent({__name:"Checkbox",props:{disabled:{type:Boolean},inversed:{type:Boolean},modelValue:{type:Boolean},name:{}},emits:["update:modelValue"],setup(o,{emit:t}){const n=t;return(s,a)=>(e.openBlock(),e.createElementBlock("div",{class:e.normalizeClass(["baklava-checkbox",{"--checked":o.inversed?!o.modelValue:o.modelValue,"--disabled":o.disabled}]),title:o.name,onClick:a[0]||(a[0]=i=>n("update:modelValue",!o.modelValue))},[a[1]||(a[1]=e.createElementVNode("div",{class:"__checkmark-container"},[e.createElementVNode("svg",{xmlns:"http://www.w3.org/2000/svg",width:"18",height:"18",viewBox:"0 0 18 18"},[e.createElementVNode("path",{class:"__checkmark",d:"M 6 5 L 6 10 L 16 10",transform:"rotate(-45 10 10)"})])],-1)),o.name?(e.openBlock(),e.createElementBlock("div",bt,e.toDisplayString(o.name),1)):e.createCommentVNode("",!0)],10,_t))}}),kt={class:"__header"},wt={class:"__node-name"},It={style:{display:"flex"}},Et={key:1,class:"__interface"},Bt=e.defineComponent({__name:"CodeGraphSidebar",setup(o){const{viewModel:t}=r.useViewModel(),{graph:n}=r.useGraph(),s=e.ref(null),a=e.toRef(t.value.settings.sidebar,"width"),i=e.computed(()=>t.value.settings.sidebar.resizable);let c=0,l=0;const m=e.computed(()=>{const h=n.value.sidebar.nodeId;return n.value.nodes.find(u=>u.id===h)}),N=e.computed(()=>m.value),_=e.computed(()=>({width:`${a.value}px`})),I=e.computed(()=>N.value?[...Object.values(N.value.inputs),...Object.values(N.value.outputs)].filter(u=>u.displayInSidebar&&u.component):[]),B=()=>{n.value.sidebar.visible=!1},b=()=>{m.value?.events.update.emit(null)},f=h=>{c=a.value,l=h.clientX,window.addEventListener("mousemove",g),window.addEventListener("mouseup",()=>{window.removeEventListener("mousemove",g)},{once:!0})},g=h=>{const u=s.value?.parentElement?.getBoundingClientRect().width??500,C=h.clientX-l;let w=c-C;w<300?w=300:w>.9*u&&(w=.9*u),a.value=w};return(h,u)=>(e.openBlock(),e.createElementBlock("div",{ref_key:"el",ref:s,class:e.normalizeClass(["baklava-sidebar",{"--open":e.unref(n).sidebar.visible}]),style:e.normalizeStyle(_.value)},[i.value?(e.openBlock(),e.createElementBlock("div",{key:0,class:"__resizer",onMousedown:f},null,32)):e.createCommentVNode("",!0),e.createElementVNode("div",kt,[e.createElementVNode("button",{tabindex:"-1",class:"__close",onClick:B},"×"),e.createElementVNode("div",wt,[e.createElementVNode("b",null,e.toDisplayString(m.value?m.value.title:""),1)])]),(e.openBlock(!0),e.createElementBlock(e.Fragment,null,e.renderList(I.value,C=>(e.openBlock(),e.createElementBlock("div",{key:C.id,class:"__interface"},[e.createElementVNode("div",It,[e.createVNode(Ct,{modelValue:C.hidden,"onUpdate:modelValue":[w=>C.hidden=w,u[0]||(u[0]=()=>m.value?.events.update.emit(null))],disabled:!C.optional,inversed:"",style:{"padding-right":"8px"}},null,8,["modelValue","onUpdate:modelValue","disabled"]),(e.openBlock(),e.createBlock(e.resolveDynamicComponent(C.component),{modelValue:C.value,"onUpdate:modelValue":w=>C.value=w,node:m.value,intf:C,style:{width:"100%"}},null,8,["modelValue","onUpdate:modelValue","node","intf"]))])]))),128)),N.value&&N.value.state?(e.openBlock(),e.createElementBlock("div",Et,[u[2]||(u[2]=e.createElementVNode("label",null,"Variable name",-1)),e.withDirectives(e.createElementVNode("input",{"onUpdate:modelValue":u[1]||(u[1]=C=>N.value.state.variableName=C),type:"text",class:"baklava-input",title:"Variable name",onBlur:b,onKeydown:e.withKeys(b,["enter"])},null,544),[[e.vModelText,N.value.state.variableName]])])):e.createCommentVNode("",!0)],6))}}),xt=e.defineComponent({props:{type:{type:String,required:!0},title:{type:String,required:!0}},setup(o){const{viewModel:t}=r.useViewModel(),{switchGraph:n}=r.useGraph(),s=e.ref(!1),a=e.computed(()=>o.type.startsWith(r.GRAPH_NODE_TYPE_PREFIX));return{showContextMenu:s,hasContextMenu:a,contextMenuItems:[{label:"Edit Subgraph",value:"editSubgraph"},{label:"Delete Subgraph",value:"deleteSubgraph"}],openContextMenu:()=>{s.value=!0},onContextMenuClick:m=>{const N=o.type.substring(r.GRAPH_NODE_TYPE_PREFIX.length),_=t.value.editor.graphTemplates.find(I=>I.id===N);if(_)switch(m){case"editSubgraph":n(_);break;case"deleteSubgraph":t.value.editor.removeGraphTemplate(_);break}}}}}),Vt=["data-node-type"],Tt={class:"__title"},Mt={class:"__title-label"};function Ot(o,t,n,s,a,i){return e.openBlock(),e.createElementBlock("div",{class:"baklava-node --palette","data-node-type":o.type},[e.createElementVNode("div",Tt,[e.createElementVNode("div",Mt,e.toDisplayString(o.title),1)])],8,Vt)}const K=E(xt,[["render",Ot]]),St={class:"baklava-node --palette",style:{"margin-top":"-20px","margin-bottom":"20px"}},$t={key:0,style:{display:"flex","justify-content":"space-between"}},zt=["onClick"],vt={key:0,style:{margin:"auto 0","font-size":"12px"}},Lt=e.defineComponent({__name:"CodeNodePalette",setup(o){const{viewModel:t}=r.useViewModel(),{x:n,y:s}=re.usePointer(),{transform:a}=r.useTransform(),i=r.useNodeCategories(t),c=e.inject("editorEl"),l=e.ref(""),m=e.ref(null),N=()=>l.value?i.value.filter(b=>b.name.toLowerCase().includes(l.value.toLowerCase())||Object.values(b.nodeTypes).some(f=>f.title.toLowerCase().includes(l.value.toLowerCase()))):i.value,_=b=>l.value?Object.values(b).filter(f=>f.category.toLowerCase().includes(l.value.toLowerCase())||f.title.toLowerCase().includes(l.value.toLowerCase())):Object.values(b),I=e.computed(()=>{if(!m.value||!c?.value)return{};const{left:b,top:f}=c.value.getBoundingClientRect();return{top:`${s.value-f}px`,left:`${n.value-b}px`}}),B=(b,f)=>{m.value={type:b,nodeInformation:f};const g=()=>{const h=e.reactive(new f.type);t.value.displayedGraph.addNode(h);const u=c.value.getBoundingClientRect(),[C,w]=a(n.value-u.left,s.value-u.top);h.position.x=C,h.position.y=w,m.value=null,document.removeEventListener("pointerup",g)};document.addEventListener("pointerup",g)};return(b,f)=>(e.openBlock(),e.createElementBlock(e.Fragment,null,[e.createElementVNode("div",{class:e.normalizeClass(["baklava-node-palette",{"--open":e.unref(t).settings.palette.enabled}]),onContextmenu:f[1]||(f[1]=e.withModifiers(()=>{},["stop","prevent"]))},[e.createElementVNode("div",St,[e.withDirectives(e.createElementVNode("input",{"onUpdate:modelValue":f[0]||(f[0]=g=>l.value=g),type:"text",class:"baklava-input",title:"Filter nodes",onKeyup:N},null,544),[[e.vModelText,l.value]])]),(e.openBlock(!0),e.createElementBlock(e.Fragment,null,e.renderList(N(),g=>(e.openBlock(),e.createElementBlock("section",{key:g.name},[g.name!=="default"?(e.openBlock(),e.createElementBlock("h3",$t,[e.createElementVNode("div",{onClick:h=>l.value=g.name,style:{cursor:"pointer"}},e.toDisplayString(g.name),9,zt),_(g.nodeTypes).length<Object.values(g.nodeTypes).length?(e.openBlock(),e.createElementBlock("div",vt," ( "+e.toDisplayString(_(g.nodeTypes).length)+" / "+e.toDisplayString(Object.values(g.nodeTypes).length)+" ) ",1)):e.createCommentVNode("",!0)])):e.createCommentVNode("",!0),(e.openBlock(!0),e.createElementBlock(e.Fragment,null,e.renderList(_(g.nodeTypes),h=>(e.openBlock(),e.createBlock(K,{key:h.type,type:h.type,title:h.title,onPointerdown:u=>B(h.type,h)},null,8,["type","title","onPointerdown"]))),128))]))),128))],34),e.createVNode(e.Transition,{name:"fade"},{default:e.withCtx(()=>[m.value?(e.openBlock(),e.createElementBlock("div",{key:0,class:"baklava-dragged-node",style:e.normalizeStyle(I.value)},[e.createVNode(K,{type:m.value.type,title:m.value.nodeInformation.title},null,8,["type","title"])],4)):e.createCommentVNode("",!0)]),_:1})],64))}}),Rt=e.defineComponent({__name:"CodeGraphEditor",props:{viewModel:{}},setup(o){const t=o,n=e.toRef(t,"viewModel"),s=a=>a.events.update.emit(null);return e.onMounted(()=>{n.value.subscribe(),n.value.engine.start()}),e.onUnmounted(()=>{n.value.unsubscribe(),n.value.engine.stop()}),(a,i)=>(e.openBlock(),e.createBlock(e.unref(r.BaklavaEditor),{"view-model":n.value},{palette:e.withCtx(()=>[e.createVNode(Lt)]),node:e.withCtx(c=>[e.createVNode(Nt,e.mergeProps(c,{onUpdate:l=>s(c.node)}),null,16,["onUpdate"])]),sidebar:e.withCtx(c=>[e.createVNode(Bt,e.normalizeProps(e.guardReactiveProps(c)),null,16)]),_:1},8,["view-model"]))}}),Q=o=>{const t="TOGGLE_PALETTE";o.commandHandler.registerCommand(t,{execute:()=>o.settings.palette.enabled=!o.settings.palette.enabled,canExecute:()=>!0});const n="CLEAR_ALL";o.commandHandler.registerCommand(n,{execute:()=>o.code.clear(),canExecute:()=>o.displayedGraph.nodes.length>0});const s="TOGGLE_MINIMAP";o.commandHandler.registerCommand(s,{execute:()=>o.settings.enableMinimap=!o.settings.enableMinimap,canExecute:()=>o.displayedGraph.nodes.length>1}),o.settings.toolbar.commands=[{command:t,title:"Toggle palette",icon:e.computed(()=>o.settings.palette.enabled?Te:$e)},...r.DEFAULT_TOOLBAR_COMMANDS,{command:n,title:"Clear all",icon:ot},{command:s,title:"Toggle minimap",icon:e.computed(()=>o.settings.enableMinimap?je:Je)}]},T={enableMinimap:!1,toolbar:{enabled:!0},palette:{enabled:!0},sidebar:{enabled:!0,resizable:!0,width:350},displayValueOnHover:!1};function Dt(o){const t=r.useBaklava(o?.existingEditor);t.code=o?.code?new o.code(t):new Y(t),Q(t);const n={};return Object.keys(T).forEach(s=>{n[s]=typeof T[s]=="object"?{...t.settings[s],...T[s]}:T[s]}),t.settings=e.reactive({...t.settings,...n}),t.settings.nodes.defaultWidth=350,t.state=e.reactive({modules:{},token:null}),t.engine=new r.DependencyEngine(t.editor),t.subscribe=()=>{t.state.token&&t.unsubscribe();const s=Symbol();t.displayedGraph.events.addNode.subscribe(s,a=>a.code=t.code),t.engine.events.beforeRun.subscribe(s,()=>{t.engine.pause(),t.code&&(t.code.onCodeUpdate(),t.code.sortNodes()),t.engine.resume()}),t.engine.events.beforeNodeCalculation.subscribe(s,a=>{t.engine.pause();const i=a.node;i.isCodeNode&&(i.updateOutputVariableName(),i.updateCodeNodeInputInterfaces()),t.engine.resume()}),t.engine.events.afterRun.subscribe(s,a=>{t.engine.pause(),r.applyResult(a,t.editor),t.code&&(t.code.renderNodeCodes(),t.code.renderCode()),t.engine.resume()}),t.state.token=s},t.unsubscribe=()=>{if(!t.state.token)return;const s=t.state.token;t.displayedGraph.events.addNode.unsubscribe(s),t.engine.events.beforeRun.unsubscribe(s),t.engine.events.afterRun.unsubscribe(s),t.state.token=null},t}Object.defineProperty(d,"CheckboxInterfaceComponent",{enumerable:!0,get:()=>r.CheckboxInterfaceComponent}),Object.defineProperty(d,"IntegerInterfaceComponent",{enumerable:!0,get:()=>r.IntegerInterfaceComponent}),Object.defineProperty(d,"NumberInterfaceComponent",{enumerable:!0,get:()=>r.NumberInterfaceComponent}),Object.defineProperty(d,"SelectInterfaceComponent",{enumerable:!0,get:()=>r.SelectInterfaceComponent}),Object.defineProperty(d,"SliderInterfaceComponent",{enumerable:!0,get:()=>r.SliderInterfaceComponent}),Object.defineProperty(d,"TextInputInterfaceComponent",{enumerable:!0,get:()=>r.TextInputInterfaceComponent}),Object.defineProperty(d,"TextareaInputInterfaceComponent",{enumerable:!0,get:()=>r.TextareaInputInterfaceComponent}),d.AbstractCodeNode=U,d.CheckboxInterface=ue,d.Code=Y,d.CodeGraphEditor=Rt,d.CodeNode=v,d.CodeNodeInputInterface=O,d.CodeNodeInterface=x,d.CodeNodeOutputInterface=X,d.DEFAULT_SETTINGS=T,d.DynamicCodeNode=q,d.IntegerInterface=he,d.NumberInterface=me,d.SelectInterface=fe,d.SliderInterface=ge,d.TextInputInterface=ye,d.TextareaInputInterface=Ne,d.addDefaultInterfaceTypes=pe,d.addToolbarCommands=Q,d.booleanType=D,d.defineCodeNode=_e,d.defineDynamicCodeNode=be,d.dictType=H,d.formatInputs=de,d.getCodeNodes=z,d.getPositionAtColumn=Ce,d.getPositionBeforeNode=ke,d.listType=W,d.loadNodeState=L,d.nodeType=V,d.numberType=S,d.saveNodeState=F,d.setOptional=ce,d.stringType=$,d.transferCodeScript=we,d.useCodeGraph=Dt,Object.defineProperty(d,Symbol.toStringTag,{value:"Module"})}));
|
|
1
|
+
(function(l,r){typeof exports=="object"&&typeof module<"u"?r(exports,require("baklavajs"),require("mustache"),require("vue"),require("toposort"),require("uuid"),require("@vueuse/core")):typeof define=="function"&&define.amd?define(["exports","baklavajs","mustache","vue","toposort","uuid","@vueuse/core"],r):(l=typeof globalThis<"u"?globalThis:l||self,r(l["@babsey/code-graph"]={},l.baklavajs,l.mustache,l.Vue,l.toposort,l.uuid,l["@vueuse/core"]))})(this,(function(l,r,O,e,re,le,de){"use strict";O.escape=o=>o;class A extends r.AbstractNode{state;code;isCodeNode=!0;name="";codeTemplate;inputs={};outputs={};constructor(){super(),this.initializeIo(),this.width=400,this.twoColumn=!0,this.state=e.reactive({codeTemplate:"",hidden:!1,integrated:!1,modules:[],script:"",variableName:""}),this.codeTemplate=function(){return`${this.name}(${H(this.codeNodeInputs).join(", ")})`}}get codeNodeInputs(){return Object.fromEntries(Object.entries(this.inputs).filter(([t,n])=>n.type!="node"))}get idx(){return this.code?.codeNodes.filter(t=>!t.state.integrated).indexOf(this)??-1}get idxByVariableNames(){return this.code?.getNodesBySameVariableNames(this.state.variableName).indexOf(this)??-1}get optionalInputs(){return Object.fromEntries(Object.entries(this.codeNodeInputs).filter(([t,n])=>n.optional))}get requiredInputs(){return Object.fromEntries(Object.entries(this.codeNodeInputs).filter(([t,n])=>!n.optional))}get script(){return this.state.script}get shortId(){return this.id.slice(0,6)}get subgraph(){}get variableName(){return this.state.variableName?this.state.variableName+(this.idxByVariableNames+1):""}getConnectedNodes(t){let n=[];if(t!=="inputs"){const s=this.graph?.connections.filter(a=>a.from.name!=="_node").filter(a=>a.from.nodeId===this.id).map(a=>a.to.nodeId);s&&(n=n.concat(s))}if(t!=="outputs"){const s=this.graph?.connections.filter(a=>a.from.name!=="_node").filter(a=>a.to.nodeId===this.id).map(a=>a.from.nodeId);s&&(n=n.concat(s))}return!n||n.length==0?[]:n.map(s=>this.graph?.findNodeById(s))}registerCode(t){this.code=t}renderCode(){const t={};Object.keys(this.inputs).forEach(s=>{if(s==="_node")return;const a=this.inputs[s];a&&a.state&&(t[s]=a.state.script.length>0?a.state.script:a.getValue())});const n={};Object.keys(this.outputs).forEach(s=>{if(s==="_node")return;const a=this.outputs[s];a&&a.state&&(n[s]=a.getValue())}),this.state.script=O.render(this.state.codeTemplate,{inputs:t,outputs:n}),this.outputs.code&&(this.outputs.code.state.script=this.state.script)}resetInputInterfaceScript(){Object.values(this.inputs).forEach(t=>t.state.script="")}updateCodeTemplate(){this.state.codeTemplate=this.codeTemplate.call(this)}updateConnectedInputInterfaces(){if(!this.graph)return;const{connectionsFromNode:t}=r.sortTopologically(this.graph);if(!t.has(this))return;const n=t.get(this);n&&n.forEach(s=>{if(!s.from.isCodeNode||!s.to.isCodeNode)return;const a=this.graph?.findNodeById(s.from.nodeId);if(a)if(a.renderCode(),s.to.allowMultipleConnections)if(s.to.state.script.startsWith("[")&&s.to.state.script.endsWith("]")){const i=JSON.parse(s.to.state.script);s.to.state.script=JSON.stringify([...i,s.from.script])}else s.to.state.script+=s.from.script;else s.to.state.script=s.from.script})}updateOutputVariableName(){this.outputs.code&&(this.outputs.code.name=this.state.integrated?"":this.variableName)}}class v extends A{calculate;load(t){super.load(t),L(this.graph,t)}save(){const t=super.save();return W(this.graph,t),t}updateModules(t){if(t)this.state.modules=t;else if(this.type.includes(".")){const n=this.type.split(".");this.state.modules.push(n.slice(0,n.length-1).join("."))}}}const H=o=>{const t=[],n=Object.keys(o);return n.forEach(s=>{if(o[s]?.hidden)return;const i=t.length<n.indexOf(s)?`${s}=`:"";t.push(`${i}{{ inputs.${s} }}`)}),t},L=(o,t)=>{if(!o)return;const n=o.findNodeById(t.id);if(!n||n.subgraph)return;const s=n;s.state&&(s.state.integrated=t.integrated,s.state.modules=t.modules,s.state.props=t.props),Object.entries(t.inputs).forEach(([a,i])=>{a!=="_node"&&s.inputs[a]&&(s.inputs[a].hidden=i.hidden)}),Object.entries(t.outputs).forEach(([a,i])=>{a!=="_node"&&s.outputs[a]&&(s.outputs[a].hidden=i.hidden)})},W=(o,t)=>{if(!o)return;const n=o.findNodeById(t.id);if(!n||n.subgraph)return;const s=n;s.state&&(t.integrated=s.state.integrated,t.modules=s.state.modules),Object.entries(t.inputs).forEach(([a,i])=>{a!=="_node"&&s.inputs[a]&&(i.hidden=s.inputs[a].hidden)}),Object.entries(t.outputs).forEach(([a,i])=>{a!=="_node"&&s.outputs[a]&&(i.hidden=s.outputs[a].hidden)})},ce=["title"],R=e.defineComponent({__name:"CodeNodeInterface",props:{intf:{}},setup(o){return(t,n)=>(e.openBlock(),e.createElementBlock("div",{title:o.intf.state?.script},e.toDisplayString(o.intf.name),9,ce))}});class x extends r.NodeInterface{isCodeNode=!0;code;state;type=null;constructor(t,n){super(t,n),this.setComponent(e.markRaw(R)),this.state=e.reactive({optional:!1,script:""})}get optional(){return this.state.optional}get shortId(){return this.id.slice(0,6)}getValue=()=>`${this.value??"None"}`}const pe=(o,t)=>{o.state.optional=t,o.setHidden(t)};class V extends x{constructor(t="",n){super(t,n),this.setComponent(e.markRaw(R)),this.use(r.displayInSidebar,!0)}get value(){return super.value}set value(t){super.value=t,this.name!=="_node"&&this.setHidden(!1)}}const D=new r.NodeInterfaceType("boolean"),X=new r.NodeInterfaceType("dict"),G=new r.NodeInterfaceType("list"),T=new r.NodeInterfaceType("node"),$=new r.NodeInterfaceType("number"),S=new r.NodeInterfaceType("string"),U=new r.NodeInterfaceType("tuple"),ue=o=>{new r.BaklavaInterfaceTypes(o.editor,{viewPlugin:o}).addTypes(D,X,G,T,$,S,U)};class he extends V{constructor(t,n){super(t,n),this.setComponent(e.markRaw(r.CheckboxInterfaceComponent)),this.use(r.setType,D)}getValue=()=>this.value?"True":"False"}class q extends x{isCodeNodeOutput=!0;constructor(t="",n=""){super(t,n),this.setComponent(e.markRaw(R))}get script(){return this.name.length>0?this.name:this.state.script}}class P extends V{min;max;constructor(t,n,s,a){super(t,n),this.min=s,this.max=a,this.use(r.setType,$)}validate(t){return(this.min===void 0||t>=this.min)&&(this.max===void 0||t<=this.max)}}class me extends P{component=e.markRaw(r.IntegerInterfaceComponent);validate(t){return Number.isInteger(t)&&super.validate(t)}}class fe extends V{constructor(t="",n=""){super(t,n),this.setComponent(e.markRaw(r.TextInputInterfaceComponent)),this.use(r.setType,G)}getValue=()=>`[${this.value}]`}class ge extends P{component=e.markRaw(r.NumberInterfaceComponent)}class F extends V{constructor(t,n){super(t,n),this.use(r.setType,S)}getValue=()=>`'${this.value}'`}class ye extends F{component=e.markRaw(r.SelectInterfaceComponent);items;constructor(t,n,s){super(t,n),this.items=s}}class Ne extends P{component=e.markRaw(r.SliderInterfaceComponent);min;max;constructor(t,n,s,a){super(t,n,s,a),this.min=s,this.max=a}getValue=()=>`${Math.round(this.value*1e3)/1e3}`}class be extends F{component=e.markRaw(r.TextInputInterfaceComponent)}class _e extends F{component=e.markRaw(r.TextareaInputInterfaceComponent)}class ke extends V{constructor(t="",n=""){super(t,n),this.setComponent(e.markRaw(r.TextInputInterfaceComponent)),this.use(r.setType,U)}getValue=()=>`(${this.value})`}function Ce(o){return class extends v{type=o.type;inputs={};outputs={};constructor(){super(),this._title=o.title??o.type,this.name=o.name??o.type,this.updateModules(o.modules),o.variableName&&(this.state.variableName=o.variableName),o.codeTemplate&&(this.codeTemplate=o.codeTemplate),this.addInput("_node",new x("",[]).use(r.setType,T).use(r.allowMultipleConnections).setHidden(!0)),this.addOutput("_node",new x("",[]).use(r.setType,T).use(r.allowMultipleConnections).setHidden(!0)),this.executeFactory("input",o.inputs),this.executeFactory("output",o.outputs),o.onCreate?.call(this)}onPlaced(){o.onPlaced?.call(this)}onDestroy(){o.onDestroy?.call(this)}onCodeUpdate(){o.onCodeUpdate?.call(this)}executeFactory(t,n){Object.keys(n||{}).forEach(s=>{const a=n[s]();t==="input"?this.addInput(s,a):this.addOutput(s,a)})}}}class Y extends v{calculate}function we(o){return class extends Y{type=o.type;inputs={};outputs={};calculate;preventUpdate=!1;staticInputKeys=Object.keys(o.inputs??{});staticOutputKeys=Object.keys(o.outputs??{});constructor(){super(),this._title=o.title??o.type,this.name=o.name??o.type,this.updateModules(o.modules),o.codeTemplate&&(this.codeTemplate=o.codeTemplate),o.variableName&&(this.state.variableName=o.variableName),this.addInput("_node",new x("",[]).use(r.setType,T).use(r.allowMultipleConnections).setHidden(!0)),this.addOutput("_node",new x("",[]).use(r.setType,T).use(r.allowMultipleConnections).setHidden(!0)),this.staticInputKeys.push("_node"),this.staticOutputKeys.push("_node"),this.executeFactory("input",o.inputs),this.executeFactory("output",o.outputs),o.onCreate?.call(this)}onPlaced(){this.events.update.subscribe(this,t=>{t&&(t.type==="input"&&this.staticInputKeys.includes(t.name)||t.type==="output"&&this.staticOutputKeys.includes(t.name))&&this.onUpdate()}),this.onUpdate(),o.onPlaced?.call(this)}onDestroy(){o.onDestroy?.call(this)}onCodeUpdate(){o.onCodeUpdate?.call(this)}load(t){this.preventUpdate=!0,this.hooks.beforeLoad.execute(t),this.id=t.id,this.title=t.title;for(const n of this.staticInputKeys)this.inputs[n].load(t.inputs[n]),this.inputs[n].nodeId=this.id,n!=="_node"&&(this.inputs[n].hidden=t.inputs[n].hidden);for(const n of this.staticOutputKeys)this.outputs[n].load(t.outputs[n]),this.outputs[n].nodeId=this.id,n!=="_node"&&(this.outputs[n].hidden=t.outputs[n].hidden);this.preventUpdate=!1,this.onUpdate(),this.preventUpdate=!0;for(const n of Object.keys(t.inputs))if(!this.staticInputKeys.includes(n)){if(!this.inputs[n]){const s=t.inputs[n].value;let a;typeof s=="number"?a=new r.IntegerInterface(n,s).use(r.setType,$):a=new r.TextInputInterface(n,JSON.stringify(s)).use(r.setType,S),a.use(r.displayInSidebar,!0),this.addInput(n,a)}this.inputs[n]&&(this.inputs[n].load(t.inputs[n]),this.inputs[n].nodeId=this.id)}for(const n of Object.keys(t.outputs))if(!this.staticOutputKeys.includes(n)){if(!this.outputs[n]){const s=new q(n);this.addOutput(n,s)}this.outputs[n]&&(this.outputs[n].load(t.outputs[n]),this.outputs[n].nodeId=this.id)}L(this.graph,t),this.preventUpdate=!1,this.events.loaded.emit(this)}onUpdate(){if(this.preventUpdate)return;this.graph&&this.graph.activeTransactions++;const t=this.getStaticValues(this.staticInputKeys,this.inputs),n=this.getStaticValues(this.staticOutputKeys,this.outputs),s=o.onUpdate.call(this,t,n);this.updateInterfaces("input",s.inputs??{},s.forceUpdateInputs??[]),this.updateInterfaces("output",s.outputs??{},s.forceUpdateOutputs??[]),this.graph&&this.graph.activeTransactions--}getStaticValues(t,n){const s={};for(const a of t)s[a]=n[a].value;return s}updateInterfaces(t,n,s){const a=t==="input"?this.staticInputKeys:this.staticOutputKeys,i=t==="input"?this.inputs:this.outputs;for(const d of Object.keys(i))a.includes(d)||n[d]&&!s.includes(d)||(t==="input"?this.removeInput(d):this.removeOutput(d));for(const d of Object.keys(n)){if(i[d])continue;const c=n[d]();t==="input"?this.addInput(d,c):this.addOutput(d,c)}}executeFactory(t,n){Object.keys(n||{}).forEach(s=>{const a=n[s]();t==="input"?this.addInput(s,a):this.addOutput(s,a)})}}}O.escape=o=>o;class J{_id;_viewModel;_state;constructor(t){this._id=le.v4(),this._viewModel=t,this._state=e.reactive({autosort:!1,modules:{},script:"",token:null,template:""})}get codeNodes(){return z(this.graph)}get connections(){return this.graph.connections}set connections(t){this.graph._connections=t}get graph(){return this.viewModel.displayedGraph}get id(){return this._id}get modules(){let t=[];return this.codeNodes.filter(n=>n.state.modules?.length>0).forEach(n=>{t=t.concat(n.state.modules)}),t?(t.sort(),Array.from(new Set(t.map(n=>this.viewModel.state.modules[n])))):[]}get nodeIds(){return this.codeNodes.map(t=>t.id)}get nodes(){return this.graph.nodes}set nodes(t){this.graph._nodes=t}get scriptedCodeNodes(){return z(this.graph).filter(t=>!t.state?.integrated)}get shortId(){return this.id.slice(0,6)}get state(){return this._state}get viewModel(){return this._viewModel}get visibleNodes(){return this.codeNodes.filter(t=>!t.state?.hidden)}addNode(t,n){return t.code||(t.code=this),n&&(t.state.props=n),this.graph.addNode(t)}addNodeAtCoordinates=(t,n={x:0,y:0},s)=>(this.addNode(t,s),t.position&&(t.position=n),t);addConnection(t,n){t.name!=="_node"&&(t.hidden=!1),n.name!=="_node"&&(n.hidden=!1),this.graph.addConnection(t,n)}clear(){this.state.modules={},this.nodes=[],this.connections=[],this.state.script=""}findNodeById(t){return this.graph.findNodeById(t)}findNodeByType(t){return this.codeNodes.find(n=>n.type===t)}getNodesBySameType(t){return this.codeNodes.filter(n=>n.type===t)}getNodesBySameVariableNames(t){return this.codeNodes.filter(n=>n.state.variableName===t)}hasConnection(t,n){return this.connections.some(s=>s.from.id===t.id&&s.to.id===n.id)}loadTemplate(t){t.then(n=>{this._state.template=n.default??""})}onCodeUpdate(){this.codeNodes.forEach(t=>t.onCodeUpdate())}removeConnection(t){this.graph.removeConnection(t)}removeNode(t){this.graph.removeNode(t)}renderNodeCodes(){this.codeNodes.length!==0&&this.codeNodes.forEach(t=>t.renderCode())}renderCode(){this.state.script=O.render(this.state.template||"",this)}resetInputInterfaceScript(){this.codeNodes.forEach(t=>t.resetInputInterfaceScript())}save(){this.state.autosort&&this.sortNodes();const t=this.viewModel.editor.save();return t.graph.id=this.id,this.saveNodeStates(t.graph.nodes),JSON.parse(JSON.stringify(t))}saveNodeStates(t){t.forEach((n,s)=>{const a=this.nodes[s];Object.entries(n.inputs).forEach(([i,d])=>{n.inputs&&a.inputs[i]&&(d.hidden=a.inputs[i].hidden)}),Object.entries(n.outputs).forEach(([i,d])=>{n.outputs&&a.outputs[i]&&(d.hidden=a.outputs[i].hidden)})})}sortNodes(){if(!(this.nodes.length===0||this.connections.length===0))try{const t=this.connections.map(i=>[i.to.nodeId,i.from.nodeId]);let n=[...this.nodeIds];n.reverse(),n=re.array(n,t),n.reverse();const s=this.graph.nodes.map(i=>i.id).filter(i=>!n.includes(i));n=n.concat(s);const a=n.map(i=>this.findNodeById(i));a&&(this.nodes=a)}catch{console.warn("Failed to sort nodes.")}}updateCodeTemplates(){this.codeNodes.forEach(t=>t.updateCodeTemplate())}updateOutputVariableNames(){this.codeNodes.forEach(t=>t.updateOutputVariableName())}}const z=o=>{let t=[];return o.nodes.forEach(n=>{n.subgraph?t=t.concat(z(n.subgraph)):n.isCodeNode&&t.push(n)}),t},Ie=(o=0,t=100)=>({x:o*420,y:t}),Ee=o=>{const t={...o.position};return t.x-=400,t.y+=50,t},Be=o=>{const{calculationOrder:t,connectionsFromNode:n}=r.sortTopologically(o);t.forEach(s=>{if(!s.isCodeNode)return;const a=s;n.has(a)&&n.get(a).forEach(i=>{i.to.state&&i.from.script&&(i.to.state.script=i.from.script)})})},xe=["id"],Ve={class:"align-middle"},K=e.defineComponent({__name:"CodeGraphNodeInterface",props:{node:{},intf:{}},setup(o){const t=o,{viewModel:n}=r.useViewModel(),{hoveredOver:s,temporaryConnection:a}=r.useTemporaryConnection(),i=e.ref(null),d=e.computed(()=>t.intf.connectionCount>0),c=e.computed(()=>({"--connected":d.value})),f=()=>{s(t.intf)},b=()=>{s(void 0)},_=()=>{i.value&&n.value.hooks.renderInterface.execute({intf:t.intf,el:i.value})};return e.onMounted(_),e.onUpdated(_),(E,B)=>(e.openBlock(),e.createElementBlock("div",{id:o.intf.id,ref_key:"el",ref:i,class:e.normalizeClass(["baklava-node-interface",c.value])},[o.intf.port?(e.openBlock(),e.createElementBlock("div",{key:0,class:e.normalizeClass(["__port",{"--selected":e.unref(a)?.from===o.intf}]),onPointerover:f,onPointerout:b},null,34)):e.createCommentVNode("",!0),e.createElementVNode("span",Ve,[e.renderSlot(E.$slots,"default")])],10,xe))}}),I=(o,t)=>{const n=o.__vccOpts||o;for(const[s,a]of t)n[s]=a;return n},Te={},Me={xmlns:"http://www.w3.org/2000/svg",width:"24",height:"24",viewBox:"0 0 24 24",fill:"none",stroke:"currentColor","stroke-width":"2","stroke-linecap":"round","stroke-linejoin":"round",class:"baklava-icon icon icon-tabler icons-tabler-outline icon-tabler-code-variable"};function Oe(o,t){return e.openBlock(),e.createElementBlock("svg",Me,[...t[0]||(t[0]=[e.createElementVNode("path",{stroke:"none",d:"M0 0h24v24H0z",fill:"none"},null,-1),e.createElementVNode("path",{d:"M4 8m0 2a2 2 0 0 1 2 -2h12a2 2 0 0 1 2 2v4a2 2 0 0 1 -2 2h-12a2 2 0 0 1 -2 -2z"},null,-1)])])}const $e=I(Te,[["render",Oe]]),Se={},ze={xmlns:"http://www.w3.org/2000/svg",width:"24",height:"24",viewBox:"0 0 24 24",fill:"none",stroke:"currentColor","stroke-width":"2","stroke-linecap":"round","stroke-linejoin":"round",class:"baklava-icon icon icon-tabler icons-tabler-outline icon-tabler-dots-vertical"};function ve(o,t){return e.openBlock(),e.createElementBlock("svg",ze,[...t[0]||(t[0]=[e.createElementVNode("path",{stroke:"none",d:"M0 0h24v24H0z",fill:"none"},null,-1),e.createElementVNode("path",{d:"M12 12m-1 0a1 1 0 1 0 2 0a1 1 0 1 0 -2 0"},null,-1),e.createElementVNode("path",{d:"M12 19m-1 0a1 1 0 1 0 2 0a1 1 0 1 0 -2 0"},null,-1),e.createElementVNode("path",{d:"M12 5m-1 0a1 1 0 1 0 2 0a1 1 0 1 0 -2 0"},null,-1)])])}const Le=I(Se,[["render",ve]]),Re={},De={xmlns:"http://www.w3.org/2000/svg",width:"24",height:"24",viewBox:"0 0 24 24",fill:"currentColor",class:"baklava-icon icon icon-tabler icons-tabler-filled icon-tabler-layout-sidebar-left-collapse"};function Ge(o,t){return e.openBlock(),e.createElementBlock("svg",De,[...t[0]||(t[0]=[e.createElementVNode("path",{stroke:"none",d:"M0 0h24v24H0z",fill:"none"},null,-1),e.createElementVNode("path",{d:"M18 3a3 3 0 0 1 2.995 2.824l.005 .176v12a3 3 0 0 1 -2.824 2.995l-.176 .005h-12a3 3 0 0 1 -2.995 -2.824l-.005 -.176v-12a3 3 0 0 1 2.824 -2.995l.176 -.005h12zm0 2h-9v14h9a1 1 0 0 0 .993 -.883l.007 -.117v-12a1 1 0 0 0 -.883 -.993l-.117 -.007zm-2.293 4.293a1 1 0 0 1 .083 1.32l-.083 .094l-1.292 1.293l1.292 1.293a1 1 0 0 1 .083 1.32l-.083 .094a1 1 0 0 1 -1.32 .083l-.094 -.083l-2 -2a1 1 0 0 1 -.083 -1.32l.083 -.094l2 -2a1 1 0 0 1 1.414 0z"},null,-1)])])}const Ue=I(Re,[["render",Ge]]),Pe={},Fe={xmlns:"http://www.w3.org/2000/svg",width:"24",height:"24",viewBox:"0 0 24 24",fill:"currentColor",class:"baklava-icon icon icon-tabler icons-tabler-filled icon-tabler-layout-sidebar-left-expand"};function Ae(o,t){return e.openBlock(),e.createElementBlock("svg",Fe,[...t[0]||(t[0]=[e.createElementVNode("path",{stroke:"none",d:"M0 0h24v24H0z",fill:"none"},null,-1),e.createElementVNode("path",{d:"M18 3a3 3 0 0 1 2.995 2.824l.005 .176v12a3 3 0 0 1 -2.824 2.995l-.176 .005h-12a3 3 0 0 1 -2.995 -2.824l-.005 -.176v-12a3 3 0 0 1 2.824 -2.995l.176 -.005h12zm0 2h-9v14h9a1 1 0 0 0 .993 -.883l.007 -.117v-12a1 1 0 0 0 -.883 -.993l-.117 -.007zm-4.387 4.21l.094 .083l2 2a1 1 0 0 1 .083 1.32l-.083 .094l-2 2a1 1 0 0 1 -1.497 -1.32l.083 -.094l1.292 -1.293l-1.292 -1.293a1 1 0 0 1 -.083 -1.32l.083 -.094a1 1 0 0 1 1.32 -.083z"},null,-1)])])}const He=I(Pe,[["render",Ae]]),We={},Xe={xmlns:"http://www.w3.org/2000/svg",width:"24",height:"24",viewBox:"0 0 24 24",fill:"currentColor",class:"balkava-icon icon icon-tabler icons-tabler-filled icon-tabler-layout-sidebar-right"};function qe(o,t){return e.openBlock(),e.createElementBlock("svg",Xe,[...t[0]||(t[0]=[e.createElementVNode("path",{stroke:"none",d:"M0 0h24v24H0z",fill:"none"},null,-1),e.createElementVNode("path",{d:"M6 21a3 3 0 0 1 -3 -3v-12a3 3 0 0 1 3 -3h12a3 3 0 0 1 3 3v12a3 3 0 0 1 -3 3zm8 -16h-8a1 1 0 0 0 -1 1v12a1 1 0 0 0 1 1h8z"},null,-1)])])}const Ye=I(We,[["render",qe]]),Je={},Ke={xmlns:"http://www.w3.org/2000/svg",width:"24",height:"24",viewBox:"0 0 24 24",fill:"currentColor",class:"baklava-icon icon icon-tabler icons-tabler-filled icon-tabler-layout-sidebar-right-collapse"};function Qe(o,t){return e.openBlock(),e.createElementBlock("svg",Ke,[...t[0]||(t[0]=[e.createElementVNode("path",{stroke:"none",d:"M0 0h24v24H0z",fill:"none"},null,-1),e.createElementVNode("path",{d:"M18 3a3 3 0 0 1 2.995 2.824l.005 .176v12a3 3 0 0 1 -2.824 2.995l-.176 .005h-12a3 3 0 0 1 -2.995 -2.824l-.005 -.176v-12a3 3 0 0 1 2.824 -2.995l.176 -.005h12zm-3 2h-9a1 1 0 0 0 -.993 .883l-.007 .117v12a1 1 0 0 0 .883 .993l.117 .007h9v-14zm-5.387 4.21l.094 .083l2 2a1 1 0 0 1 .083 1.32l-.083 .094l-2 2a1 1 0 0 1 -1.497 -1.32l.083 -.094l1.292 -1.293l-1.292 -1.293a1 1 0 0 1 -.083 -1.32l.083 -.094a1 1 0 0 1 1.32 -.083z"},null,-1)])])}const Ze=I(Je,[["render",Qe]]),je={},et={xmlns:"http://www.w3.org/2000/svg",width:"24",height:"24",viewBox:"0 0 24 24",fill:"currentColor",class:"baklava-icon icon icon-tabler icons-tabler-filled icon-tabler-layout-sidebar-right-expand"};function tt(o,t){return e.openBlock(),e.createElementBlock("svg",et,[...t[0]||(t[0]=[e.createElementVNode("path",{stroke:"none",d:"M0 0h24v24H0z",fill:"none"},null,-1),e.createElementVNode("path",{d:"M18 3a3 3 0 0 1 2.995 2.824l.005 .176v12a3 3 0 0 1 -2.824 2.995l-.176 .005h-12a3 3 0 0 1 -2.995 -2.824l-.005 -.176v-12a3 3 0 0 1 2.824 -2.995l.176 -.005h12zm-3 2h-9a1 1 0 0 0 -.993 .883l-.007 .117v12a1 1 0 0 0 .883 .993l.117 .007h9v-14zm-3.293 4.293a1 1 0 0 1 .083 1.32l-.083 .094l-1.292 1.293l1.292 1.293a1 1 0 0 1 .083 1.32l-.083 .094a1 1 0 0 1 -1.32 .083l-.094 -.083l-2 -2a1 1 0 0 1 -.083 -1.32l.083 -.094l2 -2a1 1 0 0 1 1.414 0z"},null,-1)])])}const nt=I(je,[["render",tt]]),ot={},st={xmlns:"http://www.w3.org/2000/svg",width:"24",height:"24",viewBox:"0 0 24 24",fill:"none",stroke:"currentColor","stroke-width":"2","stroke-linecap":"round","stroke-linejoin":"round",class:"baklava-icon icon icon-tabler icons-tabler-outline icon-tabler-schema"};function at(o,t){return e.openBlock(),e.createElementBlock("svg",st,[...t[0]||(t[0]=[e.createStaticVNode('<path stroke="none" d="M0 0h24v24H0z" fill="none"></path><path d="M5 2h5v4h-5z"></path><path d="M15 10h5v4h-5z"></path><path d="M5 18h5v4h-5z"></path><path d="M5 10h5v4h-5z"></path><path d="M10 12h5"></path><path d="M7.5 6v4"></path><path d="M7.5 14v4"></path>',8)])])}const it=I(ot,[["render",at]]),rt={},lt={xmlns:"http://www.w3.org/2000/svg",width:"24",height:"24",viewBox:"0 0 24 24",fill:"none",stroke:"currentColor","stroke-width":"2","stroke-linecap":"round","stroke-linejoin":"round",class:"baklava-icon icon icon-tabler icons-tabler-outline icon-tabler-schema-off"};function dt(o,t){return e.openBlock(),e.createElementBlock("svg",lt,[...t[0]||(t[0]=[e.createStaticVNode('<path stroke="none" d="M0 0h24v24H0z" fill="none"></path><path d="M6 2h4v4m-4 0h-1v-1"></path><path d="M15 11v-1h5v4h-2"></path><path d="M5 18h5v4h-5z"></path><path d="M5 10h5v4h-5z"></path><path d="M10 12h2"></path><path d="M7.5 7.5v2.5"></path><path d="M7.5 14v4"></path><path d="M3 3l18 18"></path>',9)])])}const ct=I(rt,[["render",dt]]),pt={},ut={xmlns:"http://www.w3.org/2000/svg",width:"24",height:"24",viewBox:"0 0 24 24",fill:"none",stroke:"currentColor","stroke-width":"2","stroke-linecap":"round","stroke-linejoin":"round",class:"baklava-icon icon icon-tabler icons-tabler-outline icon-tabler-transition-bottom"};function ht(o,t){return e.openBlock(),e.createElementBlock("svg",ut,[...t[0]||(t[0]=[e.createStaticVNode('<path stroke="none" d="M0 0h24v24H0z" fill="none"></path><path d="M21 18a3 3 0 0 1 -3 3h-12a3 3 0 0 1 -3 -3"></path><path d="M3 3m0 3a3 3 0 0 1 3 -3h12a3 3 0 0 1 3 3v0a3 3 0 0 1 -3 3h-12a3 3 0 0 1 -3 -3z"></path><path d="M12 9v8"></path><path d="M9 14l3 3l3 -3"></path>',5)])])}const mt=I(pt,[["render",ht]]),ft={},gt={xmlns:"http://www.w3.org/2000/svg",width:"24",height:"24",viewBox:"0 0 24 24",fill:"none",stroke:"currentColor","stroke-width":"2","stroke-linecap":"round","stroke-linejoin":"round",class:"baklava-icon icon icon-tabler icons-tabler-outline icon-tabler-trash-off"};function yt(o,t){return e.openBlock(),e.createElementBlock("svg",gt,[...t[0]||(t[0]=[e.createStaticVNode('<path stroke="none" d="M0 0h24v24H0z" fill="none"></path><path d="M3 3l18 18"></path><path d="M4 7h3m4 0h9"></path><path d="M10 11l0 6"></path><path d="M14 14l0 3"></path><path d="M5 7l1 12a2 2 0 0 0 2 2h8a2 2 0 0 0 2 -2l.077 -.923"></path><path d="M18.384 14.373l.616 -7.373"></path><path d="M9 5v-1a1 1 0 0 1 1 -1h4a1 1 0 0 1 1 1v3"></path>',8)])])}const Nt=I(ft,[["render",yt]]),bt=["id","data-node-type"],_t={class:"__title-label",style:{"flex-grow":"1"}},kt={key:0},Ct={class:"__menu",style:{display:"flex"}},wt={class:"__outputs"},It={key:0},Et=["id","title"],Bt={class:"__inputs"},xt={key:0},Vt=["id","title"],Tt=e.defineComponent({__name:"CodeGraphNode",props:{node:{},selected:{type:Boolean,default:!1},dragging:{type:Boolean}},emits:["select","start-drag","update"],setup(o,{emit:t}){const n=r.Components.ContextMenu,s=r.Components.NodeInterface,a=o,i=e.computed(()=>a.node),d=t,{viewModel:c}=r.useViewModel(),{graph:f,switchGraph:b}=r.useGraph(),_=e.ref(null),E=e.ref(!1),B=e.ref(""),k=e.ref(null),g=e.ref(!1);let y=0,m=0;const h=e.ref(!1),C=e.computed(()=>{const p=[{value:"edit",label:"Edit"},{value:"rename",label:"Rename"},{value:"delete",label:"Delete"}];return a.node.type.startsWith(r.GRAPH_NODE_TYPE_PREFIX)&&p.push({value:"editSubgraph",label:"Edit Subgraph"}),p}),w=e.computed(()=>({"--selected":a.selected,"--dragging":a.dragging,"--two-column":!!a.node.twoColumn,"--hidden":i.value.state?.hidden})),Kt=e.computed(()=>({"--reverse-y":a.node.reverseY??c.value.settings.nodes.reverseY})),Qt=e.computed(()=>({top:`${a.node.position?.y??0}px`,left:`${a.node.position?.x??0}px`,"--width":`${a.node.width??c.value.settings.nodes.defaultWidth}px`})),Zt=e.computed(()=>Object.values(a.node.inputs).filter(p=>!p.hidden)),jt=e.computed(()=>Object.values(a.node.outputs).filter(p=>!p.hidden)),j=()=>{d("select")},en=p=>{a.selected||j(),d("start-drag",p)},ee=()=>{h.value=!0},tn=()=>{const p=c.value.displayedGraph.sidebar;p.nodeId="",p.visible=!1},te=()=>{const p=c.value.displayedGraph.sidebar;p.nodeId=a.node.id,p.visible=!0},nn=()=>{const p=c.value.displayedGraph.sidebar;p.nodeId=a.node.id},on=async p=>{switch(p){case"edit":te();break;case"delete":f.value.removeNode(a.node);break;case"rename":B.value=a.node.title,E.value=!0,await e.nextTick(),k.value?.focus();break;case"editSubgraph":b(a.node.template);break}},ne=()=>{a.node.title=B.value,E.value=!1},oe=()=>{_.value&&c.value.hooks.renderNode.execute({node:a.node,el:_.value})},sn=p=>{g.value=!0,y=a.node.width,m=p.clientX,p.preventDefault()},se=p=>{i.value.state&&(i.value.state.integrated=p,d("update"))},ae=p=>{if(!g.value)return;const N=p.clientX-m,u=y+N/f.value.scaling,an=c.value.settings.nodes.minWidth,rn=c.value.settings.nodes.maxWidth;a.node.width=Math.max(an,Math.min(rn,u))},ie=()=>{g.value=!1};return e.onMounted(()=>{oe(),window.addEventListener("mousemove",ae),window.addEventListener("mouseup",ie)}),e.onUpdated(oe),e.onBeforeUnmount(()=>{window.removeEventListener("mousemove",ae),window.removeEventListener("mouseup",ie)}),(p,N)=>(e.openBlock(),e.createElementBlock("div",{id:i.value.id,ref_key:"el",ref:_,class:e.normalizeClass([w.value,"baklava-node"]),"data-node-type":i.value.type,style:e.normalizeStyle(Qt.value),onPointerdown:j},[e.unref(c).settings.nodes.resizable?(e.openBlock(),e.createElementBlock("div",{key:0,class:"__resize-handle",onMousedown:sn},null,32)):e.createCommentVNode("",!0),e.createElementVNode("div",{class:"__title",onPointerdown:e.withModifiers(en,["self","stop"]),onContextmenu:e.withModifiers(ee,["prevent"])},[i.value.inputs._node?(e.openBlock(),e.createBlock(K,{key:0,node:i.value,intf:i.value.inputs._node,class:"--input","data-interface-type":"node",style:{"flex-grow":"0"}},null,8,["node","intf"])):e.createCommentVNode("",!0),E.value?e.withDirectives((e.openBlock(),e.createElementBlock("input",{key:2,ref_key:"renameInputEl",ref:k,"onUpdate:modelValue":N[3]||(N[3]=u=>B.value=u),class:"baklava-input",placeholder:"Node Name",style:{"flex-grow":"1"},type:"text",onBlur:ne,onKeydown:e.withKeys(ne,["enter"])},null,544)),[[e.vModelText,B.value]]):(e.openBlock(),e.createElementBlock(e.Fragment,{key:1},[e.createElementVNode("div",_t,[i.value.idx>-1?(e.openBlock(),e.createElementBlock("span",kt,e.toDisplayString(i.value.idx+1)+" - ",1)):e.createCommentVNode("",!0),e.createTextVNode(e.toDisplayString(i.value.title)+" ("+e.toDisplayString(i.value.shortId)+") ",1)]),e.createElementVNode("div",Ct,[i.value.subgraph?e.createCommentVNode("",!0):(e.openBlock(),e.createElementBlock(e.Fragment,{key:0},[i.value.state.integrated?(e.openBlock(),e.createBlock(e.unref($e),{key:0,class:"--clickable mx-1",onClick:N[0]||(N[0]=u=>se(!1))})):(e.openBlock(),e.createBlock(e.unref(mt),{key:1,class:"--clickable mx-1",onClick:N[1]||(N[1]=u=>se(!0))})),!e.unref(c).displayedGraph.sidebar.visible&&e.unref(c).displayedGraph.sidebar.nodeId!==i.value.id?(e.openBlock(),e.createBlock(e.unref(nt),{key:2,class:"--clickable mx-1",onClick:te})):e.unref(c).displayedGraph.sidebar.visible&&e.unref(c).displayedGraph.sidebar.nodeId!==i.value.id?(e.openBlock(),e.createBlock(e.unref(Ye),{key:3,class:"--clickable mx-1",onClick:nn})):(e.openBlock(),e.createBlock(e.unref(Ze),{key:4,class:"--clickable mx-1",onClick:tn}))],64)),e.createVNode(e.unref(Le),{class:"--clickable mx-1",onClick:ee}),e.createVNode(e.unref(n),{modelValue:h.value,"onUpdate:modelValue":N[2]||(N[2]=u=>h.value=u),x:0,y:0,items:C.value,onClick:on},null,8,["modelValue","items"])])],64)),i.value.outputs._node?(e.openBlock(),e.createBlock(K,{key:3,node:i.value,intf:i.value.outputs._node,class:"--output","data-interface-type":"node"},null,8,["node","intf"])):e.createCommentVNode("",!0)],32),e.createElementVNode("div",{class:e.normalizeClass(["__content",Kt.value]),onKeydown:N[4]||(N[4]=e.withKeys(e.withModifiers(()=>{},["stop"]),["delete"])),onContextmenu:N[5]||(N[5]=e.withModifiers(()=>{},["prevent"]))},[e.createElementVNode("div",wt,[(e.openBlock(!0),e.createElementBlock(e.Fragment,null,e.renderList(jt.value,u=>(e.openBlock(),e.createElementBlock(e.Fragment,{key:u.id},[i.value.state?.hidden?(e.openBlock(),e.createElementBlock("div",It,[u.port?(e.openBlock(),e.createElementBlock("div",{key:0,id:u.id,title:u.name,class:"baklava-node-interface --output --connected"},[...N[6]||(N[6]=[e.createElementVNode("div",{class:"__port"},null,-1)])],8,Et)):e.createCommentVNode("",!0)])):e.renderSlot(p.$slots,"nodeInterface",{key:1,type:"output",node:i.value,intf:u},()=>[e.createVNode(e.unref(s),{node:i.value,intf:u,title:u.type},null,8,["node","intf","title"])])],64))),128))]),e.createElementVNode("div",Bt,[(e.openBlock(!0),e.createElementBlock(e.Fragment,null,e.renderList(Zt.value,u=>(e.openBlock(),e.createElementBlock(e.Fragment,{key:u.id},[i.value.state?.hidden?(e.openBlock(),e.createElementBlock("div",xt,[u.port?(e.openBlock(),e.createElementBlock("div",{key:0,id:u.id,title:u.name,class:"baklava-node-interface --input --connected"},[...N[7]||(N[7]=[e.createElementVNode("div",{class:"__port"},null,-1)])],8,Vt)):e.createCommentVNode("",!0)])):e.renderSlot(p.$slots,"nodeInterface",{key:1,node:i.value,intf:u,type:"input"},()=>[e.createVNode(e.unref(s),{node:i.value,intf:u,title:u.type},null,8,["node","intf","title"])])],64))),128))])],34)],46,bt))}}),Mt=["title"],Ot={key:0,class:"__label"},$t=e.defineComponent({__name:"Checkbox",props:{disabled:{type:Boolean},inversed:{type:Boolean},modelValue:{type:Boolean},name:{}},emits:["update:modelValue"],setup(o,{emit:t}){const n=t;return(s,a)=>(e.openBlock(),e.createElementBlock("div",{class:e.normalizeClass(["baklava-checkbox",{"--checked":o.inversed?!o.modelValue:o.modelValue,"--disabled":o.disabled}]),title:o.name,onClick:a[0]||(a[0]=i=>n("update:modelValue",!o.modelValue))},[a[1]||(a[1]=e.createElementVNode("div",{class:"__checkmark-container"},[e.createElementVNode("svg",{xmlns:"http://www.w3.org/2000/svg",width:"18",height:"18",viewBox:"0 0 18 18"},[e.createElementVNode("path",{class:"__checkmark",d:"M 6 5 L 6 10 L 16 10",transform:"rotate(-45 10 10)"})])],-1)),o.name?(e.openBlock(),e.createElementBlock("div",Ot,e.toDisplayString(o.name),1)):e.createCommentVNode("",!0)],10,Mt))}}),St={class:"__header"},zt={class:"__node-name"},vt={style:{display:"flex"}},Lt={key:1,class:"__interface"},Rt=e.defineComponent({__name:"CodeGraphSidebar",setup(o){const{viewModel:t}=r.useViewModel(),{graph:n}=r.useGraph(),s=e.ref(null),a=e.toRef(t.value.settings.sidebar,"width"),i=e.computed(()=>t.value.settings.sidebar.resizable);let d=0,c=0;const f=e.computed(()=>{const m=n.value.sidebar.nodeId;return n.value.nodes.find(h=>h.id===m)}),b=e.computed(()=>f.value),_=e.computed(()=>({width:`${a.value}px`})),E=e.computed(()=>b.value?[...Object.values(b.value.inputs),...Object.values(b.value.outputs)].filter(h=>h.displayInSidebar&&h.component):[]),B=()=>{n.value.sidebar.visible=!1},k=()=>{f.value?.events.update.emit(null)},g=m=>{d=a.value,c=m.clientX,window.addEventListener("mousemove",y),window.addEventListener("mouseup",()=>{window.removeEventListener("mousemove",y)},{once:!0})},y=m=>{const h=s.value?.parentElement?.getBoundingClientRect().width??500,C=m.clientX-c;let w=d-C;w<300?w=300:w>.9*h&&(w=.9*h),a.value=w};return(m,h)=>(e.openBlock(),e.createElementBlock("div",{ref_key:"el",ref:s,class:e.normalizeClass(["baklava-sidebar",{"--open":e.unref(n).sidebar.visible}]),style:e.normalizeStyle(_.value)},[i.value?(e.openBlock(),e.createElementBlock("div",{key:0,class:"__resizer",onMousedown:g},null,32)):e.createCommentVNode("",!0),e.createElementVNode("div",St,[e.createElementVNode("button",{tabindex:"-1",class:"__close",onClick:B},"×"),e.createElementVNode("div",zt,[e.createElementVNode("b",null,e.toDisplayString(f.value?f.value.title:""),1)])]),(e.openBlock(!0),e.createElementBlock(e.Fragment,null,e.renderList(E.value,C=>(e.openBlock(),e.createElementBlock("div",{key:C.id,class:"__interface"},[e.createElementVNode("div",vt,[e.createVNode($t,{modelValue:C.hidden,"onUpdate:modelValue":[w=>C.hidden=w,h[0]||(h[0]=()=>f.value?.events.update.emit(null))],disabled:!C.optional,inversed:"",style:{"padding-right":"8px"}},null,8,["modelValue","onUpdate:modelValue","disabled"]),(e.openBlock(),e.createBlock(e.resolveDynamicComponent(C.component),{modelValue:C.value,"onUpdate:modelValue":w=>C.value=w,node:f.value,intf:C,style:{width:"100%"}},null,8,["modelValue","onUpdate:modelValue","node","intf"]))])]))),128)),b.value&&b.value.state?(e.openBlock(),e.createElementBlock("div",Lt,[h[2]||(h[2]=e.createElementVNode("label",null,"Variable name",-1)),e.withDirectives(e.createElementVNode("input",{"onUpdate:modelValue":h[1]||(h[1]=C=>b.value.state.variableName=C),type:"text",class:"baklava-input",title:"Variable name",onBlur:k,onKeydown:e.withKeys(k,["enter"])},null,544),[[e.vModelText,b.value.state.variableName]])])):e.createCommentVNode("",!0)],6))}}),Dt=e.defineComponent({props:{type:{type:String,required:!0},title:{type:String,required:!0}},setup(o){const{viewModel:t}=r.useViewModel(),{switchGraph:n}=r.useGraph(),s=e.ref(!1),a=e.computed(()=>o.type.startsWith(r.GRAPH_NODE_TYPE_PREFIX));return{showContextMenu:s,hasContextMenu:a,contextMenuItems:[{label:"Edit Subgraph",value:"editSubgraph"},{label:"Delete Subgraph",value:"deleteSubgraph"}],openContextMenu:()=>{s.value=!0},onContextMenuClick:f=>{const b=o.type.substring(r.GRAPH_NODE_TYPE_PREFIX.length),_=t.value.editor.graphTemplates.find(E=>E.id===b);if(_)switch(f){case"editSubgraph":n(_);break;case"deleteSubgraph":t.value.editor.removeGraphTemplate(_);break}}}}}),Gt=["data-node-type"],Ut={class:"__title"},Pt={class:"__title-label"};function Ft(o,t,n,s,a,i){return e.openBlock(),e.createElementBlock("div",{class:"baklava-node --palette","data-node-type":o.type},[e.createElementVNode("div",Ut,[e.createElementVNode("div",Pt,e.toDisplayString(o.title),1)])],8,Gt)}const Q=I(Dt,[["render",Ft]]),At={class:"baklava-node --palette",style:{"margin-top":"-20px","margin-bottom":"20px"}},Ht={key:0,style:{display:"flex","justify-content":"space-between"}},Wt=["onClick"],Xt={key:0,style:{margin:"auto 0","font-size":"12px"}},qt=e.defineComponent({__name:"CodeNodePalette",setup(o){const{viewModel:t}=r.useViewModel(),{x:n,y:s}=de.usePointer(),{transform:a}=r.useTransform(),i=r.useNodeCategories(t),d=e.inject("editorEl"),c=e.ref(""),f=e.ref(null),b=()=>c.value?i.value.filter(k=>k.name.toLowerCase().includes(c.value.toLowerCase())||Object.values(k.nodeTypes).some(g=>g.title.toLowerCase().includes(c.value.toLowerCase()))):i.value,_=k=>c.value?Object.values(k).filter(g=>g.category.toLowerCase().includes(c.value.toLowerCase())||g.title.toLowerCase().includes(c.value.toLowerCase())):Object.values(k),E=e.computed(()=>{if(!f.value||!d?.value)return{};const{left:k,top:g}=d.value.getBoundingClientRect();return{top:`${s.value-g}px`,left:`${n.value-k}px`}}),B=(k,g)=>{f.value={type:k,nodeInformation:g};const y=()=>{const m=e.reactive(new g.type);t.value.displayedGraph.addNode(m);const h=d.value.getBoundingClientRect(),[C,w]=a(n.value-h.left,s.value-h.top);m.position.x=C,m.position.y=w,f.value=null,document.removeEventListener("pointerup",y)};document.addEventListener("pointerup",y)};return(k,g)=>(e.openBlock(),e.createElementBlock(e.Fragment,null,[e.createElementVNode("div",{class:e.normalizeClass(["baklava-node-palette",{"--open":e.unref(t).settings.palette.enabled}]),onContextmenu:g[1]||(g[1]=e.withModifiers(()=>{},["stop","prevent"]))},[e.createElementVNode("div",At,[e.withDirectives(e.createElementVNode("input",{"onUpdate:modelValue":g[0]||(g[0]=y=>c.value=y),type:"text",class:"baklava-input",title:"Filter nodes",onKeyup:b},null,544),[[e.vModelText,c.value]])]),(e.openBlock(!0),e.createElementBlock(e.Fragment,null,e.renderList(b(),y=>(e.openBlock(),e.createElementBlock("section",{key:y.name},[y.name!=="default"?(e.openBlock(),e.createElementBlock("h3",Ht,[e.createElementVNode("div",{onClick:m=>c.value=y.name,style:{cursor:"pointer"}},e.toDisplayString(y.name),9,Wt),_(y.nodeTypes).length<Object.values(y.nodeTypes).length?(e.openBlock(),e.createElementBlock("div",Xt," ( "+e.toDisplayString(_(y.nodeTypes).length)+" / "+e.toDisplayString(Object.values(y.nodeTypes).length)+" ) ",1)):e.createCommentVNode("",!0)])):e.createCommentVNode("",!0),(e.openBlock(!0),e.createElementBlock(e.Fragment,null,e.renderList(_(y.nodeTypes),m=>(e.openBlock(),e.createBlock(Q,{key:m.type,type:m.type,title:m.title,onPointerdown:h=>B(m.type,m)},null,8,["type","title","onPointerdown"]))),128))]))),128))],34),e.createVNode(e.Transition,{name:"fade"},{default:e.withCtx(()=>[f.value?(e.openBlock(),e.createElementBlock("div",{key:0,class:"baklava-dragged-node",style:e.normalizeStyle(E.value)},[e.createVNode(Q,{type:f.value.type,title:f.value.nodeInformation.title},null,8,["type","title"])],4)):e.createCommentVNode("",!0)]),_:1})],64))}}),Yt=e.defineComponent({__name:"CodeGraphEditor",props:{viewModel:{}},setup(o){const t=o,n=e.toRef(t,"viewModel"),s=a=>a.events.update.emit(null);return e.onMounted(()=>{n.value.subscribe(),n.value.engine.start()}),e.onUnmounted(()=>{n.value.unsubscribe(),n.value.engine.stop()}),(a,i)=>(e.openBlock(),e.createBlock(e.unref(r.BaklavaEditor),{"view-model":n.value},{palette:e.withCtx(()=>[e.createVNode(qt)]),node:e.withCtx(d=>[e.createVNode(Tt,e.mergeProps(d,{onUpdate:c=>s(d.node)}),null,16,["onUpdate"])]),sidebar:e.withCtx(d=>[e.createVNode(Rt,e.normalizeProps(e.guardReactiveProps(d)),null,16)]),_:1},8,["view-model"]))}}),Z=o=>{const t="TOGGLE_PALETTE";o.commandHandler.registerCommand(t,{execute:()=>o.settings.palette.enabled=!o.settings.palette.enabled,canExecute:()=>!0});const n="CLEAR_ALL";o.commandHandler.registerCommand(n,{execute:()=>o.code.clear(),canExecute:()=>o.displayedGraph.nodes.length>0});const s="TOGGLE_MINIMAP";o.commandHandler.registerCommand(s,{execute:()=>o.settings.enableMinimap=!o.settings.enableMinimap,canExecute:()=>o.displayedGraph.nodes.length>1}),o.settings.toolbar.commands=[{command:t,title:"Toggle palette",icon:e.computed(()=>o.settings.palette.enabled?Ue:He)},...r.DEFAULT_TOOLBAR_COMMANDS,{command:n,title:"Clear all",icon:Nt},{command:s,title:"Toggle minimap",icon:e.computed(()=>o.settings.enableMinimap?ct:it)}]},M={enableMinimap:!1,toolbar:{enabled:!0},palette:{enabled:!0},sidebar:{enabled:!0,resizable:!0,width:350},displayValueOnHover:!1};function Jt(o){const t=r.useBaklava(o?.existingEditor);t.code=o?.code?new o.code(t):new J(t),Z(t);const n={};return Object.keys(M).forEach(s=>{n[s]=typeof M[s]=="object"?{...t.settings[s],...M[s]}:M[s]}),t.settings=e.reactive({...t.settings,...n}),t.settings.nodes.defaultWidth=350,t.state=e.reactive({modules:{},token:null}),t.engine=new r.DependencyEngine(t.editor),t.subscribe=()=>{t.state.token&&t.unsubscribe();const s=Symbol();t.displayedGraph.events.addNode.subscribe(s,a=>a.code=t.code),t.engine.events.beforeRun.subscribe(s,()=>{t.engine.pause(),t.code&&(t.code.onCodeUpdate(),t.code.sortNodes(),t.code.updateCodeTemplates(),t.code.resetInputInterfaceScript()),t.engine.resume()}),t.engine.events.beforeNodeCalculation.subscribe(s,a=>{t.engine.pause();const i=a.node;i.isCodeNode&&(i.updateOutputVariableName(),i.updateConnectedInputInterfaces()),t.engine.resume()}),t.engine.events.afterRun.subscribe(s,a=>{t.engine.pause(),r.applyResult(a,t.editor),t.code&&(t.code.renderNodeCodes(),t.code.renderCode()),t.engine.resume()}),t.state.token=s},t.unsubscribe=()=>{if(!t.state.token)return;const s=t.state.token;t.displayedGraph.events.addNode.unsubscribe(s),t.engine.events.beforeRun.unsubscribe(s),t.engine.events.afterRun.unsubscribe(s),t.state.token=null},t}Object.defineProperty(l,"CheckboxInterfaceComponent",{enumerable:!0,get:()=>r.CheckboxInterfaceComponent}),Object.defineProperty(l,"NumberInterfaceComponent",{enumerable:!0,get:()=>r.NumberInterfaceComponent}),l.AbstractCodeNode=A,l.CheckboxInterface=he,l.Code=J,l.CodeGraphEditor=Yt,l.CodeNode=v,l.CodeNodeInputInterface=V,l.CodeNodeInterface=x,l.CodeNodeOutputInterface=q,l.DEFAULT_SETTINGS=M,l.DynamicCodeNode=Y,l.IntegerInterface=me,l.ListInputInterface=fe,l.NumberInterface=ge,l.SelectInterface=ye,l.SliderInterface=Ne,l.TextInputInterface=be,l.TextareaInputInterface=_e,l.TupleInputInterface=ke,l.addDefaultInterfaceTypes=ue,l.addToolbarCommands=Z,l.booleanType=D,l.defineCodeNode=Ce,l.defineDynamicCodeNode=we,l.dictType=X,l.formatInputs=H,l.getCodeNodes=z,l.getPositionAtColumn=Ie,l.getPositionBeforeNode=Ee,l.listType=G,l.loadNodeState=L,l.nodeType=T,l.numberType=$,l.saveNodeState=W,l.setOptional=pe,l.stringType=S,l.transferCodeScript=Be,l.tupleType=U,l.useCodeGraph=Jt,Object.defineProperty(l,Symbol.toStringTag,{value:"Module"})}));
|
package/dist/code.d.ts
CHANGED
|
@@ -93,6 +93,7 @@ export declare class Code {
|
|
|
93
93
|
* Render code.
|
|
94
94
|
*/
|
|
95
95
|
renderCode(): void;
|
|
96
|
+
resetInputInterfaceScript(): void;
|
|
96
97
|
/**
|
|
97
98
|
* Save code graph.
|
|
98
99
|
* @returns graph state
|
|
@@ -107,6 +108,7 @@ export declare class Code {
|
|
|
107
108
|
* Sort code nodes.
|
|
108
109
|
*/
|
|
109
110
|
sortNodes(): void;
|
|
111
|
+
updateCodeTemplates(): void;
|
|
110
112
|
updateOutputVariableNames(): void;
|
|
111
113
|
}
|
|
112
114
|
/**
|
|
@@ -7,7 +7,6 @@ interface IAbstractCodeNodeState {
|
|
|
7
7
|
hidden: boolean;
|
|
8
8
|
integrated: boolean;
|
|
9
9
|
modules: string[];
|
|
10
|
-
props?: unknown;
|
|
11
10
|
script: string;
|
|
12
11
|
variableName: string;
|
|
13
12
|
}
|
|
@@ -15,6 +14,7 @@ export declare abstract class AbstractCodeNode extends AbstractNode {
|
|
|
15
14
|
state: UnwrapRef<IAbstractCodeNodeState>;
|
|
16
15
|
code: Code | undefined;
|
|
17
16
|
isCodeNode: boolean;
|
|
17
|
+
name: string;
|
|
18
18
|
codeTemplate: () => string;
|
|
19
19
|
inputs: Record<string, NodeInterface<unknown>>;
|
|
20
20
|
outputs: Record<string, NodeInterface<unknown>>;
|
|
@@ -40,7 +40,9 @@ export declare abstract class AbstractCodeNode extends AbstractNode {
|
|
|
40
40
|
* Render code of this node.
|
|
41
41
|
*/
|
|
42
42
|
renderCode(): void;
|
|
43
|
-
|
|
43
|
+
resetInputInterfaceScript(): void;
|
|
44
|
+
updateCodeTemplate(): void;
|
|
45
|
+
updateConnectedInputInterfaces(): void;
|
|
44
46
|
updateOutputVariableName(): void;
|
|
45
47
|
}
|
|
46
48
|
export interface ICodeNodeState<I, O> extends INodeState<I, O>, IAbstractCodeNodeState {
|
|
@@ -8,6 +8,7 @@ export type InterfaceFactory<T> = {
|
|
|
8
8
|
};
|
|
9
9
|
export interface ICodeNodeDefinition<I, O> extends INodeDefinition<I, O> {
|
|
10
10
|
codeTemplate?: (node?: AbstractCodeNode) => string;
|
|
11
|
+
name?: string;
|
|
11
12
|
modules?: string[];
|
|
12
13
|
onCodeUpdate?: (node?: AbstractCodeNode) => void;
|
|
13
14
|
variableName?: string;
|
|
@@ -27,6 +27,7 @@ export interface DynamicNodeUpdateResult {
|
|
|
27
27
|
}
|
|
28
28
|
export interface IDynamicCodeNodeDefinition<I, O> extends IDynamicNodeDefinition<I, O> {
|
|
29
29
|
codeTemplate?: (node?: AbstractCodeNode) => string;
|
|
30
|
+
name?: string;
|
|
30
31
|
modules?: string[];
|
|
31
32
|
onCodeUpdate?: (node?: AbstractCodeNode) => void;
|
|
32
33
|
variableName?: string;
|
|
@@ -2,5 +2,6 @@ import { CheckboxInterfaceComponent } from 'baklavajs';
|
|
|
2
2
|
import { CodeNodeInputInterface } from '../codeNodeInput/codeNodeInputInterface';
|
|
3
3
|
export declare class CheckboxInterface extends CodeNodeInputInterface<boolean> {
|
|
4
4
|
constructor(name: string, value: boolean);
|
|
5
|
+
getValue: () => string;
|
|
5
6
|
}
|
|
6
7
|
export { CheckboxInterfaceComponent };
|
|
@@ -13,6 +13,7 @@ export declare class CodeNodeInterface<T = unknown> extends NodeInterface<T> {
|
|
|
13
13
|
constructor(name: string, value: T);
|
|
14
14
|
get optional(): boolean;
|
|
15
15
|
get shortId(): string;
|
|
16
|
+
getValue: () => string;
|
|
16
17
|
}
|
|
17
18
|
export declare const setOptional: (intf: CodeNodeInterface, value: boolean) => void;
|
|
18
19
|
export {};
|
|
@@ -3,8 +3,10 @@ export * from './codeNode/codeNodeInterface';
|
|
|
3
3
|
export * from './codeNodeInput/codeNodeInputInterface';
|
|
4
4
|
export * from './codeNodeOutput/codeNodeOutputInterface';
|
|
5
5
|
export * from './integer/integerInterface';
|
|
6
|
+
export * from './listInput/listInputInterface';
|
|
6
7
|
export * from './number/numberInterface';
|
|
7
8
|
export * from './select/selectInterface';
|
|
8
9
|
export * from './slider/sliderInterface';
|
|
9
10
|
export * from './textInput/textInputInterface';
|
|
10
11
|
export * from './textareaInput/textareaInputInterface';
|
|
12
|
+
export * from './tupleInput/tupleInputInterface';
|
|
@@ -1,8 +1,6 @@
|
|
|
1
1
|
import { ComponentOptions } from 'vue';
|
|
2
|
-
import { IntegerInterfaceComponent } from 'baklavajs';
|
|
3
2
|
import { BaseNumericInterface } from '../baseNumericInterface';
|
|
4
3
|
export declare class IntegerInterface extends BaseNumericInterface {
|
|
5
4
|
component: ComponentOptions;
|
|
6
5
|
validate(v: number): boolean;
|
|
7
6
|
}
|
|
8
|
-
export { IntegerInterfaceComponent };
|
|
@@ -1,5 +1,4 @@
|
|
|
1
1
|
import { ComponentOptions } from 'vue';
|
|
2
|
-
import { SelectInterfaceComponent } from 'baklavajs';
|
|
3
2
|
import { BaseStringInterface } from '../baseStringInterface';
|
|
4
3
|
export interface IAdvancedSelectInterfaceItem<V> {
|
|
5
4
|
text: string;
|
|
@@ -11,4 +10,3 @@ export declare class SelectInterface<V = string> extends BaseStringInterface {
|
|
|
11
10
|
items: SelectInterfaceItem<V>[];
|
|
12
11
|
constructor(name: string, value: V, items: SelectInterfaceItem<V>[]);
|
|
13
12
|
}
|
|
14
|
-
export { SelectInterfaceComponent };
|
|
@@ -1,10 +1,9 @@
|
|
|
1
1
|
import { ComponentOptions } from 'vue';
|
|
2
|
-
import { SliderInterfaceComponent } from 'baklavajs';
|
|
3
2
|
import { BaseNumericInterface } from '../baseNumericInterface';
|
|
4
3
|
export declare class SliderInterface extends BaseNumericInterface {
|
|
5
4
|
component: ComponentOptions;
|
|
6
5
|
min: number;
|
|
7
6
|
max: number;
|
|
8
7
|
constructor(name: string, value: number, min: number, max: number);
|
|
8
|
+
getValue: () => string;
|
|
9
9
|
}
|
|
10
|
-
export { SliderInterfaceComponent };
|
|
@@ -1,7 +1,5 @@
|
|
|
1
1
|
import { ComponentOptions } from 'vue';
|
|
2
|
-
import { TextInputInterfaceComponent } from 'baklavajs';
|
|
3
2
|
import { BaseStringInterface } from '../baseStringInterface';
|
|
4
3
|
export declare class TextInputInterface extends BaseStringInterface {
|
|
5
4
|
component: ComponentOptions;
|
|
6
5
|
}
|
|
7
|
-
export { TextInputInterfaceComponent };
|
|
@@ -1,7 +1,5 @@
|
|
|
1
1
|
import { ComponentOptions } from 'vue';
|
|
2
|
-
import { TextareaInputInterfaceComponent } from 'baklavajs';
|
|
3
2
|
import { BaseStringInterface } from '../baseStringInterface';
|
|
4
3
|
export declare class TextareaInputInterface extends BaseStringInterface {
|
|
5
4
|
component: ComponentOptions;
|
|
6
5
|
}
|
|
7
|
-
export { TextareaInputInterfaceComponent };
|
|
@@ -4,19 +4,19 @@ type __VLS_Props = {
|
|
|
4
4
|
selected?: boolean;
|
|
5
5
|
dragging?: boolean;
|
|
6
6
|
};
|
|
7
|
-
declare var
|
|
7
|
+
declare var __VLS_65: {
|
|
8
8
|
type: string;
|
|
9
9
|
node: AbstractCodeNode;
|
|
10
10
|
intf: import('baklavajs').NodeInterface<unknown>;
|
|
11
|
-
},
|
|
11
|
+
}, __VLS_72: {
|
|
12
12
|
node: AbstractCodeNode;
|
|
13
13
|
intf: import('baklavajs').NodeInterface<unknown>;
|
|
14
14
|
type: string;
|
|
15
15
|
};
|
|
16
16
|
type __VLS_Slots = {} & {
|
|
17
|
-
nodeInterface?: (props: typeof
|
|
17
|
+
nodeInterface?: (props: typeof __VLS_65) => any;
|
|
18
18
|
} & {
|
|
19
|
-
nodeInterface?: (props: typeof
|
|
19
|
+
nodeInterface?: (props: typeof __VLS_72) => any;
|
|
20
20
|
};
|
|
21
21
|
declare const __VLS_component: import('vue').DefineComponent<__VLS_Props, {}, {}, {}, {}, import('vue').ComponentOptionsMixin, import('vue').ComponentOptionsMixin, {} & {
|
|
22
22
|
select: () => any;
|
|
@@ -0,0 +1,2 @@
|
|
|
1
|
+
declare const _default: import('vue').DefineComponent<{}, {}, {}, {}, {}, import('vue').ComponentOptionsMixin, import('vue').ComponentOptionsMixin, {}, string, import('vue').PublicProps, Readonly<{}> & Readonly<{}>, {}, {}, {}, {}, string, import('vue').ComponentProvideOptions, true, {}, any>;
|
|
2
|
+
export default _default;
|
|
@@ -0,0 +1,2 @@
|
|
|
1
|
+
declare const _default: import('vue').DefineComponent<{}, {}, {}, {}, {}, import('vue').ComponentOptionsMixin, import('vue').ComponentOptionsMixin, {}, string, import('vue').PublicProps, Readonly<{}> & Readonly<{}>, {}, {}, {}, {}, string, import('vue').ComponentProvideOptions, true, {}, any>;
|
|
2
|
+
export default _default;
|
package/dist/icons/index.d.ts
CHANGED
|
@@ -1,3 +1,5 @@
|
|
|
1
|
+
export { default as CodeVariable } from './CodeVariable.vue';
|
|
2
|
+
export { default as DotsVertical } from './DotsVertical.vue';
|
|
1
3
|
export { default as LayoutSidebarLeftCollapse } from './LayoutSidebarLeftCollapse.vue';
|
|
2
4
|
export { default as LayoutSidebarLeftExpand } from './LayoutSidebarLeftExpand.vue';
|
|
3
5
|
export { default as LayoutSidebarRight } from './LayoutSidebarRight.vue';
|
|
@@ -5,5 +7,5 @@ export { default as LayoutSidebarRightCollapse } from './LayoutSidebarRightColla
|
|
|
5
7
|
export { default as LayoutSidebarRightExpand } from './LayoutSidebarRightExpand.vue';
|
|
6
8
|
export { default as Schema } from './Schema.vue';
|
|
7
9
|
export { default as SchemaOff } from './SchemaOff.vue';
|
|
10
|
+
export { default as TransitionBottom } from './TransitionBottom.vue';
|
|
8
11
|
export { default as TrashOff } from './TrashOff.vue';
|
|
9
|
-
export { default as VerticalDots } from './VerticalDots.vue';
|
|
@@ -5,4 +5,5 @@ export declare const listType: NodeInterfaceType<object>;
|
|
|
5
5
|
export declare const nodeType: NodeInterfaceType<null>;
|
|
6
6
|
export declare const numberType: NodeInterfaceType<number>;
|
|
7
7
|
export declare const stringType: NodeInterfaceType<string>;
|
|
8
|
+
export declare const tupleType: NodeInterfaceType<object>;
|
|
8
9
|
export declare const addDefaultInterfaceTypes: (baklavaView: IBaklavaViewModel) => void;
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@babsey/code-graph",
|
|
3
|
-
"version": "0.0.
|
|
3
|
+
"version": "0.0.17",
|
|
4
4
|
"author": "babsey <spreizer@web.de>",
|
|
5
5
|
"license": "MIT",
|
|
6
6
|
"type": "module",
|
|
@@ -31,6 +31,7 @@
|
|
|
31
31
|
"format": "prettier --write lib/ src/"
|
|
32
32
|
},
|
|
33
33
|
"dependencies": {
|
|
34
|
+
"@codemirror/lang-python": "~6.2",
|
|
34
35
|
"@codemirror/theme-one-dark": "~6.1",
|
|
35
36
|
"@vueuse/core": "~13.9",
|
|
36
37
|
"baklavajs": "~2.7",
|
|
File without changes
|