@lincle/react-shared 0.4.0-next.12 → 0.4.0-next.13
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/dist/Contexts/EdgesContext.d.ts +4 -4
- package/dist/Contexts/GraphContext.d.ts +1 -1
- package/dist/Hooks/useEdge.d.ts +1 -1
- package/dist/Providers/EdgesProvider.d.ts +1 -1
- package/dist/Providers/GraphProvider.d.ts +1 -1
- package/dist/index.d.ts +1 -1
- package/dist/index.js +0 -1
- package/dist/types.d.ts +37 -37
- package/dist/utils/EdgeSubscriber.d.ts +5 -5
- package/dist/utils/EdgeSubscriber.js +15 -15
- package/dist/utils/NodePositions.d.ts +16 -16
- package/dist/utils/NodePositions.js +89 -87
- package/dist/utils/Path/lines/generateCurve.js +2 -2
- package/dist/utils/Path/lines/generateStep.js +2 -2
- package/dist/utils/Path/lines/types.d.ts +6 -6
- package/package.json +90 -90
|
@@ -7,16 +7,16 @@ export type Edge = Partial<Omit<EdgeProps, 'id'>> & {
|
|
|
7
7
|
y: number;
|
|
8
8
|
};
|
|
9
9
|
className?: string;
|
|
10
|
-
edgeId:
|
|
10
|
+
edgeId: number | string;
|
|
11
11
|
style?: any;
|
|
12
12
|
};
|
|
13
13
|
export type Edges = {
|
|
14
|
-
[key:
|
|
14
|
+
[key: number | string]: Edge;
|
|
15
15
|
};
|
|
16
|
-
export type RemoveEdge = (edgeId: string | number) => void;
|
|
17
|
-
export type UpdateEdge = (edgeId: string | number, edge: Partial<Edge>) => void;
|
|
18
16
|
export type EdgesContextProps = {
|
|
19
17
|
edges: Edges;
|
|
20
18
|
removeEdge?: RemoveEdge;
|
|
21
19
|
updateEdge?: UpdateEdge;
|
|
22
20
|
};
|
|
21
|
+
export type RemoveEdge = (edgeId: number | string) => void;
|
|
22
|
+
export type UpdateEdge = (edgeId: number | string, edge: Partial<Edge>) => void;
|
package/dist/Hooks/useEdge.d.ts
CHANGED
|
@@ -1,2 +1,2 @@
|
|
|
1
|
-
declare const useEdge: (edgeId:
|
|
1
|
+
declare const useEdge: (edgeId: number | string) => import("../Contexts").Edge;
|
|
2
2
|
export { useEdge };
|
|
@@ -1,4 +1,4 @@
|
|
|
1
1
|
import { type FunctionComponent, type PropsWithChildren } from 'react';
|
|
2
2
|
declare const EdgesProvider: FunctionComponent<EdgesProviderProps>;
|
|
3
3
|
export { EdgesProvider };
|
|
4
|
-
export type EdgesProviderProps = PropsWithChildren<
|
|
4
|
+
export type EdgesProviderProps = PropsWithChildren<object>;
|
|
@@ -1,5 +1,5 @@
|
|
|
1
1
|
import { type GraphContextProps } from '../Contexts/GraphContext';
|
|
2
2
|
import { type FunctionComponent, type PropsWithChildren } from 'react';
|
|
3
3
|
declare const GraphProvider: FunctionComponent<GraphProviderProps>;
|
|
4
|
-
export type GraphProviderProps = PropsWithChildren<Omit<GraphContextProps, 'edgeSubscriber' | '
|
|
4
|
+
export type GraphProviderProps = PropsWithChildren<Omit<GraphContextProps, 'edgeSubscriber' | 'id' | 'nodePositions'> & Required<Pick<GraphContextProps, 'id'>>>;
|
|
5
5
|
export { GraphProvider };
|
package/dist/index.d.ts
CHANGED
package/dist/index.js
CHANGED
|
@@ -22,6 +22,5 @@ var defaultSettings_1 = require("./defaultSettings");
|
|
|
22
22
|
Object.defineProperty(exports, "defaultSettings", { enumerable: true, get: function () { return __importDefault(defaultSettings_1).default; } });
|
|
23
23
|
__exportStar(require("./Hooks"), exports);
|
|
24
24
|
__exportStar(require("./Providers"), exports);
|
|
25
|
-
__exportStar(require("./types"), exports);
|
|
26
25
|
var generateOrigins_1 = require("./utils/Path/generateOrigins");
|
|
27
26
|
Object.defineProperty(exports, "generateOrigins", { enumerable: true, get: function () { return __importDefault(generateOrigins_1).default; } });
|
package/dist/types.d.ts
CHANGED
|
@@ -1,12 +1,6 @@
|
|
|
1
1
|
import { type ProvidersProps } from './Providers';
|
|
2
2
|
import { type PropsWithChildren, type ReactElement, type ReactNode } from 'react';
|
|
3
|
-
export type
|
|
4
|
-
number,
|
|
5
|
-
number
|
|
6
|
-
];
|
|
7
|
-
export type Line = 'curve' | 'direct' | 'step';
|
|
8
|
-
export type Shape = 'oval' | 'rectangle';
|
|
9
|
-
export type EdgeNodeProps = {
|
|
3
|
+
export type Dimensions = {
|
|
10
4
|
height: number;
|
|
11
5
|
id: number | string;
|
|
12
6
|
shape: Shape;
|
|
@@ -14,18 +8,7 @@ export type EdgeNodeProps = {
|
|
|
14
8
|
x: number;
|
|
15
9
|
y: number;
|
|
16
10
|
};
|
|
17
|
-
export type
|
|
18
|
-
bottom: number;
|
|
19
|
-
height: number;
|
|
20
|
-
left: number;
|
|
21
|
-
right: number;
|
|
22
|
-
top: number;
|
|
23
|
-
width: number;
|
|
24
|
-
};
|
|
25
|
-
export type NodesDimensions = {
|
|
26
|
-
[key: string]: Dimensions;
|
|
27
|
-
};
|
|
28
|
-
export type Dimensions = {
|
|
11
|
+
export type EdgeNodeProps = {
|
|
29
12
|
height: number;
|
|
30
13
|
id: number | string;
|
|
31
14
|
shape: Shape;
|
|
@@ -33,7 +16,6 @@ export type Dimensions = {
|
|
|
33
16
|
x: number;
|
|
34
17
|
y: number;
|
|
35
18
|
};
|
|
36
|
-
export type GridContextProps = GridType;
|
|
37
19
|
export type EdgeProps = PropsWithChildren<{
|
|
38
20
|
dash?: boolean;
|
|
39
21
|
id: number | string;
|
|
@@ -52,31 +34,49 @@ export type EdgesProps = PropsWithChildren<{
|
|
|
52
34
|
y: number;
|
|
53
35
|
};
|
|
54
36
|
}>;
|
|
55
|
-
export type
|
|
56
|
-
|
|
57
|
-
edgeId: string | number;
|
|
58
|
-
line?: Line;
|
|
59
|
-
markerEnd?: string;
|
|
60
|
-
markerStart?: string;
|
|
61
|
-
source?: EdgeNodeProps;
|
|
62
|
-
target?: EdgeNodeProps;
|
|
37
|
+
export type GraphProps = ProvidersProps & {
|
|
38
|
+
showGrid?: boolean;
|
|
63
39
|
};
|
|
40
|
+
export type GridContextProps = GridType;
|
|
41
|
+
export type GridProps = PropsWithChildren<{
|
|
42
|
+
scale?: number;
|
|
43
|
+
xOffset?: number;
|
|
44
|
+
yOffset?: number;
|
|
45
|
+
}>;
|
|
46
|
+
export type GridType = [
|
|
47
|
+
number,
|
|
48
|
+
number
|
|
49
|
+
];
|
|
50
|
+
export type Line = 'curve' | 'direct' | 'step';
|
|
64
51
|
export type NodeProps = PropsWithChildren<{
|
|
65
52
|
height?: number;
|
|
66
53
|
id: number | string;
|
|
67
|
-
ref?:
|
|
54
|
+
ref?: ((instance: HTMLDivElement | null) => void) | null | React.MutableRefObject<HTMLDivElement | null>;
|
|
68
55
|
shape?: Shape;
|
|
69
56
|
track?: boolean;
|
|
70
57
|
width?: number;
|
|
71
58
|
x?: number;
|
|
72
59
|
y?: number;
|
|
73
60
|
}>;
|
|
74
|
-
export type
|
|
75
|
-
|
|
76
|
-
|
|
77
|
-
|
|
78
|
-
|
|
79
|
-
|
|
80
|
-
|
|
81
|
-
|
|
61
|
+
export type NodesDimensions = {
|
|
62
|
+
[key: string]: Dimensions;
|
|
63
|
+
};
|
|
64
|
+
export type NodesProps = PropsWithChildren<object>;
|
|
65
|
+
export type PathProps = {
|
|
66
|
+
center?: boolean;
|
|
67
|
+
edgeId: number | string;
|
|
68
|
+
line?: Line;
|
|
69
|
+
markerEnd?: string;
|
|
70
|
+
markerStart?: string;
|
|
71
|
+
source?: EdgeNodeProps;
|
|
72
|
+
target?: EdgeNodeProps;
|
|
73
|
+
};
|
|
74
|
+
export type Shape = 'oval' | 'rectangle';
|
|
75
|
+
export type Size = {
|
|
76
|
+
bottom: number;
|
|
77
|
+
height: number;
|
|
78
|
+
left: number;
|
|
79
|
+
right: number;
|
|
80
|
+
top: number;
|
|
81
|
+
width: number;
|
|
82
82
|
};
|
|
@@ -1,15 +1,15 @@
|
|
|
1
1
|
import { type EdgeNodeProps } from '../types';
|
|
2
2
|
declare class EdgeSubscriber {
|
|
3
3
|
private frequency;
|
|
4
|
-
constructor(frequency?: number);
|
|
5
|
-
getFrequency: () => number;
|
|
6
|
-
setFrequency: (frequency: number) => number;
|
|
7
4
|
private nodes;
|
|
8
5
|
private propsCache;
|
|
6
|
+
private throttleUpdates;
|
|
7
|
+
constructor(frequency?: number);
|
|
8
|
+
getFrequency: () => number;
|
|
9
9
|
register: <T>(edgeId: number | string, nodeId: number | string, updateFn: (update: T) => void) => EdgeNodeProps;
|
|
10
|
+
setFrequency: (frequency: number) => number;
|
|
10
11
|
unregister: (edgeId: number | string, nodeId: number | string) => void;
|
|
11
|
-
private readonly updateEdges;
|
|
12
|
-
private throttleUpdates;
|
|
13
12
|
update: (props: EdgeNodeProps) => void;
|
|
13
|
+
private readonly updateEdges;
|
|
14
14
|
}
|
|
15
15
|
export default EdgeSubscriber;
|
|
@@ -8,15 +8,12 @@ const lodash_throttle_1 = __importDefault(require("lodash.throttle"));
|
|
|
8
8
|
const FREQUENCY = defaultSettings_1.default.edgeFrequency;
|
|
9
9
|
class EdgeSubscriber {
|
|
10
10
|
constructor(frequency = FREQUENCY) {
|
|
11
|
+
this.nodes = {};
|
|
12
|
+
this.propsCache = {};
|
|
13
|
+
this.throttleUpdates = {};
|
|
11
14
|
this.getFrequency = () => {
|
|
12
15
|
return this.frequency;
|
|
13
16
|
};
|
|
14
|
-
this.setFrequency = (frequency) => {
|
|
15
|
-
this.frequency = frequency;
|
|
16
|
-
return this.frequency;
|
|
17
|
-
};
|
|
18
|
-
this.nodes = {};
|
|
19
|
-
this.propsCache = {};
|
|
20
17
|
this.register = (edgeId, nodeId, updateFn) => {
|
|
21
18
|
if (!this.nodes[nodeId]) {
|
|
22
19
|
this.nodes[nodeId] = {};
|
|
@@ -24,19 +21,14 @@ class EdgeSubscriber {
|
|
|
24
21
|
this.nodes[nodeId][edgeId] = updateFn;
|
|
25
22
|
return this.propsCache[nodeId];
|
|
26
23
|
};
|
|
24
|
+
this.setFrequency = (frequency) => {
|
|
25
|
+
this.frequency = frequency;
|
|
26
|
+
return this.frequency;
|
|
27
|
+
};
|
|
27
28
|
this.unregister = (edgeId, nodeId) => {
|
|
28
29
|
delete this.nodes[nodeId][edgeId];
|
|
29
30
|
delete this.throttleUpdates[nodeId];
|
|
30
31
|
};
|
|
31
|
-
this.updateEdges = (props) => {
|
|
32
|
-
if (this.nodes[props.id]) {
|
|
33
|
-
for (const [_edgeId, update] of Object.entries(this.nodes[props.id])) {
|
|
34
|
-
update(props);
|
|
35
|
-
}
|
|
36
|
-
}
|
|
37
|
-
this.propsCache[props.id] = props;
|
|
38
|
-
};
|
|
39
|
-
this.throttleUpdates = {};
|
|
40
32
|
this.update = (props) => {
|
|
41
33
|
const { id } = props;
|
|
42
34
|
if (!this.throttleUpdates[id]) {
|
|
@@ -46,6 +38,14 @@ class EdgeSubscriber {
|
|
|
46
38
|
}
|
|
47
39
|
this.throttleUpdates[id](props);
|
|
48
40
|
};
|
|
41
|
+
this.updateEdges = (props) => {
|
|
42
|
+
if (this.nodes[props.id]) {
|
|
43
|
+
for (const [_edgeId, update] of Object.entries(this.nodes[props.id])) {
|
|
44
|
+
update(props);
|
|
45
|
+
}
|
|
46
|
+
}
|
|
47
|
+
this.propsCache[props.id] = props;
|
|
48
|
+
};
|
|
49
49
|
this.frequency = frequency;
|
|
50
50
|
}
|
|
51
51
|
}
|
|
@@ -1,31 +1,31 @@
|
|
|
1
1
|
import { type Dimensions, type NodesDimensions, type Size } from '../types';
|
|
2
2
|
declare class NodePositions {
|
|
3
|
+
private bottom;
|
|
4
|
+
private debounceUpdates;
|
|
3
5
|
private frequency;
|
|
4
|
-
private
|
|
5
|
-
getFrequency: () => number;
|
|
6
|
-
setFrequency: (frequency: number) => number;
|
|
6
|
+
private left;
|
|
7
7
|
private nodes;
|
|
8
|
+
private right;
|
|
9
|
+
private subscriptions;
|
|
10
|
+
private top;
|
|
8
11
|
constructor(frequency?: number);
|
|
9
|
-
|
|
10
|
-
|
|
12
|
+
getFrequency: () => number;
|
|
13
|
+
match: (x: number, y: number) => Promise<number | string | undefined>;
|
|
11
14
|
register: (node: Dimensions, { maxWait }?: {
|
|
12
15
|
maxWait?: number | undefined;
|
|
13
16
|
}) => void;
|
|
17
|
+
setFrequency: (frequency: number) => number;
|
|
18
|
+
size: () => Size;
|
|
19
|
+
subscribe: (id: string, callback: (size?: Size, nodes?: NodesDimensions) => void) => void;
|
|
14
20
|
unregister: (id: number | string) => void;
|
|
15
|
-
|
|
16
|
-
|
|
17
|
-
private right;
|
|
18
|
-
private readonly getRight;
|
|
19
|
-
private bottom;
|
|
21
|
+
unsubscribe: (id: string) => void;
|
|
22
|
+
update: (node: Dimensions) => void;
|
|
20
23
|
private readonly getBottom;
|
|
21
|
-
private left;
|
|
22
24
|
private readonly getLeft;
|
|
25
|
+
private readonly getRight;
|
|
23
26
|
private readonly getSize;
|
|
24
|
-
private readonly
|
|
27
|
+
private readonly getTop;
|
|
25
28
|
private readonly notify;
|
|
26
|
-
private
|
|
27
|
-
update: (node: Dimensions) => void;
|
|
28
|
-
match: (x: number, y: number) => Promise<number | string | undefined>;
|
|
29
|
-
size: () => Size;
|
|
29
|
+
private readonly privateUpdate;
|
|
30
30
|
}
|
|
31
31
|
export default NodePositions;
|
|
@@ -18,29 +18,54 @@ const FREQUENCY = defaultSettings_1.default.nodeFrequency;
|
|
|
18
18
|
const MAX_WAIT = defaultSettings_1.default.nodeFrequency;
|
|
19
19
|
class NodePositions {
|
|
20
20
|
constructor(frequency = FREQUENCY) {
|
|
21
|
+
this.debounceUpdates = {};
|
|
22
|
+
this.nodes = {};
|
|
21
23
|
this.subscriptions = {};
|
|
22
24
|
this.getFrequency = () => {
|
|
23
25
|
return this.frequency;
|
|
24
26
|
};
|
|
27
|
+
this.match = (x, y) => __awaiter(this, void 0, void 0, function* () {
|
|
28
|
+
const ids = yield Promise.resolve(Object.keys(this.nodes).find((id) => {
|
|
29
|
+
const node = this.nodes[id];
|
|
30
|
+
return x > node.x &&
|
|
31
|
+
x < node.x + node.width &&
|
|
32
|
+
y > node.y &&
|
|
33
|
+
y < node.y + node.height;
|
|
34
|
+
}));
|
|
35
|
+
return ids ?
|
|
36
|
+
ids :
|
|
37
|
+
undefined;
|
|
38
|
+
});
|
|
39
|
+
this.register = (node, { maxWait = MAX_WAIT } = {}) => {
|
|
40
|
+
this.nodes[node.id] = node;
|
|
41
|
+
this.debounceUpdates[node.id] = (0, lodash_debounce_1.default)(this.privateUpdate, this.frequency, {
|
|
42
|
+
maxWait,
|
|
43
|
+
trailing: true
|
|
44
|
+
});
|
|
45
|
+
};
|
|
25
46
|
this.setFrequency = (frequency) => {
|
|
26
47
|
this.frequency = frequency;
|
|
27
48
|
return this.frequency;
|
|
28
49
|
};
|
|
29
|
-
this.
|
|
50
|
+
this.size = () => {
|
|
51
|
+
var _a, _b, _c, _d, _e, _f, _g, _h, _j, _k, _l, _m, _o, _p, _q, _r, _s, _t, _u, _v, _w, _x, _y, _z;
|
|
52
|
+
return {
|
|
53
|
+
bottom: ((_b = (_a = this.bottom) === null || _a === void 0 ? void 0 : _a.y) !== null && _b !== void 0 ? _b : 0) + ((_d = (_c = this.bottom) === null || _c === void 0 ? void 0 : _c.height) !== null && _d !== void 0 ? _d : 0),
|
|
54
|
+
height: ((_f = (_e = this.bottom) === null || _e === void 0 ? void 0 : _e.y) !== null && _f !== void 0 ? _f : 0) +
|
|
55
|
+
((_h = (_g = this.bottom) === null || _g === void 0 ? void 0 : _g.height) !== null && _h !== void 0 ? _h : 0) -
|
|
56
|
+
((_k = (_j = this.top) === null || _j === void 0 ? void 0 : _j.y) !== null && _k !== void 0 ? _k : 0),
|
|
57
|
+
left: (_m = (_l = this.left) === null || _l === void 0 ? void 0 : _l.x) !== null && _m !== void 0 ? _m : 0,
|
|
58
|
+
right: ((_p = (_o = this.right) === null || _o === void 0 ? void 0 : _o.x) !== null && _p !== void 0 ? _p : 0) + ((_r = (_q = this.right) === null || _q === void 0 ? void 0 : _q.width) !== null && _r !== void 0 ? _r : 0),
|
|
59
|
+
top: (_t = (_s = this.top) === null || _s === void 0 ? void 0 : _s.y) !== null && _t !== void 0 ? _t : 0,
|
|
60
|
+
width: ((_v = (_u = this.right) === null || _u === void 0 ? void 0 : _u.x) !== null && _v !== void 0 ? _v : 0) +
|
|
61
|
+
((_x = (_w = this.right) === null || _w === void 0 ? void 0 : _w.width) !== null && _x !== void 0 ? _x : 0) -
|
|
62
|
+
((_z = (_y = this.left) === null || _y === void 0 ? void 0 : _y.x) !== null && _z !== void 0 ? _z : 0)
|
|
63
|
+
};
|
|
64
|
+
};
|
|
30
65
|
this.subscribe = (id, callback) => {
|
|
31
66
|
this.subscriptions[id] = callback;
|
|
32
67
|
callback(this.size(), this.nodes);
|
|
33
68
|
};
|
|
34
|
-
this.unsubscribe = (id) => {
|
|
35
|
-
delete this.subscriptions[id];
|
|
36
|
-
};
|
|
37
|
-
this.register = (node, { maxWait = MAX_WAIT } = {}) => {
|
|
38
|
-
this.nodes[node.id] = node;
|
|
39
|
-
this.debounceUpdates[node.id] = (0, lodash_debounce_1.default)(this.privateUpdate, this.frequency, {
|
|
40
|
-
maxWait,
|
|
41
|
-
trailing: true
|
|
42
|
-
});
|
|
43
|
-
};
|
|
44
69
|
this.unregister = (id) => {
|
|
45
70
|
var _a, _b, _c, _d;
|
|
46
71
|
delete this.nodes[id];
|
|
@@ -83,51 +108,11 @@ class NodePositions {
|
|
|
83
108
|
}
|
|
84
109
|
this.notify();
|
|
85
110
|
};
|
|
86
|
-
this.
|
|
87
|
-
|
|
88
|
-
this.top.id === node.id) {
|
|
89
|
-
if (node.y > this.top.y) {
|
|
90
|
-
this.top = node;
|
|
91
|
-
for (const id of Object.keys(this.nodes)) {
|
|
92
|
-
if (this.top && this.nodes[id].y < this.top.y) {
|
|
93
|
-
this.top = this.nodes[id];
|
|
94
|
-
}
|
|
95
|
-
}
|
|
96
|
-
}
|
|
97
|
-
else {
|
|
98
|
-
this.top = node;
|
|
99
|
-
}
|
|
100
|
-
}
|
|
101
|
-
else if (!this.top ||
|
|
102
|
-
node.y < this.top.y) {
|
|
103
|
-
this.top = node;
|
|
104
|
-
}
|
|
111
|
+
this.unsubscribe = (id) => {
|
|
112
|
+
delete this.subscriptions[id];
|
|
105
113
|
};
|
|
106
|
-
this.
|
|
107
|
-
|
|
108
|
-
const rightNodeX = this.right ?
|
|
109
|
-
this.right.x + this.right.width :
|
|
110
|
-
undefined;
|
|
111
|
-
if (this.right &&
|
|
112
|
-
this.right.id === node.id) {
|
|
113
|
-
if (!rightNodeX ||
|
|
114
|
-
nodeX < rightNodeX) {
|
|
115
|
-
this.right = node;
|
|
116
|
-
for (const id of Object.keys(this.nodes)) {
|
|
117
|
-
if (this.nodes[id].x + this.nodes[id].width > this.right.x + this.right.width) {
|
|
118
|
-
this.right = this.nodes[id];
|
|
119
|
-
}
|
|
120
|
-
}
|
|
121
|
-
}
|
|
122
|
-
else {
|
|
123
|
-
this.right = node;
|
|
124
|
-
}
|
|
125
|
-
}
|
|
126
|
-
else if (!this.right ||
|
|
127
|
-
rightNodeX &&
|
|
128
|
-
nodeX > rightNodeX) {
|
|
129
|
-
this.right = node;
|
|
130
|
-
}
|
|
114
|
+
this.update = (node) => {
|
|
115
|
+
this.debounceUpdates[node.id](node);
|
|
131
116
|
};
|
|
132
117
|
this.getBottom = (node) => {
|
|
133
118
|
const nodeY = node.y + node.height;
|
|
@@ -175,50 +160,67 @@ class NodePositions {
|
|
|
175
160
|
this.left = node;
|
|
176
161
|
}
|
|
177
162
|
};
|
|
163
|
+
this.getRight = (node) => {
|
|
164
|
+
const nodeX = node.x + node.width;
|
|
165
|
+
const rightNodeX = this.right ?
|
|
166
|
+
this.right.x + this.right.width :
|
|
167
|
+
undefined;
|
|
168
|
+
if (this.right &&
|
|
169
|
+
this.right.id === node.id) {
|
|
170
|
+
if (!rightNodeX ||
|
|
171
|
+
nodeX < rightNodeX) {
|
|
172
|
+
this.right = node;
|
|
173
|
+
for (const id of Object.keys(this.nodes)) {
|
|
174
|
+
if (this.nodes[id].x + this.nodes[id].width > this.right.x + this.right.width) {
|
|
175
|
+
this.right = this.nodes[id];
|
|
176
|
+
}
|
|
177
|
+
}
|
|
178
|
+
}
|
|
179
|
+
else {
|
|
180
|
+
this.right = node;
|
|
181
|
+
}
|
|
182
|
+
}
|
|
183
|
+
else if (!this.right ||
|
|
184
|
+
rightNodeX &&
|
|
185
|
+
nodeX > rightNodeX) {
|
|
186
|
+
this.right = node;
|
|
187
|
+
}
|
|
188
|
+
};
|
|
178
189
|
this.getSize = (node) => {
|
|
179
190
|
this.getTop(node);
|
|
180
191
|
this.getRight(node);
|
|
181
192
|
this.getBottom(node);
|
|
182
193
|
this.getLeft(node);
|
|
183
194
|
};
|
|
184
|
-
this.
|
|
185
|
-
this.
|
|
186
|
-
|
|
187
|
-
|
|
195
|
+
this.getTop = (node) => {
|
|
196
|
+
if (this.top &&
|
|
197
|
+
this.top.id === node.id) {
|
|
198
|
+
if (node.y > this.top.y) {
|
|
199
|
+
this.top = node;
|
|
200
|
+
for (const id of Object.keys(this.nodes)) {
|
|
201
|
+
if (this.top && this.nodes[id].y < this.top.y) {
|
|
202
|
+
this.top = this.nodes[id];
|
|
203
|
+
}
|
|
204
|
+
}
|
|
205
|
+
}
|
|
206
|
+
else {
|
|
207
|
+
this.top = node;
|
|
208
|
+
}
|
|
209
|
+
}
|
|
210
|
+
else if (!this.top ||
|
|
211
|
+
node.y < this.top.y) {
|
|
212
|
+
this.top = node;
|
|
213
|
+
}
|
|
188
214
|
};
|
|
189
215
|
this.notify = () => {
|
|
190
216
|
for (const [_id, update] of Object.entries(this.subscriptions)) {
|
|
191
217
|
update(this.size(), this.nodes);
|
|
192
218
|
}
|
|
193
219
|
};
|
|
194
|
-
this.
|
|
195
|
-
|
|
196
|
-
this.
|
|
197
|
-
|
|
198
|
-
this.match = (x, y) => __awaiter(this, void 0, void 0, function* () {
|
|
199
|
-
const ids = yield Promise.resolve(Object.keys(this.nodes).find((id) => {
|
|
200
|
-
const node = this.nodes[id];
|
|
201
|
-
return x > node.x &&
|
|
202
|
-
x < node.x + node.width &&
|
|
203
|
-
y > node.y &&
|
|
204
|
-
y < node.y + node.height;
|
|
205
|
-
}));
|
|
206
|
-
return ids ?
|
|
207
|
-
ids :
|
|
208
|
-
undefined;
|
|
209
|
-
});
|
|
210
|
-
this.size = () => {
|
|
211
|
-
var _a, _b, _c, _d, _e, _f, _g, _h, _j, _k, _l, _m, _o, _p, _q, _r, _s, _t, _u, _v, _w, _x, _y, _z;
|
|
212
|
-
return {
|
|
213
|
-
bottom: ((_b = (_a = this.bottom) === null || _a === void 0 ? void 0 : _a.y) !== null && _b !== void 0 ? _b : 0) + ((_d = (_c = this.bottom) === null || _c === void 0 ? void 0 : _c.height) !== null && _d !== void 0 ? _d : 0),
|
|
214
|
-
height: (((_f = (_e = this.bottom) === null || _e === void 0 ? void 0 : _e.y) !== null && _f !== void 0 ? _f : 0) +
|
|
215
|
-
((_h = (_g = this.bottom) === null || _g === void 0 ? void 0 : _g.height) !== null && _h !== void 0 ? _h : 0)) - ((_k = (_j = this.top) === null || _j === void 0 ? void 0 : _j.y) !== null && _k !== void 0 ? _k : 0),
|
|
216
|
-
left: (_m = (_l = this.left) === null || _l === void 0 ? void 0 : _l.x) !== null && _m !== void 0 ? _m : 0,
|
|
217
|
-
right: ((_p = (_o = this.right) === null || _o === void 0 ? void 0 : _o.x) !== null && _p !== void 0 ? _p : 0) + ((_r = (_q = this.right) === null || _q === void 0 ? void 0 : _q.width) !== null && _r !== void 0 ? _r : 0),
|
|
218
|
-
top: (_t = (_s = this.top) === null || _s === void 0 ? void 0 : _s.y) !== null && _t !== void 0 ? _t : 0,
|
|
219
|
-
width: (((_v = (_u = this.right) === null || _u === void 0 ? void 0 : _u.x) !== null && _v !== void 0 ? _v : 0) +
|
|
220
|
-
((_x = (_w = this.right) === null || _w === void 0 ? void 0 : _w.width) !== null && _x !== void 0 ? _x : 0)) - ((_z = (_y = this.left) === null || _y === void 0 ? void 0 : _y.x) !== null && _z !== void 0 ? _z : 0)
|
|
221
|
-
};
|
|
220
|
+
this.privateUpdate = (node) => {
|
|
221
|
+
this.register(node);
|
|
222
|
+
this.getSize(node);
|
|
223
|
+
this.notify();
|
|
222
224
|
};
|
|
223
225
|
this.frequency = frequency;
|
|
224
226
|
}
|
|
@@ -44,7 +44,7 @@ const curveVertical = (rx1, ry1, rx2, ry2, center) => {
|
|
|
44
44
|
exports.curveVertical = curveVertical;
|
|
45
45
|
exports.default = (source, target, center) => {
|
|
46
46
|
const { orientation, source: sourcePoints, target: targetPoints } = (0, generatePoints_1.default)(source, target);
|
|
47
|
-
return Object.assign(Object.assign({},
|
|
47
|
+
return Object.assign(Object.assign({}, orientation === 'horizontal' ?
|
|
48
48
|
(0, exports.curveHorizontal)(sourcePoints.x, sourcePoints.y, targetPoints.x, targetPoints.y, center) :
|
|
49
|
-
(0, exports.curveVertical)(sourcePoints.x, sourcePoints.y, targetPoints.x, targetPoints.y, center))
|
|
49
|
+
(0, exports.curveVertical)(sourcePoints.x, sourcePoints.y, targetPoints.x, targetPoints.y, center)), { source: sourcePoints, target: targetPoints });
|
|
50
50
|
};
|
|
@@ -57,7 +57,7 @@ const stepVertical = (rx1, ry1, rx2, ry2, center) => {
|
|
|
57
57
|
exports.stepVertical = stepVertical;
|
|
58
58
|
exports.default = (source, target, center) => {
|
|
59
59
|
const { orientation, source: sourcePoints, target: targetPoints } = (0, generatePoints_1.default)(source, target);
|
|
60
|
-
return Object.assign(Object.assign({},
|
|
60
|
+
return Object.assign(Object.assign({}, orientation === 'horizontal' ?
|
|
61
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))
|
|
62
|
+
(0, exports.stepVertical)(sourcePoints.x, sourcePoints.y, targetPoints.x, targetPoints.y, center)), { source: sourcePoints, target: targetPoints });
|
|
63
63
|
};
|
|
@@ -1,13 +1,9 @@
|
|
|
1
|
-
export type
|
|
1
|
+
export type Coordinates = {
|
|
2
2
|
center?: {
|
|
3
3
|
x: number;
|
|
4
4
|
y: number;
|
|
5
5
|
};
|
|
6
6
|
path: string;
|
|
7
|
-
};
|
|
8
|
-
export type Orientation = 'horizontal' | 'vertical';
|
|
9
|
-
export type Points = {
|
|
10
|
-
orientation: Orientation;
|
|
11
7
|
source: {
|
|
12
8
|
x: number;
|
|
13
9
|
y: number;
|
|
@@ -17,12 +13,16 @@ export type Points = {
|
|
|
17
13
|
y: number;
|
|
18
14
|
};
|
|
19
15
|
};
|
|
20
|
-
export type
|
|
16
|
+
export type Line = {
|
|
21
17
|
center?: {
|
|
22
18
|
x: number;
|
|
23
19
|
y: number;
|
|
24
20
|
};
|
|
25
21
|
path: string;
|
|
22
|
+
};
|
|
23
|
+
export type Orientation = 'horizontal' | 'vertical';
|
|
24
|
+
export type Points = {
|
|
25
|
+
orientation: Orientation;
|
|
26
26
|
source: {
|
|
27
27
|
x: number;
|
|
28
28
|
y: number;
|
package/package.json
CHANGED
|
@@ -1,92 +1,92 @@
|
|
|
1
1
|
{
|
|
2
|
-
|
|
3
|
-
|
|
4
|
-
|
|
5
|
-
|
|
6
|
-
|
|
7
|
-
|
|
8
|
-
|
|
9
|
-
|
|
10
|
-
|
|
11
|
-
|
|
12
|
-
|
|
13
|
-
|
|
14
|
-
|
|
15
|
-
|
|
16
|
-
|
|
17
|
-
|
|
18
|
-
|
|
19
|
-
|
|
20
|
-
|
|
21
|
-
|
|
22
|
-
|
|
23
|
-
|
|
24
|
-
|
|
25
|
-
|
|
26
|
-
|
|
27
|
-
|
|
28
|
-
|
|
29
|
-
|
|
30
|
-
|
|
31
|
-
|
|
32
|
-
|
|
33
|
-
|
|
34
|
-
|
|
35
|
-
|
|
36
|
-
|
|
37
|
-
|
|
38
|
-
|
|
39
|
-
|
|
40
|
-
|
|
41
|
-
|
|
42
|
-
|
|
43
|
-
|
|
44
|
-
|
|
45
|
-
|
|
46
|
-
|
|
47
|
-
|
|
48
|
-
|
|
49
|
-
|
|
50
|
-
|
|
51
|
-
|
|
52
|
-
|
|
53
|
-
|
|
54
|
-
|
|
55
|
-
|
|
56
|
-
|
|
57
|
-
|
|
58
|
-
|
|
59
|
-
|
|
60
|
-
|
|
61
|
-
|
|
62
|
-
|
|
63
|
-
|
|
64
|
-
|
|
65
|
-
|
|
66
|
-
|
|
67
|
-
|
|
68
|
-
|
|
69
|
-
|
|
70
|
-
|
|
71
|
-
|
|
72
|
-
|
|
73
|
-
|
|
74
|
-
|
|
75
|
-
|
|
76
|
-
|
|
77
|
-
|
|
78
|
-
|
|
79
|
-
|
|
80
|
-
|
|
81
|
-
|
|
82
|
-
|
|
83
|
-
|
|
84
|
-
|
|
85
|
-
|
|
86
|
-
|
|
87
|
-
|
|
88
|
-
|
|
89
|
-
|
|
90
|
-
|
|
91
|
-
|
|
2
|
+
"name": "@lincle/react-shared",
|
|
3
|
+
"title": "lincle react shared",
|
|
4
|
+
"license": "LGPL-3.0-or-later",
|
|
5
|
+
"version": "0.4.0-next.13",
|
|
6
|
+
"private": false,
|
|
7
|
+
"description": "Shared library for @lincle",
|
|
8
|
+
"author": "wallzero @wallzeroblog (http://wallzero.com)",
|
|
9
|
+
"contributors": [
|
|
10
|
+
{
|
|
11
|
+
"name": "Connor Schlesiger",
|
|
12
|
+
"email": "connor@schlesiger.ca",
|
|
13
|
+
"position": "Initial and Lead Developer"
|
|
14
|
+
}
|
|
15
|
+
],
|
|
16
|
+
"main": "dist/index.js",
|
|
17
|
+
"types": "dist/index.d.ts",
|
|
18
|
+
"files": [
|
|
19
|
+
"dist/",
|
|
20
|
+
"COPYING.md",
|
|
21
|
+
"COPYING.LESSER.md"
|
|
22
|
+
],
|
|
23
|
+
"homepage": "https://gitlab.com/digested/lincle/tree/master/packages/react-shared/",
|
|
24
|
+
"repository": {
|
|
25
|
+
"type": "git",
|
|
26
|
+
"url": "https://gitlab.com/digested/lincle.git"
|
|
27
|
+
},
|
|
28
|
+
"bugs": {
|
|
29
|
+
"url": "https://gitlab.com/digested/lincle/issues"
|
|
30
|
+
},
|
|
31
|
+
"scripts": {
|
|
32
|
+
"build": "run-s clean:dist build:prod",
|
|
33
|
+
"build:prod": "tsc -p ./tsconfig.json",
|
|
34
|
+
"build:watch": "run-s clean:dist build:prod build:watch:tsc",
|
|
35
|
+
"build:watch:tsc": "tsc -p ./tsconfig.json --watch --pretty --preserveWatchOutput",
|
|
36
|
+
"----------------------------------------------------------------": "",
|
|
37
|
+
"build:prod:config": "",
|
|
38
|
+
"---------------------------------------------------------------": "",
|
|
39
|
+
"lint": "run-p lint:es",
|
|
40
|
+
"lint:es": "eslint",
|
|
41
|
+
"clean": "run-s clean:dist clean:node_modules",
|
|
42
|
+
"clean:node_modules": "rimraf node_modules yarn.lock package-lock.json",
|
|
43
|
+
"clean:dist": "rimraf dist"
|
|
44
|
+
},
|
|
45
|
+
"devDependencies": {
|
|
46
|
+
"@digest/eslint-config-jest": "^4.13.0",
|
|
47
|
+
"@digest/eslint-config-react": "^4.13.0",
|
|
48
|
+
"@digest/eslint-config-typescript": "^4.13.0",
|
|
49
|
+
"@digest/jest-junit": "^4.13.0",
|
|
50
|
+
"@digest/jest-react": "^4.13.0",
|
|
51
|
+
"@digest/jest-typescript": "^4.13.0",
|
|
52
|
+
"@digest/typescript": "^4.13.0",
|
|
53
|
+
"@types/bezier-js": "^4.1.3",
|
|
54
|
+
"@types/jest": "^29.5.14",
|
|
55
|
+
"@types/lodash.debounce": "^4.0.9",
|
|
56
|
+
"@types/lodash.throttle": "^4.1.9",
|
|
57
|
+
"@types/node": "^22.10.1",
|
|
58
|
+
"@types/react": "^18.3.12",
|
|
59
|
+
"@types/react-dom": "^18.3.1",
|
|
60
|
+
"@types/react-test-renderer": "^18.3.0",
|
|
61
|
+
"cross-env": "^7.0.3",
|
|
62
|
+
"jest-environment-jsdom": "^29.7.0",
|
|
63
|
+
"jest-environment-jsdom-global": "^4.0.0",
|
|
64
|
+
"ncp": "^2.0.0",
|
|
65
|
+
"npm-run-all": "^4.1.5",
|
|
66
|
+
"react": "^18.3.1",
|
|
67
|
+
"react-test-renderer": "^18.3.1",
|
|
68
|
+
"rimraf": "^6.0.1"
|
|
69
|
+
},
|
|
70
|
+
"dependencies": {
|
|
71
|
+
"bezier-js": "^6.1.4",
|
|
72
|
+
"lodash.debounce": "^4.0.8",
|
|
73
|
+
"lodash.throttle": "^4.1.1"
|
|
74
|
+
},
|
|
75
|
+
"peerDependencies": {
|
|
76
|
+
"react": "^18.0.0"
|
|
77
|
+
},
|
|
78
|
+
"keywords": [
|
|
79
|
+
"library",
|
|
80
|
+
"lincle",
|
|
81
|
+
"typescript",
|
|
82
|
+
"react",
|
|
83
|
+
"reactjs",
|
|
84
|
+
"reactive",
|
|
85
|
+
"graph",
|
|
86
|
+
"diagram",
|
|
87
|
+
"dag",
|
|
88
|
+
"acyclical graph",
|
|
89
|
+
"cyclical graph"
|
|
90
|
+
],
|
|
91
|
+
"gitHead": "84d45ca98dd0d6589c697cc7457a897fa777340f"
|
|
92
92
|
}
|