@lincle/react-web-interactive 0.4.0-next.2 → 0.4.0-next.3

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 (34) hide show
  1. package/dist/base.d.ts +1 -1
  2. package/dist/base.js +1 -2
  3. package/dist/components/Edge/Path/index.d.ts +1 -0
  4. package/dist/components/{Path → Edge/Path}/index.js +1 -1
  5. package/dist/components/Edge/index.d.ts +2 -1
  6. package/dist/components/Edge/index.js +7 -2
  7. package/dist/components/Edges/Connections/index.d.ts +4 -0
  8. package/dist/components/Edges/Connections/index.js +20 -0
  9. package/dist/components/Edges/index.d.ts +4 -1
  10. package/dist/components/Edges/index.js +24 -3
  11. package/dist/components/{Grid → Graph/Grid}/index.d.ts +1 -1
  12. package/dist/components/Graph/Grid/index.js +57 -0
  13. package/dist/components/Graph/index.d.ts +2 -1
  14. package/dist/components/Graph/index.js +11 -6
  15. package/dist/components/Interaction/index.d.ts +1 -1
  16. package/dist/components/Interaction/index.js +69 -79
  17. package/dist/components/Node/MoveNode/index.js +22 -3
  18. package/dist/components/Node/PullNode/index.js +60 -42
  19. package/dist/components/Node/index.d.ts +3 -1
  20. package/dist/components/Node/index.js +33 -19
  21. package/dist/components/Nodes/index.d.ts +1 -1
  22. package/dist/components/Nodes/index.js +2 -2
  23. package/dist/components/index.d.ts +6 -9
  24. package/dist/components/index.js +19 -21
  25. package/dist/shared.d.ts +8 -12
  26. package/dist/shared.js +31 -15
  27. package/dist/styles.g.css +19 -6
  28. package/package.json +18 -20
  29. package/dist/components/GraphContexts/index.d.ts +0 -4
  30. package/dist/components/GraphContexts/index.js +0 -167
  31. package/dist/components/Grid/index.js +0 -13
  32. package/dist/components/Path/index.d.ts +0 -1
  33. package/dist/components/Pull/index.d.ts +0 -4
  34. package/dist/components/Pull/index.js +0 -153
package/dist/base.d.ts CHANGED
@@ -1 +1 @@
1
- export { Edge, Edges, Graph, GraphContexts, Grid, Node, Nodes, Path } from '@lincle/react-web-base';
1
+ export { Edge, Edges, Graph, Grid, Node, Nodes, Path } from '@lincle/react-web-base';
package/dist/base.js CHANGED
@@ -1,11 +1,10 @@
1
1
  "use strict";
2
2
  Object.defineProperty(exports, "__esModule", { value: true });
3
- exports.Path = exports.Nodes = exports.Node = exports.Grid = exports.GraphContexts = exports.Graph = exports.Edges = exports.Edge = void 0;
3
+ exports.Path = exports.Nodes = exports.Node = exports.Grid = exports.Graph = exports.Edges = exports.Edge = void 0;
4
4
  var react_web_base_1 = require("@lincle/react-web-base");
5
5
  Object.defineProperty(exports, "Edge", { enumerable: true, get: function () { return react_web_base_1.Edge; } });
6
6
  Object.defineProperty(exports, "Edges", { enumerable: true, get: function () { return react_web_base_1.Edges; } });
7
7
  Object.defineProperty(exports, "Graph", { enumerable: true, get: function () { return react_web_base_1.Graph; } });
8
- Object.defineProperty(exports, "GraphContexts", { enumerable: true, get: function () { return react_web_base_1.GraphContexts; } });
9
8
  Object.defineProperty(exports, "Grid", { enumerable: true, get: function () { return react_web_base_1.Grid; } });
10
9
  Object.defineProperty(exports, "Node", { enumerable: true, get: function () { return react_web_base_1.Node; } });
11
10
  Object.defineProperty(exports, "Nodes", { enumerable: true, get: function () { return react_web_base_1.Nodes; } });
@@ -0,0 +1 @@
1
+ export { Path as default } from '../../../base';
@@ -1,5 +1,5 @@
1
1
  "use strict";
2
2
  Object.defineProperty(exports, "__esModule", { value: true });
3
3
  exports.default = void 0;
4
- var base_1 = require("../../base");
4
+ var base_1 = require("../../../base");
5
5
  Object.defineProperty(exports, "default", { enumerable: true, get: function () { return base_1.Path; } });
