@babsey/code-graph 0.0.17 → 0.1.0

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