@babsey/code-graph 0.0.14 → 0.0.15

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.
@@ -1,7 +1,7 @@
1
- import { AbstractNode as De, sortTopologically as ke, NodeInterface as Pe, NodeInterfaceType as D, BaklavaInterfaceTypes as Ae, CheckboxInterfaceComponent as He, setType as L, displayInSidebar as q, IntegerInterfaceComponent as Fe, NumberInterfaceComponent as We, SelectInterfaceComponent as Xe, SliderInterfaceComponent as Ye, TextInputInterfaceComponent as qe, TextareaInputInterfaceComponent as Je, allowMultipleConnections as Y, IntegerInterface as Qe, TextInputInterface as Ze, useViewModel as F, useTemporaryConnection as Ke, Components as _e, useGraph as ee, GRAPH_NODE_TYPE_PREFIX as J, useTransform as et, useNodeCategories as tt, BaklavaEditor as st, DEFAULT_TOOLBAR_COMMANDS as nt, useBaklava as ot, DependencyEngine as at, applyResult as it } from "baklavajs";
1
+ import { AbstractNode as De, sortTopologically as Ce, NodeInterface as Pe, displayInSidebar as ke, NodeInterfaceType as D, BaklavaInterfaceTypes as Ae, CheckboxInterfaceComponent as He, setType as L, IntegerInterfaceComponent as Fe, NumberInterfaceComponent as We, SelectInterfaceComponent as Xe, SliderInterfaceComponent as Ye, TextInputInterfaceComponent as qe, TextareaInputInterfaceComponent as Je, allowMultipleConnections as Y, IntegerInterface as Qe, TextInputInterface as Ze, useViewModel as F, useTemporaryConnection as Ke, Components as be, useGraph as K, GRAPH_NODE_TYPE_PREFIX as q, useTransform as et, useNodeCategories as tt, BaklavaEditor as st, DEFAULT_TOOLBAR_COMMANDS as nt, useBaklava as ot, DependencyEngine as at, applyResult as it } from "baklavajs";
2
2
  import { CheckboxInterfaceComponent as vn, IntegerInterfaceComponent as mn, NumberInterfaceComponent as fn, SelectInterfaceComponent as gn, SliderInterfaceComponent as bn, TextInputInterfaceComponent as _n, TextareaInputInterfaceComponent as yn } from "baklavajs";
3
3
  import xe from "mustache";
4
- import { reactive as G, defineComponent as j, createElementBlock as r, openBlock as i, toDisplayString as E, markRaw as z, ref as O, computed as b, onMounted as te, onUpdated as Ne, normalizeClass as U, createCommentVNode as I, createElementVNode as d, unref as k, renderSlot as Q, createStaticVNode as se, onBeforeUnmount as rt, normalizeStyle as ne, withModifiers as P, createBlock as V, withDirectives as oe, Fragment as $, createTextVNode as dt, createVNode as T, withKeys as Z, vModelText as ae, renderList as A, nextTick as lt, toRef as Ie, resolveDynamicComponent as ut, inject as ct, Transition as pt, withCtx as X, onUnmounted as ht, normalizeProps as vt, guardReactiveProps as mt, mergeProps as ft } from "vue";
4
+ import { reactive as G, defineComponent as j, createElementBlock as r, openBlock as i, toDisplayString as E, markRaw as z, ref as O, computed as b, onMounted as ee, onUpdated as Ne, normalizeClass as U, createCommentVNode as I, createElementVNode as d, unref as k, renderSlot as J, createStaticVNode as te, onBeforeUnmount as rt, normalizeStyle as se, withModifiers as P, createBlock as V, withDirectives as ne, Fragment as $, createTextVNode as dt, createVNode as T, withKeys as Q, vModelText as oe, renderList as A, nextTick as lt, toRef as Ie, resolveDynamicComponent as ut, inject as ct, Transition as pt, withCtx as X, onUnmounted as ht, normalizeProps as vt, guardReactiveProps as mt, mergeProps as ft } from "vue";
5
5
  import gt from "toposort";
6
6
  import { v4 as bt } from "uuid";
7
7
  import { usePointer as _t } from "@vueuse/core";
@@ -74,19 +74,19 @@ class yt extends De {
74
74
  const e = {};
75
75
  Object.keys(this.inputs).forEach((s) => {
76
76
  if (s === "_node") return;
77
- const o = this.inputs[s], a = ye(o);
77
+ const o = this.inputs[s], a = _e(o);
78
78
  o && o.state && (e[s] = o.state.script.length > 0 ? o.state.script : a);
79
79
  });
80
80
  const t = {};
81
81
  Object.keys(this.outputs).forEach((s) => {
82
82
  if (s === "_node") return;
83
- const o = this.outputs[s], a = ye(o);
83
+ const o = this.outputs[s], a = _e(o);
84
84
  o && o.state && (t[s] = a);
85
85
  }), this.state.script = xe.render(this.state.codeTemplate, { inputs: e, outputs: t }), this.outputs.code && (this.outputs.code.state.script = this.state.script);
86
86
  }
