@lincle/react-shared 0.0.1 → 0.4.0-next.10
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/LICENSE.md +165 -0
- package/dist/Contexts/EdgesContext.d.ts +22 -0
- package/dist/Contexts/EdgesContext.js +9 -0
- package/dist/Contexts/GraphContext.d.ts +17 -0
- package/dist/Contexts/GraphContext.js +19 -0
- package/dist/Contexts/index.d.ts +2 -0
- package/dist/Contexts/index.js +18 -0
- package/dist/Hooks/index.d.ts +13 -0
- package/dist/Hooks/index.js +29 -0
- package/dist/Hooks/useDefaultLine.d.ts +2 -0
- package/dist/Hooks/useDefaultLine.js +10 -0
- package/dist/Hooks/useDefaultNodeHeight.d.ts +2 -0
- package/dist/Hooks/useDefaultNodeHeight.js +10 -0
- package/dist/Hooks/useDefaultNodeWidth.d.ts +2 -0
- package/dist/Hooks/useDefaultNodeWidth.js +10 -0
- package/dist/Hooks/useDefaultShape.d.ts +2 -0
- package/dist/Hooks/useDefaultShape.js +10 -0
- package/dist/Hooks/useDiagramId.d.ts +2 -0
- package/dist/Hooks/useDiagramId.js +10 -0
- package/dist/Hooks/useEdge.d.ts +2 -0
- package/dist/Hooks/useEdge.js +10 -0
- package/dist/Hooks/useEdgeFrequency.d.ts +2 -0
- package/dist/Hooks/useEdgeFrequency.js +10 -0
- package/dist/Hooks/useEdgeSubscriber.d.ts +2 -0
- package/dist/Hooks/useEdgeSubscriber.js +10 -0
- package/dist/Hooks/useEdges.d.ts +2 -0
- package/dist/Hooks/useEdges.js +10 -0
- package/dist/Hooks/useGrid.d.ts +2 -0
- package/dist/Hooks/useGrid.js +10 -0
- package/dist/Hooks/useNodePositions.d.ts +2 -0
- package/dist/Hooks/useNodePositions.js +10 -0
- package/dist/Hooks/useRemoveEdge.d.ts +2 -0
- package/dist/Hooks/useRemoveEdge.js +10 -0
- package/dist/Hooks/useUpdateEdge.d.ts +2 -0
- package/dist/Hooks/useUpdateEdge.js +10 -0
- package/dist/Providers/EdgesProvider.d.ts +4 -0
- package/dist/Providers/EdgesProvider.js +46 -0
- package/dist/Providers/GraphProvider.d.ts +5 -0
- package/dist/Providers/GraphProvider.js +42 -0
- package/dist/Providers/Providers.d.ts +2 -0
- package/dist/Providers/Providers.js +18 -0
- package/dist/Providers/index.d.ts +5 -0
- package/dist/Providers/index.js +14 -0
- package/dist/defaultSettings.d.ts +12 -0
- package/dist/defaultSettings.js +15 -0
- package/dist/index.d.ts +5 -0
- package/dist/index.js +27 -0
- package/dist/types.d.ts +82 -0
- package/dist/types.js +2 -0
- package/dist/utils/EdgeSubscriber.d.ts +15 -0
- package/dist/utils/EdgeSubscriber.js +52 -0
- package/dist/utils/NodePositions.d.ts +31 -0
- package/dist/utils/NodePositions.js +226 -0
- package/dist/utils/Path/generateOrigins.d.ts +4 -0
- package/dist/utils/Path/generateOrigins.js +18 -0
- package/dist/utils/Path/lines/generateCurve.d.ts +17 -0
- package/dist/utils/Path/lines/generateCurve.js +50 -0
- package/dist/utils/Path/lines/generateDirect.d.ts +16 -0
- package/dist/utils/Path/lines/generateDirect.js +32 -0
- package/dist/utils/Path/lines/generatePoints.d.ts +15 -0
- package/dist/utils/Path/lines/generatePoints.js +111 -0
- package/dist/utils/Path/lines/generateStep.d.ts +17 -0
- package/dist/utils/Path/lines/generateStep.js +63 -0
- package/dist/utils/Path/lines/index.d.ts +4 -0
- package/dist/utils/Path/lines/index.js +12 -0
- package/dist/utils/Path/lines/types.d.ts +34 -0
- package/dist/utils/Path/lines/types.js +2 -0
- package/dist/utils/round.d.ts +2 -0
- package/dist/utils/round.js +9 -0
- package/package.json +29 -27
|
@@ -0,0 +1,111 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
exports.default = (source, target) => {
|
|
4
|
+
const sx = Math.round(source.x);
|
|
5
|
+
const sy = Math.round(source.y);
|
|
6
|
+
const tx = Math.round(target.x);
|
|
7
|
+
const ty = Math.round(target.y);
|
|
8
|
+
const halfTargetWidth = Math.round(target.width / 2);
|
|
9
|
+
const halfTargetHeight = Math.round(target.height / 2);
|
|
10
|
+
const halfSourceWidth = Math.round(source.width / 2);
|
|
11
|
+
const halfSourceHeight = Math.round(source.height / 2);
|
|
12
|
+
const sourceAngle = Math.atan2(tx + halfTargetWidth - (sx + halfSourceWidth), ty + halfTargetHeight - (sy + halfSourceHeight));
|
|
13
|
+
const targetAngle = Math.atan2(sx + halfSourceWidth - (tx + halfTargetWidth), sy + halfSourceHeight - (ty + halfTargetHeight));
|
|
14
|
+
const sourceEdgeX = Math.sin(sourceAngle) * halfSourceWidth + halfSourceWidth;
|
|
15
|
+
const sourceEdgeY = Math.cos(sourceAngle) * halfSourceHeight + halfSourceHeight;
|
|
16
|
+
const targetEdgeX = Math.sin(targetAngle) * halfTargetWidth + halfTargetWidth;
|
|
17
|
+
const targetEdgeY = Math.cos(targetAngle) * halfTargetHeight + halfTargetHeight;
|
|
18
|
+
const sourceDX = sx + sourceEdgeX - tx - targetEdgeX;
|
|
19
|
+
const sourceDY = sy + sourceEdgeY - ty - targetEdgeY;
|
|
20
|
+
const sourceROR = sourceDX / sourceDY;
|
|
21
|
+
let orientation;
|
|
22
|
+
let targetPoints = {
|
|
23
|
+
x: sourceEdgeX,
|
|
24
|
+
y: sourceEdgeY
|
|
25
|
+
};
|
|
26
|
+
if (sourceROR < 1 && sourceROR > -1) {
|
|
27
|
+
orientation = 'vertical';
|
|
28
|
+
if (sourceDY > 0) {
|
|
29
|
+
targetPoints = {
|
|
30
|
+
x: sx + sourceEdgeX,
|
|
31
|
+
y: sy + (source.shape === 'oval' ?
|
|
32
|
+
sourceEdgeY :
|
|
33
|
+
0)
|
|
34
|
+
};
|
|
35
|
+
}
|
|
36
|
+
else {
|
|
37
|
+
targetPoints = {
|
|
38
|
+
x: sx + sourceEdgeX,
|
|
39
|
+
y: sy + (source.shape === 'oval' ?
|
|
40
|
+
sourceEdgeY :
|
|
41
|
+
source.height)
|
|
42
|
+
};
|
|
43
|
+
}
|
|
44
|
+
}
|
|
45
|
+
else {
|
|
46
|
+
orientation = 'horizontal';
|
|
47
|
+
if (sourceDX > 0) {
|
|
48
|
+
targetPoints = {
|
|
49
|
+
x: sx + (source.shape === 'oval' ?
|
|
50
|
+
sourceEdgeX :
|
|
51
|
+
0),
|
|
52
|
+
y: sy + sourceEdgeY
|
|
53
|
+
};
|
|
54
|
+
}
|
|
55
|
+
else {
|
|
56
|
+
targetPoints = {
|
|
57
|
+
x: sx + (source.shape === 'oval' ?
|
|
58
|
+
sourceEdgeX :
|
|
59
|
+
source.width),
|
|
60
|
+
y: sy + sourceEdgeY
|
|
61
|
+
};
|
|
62
|
+
}
|
|
63
|
+
}
|
|
64
|
+
const targetDX = tx - targetEdgeX - sx - sourceEdgeX;
|
|
65
|
+
const targetDY = ty - targetEdgeY - sy - sourceEdgeY;
|
|
66
|
+
let sourcePoints = {
|
|
67
|
+
x: targetEdgeX,
|
|
68
|
+
y: targetEdgeY
|
|
69
|
+
};
|
|
70
|
+
if (orientation === 'vertical') {
|
|
71
|
+
if (targetDY > 0) {
|
|
72
|
+
sourcePoints = {
|
|
73
|
+
x: tx + targetEdgeX,
|
|
74
|
+
y: ty + (target.shape === 'oval' ?
|
|
75
|
+
targetEdgeY :
|
|
76
|
+
0)
|
|
77
|
+
};
|
|
78
|
+
}
|
|
79
|
+
else {
|
|
80
|
+
sourcePoints = {
|
|
81
|
+
x: tx + targetEdgeX,
|
|
82
|
+
y: ty + (target.shape === 'oval' ?
|
|
83
|
+
targetEdgeY :
|
|
84
|
+
target.height)
|
|
85
|
+
};
|
|
86
|
+
}
|
|
87
|
+
}
|
|
88
|
+
else {
|
|
89
|
+
if (targetDX > 0) {
|
|
90
|
+
sourcePoints = {
|
|
91
|
+
x: tx + (target.shape === 'oval' ?
|
|
92
|
+
targetEdgeX :
|
|
93
|
+
0),
|
|
94
|
+
y: ty + targetEdgeY
|
|
95
|
+
};
|
|
96
|
+
}
|
|
97
|
+
else {
|
|
98
|
+
sourcePoints = {
|
|
99
|
+
x: tx + (target.shape === 'oval' ?
|
|
100
|
+
targetEdgeX :
|
|
101
|
+
target.width),
|
|
102
|
+
y: ty + targetEdgeY
|
|
103
|
+
};
|
|
104
|
+
}
|
|
105
|
+
}
|
|
106
|
+
return {
|
|
107
|
+
orientation,
|
|
108
|
+
source: sourcePoints,
|
|
109
|
+
target: targetPoints
|
|
110
|
+
};
|
|
111
|
+
};
|
|
@@ -0,0 +1,17 @@
|
|
|
1
|
+
import { type Coordinates, type Line } from './types';
|
|
2
|
+
export declare const stepHorizontal: (rx1: number, ry1: number, rx2: number, ry2: number, center?: boolean) => Line;
|
|
3
|
+
export declare const stepVertical: (rx1: number, ry1: number, rx2: number, ry2: number, center?: boolean) => Line;
|
|
4
|
+
declare const _default: (source: {
|
|
5
|
+
height: number;
|
|
6
|
+
shape: "oval" | "rectangle";
|
|
7
|
+
width: number;
|
|
8
|
+
x: number;
|
|
9
|
+
y: number;
|
|
10
|
+
}, target: {
|
|
11
|
+
height: number;
|
|
12
|
+
shape: "oval" | "rectangle";
|
|
13
|
+
width: number;
|
|
14
|
+
x: number;
|
|
15
|
+
y: number;
|
|
16
|
+
}, center?: boolean) => Coordinates;
|
|
17
|
+
export default _default;
|
|
@@ -0,0 +1,63 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
var __importDefault = (this && this.__importDefault) || function (mod) {
|
|
3
|
+
return (mod && mod.__esModule) ? mod : { "default": mod };
|
|
4
|
+
};
|
|
5
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
6
|
+
exports.stepVertical = exports.stepHorizontal = void 0;
|
|
7
|
+
const generatePoints_1 = __importDefault(require("./generatePoints"));
|
|
8
|
+
const stepHorizontal = (rx1, ry1, rx2, ry2, center) => {
|
|
9
|
+
const x1 = Math.round(rx1);
|
|
10
|
+
const y1 = Math.round(ry1);
|
|
11
|
+
const x2 = Math.round(rx2);
|
|
12
|
+
const y2 = Math.round(ry2);
|
|
13
|
+
const d = [];
|
|
14
|
+
const mx = Math.round(x1 + (x2 - x1) / 2);
|
|
15
|
+
const my = Math.round(y1 + (y2 - y1) / 2);
|
|
16
|
+
const cx = Math.round((x2 + x1) / 2);
|
|
17
|
+
const cy = my;
|
|
18
|
+
d.push('M', x1, y1);
|
|
19
|
+
d.push('L', mx, y1);
|
|
20
|
+
d.push('L', mx, y2);
|
|
21
|
+
d.push('L', x2, y2);
|
|
22
|
+
return {
|
|
23
|
+
center: center ?
|
|
24
|
+
{
|
|
25
|
+
x: cx,
|
|
26
|
+
y: cy
|
|
27
|
+
} :
|
|
28
|
+
undefined,
|
|
29
|
+
path: d.join(' ')
|
|
30
|
+
};
|
|
31
|
+
};
|
|
32
|
+
exports.stepHorizontal = stepHorizontal;
|
|
33
|
+
const stepVertical = (rx1, ry1, rx2, ry2, center) => {
|
|
34
|
+
const x1 = Math.round(rx1);
|
|
35
|
+
const y1 = Math.round(ry1);
|
|
36
|
+
const x2 = Math.round(rx2);
|
|
37
|
+
const y2 = Math.round(ry2);
|
|
38
|
+
const d = [];
|
|
39
|
+
const mx = Math.round(x1 + (x2 - x1) / 2);
|
|
40
|
+
const my = Math.round(y1 + (y2 - y1) / 2);
|
|
41
|
+
const cx = mx;
|
|
42
|
+
const cy = Math.round((y2 + y1) / 2);
|
|
43
|
+
d.push('M', x1, y1);
|
|
44
|
+
d.push('L', x1, my);
|
|
45
|
+
d.push('L', x2, my);
|
|
46
|
+
d.push('L', x2, y2);
|
|
47
|
+
return {
|
|
48
|
+
center: center ?
|
|
49
|
+
{
|
|
50
|
+
x: cx,
|
|
51
|
+
y: cy
|
|
52
|
+
} :
|
|
53
|
+
undefined,
|
|
54
|
+
path: d.join(' ')
|
|
55
|
+
};
|
|
56
|
+
};
|
|
57
|
+
exports.stepVertical = stepVertical;
|
|
58
|
+
exports.default = (source, target, center) => {
|
|
59
|
+
const { orientation, source: sourcePoints, target: targetPoints } = (0, generatePoints_1.default)(source, target);
|
|
60
|
+
return Object.assign(Object.assign({}, (orientation === 'horizontal' ?
|
|
61
|
+
(0, exports.stepHorizontal)(sourcePoints.x, sourcePoints.y, targetPoints.x, targetPoints.y, center) :
|
|
62
|
+
(0, exports.stepVertical)(sourcePoints.x, sourcePoints.y, targetPoints.x, targetPoints.y, center))), { source: sourcePoints, target: targetPoints });
|
|
63
|
+
};
|
|
@@ -0,0 +1,12 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
var __importDefault = (this && this.__importDefault) || function (mod) {
|
|
3
|
+
return (mod && mod.__esModule) ? mod : { "default": mod };
|
|
4
|
+
};
|
|
5
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
6
|
+
exports.generateStep = exports.generateDirect = exports.generateCurve = void 0;
|
|
7
|
+
var generateCurve_1 = require("./generateCurve");
|
|
8
|
+
Object.defineProperty(exports, "generateCurve", { enumerable: true, get: function () { return __importDefault(generateCurve_1).default; } });
|
|
9
|
+
var generateDirect_1 = require("./generateDirect");
|
|
10
|
+
Object.defineProperty(exports, "generateDirect", { enumerable: true, get: function () { return __importDefault(generateDirect_1).default; } });
|
|
11
|
+
var generateStep_1 = require("./generateStep");
|
|
12
|
+
Object.defineProperty(exports, "generateStep", { enumerable: true, get: function () { return __importDefault(generateStep_1).default; } });
|
|
@@ -0,0 +1,34 @@
|
|
|
1
|
+
export type Line = {
|
|
2
|
+
center?: {
|
|
3
|
+
x: number;
|
|
4
|
+
y: number;
|
|
5
|
+
};
|
|
6
|
+
path: string;
|
|
7
|
+
};
|
|
8
|
+
export type Orientation = 'horizontal' | 'vertical';
|
|
9
|
+
export type Points = {
|
|
10
|
+
orientation: Orientation;
|
|
11
|
+
source: {
|
|
12
|
+
x: number;
|
|
13
|
+
y: number;
|
|
14
|
+
};
|
|
15
|
+
target: {
|
|
16
|
+
x: number;
|
|
17
|
+
y: number;
|
|
18
|
+
};
|
|
19
|
+
};
|
|
20
|
+
export type Coordinates = {
|
|
21
|
+
center?: {
|
|
22
|
+
x: number;
|
|
23
|
+
y: number;
|
|
24
|
+
};
|
|
25
|
+
path: string;
|
|
26
|
+
source: {
|
|
27
|
+
x: number;
|
|
28
|
+
y: number;
|
|
29
|
+
};
|
|
30
|
+
target: {
|
|
31
|
+
x: number;
|
|
32
|
+
y: number;
|
|
33
|
+
};
|
|
34
|
+
};
|
package/package.json
CHANGED
|
@@ -2,7 +2,8 @@
|
|
|
2
2
|
"name": "@lincle/react-shared",
|
|
3
3
|
"title": "lincle react shared",
|
|
4
4
|
"license": "LGPL-3.0-or-later",
|
|
5
|
-
"version": "0.0.
|
|
5
|
+
"version": "0.4.0-next.10",
|
|
6
|
+
"private": false,
|
|
6
7
|
"description": "Shared library for @lincle",
|
|
7
8
|
"author": "wallzero @wallzeroblog (http://wallzero.com)",
|
|
8
9
|
"contributors": [
|
|
@@ -19,20 +20,19 @@
|
|
|
19
20
|
"COPYING.md",
|
|
20
21
|
"COPYING.LESSER.md"
|
|
21
22
|
],
|
|
22
|
-
"homepage": "https://gitlab.com/
|
|
23
|
+
"homepage": "https://gitlab.com/digested/lincle/tree/master/packages/react-shared/",
|
|
23
24
|
"repository": {
|
|
24
25
|
"type": "git",
|
|
25
|
-
"url": "https://gitlab.com/
|
|
26
|
+
"url": "https://gitlab.com/digested/lincle.git"
|
|
26
27
|
},
|
|
27
28
|
"bugs": {
|
|
28
|
-
"url": "https://gitlab.com/
|
|
29
|
+
"url": "https://gitlab.com/digested/lincle/issues"
|
|
29
30
|
},
|
|
30
31
|
"scripts": {
|
|
31
|
-
"build": "run-s clean:dist build:prod
|
|
32
|
+
"build": "run-s clean:dist build:prod",
|
|
32
33
|
"build:prod": "tsc -p ./tsconfig.json",
|
|
33
|
-
"build:watch": "run-s clean:dist build:prod build:
|
|
34
|
+
"build:watch": "run-s clean:dist build:prod build:watch:tsc",
|
|
34
35
|
"build:watch:tsc": "tsc -p ./tsconfig.json --watch --pretty --preserveWatchOutput",
|
|
35
|
-
"build:styles": "ncp src/styles.g.css dist/styles.g.css",
|
|
36
36
|
"----------------------------------------------------------------": "",
|
|
37
37
|
"build:prod:config": "",
|
|
38
38
|
"---------------------------------------------------------------": "",
|
|
@@ -43,31 +43,32 @@
|
|
|
43
43
|
"clean:dist": "rimraf dist"
|
|
44
44
|
},
|
|
45
45
|
"devDependencies": {
|
|
46
|
-
"@digest/eslint-config-jest": "^4.
|
|
47
|
-
"@digest/eslint-config-react": "^4.
|
|
48
|
-
"@digest/eslint-config-typescript": "^4.
|
|
49
|
-
"@digest/jest-junit": "^4.
|
|
50
|
-
"@digest/jest-react": "^4.
|
|
51
|
-
"@digest/jest-typescript": "^4.
|
|
52
|
-
"@digest/typescript": "^4.
|
|
53
|
-
"@types/bezier-js": "^4.1.
|
|
54
|
-
"@types/jest": "^29.5.
|
|
55
|
-
"@types/lodash.
|
|
56
|
-
"@types/lodash.
|
|
57
|
-
"@types/node": "^
|
|
58
|
-
"@types/react": "^18.
|
|
59
|
-
"@types/react-dom": "^18.
|
|
60
|
-
"@types/react-test-renderer": "^18.0
|
|
46
|
+
"@digest/eslint-config-jest": "^4.4.3",
|
|
47
|
+
"@digest/eslint-config-react": "^4.4.3",
|
|
48
|
+
"@digest/eslint-config-typescript": "^4.4.3",
|
|
49
|
+
"@digest/jest-junit": "^4.4.3",
|
|
50
|
+
"@digest/jest-react": "^4.4.3",
|
|
51
|
+
"@digest/jest-typescript": "^4.4.3",
|
|
52
|
+
"@digest/typescript": "^4.4.3",
|
|
53
|
+
"@types/bezier-js": "^4.1.3",
|
|
54
|
+
"@types/jest": "^29.5.12",
|
|
55
|
+
"@types/lodash.debounce": "^4.0.9",
|
|
56
|
+
"@types/lodash.throttle": "^4.1.9",
|
|
57
|
+
"@types/node": "^22.1.0",
|
|
58
|
+
"@types/react": "^18.3.3",
|
|
59
|
+
"@types/react-dom": "^18.3.0",
|
|
60
|
+
"@types/react-test-renderer": "^18.3.0",
|
|
61
61
|
"cross-env": "^7.0.3",
|
|
62
|
-
"jest-environment-jsdom": "^29.
|
|
62
|
+
"jest-environment-jsdom": "^29.7.0",
|
|
63
63
|
"jest-environment-jsdom-global": "^4.0.0",
|
|
64
64
|
"ncp": "^2.0.0",
|
|
65
65
|
"npm-run-all": "^4.1.5",
|
|
66
|
-
"react": "^18.
|
|
67
|
-
"react-test-renderer": "^18.
|
|
68
|
-
"rimraf": "^
|
|
66
|
+
"react": "^18.3.1",
|
|
67
|
+
"react-test-renderer": "^18.3.1",
|
|
68
|
+
"rimraf": "^6.0.1"
|
|
69
69
|
},
|
|
70
70
|
"dependencies": {
|
|
71
|
+
"bezier-js": "^6.1.4",
|
|
71
72
|
"lodash.debounce": "^4.0.8",
|
|
72
73
|
"lodash.throttle": "^4.1.1"
|
|
73
74
|
},
|
|
@@ -86,5 +87,6 @@
|
|
|
86
87
|
"dag",
|
|
87
88
|
"acyclical graph",
|
|
88
89
|
"cyclical graph"
|
|
89
|
-
]
|
|
90
|
+
],
|
|
91
|
+
"gitHead": "c672cbc4ddbc1944133ea10ac26a4c04e7d8e3ba"
|
|
90
92
|
}
|