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