87
87
  updateCodeNodeInputInterfaces() {
88
88
  if (!this.graph) return;
89
- const { connectionsFromNode: e } = ke(this.graph);
89
+ const { connectionsFromNode: e } = Ce(this.graph);
90
90
  e.has(this) && e.get(this).forEach((t) => {
91
91
  const s = this.graph?.findNodeById(t.from.nodeId);
92
92
  s && (s.renderCode(), t.from.isCodeNode && t.to.isCodeNode && (t.to.state.script = t.from.script));
@@ -148,7 +148,7 @@ const Ys = (n) => {
148
148
  }), Object.entries(e.outputs).forEach(([o, a]) => {
149
149
  o !== "_node" && s.outputs[o] && (a.hidden = s.outputs[o].hidden);
150
150
  });
151
- }, ye = (n) => {
151
+ }, _e = (n) => {
152
152
  let e;
153
153
  if (n.value == null) return "None";
154
154
  switch (n.type) {
@@ -165,7 +165,7 @@ const Ys = (n) => {
165
165
  e = `${n.value}`;
166
166
  }
167
167
  return e;
168
- }, Ct = ["title"], ie = /* @__PURE__ */ j({
168
+ }, Ct = ["title"], ae = /* @__PURE__ */ j({
169
169
  __name: "CodeNodeInterface",
170
170
  props: {
171
171
  intf: {}
@@ -182,7 +182,7 @@ class R extends Pe {
182
182
  state;
183
183
  type = null;
184
184
  constructor(e, t) {
185
- super(e, t), this.setComponent(z(ie)), this.state = G({
185
+ super(e, t), this.setComponent(z(ae)), this.state = G({
186
186
  optional: !1,
187
187
  script: ""
188
188
  });
@@ -202,62 +202,62 @@ class R extends Pe {
202
202
  // }
203
203
  }
204
204
  const qs = (n, e) => {
205
- n.state.optional = e;
205
+ n.state.optional = e, n.setHidden(!0);
206
206
  };
207
- class re extends R {
207
+ class ie extends R {
208
208
  constructor(e = "", t) {
209
- super(e, t), this.setComponent(z(ie));
209
+ super(e, t), this.setComponent(z(ae)), this.use(ke, !0);
210
210
  }
211
211
  }
212
- const $e = new D("boolean"), kt = new D("dict"), xt = new D("list"), H = new D("node"), de = new D("number"), le = new D("string"), Js = (n) => {
213
- new Ae(n.editor, { viewPlugin: n }).addTypes($e, kt, xt, H, de, le);
212
+ const $e = new D("boolean"), kt = new D("dict"), xt = new D("list"), H = new D("node"), re = new D("number"), de = new D("string"), Js = (n) => {
213
+ new Ae(n.editor, { viewPlugin: n }).addTypes($e, kt, xt, H, re, de);
214
214
  };
215
- class Qs extends re {
215
+ class Qs extends ie {
216
216
  constructor(e, t) {
217
- super(e, t), this.setComponent(z(He)), this.use(L, $e).use(q, !0);
217
+ super(e, t), this.setComponent(z(He)), this.use(L, $e);
218
218
  }
219
219
  }
220
220
  class Nt extends R {
221
221
  isCodeNodeOutput = !0;
222
222
  constructor(e = "", t = "") {
223
- super(e, t), this.setComponent(z(ie));
223
+ super(e, t), this.setComponent(z(ae));
224
224
  }
225
225
  get script() {
226
226
  return this.name.length > 0 ? this.name : this.state.script;
227
227
  }
228
228
  }
229
- class ue extends re {
229
+ class le extends ie {
230
230
  min;
231
231
  max;
232
232
  constructor(e, t, s, o) {
233
- super(e, t), this.min = s, this.max = o, this.use(L, de).use(q, !0);
233
+ super(e, t), this.min = s, this.max = o, this.use(L, re);
234
234
  }
235
235
  validate(e) {
236
236
  return (this.min === void 0 || e >= this.min) && (this.max === void 0 || e <= this.max);
237
237
  }
238
238
  }
239
- class Zs extends ue {
239
+ class Zs extends le {
240
240
  component = z(Fe);
241
241
  validate(e) {
242
242
  return Number.isInteger(e) && super.validate(e);
243
243
  }
244
244
  }
245
- class Ks extends ue {
245
+ class Ks extends le {
246
246
  component = z(We);
247
247
  }
248
- class ce extends re {
248
+ class ue extends ie {
249
249
  constructor(e, t) {
250
- super(e, t), this.use(L, le).use(q, !0);
250
+ super(e, t), this.use(L, de);
251
251
  }
252
252
  }
253
- class en extends ce {
253
+ class en extends ue {
254
254
  component = z(Xe);
255
255
  items;
256
256
  constructor(e, t, s) {
257
257
  super(e, t), this.items = s;
258
258
  }
259
259
  }
260
- class tn extends ue {
260
+ class tn extends le {
261
261
  component = z(Ye);
262
262
  min;
263
263
  max;
@@ -265,10 +265,10 @@ class tn extends ue {
265
265
  super(e, t, s, o), this.min = s, this.max = o;
266
266
  }
267
267
  }
268
- class sn extends ce {
268
+ class sn extends ue {
269
269
  component = z(qe);
270
270
  }
271
- class nn extends ce {
271
+ class nn extends ue {
272
272
  component = z(Je);
273
273
  }
274
274
  function on(n) {
@@ -359,7 +359,7 @@ function an(n) {
359
359
  if (!this.inputs[t]) {
360
360
  const s = e.inputs[t].value;
361
361
  let o;
362
- typeof s == "number" ? o = new Qe(t, s).use(L, de) : o = new Ze(t, JSON.stringify(s)).use(L, le), o.use(q, !0), this.addInput(t, o);
362
+ typeof s == "number" ? o = new Qe(t, s).use(L, re) : o = new Ze(t, JSON.stringify(s)).use(L, de), o.use(ke, !0), this.addInput(t, o);
363
363
  }
364
364
  this.inputs[t] && (this.inputs[t].load(e.inputs[t]), this.inputs[t].nodeId = this.id);
365
365
  }
@@ -417,7 +417,7 @@ class Mt {
417
417
  });
418
418
  }
419
419
  get codeNodes() {
420
- return K(this.graph);
420
+ return Z(this.graph);
421
421
  }
422
422
  get connections() {
423
423
  return this.graph.connections;
@@ -447,7 +447,7 @@ class Mt {
447
447
  this.graph._nodes = e;
448
448
  }
449
449
  get scriptedCodeNodes() {
450
- return K(this.graph).filter(
450
+ return Z(this.graph).filter(
451
451
  (e) => e.state?.script.length > 0
452
452
  );
453
453
  }
@@ -602,10 +602,10 @@ class Mt {
602
602
  this.codeNodes.forEach((e) => e.updateOutputVariableName());
603
603
  }
604
604
  }
605
- const K = (n) => {
605
+ const Z = (n) => {
606
606
  let e = [];
607
607
  return n.nodes.forEach((t) => {
608
- t.subgraph ? e = e.concat(K(t.subgraph)) : t.isCodeNode && e.push(t);
608
+ t.subgraph ? e = e.concat(Z(t.subgraph)) : t.isCodeNode && e.push(t);
609
609
  }), e;
610
610
  }, rn = (n = 0, e = 100) => ({
611
611
  x: n * 420,
@@ -614,7 +614,7 @@ const K = (n) => {
614
614
  const e = { ...n.position };
615
615
  return e.x -= 400, e.y += 50, e;
616
616
  }, ln = (n) => {
617
- const { calculationOrder: e, connectionsFromNode: t } = ke(n);
617
+ const { calculationOrder: e, connectionsFromNode: t } = Ce(n);
618
618
  e.forEach((s) => {
619
619
  if (!s.isCodeNode) return;
620
620
  const o = s;
@@ -622,7 +622,7 @@ const K = (n) => {
622
622
  a.to.state && a.from.script && (a.to.state.script = a.from.script);
623
623
  });
624
624
  });
625
- }, Ot = ["id"], $t = { class: "align-middle" }, we = /* @__PURE__ */ j({
625
+ }, Ot = ["id"], $t = { class: "align-middle" }, ye = /* @__PURE__ */ j({
626
626
  __name: "CodeGraphNodeInterface",
627
627
  props: {
628
628
  node: {},
@@ -638,7 +638,7 @@ const K = (n) => {
638
638
  }, y = () => {
639
639
  a.value && t.value.hooks.renderInterface.execute({ intf: e.intf, el: a.value });
640
640
  };
641
- return te(y), Ne(y), (x, B) => (i(), r("div", {
641
+ return ee(y), Ne(y), (x, B) => (i(), r("div", {
642
642
  id: x.intf.id,
643
643
  ref_key: "el",
644
644
  ref: a,
@@ -651,7 +651,7 @@ const K = (n) => {
651
651
  onPointerout: _
652
652
  }, null, 34)) : I("", !0),
653
653
  d("span", $t, [
654
- Q(x.$slots, "default")
654
+ J(x.$slots, "default")
655
655
  ])
656
656
  ], 10, Ot));
657
657
  }
@@ -764,7 +764,7 @@ const qt = /* @__PURE__ */ S(Wt, [["render", Yt]]), Jt = {}, Qt = {
764
764
  };
765
765
  function Zt(n, e) {
766
766
  return i(), r("svg", Qt, [...e[0] || (e[0] = [
767
- se('<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)
767
+ te('<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)
768
768
  ])]);
769
769
  }
770
770
  const Kt = /* @__PURE__ */ S(Jt, [["render", Zt]]), es = {}, ts = {
@@ -781,7 +781,7 @@ const Kt = /* @__PURE__ */ S(Jt, [["render", Zt]]), es = {}, ts = {
781
781
  };
782
782
  function ss(n, e) {
783
783
  return i(), r("svg", ts, [...e[0] || (e[0] = [
784
- se('<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)
784
+ te('<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)
785
785
  ])]);
786
786
  }
787
787
  const ns = /* @__PURE__ */ S(es, [["render", ss]]), os = {}, as = {
@@ -798,7 +798,7 @@ const ns = /* @__PURE__ */ S(es, [["render", ss]]), os = {}, as = {
798
798
  };
799
799
  function is(n, e) {
800
800
  return i(), r("svg", as, [...e[0] || (e[0] = [
801
- se('<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)
801
+ te('<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)
802
802
  ])]);
803
803
  }
804
804
  const rs = /* @__PURE__ */ S(os, [["render", is]]), ds = {}, ls = {
@@ -852,7 +852,7 @@ const cs = /* @__PURE__ */ S(ds, [["render", us]]), ps = ["id", "data-node-type"
852
852
  },
853
853
  emits: ["select", "start-drag", "update"],
854
854
  setup(n, { emit: e }) {
855
- const t = _e.ContextMenu, s = _e.NodeInterface, o = n, a = b(() => o.node), u = e, { viewModel: l } = F(), { graph: v, switchGraph: _ } = ee(), y = O(null), x = O(!1), B = O(""), w = O(null), m = O(!1);
855
+ const t = be.ContextMenu, s = be.NodeInterface, o = n, a = b(() => o.node), u = e, { viewModel: l } = F(), { graph: v, switchGraph: _ } = K(), y = O(null), x = O(!1), B = O(""), w = O(null), m = O(!1);
856
856
  let f = 0, h = 0;
857
857
  const p = O(!1), C = b(() => {
858
858
  const c = [
@@ -860,7 +860,7 @@ const cs = /* @__PURE__ */ S(ds, [["render", us]]), ps = ["id", "data-node-type"
860
860
  { value: "rename", label: "Rename" },
861
861
  { value: "delete", label: "Delete" }
862
862
  ];
863
- return o.node.type.startsWith(J) && c.push({ value: "editSubgraph", label: "Edit Subgraph" }), c;
863
+ return o.node.type.startsWith(q) && c.push({ value: "editSubgraph", label: "Edit Subgraph" }), c;
864
864
  }), M = b(() => ({
865
865
  "--selected": o.selected,
866
866
  "--dragging": o.dragging,
@@ -872,16 +872,16 @@ const cs = /* @__PURE__ */ S(ds, [["render", us]]), ps = ["id", "data-node-type"
872
872
  top: `${o.node.position?.y ?? 0}px`,
873
873
  left: `${o.node.position?.x ?? 0}px`,
874
874
  "--width": `${o.node.width ?? l.value.settings.nodes.defaultWidth}px`
875
- })), ze = b(() => Object.values(o.node.inputs).filter((c) => !c.hidden)), Se = b(() => Object.values(o.node.outputs).filter((c) => !c.hidden)), pe = () => {
875
+ })), ze = b(() => Object.values(o.node.inputs).filter((c) => !c.hidden)), Se = b(() => Object.values(o.node.outputs).filter((c) => !c.hidden)), ce = () => {
876
876
  u("select");
877
877
  }, Be = (c) => {
878
- o.selected || pe(), u("start-drag", c);
879
- }, he = () => {
878
+ o.selected || ce(), u("start-drag", c);
879
+ }, pe = () => {
880
880
  p.value = !0;
881
881
  }, Le = () => {
882
882
  const c = l.value.displayedGraph.sidebar;
883
883
  c.nodeId = "", c.visible = !1;
884
- }, ve = () => {
884
+ }, he = () => {
885
885
  const c = l.value.displayedGraph.sidebar;
886
886
  c.nodeId = o.node.id, c.visible = !0;
887
887
  }, Ve = () => {
@@ -890,7 +890,7 @@ const cs = /* @__PURE__ */ S(ds, [["render", us]]), ps = ["id", "data-node-type"
890
890
  }, je = async (c) => {
891
891
  switch (c) {
892
892
  case "edit":
893
- ve();
893
+ he();
894
894
  break;
895
895
  case "delete":
896
896
  v.value.removeNode(o.node);
@@ -902,31 +902,31 @@ const cs = /* @__PURE__ */ S(ds, [["render", us]]), ps = ["id", "data-node-type"
902
902
  _(o.node.template);
903
903
  break;
904
904
  }
905
- }, me = () => {
905
+ }, ve = () => {
906
906
  o.node.title = B.value, x.value = !1;
907
- }, fe = () => {
907
+ }, me = () => {
908
908
  y.value && l.value.hooks.renderNode.execute({ node: o.node, el: y.value });
909
909
  }, Ue = (c) => {
910
910
  m.value = !0, f = o.node.width, h = c.clientX, c.preventDefault();
911
- }, ge = (c) => {
911
+ }, fe = (c) => {
912
912
  if (!m.value) return;
913
913
  const N = c.clientX - h, g = f + N / v.value.scaling, Ge = l.value.settings.nodes.minWidth, Re = l.value.settings.nodes.maxWidth;
914
914
  o.node.width = Math.max(Ge, Math.min(Re, g));
915
- }, be = () => {
915
+ }, ge = () => {
916
916
  m.value = !1;
917
917
  };
918
- return te(() => {
919
- fe(), window.addEventListener("mousemove", ge), window.addEventListener("mouseup", be);
920
- }), Ne(fe), rt(() => {
921
- window.removeEventListener("mousemove", ge), window.removeEventListener("mouseup", be);
918
+ return ee(() => {
919
+ me(), window.addEventListener("mousemove", fe), window.addEventListener("mouseup", ge);
920
+ }), Ne(me), rt(() => {
921
+ window.removeEventListener("mousemove", fe), window.removeEventListener("mouseup", ge);
922
922
  }), (c, N) => (i(), r("div", {
923
923
  id: a.value.id,
924
924
  ref_key: "el",
925
925
  ref: y,
926
926
  class: U([M.value, "baklava-node"]),
927
927
  "data-node-type": a.value.type,
928
- style: ne(Ee.value),
929
- onPointerdown: pe
928
+ style: se(Ee.value),
929
+ onPointerdown: ce
930
930
  }, [
931
931
  k(l).settings.nodes.resizable ? (i(), r("div", {
932
932
  key: 0,
@@ -936,9 +936,9 @@ const cs = /* @__PURE__ */ S(ds, [["render", us]]), ps = ["id", "data-node-type"
936
936
  d("div", {
937
937
  class: "__title",
938
938
  onPointerdown: P(Be, ["self", "stop"]),
939
- onContextmenu: P(he, ["prevent"])
939
+ onContextmenu: P(pe, ["prevent"])
940
940
  }, [
941
- a.value.inputs._node ? (i(), V(we, {
941
+ a.value.inputs._node ? (i(), V(ye, {
942
942
  key: 0,
943
943
  node: a.value,
944
944
  intf: a.value.inputs._node,
@@ -946,7 +946,7 @@ const cs = /* @__PURE__ */ S(ds, [["render", us]]), ps = ["id", "data-node-type"
946
946
  "data-interface-type": "node",
947
947
  style: { "flex-grow": "0" }
948
948
  }, null, 8, ["node", "intf"])) : I("", !0),
949
- x.value ? oe((i(), r("input", {
949
+ x.value ? ne((i(), r("input", {
950
950
  key: 2,
951
951
  ref_key: "renameInputEl",
952
952
  ref: w,
@@ -955,10 +955,10 @@ const cs = /* @__PURE__ */ S(ds, [["render", us]]), ps = ["id", "data-node-type"
955
955
  placeholder: "Node Name",
956
956
  style: { "flex-grow": "1" },
957
957
  type: "text",
958
- onBlur: me,
959
- onKeydown: Z(me, ["enter"])
958
+ onBlur: ve,
959
+ onKeydown: Q(ve, ["enter"])
960
960
  }, null, 544)), [
961
- [ae, B.value]
961
+ [oe, B.value]
962
962
  ]) : (i(), r($, { key: 1 }, [
963
963
  d("div", hs, [
964
964
  a.value.idx > -1 ? (i(), r("span", vs, E(a.value.idx + 1) + " - ", 1)) : I("", !0),
@@ -969,7 +969,7 @@ const cs = /* @__PURE__ */ S(ds, [["render", us]]), ps = ["id", "data-node-type"
969
969
  !k(l).displayedGraph.sidebar.visible && k(l).displayedGraph.sidebar.nodeId !== a.value.id ? (i(), V(k(qt), {
970
970
  key: 0,
971
971
  class: "--clickable mx-1",
972
- onClick: ve
972
+ onClick: he
973
973
  })) : k(l).displayedGraph.sidebar.visible && k(l).displayedGraph.sidebar.nodeId !== a.value.id ? (i(), V(k(Dt), {
974
974
  key: 1,
975
975
  class: "--clickable mx-1",
@@ -982,7 +982,7 @@ const cs = /* @__PURE__ */ S(ds, [["render", us]]), ps = ["id", "data-node-type"
982
982
  ], 64)),
983
983
  T(k(cs), {
984
984
  class: "--clickable mx-1",
985
- onClick: he
985
+ onClick: pe
986
986
  }),
987
987
  T(k(t), {
988
988
  modelValue: p.value,
@@ -994,7 +994,7 @@ const cs = /* @__PURE__ */ S(ds, [["render", us]]), ps = ["id", "data-node-type"
994
994
  }, null, 8, ["modelValue", "items"])
995
995
  ])
996
996
  ], 64)),
997
- a.value.outputs._node ? (i(), V(we, {
997
+ a.value.outputs._node ? (i(), V(ye, {
998
998
  key: 3,
999
999
  node: a.value,
1000
1000
  intf: a.value.outputs._node,
@@ -1004,7 +1004,7 @@ const cs = /* @__PURE__ */ S(ds, [["render", us]]), ps = ["id", "data-node-type"
1004
1004
  ], 32),
1005
1005
  d("div", {
1006
1006
  class: U(["__content", Te.value]),
1007
- onKeydown: N[2] || (N[2] = Z(P(() => {
1007
+ onKeydown: N[2] || (N[2] = Q(P(() => {
1008
1008
  }, ["stop"]), ["delete"])),
1009
1009
  onContextmenu: N[3] || (N[3] = P(() => {
1010
1010
  }, ["prevent"]))
@@ -1022,7 +1022,7 @@ const cs = /* @__PURE__ */ S(ds, [["render", us]]), ps = ["id", "data-node-type"
1022
1022
  }, [...N[4] || (N[4] = [
1023
1023
  d("div", { class: "__port" }, null, -1)
1024
1024
  ])], 8, bs)) : I("", !0)
1025
- ])) : Q(c.$slots, "nodeInterface", {
1025
+ ])) : J(c.$slots, "nodeInterface", {
1026
1026
  key: 1,
1027
1027
  type: "output",
1028
1028
  node: a.value,
@@ -1048,7 +1048,7 @@ const cs = /* @__PURE__ */ S(ds, [["render", us]]), ps = ["id", "data-node-type"
1048
1048
  }, [...N[5] || (N[5] = [
1049
1049
  d("div", { class: "__port" }, null, -1)
1050
1050
  ])], 8, ws)) : I("", !0)
1051
- ])) : Q(c.$slots, "nodeInterface", {
1051
+ ])) : J(c.$slots, "nodeInterface", {
1052
1052
  key: 1,
1053
1053
  node: a.value,
1054
1054
  intf: g,
@@ -1107,7 +1107,7 @@ const cs = /* @__PURE__ */ S(ds, [["render", us]]), ps = ["id", "data-node-type"
1107
1107
  }, Ts = /* @__PURE__ */ j({
1108
1108
  __name: "CodeGraphSidebar",
1109
1109
  setup(n) {
1110
- const { viewModel: e } = F(), { graph: t } = ee(), s = O(null), o = Ie(e.value.settings.sidebar, "width"), a = b(() => e.value.settings.sidebar.resizable);
1110
+ const { viewModel: e } = F(), { graph: t } = K(), s = O(null), o = Ie(e.value.settings.sidebar, "width"), a = b(() => e.value.settings.sidebar.resizable);
1111
1111
  let u = 0, l = 0;
1112
1112
  const v = b(() => {
1113
1113
  const h = t.value.sidebar.nodeId;
@@ -1135,7 +1135,7 @@ const cs = /* @__PURE__ */ S(ds, [["render", us]]), ps = ["id", "data-node-type"
1135
1135
  ref_key: "el",
1136
1136
  ref: s,
1137
1137
  class: U(["baklava-sidebar", { "--open": k(t).sidebar.visible }]),
1138
- style: ne(y.value)
1138
+ style: se(y.value)
1139
1139
  }, [
1140
1140
  a.value ? (i(), r("div", {
1141
1141
  key: 0,
@@ -1178,15 +1178,15 @@ const cs = /* @__PURE__ */ S(ds, [["render", us]]), ps = ["id", "data-node-type"
1178
1178
  ]))), 128)),
1179
1179
  _.value && _.value.state ? (i(), r("div", $s, [
1180
1180
  p[2] || (p[2] = d("label", null, "Variable name", -1)),
1181
- oe(d("input", {
1181
+ ne(d("input", {
1182
1182
  "onUpdate:modelValue": p[1] || (p[1] = (C) => _.value.state.variableName = C),
1183
1183
  type: "text",
1184
1184
  class: "baklava-input",
1185
1185
  title: "Variable name",
1186
1186
  onBlur: w,
1187
- onKeydown: Z(w, ["enter"])
1187
+ onKeydown: Q(w, ["enter"])
1188
1188
  }, null, 544), [
1189
- [ae, _.value.state.variableName]
1189
+ [oe, _.value.state.variableName]
1190
1190
  ])
1191
1191
  ])) : I("", !0)
1192
1192
  ], 6));
@@ -1203,14 +1203,14 @@ const cs = /* @__PURE__ */ S(ds, [["render", us]]), ps = ["id", "data-node-type"
1203
1203
  }
1204
1204
  },
1205
1205
  setup(n) {
1206
- const { viewModel: e } = F(), { switchGraph: t } = ee(), s = O(!1), o = b(() => n.type.startsWith(J));
1206
+ const { viewModel: e } = F(), { switchGraph: t } = K(), s = O(!1), o = b(() => n.type.startsWith(q));
1207
1207
  return { showContextMenu: s, hasContextMenu: o, contextMenuItems: [
1208
1208
  { label: "Edit Subgraph", value: "editSubgraph" },
1209
1209
  { label: "Delete Subgraph", value: "deleteSubgraph" }
1210
1210
  ], openContextMenu: () => {
1211
1211
  s.value = !0;
1212
1212
  }, onContextMenuClick: (v) => {
1213
- const _ = n.type.substring(J.length), y = e.value.editor.graphTemplates.find((x) => x.id === _);
1213
+ const _ = n.type.substring(q.length), y = e.value.editor.graphTemplates.find((x) => x.id === _);
1214
1214
  if (y)
1215
1215
  switch (v) {
1216
1216
  case "editSubgraph":
@@ -1233,7 +1233,7 @@ function Ls(n, e, t, s, o, a) {
1233
1233
  ])
1234
1234
  ], 8, zs);
1235
1235
  }
1236
- const Ce = /* @__PURE__ */ S(Es, [["render", Ls]]), Vs = {
1236
+ const we = /* @__PURE__ */ S(Es, [["render", Ls]]), Vs = {
1237
1237
  class: "baklava-node --palette",
1238
1238
  style: { "margin-top": "-20px", "margin-bottom": "20px" }
1239
1239
  }, js = {
@@ -1278,14 +1278,14 @@ const Ce = /* @__PURE__ */ S(Es, [["render", Ls]]), Vs = {
1278
1278
  }, ["stop", "prevent"]))
1279
1279
  }, [
1280
1280
  d("div", Vs, [
1281
- oe(d("input", {
1281
+ ne(d("input", {
1282
1282
  "onUpdate:modelValue": m[0] || (m[0] = (f) => l.value = f),
1283
1283
  type: "text",
1284
1284
  class: "baklava-input",
1285
1285
  title: "Filter nodes",
1286
1286
  onKeyup: _
1287
1287
  }, null, 544), [
1288
- [ae, l.value]
1288
+ [oe, l.value]
1289
1289
  ])
1290
1290
  ]),
1291
1291
  (i(!0), r($, null, A(_(), (f) => (i(), r("section", {
@@ -1298,7 +1298,7 @@ const Ce = /* @__PURE__ */ S(Es, [["render", Ls]]), Vs = {
1298
1298
  }, E(f.name), 9, Us),
1299
1299
  y(f.nodeTypes).length < Object.values(f.nodeTypes).length ? (i(), r("div", Gs, " ( " + E(y(f.nodeTypes).length) + " / " + E(Object.values(f.nodeTypes).length) + " ) ", 1)) : I("", !0)
1300
1300
  ])) : I("", !0),
1301
- (i(!0), r($, null, A(y(f.nodeTypes), (h) => (i(), V(Ce, {
1301
+ (i(!0), r($, null, A(y(f.nodeTypes), (h) => (i(), V(we, {
1302
1302
  key: h.type,
1303
1303
  type: h.type,
1304
1304
  title: h.title,
@@ -1311,9 +1311,9 @@ const Ce = /* @__PURE__ */ S(Es, [["render", Ls]]), Vs = {
1311
1311
  v.value ? (i(), r("div", {
1312
1312
  key: 0,
1313
1313
  class: "baklava-dragged-node",
1314
- style: ne(x.value)
1314
+ style: se(x.value)
1315
1315
  }, [
1316
- T(Ce, {
1316
+ T(we, {
1317
1317
  type: v.value.type,
1318
1318
  title: v.value.nodeInformation.title
1319
1319
  }, null, 8, ["type", "title"])
@@ -1330,7 +1330,7 @@ const Ce = /* @__PURE__ */ S(Es, [["render", Ls]]), Vs = {
1330
1330
  },
1331
1331
  setup(n) {
1332
1332
  const t = Ie(n, "viewModel"), s = (o) => o.events.update.emit(null);
1333
- return te(() => {
1333
+ return ee(() => {
1334
1334
  t.value.subscribe(), t.value.engine.start();
1335
1335
  }), ht(() => {
1336
1336
  t.value.unsubscribe(), t.value.engine.stop();
@@ -1434,7 +1434,7 @@ export {
1434
1434
  Mt as Code,
1435
1435
  un as CodeGraphEditor,
1436
1436
  Me as CodeNode,
1437
- re as CodeNodeInputInterface,
1437
+ ie as CodeNodeInputInterface,
1438
1438
  R as CodeNodeInterface,
1439
1439
  Nt as CodeNodeOutputInterface,
1440
1440
  W as DEFAULT_SETTINGS,
@@ -1458,16 +1458,16 @@ export {
1458
1458
  an as defineDynamicCodeNode,
1459
1459
  kt as dictType,
1460
1460
  Ys as formatInputs,
1461
- K as getCodeNodes,
1461
+ Z as getCodeNodes,
1462
1462
  rn as getPositionAtColumn,
1463
1463
  dn as getPositionBeforeNode,
1464
1464
  xt as listType,
1465
1465
  Oe as loadNodeState,
1466
1466
  H as nodeType,
1467
- de as numberType,
1467
+ re as numberType,
1468
1468
  wt as saveNodeState,
1469
1469
  qs as setOptional,
1470
- le as stringType,
1470
+ de as stringType,
1471
1471
  ln as transferCodeScript,
1472
1472
  cn as useCodeGraph
1473
1473
  };
@@ -1 +1 @@
1
- (function(d,i){typeof exports=="object"&&typeof module<"u"?i(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"],i):(d=typeof globalThis<"u"?globalThis:d||self,i(d["@babsey/code-graph"]={},d.baklavajs,d.mustache,d.Vue,d.toposort,d.uuid,d["@vueuse/core"]))})(this,(function(d,i,G,e,ae,re,ie){"use strict";class U extends i.AbstractNode{state;code;isCodeNode=!0;codeTemplate=()=>"{{ &outputs.code }}";inputs={};outputs={};constructor(){super(),this.initializeIo(),this.width=400,this.twoColumn=!0,this.state=e.reactive({codeTemplate:"",hidden:!1,integrated:!1,modules:[],script:"",variableName:""})}get codeNodeInputs(){return Object.fromEntries(Object.entries(this.inputs).filter(([t,n])=>n.type!="node"))}get idx(){return this.code?.codeNodes.filter(t=>!t.state.integrated).indexOf(this)??-1}get idxByVariableNames(){return this.code?.getNodesBySameVariableNames(this.state.variableName).indexOf(this)??-1}get optionalInputs(){return Object.fromEntries(Object.entries(this.codeNodeInputs).filter(([t,n])=>n.optional))}get requiredInputs(){return Object.fromEntries(Object.entries(this.codeNodeInputs).filter(([t,n])=>!n.optional))}get script(){return this.state.script}get shortId(){return this.id.slice(0,6)}get variableName(){return this.state.variableName?this.state.variableName+(this.idxByVariableNames+1):""}getConnectedNodes(t){let n=[];if(t!=="inputs"){const o=this.graph?.connections.filter(a=>a.from.name!=="_node").filter(a=>a.from.nodeId===this.id).map(a=>a.to.nodeId);o&&(n=n.concat(o))}if(t!=="outputs"){const o=this.graph?.connections.filter(a=>a.from.name!=="_node").filter(a=>a.to.nodeId===this.id).map(a=>a.from.nodeId);o&&(n=n.concat(o))}return!n||n.length==0?[]:n.map(o=>this.graph?.findNodeById(o))}registerCode(t){this.code=t}renderCode(){this.state.codeTemplate=this.codeTemplate.call(this);const t={};Object.keys(this.inputs).forEach(o=>{if(o==="_node")return;const a=this.inputs[o],r=A(a);a&&a.state&&(t[o]=a.state.script.length>0?a.state.script:r)});const n={};Object.keys(this.outputs).forEach(o=>{if(o==="_node")return;const a=this.outputs[o],r=A(a);a&&a.state&&(n[o]=r)}),this.state.script=G.render(this.state.codeTemplate,{inputs:t,outputs:n}),this.outputs.code&&(this.outputs.code.state.script=this.state.script)}updateCodeNodeInputInterfaces(){if(!this.graph)return;const{connectionsFromNode:t}=i.sortTopologically(this.graph);t.has(this)&&t.get(this).forEach(n=>{const o=this.graph?.findNodeById(n.from.nodeId);o&&(o.renderCode(),n.from.isCodeNode&&n.to.isCodeNode&&(n.to.state.script=n.from.script))})}updateOutputVariableName(){this.outputs.code&&(this.outputs.code.name=this.variableName)}}class z extends U{calculate;load(t){super.load(t),L(this.graph,t)}save(){const t=super.save();return F(this.graph,t),t}updateModules(t){if(t)this.state.modules=t;else if(this.type.includes(".")){const n=this.type.split(".");this.state.modules.push(n.slice(0,n.length-1).join("."))}}}const de=s=>{const t=[],n=Object.keys(s);return n.forEach(o=>{if(s[o]?.hidden)return;const r=t.length<n.indexOf(o)?`${o}=`:"";t.push(`${r}{{& inputs.${o} }}`)}),t},L=(s,t)=>{if(!s)return;const n=s.findNodeById(t.id);if(!n||n.subgraph)return;const o=n;o.state&&(o.state.integrated=t.integrated,o.state.modules=t.modules,o.state.props=t.props),Object.entries(t.inputs).forEach(([a,r])=>{a!=="_node"&&o.inputs[a]&&(o.inputs[a].hidden=r.hidden)}),Object.entries(t.outputs).forEach(([a,r])=>{a!=="_node"&&o.outputs[a]&&(o.outputs[a].hidden=r.hidden)})},F=(s,t)=>{if(!s)return;const n=s.findNodeById(t.id);if(!n||n.subgraph)return;const o=n;o.state&&(t.integrated=o.state.integrated,t.modules=o.state.modules),Object.entries(t.inputs).forEach(([a,r])=>{a!=="_node"&&o.inputs[a]&&(r.hidden=o.inputs[a].hidden)}),Object.entries(t.outputs).forEach(([a,r])=>{a!=="_node"&&o.outputs[a]&&(r.hidden=o.outputs[a].hidden)})},A=s=>{let t;if(s.value==null)return"None";switch(s.type){case"boolean":t=s.value?"True":"False";break;case"string":t=`'${s.value}'`;break;case void 0:t="None";break;default:t=`${s.value}`}return t},le=["title"],v=e.defineComponent({__name:"CodeNodeInterface",props:{intf:{}},setup(s){return(t,n)=>(e.openBlock(),e.createElementBlock("div",{title:t.intf.state?.script},e.toDisplayString(t.intf.name),9,le))}});class x extends i.NodeInterface{isCodeNode=!0;code;state;type=null;constructor(t,n){super(t,n),this.setComponent(e.markRaw(v)),this.state=e.reactive({optional:!1,script:""})}get optional(){return this.state.optional}get shortId(){return this.id.slice(0,6)}}const ce=(s,t)=>{s.state.optional=t};class M extends x{constructor(t="",n){super(t,n),this.setComponent(e.markRaw(v))}}const R=new i.NodeInterfaceType("boolean"),H=new i.NodeInterfaceType("dict"),W=new i.NodeInterfaceType("list"),V=new i.NodeInterfaceType("node"),O=new i.NodeInterfaceType("number"),S=new i.NodeInterfaceType("string"),pe=s=>{new i.BaklavaInterfaceTypes(s.editor,{viewPlugin:s}).addTypes(R,H,W,V,O,S)};class ue extends M{constructor(t,n){super(t,n),this.setComponent(e.markRaw(i.CheckboxInterfaceComponent)),this.use(i.setType,R).use(i.displayInSidebar,!0)}}class X extends x{isCodeNodeOutput=!0;constructor(t="",n=""){super(t,n),this.setComponent(e.markRaw(v))}get script(){return this.name.length>0?this.name:this.state.script}}class D extends M{min;max;constructor(t,n,o,a){super(t,n),this.min=o,this.max=a,this.use(i.setType,O).use(i.displayInSidebar,!0)}validate(t){return(this.min===void 0||t>=this.min)&&(this.max===void 0||t<=this.max)}}class he extends D{component=e.markRaw(i.IntegerInterfaceComponent);validate(t){return Number.isInteger(t)&&super.validate(t)}}class me extends D{component=e.markRaw(i.NumberInterfaceComponent)}class P extends M{constructor(t,n){super(t,n),this.use(i.setType,S).use(i.displayInSidebar,!0)}}class fe extends P{component=e.markRaw(i.SelectInterfaceComponent);items;constructor(t,n,o){super(t,n),this.items=o}}class ge extends D{component=e.markRaw(i.SliderInterfaceComponent);min;max;constructor(t,n,o,a){super(t,n,o,a),this.min=o,this.max=a}}class ye extends P{component=e.markRaw(i.TextInputInterfaceComponent)}class _e extends P{component=e.markRaw(i.TextareaInputInterfaceComponent)}function Ne(s){return class extends z{type=s.type;inputs={};outputs={};constructor(){super(),this._title=s.title??s.type,this.updateModules(s.modules),s.variableName&&(this.state.variableName=s.variableName),s.codeTemplate&&(this.codeTemplate=s.codeTemplate),this.addInput("_node",new x("",[]).use(i.setType,V).use(i.allowMultipleConnections).setHidden(!0)),this.addOutput("_node",new x("",[]).use(i.setType,V).use(i.allowMultipleConnections).setHidden(!0)),this.executeFactory("input",s.inputs),this.executeFactory("output",s.outputs),s.onCreate?.call(this)}onPlaced(){s.onPlaced?.call(this)}onDestroy(){s.onDestroy?.call(this)}onCodeUpdate(){s.onCodeUpdate?.call(this)}executeFactory(t,n){Object.keys(n||{}).forEach(o=>{const a=n[o]();t==="input"?this.addInput(o,a):this.addOutput(o,a)})}}}class q extends z{calculate}function be(s){return class extends q{type=s.type;inputs={};outputs={};calculate;preventUpdate=!1;staticInputKeys=Object.keys(s.inputs??{});staticOutputKeys=Object.keys(s.outputs??{});constructor(){super(),this._title=s.title??s.type,this.updateModules(s.modules),s.codeTemplate&&(this.codeTemplate=s.codeTemplate),s.variableName&&(this.state.variableName=s.variableName),this.addInput("_node",new x("",[]).use(i.setType,V).use(i.allowMultipleConnections).setHidden(!0)),this.addOutput("_node",new x("",[]).use(i.setType,V).use(i.allowMultipleConnections).setHidden(!0)),this.staticInputKeys.push("_node"),this.staticOutputKeys.push("_node"),this.executeFactory("input",s.inputs),this.executeFactory("output",s.outputs),s.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(),s.onPlaced?.call(this)}onDestroy(){s.onDestroy?.call(this)}onCodeUpdate(){s.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 o=t.inputs[n].value;let a;typeof o=="number"?a=new i.IntegerInterface(n,o).use(i.setType,O):a=new i.TextInputInterface(n,JSON.stringify(o)).use(i.setType,S),a.use(i.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 o=new X(n);this.addOutput(n,o)}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),o=s.onUpdate.call(this,t,n);this.updateInterfaces("input",o.inputs??{},o.forceUpdateInputs??[]),this.updateInterfaces("output",o.outputs??{},o.forceUpdateOutputs??[]),this.graph&&this.graph.activeTransactions--}getStaticValues(t,n){const o={};for(const a of t)o[a]=n[a].value;return o}updateInterfaces(t,n,o){const a=t==="input"?this.staticInputKeys:this.staticOutputKeys,r=t==="input"?this.inputs:this.outputs;for(const c of Object.keys(r))a.includes(c)||n[c]&&!o.includes(c)||(t==="input"?this.removeInput(c):this.removeOutput(c));for(const c of Object.keys(n)){if(r[c])continue;const l=n[c]();t==="input"?this.addInput(c,l):this.addOutput(c,l)}}executeFactory(t,n){Object.keys(n||{}).forEach(o=>{const a=n[o]();t==="input"?this.addInput(o,a):this.addOutput(o,a)})}}}class Y{_id;_viewModel;_state;constructor(t){this._id=re.v4(),this._viewModel=t,this._state=e.reactive({autosort:!1,modules:{},script:"",token:null,template:""})}get codeNodes(){return $(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 $(this.graph).filter(t=>t.state?.script.length>0)}get shortId(){return this.id.slice(0,6)}get state(){return this._state}get viewModel(){return this._viewModel}get visibleNodes(){return this.codeNodes.filter(t=>!t.state?.hidden)}addNode(t,n){return t.code||(t.code=this),n&&(t.state.props=n),this.graph.addNode(t)}addNodeAtCoordinates=(t,n={x:0,y:0},o)=>(this.addNode(t,o),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(o=>o.from.id===t.id&&o.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=G.render(this.state.template||"",this)}save(){this.state.autosort&&this.sortNodes();const t=this.viewModel.editor.save();return t.graph.id=this.id,this.saveNodeStates(t.graph.nodes),JSON.parse(JSON.stringify(t))}saveNodeStates(t){t.forEach((n,o)=>{const a=this.nodes[o];Object.entries(n.inputs).forEach(([r])=>{n.inputs&&a.inputs[r]&&(n.inputs[r].hidden=a.inputs[r].hidden)}),Object.entries(n.outputs).forEach(([r])=>{n.outputs&&a.outputs[r]&&(n.outputs[r].hidden=a.outputs[r].hidden)})})}sortNodes(){if(!(this.nodes.length===0||this.connections.length===0))try{const t=this.connections.map(r=>[r.to.nodeId,r.from.nodeId]);let n=[...this.nodeIds];n.reverse(),n=ae.array(n,t),n.reverse();const o=this.graph.nodes.map(r=>r.id).filter(r=>!n.includes(r));n=n.concat(o);const a=n.map(r=>this.findNodeById(r));a&&(this.nodes=a)}catch{console.warn("Failed to sort nodes.")}}updateOutputVariableNames(){this.codeNodes.forEach(t=>t.updateOutputVariableName())}}const $=s=>{let t=[];return s.nodes.forEach(n=>{n.subgraph?t=t.concat($(n.subgraph)):n.isCodeNode&&t.push(n)}),t},Ce=(s=0,t=100)=>({x:s*420,y:t}),ke=s=>{const t={...s.position};return t.x-=400,t.y+=50,t},we=s=>{const{calculationOrder:t,connectionsFromNode:n}=i.sortTopologically(s);t.forEach(o=>{if(!o.isCodeNode)return;const a=o;n.has(a)&&n.get(a).forEach(r=>{r.to.state&&r.from.script&&(r.to.state.script=r.from.script)})})},Ie=["id"],Ee={class:"align-middle"},J=e.defineComponent({__name:"CodeGraphNodeInterface",props:{node:{},intf:{}},setup(s){const t=s,{viewModel:n}=i.useViewModel(),{hoveredOver:o,temporaryConnection:a}=i.useTemporaryConnection(),r=e.ref(null),c=e.computed(()=>t.intf.connectionCount>0),l=e.computed(()=>({"--connected":c.value})),m=()=>{o(t.intf)},_=()=>{o(void 0)},N=()=>{r.value&&n.value.hooks.renderInterface.execute({intf:t.intf,el:r.value})};return e.onMounted(N),e.onUpdated(N),(k,B)=>(e.openBlock(),e.createElementBlock("div",{id:k.intf.id,ref_key:"el",ref:r,class:e.normalizeClass(["baklava-node-interface",l.value])},[k.intf.port?(e.openBlock(),e.createElementBlock("div",{key:0,class:e.normalizeClass(["__port",{"--selected":e.unref(a)?.from===k.intf}]),onPointerover:m,onPointerout:_},null,34)):e.createCommentVNode("",!0),e.createElementVNode("span",Ee,[e.renderSlot(k.$slots,"default")])],10,Ie))}}),E=(s,t)=>{const n=s.__vccOpts||s;for(const[o,a]of t)n[o]=a;return n},Be={},xe={xmlns:"http://www.w3.org/2000/svg",width:"24",height:"24",viewBox:"0 0 24 24",fill:"currentColor",class:"baklava-icon icon icon-tabler icons-tabler-filled icon-tabler-layout-sidebar-left-collapse"};function Ve(s,t){return e.openBlock(),e.createElementBlock("svg",xe,[...t[0]||(t[0]=[e.createElementVNode("path",{stroke:"none",d:"M0 0h24v24H0z",fill:"none"},null,-1),e.createElementVNode("path",{d:"M18 3a3 3 0 0 1 2.995 2.824l.005 .176v12a3 3 0 0 1 -2.824 2.995l-.176 .005h-12a3 3 0 0 1 -2.995 -2.824l-.005 -.176v-12a3 3 0 0 1 2.824 -2.995l.176 -.005h12zm0 2h-9v14h9a1 1 0 0 0 .993 -.883l.007 -.117v-12a1 1 0 0 0 -.883 -.993l-.117 -.007zm-2.293 4.293a1 1 0 0 1 .083 1.32l-.083 .094l-1.292 1.293l1.292 1.293a1 1 0 0 1 .083 1.32l-.083 .094a1 1 0 0 1 -1.32 .083l-.094 -.083l-2 -2a1 1 0 0 1 -.083 -1.32l.083 -.094l2 -2a1 1 0 0 1 1.414 0z"},null,-1)])])}const Te=E(Be,[["render",Ve]]),Me={},Oe={xmlns:"http://www.w3.org/2000/svg",width:"24",height:"24",viewBox:"0 0 24 24",fill:"currentColor",class:"baklava-icon icon icon-tabler icons-tabler-filled icon-tabler-layout-sidebar-left-expand"};function Se(s,t){return e.openBlock(),e.createElementBlock("svg",Oe,[...t[0]||(t[0]=[e.createElementVNode("path",{stroke:"none",d:"M0 0h24v24H0z",fill:"none"},null,-1),e.createElementVNode("path",{d:"M18 3a3 3 0 0 1 2.995 2.824l.005 .176v12a3 3 0 0 1 -2.824 2.995l-.176 .005h-12a3 3 0 0 1 -2.995 -2.824l-.005 -.176v-12a3 3 0 0 1 2.824 -2.995l.176 -.005h12zm0 2h-9v14h9a1 1 0 0 0 .993 -.883l.007 -.117v-12a1 1 0 0 0 -.883 -.993l-.117 -.007zm-4.387 4.21l.094 .083l2 2a1 1 0 0 1 .083 1.32l-.083 .094l-2 2a1 1 0 0 1 -1.497 -1.32l.083 -.094l1.292 -1.293l-1.292 -1.293a1 1 0 0 1 -.083 -1.32l.083 -.094a1 1 0 0 1 1.32 -.083z"},null,-1)])])}const $e=E(Me,[["render",Se]]),ze={},Le={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 ve(s,t){return e.openBlock(),e.createElementBlock("svg",Le,[...t[0]||(t[0]=[e.createElementVNode("path",{stroke:"none",d:"M0 0h24v24H0z",fill:"none"},null,-1),e.createElementVNode("path",{d:"M6 21a3 3 0 0 1 -3 -3v-12a3 3 0 0 1 3 -3h12a3 3 0 0 1 3 3v12a3 3 0 0 1 -3 3zm8 -16h-8a1 1 0 0 0 -1 1v12a1 1 0 0 0 1 1h8z"},null,-1)])])}const Re=E(ze,[["render",ve]]),De={},Pe={xmlns:"http://www.w3.org/2000/svg",width:"24",height:"24",viewBox:"0 0 24 24",fill:"currentColor",class:"baklava-icon icon icon-tabler icons-tabler-filled icon-tabler-layout-sidebar-right-collapse"};function Ge(s,t){return e.openBlock(),e.createElementBlock("svg",Pe,[...t[0]||(t[0]=[e.createElementVNode("path",{stroke:"none",d:"M0 0h24v24H0z",fill:"none"},null,-1),e.createElementVNode("path",{d:"M18 3a3 3 0 0 1 2.995 2.824l.005 .176v12a3 3 0 0 1 -2.824 2.995l-.176 .005h-12a3 3 0 0 1 -2.995 -2.824l-.005 -.176v-12a3 3 0 0 1 2.824 -2.995l.176 -.005h12zm-3 2h-9a1 1 0 0 0 -.993 .883l-.007 .117v12a1 1 0 0 0 .883 .993l.117 .007h9v-14zm-5.387 4.21l.094 .083l2 2a1 1 0 0 1 .083 1.32l-.083 .094l-2 2a1 1 0 0 1 -1.497 -1.32l.083 -.094l1.292 -1.293l-1.292 -1.293a1 1 0 0 1 -.083 -1.32l.083 -.094a1 1 0 0 1 1.32 -.083z"},null,-1)])])}const Ue=E(De,[["render",Ge]]),Fe={},Ae={xmlns:"http://www.w3.org/2000/svg",width:"24",height:"24",viewBox:"0 0 24 24",fill:"currentColor",class:"baklava-icon icon icon-tabler icons-tabler-filled icon-tabler-layout-sidebar-right-expand"};function He(s,t){return e.openBlock(),e.createElementBlock("svg",Ae,[...t[0]||(t[0]=[e.createElementVNode("path",{stroke:"none",d:"M0 0h24v24H0z",fill:"none"},null,-1),e.createElementVNode("path",{d:"M18 3a3 3 0 0 1 2.995 2.824l.005 .176v12a3 3 0 0 1 -2.824 2.995l-.176 .005h-12a3 3 0 0 1 -2.995 -2.824l-.005 -.176v-12a3 3 0 0 1 2.824 -2.995l.176 -.005h12zm-3 2h-9a1 1 0 0 0 -.993 .883l-.007 .117v12a1 1 0 0 0 .883 .993l.117 .007h9v-14zm-3.293 4.293a1 1 0 0 1 .083 1.32l-.083 .094l-1.292 1.293l1.292 1.293a1 1 0 0 1 .083 1.32l-.083 .094a1 1 0 0 1 -1.32 .083l-.094 -.083l-2 -2a1 1 0 0 1 -.083 -1.32l.083 -.094l2 -2a1 1 0 0 1 1.414 0z"},null,-1)])])}const We=E(Fe,[["render",He]]),Xe={},qe={xmlns:"http://www.w3.org/2000/svg",class:"baklava-icon",width:"24",height:"24",viewBox:"0 0 24 24",fill:"none",stroke:"currentColor","stroke-width":"2","stroke-linecap":"round","stroke-linejoin":"round"};function Ye(s,t){return e.openBlock(),e.createElementBlock("svg",qe,[...t[0]||(t[0]=[e.createStaticVNode('<path stroke="none" d="M0 0h24v24H0z" fill="none"></path><path d="M5 2h5v4h-5z"></path><path d="M15 10h5v4h-5z"></path><path d="M5 18h5v4h-5z"></path><path d="M5 10h5v4h-5z"></path><path d="M10 12h5"></path><path d="M7.5 6v4"></path><path d="M7.5 14v4"></path>',8)])])}const Je=E(Xe,[["render",Ye]]),Qe={},Ke={xmlns:"http://www.w3.org/2000/svg",class:"baklava-icon",width:"24",height:"24",viewBox:"0 0 24 24",fill:"none",stroke:"currentColor","stroke-width":"2","stroke-linecap":"round","stroke-linejoin":"round"};function Ze(s,t){return e.openBlock(),e.createElementBlock("svg",Ke,[...t[0]||(t[0]=[e.createStaticVNode('<path stroke="none" d="M0 0h24v24H0z" fill="none"></path><path d="M6 2h4v4m-4 0h-1v-1"></path><path d="M15 11v-1h5v4h-2"></path><path d="M5 18h5v4h-5z"></path><path d="M5 10h5v4h-5z"></path><path d="M10 12h2"></path><path d="M7.5 7.5v2.5"></path><path d="M7.5 14v4"></path><path d="M3 3l18 18"></path>',9)])])}const je=E(Qe,[["render",Ze]]),et={},tt={xmlns:"http://www.w3.org/2000/svg",class:"baklava-icon",width:"24",height:"24",viewBox:"0 0 24 24",fill:"none",stroke:"currentColor","stroke-width":"2","stroke-linecap":"round","stroke-linejoin":"round"};function nt(s,t){return e.openBlock(),e.createElementBlock("svg",tt,[...t[0]||(t[0]=[e.createStaticVNode('<path stroke="none" d="M0 0h24v24H0z" fill="none"></path><path d="M3 3l18 18"></path><path d="M4 7h3m4 0h9"></path><path d="M10 11l0 6"></path><path d="M14 14l0 3"></path><path d="M5 7l1 12a2 2 0 0 0 2 2h8a2 2 0 0 0 2 -2l.077 -.923"></path><path d="M18.384 14.373l.616 -7.373"></path><path d="M9 5v-1a1 1 0 0 1 1 -1h4a1 1 0 0 1 1 1v3"></path>',8)])])}const ot=E(et,[["render",nt]]),st={},at={xmlns:"http://www.w3.org/2000/svg",class:"baklava-icon",width:"16",height:"16",viewBox:"0 0 24 24","stroke-width":"2",stroke:"currentColor",fill:"none","stroke-linecap":"round","stroke-linejoin":"round"};function rt(s,t){return e.openBlock(),e.createElementBlock("svg",at,[...t[0]||(t[0]=[e.createElementVNode("path",{stroke:"none",d:"M0 0h24v24H0z",fill:"none"},null,-1),e.createElementVNode("circle",{cx:"12",cy:"12",r:"1"},null,-1),e.createElementVNode("circle",{cx:"12",cy:"19",r:"1"},null,-1),e.createElementVNode("circle",{cx:"12",cy:"5",r:"1"},null,-1)])])}const it=E(st,[["render",rt]]),dt=["id","data-node-type"],lt={class:"__title-label",style:{"flex-grow":"1"}},ct={key:0},pt={class:"__menu",style:{display:"flex"}},ut={class:"__outputs"},ht={key:0},mt=["id","title"],ft={class:"__inputs"},gt={key:0},yt=["id","title"],_t=e.defineComponent({__name:"CodeGraphNode",props:{node:{},selected:{type:Boolean,default:!1},dragging:{type:Boolean}},emits:["select","start-drag","update"],setup(s,{emit:t}){const n=i.Components.ContextMenu,o=i.Components.NodeInterface,a=s,r=e.computed(()=>a.node),c=t,{viewModel:l}=i.useViewModel(),{graph:m,switchGraph:_}=i.useGraph(),N=e.ref(null),k=e.ref(!1),B=e.ref(""),b=e.ref(null),f=e.ref(!1);let g=0,h=0;const u=e.ref(!1),C=e.computed(()=>{const p=[{value:"edit",label:"Edit"},{value:"rename",label:"Rename"},{value:"delete",label:"Delete"}];return a.node.type.startsWith(i.GRAPH_NODE_TYPE_PREFIX)&&p.push({value:"editSubgraph",label:"Edit Subgraph"}),p}),I=e.computed(()=>({"--selected":a.selected,"--dragging":a.dragging,"--two-column":!!a.node.twoColumn,"--hidden":r.value.state?.hidden})),Pt=e.computed(()=>({"--reverse-y":a.node.reverseY??l.value.settings.nodes.reverseY})),Gt=e.computed(()=>({top:`${a.node.position?.y??0}px`,left:`${a.node.position?.x??0}px`,"--width":`${a.node.width??l.value.settings.nodes.defaultWidth}px`})),Ut=e.computed(()=>Object.values(a.node.inputs).filter(p=>!p.hidden)),Ft=e.computed(()=>Object.values(a.node.outputs).filter(p=>!p.hidden)),Z=()=>{c("select")},At=p=>{a.selected||Z(),c("start-drag",p)},j=()=>{u.value=!0},Ht=()=>{const p=l.value.displayedGraph.sidebar;p.nodeId="",p.visible=!1},ee=()=>{const p=l.value.displayedGraph.sidebar;p.nodeId=a.node.id,p.visible=!0},Wt=()=>{const p=l.value.displayedGraph.sidebar;p.nodeId=a.node.id},Xt=async p=>{switch(p){case"edit":ee();break;case"delete":m.value.removeNode(a.node);break;case"rename":B.value=a.node.title,k.value=!0,await e.nextTick(),b.value?.focus();break;case"editSubgraph":_(a.node.template);break}},te=()=>{a.node.title=B.value,k.value=!1},ne=()=>{N.value&&l.value.hooks.renderNode.execute({node:a.node,el:N.value})},qt=p=>{f.value=!0,g=a.node.width,h=p.clientX,p.preventDefault()},oe=p=>{if(!f.value)return;const w=p.clientX-h,y=g+w/m.value.scaling,Yt=l.value.settings.nodes.minWidth,Jt=l.value.settings.nodes.maxWidth;a.node.width=Math.max(Yt,Math.min(Jt,y))},se=()=>{f.value=!1};return e.onMounted(()=>{ne(),window.addEventListener("mousemove",oe),window.addEventListener("mouseup",se)}),e.onUpdated(ne),e.onBeforeUnmount(()=>{window.removeEventListener("mousemove",oe),window.removeEventListener("mouseup",se)}),(p,w)=>(e.openBlock(),e.createElementBlock("div",{id:r.value.id,ref_key:"el",ref:N,class:e.normalizeClass([I.value,"baklava-node"]),"data-node-type":r.value.type,style:e.normalizeStyle(Gt.value),onPointerdown:Z},[e.unref(l).settings.nodes.resizable?(e.openBlock(),e.createElementBlock("div",{key:0,class:"__resize-handle",onMousedown:qt},null,32)):e.createCommentVNode("",!0),e.createElementVNode("div",{class:"__title",onPointerdown:e.withModifiers(At,["self","stop"]),onContextmenu:e.withModifiers(j,["prevent"])},[r.value.inputs._node?(e.openBlock(),e.createBlock(J,{key:0,node:r.value,intf:r.value.inputs._node,class:"--input","data-interface-type":"node",style:{"flex-grow":"0"}},null,8,["node","intf"])):e.createCommentVNode("",!0),k.value?e.withDirectives((e.openBlock(),e.createElementBlock("input",{key:2,ref_key:"renameInputEl",ref:b,"onUpdate:modelValue":w[1]||(w[1]=y=>B.value=y),class:"baklava-input",placeholder:"Node Name",style:{"flex-grow":"1"},type:"text",onBlur:te,onKeydown:e.withKeys(te,["enter"])},null,544)),[[e.vModelText,B.value]]):(e.openBlock(),e.createElementBlock(e.Fragment,{key:1},[e.createElementVNode("div",lt,[r.value.idx>-1?(e.openBlock(),e.createElementBlock("span",ct,e.toDisplayString(r.value.idx+1)+" - ",1)):e.createCommentVNode("",!0),e.createTextVNode(e.toDisplayString(r.value.title)+" ("+e.toDisplayString(r.value.shortId)+") ",1)]),e.createElementVNode("div",pt,[r.value.subgraph?e.createCommentVNode("",!0):(e.openBlock(),e.createElementBlock(e.Fragment,{key:0},[!e.unref(l).displayedGraph.sidebar.visible&&e.unref(l).displayedGraph.sidebar.nodeId!==r.value.id?(e.openBlock(),e.createBlock(e.unref(We),{key:0,class:"--clickable mx-1",onClick:ee})):e.unref(l).displayedGraph.sidebar.visible&&e.unref(l).displayedGraph.sidebar.nodeId!==r.value.id?(e.openBlock(),e.createBlock(e.unref(Re),{key:1,class:"--clickable mx-1",onClick:Wt})):(e.openBlock(),e.createBlock(e.unref(Ue),{key:2,class:"--clickable mx-1",onClick:Ht}))],64)),e.createVNode(e.unref(it),{class:"--clickable mx-1",onClick:j}),e.createVNode(e.unref(n),{modelValue:u.value,"onUpdate:modelValue":w[0]||(w[0]=y=>u.value=y),x:0,y:0,items:C.value,onClick:Xt},null,8,["modelValue","items"])])],64)),r.value.outputs._node?(e.openBlock(),e.createBlock(J,{key:3,node:r.value,intf:r.value.outputs._node,class:"--output","data-interface-type":"node"},null,8,["node","intf"])):e.createCommentVNode("",!0)],32),e.createElementVNode("div",{class:e.normalizeClass(["__content",Pt.value]),onKeydown:w[2]||(w[2]=e.withKeys(e.withModifiers(()=>{},["stop"]),["delete"])),onContextmenu:w[3]||(w[3]=e.withModifiers(()=>{},["prevent"]))},[e.createElementVNode("div",ut,[(e.openBlock(!0),e.createElementBlock(e.Fragment,null,e.renderList(Ft.value,y=>(e.openBlock(),e.createElementBlock(e.Fragment,{key:y.id},[r.value.state?.hidden?(e.openBlock(),e.createElementBlock("div",ht,[y.port?(e.openBlock(),e.createElementBlock("div",{key:0,id:y.id,title:y.name,class:"baklava-node-interface --output --connected"},[...w[4]||(w[4]=[e.createElementVNode("div",{class:"__port"},null,-1)])],8,mt)):e.createCommentVNode("",!0)])):e.renderSlot(p.$slots,"nodeInterface",{key:1,type:"output",node:r.value,intf:y},()=>[e.createVNode(e.unref(o),{node:r.value,intf:y},null,8,["node","intf"])])],64))),128))]),e.createElementVNode("div",ft,[(e.openBlock(!0),e.createElementBlock(e.Fragment,null,e.renderList(Ut.value,y=>(e.openBlock(),e.createElementBlock(e.Fragment,{key:y.id},[r.value.state?.hidden?(e.openBlock(),e.createElementBlock("div",gt,[y.port?(e.openBlock(),e.createElementBlock("div",{key:0,id:y.id,title:y.name,class:"baklava-node-interface --input --connected"},[...w[5]||(w[5]=[e.createElementVNode("div",{class:"__port"},null,-1)])],8,yt)):e.createCommentVNode("",!0)])):e.renderSlot(p.$slots,"nodeInterface",{key:1,node:r.value,intf:y,type:"input"},()=>[e.createVNode(e.unref(o),{node:r.value,intf:y,title:y.name},null,8,["node","intf","title"])])],64))),128))])],34)],46,dt))}}),Nt=["title"],bt={key:0,class:"__label"},Ct=e.defineComponent({__name:"Checkbox",props:{disabled:{type:Boolean},inversed:{type:Boolean},modelValue:{type:Boolean},name:{}},emits:["update:modelValue"],setup(s,{emit:t}){const n=t;return(o,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]=r=>n("update:modelValue",!o.modelValue))},[a[1]||(a[1]=e.createElementVNode("div",{class:"__checkmark-container"},[e.createElementVNode("svg",{xmlns:"http://www.w3.org/2000/svg",width:"18",height:"18",viewBox:"0 0 18 18"},[e.createElementVNode("path",{class:"__checkmark",d:"M 6 5 L 6 10 L 16 10",transform:"rotate(-45 10 10)"})])],-1)),o.name?(e.openBlock(),e.createElementBlock("div",bt,e.toDisplayString(o.name),1)):e.createCommentVNode("",!0)],10,Nt))}}),kt={class:"__header"},wt={class:"__node-name"},It={style:{display:"flex"}},Et={key:1,class:"__interface"},Bt=e.defineComponent({__name:"CodeGraphSidebar",setup(s){const{viewModel:t}=i.useViewModel(),{graph:n}=i.useGraph(),o=e.ref(null),a=e.toRef(t.value.settings.sidebar,"width"),r=e.computed(()=>t.value.settings.sidebar.resizable);let c=0,l=0;const m=e.computed(()=>{const h=n.value.sidebar.nodeId;return n.value.nodes.find(u=>u.id===h)}),_=e.computed(()=>m.value),N=e.computed(()=>({width:`${a.value}px`})),k=e.computed(()=>_.value?[...Object.values(_.value.inputs),...Object.values(_.value.outputs)].filter(u=>u.displayInSidebar&&u.component):[]),B=()=>{n.value.sidebar.visible=!1},b=()=>{m.value?.events.update.emit(null)},f=h=>{c=a.value,l=h.clientX,window.addEventListener("mousemove",g),window.addEventListener("mouseup",()=>{window.removeEventListener("mousemove",g)},{once:!0})},g=h=>{const u=o.value?.parentElement?.getBoundingClientRect().width??500,C=h.clientX-l;let I=c-C;I<300?I=300:I>.9*u&&(I=.9*u),a.value=I};return(h,u)=>(e.openBlock(),e.createElementBlock("div",{ref_key:"el",ref:o,class:e.normalizeClass(["baklava-sidebar",{"--open":e.unref(n).sidebar.visible}]),style:e.normalizeStyle(N.value)},[r.value?(e.openBlock(),e.createElementBlock("div",{key:0,class:"__resizer",onMousedown:f},null,32)):e.createCommentVNode("",!0),e.createElementVNode("div",kt,[e.createElementVNode("button",{tabindex:"-1",class:"__close",onClick:B},"×"),e.createElementVNode("div",wt,[e.createElementVNode("b",null,e.toDisplayString(m.value?m.value.title:""),1)])]),(e.openBlock(!0),e.createElementBlock(e.Fragment,null,e.renderList(k.value,C=>(e.openBlock(),e.createElementBlock("div",{key:C.id,class:"__interface"},[e.createElementVNode("div",It,[e.createVNode(Ct,{modelValue:C.hidden,"onUpdate:modelValue":[I=>C.hidden=I,u[0]||(u[0]=()=>m.value?.events.update.emit(null))],disabled:!C.optional,inversed:"",style:{"margin-right":"8px"}},null,8,["modelValue","onUpdate:modelValue","disabled"]),(e.openBlock(),e.createBlock(e.resolveDynamicComponent(C.component),{modelValue:C.value,"onUpdate:modelValue":I=>C.value=I,node:m.value,intf:C,style:{width:"100%"}},null,8,["modelValue","onUpdate:modelValue","node","intf"]))])]))),128)),_.value&&_.value.state?(e.openBlock(),e.createElementBlock("div",Et,[u[2]||(u[2]=e.createElementVNode("label",null,"Variable name",-1)),e.withDirectives(e.createElementVNode("input",{"onUpdate:modelValue":u[1]||(u[1]=C=>_.value.state.variableName=C),type:"text",class:"baklava-input",title:"Variable name",onBlur:b,onKeydown:e.withKeys(b,["enter"])},null,544),[[e.vModelText,_.value.state.variableName]])])):e.createCommentVNode("",!0)],6))}}),xt=e.defineComponent({props:{type:{type:String,required:!0},title:{type:String,required:!0}},setup(s){const{viewModel:t}=i.useViewModel(),{switchGraph:n}=i.useGraph(),o=e.ref(!1),a=e.computed(()=>s.type.startsWith(i.GRAPH_NODE_TYPE_PREFIX));return{showContextMenu:o,hasContextMenu:a,contextMenuItems:[{label:"Edit Subgraph",value:"editSubgraph"},{label:"Delete Subgraph",value:"deleteSubgraph"}],openContextMenu:()=>{o.value=!0},onContextMenuClick:m=>{const _=s.type.substring(i.GRAPH_NODE_TYPE_PREFIX.length),N=t.value.editor.graphTemplates.find(k=>k.id===_);if(N)switch(m){case"editSubgraph":n(N);break;case"deleteSubgraph":t.value.editor.removeGraphTemplate(N);break}}}}}),Vt=["data-node-type"],Tt={class:"__title"},Mt={class:"__title-label"};function Ot(s,t,n,o,a,r){return e.openBlock(),e.createElementBlock("div",{class:"baklava-node --palette","data-node-type":s.type},[e.createElementVNode("div",Tt,[e.createElementVNode("div",Mt,e.toDisplayString(s.title),1)])],8,Vt)}const Q=E(xt,[["render",Ot]]),St={class:"baklava-node --palette",style:{"margin-top":"-20px","margin-bottom":"20px"}},$t={key:0,style:{display:"flex","justify-content":"space-between"}},zt=["onClick"],Lt={key:0,style:{margin:"auto 0","font-size":"12px"}},vt=e.defineComponent({__name:"CodeNodePalette",setup(s){const{viewModel:t}=i.useViewModel(),{x:n,y:o}=ie.usePointer(),{transform:a}=i.useTransform(),r=i.useNodeCategories(t),c=e.inject("editorEl"),l=e.ref(""),m=e.ref(null),_=()=>l.value?r.value.filter(b=>b.name.toLowerCase().includes(l.value.toLowerCase())||Object.values(b.nodeTypes).some(f=>f.title.toLowerCase().includes(l.value.toLowerCase()))):r.value,N=b=>l.value?Object.values(b).filter(f=>f.category.toLowerCase().includes(l.value.toLowerCase())||f.title.toLowerCase().includes(l.value.toLowerCase())):Object.values(b),k=e.computed(()=>{if(!m.value||!c?.value)return{};const{left:b,top:f}=c.value.getBoundingClientRect();return{top:`${o.value-f}px`,left:`${n.value-b}px`}}),B=(b,f)=>{m.value={type:b,nodeInformation:f};const g=()=>{const h=e.reactive(new f.type);t.value.displayedGraph.addNode(h);const u=c.value.getBoundingClientRect(),[C,I]=a(n.value-u.left,o.value-u.top);h.position.x=C,h.position.y=I,m.value=null,document.removeEventListener("pointerup",g)};document.addEventListener("pointerup",g)};return(b,f)=>(e.openBlock(),e.createElementBlock(e.Fragment,null,[e.createElementVNode("div",{class:e.normalizeClass(["baklava-node-palette",{"--open":e.unref(t).settings.palette.enabled}]),onContextmenu:f[1]||(f[1]=e.withModifiers(()=>{},["stop","prevent"]))},[e.createElementVNode("div",St,[e.withDirectives(e.createElementVNode("input",{"onUpdate:modelValue":f[0]||(f[0]=g=>l.value=g),type:"text",class:"baklava-input",title:"Filter nodes",onKeyup:_},null,544),[[e.vModelText,l.value]])]),(e.openBlock(!0),e.createElementBlock(e.Fragment,null,e.renderList(_(),g=>(e.openBlock(),e.createElementBlock("section",{key:g.name},[g.name!=="default"?(e.openBlock(),e.createElementBlock("h3",$t,[e.createElementVNode("div",{onClick:h=>l.value=g.name,style:{cursor:"pointer"}},e.toDisplayString(g.name),9,zt),N(g.nodeTypes).length<Object.values(g.nodeTypes).length?(e.openBlock(),e.createElementBlock("div",Lt," ( "+e.toDisplayString(N(g.nodeTypes).length)+" / "+e.toDisplayString(Object.values(g.nodeTypes).length)+" ) ",1)):e.createCommentVNode("",!0)])):e.createCommentVNode("",!0),(e.openBlock(!0),e.createElementBlock(e.Fragment,null,e.renderList(N(g.nodeTypes),h=>(e.openBlock(),e.createBlock(Q,{key:h.type,type:h.type,title:h.title,onPointerdown:u=>B(h.type,h)},null,8,["type","title","onPointerdown"]))),128))]))),128))],34),e.createVNode(e.Transition,{name:"fade"},{default:e.withCtx(()=>[m.value?(e.openBlock(),e.createElementBlock("div",{key:0,class:"baklava-dragged-node",style:e.normalizeStyle(k.value)},[e.createVNode(Q,{type:m.value.type,title:m.value.nodeInformation.title},null,8,["type","title"])],4)):e.createCommentVNode("",!0)]),_:1})],64))}}),Rt=e.defineComponent({__name:"CodeGraphEditor",props:{viewModel:{}},setup(s){const t=s,n=e.toRef(t,"viewModel"),o=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,r)=>(e.openBlock(),e.createBlock(e.unref(i.BaklavaEditor),{"view-model":n.value},{palette:e.withCtx(()=>[e.createVNode(vt)]),node:e.withCtx(c=>[e.createVNode(_t,e.mergeProps(c,{onUpdate:l=>o(c.node)}),null,16,["onUpdate"])]),sidebar:e.withCtx(c=>[e.createVNode(Bt,e.normalizeProps(e.guardReactiveProps(c)),null,16)]),_:1},8,["view-model"]))}}),K=s=>{const t="TOGGLE_PALETTE";s.commandHandler.registerCommand(t,{execute:()=>s.settings.palette.enabled=!s.settings.palette.enabled,canExecute:()=>!0});const n="CLEAR_ALL";s.commandHandler.registerCommand(n,{execute:()=>s.code.clear(),canExecute:()=>s.displayedGraph.nodes.length>0});const o="TOGGLE_MINIMAP";s.commandHandler.registerCommand(o,{execute:()=>s.settings.enableMinimap=!s.settings.enableMinimap,canExecute:()=>s.displayedGraph.nodes.length>1}),s.settings.toolbar.commands=[{command:t,title:"Toggle palette",icon:e.computed(()=>s.settings.palette.enabled?Te:$e)},...i.DEFAULT_TOOLBAR_COMMANDS,{command:n,title:"Clear all",icon:ot},{command:o,title:"Toggle minimap",icon:e.computed(()=>s.settings.enableMinimap?je:Je)}]},T={enableMinimap:!1,toolbar:{enabled:!0},palette:{enabled:!0},sidebar:{enabled:!0,resizable:!0,width:350},displayValueOnHover:!1};function Dt(s){const t=i.useBaklava(s?.existingEditor);t.code=s?.code?new s.code(t):new Y(t),K(t);const n={};return Object.keys(T).forEach(o=>{n[o]=typeof T[o]=="object"?{...t.settings[o],...T[o]}:T[o]}),t.settings=e.reactive({...t.settings,...n}),t.settings.nodes.defaultWidth=350,t.state=e.reactive({modules:{},token:null}),t.engine=new i.DependencyEngine(t.editor),t.subscribe=()=>{t.state.token&&t.unsubscribe();const o=Symbol();t.displayedGraph.events.addNode.subscribe(o,a=>a.code=t.code),t.engine.events.beforeRun.subscribe(o,()=>{t.engine.pause(),t.code&&(t.code.onCodeUpdate(),t.code.sortNodes()),t.engine.resume()}),t.engine.events.beforeNodeCalculation.subscribe(o,a=>{t.engine.pause();const r=a.node;r.isCodeNode&&(r.updateOutputVariableName(),r.updateCodeNodeInputInterfaces()),t.engine.resume()}),t.engine.events.afterRun.subscribe(o,a=>{t.engine.pause(),i.applyResult(a,t.editor),t.code&&(t.code.renderNodeCodes(),t.code.renderCode()),t.engine.resume()}),t.state.token=o},t.unsubscribe=()=>{if(!t.state.token)return;const o=t.state.token;t.displayedGraph.events.addNode.unsubscribe(o),t.engine.events.beforeRun.unsubscribe(o),t.engine.events.afterRun.unsubscribe(o),t.state.token=null},t}Object.defineProperty(d,"CheckboxInterfaceComponent",{enumerable:!0,get:()=>i.CheckboxInterfaceComponent}),Object.defineProperty(d,"IntegerInterfaceComponent",{enumerable:!0,get:()=>i.IntegerInterfaceComponent}),Object.defineProperty(d,"NumberInterfaceComponent",{enumerable:!0,get:()=>i.NumberInterfaceComponent}),Object.defineProperty(d,"SelectInterfaceComponent",{enumerable:!0,get:()=>i.SelectInterfaceComponent}),Object.defineProperty(d,"SliderInterfaceComponent",{enumerable:!0,get:()=>i.SliderInterfaceComponent}),Object.defineProperty(d,"TextInputInterfaceComponent",{enumerable:!0,get:()=>i.TextInputInterfaceComponent}),Object.defineProperty(d,"TextareaInputInterfaceComponent",{enumerable:!0,get:()=>i.TextareaInputInterfaceComponent}),d.AbstractCodeNode=U,d.CheckboxInterface=ue,d.Code=Y,d.CodeGraphEditor=Rt,d.CodeNode=z,d.CodeNodeInputInterface=M,d.CodeNodeInterface=x,d.CodeNodeOutputInterface=X,d.DEFAULT_SETTINGS=T,d.DynamicCodeNode=q,d.IntegerInterface=he,d.NumberInterface=me,d.SelectInterface=fe,d.SliderInterface=ge,d.TextInputInterface=ye,d.TextareaInputInterface=_e,d.addDefaultInterfaceTypes=pe,d.addToolbarCommands=K,d.booleanType=R,d.defineCodeNode=Ne,d.defineDynamicCodeNode=be,d.dictType=H,d.formatInputs=de,d.getCodeNodes=$,d.getPositionAtColumn=Ce,d.getPositionBeforeNode=ke,d.listType=W,d.loadNodeState=L,d.nodeType=V,d.numberType=O,d.saveNodeState=F,d.setOptional=ce,d.stringType=S,d.transferCodeScript=we,d.useCodeGraph=Dt,Object.defineProperty(d,Symbol.toStringTag,{value:"Module"})}));
1
+ (function(d,i){typeof exports=="object"&&typeof module<"u"?i(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"],i):(d=typeof globalThis<"u"?globalThis:d||self,i(d["@babsey/code-graph"]={},d.baklavajs,d.mustache,d.Vue,d.toposort,d.uuid,d["@vueuse/core"]))})(this,(function(d,i,G,e,ae,re,ie){"use strict";class U extends i.AbstractNode{state;code;isCodeNode=!0;codeTemplate=()=>"{{ &outputs.code }}";inputs={};outputs={};constructor(){super(),this.initializeIo(),this.width=400,this.twoColumn=!0,this.state=e.reactive({codeTemplate:"",hidden:!1,integrated:!1,modules:[],script:"",variableName:""})}get codeNodeInputs(){return Object.fromEntries(Object.entries(this.inputs).filter(([t,n])=>n.type!="node"))}get idx(){return this.code?.codeNodes.filter(t=>!t.state.integrated).indexOf(this)??-1}get idxByVariableNames(){return this.code?.getNodesBySameVariableNames(this.state.variableName).indexOf(this)??-1}get optionalInputs(){return Object.fromEntries(Object.entries(this.codeNodeInputs).filter(([t,n])=>n.optional))}get requiredInputs(){return Object.fromEntries(Object.entries(this.codeNodeInputs).filter(([t,n])=>!n.optional))}get script(){return this.state.script}get shortId(){return this.id.slice(0,6)}get variableName(){return this.state.variableName?this.state.variableName+(this.idxByVariableNames+1):""}getConnectedNodes(t){let n=[];if(t!=="inputs"){const o=this.graph?.connections.filter(a=>a.from.name!=="_node").filter(a=>a.from.nodeId===this.id).map(a=>a.to.nodeId);o&&(n=n.concat(o))}if(t!=="outputs"){const o=this.graph?.connections.filter(a=>a.from.name!=="_node").filter(a=>a.to.nodeId===this.id).map(a=>a.from.nodeId);o&&(n=n.concat(o))}return!n||n.length==0?[]:n.map(o=>this.graph?.findNodeById(o))}registerCode(t){this.code=t}renderCode(){this.state.codeTemplate=this.codeTemplate.call(this);const t={};Object.keys(this.inputs).forEach(o=>{if(o==="_node")return;const a=this.inputs[o],r=A(a);a&&a.state&&(t[o]=a.state.script.length>0?a.state.script:r)});const n={};Object.keys(this.outputs).forEach(o=>{if(o==="_node")return;const a=this.outputs[o],r=A(a);a&&a.state&&(n[o]=r)}),this.state.script=G.render(this.state.codeTemplate,{inputs:t,outputs:n}),this.outputs.code&&(this.outputs.code.state.script=this.state.script)}updateCodeNodeInputInterfaces(){if(!this.graph)return;const{connectionsFromNode:t}=i.sortTopologically(this.graph);t.has(this)&&t.get(this).forEach(n=>{const o=this.graph?.findNodeById(n.from.nodeId);o&&(o.renderCode(),n.from.isCodeNode&&n.to.isCodeNode&&(n.to.state.script=n.from.script))})}updateOutputVariableName(){this.outputs.code&&(this.outputs.code.name=this.variableName)}}class z extends U{calculate;load(t){super.load(t),v(this.graph,t)}save(){const t=super.save();return F(this.graph,t),t}updateModules(t){if(t)this.state.modules=t;else if(this.type.includes(".")){const n=this.type.split(".");this.state.modules.push(n.slice(0,n.length-1).join("."))}}}const de=s=>{const t=[],n=Object.keys(s);return n.forEach(o=>{if(s[o]?.hidden)return;const r=t.length<n.indexOf(o)?`${o}=`:"";t.push(`${r}{{& inputs.${o} }}`)}),t},v=(s,t)=>{if(!s)return;const n=s.findNodeById(t.id);if(!n||n.subgraph)return;const o=n;o.state&&(o.state.integrated=t.integrated,o.state.modules=t.modules,o.state.props=t.props),Object.entries(t.inputs).forEach(([a,r])=>{a!=="_node"&&o.inputs[a]&&(o.inputs[a].hidden=r.hidden)}),Object.entries(t.outputs).forEach(([a,r])=>{a!=="_node"&&o.outputs[a]&&(o.outputs[a].hidden=r.hidden)})},F=(s,t)=>{if(!s)return;const n=s.findNodeById(t.id);if(!n||n.subgraph)return;const o=n;o.state&&(t.integrated=o.state.integrated,t.modules=o.state.modules),Object.entries(t.inputs).forEach(([a,r])=>{a!=="_node"&&o.inputs[a]&&(r.hidden=o.inputs[a].hidden)}),Object.entries(t.outputs).forEach(([a,r])=>{a!=="_node"&&o.outputs[a]&&(r.hidden=o.outputs[a].hidden)})},A=s=>{let t;if(s.value==null)return"None";switch(s.type){case"boolean":t=s.value?"True":"False";break;case"string":t=`'${s.value}'`;break;case void 0:t="None";break;default:t=`${s.value}`}return t},le=["title"],L=e.defineComponent({__name:"CodeNodeInterface",props:{intf:{}},setup(s){return(t,n)=>(e.openBlock(),e.createElementBlock("div",{title:t.intf.state?.script},e.toDisplayString(t.intf.name),9,le))}});class x extends i.NodeInterface{isCodeNode=!0;code;state;type=null;constructor(t,n){super(t,n),this.setComponent(e.markRaw(L)),this.state=e.reactive({optional:!1,script:""})}get optional(){return this.state.optional}get shortId(){return this.id.slice(0,6)}}const ce=(s,t)=>{s.state.optional=t,s.setHidden(!0)};class M extends x{constructor(t="",n){super(t,n),this.setComponent(e.markRaw(L)),this.use(i.displayInSidebar,!0)}}const R=new i.NodeInterfaceType("boolean"),H=new i.NodeInterfaceType("dict"),W=new i.NodeInterfaceType("list"),V=new i.NodeInterfaceType("node"),O=new i.NodeInterfaceType("number"),S=new i.NodeInterfaceType("string"),pe=s=>{new i.BaklavaInterfaceTypes(s.editor,{viewPlugin:s}).addTypes(R,H,W,V,O,S)};class ue extends M{constructor(t,n){super(t,n),this.setComponent(e.markRaw(i.CheckboxInterfaceComponent)),this.use(i.setType,R)}}class X extends x{isCodeNodeOutput=!0;constructor(t="",n=""){super(t,n),this.setComponent(e.markRaw(L))}get script(){return this.name.length>0?this.name:this.state.script}}class D extends M{min;max;constructor(t,n,o,a){super(t,n),this.min=o,this.max=a,this.use(i.setType,O)}validate(t){return(this.min===void 0||t>=this.min)&&(this.max===void 0||t<=this.max)}}class he extends D{component=e.markRaw(i.IntegerInterfaceComponent);validate(t){return Number.isInteger(t)&&super.validate(t)}}class me extends D{component=e.markRaw(i.NumberInterfaceComponent)}class P extends M{constructor(t,n){super(t,n),this.use(i.setType,S)}}class fe extends P{component=e.markRaw(i.SelectInterfaceComponent);items;constructor(t,n,o){super(t,n),this.items=o}}class ge extends D{component=e.markRaw(i.SliderInterfaceComponent);min;max;constructor(t,n,o,a){super(t,n,o,a),this.min=o,this.max=a}}class ye extends P{component=e.markRaw(i.TextInputInterfaceComponent)}class _e extends P{component=e.markRaw(i.TextareaInputInterfaceComponent)}function Ne(s){return class extends z{type=s.type;inputs={};outputs={};constructor(){super(),this._title=s.title??s.type,this.updateModules(s.modules),s.variableName&&(this.state.variableName=s.variableName),s.codeTemplate&&(this.codeTemplate=s.codeTemplate),this.addInput("_node",new x("",[]).use(i.setType,V).use(i.allowMultipleConnections).setHidden(!0)),this.addOutput("_node",new x("",[]).use(i.setType,V).use(i.allowMultipleConnections).setHidden(!0)),this.executeFactory("input",s.inputs),this.executeFactory("output",s.outputs),s.onCreate?.call(this)}onPlaced(){s.onPlaced?.call(this)}onDestroy(){s.onDestroy?.call(this)}onCodeUpdate(){s.onCodeUpdate?.call(this)}executeFactory(t,n){Object.keys(n||{}).forEach(o=>{const a=n[o]();t==="input"?this.addInput(o,a):this.addOutput(o,a)})}}}class q extends z{calculate}function be(s){return class extends q{type=s.type;inputs={};outputs={};calculate;preventUpdate=!1;staticInputKeys=Object.keys(s.inputs??{});staticOutputKeys=Object.keys(s.outputs??{});constructor(){super(),this._title=s.title??s.type,this.updateModules(s.modules),s.codeTemplate&&(this.codeTemplate=s.codeTemplate),s.variableName&&(this.state.variableName=s.variableName),this.addInput("_node",new x("",[]).use(i.setType,V).use(i.allowMultipleConnections).setHidden(!0)),this.addOutput("_node",new x("",[]).use(i.setType,V).use(i.allowMultipleConnections).setHidden(!0)),this.staticInputKeys.push("_node"),this.staticOutputKeys.push("_node"),this.executeFactory("input",s.inputs),this.executeFactory("output",s.outputs),s.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(),s.onPlaced?.call(this)}onDestroy(){s.onDestroy?.call(this)}onCodeUpdate(){s.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 o=t.inputs[n].value;let a;typeof o=="number"?a=new i.IntegerInterface(n,o).use(i.setType,O):a=new i.TextInputInterface(n,JSON.stringify(o)).use(i.setType,S),a.use(i.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 o=new X(n);this.addOutput(n,o)}this.outputs[n]&&(this.outputs[n].load(t.outputs[n]),this.outputs[n].nodeId=this.id)}v(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),o=s.onUpdate.call(this,t,n);this.updateInterfaces("input",o.inputs??{},o.forceUpdateInputs??[]),this.updateInterfaces("output",o.outputs??{},o.forceUpdateOutputs??[]),this.graph&&this.graph.activeTransactions--}getStaticValues(t,n){const o={};for(const a of t)o[a]=n[a].value;return o}updateInterfaces(t,n,o){const a=t==="input"?this.staticInputKeys:this.staticOutputKeys,r=t==="input"?this.inputs:this.outputs;for(const c of Object.keys(r))a.includes(c)||n[c]&&!o.includes(c)||(t==="input"?this.removeInput(c):this.removeOutput(c));for(const c of Object.keys(n)){if(r[c])continue;const l=n[c]();t==="input"?this.addInput(c,l):this.addOutput(c,l)}}executeFactory(t,n){Object.keys(n||{}).forEach(o=>{const a=n[o]();t==="input"?this.addInput(o,a):this.addOutput(o,a)})}}}class Y{_id;_viewModel;_state;constructor(t){this._id=re.v4(),this._viewModel=t,this._state=e.reactive({autosort:!1,modules:{},script:"",token:null,template:""})}get codeNodes(){return $(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 $(this.graph).filter(t=>t.state?.script.length>0)}get shortId(){return this.id.slice(0,6)}get state(){return this._state}get viewModel(){return this._viewModel}get visibleNodes(){return this.codeNodes.filter(t=>!t.state?.hidden)}addNode(t,n){return t.code||(t.code=this),n&&(t.state.props=n),this.graph.addNode(t)}addNodeAtCoordinates=(t,n={x:0,y:0},o)=>(this.addNode(t,o),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(o=>o.from.id===t.id&&o.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=G.render(this.state.template||"",this)}save(){this.state.autosort&&this.sortNodes();const t=this.viewModel.editor.save();return t.graph.id=this.id,this.saveNodeStates(t.graph.nodes),JSON.parse(JSON.stringify(t))}saveNodeStates(t){t.forEach((n,o)=>{const a=this.nodes[o];Object.entries(n.inputs).forEach(([r])=>{n.inputs&&a.inputs[r]&&(n.inputs[r].hidden=a.inputs[r].hidden)}),Object.entries(n.outputs).forEach(([r])=>{n.outputs&&a.outputs[r]&&(n.outputs[r].hidden=a.outputs[r].hidden)})})}sortNodes(){if(!(this.nodes.length===0||this.connections.length===0))try{const t=this.connections.map(r=>[r.to.nodeId,r.from.nodeId]);let n=[...this.nodeIds];n.reverse(),n=ae.array(n,t),n.reverse();const o=this.graph.nodes.map(r=>r.id).filter(r=>!n.includes(r));n=n.concat(o);const a=n.map(r=>this.findNodeById(r));a&&(this.nodes=a)}catch{console.warn("Failed to sort nodes.")}}updateOutputVariableNames(){this.codeNodes.forEach(t=>t.updateOutputVariableName())}}const $=s=>{let t=[];return s.nodes.forEach(n=>{n.subgraph?t=t.concat($(n.subgraph)):n.isCodeNode&&t.push(n)}),t},Ce=(s=0,t=100)=>({x:s*420,y:t}),ke=s=>{const t={...s.position};return t.x-=400,t.y+=50,t},we=s=>{const{calculationOrder:t,connectionsFromNode:n}=i.sortTopologically(s);t.forEach(o=>{if(!o.isCodeNode)return;const a=o;n.has(a)&&n.get(a).forEach(r=>{r.to.state&&r.from.script&&(r.to.state.script=r.from.script)})})},Ie=["id"],Ee={class:"align-middle"},J=e.defineComponent({__name:"CodeGraphNodeInterface",props:{node:{},intf:{}},setup(s){const t=s,{viewModel:n}=i.useViewModel(),{hoveredOver:o,temporaryConnection:a}=i.useTemporaryConnection(),r=e.ref(null),c=e.computed(()=>t.intf.connectionCount>0),l=e.computed(()=>({"--connected":c.value})),m=()=>{o(t.intf)},_=()=>{o(void 0)},N=()=>{r.value&&n.value.hooks.renderInterface.execute({intf:t.intf,el:r.value})};return e.onMounted(N),e.onUpdated(N),(k,B)=>(e.openBlock(),e.createElementBlock("div",{id:k.intf.id,ref_key:"el",ref:r,class:e.normalizeClass(["baklava-node-interface",l.value])},[k.intf.port?(e.openBlock(),e.createElementBlock("div",{key:0,class:e.normalizeClass(["__port",{"--selected":e.unref(a)?.from===k.intf}]),onPointerover:m,onPointerout:_},null,34)):e.createCommentVNode("",!0),e.createElementVNode("span",Ee,[e.renderSlot(k.$slots,"default")])],10,Ie))}}),E=(s,t)=>{const n=s.__vccOpts||s;for(const[o,a]of t)n[o]=a;return n},Be={},xe={xmlns:"http://www.w3.org/2000/svg",width:"24",height:"24",viewBox:"0 0 24 24",fill:"currentColor",class:"baklava-icon icon icon-tabler icons-tabler-filled icon-tabler-layout-sidebar-left-collapse"};function Ve(s,t){return e.openBlock(),e.createElementBlock("svg",xe,[...t[0]||(t[0]=[e.createElementVNode("path",{stroke:"none",d:"M0 0h24v24H0z",fill:"none"},null,-1),e.createElementVNode("path",{d:"M18 3a3 3 0 0 1 2.995 2.824l.005 .176v12a3 3 0 0 1 -2.824 2.995l-.176 .005h-12a3 3 0 0 1 -2.995 -2.824l-.005 -.176v-12a3 3 0 0 1 2.824 -2.995l.176 -.005h12zm0 2h-9v14h9a1 1 0 0 0 .993 -.883l.007 -.117v-12a1 1 0 0 0 -.883 -.993l-.117 -.007zm-2.293 4.293a1 1 0 0 1 .083 1.32l-.083 .094l-1.292 1.293l1.292 1.293a1 1 0 0 1 .083 1.32l-.083 .094a1 1 0 0 1 -1.32 .083l-.094 -.083l-2 -2a1 1 0 0 1 -.083 -1.32l.083 -.094l2 -2a1 1 0 0 1 1.414 0z"},null,-1)])])}const Te=E(Be,[["render",Ve]]),Me={},Oe={xmlns:"http://www.w3.org/2000/svg",width:"24",height:"24",viewBox:"0 0 24 24",fill:"currentColor",class:"baklava-icon icon icon-tabler icons-tabler-filled icon-tabler-layout-sidebar-left-expand"};function Se(s,t){return e.openBlock(),e.createElementBlock("svg",Oe,[...t[0]||(t[0]=[e.createElementVNode("path",{stroke:"none",d:"M0 0h24v24H0z",fill:"none"},null,-1),e.createElementVNode("path",{d:"M18 3a3 3 0 0 1 2.995 2.824l.005 .176v12a3 3 0 0 1 -2.824 2.995l-.176 .005h-12a3 3 0 0 1 -2.995 -2.824l-.005 -.176v-12a3 3 0 0 1 2.824 -2.995l.176 -.005h12zm0 2h-9v14h9a1 1 0 0 0 .993 -.883l.007 -.117v-12a1 1 0 0 0 -.883 -.993l-.117 -.007zm-4.387 4.21l.094 .083l2 2a1 1 0 0 1 .083 1.32l-.083 .094l-2 2a1 1 0 0 1 -1.497 -1.32l.083 -.094l1.292 -1.293l-1.292 -1.293a1 1 0 0 1 -.083 -1.32l.083 -.094a1 1 0 0 1 1.32 -.083z"},null,-1)])])}const $e=E(Me,[["render",Se]]),ze={},ve={xmlns:"http://www.w3.org/2000/svg",width:"24",height:"24",viewBox:"0 0 24 24",fill:"currentColor",class:"balkava-icon icon icon-tabler icons-tabler-filled icon-tabler-layout-sidebar-right"};function Le(s,t){return e.openBlock(),e.createElementBlock("svg",ve,[...t[0]||(t[0]=[e.createElementVNode("path",{stroke:"none",d:"M0 0h24v24H0z",fill:"none"},null,-1),e.createElementVNode("path",{d:"M6 21a3 3 0 0 1 -3 -3v-12a3 3 0 0 1 3 -3h12a3 3 0 0 1 3 3v12a3 3 0 0 1 -3 3zm8 -16h-8a1 1 0 0 0 -1 1v12a1 1 0 0 0 1 1h8z"},null,-1)])])}const Re=E(ze,[["render",Le]]),De={},Pe={xmlns:"http://www.w3.org/2000/svg",width:"24",height:"24",viewBox:"0 0 24 24",fill:"currentColor",class:"baklava-icon icon icon-tabler icons-tabler-filled icon-tabler-layout-sidebar-right-collapse"};function Ge(s,t){return e.openBlock(),e.createElementBlock("svg",Pe,[...t[0]||(t[0]=[e.createElementVNode("path",{stroke:"none",d:"M0 0h24v24H0z",fill:"none"},null,-1),e.createElementVNode("path",{d:"M18 3a3 3 0 0 1 2.995 2.824l.005 .176v12a3 3 0 0 1 -2.824 2.995l-.176 .005h-12a3 3 0 0 1 -2.995 -2.824l-.005 -.176v-12a3 3 0 0 1 2.824 -2.995l.176 -.005h12zm-3 2h-9a1 1 0 0 0 -.993 .883l-.007 .117v12a1 1 0 0 0 .883 .993l.117 .007h9v-14zm-5.387 4.21l.094 .083l2 2a1 1 0 0 1 .083 1.32l-.083 .094l-2 2a1 1 0 0 1 -1.497 -1.32l.083 -.094l1.292 -1.293l-1.292 -1.293a1 1 0 0 1 -.083 -1.32l.083 -.094a1 1 0 0 1 1.32 -.083z"},null,-1)])])}const Ue=E(De,[["render",Ge]]),Fe={},Ae={xmlns:"http://www.w3.org/2000/svg",width:"24",height:"24",viewBox:"0 0 24 24",fill:"currentColor",class:"baklava-icon icon icon-tabler icons-tabler-filled icon-tabler-layout-sidebar-right-expand"};function He(s,t){return e.openBlock(),e.createElementBlock("svg",Ae,[...t[0]||(t[0]=[e.createElementVNode("path",{stroke:"none",d:"M0 0h24v24H0z",fill:"none"},null,-1),e.createElementVNode("path",{d:"M18 3a3 3 0 0 1 2.995 2.824l.005 .176v12a3 3 0 0 1 -2.824 2.995l-.176 .005h-12a3 3 0 0 1 -2.995 -2.824l-.005 -.176v-12a3 3 0 0 1 2.824 -2.995l.176 -.005h12zm-3 2h-9a1 1 0 0 0 -.993 .883l-.007 .117v12a1 1 0 0 0 .883 .993l.117 .007h9v-14zm-3.293 4.293a1 1 0 0 1 .083 1.32l-.083 .094l-1.292 1.293l1.292 1.293a1 1 0 0 1 .083 1.32l-.083 .094a1 1 0 0 1 -1.32 .083l-.094 -.083l-2 -2a1 1 0 0 1 -.083 -1.32l.083 -.094l2 -2a1 1 0 0 1 1.414 0z"},null,-1)])])}const We=E(Fe,[["render",He]]),Xe={},qe={xmlns:"http://www.w3.org/2000/svg",class:"baklava-icon",width:"24",height:"24",viewBox:"0 0 24 24",fill:"none",stroke:"currentColor","stroke-width":"2","stroke-linecap":"round","stroke-linejoin":"round"};function Ye(s,t){return e.openBlock(),e.createElementBlock("svg",qe,[...t[0]||(t[0]=[e.createStaticVNode('<path stroke="none" d="M0 0h24v24H0z" fill="none"></path><path d="M5 2h5v4h-5z"></path><path d="M15 10h5v4h-5z"></path><path d="M5 18h5v4h-5z"></path><path d="M5 10h5v4h-5z"></path><path d="M10 12h5"></path><path d="M7.5 6v4"></path><path d="M7.5 14v4"></path>',8)])])}const Je=E(Xe,[["render",Ye]]),Qe={},Ke={xmlns:"http://www.w3.org/2000/svg",class:"baklava-icon",width:"24",height:"24",viewBox:"0 0 24 24",fill:"none",stroke:"currentColor","stroke-width":"2","stroke-linecap":"round","stroke-linejoin":"round"};function Ze(s,t){return e.openBlock(),e.createElementBlock("svg",Ke,[...t[0]||(t[0]=[e.createStaticVNode('<path stroke="none" d="M0 0h24v24H0z" fill="none"></path><path d="M6 2h4v4m-4 0h-1v-1"></path><path d="M15 11v-1h5v4h-2"></path><path d="M5 18h5v4h-5z"></path><path d="M5 10h5v4h-5z"></path><path d="M10 12h2"></path><path d="M7.5 7.5v2.5"></path><path d="M7.5 14v4"></path><path d="M3 3l18 18"></path>',9)])])}const je=E(Qe,[["render",Ze]]),et={},tt={xmlns:"http://www.w3.org/2000/svg",class:"baklava-icon",width:"24",height:"24",viewBox:"0 0 24 24",fill:"none",stroke:"currentColor","stroke-width":"2","stroke-linecap":"round","stroke-linejoin":"round"};function nt(s,t){return e.openBlock(),e.createElementBlock("svg",tt,[...t[0]||(t[0]=[e.createStaticVNode('<path stroke="none" d="M0 0h24v24H0z" fill="none"></path><path d="M3 3l18 18"></path><path d="M4 7h3m4 0h9"></path><path d="M10 11l0 6"></path><path d="M14 14l0 3"></path><path d="M5 7l1 12a2 2 0 0 0 2 2h8a2 2 0 0 0 2 -2l.077 -.923"></path><path d="M18.384 14.373l.616 -7.373"></path><path d="M9 5v-1a1 1 0 0 1 1 -1h4a1 1 0 0 1 1 1v3"></path>',8)])])}const ot=E(et,[["render",nt]]),st={},at={xmlns:"http://www.w3.org/2000/svg",class:"baklava-icon",width:"16",height:"16",viewBox:"0 0 24 24","stroke-width":"2",stroke:"currentColor",fill:"none","stroke-linecap":"round","stroke-linejoin":"round"};function rt(s,t){return e.openBlock(),e.createElementBlock("svg",at,[...t[0]||(t[0]=[e.createElementVNode("path",{stroke:"none",d:"M0 0h24v24H0z",fill:"none"},null,-1),e.createElementVNode("circle",{cx:"12",cy:"12",r:"1"},null,-1),e.createElementVNode("circle",{cx:"12",cy:"19",r:"1"},null,-1),e.createElementVNode("circle",{cx:"12",cy:"5",r:"1"},null,-1)])])}const it=E(st,[["render",rt]]),dt=["id","data-node-type"],lt={class:"__title-label",style:{"flex-grow":"1"}},ct={key:0},pt={class:"__menu",style:{display:"flex"}},ut={class:"__outputs"},ht={key:0},mt=["id","title"],ft={class:"__inputs"},gt={key:0},yt=["id","title"],_t=e.defineComponent({__name:"CodeGraphNode",props:{node:{},selected:{type:Boolean,default:!1},dragging:{type:Boolean}},emits:["select","start-drag","update"],setup(s,{emit:t}){const n=i.Components.ContextMenu,o=i.Components.NodeInterface,a=s,r=e.computed(()=>a.node),c=t,{viewModel:l}=i.useViewModel(),{graph:m,switchGraph:_}=i.useGraph(),N=e.ref(null),k=e.ref(!1),B=e.ref(""),b=e.ref(null),f=e.ref(!1);let g=0,h=0;const u=e.ref(!1),C=e.computed(()=>{const p=[{value:"edit",label:"Edit"},{value:"rename",label:"Rename"},{value:"delete",label:"Delete"}];return a.node.type.startsWith(i.GRAPH_NODE_TYPE_PREFIX)&&p.push({value:"editSubgraph",label:"Edit Subgraph"}),p}),I=e.computed(()=>({"--selected":a.selected,"--dragging":a.dragging,"--two-column":!!a.node.twoColumn,"--hidden":r.value.state?.hidden})),Pt=e.computed(()=>({"--reverse-y":a.node.reverseY??l.value.settings.nodes.reverseY})),Gt=e.computed(()=>({top:`${a.node.position?.y??0}px`,left:`${a.node.position?.x??0}px`,"--width":`${a.node.width??l.value.settings.nodes.defaultWidth}px`})),Ut=e.computed(()=>Object.values(a.node.inputs).filter(p=>!p.hidden)),Ft=e.computed(()=>Object.values(a.node.outputs).filter(p=>!p.hidden)),Z=()=>{c("select")},At=p=>{a.selected||Z(),c("start-drag",p)},j=()=>{u.value=!0},Ht=()=>{const p=l.value.displayedGraph.sidebar;p.nodeId="",p.visible=!1},ee=()=>{const p=l.value.displayedGraph.sidebar;p.nodeId=a.node.id,p.visible=!0},Wt=()=>{const p=l.value.displayedGraph.sidebar;p.nodeId=a.node.id},Xt=async p=>{switch(p){case"edit":ee();break;case"delete":m.value.removeNode(a.node);break;case"rename":B.value=a.node.title,k.value=!0,await e.nextTick(),b.value?.focus();break;case"editSubgraph":_(a.node.template);break}},te=()=>{a.node.title=B.value,k.value=!1},ne=()=>{N.value&&l.value.hooks.renderNode.execute({node:a.node,el:N.value})},qt=p=>{f.value=!0,g=a.node.width,h=p.clientX,p.preventDefault()},oe=p=>{if(!f.value)return;const w=p.clientX-h,y=g+w/m.value.scaling,Yt=l.value.settings.nodes.minWidth,Jt=l.value.settings.nodes.maxWidth;a.node.width=Math.max(Yt,Math.min(Jt,y))},se=()=>{f.value=!1};return e.onMounted(()=>{ne(),window.addEventListener("mousemove",oe),window.addEventListener("mouseup",se)}),e.onUpdated(ne),e.onBeforeUnmount(()=>{window.removeEventListener("mousemove",oe),window.removeEventListener("mouseup",se)}),(p,w)=>(e.openBlock(),e.createElementBlock("div",{id:r.value.id,ref_key:"el",ref:N,class:e.normalizeClass([I.value,"baklava-node"]),"data-node-type":r.value.type,style:e.normalizeStyle(Gt.value),onPointerdown:Z},[e.unref(l).settings.nodes.resizable?(e.openBlock(),e.createElementBlock("div",{key:0,class:"__resize-handle",onMousedown:qt},null,32)):e.createCommentVNode("",!0),e.createElementVNode("div",{class:"__title",onPointerdown:e.withModifiers(At,["self","stop"]),onContextmenu:e.withModifiers(j,["prevent"])},[r.value.inputs._node?(e.openBlock(),e.createBlock(J,{key:0,node:r.value,intf:r.value.inputs._node,class:"--input","data-interface-type":"node",style:{"flex-grow":"0"}},null,8,["node","intf"])):e.createCommentVNode("",!0),k.value?e.withDirectives((e.openBlock(),e.createElementBlock("input",{key:2,ref_key:"renameInputEl",ref:b,"onUpdate:modelValue":w[1]||(w[1]=y=>B.value=y),class:"baklava-input",placeholder:"Node Name",style:{"flex-grow":"1"},type:"text",onBlur:te,onKeydown:e.withKeys(te,["enter"])},null,544)),[[e.vModelText,B.value]]):(e.openBlock(),e.createElementBlock(e.Fragment,{key:1},[e.createElementVNode("div",lt,[r.value.idx>-1?(e.openBlock(),e.createElementBlock("span",ct,e.toDisplayString(r.value.idx+1)+" - ",1)):e.createCommentVNode("",!0),e.createTextVNode(e.toDisplayString(r.value.title)+" ("+e.toDisplayString(r.value.shortId)+") ",1)]),e.createElementVNode("div",pt,[r.value.subgraph?e.createCommentVNode("",!0):(e.openBlock(),e.createElementBlock(e.Fragment,{key:0},[!e.unref(l).displayedGraph.sidebar.visible&&e.unref(l).displayedGraph.sidebar.nodeId!==r.value.id?(e.openBlock(),e.createBlock(e.unref(We),{key:0,class:"--clickable mx-1",onClick:ee})):e.unref(l).displayedGraph.sidebar.visible&&e.unref(l).displayedGraph.sidebar.nodeId!==r.value.id?(e.openBlock(),e.createBlock(e.unref(Re),{key:1,class:"--clickable mx-1",onClick:Wt})):(e.openBlock(),e.createBlock(e.unref(Ue),{key:2,class:"--clickable mx-1",onClick:Ht}))],64)),e.createVNode(e.unref(it),{class:"--clickable mx-1",onClick:j}),e.createVNode(e.unref(n),{modelValue:u.value,"onUpdate:modelValue":w[0]||(w[0]=y=>u.value=y),x:0,y:0,items:C.value,onClick:Xt},null,8,["modelValue","items"])])],64)),r.value.outputs._node?(e.openBlock(),e.createBlock(J,{key:3,node:r.value,intf:r.value.outputs._node,class:"--output","data-interface-type":"node"},null,8,["node","intf"])):e.createCommentVNode("",!0)],32),e.createElementVNode("div",{class:e.normalizeClass(["__content",Pt.value]),onKeydown:w[2]||(w[2]=e.withKeys(e.withModifiers(()=>{},["stop"]),["delete"])),onContextmenu:w[3]||(w[3]=e.withModifiers(()=>{},["prevent"]))},[e.createElementVNode("div",ut,[(e.openBlock(!0),e.createElementBlock(e.Fragment,null,e.renderList(Ft.value,y=>(e.openBlock(),e.createElementBlock(e.Fragment,{key:y.id},[r.value.state?.hidden?(e.openBlock(),e.createElementBlock("div",ht,[y.port?(e.openBlock(),e.createElementBlock("div",{key:0,id:y.id,title:y.name,class:"baklava-node-interface --output --connected"},[...w[4]||(w[4]=[e.createElementVNode("div",{class:"__port"},null,-1)])],8,mt)):e.createCommentVNode("",!0)])):e.renderSlot(p.$slots,"nodeInterface",{key:1,type:"output",node:r.value,intf:y},()=>[e.createVNode(e.unref(o),{node:r.value,intf:y},null,8,["node","intf"])])],64))),128))]),e.createElementVNode("div",ft,[(e.openBlock(!0),e.createElementBlock(e.Fragment,null,e.renderList(Ut.value,y=>(e.openBlock(),e.createElementBlock(e.Fragment,{key:y.id},[r.value.state?.hidden?(e.openBlock(),e.createElementBlock("div",gt,[y.port?(e.openBlock(),e.createElementBlock("div",{key:0,id:y.id,title:y.name,class:"baklava-node-interface --input --connected"},[...w[5]||(w[5]=[e.createElementVNode("div",{class:"__port"},null,-1)])],8,yt)):e.createCommentVNode("",!0)])):e.renderSlot(p.$slots,"nodeInterface",{key:1,node:r.value,intf:y,type:"input"},()=>[e.createVNode(e.unref(o),{node:r.value,intf:y,title:y.name},null,8,["node","intf","title"])])],64))),128))])],34)],46,dt))}}),Nt=["title"],bt={key:0,class:"__label"},Ct=e.defineComponent({__name:"Checkbox",props:{disabled:{type:Boolean},inversed:{type:Boolean},modelValue:{type:Boolean},name:{}},emits:["update:modelValue"],setup(s,{emit:t}){const n=t;return(o,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]=r=>n("update:modelValue",!o.modelValue))},[a[1]||(a[1]=e.createElementVNode("div",{class:"__checkmark-container"},[e.createElementVNode("svg",{xmlns:"http://www.w3.org/2000/svg",width:"18",height:"18",viewBox:"0 0 18 18"},[e.createElementVNode("path",{class:"__checkmark",d:"M 6 5 L 6 10 L 16 10",transform:"rotate(-45 10 10)"})])],-1)),o.name?(e.openBlock(),e.createElementBlock("div",bt,e.toDisplayString(o.name),1)):e.createCommentVNode("",!0)],10,Nt))}}),kt={class:"__header"},wt={class:"__node-name"},It={style:{display:"flex"}},Et={key:1,class:"__interface"},Bt=e.defineComponent({__name:"CodeGraphSidebar",setup(s){const{viewModel:t}=i.useViewModel(),{graph:n}=i.useGraph(),o=e.ref(null),a=e.toRef(t.value.settings.sidebar,"width"),r=e.computed(()=>t.value.settings.sidebar.resizable);let c=0,l=0;const m=e.computed(()=>{const h=n.value.sidebar.nodeId;return n.value.nodes.find(u=>u.id===h)}),_=e.computed(()=>m.value),N=e.computed(()=>({width:`${a.value}px`})),k=e.computed(()=>_.value?[...Object.values(_.value.inputs),...Object.values(_.value.outputs)].filter(u=>u.displayInSidebar&&u.component):[]),B=()=>{n.value.sidebar.visible=!1},b=()=>{m.value?.events.update.emit(null)},f=h=>{c=a.value,l=h.clientX,window.addEventListener("mousemove",g),window.addEventListener("mouseup",()=>{window.removeEventListener("mousemove",g)},{once:!0})},g=h=>{const u=o.value?.parentElement?.getBoundingClientRect().width??500,C=h.clientX-l;let I=c-C;I<300?I=300:I>.9*u&&(I=.9*u),a.value=I};return(h,u)=>(e.openBlock(),e.createElementBlock("div",{ref_key:"el",ref:o,class:e.normalizeClass(["baklava-sidebar",{"--open":e.unref(n).sidebar.visible}]),style:e.normalizeStyle(N.value)},[r.value?(e.openBlock(),e.createElementBlock("div",{key:0,class:"__resizer",onMousedown:f},null,32)):e.createCommentVNode("",!0),e.createElementVNode("div",kt,[e.createElementVNode("button",{tabindex:"-1",class:"__close",onClick:B},"×"),e.createElementVNode("div",wt,[e.createElementVNode("b",null,e.toDisplayString(m.value?m.value.title:""),1)])]),(e.openBlock(!0),e.createElementBlock(e.Fragment,null,e.renderList(k.value,C=>(e.openBlock(),e.createElementBlock("div",{key:C.id,class:"__interface"},[e.createElementVNode("div",It,[e.createVNode(Ct,{modelValue:C.hidden,"onUpdate:modelValue":[I=>C.hidden=I,u[0]||(u[0]=()=>m.value?.events.update.emit(null))],disabled:!C.optional,inversed:"",style:{"margin-right":"8px"}},null,8,["modelValue","onUpdate:modelValue","disabled"]),(e.openBlock(),e.createBlock(e.resolveDynamicComponent(C.component),{modelValue:C.value,"onUpdate:modelValue":I=>C.value=I,node:m.value,intf:C,style:{width:"100%"}},null,8,["modelValue","onUpdate:modelValue","node","intf"]))])]))),128)),_.value&&_.value.state?(e.openBlock(),e.createElementBlock("div",Et,[u[2]||(u[2]=e.createElementVNode("label",null,"Variable name",-1)),e.withDirectives(e.createElementVNode("input",{"onUpdate:modelValue":u[1]||(u[1]=C=>_.value.state.variableName=C),type:"text",class:"baklava-input",title:"Variable name",onBlur:b,onKeydown:e.withKeys(b,["enter"])},null,544),[[e.vModelText,_.value.state.variableName]])])):e.createCommentVNode("",!0)],6))}}),xt=e.defineComponent({props:{type:{type:String,required:!0},title:{type:String,required:!0}},setup(s){const{viewModel:t}=i.useViewModel(),{switchGraph:n}=i.useGraph(),o=e.ref(!1),a=e.computed(()=>s.type.startsWith(i.GRAPH_NODE_TYPE_PREFIX));return{showContextMenu:o,hasContextMenu:a,contextMenuItems:[{label:"Edit Subgraph",value:"editSubgraph"},{label:"Delete Subgraph",value:"deleteSubgraph"}],openContextMenu:()=>{o.value=!0},onContextMenuClick:m=>{const _=s.type.substring(i.GRAPH_NODE_TYPE_PREFIX.length),N=t.value.editor.graphTemplates.find(k=>k.id===_);if(N)switch(m){case"editSubgraph":n(N);break;case"deleteSubgraph":t.value.editor.removeGraphTemplate(N);break}}}}}),Vt=["data-node-type"],Tt={class:"__title"},Mt={class:"__title-label"};function Ot(s,t,n,o,a,r){return e.openBlock(),e.createElementBlock("div",{class:"baklava-node --palette","data-node-type":s.type},[e.createElementVNode("div",Tt,[e.createElementVNode("div",Mt,e.toDisplayString(s.title),1)])],8,Vt)}const Q=E(xt,[["render",Ot]]),St={class:"baklava-node --palette",style:{"margin-top":"-20px","margin-bottom":"20px"}},$t={key:0,style:{display:"flex","justify-content":"space-between"}},zt=["onClick"],vt={key:0,style:{margin:"auto 0","font-size":"12px"}},Lt=e.defineComponent({__name:"CodeNodePalette",setup(s){const{viewModel:t}=i.useViewModel(),{x:n,y:o}=ie.usePointer(),{transform:a}=i.useTransform(),r=i.useNodeCategories(t),c=e.inject("editorEl"),l=e.ref(""),m=e.ref(null),_=()=>l.value?r.value.filter(b=>b.name.toLowerCase().includes(l.value.toLowerCase())||Object.values(b.nodeTypes).some(f=>f.title.toLowerCase().includes(l.value.toLowerCase()))):r.value,N=b=>l.value?Object.values(b).filter(f=>f.category.toLowerCase().includes(l.value.toLowerCase())||f.title.toLowerCase().includes(l.value.toLowerCase())):Object.values(b),k=e.computed(()=>{if(!m.value||!c?.value)return{};const{left:b,top:f}=c.value.getBoundingClientRect();return{top:`${o.value-f}px`,left:`${n.value-b}px`}}),B=(b,f)=>{m.value={type:b,nodeInformation:f};const g=()=>{const h=e.reactive(new f.type);t.value.displayedGraph.addNode(h);const u=c.value.getBoundingClientRect(),[C,I]=a(n.value-u.left,o.value-u.top);h.position.x=C,h.position.y=I,m.value=null,document.removeEventListener("pointerup",g)};document.addEventListener("pointerup",g)};return(b,f)=>(e.openBlock(),e.createElementBlock(e.Fragment,null,[e.createElementVNode("div",{class:e.normalizeClass(["baklava-node-palette",{"--open":e.unref(t).settings.palette.enabled}]),onContextmenu:f[1]||(f[1]=e.withModifiers(()=>{},["stop","prevent"]))},[e.createElementVNode("div",St,[e.withDirectives(e.createElementVNode("input",{"onUpdate:modelValue":f[0]||(f[0]=g=>l.value=g),type:"text",class:"baklava-input",title:"Filter nodes",onKeyup:_},null,544),[[e.vModelText,l.value]])]),(e.openBlock(!0),e.createElementBlock(e.Fragment,null,e.renderList(_(),g=>(e.openBlock(),e.createElementBlock("section",{key:g.name},[g.name!=="default"?(e.openBlock(),e.createElementBlock("h3",$t,[e.createElementVNode("div",{onClick:h=>l.value=g.name,style:{cursor:"pointer"}},e.toDisplayString(g.name),9,zt),N(g.nodeTypes).length<Object.values(g.nodeTypes).length?(e.openBlock(),e.createElementBlock("div",vt," ( "+e.toDisplayString(N(g.nodeTypes).length)+" / "+e.toDisplayString(Object.values(g.nodeTypes).length)+" ) ",1)):e.createCommentVNode("",!0)])):e.createCommentVNode("",!0),(e.openBlock(!0),e.createElementBlock(e.Fragment,null,e.renderList(N(g.nodeTypes),h=>(e.openBlock(),e.createBlock(Q,{key:h.type,type:h.type,title:h.title,onPointerdown:u=>B(h.type,h)},null,8,["type","title","onPointerdown"]))),128))]))),128))],34),e.createVNode(e.Transition,{name:"fade"},{default:e.withCtx(()=>[m.value?(e.openBlock(),e.createElementBlock("div",{key:0,class:"baklava-dragged-node",style:e.normalizeStyle(k.value)},[e.createVNode(Q,{type:m.value.type,title:m.value.nodeInformation.title},null,8,["type","title"])],4)):e.createCommentVNode("",!0)]),_:1})],64))}}),Rt=e.defineComponent({__name:"CodeGraphEditor",props:{viewModel:{}},setup(s){const t=s,n=e.toRef(t,"viewModel"),o=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,r)=>(e.openBlock(),e.createBlock(e.unref(i.BaklavaEditor),{"view-model":n.value},{palette:e.withCtx(()=>[e.createVNode(Lt)]),node:e.withCtx(c=>[e.createVNode(_t,e.mergeProps(c,{onUpdate:l=>o(c.node)}),null,16,["onUpdate"])]),sidebar:e.withCtx(c=>[e.createVNode(Bt,e.normalizeProps(e.guardReactiveProps(c)),null,16)]),_:1},8,["view-model"]))}}),K=s=>{const t="TOGGLE_PALETTE";s.commandHandler.registerCommand(t,{execute:()=>s.settings.palette.enabled=!s.settings.palette.enabled,canExecute:()=>!0});const n="CLEAR_ALL";s.commandHandler.registerCommand(n,{execute:()=>s.code.clear(),canExecute:()=>s.displayedGraph.nodes.length>0});const o="TOGGLE_MINIMAP";s.commandHandler.registerCommand(o,{execute:()=>s.settings.enableMinimap=!s.settings.enableMinimap,canExecute:()=>s.displayedGraph.nodes.length>1}),s.settings.toolbar.commands=[{command:t,title:"Toggle palette",icon:e.computed(()=>s.settings.palette.enabled?Te:$e)},...i.DEFAULT_TOOLBAR_COMMANDS,{command:n,title:"Clear all",icon:ot},{command:o,title:"Toggle minimap",icon:e.computed(()=>s.settings.enableMinimap?je:Je)}]},T={enableMinimap:!1,toolbar:{enabled:!0},palette:{enabled:!0},sidebar:{enabled:!0,resizable:!0,width:350},displayValueOnHover:!1};function Dt(s){const t=i.useBaklava(s?.existingEditor);t.code=s?.code?new s.code(t):new Y(t),K(t);const n={};return Object.keys(T).forEach(o=>{n[o]=typeof T[o]=="object"?{...t.settings[o],...T[o]}:T[o]}),t.settings=e.reactive({...t.settings,...n}),t.settings.nodes.defaultWidth=350,t.state=e.reactive({modules:{},token:null}),t.engine=new i.DependencyEngine(t.editor),t.subscribe=()=>{t.state.token&&t.unsubscribe();const o=Symbol();t.displayedGraph.events.addNode.subscribe(o,a=>a.code=t.code),t.engine.events.beforeRun.subscribe(o,()=>{t.engine.pause(),t.code&&(t.code.onCodeUpdate(),t.code.sortNodes()),t.engine.resume()}),t.engine.events.beforeNodeCalculation.subscribe(o,a=>{t.engine.pause();const r=a.node;r.isCodeNode&&(r.updateOutputVariableName(),r.updateCodeNodeInputInterfaces()),t.engine.resume()}),t.engine.events.afterRun.subscribe(o,a=>{t.engine.pause(),i.applyResult(a,t.editor),t.code&&(t.code.renderNodeCodes(),t.code.renderCode()),t.engine.resume()}),t.state.token=o},t.unsubscribe=()=>{if(!t.state.token)return;const o=t.state.token;t.displayedGraph.events.addNode.unsubscribe(o),t.engine.events.beforeRun.unsubscribe(o),t.engine.events.afterRun.unsubscribe(o),t.state.token=null},t}Object.defineProperty(d,"CheckboxInterfaceComponent",{enumerable:!0,get:()=>i.CheckboxInterfaceComponent}),Object.defineProperty(d,"IntegerInterfaceComponent",{enumerable:!0,get:()=>i.IntegerInterfaceComponent}),Object.defineProperty(d,"NumberInterfaceComponent",{enumerable:!0,get:()=>i.NumberInterfaceComponent}),Object.defineProperty(d,"SelectInterfaceComponent",{enumerable:!0,get:()=>i.SelectInterfaceComponent}),Object.defineProperty(d,"SliderInterfaceComponent",{enumerable:!0,get:()=>i.SliderInterfaceComponent}),Object.defineProperty(d,"TextInputInterfaceComponent",{enumerable:!0,get:()=>i.TextInputInterfaceComponent}),Object.defineProperty(d,"TextareaInputInterfaceComponent",{enumerable:!0,get:()=>i.TextareaInputInterfaceComponent}),d.AbstractCodeNode=U,d.CheckboxInterface=ue,d.Code=Y,d.CodeGraphEditor=Rt,d.CodeNode=z,d.CodeNodeInputInterface=M,d.CodeNodeInterface=x,d.CodeNodeOutputInterface=X,d.DEFAULT_SETTINGS=T,d.DynamicCodeNode=q,d.IntegerInterface=he,d.NumberInterface=me,d.SelectInterface=fe,d.SliderInterface=ge,d.TextInputInterface=ye,d.TextareaInputInterface=_e,d.addDefaultInterfaceTypes=pe,d.addToolbarCommands=K,d.booleanType=R,d.defineCodeNode=Ne,d.defineDynamicCodeNode=be,d.dictType=H,d.formatInputs=de,d.getCodeNodes=$,d.getPositionAtColumn=Ce,d.getPositionBeforeNode=ke,d.listType=W,d.loadNodeState=v,d.nodeType=V,d.numberType=O,d.saveNodeState=F,d.setOptional=ce,d.stringType=S,d.transferCodeScript=we,d.useCodeGraph=Dt,Object.defineProperty(d,Symbol.toStringTag,{value:"Module"})}));
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@babsey/code-graph",
3
- "version": "0.0.14",
3
+ "version": "0.0.15",
4
4
  "author": "babsey <spreizer@web.de>",
5
5
  "license": "MIT",
6
6
  "type": "module",