@babsey/code-graph 0.2.3 → 0.3.0

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.
Files changed (54) hide show
  1. package/dist/code-graph.css +1 -1
  2. package/dist/code-graph.js +1461 -1106
  3. package/dist/code-graph.umd.cjs +4 -1
  4. package/package.json +7 -7
  5. package/dist/code.d.ts +0 -158
  6. package/dist/codeNode/codeGraphNode.d.ts +0 -11
  7. package/dist/codeNode/codeNode.d.ts +0 -111
  8. package/dist/codeNode/defineCodeNode.d.ts +0 -18
  9. package/dist/codeNode/dynamicCodeNode.d.ts +0 -38
  10. package/dist/codeNode/index.d.ts +0 -4
  11. package/dist/codeNodeInterfaces/baseNumericInterface.d.ts +0 -23
  12. package/dist/codeNodeInterfaces/baseStringInterface.d.ts +0 -5
  13. package/dist/codeNodeInterfaces/checkbox/checkboxInterface.d.ts +0 -5
  14. package/dist/codeNodeInterfaces/codeNode/CodeNodeInterface.vue.d.ts +0 -7
  15. package/dist/codeNodeInterfaces/codeNode/codeNodeInterface.d.ts +0 -23
  16. package/dist/codeNodeInterfaces/codeNodeInput/codeNodeInputInterface.d.ts +0 -7
  17. package/dist/codeNodeInterfaces/codeNodeOutput/codeNodeOutputInterface.d.ts +0 -6
  18. package/dist/codeNodeInterfaces/index.d.ts +0 -12
  19. package/dist/codeNodeInterfaces/integer/integerInterface.d.ts +0 -6
  20. package/dist/codeNodeInterfaces/listInput/listInputInterface.d.ts +0 -5
  21. package/dist/codeNodeInterfaces/number/numberInterface.d.ts +0 -5
  22. package/dist/codeNodeInterfaces/select/selectInterface.d.ts +0 -12
  23. package/dist/codeNodeInterfaces/slider/sliderInterface.d.ts +0 -9
  24. package/dist/codeNodeInterfaces/textInput/TextInputInterface.vue.d.ts +0 -26
  25. package/dist/codeNodeInterfaces/textInput/textInputInterface.d.ts +0 -7
  26. package/dist/codeNodeInterfaces/textareaInput/textareaInputInterface.d.ts +0 -5
  27. package/dist/codeNodeInterfaces/tupleInput/tupleInputInterface.d.ts +0 -5
  28. package/dist/components/CodeGraphEditor.vue.d.ts +0 -19
  29. package/dist/components/index.d.ts +0 -1
  30. package/dist/components/node/CodeGraphNode.vue.d.ts +0 -39
  31. package/dist/components/nodeInterface/CodeGraphNodeInterface.vue.d.ts +0 -19
  32. package/dist/components/nodePalette/CodeNodePalette.vue.d.ts +0 -3
  33. package/dist/components/nodePalette/PaletteEntry.vue.d.ts +0 -31
  34. package/dist/components/sidebar/Checkbox.vue.d.ts +0 -13
  35. package/dist/components/sidebar/CodeGraphSidebar.vue.d.ts +0 -15
  36. package/dist/icons/CodeVariable.vue.d.ts +0 -3
  37. package/dist/icons/DotsVertical.vue.d.ts +0 -3
  38. package/dist/icons/LayoutSidebarLeftCollapse.vue.d.ts +0 -3
  39. package/dist/icons/LayoutSidebarLeftExpand.vue.d.ts +0 -3
  40. package/dist/icons/LayoutSidebarRight.vue.d.ts +0 -3
  41. package/dist/icons/LayoutSidebarRightCollapse.vue.d.ts +0 -3
  42. package/dist/icons/LayoutSidebarRightExpand.vue.d.ts +0 -3
  43. package/dist/icons/LockCode.vue.d.ts +0 -3
  44. package/dist/icons/Schema.vue.d.ts +0 -3
  45. package/dist/icons/SchemaOff.vue.d.ts +0 -3
  46. package/dist/icons/TransitionBottom.vue.d.ts +0 -3
  47. package/dist/icons/TrashOff.vue.d.ts +0 -3
  48. package/dist/icons/index.d.ts +0 -12
  49. package/dist/index.d.ts +0 -11
  50. package/dist/interfaceTypes/default.d.ts +0 -9
  51. package/dist/interfaceTypes/index.d.ts +0 -1
  52. package/dist/settings.d.ts +0 -11
  53. package/dist/utils.d.ts +0 -5
  54. package/dist/viewModel.d.ts +0 -20
