@bemedev/mind-flow 0.1.0 → 0.3.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (51) hide show
  1. package/README.md +10 -10
  2. package/lib/helpers/createContext.d.ts +7 -2
  3. package/lib/helpers/createContext.d.ts.map +1 -1
  4. package/lib/index.cjs.js +1 -1
  5. package/lib/index.es.js +556 -510
  6. package/lib/output.css +1 -1
  7. package/lib/server.cjs.js +653 -397
  8. package/lib/server.es.js +657 -401
  9. package/lib/services/main.machine.d.ts +4857 -218
  10. package/lib/services/main.machine.d.ts.map +1 -1
  11. package/lib/{ui/components/FlowChart.data.d.ts → services/main.machine.data.d.ts} +8 -3
  12. package/lib/services/main.machine.data.d.ts.map +1 -0
  13. package/lib/services/main.machine.helpers.d.ts +32 -0
  14. package/lib/services/main.machine.helpers.d.ts.map +1 -0
  15. package/lib/services/main.machine.typings.d.ts +126 -0
  16. package/lib/services/main.machine.typings.d.ts.map +1 -0
  17. package/lib/ui/Flow.d.ts +2 -0
  18. package/lib/ui/Flow.d.ts.map +1 -1
  19. package/lib/ui/components/Bounds.d.ts +2 -0
  20. package/lib/ui/components/Bounds.d.ts.map +1 -1
  21. package/lib/ui/components/EdgeComponent.d.ts +3 -2
  22. package/lib/ui/components/EdgeComponent.d.ts.map +1 -1
  23. package/lib/ui/components/EdgesBoard.d.ts +2 -0
  24. package/lib/ui/components/EdgesBoard.d.ts.map +1 -1
  25. package/lib/ui/components/FlowChart.context.d.ts +5608 -996
  26. package/lib/ui/components/FlowChart.context.d.ts.map +1 -1
  27. package/lib/ui/components/FlowChart.d.ts +3 -1
  28. package/lib/ui/components/FlowChart.d.ts.map +1 -1
  29. package/lib/ui/components/NodeComponent.d.ts +2 -10
  30. package/lib/ui/components/NodeComponent.d.ts.map +1 -1
  31. package/lib/ui/components/NodesBoard.d.ts +2 -0
  32. package/lib/ui/components/NodesBoard.d.ts.map +1 -1
  33. package/package.json +9 -15
  34. package/src/helpers/createContext.ts +7 -2
  35. package/src/{ui/components/FlowChart.data.ts → services/main.machine.data.ts} +7 -2
  36. package/src/services/main.machine.helpers.ts +55 -0
  37. package/src/services/main.machine.ts +288 -70
  38. package/src/services/main.machine.typings.ts +98 -0
  39. package/src/ui/Flow.tsx +2 -0
  40. package/src/ui/components/Bounds.tsx +13 -8
  41. package/src/ui/components/EdgeComponent.tsx +78 -56
  42. package/src/ui/components/EdgesBoard.tsx +13 -36
  43. package/src/ui/components/FlowChart.context.ts +204 -291
  44. package/src/ui/components/FlowChart.tsx +16 -16
  45. package/src/ui/components/NodeComponent.tsx +60 -104
  46. package/src/ui/components/NodesBoard.tsx +85 -47
  47. package/src/ui/components/classes.ts +1 -1
  48. package/lib/services/main.typings.d.ts +0 -68
  49. package/lib/services/main.typings.d.ts.map +0 -1
  50. package/lib/ui/components/FlowChart.data.d.ts.map +0 -1
  51. package/src/services/main.typings.ts +0 -50
package/lib/index.es.js CHANGED
@@ -1,33 +1,32 @@
1
1
  import { classList as e, createComponent as t, delegateEvents as n, effect as r, getNextElement as i, getNextMarker as a, insert as o, runHydrationEvents as s, setAttribute as c, setStyleProperty as l, template as u, use as d } from "solid-js/web";
2
- import { For as f, Show as p, createContext as m, createEffect as h, createMemo as g, createSignal as _, on as v, onCleanup as y, onMount as b, useContext as x } from "solid-js";
3
- import { createMachine as S, interpret as C } from "@bemedev/app";
4
- import { produce as w } from "solid-js/store";
5
- import { type as T } from "@bemedev/app/bemedev";
6
- import { useState as E } from "@bemedev/app-solidjs";
2
+ import { createState as f } from "@bemedev/app-solidjs";
3
+ import { For as p, Show as m, createContext as h, createEffect as g, createSignal as _, on as v, onCleanup as y, onMount as b, useContext as x } from "solid-js";
4
+ import { createMachine as S, interpret as C, toArray as w } from "@bemedev/app";
5
+ import { toArray as T, type as E } from "@bemedev/app/bemedev";
7
6
  import { DragDropProvider as D, DragDropSensors as O, DragOverlay as k, createDraggable as A, useDragDropContext as j } from "@thisbeyond/solid-dnd";
8
7
  //#region src/ui/components/classes.ts
