@babsey/code-graph 0.1.3 → 0.1.4

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,11 +1,11 @@
1
- import { AbstractNode as We, sortTopologically as Ne, NodeInterface as Xe, displayInSidebar as Me, NodeInterfaceType as R, BaklavaInterfaceTypes as qe, CheckboxInterfaceComponent as Je, setType as S, IntegerInterfaceComponent as Ye, TextInputInterfaceComponent as $e, NumberInterfaceComponent as Qe, SelectInterfaceComponent as Ke, SliderInterfaceComponent as Ze, TextareaInputInterfaceComponent as et, allowMultipleConnections as K, IntegerInterface as tt, TextInputInterface as st, useViewModel as q, useTemporaryConnection as nt, Components as ke, useGraph as ae, GRAPH_NODE_TYPE_PREFIX as se, useTransform as ot, useNodeCategories as at, BaklavaEditor as it, DEFAULT_TOOLBAR_COMMANDS as rt, useBaklava as lt, DependencyEngine as dt, applyResult as ut } from "baklavajs";
2
1
  import Z from "mustache";
3
- import { reactive as P, defineComponent as U, createElementBlock as r, openBlock as i, toDisplayString as j, markRaw as E, computed as b, createElementVNode as l, withDirectives as ee, vModelText as te, ref as B, onMounted as ie, onUpdated as Oe, normalizeClass as G, createCommentVNode as I, unref as _, renderSlot as W, createStaticVNode as J, onBeforeUnmount as ct, normalizeStyle as re, withModifiers as A, createBlock as O, Fragment as T, createTextVNode as pt, createVNode as z, withKeys as ne, renderList as D, nextTick as ht, toRef as Te, resolveDynamicComponent as Ce, inject as vt, Transition as mt, withCtx as F, onUnmounted as ft, normalizeProps as gt, guardReactiveProps as bt, mergeProps as yt } from "vue";
4
- import _t from "toposort";
2
+ import We from "toposort";
3
+ import { AbstractNode as Xe, sortTopologically as Ne, NodeInterface as qe, displayInSidebar as Me, NodeInterfaceType as R, BaklavaInterfaceTypes as Je, CheckboxInterfaceComponent as Ye, setType as B, IntegerInterfaceComponent as Qe, TextInputInterfaceComponent as $e, NumberInterfaceComponent as Ke, SelectInterfaceComponent as Ze, SliderInterfaceComponent as et, TextareaInputInterfaceComponent as tt, allowMultipleConnections as K, IntegerInterface as st, TextInputInterface as nt, useViewModel as q, useTemporaryConnection as ot, Components as ke, useGraph as ae, GRAPH_NODE_TYPE_PREFIX as se, useTransform as at, useNodeCategories as it, BaklavaEditor as rt, useBaklava as lt, DependencyEngine as dt, applyResult as ut, DEFAULT_TOOLBAR_COMMANDS as ct } from "baklavajs";
4
+ import { reactive as P, defineComponent as U, createElementBlock as r, openBlock as i, toDisplayString as j, markRaw as E, computed as b, createElementVNode as l, withDirectives as ee, vModelText as te, ref as S, onMounted as ie, onUpdated as Oe, normalizeClass as G, createCommentVNode as I, unref as _, renderSlot as W, createStaticVNode as J, onBeforeUnmount as pt, normalizeStyle as re, withModifiers as A, createBlock as O, Fragment as T, createTextVNode as ht, createVNode as z, withKeys as ne, renderList as D, nextTick as vt, toRef as Te, resolveDynamicComponent as Ce, inject as mt, Transition as ft, withCtx as F, onUnmounted as gt, normalizeProps as bt, guardReactiveProps as yt, mergeProps as _t } from "vue";
5
5
  import { v4 as kt } from "uuid";
6
6
  import { usePointer as Ct } from "@vueuse/core";
7
7
  Z.escape = (s) => s;
8
- class wt extends We {
8
+ class wt extends Xe {
9
9
  state;
10
10
  code;
11
11
  isCodeNode = !0;
@@ -151,7 +151,7 @@ class wt extends We {
151
151
  * Reset script of input interfaces.
152
152
  */
153
153
  resetInputInterfaceScript() {
154
- Object.values(this.inputs).forEach((e) => e.state.script = "");
154
+ Object.values(this.codeNodeInputs).forEach((e) => e.resetScript());
155
155
  }
156
156
  updateCodeTemplate() {
157
157
  this.state.codeTemplate = this.codeTemplate.call(this);
@@ -239,7 +239,7 @@ const xt = (s, e = !0) => {
239
239
  }, j(s.intf.name), 9, Nt));
240
240
  }
241
241
  });
