react-html-graph 1.0.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 (110) hide show
  1. package/LICENSE +21 -0
  2. package/README.md +1 -0
  3. package/dist/calculations/index.d.ts +32 -0
  4. package/dist/calculations/index.d.ts.map +1 -0
  5. package/dist/calculations/index.js +247 -0
  6. package/dist/calculations/index.js.map +1 -0
  7. package/dist/calculations/types.d.ts +43 -0
  8. package/dist/calculations/types.d.ts.map +1 -0
  9. package/dist/calculations/types.js +2 -0
  10. package/dist/calculations/types.js.map +1 -0
  11. package/dist/context/connection-context.d.ts +3 -0
  12. package/dist/context/connection-context.d.ts.map +1 -0
  13. package/dist/context/connection-context.js +13 -0
  14. package/dist/context/connection-context.js.map +1 -0
  15. package/dist/context/error-context.d.ts +3 -0
  16. package/dist/context/error-context.d.ts.map +1 -0
  17. package/dist/context/error-context.js +5 -0
  18. package/dist/context/error-context.js.map +1 -0
  19. package/dist/context/graph-context.d.ts +3 -0
  20. package/dist/context/graph-context.d.ts.map +1 -0
  21. package/dist/context/graph-context.js +8 -0
  22. package/dist/context/graph-context.js.map +1 -0
  23. package/dist/context/graph-root-context.d.ts +7 -0
  24. package/dist/context/graph-root-context.d.ts.map +1 -0
  25. package/dist/context/graph-root-context.js +8 -0
  26. package/dist/context/graph-root-context.js.map +1 -0
  27. package/dist/example/App.css +39 -0
  28. package/dist/example/App.d.ts +3 -0
  29. package/dist/example/App.d.ts.map +1 -0
  30. package/dist/example/App.js +7 -0
  31. package/dist/example/App.js.map +1 -0
  32. package/dist/example/graph-teste.d.ts +2 -0
  33. package/dist/example/graph-teste.d.ts.map +1 -0
  34. package/dist/example/graph-teste.js +205 -0
  35. package/dist/example/graph-teste.js.map +1 -0
  36. package/dist/example/index.css +48 -0
  37. package/dist/example/reportWebVitals.d.ts +4 -0
  38. package/dist/example/reportWebVitals.d.ts.map +1 -0
  39. package/dist/example/reportWebVitals.js +13 -0
  40. package/dist/example/reportWebVitals.js.map +1 -0
  41. package/dist/graph/index.d.ts +11 -0
  42. package/dist/graph/index.d.ts.map +1 -0
  43. package/dist/graph/index.js +161 -0
  44. package/dist/graph/index.js.map +1 -0
  45. package/dist/graph/viewbox.d.ts +9 -0
  46. package/dist/graph/viewbox.d.ts.map +1 -0
  47. package/dist/graph/viewbox.js +30 -0
  48. package/dist/graph/viewbox.js.map +1 -0
  49. package/dist/hooks/api.d.ts +9 -0
  50. package/dist/hooks/api.d.ts.map +1 -0
  51. package/dist/hooks/api.js +13 -0
  52. package/dist/hooks/api.js.map +1 -0
  53. package/dist/hooks/connection.d.ts +46 -0
  54. package/dist/hooks/connection.d.ts.map +1 -0
  55. package/dist/hooks/connection.js +81 -0
  56. package/dist/hooks/connection.js.map +1 -0
  57. package/dist/hooks/error.d.ts +10 -0
  58. package/dist/hooks/error.d.ts.map +1 -0
  59. package/dist/hooks/error.js +16 -0
  60. package/dist/hooks/error.js.map +1 -0
  61. package/dist/hooks/get-zoom.d.ts +2 -0
  62. package/dist/hooks/get-zoom.d.ts.map +1 -0
  63. package/dist/hooks/get-zoom.js +14 -0
  64. package/dist/hooks/get-zoom.js.map +1 -0
  65. package/dist/hooks/graph-mode.d.ts +8 -0
  66. package/dist/hooks/graph-mode.d.ts.map +1 -0
  67. package/dist/hooks/graph-mode.js +13 -0
  68. package/dist/hooks/graph-mode.js.map +1 -0
  69. package/dist/hooks/graph-root.d.ts +9 -0
  70. package/dist/hooks/graph-root.d.ts.map +1 -0
  71. package/dist/hooks/graph-root.js +13 -0
  72. package/dist/hooks/graph-root.js.map +1 -0
  73. package/dist/hooks/graph.d.ts +10 -0
  74. package/dist/hooks/graph.d.ts.map +1 -0
  75. package/dist/hooks/graph.js +12 -0
  76. package/dist/hooks/graph.js.map +1 -0
  77. package/dist/hooks/viewbox.d.ts +7 -0
  78. package/dist/hooks/viewbox.d.ts.map +1 -0
  79. package/dist/hooks/viewbox.js +12 -0
  80. package/dist/hooks/viewbox.js.map +1 -0
  81. package/dist/link/base.d.ts +34 -0
  82. package/dist/link/base.d.ts.map +1 -0
  83. package/dist/link/base.js +202 -0
  84. package/dist/link/base.js.map +1 -0
  85. package/dist/link/temp-link.d.ts +9 -0
  86. package/dist/link/temp-link.d.ts.map +1 -0
  87. package/dist/link/temp-link.js +60 -0
  88. package/dist/link/temp-link.js.map +1 -0
  89. package/dist/module.d.ts +18 -0
  90. package/dist/module.d.ts.map +1 -0
  91. package/dist/module.js +18 -0
  92. package/dist/module.js.map +1 -0
  93. package/dist/nodes/base.d.ts +11 -0
  94. package/dist/nodes/base.d.ts.map +1 -0
  95. package/dist/nodes/base.js +117 -0
  96. package/dist/nodes/base.js.map +1 -0
  97. package/dist/ports/base.d.ts +11 -0
  98. package/dist/ports/base.d.ts.map +1 -0
  99. package/dist/ports/base.js +115 -0
  100. package/dist/ports/base.js.map +1 -0
  101. package/dist/providers/connection-provider.d.ts +10 -0
  102. package/dist/providers/connection-provider.d.ts.map +1 -0
  103. package/dist/providers/connection-provider.js +120 -0
  104. package/dist/providers/connection-provider.js.map +1 -0
  105. package/dist/style.css +78 -0
  106. package/dist/types.d.ts +349 -0
  107. package/dist/types.d.ts.map +1 -0
  108. package/dist/types.js +11 -0
  109. package/dist/types.js.map +1 -0
  110. package/package.json +73 -0