9
- var M = /* @__PURE__ */ "fill-transparent cursor-pointer relative stroke-[rgba(168,168,168,0.4)] stroke-3 stroke-[rgba(168,168,168,1)] stroke-4 z-100 stroke-[rgba(168,168,168,0.8)] pointer-events-all w-[100px] h-[100px] bg-white fill-white pointer-events-none absolute top-0 w-full h-full overflow-hidden overflow-scroll h-[150vh] w-[2160px] bg-size-[30px_30px] flex flex-col cursor-grab rounded-md shadow-[1px_1px_11px_-6px_rgba(0,0,0,0.75)] select-none transition-[border,box-shadow] duration-200 ease-in-out hover:shadow-[2px_2px_12px_-6px_rgba(0,0,0,0.75)] draggable border border-[#e38c29] z-[100] border-[#e6d4be] z-[1] items-center justify-end -top-[30px] right-0 transition-all space-x-2 opacity-100 w-0 -right-3 opacity-0 w-6 h-6 fill-[#a11111] rounded-full size-6 bg-green-500 p-0.5 hover:bg-green-600 font-bold text-center overflow-visible bg-blue-500 text-white rounded-lg hover:bg-blue-600 justify-center p-3 border-b border-[#f0f0f0] cursor-default z-[-3] -left-[18px] bg-[#e38b29] w-3 h-3 my-3 -right-[18px] cursor-crosshair mt-3".split(" "), N = Object.prototype.hasOwnProperty;
10
- function P(e, t) {
11
- var n, r;
12
- if (e === t) return !0;
13
- if (e && t && (n = e.constructor) === t.constructor) {
14
- if (n === Date) return e.getTime() === t.getTime();
15
- if (n === RegExp) return e.toString() === t.toString();
16
- if (n === Array) {
17
- if ((r = e.length) === t.length) for (; r-- && P(e[r], t[r]););
18
- return r === -1;
19
- }
20
- if (!n || typeof e == "object") {
21
- for (n in r = 0, e) if (N.call(e, n) && ++r && !N.call(t, n) || !(n in t) || !P(e[n], t[n])) return !1;
22
- return Object.keys(t).length === r;
23
- }
8
+ var M = /* @__PURE__ */ "fill-transparent cursor-pointer relative stroke-[rgba(168,168,168,0.4)] stroke-3 stroke-[rgba(168,168,168,1)] stroke-4 z-100 stroke-[rgba(168,168,168,0.8)] pointer-events-all w-[100px] h-[100px] bg-white fill-white pointer-events-none absolute top-0 w-full h-full overflow-hidden overflow-auto h-[150vh] w-[2160px] bg-size-[30px_30px] flex flex-col cursor-grab rounded-md shadow-[1px_1px_11px_-6px_rgba(0,0,0,0.75)] select-none transition-[border,box-shadow] duration-200 ease-in-out hover:shadow-[2px_2px_12px_-6px_rgba(0,0,0,0.75)] draggable border border-[#e38c29] z-[100] border-[#e6d4be] z-[1] items-center justify-end -top-[30px] right-0 transition-all space-x-2 opacity-100 w-0 -right-3 opacity-0 w-6 h-6 fill-[#a11111] rounded-full size-6 bg-green-500 p-0.5 hover:bg-green-600 font-bold text-center overflow-visible bg-blue-500 text-white rounded-lg hover:bg-blue-600 justify-center p-3 border-b border-[#f0f0f0] cursor-default z-[-3] -left-[18px] bg-[#e38b29] w-3 h-3 my-3 -right-[18px] cursor-crosshair mt-3".split(" "), N = 10.5, P = {
9
+ x: -10.5,
10
+ y: 18
11
+ }, F = (e = 0) => ({
12
+ x: e + N,
13
+ y: 18
14
+ }), I = {
15
+ horizontal: 55,
16
+ vertical: 40
17
+ }, L = [{
18
+ id: "node-0",
19
+ data: {
20
+ content: "Some text",
21
+ label: "Root node"
22
+ },
23
+ input: !1,
24
+ position: {
25
+ x: 350,
26
+ y: 100
24
27
  }
25
- return e !== e && t !== t;
26
- }
27
- //#endregion
28
- //#region src/helpers/createContext.ts
29
- var F = (e, t) => {
30
- let n = m(e(), t);
28
+ }], R = (e, t) => {
29
+ let n = h(e(), t);
31
30
  return [
32
31
  ({ children: e }) => n.Provider({
33
32
  value: n.defaultValue,
@@ -36,45 +35,76 @@ var F = (e, t) => {
36
35
  () => x(n),
37
36
  n
38
37
  ];
39
- }, I = "useandom-26T198340PX75pxJACKVERYMINDBUSHWOLF_GQZbfghjklqvwyzrict", L = (e = 21) => {
38
+ }, z = "useandom-26T198340PX75pxJACKVERYMINDBUSHWOLF_GQZbfghjklqvwyzrict", ee = (e = 21) => {
40
39
  let t = "", n = crypto.getRandomValues(new Uint8Array(e |= 0));
41
- for (; e--;) t += I[n[e] & 63];
40
+ for (; e--;) t += z[n[e] & 63];
42
41
  return t;
43
- }, R = T({
42
+ }, B = (e, t) => `edge = ${e} => ${t}`, V = (e) => `node-${e}`, te = (e, t = {
43
+ width: 192,
44
+ height: 50,
45
+ inputOffset: P
46
+ }) => {
47
+ let n = t.width, r = t.height, i = t.outputOffset ?? F(n), a = t.inputOffset;
48
+ return {
49
+ width: n,
50
+ height: r,
51
+ output: {
52
+ x: e.x + i.x,
53
+ y: e.y + i.y
54
+ },
55
+ input: {
56
+ x: e.x + a.x,
57
+ y: e.y + a.y
58
+ },
59
+ outputOffset: i,
60
+ inputOffset: a
61
+ };
62
+ }, H = E({
44
63
  x: "number",
45
64
  y: "number"
46
65
  });
47
- T(({ optional: e, use: t }) => ({
48
- input: e(t(R)),
49
- output: t(R)
66
+ E(({ optional: e, use: t }) => ({
67
+ input: e(t(H)),
68
+ output: t(H)
50
69
  }));
51
- var z = T({
70
+ var U = E({
52
71
  from: "string",
53
72
  to: "string"
54
- }), B = T(({ optional: e, use: t }) => ({
55
- position: t(R),
73
+ }), W = E(({ optional: e, use: t }) => ({
74
+ position: t(H),
56
75
  data: {
57
76
  label: e("string"),
58
77
  content: "string"
59
78
  },
60
79
  input: "boolean"
61
- })), V = z;
62
- T(({ optional: e, use: t }) => ({
80
+ })), G = U, K = E(({ optional: e, use: t }) => ({
63
81
  width: "number",
64
82
  height: "number",
65
- id: "string",
66
- output: t(R),
67
- input: e(t(R))
68
- })), T({
83
+ output: t(H),
84
+ input: e(t(H)),
85
+ inputOffset: e(t(H)),
86
+ outputOffset: e(t(H))
87
+ })), q = E({
69
88
  x0: "number",
70
89
  y0: "number",
71
90
  x1: "number",
72
91
  y1: "number"
73
- });
74
- //#endregion
75
- //#region src/services/main.machine.ts
76
- var H = (e, t) => `edge = ${e} => ${t}`, U = (e) => `node-${e}`, ee = S({
92
+ }), ne = E(({ intersection: e, use: t }) => e({ from: "string" }, t(q))), J = E(({ optional: e }) => ({
93
+ self: {
94
+ left: "number",
95
+ top: "number",
96
+ width: "number",
97
+ height: "number"
98
+ },
99
+ parent: e({
100
+ scrollLeft: "number",
101
+ scrollTop: "number",
102
+ height: "number",
103
+ width: "number"
104
+ })
105
+ })), re = S({
77
106
  initial: "idle",
107
+ on: { SET_BOARD: { actions: ["setBoard"] } },
78
108
  states: {
79
109
  idle: { on: {
80
110
  CONFIGURE: {
@@ -89,7 +119,7 @@ var H = (e, t) => `edge = ${e} => ${t}`, U = (e) => `node-${e}`, ee = S({
89
119
  } },
90
120
  working: { on: {
91
121
  MOVE_IMMEDIATE: { actions: [{
92
- name: "buildImmediateUI",
122
+ name: "buildUI",
93
123
  description: "Must be in the ui"
94
124
  }] },
95
125
  ADD_CHILD: {
@@ -114,6 +144,7 @@ var H = (e, t) => `edge = ${e} => ${t}`, U = (e) => `node-${e}`, ee = S({
114
144
  ],
115
145
  target: "/construction"
116
146
  },
147
+ ADD_DIMENSION: { actions: ["addDimension"] },
117
148
  ADD_SIBLING: {
118
149
  actions: [
119
150
  "generateID",
@@ -133,20 +164,27 @@ var H = (e, t) => `edge = ${e} => ${t}`, U = (e) => `node-${e}`, ee = S({
133
164
  actions: ["addEdge"],
134
165
  target: "/construction"
135
166
  },
167
+ START_NEW_EDGE: { actions: ["startNewEdge"] },
168
+ MOVE_NEW_EDGE: { actions: ["moveNewEdge"] },
169
+ CLEAR_NEW_EDGE: { actions: ["clearNewEdge"] },
136
170
  DELETE: {
137
171
  actions: ["delete"],
138
172
  target: "/construction"
139
173
  },
140
174
  SELECT: { actions: ["select"] },
141
- DESELECT: { actions: ["deselect"] }
175
+ DESELECT: { actions: ["deselect"] },
176
+ ZOOM: { actions: ["zoom"] },
177
+ TOGGLE_ZOOM: { actions: ["toggleZoom"] },
178
+ SET_BOARD: { actions: ["setBoard"] }
142
179
  } }
143
180
  }
144
181
  }, {
145
- eventsMap: T(({ intersection: e, use: t, array: n }) => ({
182
+ eventsMap: E(({ intersection: e, use: t, array: n }) => ({
146
183
  CONFIGURE: {
147
- nodes: n(e(t(B), { id: "string" })),
148
- edges: n(e(t(V), { id: "string" }))
184
+ nodes: n(e(t(W), { id: "string" })),
185
+ edges: n(e(t(G), { id: "string" }))
149
186
  },
187
+ SET_BOARD: t(J),
150
188
  CONFIGURE_EMPTY: "never",
151
189
  MOVE: {
152
190
  id: "string",
@@ -164,288 +202,288 @@ var H = (e, t) => `edge = ${e} => ${t}`, U = (e) => `node-${e}`, ee = S({
164
202
  DELETE: "string",
165
203
  SELECT: "string",
166
204
  DESELECT: "never",
167
- ADD_EDGE: t(z)
205
+ ADD_EDGE: t(U),
206
+ START_NEW_EDGE: "string",
207
+ MOVE_NEW_EDGE: t(H),
208
+ CLEAR_NEW_EDGE: "never",
209
+ ZOOM: "number",
210
+ TOGGLE_ZOOM: "never",
211
+ ADD_DIMENSION: {
212
+ id: "string",
213
+ dimension: t(K)
214
+ }
168
215
  })),
169
216
  sync: !0,
170
- pContext: T(({ union: e }) => ({ generatedId: e("string", "null") })),
171
- context: T(({ optional: e, use: t, array: n }) => ({
217
+ pContext: E(({ union: e, optional: t, record: n, use: r, custom: i }) => ({
218
+ generatedId: e("string", "null"),
219
+ previousZoom: t("number"),
220
+ dimensions: n(r(K)),
221
+ getBoardPosition: i(),
222
+ clampPosition: i(),
223
+ calculateDimensions: i()
224
+ })),
225
+ context: E(({ optional: e, use: t, array: n, record: r }) => ({
172
226
  data: e({
173
227
  nodes: n({
174
- ...t(B),
228
+ ...t(W),
175
229
  id: "string"
176
230
  }),
177
231
  edges: n({
178
- ...t(V),
232
+ ...t(G),
179
233
  id: "string"
180
234
  })
181
235
  }),
236
+ board: e(t(J)),
237
+ edgesPositions: r(t(q)),
238
+ newEdge: e(t(ne)),
182
239
  selected: e("string"),
183
- updatingUI: e("boolean")
240
+ updatingUI: e("boolean"),
241
+ zoom: "number",
242
+ bounds: t(H)
184
243
  }))
185
- }).provideOptions(({ assign: e, batch: t, erase: n }) => ({ actions: {
186
- configure: t(e("context.data", () => ({
187
- nodes: [],
188
- edges: []
189
- })), e("context.data.nodes", { CONFIGURE: ({ payload: { nodes: e } }) => e }), e("context.data.edges", { CONFIGURE: ({ payload: { edges: e } }) => e }), e("context.updatingUI", () => !1), e("pContext.generatedId", () => null)),
190
- generateID: e("pContext.generatedId", () => L()),
191
- linkChild: t(e("context.data.edges", { ADD_CHILD: ({ context: e, pContext: t, payload: n }) => {
192
- let r = e.data, i = n, a = t?.generatedId, o = U(a), s = H(i, o);
193
- return [...r?.edges ?? [], {
244
+ }).provideOptions(({ assign: e, batch: t, erase: n, filter: r, action: i }) => ({ actions: {
245
+ configure: t(e("data", { CONFIGURE: ({ payload: e }) => e }), e("newEdge", () => void 0), e("updatingUI", () => !1), i(({ pContext: e }) => {
246
+ e.generatedId = null;
247
+ }), i({ CONFIGURE: ({ payload: { nodes: e }, pContext: { dimensions: t } }) => {
248
+ e.forEach(({ id: e, position: n }) => {
249
+ t[e] = te(n);
250
+ });
251
+ } })),
252
+ startNewEdge: e("newEdge", { START_NEW_EDGE: ({ payload: e, pContext: { dimensions: t } }) => {
253
+ let { x: n, y: r } = t[e].output;
254
+ return {
255
+ from: e,
256
+ x0: n,
257
+ y0: r,
258
+ x1: n,
259
+ y1: r
260
+ };
261
+ } }),
262
+ setBoard: e("board", { SET_BOARD: ({ payload: e }) => e }),
263
+ buildUI: t(e("edgesPositions", {
264
+ MOVE: ({ context: { data: e, edgesPositions: t }, payload: n, pContext: { dimensions: r } }) => {
265
+ let i = e?.edges, a = r[n.id], o = a?.outputOffset ?? F(a?.width), s = a?.inputOffset ?? P, c = {
266
+ x: n.x + o.x,
267
+ y: n.y + o.y
268
+ }, l = {
269
+ x: n.x + s.x,
270
+ y: n.y + s.y
271
+ };
272
+ return a && (a.output = c, a.input = l), i?.forEach(({ from: e, to: r, id: i }) => {
273
+ e === n.id && (t[i].x0 = c.x, t[i].y0 = c.y), r === n.id && (t[i].x1 = l.x, t[i].y1 = l.y);
274
+ }), t;
275
+ },
276
+ MOVE_IMMEDIATE: ({ context: { data: e, edgesPositions: t }, payload: n, pContext: { dimensions: r } }) => ((e?.edges)?.forEach(({ from: e, to: i, id: a }) => {
277
+ if (e === n.id) {
278
+ let e = r[n.id], i = e?.outputOffset ?? F(e?.width), o = n.x + i.x, s = n.y + i.y;
279
+ t[a].x0 = o, t[a].y0 = s, e && (e.output.x = o, e.output.y = s);
280
+ }
281
+ if (i === n.id) {
282
+ let e = r[n.id], i = e?.inputOffset ?? P, o = n.x + i.x, s = n.y + i.y;
283
+ t[a].x1 = o, t[a].y1 = s, e && (e.input = {
284
+ x: o,
285
+ y: s
286
+ });
287
+ }
288
+ }), t),
289
+ else: ({ context: { data: e, edgesPositions: t }, pContext: { dimensions: n } }) => {
290
+ let r = e?.edges ?? [];
291
+ return t = {}, r.forEach(({ from: e, id: r, to: i }) => {
292
+ let a = n[e]?.output, o = n[i]?.input;
293
+ a && o ? t[r] = {
294
+ x0: a.x,
295
+ y0: a.y,
296
+ x1: o.x,
297
+ y1: o.y
298
+ } : delete t[r];
299
+ }), t;
300
+ }
301
+ }), e("updatingUI", () => !0)),
302
+ addDimension: i({ ADD_DIMENSION: ({ payload: { id: e, dimension: t }, pContext: { dimensions: n } }) => {
303
+ n[e] = t;
304
+ } }),
305
+ generateID: i(({ pContext: e }) => {
306
+ e.generatedId = ee();
307
+ }),
308
+ linkChild: t(e("data.edges", { ADD_CHILD: ({ context: { data: e }, pContext: t, payload: n }) => {
309
+ let r = T.typed(e?.edges), i = n, a = t?.generatedId, o = V(a), s = B(i, o);
310
+ return r.push({
194
311
  id: s,
195
312
  from: i,
196
313
  to: o
197
- }];
198
- } }), e("context.selected", ({ pContext: { generatedId: e } }) => U(e))),
199
- linkSibling: t(e("context.data.edges", { ADD_SIBLING: ({ pContext: e, payload: t, context: n }) => {
200
- let r = n.data?.edges, i = e?.generatedId, a = [...r ?? []], o = r?.find(({ to: e }) => e === t)?.from;
201
- if (!o) return a;
202
- let s = U(i), c = H(o, s);
203
- return a.push({
204
- from: o,
205
- to: s,
206
- id: c
207
- }), a;
208
- } }), e("context.selected", ({ pContext: { generatedId: e } }) => U(e))),
209
- selectParent: e("context.selected", ({ pContext: { generatedId: e } }) => U(e)),
210
- moveNode: e("context.data.nodes", { MOVE: ({ context: { data: e }, payload: t }) => {
314
+ }), r;
315
+ } }), e("selected", ({ pContext: { generatedId: e } }) => V(e))),
316
+ linkSibling: t(e("data.edges", { ADD_SIBLING: ({ pContext: e, payload: t, context: { data: n } }) => {
317
+ let r = T.typed(n?.edges), i = e?.generatedId, a = r.find(({ to: e }) => e === t)?.from;
318
+ if (!a) return r;
319
+ let o = V(i), s = B(a, o);
320
+ return r.push({
321
+ from: a,
322
+ to: o,
323
+ id: s
324
+ }), r;
325
+ } }), e("selected", ({ pContext: { generatedId: e } }) => V(e))),
326
+ selectParent: e("selected", ({ pContext: { generatedId: e } }) => V(e)),
327
+ moveNode: e("data.nodes", { MOVE: ({ context: { data: e }, payload: t }) => {
211
328
  let { id: n, x: r, y: i } = t;
212
- return n ? e?.nodes?.map((e) => e.id === n ? {
329
+ return e?.nodes?.map((e) => e.id === n ? {
213
330
  ...e,
214
331
  position: {
215
332
  x: r,
216
333
  y: i
217
334
  }
218
- } : e) ?? [] : e?.nodes ?? [];
335
+ } : e) ?? [];
219
336
  } }),
220
- select: e("context.selected", { SELECT: ({ payload: e }) => e }),
221
- delete: e(["context.data.nodes", "context.data.edges"], { DELETE: ({ context: { data: e }, payload: t }) => [e?.nodes?.filter(({ id: e }) => e !== t), e?.edges?.filter(({ id: e, from: n, to: r }) => e !== t && n !== t && r !== t)] }),
222
- addEdge: e("context.data.edges", { ADD_EDGE: ({ context: e, payload: { from: t, to: n } }) => {
223
- let r = e.data?.edges ?? [], i = H(t, n);
337
+ select: e("selected", { SELECT: ({ payload: e }) => e }),
338
+ delete: t(r("data.edges", { DELETE: ({ id: e, from: t, to: n }, r, { payload: i }) => e !== i && t !== i && n !== i }), r("data.nodes", { DELETE: ({ id: e }, t, { payload: n }) => e !== n })),
339
+ addEdge: t(e("data.edges", { ADD_EDGE: ({ context: e, payload: { from: t, to: n } }) => {
340
+ let r = e.data?.edges ?? [], i = B(t, n);
224
341
  return r.some((e) => e.id === i) ? r : [...r, {
225
342
  id: i,
226
343
  from: t,
227
344
  to: n
228
345
  }];
346
+ } }), n("newEdge")),
347
+ clearNewEdge: n("newEdge"),
348
+ deselect: n("selected"),
349
+ zoom: e("zoom", { ZOOM: ({ context: { zoom: e }, payload: t, pContext: n }) => {
350
+ let r = e + t, i = Math.min(Math.max(Number(r.toFixed(2)), .2), 3);
351
+ return n.previousZoom = void 0, i;
229
352
  } }),
230
- deselect: n("context.selected")
231
- } })), te = 10.5, W = -10.5, G = {
232
- x: W,
233
- y: 18
234
- }, K = (e = 0) => ({
235
- x: e + te,
236
- y: 18
237
- }), q = {
238
- horizontal: 55,
239
- vertical: 40
240
- }, ne = [{
241
- id: "node-0",
242
- data: {
243
- content: "Some text",
244
- label: "Root node"
245
- },
246
- input: !1,
247
- position: {
248
- x: 350,
249
- y: 100
250
- }
251
- }], [re, J] = F(() => {
252
- let e = C(ee, {
253
- context: {},
254
- pContext: { generatedId: null }
255
- }), t = _(1), n = _(), [r, i] = _(), [a, o] = _({}, { equals: P }), s = (e, n) => {
256
- let i = r();
257
- if (!i) return {
258
- x: e,
259
- y: n
260
- };
261
- let a = i.getBoundingClientRect(), o = t[0]();
262
- return {
263
- x: e - a.left / o,
264
- y: n - a.top / o
265
- };
266
- }, [c, l] = _({}, { equals: !1 }), u = (e, n, i = 192, a = 50) => {
267
- let o = r()?.parentElement;
268
- if (!o) return {
269
- x: e,
270
- y: n
271
- };
272
- let s = t[0](), c = o.scrollLeft / s + q.horizontal, l = Math.max(c, (o.scrollLeft + o.clientWidth) / s - q.horizontal - i), u = o.scrollTop / s + q.vertical, d = Math.max(u, (o.scrollTop + o.clientHeight) / s - q.vertical - a);
273
- return {
274
- x: Math.min(Math.max(e, c), l),
275
- y: Math.min(Math.max(n, u), d)
276
- };
277
- };
278
- return e.addOptions(({ voidAction: e, batch: n, assign: i }) => ({ actions: {
279
- placeChild: i("context.data.nodes", { ADD_CHILD: ({ payload: e, context: { data: t }, pContext: { generatedId: n } }) => {
280
- let r = t?.nodes ?? [];
281
- if (!e) return r;
282
- let i = r.find((t) => t.id === e);
283
- if (!i) return r;
284
- let o = `node-${n}`, s = a()[e]?.width ?? 0, c = a()[e]?.height ?? 0, l = i.position.x + s + 100, d = i.position.y, f = u(l, d, s, c);
285
- return [...r, {
286
- id: o,
353
+ toggleZoom: e("zoom", { TOGGLE_ZOOM: ({ context: { zoom: e }, pContext: t }) => {
354
+ let n = t.previousZoom;
355
+ return n === void 0 ? (t.previousZoom = e, 1) : (t.previousZoom = void 0, n);
356
+ } })
357
+ } })), [ie, Y] = R(() => {
358
+ let e = C(re, {
359
+ context: {
360
+ zoom: 1,
361
+ edgesPositions: {},
362
+ bounds: {
363
+ x: 0,
364
+ y: 0
365
+ }
366
+ },
367
+ pContext: {
368
+ generatedId: null,
369
+ dimensions: {},
370
+ getBoardPosition(t, n, r) {
371
+ if (!r) return {
372
+ x: t,
373
+ y: n
374
+ };
375
+ let i = e.state.context.zoom;
376
+ return {
377
+ x: (t - r.self.left) / i,
378
+ y: (n - r.self.top) / i
379
+ };
380
+ },
381
+ clampPosition(t, n, r, i = 192, a = 50) {
382
+ let o = t?.parent;
383
+ if (!o) return {
384
+ x: n,
385
+ y: r
386
+ };
387
+ let s = e.state.context.zoom ?? 1, c = o.scrollLeft / s + I.horizontal, l = Math.max(c, (o.scrollLeft + o.width) / s - I.horizontal - i), u = o.scrollTop / s + I.vertical, d = Math.max(u, (o.scrollTop + o.height) / s - I.vertical - a);
388
+ return {
389
+ x: Math.min(Math.max(n, c), l),
390
+ y: Math.min(Math.max(r, u), d)
391
+ };
392
+ },
393
+ calculateDimensions: (e, t = {
394
+ width: 192,
395
+ height: 50,
396
+ inputOffset: P
397
+ }) => {
398
+ let n = t.width, r = t.height, i = t.outputOffset ?? F(n), a = t.inputOffset;
399
+ return {
400
+ width: n,
401
+ height: r,
402
+ output: {
403
+ x: e.x + i.x,
404
+ y: e.y + i.y
405
+ },
406
+ input: {
407
+ x: e.x + a.x,
408
+ y: e.y + a.y
409
+ },
410
+ outputOffset: i,
411
+ inputOffset: a
412
+ };
413
+ }
414
+ }
415
+ });
416
+ return e.addOptions(({ assign: e }) => ({ actions: {
417
+ placeChild: e("data.nodes", { ADD_CHILD: ({ payload: e, context: { data: t, board: n }, pContext: r }) => {
418
+ if (!n) return t?.nodes;
419
+ let i = t?.nodes;
420
+ if (!e) return i;
421
+ let a = i?.find((t) => t.id === e);
422
+ if (!a) return i;
423
+ let o = r.dimensions[e], s = `node-${r.generatedId}`, c = o?.width ?? 192, l = o?.height ?? 50, u = a.position.x + c + 100, d = a.position.y, f = r.clampPosition(n, u, d, c, l), p = r.calculateDimensions(f, o);
424
+ return i?.push({
425
+ id: s,
287
426
  data: { content: "<Nouveau nœud>" },
288
427
  input: !0,
289
428
  position: f
290
- }];
429
+ }), r.dimensions[s] = p, i;
291
430
  } }),
292
- placeParent: i("context.data.nodes", { ADD_PARENT: ({ context: { data: e }, pContext: { generatedId: n } }) => {
293
- let i = e?.nodes ?? [], a = `node-${n}`, o = r()?.parentElement, s = o?.scrollLeft ?? 0, c = o?.scrollTop ?? 0, l = o?.clientWidth ?? 0, u = o?.clientHeight ?? 0, d = t[0](), f = (s + l / 2) / d, p = (c + u / 2) / d;
294
- return [...i, {
431
+ placeParent: e("data.nodes", { ADD_PARENT: ({ context: { data: e, zoom: t = 1, board: n }, pContext: r }) => {
432
+ if (!n) return e?.nodes;
433
+ let i = e?.nodes, a = `node-${r.generatedId}`, o = n.parent, s = o?.scrollLeft ?? 0, c = o?.scrollTop ?? 0, l = o?.width ?? 0, u = o?.height ?? 0, d = t, f = (s + l / 2) / d, p = (c + u / 2) / d, m = r.clampPosition(n, f, p), h = r.calculateDimensions(m);
434
+ return i?.push({
295
435
  id: a,
296
436
  data: { content: "<Nouveau nœud>" },
297
437
  input: !1,
298
- position: {
299
- x: f,
300
- y: p
301
- }
302
- }];
438
+ position: m
439
+ }), r.dimensions[a] = h, i;
303
440
  } }),
304
- placeSibling: i("context.data.nodes", { ADD_SIBLING: ({ payload: e, context: { data: t }, pContext: { generatedId: n } }) => {
305
- let r = t?.edges ?? [], i = t?.nodes ?? [], o = r.find((t) => t.to === e)?.from;
306
- if (!o) return i;
307
- let s = i.find((e) => e.id === o);
308
- if (!s) return i;
309
- let c = `node-${n}`, l = a()[o]?.width ?? 0, d = a()[o]?.height ?? 0, f = s.position.x + l + 100, p = s.position.y + 100, m = u(f, p, l, d);
310
- return [...i, {
311
- id: c,
441
+ placeSibling: e("data.nodes", { ADD_SIBLING: ({ payload: e, context: { data: t, board: n }, pContext: r }) => {
442
+ if (!n) return t?.nodes;
443
+ let i = t?.edges, a = t?.nodes, o = i?.find((t) => t.to === e)?.from;
444
+ if (!o) return a;
445
+ let s = a?.find((e) => e.id === o);
446
+ if (!s) return a;
447
+ let c = r.dimensions[o], l = `node-${r.generatedId}`, u = c?.width ?? 192, d = c?.height ?? 50, f = s.position.x + u + 100, p = s.position.y + 100, m = r.clampPosition(n, f, p, u, d), h = r.calculateDimensions(m, c);
448
+ return a?.push({
449
+ id: l,
312
450
  data: { content: "<Nouveau nœud>" },
313
451
  input: !0,
314
452
  position: m
315
- }];
453
+ }), r.dimensions[l] = h, a;
316
454
  } }),
317
- buildUI: n(e(({ context: { data: e } }) => {
318
- let t = e?.edges ?? [];
319
- l((e) => {
320
- let n = Object.entries({ ...e }).filter(([e]) => t.some((t) => t.id === e));
321
- return Object.fromEntries(n);
322
- });
323
- }), e({
324
- else: ({ context: { data: e } }) => {
325
- let t = e?.edges ?? [];
326
- l(w((e) => {
327
- t?.forEach(({ from: t, id: n, to: r }) => {
328
- let i = a()[t]?.output, o = a()[r]?.input;
329
- i && o && (e[n] = {
330
- x0: i.x,
331
- y0: i.y,
332
- x1: o.x,
333
- y1: o.y
334
- });
335
- });
336
- }));
337
- },
338
- MOVE: ({ context: { data: e }, payload: t }) => {
339
- let n = e?.edges ?? [];
340
- l(w((e) => {
341
- n?.forEach(({ from: n, to: r, id: i }) => {
342
- if (n === t.id) {
343
- let n = a()[t.id]?.outputOffset ?? K(a()[t.id]?.width), r = t.x + n.x, s = t.y + n.y;
344
- e[i] = {
345
- ...e[i],
346
- x0: r,
347
- y0: s
348
- }, o(w((e) => {
349
- e[t.id] && (e[t.id] = {
350
- ...e[t.id],
351
- output: {
352
- x: r,
353
- y: s
354
- }
355
- });
356
- }));
357
- }
358
- if (r === t.id) {
359
- let n = a()[t.id]?.inputOffset ?? G, r = t.x + n.x, s = t.y + n.y;
360
- e[i] = {
361
- ...e[i],
362
- x1: r,
363
- y1: s
364
- }, o(w((e) => {
365
- e[t.id] && (e[t.id] = {
366
- ...e[t.id],
367
- input: {
368
- x: r,
369
- y: s
370
- }
371
- });
372
- }));
373
- }
374
- });
375
- }));
376
- }
377
- }), i("context.updatingUI", () => !0)),
378
- buildImmediateUI: e({ MOVE_IMMEDIATE: ({ context: { data: e }, payload: t }) => {
379
- let n = e?.edges ?? [];
380
- l(w((e) => {
381
- n?.forEach(({ from: n, to: r, id: i }) => {
382
- if (n === t.id) {
383
- let n = a()[t.id]?.outputOffset ?? K(a()[t.id]?.width), r = t.x + n.x, s = t.y + n.y;
384
- e[i] = {
385
- ...e[i],
386
- x0: r,
387
- y0: s
388
- }, o(w((e) => {
389
- e[t.id] && (e[t.id] = {
390
- ...e[t.id],
391
- output: {
392
- x: r,
393
- y: s
394
- }
395
- });
396
- }));
397
- }
398
- if (r === t.id) {
399
- let n = a()[t.id]?.inputOffset ?? G, r = t.x + n.x, s = t.y + n.y;
400
- e[i] = {
401
- ...e[i],
402
- x1: r,
403
- y1: s
404
- }, o(w((e) => {
405
- e[t.id] && (e[t.id] = {
406
- ...e[t.id],
407
- input: {
408
- x: r,
409
- y: s
410
- }
411
- });
412
- }));
413
- }
414
- });
415
- }));
455
+ moveNewEdge: e("newEdge", { MOVE_NEW_EDGE: ({ context: { newEdge: e, board: t }, payload: n, pContext: r }) => {
456
+ if (!t || !e) return;
457
+ let { x: i, y: a } = r.getBoardPosition(n.x, n.y, t);
458
+ return {
459
+ ...e,
460
+ x1: i,
461
+ y1: a
462
+ };
416
463
  } })
417
- } })), e.start(), {
418
- dimensions: [a, o],
419
- newEdge: n,
420
- board: [r, i],
421
- getBoardPoint: s,
422
- edgesPositions: [c, l],
423
- service: e,
424
- zoom: t,
425
- clampPosition: u
426
- };
427
- }, { name: "FlowContext" }), Y = Object.prototype.hasOwnProperty;
428
- function X(e, t, n) {
429
- for (n of e.keys()) if (Z(n, t)) return n;
464
+ } })), e.start(), e;
465
+ }, { name: "FlowContext" }), X = Object.prototype.hasOwnProperty;
466
+ function Z(e, t, n) {
467
+ for (n of e.keys()) if (Q(n, t)) return n;
430
468
  }
431
- function Z(e, t) {
469
+ function Q(e, t) {
432
470
  var n, r, i;
433
471
  if (e === t) return !0;
434
472
  if (e && t && (n = e.constructor) === t.constructor) {
435
473
  if (n === Date) return e.getTime() === t.getTime();
436
474
  if (n === RegExp) return e.toString() === t.toString();
437
475
  if (n === Array) {
438
- if ((r = e.length) === t.length) for (; r-- && Z(e[r], t[r]););
476
+ if ((r = e.length) === t.length) for (; r-- && Q(e[r], t[r]););
439
477
  return r === -1;
440
478
  }
441
479
  if (n === Set) {
442
480
  if (e.size !== t.size) return !1;
443
- for (r of e) if (i = r, i && typeof i == "object" && (i = X(t, i), !i) || !t.has(i)) return !1;
481
+ for (r of e) if (i = r, i && typeof i == "object" && (i = Z(t, i), !i) || !t.has(i)) return !1;
444
482
  return !0;
445
483
  }
446
484
  if (n === Map) {
447
485
  if (e.size !== t.size) return !1;
448
- for (r of e) if (i = r[0], i && typeof i == "object" && (i = X(t, i), !i) || !Z(r[1], t.get(i))) return !1;
486
+ for (r of e) if (i = r[0], i && typeof i == "object" && (i = Z(t, i), !i) || !Q(r[1], t.get(i))) return !1;
449
487
  return !0;
450
488
  }
451
489
  if (n === ArrayBuffer) e = new Uint8Array(e), t = new Uint8Array(t);
@@ -458,7 +496,7 @@ function Z(e, t) {
458
496
  return r === -1;
459
497
  }
460
498
  if (!n || typeof e == "object") {
461
- for (n in r = 0, e) if (Y.call(e, n) && ++r && !Y.call(t, n) || !(n in t) || !Z(e[n], t[n])) return !1;
499
+ for (n in r = 0, e) if (X.call(e, n) && ++r && !X.call(t, n) || !(n in t) || !Q(e[n], t[n])) return !1;
462
500
  return Object.keys(t).length === r;
463
501
  }
464
502
  }
@@ -466,236 +504,220 @@ function Z(e, t) {
466
504
  }
467
505
  //#endregion
468
506
  //#region src/ui/components/Bounds.tsx
469
- var ie = () => {
470
- let { board: [e], zoom: [t] } = J(), [n, { addTransformer: r, removeTransformer: i, onDragStart: a, onDragEnd: o }] = j(), s = {
507
+ var ae = () => {
508
+ let e = Y(), t = f(e, { selector: ({ context: e }) => e.zoom }), n = f(e, { selector: ({ context: e }) => e.board }), [r, { addTransformer: i, removeTransformer: a, onDragStart: o, onDragEnd: s }] = j(), c = {
471
509
  id: "clamp-to-container",
472
510
  order: 100,
473
- callback: (r) => {
474
- let i = e(), a = n.active.draggable;
475
- if (!i || !a) return r;
511
+ callback: (e) => {
512
+ let i = n()?.self, a = r.active.draggable;
513
+ if (!i || !a) return e;
476
514
  let o = a.node;
477
- if (!o) return r;
478
- let s = t(), c = q.horizontal, l = Math.max(c, i.clientWidth / s - o.offsetWidth - q.horizontal), u = q.vertical, d = Math.max(u, i.clientHeight / s - o.offsetHeight - q.vertical), f = (c - o.offsetLeft) * s, p = (l - o.offsetLeft) * s, m = (u - o.offsetTop) * s, h = (d - o.offsetTop) * s;
515
+ if (!o) return e;
516
+ let s = t(), c = I.horizontal, l = Math.max(c, i.width / s - o.offsetWidth - I.horizontal), u = I.vertical, d = Math.max(u, i.height / s - o.offsetHeight - I.vertical), f = (c - o.offsetLeft) * s, p = (l - o.offsetLeft) * s, m = (u - o.offsetTop) * s, h = (d - o.offsetTop) * s;
479
517
  return {
480
- x: Math.min(Math.max(r.x, f), p),
481
- y: Math.min(Math.max(r.y, m), h)
518
+ x: Math.min(Math.max(e.x, f), p),
519
+ y: Math.min(Math.max(e.y, m), h)
482
520
  };
483
521
  }
484
522
  };
485
- return a(({ draggable: e }) => {
486
- r("draggables", e.id, s);
487
- }), o(({ draggable: e }) => {
488
- i("draggables", e.id, s.id);
523
+ return o(({ draggable: e }) => {
524
+ i("draggables", e.id, c);
525
+ }), s(({ draggable: e }) => {
526
+ a("draggables", e.id, c.id);
489
527
  }), null;
490
- }, ae = /*#__PURE__*/ u("<svg><path class=\"relative cursor-pointer fill-transparent\"></svg>", !1, !0, !1), oe = /*#__PURE__*/ u("<svg><g cursor=pointer style=pointer-events:all;z-index:30><circle cx=0 cy=0 r=12 fill=\"rgba(168, 168, 168, 1)\"></circle><svg fill=currentColor stroke-width=0 xmlns=http://www.w3.org/2000/svg class=\"h-25 w-25 bg-white fill-white\"width=20 height=20 viewBox=\"0 0 20 20\"color=white x=-10 y=-10><path d=\"M10.185,1.417c-4.741,0-8.583,3.842-8.583,8.583c0,4.74,3.842,8.582,8.583,8.582S18.768,14.74,18.768,10C18.768,5.259,14.926,1.417,10.185,1.417 M10.185,17.68c-4.235,0-7.679-3.445-7.679-7.68c0-4.235,3.444-7.679,7.679-7.679S17.864,5.765,17.864,10C17.864,14.234,14.42,17.68,10.185,17.68 M10.824,10l2.842-2.844c0.178-0.176,0.178-0.46,0-0.637c-0.177-0.178-0.461-0.178-0.637,0l-2.844,2.841L7.341,6.52c-0.176-0.178-0.46-0.178-0.637,0c-0.178,0.176-0.178,0.461,0,0.637L9.546,10l-2.841,2.844c-0.178,0.176-0.178,0.461,0,0.637c0.178,0.178,0.459,0.178,0.637,0l2.844-2.841l2.844,2.841c0.178,0.178,0.459,0.178,0.637,0c0.178-0.176,0.178-0.461,0-0.637L10.824,10z\"></svg>", !1, !0, !1), Q = (e) => e * 100 / 200, se = ({ x0: e, y0: t, x1: n, y1: r }) => `M ${e} ${t} C ${e + Q(Math.abs(n - e))} ${t}, ${n - Q(Math.abs(n - e))} ${r}, ${n} ${r}`, $ = (n) => {
491
- let [a, o] = _({
492
- x: n.x0 + (n.x1 - n.x0) / 2,
493
- y: n.y0 + (n.y1 - n.y0) / 2
494
- }), { service: u } = J();
495
- h(() => {
496
- let e = n.x0 + (n.x1 - n.x0) / 2, t = n.y0 + (n.y1 - n.y0) / 2;
497
- o({
498
- x: e,
499
- y: t
500
- });
501
- });
502
- let d = E(u, { selector: (e) => e.context.selected === n.id });
503
- return [(() => {
504
- var t = i(ae);
505
- return t.$$click = () => u.send({
506
- type: "SELECT",
507
- payload: n.id
508
- }), t.$$mousedown = (e) => e.stopPropagation(), r((r) => {
509
- var i = {
510
- "stroke-[rgba(168,168,168,0.4)] stroke-3 z-200": !!n.isNew,
511
- "stroke-[rgba(168,168,168,1)] stroke-4 z-100": d() && !n.isNew,
512
- "stroke-[rgba(168,168,168,0.8)] stroke-3": !d() && !n.isNew
513
- }, a = n.isNew ? "none" : "all", o = se(n);
514
- return r.e = e(t, i, r.e), a !== r.t && l(t, "pointer-events", r.t = a), o !== r.a && c(t, "d", r.a = o), r;
515
- }, {
516
- e: void 0,
517
- t: void 0,
518
- a: void 0
519
- }), s(), t;
520
- })(), t(p, {
528
+ }, oe = /*#__PURE__*/ u("<svg><path class=\"relative cursor-pointer fill-transparent\"></svg>", !1, !0, !1), se = /*#__PURE__*/ u("<svg><g cursor=pointer style=pointer-events:all;z-index:30><circle cx=0 cy=0 r=12 fill=\"rgba(168, 168, 168, 1)\"></circle><svg fill=currentColor stroke-width=0 xmlns=http://www.w3.org/2000/svg class=\"h-25 w-25 bg-white fill-white\"width=20 height=20 viewBox=\"0 0 20 20\"color=white x=-10 y=-10><path d=\"M10.185,1.417c-4.741,0-8.583,3.842-8.583,8.583c0,4.74,3.842,8.582,8.583,8.582S18.768,14.74,18.768,10C18.768,5.259,14.926,1.417,10.185,1.417 M10.185,17.68c-4.235,0-7.679-3.445-7.679-7.68c0-4.235,3.444-7.679,7.679-7.679S17.864,5.765,17.864,10C17.864,14.234,14.42,17.68,10.185,17.68 M10.824,10l2.842-2.844c0.178-0.176,0.178-0.46,0-0.637c-0.177-0.178-0.461-0.178-0.637,0l-2.844,2.841L7.341,6.52c-0.176-0.178-0.46-0.178-0.637,0c-0.178,0.176-0.178,0.461,0,0.637L9.546,10l-2.841,2.844c-0.178,0.176-0.178,0.461,0,0.637c0.178,0.178,0.459,0.178,0.637,0l2.844-2.841l2.844,2.841c0.178,0.178,0.459,0.178,0.637,0c0.178-0.176,0.178-0.461,0-0.637L10.824,10z\"></svg>", !1, !0, !1), $ = (e) => e * 100 / 200, ce = ({ x0: e, y0: t, x1: n, y1: r }) => `M ${e} ${t} C ${e + $(Math.abs(n - e))} ${t}, ${n - $(Math.abs(n - e))} ${r}, ${n} ${r}`, le = (n) => {
529
+ let a = Y(), o = f(a, {
530
+ selector: ({ context: e }) => {
531
+ if (n.isNew) {
532
+ let t = e.newEdge;
533
+ return t ? {
534
+ x0: t.x0,
535
+ y0: t.y0,
536
+ x1: t.x1,
537
+ y1: t.y1
538
+ } : void 0;
539
+ }
540
+ return e.edgesPositions[n.id];
541
+ },
542
+ equals: Q
543
+ }), u = f(a, { selector: (e) => e.context.selected === n.id }), d = () => {
544
+ let e = o();
545
+ return e ? {
546
+ x: e.x0 + (e.x1 - e.x0) / 2,
547
+ y: e.y0 + (e.y1 - e.y0) / 2
548
+ } : {
549
+ x: 0,
550
+ y: 0
551
+ };
552
+ };
553
+ return t(m, {
521
554
  get when() {
522
- return d();
555
+ return o();
523
556
  },
524
- get children() {
525
- var e = i(oe);
526
- return e.$$mousedown = (e) => {
527
- e.stopPropagation(), u.send({
528
- type: "DELETE",
529
- payload: n.id
530
- });
531
- }, r(() => c(e, "transform", `translate(${a().x}, ${a().y})`)), s(), e;
532
- }
533
- })];
557
+ children: (o) => [(() => {
558
+ var t = i(oe);
559
+ return t.$$mousedown = (e) => (e.stopPropagation(), a.send({
560
+ type: "SELECT",
561
+ payload: n.id
562
+ })), r((r) => {
563
+ var i = {
564
+ "stroke-[rgba(168,168,168,0.4)] stroke-3 z-200": !!n.isNew,
565
+ "stroke-[rgba(168,168,168,1)] stroke-4 z-100": u() && !n.isNew,
566
+ "stroke-[rgba(168,168,168,0.8)] stroke-3": !u() && !n.isNew
567
+ }, a = n.isNew ? "none" : "all", s = ce(o());
568
+ return r.e = e(t, i, r.e), a !== r.t && l(t, "pointer-events", r.t = a), s !== r.a && c(t, "d", r.a = s), r;
569
+ }, {
570
+ e: void 0,
571
+ t: void 0,
572
+ a: void 0
573
+ }), s(), t;
574
+ })(), t(m, {
575
+ get when() {
576
+ return u();
577
+ },
578
+ get children() {
579
+ var e = i(se);
580
+ return e.$$mousedown = (e) => {
581
+ e.stopPropagation(), a.send({
582
+ type: "DELETE",
583
+ payload: n.id
584
+ });
585
+ }, r(() => c(e, "transform", `translate(${d().x}, ${d().y})`)), s(), e;
586
+ }
587
+ })]
588
+ });
534
589
  };
535
- n(["mousedown", "click"]);
590
+ n(["mousedown"]);
536
591
  //#endregion
537
592
  //#region src/ui/components/EdgesBoard.tsx
538
- var ce = /*#__PURE__*/ u("<svg class=\"pointer-events-none h-full w-full overflow-visible\"><!$><!/><!$><!/>"), le = () => {
539
- let [e, n] = _(), { newEdge: [r], edgesPositions: [s] } = J(), c = g(() => Object.entries(s()).map(([e, t]) => ({
540
- id: e,
541
- ...t
542
- })));
543
- return h(() => {
544
- e() && r() && n();
545
- }), (() => {
546
- var e = i(ce), n = e.firstChild, [s, l] = a(n.nextSibling), u = s.nextSibling, [d, m] = a(u.nextSibling);
547
- return o(e, t(p, {
593
+ var ue = /*#__PURE__*/ u("<svg class=\"pointer-events-none h-full w-full overflow-visible\"><!$><!/><!$><!/>"), de = () => {
594
+ let e = Y(), n = f(e, { selector: (e) => !!e.context.newEdge }), r = f(e, {
595
+ selector: ({ context: e }) => Object.keys(e.edgesPositions),
596
+ equals: (e, t) => e.length === t.length
597
+ });
598
+ return (() => {
599
+ var e = i(ue), s = e.firstChild, [c, l] = a(s.nextSibling), u = c.nextSibling, [d, f] = a(u.nextSibling);
600
+ return o(e, t(m, {
548
601
  get when() {
549
- return r();
602
+ return n();
550
603
  },
551
- children: (e) => t($, {
552
- id: "__#new-edge#__TEMP",
553
- isNew: !0,
554
- get x0() {
555
- return e().x0;
556
- },
557
- get y0() {
558
- return e().y0;
559
- },
560
- get x1() {
561
- return e().x1;
562
- },
563
- get y1() {
564
- return e().y1;
565
- }
566
- })
567
- }), s, l), o(e, t(f, {
604
+ get children() {
605
+ return t(le, {
606
+ id: "__#new-edge#__TEMP",
607
+ isNew: !0
608
+ });
609
+ }
610
+ }), c, l), o(e, t(p, {
568
611
  get each() {
569
- return c();
612
+ return r();
570
613
  },
571
- children: $
572
- }), d, m), e;
614
+ children: (e) => t(le, { id: e })
615
+ }), d, f), e;
573
616
  })();
574
- }, ue = /*#__PURE__*/ u("<svg class=\"cursor-pointer overflow-visible rounded-full bg-green-500 p-0.5 text-center font-bold hover:bg-green-600\"viewBox=\"0 0 1024 1024\"preserveAspectRatio=xMaxYMax xmlns=http://www.w3.org/2000/svg fill=white style=pointer-events:all;fill-rule:evenodd;clip-rule:evenodd;stroke-linejoin:round;stroke-miterlimit:2><g id=background><path d=\"M467.40667,277.66696c-0.05948,-14.53055 5.75527,-22.95613 -8.62044,-20.90487c-112.55699,16.0607 -222.1609,112.14558 -245.06161,239.85765c-46.52056,259.43466 231.33083,443.06705 449.51209,316.97506c117.31668,-67.80002 160.95215,-190.43324 151.34416,-288.29849c-5.92276,-60.32819 -27.80273,-107.95668 -53.44246,-144.25469l59.39269,-42.05363c111.72214,156.309 73.11535,351.55635 -25.06953,459.45565c-184.18877,202.4124 -470.46624,145.52064 -592.95027,-32.92123c-156.18269,-227.53604 -27.15324,-543.64371 261.18883,-582.44416c5.0579,-0.68061 3.56556,-7.04079 3.56442,-8.58985c-0.05594,-76.3354 -0.11021,-76.7687 1.10909,-77.24589c2.06886,-0.80969 151.41433,118.4561 151.92482,118.95524c4.65592,4.55233 -0.99548,7.829 -29.07828,30.50907c-120.49369,97.31245 -120.4977,98.55675 -123.0691,97.87586c-0.43639,-0.11555 -0.80698,-0.31322 -0.74442,-66.91571Z\"></path><path d=\"M316.61562,611.03414c0.11517,-90.16257 -0.25516,-99.92912 0.64739,-101.78856c1.56486,-3.22393 131.99102,0.91032 134.6959,-1.89763c2.21336,-2.2977 -0.59362,-129.97807 1.1376,-132.37034c0.7253,-1.00225 11.10552,-0.99175 12.07474,-0.99077c104.50336,0.10564 104.90098,-0.37811 105.967,0.85765c1.56461,1.81373 0.25596,114.18436 0.67852,129.81412c0.1322,4.88975 3.22386,3.28152 99.72028,3.4563c33.0841,0.05992 36.14259,-1.40368 36.21852,4.50462c0.11713,9.11348 1.41954,110.45369 -0.40274,113.92715c-1.81106,3.45208 -130.39967,-0.42618 -134.48289,1.62075c-2.29035,1.14816 -0.36989,101.12392 -1.11542,130.51904c-0.09548,3.76459 -2.13506,3.20617 -47.84854,3.17365c-69.30253,-0.0493 -69.31099,-0.25627 -69.65762,-0.42191c-3.77927,-1.80595 0.16287,-129.33555 -2.24266,-132.58994c-1.79931,-2.43424 -124.06108,-0.29118 -132.80252,-0.97392c-3.81102,-0.29766 -2.58229,-14.8847 -2.58758,-16.8402Z\">"), de = /*#__PURE__*/ u("<div id=outputs class=\"pointer-events-none absolute top-0 z-10 flex cursor-default flex-col\"><div class=\"cursor-default rounded-full bg-[#e38b29] shadow-md\"style=pointer-events:all>"), fe = /*#__PURE__*/ u("<div class=min-w-48><div><svg class=\"cursor-pointer rounded-full fill-[#a11111] opacity-100 transition-all duration-200 ease-in-out\"fill=currentColor stroke-width=2 viewBox=\"4 4 16 16\"style=overflow:visible;pointer-events:all><path d=\"M12 4c-4.419 0-8 3.582-8 8s3.581 8 8 8 8-3.582 8-8-3.581-8-8-8zm3.707 10.293a.999.999 0 11-1.414 1.414L12 13.414l-2.293 2.293a.997.997 0 01-1.414 0 .999.999 0 010-1.414L10.586 12 8.293 9.707a.999.999 0 111.414-1.414L12 10.586l2.293-2.293a.999.999 0 111.414 1.414L13.414 12l2.293 2.293z\"></path></svg><!$><!/><svg class=\"flex cursor-pointer items-center justify-center rounded-lg bg-blue-500 p-0.5 text-center font-bold text-white hover:bg-blue-600\"viewBox=\"0 0 24 24\"stroke=currentColor stroke-width=2 style=pointer-events:all><path d=\"M19 13h-6v6h-2v-6H5v-2h6V5h2v6h6v2z\"></path></svg></div><!$><!/><!$><!/><!$><!/><div id=inputs class=\"pointer-events-none absolute top-0 z-10 flex flex-col\"><div class=\"cursor-crosshair rounded-full bg-[#e38b29] shadow-md\"style=pointer-events:all>"), pe = /*#__PURE__*/ u("<span class=\"min-w-max border-b border-[#f0f0f0] p-3 whitespace-nowrap text-red-600 select-none\">"), me = /*#__PURE__*/ u("<div class=\"p-3 select-none\">"), he = (n) => {
575
- let u, f, [m, h] = _(), { dimensions: [g, v], newEdge: [y, x], getBoardPoint: S, service: C, zoom: [T] } = J(), D = E(C, { selector: (e) => e.context.selected === n.id });
576
- b(() => {
577
- let e = u, t = f, r = m(), i = T();
578
- if (!t || !r) return;
579
- let a = r.getBoundingClientRect(), o = t.getBoundingClientRect(), s = e?.getBoundingClientRect(), c = (o.left - a.left + o.width / 2) / i, l = (o.top - a.top + o.height / 2) / i, d = s ? (s.left - a.left + s.width / 2) / i : W, p = s ? (s.top - a.top + s.height / 2) / i : 18, h = a.width / i, g = a.height / i, _ = {
580
- x: n.x + c,
581
- y: n.y + l
582
- }, y = {
583
- x: n.x + d,
584
- y: n.y + p
585
- };
586
- v(w((e) => {
587
- e[n.id] = {
588
- width: h,
589
- height: g,
590
- output: _,
591
- input: y,
592
- outputOffset: {
593
- x: c,
594
- y: l
595
- },
596
- inputOffset: {
597
- x: d,
598
- y: p
599
- }
617
+ }, fe = /*#__PURE__*/ u("<svg class=\"cursor-pointer overflow-visible rounded-full bg-green-500 p-0.5 text-center font-bold hover:bg-green-600\"viewBox=\"0 0 1024 1024\"preserveAspectRatio=xMaxYMax xmlns=http://www.w3.org/2000/svg fill=white style=pointer-events:all;fill-rule:evenodd;clip-rule:evenodd;stroke-linejoin:round;stroke-miterlimit:2><g id=background><path d=\"M467.40667,277.66696c-0.05948,-14.53055 5.75527,-22.95613 -8.62044,-20.90487c-112.55699,16.0607 -222.1609,112.14558 -245.06161,239.85765c-46.52056,259.43466 231.33083,443.06705 449.51209,316.97506c117.31668,-67.80002 160.95215,-190.43324 151.34416,-288.29849c-5.92276,-60.32819 -27.80273,-107.95668 -53.44246,-144.25469l59.39269,-42.05363c111.72214,156.309 73.11535,351.55635 -25.06953,459.45565c-184.18877,202.4124 -470.46624,145.52064 -592.95027,-32.92123c-156.18269,-227.53604 -27.15324,-543.64371 261.18883,-582.44416c5.0579,-0.68061 3.56556,-7.04079 3.56442,-8.58985c-0.05594,-76.3354 -0.11021,-76.7687 1.10909,-77.24589c2.06886,-0.80969 151.41433,118.4561 151.92482,118.95524c4.65592,4.55233 -0.99548,7.829 -29.07828,30.50907c-120.49369,97.31245 -120.4977,98.55675 -123.0691,97.87586c-0.43639,-0.11555 -0.80698,-0.31322 -0.74442,-66.91571Z\"></path><path d=\"M316.61562,611.03414c0.11517,-90.16257 -0.25516,-99.92912 0.64739,-101.78856c1.56486,-3.22393 131.99102,0.91032 134.6959,-1.89763c2.21336,-2.2977 -0.59362,-129.97807 1.1376,-132.37034c0.7253,-1.00225 11.10552,-0.99175 12.07474,-0.99077c104.50336,0.10564 104.90098,-0.37811 105.967,0.85765c1.56461,1.81373 0.25596,114.18436 0.67852,129.81412c0.1322,4.88975 3.22386,3.28152 99.72028,3.4563c33.0841,0.05992 36.14259,-1.40368 36.21852,4.50462c0.11713,9.11348 1.41954,110.45369 -0.40274,113.92715c-1.81106,3.45208 -130.39967,-0.42618 -134.48289,1.62075c-2.29035,1.14816 -0.36989,101.12392 -1.11542,130.51904c-0.09548,3.76459 -2.13506,3.20617 -47.84854,3.17365c-69.30253,-0.0493 -69.31099,-0.25627 -69.65762,-0.42191c-3.77927,-1.80595 0.16287,-129.33555 -2.24266,-132.58994c-1.79931,-2.43424 -124.06108,-0.29118 -132.80252,-0.97392c-3.81102,-0.29766 -2.58229,-14.8847 -2.58758,-16.8402Z\">"), pe = /*#__PURE__*/ u("<div id=outputs class=\"pointer-events-none absolute top-0 z-10 flex cursor-default flex-col\"><div class=\"cursor-default rounded-full bg-[#e38b29] shadow-md\"style=pointer-events:all>"), me = /*#__PURE__*/ u("<div class=min-w-48><div><svg class=\"cursor-pointer rounded-full fill-[#a11111] opacity-100 transition-all duration-200 ease-in-out\"fill=currentColor stroke-width=2 viewBox=\"4 4 16 16\"style=overflow:visible;pointer-events:all><path d=\"M12 4c-4.419 0-8 3.582-8 8s3.581 8 8 8 8-3.582 8-8-3.581-8-8-8zm3.707 10.293a.999.999 0 11-1.414 1.414L12 13.414l-2.293 2.293a.997.997 0 01-1.414 0 .999.999 0 010-1.414L10.586 12 8.293 9.707a.999.999 0 111.414-1.414L12 10.586l2.293-2.293a.999.999 0 111.414 1.414L13.414 12l2.293 2.293z\"></path></svg><!$><!/><svg class=\"flex cursor-pointer items-center justify-center rounded-lg bg-blue-500 p-0.5 text-center font-bold text-white hover:bg-blue-600\"viewBox=\"0 0 24 24\"stroke=currentColor stroke-width=2 style=pointer-events:all><path d=\"M19 13h-6v6h-2v-6H5v-2h6V5h2v6h6v2z\"></path></svg></div><!$><!/><!$><!/><!$><!/><div id=inputs class=\"pointer-events-none absolute top-0 z-10 flex flex-col\"><div class=\"cursor-crosshair rounded-full bg-[#e38b29] shadow-md\"style=pointer-events:all>"), he = /*#__PURE__*/ u("<span class=\"min-w-max border-b border-[#f0f0f0] p-3 whitespace-nowrap text-red-600 select-none\">"), ge = /*#__PURE__*/ u("<div class=\"p-3 select-none\">"), _e = (n) => {
618
+ let u = Y(), p = f(u, {
619
+ selector: ({ context: e }) => {
620
+ let t = w.typed(e.data?.nodes).find((e) => e.id === n.id);
621
+ if (t) return {
622
+ x: t.position.x,
623
+ y: t.position.y,
624
+ label: t.data.label,
625
+ content: t.data.content ?? "",
626
+ input: t.input
600
627
  };
601
- }));
602
- });
603
- let O = E(C, { selector: ({ context: { data: e } }) => {
628
+ },
629
+ equals: Q
630
+ }), h = f(u, { selector: (e) => e.context.newEdge }), g = f(u, { selector: (e) => e.context.selected === n.id }), _ = f(u, { selector: ({ context: { data: e } }) => {
604
631
  let t = e?.edges;
605
632
  return t ? t.some(({ to: e }) => e === n.id) : !1;
606
- } }), k = A(n.id);
633
+ } }), v = A(n.id);
607
634
  return (() => {
608
- var m = i(fe), _ = m.firstChild, v = _.firstChild, b = v.nextSibling, [w, T] = a(b.nextSibling), E = w.nextSibling, A = _.nextSibling, [j, M] = a(A.nextSibling), N = j.nextSibling, [P, F] = a(N.nextSibling), I = P.nextSibling, [L, R] = a(I.nextSibling), z = L.nextSibling, B = z.firstChild;
609
- return d(k, m, () => ({ skipTransform: !0 })), m.$$mousedown = (e) => {
610
- e.stopPropagation(), e.stopImmediatePropagation(), C.send({
635
+ var f = i(me), y = f.firstChild, b = y.firstChild, x = b.nextSibling, [S, C] = a(x.nextSibling), w = S.nextSibling, T = y.nextSibling, [E, D] = a(T.nextSibling), O = E.nextSibling, [k, A] = a(O.nextSibling), j = k.nextSibling, [M, N] = a(j.nextSibling), P = M.nextSibling, F = P.firstChild;
636
+ return f.$$mousedown = (e) => {
637
+ e.stopPropagation(), u.send({
611
638
  type: "SELECT",
612
639
  payload: n.id
613
640
  });
614
- }, d(h, m), v.$$click = (e) => {
615
- e.stopPropagation(), C.send({
641
+ }, d(v, f, () => ({ skipTransform: !0 })), b.$$click = (e) => {
642
+ e.stopPropagation(), u.send({
616
643
  type: "DELETE",
617
644
  payload: n.id
618
645
  });
619
- }, l(v, "width", "24px"), l(v, "height", "24px"), o(_, t(p, {
646
+ }, l(b, "width", "24px"), l(b, "height", "24px"), o(y, t(m, {
620
647
  get when() {
621
- return O();
648
+ return _();
622
649
  },
623
650
  get children() {
624
- var e = i(ue);
625
- return e.$$click = () => C.send({
651
+ var e = i(fe);
652
+ return e.$$click = () => u.send({
626
653
  type: "ADD_SIBLING",
627
654
  payload: n.id
628
655
  }), l(e, "width", "24px"), l(e, "height", "24px"), s(), e;
629
656
  }
630
- }), w, T), E.$$click = () => C.send({
657
+ }), S, C), w.$$click = () => u.send({
631
658
  type: "ADD_CHILD",
632
659
  payload: n.id
633
- }), l(E, "width", "24px"), l(E, "height", "24px"), o(m, t(p, {
660
+ }), l(w, "width", "24px"), l(w, "height", "24px"), o(f, t(m, {
634
661
  get when() {
635
- return n.label;
662
+ return p()?.label;
636
663
  },
637
664
  keyed: !0,
638
665
  children: (e) => (() => {
639
- var t = i(pe);
666
+ var t = i(he);
640
667
  return o(t, e), t;
641
668
  })()
642
- }), j, M), o(m, t(p, {
669
+ }), E, D), o(f, t(m, {
643
670
  get when() {
644
- return n.content;
671
+ return p()?.content;
645
672
  },
646
673
  keyed: !0,
647
674
  children: (e) => (() => {
648
- var t = i(me);
675
+ var t = i(ge);
649
676
  return o(t, e), t;
650
677
  })()
651
- }), P, F), o(m, t(p, {
678
+ }), k, A), o(f, t(m, {
652
679
  get when() {
653
- return n.input || O();
680
+ return p()?.input || _();
654
681
  },
655
682
  get children() {
656
- var e = i(de), t = e.firstChild;
683
+ var e = i(pe), t = e.firstChild;
657
684
  return l(e, "left", "-18px"), t.$$mouseup = (e) => {
658
685
  e.stopPropagation();
659
- let t = y()?.from;
660
- t && C.send({
686
+ let t = h()?.from;
687
+ t ? u.send({
661
688
  type: "ADD_EDGE",
662
689
  payload: {
663
690
  from: t,
664
691
  to: n.id
665
692
  }
666
- }), x();
693
+ }) : u.send("CLEAR_NEW_EDGE");
667
694
  }, t.$$mousedown = (e) => {
668
695
  e.stopPropagation();
669
- }, d((e) => u = e, t), l(t, "width", "12px"), l(t, "height", "12px"), l(t, "margin-top", "12px"), s(), e;
696
+ }, l(t, "width", "12px"), l(t, "height", "12px"), l(t, "margin-top", "12px"), s(), e;
670
697
  }
671
- }), L, R), l(z, "right", "-18px"), B.$$mousedown = (e) => {
672
- e.stopPropagation(), C.send("DESELECT");
673
- let t = g()[n.id]?.output, r = S(e.clientX, e.clientY);
674
- t && x({
675
- x0: t.x,
676
- y0: t.y,
677
- x1: r.x,
678
- y1: r.y,
679
- from: n.id
698
+ }), M, N), l(P, "right", "-18px"), F.$$mousedown = (e) => {
699
+ e.stopPropagation(), u.send("DESELECT"), u.send({
700
+ type: "START_NEW_EDGE",
701
+ payload: n.id
680
702
  });
681
- }, d((e) => f = e, B), l(B, "width", "12px"), l(B, "height", "12px"), l(B, "margin-top", "12px"), r((t) => {
682
- var r = n.id, i = {
703
+ }, l(F, "width", "12px"), l(F, "height", "12px"), l(F, "margin-top", "12px"), r((t) => {
704
+ var r = {
683
705
  "flex flex-col absolute cursor-grab bg-white rounded-md shadow-md select-none transition-[border,box-shadow] duration-200 ease-in-out hover:shadow-lg draggable": !0,
684
- "border border-[#e38c29] z-[100]": D(),
685
- "border border-[#e6d4be] z-[1]": !D()
686
- }, a = `${n.y}px`, o = `${n.x}px`, s = {
706
+ "border border-[#e38c29] z-[100]": g(),
707
+ "border border-[#e6d4be] z-[1]": !g()
708
+ }, i = `${p()?.y ?? 0}px`, a = `${p()?.x ?? 0}px`, o = n.id, s = {
687
709
  "pointer-events-none absolute flex items-center justify-end -top-7.5 right-0 transition-all duration-200 ease-in-out space-x-2": !0,
688
- "w-full opacity-100": D(),
689
- "w-0 -right-3 opacity-0 overflow-hidden": !D()
710
+ "w-full opacity-100": g(),
711
+ "w-0 -right-3 opacity-0 overflow-hidden": !g()
690
712
  };
691
- return r !== t.e && c(m, "id", t.e = r), t.t = e(m, i, t.t), a !== t.a && l(m, "top", t.a = a), o !== t.o && l(m, "left", t.o = o), t.i = e(_, s, t.i), t;
713
+ return t.e = e(f, r, t.e), i !== t.t && l(f, "top", t.t = i), a !== t.a && l(f, "left", t.a = a), o !== t.o && c(f, "id", t.o = o), t.i = e(y, s, t.i), t;
692
714
  }, {
693
715
  e: void 0,
694
716
  t: void 0,
695
717
  a: void 0,
696
718
  o: void 0,
697
719
  i: void 0
698
- }), s(), m;
720
+ }), s(), f;
699
721
  })();
700
722
  };
701
723
  n([
@@ -705,66 +727,86 @@ n([
705
727
  ]);
706
728
  //#endregion
707
729
  //#region src/ui/components/NodesBoard.tsx
708
- var ge = /*#__PURE__*/ u("<div class=\"relative h-full w-full overflow-scroll rounded-lg border-2 border-gray-600\"><!$><!/><div class=\"relative cursor-crosshair overflow-hidden\"><div class=\"relative h-full w-full\"style=\"transform-origin:top left\"><!$><!/><!$><!/><!$><!/>"), _e = /*#__PURE__*/ u("<div class=\"absolute right-4 bottom-4 z-50 flex items-center gap-2 rounded-xl border border-gray-200 bg-white/90 p-2 shadow-lg backdrop-blur-md\"><button type=button class=\"flex size-9 cursor-pointer items-center justify-center rounded-lg bg-gray-100 text-lg font-bold text-gray-700 shadow-sm transition-all duration-150 hover:bg-gray-200 active:scale-95\"title=\"Zoom out\"aria-label=\"Zoom out\">-</button><button type=button class=\"h-9 cursor-pointer rounded-lg px-2 text-xs font-semibold text-gray-700 transition-colors hover:bg-gray-100\"title=\"Reset zoom\"aria-label=\"Reset zoom\"><!$><!/>%</button><button type=button class=\"flex size-9 cursor-pointer items-center justify-center rounded-lg bg-gray-100 text-lg font-bold text-gray-700 shadow-sm transition-all duration-150 hover:bg-gray-200 active:scale-95\"title=\"Zoom in\"aria-label=\"Zoom in\">+</button><div class=\"h-5 w-px bg-gray-300\"></div><button type=button class=\"flex size-9 cursor-pointer items-center justify-center rounded-lg bg-blue-600 text-white shadow transition-all duration-150 hover:bg-blue-700 active:scale-95\"title=\"Add parent node\"aria-label=\"Add parent node\"><svg class=size-5 viewBox=\"0 0 24 24\"fill=currentColor><path d=\"M19 13h-6v6h-2v-6H5v-2h6V5h2v6h6v2z\">"), ve = /*#__PURE__*/ u("<div class=\"relative mx-auto h-[calc(100vh-64px)] w-[calc(100vw-32px)] overflow-hidden\">"), ye = () => {
709
- let e, [n, c] = _(!1), [u, m] = _({
730
+ var ve = /*#__PURE__*/ u("<div class=\"relative h-full w-full overflow-auto rounded-lg border-2 border-gray-600\"><!$><!/><div class=\"relative cursor-crosshair overflow-hidden\"><div class=\"relative h-full w-full\"style=\"transform-origin:top left\"><!$><!/><!$><!/><!$><!/>"), ye = /*#__PURE__*/ u("<div class=\"absolute right-4 bottom-4 z-50 flex items-center gap-2 rounded-xl border border-gray-200 bg-white/90 p-2 shadow-lg backdrop-blur-md\"><button type=button class=\"flex size-9 cursor-pointer items-center justify-center rounded-lg bg-gray-100 text-lg font-bold text-gray-700 shadow-sm transition-all duration-150 hover:bg-gray-200 active:scale-95\"title=\"Zoom out\"aria-label=\"Zoom out\">-</button><button type=button class=\"h-9 cursor-pointer rounded-lg px-2 text-xs font-semibold text-gray-700 transition-colors hover:bg-gray-100\"title=\"Reset zoom\"aria-label=\"Reset zoom\"><!$><!/>%</button><button type=button class=\"flex size-9 cursor-pointer items-center justify-center rounded-lg bg-gray-100 text-lg font-bold text-gray-700 shadow-sm transition-all duration-150 hover:bg-gray-200 active:scale-95\"title=\"Zoom in\"aria-label=\"Zoom in\">+</button><div class=\"h-5 w-px bg-gray-300\"></div><button type=button class=\"flex size-9 cursor-pointer items-center justify-center rounded-lg bg-blue-600 text-white shadow transition-all duration-150 hover:bg-blue-700 active:scale-95\"title=\"Add parent node\"aria-label=\"Add parent node\"><svg class=size-5 viewBox=\"0 0 24 24\"fill=currentColor><path d=\"M19 13h-6v6h-2v-6H5v-2h6V5h2v6h6v2z\">"), be = /*#__PURE__*/ u("<div class=\"relative mx-auto h-[calc(100vh-64px)] w-[calc(100vw-32px)] overflow-hidden\">"), xe = () => {
731
+ let e, [n, c] = _(!1), [u, h] = _({
710
732
  x: 0,
711
733
  y: 0
712
- }), [g, y] = _(""), [b, x] = _(), S = 0, C = 0, { board: [, w], service: T, newEdge: [A], zoom: [j, M] } = J(), N = () => {
734
+ }), [y, x] = _(""), [S, C] = _(), T = 0, E = 0, A = Y(), j = f(A, {
735
+ selector: (e) => e.context.newEdge,
736
+ equals: Q
737
+ }), M = f(A, { selector: (e) => e.context.zoom ?? 1 }), N = () => {
738
+ let e = S();
739
+ if (!e) return;
740
+ let t = e.getBoundingClientRect(), n = () => S()?.parentElement, r = {
741
+ self: {
742
+ left: t.left,
743
+ top: t.top,
744
+ width: e.clientWidth,
745
+ height: e.clientHeight
746
+ },
747
+ parent: n() ? {
748
+ scrollLeft: n().scrollLeft,
749
+ scrollTop: n().scrollTop,
750
+ height: n().clientHeight,
751
+ width: n().clientWidth
752
+ } : void 0
753
+ };
754
+ A.send({
755
+ type: "SET_BOARD",
756
+ payload: r
757
+ });
758
+ }, P = () => {
713
759
  let t = e.scrollWidth - e.clientWidth, n = e.scrollHeight - e.clientHeight;
714
- S = t > 0 ? e.scrollLeft / t : 0, C = n > 0 ? e.scrollTop / n : 0;
760
+ T = t > 0 ? e.scrollLeft / t : 0, E = n > 0 ? e.scrollTop / n : 0, N();
715
761
  };
716
- h(v(j, () => {
762
+ g(v(M, () => {
717
763
  let t = e.scrollWidth - e.clientWidth, n = e.scrollHeight - e.clientHeight;
718
- t > 0 && (e.scrollLeft = S * t), n > 0 && (e.scrollTop = C * n);
719
- }, { defer: !0 }));
720
- let P = E(T, { selector: (e) => e.context?.selected }), F = (e) => P() === e, I = E(T, {
721
- selector: (e) => (e.context.data?.nodes ?? []).map((e) => ({
722
- id: e.id,
723
- x: e.position.x,
724
- y: e.position.y,
725
- label: e.data.label,
726
- content: e.data.content ?? "",
727
- input: e.input
728
- })),
729
- equals: Z
730
- }), L = () => `calc((500vw - 265px) * ${j()})`, R = () => `calc((500vh - 425px) * ${j()})`;
764
+ t > 0 && (e.scrollLeft = T * t), n > 0 && (e.scrollTop = E * n);
765
+ }, { defer: !0 })), b(N);
766
+ let F = f(A, { selector: (e) => e.context?.selected }), I = (e) => F() === e, L = f(A, {
767
+ selector: ({ context: e }) => w.typed(e.data?.nodes).map((e) => e.id),
768
+ equals: (e, t) => e.length === t.length
769
+ }), R = () => `calc((500vw - 265px) * ${M()})`, z = () => `calc((500vh - 425px) * ${M()})`;
731
770
  return (() => {
732
- var h = i(ve);
733
- return h.addEventListener("wheel", (e) => {
771
+ var f = i(be);
772
+ return f.addEventListener("wheel", (e) => {
734
773
  if (e.ctrlKey || e.metaKey) {
735
- e.preventDefault(), N();
774
+ e.preventDefault(), P();
736
775
  let t = e.deltaY < 0 ? .1 : -.1;
737
- M((e) => Math.min(Math.max(Number((e + t).toFixed(2)), .2), 3));
776
+ A.send({
777
+ type: "ZOOM",
778
+ payload: t
779
+ });
738
780
  }
739
- }), o(h, t(D, {
781
+ }), o(f, t(D, {
740
782
  onDragMove: ({ draggable: { transform: e, node: t, id: n } }) => {
741
- if (y(n), F(n)) {
742
- let r = t.parentElement?.parentElement, i = j(), a = r ? Math.max(0, r.clientWidth / i - t.offsetWidth) : Infinity, o = r ? Math.max(0, r.clientHeight / i - t.offsetHeight) : Infinity, s = t.offsetLeft + e.x / i, c = t.offsetTop + e.y / i, l = Math.min(Math.max(s, 0), a), u = Math.min(Math.max(c, 0), o), d = l - t.offsetLeft, f = u - t.offsetTop;
743
- t.style.setProperty("transform", `translate3d(${d}px, ${f}px, 0)`), T.send({
783
+ if (x(n), I(n)) {
784
+ let r = t.parentElement?.parentElement, i = M(), a = r ? Math.max(0, r.clientWidth / i - t.offsetWidth) : Infinity, o = r ? Math.max(0, r.clientHeight / i - t.offsetHeight) : Infinity, s = t.offsetLeft + e.x / i, c = t.offsetTop + e.y / i, l = Math.min(Math.max(s, 0), a), u = Math.min(Math.max(c, 0), o), d = l - t.offsetLeft, f = u - t.offsetTop;
785
+ t.style.setProperty("transform", `translate3d(${d}px, ${f}px, 0)`), A.send({
744
786
  type: "MOVE_IMMEDIATE",
745
787
  payload: {
746
788
  id: `${n}`,
747
789
  x: l,
748
790
  y: u
749
791
  }
750
- }), m({
792
+ }), h({
751
793
  x: d * i,
752
794
  y: f * i
753
795
  });
754
796
  }
755
797
  },
756
798
  onDragEnd: ({ draggable: { node: e, id: t } }) => {
757
- if (!F(t)) return;
758
- let n = e.parentElement?.parentElement, r = j(), i = n ? Math.max(0, n.clientWidth / r - e.offsetWidth) : Infinity, a = n ? Math.max(0, n.clientHeight / r - e.offsetHeight) : Infinity, o = e.offsetLeft + u().x / r, s = e.offsetTop + u().y / r, c = Math.min(Math.max(o, 0), i), l = Math.min(Math.max(s, 0), a);
759
- e.style.setProperty("top", l + "px"), e.style.setProperty("left", c + "px"), e.style.removeProperty("transform"), setTimeout(() => {
760
- T.send({
761
- type: "MOVE",
762
- payload: {
763
- id: `${t}`,
764
- x: c,
765
- y: l
766
- }
767
- }), m({
799
+ if (!I(t)) return;
800
+ let n = e.parentElement?.parentElement, r = M(), i = n ? Math.max(0, n.clientWidth / r - e.offsetWidth) : Infinity, a = n ? Math.max(0, n.clientHeight / r - e.offsetHeight) : Infinity, o = e.offsetLeft + u().x / r, s = e.offsetTop + u().y / r, c = Math.min(Math.max(o, 0), i), l = Math.min(Math.max(s, 0), a);
801
+ e.style.setProperty("top", l + "px"), e.style.setProperty("left", c + "px"), e.style.removeProperty("transform"), A.send({
802
+ type: "MOVE",
803
+ payload: {
804
+ id: `${t}`,
805
+ x: c,
806
+ y: l
807
+ }
808
+ }), setTimeout(() => {
809
+ h({
768
810
  x: 0,
769
811
  y: 0
770
812
  });
@@ -773,26 +815,26 @@ var ge = /*#__PURE__*/ u("<div class=\"relative h-full w-full overflow-scroll ro
773
815
  get children() {
774
816
  return [
775
817
  (() => {
776
- var u = i(ge), p = u.firstChild, [m, h] = a(p.nextSibling), g = m.nextSibling, _ = g.firstChild, v = _.firstChild, [y, b] = a(v.nextSibling), x = y.nextSibling, [S, C] = a(x.nextSibling), E = S.nextSibling, [D, k] = a(E.nextSibling);
777
- return u.addEventListener("scroll", N), d((t) => e = t, u), o(u, t(O, {}), m, h), g.$$mousedown = (t) => {
778
- if (A() || t.button !== 0) return;
779
- T.send("DESELECT");
818
+ var u = i(ve), f = u.firstChild, [m, h] = a(f.nextSibling), g = m.nextSibling, _ = g.firstChild, v = _.firstChild, [y, b] = a(v.nextSibling), x = y.nextSibling, [S, w] = a(x.nextSibling), T = S.nextSibling, [E, D] = a(T.nextSibling);
819
+ return u.addEventListener("scroll", P), d((t) => e = t, u), o(u, t(O, {}), m, h), g.$$mousedown = (t) => {
820
+ if (j() || t.button !== 0) return;
821
+ A.send("DESELECT");
780
822
  let n = t.clientX, r = t.clientY, i = e.scrollLeft, a = e.scrollTop;
781
823
  c(!0);
782
824
  let o = (t) => {
783
825
  let o = t.clientX - n, s = t.clientY - r;
784
- e.scrollLeft = i - o * 3, e.scrollTop = a - s * 3, N();
826
+ e.scrollLeft = i - o * 3, e.scrollTop = a - s * 3, P();
785
827
  }, s = () => {
786
828
  window.removeEventListener("mousemove", o), window.removeEventListener("mouseup", s), setTimeout(() => c(!1), 200);
787
829
  };
788
830
  window.addEventListener("mousemove", o), window.addEventListener("mouseup", s);
789
- }, d(w, g), o(_, t(ie, {}), y, b), o(_, t(le, {}), S, C), o(_, t(f, {
831
+ }, g.addEventListener("scroll", () => {}), d(C, g), o(_, t(ae, {}), y, b), o(_, t(de, {}), S, w), o(_, t(p, {
790
832
  get each() {
791
- return I();
833
+ return L();
792
834
  },
793
- children: he
794
- }), D, k), r((e) => {
795
- var t = !!n(), r = R(), i = L(), a = j();
835
+ children: (e) => t(_e, { id: e })
836
+ }), E, D), r((e) => {
837
+ var t = !!n(), r = z(), i = R(), a = M();
796
838
  return t !== e.e && g.classList.toggle("cursor-grabbing", e.e = t), r !== e.t && l(g, "height", e.t = r), i !== e.a && l(g, "width", e.a = i), a !== e.o && l(_, "scale", e.o = a), e;
797
839
  }, {
798
840
  e: void 0,
@@ -802,20 +844,26 @@ var ge = /*#__PURE__*/ u("<div class=\"relative h-full w-full overflow-scroll ro
802
844
  }), s(), u;
803
845
  })(),
804
846
  (() => {
805
- var e = i(_e), t = e.firstChild, n = t.nextSibling, r = n.firstChild, [c, l] = a(r.nextSibling);
847
+ var e = i(ye), t = e.firstChild, n = t.nextSibling, r = n.firstChild, [c, l] = a(r.nextSibling);
806
848
  c.nextSibling;
807
849
  var u = n.nextSibling, d = u.nextSibling.nextSibling;
808
850
  return t.$$click = () => {
809
- N(), x(void 0), M((e) => Math.max(1 / 5, Number((e - .1).toFixed(2))));
851
+ P(), A.send({
852
+ type: "ZOOM",
853
+ payload: -.1
854
+ });
810
855
  }, n.$$click = () => {
811
- N(), b() ? (M(b()), x(void 0)) : (x(j()), M(1));
812
- }, o(n, () => Math.round(j() * 100), c, l), u.$$click = () => {
813
- N(), x(void 0), M((e) => Math.min(3, Number((e + .1).toFixed(2))));
814
- }, d.$$click = () => T.send("ADD_PARENT"), s(), e;
856
+ P(), A.send("TOGGLE_ZOOM");
857
+ }, o(n, () => Math.round(M() * 100), c, l), u.$$click = () => {
858
+ P(), A.send({
859
+ type: "ZOOM",
860
+ payload: .1
861
+ });
862
+ }, d.$$click = () => A.send("ADD_PARENT"), s(), e;
815
863
  })(),
816
- t(p, {
864
+ t(m, {
817
865
  get when() {
818
- return !g() || !F(g());
866
+ return !y() || !I(y());
819
867
  },
820
868
  get children() {
821
869
  return t(k, { children: "" });
@@ -823,42 +871,40 @@ var ge = /*#__PURE__*/ u("<div class=\"relative h-full w-full overflow-scroll ro
823
871
  })
824
872
  ];
825
873
  }
826
- })), h;
874
+ })), f;
827
875
  })();
828
876
  };
829
877
  n(["mousedown", "click"]);
830
878
  //#endregion
831
879
  //#region src/ui/components/FlowChart.tsx
832
- var be = /*#__PURE__*/ u("<div class=\"relative h-full w-full\"><div class=\"relative h-full w-full bg-white bg-size-[30px_30px]\"style=\"background-image:radial-gradient(circle, #b8b8b8bf 1px, rgba(0, 0, 0, 0) 1px)\">"), xe = (e) => {
833
- let n = e.config?.nodes ?? ne, a = e.config?.edges, { service: c, newEdge: [u, d], getBoardPoint: f } = J();
880
+ var Se = /*#__PURE__*/ u("<div class=\"relative h-full w-full\"><div class=\"relative h-full w-full bg-white bg-size-[30px_30px]\"style=\"background-image:radial-gradient(circle, #b8b8b8bf 1px, rgba(0, 0, 0, 0) 1px)\">"), Ce = (e) => {
881
+ let n = e.config?.nodes ?? L, a = e.config?.edges, c = Y(), u = f(c, { selector: (e) => !!e.context.newEdge });
834
882
  return b(() => {
835
- c.start(), c.send({
883
+ c.resume(), c.send({
836
884
  type: "CONFIGURE",
837
885
  payload: {
838
886
  nodes: n,
839
887
  edges: a ?? []
840
888
  }
841
889
  });
842
- }), y(c.stop), (() => {
843
- var e = i(be), n = e.firstChild;
890
+ }), y(c.pause), (() => {
891
+ var e = i(Se), n = e.firstChild;
844
892
  return e.$$mousemove = (e) => {
845
- let t = u();
846
- if (t) {
847
- let n = f(e.clientX, e.clientY);
848
- d({
849
- ...t,
850
- x1: n.x,
851
- y1: n.y
852
- });
853
- }
854
- }, e.$$mouseup = () => d(), o(n, t(ye, {})), r((e) => l(n, "cursor", u() ? "inherit" : "crosshair")), s(), e;
893
+ c.send({
894
+ type: "MOVE_NEW_EDGE",
895
+ payload: {
896
+ x: e.clientX,
897
+ y: e.clientY
898
+ }
899
+ });
900
+ }, e.$$mouseup = () => c.send("CLEAR_NEW_EDGE"), o(n, t(xe, {})), r((e) => l(n, "cursor", u() ? "inherit" : "crosshair")), s(), e;
855
901
  })();
856
902
  };
857
903
  n(["mouseup", "mousemove"]);
858
904
  //#endregion
859
905
  //#region src/ui/Flow.tsx
860
- var Se = (e) => t(re, { get children() {
861
- return t(xe, e);
906
+ var we = (e) => t(ie, { get children() {
907
+ return t(Ce, e);
862
908
  } });
863
909
  //#endregion
864
- export { M as CLASSES, Se as Flow };
910
+ export { M as CLASSES, we as Flow };