@babsey/code-graph 0.3.1 → 0.3.2
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 +1 -1
- package/dist/code-graph.umd.cjs +1 -1
- package/package.json +1 -1
package/dist/code-graph.js
CHANGED
|
@@ -1159,7 +1159,7 @@ function bs(n) {
|
|
|
1159
1159
|
}), n.engine?.events.afterRun.subscribe(e, (t) => {
|
|
1160
1160
|
n.engine?.pause(), Ae(t, n.editor), n.code.state.lockCode || n.code.renderCode({
|
|
1161
1161
|
nodes: n.editor.graph.scriptedCodeNodes,
|
|
1162
|
-
modules: n.editor.
|
|
1162
|
+
modules: n.editor.code.modules
|
|
1163
1163
|
}), n.engine?.resume();
|
|
1164
1164
|
});
|
|
1165
1165
|
}, n.unsubscribe = () => {
|
package/dist/code-graph.umd.cjs
CHANGED
|
@@ -1,4 +1,4 @@
|
|
|
1
1
|
(function(r,G){typeof exports=="object"&&typeof module<"u"?G(exports,require("mustache"),require("vue"),require("uuid"),require("@baklavajs/core"),require("@baklavajs/interface-types"),require("@baklavajs/engine"),require("@baklavajs/renderer-vue"),require("toposort"),require("@baklavajs/events"),require("@vueuse/core")):typeof define=="function"&&define.amd?define(["exports","mustache","vue","uuid","@baklavajs/core","@baklavajs/interface-types","@baklavajs/engine","@baklavajs/renderer-vue","toposort","@baklavajs/events","@vueuse/core"],G):(r=typeof globalThis<"u"?globalThis:r||self,G(r["@babsey/code-graph"]={},r.mustache,r.vue,r.uuid,r["@baklavajs/core"],r["@baklavajs/interface-types"],r["@baklavajs/engine"],r["@baklavajs/renderer-vue"],r.toposort,r["@baklavajs/events"],r["@vueuse/core"]))})(this,(function(r,G,e,j,O,I,R,f,nt,fe,ot){"use strict";G.escape=o=>o;class Y extends O.AbstractNode{state;isCodeNode=!0;name="";codeTemplate;inputs={};outputs={};constructor(){super(),this.initializeIo(),this.twoColumn=!0,this.state=e.reactive({codeTemplate:"",hidden:!1,integrated:!1,lockCode:!1,modules:[],props:null,script:"",variableName:"a"}),this.codeTemplate=function(){return`${this.name}(${ge(this.codeNodeInputs).join(", ")})`}}get code(){return this.graph.code}get codeNodeInputs(){return Object.fromEntries(Object.entries(this.inputs).filter(t=>t[1].isCodeNode&&t[1].type!="node"))}get codeNodeOutputs(){return Object.fromEntries(Object.entries(this.outputs).filter(t=>t[1].isCodeNode&&t[1].type!="node"))}get graph(){return super.graph}get idx(){return this.graph.nodes.filter(t=>!t.state.integrated).indexOf(this)??-1}get idxByVariableNames(){return this.graph.getNodesBySameVariableNames(this.state.variableName).filter(t=>!t.state.integrated).indexOf(this)??-1}get lockCode(){return this.state.lockCode}set lockCode(t){this.state.lockCode=t,this.events.update.emit(null)}get optionalInputs(){return Object.fromEntries(Object.entries(this.codeNodeInputs).filter(t=>t[1].optional))}get requiredInputs(){return Object.fromEntries(Object.entries(this.codeNodeInputs).filter(t=>!t[1].optional))}get script(){return this.outputs._code?.value??""}set script(t){this.outputs._code&&(this.outputs._code.value=t),this.events.update.emit(null)}get shortId(){return this.id.slice(0,6)}get subgraph(){}get variableName(){return this.state.variableName?this.state.variableName+(this.idxByVariableNames+1):""}getConnectedNodeByInterface(t,n){const s=this.getConnectedNodesByInterface(t,n);return s.length>0?s[0]:null}getConnectedNodes(t){let n=[];if(t!=="inputs"){const s=this.graph.connections.filter(a=>a.from.name!=="_code").filter(a=>a.from.nodeId===this.id).map(a=>a.to.nodeId);s&&(n=n.concat(s))}if(t!=="outputs"){const s=this.graph.connections.filter(a=>a.from.name!=="_code").filter(a=>a.to.nodeId===this.id).map(a=>a.from.nodeId);s&&(n=n.concat(s))}return!n||n.length==0?[]:n.map(s=>this.graph.findNodeById(s))}getConnectedNodesByInterface(t,n){let s=[];if(n!=="outputs"&&this.inputs[t]){const a=this.graph.connections.filter(i=>i.to.id===this.inputs[t]?.id||i.from.id===this.inputs[t]?.id).map(i=>i.from.nodeId);a&&(s=s.concat(a))}if(n!=="inputs"&&this.outputs[t]){const a=this.graph.connections.filter(i=>i.from.id===this.outputs[t]?.id||i.from.id===this.outputs[t]?.id).map(i=>i.to.nodeId);a&&(s=s.concat(a))}return!s||s.length==0?[]:s.map(a=>this.graph.findNodeById(a))}registerCode(t){this.code=t}renderCode(t){return G.render(this.state.codeTemplate,t)}updateCodeTemplate(){this.state.codeTemplate=this.codeTemplate.call(this)}updateModules(t){if(t)this.state.modules=t;else if(this.type.includes(".")){const n=this.type.split(".");this.state.modules.push(n.slice(0,n.length-1).join("."))}}updateOutputNames(){Object.values(this.codeNodeOutputs).forEach(t=>{t.name=this.state.integrated?"":this.variableName+t.suffix})}updateOutputValues(t){Object.keys(this.outputs).forEach(n=>{n!=="_code"&&(t[n]=this.state.integrated?t._code:this.outputs[n].name)})}updateProps(t){this.state.props=t}}class A extends Y{calculate=(t,n)=>{const s={};return this.lockCode||(s._code=this.renderCode({inputs:t,...n})),this.updateOutputValues(s),s};load(t){super.load(t),K(this.graph,t)}save(){const t=super.save();return be(this.graph,t),t}}const ge=(o,t=!0)=>{const n=[],s=Object.keys(o);return s.forEach(a=>{if(o[a]?.hidden)return;const l=t&&n.length<s.indexOf(a)?`${a}=`:"";n.push(`${l}{{ inputs.${a} }}`)}),n},K=(o,t)=>{if(!o)return;const n=o.findNodeById(t.id);if(!n||n.subgraph)return;const s=n;s.state&&(s.state.integrated=t.integrated,s.state.modules=t.modules,s.state.props=t.props),Object.entries(t.inputs).forEach(([a,i])=>{a!=="_code"&&s.inputs[a]&&(s.inputs[a].hidden=i.hidden)}),Object.entries(t.outputs).forEach(([a,i])=>{a!=="_code"&&s.outputs[a]&&(s.outputs[a].hidden=i.hidden)})},be=(o,t)=>{if(!o)return;const n=o.findNodeById(t.id);if(!n||n.subgraph)return;const s=n;s.state&&(t.integrated=s.state.integrated,t.modules=s.state.modules),Object.entries(t.inputs).forEach(([a,i])=>{a!=="_code"&&s.inputs[a]&&(i.hidden=s.inputs[a].hidden)}),Object.entries(t.outputs).forEach(([a,i])=>{a!=="_code"&&s.outputs[a]&&(i.hidden=s.outputs[a].hidden)})},st=["title"],H=e.defineComponent({__name:"CodeNodeInterface",props:{intf:{}},setup(o){return(t,n)=>(e.openBlock(),e.createElementBlock("div",{title:o.intf.value},e.toDisplayString(o.intf.name),9,st))}});class x extends O.NodeInterface{isCodeNode=!0;code;state;type=null;constructor(t,n){super(t,n),this.setComponent(e.markRaw(H)),this.state=e.reactive({optional:!1})}get optional(){return this.state.optional}get shortId(){return this.id.slice(0,6)}getValue=()=>`${this.value??"None"}`;setOptional(t){return this.state.optional=t,this.setHidden(t),this}}class L extends x{constructor(t="",n){super(t,n),this.setComponent(e.markRaw(H)),this.use(f.displayInSidebar,!0)}get value(){return super.value}set value(t){super.value=t,this.name!=="_code"&&this.setHidden(!1)}}const X=new I.NodeInterfaceType("boolean"),ke=new I.NodeInterfaceType("dict"),J=new I.NodeInterfaceType("list"),V=new I.NodeInterfaceType("node"),U=new I.NodeInterfaceType("number"),F=new I.NodeInterfaceType("string"),Q=new I.NodeInterfaceType("tuple"),at=o=>{new I.BaklavaInterfaceTypes(o.editor,{viewPlugin:o}).addTypes(X,ke,J,V,U,F,Q)};class it extends L{constructor(t,n){super(t,n),this.setComponent(e.markRaw(f.CheckboxInterfaceComponent)),this.use(I.setType,X)}getValue=()=>this.value?"True":"False"}class Ce extends x{isCodeNodeOutput=!0;suffix="";constructor(t="",n=""){super(t,""),this.suffix=n,this.setComponent(e.markRaw(H))}get codeValue(){return this.node?.outputs._code.value??""}get node(){const{graph:t}=f.useGraph();return t.value.findNodeById(this.nodeId)}}class Z extends L{min;max;constructor(t,n,s,a){super(t,n),this.min=s,this.max=a,this.use(I.setType,U)}validate(t){return(this.min===void 0||t>=this.min)&&(this.max===void 0||t<=this.max)}}class rt extends Z{component=e.markRaw(f.IntegerInterfaceComponent);validate(t){return Number.isInteger(t)&&super.validate(t)}}class lt extends L{constructor(t="",n=""){super(t,n),this.setComponent(e.markRaw(f.TextInputInterfaceComponent)),this.use(I.setType,J)}getValue=()=>`[${this.value}]`}class dt extends Z{component=e.markRaw(f.NumberInterfaceComponent)}class ee extends L{constructor(t,n){super(t,n),this.use(I.setType,F)}getValue=()=>`"${this.value}"`}class ct extends ee{component=e.markRaw(f.SelectInterfaceComponent);items;constructor(t,n,s){super(t,n),this.items=s}}class ut extends Z{component=e.markRaw(f.SliderInterfaceComponent);min;max;constructor(t,n,s,a){super(t,n,s,a),this.min=s,this.max=a}getValue=()=>`${Math.round(this.value*1e3)/1e3}`}const pt=e.defineComponent({props:{intf:{type:Object,required:!0},modelValue:{type:String,required:!0}},emits:["update:modelValue"],setup(o,{emit:t}){return{v:e.computed({get:()=>o.modelValue,set:s=>{t("update:modelValue",s)}})}}}),M=(o,t)=>{const n=o.__vccOpts||o;for(const[s,a]of t)n[s]=a;return n},ht={style:{position:"relative"}},mt={style:{"font-size":"12px",padding:"0 6px",position:"absolute",top:"-8px","background-color":"var(--baklava-node-color-background)"}},ft=["placeholder","title"];function gt(o,t,n,s,a,i){return e.openBlock(),e.createElementBlock("div",ht,[e.createElementVNode("label",mt,e.toDisplayString(o.intf.name),1),e.withDirectives(e.createElementVNode("input",{"onUpdate:modelValue":t[0]||(t[0]=l=>o.v=l),type:"text",class:"baklava-input",placeholder:o.intf.name,title:o.intf.name},null,8,ft),[[e.vModelText,o.v]])])}const ye=M(pt,[["render",gt]]);class bt extends ee{component=e.markRaw(ye)}class kt extends ee{component=e.markRaw(f.TextareaInputInterfaceComponent)}class Ct extends L{constructor(t="",n=""){super(t,n),this.setComponent(e.markRaw(f.TextInputInterfaceComponent)),this.use(I.setType,Q)}getValue=()=>`(${this.value})`}function yt(o){return class extends A{type=o.type;inputs={};outputs={};constructor(){super(),this._title=o.title??o.type,this.executeFactory("input",o.inputs),this.executeFactory("output",o.outputs),o.calculate&&(this.calculate=(t,n)=>o.calculate.call(this,{inputs:t,...n})),o.onCreate?.call(this),this.name=o.name??o.type,this.updateModules(o.modules),o.variableName!=null&&(this.state.variableName=o.variableName),o.codeTemplate&&(this.codeTemplate=o.codeTemplate),this.addInput("_code",new x("",[]).use(I.setType,V).use(R.allowMultipleConnections).setHidden(!0)),this.addOutput("_code",new x("",[]).use(I.setType,V).use(R.allowMultipleConnections).setHidden(!0))}onPlaced(){o.onPlaced?.call(this)}onConnected(){o.onConnected?.call(this)}onDestroy(){o.onDestroy?.call(this)}onUnconnected(){o.onUnconnected?.call(this)}update(){o.update?.call(this)}executeFactory(t,n){Object.keys(n||{}).forEach(s=>{const a=n[s]();t==="input"?this.addInput(s,a):this.addOutput(s,a)})}}}class Ne extends A{}function Nt(o){return class extends Ne{type=o.type;inputs={};outputs={};preventUpdate=!1;staticInputKeys=Object.keys(o.inputs??{});staticOutputKeys=Object.keys(o.outputs??{});constructor(){super(),this._title=o.title??o.type,this.executeFactory("input",o.inputs),this.executeFactory("output",o.outputs),o.calculate&&(this.calculate=(t,n)=>o.calculate?.call(this,t,n)),o.onCreate?.call(this),this.name=o.name??o.type,this.updateModules(o.modules),o.codeTemplate&&(this.codeTemplate=o.codeTemplate),o.variableName&&(this.state.variableName=o.variableName),this.addInput("_code",new x("",[]).use(I.setType,V).use(R.allowMultipleConnections).setHidden(!0)),this.addOutput("_code",new x("",[]).use(I.setType,V).use(R.allowMultipleConnections).setHidden(!0)),this.staticInputKeys.push("_code"),this.staticOutputKeys.push("_code")}onPlaced(){this.events.update.subscribe(this,t=>{t&&(t.type==="input"&&this.staticInputKeys.includes(t.name)||t.type==="output"&&this.staticOutputKeys.includes(t.name))&&this.onUpdate()}),this.onUpdate(),o.onPlaced?.call(this)}onConnected(){o.onConnected?.call(this)}onDestroy(){o.onDestroy?.call(this)}onUnconnected(){o.onUnconnected?.call(this)}update(){o.update?.call(this)}load(t){this.preventUpdate=!0,this.hooks.beforeLoad.execute(t),this.id=t.id,this.title=t.title;for(const n of this.staticInputKeys)this.inputs[n].load(t.inputs[n]),this.inputs[n].nodeId=this.id,n!=="_code"&&(this.inputs[n].hidden=t.inputs[n].hidden);for(const n of this.staticOutputKeys)this.outputs[n].load(t.outputs[n]),this.outputs[n].nodeId=this.id,n!=="_code"&&(this.outputs[n].hidden=t.outputs[n].hidden);this.preventUpdate=!1,this.onUpdate(),this.preventUpdate=!0;for(const n of Object.keys(t.inputs))if(!this.staticInputKeys.includes(n)){if(!this.inputs[n]){const s=t.inputs[n].value;let a;typeof s=="number"?a=new f.IntegerInterface(n,s).use(I.setType,U):a=new f.TextInputInterface(n,JSON.stringify(s)).use(I.setType,F),a.use(f.displayInSidebar,!0),this.addInput(n,a)}this.inputs[n]&&(this.inputs[n].load(t.inputs[n]),this.inputs[n].nodeId=this.id)}for(const n of Object.keys(t.outputs))if(!this.staticOutputKeys.includes(n)){if(!this.outputs[n]){const s=new Ce(n);this.addOutput(n,s)}this.outputs[n]&&(this.outputs[n].load(t.outputs[n]),this.outputs[n].nodeId=this.id)}K(this.graph,t),this.preventUpdate=!1,this.events.loaded.emit(this)}onUpdate(){if(this.preventUpdate)return;this.graph&&this.graph.activeTransactions++;const t=this.getStaticValues(this.staticInputKeys,this.inputs),n=this.getStaticValues(this.staticOutputKeys,this.outputs),s=o.onUpdate.call(this,t,n);this.updateInterfaces("input",s.inputs??{},s.forceUpdateInputs??[]),this.updateInterfaces("output",s.outputs??{},s.forceUpdateOutputs??[]),this.graph&&this.graph.activeTransactions--}getStaticValues(t,n){const s={};for(const a of t)s[a]=n[a].value;return s}updateInterfaces(t,n,s){const a=t==="input"?this.staticInputKeys:this.staticOutputKeys,i=t==="input"?this.inputs:this.outputs;for(const l of Object.keys(i))a.includes(l)||n[l]&&!s.includes(l)||(t==="input"?this.removeInput(l):this.removeOutput(l));for(const l of Object.keys(n)){if(i[l])continue;const d=n[l]();t==="input"?this.addInput(l,d):this.addOutput(l,d)}}updateProps(t){this.state.props=t,this.onUpdate()}executeFactory(t,n){Object.keys(n||{}).forEach(s=>{const a=n[s]();t==="input"?this.addInput(s,a):this.addOutput(s,a)})}}}const te="__baklava_SubgraphInputNode",ne="__baklava_SubgraphOutputNode";class _e extends A{graphInterfaceId;constructor(){super(),this.graphInterfaceId=j.v4()}onPlaced(){super.onPlaced(),this.initializeIo()}load(t){super.load(t),this.graphInterfaceId=t.graphInterfaceId}save(){return{...super.save(),graphInterfaceId:this.graphInterfaceId}}update(){}}class oe extends _e{static isGraphInputNode(t){return t.type===te}type=te;inputs={name:new O.NodeInterface("Name","Input")};outputs={placeholder:new O.NodeInterface("Value",void 0)}}class se extends _e{static isGraphOutputNode(t){return t.type===ne}type=ne;inputs={name:new O.NodeInterface("Name","Output"),placeholder:new O.NodeInterface("Value",void 0)};outputs={output:new O.NodeInterface("Output",void 0).setHidden(!0)};calculate=({placeholder:t})=>({output:t})}const _t=["component","connectionCount","events","hidden","hooks","id","isCodeNode","isInput","name","nodeId","port","templateId","value"];function Ie(o){return class extends Y{type=O.getGraphNodeTypeString(o);get title(){return this._title}set title(n){this.template.name=n}inputs={};outputs={};template=o;subgraph;update(){}onConnected(){}onUnconnected(){}calculate=async(n,s)=>{if(!this.subgraph)throw new Error(`GraphNode ${this.id}: calculate called without subgraph being initialized`);if(!s.engine||typeof s.engine!="object")throw new Error(`GraphNode ${this.id}: calculate called but no engine provided in context`);const a=s.engine.getInputValues(this.subgraph);for(const d of this.subgraph.inputs)a.set(d.nodeInterfaceId,n[d.id]);const i=await s.engine.runGraph(this.subgraph,a,s.globalValues);s.engine.pause(),R.applyResult(i,s.engine.editor),s.engine.resume();const l={};for(const d of this.subgraph.outputs)l[d.id]=i.get(d.nodeId)?.get("output");return l._calculationResults=i,this.lockCode||(l._code=this.renderCode({inputs:n,...s.globalValues})),this.updateOutputValues(l),l};load(n){if(!this.subgraph)throw new Error("Cannot load a graph node without a graph");if(!this.template)throw new Error("Unable to load graph node without graph template");this.subgraph.load(n.graphState),super.load(n)}save(){if(!this.subgraph)throw new Error("Cannot save a graph node without a graph");return{...super.save(),graphState:this.subgraph.save()}}onPlaced(){this.template.events.updated.subscribe(this,()=>this.initialize()),this.template.events.nameChanged.subscribe(this,n=>{this._title=n}),this.initialize()}onDestroy(){this.template.events.updated.unsubscribe(this),this.template.events.nameChanged.unsubscribe(this),this.subgraph?.destroy()}initialize(){this.subgraph&&this.subgraph.destroy(),this.subgraph=this.template.createGraph(),this._title=this.template.name,this.updateInterfaces(),this.state.codeTemplate=`{{ #nodes }}{{ script }}
|
|
2
2
|
{{ /nodes }}`,this.events.update.emit(null)}renderCode(n){return this.subgraph?this.subgraph.renderCode({nodes:this.subgraph.scriptedCodeNodes}):G.render(this.state.codeTemplate,n)}updateInterfaces(){if(!this.subgraph)throw new Error("Trying to update interfaces without graph instance");for(const n of this.subgraph.inputs)n.id in this.inputs?this.inputs[n.id].name=n.name:this.addInput(n.id,this.createProxyInterface(n,!0));for(const n of Object.keys(this.inputs))this.subgraph.inputs.some(s=>s.id===n)||this.removeInput(n);for(const n of this.subgraph.outputs)n.id in this.outputs?this.outputs[n.id].name=n.name:this.addOutput(n.id,this.createProxyInterface(n,!1));for(const n of Object.keys(this.outputs))this.subgraph.outputs.some(s=>s.id===n)||this.removeOutput(n);this.addInput("_code",new x("",[]).use(I.setType,V).use(R.allowMultipleConnections).setHidden(!0)),this.addOutput("_code",new x("",[]).use(I.setType,V).use(R.allowMultipleConnections).setHidden(!0)),this.addOutput("_calculationResults",new O.NodeInterface("_calculationResults",void 0).setHidden(!0))}createProxyInterface(n,s){const a=new x(n.name,void 0);return new Proxy(a,{get:(i,l)=>{if(_t.includes(l)||l in i||typeof l=="string"&&l.startsWith("__v_"))return Reflect.get(i,l);let d;s?d=this.subgraph?.nodes.find(C=>oe.isGraphInputNode(C)&&C.graphInterfaceId===n.id)?.outputs.placeholder.id:d=this.subgraph?.nodes.find(C=>se.isGraphOutputNode(C)&&C.graphInterfaceId===n.id)?.inputs.placeholder.id;const u=this.subgraph?.connections.find(b=>d===(s?b.from:b.to)?.id),p=s?u?.to:u?.from;if(p)return Reflect.get(p,l)}})}}}G.escape=o=>o;class we{_id;_state;viewModel;constructor(){this._id=j.v4(),this._state=e.reactive({lockCode:!1,modules:{},script:"",template:""})}get engine(){return this.viewModel?.engine}get graph(){return this.viewModel?.editor.graph}get id(){return this._id}get lockCode(){return this.state.lockCode}set lockCode(t){this.state.lockCode=t,this.engine?.runOnce(null)}get modules(){const t=[];return this.graph?.codeNodes.filter(n=>n.state.modules?.length>0).forEach(n=>t.push(...n.state.modules)),t?(t.sort(),Array.from(new Set(t.map(n=>this.state.modules[n])))):[]}get script(){return this.state.script}set script(t){this.state.script=t,this.engine?.runOnce(null)}get shortId(){return this.id.slice(0,6)}get state(){return this._state}clear(){this.state.script=""}async loadTemplate(t){t.then(n=>{this._state.template=n.default??""})}registerViewModel(t){this.viewModel=t}renderCode(t){this.state.script=G.render(this.state.template||"",t)}}const It=o=>{o.allowMultipleConnections=!0};class Ee extends R.BaseEngine{order=new Map;constructor(t){super(t)}start(){super.start(),this.recalculateOrder=!0,this.calculateWithoutData()}async runGraph(t,n,s){this.order.has(t.id)||this.order.set(t.id,R.sortTopologically(t));const{calculationOrder:a,connectionsFromNode:i}=this.order.get(t.id),l=new Map;for(const d of a){const u={};Object.entries(d.inputs).forEach(([b,C])=>{u[b]=this.getInterfaceValue(n,C.id)}),d.isCodeNode&&(d.updateCodeTemplate(),d.updateOutputNames()),this.events.beforeNodeCalculation.emit({inputValues:u,node:d});let p;if(d.calculate){if(p=await d.calculate(u,{globalValues:s,engine:this}),i.has(d))for(const[b,C]of Object.entries(p))this.hooks.transferData.execute(p[b],C),i.get(d).forEach(h=>{n.set(h.to.id,C)})}else{p={};for(const[b,C]of Object.entries(d.outputs))p[b]=this.getInterfaceValue(n,C.id)}this.events.afterNodeCalculation.emit({outputValues:p,node:d}),l.set(d.id,new Map(Object.entries(p))),i.has(d)&&i.get(d).forEach(b=>{const C=Object.entries(d.outputs).find(([,w])=>w.id===b.from.id)?.[0];if(!C)throw new Error(`Could not find key for interface ${b.from.id}
|
|
3
3
|
This is likely an internal issue. Please report it on GitHub.`);const h=this.hooks.transferData.execute(p[C],b);b.to.allowMultipleConnections?n.has(b.to.id)?n.get(b.to.id).push(h):n.set(b.to.id,[h]):n.set(b.to.id,h)})}return l}async execute(t){this.recalculateOrder&&(this.order.clear(),this.recalculateOrder=!1);const n=this.getInputValues(this.editor.graph);return await this.runGraph(this.editor.graph,n,t)}getInputValues(t){const n=new Map;for(const s of t.nodes)Object.values(s.inputs).forEach(a=>{a.connectionCount===0&&n.set(a.id,a.getValue?a.getValue():a.value)}),s.calculate||Object.values(s.outputs).forEach(a=>{n.set(a.id,a.getValue?a.getValue():a.value)});return n}onChange(t){this.recalculateOrder=t||this.recalculateOrder,this.calculateWithoutData()}getInterfaceValue(t,n){if(!t.has(n))throw new Error(`Could not find value for interface ${n}
|
|
4
|
-
This is likely an internal issue. Please report it on GitHub.`);return t.get(n)}}const wt={},Et={xmlns:"http://www.w3.org/2000/svg",width:"24",height:"24",viewBox:"0 0 24 24",fill:"none",stroke:"currentColor","stroke-width":"2","stroke-linecap":"round","stroke-linejoin":"round",class:"baklava-icon icon icon-tabler icons-tabler-outline icon-tabler-code-variable"};function vt(o,t){return e.openBlock(),e.createElementBlock("svg",Et,[...t[0]||(t[0]=[e.createElementVNode("path",{stroke:"none",d:"M0 0h24v24H0z",fill:"none"},null,-1),e.createElementVNode("path",{d:"M4 8m0 2a2 2 0 0 1 2 -2h12a2 2 0 0 1 2 2v4a2 2 0 0 1 -2 2h-12a2 2 0 0 1 -2 -2z"},null,-1)])])}const ve=M(wt,[["render",vt]]),Bt={},Tt={xmlns:"http://www.w3.org/2000/svg",width:"24",height:"24",viewBox:"0 0 24 24",fill:"none",stroke:"currentColor","stroke-width":"2","stroke-linecap":"round","stroke-linejoin":"round",class:"baklava-icon icon icon-tabler icons-tabler-outline icon-tabler-dots-vertical"};function Ot(o,t){return e.openBlock(),e.createElementBlock("svg",Tt,[...t[0]||(t[0]=[e.createElementVNode("path",{stroke:"none",d:"M0 0h24v24H0z",fill:"none"},null,-1),e.createElementVNode("path",{d:"M12 12m-1 0a1 1 0 1 0 2 0a1 1 0 1 0 -2 0"},null,-1),e.createElementVNode("path",{d:"M12 19m-1 0a1 1 0 1 0 2 0a1 1 0 1 0 -2 0"},null,-1),e.createElementVNode("path",{d:"M12 5m-1 0a1 1 0 1 0 2 0a1 1 0 1 0 -2 0"},null,-1)])])}const Be=M(Bt,[["render",Ot]]),xt={},Mt={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",Mt,[...t[0]||(t[0]=[e.createElementVNode("path",{stroke:"none",d:"M0 0h24v24H0z",fill:"none"},null,-1),e.createElementVNode("path",{d:"M18 3a3 3 0 0 1 2.995 2.824l.005 .176v12a3 3 0 0 1 -2.824 2.995l-.176 .005h-12a3 3 0 0 1 -2.995 -2.824l-.005 -.176v-12a3 3 0 0 1 2.824 -2.995l.176 -.005h12zm0 2h-9v14h9a1 1 0 0 0 .993 -.883l.007 -.117v-12a1 1 0 0 0 -.883 -.993l-.117 -.007zm-2.293 4.293a1 1 0 0 1 .083 1.32l-.083 .094l-1.292 1.293l1.292 1.293a1 1 0 0 1 .083 1.32l-.083 .094a1 1 0 0 1 -1.32 .083l-.094 -.083l-2 -2a1 1 0 0 1 -.083 -1.32l.083 -.094l2 -2a1 1 0 0 1 1.414 0z"},null,-1)])])}const Te=M(xt,[["render",St]]),Vt={},$t={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 Gt(o,t){return e.openBlock(),e.createElementBlock("svg",$t,[...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=M(Vt,[["render",Gt]]),Rt={},jt={xmlns:"http://www.w3.org/2000/svg",width:"24",height:"24",viewBox:"0 0 24 24",fill:"currentColor",class:"baklava-icon icon icon-tabler icons-tabler-filled icon-tabler-layout-sidebar-right"};function Pt(o,t){return e.openBlock(),e.createElementBlock("svg",jt,[...t[0]||(t[0]=[e.createElementVNode("path",{stroke:"none",d:"M0 0h24v24H0z",fill:"none"},null,-1),e.createElementVNode("path",{d:"M6 21a3 3 0 0 1 -3 -3v-12a3 3 0 0 1 3 -3h12a3 3 0 0 1 3 3v12a3 3 0 0 1 -3 3zm8 -16h-8a1 1 0 0 0 -1 1v12a1 1 0 0 0 1 1h8z"},null,-1)])])}const xe=M(Rt,[["render",Pt]]),Lt={},Dt={xmlns:"http://www.w3.org/2000/svg",width:"24",height:"24",viewBox:"0 0 24 24",fill:"currentColor",class:"baklava-icon icon icon-tabler icons-tabler-filled icon-tabler-layout-sidebar-right-collapse"};function zt(o,t){return e.openBlock(),e.createElementBlock("svg",Dt,[...t[0]||(t[0]=[e.createElementVNode("path",{stroke:"none",d:"M0 0h24v24H0z",fill:"none"},null,-1),e.createElementVNode("path",{d:"M18 3a3 3 0 0 1 2.995 2.824l.005 .176v12a3 3 0 0 1 -2.824 2.995l-.176 .005h-12a3 3 0 0 1 -2.995 -2.824l-.005 -.176v-12a3 3 0 0 1 2.824 -2.995l.176 -.005h12zm-3 2h-9a1 1 0 0 0 -.993 .883l-.007 .117v12a1 1 0 0 0 .883 .993l.117 .007h9v-14zm-5.387 4.21l.094 .083l2 2a1 1 0 0 1 .083 1.32l-.083 .094l-2 2a1 1 0 0 1 -1.497 -1.32l.083 -.094l1.292 -1.293l-1.292 -1.293a1 1 0 0 1 -.083 -1.32l.083 -.094a1 1 0 0 1 1.32 -.083z"},null,-1)])])}const Me=M(Lt,[["render",zt]]),At={},Ht={xmlns:"http://www.w3.org/2000/svg",width:"24",height:"24",viewBox:"0 0 24 24",fill:"currentColor",class:"baklava-icon icon icon-tabler icons-tabler-filled icon-tabler-layout-sidebar-right-expand"};function Ut(o,t){return e.openBlock(),e.createElementBlock("svg",Ht,[...t[0]||(t[0]=[e.createElementVNode("path",{stroke:"none",d:"M0 0h24v24H0z",fill:"none"},null,-1),e.createElementVNode("path",{d:"M18 3a3 3 0 0 1 2.995 2.824l.005 .176v12a3 3 0 0 1 -2.824 2.995l-.176 .005h-12a3 3 0 0 1 -2.995 -2.824l-.005 -.176v-12a3 3 0 0 1 2.824 -2.995l.176 -.005h12zm-3 2h-9a1 1 0 0 0 -.993 .883l-.007 .117v12a1 1 0 0 0 .883 .993l.117 .007h9v-14zm-3.293 4.293a1 1 0 0 1 .083 1.32l-.083 .094l-1.292 1.293l1.292 1.293a1 1 0 0 1 .083 1.32l-.083 .094a1 1 0 0 1 -1.32 .083l-.094 -.083l-2 -2a1 1 0 0 1 -.083 -1.32l.083 -.094l2 -2a1 1 0 0 1 1.414 0z"},null,-1)])])}const Se=M(At,[["render",Ut]]),Ft={},Wt={xmlns:"http://www.w3.org/2000/svg",width:"24",height:"24",viewBox:"0 0 24 24",fill:"none",stroke:"currentColor","stroke-width":"2","stroke-linecap":"round","stroke-linejoin":"round",class:"baklava-icon icon icon-tabler icons-tabler-outline icon-tabler-lock-code"};function qt(o,t){return e.openBlock(),e.createElementBlock("svg",Wt,[...t[0]||(t[0]=[e.createStaticVNode('<path stroke="none" d="M0 0h24v24H0z" fill="none"></path><path d="M11.5 21h-4.5a2 2 0 0 1 -2 -2v-6a2 2 0 0 1 2 -2h10a2 2 0 0 1 2 2"></path><path d="M11 16a1 1 0 1 0 2 0a1 1 0 0 0 -2 0"></path><path d="M8 11v-4a4 4 0 1 1 8 0v4"></path><path d="M20 21l2 -2l-2 -2"></path><path d="M17 17l-2 2l2 2"></path>',6)])])}const Ve=M(Ft,[["render",qt]]),Yt={},Kt={xmlns:"http://www.w3.org/2000/svg",width:"24",height:"24",viewBox:"0 0 24 24",fill:"none",stroke:"currentColor","stroke-width":"2","stroke-linecap":"round","stroke-linejoin":"round",class:"baklava-icon icon icon-tabler icons-tabler-outline icon-tabler-player-play"};function Xt(o,t){return e.openBlock(),e.createElementBlock("svg",Kt,[...t[0]||(t[0]=[e.createElementVNode("path",{stroke:"none",d:"M0 0h24v24H0z",fill:"none"},null,-1),e.createElementVNode("path",{d:"M7 4v16l13 -8z"},null,-1)])])}const $e=M(Yt,[["render",Xt]]),Jt={},Qt={xmlns:"http://www.w3.org/2000/svg",width:"24",height:"24",viewBox:"0 0 24 24",fill:"none",stroke:"currentColor","stroke-width":"2","stroke-linecap":"round","stroke-linejoin":"round",class:"baklava-icon icon icon-tabler icons-tabler-outline icon-tabler-schema"};function Zt(o,t){return e.openBlock(),e.createElementBlock("svg",Qt,[...t[0]||(t[0]=[e.createStaticVNode('<path stroke="none" d="M0 0h24v24H0z" fill="none"></path><path d="M5 2h5v4h-5z"></path><path d="M15 10h5v4h-5z"></path><path d="M5 18h5v4h-5z"></path><path d="M5 10h5v4h-5z"></path><path d="M10 12h5"></path><path d="M7.5 6v4"></path><path d="M7.5 14v4"></path>',8)])])}const Ge=M(Jt,[["render",Zt]]),en={},tn={xmlns:"http://www.w3.org/2000/svg",width:"24",height:"24",viewBox:"0 0 24 24",fill:"none",stroke:"currentColor","stroke-width":"2","stroke-linecap":"round","stroke-linejoin":"round",class:"baklava-icon icon icon-tabler icons-tabler-outline icon-tabler-schema-off"};function nn(o,t){return e.openBlock(),e.createElementBlock("svg",tn,[...t[0]||(t[0]=[e.createStaticVNode('<path stroke="none" d="M0 0h24v24H0z" fill="none"></path><path d="M6 2h4v4m-4 0h-1v-1"></path><path d="M15 11v-1h5v4h-2"></path><path d="M5 18h5v4h-5z"></path><path d="M5 10h5v4h-5z"></path><path d="M10 12h2"></path><path d="M7.5 7.5v2.5"></path><path d="M7.5 14v4"></path><path d="M3 3l18 18"></path>',9)])])}const Re=M(en,[["render",nn]]),on={},sn={xmlns:"http://www.w3.org/2000/svg",width:"24",height:"24",viewBox:"0 0 24 24",fill:"none",stroke:"currentColor","stroke-width":"2","stroke-linecap":"round","stroke-linejoin":"round",class:"baklava-icon icon icon-tabler icons-tabler-outline icon-tabler-transition-bottom"};function an(o,t){return e.openBlock(),e.createElementBlock("svg",sn,[...t[0]||(t[0]=[e.createStaticVNode('<path stroke="none" d="M0 0h24v24H0z" fill="none"></path><path d="M21 18a3 3 0 0 1 -3 3h-12a3 3 0 0 1 -3 -3"></path><path d="M3 3m0 3a3 3 0 0 1 3 -3h12a3 3 0 0 1 3 3v0a3 3 0 0 1 -3 3h-12a3 3 0 0 1 -3 -3z"></path><path d="M12 9v8"></path><path d="M9 14l3 3l3 -3"></path>',5)])])}const je=M(on,[["render",an]]),rn={},ln={xmlns:"http://www.w3.org/2000/svg",width:"24",height:"24",viewBox:"0 0 24 24",fill:"none",stroke:"currentColor","stroke-width":"2","stroke-linecap":"round","stroke-linejoin":"round",class:"baklava-icon icon icon-tabler icons-tabler-outline icon-tabler-trash-off"};function dn(o,t){return e.openBlock(),e.createElementBlock("svg",ln,[...t[0]||(t[0]=[e.createStaticVNode('<path stroke="none" d="M0 0h24v24H0z" fill="none"></path><path d="M3 3l18 18"></path><path d="M4 7h3m4 0h9"></path><path d="M10 11l0 6"></path><path d="M14 14l0 3"></path><path d="M5 7l1 12a2 2 0 0 0 2 2h8a2 2 0 0 0 2 -2l.077 -.923"></path><path d="M18.384 14.373l.616 -7.373"></path><path d="M9 5v-1a1 1 0 0 1 1 -1h4a1 1 0 0 1 1 1v3"></path>',8)])])}const Pe=M(rn,[["render",dn]]),ae="CLEAR_ALL",ie="RUN_ENGINE",re="TOGGLE_MINIMAP",le="TOGGLE_PALETTE",Le=(o,t,n)=>{const s=n.zoomToFit.paddingLeft;t.registerCommand(le,{execute:()=>{n.palette.enabled=!n.palette.enabled,n.zoomToFit.paddingLeft=n.palette.enabled?s:50},canExecute:()=>!0}),t.registerCommand(ae,{execute:()=>o.value.clear(),canExecute:()=>o.value.nodes.length>0}),t.registerCommand(re,{execute:()=>n.enableMinimap=!n.enableMinimap,canExecute:()=>o.value.nodes.length>1})},De=o=>{const t={command:ie,title:"Run",icon:e.computed(()=>$e)},n={command:le,title:"Toggle palette",icon:e.computed(()=>o.palette.enabled?Te:Oe)},s={command:ae,title:"Clear all",icon:e.computed(()=>Pe)},a={command:re,title:"Toggle minimap",icon:e.computed(()=>o.enableMinimap?Re:Ge)};o.toolbar.commands=[n,t,...f.DEFAULT_TOOLBAR_COMMANDS,s,a]},ze=(o,t)=>{t.registerCommand(ie,{execute:()=>o.runOnce(null),canExecute:()=>!0})};function Ae(o){const t=Symbol("CodeEngineToken");o.engine=new Ee(o.editor),ze(o.engine,o.commandHandler),o.loadEditor=n=>{o.engine?.pause(),o.displayedGraph.clear(),o.editor.load(n),o.commandHandler.executeCommand(f.Commands.CLEAR_CLIPBOARD_COMMAND),o.commandHandler.executeCommand(f.Commands.CLEAR_HISTORY_COMMAND),o.engine?.resume(),o.engine?.runOnce(null)},o.newGraph=()=>{o.engine?.pause(),o.displayedGraph.clear(),o.commandHandler.executeCommand(f.Commands.CLEAR_CLIPBOARD_COMMAND),o.commandHandler.executeCommand(f.Commands.CLEAR_HISTORY_COMMAND),o.displayedGraph.id=j.v4(),o.engine?.resume(),o.engine?.runOnce(null)},o.subscribe=()=>{o.displayedGraph.events.addConnection.subscribe(t,n=>{const s=o.displayedGraph.findNodeById(n.to.nodeId);s&&s.isCodeNode&&s.onConnected();const a=o.displayedGraph.findNodeById(n.from.nodeId);a&&a.isCodeNode&&a.onConnected()}),o.displayedGraph.events.removeConnection.subscribe(t,n=>{const s=o.displayedGraph.findNodeById(n.to.nodeId);s&&s.isCodeNode&&s.onUnconnected();const a=o.displayedGraph.findNodeById(n.from.nodeId);a&&a.isCodeNode&&a.onUnconnected()}),o.engine?.events.beforeRun.subscribe(t,()=>{o.engine?.pause(),o.displayedGraph.sortNodes(),o.engine?.resume()}),o.engine?.events.afterRun.subscribe(t,n=>{o.engine?.pause(),R.applyResult(n,o.editor),o.code.state.lockCode||o.code.renderCode({nodes:o.editor.graph.scriptedCodeNodes,modules:o.editor.graph.modules}),o.engine?.resume()})},o.unsubscribe=()=>{o.displayedGraph.events.addConnection.unsubscribe(t),o.displayedGraph.events.removeConnection.unsubscribe(t),o.engine?.events.beforeRun.unsubscribe(t),o.engine?.events.afterRun.unsubscribe(t)}}class D extends O.Graph{code=null;editor;_state=e.reactive({codeTemplate:"{{ #nodes }}{{ script }}{{ /nodes }}",lockCode:!1});constructor(t,n){super(t,n),this.editor=t,this.template=n,t.code&&(this.code=t.code)}get codeNodes(){return de(this)}get connections(){return super.connections}set connections(t){this._connections=t}get nodeIds(){return this.nodes.map(t=>t.id)}get nodes(){return super.nodes}set nodes(t){this._nodes=t}get scriptedCodeNodes(){return this.nodes.filter(t=>!t.state?.integrated)}get shortId(){return this.id.slice(0,6)}get state(){return this._state}get visibleNodes(){return this.nodes.filter(t=>!t.state?.hidden)}addNodeAtCoordinates=(t,n={x:0,y:0},s)=>(this.addNode(t,s),t.position&&(t.position=n),t);addConnection(t,n){t?.name!=="_code"&&(t.hidden=!1),n?.name!=="_code"&&(n.hidden=!1),super.addConnection(t,n)}clear(){this.selectedNodes=[],this._nodes=[],this._connections=[]}findNodeByType(t){return this.nodes.find(n=>n.type===t)}getNodesBySameType(t){return this.nodes.filter(n=>n.type===t)}getNodesBySameVariableNames(t){return this.nodes.filter(n=>n.state?.variableName===t)}hasConnection(t,n){return this.connections.some(s=>s.from.id===t.id&&s.to.id===n.id)}renderCode(t){return G.render(this.state?.codeTemplate||"",t)}sortNodes(){if(!(this.nodes.length===0||this.connections.length===0))try{let t=this.nodeIds;const n=this.connections.filter(i=>t.includes(i.to.nodeId)&&t.includes(i.from.nodeId)).map(i=>[i.to.nodeId,i.from.nodeId]);t.reverse(),t=nt.array(t,n),t.reverse();const s=this.nodes.map(i=>i.id).filter(i=>!t.includes(i));t=[...t,...s];const a=t.map(i=>this.findNodeById(i));a&&(this.nodes=a)}catch{console.warn("Failed to sort nodes.")}}}const de=o=>{const t=[];return o.nodes.length===0||o.nodes.forEach(n=>{n&&(n.hasOwnProperty("subgraph")?t.push(...de(n.subgraph)):n.hasOwnProperty("isCodeNode")&&t.push(n))}),t},cn=(o=0,t=100)=>({x:o*420,y:t}),un=o=>{const t={...o.position};return t.x-=440,t.y+=50,t};function pn(o,t){return Object.fromEntries(Object.entries(o).filter(t))}function hn(o,t){return Object.fromEntries(Object.entries(o).map(([n,s])=>[n,t(s)]))}class z extends O.GraphTemplate{static fromGraph(t,n){return new z(t.save(),n)}constructor(t,n){super(t,n)}get shortId(){return this.id.slice(0,6)}createGraph(t){const n=new Map,s=h=>{const w=j.v4();return n.set(h,w),w},a=h=>{const w=n.get(h);if(!w)throw new Error(`Unable to create graph from template: Could not map old id ${h} to new id`);return w},i=h=>hn(h,w=>({id:s(w.id),templateId:w.id,value:w.value})),l=this.nodes.map(h=>({...h,id:s(h.id),inputs:i(h.inputs),outputs:i(h.outputs)})),d=this.connections.map(h=>({id:s(h.id),from:a(h.from),to:a(h.to)})),u=this.inputs.map(h=>({id:h.id,name:h.name,nodeId:a(h.nodeId),nodeInterfaceId:a(h.nodeInterfaceId)})),p=this.outputs.map(h=>({id:h.id,name:h.name,nodeId:a(h.nodeId),nodeInterfaceId:a(h.nodeInterfaceId)})),b={id:j.v4(),nodes:l,connections:d,inputs:u,outputs:p};return t||(t=new D(this.editor)),t.load(b).forEach(h=>console.warn(h)),t.template=this,t}}const mn=o=>!(o instanceof D);function He(o,t){return{switchGraph:s=>{let a;if(mn(s))a=new D(o.value),s.createGraph(a);else{if(s!==o.value.graph)throw new Error("Can only switch using 'Graph' instance when it is the root graph. Otherwise a 'GraphTemplate' must be used.");a=s}t.value&&t.value!==o.value.graph&&t.value.destroy(),a.panning=a.panning??s.panning??{x:0,y:0},a.scaling=a.scaling??s.scaling??1,a.selectedNodes=a.selectedNodes??[],a.sidebar=a.sidebar??{visible:!1,nodeId:"",optionName:""},t.value=a,a.code?.engine?.runOnce(null)}}}const fn=e.defineComponent({__name:"CodeGraphEditor",props:{viewModel:{}},setup(o){const t=o,n=e.toRef(t,"viewModel"),s=a=>a.events.update.emit(null);return e.onMounted(()=>{n.value.subscribe&&n.value.subscribe(),n.value.engine?.start()}),e.onBeforeUnmount(()=>{n.value.unsubscribe&&n.value.unsubscribe(),n.value.engine?.stop()}),e.watch(n,(a,i)=>{i&&i.unsubscribe(),a&&a.subscribe()}),(a,i)=>(e.openBlock(),e.createBlock(e.unref(f.BaklavaEditor),{viewModel:n.value},{palette:e.withCtx(()=>[e.createVNode(e.unref(Fe))]),node:e.withCtx(l=>[e.createVNode(e.unref(Ue),e.mergeProps(l,{onUpdate:d=>s(l.node)}),null,16,["onUpdate"])]),sidebar:e.withCtx(l=>[e.createVNode(e.unref(We),e.normalizeProps(e.guardReactiveProps(l)),{codeEditor:e.withCtx(({node:d})=>[e.renderSlot(a.$slots,"sidebarCodeEditor",{node:d})]),_:3},16)]),_:3},8,["viewModel"]))}}),gn={class:"code-graph-info"},bn=e.defineComponent({__name:"CodeGraphInfo",props:{viewModel:{}},setup(o){return(t,n)=>(e.openBlock(),e.createElementBlock("div",gn,[e.createElementVNode("div",null,"Editor graph: "+e.toDisplayString(o.viewModel.editor.graph.shortId),1),e.createElementVNode("div",null,"Displayed graph: "+e.toDisplayString(o.viewModel.displayedGraph.shortId),1),e.createElementVNode("div",null,"Graphs: "+e.toDisplayString(o.viewModel.editor.graphIds),1),e.createElementVNode("div",null,"Graph templates: "+e.toDisplayString(o.viewModel.editor.graphTemplateIds),1),e.createElementVNode("div",null,"Engine status: "+e.toDisplayString(o.viewModel.engine?.status),1)]))}}),kn=["id","data-node-type"],Cn={class:"__title-label",style:{"flex-grow":"1"}},yn={key:0},Nn={class:"__menu",style:{display:"flex"}},_n={class:"__outputs"},In={key:0},wn=["id","title"],En={class:"__inputs"},vn={key:0},Bn=["id","title"],Ue=e.defineComponent({__name:"CodeGraphNode",props:{node:{},selected:{type:Boolean,default:!1},dragging:{type:Boolean}},emits:["select","start-drag","update"],setup(o,{emit:t}){const n=f.Components.ContextMenu,s=f.Components.NodeInterface,a=o,i=e.computed(()=>a.node),l=t,{viewModel:d}=f.useViewModel(),{graph:u,switchGraph:p}=f.useGraph(),b=e.ref(null),C=e.ref(!1),h=e.ref(""),w=e.ref(null),k=e.ref(!1);let _=0,c=0;const m=e.ref(!1),E=e.computed(()=>{const N=[{value:"edit",label:"Edit"},{value:"rename",label:"Rename"},{value:"delete",label:"Delete"}];return a.node.type.startsWith(O.GRAPH_NODE_TYPE_PREFIX)&&N.push({value:"editSubgraph",label:"Edit Subgraph"}),N}),y=e.computed(()=>({"--selected":a.selected,"--dragging":a.dragging,"--two-column":!!a.node.twoColumn,"--hidden":i.value.state?.hidden})),B=e.computed(()=>({"--reverse-y":a.node.reverseY??d.value.settings.nodes.reverseY})),W=e.computed(()=>({top:`${a.node.position?.y??0}px`,left:`${a.node.position?.x??0}px`,"--width":`${a.node.width??d.value.settings.nodes.defaultWidth}px`})),P=e.computed(()=>Object.values(a.node.inputs).filter(N=>!N.hidden)),me=e.computed(()=>Object.values(a.node.outputs).filter(N=>!N.hidden)),q=()=>{l("select")},g=N=>{a.selected||q(),l("start-drag",N)},S=()=>{m.value=!0},$=()=>{const N=d.value.displayedGraph.sidebar;N.nodeId="",N.visible=!1},Xe=()=>{const N=d.value.displayedGraph.sidebar;N.nodeId=a.node.id,N.visible=!0},qn=()=>{const N=d.value.displayedGraph.sidebar;N.nodeId=a.node.id},Yn=async N=>{switch(N){case"edit":Xe();break;case"delete":u.value.removeNode(a.node);break;case"rename":h.value=a.node.title,C.value=!0,await e.nextTick(),w.value?.focus();break;case"editSubgraph":p(a.node.template);break}},Je=()=>{i.value.title=h.value,C.value=!1},Qe=()=>{b.value&&d.value.hooks.renderNode.execute({node:a.node,el:b.value})},Kn=N=>{k.value=!0,_=a.node.width,c=N.clientX,N.preventDefault()},Ze=N=>{i.value.state&&(i.value.state.integrated=N,l("update"))},et=N=>{if(!k.value)return;const T=N.clientX-c,v=_+T/u.value.scaling,Xn=d.value.settings.nodes.minWidth,Jn=d.value.settings.nodes.maxWidth;i.value.width=Math.max(Xn,Math.min(Jn,v))},tt=()=>{k.value=!1};return e.onMounted(()=>{Qe(),window.addEventListener("mousemove",et),window.addEventListener("mouseup",tt)}),e.onUpdated(Qe),e.onBeforeUnmount(()=>{window.removeEventListener("mousemove",et),window.removeEventListener("mouseup",tt)}),(N,T)=>(e.openBlock(),e.createElementBlock("div",{id:i.value.id,ref_key:"el",ref:b,class:e.normalizeClass([y.value,"baklava-node"]),"data-node-type":i.value.type,style:e.normalizeStyle(W.value),onPointerdown:q},[e.unref(d).settings.nodes.resizable?(e.openBlock(),e.createElementBlock("div",{key:0,class:"__resize-handle",onMousedown:Kn},null,32)):e.createCommentVNode("",!0),e.createElementVNode("div",{class:"__title",onPointerdown:e.withModifiers(g,["self","stop"]),onContextmenu:e.withModifiers(S,["prevent"])},[i.value.inputs._code?(e.openBlock(),e.createBlock(e.unref(ce),{key:0,node:i.value,intf:i.value.inputs._code,title:i.value.inputs._code.value,class:"--input","data-interface-type":"node",style:{"flex-grow":"0"}},null,8,["node","intf","title"])):e.createCommentVNode("",!0),C.value?e.withDirectives((e.openBlock(),e.createElementBlock("input",{key:2,ref_key:"renameInputEl",ref:w,"onUpdate:modelValue":T[4]||(T[4]=v=>h.value=v),class:"baklava-input",placeholder:"Node Name",style:{"flex-grow":"1"},type:"text",onBlur:Je,onKeydown:e.withKeys(Je,["enter"])},null,544)),[[e.vModelText,h.value]]):(e.openBlock(),e.createElementBlock(e.Fragment,{key:1},[e.createElementVNode("div",Cn,[i.value.idx>-1?(e.openBlock(),e.createElementBlock("span",yn,e.toDisplayString(i.value.idx+1)+" - ",1)):e.createCommentVNode("",!0),e.createTextVNode(e.toDisplayString(i.value.title)+" "+e.toDisplayString(i.value.graph.shortId)+" "+e.toDisplayString(i.value.shortId),1)]),e.createElementVNode("div",Nn,[i.value.isCodeNode?(e.openBlock(),e.createElementBlock(e.Fragment,{key:0},[i.value.state.lockCode?(e.openBlock(),e.createBlock(e.unref(Ve),{key:0,class:"--clickable mx-1",onClick:T[0]||(T[0]=v=>i.value.lockCode=!1)})):e.createCommentVNode("",!0),i.value.state.integrated?(e.openBlock(),e.createBlock(e.unref(ve),{key:1,class:"--clickable mx-1",onClick:T[1]||(T[1]=v=>Ze(!1))})):(e.openBlock(),e.createBlock(e.unref(je),{key:2,class:"--clickable mx-1",onClick:T[2]||(T[2]=v=>Ze(!0))})),!e.unref(d).displayedGraph.sidebar.visible&&e.unref(d).displayedGraph.sidebar.nodeId!==i.value.id?(e.openBlock(),e.createBlock(e.unref(Se),{key:3,class:"--clickable mx-1",onClick:Xe})):e.unref(d).displayedGraph.sidebar.visible&&e.unref(d).displayedGraph.sidebar.nodeId!==i.value.id?(e.openBlock(),e.createBlock(e.unref(xe),{key:4,class:"--clickable mx-1",onClick:qn})):(e.openBlock(),e.createBlock(e.unref(Me),{key:5,class:"--clickable mx-1",onClick:$}))],64)):e.createCommentVNode("",!0),e.createVNode(e.unref(Be),{class:"--clickable mx-1",onClick:S}),e.createVNode(e.unref(n),{modelValue:m.value,"onUpdate:modelValue":T[3]||(T[3]=v=>m.value=v),x:0,y:0,items:E.value,onClick:Yn},null,8,["modelValue","items"])])],64)),i.value.outputs._code?(e.openBlock(),e.createBlock(e.unref(ce),{key:3,node:i.value,intf:i.value.outputs._code,class:"--output",title:i.value.outputs._code.value,"data-interface-type":"node"},null,8,["node","intf","title"])):e.createCommentVNode("",!0)],32),e.createElementVNode("div",{class:e.normalizeClass(["__content",B.value]),onKeydown:T[5]||(T[5]=e.withKeys(e.withModifiers(()=>{},["stop"]),["delete"])),onContextmenu:T[6]||(T[6]=e.withModifiers(()=>{},["prevent"]))},[e.createElementVNode("div",_n,[(e.openBlock(!0),e.createElementBlock(e.Fragment,null,e.renderList(me.value,v=>(e.openBlock(),e.createElementBlock(e.Fragment,{key:v.id},[i.value.state?.hidden?(e.openBlock(),e.createElementBlock("div",In,[v.port?(e.openBlock(),e.createElementBlock("div",{key:0,id:v.id,title:v.name,class:"baklava-node-interface --output --connected"},[...T[7]||(T[7]=[e.createElementVNode("div",{class:"__port"},null,-1)])],8,wn)):e.createCommentVNode("",!0)])):e.renderSlot(N.$slots,"nodeInterface",{key:1,type:"output",node:i.value,intf:v},()=>[e.createVNode(e.unref(s),{node:i.value,intf:v,title:v.value},null,8,["node","intf","title"])])],64))),128))]),e.createElementVNode("div",En,[(e.openBlock(!0),e.createElementBlock(e.Fragment,null,e.renderList(P.value,v=>(e.openBlock(),e.createElementBlock(e.Fragment,{key:v.id},[i.value.state?.hidden?(e.openBlock(),e.createElementBlock("div",vn,[v.port?(e.openBlock(),e.createElementBlock("div",{key:0,id:v.id,title:v.name,class:"baklava-node-interface --input --connected"},[...T[8]||(T[8]=[e.createElementVNode("div",{class:"__port"},null,-1)])],8,Bn)):e.createCommentVNode("",!0)])):e.renderSlot(N.$slots,"nodeInterface",{key:1,node:i.value,intf:v,type:"input"},()=>[e.createVNode(e.unref(s),{node:i.value,intf:v,title:v.value},null,8,["node","intf","title"])])],64))),128))])],34)],46,kn))}}),Tn=["id"],On={class:"align-middle"},ce=e.defineComponent({__name:"CodeGraphNodeInterface",props:{node:{},intf:{}},setup(o){const t=o,{viewModel:n}=f.useViewModel(),{hoveredOver:s,temporaryConnection:a}=f.useTemporaryConnection(),i=e.ref(null),l=e.computed(()=>t.intf.connectionCount>0),d=e.computed(()=>({"--connected":l.value})),u=()=>{s(t.intf)},p=()=>{s(void 0)},b=()=>{i.value&&n.value.hooks.renderInterface.execute({intf:t.intf,el:i.value})};return e.onMounted(b),e.onUpdated(b),(C,h)=>(e.openBlock(),e.createElementBlock("div",{id:o.intf.id,ref_key:"el",ref:i,class:e.normalizeClass(["baklava-node-interface",d.value])},[o.intf.port?(e.openBlock(),e.createElementBlock("div",{key:0,class:e.normalizeClass(["__port",{"--selected":e.unref(a)?.from===o.intf}]),onPointerover:u,onPointerout:p},null,34)):e.createCommentVNode("",!0),e.createElementVNode("span",On,[e.renderSlot(C.$slots,"default")])],10,Tn))}}),xn={class:"baklava-node --palette",style:{"margin-top":"-20px","margin-bottom":"20px"}},Mn={key:0,style:{display:"flex","justify-content":"space-between"}},Sn=["onClick"],Vn={key:0,style:{margin:"auto 0","font-size":"12px"}},Fe=e.defineComponent({__name:"CodeNodePalette",setup(o){const t=f.Components.PaletteEntry,{viewModel:n}=f.useViewModel(),{x:s,y:a}=ot.usePointer(),{transform:i}=f.useTransform(),l=f.useNodeCategories(n),d=e.inject("editorEl"),u=e.ref(""),p=e.ref(null),b=()=>u.value?l.value.filter(k=>k.name.toLowerCase().includes(u.value.toLowerCase())||Object.values(k.nodeTypes).some(_=>_.title.toLowerCase().includes(u.value.toLowerCase()))):l.value,C=k=>u.value?pn(k,_=>{const c=_[1];return c.category.includes(u.value.toLowerCase())||c.title?.toLowerCase().includes(u.value.toLowerCase())}):k,h=e.computed(()=>{if(!p.value||!d?.value)return{};const{left:k,top:_}=d.value.getBoundingClientRect();return{top:`${a.value-_}px`,left:`${s.value-k}px`}}),w=(k,_)=>{p.value={type:k,nodeInformation:_};const c=()=>{const m=e.reactive(new _.type);n.value.displayedGraph.addNode(m);const E=d.value.getBoundingClientRect(),[y,B]=i(s.value-E.left,a.value-E.top);m.position.x=y,m.position.y=B,p.value=null,document.removeEventListener("pointerup",c)};document.addEventListener("pointerup",c)};return(k,_)=>(e.openBlock(),e.createElementBlock(e.Fragment,null,[e.createElementVNode("div",{class:e.normalizeClass([{"--open":e.unref(n).settings.palette.enabled},"baklava-node-palette"]),onContextmenu:_[1]||(_[1]=e.withModifiers(()=>{},["stop","prevent"]))},[e.createElementVNode("div",xn,[e.withDirectives(e.createElementVNode("input",{"onUpdate:modelValue":_[0]||(_[0]=c=>u.value=c),type:"text",class:"baklava-input",title:"Filter nodes",onKeyup:b},null,544),[[e.vModelText,u.value]])]),(e.openBlock(!0),e.createElementBlock(e.Fragment,null,e.renderList(b(),c=>(e.openBlock(),e.createElementBlock("section",{key:c.name},[c.name!=="default"?(e.openBlock(),e.createElementBlock("h3",Mn,[e.createElementVNode("div",{onClick:m=>u.value=c.name,style:{cursor:"pointer"}},e.toDisplayString(c.name),9,Sn),Object.keys(C(c.nodeTypes)).length<Object.values(c.nodeTypes).length?(e.openBlock(),e.createElementBlock("div",Vn," ( "+e.toDisplayString(Object.keys(C(c.nodeTypes)).length)+" / "+e.toDisplayString(Object.values(c.nodeTypes).length)+" ) ",1)):e.createCommentVNode("",!0)])):e.createCommentVNode("",!0),(e.openBlock(!0),e.createElementBlock(e.Fragment,null,e.renderList(C(c.nodeTypes),(m,E)=>(e.openBlock(),e.createBlock(e.unref(t),{key:E,type:E,title:m.title,onPointerdown:y=>w(E,m)},null,8,["type","title","onPointerdown"]))),128))]))),128))],34),e.createVNode(e.Transition,{name:"fade"},{default:e.withCtx(()=>[p.value?(e.openBlock(),e.createElementBlock("div",{key:0,class:"baklava-dragged-node",style:e.normalizeStyle(h.value)},[e.createVNode(e.unref(t),{type:p.value.type,title:p.value.nodeInformation.title},null,8,["type","title"])],4)):e.createCommentVNode("",!0)]),_:1})],64))}}),$n=["title"],Gn={key:0,class:"__label"},ue=e.defineComponent({__name:"SidebarCheckbox",props:{disabled:{type:Boolean},inversed:{type:Boolean},modelValue:{type:Boolean},name:{}},emits:["update:modelValue"],setup(o,{emit:t}){const n=t;return(s,a)=>(e.openBlock(),e.createElementBlock("div",{class:e.normalizeClass(["baklava-checkbox",{"--checked":o.inversed?!o.modelValue:o.modelValue,"--disabled":o.disabled}]),title:o.name,onClick:a[0]||(a[0]=i=>n("update:modelValue",!o.modelValue))},[a[1]||(a[1]=e.createElementVNode("div",{class:"__checkmark-container"},[e.createElementVNode("svg",{xmlns:"http://www.w3.org/2000/svg",width:"18",height:"18",viewBox:"0 0 18 18"},[e.createElementVNode("path",{class:"__checkmark",d:"M 6 5 L 6 10 L 16 10",transform:"rotate(-45 10 10)"})])],-1)),o.name?(e.openBlock(),e.createElementBlock("div",Gn,e.toDisplayString(o.name),1)):e.createCommentVNode("",!0)],10,$n))}}),Rn={class:"__header"},jn={class:"__node-name"},Pn={class:"__interfaces"},Ln={class:"__inputs"},Dn={style:{display:"flex"}},zn={class:"__outputs"},An={key:0,class:"__interface"},Hn={style:{display:"flex"}},We=e.defineComponent({__name:"CodeGraphSidebar",setup(o){const{viewModel:t}=f.useViewModel(),{graph:n}=f.useGraph(),s=e.ref(null),a=e.toRef(t.value.settings.sidebar,"width"),i=e.computed(()=>t.value.settings.sidebar.resizable);let l=0,d=0;const u=e.computed(()=>{const m=n.value.sidebar.nodeId;return n.value.nodes.find(E=>E.id===m)}),p=e.computed(()=>u.value),b=e.computed(()=>({width:`${a.value}px`})),C=e.computed(()=>p.value?Object.values(p.value.inputs).filter(m=>m.displayInSidebar&&m.component):[]),h=e.computed(()=>p.value?Object.values(p.value.outputs).filter(m=>m.displayInSidebar&&m.component):[]),w=()=>{n.value.sidebar.visible=!1},k=()=>{u.value?.events.update.emit(null)},_=m=>{l=a.value,d=m.clientX,window.addEventListener("mousemove",c),window.addEventListener("mouseup",()=>{window.removeEventListener("mousemove",c)},{once:!0})},c=m=>{const E=s.value?.parentElement?.getBoundingClientRect().width??500,y=m.clientX-d;let B=l-y;B<300?B=300:B>.9*E&&(B=.9*E),a.value=B};return(m,E)=>(e.openBlock(),e.createElementBlock("div",{class:e.normalizeClass([{"--open":e.unref(n).sidebar.visible},"baklava-sidebar"]),style:e.normalizeStyle(b.value),ref_key:"el",ref:s},[i.value?(e.openBlock(),e.createElementBlock("div",{key:0,class:"__resizer",onMousedown:_},null,32)):e.createCommentVNode("",!0),u.value?(e.openBlock(),e.createElementBlock(e.Fragment,{key:1},[e.createElementVNode("div",Rn,[e.createElementVNode("button",{tabindex:"-1",class:"__close",onClick:w},"×"),e.createElementVNode("div",jn,[e.createElementVNode("b",null,e.toDisplayString(u.value.title),1)])]),e.createElementVNode("div",Pn,[e.createElementVNode("div",Ln,[(e.openBlock(!0),e.createElementBlock(e.Fragment,null,e.renderList(C.value,y=>(e.openBlock(),e.createElementBlock("div",{key:y.id,class:"__interface"},[e.createElementVNode("div",Dn,[e.createVNode(ue,{modelValue:y.hidden,"onUpdate:modelValue":[B=>y.hidden=B,E[0]||(E[0]=()=>u.value?.events.update.emit(null))],disabled:!y.optional,inversed:"",style:{"padding-right":"8px"}},null,8,["modelValue","onUpdate:modelValue","disabled"]),(e.openBlock(),e.createBlock(e.resolveDynamicComponent(y.component),{modelValue:y.value,"onUpdate:modelValue":B=>y.value=B,node:u.value,intf:y,style:{width:"100%"}},null,8,["modelValue","onUpdate:modelValue","node","intf"]))])]))),128))]),e.createElementVNode("div",zn,[p.value&&p.value.state?(e.openBlock(),e.createElementBlock("div",An,[E[3]||(E[3]=e.createElementVNode("label",null,"Variable name",-1)),e.withDirectives(e.createElementVNode("input",{"onUpdate:modelValue":E[1]||(E[1]=y=>p.value.state.variableName=y),type:"text",class:"baklava-input",title:"Variable name",onBlur:k,onKeydown:e.withKeys(k,["enter"])},null,544),[[e.vModelText,p.value.state.variableName]])])):e.createCommentVNode("",!0),(e.openBlock(!0),e.createElementBlock(e.Fragment,null,e.renderList(h.value,y=>(e.openBlock(),e.createElementBlock("div",{key:y.id,class:"__interface"},[e.createElementVNode("div",Hn,[e.createVNode(ue,{modelValue:y.hidden,"onUpdate:modelValue":[B=>y.hidden=B,E[2]||(E[2]=()=>u.value?.events.update.emit(null))],disabled:!y.optional,inversed:"",style:{"padding-right":"8px"}},null,8,["modelValue","onUpdate:modelValue","disabled"]),(e.openBlock(),e.createBlock(e.resolveDynamicComponent(y.component),{modelValue:y.value,"onUpdate:modelValue":B=>y.value=B,node:u.value,intf:y,style:{width:"100%"}},null,8,["modelValue","onUpdate:modelValue","node","intf"]))])]))),128))])]),e.renderSlot(m.$slots,"codeEditor",{node:u.value})],64)):e.createCommentVNode("",!0)],6))}});class pe extends oe{_title="Subgraph Input";inputs={_code:new x("","").use(I.setType,V).setHidden(!0),name:new f.TextInputInterface("Name","Input").setPort(!1)};outputs={_code:new x("","").use(I.setType,V).setHidden(!0),placeholder:new O.NodeInterface("Connection",void 0)}}class he extends se{_title="Subgraph Output";inputs={_code:new x("","").use(I.setType,V).setHidden(!0),name:new f.TextInputInterface("Name","Output").setPort(!1),placeholder:new O.NodeInterface("Connection",void 0)};outputs={_code:new x("","").use(I.setType,V).setHidden(!0),output:new O.NodeInterface("Output",void 0).setHidden(!0)}}const qe="CREATE_SUBGRAPH",Ye=[O.GRAPH_INPUT_NODE_TYPE,O.GRAPH_OUTPUT_NODE_TYPE];function Ke(o,t,n){const s=()=>o.value.selectedNodes.filter(i=>!Ye.includes(i.type)).length>0,a=()=>{const{viewModel:i}=f.useViewModel(),l=o.value,d=o.value.editor;if(l.selectedNodes.length===0)return;const u=l.selectedNodes.filter(g=>!Ye.includes(g.type)),p=u.flatMap(g=>Object.values(g.inputs)),b=u.flatMap(g=>Object.values(g.outputs)),C=l.connections.filter(g=>!b.includes(g.from)&&p.includes(g.to)),h=l.connections.filter(g=>b.includes(g.from)&&!p.includes(g.to)),w=l.connections.filter(g=>b.includes(g.from)&&p.includes(g.to)),k=u.map(g=>g.save()),_=w.map(g=>({id:g.id,from:g.from.id,to:g.to.id})),c=new Map,{xLeft:m,xRight:E,yTop:y}=Un(u);for(const[g,S]of C.entries()){const $=new pe;$.inputs.name.value=S.to.name,k.push({...$.save(),position:{x:E-i.value.settings.nodes.defaultWidth-100,y:y+g*200}}),_.push({id:j.v4(),from:$.outputs.placeholder.id,to:S.to.id}),c.set(S.to.id,$.graphInterfaceId)}for(const[g,S]of h.entries()){const $=new he;$.inputs.name.value=S.from.name,k.push({...$.save(),position:{x:m+100,y:y+g*200}}),_.push({id:j.v4(),from:S.from.id,to:$.inputs.placeholder.id}),c.set(S.from.id,$.graphInterfaceId)}const B=e.reactive(new z({connections:_,nodes:k,inputs:[],outputs:[]},d));d.addGraphTemplate(B);const W=d.nodeTypes.get(O.getGraphNodeTypeString(B));if(!W)throw new Error("Unable to create subgraph: Could not find corresponding graph node type");l.activeTransactions++;const P=e.reactive(new W.type);l.addNode(P);const me=Math.round(u.map(g=>g.position.x).reduce((g,S)=>g+S,0)/u.length),q=Math.round(u.map(g=>g.position.y).reduce((g,S)=>g+S,0)/u.length);P.position.x=me,P.position.y=q,C.forEach(g=>{l.removeConnection(g),l.addConnection(g.from,P.inputs[c.get(g.to.id)])}),h.forEach(g=>{l.removeConnection(g),l.addConnection(P.outputs[c.get(g.from.id)],g.to)}),u.forEach(g=>l.removeNode(g)),l.activeTransactions--,t.canExecuteCommand(f.Commands.SAVE_SUBGRAPH_COMMAND)&&t.executeCommand(f.Commands.SAVE_SUBGRAPH_COMMAND),n(B),o.value.panning={...l.panning},o.value.scaling=l.scaling};t.registerCommand(qe,{canExecute:s,execute:a})}function Un(o){const t=o.reduce((a,i)=>{const l=i.position.x;return l<a?l:a},1/0),n=o.reduce((a,i)=>{const l=i.position.y;return l<a?l:a},1/0);return{xLeft:o.reduce((a,i)=>{const l=i.position.x+i.width;return l>a?l:a},-1/0),xRight:t,yTop:n}}class Fn extends O.Editor{code;graph;constructor(t){super(),this.code=t,this.graph=new D(this)}get graphIds(){const t=[];return this.graphs.forEach(n=>t.push(n.id)),t.map(n=>n.slice(0,6)).join(", ")}get graphTemplateIds(){const t=[];return this.graphTemplates.forEach(n=>t.push(n.id)),t.map(n=>n.slice(0,6)).join(", ")}addGraphTemplate(t){if(this.events.beforeAddGraphTemplate.emit(t).prevented)return;this._graphTemplates.push(t),this.graphTemplateEvents.addTarget(t.events),this.graphTemplateHooks.addTarget(t.hooks);const n=Ie(t);this.registerNodeType(n,{category:"Subgraphs",title:t.name}),this.events.addGraphTemplate.emit(t)}load(t){try{for(super._loading=!0,t=this.hooks.load.execute(t);this.graphTemplates.length>0;)this.removeGraphTemplate(this.graphTemplates[0]);t.graphTemplates.forEach(s=>{const a=new z(s,this);this.addGraphTemplate(a)});const n=this.graph.load(t.graph);return this.events.loaded.emit(),n.forEach(s=>console.warn(s)),n}finally{super._loading=!1}}registerCategoryModule(t,n){this.code.state.modules[t]=n}}function Wn(o){const t=e.ref(o?.code??new we),n=e.ref(o?.existingEditor??new Fn(t.value)),s=Symbol("ViewModelToken"),a=e.ref(null),i=e.shallowReadonly(a),{switchGraph:l}=He(n,a),d=e.computed(()=>i.value&&i.value!==n.value.graph),u=e.reactive(f.DEFAULT_SETTINGS());u.nodes.defaultWidth=400;const p=f.useCommandHandler(),b=f.useHistory(i,p),C=f.useClipboard(i,n,p),h={renderNode:new fe.SequentialHook(null),renderInterface:new fe.SequentialHook(null)},w=e.reactive({clipboard:C,code:t,commandHandler:p,displayedGraph:i,editor:n,history:b,hooks:h,isSubgraph:d,settings:u,switchGraph:l});return t.value.registerViewModel(w),Ae(w),f.registerDeleteNodesCommand(i,p),Ke(i,p,l),f.registerSaveSubgraphCommand(i,p),f.registerSwitchToMainGraphCommand(i,p,l),f.registerSidebarCommands(i,p),f.registerZoomToFitCommands(i,p,u),Le(i,p,u),De(u),e.watch(n,(k,_)=>{_&&(_.events.registerGraph.unsubscribe(s),_.graphEvents.beforeAddNode.unsubscribe(s),k.nodeHooks.beforeLoad.unsubscribe(s),k.nodeHooks.afterSave.unsubscribe(s),k.graphTemplateHooks.beforeLoad.unsubscribe(s),k.graphTemplateHooks.afterSave.unsubscribe(s),k.graph.hooks.load.unsubscribe(s),k.graph.hooks.save.unsubscribe(s)),k&&(k.nodeHooks.beforeLoad.subscribe(s,(c,m)=>(m.position=c.position??{x:0,y:0},m.width=c.width??u.nodes.defaultWidth,m.twoColumn=c.twoColumn??!1,c)),k.nodeHooks.afterSave.subscribe(s,(c,m)=>(c.position=m.position,c.width=m.width,c.twoColumn=m.twoColumn,c)),k.graphTemplateHooks.beforeLoad.subscribe(s,(c,m)=>(m.panning=c.panning,m.scaling=c.scaling,c)),k.graphTemplateHooks.afterSave.subscribe(s,(c,m)=>(c.panning=m.panning,c.scaling=m.scaling,c)),k.graph.hooks.load.subscribe(s,(c,m)=>(m.panning=c.panning,m.scaling=c.scaling,c)),k.graph.hooks.save.subscribe(s,(c,m)=>(c.panning=m.panning,c.scaling=m.scaling,c)),k.graphEvents.beforeAddNode.subscribe(s,c=>f.setViewNodeProperties(c,{defaultWidth:u.nodes.defaultWidth})),n.value.registerNodeType(pe,{category:"Subgraphs"}),n.value.registerNodeType(he,{category:"Subgraphs"}),l(k.graph))},{immediate:!0}),w}r.AbstractCodeNode=Y,r.CLEAR_ALL_COMMAND=ae,r.CREATE_SUBGRAPH_COMMAND=qe,r.CheckboxInterface=it,r.Code=we,r.CodeEngine=Ee,r.CodeGraph=D,r.CodeGraphEditor=fn,r.CodeGraphInfo=bn,r.CodeGraphInputNode=oe,r.CodeGraphNode=Ue,r.CodeGraphNodeInterface=ce,r.CodeGraphOutputNode=se,r.CodeGraphSidebar=We,r.CodeGraphTemplate=z,r.CodeNode=A,r.CodeNodeInputInterface=L,r.CodeNodeInterface=x,r.CodeNodeInterfaceComponent=H,r.CodeNodeOutputInterface=Ce,r.CodeNodePalette=Fe,r.CodeVariable=ve,r.DotsVertical=Be,r.DynamicCodeNode=Ne,r.GRAPH_INPUT_NODE_TYPE=te,r.GRAPH_OUTPUT_NODE_TYPE=ne,r.IntegerInterface=rt,r.LayoutSidebarLeftCollapse=Te,r.LayoutSidebarLeftExpand=Oe,r.LayoutSidebarRight=xe,r.LayoutSidebarRightCollapse=Me,r.LayoutSidebarRightExpand=Se,r.ListInputInterface=lt,r.LockCode=Ve,r.NumberInterface=dt,r.PlayerPlay=$e,r.RUN_ENGINE_COMMAND=ie,r.Schema=Ge,r.SchemaOff=Re,r.SelectInterface=ct,r.SidebarCheckbox=ue,r.SliderInterface=ut,r.SubgraphInputNode=pe,r.SubgraphOutputNode=he,r.TOGGLE_MINIMAP_COMMAND=re,r.TOGGLE_PALETTE_COMMAND=le,r.TextInputInterface=bt,r.TextInputInterfaceComponent=ye,r.TextareaInputInterface=kt,r.TransitionBottom=je,r.TrashOff=Pe,r.TupleInputInterface=Ct,r.addDefaultInterfaceTypes=at,r.allowMultipleConnections=It,r.booleanType=X,r.createCodeGraphNodeType=Ie,r.defineCodeNode=yt,r.defineDynamicCodeNode=Nt,r.dictType=ke,r.formatInputs=ge,r.getCodeNodes=de,r.getPositionAtColumn=cn,r.getPositionBeforeNode=un,r.listType=J,r.loadNodeState=K,r.nodeType=V,r.numberType=U,r.registerCodeEngine=Ae,r.registerCreateSubgraphCommand=Ke,r.registerCustomCommands=Le,r.registerRunEngineCommands=ze,r.saveNodeState=be,r.stringType=F,r.tupleType=Q,r.updateToolbarItems=De,r.useCodeGraph=Wn,r.useSwitchCodeGraph=He,Object.defineProperty(r,Symbol.toStringTag,{value:"Module"})}));
|
|
4
|
+
This is likely an internal issue. Please report it on GitHub.`);return t.get(n)}}const wt={},Et={xmlns:"http://www.w3.org/2000/svg",width:"24",height:"24",viewBox:"0 0 24 24",fill:"none",stroke:"currentColor","stroke-width":"2","stroke-linecap":"round","stroke-linejoin":"round",class:"baklava-icon icon icon-tabler icons-tabler-outline icon-tabler-code-variable"};function vt(o,t){return e.openBlock(),e.createElementBlock("svg",Et,[...t[0]||(t[0]=[e.createElementVNode("path",{stroke:"none",d:"M0 0h24v24H0z",fill:"none"},null,-1),e.createElementVNode("path",{d:"M4 8m0 2a2 2 0 0 1 2 -2h12a2 2 0 0 1 2 2v4a2 2 0 0 1 -2 2h-12a2 2 0 0 1 -2 -2z"},null,-1)])])}const ve=M(wt,[["render",vt]]),Bt={},Tt={xmlns:"http://www.w3.org/2000/svg",width:"24",height:"24",viewBox:"0 0 24 24",fill:"none",stroke:"currentColor","stroke-width":"2","stroke-linecap":"round","stroke-linejoin":"round",class:"baklava-icon icon icon-tabler icons-tabler-outline icon-tabler-dots-vertical"};function Ot(o,t){return e.openBlock(),e.createElementBlock("svg",Tt,[...t[0]||(t[0]=[e.createElementVNode("path",{stroke:"none",d:"M0 0h24v24H0z",fill:"none"},null,-1),e.createElementVNode("path",{d:"M12 12m-1 0a1 1 0 1 0 2 0a1 1 0 1 0 -2 0"},null,-1),e.createElementVNode("path",{d:"M12 19m-1 0a1 1 0 1 0 2 0a1 1 0 1 0 -2 0"},null,-1),e.createElementVNode("path",{d:"M12 5m-1 0a1 1 0 1 0 2 0a1 1 0 1 0 -2 0"},null,-1)])])}const Be=M(Bt,[["render",Ot]]),xt={},Mt={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",Mt,[...t[0]||(t[0]=[e.createElementVNode("path",{stroke:"none",d:"M0 0h24v24H0z",fill:"none"},null,-1),e.createElementVNode("path",{d:"M18 3a3 3 0 0 1 2.995 2.824l.005 .176v12a3 3 0 0 1 -2.824 2.995l-.176 .005h-12a3 3 0 0 1 -2.995 -2.824l-.005 -.176v-12a3 3 0 0 1 2.824 -2.995l.176 -.005h12zm0 2h-9v14h9a1 1 0 0 0 .993 -.883l.007 -.117v-12a1 1 0 0 0 -.883 -.993l-.117 -.007zm-2.293 4.293a1 1 0 0 1 .083 1.32l-.083 .094l-1.292 1.293l1.292 1.293a1 1 0 0 1 .083 1.32l-.083 .094a1 1 0 0 1 -1.32 .083l-.094 -.083l-2 -2a1 1 0 0 1 -.083 -1.32l.083 -.094l2 -2a1 1 0 0 1 1.414 0z"},null,-1)])])}const Te=M(xt,[["render",St]]),Vt={},$t={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 Gt(o,t){return e.openBlock(),e.createElementBlock("svg",$t,[...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=M(Vt,[["render",Gt]]),Rt={},jt={xmlns:"http://www.w3.org/2000/svg",width:"24",height:"24",viewBox:"0 0 24 24",fill:"currentColor",class:"baklava-icon icon icon-tabler icons-tabler-filled icon-tabler-layout-sidebar-right"};function Pt(o,t){return e.openBlock(),e.createElementBlock("svg",jt,[...t[0]||(t[0]=[e.createElementVNode("path",{stroke:"none",d:"M0 0h24v24H0z",fill:"none"},null,-1),e.createElementVNode("path",{d:"M6 21a3 3 0 0 1 -3 -3v-12a3 3 0 0 1 3 -3h12a3 3 0 0 1 3 3v12a3 3 0 0 1 -3 3zm8 -16h-8a1 1 0 0 0 -1 1v12a1 1 0 0 0 1 1h8z"},null,-1)])])}const xe=M(Rt,[["render",Pt]]),Lt={},Dt={xmlns:"http://www.w3.org/2000/svg",width:"24",height:"24",viewBox:"0 0 24 24",fill:"currentColor",class:"baklava-icon icon icon-tabler icons-tabler-filled icon-tabler-layout-sidebar-right-collapse"};function zt(o,t){return e.openBlock(),e.createElementBlock("svg",Dt,[...t[0]||(t[0]=[e.createElementVNode("path",{stroke:"none",d:"M0 0h24v24H0z",fill:"none"},null,-1),e.createElementVNode("path",{d:"M18 3a3 3 0 0 1 2.995 2.824l.005 .176v12a3 3 0 0 1 -2.824 2.995l-.176 .005h-12a3 3 0 0 1 -2.995 -2.824l-.005 -.176v-12a3 3 0 0 1 2.824 -2.995l.176 -.005h12zm-3 2h-9a1 1 0 0 0 -.993 .883l-.007 .117v12a1 1 0 0 0 .883 .993l.117 .007h9v-14zm-5.387 4.21l.094 .083l2 2a1 1 0 0 1 .083 1.32l-.083 .094l-2 2a1 1 0 0 1 -1.497 -1.32l.083 -.094l1.292 -1.293l-1.292 -1.293a1 1 0 0 1 -.083 -1.32l.083 -.094a1 1 0 0 1 1.32 -.083z"},null,-1)])])}const Me=M(Lt,[["render",zt]]),At={},Ht={xmlns:"http://www.w3.org/2000/svg",width:"24",height:"24",viewBox:"0 0 24 24",fill:"currentColor",class:"baklava-icon icon icon-tabler icons-tabler-filled icon-tabler-layout-sidebar-right-expand"};function Ut(o,t){return e.openBlock(),e.createElementBlock("svg",Ht,[...t[0]||(t[0]=[e.createElementVNode("path",{stroke:"none",d:"M0 0h24v24H0z",fill:"none"},null,-1),e.createElementVNode("path",{d:"M18 3a3 3 0 0 1 2.995 2.824l.005 .176v12a3 3 0 0 1 -2.824 2.995l-.176 .005h-12a3 3 0 0 1 -2.995 -2.824l-.005 -.176v-12a3 3 0 0 1 2.824 -2.995l.176 -.005h12zm-3 2h-9a1 1 0 0 0 -.993 .883l-.007 .117v12a1 1 0 0 0 .883 .993l.117 .007h9v-14zm-3.293 4.293a1 1 0 0 1 .083 1.32l-.083 .094l-1.292 1.293l1.292 1.293a1 1 0 0 1 .083 1.32l-.083 .094a1 1 0 0 1 -1.32 .083l-.094 -.083l-2 -2a1 1 0 0 1 -.083 -1.32l.083 -.094l2 -2a1 1 0 0 1 1.414 0z"},null,-1)])])}const Se=M(At,[["render",Ut]]),Ft={},Wt={xmlns:"http://www.w3.org/2000/svg",width:"24",height:"24",viewBox:"0 0 24 24",fill:"none",stroke:"currentColor","stroke-width":"2","stroke-linecap":"round","stroke-linejoin":"round",class:"baklava-icon icon icon-tabler icons-tabler-outline icon-tabler-lock-code"};function qt(o,t){return e.openBlock(),e.createElementBlock("svg",Wt,[...t[0]||(t[0]=[e.createStaticVNode('<path stroke="none" d="M0 0h24v24H0z" fill="none"></path><path d="M11.5 21h-4.5a2 2 0 0 1 -2 -2v-6a2 2 0 0 1 2 -2h10a2 2 0 0 1 2 2"></path><path d="M11 16a1 1 0 1 0 2 0a1 1 0 0 0 -2 0"></path><path d="M8 11v-4a4 4 0 1 1 8 0v4"></path><path d="M20 21l2 -2l-2 -2"></path><path d="M17 17l-2 2l2 2"></path>',6)])])}const Ve=M(Ft,[["render",qt]]),Yt={},Kt={xmlns:"http://www.w3.org/2000/svg",width:"24",height:"24",viewBox:"0 0 24 24",fill:"none",stroke:"currentColor","stroke-width":"2","stroke-linecap":"round","stroke-linejoin":"round",class:"baklava-icon icon icon-tabler icons-tabler-outline icon-tabler-player-play"};function Xt(o,t){return e.openBlock(),e.createElementBlock("svg",Kt,[...t[0]||(t[0]=[e.createElementVNode("path",{stroke:"none",d:"M0 0h24v24H0z",fill:"none"},null,-1),e.createElementVNode("path",{d:"M7 4v16l13 -8z"},null,-1)])])}const $e=M(Yt,[["render",Xt]]),Jt={},Qt={xmlns:"http://www.w3.org/2000/svg",width:"24",height:"24",viewBox:"0 0 24 24",fill:"none",stroke:"currentColor","stroke-width":"2","stroke-linecap":"round","stroke-linejoin":"round",class:"baklava-icon icon icon-tabler icons-tabler-outline icon-tabler-schema"};function Zt(o,t){return e.openBlock(),e.createElementBlock("svg",Qt,[...t[0]||(t[0]=[e.createStaticVNode('<path stroke="none" d="M0 0h24v24H0z" fill="none"></path><path d="M5 2h5v4h-5z"></path><path d="M15 10h5v4h-5z"></path><path d="M5 18h5v4h-5z"></path><path d="M5 10h5v4h-5z"></path><path d="M10 12h5"></path><path d="M7.5 6v4"></path><path d="M7.5 14v4"></path>',8)])])}const Ge=M(Jt,[["render",Zt]]),en={},tn={xmlns:"http://www.w3.org/2000/svg",width:"24",height:"24",viewBox:"0 0 24 24",fill:"none",stroke:"currentColor","stroke-width":"2","stroke-linecap":"round","stroke-linejoin":"round",class:"baklava-icon icon icon-tabler icons-tabler-outline icon-tabler-schema-off"};function nn(o,t){return e.openBlock(),e.createElementBlock("svg",tn,[...t[0]||(t[0]=[e.createStaticVNode('<path stroke="none" d="M0 0h24v24H0z" fill="none"></path><path d="M6 2h4v4m-4 0h-1v-1"></path><path d="M15 11v-1h5v4h-2"></path><path d="M5 18h5v4h-5z"></path><path d="M5 10h5v4h-5z"></path><path d="M10 12h2"></path><path d="M7.5 7.5v2.5"></path><path d="M7.5 14v4"></path><path d="M3 3l18 18"></path>',9)])])}const Re=M(en,[["render",nn]]),on={},sn={xmlns:"http://www.w3.org/2000/svg",width:"24",height:"24",viewBox:"0 0 24 24",fill:"none",stroke:"currentColor","stroke-width":"2","stroke-linecap":"round","stroke-linejoin":"round",class:"baklava-icon icon icon-tabler icons-tabler-outline icon-tabler-transition-bottom"};function an(o,t){return e.openBlock(),e.createElementBlock("svg",sn,[...t[0]||(t[0]=[e.createStaticVNode('<path stroke="none" d="M0 0h24v24H0z" fill="none"></path><path d="M21 18a3 3 0 0 1 -3 3h-12a3 3 0 0 1 -3 -3"></path><path d="M3 3m0 3a3 3 0 0 1 3 -3h12a3 3 0 0 1 3 3v0a3 3 0 0 1 -3 3h-12a3 3 0 0 1 -3 -3z"></path><path d="M12 9v8"></path><path d="M9 14l3 3l3 -3"></path>',5)])])}const je=M(on,[["render",an]]),rn={},ln={xmlns:"http://www.w3.org/2000/svg",width:"24",height:"24",viewBox:"0 0 24 24",fill:"none",stroke:"currentColor","stroke-width":"2","stroke-linecap":"round","stroke-linejoin":"round",class:"baklava-icon icon icon-tabler icons-tabler-outline icon-tabler-trash-off"};function dn(o,t){return e.openBlock(),e.createElementBlock("svg",ln,[...t[0]||(t[0]=[e.createStaticVNode('<path stroke="none" d="M0 0h24v24H0z" fill="none"></path><path d="M3 3l18 18"></path><path d="M4 7h3m4 0h9"></path><path d="M10 11l0 6"></path><path d="M14 14l0 3"></path><path d="M5 7l1 12a2 2 0 0 0 2 2h8a2 2 0 0 0 2 -2l.077 -.923"></path><path d="M18.384 14.373l.616 -7.373"></path><path d="M9 5v-1a1 1 0 0 1 1 -1h4a1 1 0 0 1 1 1v3"></path>',8)])])}const Pe=M(rn,[["render",dn]]),ae="CLEAR_ALL",ie="RUN_ENGINE",re="TOGGLE_MINIMAP",le="TOGGLE_PALETTE",Le=(o,t,n)=>{const s=n.zoomToFit.paddingLeft;t.registerCommand(le,{execute:()=>{n.palette.enabled=!n.palette.enabled,n.zoomToFit.paddingLeft=n.palette.enabled?s:50},canExecute:()=>!0}),t.registerCommand(ae,{execute:()=>o.value.clear(),canExecute:()=>o.value.nodes.length>0}),t.registerCommand(re,{execute:()=>n.enableMinimap=!n.enableMinimap,canExecute:()=>o.value.nodes.length>1})},De=o=>{const t={command:ie,title:"Run",icon:e.computed(()=>$e)},n={command:le,title:"Toggle palette",icon:e.computed(()=>o.palette.enabled?Te:Oe)},s={command:ae,title:"Clear all",icon:e.computed(()=>Pe)},a={command:re,title:"Toggle minimap",icon:e.computed(()=>o.enableMinimap?Re:Ge)};o.toolbar.commands=[n,t,...f.DEFAULT_TOOLBAR_COMMANDS,s,a]},ze=(o,t)=>{t.registerCommand(ie,{execute:()=>o.runOnce(null),canExecute:()=>!0})};function Ae(o){const t=Symbol("CodeEngineToken");o.engine=new Ee(o.editor),ze(o.engine,o.commandHandler),o.loadEditor=n=>{o.engine?.pause(),o.displayedGraph.clear(),o.editor.load(n),o.commandHandler.executeCommand(f.Commands.CLEAR_CLIPBOARD_COMMAND),o.commandHandler.executeCommand(f.Commands.CLEAR_HISTORY_COMMAND),o.engine?.resume(),o.engine?.runOnce(null)},o.newGraph=()=>{o.engine?.pause(),o.displayedGraph.clear(),o.commandHandler.executeCommand(f.Commands.CLEAR_CLIPBOARD_COMMAND),o.commandHandler.executeCommand(f.Commands.CLEAR_HISTORY_COMMAND),o.displayedGraph.id=j.v4(),o.engine?.resume(),o.engine?.runOnce(null)},o.subscribe=()=>{o.displayedGraph.events.addConnection.subscribe(t,n=>{const s=o.displayedGraph.findNodeById(n.to.nodeId);s&&s.isCodeNode&&s.onConnected();const a=o.displayedGraph.findNodeById(n.from.nodeId);a&&a.isCodeNode&&a.onConnected()}),o.displayedGraph.events.removeConnection.subscribe(t,n=>{const s=o.displayedGraph.findNodeById(n.to.nodeId);s&&s.isCodeNode&&s.onUnconnected();const a=o.displayedGraph.findNodeById(n.from.nodeId);a&&a.isCodeNode&&a.onUnconnected()}),o.engine?.events.beforeRun.subscribe(t,()=>{o.engine?.pause(),o.displayedGraph.sortNodes(),o.engine?.resume()}),o.engine?.events.afterRun.subscribe(t,n=>{o.engine?.pause(),R.applyResult(n,o.editor),o.code.state.lockCode||o.code.renderCode({nodes:o.editor.graph.scriptedCodeNodes,modules:o.editor.code.modules}),o.engine?.resume()})},o.unsubscribe=()=>{o.displayedGraph.events.addConnection.unsubscribe(t),o.displayedGraph.events.removeConnection.unsubscribe(t),o.engine?.events.beforeRun.unsubscribe(t),o.engine?.events.afterRun.unsubscribe(t)}}class D extends O.Graph{code=null;editor;_state=e.reactive({codeTemplate:"{{ #nodes }}{{ script }}{{ /nodes }}",lockCode:!1});constructor(t,n){super(t,n),this.editor=t,this.template=n,t.code&&(this.code=t.code)}get codeNodes(){return de(this)}get connections(){return super.connections}set connections(t){this._connections=t}get nodeIds(){return this.nodes.map(t=>t.id)}get nodes(){return super.nodes}set nodes(t){this._nodes=t}get scriptedCodeNodes(){return this.nodes.filter(t=>!t.state?.integrated)}get shortId(){return this.id.slice(0,6)}get state(){return this._state}get visibleNodes(){return this.nodes.filter(t=>!t.state?.hidden)}addNodeAtCoordinates=(t,n={x:0,y:0},s)=>(this.addNode(t,s),t.position&&(t.position=n),t);addConnection(t,n){t?.name!=="_code"&&(t.hidden=!1),n?.name!=="_code"&&(n.hidden=!1),super.addConnection(t,n)}clear(){this.selectedNodes=[],this._nodes=[],this._connections=[]}findNodeByType(t){return this.nodes.find(n=>n.type===t)}getNodesBySameType(t){return this.nodes.filter(n=>n.type===t)}getNodesBySameVariableNames(t){return this.nodes.filter(n=>n.state?.variableName===t)}hasConnection(t,n){return this.connections.some(s=>s.from.id===t.id&&s.to.id===n.id)}renderCode(t){return G.render(this.state?.codeTemplate||"",t)}sortNodes(){if(!(this.nodes.length===0||this.connections.length===0))try{let t=this.nodeIds;const n=this.connections.filter(i=>t.includes(i.to.nodeId)&&t.includes(i.from.nodeId)).map(i=>[i.to.nodeId,i.from.nodeId]);t.reverse(),t=nt.array(t,n),t.reverse();const s=this.nodes.map(i=>i.id).filter(i=>!t.includes(i));t=[...t,...s];const a=t.map(i=>this.findNodeById(i));a&&(this.nodes=a)}catch{console.warn("Failed to sort nodes.")}}}const de=o=>{const t=[];return o.nodes.length===0||o.nodes.forEach(n=>{n&&(n.hasOwnProperty("subgraph")?t.push(...de(n.subgraph)):n.hasOwnProperty("isCodeNode")&&t.push(n))}),t},cn=(o=0,t=100)=>({x:o*420,y:t}),un=o=>{const t={...o.position};return t.x-=440,t.y+=50,t};function pn(o,t){return Object.fromEntries(Object.entries(o).filter(t))}function hn(o,t){return Object.fromEntries(Object.entries(o).map(([n,s])=>[n,t(s)]))}class z extends O.GraphTemplate{static fromGraph(t,n){return new z(t.save(),n)}constructor(t,n){super(t,n)}get shortId(){return this.id.slice(0,6)}createGraph(t){const n=new Map,s=h=>{const w=j.v4();return n.set(h,w),w},a=h=>{const w=n.get(h);if(!w)throw new Error(`Unable to create graph from template: Could not map old id ${h} to new id`);return w},i=h=>hn(h,w=>({id:s(w.id),templateId:w.id,value:w.value})),l=this.nodes.map(h=>({...h,id:s(h.id),inputs:i(h.inputs),outputs:i(h.outputs)})),d=this.connections.map(h=>({id:s(h.id),from:a(h.from),to:a(h.to)})),u=this.inputs.map(h=>({id:h.id,name:h.name,nodeId:a(h.nodeId),nodeInterfaceId:a(h.nodeInterfaceId)})),p=this.outputs.map(h=>({id:h.id,name:h.name,nodeId:a(h.nodeId),nodeInterfaceId:a(h.nodeInterfaceId)})),b={id:j.v4(),nodes:l,connections:d,inputs:u,outputs:p};return t||(t=new D(this.editor)),t.load(b).forEach(h=>console.warn(h)),t.template=this,t}}const mn=o=>!(o instanceof D);function He(o,t){return{switchGraph:s=>{let a;if(mn(s))a=new D(o.value),s.createGraph(a);else{if(s!==o.value.graph)throw new Error("Can only switch using 'Graph' instance when it is the root graph. Otherwise a 'GraphTemplate' must be used.");a=s}t.value&&t.value!==o.value.graph&&t.value.destroy(),a.panning=a.panning??s.panning??{x:0,y:0},a.scaling=a.scaling??s.scaling??1,a.selectedNodes=a.selectedNodes??[],a.sidebar=a.sidebar??{visible:!1,nodeId:"",optionName:""},t.value=a,a.code?.engine?.runOnce(null)}}}const fn=e.defineComponent({__name:"CodeGraphEditor",props:{viewModel:{}},setup(o){const t=o,n=e.toRef(t,"viewModel"),s=a=>a.events.update.emit(null);return e.onMounted(()=>{n.value.subscribe&&n.value.subscribe(),n.value.engine?.start()}),e.onBeforeUnmount(()=>{n.value.unsubscribe&&n.value.unsubscribe(),n.value.engine?.stop()}),e.watch(n,(a,i)=>{i&&i.unsubscribe(),a&&a.subscribe()}),(a,i)=>(e.openBlock(),e.createBlock(e.unref(f.BaklavaEditor),{viewModel:n.value},{palette:e.withCtx(()=>[e.createVNode(e.unref(Fe))]),node:e.withCtx(l=>[e.createVNode(e.unref(Ue),e.mergeProps(l,{onUpdate:d=>s(l.node)}),null,16,["onUpdate"])]),sidebar:e.withCtx(l=>[e.createVNode(e.unref(We),e.normalizeProps(e.guardReactiveProps(l)),{codeEditor:e.withCtx(({node:d})=>[e.renderSlot(a.$slots,"sidebarCodeEditor",{node:d})]),_:3},16)]),_:3},8,["viewModel"]))}}),gn={class:"code-graph-info"},bn=e.defineComponent({__name:"CodeGraphInfo",props:{viewModel:{}},setup(o){return(t,n)=>(e.openBlock(),e.createElementBlock("div",gn,[e.createElementVNode("div",null,"Editor graph: "+e.toDisplayString(o.viewModel.editor.graph.shortId),1),e.createElementVNode("div",null,"Displayed graph: "+e.toDisplayString(o.viewModel.displayedGraph.shortId),1),e.createElementVNode("div",null,"Graphs: "+e.toDisplayString(o.viewModel.editor.graphIds),1),e.createElementVNode("div",null,"Graph templates: "+e.toDisplayString(o.viewModel.editor.graphTemplateIds),1),e.createElementVNode("div",null,"Engine status: "+e.toDisplayString(o.viewModel.engine?.status),1)]))}}),kn=["id","data-node-type"],Cn={class:"__title-label",style:{"flex-grow":"1"}},yn={key:0},Nn={class:"__menu",style:{display:"flex"}},_n={class:"__outputs"},In={key:0},wn=["id","title"],En={class:"__inputs"},vn={key:0},Bn=["id","title"],Ue=e.defineComponent({__name:"CodeGraphNode",props:{node:{},selected:{type:Boolean,default:!1},dragging:{type:Boolean}},emits:["select","start-drag","update"],setup(o,{emit:t}){const n=f.Components.ContextMenu,s=f.Components.NodeInterface,a=o,i=e.computed(()=>a.node),l=t,{viewModel:d}=f.useViewModel(),{graph:u,switchGraph:p}=f.useGraph(),b=e.ref(null),C=e.ref(!1),h=e.ref(""),w=e.ref(null),k=e.ref(!1);let _=0,c=0;const m=e.ref(!1),E=e.computed(()=>{const N=[{value:"edit",label:"Edit"},{value:"rename",label:"Rename"},{value:"delete",label:"Delete"}];return a.node.type.startsWith(O.GRAPH_NODE_TYPE_PREFIX)&&N.push({value:"editSubgraph",label:"Edit Subgraph"}),N}),y=e.computed(()=>({"--selected":a.selected,"--dragging":a.dragging,"--two-column":!!a.node.twoColumn,"--hidden":i.value.state?.hidden})),B=e.computed(()=>({"--reverse-y":a.node.reverseY??d.value.settings.nodes.reverseY})),W=e.computed(()=>({top:`${a.node.position?.y??0}px`,left:`${a.node.position?.x??0}px`,"--width":`${a.node.width??d.value.settings.nodes.defaultWidth}px`})),P=e.computed(()=>Object.values(a.node.inputs).filter(N=>!N.hidden)),me=e.computed(()=>Object.values(a.node.outputs).filter(N=>!N.hidden)),q=()=>{l("select")},g=N=>{a.selected||q(),l("start-drag",N)},S=()=>{m.value=!0},$=()=>{const N=d.value.displayedGraph.sidebar;N.nodeId="",N.visible=!1},Xe=()=>{const N=d.value.displayedGraph.sidebar;N.nodeId=a.node.id,N.visible=!0},qn=()=>{const N=d.value.displayedGraph.sidebar;N.nodeId=a.node.id},Yn=async N=>{switch(N){case"edit":Xe();break;case"delete":u.value.removeNode(a.node);break;case"rename":h.value=a.node.title,C.value=!0,await e.nextTick(),w.value?.focus();break;case"editSubgraph":p(a.node.template);break}},Je=()=>{i.value.title=h.value,C.value=!1},Qe=()=>{b.value&&d.value.hooks.renderNode.execute({node:a.node,el:b.value})},Kn=N=>{k.value=!0,_=a.node.width,c=N.clientX,N.preventDefault()},Ze=N=>{i.value.state&&(i.value.state.integrated=N,l("update"))},et=N=>{if(!k.value)return;const T=N.clientX-c,v=_+T/u.value.scaling,Xn=d.value.settings.nodes.minWidth,Jn=d.value.settings.nodes.maxWidth;i.value.width=Math.max(Xn,Math.min(Jn,v))},tt=()=>{k.value=!1};return e.onMounted(()=>{Qe(),window.addEventListener("mousemove",et),window.addEventListener("mouseup",tt)}),e.onUpdated(Qe),e.onBeforeUnmount(()=>{window.removeEventListener("mousemove",et),window.removeEventListener("mouseup",tt)}),(N,T)=>(e.openBlock(),e.createElementBlock("div",{id:i.value.id,ref_key:"el",ref:b,class:e.normalizeClass([y.value,"baklava-node"]),"data-node-type":i.value.type,style:e.normalizeStyle(W.value),onPointerdown:q},[e.unref(d).settings.nodes.resizable?(e.openBlock(),e.createElementBlock("div",{key:0,class:"__resize-handle",onMousedown:Kn},null,32)):e.createCommentVNode("",!0),e.createElementVNode("div",{class:"__title",onPointerdown:e.withModifiers(g,["self","stop"]),onContextmenu:e.withModifiers(S,["prevent"])},[i.value.inputs._code?(e.openBlock(),e.createBlock(e.unref(ce),{key:0,node:i.value,intf:i.value.inputs._code,title:i.value.inputs._code.value,class:"--input","data-interface-type":"node",style:{"flex-grow":"0"}},null,8,["node","intf","title"])):e.createCommentVNode("",!0),C.value?e.withDirectives((e.openBlock(),e.createElementBlock("input",{key:2,ref_key:"renameInputEl",ref:w,"onUpdate:modelValue":T[4]||(T[4]=v=>h.value=v),class:"baklava-input",placeholder:"Node Name",style:{"flex-grow":"1"},type:"text",onBlur:Je,onKeydown:e.withKeys(Je,["enter"])},null,544)),[[e.vModelText,h.value]]):(e.openBlock(),e.createElementBlock(e.Fragment,{key:1},[e.createElementVNode("div",Cn,[i.value.idx>-1?(e.openBlock(),e.createElementBlock("span",yn,e.toDisplayString(i.value.idx+1)+" - ",1)):e.createCommentVNode("",!0),e.createTextVNode(e.toDisplayString(i.value.title)+" "+e.toDisplayString(i.value.graph.shortId)+" "+e.toDisplayString(i.value.shortId),1)]),e.createElementVNode("div",Nn,[i.value.isCodeNode?(e.openBlock(),e.createElementBlock(e.Fragment,{key:0},[i.value.state.lockCode?(e.openBlock(),e.createBlock(e.unref(Ve),{key:0,class:"--clickable mx-1",onClick:T[0]||(T[0]=v=>i.value.lockCode=!1)})):e.createCommentVNode("",!0),i.value.state.integrated?(e.openBlock(),e.createBlock(e.unref(ve),{key:1,class:"--clickable mx-1",onClick:T[1]||(T[1]=v=>Ze(!1))})):(e.openBlock(),e.createBlock(e.unref(je),{key:2,class:"--clickable mx-1",onClick:T[2]||(T[2]=v=>Ze(!0))})),!e.unref(d).displayedGraph.sidebar.visible&&e.unref(d).displayedGraph.sidebar.nodeId!==i.value.id?(e.openBlock(),e.createBlock(e.unref(Se),{key:3,class:"--clickable mx-1",onClick:Xe})):e.unref(d).displayedGraph.sidebar.visible&&e.unref(d).displayedGraph.sidebar.nodeId!==i.value.id?(e.openBlock(),e.createBlock(e.unref(xe),{key:4,class:"--clickable mx-1",onClick:qn})):(e.openBlock(),e.createBlock(e.unref(Me),{key:5,class:"--clickable mx-1",onClick:$}))],64)):e.createCommentVNode("",!0),e.createVNode(e.unref(Be),{class:"--clickable mx-1",onClick:S}),e.createVNode(e.unref(n),{modelValue:m.value,"onUpdate:modelValue":T[3]||(T[3]=v=>m.value=v),x:0,y:0,items:E.value,onClick:Yn},null,8,["modelValue","items"])])],64)),i.value.outputs._code?(e.openBlock(),e.createBlock(e.unref(ce),{key:3,node:i.value,intf:i.value.outputs._code,class:"--output",title:i.value.outputs._code.value,"data-interface-type":"node"},null,8,["node","intf","title"])):e.createCommentVNode("",!0)],32),e.createElementVNode("div",{class:e.normalizeClass(["__content",B.value]),onKeydown:T[5]||(T[5]=e.withKeys(e.withModifiers(()=>{},["stop"]),["delete"])),onContextmenu:T[6]||(T[6]=e.withModifiers(()=>{},["prevent"]))},[e.createElementVNode("div",_n,[(e.openBlock(!0),e.createElementBlock(e.Fragment,null,e.renderList(me.value,v=>(e.openBlock(),e.createElementBlock(e.Fragment,{key:v.id},[i.value.state?.hidden?(e.openBlock(),e.createElementBlock("div",In,[v.port?(e.openBlock(),e.createElementBlock("div",{key:0,id:v.id,title:v.name,class:"baklava-node-interface --output --connected"},[...T[7]||(T[7]=[e.createElementVNode("div",{class:"__port"},null,-1)])],8,wn)):e.createCommentVNode("",!0)])):e.renderSlot(N.$slots,"nodeInterface",{key:1,type:"output",node:i.value,intf:v},()=>[e.createVNode(e.unref(s),{node:i.value,intf:v,title:v.value},null,8,["node","intf","title"])])],64))),128))]),e.createElementVNode("div",En,[(e.openBlock(!0),e.createElementBlock(e.Fragment,null,e.renderList(P.value,v=>(e.openBlock(),e.createElementBlock(e.Fragment,{key:v.id},[i.value.state?.hidden?(e.openBlock(),e.createElementBlock("div",vn,[v.port?(e.openBlock(),e.createElementBlock("div",{key:0,id:v.id,title:v.name,class:"baklava-node-interface --input --connected"},[...T[8]||(T[8]=[e.createElementVNode("div",{class:"__port"},null,-1)])],8,Bn)):e.createCommentVNode("",!0)])):e.renderSlot(N.$slots,"nodeInterface",{key:1,node:i.value,intf:v,type:"input"},()=>[e.createVNode(e.unref(s),{node:i.value,intf:v,title:v.value},null,8,["node","intf","title"])])],64))),128))])],34)],46,kn))}}),Tn=["id"],On={class:"align-middle"},ce=e.defineComponent({__name:"CodeGraphNodeInterface",props:{node:{},intf:{}},setup(o){const t=o,{viewModel:n}=f.useViewModel(),{hoveredOver:s,temporaryConnection:a}=f.useTemporaryConnection(),i=e.ref(null),l=e.computed(()=>t.intf.connectionCount>0),d=e.computed(()=>({"--connected":l.value})),u=()=>{s(t.intf)},p=()=>{s(void 0)},b=()=>{i.value&&n.value.hooks.renderInterface.execute({intf:t.intf,el:i.value})};return e.onMounted(b),e.onUpdated(b),(C,h)=>(e.openBlock(),e.createElementBlock("div",{id:o.intf.id,ref_key:"el",ref:i,class:e.normalizeClass(["baklava-node-interface",d.value])},[o.intf.port?(e.openBlock(),e.createElementBlock("div",{key:0,class:e.normalizeClass(["__port",{"--selected":e.unref(a)?.from===o.intf}]),onPointerover:u,onPointerout:p},null,34)):e.createCommentVNode("",!0),e.createElementVNode("span",On,[e.renderSlot(C.$slots,"default")])],10,Tn))}}),xn={class:"baklava-node --palette",style:{"margin-top":"-20px","margin-bottom":"20px"}},Mn={key:0,style:{display:"flex","justify-content":"space-between"}},Sn=["onClick"],Vn={key:0,style:{margin:"auto 0","font-size":"12px"}},Fe=e.defineComponent({__name:"CodeNodePalette",setup(o){const t=f.Components.PaletteEntry,{viewModel:n}=f.useViewModel(),{x:s,y:a}=ot.usePointer(),{transform:i}=f.useTransform(),l=f.useNodeCategories(n),d=e.inject("editorEl"),u=e.ref(""),p=e.ref(null),b=()=>u.value?l.value.filter(k=>k.name.toLowerCase().includes(u.value.toLowerCase())||Object.values(k.nodeTypes).some(_=>_.title.toLowerCase().includes(u.value.toLowerCase()))):l.value,C=k=>u.value?pn(k,_=>{const c=_[1];return c.category.includes(u.value.toLowerCase())||c.title?.toLowerCase().includes(u.value.toLowerCase())}):k,h=e.computed(()=>{if(!p.value||!d?.value)return{};const{left:k,top:_}=d.value.getBoundingClientRect();return{top:`${a.value-_}px`,left:`${s.value-k}px`}}),w=(k,_)=>{p.value={type:k,nodeInformation:_};const c=()=>{const m=e.reactive(new _.type);n.value.displayedGraph.addNode(m);const E=d.value.getBoundingClientRect(),[y,B]=i(s.value-E.left,a.value-E.top);m.position.x=y,m.position.y=B,p.value=null,document.removeEventListener("pointerup",c)};document.addEventListener("pointerup",c)};return(k,_)=>(e.openBlock(),e.createElementBlock(e.Fragment,null,[e.createElementVNode("div",{class:e.normalizeClass([{"--open":e.unref(n).settings.palette.enabled},"baklava-node-palette"]),onContextmenu:_[1]||(_[1]=e.withModifiers(()=>{},["stop","prevent"]))},[e.createElementVNode("div",xn,[e.withDirectives(e.createElementVNode("input",{"onUpdate:modelValue":_[0]||(_[0]=c=>u.value=c),type:"text",class:"baklava-input",title:"Filter nodes",onKeyup:b},null,544),[[e.vModelText,u.value]])]),(e.openBlock(!0),e.createElementBlock(e.Fragment,null,e.renderList(b(),c=>(e.openBlock(),e.createElementBlock("section",{key:c.name},[c.name!=="default"?(e.openBlock(),e.createElementBlock("h3",Mn,[e.createElementVNode("div",{onClick:m=>u.value=c.name,style:{cursor:"pointer"}},e.toDisplayString(c.name),9,Sn),Object.keys(C(c.nodeTypes)).length<Object.values(c.nodeTypes).length?(e.openBlock(),e.createElementBlock("div",Vn," ( "+e.toDisplayString(Object.keys(C(c.nodeTypes)).length)+" / "+e.toDisplayString(Object.values(c.nodeTypes).length)+" ) ",1)):e.createCommentVNode("",!0)])):e.createCommentVNode("",!0),(e.openBlock(!0),e.createElementBlock(e.Fragment,null,e.renderList(C(c.nodeTypes),(m,E)=>(e.openBlock(),e.createBlock(e.unref(t),{key:E,type:E,title:m.title,onPointerdown:y=>w(E,m)},null,8,["type","title","onPointerdown"]))),128))]))),128))],34),e.createVNode(e.Transition,{name:"fade"},{default:e.withCtx(()=>[p.value?(e.openBlock(),e.createElementBlock("div",{key:0,class:"baklava-dragged-node",style:e.normalizeStyle(h.value)},[e.createVNode(e.unref(t),{type:p.value.type,title:p.value.nodeInformation.title},null,8,["type","title"])],4)):e.createCommentVNode("",!0)]),_:1})],64))}}),$n=["title"],Gn={key:0,class:"__label"},ue=e.defineComponent({__name:"SidebarCheckbox",props:{disabled:{type:Boolean},inversed:{type:Boolean},modelValue:{type:Boolean},name:{}},emits:["update:modelValue"],setup(o,{emit:t}){const n=t;return(s,a)=>(e.openBlock(),e.createElementBlock("div",{class:e.normalizeClass(["baklava-checkbox",{"--checked":o.inversed?!o.modelValue:o.modelValue,"--disabled":o.disabled}]),title:o.name,onClick:a[0]||(a[0]=i=>n("update:modelValue",!o.modelValue))},[a[1]||(a[1]=e.createElementVNode("div",{class:"__checkmark-container"},[e.createElementVNode("svg",{xmlns:"http://www.w3.org/2000/svg",width:"18",height:"18",viewBox:"0 0 18 18"},[e.createElementVNode("path",{class:"__checkmark",d:"M 6 5 L 6 10 L 16 10",transform:"rotate(-45 10 10)"})])],-1)),o.name?(e.openBlock(),e.createElementBlock("div",Gn,e.toDisplayString(o.name),1)):e.createCommentVNode("",!0)],10,$n))}}),Rn={class:"__header"},jn={class:"__node-name"},Pn={class:"__interfaces"},Ln={class:"__inputs"},Dn={style:{display:"flex"}},zn={class:"__outputs"},An={key:0,class:"__interface"},Hn={style:{display:"flex"}},We=e.defineComponent({__name:"CodeGraphSidebar",setup(o){const{viewModel:t}=f.useViewModel(),{graph:n}=f.useGraph(),s=e.ref(null),a=e.toRef(t.value.settings.sidebar,"width"),i=e.computed(()=>t.value.settings.sidebar.resizable);let l=0,d=0;const u=e.computed(()=>{const m=n.value.sidebar.nodeId;return n.value.nodes.find(E=>E.id===m)}),p=e.computed(()=>u.value),b=e.computed(()=>({width:`${a.value}px`})),C=e.computed(()=>p.value?Object.values(p.value.inputs).filter(m=>m.displayInSidebar&&m.component):[]),h=e.computed(()=>p.value?Object.values(p.value.outputs).filter(m=>m.displayInSidebar&&m.component):[]),w=()=>{n.value.sidebar.visible=!1},k=()=>{u.value?.events.update.emit(null)},_=m=>{l=a.value,d=m.clientX,window.addEventListener("mousemove",c),window.addEventListener("mouseup",()=>{window.removeEventListener("mousemove",c)},{once:!0})},c=m=>{const E=s.value?.parentElement?.getBoundingClientRect().width??500,y=m.clientX-d;let B=l-y;B<300?B=300:B>.9*E&&(B=.9*E),a.value=B};return(m,E)=>(e.openBlock(),e.createElementBlock("div",{class:e.normalizeClass([{"--open":e.unref(n).sidebar.visible},"baklava-sidebar"]),style:e.normalizeStyle(b.value),ref_key:"el",ref:s},[i.value?(e.openBlock(),e.createElementBlock("div",{key:0,class:"__resizer",onMousedown:_},null,32)):e.createCommentVNode("",!0),u.value?(e.openBlock(),e.createElementBlock(e.Fragment,{key:1},[e.createElementVNode("div",Rn,[e.createElementVNode("button",{tabindex:"-1",class:"__close",onClick:w},"×"),e.createElementVNode("div",jn,[e.createElementVNode("b",null,e.toDisplayString(u.value.title),1)])]),e.createElementVNode("div",Pn,[e.createElementVNode("div",Ln,[(e.openBlock(!0),e.createElementBlock(e.Fragment,null,e.renderList(C.value,y=>(e.openBlock(),e.createElementBlock("div",{key:y.id,class:"__interface"},[e.createElementVNode("div",Dn,[e.createVNode(ue,{modelValue:y.hidden,"onUpdate:modelValue":[B=>y.hidden=B,E[0]||(E[0]=()=>u.value?.events.update.emit(null))],disabled:!y.optional,inversed:"",style:{"padding-right":"8px"}},null,8,["modelValue","onUpdate:modelValue","disabled"]),(e.openBlock(),e.createBlock(e.resolveDynamicComponent(y.component),{modelValue:y.value,"onUpdate:modelValue":B=>y.value=B,node:u.value,intf:y,style:{width:"100%"}},null,8,["modelValue","onUpdate:modelValue","node","intf"]))])]))),128))]),e.createElementVNode("div",zn,[p.value&&p.value.state?(e.openBlock(),e.createElementBlock("div",An,[E[3]||(E[3]=e.createElementVNode("label",null,"Variable name",-1)),e.withDirectives(e.createElementVNode("input",{"onUpdate:modelValue":E[1]||(E[1]=y=>p.value.state.variableName=y),type:"text",class:"baklava-input",title:"Variable name",onBlur:k,onKeydown:e.withKeys(k,["enter"])},null,544),[[e.vModelText,p.value.state.variableName]])])):e.createCommentVNode("",!0),(e.openBlock(!0),e.createElementBlock(e.Fragment,null,e.renderList(h.value,y=>(e.openBlock(),e.createElementBlock("div",{key:y.id,class:"__interface"},[e.createElementVNode("div",Hn,[e.createVNode(ue,{modelValue:y.hidden,"onUpdate:modelValue":[B=>y.hidden=B,E[2]||(E[2]=()=>u.value?.events.update.emit(null))],disabled:!y.optional,inversed:"",style:{"padding-right":"8px"}},null,8,["modelValue","onUpdate:modelValue","disabled"]),(e.openBlock(),e.createBlock(e.resolveDynamicComponent(y.component),{modelValue:y.value,"onUpdate:modelValue":B=>y.value=B,node:u.value,intf:y,style:{width:"100%"}},null,8,["modelValue","onUpdate:modelValue","node","intf"]))])]))),128))])]),e.renderSlot(m.$slots,"codeEditor",{node:u.value})],64)):e.createCommentVNode("",!0)],6))}});class pe extends oe{_title="Subgraph Input";inputs={_code:new x("","").use(I.setType,V).setHidden(!0),name:new f.TextInputInterface("Name","Input").setPort(!1)};outputs={_code:new x("","").use(I.setType,V).setHidden(!0),placeholder:new O.NodeInterface("Connection",void 0)}}class he extends se{_title="Subgraph Output";inputs={_code:new x("","").use(I.setType,V).setHidden(!0),name:new f.TextInputInterface("Name","Output").setPort(!1),placeholder:new O.NodeInterface("Connection",void 0)};outputs={_code:new x("","").use(I.setType,V).setHidden(!0),output:new O.NodeInterface("Output",void 0).setHidden(!0)}}const qe="CREATE_SUBGRAPH",Ye=[O.GRAPH_INPUT_NODE_TYPE,O.GRAPH_OUTPUT_NODE_TYPE];function Ke(o,t,n){const s=()=>o.value.selectedNodes.filter(i=>!Ye.includes(i.type)).length>0,a=()=>{const{viewModel:i}=f.useViewModel(),l=o.value,d=o.value.editor;if(l.selectedNodes.length===0)return;const u=l.selectedNodes.filter(g=>!Ye.includes(g.type)),p=u.flatMap(g=>Object.values(g.inputs)),b=u.flatMap(g=>Object.values(g.outputs)),C=l.connections.filter(g=>!b.includes(g.from)&&p.includes(g.to)),h=l.connections.filter(g=>b.includes(g.from)&&!p.includes(g.to)),w=l.connections.filter(g=>b.includes(g.from)&&p.includes(g.to)),k=u.map(g=>g.save()),_=w.map(g=>({id:g.id,from:g.from.id,to:g.to.id})),c=new Map,{xLeft:m,xRight:E,yTop:y}=Un(u);for(const[g,S]of C.entries()){const $=new pe;$.inputs.name.value=S.to.name,k.push({...$.save(),position:{x:E-i.value.settings.nodes.defaultWidth-100,y:y+g*200}}),_.push({id:j.v4(),from:$.outputs.placeholder.id,to:S.to.id}),c.set(S.to.id,$.graphInterfaceId)}for(const[g,S]of h.entries()){const $=new he;$.inputs.name.value=S.from.name,k.push({...$.save(),position:{x:m+100,y:y+g*200}}),_.push({id:j.v4(),from:S.from.id,to:$.inputs.placeholder.id}),c.set(S.from.id,$.graphInterfaceId)}const B=e.reactive(new z({connections:_,nodes:k,inputs:[],outputs:[]},d));d.addGraphTemplate(B);const W=d.nodeTypes.get(O.getGraphNodeTypeString(B));if(!W)throw new Error("Unable to create subgraph: Could not find corresponding graph node type");l.activeTransactions++;const P=e.reactive(new W.type);l.addNode(P);const me=Math.round(u.map(g=>g.position.x).reduce((g,S)=>g+S,0)/u.length),q=Math.round(u.map(g=>g.position.y).reduce((g,S)=>g+S,0)/u.length);P.position.x=me,P.position.y=q,C.forEach(g=>{l.removeConnection(g),l.addConnection(g.from,P.inputs[c.get(g.to.id)])}),h.forEach(g=>{l.removeConnection(g),l.addConnection(P.outputs[c.get(g.from.id)],g.to)}),u.forEach(g=>l.removeNode(g)),l.activeTransactions--,t.canExecuteCommand(f.Commands.SAVE_SUBGRAPH_COMMAND)&&t.executeCommand(f.Commands.SAVE_SUBGRAPH_COMMAND),n(B),o.value.panning={...l.panning},o.value.scaling=l.scaling};t.registerCommand(qe,{canExecute:s,execute:a})}function Un(o){const t=o.reduce((a,i)=>{const l=i.position.x;return l<a?l:a},1/0),n=o.reduce((a,i)=>{const l=i.position.y;return l<a?l:a},1/0);return{xLeft:o.reduce((a,i)=>{const l=i.position.x+i.width;return l>a?l:a},-1/0),xRight:t,yTop:n}}class Fn extends O.Editor{code;graph;constructor(t){super(),this.code=t,this.graph=new D(this)}get graphIds(){const t=[];return this.graphs.forEach(n=>t.push(n.id)),t.map(n=>n.slice(0,6)).join(", ")}get graphTemplateIds(){const t=[];return this.graphTemplates.forEach(n=>t.push(n.id)),t.map(n=>n.slice(0,6)).join(", ")}addGraphTemplate(t){if(this.events.beforeAddGraphTemplate.emit(t).prevented)return;this._graphTemplates.push(t),this.graphTemplateEvents.addTarget(t.events),this.graphTemplateHooks.addTarget(t.hooks);const n=Ie(t);this.registerNodeType(n,{category:"Subgraphs",title:t.name}),this.events.addGraphTemplate.emit(t)}load(t){try{for(super._loading=!0,t=this.hooks.load.execute(t);this.graphTemplates.length>0;)this.removeGraphTemplate(this.graphTemplates[0]);t.graphTemplates.forEach(s=>{const a=new z(s,this);this.addGraphTemplate(a)});const n=this.graph.load(t.graph);return this.events.loaded.emit(),n.forEach(s=>console.warn(s)),n}finally{super._loading=!1}}registerCategoryModule(t,n){this.code.state.modules[t]=n}}function Wn(o){const t=e.ref(o?.code??new we),n=e.ref(o?.existingEditor??new Fn(t.value)),s=Symbol("ViewModelToken"),a=e.ref(null),i=e.shallowReadonly(a),{switchGraph:l}=He(n,a),d=e.computed(()=>i.value&&i.value!==n.value.graph),u=e.reactive(f.DEFAULT_SETTINGS());u.nodes.defaultWidth=400;const p=f.useCommandHandler(),b=f.useHistory(i,p),C=f.useClipboard(i,n,p),h={renderNode:new fe.SequentialHook(null),renderInterface:new fe.SequentialHook(null)},w=e.reactive({clipboard:C,code:t,commandHandler:p,displayedGraph:i,editor:n,history:b,hooks:h,isSubgraph:d,settings:u,switchGraph:l});return t.value.registerViewModel(w),Ae(w),f.registerDeleteNodesCommand(i,p),Ke(i,p,l),f.registerSaveSubgraphCommand(i,p),f.registerSwitchToMainGraphCommand(i,p,l),f.registerSidebarCommands(i,p),f.registerZoomToFitCommands(i,p,u),Le(i,p,u),De(u),e.watch(n,(k,_)=>{_&&(_.events.registerGraph.unsubscribe(s),_.graphEvents.beforeAddNode.unsubscribe(s),k.nodeHooks.beforeLoad.unsubscribe(s),k.nodeHooks.afterSave.unsubscribe(s),k.graphTemplateHooks.beforeLoad.unsubscribe(s),k.graphTemplateHooks.afterSave.unsubscribe(s),k.graph.hooks.load.unsubscribe(s),k.graph.hooks.save.unsubscribe(s)),k&&(k.nodeHooks.beforeLoad.subscribe(s,(c,m)=>(m.position=c.position??{x:0,y:0},m.width=c.width??u.nodes.defaultWidth,m.twoColumn=c.twoColumn??!1,c)),k.nodeHooks.afterSave.subscribe(s,(c,m)=>(c.position=m.position,c.width=m.width,c.twoColumn=m.twoColumn,c)),k.graphTemplateHooks.beforeLoad.subscribe(s,(c,m)=>(m.panning=c.panning,m.scaling=c.scaling,c)),k.graphTemplateHooks.afterSave.subscribe(s,(c,m)=>(c.panning=m.panning,c.scaling=m.scaling,c)),k.graph.hooks.load.subscribe(s,(c,m)=>(m.panning=c.panning,m.scaling=c.scaling,c)),k.graph.hooks.save.subscribe(s,(c,m)=>(c.panning=m.panning,c.scaling=m.scaling,c)),k.graphEvents.beforeAddNode.subscribe(s,c=>f.setViewNodeProperties(c,{defaultWidth:u.nodes.defaultWidth})),n.value.registerNodeType(pe,{category:"Subgraphs"}),n.value.registerNodeType(he,{category:"Subgraphs"}),l(k.graph))},{immediate:!0}),w}r.AbstractCodeNode=Y,r.CLEAR_ALL_COMMAND=ae,r.CREATE_SUBGRAPH_COMMAND=qe,r.CheckboxInterface=it,r.Code=we,r.CodeEngine=Ee,r.CodeGraph=D,r.CodeGraphEditor=fn,r.CodeGraphInfo=bn,r.CodeGraphInputNode=oe,r.CodeGraphNode=Ue,r.CodeGraphNodeInterface=ce,r.CodeGraphOutputNode=se,r.CodeGraphSidebar=We,r.CodeGraphTemplate=z,r.CodeNode=A,r.CodeNodeInputInterface=L,r.CodeNodeInterface=x,r.CodeNodeInterfaceComponent=H,r.CodeNodeOutputInterface=Ce,r.CodeNodePalette=Fe,r.CodeVariable=ve,r.DotsVertical=Be,r.DynamicCodeNode=Ne,r.GRAPH_INPUT_NODE_TYPE=te,r.GRAPH_OUTPUT_NODE_TYPE=ne,r.IntegerInterface=rt,r.LayoutSidebarLeftCollapse=Te,r.LayoutSidebarLeftExpand=Oe,r.LayoutSidebarRight=xe,r.LayoutSidebarRightCollapse=Me,r.LayoutSidebarRightExpand=Se,r.ListInputInterface=lt,r.LockCode=Ve,r.NumberInterface=dt,r.PlayerPlay=$e,r.RUN_ENGINE_COMMAND=ie,r.Schema=Ge,r.SchemaOff=Re,r.SelectInterface=ct,r.SidebarCheckbox=ue,r.SliderInterface=ut,r.SubgraphInputNode=pe,r.SubgraphOutputNode=he,r.TOGGLE_MINIMAP_COMMAND=re,r.TOGGLE_PALETTE_COMMAND=le,r.TextInputInterface=bt,r.TextInputInterfaceComponent=ye,r.TextareaInputInterface=kt,r.TransitionBottom=je,r.TrashOff=Pe,r.TupleInputInterface=Ct,r.addDefaultInterfaceTypes=at,r.allowMultipleConnections=It,r.booleanType=X,r.createCodeGraphNodeType=Ie,r.defineCodeNode=yt,r.defineDynamicCodeNode=Nt,r.dictType=ke,r.formatInputs=ge,r.getCodeNodes=de,r.getPositionAtColumn=cn,r.getPositionBeforeNode=un,r.listType=J,r.loadNodeState=K,r.nodeType=V,r.numberType=U,r.registerCodeEngine=Ae,r.registerCreateSubgraphCommand=Ke,r.registerCustomCommands=Le,r.registerRunEngineCommands=ze,r.saveNodeState=be,r.stringType=F,r.tupleType=Q,r.updateToolbarItems=De,r.useCodeGraph=Wn,r.useSwitchCodeGraph=He,Object.defineProperty(r,Symbol.toStringTag,{value:"Module"})}));
|