@@ -0,0 +1,18 @@
1
+ export { default, default as Graph } from "./graph";
2
+ export { calculateLabels, calculatePath, configureWorkerPool } from "./calculations";
3
+ export { ConnectionContext } from "./context/connection-context";
4
+ export { ErrorContext } from "./context/error-context";
5
+ export { GraphContext } from "./context/graph-context";
6
+ export { GraphRootContext } from "./context/graph-root-context";
7
+ export { default as useConnectionApi } from "./hooks/api";
8
+ export { useConnections, usePortDrag, usePortDrop } from "./hooks/connection";
9
+ export { default as useGraphError } from "./hooks/error";
10
+ export { default as useGraphItems } from "./hooks/graph";
11
+ export { default as useGraphMode } from "./hooks/graph-mode";
12
+ export { default as useGraphRoot } from "./hooks/graph-root";
13
+ export { default as useViewbox } from "./hooks/viewbox";
14
+ export { default as GraphLink } from "./link/base";
15
+ export { default as GraphObject } from "./nodes/base";
16
+ export { default as GraphPort } from "./ports/base";
17
+ export * from "./types";
18
+ //# sourceMappingURL=module.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"module.d.ts","sourceRoot":"","sources":["../src/module.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,OAAO,EAAE,OAAO,IAAI,KAAK,EAAE,MAAM,SAAS,CAAC;AACpD,OAAO,EAAE,eAAe,EAAE,aAAa,EAAE,mBAAmB,EAAE,MAAM,gBAAgB,CAAC;AACrF,OAAO,EAAE,iBAAiB,EAAE,MAAM,8BAA8B,CAAC;AACjE,OAAO,EAAE,YAAY,EAAE,MAAM,yBAAyB,CAAC;AACvD,OAAO,EAAE,YAAY,EAAE,MAAM,yBAAyB,CAAC;AACvD,OAAO,EAAE,gBAAgB,EAAE,MAAM,8BAA8B,CAAC;AAChE,OAAO,EAAE,OAAO,IAAI,gBAAgB,EAAE,MAAM,aAAa,CAAC;AAC1D,OAAO,EAAE,cAAc,EAAE,WAAW,EAAE,WAAW,EAAE,MAAM,oBAAoB,CAAC;AAC9E,OAAO,EAAE,OAAO,IAAI,aAAa,EAAE,MAAM,eAAe,CAAC;AACzD,OAAO,EAAE,OAAO,IAAI,aAAa,EAAE,MAAM,eAAe,CAAC;AACzD,OAAO,EAAE,OAAO,IAAI,YAAY,EAAE,MAAM,oBAAoB,CAAC;AAC7D,OAAO,EAAE,OAAO,IAAI,YAAY,EAAE,MAAM,oBAAoB,CAAC;AAC7D,OAAO,EAAE,OAAO,IAAI,UAAU,EAAE,MAAM,iBAAiB,CAAC;AACxD,OAAO,EAAE,OAAO,IAAI,SAAS,EAAE,MAAM,aAAa,CAAC;AACnD,OAAO,EAAE,OAAO,IAAI,WAAW,EAAE,MAAM,cAAc,CAAC;AACtD,OAAO,EAAE,OAAO,IAAI,SAAS,EAAE,MAAM,cAAc,CAAC;AACpD,cAAc,SAAS,CAAC"}
package/dist/module.js ADDED
@@ -0,0 +1,18 @@
1
+ export { default, default as Graph } from "./graph";
2
+ export { calculateLabels, calculatePath, configureWorkerPool } from "./calculations";
3
+ export { ConnectionContext } from "./context/connection-context";
4
+ export { ErrorContext } from "./context/error-context";
5
+ export { GraphContext } from "./context/graph-context";
6
+ export { GraphRootContext } from "./context/graph-root-context";
7
+ export { default as useConnectionApi } from "./hooks/api";
8
+ export { useConnections, usePortDrag, usePortDrop } from "./hooks/connection";
9
+ export { default as useGraphError } from "./hooks/error";
10
+ export { default as useGraphItems } from "./hooks/graph";
11
+ export { default as useGraphMode } from "./hooks/graph-mode";
12
+ export { default as useGraphRoot } from "./hooks/graph-root";
13
+ export { default as useViewbox } from "./hooks/viewbox";
14
+ export { default as GraphLink } from "./link/base";
15
+ export { default as GraphObject } from "./nodes/base";
16
+ export { default as GraphPort } from "./ports/base";
17
+ export * from "./types";
18
+ //# sourceMappingURL=module.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"module.js","sourceRoot":"","sources":["../src/module.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,OAAO,EAAE,OAAO,IAAI,KAAK,EAAE,MAAM,SAAS,CAAC;AACpD,OAAO,EAAE,eAAe,EAAE,aAAa,EAAE,mBAAmB,EAAE,MAAM,gBAAgB,CAAC;AACrF,OAAO,EAAE,iBAAiB,EAAE,MAAM,8BAA8B,CAAC;AACjE,OAAO,EAAE,YAAY,EAAE,MAAM,yBAAyB,CAAC;AACvD,OAAO,EAAE,YAAY,EAAE,MAAM,yBAAyB,CAAC;AACvD,OAAO,EAAE,gBAAgB,EAAE,MAAM,8BAA8B,CAAC;AAChE,OAAO,EAAE,OAAO,IAAI,gBAAgB,EAAE,MAAM,aAAa,CAAC;AAC1D,OAAO,EAAE,cAAc,EAAE,WAAW,EAAE,WAAW,EAAE,MAAM,oBAAoB,CAAC;AAC9E,OAAO,EAAE,OAAO,IAAI,aAAa,EAAE,MAAM,eAAe,CAAC;AACzD,OAAO,EAAE,OAAO,IAAI,aAAa,EAAE,MAAM,eAAe,CAAC;AACzD,OAAO,EAAE,OAAO,IAAI,YAAY,EAAE,MAAM,oBAAoB,CAAC;AAC7D,OAAO,EAAE,OAAO,IAAI,YAAY,EAAE,MAAM,oBAAoB,CAAC;AAC7D,OAAO,EAAE,OAAO,IAAI,UAAU,EAAE,MAAM,iBAAiB,CAAC;AACxD,OAAO,EAAE,OAAO,IAAI,SAAS,EAAE,MAAM,aAAa,CAAC;AACnD,OAAO,EAAE,OAAO,IAAI,WAAW,EAAE,MAAM,cAAc,CAAC;AACtD,OAAO,EAAE,OAAO,IAAI,SAAS,EAAE,MAAM,cAAc,CAAC;AACpD,cAAc,SAAS,CAAC"}
@@ -0,0 +1,11 @@
1
+ import { GraphObjectProps } from "../types";
2
+ /**
3
+ * Componente que representa um objeto/nó do grafo. Gerencia posicionamento,
4
+ * arraste (drag) e exposição das portas no local correto.
5
+ *
6
+ * @param props GraphObjectProps
7
+ * @returns JSX.Element
8
+ */
9
+ declare const MemoizedGraphObject: import("react").MemoExoticComponent<({ children, id, ports, data, initialPosition, onMove }: GraphObjectProps) => import("react/jsx-runtime").JSX.Element>;
10
+ export default MemoizedGraphObject;
11
+ //# sourceMappingURL=base.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"base.d.ts","sourceRoot":"","sources":["../../src/nodes/base.tsx"],"names":[],"mappings":"AAEA,OAAO,EAAE,gBAAgB,EAA4B,MAAM,UAAU,CAAC;AAatE;;;;;;GAMG;AACH,QAAA,MAAM,mBAAmB,+FAAqF,gBAAgB,6CAwI5H,CAAA;AAEF,eAAe,mBAAmB,CAAC"}
@@ -0,0 +1,117 @@
1
+ import { jsx as _jsx } from "react/jsx-runtime";
2
+ import { useRef, useState, useCallback, useEffect, useMemo, memo } from "react";
3
+ import useGraphMode from "../hooks/graph-mode";
4
+ import GraphPort from "../ports/base";
5
+ import useGetZoom from "../hooks/get-zoom";
6
+ /**
7
+ * Componente que representa um objeto/nó do grafo. Gerencia posicionamento,
8
+ * arraste (drag) e exposição das portas no local correto.
9
+ *
10
+ * @param props GraphObjectProps
11
+ * @returns JSX.Element
12
+ */
13
+ const MemoizedGraphObject = memo(function GraphObject({ children, id, ports, data, initialPosition, onMove }) {
14
+ const ref = useRef(null);
15
+ const getZoom = useGetZoom();
16
+ const mode = useGraphMode();
17
+ const [position, setPosition] = useState(() => initialPosition ?? { x: 0, y: 0, z: 0 });
18
+ const moveRef = useRef({
19
+ moving: false,
20
+ movePointStart: { x: 0, y: 0 },
21
+ startPos: { x: 0, y: 0 },
22
+ currentPos: { x: 0, y: 0 },
23
+ });
24
+ const handleMouseDown = useCallback((e) => {
25
+ if (e.button !== 0 || mode === "readonly")
26
+ return;
27
+ e.preventDefault();
28
+ moveRef.current.moving = true;
29
+ moveRef.current.movePointStart.x = e.clientX;
30
+ moveRef.current.movePointStart.y = e.clientY;
31
+ moveRef.current.startPos = { x: position.x, y: position.y };
32
+ moveRef.current.currentPos = { x: position.x, y: position.y };
33
+ }, [position, mode]);
34
+ const stopMoving = useCallback((e) => {
35
+ if (e.button === 0 && moveRef.current.moving) {
36
+ moveRef.current.moving = false;
37
+ setPosition(prev => ({
38
+ x: moveRef.current.currentPos.x,
39
+ y: moveRef.current.currentPos.y,
40
+ z: prev.z
41
+ }));
42
+ }
43
+ }, []);
44
+ const handleMouseMove = useCallback((e) => {
45
+ if (!ref.current || !moveRef.current.moving)
46
+ return;
47
+ const zoom = getZoom();
48
+ const dx = (e.clientX - moveRef.current.movePointStart.x) / zoom;
49
+ const dy = (e.clientY - moveRef.current.movePointStart.y) / zoom;
50
+ const newX = moveRef.current.startPos.x + dx;
51
+ const newY = moveRef.current.startPos.y + dy;
52
+ moveRef.current.currentPos.x = newX;
53
+ moveRef.current.currentPos.y = newY;
54
+ ref.current.style.left = `${newX.toFixed(0)}px`;
55
+ ref.current.style.top = `${newY.toFixed(0)}px`;
56
+ }, [getZoom]);
57
+ useEffect(() => {
58
+ if (!ref.current)
59
+ return;
60
+ ref.current.style.left = `${position.x.toFixed(0)}px`;
61
+ ref.current.style.top = `${position.y.toFixed(0)}px`;
62
+ ref.current.style.zIndex = position.z.toFixed(0);
63
+ }, [position]);
64
+ useEffect(() => {
65
+ if (mode === "readonly")
66
+ return;
67
+ const handlerUp = (e) => {
68
+ stopMoving(e);
69
+ };
70
+ const handleMove = (e) => {
71
+ handleMouseMove(e);
72
+ };
73
+ document.addEventListener('mouseup', handlerUp);
74
+ document.addEventListener('mousemove', handleMove);
75
+ return () => {
76
+ document.removeEventListener('mouseup', handlerUp);
77
+ document.removeEventListener('mousemove', handleMove);
78
+ };
79
+ }, [stopMoving, handleMouseMove, mode]);
80
+ const portsByLocation = useMemo(() => {
81
+ const result = {
82
+ top: [], bottom: [], left: [], right: [], floating: [], all: [],
83
+ };
84
+ for (const port of ports ?? []) {
85
+ const element = (_jsx(GraphPort, { type: port.type, id: port.id, nodeId: id, direction: port.direction, location: port.location, onDragEnd: port.onDragEnd, children: port.children }, port.id));
86
+ if (typeof port.location === "string" && port.location in result) {
87
+ result[port.location].push(element);
88
+ }
89
+ else if (typeof port.location === "object") {
90
+ result.floating.push(element);
91
+ }
92
+ result.all.push(element);
93
+ }
94
+ return result;
95
+ }, [ports, id]);
96
+ useEffect(() => {
97
+ if (onMove) {
98
+ onMove({ x: position.x, y: position.y, z: position.z });
99
+ }
100
+ if (ref.current) {
101
+ ref.current.style.zIndex = position.z.toFixed(0);
102
+ }
103
+ }, [position, onMove]);
104
+ useEffect(() => {
105
+ if (initialPosition) {
106
+ setPosition({
107
+ x: initialPosition.x,
108
+ y: initialPosition.y,
109
+ z: initialPosition.z ?? 0
110
+ });
111
+ }
112
+ // eslint-disable-next-line react-hooks/exhaustive-deps
113
+ }, [initialPosition?.x, initialPosition?.y, initialPosition?.z]);
114
+ return _jsx("node-graph-object", { ref: ref, onMouseDown: handleMouseDown, onMouseUp: stopMoving, "node-id": id, children: children({ id, ports: portsByLocation, data }) }, id);
115
+ });
116
+ export default Memo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eAAe,CAAC,CAAC,IAAI,CAAC;aAC5B,CAAC,CAAC;QACP,CAAC;QACD,uDAAuD;IAC3D,CAAC,EAAE,CAAC,eAAe,EAAE,CAAC,EAAE,eAAe,EAAE,CAAC,EAAE,eAAe,EAAE,CAAC,CAAC,CAAC,CAAC;IAEjE,OAAO,4BAEH,GAAG,EAAE,GAAG,EACR,WAAW,EAAE,eAAe,EAC5B,SAAS,EAAE,UAAU,aACZ,EAAE,YAEV,QAAQ,CAAC,EAAE,EAAE,EAAE,KAAK,EAAE,eAAe,EAAE,IAAI,EAAE,CAAC,IAN1C,EAAE,CAOS,CAAA;AACxB,CAAC,CAAC,CAAA;AAEF,eAAe,mBAAmB,CAAC"}
@@ -0,0 +1,11 @@
1
+ import { GraphPortProps } from "../types";
2
+ /**
3
+ * Componente que representa uma porta de nó (input/output/bidirectional).
4
+ * Registra a porta no contexto de conexões e fornece handlers de arraste
5
+ * e drop conforme o modo do graph.
6
+ *
7
+ * @param props Propriedades da porta (GraphPortProps)
8
+ * @returns JSX.Element
9
+ */
10
+ export default function GraphPort({ onClick, onMouseOver, onMouseLeave, ...props }: GraphPortProps): import("react/jsx-runtime").JSX.Element;
11
+ //# sourceMappingURL=base.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"base.d.ts","sourceRoot":"","sources":["../../src/ports/base.tsx"],"names":[],"mappings":"AAMA,OAAO,EAAY,cAAc,EAAE,MAAM,UAAU,CAAC;AAIpD;;;;;;;GAOG;AACH,MAAM,CAAC,OAAO,UAAU,SAAS,CAAC,EAC9B,OAAO,EAAE,WAAW,EAAE,YAAY,EAAE,GAAG,KAAK,EAC/C,EAAE,cAAc,2CA8HhB"}
@@ -0,0 +1,115 @@
1
+ import { jsx as _jsx } from "react/jsx-runtime";
2
+ import { useEffect, useContext, useCallback } from "react";
3
+ import { usePortDrag, usePortDrop } from "../hooks/connection";
4
+ import { ConnectionContext } from "../context/connection-context";
5
+ import useGraphMode from "../hooks/graph-mode";
6
+ /**
7
+ * Componente que representa uma porta de nó (input/output/bidirectional).
8
+ * Registra a porta no contexto de conexões e fornece handlers de arraste
9
+ * e drop conforme o modo do graph.
10
+ *
11
+ * @param props Propriedades da porta (GraphPortProps)
12
+ * @returns JSX.Element
13
+ */
14
+ export default function GraphPort({ onClick, onMouseOver, onMouseLeave, ...props }) {
15
+ const { registerPort, unregisterPort, getGraphApi } = useContext(ConnectionContext);
16
+ const mode = useGraphMode();
17
+ const { dragHandlers, isDragging, canDrag } = usePortDrag(props.nodeId, props.id, props.type);
18
+ const { dropHandlers, canDrop } = usePortDrop(props.nodeId, props.id, props.type);
19
+ useEffect(() => {
20
+ registerPort({
21
+ nodeId: props.nodeId,
22
+ portName: props.id,
23
+ connectionType: props.type,
24
+ direction: props.direction,
25
+ onDragEnd: props.onDragEnd,
26
+ });
27
+ return () => {
28
+ unregisterPort(props.nodeId, props.id);
29
+ };
30
+ }, [
31
+ props.nodeId,
32
+ props.id,
33
+ props.type,
34
+ props.direction,
35
+ props.onDragEnd,
36
+ registerPort,
37
+ unregisterPort,
38
+ ]);
39
+ const forwardClickEvents = useCallback((event) => {
40
+ if (!onClick)
41
+ return;
42
+ const api = getGraphApi();
43
+ if (!api)
44
+ return;
45
+ onClick({
46
+ type: 'click',
47
+ graph: {
48
+ type: props.type,
49
+ id: props.id,
50
+ nodeId: props.nodeId,
51
+ direction: props.direction,
52
+ },
53
+ nativeEvent: event.nativeEvent,
54
+ api,
55
+ });
56
+ }, [getGraphApi, onClick, props.direction, props.id, props.nodeId, props.type]);
57
+ const forwardMouseOverEvents = useCallback((event) => {
58
+ if (!onMouseOver)
59
+ return;
60
+ const api = getGraphApi();
61
+ if (!api)
62
+ return;
63
+ onMouseOver({
64
+ type: 'mouseOver',
65
+ graph: {
66
+ type: props.type,
67
+ id: props.id,
68
+ nodeId: props.nodeId,
69
+ direction: props.direction,
70
+ },
71
+ nativeEvent: event.nativeEvent,
72
+ api,
73
+ });
74
+ }, [getGraphApi, onMouseOver, props.direction, props.id, props.nodeId, props.type]);
75
+ const forwardMouseLeaveEvents = useCallback((event) => {
76
+ if (!onMouseLeave)
77
+ return;
78
+ const api = getGraphApi();
79
+ if (!api)
80
+ return;
81
+ onMouseLeave({
82
+ type: 'mouseLeave',
83
+ graph: {
84
+ type: props.type,
85
+ id: props.id,
86
+ nodeId: props.nodeId,
87
+ direction: props.direction,
88
+ },
89
+ nativeEvent: event.nativeEvent,
90
+ api,
91
+ });
92
+ }, [getGraphApi, onMouseLeave, props.direction, props.id, props.nodeId, props.type]);
93
+ const isOutput = props.direction === "output" || props.direction === "bidirectional";
94
+ const isInput = props.direction === "input" || props.direction === "bidirectional";
95
+ const handlers = mode === "edit"
96
+ ? {
97
+ ...(isOutput ? dragHandlers : {}),
98
+ ...(isInput ? dropHandlers : {}),
99
+ }
100
+ : {};
101
+ const portAttr = props.direction === "bidirectional"
102
+ ? "bidirectional"
103
+ : props.direction;
104
+ return (_jsx("node-graph-port", { ...handlers, onClick: forwardClickEvents, onMouseOver: forwardMouseOverEvents, onMouseLeave: forwardMouseLeaveEvents, "node-port": portAttr, "port-id": props.id, children: props.children({
105
+ type: props.type,
106
+ id: props.id,
107
+ nodeId: props.nodeId,
108
+ direction: props.direction,
109
+ location: props.location,
110
+ isDragging,
111
+ canDrop,
112
+ canDrag,
113
+ }) }));
114
+ }
115
+ //# sourceMappingURL=base.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"base.js","sourceRoot":"","sources":["../../src/ports/base.tsx"],"names":[],"mappings":";AAEA,OAAO,EAAE,SAAS,EAAE,UAAU,EAAE,WAAW,EAAE,MAAM,OAAO,CAAC;AAC3D,OAAO,EAAE,WAAW,EAAE,WAAW,EAAE,MAAM,qBAAqB,CAAC;AAC/D,OAAO,EAAE,iBAAiB,EAAE,MAAM,+BAA+B,CAAC;AAClE,OAAO,YAAY,MAAM,qBAAqB,CAAC;AAK/C;;;;;;;GAOG;AACH,MAAM,CAAC,OAAO,UAAU,SAAS,CAAC,EAC9B,O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,KAAK,CAAC,MAAM;YACpB,SAAS,EAAE,KAAK,CAAC,SAAS;YAC1B,QAAQ,EAAE,KAAK,CAAC,QAAQ;YACxB,UAAU;YACV,OAAO;YACP,OAAO;SACV,CAAC,GACY,CACrB,CAAC;AACN,CAAC"}
@@ -0,0 +1,10 @@
1
+ import { ConnectionProviderProps } from "../types";
2
+ /**
3
+ * Provider que gerencia o estado de conexões e arraste entre portas. Expõe a
4
+ * API de conexões e o estado de drag através do ConnectionContext.
5
+ *
6
+ * @param props Propriedades do provider (ConnectionProviderProps)
7
+ * @returns JSX.Element
8
+ */
9
+ export default function ConnectionProvider({ graphApiRef, children }: ConnectionProviderProps): import("react/jsx-runtime").JSX.Element;
10
+ //# sourceMappingURL=connection-provider.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"connection-provider.d.ts","sourceRoot":"","sources":["../../src/providers/connection-provider.tsx"],"names":[],"mappings":"AAEA,OAAO,EAAkC,uBAAuB,EAA+B,MAAM,UAAU,CAAC;AAMhH;;;;;;GAMG;AACH,MAAM,CAAC,OAAO,UAAU,kBAAkB,CAAC,EAAE,WAAW,EAAE,QAAQ,EAAE,EAAE,uBAAuB,2CAuI5F"}
@@ -0,0 +1,120 @@
1
+ import { jsx as _jsx } from "react/jsx-runtime";
2
+ import { useState, useCallback, useRef, useMemo, useEffect } from "react";
3
+ import { ConnectionContext } from "../context/connection-context";
4
+ import useGraphMode from "../hooks/graph-mode";
5
+ import useViewbox from "../hooks/viewbox";
6
+ import useGraphRoot from "../hooks/graph-root";
7
+ /**
8
+ * Provider que gerencia o estado de conexões e arraste entre portas. Expõe a
9
+ * API de conexões e o estado de drag através do ConnectionContext.
10
+ *
11
+ * @param props Propriedades do provider (ConnectionProviderProps)
12
+ * @returns JSX.Element
13
+ */
14
+ export default function ConnectionProvider({ graphApiRef, children }) {
15
+ const [connections, setConnections] = useState([]);
16
+ const [dragState, setDragState] = useState({ active: false });
17
+ const dragStateRef = useRef({ active: false });
18
+ const connectionsRef = useRef([]);
19
+ const portRegistry = useRef(new Map());
20
+ const mode = useGraphMode();
21
+ const viewbox = useViewbox();
22
+ const graphRoot = useGraphRoot();
23
+ const viewboxRef = useRef(viewbox);
24
+ viewboxRef.current = viewbox;
25
+ connectionsRef.current = connections;
26
+ const registerPort = useCallback((reg) => {
27
+ portRegistry.current.set(`${reg.nodeId}:${reg.portName}`, reg);
28
+ }, []);
29
+ const unregisterPort = useCallback((nodeId, portName) => {
30
+ portRegistry.current.delete(`${nodeId}:${portName}`);
31
+ }, []);
32
+ const getGraphApi = useCallback(() => {
33
+ return graphApiRef.current;
34
+ }, [graphApiRef]);
35
+ const connect = useCallback((connection) => {
36
+ if (mode === "readonly")
37
+ return;
38
+ setConnections(prev => [...prev, connection]);
39
+ }, [mode]);
40
+ const disconnect = useCallback((connection) => {
41
+ if (mode === "readonly")
42
+ return;
43
+ setConnections(prev => prev.filter(c => !(c.from.nodeId === connection.from.nodeId &&
44
+ c.from.portName === connection.from.portName &&
45
+ c.to.nodeId === connection.to.nodeId &&
46
+ c.to.portName === connection.to.portName)));
47
+ }, [mode]);
48
+ const startDrag = useCallback((sourceNodeId, sourcePortName, connectionType) => {
49
+ if (mode === "readonly")
50
+ return;
51
+ const state = {
52
+ active: true,
53
+ sourceNodeId,
54
+ sourcePortName,
55
+ connectionType,
56
+ cursorPosition: { x: 0, y: 0 },
57
+ };
58
+ dragStateRef.current = state;
59
+ setDragState(state);
60
+ }, [mode]);
61
+ const endDrag = useCallback(async (targetNodeId, targetPortName, cursorPosition) => {
62
+ const current = dragStateRef.current;
63
+ if (!current.active)
64
+ return;
65
+ // Evita reentradas causadas por mouseup global
66
+ dragStateRef.current = { active: false };
67
+ const sourceKey = `${current.sourceNodeId}:${current.sourcePortName}`;
68
+ const sourcePort = portRegistry.current.get(sourceKey);
69
+ if (sourcePort?.onDragEnd) {
70
+ try {
71
+ await sourcePort.onDragEnd(graphApiRef.current, {
72
+ sourceNodeId: current.sourceNodeId,
73
+ sourcePortName: current.sourcePortName,
74
+ connectionType: current.connectionType,
75
+ targetNodeId,
76
+ targetPortName,
77
+ cursorPosition: cursorPosition ?? { x: 0, y: 0 },
78
+ });
79
+ }
80
+ catch (_e) {
81
+ // Erro no callback - o link temporário ainda será limpo
82
+ }
83
+ }
84
+ // Oculta o link temporário após o callback finalizar
85
+ setDragState({ active: false });
86
+ }, [graphApiRef]);
87
+ // mouseup global: encerra o arraste quando clicado em espaço vazio
88
+ useEffect(() => {
89
+ const handleMouseUp = (e) => {
90
+ if (!dragStateRef.current.active)
91
+ return;
92
+ const vb = viewboxRef.current;
93
+ const graph = graphRoot.current;
94
+ let cursorPos = { x: 0, y: 0 };
95
+ if (graph) {
96
+ const rect = graph.getBoundingClientRect();
97
+ cursorPos = {
98
+ x: (e.clientX - rect.left) / vb.zoom + vb.x,
99
+ y: (e.clientY - rect.top) / vb.zoom + vb.y,
100
+ };
101
+ }
102
+ endDrag(undefined, undefined, cursorPos);
103
+ };
104
+ document.addEventListener("mouseup", handleMouseUp);
105
+ return () => document.removeEventListener("mouseup", handleMouseUp);
106
+ }, [endDrag, graphRoot]);
107
+ const value = useMemo(() => ({
108
+ connections,
109
+ dragState,
110
+ getGraphApi,
111
+ connect,
112
+ disconnect,
113
+ startDrag,
114
+ endDrag,
115
+ registerPort,
116
+ unregisterPort,
117
+ }), [connections, dragState, getGraphApi, connect, disconnect, startDrag, endDrag, registerPort, unregisterPort]);
118
+ return (_jsx(ConnectionContext.Provider, { value: value, children: children }));
119
+ }
120
+ //# sourceMappingURL=connection-provider.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"connection-provider.js","sourceRoot":"","sources":["../../src/providers/connection-provider.tsx"],"names":[],"mappings":";AAAA,OAAO,EAAE,QAAQ,EAAE,WAAW,EAAE,MAAM,EAAE,OAAO,EAAE,SAAS,EAAE,MAAM,OAAO,CAAC;AAC1E,OAAO,EAAE,iBAAiB,EAAE,MAAM,+BAA+B,CAAC;AAElE,OAAO,YAAY,MAAM,qB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F,OAAO,CACH,KAAC,iBAAiB,CAAC,QAAQ,IAAC,KAAK,EAAE,KAAK,YACnC,QAAQ,GACgB,CAChC,CAAC;AACN,CAAC"}
package/dist/style.css ADDED
@@ -0,0 +1,78 @@
1
+ graph-root {
2
+ display: block;
3
+ position: relative;
4
+ width: 100%;
5
+ height: 100%;
6
+ background: #000;
7
+ color: #fff;
8
+ overflow: hidden;
9
+
10
+ graph-viewbox {
11
+ display: block;
12
+ position: relative;
13
+ min-width: 100%;
14
+ min-height: 100%;
15
+ transform-origin: 0 0;
16
+ overflow: visible;
17
+
18
+ node-graph-object {
19
+ position: absolute;
20
+ width: fit-content;
21
+ height: fit-content;
22
+ display: flex;
23
+ align-items: center;
24
+ }
25
+ }
26
+ }
27
+
28
+
29
+
30
+ @keyframes graph-link-flow {
31
+ from {
32
+ stroke-dashoffset: 0;
33
+ }
34
+
35
+ to {
36
+ stroke-dashoffset: var(--cycle-len);
37
+ }
38
+ }
39
+
40
+ node-graph-link,
41
+ node-graph-node {
42
+ position: absolute;
43
+ pointer-events: all;
44
+ }
45
+
46
+ node-graph-temp-link {
47
+ position: absolute;
48
+
49
+ >svg {
50
+ position: absolute;
51
+ left: 0;
52
+ top: 0;
53
+ width: 0;
54
+ height: 0;
55
+ overflow: visible;
56
+ pointer-events: none;
57
+ }
58
+ }
59
+
60
+ node-graph-link>svg {
61
+ position: absolute;
62
+ pointer-events: none;
63
+ overflow: visible;
64
+ }
65
+
66
+ node-graph-link>svg path {
67
+ animation-name: graph-link-flow;
68
+ animation-timing-function: linear;
69
+ animation-iteration-count: infinite;
70
+ transition: stroke 0.3s ease, stroke-width 0.15s ease;
71
+ }
72
+
73
+ node-graph-link>svg text {
74
+ pointer-events: none;
75
+ -webkit-user-select: none;
76
+ user-select: none;
77
+ transition: font-size 0.15s ease;
78
+ }