@@ -1 +1,2 @@
1
- export { Edge as default } from '../../base';
1
+ export { Edge } from '../../base';
2
+ export { default as Path } from './Path';
@@ -1,5 +1,10 @@
1
1
  "use strict";
2
+ var __importDefault = (this && this.__importDefault) || function (mod) {
3
+ return (mod && mod.__esModule) ? mod : { "default": mod };
4
+ };
2
5
  Object.defineProperty(exports, "__esModule", { value: true });
3
- exports.default = void 0;
6
+ exports.Path = exports.Edge = void 0;
4
7
  var base_1 = require("../../base");
5
- Object.defineProperty(exports, "default", { enumerable: true, get: function () { return base_1.Edge; } });
8
+ Object.defineProperty(exports, "Edge", { enumerable: true, get: function () { return base_1.Edge; } });
9
+ var Path_1 = require("./Path");
10
+ Object.defineProperty(exports, "Path", { enumerable: true, get: function () { return __importDefault(Path_1).default; } });
@@ -0,0 +1,4 @@
1
+ import { type FunctionComponent, type PropsWithChildren } from 'react';
2
+ declare const Connections: FunctionComponent<ConnectionsProps>;
3
+ export default Connections;
4
+ export type ConnectionsProps = PropsWithChildren<{}>;
@@ -0,0 +1,20 @@
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
3
+ const jsx_runtime_1 = require("react/jsx-runtime");
4
+ const shared_1 = require("../../../shared");
5
+ const Edge_1 = require("../../Edge");
6
+ const react_1 = require("react");
7
+ const Connections = () => {
8
+ const connections = (0, shared_1.useConnections)();
9
+ const paths = (0, react_1.useMemo)(() => {
10
+ return Object.keys(connections).map((sourceId) => {
11
+ const { line, source, target } = connections[sourceId];
12
+ return ((0, jsx_runtime_1.jsx)(Edge_1.Path, { edgeId: sourceId + 'temp', line: line, source: source, target: target }, sourceId));
13
+ });
14
+ }, [
15
+ connections
16
+ ]);
17
+ return ((0, jsx_runtime_1.jsx)("svg", { className: 'lincle-interactive-connection', children: paths }));
18
+ };
19
+ Connections.displayName = 'LincleInteractiveConnections';
20
+ exports.default = Connections;
@@ -1 +1,4 @@
1
- export { Edges as default } from '../../base';
1
+ import { type EdgesProps } from '../../shared';
2
+ import { type FunctionComponent } from 'react';
3
+ declare const Edges: FunctionComponent<EdgesProps>;
4
+ export { Edges };
@@ -1,5 +1,26 @@
1
1
  "use strict";
2
+ var __rest = (this && this.__rest) || function (s, e) {
3
+ var t = {};
4
+ for (var p in s) if (Object.prototype.hasOwnProperty.call(s, p) && e.indexOf(p) < 0)
5
+ t[p] = s[p];
6
+ if (s != null && typeof Object.getOwnPropertySymbols === "function")
7
+ for (var i = 0, p = Object.getOwnPropertySymbols(s); i < p.length; i++) {
8
+ if (e.indexOf(p[i]) < 0 && Object.prototype.propertyIsEnumerable.call(s, p[i]))
9
+ t[p[i]] = s[p[i]];
10
+ }
11
+ return t;
12
+ };
13
+ var __importDefault = (this && this.__importDefault) || function (mod) {
14
+ return (mod && mod.__esModule) ? mod : { "default": mod };
15
+ };
2
16
  Object.defineProperty(exports, "__esModule", { value: true });
3
- exports.default = void 0;
4
- var base_1 = require("../../base");
5
- Object.defineProperty(exports, "default", { enumerable: true, get: function () { return base_1.Edges; } });
17
+ exports.Edges = void 0;
18
+ const jsx_runtime_1 = require("react/jsx-runtime");
19
+ const base_1 = require("../../base");
20
+ const Connections_1 = __importDefault(require("./Connections"));
21
+ const Edges = (_a) => {
22
+ var { children } = _a, props = __rest(_a, ["children"]);
23
+ return ((0, jsx_runtime_1.jsxs)(base_1.Edges, Object.assign({}, props, { children: [children, (0, jsx_runtime_1.jsx)(Connections_1.default, {})] })));
24
+ };
25
+ exports.Edges = Edges;
26
+ Edges.displayName = 'LincleInteractiveEdges';
@@ -1,4 +1,4 @@
1
- import { type GridProps } from '../../shared';
1
+ import { type GridProps } from '../../../shared';
2
2
  import { type FunctionComponent } from 'react';
