@bemedev/mind-flow 0.3.0 → 0.3.2

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
package/lib/server.cjs.js CHANGED
@@ -460,6 +460,11 @@ var machine = (0, _bemedev_app.createMachine)({
460
460
  dimensions[id] = calculateDimensions(position);
461
461
  });
462
462
  } })),
463
+ setBoard: assign("board", { SET_BOARD: ({ payload }) => payload }),
464
+ generateID: action(({ pContext }) => pContext.generatedId = (0, nanoid.nanoid)()),
465
+ select: assign("selected", { SELECT: ({ payload }) => payload }),
466
+ clearNewEdge: erase("newEdge"),
467
+ deselect: erase("selected"),
463
468
  startNewEdge: assign("newEdge", { START_NEW_EDGE: ({ payload: from, pContext: { dimensions } }) => {
464
469
  const { x, y } = dimensions[from].output;
465
470
  return {
@@ -470,7 +475,6 @@ var machine = (0, _bemedev_app.createMachine)({
470
475
  y1: y
471
476
  };
472
477
  } }),
473
- setBoard: assign("board", { SET_BOARD: ({ payload }) => payload }),
474
478
  buildUI: batch(assign("edgesPositions", {
475
479
  MOVE: ({ context: { data, edgesPositions }, payload, pContext: { dimensions } }) => {
476
480
  const edges = data?.edges;
@@ -503,26 +507,27 @@ var machine = (0, _bemedev_app.createMachine)({
503
507
  },
504
508
  MOVE_IMMEDIATE: ({ context: { data, edgesPositions }, payload, pContext: { dimensions } }) => {
505
509
  (data?.edges)?.forEach(({ from, to, id }) => {
510
+ const dimension = dimensions[payload.id];
511
+ const edgePosition = edgesPositions[id];
512
+ if (!edgePosition || !dimension) return;
506
513
  if (from === payload.id) {
507
- const dimension = dimensions[payload.id];
508
- const offset = dimension?.outputOffset ?? getDefaultOutputOffset(dimension?.width);
514
+ const offset = dimension.outputOffset ?? getDefaultOutputOffset(dimension.width);
509
515
  const x0 = payload.x + offset.x;
510
516
  const y0 = payload.y + offset.y;
511
- edgesPositions[id].x0 = x0;
512
- edgesPositions[id].y0 = y0;
513
- if (dimension) {
514
- dimension.output.x = x0;
515
- dimension.output.y = y0;
516
- }
517
+ edgePosition.x0 = x0;
518
+ edgePosition.y0 = y0;
519
+ dimension.output = {
520
+ x: x0,
521
+ y: y0
522
+ };
517
523
  }
518
524
  if (to === payload.id) {
519
- const dimension = dimensions[payload.id];
520
525
  const offset = dimension?.inputOffset ?? DEFAULT_INPUT_OFFSET;
521
526
  const x1 = payload.x + offset.x;
522
527
  const y1 = payload.y + offset.y;
523
- edgesPositions[id].x1 = x1;
524
- edgesPositions[id].y1 = y1;
525
- if (dimension) dimension.input = {
528
+ edgePosition.x1 = x1;
529
+ edgePosition.y1 = y1;
530
+ dimension.input = {
526
531
  x: x1,
527
532
  y: y1
528
533
  };
@@ -531,7 +536,7 @@ var machine = (0, _bemedev_app.createMachine)({
531
536
  return edgesPositions;
532
537
  },
533
538
  else: ({ context: { data, edgesPositions }, pContext: { dimensions } }) => {
534
- const edges = data?.edges ?? [];
539
+ const edges = _bemedev_app_bemedev.toArray.typed(data?.edges);
535
540
  edgesPositions = {};
536
541
  edges.forEach(({ from, id, to }) => {
537
542
  const output = dimensions[from]?.output;
@@ -550,9 +555,6 @@ var machine = (0, _bemedev_app.createMachine)({
550
555
  addDimension: action({ ADD_DIMENSION: ({ payload: { id, dimension }, pContext: { dimensions } }) => {
551
556
  dimensions[id] = dimension;
552
557
  } }),
553
- generateID: action(({ pContext }) => {
554
- pContext.generatedId = (0, nanoid.nanoid)();
555
- }),
556
558
  linkChild: batch(assign("data.edges", { ADD_CHILD: ({ context: { data }, pContext, payload }) => {
557
559
  const edges = _bemedev_app_bemedev.toArray.typed(data?.edges);
558
560
  const from = payload;
@@ -581,20 +583,18 @@ var machine = (0, _bemedev_app.createMachine)({
581
583
  return edges;
582
584
  } }), assign("selected", ({ pContext: { generatedId } }) => buildNodeID(generatedId))),
583
585
  selectParent: assign("selected", ({ pContext: { generatedId } }) => buildNodeID(generatedId)),
584
- moveNode: assign("data.nodes", { MOVE: ({ context: { data }, payload }) => {
585
- const { id, x, y } = payload;
586
- return data?.nodes?.map((d) => {
587
- if (d.id === id) return {
588
- ...d,
586
+ moveNode: assign("data.nodes", { MOVE: ({ context: { data }, payload: { id, x, y } }) => {
587
+ return data?.nodes?.map((node) => {
588
+ if (node.id === id) return {
589
+ ...node,
589
590
  position: {
590
591
  x,
591
592
  y
592
593
  }
593
594
  };
594
- return d;
595
- }) ?? [];
595
+ return node;
596
+ });
596
597
  } }),
597
- select: assign("selected", { SELECT: ({ payload }) => payload }),
598
598
  delete: batch(filter("data.edges", { DELETE: ({ id, from, to }, _, { payload }) => {
599
599
  return id !== payload && from !== payload && to !== payload;
600
600
  } }), filter("data.nodes", { DELETE: ({ id }, _, { payload }) => id !== payload })),
@@ -608,8 +608,6 @@ var machine = (0, _bemedev_app.createMachine)({
608
608
  to
609
609
  }];
610
610
  } }), erase("newEdge")),
611
- clearNewEdge: erase("newEdge"),
612
- deselect: erase("selected"),
613
611
  zoom: assign("zoom", { ZOOM: ({ context: { zoom }, payload, pContext }) => {
614
612
  const next = zoom + payload;
615
613
  const clamped = Math.min(Math.max(Number(next.toFixed(2)), .2), 3);
@@ -624,6 +622,87 @@ var machine = (0, _bemedev_app.createMachine)({
624
622
  }
625
623
  pContext.previousZoom = zoom;
626
624
  return 1;
625
+ } }),
626
+ placeChild: assign("data.nodes", { ADD_CHILD: ({ payload, context: { data, board }, pContext }) => {
627
+ if (!board) return data?.nodes;
628
+ const nodes = data?.nodes;
629
+ if (!payload) return nodes;
630
+ const parentNode = nodes?.find((node) => node.id === payload);
631
+ if (!parentNode) return nodes;
632
+ const parentDimension = pContext.dimensions[payload];
633
+ const id = `node-${pContext.generatedId}`;
634
+ const width = parentDimension?.width ?? 192;
635
+ const height = parentDimension?.height ?? 50;
636
+ const initialX = parentNode.position.x + width + 100;
637
+ const initialY = parentNode.position.y;
638
+ const position = pContext.clampPosition(board, initialX, initialY, width, height);
639
+ const dimension = pContext.calculateDimensions(position, parentDimension);
640
+ nodes?.push({
641
+ id,
642
+ data: { content: "<Nouveau nœud>" },
643
+ input: true,
644
+ position
645
+ });
646
+ pContext.dimensions[id] = dimension;
647
+ return nodes;
648
+ } }),
649
+ placeParent: assign("data.nodes", { ADD_PARENT: ({ context: { data, zoom = 1, board }, pContext }) => {
650
+ if (!board) return data?.nodes;
651
+ const nodes = data?.nodes;
652
+ const id = `node-${pContext.generatedId}`;
653
+ const container = board.parent;
654
+ const scrollLeft = container?.scrollLeft ?? 0;
655
+ const scrollTop = container?.scrollTop ?? 0;
656
+ const width = container?.width ?? 0;
657
+ const height = container?.height ?? 0;
658
+ const currentZoom = zoom;
659
+ const x = (scrollLeft + width / 2) / currentZoom;
660
+ const y = (scrollTop + height / 2) / currentZoom;
661
+ const position = pContext.clampPosition(board, x, y);
662
+ const dimension = pContext.calculateDimensions(position);
663
+ nodes?.push({
664
+ id,
665
+ data: { content: "<Nouveau nœud>" },
666
+ input: false,
667
+ position
668
+ });
669
+ pContext.dimensions[id] = dimension;
670
+ return nodes;
671
+ } }),
672
+ placeSibling: assign("data.nodes", { ADD_SIBLING: ({ payload, context: { data, board }, pContext }) => {
673
+ if (!board) return data?.nodes;
674
+ const edges = data?.edges;
675
+ const nodes = data?.nodes;
676
+ const parentID = edges?.find((edge) => edge.to === payload)?.from;
677
+ if (!parentID) return nodes;
678
+ const parentNode = nodes?.find((node) => node.id === parentID);
679
+ if (!parentNode) return nodes;
680
+ const parentDimension = pContext.dimensions[parentID];
681
+ const id = `node-${pContext.generatedId}`;
682
+ const width = parentDimension?.width ?? 192;
683
+ const height = parentDimension?.height ?? 50;
684
+ const initialX = parentNode.position.x + width + 100;
685
+ const initialY = parentNode.position.y + 100;
686
+ const position = pContext.clampPosition(board, initialX, initialY, width, height);
687
+ const dimension = pContext.calculateDimensions(position, parentDimension);
688
+ nodes?.push({
689
+ id,
690
+ data: { content: "<Nouveau nœud>" },
691
+ input: true,
692
+ position
693
+ });
694
+ pContext.dimensions[id] = dimension;
695
+ return nodes;
696
+ } }),
697
+ moveNewEdge: assign("newEdge", { MOVE_NEW_EDGE: ({ context: { newEdge, board }, payload, pContext }) => {
698
+ if (!board) return void 0;
699
+ if (!newEdge) return void 0;
700
+ const { x: x1, y: y1 } = pContext.getBoardPosition(payload.x, payload.y, board);
701
+ return {
702
+ ...newEdge,
703
+ x1,
704
+ y1
705
+ };
627
706
  } })
628
707
  } }));
629
708
  //#endregion
@@ -657,7 +736,7 @@ var [Provider, useFlow] = createContext(() => {
657
736
  *
658
737
  * @returns Calculated 2D coordinate of type {@linkcode Point}.
659
738
  */
660
- getBoardPosition(clientX, clientY, el) {
739
+ getBoardPosition: (clientX, clientY, el) => {
661
740
  if (!el) return {
662
741
  x: clientX,
663
742
  y: clientY
@@ -682,7 +761,7 @@ var [Provider, useFlow] = createContext(() => {
682
761
  *
683
762
  * @see {@linkcode BOUNDS_CONSTRAINTS}
684
763
  */
685
- clampPosition(board, x, y, nodeWidth = 192, nodeHeight = 50) {
764
+ clampPosition: (board, x, y, nodeWidth = 192, nodeHeight = 50) => {
686
765
  const container = board?.parent;
687
766
  if (!container) return {
688
767
  x,
@@ -734,89 +813,6 @@ var [Provider, useFlow] = createContext(() => {
734
813
  }
735
814
  }
736
815
  });
737
- service.addOptions(({ assign }) => ({ actions: {
738
- placeChild: assign("data.nodes", { ADD_CHILD: ({ payload, context: { data, board }, pContext }) => {
739
- if (!board) return data?.nodes;
740
- const nodes = data?.nodes;
741
- if (!payload) return nodes;
742
- const parentNode = nodes?.find((node) => node.id === payload);
743
- if (!parentNode) return nodes;
744
- const parentDimension = pContext.dimensions[payload];
745
- const id = `node-${pContext.generatedId}`;
746
- const width = parentDimension?.width ?? 192;
747
- const height = parentDimension?.height ?? 50;
748
- const initialX = parentNode.position.x + width + 100;
749
- const initialY = parentNode.position.y;
750
- const position = pContext.clampPosition(board, initialX, initialY, width, height);
751
- const dimension = pContext.calculateDimensions(position, parentDimension);
752
- nodes?.push({
753
- id,
754
- data: { content: "<Nouveau nœud>" },
755
- input: true,
756
- position
757
- });
758
- pContext.dimensions[id] = dimension;
759
- return nodes;
760
- } }),
761
- placeParent: assign("data.nodes", { ADD_PARENT: ({ context: { data, zoom = 1, board }, pContext }) => {
762
- if (!board) return data?.nodes;
763
- const nodes = data?.nodes;
764
- const id = `node-${pContext.generatedId}`;
765
- const container = board.parent;
766
- const scrollLeft = container?.scrollLeft ?? 0;
767
- const scrollTop = container?.scrollTop ?? 0;
768
- const width = container?.width ?? 0;
769
- const height = container?.height ?? 0;
770
- const currentZoom = zoom;
771
- const x = (scrollLeft + width / 2) / currentZoom;
772
- const y = (scrollTop + height / 2) / currentZoom;
773
- const position = pContext.clampPosition(board, x, y);
774
- const dimension = pContext.calculateDimensions(position);
775
- nodes?.push({
776
- id,
777
- data: { content: "<Nouveau nœud>" },
778
- input: false,
779
- position
780
- });
781
- pContext.dimensions[id] = dimension;
782
- return nodes;
783
- } }),
784
- placeSibling: assign("data.nodes", { ADD_SIBLING: ({ payload, context: { data, board }, pContext }) => {
785
- if (!board) return data?.nodes;
786
- const edges = data?.edges;
787
- const nodes = data?.nodes;
788
- const parentID = edges?.find((edge) => edge.to === payload)?.from;
789
- if (!parentID) return nodes;
790
- const parentNode = nodes?.find((node) => node.id === parentID);
791
- if (!parentNode) return nodes;
792
- const parentDimension = pContext.dimensions[parentID];
793
- const id = `node-${pContext.generatedId}`;
794
- const width = parentDimension?.width ?? 192;
795
- const height = parentDimension?.height ?? 50;
796
- const initialX = parentNode.position.x + width + 100;
797
- const initialY = parentNode.position.y + 100;
798
- const position = pContext.clampPosition(board, initialX, initialY, width, height);
799
- const dimension = pContext.calculateDimensions(position, parentDimension);
800
- nodes?.push({
801
- id,
802
- data: { content: "<Nouveau nœud>" },
803
- input: true,
804
- position
805
- });
806
- pContext.dimensions[id] = dimension;
807
- return nodes;
808
- } }),
809
- moveNewEdge: assign("newEdge", { MOVE_NEW_EDGE: ({ context: { newEdge, board }, payload, pContext }) => {
810
- if (!board) return void 0;
811
- if (!newEdge) return void 0;
812
- const { x: x1, y: y1 } = pContext.getBoardPosition(payload.x, payload.y, board);
813
- return {
814
- ...newEdge,
815
- x1,
816
- y1
817
- };
818
- } })
819
- } }));
820
816
  service.start();
821
817
  return service;
822
818
  }, { name: "FlowContext" });
@@ -917,18 +913,9 @@ var draw = ({ x0, y0, x1, y1 }) => {
917
913
  var EdgeComponent = (props) => {
918
914
  const service = useFlow();
919
915
  const vector = (0, _bemedev_app_solidjs.createState)(service, {
920
- selector: ({ context }) => {
921
- if (props.isNew) {
922
- const edge = context.newEdge;
923
- if (!edge) return void 0;
924
- return {
925
- x0: edge.x0,
926
- y0: edge.y0,
927
- x1: edge.x1,
928
- y1: edge.y1
929
- };
930
- }
931
- return context.edgesPositions[props.id];
916
+ selector: ({ context: { newEdge, edgesPositions } }) => {
917
+ if (props.isNew) return newEdge;
918
+ return edgesPositions[props.id];
932
919
  },
933
920
  equals: dequal.dequal
934
921
  });
@@ -936,28 +923,19 @@ var EdgeComponent = (props) => {
936
923
  /** Computes the 2D midpoint coordinate of the edge curve for handle placement. */
937
924
  const middlePoint = () => {
938
925
  const v = vector();
939
- if (!v) return {
940
- x: 0,
941
- y: 0
942
- };
943
926
  return {
944
927
  x: v.x0 + (v.x1 - v.x0) / 2,
945
928
  y: v.y0 + (v.y1 - v.y0) / 2
946
929
  };
947
930
  };
948
- return (0, solid_js_web.createComponent)(solid_js.Show, {
931
+ return [(0, solid_js_web.ssr)(_tmpl$$4, (0, solid_js_web.ssrHydrationKey)(), `relative cursor-pointer fill-transparent ${!!props.isNew ? "stroke-[rgba(168,168,168,0.4)] stroke-3 z-200" : ""} ${selected() && !props.isNew ? "stroke-[rgba(168,168,168,1)] stroke-4 z-100" : ""} ${!selected() && !props.isNew ? "stroke-[rgba(168,168,168,0.8)] stroke-3" : ""}`, (0, solid_js_web.ssrStyleProperty)("pointer-events:", props.isNew ? "none" : "all"), (0, solid_js_web.ssrAttribute)("d", (0, solid_js_web.escape)(draw(vector()), true), false)), (0, solid_js_web.createComponent)(solid_js.Show, {
949
932
  get when() {
950
- return vector();
933
+ return selected();
951
934
  },
952
- children: (v) => [(0, solid_js_web.ssr)(_tmpl$$4, (0, solid_js_web.ssrHydrationKey)(), `relative cursor-pointer fill-transparent ${!!props.isNew ? "stroke-[rgba(168,168,168,0.4)] stroke-3 z-200" : ""} ${selected() && !props.isNew ? "stroke-[rgba(168,168,168,1)] stroke-4 z-100" : ""} ${!selected() && !props.isNew ? "stroke-[rgba(168,168,168,0.8)] stroke-3" : ""}`, (0, solid_js_web.ssrStyleProperty)("pointer-events:", props.isNew ? "none" : "all"), (0, solid_js_web.ssrAttribute)("d", (0, solid_js_web.escape)(draw(v()), true), false)), (0, solid_js_web.createComponent)(solid_js.Show, {
953
- get when() {
954
- return selected();
955
- },
956
- get children() {
957
- return (0, solid_js_web.ssr)(_tmpl$2$2, (0, solid_js_web.ssrHydrationKey)(), `translate(${(0, solid_js_web.escape)(middlePoint().x, true)}, ${(0, solid_js_web.escape)(middlePoint().y, true)})`, (0, solid_js_web.ssrStyleProperty)("pointer-events:", "all") + (0, solid_js_web.ssrStyleProperty)(";z-index:", "30"));
958
- }
959
- })]
960
- });
935
+ get children() {
936
+ return (0, solid_js_web.ssr)(_tmpl$2$2, (0, solid_js_web.ssrHydrationKey)(), `translate(${(0, solid_js_web.escape)(middlePoint().x, true)}, ${(0, solid_js_web.escape)(middlePoint().y, true)})`, (0, solid_js_web.ssrStyleProperty)("pointer-events:", "all") + (0, solid_js_web.ssrStyleProperty)(";z-index:", "30"));
937
+ }
938
+ })];
961
939
  };
962
940
  //#endregion
963
941
  //#region src/ui/components/EdgesBoard.tsx
@@ -1008,7 +986,7 @@ var _tmpl$$2 = [
1008
986
  ];
1009
987
  var _tmpl$2$1 = [
1010
988
  "<div",
1011
- " id=\"outputs\" class=\"pointer-events-none absolute top-0 z-10 flex cursor-default flex-col\" style=\"",
989
+ " id=\"inputs\" class=\"pointer-events-none absolute top-0 z-10 flex cursor-default flex-col\" style=\"",
1012
990
  "\"><div class=\"cursor-default rounded-full bg-[#e38b29] shadow-md\" style=\"",
1013
991
  "\"></div></div>"
1014
992
  ];
@@ -1024,7 +1002,7 @@ var _tmpl$3$1 = [
1024
1002
  "\"><path d=\"M19 13h-6v6h-2v-6H5v-2h6V5h2v6h6v2z\"></path></svg></div><!--$-->",
1025
1003
  "<!--/--><!--$-->",
1026
1004
  "<!--/--><!--$-->",
1027
- "<!--/--><div id=\"inputs\" class=\"pointer-events-none absolute top-0 z-10 flex flex-col\" style=\"",
1005
+ "<!--/--><div id=\"outputs\" class=\"pointer-events-none absolute top-0 z-10 flex flex-col\" style=\"",
1028
1006
  "\"><div class=\"cursor-crosshair rounded-full bg-[#e38b29] shadow-md\" style=\"",
1029
1007
  "\"></div></div></div>"
1030
1008
  ];
@@ -1050,10 +1028,11 @@ var _tmpl$5 = [
1050
1028
  */
1051
1029
  var NodeComponent = (props) => {
1052
1030
  const service = useFlow();
1031
+ (0, _bemedev_app_solidjs.createState)(service, { selector: (s) => s.context.newEdge });
1032
+ (0, _thisbeyond_solid_dnd.createDraggable)(props.id);
1053
1033
  const node = (0, _bemedev_app_solidjs.createState)(service, {
1054
1034
  selector: ({ context }) => {
1055
1035
  const item = _bemedev_app.toArray.typed(context.data?.nodes).find((n) => n.id === props.id);
1056
- if (!item) return void 0;
1057
1036
  return {
1058
1037
  x: item.position.x,
1059
1038
  y: item.position.y,
@@ -1064,15 +1043,13 @@ var NodeComponent = (props) => {
1064
1043
  },
1065
1044
  equals: dequal.dequal
1066
1045
  });
1067
- (0, _bemedev_app_solidjs.createState)(service, { selector: (s) => s.context.newEdge });
1068
- const selected = (0, _bemedev_app_solidjs.createState)(service, { selector: (s) => s.context.selected === props.id });
1046
+ const selected = (0, _bemedev_app_solidjs.createState)(service, { selector: ({ context }) => context.selected === props.id });
1069
1047
  const hasParent = (0, _bemedev_app_solidjs.createState)(service, { selector: ({ context: { data } }) => {
1070
1048
  const edges = data?.edges;
1071
1049
  if (!edges) return false;
1072
1050
  return edges.some(({ to }) => to === props.id);
1073
1051
  } });
1074
- (0, _thisbeyond_solid_dnd.createDraggable)(props.id);
1075
- return (0, solid_js_web.ssr)(_tmpl$3$1, (0, solid_js_web.ssrHydrationKey)(), `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 ${selected() ? "border border-[#e38c29] z-[100]" : ""} ${!selected() ? "border border-[#e6d4be] z-[1]" : ""} min-w-48`, (0, solid_js_web.ssrStyleProperty)("top:", `${(0, solid_js_web.escape)(node()?.y ?? 0, true)}px`) + (0, solid_js_web.ssrStyleProperty)(";left:", `${(0, solid_js_web.escape)(node()?.x ?? 0, true)}px`), (0, solid_js_web.ssrAttribute)("id", (0, solid_js_web.escape)(props.id, true), false), `pointer-events-none absolute flex items-center justify-end -top-7.5 right-0 transition-all duration-200 ease-in-out space-x-2 ${selected() ? "w-full opacity-100" : ""} ${!selected() ? "w-0 -right-3 opacity-0 overflow-hidden" : ""}`, (0, solid_js_web.ssrStyleProperty)("overflow:", "visible") + (0, solid_js_web.ssrStyleProperty)(";pointer-events:", "all") + (0, solid_js_web.ssrStyleProperty)(";width:", `${(0, solid_js_web.escape)(12, true) * 2}px`) + (0, solid_js_web.ssrStyleProperty)(";height:", `${(0, solid_js_web.escape)(12, true) * 2}px`), (0, solid_js_web.escape)((0, solid_js_web.createComponent)(solid_js.Show, {
1052
+ return (0, solid_js_web.ssr)(_tmpl$3$1, (0, solid_js_web.ssrHydrationKey)(), `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 ${selected() ? "border border-[#e38c29] z-[100]" : ""} ${!selected() ? "border border-[#e6d4be] z-[1]" : ""} min-w-48`, (0, solid_js_web.ssrStyleProperty)("top:", `${(0, solid_js_web.escape)(node().y, true)}px`) + (0, solid_js_web.ssrStyleProperty)(";left:", `${(0, solid_js_web.escape)(node().x, true)}px`), (0, solid_js_web.ssrAttribute)("id", (0, solid_js_web.escape)(props.id, true), false), `pointer-events-none absolute flex items-center justify-end -top-7.5 right-0 transition-all duration-200 ease-in-out space-x-2 ${selected() ? "w-full opacity-100" : ""} ${!selected() ? "w-0 -right-3 opacity-0 overflow-hidden" : ""}`, (0, solid_js_web.ssrStyleProperty)("overflow:", "visible") + (0, solid_js_web.ssrStyleProperty)(";pointer-events:", "all") + (0, solid_js_web.ssrStyleProperty)(";width:", `${(0, solid_js_web.escape)(12, true) * 2}px`) + (0, solid_js_web.ssrStyleProperty)(";height:", `${(0, solid_js_web.escape)(12, true) * 2}px`), (0, solid_js_web.escape)((0, solid_js_web.createComponent)(solid_js.Show, {
1076
1053
  get when() {
1077
1054
  return hasParent();
1078
1055
  },
@@ -1081,19 +1058,19 @@ var NodeComponent = (props) => {
1081
1058
  }
1082
1059
  })), (0, solid_js_web.ssrStyleProperty)("pointer-events:", "all") + (0, solid_js_web.ssrStyleProperty)(";width:", `${(0, solid_js_web.escape)(12, true) * 2}px`) + (0, solid_js_web.ssrStyleProperty)(";height:", `${(0, solid_js_web.escape)(12, true) * 2}px`), (0, solid_js_web.escape)((0, solid_js_web.createComponent)(solid_js.Show, {
1083
1060
  get when() {
1084
- return node()?.label;
1061
+ return node().label;
1085
1062
  },
1086
1063
  keyed: true,
1087
1064
  children: (label) => (0, solid_js_web.ssr)(_tmpl$4, (0, solid_js_web.ssrHydrationKey)(), (0, solid_js_web.escape)(label))
1088
1065
  })), (0, solid_js_web.escape)((0, solid_js_web.createComponent)(solid_js.Show, {
1089
1066
  get when() {
1090
- return node()?.content;
1067
+ return node().content;
1091
1068
  },
1092
1069
  keyed: true,
1093
1070
  children: (content) => (0, solid_js_web.ssr)(_tmpl$5, (0, solid_js_web.ssrHydrationKey)(), (0, solid_js_web.escape)(content))
1094
1071
  })), (0, solid_js_web.escape)((0, solid_js_web.createComponent)(solid_js.Show, {
1095
1072
  get when() {
1096
- return node()?.input || hasParent();
1073
+ return node().input || hasParent();
1097
1074
  },
1098
1075
  get children() {
1099
1076
  return (0, solid_js_web.ssr)(_tmpl$2$1, (0, solid_js_web.ssrHydrationKey)(), (0, solid_js_web.ssrStyleProperty)("left:", `-${(0, solid_js_web.escape)(18, true)}px`), (0, solid_js_web.ssrStyleProperty)("width:", `${(0, solid_js_web.escape)(12, true)}px`) + (0, solid_js_web.ssrStyleProperty)(";height:", `${(0, solid_js_web.escape)(12, true)}px`) + (0, solid_js_web.ssrStyleProperty)(";margin-top:", `${(0, solid_js_web.escape)(12, true)}px`) + (0, solid_js_web.ssrStyleProperty)(";pointer-events:", "all"));
@@ -1138,7 +1115,6 @@ var NodesBoard = () => {
1138
1115
  x: 0,
1139
1116
  y: 0
1140
1117
  });
1141
- const [id, setId] = (0, solid_js.createSignal)("");
1142
1118
  const [ref, setRef] = (0, solid_js.createSignal)();
1143
1119
  let percentX = 0;
1144
1120
  let percentY = 0;
@@ -1184,14 +1160,6 @@ var NodesBoard = () => {
1184
1160
  }, { defer: true }));
1185
1161
  (0, solid_js.onMount)(sendBoard);
1186
1162
  const selectedId = (0, _bemedev_app_solidjs.createState)(service, { selector: (s) => s.context?.selected });
1187
- /**
1188
- * Determines whether the given element ID matches the currently selected entity.
1189
- *
1190
- * @param id - The node or edge identifier to check.
1191
- *
1192
- * @returns `true` if the item is currently selected, otherwise `false`.
1193
- */
1194
- const selected = (id) => selectedId() === id;
1195
1163
  const nodeIds = (0, _bemedev_app_solidjs.createState)(service, {
1196
1164
  selector: ({ context }) => {
1197
1165
  return _bemedev_app.toArray.typed(context.data?.nodes).map((item) => item.id);
@@ -1207,37 +1175,33 @@ var NodesBoard = () => {
1207
1175
  const cHeight = () => `calc((${CANVAS_SIZE}vh - ${MARGIN_Y}px) * ${zoom()})`;
1208
1176
  return (0, solid_js_web.ssr)(_tmpl$3, (0, solid_js_web.ssrHydrationKey)(), (0, solid_js_web.escape)((0, solid_js_web.createComponent)(_thisbeyond_solid_dnd.DragDropProvider, {
1209
1177
  onDragMove: ({ draggable: { transform: _transform, node, id } }) => {
1210
- setId(id);
1211
- if (selected(id)) {
1212
- const grandParent = node.parentElement?.parentElement;
1213
- const currentZoom = zoom();
1214
- const minX = 0;
1215
- const maxX = grandParent ? Math.max(0, grandParent.clientWidth / currentZoom - node.offsetWidth) : Infinity;
1216
- const minY = 0;
1217
- const maxY = grandParent ? Math.max(0, grandParent.clientHeight / currentZoom - node.offsetHeight) : Infinity;
1218
- const targetX = node.offsetLeft + _transform.x / currentZoom;
1219
- const targetY = node.offsetTop + _transform.y / currentZoom;
1220
- const x = Math.min(Math.max(targetX, minX), maxX);
1221
- const y = Math.min(Math.max(targetY, minY), maxY);
1222
- const deltaX = x - node.offsetLeft;
1223
- const deltaY = y - node.offsetTop;
1224
- node.style.setProperty("transform", `translate3d(${deltaX}px, ${deltaY}px, 0)`);
1225
- service.send({
1226
- type: "MOVE_IMMEDIATE",
1227
- payload: {
1228
- id: `${id}`,
1229
- x,
1230
- y
1231
- }
1232
- });
1233
- setTransform({
1234
- x: deltaX * currentZoom,
1235
- y: deltaY * currentZoom
1236
- });
1237
- }
1178
+ const grandParent = node.parentElement?.parentElement;
1179
+ const currentZoom = zoom();
1180
+ const minX = 0;
1181
+ const maxX = grandParent ? Math.max(0, grandParent.clientWidth / currentZoom - node.offsetWidth) : Infinity;
1182
+ const minY = 0;
1183
+ const maxY = grandParent ? Math.max(0, grandParent.clientHeight / currentZoom - node.offsetHeight) : Infinity;
1184
+ const targetX = node.offsetLeft + _transform.x / currentZoom;
1185
+ const targetY = node.offsetTop + _transform.y / currentZoom;
1186
+ const x = Math.min(Math.max(targetX, minX), maxX);
1187
+ const y = Math.min(Math.max(targetY, minY), maxY);
1188
+ const deltaX = x - node.offsetLeft;
1189
+ const deltaY = y - node.offsetTop;
1190
+ node.style.setProperty("transform", `translate3d(${deltaX}px, ${deltaY}px, 0)`);
1191
+ service.send({
1192
+ type: "MOVE_IMMEDIATE",
1193
+ payload: {
1194
+ id: `${id}`,
1195
+ x,
1196
+ y
1197
+ }
1198
+ });
1199
+ setTransform({
1200
+ x: deltaX * currentZoom,
1201
+ y: deltaY * currentZoom
1202
+ });
1238
1203
  },
1239
1204
  onDragEnd: ({ draggable: { node, id } }) => {
1240
- if (!selected(id)) return;
1241
1205
  const grandParent = node.parentElement?.parentElement;
1242
1206
  const currentZoom = zoom();
1243
1207
  const minX = 0;
@@ -1277,7 +1241,7 @@ var NodesBoard = () => {
1277
1241
  (0, solid_js_web.ssr)(_tmpl$2, (0, solid_js_web.ssrHydrationKey)(), (0, solid_js_web.escape)(Math.round(zoom() * 100))),
1278
1242
  (0, solid_js_web.createComponent)(solid_js.Show, {
1279
1243
  get when() {
1280
- return !id() || !selected(id());
1244
+ return !selectedId();
1281
1245
  },
1282
1246
  get children() {
1283
1247
  return (0, solid_js_web.createComponent)(_thisbeyond_solid_dnd.DragOverlay, { children: "" });
@@ -1311,6 +1275,7 @@ var FlowChart = (props) => {
1311
1275
  const primaryEdges = props.config?.edges;
1312
1276
  const service = useFlow();
1313
1277
  const hasNewEdge = (0, _bemedev_app_solidjs.createState)(service, { selector: (s) => !!s.context.newEdge });
1278
+ (0, solid_js.onCleanup)(service.pause);
1314
1279
  (0, solid_js.onMount)(() => {
1315
1280
  service.resume();
1316
1281
  service.send({
@@ -1321,7 +1286,6 @@ var FlowChart = (props) => {
1321
1286
  }
1322
1287
  });
1323
1288
  });
1324
- (0, solid_js.onCleanup)(service.pause);
1325
1289
  return (0, solid_js_web.ssr)(_tmpl$, (0, solid_js_web.ssrHydrationKey)(), (0, solid_js_web.ssrStyleProperty)("cursor:", hasNewEdge() ? "inherit" : "crosshair") + (0, solid_js_web.ssrStyleProperty)(";background-image:", "radial-gradient(circle, #b8b8b8bf 1px, rgba(0, 0, 0, 0) 1px)"), (0, solid_js_web.escape)((0, solid_js_web.createComponent)(NodesBoard, {})));
1326
1290
  };
1327
1291
  //#endregion