@babsey/code-graph 0.3.0 → 0.3.2

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
@@ -1,10 +1,10 @@
1
1
  import Z from "mustache";
2
- import { reactive as D, defineComponent as F, createElementBlock as p, openBlock as d, toDisplayString as G, markRaw as z, computed as O, createElementVNode as u, withDirectives as de, vModelText as le, createStaticVNode as se, toRef as Be, onMounted as fe, onBeforeUnmount as ze, watch as He, createBlock as j, unref as w, withCtx as ee, createVNode as L, normalizeProps as pt, guardReactiveProps as ht, renderSlot as ne, mergeProps as mt, ref as R, onUpdated as Le, normalizeStyle as ve, normalizeClass as Y, createCommentVNode as M, withModifiers as te, Fragment as B, createTextVNode as ft, withKeys as he, renderList as J, nextTick as vt, inject as gt, Transition as bt, resolveDynamicComponent as Me, shallowReadonly as _t } from "vue";
2
+ import { reactive as D, defineComponent as F, createElementBlock as p, openBlock as d, toDisplayString as G, markRaw as z, computed as O, createElementVNode as u, withDirectives as de, vModelText as le, createStaticVNode as se, toRef as Be, onMounted as fe, onBeforeUnmount as ze, watch as He, createBlock as j, unref as w, withCtx as ee, createVNode as L, normalizeProps as pt, guardReactiveProps as ht, renderSlot as ne, mergeProps as mt, ref as V, onUpdated as Le, normalizeStyle as ve, normalizeClass as Y, createCommentVNode as M, withModifiers as te, Fragment as B, createTextVNode as ft, withKeys as he, renderList as J, nextTick as vt, inject as gt, Transition as bt, resolveDynamicComponent as Me, shallowReadonly as _t } from "vue";
3
3
  import { v4 as K } from "uuid";
4
4
  import { AbstractNode as yt, NodeInterface as A, getGraphNodeTypeString as Ue, Graph as Ct, GraphTemplate as It, GRAPH_NODE_TYPE_PREFIX as wt, GRAPH_INPUT_NODE_TYPE as kt, GRAPH_OUTPUT_NODE_TYPE as Nt, Editor as xt } from "@baklavajs/core";
5
5
  import { NodeInterfaceType as X, BaklavaInterfaceTypes as Ot, setType as $ } from "@baklavajs/interface-types";
6
6
  import { allowMultipleConnections as Q, applyResult as Ae, BaseEngine as Tt, sortTopologically as Et } from "@baklavajs/engine";
7
- import { displayInSidebar as De, CheckboxInterfaceComponent as $t, useGraph as ge, IntegerInterfaceComponent as Mt, TextInputInterfaceComponent as Fe, NumberInterfaceComponent as Gt, SelectInterfaceComponent as St, SliderInterfaceComponent as Pt, TextareaInputInterfaceComponent as Rt, IntegerInterface as Vt, TextInputInterface as be, DEFAULT_TOOLBAR_COMMANDS as jt, Commands as q, BaklavaEditor as Bt, Components as me, useViewModel as oe, useTemporaryConnection as zt, useTransform as Ht, useNodeCategories as Lt, DEFAULT_SETTINGS as Ut, useCommandHandler as At, useHistory as Dt, useClipboard as Ft, registerDeleteNodesCommand as Wt, registerSaveSubgraphCommand as Yt, registerSwitchToMainGraphCommand as Kt, registerSidebarCommands as Xt, registerZoomToFitCommands as qt, setViewNodeProperties as Jt } from "@baklavajs/renderer-vue";
7
+ import { displayInSidebar as De, CheckboxInterfaceComponent as $t, useGraph as ge, IntegerInterfaceComponent as Mt, TextInputInterfaceComponent as Fe, NumberInterfaceComponent as Gt, SelectInterfaceComponent as St, SliderInterfaceComponent as Pt, TextareaInputInterfaceComponent as Vt, IntegerInterface as Rt, TextInputInterface as be, DEFAULT_TOOLBAR_COMMANDS as jt, Commands as q, BaklavaEditor as Bt, Components as me, useViewModel as oe, useTemporaryConnection as zt, useTransform as Ht, useNodeCategories as Lt, DEFAULT_SETTINGS as Ut, useCommandHandler as At, useHistory as Dt, useClipboard as Ft, registerDeleteNodesCommand as Wt, registerSaveSubgraphCommand as Yt, registerSwitchToMainGraphCommand as Kt, registerSidebarCommands as Xt, registerZoomToFitCommands as qt, setViewNodeProperties as Jt } from "@baklavajs/renderer-vue";
8
8
  import Qt from "toposort";
9
9
  import { SequentialHook as Ge } from "@baklavajs/events";
10
10
  import { usePointer as Zt } from "@vueuse/core";
@@ -247,7 +247,7 @@ const en = (n, e = !0) => {
247
247
  }, G(n.intf.name), 9, nn));
248
248
  }
249
249
  });