3
3
  declare const Grid: FunctionComponent<GridProps>;
4
4
  export default Grid;
@@ -0,0 +1,57 @@
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
3
+ const jsx_runtime_1 = require("react/jsx-runtime");
4
+ const base_1 = require("../../../base");
5
+ const shared_1 = require("../../../shared");
6
+ const react_1 = require("react");
7
+ const WIDTH = 0.4;
8
+ const Grid = ({ children }) => {
9
+ const scale = (0, shared_1.useScale)();
10
+ const translate = (0, shared_1.useTranslate)();
11
+ const mode = (0, shared_1.useMode)();
12
+ const line = (0, react_1.useMemo)(() => {
13
+ const t1 = 1 + scale;
14
+ const t2 = 4 * scale;
15
+ return ((0, jsx_runtime_1.jsx)("line", { stroke: 'black', strokeWidth: WIDTH, x1: t1, x2: t2, y1: t1, y2: t2 }));
16
+ }, [
17
+ scale
18
+ ]);
19
+ const plus = (0, react_1.useMemo)(() => {
20
+ const t1 = scale;
21
+ const t2 = 4 * scale;
22
+ return ((0, jsx_runtime_1.jsxs)(jsx_runtime_1.Fragment, { children: [(0, jsx_runtime_1.jsx)("line", { stroke: 'black', strokeWidth: WIDTH, x1: t1, x2: t2, y1: t2, y2: t2 }), (0, jsx_runtime_1.jsx)("line", { stroke: 'black', strokeWidth: WIDTH, x1: t2, x2: t2, y1: t1, y2: t2 })] }));
23
+ }, [
24
+ scale
25
+ ]);
26
+ const circle = (0, react_1.useMemo)(() => {
27
+ const t2 = 4 * scale;
28
+ return ((0, jsx_runtime_1.jsx)("circle", { cx: t2, cy: t2, fill: 'black', r: WIDTH }));
29
+ }, [
30
+ scale
31
+ ]);
32
+ const child = (0, react_1.useMemo)(() => {
33
+ if (!children) {
34
+ switch (mode) {
35
+ case 'pull': {
36
+ return line;
37
+ }
38
+ case 'select': {
39
+ return plus;
40
+ }
41
+ case 'move': {
42
+ return circle;
43
+ }
44
+ }
45
+ }
46
+ return children;
47
+ }, [
48
+ children,
49
+ circle,
50
+ line,
51
+ mode,
52
+ plus
53
+ ]);
54
+ return ((0, jsx_runtime_1.jsx)(base_1.Grid, { scale: scale, xOffset: translate.x, yOffset: translate.y, children: child }));
55
+ };
56
+ Grid.displayName = 'LincleInteractiveGrid';
57
+ exports.default = Grid;
@@ -1,4 +1,5 @@
1
1
  import { type GraphProps } from '../../shared';
2
2
  import { type FunctionComponent } from 'react';
3
3
  declare const Graph: FunctionComponent<GraphProps>;
4
- export default Graph;
4
+ export { Graph };
5
+ export { default as Grid } from './Grid';
@@ -3,16 +3,21 @@ var __importDefault = (this && this.__importDefault) || function (mod) {
3
3
  return (mod && mod.__esModule) ? mod : { "default": mod };
4
4
  };
5
5
  Object.defineProperty(exports, "__esModule", { value: true });
6
+ exports.Grid = exports.Graph = void 0;
6
7
  const jsx_runtime_1 = require("react/jsx-runtime");
