@babsey/code-graph 0.2.1 → 0.2.3
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/dist/code-graph.js +249 -247
- package/dist/code-graph.umd.cjs +1 -1
- package/package.json +1 -1
package/dist/code-graph.umd.cjs
CHANGED
|
@@ -1 +1 @@
|
|
|
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 H 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 A 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 A{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 A{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 A{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 He(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 Ae(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 H(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 H("_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 bt(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",bt]]),_t={},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(_t,[["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"],Ht=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),b=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},bn=()=>{const p=c.value.displayedGraph.sidebar;p.nodeId=i.node.id},_n=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}},be=()=>{a.value.title=T.value,k.value=!1},_e=()=>{y.value&&c.value.hooks.renderNode.execute({node:i.node,el:y.value})},Nn=p=>{b.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(!b.value)return;const _=p.clientX-B,f=g+_/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=()=>{b.value=!1};return e.onMounted(()=>{_e(),window.addEventListener("mousemove",ke),window.addEventListener("mouseup",we)}),e.onUpdated(_e),e.onBeforeUnmount(()=>{window.removeEventListener("mousemove",ke),window.removeEventListener("mouseup",we)}),(p,_)=>(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":_[4]||(_[4]=f=>T.value=f),class:"baklava-input",placeholder:"Node Name",style:{"flex-grow":"1"},type:"text",onBlur:be,onKeydown:e.withKeys(be,["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:_[0]||(_[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:_[1]||(_[1]=f=>Ne(!1))})):(e.openBlock(),e.createBlock(e.unref(ce),{key:2,class:"--clickable mx-1",onClick:_[2]||(_[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:bn})):(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":_[3]||(_[3]=f=>m.value=f),x:0,y:0,items:N.value,onClick:_n},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:_[5]||(_[5]=e.withKeys(e.withModifiers(()=>{},["stop"]),["delete"])),onContextmenu:_[6]||(_[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"},[..._[7]||(_[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"},[..._[8]||(_[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))}}),At=["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,At))}}),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},b=()=>{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:b,onKeydown:e.withKeys(b,["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(b=>b.title.toLowerCase().includes(c.value.toLowerCase()))):a.value,y=w=>c.value?en(w,b=>{const g=b[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:b}=l.value.getBoundingClientRect();return{top:`${s.value-b}px`,left:`${n.value-w}px`}}),T=(w,b)=>{u.value={type:w,nodeInformation:b};const g=()=>{const B=e.reactive(new b.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,b)=>(e.openBlock(),e.createElementBlock(e.Fragment,null,[e.createElementVNode("div",{class:e.normalizeClass([{"--open":e.unref(t).settings.palette.enabled},"baklava-node-palette"]),onContextmenu:b[1]||(b[1]=e.withModifiers(()=>{},["stop","prevent"]))},[e.createElementVNode("div",rn,[e.withDirectives(e.createElementVNode("input",{"onUpdate:modelValue":b[0]||(b[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(Ht,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}),o.settings.toolbar.commands.unshift({command:t,title:"Toggle palette",icon:e.computed(()=>o.settings.palette.enabled?ne:oe)});const n="CLEAR_ALL";o.commandHandler.registerCommand(n,{execute:()=>o.code.clear(),canExecute:()=>o.displayedGraph.nodes.length>0}),o.settings.toolbar.commands.push({command:n,title:"Clear all",icon:e.computed(()=>pe)});const s="TOGGLE_MINIMAP";o.commandHandler.registerCommand(s,{execute:()=>o.settings.enableMinimap=!o.settings.enableMinimap,canExecute:()=>o.displayedGraph.nodes.length>1}),o.settings.toolbar.commands.push({command:s,title:"Toggle minimap",icon:e.computed(()=>o.settings.enableMinimap?le:de)})},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=H,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=He,d.defineDynamicCodeNode=Ae,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(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"})}));
|