250
- class V extends A {
250
+ class R extends A {
251
251
  isCodeNode = !0;
252
252
  code;
253
253
  state;
@@ -268,7 +268,7 @@ class V extends A {
268
268
  return this.state.optional = e, this.setHidden(e), this;
269
269
  }
270
270
  }
271
- class ae extends V {
271
+ class ae extends R {
272
272
  constructor(e = "", t) {
273
273
  super(e, t), this.setComponent(z(ye)), this.use(De, !0);
274
274
  }
@@ -288,7 +288,7 @@ class fo extends ae {
288
288
  }
289
289
  getValue = () => this.value ? "True" : "False";
290
290
  }
291
- class on extends V {
291
+ class on extends R {
292
292
  isCodeNodeOutput = !0;
293
293
  suffix = "";
294
294
  constructor(e = "", t = "") {
@@ -394,7 +394,7 @@ class Co extends ke {
394
394
  component = z(cn);
395
395
  }
396
396
  class Io extends ke {
397
- component = z(Rt);
397
+ component = z(Vt);
398
398
  }
399
399
  class wo extends ae {
400
400
  constructor(e = "", t = "") {
@@ -410,10 +410,10 @@ function ko(n) {
410
410
  constructor() {
411
411
  super(), this._title = n.title ?? n.type, this.executeFactory("input", n.inputs), this.executeFactory("output", n.outputs), n.calculate && (this.calculate = (e, t) => n.calculate.call(this, { inputs: e, ...t })), n.onCreate?.call(this), this.name = n.name ?? n.type, this.updateModules(n.modules), n.variableName != null && (this.state.variableName = n.variableName), n.codeTemplate && (this.codeTemplate = n.codeTemplate), this.addInput(
412
412
  "_code",
413
- new V("", []).use($, U).use(Q).setHidden(!0)
413
+ new R("", []).use($, U).use(Q).setHidden(!0)
414
414
  ), this.addOutput(
415
415
  "_code",
416
- new V("", []).use($, U).use(Q).setHidden(!0)
416
+ new R("", []).use($, U).use(Q).setHidden(!0)
417
417
  );
418
418
  }
419
419
  onPlaced() {
@@ -452,10 +452,10 @@ function No(n) {
452
452
  constructor() {
453
453
  super(), this._title = n.title ?? n.type, this.executeFactory("input", n.inputs), this.executeFactory("output", n.outputs), n.calculate && (this.calculate = (e, t) => n.calculate?.call(this, e, t)), n.onCreate?.call(this), this.name = n.name ?? n.type, this.updateModules(n.modules), n.codeTemplate && (this.codeTemplate = n.codeTemplate), n.variableName && (this.state.variableName = n.variableName), this.addInput(
454
454
  "_code",
455
- new V("", []).use($, U).use(Q).setHidden(!0)
455
+ new R("", []).use($, U).use(Q).setHidden(!0)
456
456
  ), this.addOutput(
457
457
  "_code",
458
- new V("", []).use($, U).use(Q).setHidden(!0)
458
+ new R("", []).use($, U).use(Q).setHidden(!0)
459
459
  ), this.staticInputKeys.push("_code"), this.staticOutputKeys.push("_code");
460
460
  }
461
461
  onPlaced() {
@@ -487,7 +487,7 @@ function No(n) {
487
487
  if (!this.inputs[t]) {
488
488
  const s = e.inputs[t].value;
489
489
  let o;
490
- typeof s == "number" ? o = new Vt(t, s).use($, Ce) : o = new be(t, JSON.stringify(s)).use($, Ie), o.use(De, !0), this.addInput(t, o);
490
+ typeof s == "number" ? o = new Rt(t, s).use($, Ce) : o = new be(t, JSON.stringify(s)).use($, Ie), o.use(De, !0), this.addInput(t, o);
491
491
  }
492
492
  this.inputs[t] && (this.inputs[t].load(e.inputs[t]), this.inputs[t].nodeId = this.id);
493
493
  }
@@ -677,10 +677,10 @@ function mn(n) {
677
677
  this.subgraph.outputs.some((s) => s.id === t) || this.removeOutput(t);
678
678
  this.addInput(
679
679
  "_code",
680
- new V("", []).use($, U).use(Q).setHidden(!0)
680
+ new R("", []).use($, U).use(Q).setHidden(!0)
681
681
  ), this.addOutput(
682
682
  "_code",
683
- new V("", []).use($, U).use(Q).setHidden(!0)
683
+ new R("", []).use($, U).use(Q).setHidden(!0)
684
684
  ), this.addOutput("_calculationResults", new A("_calculationResults", void 0).setHidden(!0));
685
685
  }
686
686
  /**
@@ -689,7 +689,7 @@ function mn(n) {
689
689
  * These properties should be proxied to the subgraph interface, so they behave the same as the original interface.
690
690
  */
691
691
  createProxyInterface(t, s) {
692
- const o = new V(t.name, void 0);
692
+ const o = new R(t.name, void 0);
693
693
  return new Proxy(o, {
694
694
  get: (a, i) => {
695
695
  if (hn.includes(i) || i in a || typeof i == "string" && i.startsWith("__v_"))
@@ -710,9 +710,8 @@ function mn(n) {
710
710
  Z.escape = (n) => n;
711
711
  class fn {
712
712
  _id;
713
- _graph = null;
714
713
  _state;
715
- _engine = null;
714
+ viewModel;
716
715
  constructor() {
717
716
  this._id = K(), this._state = D({
718
717
  lockCode: !1,
@@ -722,10 +721,10 @@ class fn {
722
721
  });
723
722
  }
724
723
  get engine() {
725
- return this._engine;
724
+ return this.viewModel?.engine;
726
725
  }
727
726
  get graph() {
728
- return this._graph;
727
+ return this.viewModel?.editor.graph;
729
728
  }
730
729
  get id() {
731
730
  return this._id;
@@ -768,18 +767,11 @@ class fn {
768
767
  });
769
768
  }
770
769
  /**
771
- * Register engine instance.
772
- * @param engine engine
770
+ * Register code view model instance.
771
+ * @param viewModel view model
773
772
  */
774
- registerEngine(e) {
775
- this._engine = e;
776
- }
777
- /**
778
- * Register code graph instance.
779
- * @param graph code graph
780
- */
781
- registerGraph(e) {
782
- this._graph = e;
773
+ registerViewModel(e) {
774
+ this.viewModel = e;
783
775
  }
784
776
  /**
785
777
  * Render code script.
@@ -794,7 +786,7 @@ const Oo = (n) => {
794
786
  class vn extends Tt {
795
787
  order = /* @__PURE__ */ new Map();
796
788
  constructor(e) {
797
- super(e), e.code.registerEngine(this);
789
+ super(e);
798
790
  }
799
791
  start() {
800
792
  super.start(), this.recalculateOrder = !0, this.calculateWithoutData();
@@ -820,7 +812,7 @@ class vn extends Tt {
820
812
  h[g] = this.getInterfaceValue(t, _.id);
821
813
  }
822
814
  this.events.afterNodeCalculation.emit({ outputValues: h, node: r }), i.set(r.id, new Map(Object.entries(h))), a.has(r) && a.get(r).forEach((g) => {
823
- const _ = Object.entries(r.outputs).find(([, x]) => x.id === g.from.id)?.[0];
815
+ const _ = Object.entries(r.outputs).find(([, k]) => k.id === g.from.id)?.[0];
824
816
  if (!_)
825
817
  throw new Error(
826
818
  `Could not find key for interface ${g.from.id}
@@ -949,7 +941,7 @@ const Gn = /* @__PURE__ */ P(En, [["render", Mn]]), Sn = {}, Pn = {
949
941
  fill: "currentColor",
950
942
  class: "baklava-icon icon icon-tabler icons-tabler-filled icon-tabler-layout-sidebar-right"
951
943
  };
952
- function Rn(n, e) {
944
+ function Vn(n, e) {
953
945
  return d(), p("svg", Pn, [...e[0] || (e[0] = [
954
946
  u("path", {
955
947
  stroke: "none",
@@ -959,7 +951,7 @@ function Rn(n, e) {
959
951
  u("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)
960
952
  ])]);
961
953
  }
962
- const Vn = /* @__PURE__ */ P(Sn, [["render", Rn]]), jn = {}, Bn = {
954
+ const Rn = /* @__PURE__ */ P(Sn, [["render", Vn]]), jn = {}, Bn = {
963
955
  xmlns: "http://www.w3.org/2000/svg",
964
956
  width: "24",
965
957
  height: "24",
@@ -1165,9 +1157,9 @@ function bs(n) {
1165
1157
  }), n.engine?.events.beforeRun.subscribe(e, () => {
1166
1158
  n.engine?.pause(), n.displayedGraph.sortNodes(), n.engine?.resume();
1167
1159
  }), n.engine?.events.afterRun.subscribe(e, (t) => {
1168
- n.engine?.pause(), Ae(t, n.editor), n.editor.saveState(), n.code.state.lockCode || n.code.renderCode({
1160
+ n.engine?.pause(), Ae(t, n.editor), n.code.state.lockCode || n.code.renderCode({
1169
1161
  nodes: n.editor.graph.scriptedCodeNodes,
1170
- modules: n.editor.graph.modules
1162
+ modules: n.editor.code.modules
1171
1163
  }), n.engine?.resume();
1172
1164
  });
1173
1165
  }, n.unsubscribe = () => {
@@ -1343,16 +1335,16 @@ class ce extends It {
1343
1335
  */
1344
1336
  createGraph(e) {
1345
1337
  const t = /* @__PURE__ */ new Map(), s = (m) => {
1346
- const x = K();
1347
- return t.set(m, x), x;
1338
+ const k = K();
1339
+ return t.set(m, k), k;
1348
1340
  }, o = (m) => {
1349
- const x = t.get(m);
1350
- if (!x) throw new Error(`Unable to create graph from template: Could not map old id ${m} to new id`);
1351
- return x;
1352
- }, a = (m) => ys(m, (x) => ({
1353
- id: s(x.id),
1354
- templateId: x.id,
1355
- value: x.value
1341
+ const k = t.get(m);
1342
+ if (!k) throw new Error(`Unable to create graph from template: Could not map old id ${m} to new id`);
1343
+ return k;
1344
+ }, a = (m) => ys(m, (k) => ({
1345
+ id: s(k.id),
1346
+ templateId: k.id,
1347
+ value: k.value
1356
1348
  })), i = this.nodes.map((m) => ({
1357
1349
  ...m,
1358
1350
  id: s(m.id),
@@ -1460,9 +1452,9 @@ const $o = /* @__PURE__ */ F({
1460
1452
  },
1461
1453
  emits: ["select", "start-drag", "update"],
1462
1454
  setup(n, { emit: e }) {
1463
- const t = me.ContextMenu, s = me.NodeInterface, o = n, a = O(() => o.node), i = e, { viewModel: r } = oe(), { graph: c, switchGraph: h } = ge(), g = R(null), _ = R(!1), m = R(""), x = R(null), b = R(!1);
1455
+ const t = me.ContextMenu, s = me.NodeInterface, o = n, a = O(() => o.node), i = e, { viewModel: r } = oe(), { graph: c, switchGraph: h } = ge(), g = V(null), _ = V(!1), m = V(""), k = V(null), b = V(!1);
1464
1456
  let I = 0, l = 0;
1465
- const f = R(!1), k = O(() => {
1457
+ const f = V(!1), N = O(() => {
1466
1458
  const C = [
1467
1459
  { value: "edit", label: "Edit" },
1468
1460
  { value: "rename", label: "Rename" },
@@ -1504,7 +1496,7 @@ const $o = /* @__PURE__ */ F({
1504
1496
  c.value.removeNode(o.node);
1505
1497
  break;
1506
1498
  case "rename":
1507
- m.value = o.node.title, _.value = !0, await vt(), x.value?.focus();
1499
+ m.value = o.node.title, _.value = !0, await vt(), k.value?.focus();
1508
1500
  break;
1509
1501
  case "editSubgraph":
1510
1502
  h(o.node.template);
@@ -1520,8 +1512,8 @@ const $o = /* @__PURE__ */ F({
1520
1512
  a.value.state && (a.value.state.integrated = C, i("update"));
1521
1513
  }, Ee = (C) => {
1522
1514
  if (!b.value) return;
1523
- const E = C.clientX - l, N = I + E / c.value.scaling, ut = r.value.settings.nodes.minWidth, ct = r.value.settings.nodes.maxWidth;
1524
- a.value.width = Math.max(ut, Math.min(ct, N));
1515
+ const E = C.clientX - l, x = I + E / c.value.scaling, ut = r.value.settings.nodes.minWidth, ct = r.value.settings.nodes.maxWidth;
1516
+ a.value.width = Math.max(ut, Math.min(ct, x));
1525
1517
  }, $e = () => {
1526
1518
  b.value = !1;
1527
1519
  };
@@ -1548,7 +1540,7 @@ const $o = /* @__PURE__ */ F({
1548
1540
  onPointerdown: te(v, ["self", "stop"]),
1549
1541
  onContextmenu: te(S, ["prevent"])
1550
1542
  }, [
1551
- a.value.inputs._code ? (d(), j(w(Re), {
1543
+ a.value.inputs._code ? (d(), j(w(Ve), {
1552
1544
  key: 0,
1553
1545
  node: a.value,
1554
1546
  intf: a.value.inputs._code,
@@ -1560,8 +1552,8 @@ const $o = /* @__PURE__ */ F({
1560
1552
  _.value ? de((d(), p("input", {
1561
1553
  key: 2,
1562
1554
  ref_key: "renameInputEl",
1563
- ref: x,
1564
- "onUpdate:modelValue": E[4] || (E[4] = (N) => m.value = N),
1555
+ ref: k,
1556
+ "onUpdate:modelValue": E[4] || (E[4] = (x) => m.value = x),
1565
1557
  class: "baklava-input",
1566
1558
  placeholder: "Node Name",
1567
1559
  style: { "flex-grow": "1" },
@@ -1580,22 +1572,22 @@ const $o = /* @__PURE__ */ F({
1580
1572
  a.value.state.lockCode ? (d(), j(w(Kn), {
1581
1573
  key: 0,
1582
1574
  class: "--clickable mx-1",
1583
- onClick: E[0] || (E[0] = (N) => a.value.lockCode = !1)
1575
+ onClick: E[0] || (E[0] = (x) => a.value.lockCode = !1)
1584
1576
  })) : M("", !0),
1585
1577
  a.value.state.integrated ? (d(), j(w(yn), {
1586
1578
  key: 1,
1587
1579
  class: "--clickable mx-1",
1588
- onClick: E[1] || (E[1] = (N) => Te(!1))
1580
+ onClick: E[1] || (E[1] = (x) => Te(!1))
1589
1581
  })) : (d(), j(w(us), {
1590
1582
  key: 2,
1591
1583
  class: "--clickable mx-1",
1592
- onClick: E[2] || (E[2] = (N) => Te(!0))
1584
+ onClick: E[2] || (E[2] = (x) => Te(!0))
1593
1585
  })),
1594
1586
  !w(r).displayedGraph.sidebar.visible && w(r).displayedGraph.sidebar.nodeId !== a.value.id ? (d(), j(w(Dn), {
1595
1587
  key: 3,
1596
1588
  class: "--clickable mx-1",
1597
1589
  onClick: Ne
1598
- })) : w(r).displayedGraph.sidebar.visible && w(r).displayedGraph.sidebar.nodeId !== a.value.id ? (d(), j(w(Vn), {
1590
+ })) : w(r).displayedGraph.sidebar.visible && w(r).displayedGraph.sidebar.nodeId !== a.value.id ? (d(), j(w(Rn), {
1599
1591
  key: 4,
1600
1592
  class: "--clickable mx-1",
1601
1593
  onClick: rt
@@ -1611,15 +1603,15 @@ const $o = /* @__PURE__ */ F({
1611
1603
  }),
1612
1604
  L(w(t), {
1613
1605
  modelValue: f.value,
1614
- "onUpdate:modelValue": E[3] || (E[3] = (N) => f.value = N),
1606
+ "onUpdate:modelValue": E[3] || (E[3] = (x) => f.value = x),
1615
1607
  x: 0,
1616
1608
  y: 0,
1617
- items: k.value,
1609
+ items: N.value,
1618
1610
  onClick: dt
1619
1611
  }, null, 8, ["modelValue", "items"])
1620
1612
  ])
1621
1613
  ], 64)),
1622
- a.value.outputs._code ? (d(), j(w(Re), {
1614
+ a.value.outputs._code ? (d(), j(w(Ve), {
1623
1615
  key: 3,
1624
1616
  node: a.value,
1625
1617
  intf: a.value.outputs._code,
@@ -1636,14 +1628,14 @@ const $o = /* @__PURE__ */ F({
1636
1628
  }, ["prevent"]))
1637
1629
  }, [
1638
1630
  u("div", Ts, [
1639
- (d(!0), p(B, null, J(pe.value, (N) => (d(), p(B, {
1640
- key: N.id
1631
+ (d(!0), p(B, null, J(pe.value, (x) => (d(), p(B, {
1632
+ key: x.id
1641
1633
  }, [
1642
1634
  a.value.state?.hidden ? (d(), p("div", Es, [
1643
- N.port ? (d(), p("div", {
1635
+ x.port ? (d(), p("div", {
1644
1636
  key: 0,
1645
- id: N.id,
1646
- title: N.name,
1637
+ id: x.id,
1638
+ title: x.name,
1647
1639
  class: "baklava-node-interface --output --connected"
1648
1640
  }, [...E[7] || (E[7] = [
1649
1641
  u("div", { class: "__port" }, null, -1)
@@ -1652,25 +1644,25 @@ const $o = /* @__PURE__ */ F({
1652
1644
  key: 1,
1653
1645
  type: "output",
1654
1646
  node: a.value,
1655
- intf: N
1647
+ intf: x
1656
1648
  }, () => [
1657
1649
  L(w(s), {
1658
1650
  node: a.value,
1659
- intf: N,
1660
- title: N.value
1651
+ intf: x,
1652
+ title: x.value
1661
1653
  }, null, 8, ["node", "intf", "title"])
1662
1654
  ])
1663
1655
  ], 64))), 128))
1664
1656
  ]),
1665
1657
  u("div", Ms, [
1666
- (d(!0), p(B, null, J(W.value, (N) => (d(), p(B, {
1667
- key: N.id
1658
+ (d(!0), p(B, null, J(W.value, (x) => (d(), p(B, {
1659
+ key: x.id
1668
1660
  }, [
1669
1661
  a.value.state?.hidden ? (d(), p("div", Gs, [
1670
- N.port ? (d(), p("div", {
1662
+ x.port ? (d(), p("div", {
1671
1663
  key: 0,
1672
- id: N.id,
1673
- title: N.name,
1664
+ id: x.id,
1665
+ title: x.name,
1674
1666
  class: "baklava-node-interface --input --connected"
1675
1667
  }, [...E[8] || (E[8] = [
1676
1668
  u("div", { class: "__port" }, null, -1)
@@ -1678,13 +1670,13 @@ const $o = /* @__PURE__ */ F({
1678
1670
  ])) : ne(C.$slots, "nodeInterface", {
1679
1671
  key: 1,
1680
1672
  node: a.value,
1681
- intf: N,
1673
+ intf: x,
1682
1674
  type: "input"
1683
1675
  }, () => [
1684
1676
  L(w(s), {
1685
1677
  node: a.value,
1686
- intf: N,
1687
- title: N.value
1678
+ intf: x,
1679
+ title: x.value
1688
1680
  }, null, 8, ["node", "intf", "title"])
1689
1681
  ])
1690
1682
  ], 64))), 128))
@@ -1692,14 +1684,14 @@ const $o = /* @__PURE__ */ F({
1692
1684
  ], 34)
1693
1685
  ], 46, ks));
1694
1686
  }
1695
- }), Rs = ["id"], Vs = { class: "align-middle" }, Re = /* @__PURE__ */ F({
1687
+ }), Vs = ["id"], Rs = { class: "align-middle" }, Ve = /* @__PURE__ */ F({
1696
1688
  __name: "CodeGraphNodeInterface",
1697
1689
  props: {
1698
1690
  node: {},
1699
1691
  intf: {}
1700
1692
  },
1701
1693
  setup(n) {
1702
- const e = n, { viewModel: t } = oe(), { hoveredOver: s, temporaryConnection: o } = zt(), a = R(null), i = O(() => e.intf.connectionCount > 0), r = O(() => ({
1694
+ const e = n, { viewModel: t } = oe(), { hoveredOver: s, temporaryConnection: o } = zt(), a = V(null), i = O(() => e.intf.connectionCount > 0), r = O(() => ({
1703
1695
  "--connected": i.value
1704
1696
  })), c = () => {
1705
1697
  s(e.intf);
@@ -1720,10 +1712,10 @@ const $o = /* @__PURE__ */ F({
1720
1712
  onPointerover: c,
1721
1713
  onPointerout: h
1722
1714
  }, null, 34)) : M("", !0),
1723
- u("span", Vs, [
1715
+ u("span", Rs, [
1724
1716
  ne(_.$slots, "default")
1725
1717
  ])
1726
- ], 10, Rs));
1718
+ ], 10, Vs));
1727
1719
  }
1728
1720
  }), js = {
1729
1721
  class: "baklava-node --palette",
@@ -1737,7 +1729,7 @@ const $o = /* @__PURE__ */ F({
1737
1729
  }, Ls = /* @__PURE__ */ F({
1738
1730
  __name: "CodeNodePalette",
1739
1731
  setup(n) {
1740
- const e = me.PaletteEntry, { viewModel: t } = oe(), { x: s, y: o } = Zt(), { transform: a } = Ht(), i = Lt(t), r = gt("editorEl"), c = R(""), h = R(null), g = () => c.value ? i.value.filter(
1732
+ const e = me.PaletteEntry, { viewModel: t } = oe(), { x: s, y: o } = Zt(), { transform: a } = Ht(), i = Lt(t), r = gt("editorEl"), c = V(""), h = V(null), g = () => c.value ? i.value.filter(
1741
1733
  (b) => b.name.toLowerCase().includes(c.value.toLowerCase()) || Object.values(b.nodeTypes).some(
1742
1734
  (I) => I.title.toLowerCase().includes(c.value.toLowerCase())
1743
1735
  )
@@ -1751,7 +1743,7 @@ const $o = /* @__PURE__ */ F({
1751
1743
  top: `${o.value - I}px`,
1752
1744
  left: `${s.value - b}px`
1753
1745
  };
1754
- }), x = (b, I) => {
1746
+ }), k = (b, I) => {
1755
1747
  h.value = {
1756
1748
  type: b,
1757
1749
  nodeInformation: I
@@ -1759,7 +1751,7 @@ const $o = /* @__PURE__ */ F({
1759
1751
  const l = () => {
1760
1752
  const f = D(new I.type());
1761
1753
  t.value.displayedGraph.addNode(f);
1762
- const k = r.value.getBoundingClientRect(), [y, T] = a(s.value - k.left, o.value - k.top);
1754
+ const N = r.value.getBoundingClientRect(), [y, T] = a(s.value - N.left, o.value - N.top);
1763
1755
  f.position.x = y, f.position.y = T, h.value = null, document.removeEventListener("pointerup", l);
1764
1756
  };
1765
1757
  document.addEventListener("pointerup", l);
@@ -1791,11 +1783,11 @@ const $o = /* @__PURE__ */ F({
1791
1783
  }, G(l.name), 9, zs),
1792
1784
  Object.keys(_(l.nodeTypes)).length < Object.values(l.nodeTypes).length ? (d(), p("div", Hs, " ( " + G(Object.keys(_(l.nodeTypes)).length) + " / " + G(Object.values(l.nodeTypes).length) + " ) ", 1)) : M("", !0)
1793
1785
  ])) : M("", !0),
1794
- (d(!0), p(B, null, J(_(l.nodeTypes), (f, k) => (d(), j(w(e), {
1795
- key: k,
1796
- type: k,
1786
+ (d(!0), p(B, null, J(_(l.nodeTypes), (f, N) => (d(), j(w(e), {
1787
+ key: N,
1788
+ type: N,
1797
1789
  title: f.title,
1798
- onPointerdown: (y) => x(k, f)
1790
+ onPointerdown: (y) => k(N, f)
1799
1791
  }, null, 8, ["type", "title", "onPointerdown"]))), 128))
1800
1792
  ]))), 128))
1801
1793
  ], 34),
@@ -1819,7 +1811,7 @@ const $o = /* @__PURE__ */ F({
1819
1811
  }), Us = ["title"], As = {
1820
1812
  key: 0,
1821
1813
  class: "__label"
1822
- }, Ve = /* @__PURE__ */ F({
1814
+ }, Re = /* @__PURE__ */ F({
1823
1815
  __name: "SidebarCheckbox",
1824
1816
  props: {
1825
1817
  disabled: { type: Boolean },
@@ -1858,14 +1850,14 @@ const $o = /* @__PURE__ */ F({
1858
1850
  }, Js = { style: { display: "flex" } }, Qs = /* @__PURE__ */ F({
1859
1851
  __name: "CodeGraphSidebar",
1860
1852
  setup(n) {
1861
- const { viewModel: e } = oe(), { graph: t } = ge(), s = R(null), o = Be(e.value.settings.sidebar, "width"), a = O(() => e.value.settings.sidebar.resizable);
1853
+ const { viewModel: e } = oe(), { graph: t } = ge(), s = V(null), o = Be(e.value.settings.sidebar, "width"), a = O(() => e.value.settings.sidebar.resizable);
1862
1854
  let i = 0, r = 0;
1863
1855
  const c = O(() => {
1864
1856
  const f = t.value.sidebar.nodeId;
1865
- return t.value.nodes.find((k) => k.id === f);
1857
+ return t.value.nodes.find((N) => N.id === f);
1866
1858
  }), h = O(() => c.value), g = O(() => ({
1867
1859
  width: `${o.value}px`
1868
- })), _ = O(() => h.value ? Object.values(h.value.inputs).filter((f) => f.displayInSidebar && f.component) : []), m = O(() => h.value ? Object.values(h.value.outputs).filter((f) => f.displayInSidebar && f.component) : []), x = () => {
1860
+ })), _ = O(() => h.value ? Object.values(h.value.inputs).filter((f) => f.displayInSidebar && f.component) : []), m = O(() => h.value ? Object.values(h.value.outputs).filter((f) => f.displayInSidebar && f.component) : []), k = () => {
1869
1861
  t.value.sidebar.visible = !1;
1870
1862
  }, b = () => {
1871
1863
  c.value?.events.update.emit(null);
@@ -1878,11 +1870,11 @@ const $o = /* @__PURE__ */ F({
1878
1870
  { once: !0 }
1879
1871
  );
1880
1872
  }, l = (f) => {
1881
- const k = s.value?.parentElement?.getBoundingClientRect().width ?? 500, y = f.clientX - r;
1873
+ const N = s.value?.parentElement?.getBoundingClientRect().width ?? 500, y = f.clientX - r;
1882
1874
  let T = i - y;
1883
- T < 300 ? T = 300 : T > 0.9 * k && (T = 0.9 * k), o.value = T;
1875
+ T < 300 ? T = 300 : T > 0.9 * N && (T = 0.9 * N), o.value = T;
1884
1876
  };
1885
- return (f, k) => (d(), p("div", {
1877
+ return (f, N) => (d(), p("div", {
1886
1878
  class: Y([{ "--open": w(t).sidebar.visible }, "baklava-sidebar"]),
1887
1879
  style: ve(g.value),
1888
1880
  ref_key: "el",
@@ -1898,7 +1890,7 @@ const $o = /* @__PURE__ */ F({
1898
1890
  u("button", {
1899
1891
  tabindex: "-1",
1900
1892
  class: "__close",
1901
- onClick: x
1893
+ onClick: k
1902
1894
  }, "×"),
1903
1895
  u("div", Fs, [
1904
1896
  u("b", null, G(c.value.title), 1)
@@ -1911,11 +1903,11 @@ const $o = /* @__PURE__ */ F({
1911
1903
  class: "__interface"
1912
1904
  }, [
1913
1905
  u("div", Ks, [
1914
- L(Ve, {
1906
+ L(Re, {
1915
1907
  modelValue: y.hidden,
1916
1908
  "onUpdate:modelValue": [
1917
1909
  (T) => y.hidden = T,
1918
- k[0] || (k[0] = () => c.value?.events.update.emit(null))
1910
+ N[0] || (N[0] = () => c.value?.events.update.emit(null))
1919
1911
  ],
1920
1912
  disabled: !y.optional,
1921
1913
  inversed: "",
@@ -1933,9 +1925,9 @@ const $o = /* @__PURE__ */ F({
1933
1925
  ]),
1934
1926
  u("div", Xs, [
1935
1927
  h.value && h.value.state ? (d(), p("div", qs, [
1936
- k[3] || (k[3] = u("label", null, "Variable name", -1)),
1928
+ N[3] || (N[3] = u("label", null, "Variable name", -1)),
1937
1929
  de(u("input", {
1938
- "onUpdate:modelValue": k[1] || (k[1] = (y) => h.value.state.variableName = y),
1930
+ "onUpdate:modelValue": N[1] || (N[1] = (y) => h.value.state.variableName = y),
1939
1931
  type: "text",
1940
1932
  class: "baklava-input",
1941
1933
  title: "Variable name",
@@ -1950,11 +1942,11 @@ const $o = /* @__PURE__ */ F({
1950
1942
  class: "__interface"
1951
1943
  }, [
1952
1944
  u("div", Js, [
1953
- L(Ve, {
1945
+ L(Re, {
1954
1946
  modelValue: y.hidden,
1955
1947
  "onUpdate:modelValue": [
1956
1948
  (T) => y.hidden = T,
1957
- k[2] || (k[2] = () => c.value?.events.update.emit(null))
1949
+ N[2] || (N[2] = () => c.value?.events.update.emit(null))
1958
1950
  ],
1959
1951
  disabled: !y.optional,
1960
1952
  inversed: "",
@@ -1979,23 +1971,23 @@ const $o = /* @__PURE__ */ F({
1979
1971
  class at extends Qe {
1980
1972
  _title = "Subgraph Input";
1981
1973
  inputs = {
1982
- _code: new V("", "").use($, U).setHidden(!0),
1974
+ _code: new R("", "").use($, U).setHidden(!0),
1983
1975
  name: new be("Name", "Input").setPort(!1)
1984
1976
  };
1985
1977
  outputs = {
1986
- _code: new V("", "").use($, U).setHidden(!0),
1978
+ _code: new R("", "").use($, U).setHidden(!0),
1987
1979
  placeholder: new A("Connection", void 0)
1988
1980
  };
1989
1981
  }
1990
1982
  class it extends Ze {
1991
1983
  _title = "Subgraph Output";
1992
1984
  inputs = {
1993
- _code: new V("", "").use($, U).setHidden(!0),
1985
+ _code: new R("", "").use($, U).setHidden(!0),
1994
1986
  name: new be("Name", "Output").setPort(!1),
1995
1987
  placeholder: new A("Connection", void 0)
1996
1988
  };
1997
1989
  outputs = {
1998
- _code: new V("", "").use($, U).setHidden(!0),
1990
+ _code: new R("", "").use($, U).setHidden(!0),
1999
1991
  output: new A("Output", void 0).setHidden(!0)
2000
1992
  };
2001
1993
  }
@@ -2008,18 +2000,18 @@ function eo(n, e, t) {
2008
2000
  (v) => !g.includes(v.from) && h.includes(v.to)
2009
2001
  ), m = i.connections.filter(
2010
2002
  (v) => g.includes(v.from) && !h.includes(v.to)
2011
- ), x = i.connections.filter(
2003
+ ), k = i.connections.filter(
2012
2004
  (v) => g.includes(v.from) && h.includes(v.to)
2013
- ), b = c.map((v) => v.save()), I = x.map((v) => ({
2005
+ ), b = c.map((v) => v.save()), I = k.map((v) => ({
2014
2006
  id: v.id,
2015
2007
  from: v.from.id,
2016
2008
  to: v.to.id
2017
- })), l = /* @__PURE__ */ new Map(), { xLeft: f, xRight: k, yTop: y } = to(c);
2009
+ })), l = /* @__PURE__ */ new Map(), { xLeft: f, xRight: N, yTop: y } = to(c);
2018
2010
  for (const [v, S] of _.entries()) {
2019
2011
  const H = new at();
2020
2012
  H.inputs.name.value = S.to.name, b.push({
2021
2013
  ...H.save(),
2022
- position: { x: k - a.value.settings.nodes.defaultWidth - 100, y: y + v * 200 }
2014
+ position: { x: N - a.value.settings.nodes.defaultWidth - 100, y: y + v * 200 }
2023
2015
  }), I.push({ id: K(), from: H.outputs.placeholder.id, to: S.to.id }), l.set(S.to.id, H.graphInterfaceId);
2024
2016
  }
2025
2017
  for (const [v, S] of m.entries()) {
@@ -2079,9 +2071,8 @@ function to(n) {
2079
2071
  class no extends xt {
2080
2072
  code;
2081
2073
  graph;
2082
- state;
2083
2074
  constructor(e) {
2084
- super(), this.code = e, this.graph = new ue(this), this.code.registerGraph(this.graph), this.saveState();
2075
+ super(), this.code = e, this.graph = new ue(this);
2085
2076
  }
2086
2077
  get graphIds() {
2087
2078
  const e = [];
@@ -2128,22 +2119,16 @@ class no extends xt {
2128
2119
  registerCategoryModule(e, t) {
2129
2120
  this.code.state.modules[e] = t;
2130
2121
  }
2131
- /**
2132
- * Save editor state.
2133
- */
2134
- saveState() {
2135
- this.state = this.save();
2136
- }
2137
2122
  }
2138
2123
  function Go(n) {
2139
- const e = R(n?.code ?? new fn()), t = R(n?.existingEditor ?? new no(e.value)), s = Symbol("ViewModelToken"), o = R(null), a = _t(o), { switchGraph: i } = Is(t, o), r = O(() => a.value && a.value !== t.value.graph), c = D(Ut());
2124
+ const e = V(n?.code ?? new fn()), t = V(n?.existingEditor ?? new no(e.value)), s = Symbol("ViewModelToken"), o = V(null), a = _t(o), { switchGraph: i } = Is(t, o), r = O(() => a.value && a.value !== t.value.graph), c = D(Ut());
2140
2125
  c.nodes.defaultWidth = 400;
2141
2126
  const h = At(), g = Dt(a, h), _ = Ft(a, t, h), m = {
2142
2127
  /** Called whenever a node is rendered */
2143
2128
  renderNode: new Ge(null),
2144
2129
  /** Called whenever an interface is rendered */
2145
2130
  renderInterface: new Ge(null)
2146
- }, x = D({
2131
+ }, k = D({
2147
2132
  clipboard: _,
2148
2133
  code: e,
2149
2134
  commandHandler: h,
@@ -2155,7 +2140,7 @@ function Go(n) {
2155
2140
  settings: c,
2156
2141
  switchGraph: i
2157
2142
  });
2158
- return bs(x), Wt(a, h), eo(a, h, i), Yt(a, h), Kt(a, h, i), Xt(a, h), qt(a, h, c), fs(a, h, c), vs(c), He(
2143
+ return e.value.registerViewModel(k), bs(k), Wt(a, h), eo(a, h, i), Yt(a, h), Kt(a, h, i), Xt(a, h), qt(a, h, c), fs(a, h, c), vs(c), He(
2159
2144
  t,
2160
2145
  (b, I) => {
2161
2146
  I && (I.events.registerGraph.unsubscribe(s), I.graphEvents.beforeAddNode.unsubscribe(s), b.nodeHooks.beforeLoad.unsubscribe(s), b.nodeHooks.afterSave.unsubscribe(s), b.graphTemplateHooks.beforeLoad.unsubscribe(s), b.graphTemplateHooks.afterSave.unsubscribe(s), b.graph.hooks.load.unsubscribe(s), b.graph.hooks.save.unsubscribe(s)), b && (b.nodeHooks.beforeLoad.subscribe(s, (l, f) => (f.position = l.position ?? { x: 0, y: 0 }, f.width = l.width ?? c.nodes.defaultWidth, f.twoColumn = l.twoColumn ?? !1, l)), b.nodeHooks.afterSave.subscribe(s, (l, f) => (l.position = f.position, l.width = f.width, l.twoColumn = f.twoColumn, l)), b.graphTemplateHooks.beforeLoad.subscribe(s, (l, f) => (f.panning = l.panning, f.scaling = l.scaling, l)), b.graphTemplateHooks.afterSave.subscribe(s, (l, f) => (l.panning = f.panning, l.scaling = f.scaling, l)), b.graph.hooks.load.subscribe(s, (l, f) => (f.panning = l.panning, f.scaling = l.scaling, l)), b.graph.hooks.save.subscribe(s, (l, f) => (l.panning = f.panning, l.scaling = f.scaling, l)), b.graphEvents.beforeAddNode.subscribe(
@@ -2164,7 +2149,7 @@ function Go(n) {
2164
2149
  ), t.value.registerNodeType(at, { category: "Subgraphs" }), t.value.registerNodeType(it, { category: "Subgraphs" }), i(b.graph));
2165
2150
  },
2166
2151
  { immediate: !0 }
2167
- ), x;
2152
+ ), k;
2168
2153
  }
2169
2154
  export {
2170
2155
  We as AbstractCodeNode,
@@ -2178,13 +2163,13 @@ export {
2178
2163
  Mo as CodeGraphInfo,
2179
2164
  Qe as CodeGraphInputNode,
2180
2165
  Ps as CodeGraphNode,
2181
- Re as CodeGraphNodeInterface,
2166
+ Ve as CodeGraphNodeInterface,
2182
2167
  Ze as CodeGraphOutputNode,
2183
2168
  Qs as CodeGraphSidebar,
2184
2169
  ce as CodeGraphTemplate,
2185
2170
  _e as CodeNode,
2186
2171
  ae as CodeNodeInputInterface,
2187
- V as CodeNodeInterface,
2172
+ R as CodeNodeInterface,
2188
2173
  ye as CodeNodeInterfaceComponent,
2189
2174
  on as CodeNodeOutputInterface,
2190
2175
  Ls as CodeNodePalette,
@@ -2196,7 +2181,7 @@ export {
2196
2181
  vo as IntegerInterface,
2197
2182
  Tn as LayoutSidebarLeftCollapse,
2198
2183
  Gn as LayoutSidebarLeftExpand,
2199
- Vn as LayoutSidebarRight,
2184
+ Rn as LayoutSidebarRight,
2200
2185
  Hn as LayoutSidebarRightCollapse,
2201
2186
  Dn as LayoutSidebarRightExpand,
2202
2187
  go as ListInputInterface,
@@ -2207,7 +2192,7 @@ export {
2207
2192
  ns as Schema,
2208
2193
  is as SchemaOff,
2209
2194
  _o as SelectInterface,
2210
- Ve as SidebarCheckbox,
2195
+ Re as SidebarCheckbox,
2211
2196
  yo as SliderInterface,
2212
2197
  at as SubgraphInputNode,
2213
2198
  it as SubgraphOutputNode,
@@ -1,4 +1,4 @@
1
- (function(r,$){typeof exports=="object"&&typeof module<"u"?$(exports,require("mustache"),require("vue"),require("uuid"),require("@baklavajs/core"),require("@baklavajs/interface-types"),require("@baklavajs/engine"),require("@baklavajs/renderer-vue"),require("toposort"),require("@baklavajs/events"),require("@vueuse/core")):typeof define=="function"&&define.amd?define(["exports","mustache","vue","uuid","@baklavajs/core","@baklavajs/interface-types","@baklavajs/engine","@baklavajs/renderer-vue","toposort","@baklavajs/events","@vueuse/core"],$):(r=typeof globalThis<"u"?globalThis:r||self,$(r["@babsey/code-graph"]={},r.mustache,r.vue,r.uuid,r["@baklavajs/core"],r["@baklavajs/interface-types"],r["@baklavajs/engine"],r["@baklavajs/renderer-vue"],r.toposort,r["@baklavajs/events"],r["@vueuse/core"]))})(this,(function(r,$,e,j,O,I,R,f,nt,fe,ot){"use strict";$.escape=o=>o;class Y extends O.AbstractNode{state;isCodeNode=!0;name="";codeTemplate;inputs={};outputs={};constructor(){super(),this.initializeIo(),this.twoColumn=!0,this.state=e.reactive({codeTemplate:"",hidden:!1,integrated:!1,lockCode:!1,modules:[],props:null,script:"",variableName:"a"}),this.codeTemplate=function(){return`${this.name}(${ge(this.codeNodeInputs).join(", ")})`}}get code(){return this.graph.code}get codeNodeInputs(){return Object.fromEntries(Object.entries(this.inputs).filter(t=>t[1].isCodeNode&&t[1].type!="node"))}get codeNodeOutputs(){return Object.fromEntries(Object.entries(this.outputs).filter(t=>t[1].isCodeNode&&t[1].type!="node"))}get graph(){return super.graph}get idx(){return this.graph.nodes.filter(t=>!t.state.integrated).indexOf(this)??-1}get idxByVariableNames(){return this.graph.getNodesBySameVariableNames(this.state.variableName).filter(t=>!t.state.integrated).indexOf(this)??-1}get lockCode(){return this.state.lockCode}set lockCode(t){this.state.lockCode=t,this.events.update.emit(null)}get optionalInputs(){return Object.fromEntries(Object.entries(this.codeNodeInputs).filter(t=>t[1].optional))}get requiredInputs(){return Object.fromEntries(Object.entries(this.codeNodeInputs).filter(t=>!t[1].optional))}get script(){return this.outputs._code?.value??""}set script(t){this.outputs._code&&(this.outputs._code.value=t),this.events.update.emit(null)}get shortId(){return this.id.slice(0,6)}get subgraph(){}get variableName(){return this.state.variableName?this.state.variableName+(this.idxByVariableNames+1):""}getConnectedNodeByInterface(t,n){const s=this.getConnectedNodesByInterface(t,n);return s.length>0?s[0]:null}getConnectedNodes(t){let n=[];if(t!=="inputs"){const s=this.graph.connections.filter(a=>a.from.name!=="_code").filter(a=>a.from.nodeId===this.id).map(a=>a.to.nodeId);s&&(n=n.concat(s))}if(t!=="outputs"){const s=this.graph.connections.filter(a=>a.from.name!=="_code").filter(a=>a.to.nodeId===this.id).map(a=>a.from.nodeId);s&&(n=n.concat(s))}return!n||n.length==0?[]:n.map(s=>this.graph.findNodeById(s))}getConnectedNodesByInterface(t,n){let s=[];if(n!=="outputs"&&this.inputs[t]){const a=this.graph.connections.filter(i=>i.to.id===this.inputs[t]?.id||i.from.id===this.inputs[t]?.id).map(i=>i.from.nodeId);a&&(s=s.concat(a))}if(n!=="inputs"&&this.outputs[t]){const a=this.graph.connections.filter(i=>i.from.id===this.outputs[t]?.id||i.from.id===this.outputs[t]?.id).map(i=>i.to.nodeId);a&&(s=s.concat(a))}return!s||s.length==0?[]:s.map(a=>this.graph.findNodeById(a))}registerCode(t){this.code=t}renderCode(t){return $.render(this.state.codeTemplate,t)}updateCodeTemplate(){this.state.codeTemplate=this.codeTemplate.call(this)}updateModules(t){if(t)this.state.modules=t;else if(this.type.includes(".")){const n=this.type.split(".");this.state.modules.push(n.slice(0,n.length-1).join("."))}}updateOutputNames(){Object.values(this.codeNodeOutputs).forEach(t=>{t.name=this.state.integrated?"":this.variableName+t.suffix})}updateOutputValues(t){Object.keys(this.outputs).forEach(n=>{n!=="_code"&&(t[n]=this.state.integrated?t._code:this.outputs[n].name)})}updateProps(t){this.state.props=t}}class A extends Y{calculate=(t,n)=>{const s={};return this.lockCode||(s._code=this.renderCode({inputs:t,...n})),this.updateOutputValues(s),s};load(t){super.load(t),K(this.graph,t)}save(){const t=super.save();return be(this.graph,t),t}}const ge=(o,t=!0)=>{const n=[],s=Object.keys(o);return s.forEach(a=>{if(o[a]?.hidden)return;const l=t&&n.length<s.indexOf(a)?`${a}=`:"";n.push(`${l}{{ inputs.${a} }}`)}),n},K=(o,t)=>{if(!o)return;const n=o.findNodeById(t.id);if(!n||n.subgraph)return;const s=n;s.state&&(s.state.integrated=t.integrated,s.state.modules=t.modules,s.state.props=t.props),Object.entries(t.inputs).forEach(([a,i])=>{a!=="_code"&&s.inputs[a]&&(s.inputs[a].hidden=i.hidden)}),Object.entries(t.outputs).forEach(([a,i])=>{a!=="_code"&&s.outputs[a]&&(s.outputs[a].hidden=i.hidden)})},be=(o,t)=>{if(!o)return;const n=o.findNodeById(t.id);if(!n||n.subgraph)return;const s=n;s.state&&(t.integrated=s.state.integrated,t.modules=s.state.modules),Object.entries(t.inputs).forEach(([a,i])=>{a!=="_code"&&s.inputs[a]&&(i.hidden=s.inputs[a].hidden)}),Object.entries(t.outputs).forEach(([a,i])=>{a!=="_code"&&s.outputs[a]&&(i.hidden=s.outputs[a].hidden)})},st=["title"],H=e.defineComponent({__name:"CodeNodeInterface",props:{intf:{}},setup(o){return(t,n)=>(e.openBlock(),e.createElementBlock("div",{title:o.intf.value},e.toDisplayString(o.intf.name),9,st))}});class x extends O.NodeInterface{isCodeNode=!0;code;state;type=null;constructor(t,n){super(t,n),this.setComponent(e.markRaw(H)),this.state=e.reactive({optional:!1})}get optional(){return this.state.optional}get shortId(){return this.id.slice(0,6)}getValue=()=>`${this.value??"None"}`;setOptional(t){return this.state.optional=t,this.setHidden(t),this}}class L extends x{constructor(t="",n){super(t,n),this.setComponent(e.markRaw(H)),this.use(f.displayInSidebar,!0)}get value(){return super.value}set value(t){super.value=t,this.name!=="_code"&&this.setHidden(!1)}}const X=new I.NodeInterfaceType("boolean"),ke=new I.NodeInterfaceType("dict"),J=new I.NodeInterfaceType("list"),V=new I.NodeInterfaceType("node"),U=new I.NodeInterfaceType("number"),F=new I.NodeInterfaceType("string"),Q=new I.NodeInterfaceType("tuple"),at=o=>{new I.BaklavaInterfaceTypes(o.editor,{viewPlugin:o}).addTypes(X,ke,J,V,U,F,Q)};class it extends L{constructor(t,n){super(t,n),this.setComponent(e.markRaw(f.CheckboxInterfaceComponent)),this.use(I.setType,X)}getValue=()=>this.value?"True":"False"}class Ce extends x{isCodeNodeOutput=!0;suffix="";constructor(t="",n=""){super(t,""),this.suffix=n,this.setComponent(e.markRaw(H))}get codeValue(){return this.node?.outputs._code.value??""}get node(){const{graph:t}=f.useGraph();return t.value.findNodeById(this.nodeId)}}class Z extends L{min;max;constructor(t,n,s,a){super(t,n),this.min=s,this.max=a,this.use(I.setType,U)}validate(t){return(this.min===void 0||t>=this.min)&&(this.max===void 0||t<=this.max)}}class rt extends Z{component=e.markRaw(f.IntegerInterfaceComponent);validate(t){return Number.isInteger(t)&&super.validate(t)}}class lt extends L{constructor(t="",n=""){super(t,n),this.setComponent(e.markRaw(f.TextInputInterfaceComponent)),this.use(I.setType,J)}getValue=()=>`[${this.value}]`}class dt extends Z{component=e.markRaw(f.NumberInterfaceComponent)}class ee extends L{constructor(t,n){super(t,n),this.use(I.setType,F)}getValue=()=>`"${this.value}"`}class ct extends ee{component=e.markRaw(f.SelectInterfaceComponent);items;constructor(t,n,s){super(t,n),this.items=s}}class ut extends Z{component=e.markRaw(f.SliderInterfaceComponent);min;max;constructor(t,n,s,a){super(t,n,s,a),this.min=s,this.max=a}getValue=()=>`${Math.round(this.value*1e3)/1e3}`}const pt=e.defineComponent({props:{intf:{type:Object,required:!0},modelValue:{type:String,required:!0}},emits:["update:modelValue"],setup(o,{emit:t}){return{v:e.computed({get:()=>o.modelValue,set:s=>{t("update:modelValue",s)}})}}}),S=(o,t)=>{const n=o.__vccOpts||o;for(const[s,a]of t)n[s]=a;return n},ht={style:{position:"relative"}},mt={style:{"font-size":"12px",padding:"0 6px",position:"absolute",top:"-8px","background-color":"var(--baklava-node-color-background)"}},ft=["placeholder","title"];function gt(o,t,n,s,a,i){return e.openBlock(),e.createElementBlock("div",ht,[e.createElementVNode("label",mt,e.toDisplayString(o.intf.name),1),e.withDirectives(e.createElementVNode("input",{"onUpdate:modelValue":t[0]||(t[0]=l=>o.v=l),type:"text",class:"baklava-input",placeholder:o.intf.name,title:o.intf.name},null,8,ft),[[e.vModelText,o.v]])])}const ye=S(pt,[["render",gt]]);class bt extends ee{component=e.markRaw(ye)}class kt extends ee{component=e.markRaw(f.TextareaInputInterfaceComponent)}class Ct extends L{constructor(t="",n=""){super(t,n),this.setComponent(e.markRaw(f.TextInputInterfaceComponent)),this.use(I.setType,Q)}getValue=()=>`(${this.value})`}function yt(o){return class extends A{type=o.type;inputs={};outputs={};constructor(){super(),this._title=o.title??o.type,this.executeFactory("input",o.inputs),this.executeFactory("output",o.outputs),o.calculate&&(this.calculate=(t,n)=>o.calculate.call(this,{inputs:t,...n})),o.onCreate?.call(this),this.name=o.name??o.type,this.updateModules(o.modules),o.variableName!=null&&(this.state.variableName=o.variableName),o.codeTemplate&&(this.codeTemplate=o.codeTemplate),this.addInput("_code",new x("",[]).use(I.setType,V).use(R.allowMultipleConnections).setHidden(!0)),this.addOutput("_code",new x("",[]).use(I.setType,V).use(R.allowMultipleConnections).setHidden(!0))}onPlaced(){o.onPlaced?.call(this)}onConnected(){o.onConnected?.call(this)}onDestroy(){o.onDestroy?.call(this)}onUnconnected(){o.onUnconnected?.call(this)}update(){o.update?.call(this)}executeFactory(t,n){Object.keys(n||{}).forEach(s=>{const a=n[s]();t==="input"?this.addInput(s,a):this.addOutput(s,a)})}}}class Ne extends A{}function Nt(o){return class extends Ne{type=o.type;inputs={};outputs={};preventUpdate=!1;staticInputKeys=Object.keys(o.inputs??{});staticOutputKeys=Object.keys(o.outputs??{});constructor(){super(),this._title=o.title??o.type,this.executeFactory("input",o.inputs),this.executeFactory("output",o.outputs),o.calculate&&(this.calculate=(t,n)=>o.calculate?.call(this,t,n)),o.onCreate?.call(this),this.name=o.name??o.type,this.updateModules(o.modules),o.codeTemplate&&(this.codeTemplate=o.codeTemplate),o.variableName&&(this.state.variableName=o.variableName),this.addInput("_code",new x("",[]).use(I.setType,V).use(R.allowMultipleConnections).setHidden(!0)),this.addOutput("_code",new x("",[]).use(I.setType,V).use(R.allowMultipleConnections).setHidden(!0)),this.staticInputKeys.push("_code"),this.staticOutputKeys.push("_code")}onPlaced(){this.events.update.subscribe(this,t=>{t&&(t.type==="input"&&this.staticInputKeys.includes(t.name)||t.type==="output"&&this.staticOutputKeys.includes(t.name))&&this.onUpdate()}),this.onUpdate(),o.onPlaced?.call(this)}onConnected(){o.onConnected?.call(this)}onDestroy(){o.onDestroy?.call(this)}onUnconnected(){o.onUnconnected?.call(this)}update(){o.update?.call(this)}load(t){this.preventUpdate=!0,this.hooks.beforeLoad.execute(t),this.id=t.id,this.title=t.title;for(const n of this.staticInputKeys)this.inputs[n].load(t.inputs[n]),this.inputs[n].nodeId=this.id,n!=="_code"&&(this.inputs[n].hidden=t.inputs[n].hidden);for(const n of this.staticOutputKeys)this.outputs[n].load(t.outputs[n]),this.outputs[n].nodeId=this.id,n!=="_code"&&(this.outputs[n].hidden=t.outputs[n].hidden);this.preventUpdate=!1,this.onUpdate(),this.preventUpdate=!0;for(const n of Object.keys(t.inputs))if(!this.staticInputKeys.includes(n)){if(!this.inputs[n]){const s=t.inputs[n].value;let a;typeof s=="number"?a=new f.IntegerInterface(n,s).use(I.setType,U):a=new f.TextInputInterface(n,JSON.stringify(s)).use(I.setType,F),a.use(f.displayInSidebar,!0),this.addInput(n,a)}this.inputs[n]&&(this.inputs[n].load(t.inputs[n]),this.inputs[n].nodeId=this.id)}for(const n of Object.keys(t.outputs))if(!this.staticOutputKeys.includes(n)){if(!this.outputs[n]){const s=new Ce(n);this.addOutput(n,s)}this.outputs[n]&&(this.outputs[n].load(t.outputs[n]),this.outputs[n].nodeId=this.id)}K(this.graph,t),this.preventUpdate=!1,this.events.loaded.emit(this)}onUpdate(){if(this.preventUpdate)return;this.graph&&this.graph.activeTransactions++;const t=this.getStaticValues(this.staticInputKeys,this.inputs),n=this.getStaticValues(this.staticOutputKeys,this.outputs),s=o.onUpdate.call(this,t,n);this.updateInterfaces("input",s.inputs??{},s.forceUpdateInputs??[]),this.updateInterfaces("output",s.outputs??{},s.forceUpdateOutputs??[]),this.graph&&this.graph.activeTransactions--}getStaticValues(t,n){const s={};for(const a of t)s[a]=n[a].value;return s}updateInterfaces(t,n,s){const a=t==="input"?this.staticInputKeys:this.staticOutputKeys,i=t==="input"?this.inputs:this.outputs;for(const l of Object.keys(i))a.includes(l)||n[l]&&!s.includes(l)||(t==="input"?this.removeInput(l):this.removeOutput(l));for(const l of Object.keys(n)){if(i[l])continue;const d=n[l]();t==="input"?this.addInput(l,d):this.addOutput(l,d)}}updateProps(t){this.state.props=t,this.onUpdate()}executeFactory(t,n){Object.keys(n||{}).forEach(s=>{const a=n[s]();t==="input"?this.addInput(s,a):this.addOutput(s,a)})}}}const te="__baklava_SubgraphInputNode",ne="__baklava_SubgraphOutputNode";class _e extends A{graphInterfaceId;constructor(){super(),this.graphInterfaceId=j.v4()}onPlaced(){super.onPlaced(),this.initializeIo()}load(t){super.load(t),this.graphInterfaceId=t.graphInterfaceId}save(){return{...super.save(),graphInterfaceId:this.graphInterfaceId}}update(){}}class oe extends _e{static isGraphInputNode(t){return t.type===te}type=te;inputs={name:new O.NodeInterface("Name","Input")};outputs={placeholder:new O.NodeInterface("Value",void 0)}}class se extends _e{static isGraphOutputNode(t){return t.type===ne}type=ne;inputs={name:new O.NodeInterface("Name","Output"),placeholder:new O.NodeInterface("Value",void 0)};outputs={output:new O.NodeInterface("Output",void 0).setHidden(!0)};calculate=({placeholder:t})=>({output:t})}const _t=["component","connectionCount","events","hidden","hooks","id","isCodeNode","isInput","name","nodeId","port","templateId","value"];function Ie(o){return class extends Y{type=O.getGraphNodeTypeString(o);get title(){return this._title}set title(n){this.template.name=n}inputs={};outputs={};template=o;subgraph;update(){}onConnected(){}onUnconnected(){}calculate=async(n,s)=>{if(!this.subgraph)throw new Error(`GraphNode ${this.id}: calculate called without subgraph being initialized`);if(!s.engine||typeof s.engine!="object")throw new Error(`GraphNode ${this.id}: calculate called but no engine provided in context`);const a=s.engine.getInputValues(this.subgraph);for(const d of this.subgraph.inputs)a.set(d.nodeInterfaceId,n[d.id]);const i=await s.engine.runGraph(this.subgraph,a,s.globalValues);s.engine.pause(),R.applyResult(i,s.engine.editor),s.engine.resume();const l={};for(const d of this.subgraph.outputs)l[d.id]=i.get(d.nodeId)?.get("output");return l._calculationResults=i,this.lockCode||(l._code=this.renderCode({inputs:n,...s.globalValues})),this.updateOutputValues(l),l};load(n){if(!this.subgraph)throw new Error("Cannot load a graph node without a graph");if(!this.template)throw new Error("Unable to load graph node without graph template");this.subgraph.load(n.graphState),super.load(n)}save(){if(!this.subgraph)throw new Error("Cannot save a graph node without a graph");return{...super.save(),graphState:this.subgraph.save()}}onPlaced(){this.template.events.updated.subscribe(this,()=>this.initialize()),this.template.events.nameChanged.subscribe(this,n=>{this._title=n}),this.initialize()}onDestroy(){this.template.events.updated.unsubscribe(this),this.template.events.nameChanged.unsubscribe(this),this.subgraph?.destroy()}initialize(){this.subgraph&&this.subgraph.destroy(),this.subgraph=this.template.createGraph(),this._title=this.template.name,this.updateInterfaces(),this.state.codeTemplate=`{{ #nodes }}{{ script }}
2
- {{ /nodes }}`,this.events.update.emit(null)}renderCode(n){return this.subgraph?this.subgraph.renderCode({nodes:this.subgraph.scriptedCodeNodes}):$.render(this.state.codeTemplate,n)}updateInterfaces(){if(!this.subgraph)throw new Error("Trying to update interfaces without graph instance");for(const n of this.subgraph.inputs)n.id in this.inputs?this.inputs[n.id].name=n.name:this.addInput(n.id,this.createProxyInterface(n,!0));for(const n of Object.keys(this.inputs))this.subgraph.inputs.some(s=>s.id===n)||this.removeInput(n);for(const n of this.subgraph.outputs)n.id in this.outputs?this.outputs[n.id].name=n.name:this.addOutput(n.id,this.createProxyInterface(n,!1));for(const n of Object.keys(this.outputs))this.subgraph.outputs.some(s=>s.id===n)||this.removeOutput(n);this.addInput("_code",new x("",[]).use(I.setType,V).use(R.allowMultipleConnections).setHidden(!0)),this.addOutput("_code",new x("",[]).use(I.setType,V).use(R.allowMultipleConnections).setHidden(!0)),this.addOutput("_calculationResults",new O.NodeInterface("_calculationResults",void 0).setHidden(!0))}createProxyInterface(n,s){const a=new x(n.name,void 0);return new Proxy(a,{get:(i,l)=>{if(_t.includes(l)||l in i||typeof l=="string"&&l.startsWith("__v_"))return Reflect.get(i,l);let d;s?d=this.subgraph?.nodes.find(C=>oe.isGraphInputNode(C)&&C.graphInterfaceId===n.id)?.outputs.placeholder.id:d=this.subgraph?.nodes.find(C=>se.isGraphOutputNode(C)&&C.graphInterfaceId===n.id)?.inputs.placeholder.id;const u=this.subgraph?.connections.find(b=>d===(s?b.from:b.to)?.id),p=s?u?.to:u?.from;if(p)return Reflect.get(p,l)}})}}}$.escape=o=>o;class we{_id;_graph=null;_state;_engine=null;constructor(){this._id=j.v4(),this._state=e.reactive({lockCode:!1,modules:{},script:"",template:""})}get engine(){return this._engine}get graph(){return this._graph}get id(){return this._id}get lockCode(){return this.state.lockCode}set lockCode(t){this.state.lockCode=t,this.engine?.runOnce(null)}get modules(){const t=[];return this.graph?.codeNodes.filter(n=>n.state.modules?.length>0).forEach(n=>t.push(...n.state.modules)),t?(t.sort(),Array.from(new Set(t.map(n=>this.state.modules[n])))):[]}get script(){return this.state.script}set script(t){this.state.script=t,this.engine?.runOnce(null)}get shortId(){return this.id.slice(0,6)}get state(){return this._state}clear(){this.state.script=""}async loadTemplate(t){t.then(n=>{this._state.template=n.default??""})}registerEngine(t){this._engine=t}registerGraph(t){this._graph=t}renderCode(t){this.state.script=$.render(this.state.template||"",t)}}const It=o=>{o.allowMultipleConnections=!0};class Ee extends R.BaseEngine{order=new Map;constructor(t){super(t),t.code.registerEngine(this)}start(){super.start(),this.recalculateOrder=!0,this.calculateWithoutData()}async runGraph(t,n,s){this.order.has(t.id)||this.order.set(t.id,R.sortTopologically(t));const{calculationOrder:a,connectionsFromNode:i}=this.order.get(t.id),l=new Map;for(const d of a){const u={};Object.entries(d.inputs).forEach(([b,C])=>{u[b]=this.getInterfaceValue(n,C.id)}),d.isCodeNode&&(d.updateCodeTemplate(),d.updateOutputNames()),this.events.beforeNodeCalculation.emit({inputValues:u,node:d});let p;if(d.calculate){if(p=await d.calculate(u,{globalValues:s,engine:this}),i.has(d))for(const[b,C]of Object.entries(p))this.hooks.transferData.execute(p[b],C),i.get(d).forEach(h=>{n.set(h.to.id,C)})}else{p={};for(const[b,C]of Object.entries(d.outputs))p[b]=this.getInterfaceValue(n,C.id)}this.events.afterNodeCalculation.emit({outputValues:p,node:d}),l.set(d.id,new Map(Object.entries(p))),i.has(d)&&i.get(d).forEach(b=>{const C=Object.entries(d.outputs).find(([,v])=>v.id===b.from.id)?.[0];if(!C)throw new Error(`Could not find key for interface ${b.from.id}
1
+ (function(r,G){typeof exports=="object"&&typeof module<"u"?G(exports,require("mustache"),require("vue"),require("uuid"),require("@baklavajs/core"),require("@baklavajs/interface-types"),require("@baklavajs/engine"),require("@baklavajs/renderer-vue"),require("toposort"),require("@baklavajs/events"),require("@vueuse/core")):typeof define=="function"&&define.amd?define(["exports","mustache","vue","uuid","@baklavajs/core","@baklavajs/interface-types","@baklavajs/engine","@baklavajs/renderer-vue","toposort","@baklavajs/events","@vueuse/core"],G):(r=typeof globalThis<"u"?globalThis:r||self,G(r["@babsey/code-graph"]={},r.mustache,r.vue,r.uuid,r["@baklavajs/core"],r["@baklavajs/interface-types"],r["@baklavajs/engine"],r["@baklavajs/renderer-vue"],r.toposort,r["@baklavajs/events"],r["@vueuse/core"]))})(this,(function(r,G,e,j,O,I,R,f,nt,fe,ot){"use strict";G.escape=o=>o;class Y extends O.AbstractNode{state;isCodeNode=!0;name="";codeTemplate;inputs={};outputs={};constructor(){super(),this.initializeIo(),this.twoColumn=!0,this.state=e.reactive({codeTemplate:"",hidden:!1,integrated:!1,lockCode:!1,modules:[],props:null,script:"",variableName:"a"}),this.codeTemplate=function(){return`${this.name}(${ge(this.codeNodeInputs).join(", ")})`}}get code(){return this.graph.code}get codeNodeInputs(){return Object.fromEntries(Object.entries(this.inputs).filter(t=>t[1].isCodeNode&&t[1].type!="node"))}get codeNodeOutputs(){return Object.fromEntries(Object.entries(this.outputs).filter(t=>t[1].isCodeNode&&t[1].type!="node"))}get graph(){return super.graph}get idx(){return this.graph.nodes.filter(t=>!t.state.integrated).indexOf(this)??-1}get idxByVariableNames(){return this.graph.getNodesBySameVariableNames(this.state.variableName).filter(t=>!t.state.integrated).indexOf(this)??-1}get lockCode(){return this.state.lockCode}set lockCode(t){this.state.lockCode=t,this.events.update.emit(null)}get optionalInputs(){return Object.fromEntries(Object.entries(this.codeNodeInputs).filter(t=>t[1].optional))}get requiredInputs(){return Object.fromEntries(Object.entries(this.codeNodeInputs).filter(t=>!t[1].optional))}get script(){return this.outputs._code?.value??""}set script(t){this.outputs._code&&(this.outputs._code.value=t),this.events.update.emit(null)}get shortId(){return this.id.slice(0,6)}get subgraph(){}get variableName(){return this.state.variableName?this.state.variableName+(this.idxByVariableNames+1):""}getConnectedNodeByInterface(t,n){const s=this.getConnectedNodesByInterface(t,n);return s.length>0?s[0]:null}getConnectedNodes(t){let n=[];if(t!=="inputs"){const s=this.graph.connections.filter(a=>a.from.name!=="_code").filter(a=>a.from.nodeId===this.id).map(a=>a.to.nodeId);s&&(n=n.concat(s))}if(t!=="outputs"){const s=this.graph.connections.filter(a=>a.from.name!=="_code").filter(a=>a.to.nodeId===this.id).map(a=>a.from.nodeId);s&&(n=n.concat(s))}return!n||n.length==0?[]:n.map(s=>this.graph.findNodeById(s))}getConnectedNodesByInterface(t,n){let s=[];if(n!=="outputs"&&this.inputs[t]){const a=this.graph.connections.filter(i=>i.to.id===this.inputs[t]?.id||i.from.id===this.inputs[t]?.id).map(i=>i.from.nodeId);a&&(s=s.concat(a))}if(n!=="inputs"&&this.outputs[t]){const a=this.graph.connections.filter(i=>i.from.id===this.outputs[t]?.id||i.from.id===this.outputs[t]?.id).map(i=>i.to.nodeId);a&&(s=s.concat(a))}return!s||s.length==0?[]:s.map(a=>this.graph.findNodeById(a))}registerCode(t){this.code=t}renderCode(t){return G.render(this.state.codeTemplate,t)}updateCodeTemplate(){this.state.codeTemplate=this.codeTemplate.call(this)}updateModules(t){if(t)this.state.modules=t;else if(this.type.includes(".")){const n=this.type.split(".");this.state.modules.push(n.slice(0,n.length-1).join("."))}}updateOutputNames(){Object.values(this.codeNodeOutputs).forEach(t=>{t.name=this.state.integrated?"":this.variableName+t.suffix})}updateOutputValues(t){Object.keys(this.outputs).forEach(n=>{n!=="_code"&&(t[n]=this.state.integrated?t._code:this.outputs[n].name)})}updateProps(t){this.state.props=t}}class A extends Y{calculate=(t,n)=>{const s={};return this.lockCode||(s._code=this.renderCode({inputs:t,...n})),this.updateOutputValues(s),s};load(t){super.load(t),K(this.graph,t)}save(){const t=super.save();return be(this.graph,t),t}}const ge=(o,t=!0)=>{const n=[],s=Object.keys(o);return s.forEach(a=>{if(o[a]?.hidden)return;const l=t&&n.length<s.indexOf(a)?`${a}=`:"";n.push(`${l}{{ inputs.${a} }}`)}),n},K=(o,t)=>{if(!o)return;const n=o.findNodeById(t.id);if(!n||n.subgraph)return;const s=n;s.state&&(s.state.integrated=t.integrated,s.state.modules=t.modules,s.state.props=t.props),Object.entries(t.inputs).forEach(([a,i])=>{a!=="_code"&&s.inputs[a]&&(s.inputs[a].hidden=i.hidden)}),Object.entries(t.outputs).forEach(([a,i])=>{a!=="_code"&&s.outputs[a]&&(s.outputs[a].hidden=i.hidden)})},be=(o,t)=>{if(!o)return;const n=o.findNodeById(t.id);if(!n||n.subgraph)return;const s=n;s.state&&(t.integrated=s.state.integrated,t.modules=s.state.modules),Object.entries(t.inputs).forEach(([a,i])=>{a!=="_code"&&s.inputs[a]&&(i.hidden=s.inputs[a].hidden)}),Object.entries(t.outputs).forEach(([a,i])=>{a!=="_code"&&s.outputs[a]&&(i.hidden=s.outputs[a].hidden)})},st=["title"],H=e.defineComponent({__name:"CodeNodeInterface",props:{intf:{}},setup(o){return(t,n)=>(e.openBlock(),e.createElementBlock("div",{title:o.intf.value},e.toDisplayString(o.intf.name),9,st))}});class x extends O.NodeInterface{isCodeNode=!0;code;state;type=null;constructor(t,n){super(t,n),this.setComponent(e.markRaw(H)),this.state=e.reactive({optional:!1})}get optional(){return this.state.optional}get shortId(){return this.id.slice(0,6)}getValue=()=>`${this.value??"None"}`;setOptional(t){return this.state.optional=t,this.setHidden(t),this}}class L extends x{constructor(t="",n){super(t,n),this.setComponent(e.markRaw(H)),this.use(f.displayInSidebar,!0)}get value(){return super.value}set value(t){super.value=t,this.name!=="_code"&&this.setHidden(!1)}}const X=new I.NodeInterfaceType("boolean"),ke=new I.NodeInterfaceType("dict"),J=new I.NodeInterfaceType("list"),V=new I.NodeInterfaceType("node"),U=new I.NodeInterfaceType("number"),F=new I.NodeInterfaceType("string"),Q=new I.NodeInterfaceType("tuple"),at=o=>{new I.BaklavaInterfaceTypes(o.editor,{viewPlugin:o}).addTypes(X,ke,J,V,U,F,Q)};class it extends L{constructor(t,n){super(t,n),this.setComponent(e.markRaw(f.CheckboxInterfaceComponent)),this.use(I.setType,X)}getValue=()=>this.value?"True":"False"}class Ce extends x{isCodeNodeOutput=!0;suffix="";constructor(t="",n=""){super(t,""),this.suffix=n,this.setComponent(e.markRaw(H))}get codeValue(){return this.node?.outputs._code.value??""}get node(){const{graph:t}=f.useGraph();return t.value.findNodeById(this.nodeId)}}class Z extends L{min;max;constructor(t,n,s,a){super(t,n),this.min=s,this.max=a,this.use(I.setType,U)}validate(t){return(this.min===void 0||t>=this.min)&&(this.max===void 0||t<=this.max)}}class rt extends Z{component=e.markRaw(f.IntegerInterfaceComponent);validate(t){return Number.isInteger(t)&&super.validate(t)}}class lt extends L{constructor(t="",n=""){super(t,n),this.setComponent(e.markRaw(f.TextInputInterfaceComponent)),this.use(I.setType,J)}getValue=()=>`[${this.value}]`}class dt extends Z{component=e.markRaw(f.NumberInterfaceComponent)}class ee extends L{constructor(t,n){super(t,n),this.use(I.setType,F)}getValue=()=>`"${this.value}"`}class ct extends ee{component=e.markRaw(f.SelectInterfaceComponent);items;constructor(t,n,s){super(t,n),this.items=s}}class ut extends Z{component=e.markRaw(f.SliderInterfaceComponent);min;max;constructor(t,n,s,a){super(t,n,s,a),this.min=s,this.max=a}getValue=()=>`${Math.round(this.value*1e3)/1e3}`}const pt=e.defineComponent({props:{intf:{type:Object,required:!0},modelValue:{type:String,required:!0}},emits:["update:modelValue"],setup(o,{emit:t}){return{v:e.computed({get:()=>o.modelValue,set:s=>{t("update:modelValue",s)}})}}}),M=(o,t)=>{const n=o.__vccOpts||o;for(const[s,a]of t)n[s]=a;return n},ht={style:{position:"relative"}},mt={style:{"font-size":"12px",padding:"0 6px",position:"absolute",top:"-8px","background-color":"var(--baklava-node-color-background)"}},ft=["placeholder","title"];function gt(o,t,n,s,a,i){return e.openBlock(),e.createElementBlock("div",ht,[e.createElementVNode("label",mt,e.toDisplayString(o.intf.name),1),e.withDirectives(e.createElementVNode("input",{"onUpdate:modelValue":t[0]||(t[0]=l=>o.v=l),type:"text",class:"baklava-input",placeholder:o.intf.name,title:o.intf.name},null,8,ft),[[e.vModelText,o.v]])])}const ye=M(pt,[["render",gt]]);class bt extends ee{component=e.markRaw(ye)}class kt extends ee{component=e.markRaw(f.TextareaInputInterfaceComponent)}class Ct extends L{constructor(t="",n=""){super(t,n),this.setComponent(e.markRaw(f.TextInputInterfaceComponent)),this.use(I.setType,Q)}getValue=()=>`(${this.value})`}function yt(o){return class extends A{type=o.type;inputs={};outputs={};constructor(){super(),this._title=o.title??o.type,this.executeFactory("input",o.inputs),this.executeFactory("output",o.outputs),o.calculate&&(this.calculate=(t,n)=>o.calculate.call(this,{inputs:t,...n})),o.onCreate?.call(this),this.name=o.name??o.type,this.updateModules(o.modules),o.variableName!=null&&(this.state.variableName=o.variableName),o.codeTemplate&&(this.codeTemplate=o.codeTemplate),this.addInput("_code",new x("",[]).use(I.setType,V).use(R.allowMultipleConnections).setHidden(!0)),this.addOutput("_code",new x("",[]).use(I.setType,V).use(R.allowMultipleConnections).setHidden(!0))}onPlaced(){o.onPlaced?.call(this)}onConnected(){o.onConnected?.call(this)}onDestroy(){o.onDestroy?.call(this)}onUnconnected(){o.onUnconnected?.call(this)}update(){o.update?.call(this)}executeFactory(t,n){Object.keys(n||{}).forEach(s=>{const a=n[s]();t==="input"?this.addInput(s,a):this.addOutput(s,a)})}}}class Ne extends A{}function Nt(o){return class extends Ne{type=o.type;inputs={};outputs={};preventUpdate=!1;staticInputKeys=Object.keys(o.inputs??{});staticOutputKeys=Object.keys(o.outputs??{});constructor(){super(),this._title=o.title??o.type,this.executeFactory("input",o.inputs),this.executeFactory("output",o.outputs),o.calculate&&(this.calculate=(t,n)=>o.calculate?.call(this,t,n)),o.onCreate?.call(this),this.name=o.name??o.type,this.updateModules(o.modules),o.codeTemplate&&(this.codeTemplate=o.codeTemplate),o.variableName&&(this.state.variableName=o.variableName),this.addInput("_code",new x("",[]).use(I.setType,V).use(R.allowMultipleConnections).setHidden(!0)),this.addOutput("_code",new x("",[]).use(I.setType,V).use(R.allowMultipleConnections).setHidden(!0)),this.staticInputKeys.push("_code"),this.staticOutputKeys.push("_code")}onPlaced(){this.events.update.subscribe(this,t=>{t&&(t.type==="input"&&this.staticInputKeys.includes(t.name)||t.type==="output"&&this.staticOutputKeys.includes(t.name))&&this.onUpdate()}),this.onUpdate(),o.onPlaced?.call(this)}onConnected(){o.onConnected?.call(this)}onDestroy(){o.onDestroy?.call(this)}onUnconnected(){o.onUnconnected?.call(this)}update(){o.update?.call(this)}load(t){this.preventUpdate=!0,this.hooks.beforeLoad.execute(t),this.id=t.id,this.title=t.title;for(const n of this.staticInputKeys)this.inputs[n].load(t.inputs[n]),this.inputs[n].nodeId=this.id,n!=="_code"&&(this.inputs[n].hidden=t.inputs[n].hidden);for(const n of this.staticOutputKeys)this.outputs[n].load(t.outputs[n]),this.outputs[n].nodeId=this.id,n!=="_code"&&(this.outputs[n].hidden=t.outputs[n].hidden);this.preventUpdate=!1,this.onUpdate(),this.preventUpdate=!0;for(const n of Object.keys(t.inputs))if(!this.staticInputKeys.includes(n)){if(!this.inputs[n]){const s=t.inputs[n].value;let a;typeof s=="number"?a=new f.IntegerInterface(n,s).use(I.setType,U):a=new f.TextInputInterface(n,JSON.stringify(s)).use(I.setType,F),a.use(f.displayInSidebar,!0),this.addInput(n,a)}this.inputs[n]&&(this.inputs[n].load(t.inputs[n]),this.inputs[n].nodeId=this.id)}for(const n of Object.keys(t.outputs))if(!this.staticOutputKeys.includes(n)){if(!this.outputs[n]){const s=new Ce(n);this.addOutput(n,s)}this.outputs[n]&&(this.outputs[n].load(t.outputs[n]),this.outputs[n].nodeId=this.id)}K(this.graph,t),this.preventUpdate=!1,this.events.loaded.emit(this)}onUpdate(){if(this.preventUpdate)return;this.graph&&this.graph.activeTransactions++;const t=this.getStaticValues(this.staticInputKeys,this.inputs),n=this.getStaticValues(this.staticOutputKeys,this.outputs),s=o.onUpdate.call(this,t,n);this.updateInterfaces("input",s.inputs??{},s.forceUpdateInputs??[]),this.updateInterfaces("output",s.outputs??{},s.forceUpdateOutputs??[]),this.graph&&this.graph.activeTransactions--}getStaticValues(t,n){const s={};for(const a of t)s[a]=n[a].value;return s}updateInterfaces(t,n,s){const a=t==="input"?this.staticInputKeys:this.staticOutputKeys,i=t==="input"?this.inputs:this.outputs;for(const l of Object.keys(i))a.includes(l)||n[l]&&!s.includes(l)||(t==="input"?this.removeInput(l):this.removeOutput(l));for(const l of Object.keys(n)){if(i[l])continue;const d=n[l]();t==="input"?this.addInput(l,d):this.addOutput(l,d)}}updateProps(t){this.state.props=t,this.onUpdate()}executeFactory(t,n){Object.keys(n||{}).forEach(s=>{const a=n[s]();t==="input"?this.addInput(s,a):this.addOutput(s,a)})}}}const te="__baklava_SubgraphInputNode",ne="__baklava_SubgraphOutputNode";class _e extends A{graphInterfaceId;constructor(){super(),this.graphInterfaceId=j.v4()}onPlaced(){super.onPlaced(),this.initializeIo()}load(t){super.load(t),this.graphInterfaceId=t.graphInterfaceId}save(){return{...super.save(),graphInterfaceId:this.graphInterfaceId}}update(){}}class oe extends _e{static isGraphInputNode(t){return t.type===te}type=te;inputs={name:new O.NodeInterface("Name","Input")};outputs={placeholder:new O.NodeInterface("Value",void 0)}}class se extends _e{static isGraphOutputNode(t){return t.type===ne}type=ne;inputs={name:new O.NodeInterface("Name","Output"),placeholder:new O.NodeInterface("Value",void 0)};outputs={output:new O.NodeInterface("Output",void 0).setHidden(!0)};calculate=({placeholder:t})=>({output:t})}const _t=["component","connectionCount","events","hidden","hooks","id","isCodeNode","isInput","name","nodeId","port","templateId","value"];function Ie(o){return class extends Y{type=O.getGraphNodeTypeString(o);get title(){return this._title}set title(n){this.template.name=n}inputs={};outputs={};template=o;subgraph;update(){}onConnected(){}onUnconnected(){}calculate=async(n,s)=>{if(!this.subgraph)throw new Error(`GraphNode ${this.id}: calculate called without subgraph being initialized`);if(!s.engine||typeof s.engine!="object")throw new Error(`GraphNode ${this.id}: calculate called but no engine provided in context`);const a=s.engine.getInputValues(this.subgraph);for(const d of this.subgraph.inputs)a.set(d.nodeInterfaceId,n[d.id]);const i=await s.engine.runGraph(this.subgraph,a,s.globalValues);s.engine.pause(),R.applyResult(i,s.engine.editor),s.engine.resume();const l={};for(const d of this.subgraph.outputs)l[d.id]=i.get(d.nodeId)?.get("output");return l._calculationResults=i,this.lockCode||(l._code=this.renderCode({inputs:n,...s.globalValues})),this.updateOutputValues(l),l};load(n){if(!this.subgraph)throw new Error("Cannot load a graph node without a graph");if(!this.template)throw new Error("Unable to load graph node without graph template");this.subgraph.load(n.graphState),super.load(n)}save(){if(!this.subgraph)throw new Error("Cannot save a graph node without a graph");return{...super.save(),graphState:this.subgraph.save()}}onPlaced(){this.template.events.updated.subscribe(this,()=>this.initialize()),this.template.events.nameChanged.subscribe(this,n=>{this._title=n}),this.initialize()}onDestroy(){this.template.events.updated.unsubscribe(this),this.template.events.nameChanged.unsubscribe(this),this.subgraph?.destroy()}initialize(){this.subgraph&&this.subgraph.destroy(),this.subgraph=this.template.createGraph(),this._title=this.template.name,this.updateInterfaces(),this.state.codeTemplate=`{{ #nodes }}{{ script }}
2
+ {{ /nodes }}`,this.events.update.emit(null)}renderCode(n){return this.subgraph?this.subgraph.renderCode({nodes:this.subgraph.scriptedCodeNodes}):G.render(this.state.codeTemplate,n)}updateInterfaces(){if(!this.subgraph)throw new Error("Trying to update interfaces without graph instance");for(const n of this.subgraph.inputs)n.id in this.inputs?this.inputs[n.id].name=n.name:this.addInput(n.id,this.createProxyInterface(n,!0));for(const n of Object.keys(this.inputs))this.subgraph.inputs.some(s=>s.id===n)||this.removeInput(n);for(const n of this.subgraph.outputs)n.id in this.outputs?this.outputs[n.id].name=n.name:this.addOutput(n.id,this.createProxyInterface(n,!1));for(const n of Object.keys(this.outputs))this.subgraph.outputs.some(s=>s.id===n)||this.removeOutput(n);this.addInput("_code",new x("",[]).use(I.setType,V).use(R.allowMultipleConnections).setHidden(!0)),this.addOutput("_code",new x("",[]).use(I.setType,V).use(R.allowMultipleConnections).setHidden(!0)),this.addOutput("_calculationResults",new O.NodeInterface("_calculationResults",void 0).setHidden(!0))}createProxyInterface(n,s){const a=new x(n.name,void 0);return new Proxy(a,{get:(i,l)=>{if(_t.includes(l)||l in i||typeof l=="string"&&l.startsWith("__v_"))return Reflect.get(i,l);let d;s?d=this.subgraph?.nodes.find(C=>oe.isGraphInputNode(C)&&C.graphInterfaceId===n.id)?.outputs.placeholder.id:d=this.subgraph?.nodes.find(C=>se.isGraphOutputNode(C)&&C.graphInterfaceId===n.id)?.inputs.placeholder.id;const u=this.subgraph?.connections.find(b=>d===(s?b.from:b.to)?.id),p=s?u?.to:u?.from;if(p)return Reflect.get(p,l)}})}}}G.escape=o=>o;class we{_id;_state;viewModel;constructor(){this._id=j.v4(),this._state=e.reactive({lockCode:!1,modules:{},script:"",template:""})}get engine(){return this.viewModel?.engine}get graph(){return this.viewModel?.editor.graph}get id(){return this._id}get lockCode(){return this.state.lockCode}set lockCode(t){this.state.lockCode=t,this.engine?.runOnce(null)}get modules(){const t=[];return this.graph?.codeNodes.filter(n=>n.state.modules?.length>0).forEach(n=>t.push(...n.state.modules)),t?(t.sort(),Array.from(new Set(t.map(n=>this.state.modules[n])))):[]}get script(){return this.state.script}set script(t){this.state.script=t,this.engine?.runOnce(null)}get shortId(){return this.id.slice(0,6)}get state(){return this._state}clear(){this.state.script=""}async loadTemplate(t){t.then(n=>{this._state.template=n.default??""})}registerViewModel(t){this.viewModel=t}renderCode(t){this.state.script=G.render(this.state.template||"",t)}}const It=o=>{o.allowMultipleConnections=!0};class Ee extends R.BaseEngine{order=new Map;constructor(t){super(t)}start(){super.start(),this.recalculateOrder=!0,this.calculateWithoutData()}async runGraph(t,n,s){this.order.has(t.id)||this.order.set(t.id,R.sortTopologically(t));const{calculationOrder:a,connectionsFromNode:i}=this.order.get(t.id),l=new Map;for(const d of a){const u={};Object.entries(d.inputs).forEach(([b,C])=>{u[b]=this.getInterfaceValue(n,C.id)}),d.isCodeNode&&(d.updateCodeTemplate(),d.updateOutputNames()),this.events.beforeNodeCalculation.emit({inputValues:u,node:d});let p;if(d.calculate){if(p=await d.calculate(u,{globalValues:s,engine:this}),i.has(d))for(const[b,C]of Object.entries(p))this.hooks.transferData.execute(p[b],C),i.get(d).forEach(h=>{n.set(h.to.id,C)})}else{p={};for(const[b,C]of Object.entries(d.outputs))p[b]=this.getInterfaceValue(n,C.id)}this.events.afterNodeCalculation.emit({outputValues:p,node:d}),l.set(d.id,new Map(Object.entries(p))),i.has(d)&&i.get(d).forEach(b=>{const C=Object.entries(d.outputs).find(([,w])=>w.id===b.from.id)?.[0];if(!C)throw new Error(`Could not find key for interface ${b.from.id}
3
3
  This is likely an internal issue. Please report it on GitHub.`);const h=this.hooks.transferData.execute(p[C],b);b.to.allowMultipleConnections?n.has(b.to.id)?n.get(b.to.id).push(h):n.set(b.to.id,[h]):n.set(b.to.id,h)})}return l}async execute(t){this.recalculateOrder&&(this.order.clear(),this.recalculateOrder=!1);const n=this.getInputValues(this.editor.graph);return await this.runGraph(this.editor.graph,n,t)}getInputValues(t){const n=new Map;for(const s of t.nodes)Object.values(s.inputs).forEach(a=>{a.connectionCount===0&&n.set(a.id,a.getValue?a.getValue():a.value)}),s.calculate||Object.values(s.outputs).forEach(a=>{n.set(a.id,a.getValue?a.getValue():a.value)});return n}onChange(t){this.recalculateOrder=t||this.recalculateOrder,this.calculateWithoutData()}getInterfaceValue(t,n){if(!t.has(n))throw new Error(`Could not find value for interface ${n}
4
- This is likely an internal issue. Please report it on GitHub.`);return t.get(n)}}const wt={},Et={xmlns:"http://www.w3.org/2000/svg",width:"24",height:"24",viewBox:"0 0 24 24",fill:"none",stroke:"currentColor","stroke-width":"2","stroke-linecap":"round","stroke-linejoin":"round",class:"baklava-icon icon icon-tabler icons-tabler-outline icon-tabler-code-variable"};function vt(o,t){return e.openBlock(),e.createElementBlock("svg",Et,[...t[0]||(t[0]=[e.createElementVNode("path",{stroke:"none",d:"M0 0h24v24H0z",fill:"none"},null,-1),e.createElementVNode("path",{d:"M4 8m0 2a2 2 0 0 1 2 -2h12a2 2 0 0 1 2 2v4a2 2 0 0 1 -2 2h-12a2 2 0 0 1 -2 -2z"},null,-1)])])}const ve=S(wt,[["render",vt]]),Bt={},Tt={xmlns:"http://www.w3.org/2000/svg",width:"24",height:"24",viewBox:"0 0 24 24",fill:"none",stroke:"currentColor","stroke-width":"2","stroke-linecap":"round","stroke-linejoin":"round",class:"baklava-icon icon icon-tabler icons-tabler-outline icon-tabler-dots-vertical"};function Ot(o,t){return e.openBlock(),e.createElementBlock("svg",Tt,[...t[0]||(t[0]=[e.createElementVNode("path",{stroke:"none",d:"M0 0h24v24H0z",fill:"none"},null,-1),e.createElementVNode("path",{d:"M12 12m-1 0a1 1 0 1 0 2 0a1 1 0 1 0 -2 0"},null,-1),e.createElementVNode("path",{d:"M12 19m-1 0a1 1 0 1 0 2 0a1 1 0 1 0 -2 0"},null,-1),e.createElementVNode("path",{d:"M12 5m-1 0a1 1 0 1 0 2 0a1 1 0 1 0 -2 0"},null,-1)])])}const Be=S(Bt,[["render",Ot]]),xt={},St={xmlns:"http://www.w3.org/2000/svg",width:"24",height:"24",viewBox:"0 0 24 24",fill:"currentColor",class:"baklava-icon icon icon-tabler icons-tabler-filled icon-tabler-layout-sidebar-left-collapse"};function Mt(o,t){return e.openBlock(),e.createElementBlock("svg",St,[...t[0]||(t[0]=[e.createElementVNode("path",{stroke:"none",d:"M0 0h24v24H0z",fill:"none"},null,-1),e.createElementVNode("path",{d:"M18 3a3 3 0 0 1 2.995 2.824l.005 .176v12a3 3 0 0 1 -2.824 2.995l-.176 .005h-12a3 3 0 0 1 -2.995 -2.824l-.005 -.176v-12a3 3 0 0 1 2.824 -2.995l.176 -.005h12zm0 2h-9v14h9a1 1 0 0 0 .993 -.883l.007 -.117v-12a1 1 0 0 0 -.883 -.993l-.117 -.007zm-2.293 4.293a1 1 0 0 1 .083 1.32l-.083 .094l-1.292 1.293l1.292 1.293a1 1 0 0 1 .083 1.32l-.083 .094a1 1 0 0 1 -1.32 .083l-.094 -.083l-2 -2a1 1 0 0 1 -.083 -1.32l.083 -.094l2 -2a1 1 0 0 1 1.414 0z"},null,-1)])])}const Te=S(xt,[["render",Mt]]),Vt={},Gt={xmlns:"http://www.w3.org/2000/svg",width:"24",height:"24",viewBox:"0 0 24 24",fill:"currentColor",class:"baklava-icon icon icon-tabler icons-tabler-filled icon-tabler-layout-sidebar-left-expand"};function $t(o,t){return e.openBlock(),e.createElementBlock("svg",Gt,[...t[0]||(t[0]=[e.createElementVNode("path",{stroke:"none",d:"M0 0h24v24H0z",fill:"none"},null,-1),e.createElementVNode("path",{d:"M18 3a3 3 0 0 1 2.995 2.824l.005 .176v12a3 3 0 0 1 -2.824 2.995l-.176 .005h-12a3 3 0 0 1 -2.995 -2.824l-.005 -.176v-12a3 3 0 0 1 2.824 -2.995l.176 -.005h12zm0 2h-9v14h9a1 1 0 0 0 .993 -.883l.007 -.117v-12a1 1 0 0 0 -.883 -.993l-.117 -.007zm-4.387 4.21l.094 .083l2 2a1 1 0 0 1 .083 1.32l-.083 .094l-2 2a1 1 0 0 1 -1.497 -1.32l.083 -.094l1.292 -1.293l-1.292 -1.293a1 1 0 0 1 -.083 -1.32l.083 -.094a1 1 0 0 1 1.32 -.083z"},null,-1)])])}const Oe=S(Vt,[["render",$t]]),Rt={},jt={xmlns:"http://www.w3.org/2000/svg",width:"24",height:"24",viewBox:"0 0 24 24",fill:"currentColor",class:"baklava-icon icon icon-tabler icons-tabler-filled icon-tabler-layout-sidebar-right"};function Pt(o,t){return e.openBlock(),e.createElementBlock("svg",jt,[...t[0]||(t[0]=[e.createElementVNode("path",{stroke:"none",d:"M0 0h24v24H0z",fill:"none"},null,-1),e.createElementVNode("path",{d:"M6 21a3 3 0 0 1 -3 -3v-12a3 3 0 0 1 3 -3h12a3 3 0 0 1 3 3v12a3 3 0 0 1 -3 3zm8 -16h-8a1 1 0 0 0 -1 1v12a1 1 0 0 0 1 1h8z"},null,-1)])])}const xe=S(Rt,[["render",Pt]]),Lt={},Dt={xmlns:"http://www.w3.org/2000/svg",width:"24",height:"24",viewBox:"0 0 24 24",fill:"currentColor",class:"baklava-icon icon icon-tabler icons-tabler-filled icon-tabler-layout-sidebar-right-collapse"};function zt(o,t){return e.openBlock(),e.createElementBlock("svg",Dt,[...t[0]||(t[0]=[e.createElementVNode("path",{stroke:"none",d:"M0 0h24v24H0z",fill:"none"},null,-1),e.createElementVNode("path",{d:"M18 3a3 3 0 0 1 2.995 2.824l.005 .176v12a3 3 0 0 1 -2.824 2.995l-.176 .005h-12a3 3 0 0 1 -2.995 -2.824l-.005 -.176v-12a3 3 0 0 1 2.824 -2.995l.176 -.005h12zm-3 2h-9a1 1 0 0 0 -.993 .883l-.007 .117v12a1 1 0 0 0 .883 .993l.117 .007h9v-14zm-5.387 4.21l.094 .083l2 2a1 1 0 0 1 .083 1.32l-.083 .094l-2 2a1 1 0 0 1 -1.497 -1.32l.083 -.094l1.292 -1.293l-1.292 -1.293a1 1 0 0 1 -.083 -1.32l.083 -.094a1 1 0 0 1 1.32 -.083z"},null,-1)])])}const Se=S(Lt,[["render",zt]]),At={},Ht={xmlns:"http://www.w3.org/2000/svg",width:"24",height:"24",viewBox:"0 0 24 24",fill:"currentColor",class:"baklava-icon icon icon-tabler icons-tabler-filled icon-tabler-layout-sidebar-right-expand"};function Ut(o,t){return e.openBlock(),e.createElementBlock("svg",Ht,[...t[0]||(t[0]=[e.createElementVNode("path",{stroke:"none",d:"M0 0h24v24H0z",fill:"none"},null,-1),e.createElementVNode("path",{d:"M18 3a3 3 0 0 1 2.995 2.824l.005 .176v12a3 3 0 0 1 -2.824 2.995l-.176 .005h-12a3 3 0 0 1 -2.995 -2.824l-.005 -.176v-12a3 3 0 0 1 2.824 -2.995l.176 -.005h12zm-3 2h-9a1 1 0 0 0 -.993 .883l-.007 .117v12a1 1 0 0 0 .883 .993l.117 .007h9v-14zm-3.293 4.293a1 1 0 0 1 .083 1.32l-.083 .094l-1.292 1.293l1.292 1.293a1 1 0 0 1 .083 1.32l-.083 .094a1 1 0 0 1 -1.32 .083l-.094 -.083l-2 -2a1 1 0 0 1 -.083 -1.32l.083 -.094l2 -2a1 1 0 0 1 1.414 0z"},null,-1)])])}const Me=S(At,[["render",Ut]]),Ft={},Wt={xmlns:"http://www.w3.org/2000/svg",width:"24",height:"24",viewBox:"0 0 24 24",fill:"none",stroke:"currentColor","stroke-width":"2","stroke-linecap":"round","stroke-linejoin":"round",class:"baklava-icon icon icon-tabler icons-tabler-outline icon-tabler-lock-code"};function qt(o,t){return e.openBlock(),e.createElementBlock("svg",Wt,[...t[0]||(t[0]=[e.createStaticVNode('<path stroke="none" d="M0 0h24v24H0z" fill="none"></path><path d="M11.5 21h-4.5a2 2 0 0 1 -2 -2v-6a2 2 0 0 1 2 -2h10a2 2 0 0 1 2 2"></path><path d="M11 16a1 1 0 1 0 2 0a1 1 0 0 0 -2 0"></path><path d="M8 11v-4a4 4 0 1 1 8 0v4"></path><path d="M20 21l2 -2l-2 -2"></path><path d="M17 17l-2 2l2 2"></path>',6)])])}const Ve=S(Ft,[["render",qt]]),Yt={},Kt={xmlns:"http://www.w3.org/2000/svg",width:"24",height:"24",viewBox:"0 0 24 24",fill:"none",stroke:"currentColor","stroke-width":"2","stroke-linecap":"round","stroke-linejoin":"round",class:"baklava-icon icon icon-tabler icons-tabler-outline icon-tabler-player-play"};function Xt(o,t){return e.openBlock(),e.createElementBlock("svg",Kt,[...t[0]||(t[0]=[e.createElementVNode("path",{stroke:"none",d:"M0 0h24v24H0z",fill:"none"},null,-1),e.createElementVNode("path",{d:"M7 4v16l13 -8z"},null,-1)])])}const Ge=S(Yt,[["render",Xt]]),Jt={},Qt={xmlns:"http://www.w3.org/2000/svg",width:"24",height:"24",viewBox:"0 0 24 24",fill:"none",stroke:"currentColor","stroke-width":"2","stroke-linecap":"round","stroke-linejoin":"round",class:"baklava-icon icon icon-tabler icons-tabler-outline icon-tabler-schema"};function Zt(o,t){return e.openBlock(),e.createElementBlock("svg",Qt,[...t[0]||(t[0]=[e.createStaticVNode('<path stroke="none" d="M0 0h24v24H0z" fill="none"></path><path d="M5 2h5v4h-5z"></path><path d="M15 10h5v4h-5z"></path><path d="M5 18h5v4h-5z"></path><path d="M5 10h5v4h-5z"></path><path d="M10 12h5"></path><path d="M7.5 6v4"></path><path d="M7.5 14v4"></path>',8)])])}const $e=S(Jt,[["render",Zt]]),en={},tn={xmlns:"http://www.w3.org/2000/svg",width:"24",height:"24",viewBox:"0 0 24 24",fill:"none",stroke:"currentColor","stroke-width":"2","stroke-linecap":"round","stroke-linejoin":"round",class:"baklava-icon icon icon-tabler icons-tabler-outline icon-tabler-schema-off"};function nn(o,t){return e.openBlock(),e.createElementBlock("svg",tn,[...t[0]||(t[0]=[e.createStaticVNode('<path stroke="none" d="M0 0h24v24H0z" fill="none"></path><path d="M6 2h4v4m-4 0h-1v-1"></path><path d="M15 11v-1h5v4h-2"></path><path d="M5 18h5v4h-5z"></path><path d="M5 10h5v4h-5z"></path><path d="M10 12h2"></path><path d="M7.5 7.5v2.5"></path><path d="M7.5 14v4"></path><path d="M3 3l18 18"></path>',9)])])}const Re=S(en,[["render",nn]]),on={},sn={xmlns:"http://www.w3.org/2000/svg",width:"24",height:"24",viewBox:"0 0 24 24",fill:"none",stroke:"currentColor","stroke-width":"2","stroke-linecap":"round","stroke-linejoin":"round",class:"baklava-icon icon icon-tabler icons-tabler-outline icon-tabler-transition-bottom"};function an(o,t){return e.openBlock(),e.createElementBlock("svg",sn,[...t[0]||(t[0]=[e.createStaticVNode('<path stroke="none" d="M0 0h24v24H0z" fill="none"></path><path d="M21 18a3 3 0 0 1 -3 3h-12a3 3 0 0 1 -3 -3"></path><path d="M3 3m0 3a3 3 0 0 1 3 -3h12a3 3 0 0 1 3 3v0a3 3 0 0 1 -3 3h-12a3 3 0 0 1 -3 -3z"></path><path d="M12 9v8"></path><path d="M9 14l3 3l3 -3"></path>',5)])])}const je=S(on,[["render",an]]),rn={},ln={xmlns:"http://www.w3.org/2000/svg",width:"24",height:"24",viewBox:"0 0 24 24",fill:"none",stroke:"currentColor","stroke-width":"2","stroke-linecap":"round","stroke-linejoin":"round",class:"baklava-icon icon icon-tabler icons-tabler-outline icon-tabler-trash-off"};function dn(o,t){return e.openBlock(),e.createElementBlock("svg",ln,[...t[0]||(t[0]=[e.createStaticVNode('<path stroke="none" d="M0 0h24v24H0z" fill="none"></path><path d="M3 3l18 18"></path><path d="M4 7h3m4 0h9"></path><path d="M10 11l0 6"></path><path d="M14 14l0 3"></path><path d="M5 7l1 12a2 2 0 0 0 2 2h8a2 2 0 0 0 2 -2l.077 -.923"></path><path d="M18.384 14.373l.616 -7.373"></path><path d="M9 5v-1a1 1 0 0 1 1 -1h4a1 1 0 0 1 1 1v3"></path>',8)])])}const Pe=S(rn,[["render",dn]]),ae="CLEAR_ALL",ie="RUN_ENGINE",re="TOGGLE_MINIMAP",le="TOGGLE_PALETTE",Le=(o,t,n)=>{const s=n.zoomToFit.paddingLeft;t.registerCommand(le,{execute:()=>{n.palette.enabled=!n.palette.enabled,n.zoomToFit.paddingLeft=n.palette.enabled?s:50},canExecute:()=>!0}),t.registerCommand(ae,{execute:()=>o.value.clear(),canExecute:()=>o.value.nodes.length>0}),t.registerCommand(re,{execute:()=>n.enableMinimap=!n.enableMinimap,canExecute:()=>o.value.nodes.length>1})},De=o=>{const t={command:ie,title:"Run",icon:e.computed(()=>Ge)},n={command:le,title:"Toggle palette",icon:e.computed(()=>o.palette.enabled?Te:Oe)},s={command:ae,title:"Clear all",icon:e.computed(()=>Pe)},a={command:re,title:"Toggle minimap",icon:e.computed(()=>o.enableMinimap?Re:$e)};o.toolbar.commands=[n,t,...f.DEFAULT_TOOLBAR_COMMANDS,s,a]},ze=(o,t)=>{t.registerCommand(ie,{execute:()=>o.runOnce(null),canExecute:()=>!0})};function Ae(o){const t=Symbol("CodeEngineToken");o.engine=new Ee(o.editor),ze(o.engine,o.commandHandler),o.loadEditor=n=>{o.engine?.pause(),o.displayedGraph.clear(),o.editor.load(n),o.commandHandler.executeCommand(f.Commands.CLEAR_CLIPBOARD_COMMAND),o.commandHandler.executeCommand(f.Commands.CLEAR_HISTORY_COMMAND),o.engine?.resume(),o.engine?.runOnce(null)},o.newGraph=()=>{o.engine?.pause(),o.displayedGraph.clear(),o.commandHandler.executeCommand(f.Commands.CLEAR_CLIPBOARD_COMMAND),o.commandHandler.executeCommand(f.Commands.CLEAR_HISTORY_COMMAND),o.displayedGraph.id=j.v4(),o.engine?.resume(),o.engine?.runOnce(null)},o.subscribe=()=>{o.displayedGraph.events.addConnection.subscribe(t,n=>{const s=o.displayedGraph.findNodeById(n.to.nodeId);s&&s.isCodeNode&&s.onConnected();const a=o.displayedGraph.findNodeById(n.from.nodeId);a&&a.isCodeNode&&a.onConnected()}),o.displayedGraph.events.removeConnection.subscribe(t,n=>{const s=o.displayedGraph.findNodeById(n.to.nodeId);s&&s.isCodeNode&&s.onUnconnected();const a=o.displayedGraph.findNodeById(n.from.nodeId);a&&a.isCodeNode&&a.onUnconnected()}),o.engine?.events.beforeRun.subscribe(t,()=>{o.engine?.pause(),o.displayedGraph.sortNodes(),o.engine?.resume()}),o.engine?.events.afterRun.subscribe(t,n=>{o.engine?.pause(),R.applyResult(n,o.editor),o.editor.saveState(),o.code.state.lockCode||o.code.renderCode({nodes:o.editor.graph.scriptedCodeNodes,modules:o.editor.graph.modules}),o.engine?.resume()})},o.unsubscribe=()=>{o.displayedGraph.events.addConnection.unsubscribe(t),o.displayedGraph.events.removeConnection.unsubscribe(t),o.engine?.events.beforeRun.unsubscribe(t),o.engine?.events.afterRun.unsubscribe(t)}}class D extends O.Graph{code=null;editor;_state=e.reactive({codeTemplate:"{{ #nodes }}{{ script }}{{ /nodes }}",lockCode:!1});constructor(t,n){super(t,n),this.editor=t,this.template=n,t.code&&(this.code=t.code)}get codeNodes(){return de(this)}get connections(){return super.connections}set connections(t){this._connections=t}get nodeIds(){return this.nodes.map(t=>t.id)}get nodes(){return super.nodes}set nodes(t){this._nodes=t}get scriptedCodeNodes(){return this.nodes.filter(t=>!t.state?.integrated)}get shortId(){return this.id.slice(0,6)}get state(){return this._state}get visibleNodes(){return this.nodes.filter(t=>!t.state?.hidden)}addNodeAtCoordinates=(t,n={x:0,y:0},s)=>(this.addNode(t,s),t.position&&(t.position=n),t);addConnection(t,n){t?.name!=="_code"&&(t.hidden=!1),n?.name!=="_code"&&(n.hidden=!1),super.addConnection(t,n)}clear(){this.selectedNodes=[],this._nodes=[],this._connections=[]}findNodeByType(t){return this.nodes.find(n=>n.type===t)}getNodesBySameType(t){return this.nodes.filter(n=>n.type===t)}getNodesBySameVariableNames(t){return this.nodes.filter(n=>n.state?.variableName===t)}hasConnection(t,n){return this.connections.some(s=>s.from.id===t.id&&s.to.id===n.id)}renderCode(t){return $.render(this.state?.codeTemplate||"",t)}sortNodes(){if(!(this.nodes.length===0||this.connections.length===0))try{let t=this.nodeIds;const n=this.connections.filter(i=>t.includes(i.to.nodeId)&&t.includes(i.from.nodeId)).map(i=>[i.to.nodeId,i.from.nodeId]);t.reverse(),t=nt.array(t,n),t.reverse();const s=this.nodes.map(i=>i.id).filter(i=>!t.includes(i));t=[...t,...s];const a=t.map(i=>this.findNodeById(i));a&&(this.nodes=a)}catch{console.warn("Failed to sort nodes.")}}}const de=o=>{const t=[];return o.nodes.length===0||o.nodes.forEach(n=>{n&&(n.hasOwnProperty("subgraph")?t.push(...de(n.subgraph)):n.hasOwnProperty("isCodeNode")&&t.push(n))}),t},cn=(o=0,t=100)=>({x:o*420,y:t}),un=o=>{const t={...o.position};return t.x-=440,t.y+=50,t};function pn(o,t){return Object.fromEntries(Object.entries(o).filter(t))}function hn(o,t){return Object.fromEntries(Object.entries(o).map(([n,s])=>[n,t(s)]))}class z extends O.GraphTemplate{static fromGraph(t,n){return new z(t.save(),n)}constructor(t,n){super(t,n)}get shortId(){return this.id.slice(0,6)}createGraph(t){const n=new Map,s=h=>{const v=j.v4();return n.set(h,v),v},a=h=>{const v=n.get(h);if(!v)throw new Error(`Unable to create graph from template: Could not map old id ${h} to new id`);return v},i=h=>hn(h,v=>({id:s(v.id),templateId:v.id,value:v.value})),l=this.nodes.map(h=>({...h,id:s(h.id),inputs:i(h.inputs),outputs:i(h.outputs)})),d=this.connections.map(h=>({id:s(h.id),from:a(h.from),to:a(h.to)})),u=this.inputs.map(h=>({id:h.id,name:h.name,nodeId:a(h.nodeId),nodeInterfaceId:a(h.nodeInterfaceId)})),p=this.outputs.map(h=>({id:h.id,name:h.name,nodeId:a(h.nodeId),nodeInterfaceId:a(h.nodeInterfaceId)})),b={id:j.v4(),nodes:l,connections:d,inputs:u,outputs:p};return t||(t=new D(this.editor)),t.load(b).forEach(h=>console.warn(h)),t.template=this,t}}const mn=o=>!(o instanceof D);function He(o,t){return{switchGraph:s=>{let a;if(mn(s))a=new D(o.value),s.createGraph(a);else{if(s!==o.value.graph)throw new Error("Can only switch using 'Graph' instance when it is the root graph. Otherwise a 'GraphTemplate' must be used.");a=s}t.value&&t.value!==o.value.graph&&t.value.destroy(),a.panning=a.panning??s.panning??{x:0,y:0},a.scaling=a.scaling??s.scaling??1,a.selectedNodes=a.selectedNodes??[],a.sidebar=a.sidebar??{visible:!1,nodeId:"",optionName:""},t.value=a,a.code?.engine?.runOnce(null)}}}const fn=e.defineComponent({__name:"CodeGraphEditor",props:{viewModel:{}},setup(o){const t=o,n=e.toRef(t,"viewModel"),s=a=>a.events.update.emit(null);return e.onMounted(()=>{n.value.subscribe&&n.value.subscribe(),n.value.engine?.start()}),e.onBeforeUnmount(()=>{n.value.unsubscribe&&n.value.unsubscribe(),n.value.engine?.stop()}),e.watch(n,(a,i)=>{i&&i.unsubscribe(),a&&a.subscribe()}),(a,i)=>(e.openBlock(),e.createBlock(e.unref(f.BaklavaEditor),{viewModel:n.value},{palette:e.withCtx(()=>[e.createVNode(e.unref(Fe))]),node:e.withCtx(l=>[e.createVNode(e.unref(Ue),e.mergeProps(l,{onUpdate:d=>s(l.node)}),null,16,["onUpdate"])]),sidebar:e.withCtx(l=>[e.createVNode(e.unref(We),e.normalizeProps(e.guardReactiveProps(l)),{codeEditor:e.withCtx(({node:d})=>[e.renderSlot(a.$slots,"sidebarCodeEditor",{node:d})]),_:3},16)]),_:3},8,["viewModel"]))}}),gn={class:"code-graph-info"},bn=e.defineComponent({__name:"CodeGraphInfo",props:{viewModel:{}},setup(o){return(t,n)=>(e.openBlock(),e.createElementBlock("div",gn,[e.createElementVNode("div",null,"Editor graph: "+e.toDisplayString(o.viewModel.editor.graph.shortId),1),e.createElementVNode("div",null,"Displayed graph: "+e.toDisplayString(o.viewModel.displayedGraph.shortId),1),e.createElementVNode("div",null,"Graphs: "+e.toDisplayString(o.viewModel.editor.graphIds),1),e.createElementVNode("div",null,"Graph templates: "+e.toDisplayString(o.viewModel.editor.graphTemplateIds),1),e.createElementVNode("div",null,"Engine status: "+e.toDisplayString(o.viewModel.engine?.status),1)]))}}),kn=["id","data-node-type"],Cn={class:"__title-label",style:{"flex-grow":"1"}},yn={key:0},Nn={class:"__menu",style:{display:"flex"}},_n={class:"__outputs"},In={key:0},wn=["id","title"],En={class:"__inputs"},vn={key:0},Bn=["id","title"],Ue=e.defineComponent({__name:"CodeGraphNode",props:{node:{},selected:{type:Boolean,default:!1},dragging:{type:Boolean}},emits:["select","start-drag","update"],setup(o,{emit:t}){const n=f.Components.ContextMenu,s=f.Components.NodeInterface,a=o,i=e.computed(()=>a.node),l=t,{viewModel:d}=f.useViewModel(),{graph:u,switchGraph:p}=f.useGraph(),b=e.ref(null),C=e.ref(!1),h=e.ref(""),v=e.ref(null),k=e.ref(!1);let _=0,c=0;const m=e.ref(!1),w=e.computed(()=>{const N=[{value:"edit",label:"Edit"},{value:"rename",label:"Rename"},{value:"delete",label:"Delete"}];return a.node.type.startsWith(O.GRAPH_NODE_TYPE_PREFIX)&&N.push({value:"editSubgraph",label:"Edit Subgraph"}),N}),y=e.computed(()=>({"--selected":a.selected,"--dragging":a.dragging,"--two-column":!!a.node.twoColumn,"--hidden":i.value.state?.hidden})),B=e.computed(()=>({"--reverse-y":a.node.reverseY??d.value.settings.nodes.reverseY})),W=e.computed(()=>({top:`${a.node.position?.y??0}px`,left:`${a.node.position?.x??0}px`,"--width":`${a.node.width??d.value.settings.nodes.defaultWidth}px`})),P=e.computed(()=>Object.values(a.node.inputs).filter(N=>!N.hidden)),me=e.computed(()=>Object.values(a.node.outputs).filter(N=>!N.hidden)),q=()=>{l("select")},g=N=>{a.selected||q(),l("start-drag",N)},M=()=>{m.value=!0},G=()=>{const N=d.value.displayedGraph.sidebar;N.nodeId="",N.visible=!1},Xe=()=>{const N=d.value.displayedGraph.sidebar;N.nodeId=a.node.id,N.visible=!0},qn=()=>{const N=d.value.displayedGraph.sidebar;N.nodeId=a.node.id},Yn=async N=>{switch(N){case"edit":Xe();break;case"delete":u.value.removeNode(a.node);break;case"rename":h.value=a.node.title,C.value=!0,await e.nextTick(),v.value?.focus();break;case"editSubgraph":p(a.node.template);break}},Je=()=>{i.value.title=h.value,C.value=!1},Qe=()=>{b.value&&d.value.hooks.renderNode.execute({node:a.node,el:b.value})},Kn=N=>{k.value=!0,_=a.node.width,c=N.clientX,N.preventDefault()},Ze=N=>{i.value.state&&(i.value.state.integrated=N,l("update"))},et=N=>{if(!k.value)return;const T=N.clientX-c,E=_+T/u.value.scaling,Xn=d.value.settings.nodes.minWidth,Jn=d.value.settings.nodes.maxWidth;i.value.width=Math.max(Xn,Math.min(Jn,E))},tt=()=>{k.value=!1};return e.onMounted(()=>{Qe(),window.addEventListener("mousemove",et),window.addEventListener("mouseup",tt)}),e.onUpdated(Qe),e.onBeforeUnmount(()=>{window.removeEventListener("mousemove",et),window.removeEventListener("mouseup",tt)}),(N,T)=>(e.openBlock(),e.createElementBlock("div",{id:i.value.id,ref_key:"el",ref:b,class:e.normalizeClass([y.value,"baklava-node"]),"data-node-type":i.value.type,style:e.normalizeStyle(W.value),onPointerdown:q},[e.unref(d).settings.nodes.resizable?(e.openBlock(),e.createElementBlock("div",{key:0,class:"__resize-handle",onMousedown:Kn},null,32)):e.createCommentVNode("",!0),e.createElementVNode("div",{class:"__title",onPointerdown:e.withModifiers(g,["self","stop"]),onContextmenu:e.withModifiers(M,["prevent"])},[i.value.inputs._code?(e.openBlock(),e.createBlock(e.unref(ce),{key:0,node:i.value,intf:i.value.inputs._code,title:i.value.inputs._code.value,class:"--input","data-interface-type":"node",style:{"flex-grow":"0"}},null,8,["node","intf","title"])):e.createCommentVNode("",!0),C.value?e.withDirectives((e.openBlock(),e.createElementBlock("input",{key:2,ref_key:"renameInputEl",ref:v,"onUpdate:modelValue":T[4]||(T[4]=E=>h.value=E),class:"baklava-input",placeholder:"Node Name",style:{"flex-grow":"1"},type:"text",onBlur:Je,onKeydown:e.withKeys(Je,["enter"])},null,544)),[[e.vModelText,h.value]]):(e.openBlock(),e.createElementBlock(e.Fragment,{key:1},[e.createElementVNode("div",Cn,[i.value.idx>-1?(e.openBlock(),e.createElementBlock("span",yn,e.toDisplayString(i.value.idx+1)+" - ",1)):e.createCommentVNode("",!0),e.createTextVNode(e.toDisplayString(i.value.title)+" "+e.toDisplayString(i.value.graph.shortId)+" "+e.toDisplayString(i.value.shortId),1)]),e.createElementVNode("div",Nn,[i.value.isCodeNode?(e.openBlock(),e.createElementBlock(e.Fragment,{key:0},[i.value.state.lockCode?(e.openBlock(),e.createBlock(e.unref(Ve),{key:0,class:"--clickable mx-1",onClick:T[0]||(T[0]=E=>i.value.lockCode=!1)})):e.createCommentVNode("",!0),i.value.state.integrated?(e.openBlock(),e.createBlock(e.unref(ve),{key:1,class:"--clickable mx-1",onClick:T[1]||(T[1]=E=>Ze(!1))})):(e.openBlock(),e.createBlock(e.unref(je),{key:2,class:"--clickable mx-1",onClick:T[2]||(T[2]=E=>Ze(!0))})),!e.unref(d).displayedGraph.sidebar.visible&&e.unref(d).displayedGraph.sidebar.nodeId!==i.value.id?(e.openBlock(),e.createBlock(e.unref(Me),{key:3,class:"--clickable mx-1",onClick:Xe})):e.unref(d).displayedGraph.sidebar.visible&&e.unref(d).displayedGraph.sidebar.nodeId!==i.value.id?(e.openBlock(),e.createBlock(e.unref(xe),{key:4,class:"--clickable mx-1",onClick:qn})):(e.openBlock(),e.createBlock(e.unref(Se),{key:5,class:"--clickable mx-1",onClick:G}))],64)):e.createCommentVNode("",!0),e.createVNode(e.unref(Be),{class:"--clickable mx-1",onClick:M}),e.createVNode(e.unref(n),{modelValue:m.value,"onUpdate:modelValue":T[3]||(T[3]=E=>m.value=E),x:0,y:0,items:w.value,onClick:Yn},null,8,["modelValue","items"])])],64)),i.value.outputs._code?(e.openBlock(),e.createBlock(e.unref(ce),{key:3,node:i.value,intf:i.value.outputs._code,class:"--output",title:i.value.outputs._code.value,"data-interface-type":"node"},null,8,["node","intf","title"])):e.createCommentVNode("",!0)],32),e.createElementVNode("div",{class:e.normalizeClass(["__content",B.value]),onKeydown:T[5]||(T[5]=e.withKeys(e.withModifiers(()=>{},["stop"]),["delete"])),onContextmenu:T[6]||(T[6]=e.withModifiers(()=>{},["prevent"]))},[e.createElementVNode("div",_n,[(e.openBlock(!0),e.createElementBlock(e.Fragment,null,e.renderList(me.value,E=>(e.openBlock(),e.createElementBlock(e.Fragment,{key:E.id},[i.value.state?.hidden?(e.openBlock(),e.createElementBlock("div",In,[E.port?(e.openBlock(),e.createElementBlock("div",{key:0,id:E.id,title:E.name,class:"baklava-node-interface --output --connected"},[...T[7]||(T[7]=[e.createElementVNode("div",{class:"__port"},null,-1)])],8,wn)):e.createCommentVNode("",!0)])):e.renderSlot(N.$slots,"nodeInterface",{key:1,type:"output",node:i.value,intf:E},()=>[e.createVNode(e.unref(s),{node:i.value,intf:E,title:E.value},null,8,["node","intf","title"])])],64))),128))]),e.createElementVNode("div",En,[(e.openBlock(!0),e.createElementBlock(e.Fragment,null,e.renderList(P.value,E=>(e.openBlock(),e.createElementBlock(e.Fragment,{key:E.id},[i.value.state?.hidden?(e.openBlock(),e.createElementBlock("div",vn,[E.port?(e.openBlock(),e.createElementBlock("div",{key:0,id:E.id,title:E.name,class:"baklava-node-interface --input --connected"},[...T[8]||(T[8]=[e.createElementVNode("div",{class:"__port"},null,-1)])],8,Bn)):e.createCommentVNode("",!0)])):e.renderSlot(N.$slots,"nodeInterface",{key:1,node:i.value,intf:E,type:"input"},()=>[e.createVNode(e.unref(s),{node:i.value,intf:E,title:E.value},null,8,["node","intf","title"])])],64))),128))])],34)],46,kn))}}),Tn=["id"],On={class:"align-middle"},ce=e.defineComponent({__name:"CodeGraphNodeInterface",props:{node:{},intf:{}},setup(o){const t=o,{viewModel:n}=f.useViewModel(),{hoveredOver:s,temporaryConnection:a}=f.useTemporaryConnection(),i=e.ref(null),l=e.computed(()=>t.intf.connectionCount>0),d=e.computed(()=>({"--connected":l.value})),u=()=>{s(t.intf)},p=()=>{s(void 0)},b=()=>{i.value&&n.value.hooks.renderInterface.execute({intf:t.intf,el:i.value})};return e.onMounted(b),e.onUpdated(b),(C,h)=>(e.openBlock(),e.createElementBlock("div",{id:o.intf.id,ref_key:"el",ref:i,class:e.normalizeClass(["baklava-node-interface",d.value])},[o.intf.port?(e.openBlock(),e.createElementBlock("div",{key:0,class:e.normalizeClass(["__port",{"--selected":e.unref(a)?.from===o.intf}]),onPointerover:u,onPointerout:p},null,34)):e.createCommentVNode("",!0),e.createElementVNode("span",On,[e.renderSlot(C.$slots,"default")])],10,Tn))}}),xn={class:"baklava-node --palette",style:{"margin-top":"-20px","margin-bottom":"20px"}},Sn={key:0,style:{display:"flex","justify-content":"space-between"}},Mn=["onClick"],Vn={key:0,style:{margin:"auto 0","font-size":"12px"}},Fe=e.defineComponent({__name:"CodeNodePalette",setup(o){const t=f.Components.PaletteEntry,{viewModel:n}=f.useViewModel(),{x:s,y:a}=ot.usePointer(),{transform:i}=f.useTransform(),l=f.useNodeCategories(n),d=e.inject("editorEl"),u=e.ref(""),p=e.ref(null),b=()=>u.value?l.value.filter(k=>k.name.toLowerCase().includes(u.value.toLowerCase())||Object.values(k.nodeTypes).some(_=>_.title.toLowerCase().includes(u.value.toLowerCase()))):l.value,C=k=>u.value?pn(k,_=>{const c=_[1];return c.category.includes(u.value.toLowerCase())||c.title?.toLowerCase().includes(u.value.toLowerCase())}):k,h=e.computed(()=>{if(!p.value||!d?.value)return{};const{left:k,top:_}=d.value.getBoundingClientRect();return{top:`${a.value-_}px`,left:`${s.value-k}px`}}),v=(k,_)=>{p.value={type:k,nodeInformation:_};const c=()=>{const m=e.reactive(new _.type);n.value.displayedGraph.addNode(m);const w=d.value.getBoundingClientRect(),[y,B]=i(s.value-w.left,a.value-w.top);m.position.x=y,m.position.y=B,p.value=null,document.removeEventListener("pointerup",c)};document.addEventListener("pointerup",c)};return(k,_)=>(e.openBlock(),e.createElementBlock(e.Fragment,null,[e.createElementVNode("div",{class:e.normalizeClass([{"--open":e.unref(n).settings.palette.enabled},"baklava-node-palette"]),onContextmenu:_[1]||(_[1]=e.withModifiers(()=>{},["stop","prevent"]))},[e.createElementVNode("div",xn,[e.withDirectives(e.createElementVNode("input",{"onUpdate:modelValue":_[0]||(_[0]=c=>u.value=c),type:"text",class:"baklava-input",title:"Filter nodes",onKeyup:b},null,544),[[e.vModelText,u.value]])]),(e.openBlock(!0),e.createElementBlock(e.Fragment,null,e.renderList(b(),c=>(e.openBlock(),e.createElementBlock("section",{key:c.name},[c.name!=="default"?(e.openBlock(),e.createElementBlock("h3",Sn,[e.createElementVNode("div",{onClick:m=>u.value=c.name,style:{cursor:"pointer"}},e.toDisplayString(c.name),9,Mn),Object.keys(C(c.nodeTypes)).length<Object.values(c.nodeTypes).length?(e.openBlock(),e.createElementBlock("div",Vn," ( "+e.toDisplayString(Object.keys(C(c.nodeTypes)).length)+" / "+e.toDisplayString(Object.values(c.nodeTypes).length)+" ) ",1)):e.createCommentVNode("",!0)])):e.createCommentVNode("",!0),(e.openBlock(!0),e.createElementBlock(e.Fragment,null,e.renderList(C(c.nodeTypes),(m,w)=>(e.openBlock(),e.createBlock(e.unref(t),{key:w,type:w,title:m.title,onPointerdown:y=>v(w,m)},null,8,["type","title","onPointerdown"]))),128))]))),128))],34),e.createVNode(e.Transition,{name:"fade"},{default:e.withCtx(()=>[p.value?(e.openBlock(),e.createElementBlock("div",{key:0,class:"baklava-dragged-node",style:e.normalizeStyle(h.value)},[e.createVNode(e.unref(t),{type:p.value.type,title:p.value.nodeInformation.title},null,8,["type","title"])],4)):e.createCommentVNode("",!0)]),_:1})],64))}}),Gn=["title"],$n={key:0,class:"__label"},ue=e.defineComponent({__name:"SidebarCheckbox",props:{disabled:{type:Boolean},inversed:{type:Boolean},modelValue:{type:Boolean},name:{}},emits:["update:modelValue"],setup(o,{emit:t}){const n=t;return(s,a)=>(e.openBlock(),e.createElementBlock("div",{class:e.normalizeClass(["baklava-checkbox",{"--checked":o.inversed?!o.modelValue:o.modelValue,"--disabled":o.disabled}]),title:o.name,onClick:a[0]||(a[0]=i=>n("update:modelValue",!o.modelValue))},[a[1]||(a[1]=e.createElementVNode("div",{class:"__checkmark-container"},[e.createElementVNode("svg",{xmlns:"http://www.w3.org/2000/svg",width:"18",height:"18",viewBox:"0 0 18 18"},[e.createElementVNode("path",{class:"__checkmark",d:"M 6 5 L 6 10 L 16 10",transform:"rotate(-45 10 10)"})])],-1)),o.name?(e.openBlock(),e.createElementBlock("div",$n,e.toDisplayString(o.name),1)):e.createCommentVNode("",!0)],10,Gn))}}),Rn={class:"__header"},jn={class:"__node-name"},Pn={class:"__interfaces"},Ln={class:"__inputs"},Dn={style:{display:"flex"}},zn={class:"__outputs"},An={key:0,class:"__interface"},Hn={style:{display:"flex"}},We=e.defineComponent({__name:"CodeGraphSidebar",setup(o){const{viewModel:t}=f.useViewModel(),{graph:n}=f.useGraph(),s=e.ref(null),a=e.toRef(t.value.settings.sidebar,"width"),i=e.computed(()=>t.value.settings.sidebar.resizable);let l=0,d=0;const u=e.computed(()=>{const m=n.value.sidebar.nodeId;return n.value.nodes.find(w=>w.id===m)}),p=e.computed(()=>u.value),b=e.computed(()=>({width:`${a.value}px`})),C=e.computed(()=>p.value?Object.values(p.value.inputs).filter(m=>m.displayInSidebar&&m.component):[]),h=e.computed(()=>p.value?Object.values(p.value.outputs).filter(m=>m.displayInSidebar&&m.component):[]),v=()=>{n.value.sidebar.visible=!1},k=()=>{u.value?.events.update.emit(null)},_=m=>{l=a.value,d=m.clientX,window.addEventListener("mousemove",c),window.addEventListener("mouseup",()=>{window.removeEventListener("mousemove",c)},{once:!0})},c=m=>{const w=s.value?.parentElement?.getBoundingClientRect().width??500,y=m.clientX-d;let B=l-y;B<300?B=300:B>.9*w&&(B=.9*w),a.value=B};return(m,w)=>(e.openBlock(),e.createElementBlock("div",{class:e.normalizeClass([{"--open":e.unref(n).sidebar.visible},"baklava-sidebar"]),style:e.normalizeStyle(b.value),ref_key:"el",ref:s},[i.value?(e.openBlock(),e.createElementBlock("div",{key:0,class:"__resizer",onMousedown:_},null,32)):e.createCommentVNode("",!0),u.value?(e.openBlock(),e.createElementBlock(e.Fragment,{key:1},[e.createElementVNode("div",Rn,[e.createElementVNode("button",{tabindex:"-1",class:"__close",onClick:v},"×"),e.createElementVNode("div",jn,[e.createElementVNode("b",null,e.toDisplayString(u.value.title),1)])]),e.createElementVNode("div",Pn,[e.createElementVNode("div",Ln,[(e.openBlock(!0),e.createElementBlock(e.Fragment,null,e.renderList(C.value,y=>(e.openBlock(),e.createElementBlock("div",{key:y.id,class:"__interface"},[e.createElementVNode("div",Dn,[e.createVNode(ue,{modelValue:y.hidden,"onUpdate:modelValue":[B=>y.hidden=B,w[0]||(w[0]=()=>u.value?.events.update.emit(null))],disabled:!y.optional,inversed:"",style:{"padding-right":"8px"}},null,8,["modelValue","onUpdate:modelValue","disabled"]),(e.openBlock(),e.createBlock(e.resolveDynamicComponent(y.component),{modelValue:y.value,"onUpdate:modelValue":B=>y.value=B,node:u.value,intf:y,style:{width:"100%"}},null,8,["modelValue","onUpdate:modelValue","node","intf"]))])]))),128))]),e.createElementVNode("div",zn,[p.value&&p.value.state?(e.openBlock(),e.createElementBlock("div",An,[w[3]||(w[3]=e.createElementVNode("label",null,"Variable name",-1)),e.withDirectives(e.createElementVNode("input",{"onUpdate:modelValue":w[1]||(w[1]=y=>p.value.state.variableName=y),type:"text",class:"baklava-input",title:"Variable name",onBlur:k,onKeydown:e.withKeys(k,["enter"])},null,544),[[e.vModelText,p.value.state.variableName]])])):e.createCommentVNode("",!0),(e.openBlock(!0),e.createElementBlock(e.Fragment,null,e.renderList(h.value,y=>(e.openBlock(),e.createElementBlock("div",{key:y.id,class:"__interface"},[e.createElementVNode("div",Hn,[e.createVNode(ue,{modelValue:y.hidden,"onUpdate:modelValue":[B=>y.hidden=B,w[2]||(w[2]=()=>u.value?.events.update.emit(null))],disabled:!y.optional,inversed:"",style:{"padding-right":"8px"}},null,8,["modelValue","onUpdate:modelValue","disabled"]),(e.openBlock(),e.createBlock(e.resolveDynamicComponent(y.component),{modelValue:y.value,"onUpdate:modelValue":B=>y.value=B,node:u.value,intf:y,style:{width:"100%"}},null,8,["modelValue","onUpdate:modelValue","node","intf"]))])]))),128))])]),e.renderSlot(m.$slots,"codeEditor",{node:u.value})],64)):e.createCommentVNode("",!0)],6))}});class pe extends oe{_title="Subgraph Input";inputs={_code:new x("","").use(I.setType,V).setHidden(!0),name:new f.TextInputInterface("Name","Input").setPort(!1)};outputs={_code:new x("","").use(I.setType,V).setHidden(!0),placeholder:new O.NodeInterface("Connection",void 0)}}class he extends se{_title="Subgraph Output";inputs={_code:new x("","").use(I.setType,V).setHidden(!0),name:new f.TextInputInterface("Name","Output").setPort(!1),placeholder:new O.NodeInterface("Connection",void 0)};outputs={_code:new x("","").use(I.setType,V).setHidden(!0),output:new O.NodeInterface("Output",void 0).setHidden(!0)}}const qe="CREATE_SUBGRAPH",Ye=[O.GRAPH_INPUT_NODE_TYPE,O.GRAPH_OUTPUT_NODE_TYPE];function Ke(o,t,n){const s=()=>o.value.selectedNodes.filter(i=>!Ye.includes(i.type)).length>0,a=()=>{const{viewModel:i}=f.useViewModel(),l=o.value,d=o.value.editor;if(l.selectedNodes.length===0)return;const u=l.selectedNodes.filter(g=>!Ye.includes(g.type)),p=u.flatMap(g=>Object.values(g.inputs)),b=u.flatMap(g=>Object.values(g.outputs)),C=l.connections.filter(g=>!b.includes(g.from)&&p.includes(g.to)),h=l.connections.filter(g=>b.includes(g.from)&&!p.includes(g.to)),v=l.connections.filter(g=>b.includes(g.from)&&p.includes(g.to)),k=u.map(g=>g.save()),_=v.map(g=>({id:g.id,from:g.from.id,to:g.to.id})),c=new Map,{xLeft:m,xRight:w,yTop:y}=Un(u);for(const[g,M]of C.entries()){const G=new pe;G.inputs.name.value=M.to.name,k.push({...G.save(),position:{x:w-i.value.settings.nodes.defaultWidth-100,y:y+g*200}}),_.push({id:j.v4(),from:G.outputs.placeholder.id,to:M.to.id}),c.set(M.to.id,G.graphInterfaceId)}for(const[g,M]of h.entries()){const G=new he;G.inputs.name.value=M.from.name,k.push({...G.save(),position:{x:m+100,y:y+g*200}}),_.push({id:j.v4(),from:M.from.id,to:G.inputs.placeholder.id}),c.set(M.from.id,G.graphInterfaceId)}const B=e.reactive(new z({connections:_,nodes:k,inputs:[],outputs:[]},d));d.addGraphTemplate(B);const W=d.nodeTypes.get(O.getGraphNodeTypeString(B));if(!W)throw new Error("Unable to create subgraph: Could not find corresponding graph node type");l.activeTransactions++;const P=e.reactive(new W.type);l.addNode(P);const me=Math.round(u.map(g=>g.position.x).reduce((g,M)=>g+M,0)/u.length),q=Math.round(u.map(g=>g.position.y).reduce((g,M)=>g+M,0)/u.length);P.position.x=me,P.position.y=q,C.forEach(g=>{l.removeConnection(g),l.addConnection(g.from,P.inputs[c.get(g.to.id)])}),h.forEach(g=>{l.removeConnection(g),l.addConnection(P.outputs[c.get(g.from.id)],g.to)}),u.forEach(g=>l.removeNode(g)),l.activeTransactions--,t.canExecuteCommand(f.Commands.SAVE_SUBGRAPH_COMMAND)&&t.executeCommand(f.Commands.SAVE_SUBGRAPH_COMMAND),n(B),o.value.panning={...l.panning},o.value.scaling=l.scaling};t.registerCommand(qe,{canExecute:s,execute:a})}function Un(o){const t=o.reduce((a,i)=>{const l=i.position.x;return l<a?l:a},1/0),n=o.reduce((a,i)=>{const l=i.position.y;return l<a?l:a},1/0);return{xLeft:o.reduce((a,i)=>{const l=i.position.x+i.width;return l>a?l:a},-1/0),xRight:t,yTop:n}}class Fn extends O.Editor{code;graph;state;constructor(t){super(),this.code=t,this.graph=new D(this),this.code.registerGraph(this.graph),this.saveState()}get graphIds(){const t=[];return this.graphs.forEach(n=>t.push(n.id)),t.map(n=>n.slice(0,6)).join(", ")}get graphTemplateIds(){const t=[];return this.graphTemplates.forEach(n=>t.push(n.id)),t.map(n=>n.slice(0,6)).join(", ")}addGraphTemplate(t){if(this.events.beforeAddGraphTemplate.emit(t).prevented)return;this._graphTemplates.push(t),this.graphTemplateEvents.addTarget(t.events),this.graphTemplateHooks.addTarget(t.hooks);const n=Ie(t);this.registerNodeType(n,{category:"Subgraphs",title:t.name}),this.events.addGraphTemplate.emit(t)}load(t){try{for(super._loading=!0,t=this.hooks.load.execute(t);this.graphTemplates.length>0;)this.removeGraphTemplate(this.graphTemplates[0]);t.graphTemplates.forEach(s=>{const a=new z(s,this);this.addGraphTemplate(a)});const n=this.graph.load(t.graph);return this.events.loaded.emit(),n.forEach(s=>console.warn(s)),n}finally{super._loading=!1}}registerCategoryModule(t,n){this.code.state.modules[t]=n}saveState(){this.state=this.save()}}function Wn(o){const t=e.ref(o?.code??new we),n=e.ref(o?.existingEditor??new Fn(t.value)),s=Symbol("ViewModelToken"),a=e.ref(null),i=e.shallowReadonly(a),{switchGraph:l}=He(n,a),d=e.computed(()=>i.value&&i.value!==n.value.graph),u=e.reactive(f.DEFAULT_SETTINGS());u.nodes.defaultWidth=400;const p=f.useCommandHandler(),b=f.useHistory(i,p),C=f.useClipboard(i,n,p),h={renderNode:new fe.SequentialHook(null),renderInterface:new fe.SequentialHook(null)},v=e.reactive({clipboard:C,code:t,commandHandler:p,displayedGraph:i,editor:n,history:b,hooks:h,isSubgraph:d,settings:u,switchGraph:l});return Ae(v),f.registerDeleteNodesCommand(i,p),Ke(i,p,l),f.registerSaveSubgraphCommand(i,p),f.registerSwitchToMainGraphCommand(i,p,l),f.registerSidebarCommands(i,p),f.registerZoomToFitCommands(i,p,u),Le(i,p,u),De(u),e.watch(n,(k,_)=>{_&&(_.events.registerGraph.unsubscribe(s),_.graphEvents.beforeAddNode.unsubscribe(s),k.nodeHooks.beforeLoad.unsubscribe(s),k.nodeHooks.afterSave.unsubscribe(s),k.graphTemplateHooks.beforeLoad.unsubscribe(s),k.graphTemplateHooks.afterSave.unsubscribe(s),k.graph.hooks.load.unsubscribe(s),k.graph.hooks.save.unsubscribe(s)),k&&(k.nodeHooks.beforeLoad.subscribe(s,(c,m)=>(m.position=c.position??{x:0,y:0},m.width=c.width??u.nodes.defaultWidth,m.twoColumn=c.twoColumn??!1,c)),k.nodeHooks.afterSave.subscribe(s,(c,m)=>(c.position=m.position,c.width=m.width,c.twoColumn=m.twoColumn,c)),k.graphTemplateHooks.beforeLoad.subscribe(s,(c,m)=>(m.panning=c.panning,m.scaling=c.scaling,c)),k.graphTemplateHooks.afterSave.subscribe(s,(c,m)=>(c.panning=m.panning,c.scaling=m.scaling,c)),k.graph.hooks.load.subscribe(s,(c,m)=>(m.panning=c.panning,m.scaling=c.scaling,c)),k.graph.hooks.save.subscribe(s,(c,m)=>(c.panning=m.panning,c.scaling=m.scaling,c)),k.graphEvents.beforeAddNode.subscribe(s,c=>f.setViewNodeProperties(c,{defaultWidth:u.nodes.defaultWidth})),n.value.registerNodeType(pe,{category:"Subgraphs"}),n.value.registerNodeType(he,{category:"Subgraphs"}),l(k.graph))},{immediate:!0}),v}r.AbstractCodeNode=Y,r.CLEAR_ALL_COMMAND=ae,r.CREATE_SUBGRAPH_COMMAND=qe,r.CheckboxInterface=it,r.Code=we,r.CodeEngine=Ee,r.CodeGraph=D,r.CodeGraphEditor=fn,r.CodeGraphInfo=bn,r.CodeGraphInputNode=oe,r.CodeGraphNode=Ue,r.CodeGraphNodeInterface=ce,r.CodeGraphOutputNode=se,r.CodeGraphSidebar=We,r.CodeGraphTemplate=z,r.CodeNode=A,r.CodeNodeInputInterface=L,r.CodeNodeInterface=x,r.CodeNodeInterfaceComponent=H,r.CodeNodeOutputInterface=Ce,r.CodeNodePalette=Fe,r.CodeVariable=ve,r.DotsVertical=Be,r.DynamicCodeNode=Ne,r.GRAPH_INPUT_NODE_TYPE=te,r.GRAPH_OUTPUT_NODE_TYPE=ne,r.IntegerInterface=rt,r.LayoutSidebarLeftCollapse=Te,r.LayoutSidebarLeftExpand=Oe,r.LayoutSidebarRight=xe,r.LayoutSidebarRightCollapse=Se,r.LayoutSidebarRightExpand=Me,r.ListInputInterface=lt,r.LockCode=Ve,r.NumberInterface=dt,r.PlayerPlay=Ge,r.RUN_ENGINE_COMMAND=ie,r.Schema=$e,r.SchemaOff=Re,r.SelectInterface=ct,r.SidebarCheckbox=ue,r.SliderInterface=ut,r.SubgraphInputNode=pe,r.SubgraphOutputNode=he,r.TOGGLE_MINIMAP_COMMAND=re,r.TOGGLE_PALETTE_COMMAND=le,r.TextInputInterface=bt,r.TextInputInterfaceComponent=ye,r.TextareaInputInterface=kt,r.TransitionBottom=je,r.TrashOff=Pe,r.TupleInputInterface=Ct,r.addDefaultInterfaceTypes=at,r.allowMultipleConnections=It,r.booleanType=X,r.createCodeGraphNodeType=Ie,r.defineCodeNode=yt,r.defineDynamicCodeNode=Nt,r.dictType=ke,r.formatInputs=ge,r.getCodeNodes=de,r.getPositionAtColumn=cn,r.getPositionBeforeNode=un,r.listType=J,r.loadNodeState=K,r.nodeType=V,r.numberType=U,r.registerCodeEngine=Ae,r.registerCreateSubgraphCommand=Ke,r.registerCustomCommands=Le,r.registerRunEngineCommands=ze,r.saveNodeState=be,r.stringType=F,r.tupleType=Q,r.updateToolbarItems=De,r.useCodeGraph=Wn,r.useSwitchCodeGraph=He,Object.defineProperty(r,Symbol.toStringTag,{value:"Module"})}));
4
+ This is likely an internal issue. Please report it on GitHub.`);return t.get(n)}}const wt={},Et={xmlns:"http://www.w3.org/2000/svg",width:"24",height:"24",viewBox:"0 0 24 24",fill:"none",stroke:"currentColor","stroke-width":"2","stroke-linecap":"round","stroke-linejoin":"round",class:"baklava-icon icon icon-tabler icons-tabler-outline icon-tabler-code-variable"};function vt(o,t){return e.openBlock(),e.createElementBlock("svg",Et,[...t[0]||(t[0]=[e.createElementVNode("path",{stroke:"none",d:"M0 0h24v24H0z",fill:"none"},null,-1),e.createElementVNode("path",{d:"M4 8m0 2a2 2 0 0 1 2 -2h12a2 2 0 0 1 2 2v4a2 2 0 0 1 -2 2h-12a2 2 0 0 1 -2 -2z"},null,-1)])])}const ve=M(wt,[["render",vt]]),Bt={},Tt={xmlns:"http://www.w3.org/2000/svg",width:"24",height:"24",viewBox:"0 0 24 24",fill:"none",stroke:"currentColor","stroke-width":"2","stroke-linecap":"round","stroke-linejoin":"round",class:"baklava-icon icon icon-tabler icons-tabler-outline icon-tabler-dots-vertical"};function Ot(o,t){return e.openBlock(),e.createElementBlock("svg",Tt,[...t[0]||(t[0]=[e.createElementVNode("path",{stroke:"none",d:"M0 0h24v24H0z",fill:"none"},null,-1),e.createElementVNode("path",{d:"M12 12m-1 0a1 1 0 1 0 2 0a1 1 0 1 0 -2 0"},null,-1),e.createElementVNode("path",{d:"M12 19m-1 0a1 1 0 1 0 2 0a1 1 0 1 0 -2 0"},null,-1),e.createElementVNode("path",{d:"M12 5m-1 0a1 1 0 1 0 2 0a1 1 0 1 0 -2 0"},null,-1)])])}const Be=M(Bt,[["render",Ot]]),xt={},Mt={xmlns:"http://www.w3.org/2000/svg",width:"24",height:"24",viewBox:"0 0 24 24",fill:"currentColor",class:"baklava-icon icon icon-tabler icons-tabler-filled icon-tabler-layout-sidebar-left-collapse"};function St(o,t){return e.openBlock(),e.createElementBlock("svg",Mt,[...t[0]||(t[0]=[e.createElementVNode("path",{stroke:"none",d:"M0 0h24v24H0z",fill:"none"},null,-1),e.createElementVNode("path",{d:"M18 3a3 3 0 0 1 2.995 2.824l.005 .176v12a3 3 0 0 1 -2.824 2.995l-.176 .005h-12a3 3 0 0 1 -2.995 -2.824l-.005 -.176v-12a3 3 0 0 1 2.824 -2.995l.176 -.005h12zm0 2h-9v14h9a1 1 0 0 0 .993 -.883l.007 -.117v-12a1 1 0 0 0 -.883 -.993l-.117 -.007zm-2.293 4.293a1 1 0 0 1 .083 1.32l-.083 .094l-1.292 1.293l1.292 1.293a1 1 0 0 1 .083 1.32l-.083 .094a1 1 0 0 1 -1.32 .083l-.094 -.083l-2 -2a1 1 0 0 1 -.083 -1.32l.083 -.094l2 -2a1 1 0 0 1 1.414 0z"},null,-1)])])}const Te=M(xt,[["render",St]]),Vt={},$t={xmlns:"http://www.w3.org/2000/svg",width:"24",height:"24",viewBox:"0 0 24 24",fill:"currentColor",class:"baklava-icon icon icon-tabler icons-tabler-filled icon-tabler-layout-sidebar-left-expand"};function Gt(o,t){return e.openBlock(),e.createElementBlock("svg",$t,[...t[0]||(t[0]=[e.createElementVNode("path",{stroke:"none",d:"M0 0h24v24H0z",fill:"none"},null,-1),e.createElementVNode("path",{d:"M18 3a3 3 0 0 1 2.995 2.824l.005 .176v12a3 3 0 0 1 -2.824 2.995l-.176 .005h-12a3 3 0 0 1 -2.995 -2.824l-.005 -.176v-12a3 3 0 0 1 2.824 -2.995l.176 -.005h12zm0 2h-9v14h9a1 1 0 0 0 .993 -.883l.007 -.117v-12a1 1 0 0 0 -.883 -.993l-.117 -.007zm-4.387 4.21l.094 .083l2 2a1 1 0 0 1 .083 1.32l-.083 .094l-2 2a1 1 0 0 1 -1.497 -1.32l.083 -.094l1.292 -1.293l-1.292 -1.293a1 1 0 0 1 -.083 -1.32l.083 -.094a1 1 0 0 1 1.32 -.083z"},null,-1)])])}const Oe=M(Vt,[["render",Gt]]),Rt={},jt={xmlns:"http://www.w3.org/2000/svg",width:"24",height:"24",viewBox:"0 0 24 24",fill:"currentColor",class:"baklava-icon icon icon-tabler icons-tabler-filled icon-tabler-layout-sidebar-right"};function Pt(o,t){return e.openBlock(),e.createElementBlock("svg",jt,[...t[0]||(t[0]=[e.createElementVNode("path",{stroke:"none",d:"M0 0h24v24H0z",fill:"none"},null,-1),e.createElementVNode("path",{d:"M6 21a3 3 0 0 1 -3 -3v-12a3 3 0 0 1 3 -3h12a3 3 0 0 1 3 3v12a3 3 0 0 1 -3 3zm8 -16h-8a1 1 0 0 0 -1 1v12a1 1 0 0 0 1 1h8z"},null,-1)])])}const xe=M(Rt,[["render",Pt]]),Lt={},Dt={xmlns:"http://www.w3.org/2000/svg",width:"24",height:"24",viewBox:"0 0 24 24",fill:"currentColor",class:"baklava-icon icon icon-tabler icons-tabler-filled icon-tabler-layout-sidebar-right-collapse"};function zt(o,t){return e.openBlock(),e.createElementBlock("svg",Dt,[...t[0]||(t[0]=[e.createElementVNode("path",{stroke:"none",d:"M0 0h24v24H0z",fill:"none"},null,-1),e.createElementVNode("path",{d:"M18 3a3 3 0 0 1 2.995 2.824l.005 .176v12a3 3 0 0 1 -2.824 2.995l-.176 .005h-12a3 3 0 0 1 -2.995 -2.824l-.005 -.176v-12a3 3 0 0 1 2.824 -2.995l.176 -.005h12zm-3 2h-9a1 1 0 0 0 -.993 .883l-.007 .117v12a1 1 0 0 0 .883 .993l.117 .007h9v-14zm-5.387 4.21l.094 .083l2 2a1 1 0 0 1 .083 1.32l-.083 .094l-2 2a1 1 0 0 1 -1.497 -1.32l.083 -.094l1.292 -1.293l-1.292 -1.293a1 1 0 0 1 -.083 -1.32l.083 -.094a1 1 0 0 1 1.32 -.083z"},null,-1)])])}const Me=M(Lt,[["render",zt]]),At={},Ht={xmlns:"http://www.w3.org/2000/svg",width:"24",height:"24",viewBox:"0 0 24 24",fill:"currentColor",class:"baklava-icon icon icon-tabler icons-tabler-filled icon-tabler-layout-sidebar-right-expand"};function Ut(o,t){return e.openBlock(),e.createElementBlock("svg",Ht,[...t[0]||(t[0]=[e.createElementVNode("path",{stroke:"none",d:"M0 0h24v24H0z",fill:"none"},null,-1),e.createElementVNode("path",{d:"M18 3a3 3 0 0 1 2.995 2.824l.005 .176v12a3 3 0 0 1 -2.824 2.995l-.176 .005h-12a3 3 0 0 1 -2.995 -2.824l-.005 -.176v-12a3 3 0 0 1 2.824 -2.995l.176 -.005h12zm-3 2h-9a1 1 0 0 0 -.993 .883l-.007 .117v12a1 1 0 0 0 .883 .993l.117 .007h9v-14zm-3.293 4.293a1 1 0 0 1 .083 1.32l-.083 .094l-1.292 1.293l1.292 1.293a1 1 0 0 1 .083 1.32l-.083 .094a1 1 0 0 1 -1.32 .083l-.094 -.083l-2 -2a1 1 0 0 1 -.083 -1.32l.083 -.094l2 -2a1 1 0 0 1 1.414 0z"},null,-1)])])}const Se=M(At,[["render",Ut]]),Ft={},Wt={xmlns:"http://www.w3.org/2000/svg",width:"24",height:"24",viewBox:"0 0 24 24",fill:"none",stroke:"currentColor","stroke-width":"2","stroke-linecap":"round","stroke-linejoin":"round",class:"baklava-icon icon icon-tabler icons-tabler-outline icon-tabler-lock-code"};function qt(o,t){return e.openBlock(),e.createElementBlock("svg",Wt,[...t[0]||(t[0]=[e.createStaticVNode('<path stroke="none" d="M0 0h24v24H0z" fill="none"></path><path d="M11.5 21h-4.5a2 2 0 0 1 -2 -2v-6a2 2 0 0 1 2 -2h10a2 2 0 0 1 2 2"></path><path d="M11 16a1 1 0 1 0 2 0a1 1 0 0 0 -2 0"></path><path d="M8 11v-4a4 4 0 1 1 8 0v4"></path><path d="M20 21l2 -2l-2 -2"></path><path d="M17 17l-2 2l2 2"></path>',6)])])}const Ve=M(Ft,[["render",qt]]),Yt={},Kt={xmlns:"http://www.w3.org/2000/svg",width:"24",height:"24",viewBox:"0 0 24 24",fill:"none",stroke:"currentColor","stroke-width":"2","stroke-linecap":"round","stroke-linejoin":"round",class:"baklava-icon icon icon-tabler icons-tabler-outline icon-tabler-player-play"};function Xt(o,t){return e.openBlock(),e.createElementBlock("svg",Kt,[...t[0]||(t[0]=[e.createElementVNode("path",{stroke:"none",d:"M0 0h24v24H0z",fill:"none"},null,-1),e.createElementVNode("path",{d:"M7 4v16l13 -8z"},null,-1)])])}const $e=M(Yt,[["render",Xt]]),Jt={},Qt={xmlns:"http://www.w3.org/2000/svg",width:"24",height:"24",viewBox:"0 0 24 24",fill:"none",stroke:"currentColor","stroke-width":"2","stroke-linecap":"round","stroke-linejoin":"round",class:"baklava-icon icon icon-tabler icons-tabler-outline icon-tabler-schema"};function Zt(o,t){return e.openBlock(),e.createElementBlock("svg",Qt,[...t[0]||(t[0]=[e.createStaticVNode('<path stroke="none" d="M0 0h24v24H0z" fill="none"></path><path d="M5 2h5v4h-5z"></path><path d="M15 10h5v4h-5z"></path><path d="M5 18h5v4h-5z"></path><path d="M5 10h5v4h-5z"></path><path d="M10 12h5"></path><path d="M7.5 6v4"></path><path d="M7.5 14v4"></path>',8)])])}const Ge=M(Jt,[["render",Zt]]),en={},tn={xmlns:"http://www.w3.org/2000/svg",width:"24",height:"24",viewBox:"0 0 24 24",fill:"none",stroke:"currentColor","stroke-width":"2","stroke-linecap":"round","stroke-linejoin":"round",class:"baklava-icon icon icon-tabler icons-tabler-outline icon-tabler-schema-off"};function nn(o,t){return e.openBlock(),e.createElementBlock("svg",tn,[...t[0]||(t[0]=[e.createStaticVNode('<path stroke="none" d="M0 0h24v24H0z" fill="none"></path><path d="M6 2h4v4m-4 0h-1v-1"></path><path d="M15 11v-1h5v4h-2"></path><path d="M5 18h5v4h-5z"></path><path d="M5 10h5v4h-5z"></path><path d="M10 12h2"></path><path d="M7.5 7.5v2.5"></path><path d="M7.5 14v4"></path><path d="M3 3l18 18"></path>',9)])])}const Re=M(en,[["render",nn]]),on={},sn={xmlns:"http://www.w3.org/2000/svg",width:"24",height:"24",viewBox:"0 0 24 24",fill:"none",stroke:"currentColor","stroke-width":"2","stroke-linecap":"round","stroke-linejoin":"round",class:"baklava-icon icon icon-tabler icons-tabler-outline icon-tabler-transition-bottom"};function an(o,t){return e.openBlock(),e.createElementBlock("svg",sn,[...t[0]||(t[0]=[e.createStaticVNode('<path stroke="none" d="M0 0h24v24H0z" fill="none"></path><path d="M21 18a3 3 0 0 1 -3 3h-12a3 3 0 0 1 -3 -3"></path><path d="M3 3m0 3a3 3 0 0 1 3 -3h12a3 3 0 0 1 3 3v0a3 3 0 0 1 -3 3h-12a3 3 0 0 1 -3 -3z"></path><path d="M12 9v8"></path><path d="M9 14l3 3l3 -3"></path>',5)])])}const je=M(on,[["render",an]]),rn={},ln={xmlns:"http://www.w3.org/2000/svg",width:"24",height:"24",viewBox:"0 0 24 24",fill:"none",stroke:"currentColor","stroke-width":"2","stroke-linecap":"round","stroke-linejoin":"round",class:"baklava-icon icon icon-tabler icons-tabler-outline icon-tabler-trash-off"};function dn(o,t){return e.openBlock(),e.createElementBlock("svg",ln,[...t[0]||(t[0]=[e.createStaticVNode('<path stroke="none" d="M0 0h24v24H0z" fill="none"></path><path d="M3 3l18 18"></path><path d="M4 7h3m4 0h9"></path><path d="M10 11l0 6"></path><path d="M14 14l0 3"></path><path d="M5 7l1 12a2 2 0 0 0 2 2h8a2 2 0 0 0 2 -2l.077 -.923"></path><path d="M18.384 14.373l.616 -7.373"></path><path d="M9 5v-1a1 1 0 0 1 1 -1h4a1 1 0 0 1 1 1v3"></path>',8)])])}const Pe=M(rn,[["render",dn]]),ae="CLEAR_ALL",ie="RUN_ENGINE",re="TOGGLE_MINIMAP",le="TOGGLE_PALETTE",Le=(o,t,n)=>{const s=n.zoomToFit.paddingLeft;t.registerCommand(le,{execute:()=>{n.palette.enabled=!n.palette.enabled,n.zoomToFit.paddingLeft=n.palette.enabled?s:50},canExecute:()=>!0}),t.registerCommand(ae,{execute:()=>o.value.clear(),canExecute:()=>o.value.nodes.length>0}),t.registerCommand(re,{execute:()=>n.enableMinimap=!n.enableMinimap,canExecute:()=>o.value.nodes.length>1})},De=o=>{const t={command:ie,title:"Run",icon:e.computed(()=>$e)},n={command:le,title:"Toggle palette",icon:e.computed(()=>o.palette.enabled?Te:Oe)},s={command:ae,title:"Clear all",icon:e.computed(()=>Pe)},a={command:re,title:"Toggle minimap",icon:e.computed(()=>o.enableMinimap?Re:Ge)};o.toolbar.commands=[n,t,...f.DEFAULT_TOOLBAR_COMMANDS,s,a]},ze=(o,t)=>{t.registerCommand(ie,{execute:()=>o.runOnce(null),canExecute:()=>!0})};function Ae(o){const t=Symbol("CodeEngineToken");o.engine=new Ee(o.editor),ze(o.engine,o.commandHandler),o.loadEditor=n=>{o.engine?.pause(),o.displayedGraph.clear(),o.editor.load(n),o.commandHandler.executeCommand(f.Commands.CLEAR_CLIPBOARD_COMMAND),o.commandHandler.executeCommand(f.Commands.CLEAR_HISTORY_COMMAND),o.engine?.resume(),o.engine?.runOnce(null)},o.newGraph=()=>{o.engine?.pause(),o.displayedGraph.clear(),o.commandHandler.executeCommand(f.Commands.CLEAR_CLIPBOARD_COMMAND),o.commandHandler.executeCommand(f.Commands.CLEAR_HISTORY_COMMAND),o.displayedGraph.id=j.v4(),o.engine?.resume(),o.engine?.runOnce(null)},o.subscribe=()=>{o.displayedGraph.events.addConnection.subscribe(t,n=>{const s=o.displayedGraph.findNodeById(n.to.nodeId);s&&s.isCodeNode&&s.onConnected();const a=o.displayedGraph.findNodeById(n.from.nodeId);a&&a.isCodeNode&&a.onConnected()}),o.displayedGraph.events.removeConnection.subscribe(t,n=>{const s=o.displayedGraph.findNodeById(n.to.nodeId);s&&s.isCodeNode&&s.onUnconnected();const a=o.displayedGraph.findNodeById(n.from.nodeId);a&&a.isCodeNode&&a.onUnconnected()}),o.engine?.events.beforeRun.subscribe(t,()=>{o.engine?.pause(),o.displayedGraph.sortNodes(),o.engine?.resume()}),o.engine?.events.afterRun.subscribe(t,n=>{o.engine?.pause(),R.applyResult(n,o.editor),o.code.state.lockCode||o.code.renderCode({nodes:o.editor.graph.scriptedCodeNodes,modules:o.editor.code.modules}),o.engine?.resume()})},o.unsubscribe=()=>{o.displayedGraph.events.addConnection.unsubscribe(t),o.displayedGraph.events.removeConnection.unsubscribe(t),o.engine?.events.beforeRun.unsubscribe(t),o.engine?.events.afterRun.unsubscribe(t)}}class D extends O.Graph{code=null;editor;_state=e.reactive({codeTemplate:"{{ #nodes }}{{ script }}{{ /nodes }}",lockCode:!1});constructor(t,n){super(t,n),this.editor=t,this.template=n,t.code&&(this.code=t.code)}get codeNodes(){return de(this)}get connections(){return super.connections}set connections(t){this._connections=t}get nodeIds(){return this.nodes.map(t=>t.id)}get nodes(){return super.nodes}set nodes(t){this._nodes=t}get scriptedCodeNodes(){return this.nodes.filter(t=>!t.state?.integrated)}get shortId(){return this.id.slice(0,6)}get state(){return this._state}get visibleNodes(){return this.nodes.filter(t=>!t.state?.hidden)}addNodeAtCoordinates=(t,n={x:0,y:0},s)=>(this.addNode(t,s),t.position&&(t.position=n),t);addConnection(t,n){t?.name!=="_code"&&(t.hidden=!1),n?.name!=="_code"&&(n.hidden=!1),super.addConnection(t,n)}clear(){this.selectedNodes=[],this._nodes=[],this._connections=[]}findNodeByType(t){return this.nodes.find(n=>n.type===t)}getNodesBySameType(t){return this.nodes.filter(n=>n.type===t)}getNodesBySameVariableNames(t){return this.nodes.filter(n=>n.state?.variableName===t)}hasConnection(t,n){return this.connections.some(s=>s.from.id===t.id&&s.to.id===n.id)}renderCode(t){return G.render(this.state?.codeTemplate||"",t)}sortNodes(){if(!(this.nodes.length===0||this.connections.length===0))try{let t=this.nodeIds;const n=this.connections.filter(i=>t.includes(i.to.nodeId)&&t.includes(i.from.nodeId)).map(i=>[i.to.nodeId,i.from.nodeId]);t.reverse(),t=nt.array(t,n),t.reverse();const s=this.nodes.map(i=>i.id).filter(i=>!t.includes(i));t=[...t,...s];const a=t.map(i=>this.findNodeById(i));a&&(this.nodes=a)}catch{console.warn("Failed to sort nodes.")}}}const de=o=>{const t=[];return o.nodes.length===0||o.nodes.forEach(n=>{n&&(n.hasOwnProperty("subgraph")?t.push(...de(n.subgraph)):n.hasOwnProperty("isCodeNode")&&t.push(n))}),t},cn=(o=0,t=100)=>({x:o*420,y:t}),un=o=>{const t={...o.position};return t.x-=440,t.y+=50,t};function pn(o,t){return Object.fromEntries(Object.entries(o).filter(t))}function hn(o,t){return Object.fromEntries(Object.entries(o).map(([n,s])=>[n,t(s)]))}class z extends O.GraphTemplate{static fromGraph(t,n){return new z(t.save(),n)}constructor(t,n){super(t,n)}get shortId(){return this.id.slice(0,6)}createGraph(t){const n=new Map,s=h=>{const w=j.v4();return n.set(h,w),w},a=h=>{const w=n.get(h);if(!w)throw new Error(`Unable to create graph from template: Could not map old id ${h} to new id`);return w},i=h=>hn(h,w=>({id:s(w.id),templateId:w.id,value:w.value})),l=this.nodes.map(h=>({...h,id:s(h.id),inputs:i(h.inputs),outputs:i(h.outputs)})),d=this.connections.map(h=>({id:s(h.id),from:a(h.from),to:a(h.to)})),u=this.inputs.map(h=>({id:h.id,name:h.name,nodeId:a(h.nodeId),nodeInterfaceId:a(h.nodeInterfaceId)})),p=this.outputs.map(h=>({id:h.id,name:h.name,nodeId:a(h.nodeId),nodeInterfaceId:a(h.nodeInterfaceId)})),b={id:j.v4(),nodes:l,connections:d,inputs:u,outputs:p};return t||(t=new D(this.editor)),t.load(b).forEach(h=>console.warn(h)),t.template=this,t}}const mn=o=>!(o instanceof D);function He(o,t){return{switchGraph:s=>{let a;if(mn(s))a=new D(o.value),s.createGraph(a);else{if(s!==o.value.graph)throw new Error("Can only switch using 'Graph' instance when it is the root graph. Otherwise a 'GraphTemplate' must be used.");a=s}t.value&&t.value!==o.value.graph&&t.value.destroy(),a.panning=a.panning??s.panning??{x:0,y:0},a.scaling=a.scaling??s.scaling??1,a.selectedNodes=a.selectedNodes??[],a.sidebar=a.sidebar??{visible:!1,nodeId:"",optionName:""},t.value=a,a.code?.engine?.runOnce(null)}}}const fn=e.defineComponent({__name:"CodeGraphEditor",props:{viewModel:{}},setup(o){const t=o,n=e.toRef(t,"viewModel"),s=a=>a.events.update.emit(null);return e.onMounted(()=>{n.value.subscribe&&n.value.subscribe(),n.value.engine?.start()}),e.onBeforeUnmount(()=>{n.value.unsubscribe&&n.value.unsubscribe(),n.value.engine?.stop()}),e.watch(n,(a,i)=>{i&&i.unsubscribe(),a&&a.subscribe()}),(a,i)=>(e.openBlock(),e.createBlock(e.unref(f.BaklavaEditor),{viewModel:n.value},{palette:e.withCtx(()=>[e.createVNode(e.unref(Fe))]),node:e.withCtx(l=>[e.createVNode(e.unref(Ue),e.mergeProps(l,{onUpdate:d=>s(l.node)}),null,16,["onUpdate"])]),sidebar:e.withCtx(l=>[e.createVNode(e.unref(We),e.normalizeProps(e.guardReactiveProps(l)),{codeEditor:e.withCtx(({node:d})=>[e.renderSlot(a.$slots,"sidebarCodeEditor",{node:d})]),_:3},16)]),_:3},8,["viewModel"]))}}),gn={class:"code-graph-info"},bn=e.defineComponent({__name:"CodeGraphInfo",props:{viewModel:{}},setup(o){return(t,n)=>(e.openBlock(),e.createElementBlock("div",gn,[e.createElementVNode("div",null,"Editor graph: "+e.toDisplayString(o.viewModel.editor.graph.shortId),1),e.createElementVNode("div",null,"Displayed graph: "+e.toDisplayString(o.viewModel.displayedGraph.shortId),1),e.createElementVNode("div",null,"Graphs: "+e.toDisplayString(o.viewModel.editor.graphIds),1),e.createElementVNode("div",null,"Graph templates: "+e.toDisplayString(o.viewModel.editor.graphTemplateIds),1),e.createElementVNode("div",null,"Engine status: "+e.toDisplayString(o.viewModel.engine?.status),1)]))}}),kn=["id","data-node-type"],Cn={class:"__title-label",style:{"flex-grow":"1"}},yn={key:0},Nn={class:"__menu",style:{display:"flex"}},_n={class:"__outputs"},In={key:0},wn=["id","title"],En={class:"__inputs"},vn={key:0},Bn=["id","title"],Ue=e.defineComponent({__name:"CodeGraphNode",props:{node:{},selected:{type:Boolean,default:!1},dragging:{type:Boolean}},emits:["select","start-drag","update"],setup(o,{emit:t}){const n=f.Components.ContextMenu,s=f.Components.NodeInterface,a=o,i=e.computed(()=>a.node),l=t,{viewModel:d}=f.useViewModel(),{graph:u,switchGraph:p}=f.useGraph(),b=e.ref(null),C=e.ref(!1),h=e.ref(""),w=e.ref(null),k=e.ref(!1);let _=0,c=0;const m=e.ref(!1),E=e.computed(()=>{const N=[{value:"edit",label:"Edit"},{value:"rename",label:"Rename"},{value:"delete",label:"Delete"}];return a.node.type.startsWith(O.GRAPH_NODE_TYPE_PREFIX)&&N.push({value:"editSubgraph",label:"Edit Subgraph"}),N}),y=e.computed(()=>({"--selected":a.selected,"--dragging":a.dragging,"--two-column":!!a.node.twoColumn,"--hidden":i.value.state?.hidden})),B=e.computed(()=>({"--reverse-y":a.node.reverseY??d.value.settings.nodes.reverseY})),W=e.computed(()=>({top:`${a.node.position?.y??0}px`,left:`${a.node.position?.x??0}px`,"--width":`${a.node.width??d.value.settings.nodes.defaultWidth}px`})),P=e.computed(()=>Object.values(a.node.inputs).filter(N=>!N.hidden)),me=e.computed(()=>Object.values(a.node.outputs).filter(N=>!N.hidden)),q=()=>{l("select")},g=N=>{a.selected||q(),l("start-drag",N)},S=()=>{m.value=!0},$=()=>{const N=d.value.displayedGraph.sidebar;N.nodeId="",N.visible=!1},Xe=()=>{const N=d.value.displayedGraph.sidebar;N.nodeId=a.node.id,N.visible=!0},qn=()=>{const N=d.value.displayedGraph.sidebar;N.nodeId=a.node.id},Yn=async N=>{switch(N){case"edit":Xe();break;case"delete":u.value.removeNode(a.node);break;case"rename":h.value=a.node.title,C.value=!0,await e.nextTick(),w.value?.focus();break;case"editSubgraph":p(a.node.template);break}},Je=()=>{i.value.title=h.value,C.value=!1},Qe=()=>{b.value&&d.value.hooks.renderNode.execute({node:a.node,el:b.value})},Kn=N=>{k.value=!0,_=a.node.width,c=N.clientX,N.preventDefault()},Ze=N=>{i.value.state&&(i.value.state.integrated=N,l("update"))},et=N=>{if(!k.value)return;const T=N.clientX-c,v=_+T/u.value.scaling,Xn=d.value.settings.nodes.minWidth,Jn=d.value.settings.nodes.maxWidth;i.value.width=Math.max(Xn,Math.min(Jn,v))},tt=()=>{k.value=!1};return e.onMounted(()=>{Qe(),window.addEventListener("mousemove",et),window.addEventListener("mouseup",tt)}),e.onUpdated(Qe),e.onBeforeUnmount(()=>{window.removeEventListener("mousemove",et),window.removeEventListener("mouseup",tt)}),(N,T)=>(e.openBlock(),e.createElementBlock("div",{id:i.value.id,ref_key:"el",ref:b,class:e.normalizeClass([y.value,"baklava-node"]),"data-node-type":i.value.type,style:e.normalizeStyle(W.value),onPointerdown:q},[e.unref(d).settings.nodes.resizable?(e.openBlock(),e.createElementBlock("div",{key:0,class:"__resize-handle",onMousedown:Kn},null,32)):e.createCommentVNode("",!0),e.createElementVNode("div",{class:"__title",onPointerdown:e.withModifiers(g,["self","stop"]),onContextmenu:e.withModifiers(S,["prevent"])},[i.value.inputs._code?(e.openBlock(),e.createBlock(e.unref(ce),{key:0,node:i.value,intf:i.value.inputs._code,title:i.value.inputs._code.value,class:"--input","data-interface-type":"node",style:{"flex-grow":"0"}},null,8,["node","intf","title"])):e.createCommentVNode("",!0),C.value?e.withDirectives((e.openBlock(),e.createElementBlock("input",{key:2,ref_key:"renameInputEl",ref:w,"onUpdate:modelValue":T[4]||(T[4]=v=>h.value=v),class:"baklava-input",placeholder:"Node Name",style:{"flex-grow":"1"},type:"text",onBlur:Je,onKeydown:e.withKeys(Je,["enter"])},null,544)),[[e.vModelText,h.value]]):(e.openBlock(),e.createElementBlock(e.Fragment,{key:1},[e.createElementVNode("div",Cn,[i.value.idx>-1?(e.openBlock(),e.createElementBlock("span",yn,e.toDisplayString(i.value.idx+1)+" - ",1)):e.createCommentVNode("",!0),e.createTextVNode(e.toDisplayString(i.value.title)+" "+e.toDisplayString(i.value.graph.shortId)+" "+e.toDisplayString(i.value.shortId),1)]),e.createElementVNode("div",Nn,[i.value.isCodeNode?(e.openBlock(),e.createElementBlock(e.Fragment,{key:0},[i.value.state.lockCode?(e.openBlock(),e.createBlock(e.unref(Ve),{key:0,class:"--clickable mx-1",onClick:T[0]||(T[0]=v=>i.value.lockCode=!1)})):e.createCommentVNode("",!0),i.value.state.integrated?(e.openBlock(),e.createBlock(e.unref(ve),{key:1,class:"--clickable mx-1",onClick:T[1]||(T[1]=v=>Ze(!1))})):(e.openBlock(),e.createBlock(e.unref(je),{key:2,class:"--clickable mx-1",onClick:T[2]||(T[2]=v=>Ze(!0))})),!e.unref(d).displayedGraph.sidebar.visible&&e.unref(d).displayedGraph.sidebar.nodeId!==i.value.id?(e.openBlock(),e.createBlock(e.unref(Se),{key:3,class:"--clickable mx-1",onClick:Xe})):e.unref(d).displayedGraph.sidebar.visible&&e.unref(d).displayedGraph.sidebar.nodeId!==i.value.id?(e.openBlock(),e.createBlock(e.unref(xe),{key:4,class:"--clickable mx-1",onClick:qn})):(e.openBlock(),e.createBlock(e.unref(Me),{key:5,class:"--clickable mx-1",onClick:$}))],64)):e.createCommentVNode("",!0),e.createVNode(e.unref(Be),{class:"--clickable mx-1",onClick:S}),e.createVNode(e.unref(n),{modelValue:m.value,"onUpdate:modelValue":T[3]||(T[3]=v=>m.value=v),x:0,y:0,items:E.value,onClick:Yn},null,8,["modelValue","items"])])],64)),i.value.outputs._code?(e.openBlock(),e.createBlock(e.unref(ce),{key:3,node:i.value,intf:i.value.outputs._code,class:"--output",title:i.value.outputs._code.value,"data-interface-type":"node"},null,8,["node","intf","title"])):e.createCommentVNode("",!0)],32),e.createElementVNode("div",{class:e.normalizeClass(["__content",B.value]),onKeydown:T[5]||(T[5]=e.withKeys(e.withModifiers(()=>{},["stop"]),["delete"])),onContextmenu:T[6]||(T[6]=e.withModifiers(()=>{},["prevent"]))},[e.createElementVNode("div",_n,[(e.openBlock(!0),e.createElementBlock(e.Fragment,null,e.renderList(me.value,v=>(e.openBlock(),e.createElementBlock(e.Fragment,{key:v.id},[i.value.state?.hidden?(e.openBlock(),e.createElementBlock("div",In,[v.port?(e.openBlock(),e.createElementBlock("div",{key:0,id:v.id,title:v.name,class:"baklava-node-interface --output --connected"},[...T[7]||(T[7]=[e.createElementVNode("div",{class:"__port"},null,-1)])],8,wn)):e.createCommentVNode("",!0)])):e.renderSlot(N.$slots,"nodeInterface",{key:1,type:"output",node:i.value,intf:v},()=>[e.createVNode(e.unref(s),{node:i.value,intf:v,title:v.value},null,8,["node","intf","title"])])],64))),128))]),e.createElementVNode("div",En,[(e.openBlock(!0),e.createElementBlock(e.Fragment,null,e.renderList(P.value,v=>(e.openBlock(),e.createElementBlock(e.Fragment,{key:v.id},[i.value.state?.hidden?(e.openBlock(),e.createElementBlock("div",vn,[v.port?(e.openBlock(),e.createElementBlock("div",{key:0,id:v.id,title:v.name,class:"baklava-node-interface --input --connected"},[...T[8]||(T[8]=[e.createElementVNode("div",{class:"__port"},null,-1)])],8,Bn)):e.createCommentVNode("",!0)])):e.renderSlot(N.$slots,"nodeInterface",{key:1,node:i.value,intf:v,type:"input"},()=>[e.createVNode(e.unref(s),{node:i.value,intf:v,title:v.value},null,8,["node","intf","title"])])],64))),128))])],34)],46,kn))}}),Tn=["id"],On={class:"align-middle"},ce=e.defineComponent({__name:"CodeGraphNodeInterface",props:{node:{},intf:{}},setup(o){const t=o,{viewModel:n}=f.useViewModel(),{hoveredOver:s,temporaryConnection:a}=f.useTemporaryConnection(),i=e.ref(null),l=e.computed(()=>t.intf.connectionCount>0),d=e.computed(()=>({"--connected":l.value})),u=()=>{s(t.intf)},p=()=>{s(void 0)},b=()=>{i.value&&n.value.hooks.renderInterface.execute({intf:t.intf,el:i.value})};return e.onMounted(b),e.onUpdated(b),(C,h)=>(e.openBlock(),e.createElementBlock("div",{id:o.intf.id,ref_key:"el",ref:i,class:e.normalizeClass(["baklava-node-interface",d.value])},[o.intf.port?(e.openBlock(),e.createElementBlock("div",{key:0,class:e.normalizeClass(["__port",{"--selected":e.unref(a)?.from===o.intf}]),onPointerover:u,onPointerout:p},null,34)):e.createCommentVNode("",!0),e.createElementVNode("span",On,[e.renderSlot(C.$slots,"default")])],10,Tn))}}),xn={class:"baklava-node --palette",style:{"margin-top":"-20px","margin-bottom":"20px"}},Mn={key:0,style:{display:"flex","justify-content":"space-between"}},Sn=["onClick"],Vn={key:0,style:{margin:"auto 0","font-size":"12px"}},Fe=e.defineComponent({__name:"CodeNodePalette",setup(o){const t=f.Components.PaletteEntry,{viewModel:n}=f.useViewModel(),{x:s,y:a}=ot.usePointer(),{transform:i}=f.useTransform(),l=f.useNodeCategories(n),d=e.inject("editorEl"),u=e.ref(""),p=e.ref(null),b=()=>u.value?l.value.filter(k=>k.name.toLowerCase().includes(u.value.toLowerCase())||Object.values(k.nodeTypes).some(_=>_.title.toLowerCase().includes(u.value.toLowerCase()))):l.value,C=k=>u.value?pn(k,_=>{const c=_[1];return c.category.includes(u.value.toLowerCase())||c.title?.toLowerCase().includes(u.value.toLowerCase())}):k,h=e.computed(()=>{if(!p.value||!d?.value)return{};const{left:k,top:_}=d.value.getBoundingClientRect();return{top:`${a.value-_}px`,left:`${s.value-k}px`}}),w=(k,_)=>{p.value={type:k,nodeInformation:_};const c=()=>{const m=e.reactive(new _.type);n.value.displayedGraph.addNode(m);const E=d.value.getBoundingClientRect(),[y,B]=i(s.value-E.left,a.value-E.top);m.position.x=y,m.position.y=B,p.value=null,document.removeEventListener("pointerup",c)};document.addEventListener("pointerup",c)};return(k,_)=>(e.openBlock(),e.createElementBlock(e.Fragment,null,[e.createElementVNode("div",{class:e.normalizeClass([{"--open":e.unref(n).settings.palette.enabled},"baklava-node-palette"]),onContextmenu:_[1]||(_[1]=e.withModifiers(()=>{},["stop","prevent"]))},[e.createElementVNode("div",xn,[e.withDirectives(e.createElementVNode("input",{"onUpdate:modelValue":_[0]||(_[0]=c=>u.value=c),type:"text",class:"baklava-input",title:"Filter nodes",onKeyup:b},null,544),[[e.vModelText,u.value]])]),(e.openBlock(!0),e.createElementBlock(e.Fragment,null,e.renderList(b(),c=>(e.openBlock(),e.createElementBlock("section",{key:c.name},[c.name!=="default"?(e.openBlock(),e.createElementBlock("h3",Mn,[e.createElementVNode("div",{onClick:m=>u.value=c.name,style:{cursor:"pointer"}},e.toDisplayString(c.name),9,Sn),Object.keys(C(c.nodeTypes)).length<Object.values(c.nodeTypes).length?(e.openBlock(),e.createElementBlock("div",Vn," ( "+e.toDisplayString(Object.keys(C(c.nodeTypes)).length)+" / "+e.toDisplayString(Object.values(c.nodeTypes).length)+" ) ",1)):e.createCommentVNode("",!0)])):e.createCommentVNode("",!0),(e.openBlock(!0),e.createElementBlock(e.Fragment,null,e.renderList(C(c.nodeTypes),(m,E)=>(e.openBlock(),e.createBlock(e.unref(t),{key:E,type:E,title:m.title,onPointerdown:y=>w(E,m)},null,8,["type","title","onPointerdown"]))),128))]))),128))],34),e.createVNode(e.Transition,{name:"fade"},{default:e.withCtx(()=>[p.value?(e.openBlock(),e.createElementBlock("div",{key:0,class:"baklava-dragged-node",style:e.normalizeStyle(h.value)},[e.createVNode(e.unref(t),{type:p.value.type,title:p.value.nodeInformation.title},null,8,["type","title"])],4)):e.createCommentVNode("",!0)]),_:1})],64))}}),$n=["title"],Gn={key:0,class:"__label"},ue=e.defineComponent({__name:"SidebarCheckbox",props:{disabled:{type:Boolean},inversed:{type:Boolean},modelValue:{type:Boolean},name:{}},emits:["update:modelValue"],setup(o,{emit:t}){const n=t;return(s,a)=>(e.openBlock(),e.createElementBlock("div",{class:e.normalizeClass(["baklava-checkbox",{"--checked":o.inversed?!o.modelValue:o.modelValue,"--disabled":o.disabled}]),title:o.name,onClick:a[0]||(a[0]=i=>n("update:modelValue",!o.modelValue))},[a[1]||(a[1]=e.createElementVNode("div",{class:"__checkmark-container"},[e.createElementVNode("svg",{xmlns:"http://www.w3.org/2000/svg",width:"18",height:"18",viewBox:"0 0 18 18"},[e.createElementVNode("path",{class:"__checkmark",d:"M 6 5 L 6 10 L 16 10",transform:"rotate(-45 10 10)"})])],-1)),o.name?(e.openBlock(),e.createElementBlock("div",Gn,e.toDisplayString(o.name),1)):e.createCommentVNode("",!0)],10,$n))}}),Rn={class:"__header"},jn={class:"__node-name"},Pn={class:"__interfaces"},Ln={class:"__inputs"},Dn={style:{display:"flex"}},zn={class:"__outputs"},An={key:0,class:"__interface"},Hn={style:{display:"flex"}},We=e.defineComponent({__name:"CodeGraphSidebar",setup(o){const{viewModel:t}=f.useViewModel(),{graph:n}=f.useGraph(),s=e.ref(null),a=e.toRef(t.value.settings.sidebar,"width"),i=e.computed(()=>t.value.settings.sidebar.resizable);let l=0,d=0;const u=e.computed(()=>{const m=n.value.sidebar.nodeId;return n.value.nodes.find(E=>E.id===m)}),p=e.computed(()=>u.value),b=e.computed(()=>({width:`${a.value}px`})),C=e.computed(()=>p.value?Object.values(p.value.inputs).filter(m=>m.displayInSidebar&&m.component):[]),h=e.computed(()=>p.value?Object.values(p.value.outputs).filter(m=>m.displayInSidebar&&m.component):[]),w=()=>{n.value.sidebar.visible=!1},k=()=>{u.value?.events.update.emit(null)},_=m=>{l=a.value,d=m.clientX,window.addEventListener("mousemove",c),window.addEventListener("mouseup",()=>{window.removeEventListener("mousemove",c)},{once:!0})},c=m=>{const E=s.value?.parentElement?.getBoundingClientRect().width??500,y=m.clientX-d;let B=l-y;B<300?B=300:B>.9*E&&(B=.9*E),a.value=B};return(m,E)=>(e.openBlock(),e.createElementBlock("div",{class:e.normalizeClass([{"--open":e.unref(n).sidebar.visible},"baklava-sidebar"]),style:e.normalizeStyle(b.value),ref_key:"el",ref:s},[i.value?(e.openBlock(),e.createElementBlock("div",{key:0,class:"__resizer",onMousedown:_},null,32)):e.createCommentVNode("",!0),u.value?(e.openBlock(),e.createElementBlock(e.Fragment,{key:1},[e.createElementVNode("div",Rn,[e.createElementVNode("button",{tabindex:"-1",class:"__close",onClick:w},"×"),e.createElementVNode("div",jn,[e.createElementVNode("b",null,e.toDisplayString(u.value.title),1)])]),e.createElementVNode("div",Pn,[e.createElementVNode("div",Ln,[(e.openBlock(!0),e.createElementBlock(e.Fragment,null,e.renderList(C.value,y=>(e.openBlock(),e.createElementBlock("div",{key:y.id,class:"__interface"},[e.createElementVNode("div",Dn,[e.createVNode(ue,{modelValue:y.hidden,"onUpdate:modelValue":[B=>y.hidden=B,E[0]||(E[0]=()=>u.value?.events.update.emit(null))],disabled:!y.optional,inversed:"",style:{"padding-right":"8px"}},null,8,["modelValue","onUpdate:modelValue","disabled"]),(e.openBlock(),e.createBlock(e.resolveDynamicComponent(y.component),{modelValue:y.value,"onUpdate:modelValue":B=>y.value=B,node:u.value,intf:y,style:{width:"100%"}},null,8,["modelValue","onUpdate:modelValue","node","intf"]))])]))),128))]),e.createElementVNode("div",zn,[p.value&&p.value.state?(e.openBlock(),e.createElementBlock("div",An,[E[3]||(E[3]=e.createElementVNode("label",null,"Variable name",-1)),e.withDirectives(e.createElementVNode("input",{"onUpdate:modelValue":E[1]||(E[1]=y=>p.value.state.variableName=y),type:"text",class:"baklava-input",title:"Variable name",onBlur:k,onKeydown:e.withKeys(k,["enter"])},null,544),[[e.vModelText,p.value.state.variableName]])])):e.createCommentVNode("",!0),(e.openBlock(!0),e.createElementBlock(e.Fragment,null,e.renderList(h.value,y=>(e.openBlock(),e.createElementBlock("div",{key:y.id,class:"__interface"},[e.createElementVNode("div",Hn,[e.createVNode(ue,{modelValue:y.hidden,"onUpdate:modelValue":[B=>y.hidden=B,E[2]||(E[2]=()=>u.value?.events.update.emit(null))],disabled:!y.optional,inversed:"",style:{"padding-right":"8px"}},null,8,["modelValue","onUpdate:modelValue","disabled"]),(e.openBlock(),e.createBlock(e.resolveDynamicComponent(y.component),{modelValue:y.value,"onUpdate:modelValue":B=>y.value=B,node:u.value,intf:y,style:{width:"100%"}},null,8,["modelValue","onUpdate:modelValue","node","intf"]))])]))),128))])]),e.renderSlot(m.$slots,"codeEditor",{node:u.value})],64)):e.createCommentVNode("",!0)],6))}});class pe extends oe{_title="Subgraph Input";inputs={_code:new x("","").use(I.setType,V).setHidden(!0),name:new f.TextInputInterface("Name","Input").setPort(!1)};outputs={_code:new x("","").use(I.setType,V).setHidden(!0),placeholder:new O.NodeInterface("Connection",void 0)}}class he extends se{_title="Subgraph Output";inputs={_code:new x("","").use(I.setType,V).setHidden(!0),name:new f.TextInputInterface("Name","Output").setPort(!1),placeholder:new O.NodeInterface("Connection",void 0)};outputs={_code:new x("","").use(I.setType,V).setHidden(!0),output:new O.NodeInterface("Output",void 0).setHidden(!0)}}const qe="CREATE_SUBGRAPH",Ye=[O.GRAPH_INPUT_NODE_TYPE,O.GRAPH_OUTPUT_NODE_TYPE];function Ke(o,t,n){const s=()=>o.value.selectedNodes.filter(i=>!Ye.includes(i.type)).length>0,a=()=>{const{viewModel:i}=f.useViewModel(),l=o.value,d=o.value.editor;if(l.selectedNodes.length===0)return;const u=l.selectedNodes.filter(g=>!Ye.includes(g.type)),p=u.flatMap(g=>Object.values(g.inputs)),b=u.flatMap(g=>Object.values(g.outputs)),C=l.connections.filter(g=>!b.includes(g.from)&&p.includes(g.to)),h=l.connections.filter(g=>b.includes(g.from)&&!p.includes(g.to)),w=l.connections.filter(g=>b.includes(g.from)&&p.includes(g.to)),k=u.map(g=>g.save()),_=w.map(g=>({id:g.id,from:g.from.id,to:g.to.id})),c=new Map,{xLeft:m,xRight:E,yTop:y}=Un(u);for(const[g,S]of C.entries()){const $=new pe;$.inputs.name.value=S.to.name,k.push({...$.save(),position:{x:E-i.value.settings.nodes.defaultWidth-100,y:y+g*200}}),_.push({id:j.v4(),from:$.outputs.placeholder.id,to:S.to.id}),c.set(S.to.id,$.graphInterfaceId)}for(const[g,S]of h.entries()){const $=new he;$.inputs.name.value=S.from.name,k.push({...$.save(),position:{x:m+100,y:y+g*200}}),_.push({id:j.v4(),from:S.from.id,to:$.inputs.placeholder.id}),c.set(S.from.id,$.graphInterfaceId)}const B=e.reactive(new z({connections:_,nodes:k,inputs:[],outputs:[]},d));d.addGraphTemplate(B);const W=d.nodeTypes.get(O.getGraphNodeTypeString(B));if(!W)throw new Error("Unable to create subgraph: Could not find corresponding graph node type");l.activeTransactions++;const P=e.reactive(new W.type);l.addNode(P);const me=Math.round(u.map(g=>g.position.x).reduce((g,S)=>g+S,0)/u.length),q=Math.round(u.map(g=>g.position.y).reduce((g,S)=>g+S,0)/u.length);P.position.x=me,P.position.y=q,C.forEach(g=>{l.removeConnection(g),l.addConnection(g.from,P.inputs[c.get(g.to.id)])}),h.forEach(g=>{l.removeConnection(g),l.addConnection(P.outputs[c.get(g.from.id)],g.to)}),u.forEach(g=>l.removeNode(g)),l.activeTransactions--,t.canExecuteCommand(f.Commands.SAVE_SUBGRAPH_COMMAND)&&t.executeCommand(f.Commands.SAVE_SUBGRAPH_COMMAND),n(B),o.value.panning={...l.panning},o.value.scaling=l.scaling};t.registerCommand(qe,{canExecute:s,execute:a})}function Un(o){const t=o.reduce((a,i)=>{const l=i.position.x;return l<a?l:a},1/0),n=o.reduce((a,i)=>{const l=i.position.y;return l<a?l:a},1/0);return{xLeft:o.reduce((a,i)=>{const l=i.position.x+i.width;return l>a?l:a},-1/0),xRight:t,yTop:n}}class Fn extends O.Editor{code;graph;constructor(t){super(),this.code=t,this.graph=new D(this)}get graphIds(){const t=[];return this.graphs.forEach(n=>t.push(n.id)),t.map(n=>n.slice(0,6)).join(", ")}get graphTemplateIds(){const t=[];return this.graphTemplates.forEach(n=>t.push(n.id)),t.map(n=>n.slice(0,6)).join(", ")}addGraphTemplate(t){if(this.events.beforeAddGraphTemplate.emit(t).prevented)return;this._graphTemplates.push(t),this.graphTemplateEvents.addTarget(t.events),this.graphTemplateHooks.addTarget(t.hooks);const n=Ie(t);this.registerNodeType(n,{category:"Subgraphs",title:t.name}),this.events.addGraphTemplate.emit(t)}load(t){try{for(super._loading=!0,t=this.hooks.load.execute(t);this.graphTemplates.length>0;)this.removeGraphTemplate(this.graphTemplates[0]);t.graphTemplates.forEach(s=>{const a=new z(s,this);this.addGraphTemplate(a)});const n=this.graph.load(t.graph);return this.events.loaded.emit(),n.forEach(s=>console.warn(s)),n}finally{super._loading=!1}}registerCategoryModule(t,n){this.code.state.modules[t]=n}}function Wn(o){const t=e.ref(o?.code??new we),n=e.ref(o?.existingEditor??new Fn(t.value)),s=Symbol("ViewModelToken"),a=e.ref(null),i=e.shallowReadonly(a),{switchGraph:l}=He(n,a),d=e.computed(()=>i.value&&i.value!==n.value.graph),u=e.reactive(f.DEFAULT_SETTINGS());u.nodes.defaultWidth=400;const p=f.useCommandHandler(),b=f.useHistory(i,p),C=f.useClipboard(i,n,p),h={renderNode:new fe.SequentialHook(null),renderInterface:new fe.SequentialHook(null)},w=e.reactive({clipboard:C,code:t,commandHandler:p,displayedGraph:i,editor:n,history:b,hooks:h,isSubgraph:d,settings:u,switchGraph:l});return t.value.registerViewModel(w),Ae(w),f.registerDeleteNodesCommand(i,p),Ke(i,p,l),f.registerSaveSubgraphCommand(i,p),f.registerSwitchToMainGraphCommand(i,p,l),f.registerSidebarCommands(i,p),f.registerZoomToFitCommands(i,p,u),Le(i,p,u),De(u),e.watch(n,(k,_)=>{_&&(_.events.registerGraph.unsubscribe(s),_.graphEvents.beforeAddNode.unsubscribe(s),k.nodeHooks.beforeLoad.unsubscribe(s),k.nodeHooks.afterSave.unsubscribe(s),k.graphTemplateHooks.beforeLoad.unsubscribe(s),k.graphTemplateHooks.afterSave.unsubscribe(s),k.graph.hooks.load.unsubscribe(s),k.graph.hooks.save.unsubscribe(s)),k&&(k.nodeHooks.beforeLoad.subscribe(s,(c,m)=>(m.position=c.position??{x:0,y:0},m.width=c.width??u.nodes.defaultWidth,m.twoColumn=c.twoColumn??!1,c)),k.nodeHooks.afterSave.subscribe(s,(c,m)=>(c.position=m.position,c.width=m.width,c.twoColumn=m.twoColumn,c)),k.graphTemplateHooks.beforeLoad.subscribe(s,(c,m)=>(m.panning=c.panning,m.scaling=c.scaling,c)),k.graphTemplateHooks.afterSave.subscribe(s,(c,m)=>(c.panning=m.panning,c.scaling=m.scaling,c)),k.graph.hooks.load.subscribe(s,(c,m)=>(m.panning=c.panning,m.scaling=c.scaling,c)),k.graph.hooks.save.subscribe(s,(c,m)=>(c.panning=m.panning,c.scaling=m.scaling,c)),k.graphEvents.beforeAddNode.subscribe(s,c=>f.setViewNodeProperties(c,{defaultWidth:u.nodes.defaultWidth})),n.value.registerNodeType(pe,{category:"Subgraphs"}),n.value.registerNodeType(he,{category:"Subgraphs"}),l(k.graph))},{immediate:!0}),w}r.AbstractCodeNode=Y,r.CLEAR_ALL_COMMAND=ae,r.CREATE_SUBGRAPH_COMMAND=qe,r.CheckboxInterface=it,r.Code=we,r.CodeEngine=Ee,r.CodeGraph=D,r.CodeGraphEditor=fn,r.CodeGraphInfo=bn,r.CodeGraphInputNode=oe,r.CodeGraphNode=Ue,r.CodeGraphNodeInterface=ce,r.CodeGraphOutputNode=se,r.CodeGraphSidebar=We,r.CodeGraphTemplate=z,r.CodeNode=A,r.CodeNodeInputInterface=L,r.CodeNodeInterface=x,r.CodeNodeInterfaceComponent=H,r.CodeNodeOutputInterface=Ce,r.CodeNodePalette=Fe,r.CodeVariable=ve,r.DotsVertical=Be,r.DynamicCodeNode=Ne,r.GRAPH_INPUT_NODE_TYPE=te,r.GRAPH_OUTPUT_NODE_TYPE=ne,r.IntegerInterface=rt,r.LayoutSidebarLeftCollapse=Te,r.LayoutSidebarLeftExpand=Oe,r.LayoutSidebarRight=xe,r.LayoutSidebarRightCollapse=Me,r.LayoutSidebarRightExpand=Se,r.ListInputInterface=lt,r.LockCode=Ve,r.NumberInterface=dt,r.PlayerPlay=$e,r.RUN_ENGINE_COMMAND=ie,r.Schema=Ge,r.SchemaOff=Re,r.SelectInterface=ct,r.SidebarCheckbox=ue,r.SliderInterface=ut,r.SubgraphInputNode=pe,r.SubgraphOutputNode=he,r.TOGGLE_MINIMAP_COMMAND=re,r.TOGGLE_PALETTE_COMMAND=le,r.TextInputInterface=bt,r.TextInputInterfaceComponent=ye,r.TextareaInputInterface=kt,r.TransitionBottom=je,r.TrashOff=Pe,r.TupleInputInterface=Ct,r.addDefaultInterfaceTypes=at,r.allowMultipleConnections=It,r.booleanType=X,r.createCodeGraphNodeType=Ie,r.defineCodeNode=yt,r.defineDynamicCodeNode=Nt,r.dictType=ke,r.formatInputs=ge,r.getCodeNodes=de,r.getPositionAtColumn=cn,r.getPositionBeforeNode=un,r.listType=J,r.loadNodeState=K,r.nodeType=V,r.numberType=U,r.registerCodeEngine=Ae,r.registerCreateSubgraphCommand=Ke,r.registerCustomCommands=Le,r.registerRunEngineCommands=ze,r.saveNodeState=be,r.stringType=F,r.tupleType=Q,r.updateToolbarItems=De,r.useCodeGraph=Wn,r.useSwitchCodeGraph=He,Object.defineProperty(r,Symbol.toStringTag,{value:"Module"})}));
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@babsey/code-graph",
3
- "version": "0.3.0",
3
+ "version": "0.3.2",
4
4
  "author": "babsey <spreizer@web.de>",
5
5
  "license": "MIT",
6
6
  "type": "module",