7
- const base_1 = require("../../base");
8
- const GraphContexts_1 = __importDefault(require("../GraphContexts"));
9
- const Interaction_1 = __importDefault(require("../Interaction"));
10
- const Graph = ({ children, disableMove, disablePan, disablePull, disableScale, edgeFrequency, grid, id, line, maxScale, minScale, mode: givenMode, nodeFrequency, nodeHeight, nodeWidth, onEdgeDrop, onMouseDown, onMouseUp, onNodeDrag, onNodeSelect, onNodeStart, onNodeStop, onScale, onTouchEnd, onTouchStart, onTranslate, scale, shape, snap, xOffset, yOffset }) => {
8
+ const shared_1 = require("../../shared");
9
+ const Grid_1 = __importDefault(require("./Grid"));
10
+ const Graph = ({ children, edgeFrequency, grid, id, line, maxScale, minScale, mode, move, nodeFrequency, nodeHeight, nodeWidth, onNodeDrag, onNodeEdgeDrop, onNodeSelect, onNodeStart, onNodeStop, onScale, onTranslate, pan, pull, scale, shape, showGrid, snap, translate, zoom }) => {
11
11
  if (!id) {
12
12
  console.error('No ID provided to @lincle/interactive Graph!');
13
13
  return null;
14
14
  }
15
- return ((0, jsx_runtime_1.jsx)(GraphContexts_1.default, { disableMove: disableMove, disablePan: disablePan, disablePull: disablePull, disableScale: disableScale, edgeFrequency: edgeFrequency, grid: grid, id: id !== null && id !== void 0 ? id : 0, line: line, maxScale: maxScale, minScale: minScale, mode: givenMode, nodeFrequency: nodeFrequency, nodeHeight: nodeHeight, nodeWidth: nodeWidth, onEdgeDrop: onEdgeDrop, onNodeDrag: onNodeDrag, onNodeSelect: onNodeSelect, onNodeStart: onNodeStart, onNodeStop: onNodeStop, onScale: onScale, onTranslate: onTranslate, scale: scale, shape: shape, snap: snap, xOffset: xOffset, yOffset: yOffset, children: (0, jsx_runtime_1.jsx)(base_1.Graph, { grid: false, id: id, children: (0, jsx_runtime_1.jsx)(Interaction_1.default, { onMouseDown: onMouseDown, onMouseUp: onMouseUp, onTouchEnd: onTouchEnd, onTouchStart: onTouchStart, children: children }) }) }));
15
+ const gird = showGrid === false ?
16
+ null :
17
+ (0, jsx_runtime_1.jsx)(Grid_1.default, {});
18
+ return ((0, jsx_runtime_1.jsx)(shared_1.GraphBase, { edgeFrequency: edgeFrequency, grid: grid, id: id, line: line, nodeFrequency: nodeFrequency, nodeHeight: nodeHeight, nodeWidth: nodeWidth, shape: shape, showGrid: false, children: (0, jsx_runtime_1.jsxs)(shared_1.Providers, { maxScale: maxScale, minScale: minScale, mode: mode, move: move, onNodeDrag: onNodeDrag, onNodeEdgeDrop: onNodeEdgeDrop, onNodeSelect: onNodeSelect, onNodeStart: onNodeStart, onNodeStop: onNodeStop, onScale: onScale, onTranslate: onTranslate, pan: pan, pull: pull, scale: scale, snap: snap, translate: translate, zoom: zoom, children: [gird, children] }) }));
16
19
  };
20
+ exports.Graph = Graph;
17
21
  Graph.displayName = 'LincleInteractiveGraph';
18
- exports.default = Graph;
22
+ var Grid_2 = require("./Grid");
23
+ Object.defineProperty(exports, "Grid", { enumerable: true, get: function () { return __importDefault(Grid_2).default; } });
@@ -1,4 +1,4 @@
1
1
  import { type InteractionProps } from '../../shared';
2
2
  import { type FunctionComponent } from 'react';
3
3
  declare const Interaction: FunctionComponent<InteractionProps>;
4
- export default Interaction;
4
+ export { Interaction };
@@ -1,26 +1,52 @@
1
1
  "use strict";
2
2
  Object.defineProperty(exports, "__esModule", { value: true });
3
+ exports.Interaction = void 0;
3
4
  const jsx_runtime_1 = require("react/jsx-runtime");
4
5
  const shared_1 = require("../../shared");
5
6
  const react_1 = require("react");
6
7
  const react_map_interaction_1 = require("react-map-interaction");
7
8
  const CLICK_TIME = 500;
8
- const PRESS_TIME = 350;
9
+ const useDoubleTap = () => {
10
+ const timer = (0, react_1.useRef)(null);
11
+ (0, react_1.useEffect)(() => {
12
+ return () => {
13
+ if (timer.current) {
14
+ clearTimeout(timer.current);
15
+ timer.current = null;
16
+ }
17
+ };
18
+ }, []);
19
+ return (0, react_1.useCallback)((callback, threshold = CLICK_TIME) => {
20
+ if (timer.current) {
21
+ clearTimeout(timer.current);
22
+ timer.current = null;
23
+ return callback();
24
+ }
25
+ else {
26
+ timer.current = setTimeout(() => {
27
+ timer.current = null;
28
+ }, threshold);
29
+ return;
30
+ }
31
+ }, []);
32
+ };
9
33
  const Interaction = ({ children, onMouseDown, onMouseUp, onTouchEnd, onTouchStart }) => {
10
- const { givenMode, onMode } = (0, react_1.useContext)(shared_1.ModeContext);
11
- const { onNodeSelect } = (0, react_1.useContext)(shared_1.NodeContext);
12
- const { disablePan, disableScale, maxScale, minScale } = (0, react_1.useContext)(shared_1.TransformContext);
13
- const { onScale, scale } = (0, react_1.useContext)(shared_1.ScaleContext);
14
- const { onTranslate, translate } = (0, react_1.useContext)(shared_1.TranslateContext);
15
- const clickTimeout = (0, react_1.useRef)();
16
- const pressTimeout = (0, react_1.useRef)();
34
+ const scale = (0, shared_1.useScale)();
35
+ const onScale = (0, shared_1.useOnScale)();
36
+ const translate = (0, shared_1.useTranslate)();
37
+ const onTranslate = (0, shared_1.useOnTranslate)();
38
+ const graphMode = (0, shared_1.useMode)();
39
+ const givenMode = (0, shared_1.useModeGiven)();
40
+ const onMode = (0, shared_1.useOnMode)();
41
+ const maxScale = (0, shared_1.useMinScale)();
42
+ const minScale = (0, shared_1.useMaxScale)();
43
+ const pan = (0, shared_1.usePan)();
44
+ const zoom = (0, shared_1.useZoom)();
17
45
  const keypress = (0, react_1.useRef)(false);
18
- const privateMode = (0, react_1.useRef)(givenMode);
19
- const handleMode = (0, react_1.useCallback)((mode) => {
20
- if (onMode &&
21
- privateMode.current !== mode) {
22
- privateMode.current = mode;
23
- onMode(mode);
46
+ const handleDoubleTap = useDoubleTap();
47
+ const handleMode = (0, react_1.useCallback)((changedMode) => {
48
+ if (onMode) {
49
+ onMode(changedMode);
24
50
  }
25
51
  }, [
26
52
  onMode
@@ -52,12 +78,6 @@ const Interaction = ({ children, onMouseDown, onMouseUp, onTouchEnd, onTouchStar
52
78
  window.addEventListener('keyup', onKeyUp);
53
79
  return () => {
54
80
  keypress.current = false;
55
- if (clickTimeout.current) {
56
- clearTimeout(clickTimeout.current);
57
- }
58
- if (pressTimeout.current) {
59
- clearTimeout(pressTimeout.current);
60
- }
61
81
  window.removeEventListener('keydown', onKeyDown);
62
82
  window.removeEventListener('keyup', onKeyUp);
63
83
  };
@@ -72,14 +92,6 @@ const Interaction = ({ children, onMouseDown, onMouseUp, onTouchEnd, onTouchStar
72
92
  };
73
93
  }, []);
74
94
  const handleChange = (0, react_1.useCallback)(({ scale: z, translation: { x, y } }) => {
75
- if (pressTimeout.current) {
76
- clearTimeout(pressTimeout.current);
77
- pressTimeout.current = undefined;
78
- }
79
- if (clickTimeout.current) {
80
- clearTimeout(clickTimeout.current);
81
- clickTimeout.current = undefined;
82
- }
83
95
  if (onTranslate) {
84
96
  onTranslate({
85
97
  x,
@@ -93,50 +105,34 @@ const Interaction = ({ children, onMouseDown, onMouseUp, onTouchEnd, onTouchStar
93
105
  onScale,
94
106
  onTranslate
95
107
  ]);
96
- const handlePressStart = (0, react_1.useCallback)(() => {
97
- if (!givenMode &&
98
- onNodeSelect &&
99
- !clickTimeout.current) {
100
- pressTimeout.current = setTimeout(() => {
101
- pressTimeout.current = undefined;
102
- handleMode('select');
103
- }, PRESS_TIME);
104
- }
105
- }, [
106
- givenMode,
107
- handleMode,
108
- onNodeSelect
109
- ]);
110
- const handleTapStart = (0, react_1.useCallback)(() => {
111
- if (!givenMode) {
112
- if (clickTimeout.current) {
113
- clearTimeout(clickTimeout.current);
114
- clickTimeout.current = setTimeout(() => {
115
- clickTimeout.current = undefined;
116
- handleMode('pull');
117
- }, PRESS_TIME);
118
- }
119
- else {
120
- clickTimeout.current = setTimeout(() => {
121
- clickTimeout.current = undefined;
122
- }, CLICK_TIME);
123
- }
124
- }
125
- }, [
126
- givenMode,
127
- handleMode
128
- ]);
129
108
  const handleTapEnd = (0, react_1.useCallback)(() => {
130
- if (!givenMode) {
131
- if (pressTimeout.current) {
132
- clearTimeout(pressTimeout.current);
133
- pressTimeout.current = undefined;
109
+ if (onMode) {
110
+ switch (graphMode) {
111
+ case 'move': {
112
+ return handleDoubleTap(() => {
113
+ onMode('pull');
114
+ });
115
+ }
116
+ case 'pull': {
117
+ return handleDoubleTap(() => {
118
+ onMode('select');
119
+ });
120
+ }
121
+ case 'select':
122
+ default: {
123
+ return handleDoubleTap(() => {
124
+ onMode('move');
125
+ });
126
+ }
134
127
  }
135
- handleMode('move');
128
+ }
129
+ else {
130
+ return;
136
131
  }
137
132
  }, [
138
- givenMode,
139
- handleMode
133
+ graphMode,
134
+ handleDoubleTap,
135
+ onMode
140
136
  ]);
141
137
  const handleMouseDown = (0, react_1.useCallback)((event) => {
142
138
  if (onMouseDown) {
@@ -146,29 +142,23 @@ const Interaction = ({ children, onMouseDown, onMouseUp, onTouchEnd, onTouchStar
146
142
  onMouseDown
147
143
  ]);
148
144
  const handleMouseUp = (0, react_1.useCallback)((event) => {
145
+ handleTapEnd();
149
146
  if (onMouseUp) {
150
147
  onMouseUp(event);
151
148
  }
152
149
  }, [
150
+ handleTapEnd,
153
151
  onMouseUp
154
152
  ]);
155
153
  const handleTouchStart = (0, react_1.useCallback)((event) => {
156
- if (keypress.current === false) {
157
- handlePressStart();
158
- handleTapStart();
159
- }
160
154
  if (onTouchStart) {
161
155
  onTouchStart(event);
162
156
  }
163
157
  }, [
164
- handlePressStart,
165
- handleTapStart,
166
158
  onTouchStart
167
159
  ]);
168
160
  const handleTouchEnd = (0, react_1.useCallback)((event) => {
169
- if (keypress.current === false) {
170
- handleTapEnd();
171
- }
161
+ handleTapEnd();
172
162
  if (onTouchEnd) {
173
163
  onTouchEnd(event);
174
164
  }
@@ -194,9 +184,9 @@ const Interaction = ({ children, onMouseDown, onMouseUp, onTouchEnd, onTouchStar
194
184
  scale,
195
185
  translate
196
186
  ]);
197
- return ((0, jsx_runtime_1.jsx)(react_map_interaction_1.MapInteraction, { defaultScale: scale, defaultTranslation: defaultTranslation, disablePan: disablePan, disableZoom: disableScale, maxScale: maxScale, minScale: minScale, onChange: handleChange, value: transform, children: () => {
187
+ return ((0, jsx_runtime_1.jsx)(react_map_interaction_1.MapInteraction, { defaultScale: scale, defaultTranslation: defaultTranslation, disablePan: !pan, disableZoom: !zoom, maxScale: maxScale, minScale: minScale, onChange: handleChange, value: transform, children: () => {
198
188
  return ((0, jsx_runtime_1.jsx)("div", { className: 'lincle-interactive-graph', onMouseDown: handleMouseDown, onMouseUp: handleMouseUp, onTouchEnd: handleTouchEnd, onTouchStart: handleTouchStart, role: 'none', children: (0, jsx_runtime_1.jsx)("div", { className: 'lincle-interactive-transform', style: style, children: children }) }));
199
189
  } }));
200
190
  };
191
+ exports.Interaction = Interaction;
201
192
  Interaction.displayName = 'LincleInteractiveInteraction';
202
- exports.default = Interaction;
@@ -10,9 +10,28 @@ const emptySnap = [
10
10
  1,
11
11
  1
12
12
  ];
13
- const MoveNode = ({ children, className, disabled, height, id, mode, onDrag, onSelect, onStart, onStop, shape, snap, style, width, x, y }) => {
14
- const { scale } = (0, react_1.useContext)(shared_1.ScaleContext);
15
- const [snapX, snapY] = snap !== null && snap !== void 0 ? snap : emptySnap;
13
+ const MoveNode = ({ children, className, disabled, height, id, mode, onDrag, onSelect, onStart, onStop, shape, snap: givenSnap, style, width, x, y }) => {
14
+ const scale = (0, shared_1.useScale)();
15
+ const snap = (0, shared_1.useSnap)();
16
+ const [snapX, snapY] = (0, react_1.useMemo)(() => {
17
+ if (givenSnap === undefined) {
18
+ if (Array.isArray(snap)) {
19
+ return snap;
20
+ }
21
+ else {
22
+ return emptySnap;
23
+ }
24
+ }
25
+ else if (Array.isArray(givenSnap)) {
26
+ return givenSnap;
27
+ }
28
+ else {
29
+ return emptySnap;
30
+ }
31
+ }, [
32
+ givenSnap,
33
+ snap
34
+ ]);
16
35
  const [position, setPosition] = (0, react_1.useState)({
17
36
  x,
18
37
  y
@@ -1,40 +1,53 @@
1
1
  "use strict";
2
- var __importDefault = (this && this.__importDefault) || function (mod) {
3
- return (mod && mod.__esModule) ? mod : { "default": mod };
4
- };
5
2
  Object.defineProperty(exports, "__esModule", { value: true });
6
3
  const jsx_runtime_1 = require("react/jsx-runtime");
7
4
  const shared_1 = require("../../../shared");
8
- const Pull_1 = __importDefault(require("../../Pull"));
9
5
  const react_1 = require("react");
10
6
  const react_draggable_1 = require("react-draggable");
11
- const PullNode = ({ className, disabled, height, line, onDrag, onEdgeDrop: givenOnEdgeDrop, onStart, onStop, shape, sourceId, style, width, x, y }) => {
12
- var _a, _b;
13
- const diagramId = (_a = (0, react_1.useContext)(shared_1.GraphContext)) === null || _a === void 0 ? void 0 : _a.diagramId;
14
- const nodePositions = (_b = (0, react_1.useContext)(shared_1.GraphContext)) === null || _b === void 0 ? void 0 : _b.nodePositions;
15
- const { onEdgeDrop: defaultOnEdgeDrop } = (0, react_1.useContext)(shared_1.NodeContext);
16
- const onEdgeDrop = givenOnEdgeDrop !== null && givenOnEdgeDrop !== void 0 ? givenOnEdgeDrop : defaultOnEdgeDrop;
17
- const { scale } = (0, react_1.useContext)(shared_1.ScaleContext);
18
- const [position, setPosition] = (0, react_1.useState)({
19
- x,
20
- y
21
- });
22
- const pos = (0, react_1.useRef)(position);
23
- pos.current = position;
7
+ const PullNode = ({ className, disabled, height = 0, line = 'direct', onDrag, onEdgeDrop: givenOnEdgeDrop, onStart, onStop, shape = 'oval', sourceId, style, width = 0, x = 0, y = 0 }) => {
8
+ const diagramId = (0, shared_1.useDiagramId)();
9
+ const nodePositions = (0, shared_1.useNodePositions)();
10
+ const setConnection = (0, shared_1.useSetConnection)(sourceId);
11
+ const onNodeEdgeDrop = (0, shared_1.useOnNodeEdgeDrop)();
12
+ const onEdgeDrop = givenOnEdgeDrop !== null && givenOnEdgeDrop !== void 0 ? givenOnEdgeDrop : onNodeEdgeDrop;
13
+ const scale = (0, shared_1.useScale)();
14
+ (0, react_1.useEffect)(() => {
15
+ return () => {
16
+ setConnection();
17
+ };
18
+ }, []);
24
19
  const handleStart = (0, react_1.useCallback)((event) => {
25
20
  event.stopPropagation();
26
- if (onStart) {
21
+ if (!disabled &&
22
+ onStart) {
27
23
  onStart(event);
28
24
  }
29
25
  }, [
26
+ disabled,
30
27
  onStart
31
28
  ]);
32
29
  const handleDrag = (0, react_1.useCallback)((event, data) => {
30
+ var _a, _b;
33
31
  event.stopPropagation();
34
32
  if (!disabled) {
35
- setPosition({
36
- x: data.x,
37
- y: data.y
33
+ setConnection({
34
+ line,
35
+ source: {
36
+ height,
37
+ id: sourceId,
38
+ shape,
39
+ width,
40
+ x,
41
+ y
42
+ },
43
+ target: {
44
+ height: 0,
45
+ id: sourceId,
46
+ shape,
47
+ width: 0,
48
+ x: (_a = data.x) !== null && _a !== void 0 ? _a : 0,
49
+ y: (_b = data.y) !== null && _b !== void 0 ? _b : 0
50
+ }
38
51
  });
39
52
  if (onDrag) {
40
53
  onDrag(event, data);
@@ -42,48 +55,53 @@ const PullNode = ({ className, disabled, height, line, onDrag, onEdgeDrop: given
42
55
  }
43
56
  }, [
44
57
  disabled,
45
- onDrag
58
+ height,
59
+ line,
60
+ onDrag,
61
+ setConnection,
62
+ shape,
63
+ sourceId,
64
+ width,
65
+ x,
66
+ y
46
67
  ]);
47
68
  const handleStop = (0, react_1.useCallback)((event, data) => {
48
69
  event.stopPropagation();
49
- if (!disabled) {
50
- setPosition({
51
- x: data.x,
52
- y: data.y
53
- });
54
- }
70
+ setConnection();
55
71
  if (onStop) {
56
72
  onStop(event, data);
57
73
  }
58
74
  if (onEdgeDrop &&
59
- nodePositions &&
60
- position.x &&
61
- position.y) {
62
- nodePositions.match(position.x, position.y).then((match) => {
63
- onEdgeDrop(sourceId, Boolean(match) || match === 0 ?
75
+ nodePositions) {
76
+ nodePositions.match(data.x, data.y).then((match) => {
77
+ onEdgeDrop(event, sourceId, Boolean(match) || match === 0 ?
64
78
  match :
65
79
  undefined);
66
80
  }).catch(() => {
67
81
  });
68
82
  }
69
- setPosition({
70
- x,
71
- y
72
- });
73
83
  }, [
74
- disabled,
75
84
  nodePositions,
76
85
  onEdgeDrop,
77
86
  onStop,
78
- position.x,
79
- position.y,
80
- sourceId,
87
+ setConnection,
88
+ sourceId
89
+ ]);
90
+ const viewStyle = (0, react_1.useMemo)(() => {
91
+ return Object.assign({ borderRadius: shape === 'oval' ?
92
+ 50 :
93
+ undefined, height, left: x, position: 'absolute', top: y, width }, style);
94
+ }, [
95
+ height,
96
+ shape,
97
+ style,
98
+ width,
81
99
  x,
82
100
  y
83
101
  ]);
84
102
  const nodeRef = (0, react_1.useRef)(null);
85
103
  return diagramId ?
86
- ((0, jsx_runtime_1.jsx)(react_draggable_1.DraggableCore, { disabled: disabled, nodeRef: nodeRef, onDrag: handleDrag, onStart: handleStart, onStop: handleStop, scale: scale, children: (0, jsx_runtime_1.jsx)(Pull_1.default, { className: className, diagramId: diagramId, height: height, line: line, ref: nodeRef, shape: shape, sourceId: sourceId, style: style, width: width, x: position.x, y: position.y }) })) :
104
+ ((0, jsx_runtime_1.jsx)(react_draggable_1.DraggableCore, { disabled: disabled, nodeRef: nodeRef, onDrag: handleDrag, onStart: handleStart, onStop: handleStop, scale: scale, children: (0, jsx_runtime_1.jsx)("div", { className: className, ref: nodeRef, style: viewStyle }) })) :
87
105
  null;
88
106
  };
89
107
  PullNode.displayName = 'LincleInteractivePullNode';
@@ -1,4 +1,6 @@
1
1
  import { type NodeProps } from '../../shared';
2
2
  import { type FunctionComponent } from 'react';
3
3
  declare const Node: FunctionComponent<NodeProps>;
4
- export default Node;
4
+ export { Node };
5
+ export { default as MoveNode } from './MoveNode';
6
+ export { default as PullNode } from './PullNode';