242
- class H extends Xe {
242
+ class H extends qe {
243
243
  isCodeNode = !0;
244
244
  code;
245
245
  state;
@@ -263,6 +263,7 @@ class H extends Xe {
263
263
  return this.id.slice(0, 6);
264
264
  }
265
265
  getValue = () => `${this.value ?? "None"}`;
266
+ resetScript = () => this.state.script = "";
266
267
  }
267
268
  const yn = (s, e) => {
268
269
  s.state.optional = e, s.setHidden(e);
@@ -285,12 +286,12 @@ class Y extends H {
285
286
  super.value = e, this.name !== "_node" && this.setHidden(!1);
286
287
  }
287
288
  }
288
- const Be = new R("boolean"), Mt = new R("dict"), Se = new R("list"), X = new R("node"), de = new R("number"), ue = new R("string"), ze = new R("tuple"), _n = (s) => {
289
- new qe(s.editor, { viewPlugin: s }).addTypes(Be, Mt, Se, X, de, ue, ze);
289
+ const Se = new R("boolean"), Mt = new R("dict"), Be = new R("list"), X = new R("node"), de = new R("number"), ue = new R("string"), ze = new R("tuple"), _n = (s) => {
290
+ new Je(s.editor, { viewPlugin: s }).addTypes(Se, Mt, Be, X, de, ue, ze);
290
291
  };
291
292
  class kn extends Y {
292
293
  constructor(e, t) {
293
- super(e, t), this.setComponent(E(Je)), this.use(S, Be);
294
+ super(e, t), this.setComponent(E(Ye)), this.use(B, Se);
294
295
  }
295
296
  getValue = () => this.value ? "True" : "False";
296
297
  }
@@ -307,42 +308,42 @@ class ce extends Y {
307
308
  min;
308
309
  max;
309
310
  constructor(e, t, n, o) {
310
- super(e, t), this.min = n, this.max = o, this.use(S, de);
311
+ super(e, t), this.min = n, this.max = o, this.use(B, de);
311
312
  }
312
313
  validate(e) {
313
314
  return (this.min === void 0 || e >= this.min) && (this.max === void 0 || e <= this.max);
314
315
  }
315
316
  }
316
317
  class Cn extends ce {
317
- component = E(Ye);
318
+ component = E(Qe);
318
319
  validate(e) {
319
320
  return Number.isInteger(e) && super.validate(e);
320
321
  }
321
322
  }
322
323
  class wn extends Y {
323
324
  constructor(e = "", t = "") {
324
- super(e, t), this.setComponent(E($e)), this.use(S, Se);
325
+ super(e, t), this.setComponent(E($e)), this.use(B, Be);
325
326
  }
326
327
  getValue = () => `[${this.value}]`;
327
328
  }
328
329
  class xn extends ce {
329
- component = E(Qe);
330
+ component = E(Ke);
330
331
  }
331
332
  class pe extends Y {
332
333
  constructor(e, t) {
333
- super(e, t), this.use(S, ue);
334
+ super(e, t), this.use(B, ue);
334
335
  }
335
336
  getValue = () => `"${this.value}"`;
336
337
  }
337
338
  class In extends pe {
338
- component = E(Ke);
339
+ component = E(Ze);
339
340
  items;
340
341
  constructor(e, t, n) {
341
342
  super(e, t), this.items = n;
342
343
  }
343
344
  }
344
345
  class Nn extends ce {
345
- component = E(Ze);
346
+ component = E(et);
346
347
  min;
347
348
  max;
348
349
  constructor(e, t, n, o) {
@@ -376,7 +377,7 @@ const Ot = U({
376
377
  t[n] = o;
377
378
  return t;
378
379
  }, Tt = { style: { position: "relative" } }, Et = { style: { "font-size": "12px", padding: "0 6px", position: "absolute", top: "-8px", "background-color": "var(--baklava-node-color-background)" } }, Vt = ["placeholder", "title"];
379
- function Bt(s, e, t, n, o, a) {
380
+ function St(s, e, t, n, o, a) {
380
381
  return i(), r("div", Tt, [
381
382
  l("label", Et, j(s.intf.name), 1),
382
383
  ee(l("input", {
@@ -390,16 +391,16 @@ function Bt(s, e, t, n, o, a) {
390
391
  ])
391
392
  ]);
392
393
  }
393
- const St = /* @__PURE__ */ $(Ot, [["render", Bt]]);
394
+ const Bt = /* @__PURE__ */ $(Ot, [["render", St]]);
394
395
  class Mn extends pe {
395
- component = E(St);
396
+ component = E(Bt);
396
397
  }
397
398
  class $n extends pe {
398
- component = E(et);
399
+ component = E(tt);
399
400
  }
400
401
  class On extends Y {
401
402
  constructor(e = "", t = "") {
402
- super(e, t), this.setComponent(E($e)), this.use(S, ze);
403
+ super(e, t), this.setComponent(E($e)), this.use(B, ze);
403
404
  }
404
405
  getValue = () => `(${this.value})`;
405
406
  }
@@ -411,10 +412,10 @@ function Tn(s) {
411
412
  constructor() {
412
413
  super(), this._title = s.title ?? s.type, this.name = s.name ?? s.type, this.updateModules(s.modules), s.variableName && (this.state.variableName = s.variableName), s.codeTemplate && (this.codeTemplate = s.codeTemplate), this.addInput(
413
414
  "_node",
414
- new H("", []).use(S, X).use(K).setHidden(!0)
415
+ new H("", []).use(B, X).use(K).setHidden(!0)
415
416
  ), this.addOutput(
416
417
  "_node",
417
- new H("", []).use(S, X).use(K).setHidden(!0)
418
+ new H("", []).use(B, X).use(K).setHidden(!0)
418
419
  ), this.executeFactory("input", s.inputs), this.executeFactory("output", s.outputs), s.onCreate?.call(this);
419
420
  }
420
421
  // public calculate = definition.calculate
@@ -468,10 +469,10 @@ function En(s) {
468
469
  constructor() {
469
470
  super(), this._title = s.title ?? s.type, this.name = s.name ?? s.type, this.updateModules(s.modules), s.codeTemplate && (this.codeTemplate = s.codeTemplate), s.variableName && (this.state.variableName = s.variableName), this.addInput(
470
471
  "_node",
471
- new H("", []).use(S, X).use(K).setHidden(!0)
472
+ new H("", []).use(B, X).use(K).setHidden(!0)
472
473
  ), this.addOutput(
473
474
  "_node",
474
- new H("", []).use(S, X).use(K).setHidden(!0)
475
+ new H("", []).use(B, X).use(K).setHidden(!0)
475
476
  ), this.staticInputKeys.push("_node"), this.staticOutputKeys.push("_node"), this.executeFactory("input", s.inputs), this.executeFactory("output", s.outputs), s.onCreate?.call(this);
476
477
  }
477
478
  onPlaced() {
@@ -503,7 +504,7 @@ function En(s) {
503
504
  if (!this.inputs[t]) {
504
505
  const n = e.inputs[t].value;
505
506
  let o;
506
- typeof n == "number" ? o = new tt(t, n).use(S, de) : o = new st(t, JSON.stringify(n)).use(S, ue), o.use(Me, !0), this.addInput(t, o);
507
+ typeof n == "number" ? o = new st(t, n).use(B, de) : o = new nt(t, JSON.stringify(n)).use(B, ue), o.use(Me, !0), this.addInput(t, o);
507
508
  }
508
509
  this.inputs[t] && (this.inputs[t].load(e.inputs[t]), this.inputs[t].nodeId = this.id);
509
510
  }
@@ -753,7 +754,7 @@ class jt {
753
754
  a.from.nodeId
754
755
  ]);
755
756
  let t = [...this.nodeIds];
756
- t.reverse(), t = _t.array(t, e), t.reverse();
757
+ t.reverse(), t = We.array(t, e), t.reverse();
757
758
  const n = this.graph.nodes.map((a) => a.id).filter((a) => !t.includes(a));
758
759
  t = t.concat(n);
759
760
  const o = t.map((a) => this.findNodeById(a));
@@ -783,10 +784,10 @@ const oe = (s) => {
783
784
  }, Vn = (s = 0, e = 100) => ({
784
785
  x: s * 420,
785
786
  y: e
786
- }), Bn = (s) => {
787
+ }), Sn = (s) => {
787
788
  const e = { ...s.position };
788
789
  return e.x -= 440, e.y += 50, e;
789
- }, Sn = (s) => {
790
+ }, Bn = (s) => {
790
791
  const { calculationOrder: e, connectionsFromNode: t } = Ne(s);
791
792
  e.forEach((n) => {
792
793
  if (!n.isCodeNode) return;
@@ -802,7 +803,7 @@ const oe = (s) => {
802
803
  intf: {}
803
804
  },
804
805
  setup(s) {
805
- const e = s, { viewModel: t } = q(), { hoveredOver: n, temporaryConnection: o } = nt(), a = B(null), d = b(() => e.intf.connectionCount > 0), u = b(() => ({
806
+ const e = s, { viewModel: t } = q(), { hoveredOver: n, temporaryConnection: o } = ot(), a = S(null), d = b(() => e.intf.connectionCount > 0), u = b(() => ({
806
807
  "--connected": d.value
807
808
  })), v = () => {
808
809
  n(e.intf);
@@ -1049,7 +1050,7 @@ function Es(s, e) {
1049
1050
  J('<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)
1050
1051
  ])]);
1051
1052
  }
1052
- const Vs = /* @__PURE__ */ $(Os, [["render", Es]]), Bs = ["id", "data-node-type"], Ss = {
1053
+ const Vs = /* @__PURE__ */ $(Os, [["render", Es]]), Ss = ["id", "data-node-type"], Bs = {
1053
1054
  class: "__title-label",
1054
1055
  style: { "flex-grow": "1" }
1055
1056
  }, zs = { key: 0 }, js = {
@@ -1064,9 +1065,9 @@ const Vs = /* @__PURE__ */ $(Os, [["render", Es]]), Bs = ["id", "data-node-type"
1064
1065
  },
1065
1066
  emits: ["select", "start-drag", "update"],
1066
1067
  setup(s, { emit: e }) {
1067
- const t = ke.ContextMenu, n = ke.NodeInterface, o = s, a = b(() => o.node), d = e, { viewModel: u } = q(), { graph: v, switchGraph: k } = ae(), w = B(null), V = B(!1), L = B(""), N = B(null), m = B(!1);
1068
+ const t = ke.ContextMenu, n = ke.NodeInterface, o = s, a = b(() => o.node), d = e, { viewModel: u } = q(), { graph: v, switchGraph: k } = ae(), w = S(null), V = S(!1), L = S(""), N = S(null), m = S(!1);
1068
1069
  let y = 0, x = 0;
1069
- const f = B(!1), C = b(() => {
1070
+ const f = S(!1), C = b(() => {
1070
1071
  const c = [
1071
1072
  { value: "edit", label: "Edit" },
1072
1073
  { value: "rename", label: "Rename" },
@@ -1108,7 +1109,7 @@ const Vs = /* @__PURE__ */ $(Os, [["render", Es]]), Bs = ["id", "data-node-type"
1108
1109
  v.value.removeNode(o.node);
1109
1110
  break;
1110
1111
  case "rename":
1111
- L.value = o.node.title, V.value = !0, await ht(), N.value?.focus();
1112
+ L.value = o.node.title, V.value = !0, await vt(), N.value?.focus();
1112
1113
  break;
1113
1114
  case "editSubgraph":
1114
1115
  k(o.node.template);
@@ -1131,7 +1132,7 @@ const Vs = /* @__PURE__ */ $(Os, [["render", Es]]), Bs = ["id", "data-node-type"
1131
1132
  };
1132
1133
  return ie(() => {
1133
1134
  ge(), window.addEventListener("mousemove", ye), window.addEventListener("mouseup", _e);
1134
- }), Oe(ge), ct(() => {
1135
+ }), Oe(ge), pt(() => {
1135
1136
  window.removeEventListener("mousemove", ye), window.removeEventListener("mouseup", _e);
1136
1137
  }), (c, g) => (i(), r("div", {
1137
1138
  id: a.value.id,
@@ -1174,9 +1175,9 @@ const Vs = /* @__PURE__ */ $(Os, [["render", Es]]), Bs = ["id", "data-node-type"
1174
1175
  }, null, 544)), [
1175
1176
  [te, L.value]
1176
1177
  ]) : (i(), r(T, { key: 1 }, [
1177
- l("div", Ss, [
1178
+ l("div", Bs, [
1178
1179
  a.value.idx > -1 ? (i(), r("span", zs, j(a.value.idx + 1) + " - ", 1)) : I("", !0),
1179
- pt(j(a.value.title), 1)
1180
+ ht(j(a.value.title), 1)
1180
1181
  ]),
1181
1182
  l("div", js, [
1182
1183
  a.value.subgraph ? I("", !0) : (i(), r(T, { key: 0 }, [
@@ -1292,7 +1293,7 @@ const Vs = /* @__PURE__ */ $(Os, [["render", Es]]), Bs = ["id", "data-node-type"
1292
1293
  ], 64))), 128))
1293
1294
  ])
1294
1295
  ], 34)
1295
- ], 46, Bs));
1296
+ ], 46, Ss));
1296
1297
  }
1297
1298
  }), As = ["title"], Fs = {
1298
1299
  key: 0,
@@ -1336,7 +1337,7 @@ const Vs = /* @__PURE__ */ $(Os, [["render", Es]]), Bs = ["id", "data-node-type"
1336
1337
  }, Zs = { style: { display: "flex" } }, en = /* @__PURE__ */ U({
1337
1338
  __name: "CodeGraphSidebar",
1338
1339
  setup(s) {
1339
- const { viewModel: e } = q(), { graph: t } = ae(), n = B(null), o = Te(e.value.settings.sidebar, "width"), a = b(() => e.value.settings.sidebar.resizable);
1340
+ const { viewModel: e } = q(), { graph: t } = ae(), n = S(null), o = Te(e.value.settings.sidebar, "width"), a = b(() => e.value.settings.sidebar.resizable);
1340
1341
  let d = 0, u = 0;
1341
1342
  const v = b(() => {
1342
1343
  const f = t.value.sidebar.nodeId;
@@ -1465,7 +1466,7 @@ const Vs = /* @__PURE__ */ $(Os, [["render", Es]]), Bs = ["id", "data-node-type"
1465
1466
  }
1466
1467
  },
1467
1468
  setup(s) {
1468
- const { viewModel: e } = q(), { switchGraph: t } = ae(), n = B(!1), o = b(() => s.type.startsWith(se));
1469
+ const { viewModel: e } = q(), { switchGraph: t } = ae(), n = S(!1), o = b(() => s.type.startsWith(se));
1469
1470
  return { showContextMenu: n, hasContextMenu: o, contextMenuItems: [
1470
1471
  { label: "Edit Subgraph", value: "editSubgraph" },
1471
1472
  { label: "Delete Subgraph", value: "deleteSubgraph" }
@@ -1507,7 +1508,7 @@ const Ie = /* @__PURE__ */ $(tn, [["render", an]]), rn = {
1507
1508
  }, cn = /* @__PURE__ */ U({
1508
1509
  __name: "CodeNodePalette",
1509
1510
  setup(s) {
1510
- const { viewModel: e } = q(), { x: t, y: n } = Ct(), { transform: o } = ot(), a = at(e), d = vt("editorEl"), u = B(""), v = B(null), k = () => u.value ? a.value.filter(
1511
+ const { viewModel: e } = q(), { x: t, y: n } = Ct(), { transform: o } = at(), a = it(e), d = mt("editorEl"), u = S(""), v = S(null), k = () => u.value ? a.value.filter(
1511
1512
  (N) => N.name.toLowerCase().includes(u.value.toLowerCase()) || Object.values(N.nodeTypes).some(
1512
1513
  (m) => m.title.toLowerCase().includes(u.value.toLowerCase())
1513
1514
  )
@@ -1568,7 +1569,7 @@ const Ie = /* @__PURE__ */ $(tn, [["render", an]]), rn = {
1568
1569
  }, null, 8, ["type", "title", "onPointerdown"]))), 128))
1569
1570
  ]))), 128))
1570
1571
  ], 34),
1571
- z(mt, { name: "fade" }, {
1572
+ z(ft, { name: "fade" }, {
1572
1573
  default: F(() => [
1573
1574
  v.value ? (i(), r("div", {
1574
1575
  key: 0,
@@ -1594,19 +1595,19 @@ const Ie = /* @__PURE__ */ $(tn, [["render", an]]), rn = {
1594
1595
  const t = Te(s, "viewModel"), n = (o) => o.events.update.emit(null);
1595
1596
  return ie(() => {
1596
1597
  t.value.subscribe(), t.value.engine.start();
1597
- }), ft(() => {
1598
+ }), gt(() => {
1598
1599
  t.value.unsubscribe(), t.value.engine.stop();
1599
- }), (o, a) => (i(), O(_(it), { "view-model": t.value }, {
1600
+ }), (o, a) => (i(), O(_(rt), { "view-model": t.value }, {
1600
1601
  palette: F(() => [
1601
1602
  z(cn)
1602
1603
  ]),
1603
1604
  node: F((d) => [
1604
- z(Hs, yt(d, {
1605
+ z(Hs, _t(d, {
1605
1606
  onUpdate: (u) => n(d.node)
1606
1607
  }), null, 16, ["onUpdate"])
1607
1608
  ]),
1608
1609
  sidebar: F((d) => [
1609
- z(en, gt(bt(d)), {
1610
+ z(en, bt(yt(d)), {
1610
1611
  codeEditor: F(({ node: u }) => [
1611
1612
  W(o.$slots, "sidebarCodeEditor", { node: u })
1612
1613
  ]),
@@ -1616,7 +1617,43 @@ const Ie = /* @__PURE__ */ $(tn, [["render", an]]), rn = {
1616
1617
  _: 3
1617
1618
  }, 8, ["view-model"]));
1618
1619
  }
1619
- }), pn = (s) => {
1620
+ });
1621
+ function jn(s) {
1622
+ const e = lt(s?.existingEditor);
1623
+ e.code = s?.code ? new s.code(e) : new jt(e), pn(e);
1624
+ const t = {};
1625
+ return Object.keys(Q).forEach((n) => {
1626
+ t[n] = typeof Q[n] == "object" ? { ...e.settings[n], ...Q[n] } : Q[n];
1627
+ }), e.settings = P({ ...e.settings, ...t }), e.settings.nodes.defaultWidth = 350, e.state = P({
1628
+ modules: {},
1629
+ token: null
1630
+ }), e.init = () => {
1631
+ e.unsubscribe(), e.engine = new dt(e.editor);
1632
+ }, e.subscribe = () => {
1633
+ e.state.token && e.unsubscribe();
1634
+ const n = Symbol(), o = e.displayedGraph;
1635
+ o.events.addNode.subscribe(n, (a) => {
1636
+ a.code = e.code;
1637
+ }), o.events.addConnection.subscribe(n, (a) => {
1638
+ e.code.findNodeById(a.to.nodeId)?.onConnected(), e.code.findNodeById(a.from.nodeId)?.onConnected();
1639
+ }), o.events.removeConnection.subscribe(n, (a) => {
1640
+ e.code.findNodeById(a.to.nodeId)?.onUnconnected(), e.code.findNodeById(a.from.nodeId)?.onUnconnected();
1641
+ }), e.engine.events.beforeRun.subscribe(n, () => {
1642
+ e.engine.pause(), e.code && (e.code.updateCodeNodes(), e.code.sortNodes(), e.code.updateCodeTemplates(), e.code.resetInputInterfaceScript()), e.engine.resume();
1643
+ }), e.engine.events.beforeNodeCalculation.subscribe(n, (a) => {
1644
+ e.engine.pause();
1645
+ const d = a.node;
1646
+ d.isCodeNode && (d.updateOutputNames(), d.updateConnectedInputInterfaces()), e.engine.resume();
1647
+ }), e.engine.events.afterRun.subscribe(n, (a) => {
1648
+ e.engine.pause(), ut(a, e.editor), e.code && (e.code.renderNodeCodes(), e.code.renderCode()), e.engine.resume();
1649
+ }), e.state.token = n;
1650
+ }, e.unsubscribe = () => {
1651
+ if (!e.state.token) return;
1652
+ const n = e.state.token;
1653
+ e.displayedGraph.events.addNode.unsubscribe(n), e.displayedGraph.events.addConnection.unsubscribe(n), e.engine.events.beforeRun.unsubscribe(n), e.engine.events.afterRun.unsubscribe(n), e.state.token = null;
1654
+ }, e;
1655
+ }
1656
+ const pn = (s) => {
1620
1657
  const e = "TOGGLE_PALETTE";
1621
1658
  s.commandHandler.registerCommand(e, {
1622
1659
  execute: () => s.settings.palette.enabled = !s.settings.palette.enabled,
@@ -1638,7 +1675,7 @@ const Ie = /* @__PURE__ */ $(tn, [["render", an]]), rn = {
1638
1675
  // Tooltip text
1639
1676
  icon: b(() => s.settings.palette.enabled ? Yt : es)
1640
1677
  },
1641
- ...rt,
1678
+ ...ct,
1642
1679
  {
1643
1680
  command: t,
1644
1681
  title: "Clear all",
@@ -1667,41 +1704,6 @@ const Ie = /* @__PURE__ */ $(tn, [["render", an]]), rn = {
1667
1704
  },
1668
1705
  displayValueOnHover: !1
1669
1706
  };
1670
- function jn(s) {
1671
- const e = lt(s?.existingEditor);
1672
- e.code = s?.code ? new s.code(e) : new jt(e), pn(e);
1673
- const t = {};
1674
- return Object.keys(Q).forEach((n) => {
1675
- t[n] = typeof Q[n] == "object" ? { ...e.settings[n], ...Q[n] } : Q[n];
1676
- }), e.settings = P({ ...e.settings, ...t }), e.settings.nodes.defaultWidth = 350, e.state = P({
1677
- modules: {},
1678
- token: null
1679
- }), e.init = () => {
1680
- e.unsubscribe(), e.engine = new dt(e.editor);
1681
- }, e.subscribe = () => {
1682
- e.state.token && e.unsubscribe();
1683
- const n = Symbol(), o = e.displayedGraph;
1684
- o.events.addNode.subscribe(n, (a) => {
1685
- a.code = e.code;
1686
- }), o.events.addConnection.subscribe(n, (a) => {
1687
- e.code.findNodeById(a.to.nodeId)?.onConnected(), e.code.findNodeById(a.from.nodeId)?.onConnected();
1688
- }), o.events.removeConnection.subscribe(n, (a) => {
1689
- e.code.findNodeById(a.to.nodeId)?.onUnconnected(), e.code.findNodeById(a.from.nodeId)?.onUnconnected();
1690
- }), e.engine.events.beforeRun.subscribe(n, () => {
1691
- e.engine.pause(), e.code && (e.code.updateCodeNodes(), e.code.sortNodes(), e.code.updateCodeTemplates(), e.code.resetInputInterfaceScript()), e.engine.resume();
1692
- }), e.engine.events.beforeNodeCalculation.subscribe(n, (a) => {
1693
- e.engine.pause();
1694
- const d = a.node;
1695
- d.isCodeNode && (d.updateOutputNames(), d.updateConnectedInputInterfaces()), e.engine.resume();
1696
- }), e.engine.events.afterRun.subscribe(n, (a) => {
1697
- e.engine.pause(), ut(a, e.editor), e.code && (e.code.renderNodeCodes(), e.code.renderCode()), e.engine.resume();
1698
- }), e.state.token = n;
1699
- }, e.unsubscribe = () => {
1700
- if (!e.state.token) return;
1701
- const n = e.state.token;
1702
- e.displayedGraph.events.addNode.unsubscribe(n), e.displayedGraph.events.addConnection.unsubscribe(n), e.engine.events.beforeRun.unsubscribe(n), e.engine.events.afterRun.unsubscribe(n), e.state.token = null;
1703
- }, e;
1704
- }
1705
1707
  export {
1706
1708
  wt as AbstractCodeNode,
1707
1709
  kn as CheckboxInterface,
@@ -1730,29 +1732,29 @@ export {
1730
1732
  In as SelectInterface,
1731
1733
  Nn as SliderInterface,
1732
1734
  Mn as TextInputInterface,
1733
- St as TextInputInterfaceComponent,
1735
+ Bt as TextInputInterfaceComponent,
1734
1736
  $n as TextareaInputInterface,
1735
1737
  $s as TransitionBottom,
1736
1738
  Vs as TrashOff,
1737
1739
  On as TupleInputInterface,
1738
1740
  _n as addDefaultInterfaceTypes,
1739
1741
  pn as addToolbarCommands,
1740
- Be as booleanType,
1742
+ Se as booleanType,
1741
1743
  Tn as defineCodeNode,
1742
1744
  En as defineDynamicCodeNode,
1743
1745
  Mt as dictType,
1744
1746
  xt as formatInputs,
1745
1747
  oe as getCodeNodes,
1746
1748
  Vn as getPositionAtColumn,
1747
- Bn as getPositionBeforeNode,
1748
- Se as listType,
1749
+ Sn as getPositionBeforeNode,
1750
+ Be as listType,
1749
1751
  Ve as loadNodeState,
1750
1752
  X as nodeType,
1751
1753
  de as numberType,
1752
1754
  It as saveNodeState,
1753
1755
  yn as setOptional,
1754
1756
  ue as stringType,
1755
- Sn as transferCodeScript,
1757
+ Bn as transferCodeScript,
1756
1758
  ze as tupleType,
1757
1759
  jn as useCodeGraph
1758
1760
  };
@@ -1 +1 @@
1
- (function(l,r){typeof exports=="object"&&typeof module<"u"?r(exports,require("baklavajs"),require("mustache"),require("vue"),require("toposort"),require("uuid"),require("@vueuse/core")):typeof define=="function"&&define.amd?define(["exports","baklavajs","mustache","vue","toposort","uuid","@vueuse/core"],r):(l=typeof globalThis<"u"?globalThis:l||self,r(l["@babsey/code-graph"]={},l.baklavajs,l.mustache,l.Vue,l.toposort,l.uuid,l["@vueuse/core"]))})(this,(function(l,r,O,e,Ce,we,Ie){"use strict";O.escape=o=>o;class A extends r.AbstractNode{state;code;isCodeNode=!0;name="";codeTemplate;inputs={};outputs={};constructor(){super(),this.initializeIo(),this.width=400,this.twoColumn=!0,this.state=e.reactive({codeTemplate:"",hidden:!1,integrated:!1,lockCode:!1,modules:[],props:null,script:"",variableName:""}),this.codeTemplate=function(){return`${this.name}(${W(this.codeNodeInputs).join(", ")})`}}get codeNodeInputs(){return Object.fromEntries(Object.entries(this.inputs).filter(t=>t[1].type!="node"))}get codeNodeOutputs(){return Object.fromEntries(Object.entries(this.outputs).filter(t=>t[1].type!="node"))}get idx(){return this.code?.codeNodes.filter(t=>!t.state.integrated).indexOf(this)??-1}get idxByVariableNames(){return this.code?.getNodesBySameVariableNames(this.state.variableName).indexOf(this)??-1}get lockCode(){return this.state.lockCode}set lockCode(t){this.state.lockCode=t,this.events.update.emit(null)}get optionalInputs(){return Object.fromEntries(Object.entries(this.codeNodeInputs).filter(t=>t[1].optional))}get requiredInputs(){return Object.fromEntries(Object.entries(this.codeNodeInputs).filter(t=>!t[1].optional))}get script(){return this.state.script}set script(t){this.state.script=t,this.events.update.emit(null)}get shortId(){return this.id.slice(0,6)}get subgraph(){}get variableName(){return this.state.variableName?this.state.variableName+(this.idxByVariableNames+1):""}getConnectedNodeByInterface(t,n){const s=this.getConnectedNodesByInterface(t,n);return s.length>0?s[0]:null}getConnectedNodes(t){let n=[];if(t!=="inputs"){const s=this.graph?.connections.filter(a=>a.from.name!=="_node").filter(a=>a.from.nodeId===this.id).map(a=>a.to.nodeId);s&&(n=n.concat(s))}if(t!=="outputs"){const s=this.graph?.connections.filter(a=>a.from.name!=="_node").filter(a=>a.to.nodeId===this.id).map(a=>a.from.nodeId);s&&(n=n.concat(s))}return!n||n.length==0?[]:n.map(s=>this.graph?.findNodeById(s))}getConnectedNodesByInterface(t,n){let s=[];if(n!=="outputs"&&this.inputs[t]){const a=this.graph?.connections.filter(i=>i.to.id===this.inputs[t]?.id||i.from.id===this.inputs[t]?.id).map(i=>i.from.nodeId);a&&(s=s.concat(a))}if(n!=="inputs"&&this.outputs[t]){const a=this.graph?.connections.filter(i=>i.from.id===this.outputs[t]?.id||i.from.id===this.outputs[t]?.id).map(i=>i.to.nodeId);a&&(s=s.concat(a))}return!s||s.length==0?[]:s.map(a=>this.graph?.findNodeById(a))}registerCode(t){this.code=t}renderCode(){if(!this.lockCode){const t={};Object.keys(this.inputs).forEach(s=>{if(s==="_node")return;const a=this.inputs[s];a&&a.state&&(t[s]=a.state.script.length>0?a.state.script:a.getValue())});const n={};Object.keys(this.outputs).forEach(s=>{if(s==="_node")return;const a=this.outputs[s];a&&a.state&&(n[s]=a.getValue())}),this.state.script=O.render(this.state.codeTemplate,{inputs:t,outputs:n})}this.outputs.out&&(this.outputs.out.state.script=this.script)}resetInputInterfaceScript(){Object.values(this.inputs).forEach(t=>t.state.script="")}updateCodeTemplate(){this.state.codeTemplate=this.codeTemplate.call(this)}updateConnectedInputInterfaces(){if(!this.graph)return;const{connectionsFromNode:t}=r.sortTopologically(this.graph);if(!t.has(this))return;const n=t.get(this);n&&n.forEach(s=>{if(!s.from.isCodeNode||!s.to.isCodeNode)return;const a=this.graph?.findNodeById(s.from.nodeId);a&&(a.renderCode(),s.to.script=s.from.script)})}updateOutputNames(){Object.values(this.codeNodeOutputs).forEach(t=>{t.name=this.state.integrated?"":this.variableName+t.value})}updateProps(t){this.state.props=t}}class R extends A{calculate;load(t){super.load(t),D(this.graph,t)}save(){const t=super.save();return X(this.graph,t),t}updateModules(t){if(t)this.state.modules=t;else if(this.type.includes(".")){const n=this.type.split(".");this.state.modules.push(n.slice(0,n.length-1).join("."))}}}const W=(o,t=!0)=>{const n=[],s=Object.keys(o);return s.forEach(a=>{if(o[a]?.hidden)return;const d=t&&n.length<s.indexOf(a)?`${a}=`:"";n.push(`${d}{{ inputs.${a} }}`)}),n},D=(o,t)=>{if(!o)return;const n=o.findNodeById(t.id);if(!n||n.subgraph)return;const s=n;s.state&&(s.state.integrated=t.integrated,s.state.modules=t.modules,s.state.props=t.props),Object.entries(t.inputs).forEach(([a,i])=>{a!=="_node"&&s.inputs[a]&&(s.inputs[a].hidden=i.hidden)}),Object.entries(t.outputs).forEach(([a,i])=>{a!=="_node"&&s.outputs[a]&&(s.outputs[a].hidden=i.hidden)})},X=(o,t)=>{if(!o)return;const n=o.findNodeById(t.id);if(!n||n.subgraph)return;const s=n;s.state&&(t.integrated=s.state.integrated,t.modules=s.state.modules),Object.entries(t.inputs).forEach(([a,i])=>{a!=="_node"&&s.inputs[a]&&(i.hidden=s.inputs[a].hidden)}),Object.entries(t.outputs).forEach(([a,i])=>{a!=="_node"&&s.outputs[a]&&(i.hidden=s.outputs[a].hidden)})},Ee=["title"],S=e.defineComponent({__name:"CodeNodeInterface",props:{intf:{}},setup(o){return(t,n)=>(e.openBlock(),e.createElementBlock("div",{title:o.intf.state?.script},e.toDisplayString(o.intf.name),9,Ee))}});class x extends r.NodeInterface{isCodeNode=!0;code;state;type=null;constructor(t,n){super(t,n),this.setComponent(e.markRaw(S)),this.state=e.reactive({optional:!1,script:""})}get optional(){return this.state.optional}get script(){return this.state.script}set script(t){this.state.script=t}get shortId(){return this.id.slice(0,6)}getValue=()=>`${this.value??"None"}`}const Be=(o,t)=>{o.state.optional=t,o.setHidden(t)};class M extends x{constructor(t="",n){super(t,n),this.setComponent(e.markRaw(S)),this.use(r.displayInSidebar,!0)}set script(t){if(this.state.script&&this.allowMultipleConnections){const n=this.state.script;n.startsWith("[")&&n.endsWith("]")?t=JSON.stringify([t,...JSON.parse(n)]):t=[t,n].join(", ")}this.state.script=t}get value(){return super.value}set value(t){super.value=t,this.name!=="_node"&&this.setHidden(!1)}}const U=new r.NodeInterfaceType("boolean"),q=new r.NodeInterfaceType("dict"),G=new r.NodeInterfaceType("list"),T=new r.NodeInterfaceType("node"),v=new r.NodeInterfaceType("number"),z=new r.NodeInterfaceType("string"),P=new r.NodeInterfaceType("tuple"),Ve=o=>{new r.BaklavaInterfaceTypes(o.editor,{viewPlugin:o}).addTypes(U,q,G,T,v,z,P)};class xe extends M{constructor(t,n){super(t,n),this.setComponent(e.markRaw(r.CheckboxInterfaceComponent)),this.use(r.setType,U)}getValue=()=>this.value?"True":"False"}class Y extends x{isCodeNodeOutput=!0;constructor(t="",n=""){super(t,n),this.setComponent(e.markRaw(S))}get script(){return this.name?this.name:this.state.script}}class F extends M{min;max;constructor(t,n,s,a){super(t,n),this.min=s,this.max=a,this.use(r.setType,v)}validate(t){return(this.min===void 0||t>=this.min)&&(this.max===void 0||t<=this.max)}}class Me extends F{component=e.markRaw(r.IntegerInterfaceComponent);validate(t){return Number.isInteger(t)&&super.validate(t)}}class Te extends M{constructor(t="",n=""){super(t,n),this.setComponent(e.markRaw(r.TextInputInterfaceComponent)),this.use(r.setType,G)}getValue=()=>`[${this.value}]`}class $e extends F{component=e.markRaw(r.NumberInterfaceComponent)}class H extends M{constructor(t,n){super(t,n),this.use(r.setType,z)}getValue=()=>`"${this.value}"`}class Oe extends H{component=e.markRaw(r.SelectInterfaceComponent);items;constructor(t,n,s){super(t,n),this.items=s}}class Se extends F{component=e.markRaw(r.SliderInterfaceComponent);min;max;constructor(t,n,s,a){super(t,n,s,a),this.min=s,this.max=a}getValue=()=>`${Math.round(this.value*1e3)/1e3}`}const ve=e.defineComponent({props:{intf:{type:Object,required:!0},modelValue:{type:String,required:!0}},emits:["update:modelValue"],setup(o,{emit:t}){return{v:e.computed({get:()=>o.modelValue,set:s=>{t("update:modelValue",s)}})}}}),E=(o,t)=>{const n=o.__vccOpts||o;for(const[s,a]of t)n[s]=a;return n},ze={style:{position:"relative"}},Le={style:{"font-size":"12px",padding:"0 6px",position:"absolute",top:"-8px","background-color":"var(--baklava-node-color-background)"}},Re=["placeholder","title"];function De(o,t,n,s,a,i){return e.openBlock(),e.createElementBlock("div",ze,[e.createElementVNode("label",Le,e.toDisplayString(o.intf.name),1),e.withDirectives(e.createElementVNode("input",{"onUpdate:modelValue":t[0]||(t[0]=d=>o.v=d),type:"text",class:"baklava-input",placeholder:o.intf.name,title:o.intf.name},null,8,Re),[[e.vModelText,o.v]])])}const J=E(ve,[["render",De]]);class Ue extends H{component=e.markRaw(J)}class Ge extends H{component=e.markRaw(r.TextareaInputInterfaceComponent)}class Pe extends M{constructor(t="",n=""){super(t,n),this.setComponent(e.markRaw(r.TextInputInterfaceComponent)),this.use(r.setType,P)}getValue=()=>`(${this.value})`}function Fe(o){return class extends R{type=o.type;inputs={};outputs={};constructor(){super(),this._title=o.title??o.type,this.name=o.name??o.type,this.updateModules(o.modules),o.variableName&&(this.state.variableName=o.variableName),o.codeTemplate&&(this.codeTemplate=o.codeTemplate),this.addInput("_node",new x("",[]).use(r.setType,T).use(r.allowMultipleConnections).setHidden(!0)),this.addOutput("_node",new x("",[]).use(r.setType,T).use(r.allowMultipleConnections).setHidden(!0)),this.executeFactory("input",o.inputs),this.executeFactory("output",o.outputs),o.onCreate?.call(this)}onPlaced(){o.onPlaced?.call(this)}onConnected(){o.onConnected?.call(this)}onDestroy(){o.onDestroy?.call(this)}onUnconnected(){o.onUnconnected?.call(this)}update(){o.update?.call(this)}executeFactory(t,n){Object.keys(n||{}).forEach(s=>{const a=n[s]();t==="input"?this.addInput(s,a):this.addOutput(s,a)})}}}class K extends R{calculate}function He(o){return class extends K{type=o.type;inputs={};outputs={};calculate;preventUpdate=!1;staticInputKeys=Object.keys(o.inputs??{});staticOutputKeys=Object.keys(o.outputs??{});constructor(){super(),this._title=o.title??o.type,this.name=o.name??o.type,this.updateModules(o.modules),o.codeTemplate&&(this.codeTemplate=o.codeTemplate),o.variableName&&(this.state.variableName=o.variableName),this.addInput("_node",new x("",[]).use(r.setType,T).use(r.allowMultipleConnections).setHidden(!0)),this.addOutput("_node",new x("",[]).use(r.setType,T).use(r.allowMultipleConnections).setHidden(!0)),this.staticInputKeys.push("_node"),this.staticOutputKeys.push("_node"),this.executeFactory("input",o.inputs),this.executeFactory("output",o.outputs),o.onCreate?.call(this)}onPlaced(){this.events.update.subscribe(this,t=>{t&&(t.type==="input"&&this.staticInputKeys.includes(t.name)||t.type==="output"&&this.staticOutputKeys.includes(t.name))&&this.onUpdate()}),this.onUpdate(),o.onPlaced?.call(this)}onConnected(){o.onConnected?.call(this)}onDestroy(){o.onDestroy?.call(this)}onUnconnected(){o.onUnconnected?.call(this)}update(){o.update?.call(this)}load(t){this.preventUpdate=!0,this.hooks.beforeLoad.execute(t),this.id=t.id,this.title=t.title;for(const n of this.staticInputKeys)this.inputs[n].load(t.inputs[n]),this.inputs[n].nodeId=this.id,n!=="_node"&&(this.inputs[n].hidden=t.inputs[n].hidden);for(const n of this.staticOutputKeys)this.outputs[n].load(t.outputs[n]),this.outputs[n].nodeId=this.id,n!=="_node"&&(this.outputs[n].hidden=t.outputs[n].hidden);this.preventUpdate=!1,this.onUpdate(),this.preventUpdate=!0;for(const n of Object.keys(t.inputs))if(!this.staticInputKeys.includes(n)){if(!this.inputs[n]){const s=t.inputs[n].value;let a;typeof s=="number"?a=new r.IntegerInterface(n,s).use(r.setType,v):a=new r.TextInputInterface(n,JSON.stringify(s)).use(r.setType,z),a.use(r.displayInSidebar,!0),this.addInput(n,a)}this.inputs[n]&&(this.inputs[n].load(t.inputs[n]),this.inputs[n].nodeId=this.id)}for(const n of Object.keys(t.outputs))if(!this.staticOutputKeys.includes(n)){if(!this.outputs[n]){const s=new Y(n);this.addOutput(n,s)}this.outputs[n]&&(this.outputs[n].load(t.outputs[n]),this.outputs[n].nodeId=this.id)}D(this.graph,t),this.preventUpdate=!1,this.events.loaded.emit(this)}onUpdate(){if(this.preventUpdate)return;this.graph&&this.graph.activeTransactions++;const t=this.getStaticValues(this.staticInputKeys,this.inputs),n=this.getStaticValues(this.staticOutputKeys,this.outputs),s=o.onUpdate.call(this,t,n);this.updateInterfaces("input",s.inputs??{},s.forceUpdateInputs??[]),this.updateInterfaces("output",s.outputs??{},s.forceUpdateOutputs??[]),this.graph&&this.graph.activeTransactions--}getStaticValues(t,n){const s={};for(const a of t)s[a]=n[a].value;return s}updateInterfaces(t,n,s){const a=t==="input"?this.staticInputKeys:this.staticOutputKeys,i=t==="input"?this.inputs:this.outputs;for(const d of Object.keys(i))a.includes(d)||n[d]&&!s.includes(d)||(t==="input"?this.removeInput(d):this.removeOutput(d));for(const d of Object.keys(n)){if(i[d])continue;const c=n[d]();t==="input"?this.addInput(d,c):this.addOutput(d,c)}}updateProps(t){this.state.props=t,this.onUpdate()}executeFactory(t,n){Object.keys(n||{}).forEach(s=>{const a=n[s]();t==="input"?this.addInput(s,a):this.addOutput(s,a)})}}}O.escape=o=>o;class Q{_id;_viewModel;_state;constructor(t){this._id=we.v4(),this._viewModel=t,this._state=e.reactive({autosort:!1,lockCode:!1,modules:{},script:"",template:"",token:null})}get codeNodes(){return L(this.graph)}get connections(){return this.graph.connections}set connections(t){this.graph._connections=t}get graph(){return this.viewModel.displayedGraph}get id(){return this._id}get lockCode(){return this.state.lockCode}set lockCode(t){this.state.lockCode=t,this.viewModel.engine.runOnce(null)}get modules(){let t=[];return this.codeNodes.filter(n=>n.state.modules?.length>0).forEach(n=>{t=t.concat(n.state.modules)}),t?(t.sort(),Array.from(new Set(t.map(n=>this.viewModel.state.modules[n])))):[]}get nodeIds(){return this.codeNodes.map(t=>t.id)}get nodes(){return this.graph.nodes}set nodes(t){this.graph._nodes=t}get script(){return this.state.script}set script(t){this.state.script=t,this.viewModel.engine.runOnce(null)}get scriptedCodeNodes(){return L(this.graph).filter(t=>!t.state?.integrated)}get shortId(){return this.id.slice(0,6)}get state(){return this._state}get viewModel(){return this._viewModel}get visibleNodes(){return this.codeNodes.filter(t=>!t.state?.hidden)}addNode(t,n){return t.code||(t.code=this),n&&(t.state.props=n),this.graph.addNode(t)}addNodeAtCoordinates=(t,n={x:0,y:0},s)=>(this.addNode(t,s),t.position&&(t.position=n),t);addConnection(t,n){t.name!=="_node"&&(t.hidden=!1),n.name!=="_node"&&(n.hidden=!1),this.graph.addConnection(t,n)}clear(){this.state.modules={},this.nodes=[],this.connections=[],this.state.script=""}findNodeById(t){return this.graph.findNodeById(t)}findNodeByType(t){return this.codeNodes.find(n=>n.type===t)}getNodesBySameType(t){return this.codeNodes.filter(n=>n.type===t)}getNodesBySameVariableNames(t){return this.codeNodes.filter(n=>n.state.variableName===t)}hasConnection(t,n){return this.connections.some(s=>s.from.id===t.id&&s.to.id===n.id)}loadTemplate(t){t.then(n=>{this._state.template=n.default??""})}removeConnection(t){this.graph.removeConnection(t)}removeNode(t){this.graph.removeNode(t)}renderNodeCodes(){this.state.lockCode||this.codeNodes.length!==0&&this.codeNodes.forEach(t=>t.renderCode())}renderCode(){this.state.lockCode||(this.state.script=O.render(this.state.template||"",this))}resetInputInterfaceScript(){this.codeNodes.forEach(t=>t.resetInputInterfaceScript())}save(){this.state.autosort&&this.sortNodes();const t=this.viewModel.editor.save();return t.graph.id=this.id,this.saveNodeStates(t.graph.nodes),JSON.parse(JSON.stringify(t))}saveNodeStates(t){t.forEach((n,s)=>{const a=this.nodes[s];Object.entries(n.inputs).forEach(([i,d])=>{n.inputs&&a.inputs[i]&&(d.hidden=a.inputs[i].hidden)}),Object.entries(n.outputs).forEach(([i,d])=>{n.outputs&&a.outputs[i]&&(d.hidden=a.outputs[i].hidden)})})}sortNodes(){if(!(this.nodes.length===0||this.connections.length===0))try{const t=this.connections.map(i=>[i.to.nodeId,i.from.nodeId]);let n=[...this.nodeIds];n.reverse(),n=Ce.array(n,t),n.reverse();const s=this.graph.nodes.map(i=>i.id).filter(i=>!n.includes(i));n=n.concat(s);const a=n.map(i=>this.findNodeById(i));a&&(this.nodes=a)}catch{console.warn("Failed to sort nodes.")}}updateCodeNodes(){this.codeNodes.forEach(t=>t.update())}updateCodeTemplates(){this.codeNodes.forEach(t=>t.updateCodeTemplate())}}const L=o=>{let t=[];return o.nodes.forEach(n=>{n.subgraph?t=t.concat(L(n.subgraph)):n.isCodeNode&&t.push(n)}),t},Ae=(o=0,t=100)=>({x:o*420,y:t}),We=o=>{const t={...o.position};return t.x-=440,t.y+=50,t},Xe=o=>{const{calculationOrder:t,connectionsFromNode:n}=r.sortTopologically(o);t.forEach(s=>{if(!s.isCodeNode)return;const a=s;n.has(a)&&n.get(a).forEach(i=>{i.to.state&&i.from.script&&(i.to.state.script=i.from.script)})})},qe=["id"],Ye={class:"align-middle"},Z=e.defineComponent({__name:"CodeGraphNodeInterface",props:{node:{},intf:{}},setup(o){const t=o,{viewModel:n}=r.useViewModel(),{hoveredOver:s,temporaryConnection:a}=r.useTemporaryConnection(),i=e.ref(null),d=e.computed(()=>t.intf.connectionCount>0),c=e.computed(()=>({"--connected":d.value})),m=()=>{s(t.intf)},b=()=>{s(void 0)},_=()=>{i.value&&n.value.hooks.renderInterface.execute({intf:t.intf,el:i.value})};return e.onMounted(_),e.onUpdated(_),(B,V)=>(e.openBlock(),e.createElementBlock("div",{id:o.intf.id,ref_key:"el",ref:i,class:e.normalizeClass(["baklava-node-interface",c.value])},[o.intf.port?(e.openBlock(),e.createElementBlock("div",{key:0,class:e.normalizeClass(["__port",{"--selected":e.unref(a)?.from===o.intf}]),onPointerover:m,onPointerout:b},null,34)):e.createCommentVNode("",!0),e.createElementVNode("span",Ye,[e.renderSlot(B.$slots,"default")])],10,qe))}}),Je={},Ke={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 Qe(o,t){return e.openBlock(),e.createElementBlock("svg",Ke,[...t[0]||(t[0]=[e.createElementVNode("path",{stroke:"none",d:"M0 0h24v24H0z",fill:"none"},null,-1),e.createElementVNode("path",{d:"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 j=E(Je,[["render",Qe]]),Ze={},je={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 et(o,t){return e.openBlock(),e.createElementBlock("svg",je,[...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 ee=E(Ze,[["render",et]]),tt={},nt={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 ot(o,t){return e.openBlock(),e.createElementBlock("svg",nt,[...t[0]||(t[0]=[e.createElementVNode("path",{stroke:"none",d:"M0 0h24v24H0z",fill:"none"},null,-1),e.createElementVNode("path",{d:"M18 3a3 3 0 0 1 2.995 2.824l.005 .176v12a3 3 0 0 1 -2.824 2.995l-.176 .005h-12a3 3 0 0 1 -2.995 -2.824l-.005 -.176v-12a3 3 0 0 1 2.824 -2.995l.176 -.005h12zm0 2h-9v14h9a1 1 0 0 0 .993 -.883l.007 -.117v-12a1 1 0 0 0 -.883 -.993l-.117 -.007zm-2.293 4.293a1 1 0 0 1 .083 1.32l-.083 .094l-1.292 1.293l1.292 1.293a1 1 0 0 1 .083 1.32l-.083 .094a1 1 0 0 1 -1.32 .083l-.094 -.083l-2 -2a1 1 0 0 1 -.083 -1.32l.083 -.094l2 -2a1 1 0 0 1 1.414 0z"},null,-1)])])}const te=E(tt,[["render",ot]]),st={},at={xmlns:"http://www.w3.org/2000/svg",width:"24",height:"24",viewBox:"0 0 24 24",fill:"currentColor",class:"baklava-icon icon icon-tabler icons-tabler-filled icon-tabler-layout-sidebar-left-expand"};function it(o,t){return e.openBlock(),e.createElementBlock("svg",at,[...t[0]||(t[0]=[e.createElementVNode("path",{stroke:"none",d:"M0 0h24v24H0z",fill:"none"},null,-1),e.createElementVNode("path",{d:"M18 3a3 3 0 0 1 2.995 2.824l.005 .176v12a3 3 0 0 1 -2.824 2.995l-.176 .005h-12a3 3 0 0 1 -2.995 -2.824l-.005 -.176v-12a3 3 0 0 1 2.824 -2.995l.176 -.005h12zm0 2h-9v14h9a1 1 0 0 0 .993 -.883l.007 -.117v-12a1 1 0 0 0 -.883 -.993l-.117 -.007zm-4.387 4.21l.094 .083l2 2a1 1 0 0 1 .083 1.32l-.083 .094l-2 2a1 1 0 0 1 -1.497 -1.32l.083 -.094l1.292 -1.293l-1.292 -1.293a1 1 0 0 1 -.083 -1.32l.083 -.094a1 1 0 0 1 1.32 -.083z"},null,-1)])])}const ne=E(st,[["render",it]]),rt={},lt={xmlns:"http://www.w3.org/2000/svg",width:"24",height:"24",viewBox:"0 0 24 24",fill:"currentColor",class:"baklava-icon icon icon-tabler icons-tabler-filled icon-tabler-layout-sidebar-right"};function dt(o,t){return e.openBlock(),e.createElementBlock("svg",lt,[...t[0]||(t[0]=[e.createElementVNode("path",{stroke:"none",d:"M0 0h24v24H0z",fill:"none"},null,-1),e.createElementVNode("path",{d:"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 oe=E(rt,[["render",dt]]),ct={},pt={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 ut(o,t){return e.openBlock(),e.createElementBlock("svg",pt,[...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=E(ct,[["render",ut]]),ht={},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-right-expand"};function ft(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 -.005h12zm-3 2h-9a1 1 0 0 0 -.993 .883l-.007 .117v12a1 1 0 0 0 .883 .993l.117 .007h9v-14zm-3.293 4.293a1 1 0 0 1 .083 1.32l-.083 .094l-1.292 1.293l1.292 1.293a1 1 0 0 1 .083 1.32l-.083 .094a1 1 0 0 1 -1.32 .083l-.094 -.083l-2 -2a1 1 0 0 1 -.083 -1.32l.083 -.094l2 -2a1 1 0 0 1 1.414 0z"},null,-1)])])}const ae=E(ht,[["render",ft]]),gt={},yt={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 kt(o,t){return e.openBlock(),e.createElementBlock("svg",yt,[...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 ie=E(gt,[["render",kt]]),bt={},Nt={xmlns:"http://www.w3.org/2000/svg",width:"24",height:"24",viewBox:"0 0 24 24",fill:"none",stroke:"currentColor","stroke-width":"2","stroke-linecap":"round","stroke-linejoin":"round",class:"baklava-icon icon icon-tabler icons-tabler-outline icon-tabler-schema"};function _t(o,t){return e.openBlock(),e.createElementBlock("svg",Nt,[...t[0]||(t[0]=[e.createStaticVNode('<path stroke="none" d="M0 0h24v24H0z" fill="none"></path><path d="M5 2h5v4h-5z"></path><path d="M15 10h5v4h-5z"></path><path d="M5 18h5v4h-5z"></path><path d="M5 10h5v4h-5z"></path><path d="M10 12h5"></path><path d="M7.5 6v4"></path><path d="M7.5 14v4"></path>',8)])])}const re=E(bt,[["render",_t]]),Ct={},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-schema-off"};function It(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="M6 2h4v4m-4 0h-1v-1"></path><path d="M15 11v-1h5v4h-2"></path><path d="M5 18h5v4h-5z"></path><path d="M5 10h5v4h-5z"></path><path d="M10 12h2"></path><path d="M7.5 7.5v2.5"></path><path d="M7.5 14v4"></path><path d="M3 3l18 18"></path>',9)])])}const le=E(Ct,[["render",It]]),Et={},Bt={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 Vt(o,t){return e.openBlock(),e.createElementBlock("svg",Bt,[...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 de=E(Et,[["render",Vt]]),xt={},Mt={xmlns:"http://www.w3.org/2000/svg",width:"24",height:"24",viewBox:"0 0 24 24",fill:"none",stroke:"currentColor","stroke-width":"2","stroke-linecap":"round","stroke-linejoin":"round",class:"baklava-icon icon icon-tabler icons-tabler-outline icon-tabler-trash-off"};function Tt(o,t){return e.openBlock(),e.createElementBlock("svg",Mt,[...t[0]||(t[0]=[e.createStaticVNode('<path stroke="none" d="M0 0h24v24H0z" fill="none"></path><path d="M3 3l18 18"></path><path d="M4 7h3m4 0h9"></path><path d="M10 11l0 6"></path><path d="M14 14l0 3"></path><path d="M5 7l1 12a2 2 0 0 0 2 2h8a2 2 0 0 0 2 -2l.077 -.923"></path><path d="M18.384 14.373l.616 -7.373"></path><path d="M9 5v-1a1 1 0 0 1 1 -1h4a1 1 0 0 1 1 1v3"></path>',8)])])}const ce=E(xt,[["render",Tt]]),$t=["id","data-node-type"],Ot={class:"__title-label",style:{"flex-grow":"1"}},St={key:0},vt={class:"__menu",style:{display:"flex"}},zt={class:"__outputs"},Lt={key:0},Rt=["id","title"],Dt={class:"__inputs"},Ut={key:0},Gt=["id","title"],Pt=e.defineComponent({__name:"CodeGraphNode",props:{node:{},selected:{type:Boolean,default:!1},dragging:{type:Boolean}},emits:["select","start-drag","update"],setup(o,{emit:t}){const n=r.Components.ContextMenu,s=r.Components.NodeInterface,a=o,i=e.computed(()=>a.node),d=t,{viewModel:c}=r.useViewModel(),{graph:m,switchGraph:b}=r.useGraph(),_=e.ref(null),B=e.ref(!1),V=e.ref(""),w=e.ref(null),f=e.ref(!1);let k=0,C=0;const g=e.ref(!1),N=e.computed(()=>{const p=[{value:"edit",label:"Edit"},{value:"rename",label:"Rename"},{value:"delete",label:"Delete"}];return a.node.type.startsWith(r.GRAPH_NODE_TYPE_PREFIX)&&p.push({value:"editSubgraph",label:"Edit Subgraph"}),p}),u=e.computed(()=>({"--selected":a.selected,"--dragging":a.dragging,"--two-column":!!a.node.twoColumn,"--hidden":i.value.state?.hidden})),I=e.computed(()=>({"--reverse-y":a.node.reverseY??c.value.settings.nodes.reverseY})),un=e.computed(()=>({top:`${a.node.position?.y??0}px`,left:`${a.node.position?.x??0}px`,"--width":`${a.node.width??c.value.settings.nodes.defaultWidth}px`})),hn=e.computed(()=>Object.values(a.node.inputs).filter(p=>!p.hidden)),mn=e.computed(()=>Object.values(a.node.outputs).filter(p=>!p.hidden)),me=()=>{d("select")},fn=p=>{a.selected||me(),d("start-drag",p)},fe=()=>{g.value=!0},gn=()=>{const p=c.value.displayedGraph.sidebar;p.nodeId="",p.visible=!1},ge=()=>{const p=c.value.displayedGraph.sidebar;p.nodeId=a.node.id,p.visible=!0},yn=()=>{const p=c.value.displayedGraph.sidebar;p.nodeId=a.node.id},kn=async p=>{switch(p){case"edit":ge();break;case"delete":m.value.removeNode(a.node);break;case"rename":V.value=a.node.title,B.value=!0,await e.nextTick(),w.value?.focus();break;case"editSubgraph":b(a.node.template);break}},ye=()=>{i.value.title=V.value,B.value=!1},ke=()=>{_.value&&c.value.hooks.renderNode.execute({node:a.node,el:_.value})},bn=p=>{f.value=!0,k=a.node.width,C=p.clientX,p.preventDefault()},be=p=>{i.value.state&&(i.value.state.integrated=p,d("update"))},Ne=p=>{if(!f.value)return;const y=p.clientX-C,h=k+y/m.value.scaling,Nn=c.value.settings.nodes.minWidth,_n=c.value.settings.nodes.maxWidth;i.value.width=Math.max(Nn,Math.min(_n,h))},_e=()=>{f.value=!1};return e.onMounted(()=>{ke(),window.addEventListener("mousemove",Ne),window.addEventListener("mouseup",_e)}),e.onUpdated(ke),e.onBeforeUnmount(()=>{window.removeEventListener("mousemove",Ne),window.removeEventListener("mouseup",_e)}),(p,y)=>(e.openBlock(),e.createElementBlock("div",{id:i.value.id,ref_key:"el",ref:_,class:e.normalizeClass([u.value,"baklava-node"]),"data-node-type":i.value.type,style:e.normalizeStyle(un.value),onPointerdown:me},[e.unref(c).settings.nodes.resizable?(e.openBlock(),e.createElementBlock("div",{key:0,class:"__resize-handle",onMousedown:bn},null,32)):e.createCommentVNode("",!0),e.createElementVNode("div",{class:"__title",onPointerdown:e.withModifiers(fn,["self","stop"]),onContextmenu:e.withModifiers(fe,["prevent"])},[i.value.inputs._node?(e.openBlock(),e.createBlock(Z,{key:0,node:i.value,intf:i.value.inputs._node,class:"--input","data-interface-type":"node",style:{"flex-grow":"0"}},null,8,["node","intf"])):e.createCommentVNode("",!0),B.value?e.withDirectives((e.openBlock(),e.createElementBlock("input",{key:2,ref_key:"renameInputEl",ref:w,"onUpdate:modelValue":y[4]||(y[4]=h=>V.value=h),class:"baklava-input",placeholder:"Node Name",style:{"flex-grow":"1"},type:"text",onBlur:ye,onKeydown:e.withKeys(ye,["enter"])},null,544)),[[e.vModelText,V.value]]):(e.openBlock(),e.createElementBlock(e.Fragment,{key:1},[e.createElementVNode("div",Ot,[i.value.idx>-1?(e.openBlock(),e.createElementBlock("span",St,e.toDisplayString(i.value.idx+1)+" - ",1)):e.createCommentVNode("",!0),e.createTextVNode(e.toDisplayString(i.value.title),1)]),e.createElementVNode("div",vt,[i.value.subgraph?e.createCommentVNode("",!0):(e.openBlock(),e.createElementBlock(e.Fragment,{key:0},[i.value.state.lockCode?(e.openBlock(),e.createBlock(e.unref(ie),{key:0,class:"--clickable mx-1",onClick:y[0]||(y[0]=h=>i.value.lockCode=!1)})):e.createCommentVNode("",!0),i.value.state.integrated?(e.openBlock(),e.createBlock(e.unref(j),{key:1,class:"--clickable mx-1",onClick:y[1]||(y[1]=h=>be(!1))})):(e.openBlock(),e.createBlock(e.unref(de),{key:2,class:"--clickable mx-1",onClick:y[2]||(y[2]=h=>be(!0))})),!e.unref(c).displayedGraph.sidebar.visible&&e.unref(c).displayedGraph.sidebar.nodeId!==i.value.id?(e.openBlock(),e.createBlock(e.unref(ae),{key:3,class:"--clickable mx-1",onClick:ge})):e.unref(c).displayedGraph.sidebar.visible&&e.unref(c).displayedGraph.sidebar.nodeId!==i.value.id?(e.openBlock(),e.createBlock(e.unref(oe),{key:4,class:"--clickable mx-1",onClick:yn})):(e.openBlock(),e.createBlock(e.unref(se),{key:5,class:"--clickable mx-1",onClick:gn}))],64)),e.createVNode(e.unref(ee),{class:"--clickable mx-1",onClick:fe}),e.createVNode(e.unref(n),{modelValue:g.value,"onUpdate:modelValue":y[3]||(y[3]=h=>g.value=h),x:0,y:0,items:N.value,onClick:kn},null,8,["modelValue","items"])])],64)),i.value.outputs._node?(e.openBlock(),e.createBlock(Z,{key:3,node:i.value,intf:i.value.outputs._node,class:"--output","data-interface-type":"node"},null,8,["node","intf"])):e.createCommentVNode("",!0)],32),e.createElementVNode("div",{class:e.normalizeClass(["__content",I.value]),onKeydown:y[5]||(y[5]=e.withKeys(e.withModifiers(()=>{},["stop"]),["delete"])),onContextmenu:y[6]||(y[6]=e.withModifiers(()=>{},["prevent"]))},[e.createElementVNode("div",zt,[(e.openBlock(!0),e.createElementBlock(e.Fragment,null,e.renderList(mn.value,h=>(e.openBlock(),e.createElementBlock(e.Fragment,{key:h.id},[i.value.state?.hidden?(e.openBlock(),e.createElementBlock("div",Lt,[h.port?(e.openBlock(),e.createElementBlock("div",{key:0,id:h.id,title:h.name,class:"baklava-node-interface --output --connected"},[...y[7]||(y[7]=[e.createElementVNode("div",{class:"__port"},null,-1)])],8,Rt)):e.createCommentVNode("",!0)])):e.renderSlot(p.$slots,"nodeInterface",{key:1,type:"output",node:i.value,intf:h},()=>[e.createVNode(e.unref(s),{node:i.value,intf:h,title:h.type},null,8,["node","intf","title"])])],64))),128))]),e.createElementVNode("div",Dt,[(e.openBlock(!0),e.createElementBlock(e.Fragment,null,e.renderList(hn.value,h=>(e.openBlock(),e.createElementBlock(e.Fragment,{key:h.id},[i.value.state?.hidden?(e.openBlock(),e.createElementBlock("div",Ut,[h.port?(e.openBlock(),e.createElementBlock("div",{key:0,id:h.id,title:h.name,class:"baklava-node-interface --input --connected"},[...y[8]||(y[8]=[e.createElementVNode("div",{class:"__port"},null,-1)])],8,Gt)):e.createCommentVNode("",!0)])):e.renderSlot(p.$slots,"nodeInterface",{key:1,node:i.value,intf:h,type:"input"},()=>[e.createVNode(e.unref(s),{node:i.value,intf:h,title:h.type},null,8,["node","intf","title"])])],64))),128))])],34)],46,$t))}}),Ft=["title"],Ht={key:0,class:"__label"},pe=e.defineComponent({__name:"Checkbox",props:{disabled:{type:Boolean},inversed:{type:Boolean},modelValue:{type:Boolean},name:{}},emits:["update:modelValue"],setup(o,{emit:t}){const n=t;return(s,a)=>(e.openBlock(),e.createElementBlock("div",{class:e.normalizeClass(["baklava-checkbox",{"--checked":o.inversed?!o.modelValue:o.modelValue,"--disabled":o.disabled}]),title:o.name,onClick:a[0]||(a[0]=i=>n("update:modelValue",!o.modelValue))},[a[1]||(a[1]=e.createElementVNode("div",{class:"__checkmark-container"},[e.createElementVNode("svg",{xmlns:"http://www.w3.org/2000/svg",width:"18",height:"18",viewBox:"0 0 18 18"},[e.createElementVNode("path",{class:"__checkmark",d:"M 6 5 L 6 10 L 16 10",transform:"rotate(-45 10 10)"})])],-1)),o.name?(e.openBlock(),e.createElementBlock("div",Ht,e.toDisplayString(o.name),1)):e.createCommentVNode("",!0)],10,Ft))}}),At={class:"__header"},Wt={class:"__node-name"},Xt={class:"__interfaces"},qt={class:"__inputs"},Yt={style:{display:"flex"}},Jt={class:"__outputs"},Kt={key:0,class:"__interface"},Qt={style:{display:"flex"}},Zt=e.defineComponent({__name:"CodeGraphSidebar",setup(o){const{viewModel:t}=r.useViewModel(),{graph:n}=r.useGraph(),s=e.ref(null),a=e.toRef(t.value.settings.sidebar,"width"),i=e.computed(()=>t.value.settings.sidebar.resizable);let d=0,c=0;const m=e.computed(()=>{const g=n.value.sidebar.nodeId;return n.value.nodes.find(N=>N.id===g)}),b=e.computed(()=>m.value),_=e.computed(()=>({width:`${a.value}px`})),B=e.computed(()=>b.value?Object.values(b.value.inputs).filter(g=>g.displayInSidebar&&g.component):[]),V=e.computed(()=>b.value?Object.values(b.value.outputs).filter(g=>g.displayInSidebar&&g.component):[]),w=()=>{n.value.sidebar.visible=!1},f=()=>{m.value?.events.update.emit(null)},k=g=>{d=a.value,c=g.clientX,window.addEventListener("mousemove",C),window.addEventListener("mouseup",()=>{window.removeEventListener("mousemove",C)},{once:!0})},C=g=>{const N=s.value?.parentElement?.getBoundingClientRect().width??500,u=g.clientX-c;let I=d-u;I<300?I=300:I>.9*N&&(I=.9*N),a.value=I};return(g,N)=>(e.openBlock(),e.createElementBlock("div",{class:e.normalizeClass([{"--open":e.unref(n).sidebar.visible},"baklava-sidebar"]),style:e.normalizeStyle(_.value),ref_key:"el",ref:s},[i.value?(e.openBlock(),e.createElementBlock("div",{key:0,class:"__resizer",onMousedown:k},null,32)):e.createCommentVNode("",!0),m.value?(e.openBlock(),e.createElementBlock(e.Fragment,{key:1},[e.createElementVNode("div",At,[e.createElementVNode("button",{tabindex:"-1",class:"__close",onClick:w},"×"),e.createElementVNode("div",Wt,[e.createElementVNode("b",null,e.toDisplayString(m.value.title),1)])]),e.createElementVNode("div",Xt,[e.createElementVNode("div",qt,[(e.openBlock(!0),e.createElementBlock(e.Fragment,null,e.renderList(B.value,u=>(e.openBlock(),e.createElementBlock("div",{key:u.id,class:"__interface"},[e.createElementVNode("div",Yt,[e.createVNode(pe,{modelValue:u.hidden,"onUpdate:modelValue":[I=>u.hidden=I,N[0]||(N[0]=()=>m.value?.events.update.emit(null))],disabled:!u.optional,inversed:"",style:{"padding-right":"8px"}},null,8,["modelValue","onUpdate:modelValue","disabled"]),(e.openBlock(),e.createBlock(e.resolveDynamicComponent(u.component),{modelValue:u.value,"onUpdate:modelValue":I=>u.value=I,node:m.value,intf:u,style:{width:"100%"}},null,8,["modelValue","onUpdate:modelValue","node","intf"]))])]))),128))]),e.createElementVNode("div",Jt,[b.value&&b.value.state?(e.openBlock(),e.createElementBlock("div",Kt,[N[3]||(N[3]=e.createElementVNode("label",null,"Variable name",-1)),e.withDirectives(e.createElementVNode("input",{"onUpdate:modelValue":N[1]||(N[1]=u=>b.value.state.variableName=u),type:"text",class:"baklava-input",title:"Variable name",onBlur:f,onKeydown:e.withKeys(f,["enter"])},null,544),[[e.vModelText,b.value.state.variableName]])])):e.createCommentVNode("",!0),(e.openBlock(!0),e.createElementBlock(e.Fragment,null,e.renderList(V.value,u=>(e.openBlock(),e.createElementBlock("div",{key:u.id,class:"__interface"},[e.createElementVNode("div",Qt,[e.createVNode(pe,{modelValue:u.hidden,"onUpdate:modelValue":[I=>u.hidden=I,N[2]||(N[2]=()=>m.value?.events.update.emit(null))],disabled:!u.optional,inversed:"",style:{"padding-right":"8px"}},null,8,["modelValue","onUpdate:modelValue","disabled"]),(e.openBlock(),e.createBlock(e.resolveDynamicComponent(u.component),{modelValue:u.value,"onUpdate:modelValue":I=>u.value=I,node:m.value,intf:u,style:{width:"100%"}},null,8,["modelValue","onUpdate:modelValue","node","intf"]))])]))),128))])]),e.renderSlot(g.$slots,"codeEditor",{node:m.value})],64)):e.createCommentVNode("",!0)],6))}}),jt=e.defineComponent({props:{type:{type:String,required:!0},title:{type:String,required:!0}},setup(o){const{viewModel:t}=r.useViewModel(),{switchGraph:n}=r.useGraph(),s=e.ref(!1),a=e.computed(()=>o.type.startsWith(r.GRAPH_NODE_TYPE_PREFIX));return{showContextMenu:s,hasContextMenu:a,contextMenuItems:[{label:"Edit Subgraph",value:"editSubgraph"},{label:"Delete Subgraph",value:"deleteSubgraph"}],openContextMenu:()=>{s.value=!0},onContextMenuClick:m=>{const b=o.type.substring(r.GRAPH_NODE_TYPE_PREFIX.length),_=t.value.editor.graphTemplates.find(B=>B.id===b);if(_)switch(m){case"editSubgraph":n(_);break;case"deleteSubgraph":t.value.editor.removeGraphTemplate(_);break}}}}}),en=["data-node-type"],tn={class:"__title"},nn={class:"__title-label"};function on(o,t,n,s,a,i){return e.openBlock(),e.createElementBlock("div",{class:"baklava-node --palette","data-node-type":o.type},[e.createElementVNode("div",tn,[e.createElementVNode("div",nn,e.toDisplayString(o.title),1)])],8,en)}const ue=E(jt,[["render",on]]),sn={class:"baklava-node --palette",style:{"margin-top":"-20px","margin-bottom":"20px"}},an={key:0,style:{display:"flex","justify-content":"space-between"}},rn=["onClick"],ln={key:0,style:{margin:"auto 0","font-size":"12px"}},dn=e.defineComponent({__name:"CodeNodePalette",setup(o){const{viewModel:t}=r.useViewModel(),{x:n,y:s}=Ie.usePointer(),{transform:a}=r.useTransform(),i=r.useNodeCategories(t),d=e.inject("editorEl"),c=e.ref(""),m=e.ref(null),b=()=>c.value?i.value.filter(w=>w.name.toLowerCase().includes(c.value.toLowerCase())||Object.values(w.nodeTypes).some(f=>f.title.toLowerCase().includes(c.value.toLowerCase()))):i.value,_=w=>c.value?Object.values(w).filter(f=>f.category.toLowerCase().includes(c.value.toLowerCase())||f.title.toLowerCase().includes(c.value.toLowerCase())):Object.values(w),B=e.computed(()=>{if(!m.value||!d?.value)return{};const{left:w,top:f}=d.value.getBoundingClientRect();return{top:`${s.value-f}px`,left:`${n.value-w}px`}}),V=(w,f)=>{m.value={type:w,nodeInformation:f};const k=()=>{const C=e.reactive(new f.type);t.value.displayedGraph.addNode(C);const g=d.value.getBoundingClientRect(),[N,u]=a(n.value-g.left,s.value-g.top);C.position.x=N,C.position.y=u,m.value=null,document.removeEventListener("pointerup",k)};document.addEventListener("pointerup",k)};return(w,f)=>(e.openBlock(),e.createElementBlock(e.Fragment,null,[e.createElementVNode("div",{class:e.normalizeClass([{"--open":e.unref(t).settings.palette.enabled},"baklava-node-palette"]),onContextmenu:f[1]||(f[1]=e.withModifiers(()=>{},["stop","prevent"]))},[e.createElementVNode("div",sn,[e.withDirectives(e.createElementVNode("input",{"onUpdate:modelValue":f[0]||(f[0]=k=>c.value=k),type:"text",class:"baklava-input",title:"Filter nodes",onKeyup:b},null,544),[[e.vModelText,c.value]])]),(e.openBlock(!0),e.createElementBlock(e.Fragment,null,e.renderList(b(),k=>(e.openBlock(),e.createElementBlock("section",{key:k.name},[k.name!=="default"?(e.openBlock(),e.createElementBlock("h3",an,[e.createElementVNode("div",{onClick:C=>c.value=k.name,style:{cursor:"pointer"}},e.toDisplayString(k.name),9,rn),_(k.nodeTypes).length<Object.values(k.nodeTypes).length?(e.openBlock(),e.createElementBlock("div",ln," ( "+e.toDisplayString(_(k.nodeTypes).length)+" / "+e.toDisplayString(Object.values(k.nodeTypes).length)+" ) ",1)):e.createCommentVNode("",!0)])):e.createCommentVNode("",!0),(e.openBlock(!0),e.createElementBlock(e.Fragment,null,e.renderList(_(k.nodeTypes),C=>(e.openBlock(),e.createBlock(ue,{key:C.type,type:C.type,title:C.title,onPointerdown:g=>V(C.type,C)},null,8,["type","title","onPointerdown"]))),128))]))),128))],34),e.createVNode(e.Transition,{name:"fade"},{default:e.withCtx(()=>[m.value?(e.openBlock(),e.createElementBlock("div",{key:0,class:"baklava-dragged-node",style:e.normalizeStyle(B.value)},[e.createVNode(ue,{type:m.value.type,title:m.value.nodeInformation.title},null,8,["type","title"])],4)):e.createCommentVNode("",!0)]),_:1})],64))}}),cn=e.defineComponent({__name:"CodeGraphEditor",props:{viewModel:{}},setup(o){const t=o,n=e.toRef(t,"viewModel"),s=a=>a.events.update.emit(null);return e.onMounted(()=>{n.value.subscribe(),n.value.engine.start()}),e.onUnmounted(()=>{n.value.unsubscribe(),n.value.engine.stop()}),(a,i)=>(e.openBlock(),e.createBlock(e.unref(r.BaklavaEditor),{"view-model":n.value},{palette:e.withCtx(()=>[e.createVNode(dn)]),node:e.withCtx(d=>[e.createVNode(Pt,e.mergeProps(d,{onUpdate:c=>s(d.node)}),null,16,["onUpdate"])]),sidebar:e.withCtx(d=>[e.createVNode(Zt,e.normalizeProps(e.guardReactiveProps(d)),{codeEditor:e.withCtx(({node:c})=>[e.renderSlot(a.$slots,"sidebarCodeEditor",{node:c})]),_:3},16)]),_:3},8,["view-model"]))}}),he=o=>{const t="TOGGLE_PALETTE";o.commandHandler.registerCommand(t,{execute:()=>o.settings.palette.enabled=!o.settings.palette.enabled,canExecute:()=>!0});const n="CLEAR_ALL";o.commandHandler.registerCommand(n,{execute:()=>o.code.clear(),canExecute:()=>o.displayedGraph.nodes.length>0});const s="TOGGLE_MINIMAP";o.commandHandler.registerCommand(s,{execute:()=>o.settings.enableMinimap=!o.settings.enableMinimap,canExecute:()=>o.displayedGraph.nodes.length>1}),o.settings.toolbar.commands=[{command:t,title:"Toggle palette",icon:e.computed(()=>o.settings.palette.enabled?te:ne)},...r.DEFAULT_TOOLBAR_COMMANDS,{command:n,title:"Clear all",icon:ce},{command:s,title:"Toggle minimap",icon:e.computed(()=>o.settings.enableMinimap?le:re)}]},$={enableMinimap:!1,toolbar:{enabled:!0},palette:{enabled:!0},sidebar:{enabled:!0,resizable:!0,width:350},displayValueOnHover:!1};function pn(o){const t=r.useBaklava(o?.existingEditor);t.code=o?.code?new o.code(t):new Q(t),he(t);const n={};return Object.keys($).forEach(s=>{n[s]=typeof $[s]=="object"?{...t.settings[s],...$[s]}:$[s]}),t.settings=e.reactive({...t.settings,...n}),t.settings.nodes.defaultWidth=350,t.state=e.reactive({modules:{},token:null}),t.init=()=>{t.unsubscribe(),t.engine=new r.DependencyEngine(t.editor)},t.subscribe=()=>{t.state.token&&t.unsubscribe();const s=Symbol(),a=t.displayedGraph;a.events.addNode.subscribe(s,i=>{i.code=t.code}),a.events.addConnection.subscribe(s,i=>{t.code.findNodeById(i.to.nodeId)?.onConnected(),t.code.findNodeById(i.from.nodeId)?.onConnected()}),a.events.removeConnection.subscribe(s,i=>{t.code.findNodeById(i.to.nodeId)?.onUnconnected(),t.code.findNodeById(i.from.nodeId)?.onUnconnected()}),t.engine.events.beforeRun.subscribe(s,()=>{t.engine.pause(),t.code&&(t.code.updateCodeNodes(),t.code.sortNodes(),t.code.updateCodeTemplates(),t.code.resetInputInterfaceScript()),t.engine.resume()}),t.engine.events.beforeNodeCalculation.subscribe(s,i=>{t.engine.pause();const d=i.node;d.isCodeNode&&(d.updateOutputNames(),d.updateConnectedInputInterfaces()),t.engine.resume()}),t.engine.events.afterRun.subscribe(s,i=>{t.engine.pause(),r.applyResult(i,t.editor),t.code&&(t.code.renderNodeCodes(),t.code.renderCode()),t.engine.resume()}),t.state.token=s},t.unsubscribe=()=>{if(!t.state.token)return;const s=t.state.token;t.displayedGraph.events.addNode.unsubscribe(s),t.displayedGraph.events.addConnection.unsubscribe(s),t.engine.events.beforeRun.unsubscribe(s),t.engine.events.afterRun.unsubscribe(s),t.state.token=null},t}l.AbstractCodeNode=A,l.CheckboxInterface=xe,l.Code=Q,l.CodeGraphEditor=cn,l.CodeNode=R,l.CodeNodeInputInterface=M,l.CodeNodeInterface=x,l.CodeNodeInterfaceComponent=S,l.CodeNodeOutputInterface=Y,l.CodeVariable=j,l.DEFAULT_SETTINGS=$,l.DotsVertical=ee,l.DynamicCodeNode=K,l.IntegerInterface=Me,l.LayoutSidebarLeftCollapse=te,l.LayoutSidebarLeftExpand=ne,l.LayoutSidebarRight=oe,l.LayoutSidebarRightCollapse=se,l.LayoutSidebarRightExpand=ae,l.ListInputInterface=Te,l.LockCode=ie,l.NumberInterface=$e,l.Schema=re,l.SchemaOff=le,l.SelectInterface=Oe,l.SliderInterface=Se,l.TextInputInterface=Ue,l.TextInputInterfaceComponent=J,l.TextareaInputInterface=Ge,l.TransitionBottom=de,l.TrashOff=ce,l.TupleInputInterface=Pe,l.addDefaultInterfaceTypes=Ve,l.addToolbarCommands=he,l.booleanType=U,l.defineCodeNode=Fe,l.defineDynamicCodeNode=He,l.dictType=q,l.formatInputs=W,l.getCodeNodes=L,l.getPositionAtColumn=Ae,l.getPositionBeforeNode=We,l.listType=G,l.loadNodeState=D,l.nodeType=T,l.numberType=v,l.saveNodeState=X,l.setOptional=Be,l.stringType=z,l.transferCodeScript=Xe,l.tupleType=P,l.useCodeGraph=pn,Object.defineProperty(l,Symbol.toStringTag,{value:"Module"})}));
1
+ (function(r,x){typeof exports=="object"&&typeof module<"u"?x(exports,require("mustache"),require("toposort"),require("baklavajs"),require("vue"),require("uuid"),require("@vueuse/core")):typeof define=="function"&&define.amd?define(["exports","mustache","toposort","baklavajs","vue","uuid","@vueuse/core"],x):(r=typeof globalThis<"u"?globalThis:r||self,x(r["@babsey/code-graph"]={},r.mustache,r.toposort,r.baklavajs,r.Vue,r.uuid,r["@vueuse/core"]))})(this,(function(r,x,Ce,l,e,we,Ie){"use strict";x.escape=o=>o;class A extends l.AbstractNode{state;code;isCodeNode=!0;name="";codeTemplate;inputs={};outputs={};constructor(){super(),this.initializeIo(),this.width=400,this.twoColumn=!0,this.state=e.reactive({codeTemplate:"",hidden:!1,integrated:!1,lockCode:!1,modules:[],props:null,script:"",variableName:""}),this.codeTemplate=function(){return`${this.name}(${W(this.codeNodeInputs).join(", ")})`}}get codeNodeInputs(){return Object.fromEntries(Object.entries(this.inputs).filter(t=>t[1].type!="node"))}get codeNodeOutputs(){return Object.fromEntries(Object.entries(this.outputs).filter(t=>t[1].type!="node"))}get idx(){return this.code?.codeNodes.filter(t=>!t.state.integrated).indexOf(this)??-1}get idxByVariableNames(){return this.code?.getNodesBySameVariableNames(this.state.variableName).indexOf(this)??-1}get lockCode(){return this.state.lockCode}set lockCode(t){this.state.lockCode=t,this.events.update.emit(null)}get optionalInputs(){return Object.fromEntries(Object.entries(this.codeNodeInputs).filter(t=>t[1].optional))}get requiredInputs(){return Object.fromEntries(Object.entries(this.codeNodeInputs).filter(t=>!t[1].optional))}get script(){return this.state.script}set script(t){this.state.script=t,this.events.update.emit(null)}get shortId(){return this.id.slice(0,6)}get subgraph(){}get variableName(){return this.state.variableName?this.state.variableName+(this.idxByVariableNames+1):""}getConnectedNodeByInterface(t,n){const s=this.getConnectedNodesByInterface(t,n);return s.length>0?s[0]:null}getConnectedNodes(t){let n=[];if(t!=="inputs"){const s=this.graph?.connections.filter(a=>a.from.name!=="_node").filter(a=>a.from.nodeId===this.id).map(a=>a.to.nodeId);s&&(n=n.concat(s))}if(t!=="outputs"){const s=this.graph?.connections.filter(a=>a.from.name!=="_node").filter(a=>a.to.nodeId===this.id).map(a=>a.from.nodeId);s&&(n=n.concat(s))}return!n||n.length==0?[]:n.map(s=>this.graph?.findNodeById(s))}getConnectedNodesByInterface(t,n){let s=[];if(n!=="outputs"&&this.inputs[t]){const a=this.graph?.connections.filter(i=>i.to.id===this.inputs[t]?.id||i.from.id===this.inputs[t]?.id).map(i=>i.from.nodeId);a&&(s=s.concat(a))}if(n!=="inputs"&&this.outputs[t]){const a=this.graph?.connections.filter(i=>i.from.id===this.outputs[t]?.id||i.from.id===this.outputs[t]?.id).map(i=>i.to.nodeId);a&&(s=s.concat(a))}return!s||s.length==0?[]:s.map(a=>this.graph?.findNodeById(a))}registerCode(t){this.code=t}renderCode(){if(!this.lockCode){const t={};Object.keys(this.inputs).forEach(s=>{if(s==="_node")return;const a=this.inputs[s];a&&a.state&&(t[s]=a.state.script.length>0?a.state.script:a.getValue())});const n={};Object.keys(this.outputs).forEach(s=>{if(s==="_node")return;const a=this.outputs[s];a&&a.state&&(n[s]=a.getValue())}),this.state.script=x.render(this.state.codeTemplate,{inputs:t,outputs:n})}this.outputs.out&&(this.outputs.out.state.script=this.script)}resetInputInterfaceScript(){Object.values(this.codeNodeInputs).forEach(t=>t.resetScript())}updateCodeTemplate(){this.state.codeTemplate=this.codeTemplate.call(this)}updateConnectedInputInterfaces(){if(!this.graph)return;const{connectionsFromNode:t}=l.sortTopologically(this.graph);if(!t.has(this))return;const n=t.get(this);n&&n.forEach(s=>{if(!s.from.isCodeNode||!s.to.isCodeNode)return;const a=this.graph?.findNodeById(s.from.nodeId);a&&(a.renderCode(),s.to.script=s.from.script)})}updateOutputNames(){Object.values(this.codeNodeOutputs).forEach(t=>{t.name=this.state.integrated?"":this.variableName+t.value})}updateProps(t){this.state.props=t}}class R extends A{calculate;load(t){super.load(t),D(this.graph,t)}save(){const t=super.save();return X(this.graph,t),t}updateModules(t){if(t)this.state.modules=t;else if(this.type.includes(".")){const n=this.type.split(".");this.state.modules.push(n.slice(0,n.length-1).join("."))}}}const W=(o,t=!0)=>{const n=[],s=Object.keys(o);return s.forEach(a=>{if(o[a]?.hidden)return;const d=t&&n.length<s.indexOf(a)?`${a}=`:"";n.push(`${d}{{ inputs.${a} }}`)}),n},D=(o,t)=>{if(!o)return;const n=o.findNodeById(t.id);if(!n||n.subgraph)return;const s=n;s.state&&(s.state.integrated=t.integrated,s.state.modules=t.modules,s.state.props=t.props),Object.entries(t.inputs).forEach(([a,i])=>{a!=="_node"&&s.inputs[a]&&(s.inputs[a].hidden=i.hidden)}),Object.entries(t.outputs).forEach(([a,i])=>{a!=="_node"&&s.outputs[a]&&(s.outputs[a].hidden=i.hidden)})},X=(o,t)=>{if(!o)return;const n=o.findNodeById(t.id);if(!n||n.subgraph)return;const s=n;s.state&&(t.integrated=s.state.integrated,t.modules=s.state.modules),Object.entries(t.inputs).forEach(([a,i])=>{a!=="_node"&&s.inputs[a]&&(i.hidden=s.inputs[a].hidden)}),Object.entries(t.outputs).forEach(([a,i])=>{a!=="_node"&&s.outputs[a]&&(i.hidden=s.outputs[a].hidden)})},Ee=["title"],S=e.defineComponent({__name:"CodeNodeInterface",props:{intf:{}},setup(o){return(t,n)=>(e.openBlock(),e.createElementBlock("div",{title:o.intf.state?.script},e.toDisplayString(o.intf.name),9,Ee))}});class M extends l.NodeInterface{isCodeNode=!0;code;state;type=null;constructor(t,n){super(t,n),this.setComponent(e.markRaw(S)),this.state=e.reactive({optional:!1,script:""})}get optional(){return this.state.optional}get script(){return this.state.script}set script(t){this.state.script=t}get shortId(){return this.id.slice(0,6)}getValue=()=>`${this.value??"None"}`;resetScript=()=>this.state.script=""}const Be=(o,t)=>{o.state.optional=t,o.setHidden(t)};class T extends M{constructor(t="",n){super(t,n),this.setComponent(e.markRaw(S)),this.use(l.displayInSidebar,!0)}set script(t){if(this.state.script&&this.allowMultipleConnections){const n=this.state.script;n.startsWith("[")&&n.endsWith("]")?t=JSON.stringify([t,...JSON.parse(n)]):t=[t,n].join(", ")}this.state.script=t}get value(){return super.value}set value(t){super.value=t,this.name!=="_node"&&this.setHidden(!1)}}const U=new l.NodeInterfaceType("boolean"),q=new l.NodeInterfaceType("dict"),G=new l.NodeInterfaceType("list"),$=new l.NodeInterfaceType("node"),v=new l.NodeInterfaceType("number"),z=new l.NodeInterfaceType("string"),P=new l.NodeInterfaceType("tuple"),Ve=o=>{new l.BaklavaInterfaceTypes(o.editor,{viewPlugin:o}).addTypes(U,q,G,$,v,z,P)};class xe extends T{constructor(t,n){super(t,n),this.setComponent(e.markRaw(l.CheckboxInterfaceComponent)),this.use(l.setType,U)}getValue=()=>this.value?"True":"False"}class Y extends M{isCodeNodeOutput=!0;constructor(t="",n=""){super(t,n),this.setComponent(e.markRaw(S))}get script(){return this.name?this.name:this.state.script}}class F extends T{min;max;constructor(t,n,s,a){super(t,n),this.min=s,this.max=a,this.use(l.setType,v)}validate(t){return(this.min===void 0||t>=this.min)&&(this.max===void 0||t<=this.max)}}class Me extends F{component=e.markRaw(l.IntegerInterfaceComponent);validate(t){return Number.isInteger(t)&&super.validate(t)}}class Te extends T{constructor(t="",n=""){super(t,n),this.setComponent(e.markRaw(l.TextInputInterfaceComponent)),this.use(l.setType,G)}getValue=()=>`[${this.value}]`}class $e extends F{component=e.markRaw(l.NumberInterfaceComponent)}class H extends T{constructor(t,n){super(t,n),this.use(l.setType,z)}getValue=()=>`"${this.value}"`}class Oe extends H{component=e.markRaw(l.SelectInterfaceComponent);items;constructor(t,n,s){super(t,n),this.items=s}}class Se extends F{component=e.markRaw(l.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 ve=e.defineComponent({props:{intf:{type:Object,required:!0},modelValue:{type:String,required:!0}},emits:["update:modelValue"],setup(o,{emit:t}){return{v:e.computed({get:()=>o.modelValue,set:s=>{t("update:modelValue",s)}})}}}),E=(o,t)=>{const n=o.__vccOpts||o;for(const[s,a]of t)n[s]=a;return n},ze={style:{position:"relative"}},Le={style:{"font-size":"12px",padding:"0 6px",position:"absolute",top:"-8px","background-color":"var(--baklava-node-color-background)"}},Re=["placeholder","title"];function De(o,t,n,s,a,i){return e.openBlock(),e.createElementBlock("div",ze,[e.createElementVNode("label",Le,e.toDisplayString(o.intf.name),1),e.withDirectives(e.createElementVNode("input",{"onUpdate:modelValue":t[0]||(t[0]=d=>o.v=d),type:"text",class:"baklava-input",placeholder:o.intf.name,title:o.intf.name},null,8,Re),[[e.vModelText,o.v]])])}const J=E(ve,[["render",De]]);class Ue extends H{component=e.markRaw(J)}class Ge extends H{component=e.markRaw(l.TextareaInputInterfaceComponent)}class Pe extends T{constructor(t="",n=""){super(t,n),this.setComponent(e.markRaw(l.TextInputInterfaceComponent)),this.use(l.setType,P)}getValue=()=>`(${this.value})`}function Fe(o){return class extends R{type=o.type;inputs={};outputs={};constructor(){super(),this._title=o.title??o.type,this.name=o.name??o.type,this.updateModules(o.modules),o.variableName&&(this.state.variableName=o.variableName),o.codeTemplate&&(this.codeTemplate=o.codeTemplate),this.addInput("_node",new M("",[]).use(l.setType,$).use(l.allowMultipleConnections).setHidden(!0)),this.addOutput("_node",new M("",[]).use(l.setType,$).use(l.allowMultipleConnections).setHidden(!0)),this.executeFactory("input",o.inputs),this.executeFactory("output",o.outputs),o.onCreate?.call(this)}onPlaced(){o.onPlaced?.call(this)}onConnected(){o.onConnected?.call(this)}onDestroy(){o.onDestroy?.call(this)}onUnconnected(){o.onUnconnected?.call(this)}update(){o.update?.call(this)}executeFactory(t,n){Object.keys(n||{}).forEach(s=>{const a=n[s]();t==="input"?this.addInput(s,a):this.addOutput(s,a)})}}}class K extends R{calculate}function He(o){return class extends K{type=o.type;inputs={};outputs={};calculate;preventUpdate=!1;staticInputKeys=Object.keys(o.inputs??{});staticOutputKeys=Object.keys(o.outputs??{});constructor(){super(),this._title=o.title??o.type,this.name=o.name??o.type,this.updateModules(o.modules),o.codeTemplate&&(this.codeTemplate=o.codeTemplate),o.variableName&&(this.state.variableName=o.variableName),this.addInput("_node",new M("",[]).use(l.setType,$).use(l.allowMultipleConnections).setHidden(!0)),this.addOutput("_node",new M("",[]).use(l.setType,$).use(l.allowMultipleConnections).setHidden(!0)),this.staticInputKeys.push("_node"),this.staticOutputKeys.push("_node"),this.executeFactory("input",o.inputs),this.executeFactory("output",o.outputs),o.onCreate?.call(this)}onPlaced(){this.events.update.subscribe(this,t=>{t&&(t.type==="input"&&this.staticInputKeys.includes(t.name)||t.type==="output"&&this.staticOutputKeys.includes(t.name))&&this.onUpdate()}),this.onUpdate(),o.onPlaced?.call(this)}onConnected(){o.onConnected?.call(this)}onDestroy(){o.onDestroy?.call(this)}onUnconnected(){o.onUnconnected?.call(this)}update(){o.update?.call(this)}load(t){this.preventUpdate=!0,this.hooks.beforeLoad.execute(t),this.id=t.id,this.title=t.title;for(const n of this.staticInputKeys)this.inputs[n].load(t.inputs[n]),this.inputs[n].nodeId=this.id,n!=="_node"&&(this.inputs[n].hidden=t.inputs[n].hidden);for(const n of this.staticOutputKeys)this.outputs[n].load(t.outputs[n]),this.outputs[n].nodeId=this.id,n!=="_node"&&(this.outputs[n].hidden=t.outputs[n].hidden);this.preventUpdate=!1,this.onUpdate(),this.preventUpdate=!0;for(const n of Object.keys(t.inputs))if(!this.staticInputKeys.includes(n)){if(!this.inputs[n]){const s=t.inputs[n].value;let a;typeof s=="number"?a=new l.IntegerInterface(n,s).use(l.setType,v):a=new l.TextInputInterface(n,JSON.stringify(s)).use(l.setType,z),a.use(l.displayInSidebar,!0),this.addInput(n,a)}this.inputs[n]&&(this.inputs[n].load(t.inputs[n]),this.inputs[n].nodeId=this.id)}for(const n of Object.keys(t.outputs))if(!this.staticOutputKeys.includes(n)){if(!this.outputs[n]){const s=new Y(n);this.addOutput(n,s)}this.outputs[n]&&(this.outputs[n].load(t.outputs[n]),this.outputs[n].nodeId=this.id)}D(this.graph,t),this.preventUpdate=!1,this.events.loaded.emit(this)}onUpdate(){if(this.preventUpdate)return;this.graph&&this.graph.activeTransactions++;const t=this.getStaticValues(this.staticInputKeys,this.inputs),n=this.getStaticValues(this.staticOutputKeys,this.outputs),s=o.onUpdate.call(this,t,n);this.updateInterfaces("input",s.inputs??{},s.forceUpdateInputs??[]),this.updateInterfaces("output",s.outputs??{},s.forceUpdateOutputs??[]),this.graph&&this.graph.activeTransactions--}getStaticValues(t,n){const s={};for(const a of t)s[a]=n[a].value;return s}updateInterfaces(t,n,s){const a=t==="input"?this.staticInputKeys:this.staticOutputKeys,i=t==="input"?this.inputs:this.outputs;for(const d of Object.keys(i))a.includes(d)||n[d]&&!s.includes(d)||(t==="input"?this.removeInput(d):this.removeOutput(d));for(const d of Object.keys(n)){if(i[d])continue;const c=n[d]();t==="input"?this.addInput(d,c):this.addOutput(d,c)}}updateProps(t){this.state.props=t,this.onUpdate()}executeFactory(t,n){Object.keys(n||{}).forEach(s=>{const a=n[s]();t==="input"?this.addInput(s,a):this.addOutput(s,a)})}}}x.escape=o=>o;class Q{_id;_viewModel;_state;constructor(t){this._id=we.v4(),this._viewModel=t,this._state=e.reactive({autosort:!1,lockCode:!1,modules:{},script:"",template:"",token:null})}get codeNodes(){return L(this.graph)}get connections(){return this.graph.connections}set connections(t){this.graph._connections=t}get graph(){return this.viewModel.displayedGraph}get id(){return this._id}get lockCode(){return this.state.lockCode}set lockCode(t){this.state.lockCode=t,this.viewModel.engine.runOnce(null)}get modules(){let t=[];return this.codeNodes.filter(n=>n.state.modules?.length>0).forEach(n=>{t=t.concat(n.state.modules)}),t?(t.sort(),Array.from(new Set(t.map(n=>this.viewModel.state.modules[n])))):[]}get nodeIds(){return this.codeNodes.map(t=>t.id)}get nodes(){return this.graph.nodes}set nodes(t){this.graph._nodes=t}get script(){return this.state.script}set script(t){this.state.script=t,this.viewModel.engine.runOnce(null)}get scriptedCodeNodes(){return L(this.graph).filter(t=>!t.state?.integrated)}get shortId(){return this.id.slice(0,6)}get state(){return this._state}get viewModel(){return this._viewModel}get visibleNodes(){return this.codeNodes.filter(t=>!t.state?.hidden)}addNode(t,n){return t.code||(t.code=this),n&&(t.state.props=n),this.graph.addNode(t)}addNodeAtCoordinates=(t,n={x:0,y:0},s)=>(this.addNode(t,s),t.position&&(t.position=n),t);addConnection(t,n){t.name!=="_node"&&(t.hidden=!1),n.name!=="_node"&&(n.hidden=!1),this.graph.addConnection(t,n)}clear(){this.state.modules={},this.nodes=[],this.connections=[],this.state.script=""}findNodeById(t){return this.graph.findNodeById(t)}findNodeByType(t){return this.codeNodes.find(n=>n.type===t)}getNodesBySameType(t){return this.codeNodes.filter(n=>n.type===t)}getNodesBySameVariableNames(t){return this.codeNodes.filter(n=>n.state.variableName===t)}hasConnection(t,n){return this.connections.some(s=>s.from.id===t.id&&s.to.id===n.id)}loadTemplate(t){t.then(n=>{this._state.template=n.default??""})}removeConnection(t){this.graph.removeConnection(t)}removeNode(t){this.graph.removeNode(t)}renderNodeCodes(){this.state.lockCode||this.codeNodes.length!==0&&this.codeNodes.forEach(t=>t.renderCode())}renderCode(){this.state.lockCode||(this.state.script=x.render(this.state.template||"",this))}resetInputInterfaceScript(){this.codeNodes.forEach(t=>t.resetInputInterfaceScript())}save(){this.state.autosort&&this.sortNodes();const t=this.viewModel.editor.save();return t.graph.id=this.id,this.saveNodeStates(t.graph.nodes),JSON.parse(JSON.stringify(t))}saveNodeStates(t){t.forEach((n,s)=>{const a=this.nodes[s];Object.entries(n.inputs).forEach(([i,d])=>{n.inputs&&a.inputs[i]&&(d.hidden=a.inputs[i].hidden)}),Object.entries(n.outputs).forEach(([i,d])=>{n.outputs&&a.outputs[i]&&(d.hidden=a.outputs[i].hidden)})})}sortNodes(){if(!(this.nodes.length===0||this.connections.length===0))try{const t=this.connections.map(i=>[i.to.nodeId,i.from.nodeId]);let n=[...this.nodeIds];n.reverse(),n=Ce.array(n,t),n.reverse();const s=this.graph.nodes.map(i=>i.id).filter(i=>!n.includes(i));n=n.concat(s);const a=n.map(i=>this.findNodeById(i));a&&(this.nodes=a)}catch{console.warn("Failed to sort nodes.")}}updateCodeNodes(){this.codeNodes.forEach(t=>t.update())}updateCodeTemplates(){this.codeNodes.forEach(t=>t.updateCodeTemplate())}}const L=o=>{let t=[];return o.nodes.forEach(n=>{n.subgraph?t=t.concat(L(n.subgraph)):n.isCodeNode&&t.push(n)}),t},Ae=(o=0,t=100)=>({x:o*420,y:t}),We=o=>{const t={...o.position};return t.x-=440,t.y+=50,t},Xe=o=>{const{calculationOrder:t,connectionsFromNode:n}=l.sortTopologically(o);t.forEach(s=>{if(!s.isCodeNode)return;const a=s;n.has(a)&&n.get(a).forEach(i=>{i.to.state&&i.from.script&&(i.to.state.script=i.from.script)})})},qe=["id"],Ye={class:"align-middle"},Z=e.defineComponent({__name:"CodeGraphNodeInterface",props:{node:{},intf:{}},setup(o){const t=o,{viewModel:n}=l.useViewModel(),{hoveredOver:s,temporaryConnection:a}=l.useTemporaryConnection(),i=e.ref(null),d=e.computed(()=>t.intf.connectionCount>0),c=e.computed(()=>({"--connected":d.value})),m=()=>{s(t.intf)},b=()=>{s(void 0)},_=()=>{i.value&&n.value.hooks.renderInterface.execute({intf:t.intf,el:i.value})};return e.onMounted(_),e.onUpdated(_),(B,V)=>(e.openBlock(),e.createElementBlock("div",{id:o.intf.id,ref_key:"el",ref:i,class:e.normalizeClass(["baklava-node-interface",c.value])},[o.intf.port?(e.openBlock(),e.createElementBlock("div",{key:0,class:e.normalizeClass(["__port",{"--selected":e.unref(a)?.from===o.intf}]),onPointerover:m,onPointerout:b},null,34)):e.createCommentVNode("",!0),e.createElementVNode("span",Ye,[e.renderSlot(B.$slots,"default")])],10,qe))}}),Je={},Ke={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 Qe(o,t){return e.openBlock(),e.createElementBlock("svg",Ke,[...t[0]||(t[0]=[e.createElementVNode("path",{stroke:"none",d:"M0 0h24v24H0z",fill:"none"},null,-1),e.createElementVNode("path",{d:"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 j=E(Je,[["render",Qe]]),Ze={},je={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 et(o,t){return e.openBlock(),e.createElementBlock("svg",je,[...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 ee=E(Ze,[["render",et]]),tt={},nt={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 ot(o,t){return e.openBlock(),e.createElementBlock("svg",nt,[...t[0]||(t[0]=[e.createElementVNode("path",{stroke:"none",d:"M0 0h24v24H0z",fill:"none"},null,-1),e.createElementVNode("path",{d:"M18 3a3 3 0 0 1 2.995 2.824l.005 .176v12a3 3 0 0 1 -2.824 2.995l-.176 .005h-12a3 3 0 0 1 -2.995 -2.824l-.005 -.176v-12a3 3 0 0 1 2.824 -2.995l.176 -.005h12zm0 2h-9v14h9a1 1 0 0 0 .993 -.883l.007 -.117v-12a1 1 0 0 0 -.883 -.993l-.117 -.007zm-2.293 4.293a1 1 0 0 1 .083 1.32l-.083 .094l-1.292 1.293l1.292 1.293a1 1 0 0 1 .083 1.32l-.083 .094a1 1 0 0 1 -1.32 .083l-.094 -.083l-2 -2a1 1 0 0 1 -.083 -1.32l.083 -.094l2 -2a1 1 0 0 1 1.414 0z"},null,-1)])])}const te=E(tt,[["render",ot]]),st={},at={xmlns:"http://www.w3.org/2000/svg",width:"24",height:"24",viewBox:"0 0 24 24",fill:"currentColor",class:"baklava-icon icon icon-tabler icons-tabler-filled icon-tabler-layout-sidebar-left-expand"};function it(o,t){return e.openBlock(),e.createElementBlock("svg",at,[...t[0]||(t[0]=[e.createElementVNode("path",{stroke:"none",d:"M0 0h24v24H0z",fill:"none"},null,-1),e.createElementVNode("path",{d:"M18 3a3 3 0 0 1 2.995 2.824l.005 .176v12a3 3 0 0 1 -2.824 2.995l-.176 .005h-12a3 3 0 0 1 -2.995 -2.824l-.005 -.176v-12a3 3 0 0 1 2.824 -2.995l.176 -.005h12zm0 2h-9v14h9a1 1 0 0 0 .993 -.883l.007 -.117v-12a1 1 0 0 0 -.883 -.993l-.117 -.007zm-4.387 4.21l.094 .083l2 2a1 1 0 0 1 .083 1.32l-.083 .094l-2 2a1 1 0 0 1 -1.497 -1.32l.083 -.094l1.292 -1.293l-1.292 -1.293a1 1 0 0 1 -.083 -1.32l.083 -.094a1 1 0 0 1 1.32 -.083z"},null,-1)])])}const ne=E(st,[["render",it]]),rt={},lt={xmlns:"http://www.w3.org/2000/svg",width:"24",height:"24",viewBox:"0 0 24 24",fill:"currentColor",class:"baklava-icon icon icon-tabler icons-tabler-filled icon-tabler-layout-sidebar-right"};function dt(o,t){return e.openBlock(),e.createElementBlock("svg",lt,[...t[0]||(t[0]=[e.createElementVNode("path",{stroke:"none",d:"M0 0h24v24H0z",fill:"none"},null,-1),e.createElementVNode("path",{d:"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 oe=E(rt,[["render",dt]]),ct={},pt={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 ut(o,t){return e.openBlock(),e.createElementBlock("svg",pt,[...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=E(ct,[["render",ut]]),ht={},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-right-expand"};function ft(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 -.005h12zm-3 2h-9a1 1 0 0 0 -.993 .883l-.007 .117v12a1 1 0 0 0 .883 .993l.117 .007h9v-14zm-3.293 4.293a1 1 0 0 1 .083 1.32l-.083 .094l-1.292 1.293l1.292 1.293a1 1 0 0 1 .083 1.32l-.083 .094a1 1 0 0 1 -1.32 .083l-.094 -.083l-2 -2a1 1 0 0 1 -.083 -1.32l.083 -.094l2 -2a1 1 0 0 1 1.414 0z"},null,-1)])])}const ae=E(ht,[["render",ft]]),gt={},yt={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 kt(o,t){return e.openBlock(),e.createElementBlock("svg",yt,[...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 ie=E(gt,[["render",kt]]),bt={},Nt={xmlns:"http://www.w3.org/2000/svg",width:"24",height:"24",viewBox:"0 0 24 24",fill:"none",stroke:"currentColor","stroke-width":"2","stroke-linecap":"round","stroke-linejoin":"round",class:"baklava-icon icon icon-tabler icons-tabler-outline icon-tabler-schema"};function _t(o,t){return e.openBlock(),e.createElementBlock("svg",Nt,[...t[0]||(t[0]=[e.createStaticVNode('<path stroke="none" d="M0 0h24v24H0z" fill="none"></path><path d="M5 2h5v4h-5z"></path><path d="M15 10h5v4h-5z"></path><path d="M5 18h5v4h-5z"></path><path d="M5 10h5v4h-5z"></path><path d="M10 12h5"></path><path d="M7.5 6v4"></path><path d="M7.5 14v4"></path>',8)])])}const re=E(bt,[["render",_t]]),Ct={},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-schema-off"};function It(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="M6 2h4v4m-4 0h-1v-1"></path><path d="M15 11v-1h5v4h-2"></path><path d="M5 18h5v4h-5z"></path><path d="M5 10h5v4h-5z"></path><path d="M10 12h2"></path><path d="M7.5 7.5v2.5"></path><path d="M7.5 14v4"></path><path d="M3 3l18 18"></path>',9)])])}const le=E(Ct,[["render",It]]),Et={},Bt={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 Vt(o,t){return e.openBlock(),e.createElementBlock("svg",Bt,[...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 de=E(Et,[["render",Vt]]),xt={},Mt={xmlns:"http://www.w3.org/2000/svg",width:"24",height:"24",viewBox:"0 0 24 24",fill:"none",stroke:"currentColor","stroke-width":"2","stroke-linecap":"round","stroke-linejoin":"round",class:"baklava-icon icon icon-tabler icons-tabler-outline icon-tabler-trash-off"};function Tt(o,t){return e.openBlock(),e.createElementBlock("svg",Mt,[...t[0]||(t[0]=[e.createStaticVNode('<path stroke="none" d="M0 0h24v24H0z" fill="none"></path><path d="M3 3l18 18"></path><path d="M4 7h3m4 0h9"></path><path d="M10 11l0 6"></path><path d="M14 14l0 3"></path><path d="M5 7l1 12a2 2 0 0 0 2 2h8a2 2 0 0 0 2 -2l.077 -.923"></path><path d="M18.384 14.373l.616 -7.373"></path><path d="M9 5v-1a1 1 0 0 1 1 -1h4a1 1 0 0 1 1 1v3"></path>',8)])])}const ce=E(xt,[["render",Tt]]),$t=["id","data-node-type"],Ot={class:"__title-label",style:{"flex-grow":"1"}},St={key:0},vt={class:"__menu",style:{display:"flex"}},zt={class:"__outputs"},Lt={key:0},Rt=["id","title"],Dt={class:"__inputs"},Ut={key:0},Gt=["id","title"],Pt=e.defineComponent({__name:"CodeGraphNode",props:{node:{},selected:{type:Boolean,default:!1},dragging:{type:Boolean}},emits:["select","start-drag","update"],setup(o,{emit:t}){const n=l.Components.ContextMenu,s=l.Components.NodeInterface,a=o,i=e.computed(()=>a.node),d=t,{viewModel:c}=l.useViewModel(),{graph:m,switchGraph:b}=l.useGraph(),_=e.ref(null),B=e.ref(!1),V=e.ref(""),w=e.ref(null),f=e.ref(!1);let k=0,C=0;const g=e.ref(!1),N=e.computed(()=>{const p=[{value:"edit",label:"Edit"},{value:"rename",label:"Rename"},{value:"delete",label:"Delete"}];return a.node.type.startsWith(l.GRAPH_NODE_TYPE_PREFIX)&&p.push({value:"editSubgraph",label:"Edit Subgraph"}),p}),u=e.computed(()=>({"--selected":a.selected,"--dragging":a.dragging,"--two-column":!!a.node.twoColumn,"--hidden":i.value.state?.hidden})),I=e.computed(()=>({"--reverse-y":a.node.reverseY??c.value.settings.nodes.reverseY})),un=e.computed(()=>({top:`${a.node.position?.y??0}px`,left:`${a.node.position?.x??0}px`,"--width":`${a.node.width??c.value.settings.nodes.defaultWidth}px`})),hn=e.computed(()=>Object.values(a.node.inputs).filter(p=>!p.hidden)),mn=e.computed(()=>Object.values(a.node.outputs).filter(p=>!p.hidden)),me=()=>{d("select")},fn=p=>{a.selected||me(),d("start-drag",p)},fe=()=>{g.value=!0},gn=()=>{const p=c.value.displayedGraph.sidebar;p.nodeId="",p.visible=!1},ge=()=>{const p=c.value.displayedGraph.sidebar;p.nodeId=a.node.id,p.visible=!0},yn=()=>{const p=c.value.displayedGraph.sidebar;p.nodeId=a.node.id},kn=async p=>{switch(p){case"edit":ge();break;case"delete":m.value.removeNode(a.node);break;case"rename":V.value=a.node.title,B.value=!0,await e.nextTick(),w.value?.focus();break;case"editSubgraph":b(a.node.template);break}},ye=()=>{i.value.title=V.value,B.value=!1},ke=()=>{_.value&&c.value.hooks.renderNode.execute({node:a.node,el:_.value})},bn=p=>{f.value=!0,k=a.node.width,C=p.clientX,p.preventDefault()},be=p=>{i.value.state&&(i.value.state.integrated=p,d("update"))},Ne=p=>{if(!f.value)return;const y=p.clientX-C,h=k+y/m.value.scaling,Nn=c.value.settings.nodes.minWidth,_n=c.value.settings.nodes.maxWidth;i.value.width=Math.max(Nn,Math.min(_n,h))},_e=()=>{f.value=!1};return e.onMounted(()=>{ke(),window.addEventListener("mousemove",Ne),window.addEventListener("mouseup",_e)}),e.onUpdated(ke),e.onBeforeUnmount(()=>{window.removeEventListener("mousemove",Ne),window.removeEventListener("mouseup",_e)}),(p,y)=>(e.openBlock(),e.createElementBlock("div",{id:i.value.id,ref_key:"el",ref:_,class:e.normalizeClass([u.value,"baklava-node"]),"data-node-type":i.value.type,style:e.normalizeStyle(un.value),onPointerdown:me},[e.unref(c).settings.nodes.resizable?(e.openBlock(),e.createElementBlock("div",{key:0,class:"__resize-handle",onMousedown:bn},null,32)):e.createCommentVNode("",!0),e.createElementVNode("div",{class:"__title",onPointerdown:e.withModifiers(fn,["self","stop"]),onContextmenu:e.withModifiers(fe,["prevent"])},[i.value.inputs._node?(e.openBlock(),e.createBlock(Z,{key:0,node:i.value,intf:i.value.inputs._node,class:"--input","data-interface-type":"node",style:{"flex-grow":"0"}},null,8,["node","intf"])):e.createCommentVNode("",!0),B.value?e.withDirectives((e.openBlock(),e.createElementBlock("input",{key:2,ref_key:"renameInputEl",ref:w,"onUpdate:modelValue":y[4]||(y[4]=h=>V.value=h),class:"baklava-input",placeholder:"Node Name",style:{"flex-grow":"1"},type:"text",onBlur:ye,onKeydown:e.withKeys(ye,["enter"])},null,544)),[[e.vModelText,V.value]]):(e.openBlock(),e.createElementBlock(e.Fragment,{key:1},[e.createElementVNode("div",Ot,[i.value.idx>-1?(e.openBlock(),e.createElementBlock("span",St,e.toDisplayString(i.value.idx+1)+" - ",1)):e.createCommentVNode("",!0),e.createTextVNode(e.toDisplayString(i.value.title),1)]),e.createElementVNode("div",vt,[i.value.subgraph?e.createCommentVNode("",!0):(e.openBlock(),e.createElementBlock(e.Fragment,{key:0},[i.value.state.lockCode?(e.openBlock(),e.createBlock(e.unref(ie),{key:0,class:"--clickable mx-1",onClick:y[0]||(y[0]=h=>i.value.lockCode=!1)})):e.createCommentVNode("",!0),i.value.state.integrated?(e.openBlock(),e.createBlock(e.unref(j),{key:1,class:"--clickable mx-1",onClick:y[1]||(y[1]=h=>be(!1))})):(e.openBlock(),e.createBlock(e.unref(de),{key:2,class:"--clickable mx-1",onClick:y[2]||(y[2]=h=>be(!0))})),!e.unref(c).displayedGraph.sidebar.visible&&e.unref(c).displayedGraph.sidebar.nodeId!==i.value.id?(e.openBlock(),e.createBlock(e.unref(ae),{key:3,class:"--clickable mx-1",onClick:ge})):e.unref(c).displayedGraph.sidebar.visible&&e.unref(c).displayedGraph.sidebar.nodeId!==i.value.id?(e.openBlock(),e.createBlock(e.unref(oe),{key:4,class:"--clickable mx-1",onClick:yn})):(e.openBlock(),e.createBlock(e.unref(se),{key:5,class:"--clickable mx-1",onClick:gn}))],64)),e.createVNode(e.unref(ee),{class:"--clickable mx-1",onClick:fe}),e.createVNode(e.unref(n),{modelValue:g.value,"onUpdate:modelValue":y[3]||(y[3]=h=>g.value=h),x:0,y:0,items:N.value,onClick:kn},null,8,["modelValue","items"])])],64)),i.value.outputs._node?(e.openBlock(),e.createBlock(Z,{key:3,node:i.value,intf:i.value.outputs._node,class:"--output","data-interface-type":"node"},null,8,["node","intf"])):e.createCommentVNode("",!0)],32),e.createElementVNode("div",{class:e.normalizeClass(["__content",I.value]),onKeydown:y[5]||(y[5]=e.withKeys(e.withModifiers(()=>{},["stop"]),["delete"])),onContextmenu:y[6]||(y[6]=e.withModifiers(()=>{},["prevent"]))},[e.createElementVNode("div",zt,[(e.openBlock(!0),e.createElementBlock(e.Fragment,null,e.renderList(mn.value,h=>(e.openBlock(),e.createElementBlock(e.Fragment,{key:h.id},[i.value.state?.hidden?(e.openBlock(),e.createElementBlock("div",Lt,[h.port?(e.openBlock(),e.createElementBlock("div",{key:0,id:h.id,title:h.name,class:"baklava-node-interface --output --connected"},[...y[7]||(y[7]=[e.createElementVNode("div",{class:"__port"},null,-1)])],8,Rt)):e.createCommentVNode("",!0)])):e.renderSlot(p.$slots,"nodeInterface",{key:1,type:"output",node:i.value,intf:h},()=>[e.createVNode(e.unref(s),{node:i.value,intf:h,title:h.type},null,8,["node","intf","title"])])],64))),128))]),e.createElementVNode("div",Dt,[(e.openBlock(!0),e.createElementBlock(e.Fragment,null,e.renderList(hn.value,h=>(e.openBlock(),e.createElementBlock(e.Fragment,{key:h.id},[i.value.state?.hidden?(e.openBlock(),e.createElementBlock("div",Ut,[h.port?(e.openBlock(),e.createElementBlock("div",{key:0,id:h.id,title:h.name,class:"baklava-node-interface --input --connected"},[...y[8]||(y[8]=[e.createElementVNode("div",{class:"__port"},null,-1)])],8,Gt)):e.createCommentVNode("",!0)])):e.renderSlot(p.$slots,"nodeInterface",{key:1,node:i.value,intf:h,type:"input"},()=>[e.createVNode(e.unref(s),{node:i.value,intf:h,title:h.type},null,8,["node","intf","title"])])],64))),128))])],34)],46,$t))}}),Ft=["title"],Ht={key:0,class:"__label"},pe=e.defineComponent({__name:"Checkbox",props:{disabled:{type:Boolean},inversed:{type:Boolean},modelValue:{type:Boolean},name:{}},emits:["update:modelValue"],setup(o,{emit:t}){const n=t;return(s,a)=>(e.openBlock(),e.createElementBlock("div",{class:e.normalizeClass(["baklava-checkbox",{"--checked":o.inversed?!o.modelValue:o.modelValue,"--disabled":o.disabled}]),title:o.name,onClick:a[0]||(a[0]=i=>n("update:modelValue",!o.modelValue))},[a[1]||(a[1]=e.createElementVNode("div",{class:"__checkmark-container"},[e.createElementVNode("svg",{xmlns:"http://www.w3.org/2000/svg",width:"18",height:"18",viewBox:"0 0 18 18"},[e.createElementVNode("path",{class:"__checkmark",d:"M 6 5 L 6 10 L 16 10",transform:"rotate(-45 10 10)"})])],-1)),o.name?(e.openBlock(),e.createElementBlock("div",Ht,e.toDisplayString(o.name),1)):e.createCommentVNode("",!0)],10,Ft))}}),At={class:"__header"},Wt={class:"__node-name"},Xt={class:"__interfaces"},qt={class:"__inputs"},Yt={style:{display:"flex"}},Jt={class:"__outputs"},Kt={key:0,class:"__interface"},Qt={style:{display:"flex"}},Zt=e.defineComponent({__name:"CodeGraphSidebar",setup(o){const{viewModel:t}=l.useViewModel(),{graph:n}=l.useGraph(),s=e.ref(null),a=e.toRef(t.value.settings.sidebar,"width"),i=e.computed(()=>t.value.settings.sidebar.resizable);let d=0,c=0;const m=e.computed(()=>{const g=n.value.sidebar.nodeId;return n.value.nodes.find(N=>N.id===g)}),b=e.computed(()=>m.value),_=e.computed(()=>({width:`${a.value}px`})),B=e.computed(()=>b.value?Object.values(b.value.inputs).filter(g=>g.displayInSidebar&&g.component):[]),V=e.computed(()=>b.value?Object.values(b.value.outputs).filter(g=>g.displayInSidebar&&g.component):[]),w=()=>{n.value.sidebar.visible=!1},f=()=>{m.value?.events.update.emit(null)},k=g=>{d=a.value,c=g.clientX,window.addEventListener("mousemove",C),window.addEventListener("mouseup",()=>{window.removeEventListener("mousemove",C)},{once:!0})},C=g=>{const N=s.value?.parentElement?.getBoundingClientRect().width??500,u=g.clientX-c;let I=d-u;I<300?I=300:I>.9*N&&(I=.9*N),a.value=I};return(g,N)=>(e.openBlock(),e.createElementBlock("div",{class:e.normalizeClass([{"--open":e.unref(n).sidebar.visible},"baklava-sidebar"]),style:e.normalizeStyle(_.value),ref_key:"el",ref:s},[i.value?(e.openBlock(),e.createElementBlock("div",{key:0,class:"__resizer",onMousedown:k},null,32)):e.createCommentVNode("",!0),m.value?(e.openBlock(),e.createElementBlock(e.Fragment,{key:1},[e.createElementVNode("div",At,[e.createElementVNode("button",{tabindex:"-1",class:"__close",onClick:w},"×"),e.createElementVNode("div",Wt,[e.createElementVNode("b",null,e.toDisplayString(m.value.title),1)])]),e.createElementVNode("div",Xt,[e.createElementVNode("div",qt,[(e.openBlock(!0),e.createElementBlock(e.Fragment,null,e.renderList(B.value,u=>(e.openBlock(),e.createElementBlock("div",{key:u.id,class:"__interface"},[e.createElementVNode("div",Yt,[e.createVNode(pe,{modelValue:u.hidden,"onUpdate:modelValue":[I=>u.hidden=I,N[0]||(N[0]=()=>m.value?.events.update.emit(null))],disabled:!u.optional,inversed:"",style:{"padding-right":"8px"}},null,8,["modelValue","onUpdate:modelValue","disabled"]),(e.openBlock(),e.createBlock(e.resolveDynamicComponent(u.component),{modelValue:u.value,"onUpdate:modelValue":I=>u.value=I,node:m.value,intf:u,style:{width:"100%"}},null,8,["modelValue","onUpdate:modelValue","node","intf"]))])]))),128))]),e.createElementVNode("div",Jt,[b.value&&b.value.state?(e.openBlock(),e.createElementBlock("div",Kt,[N[3]||(N[3]=e.createElementVNode("label",null,"Variable name",-1)),e.withDirectives(e.createElementVNode("input",{"onUpdate:modelValue":N[1]||(N[1]=u=>b.value.state.variableName=u),type:"text",class:"baklava-input",title:"Variable name",onBlur:f,onKeydown:e.withKeys(f,["enter"])},null,544),[[e.vModelText,b.value.state.variableName]])])):e.createCommentVNode("",!0),(e.openBlock(!0),e.createElementBlock(e.Fragment,null,e.renderList(V.value,u=>(e.openBlock(),e.createElementBlock("div",{key:u.id,class:"__interface"},[e.createElementVNode("div",Qt,[e.createVNode(pe,{modelValue:u.hidden,"onUpdate:modelValue":[I=>u.hidden=I,N[2]||(N[2]=()=>m.value?.events.update.emit(null))],disabled:!u.optional,inversed:"",style:{"padding-right":"8px"}},null,8,["modelValue","onUpdate:modelValue","disabled"]),(e.openBlock(),e.createBlock(e.resolveDynamicComponent(u.component),{modelValue:u.value,"onUpdate:modelValue":I=>u.value=I,node:m.value,intf:u,style:{width:"100%"}},null,8,["modelValue","onUpdate:modelValue","node","intf"]))])]))),128))])]),e.renderSlot(g.$slots,"codeEditor",{node:m.value})],64)):e.createCommentVNode("",!0)],6))}}),jt=e.defineComponent({props:{type:{type:String,required:!0},title:{type:String,required:!0}},setup(o){const{viewModel:t}=l.useViewModel(),{switchGraph:n}=l.useGraph(),s=e.ref(!1),a=e.computed(()=>o.type.startsWith(l.GRAPH_NODE_TYPE_PREFIX));return{showContextMenu:s,hasContextMenu:a,contextMenuItems:[{label:"Edit Subgraph",value:"editSubgraph"},{label:"Delete Subgraph",value:"deleteSubgraph"}],openContextMenu:()=>{s.value=!0},onContextMenuClick:m=>{const b=o.type.substring(l.GRAPH_NODE_TYPE_PREFIX.length),_=t.value.editor.graphTemplates.find(B=>B.id===b);if(_)switch(m){case"editSubgraph":n(_);break;case"deleteSubgraph":t.value.editor.removeGraphTemplate(_);break}}}}}),en=["data-node-type"],tn={class:"__title"},nn={class:"__title-label"};function on(o,t,n,s,a,i){return e.openBlock(),e.createElementBlock("div",{class:"baklava-node --palette","data-node-type":o.type},[e.createElementVNode("div",tn,[e.createElementVNode("div",nn,e.toDisplayString(o.title),1)])],8,en)}const ue=E(jt,[["render",on]]),sn={class:"baklava-node --palette",style:{"margin-top":"-20px","margin-bottom":"20px"}},an={key:0,style:{display:"flex","justify-content":"space-between"}},rn=["onClick"],ln={key:0,style:{margin:"auto 0","font-size":"12px"}},dn=e.defineComponent({__name:"CodeNodePalette",setup(o){const{viewModel:t}=l.useViewModel(),{x:n,y:s}=Ie.usePointer(),{transform:a}=l.useTransform(),i=l.useNodeCategories(t),d=e.inject("editorEl"),c=e.ref(""),m=e.ref(null),b=()=>c.value?i.value.filter(w=>w.name.toLowerCase().includes(c.value.toLowerCase())||Object.values(w.nodeTypes).some(f=>f.title.toLowerCase().includes(c.value.toLowerCase()))):i.value,_=w=>c.value?Object.values(w).filter(f=>f.category.toLowerCase().includes(c.value.toLowerCase())||f.title.toLowerCase().includes(c.value.toLowerCase())):Object.values(w),B=e.computed(()=>{if(!m.value||!d?.value)return{};const{left:w,top:f}=d.value.getBoundingClientRect();return{top:`${s.value-f}px`,left:`${n.value-w}px`}}),V=(w,f)=>{m.value={type:w,nodeInformation:f};const k=()=>{const C=e.reactive(new f.type);t.value.displayedGraph.addNode(C);const g=d.value.getBoundingClientRect(),[N,u]=a(n.value-g.left,s.value-g.top);C.position.x=N,C.position.y=u,m.value=null,document.removeEventListener("pointerup",k)};document.addEventListener("pointerup",k)};return(w,f)=>(e.openBlock(),e.createElementBlock(e.Fragment,null,[e.createElementVNode("div",{class:e.normalizeClass([{"--open":e.unref(t).settings.palette.enabled},"baklava-node-palette"]),onContextmenu:f[1]||(f[1]=e.withModifiers(()=>{},["stop","prevent"]))},[e.createElementVNode("div",sn,[e.withDirectives(e.createElementVNode("input",{"onUpdate:modelValue":f[0]||(f[0]=k=>c.value=k),type:"text",class:"baklava-input",title:"Filter nodes",onKeyup:b},null,544),[[e.vModelText,c.value]])]),(e.openBlock(!0),e.createElementBlock(e.Fragment,null,e.renderList(b(),k=>(e.openBlock(),e.createElementBlock("section",{key:k.name},[k.name!=="default"?(e.openBlock(),e.createElementBlock("h3",an,[e.createElementVNode("div",{onClick:C=>c.value=k.name,style:{cursor:"pointer"}},e.toDisplayString(k.name),9,rn),_(k.nodeTypes).length<Object.values(k.nodeTypes).length?(e.openBlock(),e.createElementBlock("div",ln," ( "+e.toDisplayString(_(k.nodeTypes).length)+" / "+e.toDisplayString(Object.values(k.nodeTypes).length)+" ) ",1)):e.createCommentVNode("",!0)])):e.createCommentVNode("",!0),(e.openBlock(!0),e.createElementBlock(e.Fragment,null,e.renderList(_(k.nodeTypes),C=>(e.openBlock(),e.createBlock(ue,{key:C.type,type:C.type,title:C.title,onPointerdown:g=>V(C.type,C)},null,8,["type","title","onPointerdown"]))),128))]))),128))],34),e.createVNode(e.Transition,{name:"fade"},{default:e.withCtx(()=>[m.value?(e.openBlock(),e.createElementBlock("div",{key:0,class:"baklava-dragged-node",style:e.normalizeStyle(B.value)},[e.createVNode(ue,{type:m.value.type,title:m.value.nodeInformation.title},null,8,["type","title"])],4)):e.createCommentVNode("",!0)]),_:1})],64))}}),cn=e.defineComponent({__name:"CodeGraphEditor",props:{viewModel:{}},setup(o){const t=o,n=e.toRef(t,"viewModel"),s=a=>a.events.update.emit(null);return e.onMounted(()=>{n.value.subscribe(),n.value.engine.start()}),e.onUnmounted(()=>{n.value.unsubscribe(),n.value.engine.stop()}),(a,i)=>(e.openBlock(),e.createBlock(e.unref(l.BaklavaEditor),{"view-model":n.value},{palette:e.withCtx(()=>[e.createVNode(dn)]),node:e.withCtx(d=>[e.createVNode(Pt,e.mergeProps(d,{onUpdate:c=>s(d.node)}),null,16,["onUpdate"])]),sidebar:e.withCtx(d=>[e.createVNode(Zt,e.normalizeProps(e.guardReactiveProps(d)),{codeEditor:e.withCtx(({node:c})=>[e.renderSlot(a.$slots,"sidebarCodeEditor",{node:c})]),_:3},16)]),_:3},8,["view-model"]))}});function pn(o){const t=l.useBaklava(o?.existingEditor);t.code=o?.code?new o.code(t):new Q(t),he(t);const n={};return Object.keys(O).forEach(s=>{n[s]=typeof O[s]=="object"?{...t.settings[s],...O[s]}:O[s]}),t.settings=e.reactive({...t.settings,...n}),t.settings.nodes.defaultWidth=350,t.state=e.reactive({modules:{},token:null}),t.init=()=>{t.unsubscribe(),t.engine=new l.DependencyEngine(t.editor)},t.subscribe=()=>{t.state.token&&t.unsubscribe();const s=Symbol(),a=t.displayedGraph;a.events.addNode.subscribe(s,i=>{i.code=t.code}),a.events.addConnection.subscribe(s,i=>{t.code.findNodeById(i.to.nodeId)?.onConnected(),t.code.findNodeById(i.from.nodeId)?.onConnected()}),a.events.removeConnection.subscribe(s,i=>{t.code.findNodeById(i.to.nodeId)?.onUnconnected(),t.code.findNodeById(i.from.nodeId)?.onUnconnected()}),t.engine.events.beforeRun.subscribe(s,()=>{t.engine.pause(),t.code&&(t.code.updateCodeNodes(),t.code.sortNodes(),t.code.updateCodeTemplates(),t.code.resetInputInterfaceScript()),t.engine.resume()}),t.engine.events.beforeNodeCalculation.subscribe(s,i=>{t.engine.pause();const d=i.node;d.isCodeNode&&(d.updateOutputNames(),d.updateConnectedInputInterfaces()),t.engine.resume()}),t.engine.events.afterRun.subscribe(s,i=>{t.engine.pause(),l.applyResult(i,t.editor),t.code&&(t.code.renderNodeCodes(),t.code.renderCode()),t.engine.resume()}),t.state.token=s},t.unsubscribe=()=>{if(!t.state.token)return;const s=t.state.token;t.displayedGraph.events.addNode.unsubscribe(s),t.displayedGraph.events.addConnection.unsubscribe(s),t.engine.events.beforeRun.unsubscribe(s),t.engine.events.afterRun.unsubscribe(s),t.state.token=null},t}const he=o=>{const t="TOGGLE_PALETTE";o.commandHandler.registerCommand(t,{execute:()=>o.settings.palette.enabled=!o.settings.palette.enabled,canExecute:()=>!0});const n="CLEAR_ALL";o.commandHandler.registerCommand(n,{execute:()=>o.code.clear(),canExecute:()=>o.displayedGraph.nodes.length>0});const s="TOGGLE_MINIMAP";o.commandHandler.registerCommand(s,{execute:()=>o.settings.enableMinimap=!o.settings.enableMinimap,canExecute:()=>o.displayedGraph.nodes.length>1}),o.settings.toolbar.commands=[{command:t,title:"Toggle palette",icon:e.computed(()=>o.settings.palette.enabled?te:ne)},...l.DEFAULT_TOOLBAR_COMMANDS,{command:n,title:"Clear all",icon:ce},{command:s,title:"Toggle minimap",icon:e.computed(()=>o.settings.enableMinimap?le:re)}]},O={enableMinimap:!1,toolbar:{enabled:!0},palette:{enabled:!0},sidebar:{enabled:!0,resizable:!0,width:350},displayValueOnHover:!1};r.AbstractCodeNode=A,r.CheckboxInterface=xe,r.Code=Q,r.CodeGraphEditor=cn,r.CodeNode=R,r.CodeNodeInputInterface=T,r.CodeNodeInterface=M,r.CodeNodeInterfaceComponent=S,r.CodeNodeOutputInterface=Y,r.CodeVariable=j,r.DEFAULT_SETTINGS=O,r.DotsVertical=ee,r.DynamicCodeNode=K,r.IntegerInterface=Me,r.LayoutSidebarLeftCollapse=te,r.LayoutSidebarLeftExpand=ne,r.LayoutSidebarRight=oe,r.LayoutSidebarRightCollapse=se,r.LayoutSidebarRightExpand=ae,r.ListInputInterface=Te,r.LockCode=ie,r.NumberInterface=$e,r.Schema=re,r.SchemaOff=le,r.SelectInterface=Oe,r.SliderInterface=Se,r.TextInputInterface=Ue,r.TextInputInterfaceComponent=J,r.TextareaInputInterface=Ge,r.TransitionBottom=de,r.TrashOff=ce,r.TupleInputInterface=Pe,r.addDefaultInterfaceTypes=Ve,r.addToolbarCommands=he,r.booleanType=U,r.defineCodeNode=Fe,r.defineDynamicCodeNode=He,r.dictType=q,r.formatInputs=W,r.getCodeNodes=L,r.getPositionAtColumn=Ae,r.getPositionBeforeNode=We,r.listType=G,r.loadNodeState=D,r.nodeType=$,r.numberType=v,r.saveNodeState=X,r.setOptional=Be,r.stringType=z,r.transferCodeScript=Xe,r.tupleType=P,r.useCodeGraph=pn,Object.defineProperty(r,Symbol.toStringTag,{value:"Module"})}));
package/dist/code.d.ts CHANGED
@@ -7,7 +7,7 @@ interface IPosition {
7
7
  x: number;
8
8
  y: number;
9
9
  }
10
- interface ICodeState {
10
+ export interface ICodeState {
11
11
  autosort: boolean;
12
12
  lockCode: boolean;
13
13
  modules: Record<string, string>;
@@ -2,7 +2,7 @@ import { AbstractNode, Graph, NodeInterface, CalculateFunction, INodeState, Node
2
2
  import { UnwrapRef } from 'vue';
3
3
  import { Code } from '../code';
4
4
  import { CodeNodeInputInterface, CodeNodeOutputInterface } from '../codeNodeInterfaces';
5
- interface IAbstractCodeNodeState {
5
+ export interface IAbstractCodeNodeState {
6
6
  codeTemplate: string;
7
7
  hidden: boolean;
8
8
  integrated: boolean;
@@ -109,4 +109,3 @@ export declare const loadNodeState: (graph: Graph | undefined, nodeState: ICodeN
109
109
  * @param nodeState node state
110
110
  */
111
111
  export declare const saveNodeState: (graph: Graph | undefined, nodeState: ICodeNodeState<unknown, unknown>) => void;
112
- export {};
@@ -2,7 +2,7 @@ import { NodeInterface } from 'baklavajs';
2
2
  import { UnwrapRef } from 'vue';
3
3
  import { default as CodeNodeInterfaceComponent } from './CodeNodeInterface.vue';
4
4
  import { Code } from '../../code';
5
- interface ICodeNodeInterfaceState {
5
+ export interface ICodeNodeInterfaceState {
6
6
  optional: boolean;
7
7
  script: string;
8
8
  }
@@ -17,6 +17,7 @@ export declare class CodeNodeInterface<T = unknown> extends NodeInterface<T> {
17
17
  set script(value: string);
18
18
  get shortId(): string;
19
19
  getValue: () => string;
20
+ resetScript: () => string;
20
21
  }
21
22
  export { CodeNodeInterfaceComponent };
22
23
  export declare const setOptional: (intf: CodeNodeInterface, value: boolean) => void;
Binary file
package/dist/index.d.ts CHANGED
@@ -1,8 +1,11 @@
1
+ /**
2
+ * @module @babsey/code-graph
3
+ */
4
+ export * from './code';
1
5
  export * from './codeNode';
2
6
  export * from './codeNodeInterfaces';
3
- export * from './code';
4
7
  export * from './components';
5
8
  export * from './icons';
6
9
  export * from './interfaceTypes';
7
- export * from './viewModel';
8
10
  export * from './settings';
11
+ export * from './viewModel';
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@babsey/code-graph",
3
- "version": "0.1.3",
3
+ "version": "0.1.4",
4
4
  "author": "babsey <spreizer@web.de>",
5
5
  "license": "MIT",
6
6
  "type": "module",
@@ -12,6 +12,7 @@
12
12
  },
13
13
  "main": "./dist/code-mirror.umd.cjs",
14
14
  "module": "./dist/code-graph.js",
15
+ "types": "./dist/index.d.ts",
15
16
  "exports": {
16
17
  ".": {
17
18
  "types": "./dist/lib/index.d.ts",
@@ -45,14 +46,14 @@
45
46
  "devDependencies": {
46
47
  "@tsconfig/node-lts": "~22.0",
47
48
  "@types/mustache": "~4.2",
48
- "@types/node": "~24.8",
49
+ "@types/node": "~24.9",
49
50
  "@types/toposort": "~2.0",
50
51
  "@vitejs/plugin-vue": "~6.0",
51
52
  "@vue/eslint-config-prettier": "~10.2",
52
53
  "@vue/eslint-config-typescript": "~14.6",
53
54
  "@vue/language-core": "~3.1",
54
55
  "@vue/tsconfig": "~0.8",
55
- "eslint": "~9.37",
56
+ "eslint": "~9.38",
56
57
  "eslint-plugin-vue": "~10.5",
57
58
  "jiti": "~2.6",
58
59
  "npm-run-all2": "~8.0",