@@ -1 +1,4 @@
1
- (function(d,x){typeof exports=="object"&&typeof module<"u"?x(exports,require("mustache"),require("toposort"),require("baklavajs"),require("vue"),require("uuid"),require("@vueuse/core")):typeof define=="function"&&define.amd?define(["exports","mustache","toposort","baklavajs","vue","uuid","@vueuse/core"],x):(d=typeof globalThis<"u"?globalThis:d||self,x(d["@babsey/code-graph"]={},d.mustache,d.toposort,d.baklavajs,d.Vue,d.uuid,d["@vueuse/core"]))})(this,(function(d,x,Ie,r,e,W,Ee){"use strict";x.escape=o=>o;class z extends r.AbstractNode{state;code;isCodeNode=!0;name="";codeTemplate;inputs={};outputs={};constructor(){super(),this.initializeIo(),this.twoColumn=!0,this.state=e.reactive({codeTemplate:"",hidden:!1,integrated:!1,lockCode:!1,modules:[],props:null,script:"",variableName:"x"}),this.codeTemplate=function(){return`${this.name}(${X(this.codeNodeInputs).join(", ")})`}}get codeNodeInputs(){return Object.fromEntries(Object.entries(this.inputs).filter(t=>t[1].type!="node"))}get codeNodeOutputs(){return Object.fromEntries(Object.entries(this.outputs).filter(t=>t[1].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 lockCode(){return this.state.lockCode}set lockCode(t){this.state.lockCode=t,this.events.update.emit(null)}get optionalInputs(){return Object.fromEntries(Object.entries(this.codeNodeInputs).filter(t=>t[1].optional))}get requiredInputs(){return Object.fromEntries(Object.entries(this.codeNodeInputs).filter(t=>!t[1].optional))}get script(){return this.state.script}set script(t){this.state.script=t,this.events.update.emit(null)}get shortId(){return this.id.slice(0,6)}get subgraph(){}get variableName(){return this.state.variableName?this.state.variableName+(this.idxByVariableNames+1):""}getConnectedNodeByInterface(t,n){const s=this.getConnectedNodesByInterface(t,n);return s.length>0?s[0]:null}getConnectedNodes(t){let n=[];if(t!=="inputs"){const s=this.graph?.connections.filter(i=>i.from.name!=="_code").filter(i=>i.from.nodeId===this.id).map(i=>i.to.nodeId);s&&(n=n.concat(s))}if(t!=="outputs"){const s=this.graph?.connections.filter(i=>i.from.name!=="_code").filter(i=>i.to.nodeId===this.id).map(i=>i.from.nodeId);s&&(n=n.concat(s))}return!n||n.length==0?[]:n.map(s=>this.graph?.findNodeById(s))}getConnectedNodesByInterface(t,n){let s=[];if(n!=="outputs"&&this.inputs[t]){const i=this.graph?.connections.filter(a=>a.to.id===this.inputs[t]?.id||a.from.id===this.inputs[t]?.id).map(a=>a.from.nodeId);i&&(s=s.concat(i))}if(n!=="inputs"&&this.outputs[t]){const i=this.graph?.connections.filter(a=>a.from.id===this.outputs[t]?.id||a.from.id===this.outputs[t]?.id).map(a=>a.to.nodeId);i&&(s=s.concat(i))}return!s||s.length==0?[]:s.map(i=>this.graph?.findNodeById(i))}registerCode(t){this.code=t}renderCode(){if(!this.lockCode){const t={};Object.keys(this.inputs).forEach(s=>{if(s==="_code")return;const i=this.inputs[s];i&&i.state&&(t[s]=i.state.script.length>0?i.state.script:i.getValue())});const n={};Object.keys(this.outputs).forEach(s=>{if(s==="_code")return;const i=this.outputs[s];i&&i.state&&(n[s]=i.getValue())}),this.state.script=x.render(this.state.codeTemplate,{inputs:t,outputs:n})}this.outputs.out&&(this.outputs.out.state.script=this.script)}resetInputInterfaceScript(){Object.values(this.codeNodeInputs).forEach(t=>t.resetScript())}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 i=this.graph?.findNodeById(s.from.nodeId);i&&(i.renderCode(),s.to.script=s.from.script)})}updateOutputNames(){Object.values(this.codeNodeOutputs).forEach(t=>{t.name=this.state.integrated?"":this.variableName+t.value})}updateProps(t){this.state.props=t}}class L extends z{calculate;load(t){super.load(t),P(this.graph,t)}save(){const t=super.save();return q(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 X=(o,t=!0)=>{const n=[],s=Object.keys(o);return s.forEach(i=>{if(o[i]?.hidden)return;const l=t&&n.length<s.indexOf(i)?`${i}=`:"";n.push(`${l}{{ inputs.${i} }}`)}),n},P=(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(([i,a])=>{i!=="_code"&&s.inputs[i]&&(s.inputs[i].hidden=a.hidden)}),Object.entries(t.outputs).forEach(([i,a])=>{i!=="_code"&&s.outputs[i]&&(s.outputs[i].hidden=a.hidden)})},q=(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(([i,a])=>{i!=="_code"&&s.inputs[i]&&(a.hidden=s.inputs[i].hidden)}),Object.entries(t.outputs).forEach(([i,a])=>{i!=="_code"&&s.outputs[i]&&(a.hidden=s.outputs[i].hidden)})},Be=["title"],$=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,Be))}});class V extends r.NodeInterface{isCodeNode=!0;code;state;type=null;constructor(t,n){super(t,n),this.setComponent(e.markRaw($)),this.state=e.reactive({optional:!1,script:""})}get optional(){return this.state.optional}get script(){return this.state.script}set script(t){this.state.script=t}get shortId(){return this.id.slice(0,6)}getValue=()=>`${this.value??"None"}`;resetScript=()=>this.state.script="";setOptional(t){return this.state.optional=t,this.setHidden(t),this}}class O extends V{constructor(t="",n){super(t,n),this.setComponent(e.markRaw($)),this.use(r.displayInSidebar,!0)}set script(t){if(this.state.script&&this.allowMultipleConnections){const n=this.state.script;n.startsWith("[")&&n.endsWith("]")?t=JSON.stringify([t,...JSON.parse(n)]):t=[t,n].join(", ")}this.state.script=t}get value(){return super.value}set value(t){super.value=t,this.name!=="_code"&&this.setHidden(!1)}}const G=new r.NodeInterfaceType("boolean"),Y=new r.NodeInterfaceType("dict"),D=new r.NodeInterfaceType("list"),M=new r.NodeInterfaceType("node"),S=new r.NodeInterfaceType("number"),v=new r.NodeInterfaceType("string"),U=new r.NodeInterfaceType("tuple"),Ve=o=>{new r.BaklavaInterfaceTypes(o.editor,{viewPlugin:o}).addTypes(G,Y,D,M,S,v,U)};class xe extends O{constructor(t,n){super(t,n),this.setComponent(e.markRaw(r.CheckboxInterfaceComponent)),this.use(r.setType,G)}getValue=()=>this.value?"True":"False"}class A extends V{isCodeNodeOutput=!0;constructor(t="",n=""){super(t,n),this.setComponent(e.markRaw($))}get script(){return this.name?this.name:this.state.script}}class H extends O{min;max;constructor(t,n,s,i){super(t,n),this.min=s,this.max=i,this.use(r.setType,S)}validate(t){return(this.min===void 0||t>=this.min)&&(this.max===void 0||t<=this.max)}}class Te extends H{component=e.markRaw(r.IntegerInterfaceComponent);validate(t){return Number.isInteger(t)&&super.validate(t)}}class Me extends O{constructor(t="",n=""){super(t,n),this.setComponent(e.markRaw(r.TextInputInterfaceComponent)),this.use(r.setType,D)}getValue=()=>`[${this.value}]`}class Oe extends H{component=e.markRaw(r.NumberInterfaceComponent)}class F extends O{constructor(t,n){super(t,n),this.use(r.setType,v)}getValue=()=>`"${this.value}"`}class $e extends F{component=e.markRaw(r.SelectInterfaceComponent);items;constructor(t,n,s){super(t,n),this.items=s}}class Se extends H{component=e.markRaw(r.SliderInterfaceComponent);min;max;constructor(t,n,s,i){super(t,n,s,i),this.min=s,this.max=i}getValue=()=>`${Math.round(this.value*1e3)/1e3}`}const ve=e.defineComponent({props:{intf:{type:Object,required:!0},modelValue:{type:String,required:!0}},emits:["update:modelValue"],setup(o,{emit:t}){return{v:e.computed({get:()=>o.modelValue,set:s=>{t("update:modelValue",s)}})}}}),E=(o,t)=>{const n=o.__vccOpts||o;for(const[s,i]of t)n[s]=i;return n},Re={style:{position:"relative"}},ze={style:{"font-size":"12px",padding:"0 6px",position:"absolute",top:"-8px","background-color":"var(--baklava-node-color-background)"}},Le=["placeholder","title"];function Pe(o,t,n,s,i,a){return e.openBlock(),e.createElementBlock("div",Re,[e.createElementVNode("label",ze,e.toDisplayString(o.intf.name),1),e.withDirectives(e.createElementVNode("input",{"onUpdate:modelValue":t[0]||(t[0]=l=>o.v=l),type:"text",class:"baklava-input",placeholder:o.intf.name,title:o.intf.name},null,8,Le),[[e.vModelText,o.v]])])}const K=E(ve,[["render",Pe]]);class Ge extends F{component=e.markRaw(K)}class De extends F{component=e.markRaw(r.TextareaInputInterfaceComponent)}class Ue extends O{constructor(t="",n=""){super(t,n),this.setComponent(e.markRaw(r.TextInputInterfaceComponent)),this.use(r.setType,U)}getValue=()=>`(${this.value})`}function Ae(o){return class extends L{type=o.type;inputs={};outputs={};constructor(){super(),this._title=o.title??o.type,this.executeFactory("input",o.inputs),this.executeFactory("output",o.outputs),o.onCreate?.call(this),this.name=o.name??o.type,this.updateModules(o.modules),o.variableName!=null&&(this.state.variableName=o.variableName),o.codeTemplate&&(this.codeTemplate=o.codeTemplate),this.addInput("_code",new V("",[]).use(r.setType,M).use(r.allowMultipleConnections).setHidden(!0)),this.addOutput("_code",new V("",[]).use(r.setType,M).use(r.allowMultipleConnections).setHidden(!0))}onPlaced(){o.onPlaced?.call(this)}onConnected(){o.onConnected?.call(this)}onDestroy(){o.onDestroy?.call(this)}onUnconnected(){o.onUnconnected?.call(this)}update(){o.update?.call(this)}executeFactory(t,n){Object.keys(n||{}).forEach(s=>{const i=n[s]();t==="input"?this.addInput(s,i):this.addOutput(s,i)})}}}class J extends L{calculate}function He(o){return class extends J{type=o.type;inputs={};outputs={};preventUpdate=!1;staticInputKeys=Object.keys(o.inputs??{});staticOutputKeys=Object.keys(o.outputs??{});constructor(){super(),this._title=o.title??o.type,this.executeFactory("input",o.inputs),this.executeFactory("output",o.outputs),o.onCreate?.call(this),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("_code",new V("",[]).use(r.setType,M).use(r.allowMultipleConnections).setHidden(!0)),this.addOutput("_code",new V("",[]).use(r.setType,M).use(r.allowMultipleConnections).setHidden(!0)),this.staticInputKeys.push("_code"),this.staticOutputKeys.push("_code")}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)}onConnected(){o.onConnected?.call(this)}onDestroy(){o.onDestroy?.call(this)}onUnconnected(){o.onUnconnected?.call(this)}update(){o.update?.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!=="_code"&&(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!=="_code"&&(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 i;typeof s=="number"?i=new r.IntegerInterface(n,s).use(r.setType,S):i=new r.TextInputInterface(n,JSON.stringify(s)).use(r.setType,v),i.use(r.displayInSidebar,!0),this.addInput(n,i)}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 A(n);this.addOutput(n,s)}this.outputs[n]&&(this.outputs[n].load(t.outputs[n]),this.outputs[n].nodeId=this.id)}P(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 i of t)s[i]=n[i].value;return s}updateInterfaces(t,n,s){const i=t==="input"?this.staticInputKeys:this.staticOutputKeys,a=t==="input"?this.inputs:this.outputs;for(const l of Object.keys(a))i.includes(l)||n[l]&&!s.includes(l)||(t==="input"?this.removeInput(l):this.removeOutput(l));for(const l of Object.keys(n)){if(a[l])continue;const c=n[l]();t==="input"?this.addInput(l,c):this.addOutput(l,c)}}updateProps(t){this.state.props=t,this.onUpdate()}executeFactory(t,n){Object.keys(n||{}).forEach(s=>{const i=n[s]();t==="input"?this.addInput(s,i):this.addOutput(s,i)})}}}const Fe="__baklava_GraphNode-",We=["component","connectionCount","events","hidden","hooks","id","isCodeNode","isInput","name","nodeId","port","templateId","value"];function Q(o){return class extends z{type=r.getGraphNodeTypeString(o);get title(){return this._title}set title(n){this.template.name=n}inputs={};outputs={};template=o;subgraph;renderCodes(){if(!this.subgraph)return;this.subgraph.nodes.filter(s=>s.isCodeNode).forEach(s=>s.renderCode());const n=this.subgraph.nodes;this.state.script=x.render(this.code.state.template||"",{nodes:n})}load(n){if(!this.subgraph)throw new Error("Cannot load a graph node without a graph");if(!this.template)throw new Error("Unable to load graph node without graph template");this.subgraph.load(n.graphState),super.load(n)}save(){if(!this.subgraph)throw new Error("Cannot save a graph node without a graph");return{...super.save(),graphState:this.subgraph.save()}}onPlaced(){this.template.events.updated.subscribe(this,()=>this.initialize()),this.template.events.nameChanged.subscribe(this,n=>{this._title=n}),this.initialize()}onConnected(){}onDestroy(){this.template.events.updated.unsubscribe(this),this.template.events.nameChanged.unsubscribe(this),this.subgraph?.destroy()}onUnconnected(){}initialize(){this.subgraph&&this.subgraph.destroy(),this.subgraph=this.template.createGraph(),this._title=this.template.name,this.updateInterfaces(),this.events.update.emit(null)}updateInterfaces(){if(!this.subgraph)throw new Error("Trying to update interfaces without graph instance");for(const n of this.subgraph.inputs)n.id in this.inputs?this.inputs[n.id].name=n.name:this.addInput(n.id,this.createProxyInterface(n,!0));for(const n of Object.keys(this.inputs))this.subgraph.inputs.some(s=>s.id===n)||this.removeInput(n);for(const n of this.subgraph.outputs)n.id in this.outputs?this.outputs[n.id].name=n.name:this.addOutput(n.id,this.createProxyInterface(n,!1));for(const n of Object.keys(this.outputs))this.subgraph.outputs.some(s=>s.id===n)||this.removeOutput(n);this.addInput("_code",new V("",[]).use(r.setType,M).use(r.allowMultipleConnections).setHidden(!0)),this.addOutput("_code",new V("",[]).use(r.setType,M).use(r.allowMultipleConnections).setHidden(!0)),this.addOutput("_calculationResults",new A("_calculationResults",void 0).setHidden(!0))}createProxyInterface(n,s){const i=new V(n.name,void 0);return new Proxy(i,{get:(a,l)=>{if(We.includes(l)||l in a||typeof l=="string"&&l.startsWith("__v_"))return Reflect.get(a,l);let c;s?c=this.subgraph?.nodes.find(k=>r.GraphInputNode.isGraphInputNode(k)&&k.graphInterfaceId===n.id)?.outputs.placeholder.id:c=this.subgraph?.nodes.find(k=>r.GraphOutputNode.isGraphOutputNode(k)&&k.graphInterfaceId===n.id)?.inputs.placeholder.id;const u=this.subgraph?.connections.find(y=>c===(s?y.from:y.to)?.id),C=s?u?.to:u?.from;if(C)return Reflect.get(C,l)}})}}}x.escape=o=>o;class Z{_id;_viewModel;_state;constructor(t){this._id=W.v4(),this._viewModel=t,this._state=e.reactive({autosort:!1,lockCode:!1,modules:{},script:"",template:"",token:null})}get codeNodes(){return R(this.graph)}get codeNodeIds(){return this.codeNodes.map(t=>t.id)}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 lockCode(){return this.state.lockCode}set lockCode(t){this.state.lockCode=t,this.viewModel.engine.runOnce(null)}get modules(){const t=[];return this.codeNodes.filter(n=>n.state.modules?.length>0).forEach(n=>t.push(...n.state.modules)),t?(t.sort(),Array.from(new Set(t.map(n=>this.viewModel.state.modules[n])))):[]}get nodeIds(){return this.nodes.map(t=>t.id)}get nodes(){return this.graph.nodes}set nodes(t){this.graph._nodes=t}get script(){return this.state.script}set script(t){this.state.script=t}get scriptedCodeNodes(){return R(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!=="_code"&&(t.hidden=!1),n.name!=="_code"&&(n.hidden=!1),this.graph.addConnection(t,n)}clear(){this.viewModel.commandHandler.executeCommand(r.Commands.CLEAR_CLIPBOARD_COMMAND),this.viewModel.commandHandler.executeCommand(r.Commands.CLEAR_HISTORY_COMMAND),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)}async loadTemplate(t){t.then(n=>{this._state.template=n.default??""})}removeConnection(t){this.graph.removeConnection(t)}removeNode(t){this.graph.removeNode(t)}renderNodeCodes(){this.state.lockCode||this.codeNodes.length===0||this.codeNodes.forEach(t=>t.renderCode())}renderCode(){if(this.state.lockCode)return;const t=this.scriptedCodeNodes,n=this.modules;this.state.script=x.render(this.state.template||"",{nodes:t,modules:n})}resetInputInterfaceScript(){this.codeNodes.forEach(t=>t.resetInputInterfaceScript())}sortNodes(){if(!(this.nodes.length===0||this.connections.length===0))try{let t=this.nodeIds;const n=this.connections.filter(a=>t.includes(a.to.nodeId)&&t.includes(a.from.nodeId)).map(a=>[a.to.nodeId,a.from.nodeId]);t.reverse(),t=Ie.array(t,n),t.reverse();const s=this.graph.nodes.map(a=>a.id).filter(a=>!t.includes(a));t=[...t,...s];const i=t.map(a=>this.findNodeById(a));i&&(this.nodes=i)}catch{console.warn("Failed to sort nodes.")}}updateCodeNodes(){this.codeNodes.forEach(t=>t.update())}updateCodeTemplates(){this.codeNodes.forEach(t=>t.updateCodeTemplate())}}const R=o=>{const t=[];return o.nodes.length===0||o.nodes.forEach(n=>{n&&(n.hasOwnProperty("subgraph")?t.push(...R(n.subgraph)):n.hasOwnProperty("isCodeNode")&&t.push(n))}),t},Xe=(o=0,t=100)=>({x:o*420,y:t}),qe=o=>{const t={...o.position};return t.x-=440,t.y+=50,t},Ye=["id"],Ke={class:"align-middle"},j=e.defineComponent({__name:"CodeGraphNodeInterface",props:{node:{},intf:{}},setup(o){const t=o,{viewModel:n}=r.useViewModel(),{hoveredOver:s,temporaryConnection:i}=r.useTemporaryConnection(),a=e.ref(null),l=e.computed(()=>t.intf.connectionCount>0),c=e.computed(()=>({"--connected":l.value})),u=()=>{s(t.intf)},C=()=>{s(void 0)},y=()=>{a.value&&n.value.hooks.renderInterface.execute({intf:t.intf,el:a.value})};return e.onMounted(y),e.onUpdated(y),(k,T)=>(e.openBlock(),e.createElementBlock("div",{id:o.intf.id,ref_key:"el",ref:a,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(i)?.from===o.intf}]),onPointerover:u,onPointerout:C},null,34)):e.createCommentVNode("",!0),e.createElementVNode("span",Ke,[e.renderSlot(k.$slots,"default")])],10,Ye))}}),Je={},Qe={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 Ze(o,t){return e.openBlock(),e.createElementBlock("svg",Qe,[...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 ee=E(Je,[["render",Ze]]),je={},et={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 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:"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 te=E(je,[["render",tt]]),nt={},ot={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 st(o,t){return e.openBlock(),e.createElementBlock("svg",ot,[...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 ne=E(nt,[["render",st]]),it={},at={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 rt(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("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 oe=E(it,[["render",rt]]),dt={},lt={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"};function ct(o,t){return e.openBlock(),e.createElementBlock("svg",lt,[...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 se=E(dt,[["render",ct]]),pt={},ut={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 ht(o,t){return e.openBlock(),e.createElementBlock("svg",ut,[...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 ie=E(pt,[["render",ht]]),mt={},ft={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 gt(o,t){return e.openBlock(),e.createElementBlock("svg",ft,[...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 ae=E(mt,[["render",gt]]),yt={},Ct={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-lock-code"};function _t(o,t){return e.openBlock(),e.createElementBlock("svg",Ct,[...t[0]||(t[0]=[e.createStaticVNode('<path stroke="none" d="M0 0h24v24H0z" fill="none"></path><path d="M11.5 21h-4.5a2 2 0 0 1 -2 -2v-6a2 2 0 0 1 2 -2h10a2 2 0 0 1 2 2"></path><path d="M11 16a1 1 0 1 0 2 0a1 1 0 0 0 -2 0"></path><path d="M8 11v-4a4 4 0 1 1 8 0v4"></path><path d="M20 21l2 -2l-2 -2"></path><path d="M17 17l-2 2l2 2"></path>',6)])])}const re=E(yt,[["render",_t]]),bt={},Nt={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 kt(o,t){return e.openBlock(),e.createElementBlock("svg",Nt,[...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 de=E(bt,[["render",kt]]),wt={},It={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 Et(o,t){return e.openBlock(),e.createElementBlock("svg",It,[...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 le=E(wt,[["render",Et]]),Bt={},Vt={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 xt(o,t){return e.openBlock(),e.createElementBlock("svg",Vt,[...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 ce=E(Bt,[["render",xt]]),Tt={},Mt={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 Ot(o,t){return e.openBlock(),e.createElementBlock("svg",Mt,[...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 pe=E(Tt,[["render",Ot]]),$t=["id","data-node-type"],St={class:"__title-label",style:{"flex-grow":"1"}},vt={key:0},Rt={class:"__menu",style:{display:"flex"}},zt={class:"__outputs"},Lt={key:0},Pt=["id","title"],Gt={class:"__inputs"},Dt={key:0},Ut=["id","title"],At=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,i=o,a=e.computed(()=>i.node),l=t,{viewModel:c}=r.useViewModel(),{graph:u,switchGraph:C}=r.useGraph(),y=e.ref(null),k=e.ref(!1),T=e.ref(""),w=e.ref(null),_=e.ref(!1);let g=0,B=0;const m=e.ref(!1),N=e.computed(()=>{const p=[{value:"edit",label:"Edit"},{value:"rename",label:"Rename"},{value:"delete",label:"Delete"}];return i.node.type.startsWith(r.GRAPH_NODE_TYPE_PREFIX)&&p.push({value:"editSubgraph",label:"Edit Subgraph"}),p}),h=e.computed(()=>({"--selected":i.selected,"--dragging":i.dragging,"--two-column":!!i.node.twoColumn,"--hidden":a.value.state?.hidden})),I=e.computed(()=>({"--reverse-y":i.node.reverseY??c.value.settings.nodes.reverseY})),mn=e.computed(()=>({top:`${i.node.position?.y??0}px`,left:`${i.node.position?.x??0}px`,"--width":`${i.node.width??c.value.settings.nodes.defaultWidth}px`})),fn=e.computed(()=>Object.values(i.node.inputs).filter(p=>!p.hidden)),gn=e.computed(()=>Object.values(i.node.outputs).filter(p=>!p.hidden)),ge=()=>{l("select")},yn=p=>{i.selected||ge(),l("start-drag",p)},ye=()=>{m.value=!0},Cn=()=>{const p=c.value.displayedGraph.sidebar;p.nodeId="",p.visible=!1},Ce=()=>{const p=c.value.displayedGraph.sidebar;p.nodeId=i.node.id,p.visible=!0},_n=()=>{const p=c.value.displayedGraph.sidebar;p.nodeId=i.node.id},bn=async p=>{switch(p){case"edit":Ce();break;case"delete":u.value.removeNode(i.node);break;case"rename":T.value=i.node.title,k.value=!0,await e.nextTick(),w.value?.focus();break;case"editSubgraph":C(i.node.template);break}},_e=()=>{a.value.title=T.value,k.value=!1},be=()=>{y.value&&c.value.hooks.renderNode.execute({node:i.node,el:y.value})},Nn=p=>{_.value=!0,g=i.node.width,B=p.clientX,p.preventDefault()},Ne=p=>{a.value.state&&(a.value.state.integrated=p,l("update"))},ke=p=>{if(!_.value)return;const b=p.clientX-B,f=g+b/u.value.scaling,kn=c.value.settings.nodes.minWidth,wn=c.value.settings.nodes.maxWidth;a.value.width=Math.max(kn,Math.min(wn,f))},we=()=>{_.value=!1};return e.onMounted(()=>{be(),window.addEventListener("mousemove",ke),window.addEventListener("mouseup",we)}),e.onUpdated(be),e.onBeforeUnmount(()=>{window.removeEventListener("mousemove",ke),window.removeEventListener("mouseup",we)}),(p,b)=>(e.openBlock(),e.createElementBlock("div",{id:a.value.id,ref_key:"el",ref:y,class:e.normalizeClass([h.value,"baklava-node"]),"data-node-type":a.value.type,style:e.normalizeStyle(mn.value),onPointerdown:ge},[e.unref(c).settings.nodes.resizable?(e.openBlock(),e.createElementBlock("div",{key:0,class:"__resize-handle",onMousedown:Nn},null,32)):e.createCommentVNode("",!0),e.createElementVNode("div",{class:"__title",onPointerdown:e.withModifiers(yn,["self","stop"]),onContextmenu:e.withModifiers(ye,["prevent"])},[a.value.inputs._code?(e.openBlock(),e.createBlock(j,{key:0,node:a.value,intf:a.value.inputs._code,title:a.value.inputs._code.value,class:"--input","data-interface-type":"node",style:{"flex-grow":"0"}},null,8,["node","intf","title"])):e.createCommentVNode("",!0),k.value?e.withDirectives((e.openBlock(),e.createElementBlock("input",{key:2,ref_key:"renameInputEl",ref:w,"onUpdate:modelValue":b[4]||(b[4]=f=>T.value=f),class:"baklava-input",placeholder:"Node Name",style:{"flex-grow":"1"},type:"text",onBlur:_e,onKeydown:e.withKeys(_e,["enter"])},null,544)),[[e.vModelText,T.value]]):(e.openBlock(),e.createElementBlock(e.Fragment,{key:1},[e.createElementVNode("div",St,[a.value.idx>-1?(e.openBlock(),e.createElementBlock("span",vt,e.toDisplayString(a.value.idx+1)+" - ",1)):e.createCommentVNode("",!0),e.createTextVNode(e.toDisplayString(a.value.title),1)]),e.createElementVNode("div",Rt,[a.value.isCodeNode?(e.openBlock(),e.createElementBlock(e.Fragment,{key:0},[a.value.state.lockCode?(e.openBlock(),e.createBlock(e.unref(re),{key:0,class:"--clickable mx-1",onClick:b[0]||(b[0]=f=>a.value.lockCode=!1)})):e.createCommentVNode("",!0),a.value.state.integrated?(e.openBlock(),e.createBlock(e.unref(ee),{key:1,class:"--clickable mx-1",onClick:b[1]||(b[1]=f=>Ne(!1))})):(e.openBlock(),e.createBlock(e.unref(ce),{key:2,class:"--clickable mx-1",onClick:b[2]||(b[2]=f=>Ne(!0))})),!e.unref(c).displayedGraph.sidebar.visible&&e.unref(c).displayedGraph.sidebar.nodeId!==a.value.id?(e.openBlock(),e.createBlock(e.unref(ae),{key:3,class:"--clickable mx-1",onClick:Ce})):e.unref(c).displayedGraph.sidebar.visible&&e.unref(c).displayedGraph.sidebar.nodeId!==a.value.id?(e.openBlock(),e.createBlock(e.unref(se),{key:4,class:"--clickable mx-1",onClick:_n})):(e.openBlock(),e.createBlock(e.unref(ie),{key:5,class:"--clickable mx-1",onClick:Cn}))],64)):e.createCommentVNode("",!0),e.createVNode(e.unref(te),{class:"--clickable mx-1",onClick:ye}),e.createVNode(e.unref(n),{modelValue:m.value,"onUpdate:modelValue":b[3]||(b[3]=f=>m.value=f),x:0,y:0,items:N.value,onClick:bn},null,8,["modelValue","items"])])],64)),a.value.outputs._code?(e.openBlock(),e.createBlock(j,{key:3,node:a.value,intf:a.value.outputs._code,class:"--output",title:a.value.outputs._code.value,"data-interface-type":"node"},null,8,["node","intf","title"])):e.createCommentVNode("",!0)],32),e.createElementVNode("div",{class:e.normalizeClass(["__content",I.value]),onKeydown:b[5]||(b[5]=e.withKeys(e.withModifiers(()=>{},["stop"]),["delete"])),onContextmenu:b[6]||(b[6]=e.withModifiers(()=>{},["prevent"]))},[e.createElementVNode("div",zt,[(e.openBlock(!0),e.createElementBlock(e.Fragment,null,e.renderList(gn.value,f=>(e.openBlock(),e.createElementBlock(e.Fragment,{key:f.id},[a.value.state?.hidden?(e.openBlock(),e.createElementBlock("div",Lt,[f.port?(e.openBlock(),e.createElementBlock("div",{key:0,id:f.id,title:f.name,class:"baklava-node-interface --output --connected"},[...b[7]||(b[7]=[e.createElementVNode("div",{class:"__port"},null,-1)])],8,Pt)):e.createCommentVNode("",!0)])):e.renderSlot(p.$slots,"nodeInterface",{key:1,type:"output",node:a.value,intf:f},()=>[e.createVNode(e.unref(s),{node:a.value,intf:f,title:f.type},null,8,["node","intf","title"])])],64))),128))]),e.createElementVNode("div",Gt,[(e.openBlock(!0),e.createElementBlock(e.Fragment,null,e.renderList(fn.value,f=>(e.openBlock(),e.createElementBlock(e.Fragment,{key:f.id},[a.value.state?.hidden?(e.openBlock(),e.createElementBlock("div",Dt,[f.port?(e.openBlock(),e.createElementBlock("div",{key:0,id:f.id,title:f.name,class:"baklava-node-interface --input --connected"},[...b[8]||(b[8]=[e.createElementVNode("div",{class:"__port"},null,-1)])],8,Ut)):e.createCommentVNode("",!0)])):e.renderSlot(p.$slots,"nodeInterface",{key:1,node:a.value,intf:f,type:"input"},()=>[e.createVNode(e.unref(s),{node:a.value,intf:f,title:f.type},null,8,["node","intf","title"])])],64))),128))])],34)],46,$t))}}),Ht=["title"],Ft={key:0,class:"__label"},ue=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,i)=>(e.openBlock(),e.createElementBlock("div",{class:e.normalizeClass(["baklava-checkbox",{"--checked":o.inversed?!o.modelValue:o.modelValue,"--disabled":o.disabled}]),title:o.name,onClick:i[0]||(i[0]=a=>n("update:modelValue",!o.modelValue))},[i[1]||(i[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",Ft,e.toDisplayString(o.name),1)):e.createCommentVNode("",!0)],10,Ht))}}),Wt={class:"__header"},Xt={class:"__node-name"},qt={class:"__interfaces"},Yt={class:"__inputs"},Kt={style:{display:"flex"}},Jt={class:"__outputs"},Qt={key:0,class:"__interface"},Zt={style:{display:"flex"}},jt=e.defineComponent({__name:"CodeGraphSidebar",setup(o){const{viewModel:t}=r.useViewModel(),{graph:n}=r.useGraph(),s=e.ref(null),i=e.toRef(t.value.settings.sidebar,"width"),a=e.computed(()=>t.value.settings.sidebar.resizable);let l=0,c=0;const u=e.computed(()=>{const m=n.value.sidebar.nodeId;return n.value.nodes.find(N=>N.id===m)}),C=e.computed(()=>u.value),y=e.computed(()=>({width:`${i.value}px`})),k=e.computed(()=>C.value?Object.values(C.value.inputs).filter(m=>m.displayInSidebar&&m.component):[]),T=e.computed(()=>C.value?Object.values(C.value.outputs).filter(m=>m.displayInSidebar&&m.component):[]),w=()=>{n.value.sidebar.visible=!1},_=()=>{u.value?.events.update.emit(null)},g=m=>{l=i.value,c=m.clientX,window.addEventListener("mousemove",B),window.addEventListener("mouseup",()=>{window.removeEventListener("mousemove",B)},{once:!0})},B=m=>{const N=s.value?.parentElement?.getBoundingClientRect().width??500,h=m.clientX-c;let I=l-h;I<300?I=300:I>.9*N&&(I=.9*N),i.value=I};return(m,N)=>(e.openBlock(),e.createElementBlock("div",{class:e.normalizeClass([{"--open":e.unref(n).sidebar.visible},"baklava-sidebar"]),style:e.normalizeStyle(y.value),ref_key:"el",ref:s},[a.value?(e.openBlock(),e.createElementBlock("div",{key:0,class:"__resizer",onMousedown:g},null,32)):e.createCommentVNode("",!0),u.value?(e.openBlock(),e.createElementBlock(e.Fragment,{key:1},[e.createElementVNode("div",Wt,[e.createElementVNode("button",{tabindex:"-1",class:"__close",onClick:w},"×"),e.createElementVNode("div",Xt,[e.createElementVNode("b",null,e.toDisplayString(u.value.title),1)])]),e.createElementVNode("div",qt,[e.createElementVNode("div",Yt,[(e.openBlock(!0),e.createElementBlock(e.Fragment,null,e.renderList(k.value,h=>(e.openBlock(),e.createElementBlock("div",{key:h.id,class:"__interface"},[e.createElementVNode("div",Kt,[e.createVNode(ue,{modelValue:h.hidden,"onUpdate:modelValue":[I=>h.hidden=I,N[0]||(N[0]=()=>u.value?.events.update.emit(null))],disabled:!h.optional,inversed:"",style:{"padding-right":"8px"}},null,8,["modelValue","onUpdate:modelValue","disabled"]),(e.openBlock(),e.createBlock(e.resolveDynamicComponent(h.component),{modelValue:h.value,"onUpdate:modelValue":I=>h.value=I,node:u.value,intf:h,style:{width:"100%"}},null,8,["modelValue","onUpdate:modelValue","node","intf"]))])]))),128))]),e.createElementVNode("div",Jt,[C.value&&C.value.state?(e.openBlock(),e.createElementBlock("div",Qt,[N[3]||(N[3]=e.createElementVNode("label",null,"Variable name",-1)),e.withDirectives(e.createElementVNode("input",{"onUpdate:modelValue":N[1]||(N[1]=h=>C.value.state.variableName=h),type:"text",class:"baklava-input",title:"Variable name",onBlur:_,onKeydown:e.withKeys(_,["enter"])},null,544),[[e.vModelText,C.value.state.variableName]])])):e.createCommentVNode("",!0),(e.openBlock(!0),e.createElementBlock(e.Fragment,null,e.renderList(T.value,h=>(e.openBlock(),e.createElementBlock("div",{key:h.id,class:"__interface"},[e.createElementVNode("div",Zt,[e.createVNode(ue,{modelValue:h.hidden,"onUpdate:modelValue":[I=>h.hidden=I,N[2]||(N[2]=()=>u.value?.events.update.emit(null))],disabled:!h.optional,inversed:"",style:{"padding-right":"8px"}},null,8,["modelValue","onUpdate:modelValue","disabled"]),(e.openBlock(),e.createBlock(e.resolveDynamicComponent(h.component),{modelValue:h.value,"onUpdate:modelValue":I=>h.value=I,node:u.value,intf:h,style:{width:"100%"}},null,8,["modelValue","onUpdate:modelValue","node","intf"]))])]))),128))])]),e.renderSlot(m.$slots,"codeEditor",{node:u.value})],64)):e.createCommentVNode("",!0)],6))}});function en(o,t){return Object.fromEntries(Object.entries(o).filter(t))}const tn=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),i=e.computed(()=>o.type.startsWith(r.GRAPH_NODE_TYPE_PREFIX));return{showContextMenu:s,hasContextMenu:i,contextMenuItems:[{label:"Edit Subgraph",value:"editSubgraph"},{label:"Delete Subgraph",value:"deleteSubgraph"}],openContextMenu:()=>{s.value=!0},onContextMenuClick:u=>{const C=o.type.substring(r.GRAPH_NODE_TYPE_PREFIX.length),y=t.value.editor.graphTemplates.find(k=>k.id===C);if(y)switch(u){case"editSubgraph":n(y);break;case"deleteSubgraph":t.value.editor.removeGraphTemplate(y);break}}}}}),nn=["data-node-type"],on={class:"__title"},sn={class:"__title-label"};function an(o,t,n,s,i,a){return e.openBlock(),e.createElementBlock("div",{class:"baklava-node --palette","data-node-type":o.type},[e.createElementVNode("div",on,[e.createElementVNode("div",sn,e.toDisplayString(o.title),1)])],8,nn)}const he=E(tn,[["render",an]]),rn={class:"baklava-node --palette",style:{"margin-top":"-20px","margin-bottom":"20px"}},dn={key:0,style:{display:"flex","justify-content":"space-between"}},ln=["onClick"],cn={key:0,style:{margin:"auto 0","font-size":"12px"}},pn=e.defineComponent({__name:"CodeNodePalette",setup(o){const{viewModel:t}=r.useViewModel(),{x:n,y:s}=Ee.usePointer(),{transform:i}=r.useTransform(),a=r.useNodeCategories(t),l=e.inject("editorEl"),c=e.ref(""),u=e.ref(null),C=()=>c.value?a.value.filter(w=>w.name.toLowerCase().includes(c.value.toLowerCase())||Object.values(w.nodeTypes).some(_=>_.title.toLowerCase().includes(c.value.toLowerCase()))):a.value,y=w=>c.value?en(w,_=>{const g=_[1];return g.category.includes(c.value.toLowerCase())||g.title?.toLowerCase().includes(c.value.toLowerCase())}):w,k=e.computed(()=>{if(!u.value||!l?.value)return{};const{left:w,top:_}=l.value.getBoundingClientRect();return{top:`${s.value-_}px`,left:`${n.value-w}px`}}),T=(w,_)=>{u.value={type:w,nodeInformation:_};const g=()=>{const B=e.reactive(new _.type);t.value.displayedGraph.addNode(B);const m=l.value.getBoundingClientRect(),[N,h]=i(n.value-m.left,s.value-m.top);B.position.x=N,B.position.y=h,u.value=null,document.removeEventListener("pointerup",g)};document.addEventListener("pointerup",g)};return(w,_)=>(e.openBlock(),e.createElementBlock(e.Fragment,null,[e.createElementVNode("div",{class:e.normalizeClass([{"--open":e.unref(t).settings.palette.enabled},"baklava-node-palette"]),onContextmenu:_[1]||(_[1]=e.withModifiers(()=>{},["stop","prevent"]))},[e.createElementVNode("div",rn,[e.withDirectives(e.createElementVNode("input",{"onUpdate:modelValue":_[0]||(_[0]=g=>c.value=g),type:"text",class:"baklava-input",title:"Filter nodes",onKeyup:C},null,544),[[e.vModelText,c.value]])]),(e.openBlock(!0),e.createElementBlock(e.Fragment,null,e.renderList(C(),g=>(e.openBlock(),e.createElementBlock("section",{key:g.name},[g.name!=="default"?(e.openBlock(),e.createElementBlock("h3",dn,[e.createElementVNode("div",{onClick:B=>c.value=g.name,style:{cursor:"pointer"}},e.toDisplayString(g.name),9,ln),Object.keys(y(g.nodeTypes)).length<Object.values(g.nodeTypes).length?(e.openBlock(),e.createElementBlock("div",cn," ( "+e.toDisplayString(Object.keys(y(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(y(g.nodeTypes),(B,m)=>(e.openBlock(),e.createBlock(he,{key:m,type:m,title:B.title,onPointerdown:N=>T(m,B)},null,8,["type","title","onPointerdown"]))),128))]))),128))],34),e.createVNode(e.Transition,{name:"fade"},{default:e.withCtx(()=>[u.value?(e.openBlock(),e.createElementBlock("div",{key:0,class:"baklava-dragged-node",style:e.normalizeStyle(k.value)},[e.createVNode(he,{type:u.value.type,title:u.value.nodeInformation.title},null,8,["type","title"])],4)):e.createCommentVNode("",!0)]),_:1})],64))}}),un=e.defineComponent({__name:"CodeGraphEditor",props:{viewModel:{}},setup(o){const t=o,n=e.toRef(t,"viewModel"),s=i=>i.events.update.emit(null);return e.onMounted(()=>{n.value.subscribe(),n.value.engine.start()}),e.onUnmounted(()=>{n.value.unsubscribe(),n.value.engine.stop()}),(i,a)=>(e.openBlock(),e.createBlock(e.unref(r.BaklavaEditor),{"view-model":n.value},{palette:e.withCtx(()=>[e.createVNode(pn)]),node:e.withCtx(l=>[e.createVNode(At,e.mergeProps(l,{onUpdate:c=>s(l.node)}),null,16,["onUpdate"])]),sidebar:e.withCtx(l=>[e.createVNode(jt,e.normalizeProps(e.guardReactiveProps(l)),{codeEditor:e.withCtx(({node:c})=>[e.renderSlot(i.$slots,"sidebarCodeEditor",{node:c})]),_:3},16)]),_:3},8,["view-model"]))}});function hn(o){const t=r.useBaklava(o?.existingEditor);return t.code=o?.code?new o.code(t):new Z(t),t.editor.addGraphTemplate=function(n){if(this.events.beforeAddGraphTemplate.emit(n).prevented)return;this._graphTemplates.push(n),this.graphTemplateEvents.addTarget(n.events),this.graphTemplateHooks.addTarget(n.hooks);const s=Q(n);this.registerNodeType(s,{category:"Subgraphs",title:n.name}),this.events.addGraphTemplate.emit(n)},me(t),fe(t),t.state=e.reactive({modules:{},token:null}),t.init=()=>{t.unsubscribe(),t.engine=new r.DependencyEngine(t.editor)},t.loadEditor=n=>{t.engine?.pause(),t.code.clear(),t.editor.load(n),t.commandHandler.executeCommand(r.Commands.CLEAR_CLIPBOARD_COMMAND),t.commandHandler.executeCommand(r.Commands.CLEAR_HISTORY_COMMAND),t.engine?.resume(),t.engine?.runOnce(void 0)},t.newGraph=()=>{t.engine?.pause(),t.code.clear(),t.editor.graph.id=W.v4(),t.engine?.resume(),t.engine?.runOnce(void 0)},t.subscribe=()=>{t.state.token&&t.unsubscribe();const n=Symbol(),s=t.displayedGraph;s.events.addNode.subscribe(n,i=>{!i.subgraph&&i.isCodeNode&&(i.code=t.code)}),s.events.addConnection.subscribe(n,i=>{const a=t.code.findNodeById(i.to.nodeId);a&&a.isCodeNode&&a.onConnected();const l=t.code.findNodeById(i.from.nodeId);l&&l.isCodeNode&&l.onConnected()}),s.events.removeConnection.subscribe(n,i=>{const a=t.code.findNodeById(i.to.nodeId);a&&a.isCodeNode&&a.onUnconnected();const l=t.code.findNodeById(i.from.nodeId);l&&l.isCodeNode&&l.onUnconnected()}),t.engine.events.beforeRun.subscribe(n,()=>{t.engine.pause(),t.code&&(t.code.updateCodeNodes(),t.code.sortNodes(),t.code.updateCodeTemplates(),t.code.resetInputInterfaceScript()),t.engine.resume()}),t.engine.events.beforeNodeCalculation.subscribe(n,i=>{t.engine.pause();const a=i.node;a.isCodeNode&&(a.updateOutputNames(),a.updateConnectedInputInterfaces()),t.engine.resume()}),t.engine.events.afterRun.subscribe(n,()=>{t.engine.pause(),t.code&&(t.code.renderNodeCodes(),t.code.renderCode()),t.engine.resume()}),t.state.token=n},t.unsubscribe=()=>{if(!t.state.token)return;const n=t.state.token;t.displayedGraph.events.addNode.unsubscribe(n),t.displayedGraph.events.addConnection.unsubscribe(n),t.engine.events.beforeRun.unsubscribe(n),t.engine.events.beforeNodeCalculation.unsubscribe(n),t.engine.events.afterRun.unsubscribe(n),t.state.token=null},t}const me=o=>{const t="TOGGLE_PALETTE";o.commandHandler.registerCommand(t,{execute:()=>o.settings.palette.enabled=!o.settings.palette.enabled,canExecute:()=>!0});const n={command:t,title:"Toggle palette",icon:e.computed(()=>o.settings.palette.enabled?ne:oe)},s="CLEAR_ALL";o.commandHandler.registerCommand(s,{execute:()=>o.code.clear(),canExecute:()=>o.displayedGraph.nodes.length>0});const i={command:s,title:"Clear all",icon:e.computed(()=>pe)},a="TOGGLE_MINIMAP";o.commandHandler.registerCommand(a,{execute:()=>o.settings.enableMinimap=!o.settings.enableMinimap,canExecute:()=>o.displayedGraph.nodes.length>1});const l={command:a,title:"Toggle minimap",icon:e.computed(()=>o.settings.enableMinimap?le:de)};o.settings.toolbar.commands=[n,...r.DEFAULT_TOOLBAR_COMMANDS,i,l]},fe=o=>{o.settings.nodes.defaultWidth=400};d.AbstractCodeNode=z,d.CheckboxInterface=xe,d.Code=Z,d.CodeGraphEditor=un,d.CodeNode=L,d.CodeNodeInputInterface=O,d.CodeNodeInterface=V,d.CodeNodeInterfaceComponent=$,d.CodeNodeOutputInterface=A,d.CodeVariable=ee,d.DotsVertical=te,d.DynamicCodeNode=J,d.GRAPH_NODE_TYPE_PREFIX=Fe,d.IntegerInterface=Te,d.LayoutSidebarLeftCollapse=ne,d.LayoutSidebarLeftExpand=oe,d.LayoutSidebarRight=se,d.LayoutSidebarRightCollapse=ie,d.LayoutSidebarRightExpand=ae,d.ListInputInterface=Me,d.LockCode=re,d.NumberInterface=Oe,d.Schema=de,d.SchemaOff=le,d.SelectInterface=$e,d.SliderInterface=Se,d.TextInputInterface=Ge,d.TextInputInterfaceComponent=K,d.TextareaInputInterface=De,d.TransitionBottom=ce,d.TrashOff=pe,d.TupleInputInterface=Ue,d.addDefaultInterfaceTypes=Ve,d.addToolbarCommands=me,d.booleanType=G,d.createCodeGraphNodeType=Q,d.defineCodeNode=Ae,d.defineDynamicCodeNode=He,d.dictType=Y,d.formatInputs=X,d.getCodeNodes=R,d.getPositionAtColumn=Xe,d.getPositionBeforeNode=qe,d.listType=D,d.loadNodeState=P,d.nodeType=M,d.numberType=S,d.saveNodeState=q,d.stringType=v,d.tupleType=U,d.updateSettings=fe,d.useCodeGraph=hn,Object.defineProperty(d,Symbol.toStringTag,{value:"Module"})}));
1
+ (function(r,$){typeof exports=="object"&&typeof module<"u"?$(exports,require("mustache"),require("vue"),require("uuid"),require("@baklavajs/core"),require("@baklavajs/interface-types"),require("@baklavajs/engine"),require("@baklavajs/renderer-vue"),require("toposort"),require("@baklavajs/events"),require("@vueuse/core")):typeof define=="function"&&define.amd?define(["exports","mustache","vue","uuid","@baklavajs/core","@baklavajs/interface-types","@baklavajs/engine","@baklavajs/renderer-vue","toposort","@baklavajs/events","@vueuse/core"],$):(r=typeof globalThis<"u"?globalThis:r||self,$(r["@babsey/code-graph"]={},r.mustache,r.vue,r.uuid,r["@baklavajs/core"],r["@baklavajs/interface-types"],r["@baklavajs/engine"],r["@baklavajs/renderer-vue"],r.toposort,r["@baklavajs/events"],r["@vueuse/core"]))})(this,(function(r,$,e,j,O,I,R,f,nt,fe,ot){"use strict";$.escape=o=>o;class Y extends O.AbstractNode{state;isCodeNode=!0;name="";codeTemplate;inputs={};outputs={};constructor(){super(),this.initializeIo(),this.twoColumn=!0,this.state=e.reactive({codeTemplate:"",hidden:!1,integrated:!1,lockCode:!1,modules:[],props:null,script:"",variableName:"a"}),this.codeTemplate=function(){return`${this.name}(${ge(this.codeNodeInputs).join(", ")})`}}get code(){return this.graph.code}get codeNodeInputs(){return Object.fromEntries(Object.entries(this.inputs).filter(t=>t[1].isCodeNode&&t[1].type!="node"))}get codeNodeOutputs(){return Object.fromEntries(Object.entries(this.outputs).filter(t=>t[1].isCodeNode&&t[1].type!="node"))}get graph(){return super.graph}get idx(){return this.graph.nodes.filter(t=>!t.state.integrated).indexOf(this)??-1}get idxByVariableNames(){return this.graph.getNodesBySameVariableNames(this.state.variableName).filter(t=>!t.state.integrated).indexOf(this)??-1}get lockCode(){return this.state.lockCode}set lockCode(t){this.state.lockCode=t,this.events.update.emit(null)}get optionalInputs(){return Object.fromEntries(Object.entries(this.codeNodeInputs).filter(t=>t[1].optional))}get requiredInputs(){return Object.fromEntries(Object.entries(this.codeNodeInputs).filter(t=>!t[1].optional))}get script(){return this.outputs._code?.value??""}set script(t){this.outputs._code&&(this.outputs._code.value=t),this.events.update.emit(null)}get shortId(){return this.id.slice(0,6)}get subgraph(){}get variableName(){return this.state.variableName?this.state.variableName+(this.idxByVariableNames+1):""}getConnectedNodeByInterface(t,n){const s=this.getConnectedNodesByInterface(t,n);return s.length>0?s[0]:null}getConnectedNodes(t){let n=[];if(t!=="inputs"){const s=this.graph.connections.filter(a=>a.from.name!=="_code").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!=="_code").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))}getConnectedNodesByInterface(t,n){let s=[];if(n!=="outputs"&&this.inputs[t]){const a=this.graph.connections.filter(i=>i.to.id===this.inputs[t]?.id||i.from.id===this.inputs[t]?.id).map(i=>i.from.nodeId);a&&(s=s.concat(a))}if(n!=="inputs"&&this.outputs[t]){const a=this.graph.connections.filter(i=>i.from.id===this.outputs[t]?.id||i.from.id===this.outputs[t]?.id).map(i=>i.to.nodeId);a&&(s=s.concat(a))}return!s||s.length==0?[]:s.map(a=>this.graph.findNodeById(a))}registerCode(t){this.code=t}renderCode(t){return $.render(this.state.codeTemplate,t)}updateCodeTemplate(){this.state.codeTemplate=this.codeTemplate.call(this)}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("."))}}updateOutputNames(){Object.values(this.codeNodeOutputs).forEach(t=>{t.name=this.state.integrated?"":this.variableName+t.suffix})}updateOutputValues(t){Object.keys(this.outputs).forEach(n=>{n!=="_code"&&(t[n]=this.state.integrated?t._code:this.outputs[n].name)})}updateProps(t){this.state.props=t}}class A extends Y{calculate=(t,n)=>{const s={};return this.lockCode||(s._code=this.renderCode({inputs:t,...n})),this.updateOutputValues(s),s};load(t){super.load(t),K(this.graph,t)}save(){const t=super.save();return be(this.graph,t),t}}const ge=(o,t=!0)=>{const n=[],s=Object.keys(o);return s.forEach(a=>{if(o[a]?.hidden)return;const l=t&&n.length<s.indexOf(a)?`${a}=`:"";n.push(`${l}{{ inputs.${a} }}`)}),n},K=(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!=="_code"&&s.inputs[a]&&(s.inputs[a].hidden=i.hidden)}),Object.entries(t.outputs).forEach(([a,i])=>{a!=="_code"&&s.outputs[a]&&(s.outputs[a].hidden=i.hidden)})},be=(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!=="_code"&&s.inputs[a]&&(i.hidden=s.inputs[a].hidden)}),Object.entries(t.outputs).forEach(([a,i])=>{a!=="_code"&&s.outputs[a]&&(i.hidden=s.outputs[a].hidden)})},st=["title"],H=e.defineComponent({__name:"CodeNodeInterface",props:{intf:{}},setup(o){return(t,n)=>(e.openBlock(),e.createElementBlock("div",{title:o.intf.value},e.toDisplayString(o.intf.name),9,st))}});class x extends O.NodeInterface{isCodeNode=!0;code;state;type=null;constructor(t,n){super(t,n),this.setComponent(e.markRaw(H)),this.state=e.reactive({optional:!1})}get optional(){return this.state.optional}get shortId(){return this.id.slice(0,6)}getValue=()=>`${this.value??"None"}`;setOptional(t){return this.state.optional=t,this.setHidden(t),this}}class L extends x{constructor(t="",n){super(t,n),this.setComponent(e.markRaw(H)),this.use(f.displayInSidebar,!0)}get value(){return super.value}set value(t){super.value=t,this.name!=="_code"&&this.setHidden(!1)}}const X=new I.NodeInterfaceType("boolean"),ke=new I.NodeInterfaceType("dict"),J=new I.NodeInterfaceType("list"),V=new I.NodeInterfaceType("node"),U=new I.NodeInterfaceType("number"),F=new I.NodeInterfaceType("string"),Q=new I.NodeInterfaceType("tuple"),at=o=>{new I.BaklavaInterfaceTypes(o.editor,{viewPlugin:o}).addTypes(X,ke,J,V,U,F,Q)};class it extends L{constructor(t,n){super(t,n),this.setComponent(e.markRaw(f.CheckboxInterfaceComponent)),this.use(I.setType,X)}getValue=()=>this.value?"True":"False"}class Ce extends x{isCodeNodeOutput=!0;suffix="";constructor(t="",n=""){super(t,""),this.suffix=n,this.setComponent(e.markRaw(H))}get codeValue(){return this.node?.outputs._code.value??""}get node(){const{graph:t}=f.useGraph();return t.value.findNodeById(this.nodeId)}}class Z extends L{min;max;constructor(t,n,s,a){super(t,n),this.min=s,this.max=a,this.use(I.setType,U)}validate(t){return(this.min===void 0||t>=this.min)&&(this.max===void 0||t<=this.max)}}class rt extends Z{component=e.markRaw(f.IntegerInterfaceComponent);validate(t){return Number.isInteger(t)&&super.validate(t)}}class lt extends L{constructor(t="",n=""){super(t,n),this.setComponent(e.markRaw(f.TextInputInterfaceComponent)),this.use(I.setType,J)}getValue=()=>`[${this.value}]`}class dt extends Z{component=e.markRaw(f.NumberInterfaceComponent)}class ee extends L{constructor(t,n){super(t,n),this.use(I.setType,F)}getValue=()=>`"${this.value}"`}class ct extends ee{component=e.markRaw(f.SelectInterfaceComponent);items;constructor(t,n,s){super(t,n),this.items=s}}class ut extends Z{component=e.markRaw(f.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}`}const pt=e.defineComponent({props:{intf:{type:Object,required:!0},modelValue:{type:String,required:!0}},emits:["update:modelValue"],setup(o,{emit:t}){return{v:e.computed({get:()=>o.modelValue,set:s=>{t("update:modelValue",s)}})}}}),S=(o,t)=>{const n=o.__vccOpts||o;for(const[s,a]of t)n[s]=a;return n},ht={style:{position:"relative"}},mt={style:{"font-size":"12px",padding:"0 6px",position:"absolute",top:"-8px","background-color":"var(--baklava-node-color-background)"}},ft=["placeholder","title"];function gt(o,t,n,s,a,i){return e.openBlock(),e.createElementBlock("div",ht,[e.createElementVNode("label",mt,e.toDisplayString(o.intf.name),1),e.withDirectives(e.createElementVNode("input",{"onUpdate:modelValue":t[0]||(t[0]=l=>o.v=l),type:"text",class:"baklava-input",placeholder:o.intf.name,title:o.intf.name},null,8,ft),[[e.vModelText,o.v]])])}const ye=S(pt,[["render",gt]]);class bt extends ee{component=e.markRaw(ye)}class kt extends ee{component=e.markRaw(f.TextareaInputInterfaceComponent)}class Ct extends L{constructor(t="",n=""){super(t,n),this.setComponent(e.markRaw(f.TextInputInterfaceComponent)),this.use(I.setType,Q)}getValue=()=>`(${this.value})`}function yt(o){return class extends A{type=o.type;inputs={};outputs={};constructor(){super(),this._title=o.title??o.type,this.executeFactory("input",o.inputs),this.executeFactory("output",o.outputs),o.calculate&&(this.calculate=(t,n)=>o.calculate.call(this,{inputs:t,...n})),o.onCreate?.call(this),this.name=o.name??o.type,this.updateModules(o.modules),o.variableName!=null&&(this.state.variableName=o.variableName),o.codeTemplate&&(this.codeTemplate=o.codeTemplate),this.addInput("_code",new x("",[]).use(I.setType,V).use(R.allowMultipleConnections).setHidden(!0)),this.addOutput("_code",new x("",[]).use(I.setType,V).use(R.allowMultipleConnections).setHidden(!0))}onPlaced(){o.onPlaced?.call(this)}onConnected(){o.onConnected?.call(this)}onDestroy(){o.onDestroy?.call(this)}onUnconnected(){o.onUnconnected?.call(this)}update(){o.update?.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 Ne extends A{}function Nt(o){return class extends Ne{type=o.type;inputs={};outputs={};preventUpdate=!1;staticInputKeys=Object.keys(o.inputs??{});staticOutputKeys=Object.keys(o.outputs??{});constructor(){super(),this._title=o.title??o.type,this.executeFactory("input",o.inputs),this.executeFactory("output",o.outputs),o.calculate&&(this.calculate=(t,n)=>o.calculate?.call(this,t,n)),o.onCreate?.call(this),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("_code",new x("",[]).use(I.setType,V).use(R.allowMultipleConnections).setHidden(!0)),this.addOutput("_code",new x("",[]).use(I.setType,V).use(R.allowMultipleConnections).setHidden(!0)),this.staticInputKeys.push("_code"),this.staticOutputKeys.push("_code")}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)}onConnected(){o.onConnected?.call(this)}onDestroy(){o.onDestroy?.call(this)}onUnconnected(){o.onUnconnected?.call(this)}update(){o.update?.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!=="_code"&&(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!=="_code"&&(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 f.IntegerInterface(n,s).use(I.setType,U):a=new f.TextInputInterface(n,JSON.stringify(s)).use(I.setType,F),a.use(f.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 Ce(n);this.addOutput(n,s)}this.outputs[n]&&(this.outputs[n].load(t.outputs[n]),this.outputs[n].nodeId=this.id)}K(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 l of Object.keys(i))a.includes(l)||n[l]&&!s.includes(l)||(t==="input"?this.removeInput(l):this.removeOutput(l));for(const l of Object.keys(n)){if(i[l])continue;const d=n[l]();t==="input"?this.addInput(l,d):this.addOutput(l,d)}}updateProps(t){this.state.props=t,this.onUpdate()}executeFactory(t,n){Object.keys(n||{}).forEach(s=>{const a=n[s]();t==="input"?this.addInput(s,a):this.addOutput(s,a)})}}}const te="__baklava_SubgraphInputNode",ne="__baklava_SubgraphOutputNode";class _e extends A{graphInterfaceId;constructor(){super(),this.graphInterfaceId=j.v4()}onPlaced(){super.onPlaced(),this.initializeIo()}load(t){super.load(t),this.graphInterfaceId=t.graphInterfaceId}save(){return{...super.save(),graphInterfaceId:this.graphInterfaceId}}update(){}}class oe extends _e{static isGraphInputNode(t){return t.type===te}type=te;inputs={name:new O.NodeInterface("Name","Input")};outputs={placeholder:new O.NodeInterface("Value",void 0)}}class se extends _e{static isGraphOutputNode(t){return t.type===ne}type=ne;inputs={name:new O.NodeInterface("Name","Output"),placeholder:new O.NodeInterface("Value",void 0)};outputs={output:new O.NodeInterface("Output",void 0).setHidden(!0)};calculate=({placeholder:t})=>({output:t})}const _t=["component","connectionCount","events","hidden","hooks","id","isCodeNode","isInput","name","nodeId","port","templateId","value"];function Ie(o){return class extends Y{type=O.getGraphNodeTypeString(o);get title(){return this._title}set title(n){this.template.name=n}inputs={};outputs={};template=o;subgraph;update(){}onConnected(){}onUnconnected(){}calculate=async(n,s)=>{if(!this.subgraph)throw new Error(`GraphNode ${this.id}: calculate called without subgraph being initialized`);if(!s.engine||typeof s.engine!="object")throw new Error(`GraphNode ${this.id}: calculate called but no engine provided in context`);const a=s.engine.getInputValues(this.subgraph);for(const d of this.subgraph.inputs)a.set(d.nodeInterfaceId,n[d.id]);const i=await s.engine.runGraph(this.subgraph,a,s.globalValues);s.engine.pause(),R.applyResult(i,s.engine.editor),s.engine.resume();const l={};for(const d of this.subgraph.outputs)l[d.id]=i.get(d.nodeId)?.get("output");return l._calculationResults=i,this.lockCode||(l._code=this.renderCode({inputs:n,...s.globalValues})),this.updateOutputValues(l),l};load(n){if(!this.subgraph)throw new Error("Cannot load a graph node without a graph");if(!this.template)throw new Error("Unable to load graph node without graph template");this.subgraph.load(n.graphState),super.load(n)}save(){if(!this.subgraph)throw new Error("Cannot save a graph node without a graph");return{...super.save(),graphState:this.subgraph.save()}}onPlaced(){this.template.events.updated.subscribe(this,()=>this.initialize()),this.template.events.nameChanged.subscribe(this,n=>{this._title=n}),this.initialize()}onDestroy(){this.template.events.updated.unsubscribe(this),this.template.events.nameChanged.unsubscribe(this),this.subgraph?.destroy()}initialize(){this.subgraph&&this.subgraph.destroy(),this.subgraph=this.template.createGraph(),this._title=this.template.name,this.updateInterfaces(),this.state.codeTemplate=`{{ #nodes }}{{ script }}
2
+ {{ /nodes }}`,this.events.update.emit(null)}renderCode(n){return this.subgraph?this.subgraph.renderCode({nodes:this.subgraph.scriptedCodeNodes}):$.render(this.state.codeTemplate,n)}updateInterfaces(){if(!this.subgraph)throw new Error("Trying to update interfaces without graph instance");for(const n of this.subgraph.inputs)n.id in this.inputs?this.inputs[n.id].name=n.name:this.addInput(n.id,this.createProxyInterface(n,!0));for(const n of Object.keys(this.inputs))this.subgraph.inputs.some(s=>s.id===n)||this.removeInput(n);for(const n of this.subgraph.outputs)n.id in this.outputs?this.outputs[n.id].name=n.name:this.addOutput(n.id,this.createProxyInterface(n,!1));for(const n of Object.keys(this.outputs))this.subgraph.outputs.some(s=>s.id===n)||this.removeOutput(n);this.addInput("_code",new x("",[]).use(I.setType,V).use(R.allowMultipleConnections).setHidden(!0)),this.addOutput("_code",new x("",[]).use(I.setType,V).use(R.allowMultipleConnections).setHidden(!0)),this.addOutput("_calculationResults",new O.NodeInterface("_calculationResults",void 0).setHidden(!0))}createProxyInterface(n,s){const a=new x(n.name,void 0);return new Proxy(a,{get:(i,l)=>{if(_t.includes(l)||l in i||typeof l=="string"&&l.startsWith("__v_"))return Reflect.get(i,l);let d;s?d=this.subgraph?.nodes.find(C=>oe.isGraphInputNode(C)&&C.graphInterfaceId===n.id)?.outputs.placeholder.id:d=this.subgraph?.nodes.find(C=>se.isGraphOutputNode(C)&&C.graphInterfaceId===n.id)?.inputs.placeholder.id;const u=this.subgraph?.connections.find(b=>d===(s?b.from:b.to)?.id),p=s?u?.to:u?.from;if(p)return Reflect.get(p,l)}})}}}$.escape=o=>o;class we{_id;_graph=null;_state;_engine=null;constructor(){this._id=j.v4(),this._state=e.reactive({lockCode:!1,modules:{},script:"",template:""})}get engine(){return this._engine}get graph(){return this._graph}get id(){return this._id}get lockCode(){return this.state.lockCode}set lockCode(t){this.state.lockCode=t,this.engine?.runOnce(null)}get modules(){const t=[];return this.graph?.codeNodes.filter(n=>n.state.modules?.length>0).forEach(n=>t.push(...n.state.modules)),t?(t.sort(),Array.from(new Set(t.map(n=>this.state.modules[n])))):[]}get script(){return this.state.script}set script(t){this.state.script=t,this.engine?.runOnce(null)}get shortId(){return this.id.slice(0,6)}get state(){return this._state}clear(){this.state.script=""}async loadTemplate(t){t.then(n=>{this._state.template=n.default??""})}registerEngine(t){this._engine=t}registerGraph(t){this._graph=t}renderCode(t){this.state.script=$.render(this.state.template||"",t)}}const It=o=>{o.allowMultipleConnections=!0};class Ee extends R.BaseEngine{order=new Map;constructor(t){super(t),t.code.registerEngine(this)}start(){super.start(),this.recalculateOrder=!0,this.calculateWithoutData()}async runGraph(t,n,s){this.order.has(t.id)||this.order.set(t.id,R.sortTopologically(t));const{calculationOrder:a,connectionsFromNode:i}=this.order.get(t.id),l=new Map;for(const d of a){const u={};Object.entries(d.inputs).forEach(([b,C])=>{u[b]=this.getInterfaceValue(n,C.id)}),d.isCodeNode&&(d.updateCodeTemplate(),d.updateOutputNames()),this.events.beforeNodeCalculation.emit({inputValues:u,node:d});let p;if(d.calculate){if(p=await d.calculate(u,{globalValues:s,engine:this}),i.has(d))for(const[b,C]of Object.entries(p))this.hooks.transferData.execute(p[b],C),i.get(d).forEach(h=>{n.set(h.to.id,C)})}else{p={};for(const[b,C]of Object.entries(d.outputs))p[b]=this.getInterfaceValue(n,C.id)}this.events.afterNodeCalculation.emit({outputValues:p,node:d}),l.set(d.id,new Map(Object.entries(p))),i.has(d)&&i.get(d).forEach(b=>{const C=Object.entries(d.outputs).find(([,v])=>v.id===b.from.id)?.[0];if(!C)throw new Error(`Could not find key for interface ${b.from.id}
3
+ This is likely an internal issue. Please report it on GitHub.`);const h=this.hooks.transferData.execute(p[C],b);b.to.allowMultipleConnections?n.has(b.to.id)?n.get(b.to.id).push(h):n.set(b.to.id,[h]):n.set(b.to.id,h)})}return l}async execute(t){this.recalculateOrder&&(this.order.clear(),this.recalculateOrder=!1);const n=this.getInputValues(this.editor.graph);return await this.runGraph(this.editor.graph,n,t)}getInputValues(t){const n=new Map;for(const s of t.nodes)Object.values(s.inputs).forEach(a=>{a.connectionCount===0&&n.set(a.id,a.getValue?a.getValue():a.value)}),s.calculate||Object.values(s.outputs).forEach(a=>{n.set(a.id,a.getValue?a.getValue():a.value)});return n}onChange(t){this.recalculateOrder=t||this.recalculateOrder,this.calculateWithoutData()}getInterfaceValue(t,n){if(!t.has(n))throw new Error(`Could not find value for interface ${n}
4
+ This is likely an internal issue. Please report it on GitHub.`);return t.get(n)}}const wt={},Et={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 vt(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:"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 ve=S(wt,[["render",vt]]),Bt={},Tt={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 Ot(o,t){return e.openBlock(),e.createElementBlock("svg",Tt,[...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 Be=S(Bt,[["render",Ot]]),xt={},St={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 Mt(o,t){return e.openBlock(),e.createElementBlock("svg",St,[...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=S(xt,[["render",Mt]]),Vt={},Gt={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 $t(o,t){return e.openBlock(),e.createElementBlock("svg",Gt,[...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 Oe=S(Vt,[["render",$t]]),Rt={},jt={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"};function Pt(o,t){return e.openBlock(),e.createElementBlock("svg",jt,[...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 xe=S(Rt,[["render",Pt]]),Lt={},Dt={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 zt(o,t){return e.openBlock(),e.createElementBlock("svg",Dt,[...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 Se=S(Lt,[["render",zt]]),At={},Ht={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 Ut(o,t){return e.openBlock(),e.createElementBlock("svg",Ht,[...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 Me=S(At,[["render",Ut]]),Ft={},Wt={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-lock-code"};function qt(o,t){return e.openBlock(),e.createElementBlock("svg",Wt,[...t[0]||(t[0]=[e.createStaticVNode('<path stroke="none" d="M0 0h24v24H0z" fill="none"></path><path d="M11.5 21h-4.5a2 2 0 0 1 -2 -2v-6a2 2 0 0 1 2 -2h10a2 2 0 0 1 2 2"></path><path d="M11 16a1 1 0 1 0 2 0a1 1 0 0 0 -2 0"></path><path d="M8 11v-4a4 4 0 1 1 8 0v4"></path><path d="M20 21l2 -2l-2 -2"></path><path d="M17 17l-2 2l2 2"></path>',6)])])}const Ve=S(Ft,[["render",qt]]),Yt={},Kt={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-player-play"};function Xt(o,t){return e.openBlock(),e.createElementBlock("svg",Kt,[...t[0]||(t[0]=[e.createElementVNode("path",{stroke:"none",d:"M0 0h24v24H0z",fill:"none"},null,-1),e.createElementVNode("path",{d:"M7 4v16l13 -8z"},null,-1)])])}const Ge=S(Yt,[["render",Xt]]),Jt={},Qt={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 Zt(o,t){return e.openBlock(),e.createElementBlock("svg",Qt,[...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 $e=S(Jt,[["render",Zt]]),en={},tn={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 nn(o,t){return e.openBlock(),e.createElementBlock("svg",tn,[...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 Re=S(en,[["render",nn]]),on={},sn={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 an(o,t){return e.openBlock(),e.createElementBlock("svg",sn,[...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 je=S(on,[["render",an]]),rn={},ln={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 dn(o,t){return e.openBlock(),e.createElementBlock("svg",ln,[...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 Pe=S(rn,[["render",dn]]),ae="CLEAR_ALL",ie="RUN_ENGINE",re="TOGGLE_MINIMAP",le="TOGGLE_PALETTE",Le=(o,t,n)=>{const s=n.zoomToFit.paddingLeft;t.registerCommand(le,{execute:()=>{n.palette.enabled=!n.palette.enabled,n.zoomToFit.paddingLeft=n.palette.enabled?s:50},canExecute:()=>!0}),t.registerCommand(ae,{execute:()=>o.value.clear(),canExecute:()=>o.value.nodes.length>0}),t.registerCommand(re,{execute:()=>n.enableMinimap=!n.enableMinimap,canExecute:()=>o.value.nodes.length>1})},De=o=>{const t={command:ie,title:"Run",icon:e.computed(()=>Ge)},n={command:le,title:"Toggle palette",icon:e.computed(()=>o.palette.enabled?Te:Oe)},s={command:ae,title:"Clear all",icon:e.computed(()=>Pe)},a={command:re,title:"Toggle minimap",icon:e.computed(()=>o.enableMinimap?Re:$e)};o.toolbar.commands=[n,t,...f.DEFAULT_TOOLBAR_COMMANDS,s,a]},ze=(o,t)=>{t.registerCommand(ie,{execute:()=>o.runOnce(null),canExecute:()=>!0})};function Ae(o){const t=Symbol("CodeEngineToken");o.engine=new Ee(o.editor),ze(o.engine,o.commandHandler),o.loadEditor=n=>{o.engine?.pause(),o.displayedGraph.clear(),o.editor.load(n),o.commandHandler.executeCommand(f.Commands.CLEAR_CLIPBOARD_COMMAND),o.commandHandler.executeCommand(f.Commands.CLEAR_HISTORY_COMMAND),o.engine?.resume(),o.engine?.runOnce(null)},o.newGraph=()=>{o.engine?.pause(),o.displayedGraph.clear(),o.commandHandler.executeCommand(f.Commands.CLEAR_CLIPBOARD_COMMAND),o.commandHandler.executeCommand(f.Commands.CLEAR_HISTORY_COMMAND),o.displayedGraph.id=j.v4(),o.engine?.resume(),o.engine?.runOnce(null)},o.subscribe=()=>{o.displayedGraph.events.addConnection.subscribe(t,n=>{const s=o.displayedGraph.findNodeById(n.to.nodeId);s&&s.isCodeNode&&s.onConnected();const a=o.displayedGraph.findNodeById(n.from.nodeId);a&&a.isCodeNode&&a.onConnected()}),o.displayedGraph.events.removeConnection.subscribe(t,n=>{const s=o.displayedGraph.findNodeById(n.to.nodeId);s&&s.isCodeNode&&s.onUnconnected();const a=o.displayedGraph.findNodeById(n.from.nodeId);a&&a.isCodeNode&&a.onUnconnected()}),o.engine?.events.beforeRun.subscribe(t,()=>{o.engine?.pause(),o.displayedGraph.sortNodes(),o.engine?.resume()}),o.engine?.events.afterRun.subscribe(t,n=>{o.engine?.pause(),R.applyResult(n,o.editor),o.editor.saveState(),o.code.state.lockCode||o.code.renderCode({nodes:o.editor.graph.scriptedCodeNodes,modules:o.editor.graph.modules}),o.engine?.resume()})},o.unsubscribe=()=>{o.displayedGraph.events.addConnection.unsubscribe(t),o.displayedGraph.events.removeConnection.unsubscribe(t),o.engine?.events.beforeRun.unsubscribe(t),o.engine?.events.afterRun.unsubscribe(t)}}class D extends O.Graph{code=null;editor;_state=e.reactive({codeTemplate:"{{ #nodes }}{{ script }}{{ /nodes }}",lockCode:!1});constructor(t,n){super(t,n),this.editor=t,this.template=n,t.code&&(this.code=t.code)}get codeNodes(){return de(this)}get connections(){return super.connections}set connections(t){this._connections=t}get nodeIds(){return this.nodes.map(t=>t.id)}get nodes(){return super.nodes}set nodes(t){this._nodes=t}get scriptedCodeNodes(){return this.nodes.filter(t=>!t.state?.integrated)}get shortId(){return this.id.slice(0,6)}get state(){return this._state}get visibleNodes(){return this.nodes.filter(t=>!t.state?.hidden)}addNodeAtCoordinates=(t,n={x:0,y:0},s)=>(this.addNode(t,s),t.position&&(t.position=n),t);addConnection(t,n){t?.name!=="_code"&&(t.hidden=!1),n?.name!=="_code"&&(n.hidden=!1),super.addConnection(t,n)}clear(){this.selectedNodes=[],this._nodes=[],this._connections=[]}findNodeByType(t){return this.nodes.find(n=>n.type===t)}getNodesBySameType(t){return this.nodes.filter(n=>n.type===t)}getNodesBySameVariableNames(t){return this.nodes.filter(n=>n.state?.variableName===t)}hasConnection(t,n){return this.connections.some(s=>s.from.id===t.id&&s.to.id===n.id)}renderCode(t){return $.render(this.state?.codeTemplate||"",t)}sortNodes(){if(!(this.nodes.length===0||this.connections.length===0))try{let t=this.nodeIds;const n=this.connections.filter(i=>t.includes(i.to.nodeId)&&t.includes(i.from.nodeId)).map(i=>[i.to.nodeId,i.from.nodeId]);t.reverse(),t=nt.array(t,n),t.reverse();const s=this.nodes.map(i=>i.id).filter(i=>!t.includes(i));t=[...t,...s];const a=t.map(i=>this.findNodeById(i));a&&(this.nodes=a)}catch{console.warn("Failed to sort nodes.")}}}const de=o=>{const t=[];return o.nodes.length===0||o.nodes.forEach(n=>{n&&(n.hasOwnProperty("subgraph")?t.push(...de(n.subgraph)):n.hasOwnProperty("isCodeNode")&&t.push(n))}),t},cn=(o=0,t=100)=>({x:o*420,y:t}),un=o=>{const t={...o.position};return t.x-=440,t.y+=50,t};function pn(o,t){return Object.fromEntries(Object.entries(o).filter(t))}function hn(o,t){return Object.fromEntries(Object.entries(o).map(([n,s])=>[n,t(s)]))}class z extends O.GraphTemplate{static fromGraph(t,n){return new z(t.save(),n)}constructor(t,n){super(t,n)}get shortId(){return this.id.slice(0,6)}createGraph(t){const n=new Map,s=h=>{const v=j.v4();return n.set(h,v),v},a=h=>{const v=n.get(h);if(!v)throw new Error(`Unable to create graph from template: Could not map old id ${h} to new id`);return v},i=h=>hn(h,v=>({id:s(v.id),templateId:v.id,value:v.value})),l=this.nodes.map(h=>({...h,id:s(h.id),inputs:i(h.inputs),outputs:i(h.outputs)})),d=this.connections.map(h=>({id:s(h.id),from:a(h.from),to:a(h.to)})),u=this.inputs.map(h=>({id:h.id,name:h.name,nodeId:a(h.nodeId),nodeInterfaceId:a(h.nodeInterfaceId)})),p=this.outputs.map(h=>({id:h.id,name:h.name,nodeId:a(h.nodeId),nodeInterfaceId:a(h.nodeInterfaceId)})),b={id:j.v4(),nodes:l,connections:d,inputs:u,outputs:p};return t||(t=new D(this.editor)),t.load(b).forEach(h=>console.warn(h)),t.template=this,t}}const mn=o=>!(o instanceof D);function He(o,t){return{switchGraph:s=>{let a;if(mn(s))a=new D(o.value),s.createGraph(a);else{if(s!==o.value.graph)throw new Error("Can only switch using 'Graph' instance when it is the root graph. Otherwise a 'GraphTemplate' must be used.");a=s}t.value&&t.value!==o.value.graph&&t.value.destroy(),a.panning=a.panning??s.panning??{x:0,y:0},a.scaling=a.scaling??s.scaling??1,a.selectedNodes=a.selectedNodes??[],a.sidebar=a.sidebar??{visible:!1,nodeId:"",optionName:""},t.value=a,a.code?.engine?.runOnce(null)}}}const fn=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.subscribe(),n.value.engine?.start()}),e.onBeforeUnmount(()=>{n.value.unsubscribe&&n.value.unsubscribe(),n.value.engine?.stop()}),e.watch(n,(a,i)=>{i&&i.unsubscribe(),a&&a.subscribe()}),(a,i)=>(e.openBlock(),e.createBlock(e.unref(f.BaklavaEditor),{viewModel:n.value},{palette:e.withCtx(()=>[e.createVNode(e.unref(Fe))]),node:e.withCtx(l=>[e.createVNode(e.unref(Ue),e.mergeProps(l,{onUpdate:d=>s(l.node)}),null,16,["onUpdate"])]),sidebar:e.withCtx(l=>[e.createVNode(e.unref(We),e.normalizeProps(e.guardReactiveProps(l)),{codeEditor:e.withCtx(({node:d})=>[e.renderSlot(a.$slots,"sidebarCodeEditor",{node:d})]),_:3},16)]),_:3},8,["viewModel"]))}}),gn={class:"code-graph-info"},bn=e.defineComponent({__name:"CodeGraphInfo",props:{viewModel:{}},setup(o){return(t,n)=>(e.openBlock(),e.createElementBlock("div",gn,[e.createElementVNode("div",null,"Editor graph: "+e.toDisplayString(o.viewModel.editor.graph.shortId),1),e.createElementVNode("div",null,"Displayed graph: "+e.toDisplayString(o.viewModel.displayedGraph.shortId),1),e.createElementVNode("div",null,"Graphs: "+e.toDisplayString(o.viewModel.editor.graphIds),1),e.createElementVNode("div",null,"Graph templates: "+e.toDisplayString(o.viewModel.editor.graphTemplateIds),1),e.createElementVNode("div",null,"Engine status: "+e.toDisplayString(o.viewModel.engine?.status),1)]))}}),kn=["id","data-node-type"],Cn={class:"__title-label",style:{"flex-grow":"1"}},yn={key:0},Nn={class:"__menu",style:{display:"flex"}},_n={class:"__outputs"},In={key:0},wn=["id","title"],En={class:"__inputs"},vn={key:0},Bn=["id","title"],Ue=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=f.Components.ContextMenu,s=f.Components.NodeInterface,a=o,i=e.computed(()=>a.node),l=t,{viewModel:d}=f.useViewModel(),{graph:u,switchGraph:p}=f.useGraph(),b=e.ref(null),C=e.ref(!1),h=e.ref(""),v=e.ref(null),k=e.ref(!1);let _=0,c=0;const m=e.ref(!1),w=e.computed(()=>{const N=[{value:"edit",label:"Edit"},{value:"rename",label:"Rename"},{value:"delete",label:"Delete"}];return a.node.type.startsWith(O.GRAPH_NODE_TYPE_PREFIX)&&N.push({value:"editSubgraph",label:"Edit Subgraph"}),N}),y=e.computed(()=>({"--selected":a.selected,"--dragging":a.dragging,"--two-column":!!a.node.twoColumn,"--hidden":i.value.state?.hidden})),B=e.computed(()=>({"--reverse-y":a.node.reverseY??d.value.settings.nodes.reverseY})),W=e.computed(()=>({top:`${a.node.position?.y??0}px`,left:`${a.node.position?.x??0}px`,"--width":`${a.node.width??d.value.settings.nodes.defaultWidth}px`})),P=e.computed(()=>Object.values(a.node.inputs).filter(N=>!N.hidden)),me=e.computed(()=>Object.values(a.node.outputs).filter(N=>!N.hidden)),q=()=>{l("select")},g=N=>{a.selected||q(),l("start-drag",N)},M=()=>{m.value=!0},G=()=>{const N=d.value.displayedGraph.sidebar;N.nodeId="",N.visible=!1},Xe=()=>{const N=d.value.displayedGraph.sidebar;N.nodeId=a.node.id,N.visible=!0},qn=()=>{const N=d.value.displayedGraph.sidebar;N.nodeId=a.node.id},Yn=async N=>{switch(N){case"edit":Xe();break;case"delete":u.value.removeNode(a.node);break;case"rename":h.value=a.node.title,C.value=!0,await e.nextTick(),v.value?.focus();break;case"editSubgraph":p(a.node.template);break}},Je=()=>{i.value.title=h.value,C.value=!1},Qe=()=>{b.value&&d.value.hooks.renderNode.execute({node:a.node,el:b.value})},Kn=N=>{k.value=!0,_=a.node.width,c=N.clientX,N.preventDefault()},Ze=N=>{i.value.state&&(i.value.state.integrated=N,l("update"))},et=N=>{if(!k.value)return;const T=N.clientX-c,E=_+T/u.value.scaling,Xn=d.value.settings.nodes.minWidth,Jn=d.value.settings.nodes.maxWidth;i.value.width=Math.max(Xn,Math.min(Jn,E))},tt=()=>{k.value=!1};return e.onMounted(()=>{Qe(),window.addEventListener("mousemove",et),window.addEventListener("mouseup",tt)}),e.onUpdated(Qe),e.onBeforeUnmount(()=>{window.removeEventListener("mousemove",et),window.removeEventListener("mouseup",tt)}),(N,T)=>(e.openBlock(),e.createElementBlock("div",{id:i.value.id,ref_key:"el",ref:b,class:e.normalizeClass([y.value,"baklava-node"]),"data-node-type":i.value.type,style:e.normalizeStyle(W.value),onPointerdown:q},[e.unref(d).settings.nodes.resizable?(e.openBlock(),e.createElementBlock("div",{key:0,class:"__resize-handle",onMousedown:Kn},null,32)):e.createCommentVNode("",!0),e.createElementVNode("div",{class:"__title",onPointerdown:e.withModifiers(g,["self","stop"]),onContextmenu:e.withModifiers(M,["prevent"])},[i.value.inputs._code?(e.openBlock(),e.createBlock(e.unref(ce),{key:0,node:i.value,intf:i.value.inputs._code,title:i.value.inputs._code.value,class:"--input","data-interface-type":"node",style:{"flex-grow":"0"}},null,8,["node","intf","title"])):e.createCommentVNode("",!0),C.value?e.withDirectives((e.openBlock(),e.createElementBlock("input",{key:2,ref_key:"renameInputEl",ref:v,"onUpdate:modelValue":T[4]||(T[4]=E=>h.value=E),class:"baklava-input",placeholder:"Node Name",style:{"flex-grow":"1"},type:"text",onBlur:Je,onKeydown:e.withKeys(Je,["enter"])},null,544)),[[e.vModelText,h.value]]):(e.openBlock(),e.createElementBlock(e.Fragment,{key:1},[e.createElementVNode("div",Cn,[i.value.idx>-1?(e.openBlock(),e.createElementBlock("span",yn,e.toDisplayString(i.value.idx+1)+" - ",1)):e.createCommentVNode("",!0),e.createTextVNode(e.toDisplayString(i.value.title)+" "+e.toDisplayString(i.value.graph.shortId)+" "+e.toDisplayString(i.value.shortId),1)]),e.createElementVNode("div",Nn,[i.value.isCodeNode?(e.openBlock(),e.createElementBlock(e.Fragment,{key:0},[i.value.state.lockCode?(e.openBlock(),e.createBlock(e.unref(Ve),{key:0,class:"--clickable mx-1",onClick:T[0]||(T[0]=E=>i.value.lockCode=!1)})):e.createCommentVNode("",!0),i.value.state.integrated?(e.openBlock(),e.createBlock(e.unref(ve),{key:1,class:"--clickable mx-1",onClick:T[1]||(T[1]=E=>Ze(!1))})):(e.openBlock(),e.createBlock(e.unref(je),{key:2,class:"--clickable mx-1",onClick:T[2]||(T[2]=E=>Ze(!0))})),!e.unref(d).displayedGraph.sidebar.visible&&e.unref(d).displayedGraph.sidebar.nodeId!==i.value.id?(e.openBlock(),e.createBlock(e.unref(Me),{key:3,class:"--clickable mx-1",onClick:Xe})):e.unref(d).displayedGraph.sidebar.visible&&e.unref(d).displayedGraph.sidebar.nodeId!==i.value.id?(e.openBlock(),e.createBlock(e.unref(xe),{key:4,class:"--clickable mx-1",onClick:qn})):(e.openBlock(),e.createBlock(e.unref(Se),{key:5,class:"--clickable mx-1",onClick:G}))],64)):e.createCommentVNode("",!0),e.createVNode(e.unref(Be),{class:"--clickable mx-1",onClick:M}),e.createVNode(e.unref(n),{modelValue:m.value,"onUpdate:modelValue":T[3]||(T[3]=E=>m.value=E),x:0,y:0,items:w.value,onClick:Yn},null,8,["modelValue","items"])])],64)),i.value.outputs._code?(e.openBlock(),e.createBlock(e.unref(ce),{key:3,node:i.value,intf:i.value.outputs._code,class:"--output",title:i.value.outputs._code.value,"data-interface-type":"node"},null,8,["node","intf","title"])):e.createCommentVNode("",!0)],32),e.createElementVNode("div",{class:e.normalizeClass(["__content",B.value]),onKeydown:T[5]||(T[5]=e.withKeys(e.withModifiers(()=>{},["stop"]),["delete"])),onContextmenu:T[6]||(T[6]=e.withModifiers(()=>{},["prevent"]))},[e.createElementVNode("div",_n,[(e.openBlock(!0),e.createElementBlock(e.Fragment,null,e.renderList(me.value,E=>(e.openBlock(),e.createElementBlock(e.Fragment,{key:E.id},[i.value.state?.hidden?(e.openBlock(),e.createElementBlock("div",In,[E.port?(e.openBlock(),e.createElementBlock("div",{key:0,id:E.id,title:E.name,class:"baklava-node-interface --output --connected"},[...T[7]||(T[7]=[e.createElementVNode("div",{class:"__port"},null,-1)])],8,wn)):e.createCommentVNode("",!0)])):e.renderSlot(N.$slots,"nodeInterface",{key:1,type:"output",node:i.value,intf:E},()=>[e.createVNode(e.unref(s),{node:i.value,intf:E,title:E.value},null,8,["node","intf","title"])])],64))),128))]),e.createElementVNode("div",En,[(e.openBlock(!0),e.createElementBlock(e.Fragment,null,e.renderList(P.value,E=>(e.openBlock(),e.createElementBlock(e.Fragment,{key:E.id},[i.value.state?.hidden?(e.openBlock(),e.createElementBlock("div",vn,[E.port?(e.openBlock(),e.createElementBlock("div",{key:0,id:E.id,title:E.name,class:"baklava-node-interface --input --connected"},[...T[8]||(T[8]=[e.createElementVNode("div",{class:"__port"},null,-1)])],8,Bn)):e.createCommentVNode("",!0)])):e.renderSlot(N.$slots,"nodeInterface",{key:1,node:i.value,intf:E,type:"input"},()=>[e.createVNode(e.unref(s),{node:i.value,intf:E,title:E.value},null,8,["node","intf","title"])])],64))),128))])],34)],46,kn))}}),Tn=["id"],On={class:"align-middle"},ce=e.defineComponent({__name:"CodeGraphNodeInterface",props:{node:{},intf:{}},setup(o){const t=o,{viewModel:n}=f.useViewModel(),{hoveredOver:s,temporaryConnection:a}=f.useTemporaryConnection(),i=e.ref(null),l=e.computed(()=>t.intf.connectionCount>0),d=e.computed(()=>({"--connected":l.value})),u=()=>{s(t.intf)},p=()=>{s(void 0)},b=()=>{i.value&&n.value.hooks.renderInterface.execute({intf:t.intf,el:i.value})};return e.onMounted(b),e.onUpdated(b),(C,h)=>(e.openBlock(),e.createElementBlock("div",{id:o.intf.id,ref_key:"el",ref:i,class:e.normalizeClass(["baklava-node-interface",d.value])},[o.intf.port?(e.openBlock(),e.createElementBlock("div",{key:0,class:e.normalizeClass(["__port",{"--selected":e.unref(a)?.from===o.intf}]),onPointerover:u,onPointerout:p},null,34)):e.createCommentVNode("",!0),e.createElementVNode("span",On,[e.renderSlot(C.$slots,"default")])],10,Tn))}}),xn={class:"baklava-node --palette",style:{"margin-top":"-20px","margin-bottom":"20px"}},Sn={key:0,style:{display:"flex","justify-content":"space-between"}},Mn=["onClick"],Vn={key:0,style:{margin:"auto 0","font-size":"12px"}},Fe=e.defineComponent({__name:"CodeNodePalette",setup(o){const t=f.Components.PaletteEntry,{viewModel:n}=f.useViewModel(),{x:s,y:a}=ot.usePointer(),{transform:i}=f.useTransform(),l=f.useNodeCategories(n),d=e.inject("editorEl"),u=e.ref(""),p=e.ref(null),b=()=>u.value?l.value.filter(k=>k.name.toLowerCase().includes(u.value.toLowerCase())||Object.values(k.nodeTypes).some(_=>_.title.toLowerCase().includes(u.value.toLowerCase()))):l.value,C=k=>u.value?pn(k,_=>{const c=_[1];return c.category.includes(u.value.toLowerCase())||c.title?.toLowerCase().includes(u.value.toLowerCase())}):k,h=e.computed(()=>{if(!p.value||!d?.value)return{};const{left:k,top:_}=d.value.getBoundingClientRect();return{top:`${a.value-_}px`,left:`${s.value-k}px`}}),v=(k,_)=>{p.value={type:k,nodeInformation:_};const c=()=>{const m=e.reactive(new _.type);n.value.displayedGraph.addNode(m);const w=d.value.getBoundingClientRect(),[y,B]=i(s.value-w.left,a.value-w.top);m.position.x=y,m.position.y=B,p.value=null,document.removeEventListener("pointerup",c)};document.addEventListener("pointerup",c)};return(k,_)=>(e.openBlock(),e.createElementBlock(e.Fragment,null,[e.createElementVNode("div",{class:e.normalizeClass([{"--open":e.unref(n).settings.palette.enabled},"baklava-node-palette"]),onContextmenu:_[1]||(_[1]=e.withModifiers(()=>{},["stop","prevent"]))},[e.createElementVNode("div",xn,[e.withDirectives(e.createElementVNode("input",{"onUpdate:modelValue":_[0]||(_[0]=c=>u.value=c),type:"text",class:"baklava-input",title:"Filter nodes",onKeyup:b},null,544),[[e.vModelText,u.value]])]),(e.openBlock(!0),e.createElementBlock(e.Fragment,null,e.renderList(b(),c=>(e.openBlock(),e.createElementBlock("section",{key:c.name},[c.name!=="default"?(e.openBlock(),e.createElementBlock("h3",Sn,[e.createElementVNode("div",{onClick:m=>u.value=c.name,style:{cursor:"pointer"}},e.toDisplayString(c.name),9,Mn),Object.keys(C(c.nodeTypes)).length<Object.values(c.nodeTypes).length?(e.openBlock(),e.createElementBlock("div",Vn," ( "+e.toDisplayString(Object.keys(C(c.nodeTypes)).length)+" / "+e.toDisplayString(Object.values(c.nodeTypes).length)+" ) ",1)):e.createCommentVNode("",!0)])):e.createCommentVNode("",!0),(e.openBlock(!0),e.createElementBlock(e.Fragment,null,e.renderList(C(c.nodeTypes),(m,w)=>(e.openBlock(),e.createBlock(e.unref(t),{key:w,type:w,title:m.title,onPointerdown:y=>v(w,m)},null,8,["type","title","onPointerdown"]))),128))]))),128))],34),e.createVNode(e.Transition,{name:"fade"},{default:e.withCtx(()=>[p.value?(e.openBlock(),e.createElementBlock("div",{key:0,class:"baklava-dragged-node",style:e.normalizeStyle(h.value)},[e.createVNode(e.unref(t),{type:p.value.type,title:p.value.nodeInformation.title},null,8,["type","title"])],4)):e.createCommentVNode("",!0)]),_:1})],64))}}),Gn=["title"],$n={key:0,class:"__label"},ue=e.defineComponent({__name:"SidebarCheckbox",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",$n,e.toDisplayString(o.name),1)):e.createCommentVNode("",!0)],10,Gn))}}),Rn={class:"__header"},jn={class:"__node-name"},Pn={class:"__interfaces"},Ln={class:"__inputs"},Dn={style:{display:"flex"}},zn={class:"__outputs"},An={key:0,class:"__interface"},Hn={style:{display:"flex"}},We=e.defineComponent({__name:"CodeGraphSidebar",setup(o){const{viewModel:t}=f.useViewModel(),{graph:n}=f.useGraph(),s=e.ref(null),a=e.toRef(t.value.settings.sidebar,"width"),i=e.computed(()=>t.value.settings.sidebar.resizable);let l=0,d=0;const u=e.computed(()=>{const m=n.value.sidebar.nodeId;return n.value.nodes.find(w=>w.id===m)}),p=e.computed(()=>u.value),b=e.computed(()=>({width:`${a.value}px`})),C=e.computed(()=>p.value?Object.values(p.value.inputs).filter(m=>m.displayInSidebar&&m.component):[]),h=e.computed(()=>p.value?Object.values(p.value.outputs).filter(m=>m.displayInSidebar&&m.component):[]),v=()=>{n.value.sidebar.visible=!1},k=()=>{u.value?.events.update.emit(null)},_=m=>{l=a.value,d=m.clientX,window.addEventListener("mousemove",c),window.addEventListener("mouseup",()=>{window.removeEventListener("mousemove",c)},{once:!0})},c=m=>{const w=s.value?.parentElement?.getBoundingClientRect().width??500,y=m.clientX-d;let B=l-y;B<300?B=300:B>.9*w&&(B=.9*w),a.value=B};return(m,w)=>(e.openBlock(),e.createElementBlock("div",{class:e.normalizeClass([{"--open":e.unref(n).sidebar.visible},"baklava-sidebar"]),style:e.normalizeStyle(b.value),ref_key:"el",ref:s},[i.value?(e.openBlock(),e.createElementBlock("div",{key:0,class:"__resizer",onMousedown:_},null,32)):e.createCommentVNode("",!0),u.value?(e.openBlock(),e.createElementBlock(e.Fragment,{key:1},[e.createElementVNode("div",Rn,[e.createElementVNode("button",{tabindex:"-1",class:"__close",onClick:v},"×"),e.createElementVNode("div",jn,[e.createElementVNode("b",null,e.toDisplayString(u.value.title),1)])]),e.createElementVNode("div",Pn,[e.createElementVNode("div",Ln,[(e.openBlock(!0),e.createElementBlock(e.Fragment,null,e.renderList(C.value,y=>(e.openBlock(),e.createElementBlock("div",{key:y.id,class:"__interface"},[e.createElementVNode("div",Dn,[e.createVNode(ue,{modelValue:y.hidden,"onUpdate:modelValue":[B=>y.hidden=B,w[0]||(w[0]=()=>u.value?.events.update.emit(null))],disabled:!y.optional,inversed:"",style:{"padding-right":"8px"}},null,8,["modelValue","onUpdate:modelValue","disabled"]),(e.openBlock(),e.createBlock(e.resolveDynamicComponent(y.component),{modelValue:y.value,"onUpdate:modelValue":B=>y.value=B,node:u.value,intf:y,style:{width:"100%"}},null,8,["modelValue","onUpdate:modelValue","node","intf"]))])]))),128))]),e.createElementVNode("div",zn,[p.value&&p.value.state?(e.openBlock(),e.createElementBlock("div",An,[w[3]||(w[3]=e.createElementVNode("label",null,"Variable name",-1)),e.withDirectives(e.createElementVNode("input",{"onUpdate:modelValue":w[1]||(w[1]=y=>p.value.state.variableName=y),type:"text",class:"baklava-input",title:"Variable name",onBlur:k,onKeydown:e.withKeys(k,["enter"])},null,544),[[e.vModelText,p.value.state.variableName]])])):e.createCommentVNode("",!0),(e.openBlock(!0),e.createElementBlock(e.Fragment,null,e.renderList(h.value,y=>(e.openBlock(),e.createElementBlock("div",{key:y.id,class:"__interface"},[e.createElementVNode("div",Hn,[e.createVNode(ue,{modelValue:y.hidden,"onUpdate:modelValue":[B=>y.hidden=B,w[2]||(w[2]=()=>u.value?.events.update.emit(null))],disabled:!y.optional,inversed:"",style:{"padding-right":"8px"}},null,8,["modelValue","onUpdate:modelValue","disabled"]),(e.openBlock(),e.createBlock(e.resolveDynamicComponent(y.component),{modelValue:y.value,"onUpdate:modelValue":B=>y.value=B,node:u.value,intf:y,style:{width:"100%"}},null,8,["modelValue","onUpdate:modelValue","node","intf"]))])]))),128))])]),e.renderSlot(m.$slots,"codeEditor",{node:u.value})],64)):e.createCommentVNode("",!0)],6))}});class pe extends oe{_title="Subgraph Input";inputs={_code:new x("","").use(I.setType,V).setHidden(!0),name:new f.TextInputInterface("Name","Input").setPort(!1)};outputs={_code:new x("","").use(I.setType,V).setHidden(!0),placeholder:new O.NodeInterface("Connection",void 0)}}class he extends se{_title="Subgraph Output";inputs={_code:new x("","").use(I.setType,V).setHidden(!0),name:new f.TextInputInterface("Name","Output").setPort(!1),placeholder:new O.NodeInterface("Connection",void 0)};outputs={_code:new x("","").use(I.setType,V).setHidden(!0),output:new O.NodeInterface("Output",void 0).setHidden(!0)}}const qe="CREATE_SUBGRAPH",Ye=[O.GRAPH_INPUT_NODE_TYPE,O.GRAPH_OUTPUT_NODE_TYPE];function Ke(o,t,n){const s=()=>o.value.selectedNodes.filter(i=>!Ye.includes(i.type)).length>0,a=()=>{const{viewModel:i}=f.useViewModel(),l=o.value,d=o.value.editor;if(l.selectedNodes.length===0)return;const u=l.selectedNodes.filter(g=>!Ye.includes(g.type)),p=u.flatMap(g=>Object.values(g.inputs)),b=u.flatMap(g=>Object.values(g.outputs)),C=l.connections.filter(g=>!b.includes(g.from)&&p.includes(g.to)),h=l.connections.filter(g=>b.includes(g.from)&&!p.includes(g.to)),v=l.connections.filter(g=>b.includes(g.from)&&p.includes(g.to)),k=u.map(g=>g.save()),_=v.map(g=>({id:g.id,from:g.from.id,to:g.to.id})),c=new Map,{xLeft:m,xRight:w,yTop:y}=Un(u);for(const[g,M]of C.entries()){const G=new pe;G.inputs.name.value=M.to.name,k.push({...G.save(),position:{x:w-i.value.settings.nodes.defaultWidth-100,y:y+g*200}}),_.push({id:j.v4(),from:G.outputs.placeholder.id,to:M.to.id}),c.set(M.to.id,G.graphInterfaceId)}for(const[g,M]of h.entries()){const G=new he;G.inputs.name.value=M.from.name,k.push({...G.save(),position:{x:m+100,y:y+g*200}}),_.push({id:j.v4(),from:M.from.id,to:G.inputs.placeholder.id}),c.set(M.from.id,G.graphInterfaceId)}const B=e.reactive(new z({connections:_,nodes:k,inputs:[],outputs:[]},d));d.addGraphTemplate(B);const W=d.nodeTypes.get(O.getGraphNodeTypeString(B));if(!W)throw new Error("Unable to create subgraph: Could not find corresponding graph node type");l.activeTransactions++;const P=e.reactive(new W.type);l.addNode(P);const me=Math.round(u.map(g=>g.position.x).reduce((g,M)=>g+M,0)/u.length),q=Math.round(u.map(g=>g.position.y).reduce((g,M)=>g+M,0)/u.length);P.position.x=me,P.position.y=q,C.forEach(g=>{l.removeConnection(g),l.addConnection(g.from,P.inputs[c.get(g.to.id)])}),h.forEach(g=>{l.removeConnection(g),l.addConnection(P.outputs[c.get(g.from.id)],g.to)}),u.forEach(g=>l.removeNode(g)),l.activeTransactions--,t.canExecuteCommand(f.Commands.SAVE_SUBGRAPH_COMMAND)&&t.executeCommand(f.Commands.SAVE_SUBGRAPH_COMMAND),n(B),o.value.panning={...l.panning},o.value.scaling=l.scaling};t.registerCommand(qe,{canExecute:s,execute:a})}function Un(o){const t=o.reduce((a,i)=>{const l=i.position.x;return l<a?l:a},1/0),n=o.reduce((a,i)=>{const l=i.position.y;return l<a?l:a},1/0);return{xLeft:o.reduce((a,i)=>{const l=i.position.x+i.width;return l>a?l:a},-1/0),xRight:t,yTop:n}}class Fn extends O.Editor{code;graph;state;constructor(t){super(),this.code=t,this.graph=new D(this),this.code.registerGraph(this.graph),this.saveState()}get graphIds(){const t=[];return this.graphs.forEach(n=>t.push(n.id)),t.map(n=>n.slice(0,6)).join(", ")}get graphTemplateIds(){const t=[];return this.graphTemplates.forEach(n=>t.push(n.id)),t.map(n=>n.slice(0,6)).join(", ")}addGraphTemplate(t){if(this.events.beforeAddGraphTemplate.emit(t).prevented)return;this._graphTemplates.push(t),this.graphTemplateEvents.addTarget(t.events),this.graphTemplateHooks.addTarget(t.hooks);const n=Ie(t);this.registerNodeType(n,{category:"Subgraphs",title:t.name}),this.events.addGraphTemplate.emit(t)}load(t){try{for(super._loading=!0,t=this.hooks.load.execute(t);this.graphTemplates.length>0;)this.removeGraphTemplate(this.graphTemplates[0]);t.graphTemplates.forEach(s=>{const a=new z(s,this);this.addGraphTemplate(a)});const n=this.graph.load(t.graph);return this.events.loaded.emit(),n.forEach(s=>console.warn(s)),n}finally{super._loading=!1}}registerCategoryModule(t,n){this.code.state.modules[t]=n}saveState(){this.state=this.save()}}function Wn(o){const t=e.ref(o?.code??new we),n=e.ref(o?.existingEditor??new Fn(t.value)),s=Symbol("ViewModelToken"),a=e.ref(null),i=e.shallowReadonly(a),{switchGraph:l}=He(n,a),d=e.computed(()=>i.value&&i.value!==n.value.graph),u=e.reactive(f.DEFAULT_SETTINGS());u.nodes.defaultWidth=400;const p=f.useCommandHandler(),b=f.useHistory(i,p),C=f.useClipboard(i,n,p),h={renderNode:new fe.SequentialHook(null),renderInterface:new fe.SequentialHook(null)},v=e.reactive({clipboard:C,code:t,commandHandler:p,displayedGraph:i,editor:n,history:b,hooks:h,isSubgraph:d,settings:u,switchGraph:l});return Ae(v),f.registerDeleteNodesCommand(i,p),Ke(i,p,l),f.registerSaveSubgraphCommand(i,p),f.registerSwitchToMainGraphCommand(i,p,l),f.registerSidebarCommands(i,p),f.registerZoomToFitCommands(i,p,u),Le(i,p,u),De(u),e.watch(n,(k,_)=>{_&&(_.events.registerGraph.unsubscribe(s),_.graphEvents.beforeAddNode.unsubscribe(s),k.nodeHooks.beforeLoad.unsubscribe(s),k.nodeHooks.afterSave.unsubscribe(s),k.graphTemplateHooks.beforeLoad.unsubscribe(s),k.graphTemplateHooks.afterSave.unsubscribe(s),k.graph.hooks.load.unsubscribe(s),k.graph.hooks.save.unsubscribe(s)),k&&(k.nodeHooks.beforeLoad.subscribe(s,(c,m)=>(m.position=c.position??{x:0,y:0},m.width=c.width??u.nodes.defaultWidth,m.twoColumn=c.twoColumn??!1,c)),k.nodeHooks.afterSave.subscribe(s,(c,m)=>(c.position=m.position,c.width=m.width,c.twoColumn=m.twoColumn,c)),k.graphTemplateHooks.beforeLoad.subscribe(s,(c,m)=>(m.panning=c.panning,m.scaling=c.scaling,c)),k.graphTemplateHooks.afterSave.subscribe(s,(c,m)=>(c.panning=m.panning,c.scaling=m.scaling,c)),k.graph.hooks.load.subscribe(s,(c,m)=>(m.panning=c.panning,m.scaling=c.scaling,c)),k.graph.hooks.save.subscribe(s,(c,m)=>(c.panning=m.panning,c.scaling=m.scaling,c)),k.graphEvents.beforeAddNode.subscribe(s,c=>f.setViewNodeProperties(c,{defaultWidth:u.nodes.defaultWidth})),n.value.registerNodeType(pe,{category:"Subgraphs"}),n.value.registerNodeType(he,{category:"Subgraphs"}),l(k.graph))},{immediate:!0}),v}r.AbstractCodeNode=Y,r.CLEAR_ALL_COMMAND=ae,r.CREATE_SUBGRAPH_COMMAND=qe,r.CheckboxInterface=it,r.Code=we,r.CodeEngine=Ee,r.CodeGraph=D,r.CodeGraphEditor=fn,r.CodeGraphInfo=bn,r.CodeGraphInputNode=oe,r.CodeGraphNode=Ue,r.CodeGraphNodeInterface=ce,r.CodeGraphOutputNode=se,r.CodeGraphSidebar=We,r.CodeGraphTemplate=z,r.CodeNode=A,r.CodeNodeInputInterface=L,r.CodeNodeInterface=x,r.CodeNodeInterfaceComponent=H,r.CodeNodeOutputInterface=Ce,r.CodeNodePalette=Fe,r.CodeVariable=ve,r.DotsVertical=Be,r.DynamicCodeNode=Ne,r.GRAPH_INPUT_NODE_TYPE=te,r.GRAPH_OUTPUT_NODE_TYPE=ne,r.IntegerInterface=rt,r.LayoutSidebarLeftCollapse=Te,r.LayoutSidebarLeftExpand=Oe,r.LayoutSidebarRight=xe,r.LayoutSidebarRightCollapse=Se,r.LayoutSidebarRightExpand=Me,r.ListInputInterface=lt,r.LockCode=Ve,r.NumberInterface=dt,r.PlayerPlay=Ge,r.RUN_ENGINE_COMMAND=ie,r.Schema=$e,r.SchemaOff=Re,r.SelectInterface=ct,r.SidebarCheckbox=ue,r.SliderInterface=ut,r.SubgraphInputNode=pe,r.SubgraphOutputNode=he,r.TOGGLE_MINIMAP_COMMAND=re,r.TOGGLE_PALETTE_COMMAND=le,r.TextInputInterface=bt,r.TextInputInterfaceComponent=ye,r.TextareaInputInterface=kt,r.TransitionBottom=je,r.TrashOff=Pe,r.TupleInputInterface=Ct,r.addDefaultInterfaceTypes=at,r.allowMultipleConnections=It,r.booleanType=X,r.createCodeGraphNodeType=Ie,r.defineCodeNode=yt,r.defineDynamicCodeNode=Nt,r.dictType=ke,r.formatInputs=ge,r.getCodeNodes=de,r.getPositionAtColumn=cn,r.getPositionBeforeNode=un,r.listType=J,r.loadNodeState=K,r.nodeType=V,r.numberType=U,r.registerCodeEngine=Ae,r.registerCreateSubgraphCommand=Ke,r.registerCustomCommands=Le,r.registerRunEngineCommands=ze,r.saveNodeState=be,r.stringType=F,r.tupleType=Q,r.updateToolbarItems=De,r.useCodeGraph=Wn,r.useSwitchCodeGraph=He,Object.defineProperty(r,Symbol.toStringTag,{value:"Module"})}));
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@babsey/code-graph",
3
- "version": "0.2.3",
3
+ "version": "0.3.0",
4
4
  "author": "babsey <spreizer@web.de>",
5
5
  "license": "MIT",
6
6
  "type": "module",
@@ -29,7 +29,7 @@
29
29
  "type-check": "vue-tsc --build",
30
30
  "clean": "rimraf dist",
31
31
  "lint": "eslint . --fix",
32
- "format": "prettier --write lib/ src/"
32
+ "format": "prettier --write examples/**/src/ lib/ src/"
33
33
  },
34
34
  "dependencies": {
35
35
  "@codemirror/lang-python": "~6.2",
@@ -38,6 +38,7 @@
38
38
  "baklavajs": "~2.8",
39
39
  "codemirror": "~6.0",
40
40
  "mustache": "~4.2",
41
+ "splitpanes": "~4.0",
41
42
  "toposort": "~2.0",
42
43
  "uuid": "~13.0",
43
44
  "vue": "~3.5",
@@ -47,23 +48,22 @@
47
48
  "devDependencies": {
48
49
  "@tsconfig/node-lts": "~22.0",
49
50
  "@types/mustache": "~4.2",
50
- "@types/node": "~24.9",
51
+ "@types/node": "~24.10",
51
52
  "@types/toposort": "~2.0",
52
53
  "@vitejs/plugin-vue": "~6.0",
53
54
  "@vue/eslint-config-prettier": "~10.2",
54
55
  "@vue/eslint-config-typescript": "~14.6",
55
56
  "@vue/language-core": "~3.1",
56
57
  "@vue/tsconfig": "~0.8",
57
- "eslint": "~9.38",
58
+ "eslint": "~9.39",
58
59
  "eslint-plugin-vue": "~10.5",
59
60
  "jiti": "~2.6",
60
61
  "npm-run-all2": "~8.0",
61
62
  "prettier": "~3.6",
62
- "rimraf": "~6.0",
63
+ "rimraf": "~6.1",
63
64
  "sass-embedded": "~1.93",
64
65
  "typescript": "~5.9",
65
- "unplugin-dts": "~1.0.0-beta.6",
66
- "vite": "~7.1",
66
+ "vite": "~7.2",
67
67
  "vite-plugin-vue-devtools": "~8.0",
68
68
  "vue-tsc": "~3.1"
69
69
  }
package/dist/code.d.ts DELETED
@@ -1,158 +0,0 @@
1
- import { Connection, Graph, NodeInterface } from 'baklavajs';
2
- import { UnwrapRef } from 'vue';
3
- import { AbstractCodeNode } from './codeNode';
4
- import { CodeNodeInterface } from './codeNodeInterfaces';
5
- import { ICodeGraphViewModel } from './viewModel';
6
- interface IPosition {
7
- x: number;
8
- y: number;
9
- }
10
- export interface ICodeState {
11
- autosort: boolean;
12
- lockCode: boolean;
13
- modules: Record<string, string>;
14
- script: string;
15
- template: string;
16
- token: symbol | null;
17
- }
18
- export declare class Code {
19
- private _id;
20
- private _viewModel;
21
- private _state;
22
- constructor(viewModel: ICodeGraphViewModel);
23
- get codeNodes(): AbstractCodeNode[];
24
- get codeNodeIds(): string[];
25
- get connections(): Connection[];
26
- set connections(values: Connection[]);
27
- get graph(): Graph;
28
- get id(): string;
29
- get lockCode(): boolean;
30
- set lockCode(value: boolean);
31
- get modules(): string[];
32
- get nodeIds(): string[];
33
- get nodes(): AbstractCodeNode[];
34
- set nodes(values: AbstractCodeNode[]);
35
- get script(): string;
36
- set script(value: string);
37
- get scriptedCodeNodes(): AbstractCodeNode[];
38
- get shortId(): string;
39
- get state(): UnwrapRef<ICodeState>;
40
- get viewModel(): ICodeGraphViewModel;
41
- get visibleNodes(): AbstractCodeNode[];
42
- /**
43
- * Add code node to graph.
44
- * @param node code node
45
- * @param props optional
46
- */
47
- addNode(node: AbstractCodeNode, props?: unknown): AbstractCodeNode | undefined;
48
- /**
49
- * Add code node at coordinates.
50
- * @param node code node
51
- * @param position position
52
- * @param props optional
53
- * @returns code node
54
- */
55
- addNodeAtCoordinates: (node: AbstractCodeNode, position?: IPosition, props?: unknown) => AbstractCodeNode;
56
- /**
57
- * Add connection of code nodes
58
- * @param from code node interface
59
- * @param to code node interface
60
- */
61
- addConnection(from: CodeNodeInterface | NodeInterface, to: CodeNodeInterface | NodeInterface): void;
62
- /**
63
- * Clear code graph.
64
- */
65
- clear(): void;
66
- /**
67
- * Find node by ID.
68
- * @param id node ID
69
- * @returns node instance
70
- */
71
- findNodeById(id: string): AbstractCodeNode | undefined;
72
- /**
73
- * Find node by type.
74
- * @param nodeType node type
75
- * @returns node instance
76
- */
77
- findNodeByType(nodeType: string): AbstractCodeNode | undefined;
78
- /**
79
- * Get nodes of the same type.
80
- * @param type node type
81
- * @returns a list of node instances
82
- */
83
- getNodesBySameType(type: string): AbstractCodeNode[];
84
- /**
85
- * Get nodes of the same variable name.
86
- * @param variableName variable name
87
- * @returns a list of node instances
88
- */
89
- getNodesBySameVariableNames(variableName: string): AbstractCodeNode[];
90
- /**
91
- * Check whether the graph has this connection.
92
- * @param from node interface
93
- * @param to node interface
94
- * @returns boolean
95
- */
96
- hasConnection(from: NodeInterface, to: NodeInterface): boolean;
97
- /**
98
- * Load template from the file.
99
- * @param resolve: default string in promise resolve (from import)
100
- */
101
- loadTemplate(resolve: Promise<{
102
- default: string;
103
- }>): Promise<void>;
104
- /**
105
- * Remove connection from the graph
106
- * @param connection connection between code nodes
107
- */
108
- removeConnection(connection: Connection): void;
109
- /**
110
- * Remove node from the graph.
111
- * @param codeNode code node
112
- */
113
- removeNode(codeNode: AbstractCodeNode): void;
114
- /**
115
- * Render code script of code nodes.
116
- */
117
- renderNodeCodes(): void;
118
- /**
119
- * Render code script.
120
- */
121
- renderCode(): void;
122
- /**
123
- * Reset scripts of intput interfaces.
124
- */
125
- resetInputInterfaceScript(): void;
126
- /**
127
- * Sort code nodes.
128
- */
129
- sortNodes(): void;
130
- /**
131
- * Update code nodes.
132
- */
133
- updateCodeNodes(): void;
134
- /**
135
- * Update code templates.
136
- */
137
- updateCodeTemplates(): void;
138
- }
139
- /**
140
- * Get code nodes of current graph.
141
- * @param graph graph / subgraph
142
- * @returns list of code nodes
143
- */
144
- export declare const getCodeNodes: (graph: Graph) => AbstractCodeNode[];
145
- /**
146
- * Get position at specific column.
147
- * @param col column
148
- * @param offset number
149
- * @returns position
150
- */
151
- export declare const getPositionAtColumn: (col?: number, offset?: number) => IPosition;
152
- /**
153
- * Get position before target node.
154
- * @param node code node
155
- * @returns position
156
- */
157
- export declare const getPositionBeforeNode: (node: AbstractCodeNode) => IPosition;
158
- export {};
@@ -1,11 +0,0 @@
1
- import { Graph, GraphTemplate, IGraphNode, IGraphState, INodeState } from 'baklavajs';
2
- import { AbstractCodeNode } from '../main';
3
- export interface IGraphCodeNodeState extends INodeState<unknown, unknown> {
4
- graphState: IGraphState;
5
- }
6
- export interface IGraphCodeNode extends IGraphNode {
7
- template: GraphTemplate;
8
- subgraph: Graph | undefined;
9
- }
10
- export declare const GRAPH_NODE_TYPE_PREFIX = "__baklava_GraphNode-";
11
- export declare function createCodeGraphNodeType(template: GraphTemplate): new () => AbstractCodeNode & IGraphNode;
@@ -1,111 +0,0 @@
1
- import { AbstractNode, Graph, NodeInterface, CalculateFunction, INodeState, NodeInterfaceDefinition } from 'baklavajs';
2
- import { UnwrapRef } from 'vue';
3
- import { Code } from '../code';
4
- import { CodeNodeInputInterface, CodeNodeOutputInterface } from '../codeNodeInterfaces';
5
- export interface IAbstractCodeNodeState {
6
- codeTemplate: string;
7
- hidden: boolean;
8
- integrated: boolean;
9
- lockCode: boolean;
10
- modules: string[];
11
- props?: unknown | null;
12
- script: string;
13
- variableName: string;
14
- }
15
- export declare abstract class AbstractCodeNode extends AbstractNode {
16
- state: UnwrapRef<IAbstractCodeNodeState>;
17
- code: Code | undefined;
18
- isCodeNode: boolean;
19
- name: string;
20
- codeTemplate: () => string;
21
- inputs: Record<string, NodeInterface<unknown>>;
22
- outputs: Record<string, NodeInterface<unknown>>;
23
- constructor();
24
- get codeNodeInputs(): Record<string, CodeNodeInputInterface>;
25
- get codeNodeOutputs(): Record<string, CodeNodeOutputInterface>;
26
- get idx(): number;
27
- get idxByVariableNames(): number;
28
- get lockCode(): boolean;
29
- set lockCode(value: boolean);
30
- get optionalInputs(): Record<string, CodeNodeInputInterface>;
31
- get requiredInputs(): Record<string, CodeNodeInputInterface>;
32
- get script(): string;
33
- set script(value: string);
34
- get shortId(): string;
35
- get subgraph(): Graph | undefined;
36
- get variableName(): string;
37
- abstract onConnected(): void;
38
- abstract onUnconnected(): void;
39
- abstract update(): void;
40
- /**
41
- * Get connected node to the node interface.
42
- * @param nodeInterface string
43
- * @returns code node instance or null
44
- */
45
- getConnectedNodeByInterface(nodeInterface: string, type?: 'inputs' | 'outputs'): AbstractCodeNode | null;
46
- /**
47
- * Get connected nodes to the node.
48
- * @param type inputs or outputs
49
- * @returns code node instances
50
- */
51
- getConnectedNodes(type?: 'inputs' | 'outputs'): AbstractCodeNode[];
52
- /**
53
- * Get connected nodes to the node interface.
54
- * @param nodeInterface string
55
- * @returns code node instances
56
- */
57
- getConnectedNodesByInterface(nodeInterface: string, type?: 'inputs' | 'outputs'): AbstractCodeNode[];
58
- /**
59
- * Register code
60
- * @param code
61
- */
62
- registerCode(code: Code): void;
63
- /**
64
- * Render code of this node.
65
- */
66
- renderCode(): void;
67
- /**
68
- * Reset script of input interfaces.
69
- */
70
- resetInputInterfaceScript(): void;
71
- updateCodeTemplate(): void;
72
- updateConnectedInputInterfaces(): void;
73
- updateOutputNames(): void;
74
- updateProps(props: unknown): void;
75
- }
76
- export interface ICodeNodeState<I, O> extends INodeState<I, O>, IAbstractCodeNodeState {
77
- }
78
- export declare abstract class CodeNode<I, O> extends AbstractCodeNode {
79
- abstract inputs: NodeInterfaceDefinition<I>;
80
- abstract outputs: NodeInterfaceDefinition<O>;
81
- /**
82
- * The default implementation does nothing.
83
- * Overwrite this method to do calculation.
84
- * @param inputs Values of all input interfaces
85
- * @param globalValues Set of values passed to every node by the engine plugin
86
- * @return Values for output interfaces
87
- */
88
- calculate?: CalculateFunction<I, O>;
89
- load(state: ICodeNodeState<I, O>): void;
90
- save(): ICodeNodeState<I, O>;
91
- updateModules(modules?: string[]): void;
92
- }
93
- export type AbstractCodeNodeConstructor = new () => AbstractCodeNode;
94
- /**
95
- * Format inputs for mustache templates.
96
- * @param intfs code node input interfaces
97
- * @returns a list of string
98
- */
99
- export declare const formatInputs: (intfs: Record<string, CodeNodeInputInterface>, withKeywords?: boolean) => string[];
100
- /**
101
- * Load node state.
102
- * @param graph code graph
103
- * @param nodeState node state
104
- */
105
- export declare const loadNodeState: (graph: Graph | undefined, nodeState: ICodeNodeState<unknown, unknown>) => void;
106
- /**
107
- * Save state of node.
108
- * @param graph code graph
109
- * @param nodeState node state
110
- */
111
- export declare const saveNodeState: (graph: Graph | undefined, nodeState: ICodeNodeState<unknown, unknown>) => void;