@lincle/react-web-base 0.0.1
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/COPYING.LESSER.md +157 -0
- package/COPYING.md +675 -0
- package/README.md +225 -0
- package/dist/Edge/index.d.ts +4 -0
- package/dist/Edge/index.js +40 -0
- package/dist/Edges/index.d.ts +8 -0
- package/dist/Edges/index.js +19 -0
- package/dist/Graph/index.d.ts +4 -0
- package/dist/Graph/index.js +22 -0
- package/dist/GraphContexts/index.d.ts +4 -0
- package/dist/GraphContexts/index.js +46 -0
- package/dist/Grid/index.d.ts +4 -0
- package/dist/Grid/index.js +40 -0
- package/dist/Node/index.d.ts +4 -0
- package/dist/Node/index.js +125 -0
- package/dist/Nodes/index.d.ts +4 -0
- package/dist/Nodes/index.js +7 -0
- package/dist/Path/generateOrigins.d.ts +5 -0
- package/dist/Path/generateOrigins.js +18 -0
- package/dist/Path/index.d.ts +4 -0
- package/dist/Path/index.js +44 -0
- package/dist/Path/lines/generateCurve.d.ts +17 -0
- package/dist/Path/lines/generateCurve.js +50 -0
- package/dist/Path/lines/generateDirect.d.ts +16 -0
- package/dist/Path/lines/generateDirect.js +32 -0
- package/dist/Path/lines/generatePoints.d.ts +15 -0
- package/dist/Path/lines/generatePoints.js +111 -0
- package/dist/Path/lines/generateStep.d.ts +17 -0
- package/dist/Path/lines/generateStep.js +63 -0
- package/dist/Path/lines/index.d.ts +4 -0
- package/dist/Path/lines/index.js +12 -0
- package/dist/Path/lines/types.d.ts +34 -0
- package/dist/Path/lines/types.js +2 -0
- package/dist/index.d.ts +99 -0
- package/dist/index.js +30 -0
- package/dist/styles.g.css +99 -0
- package/package.json +96 -0
package/README.md
ADDED
|
@@ -0,0 +1,225 @@
|
|
|
1
|
+
<div align="center">
|
|
2
|
+
<h1><code>lincle</code>: A <i>reactive</i> React node and edge generator</h1>
|
|
3
|
+
</div>
|
|
4
|
+
|
|
5
|
+
<div align="center">
|
|
6
|
+
<a href="https://www.npmjs.org/package/@lincle/react-web-base"><img alt="NPM Version" src="https://img.shields.io/npm/v/@lincle/react-web-base.svg" /></a>
|
|
7
|
+
<a href="https://www.gnu.org/licenses/gpl-3.0.en.html"><img alt="License" src="https://img.shields.io/npm/l/@lincle/react-web-base.svg" /></a>
|
|
8
|
+
<a href="https://app.fossa.io/projects/git%2Bhttps%3A%2F%2Fgitlab.com%2Flincle%2Flincle?ref=badge_shield"><img alt="FOSSA Status" src="https://app.fossa.io/api/projects/git%2Bhttps%3A%2F%2Fgitlab.com%2Flincle%2Flincle.svg?type=shield" /></a>
|
|
9
|
+
</div>
|
|
10
|
+
|
|
11
|
+
<div align="center">
|
|
12
|
+
<a href="https://github.com/gajus/canonical"><img alt="Canonical Code Style" src="https://img.shields.io/badge/code%20style-canonical-blue.svg" /></a>
|
|
13
|
+
<a href="https://commitizen.github.io/cz-cli/"><img alt="Commitizen Friendly" src="https://img.shields.io/badge/commitizen-friendly-brightgreen.svg" /></a>
|
|
14
|
+
<a href="https://gitlab.com/hyper-expanse/semantic-release-gitlab#readme"><img alt="Semantic Release" src="https://img.shields.io/badge/%20%20%F0%9F%93%A6%F0%9F%9A%80-semantic--release-e10079.svg" /></a>
|
|
15
|
+
</div>
|
|
16
|
+
|
|
17
|
+
<div align="center">
|
|
18
|
+
<a href="https://gitlab.com/lincle/lincle/commits/master"><img alt="Build Status" src="https://gitlab.com/lincle/lincle/badges/master/pipeline.svg" /></a>
|
|
19
|
+
<a href="https://lincle.gitlab.io/lincle/stats/react-web-base/coverage/lcov-report/"><img alt="Coverage Report" src="https://gitlab.com/lincle/lincle/badges/master/coverage.svg" /></a>
|
|
20
|
+
<a href="https://lincle.gitlab.io/lincle/stats/react-web-base/webpack/"><img alt="Build Analysis" src="https://img.shields.io/badge/webpack-stats-blue.svg" /></a>
|
|
21
|
+
</div>
|
|
22
|
+
|
|
23
|
+
**lincle** generates a reactive graph.
|
|
24
|
+
|
|
25
|
+
Please see the various testing [demos](https://lincle.gitlab.io/lincle/) for examples.
|
|
26
|
+
|
|
27
|
+
If you require an interactive diagram, checkout [`@lincle/interactive`](https://www.npmjs.com/package/react-yad).
|
|
28
|
+
|
|
29
|
+
## Installation & Setup
|
|
30
|
+
|
|
31
|
+
Install `@lincle/react-web-base` and the peer dependencies `react`, `react-dom`:
|
|
32
|
+
|
|
33
|
+
```
|
|
34
|
+
npm install react react-dom @lincle/react-web-base
|
|
35
|
+
```
|
|
36
|
+
|
|
37
|
+
Also include the provided styles file. For example:
|
|
38
|
+
|
|
39
|
+
```
|
|
40
|
+
import '@lincle/react-web-base/dist/main.min.css';
|
|
41
|
+
```
|
|
42
|
+
|
|
43
|
+
## Simple Example
|
|
44
|
+
|
|
45
|
+
The following example will generate this diagram:
|
|
46
|
+
|
|
47
|
+
<div align="center">
|
|
48
|
+
<a href="https://gitlab.com/lincle/lincle/-/raw/master/static/simple.png">
|
|
49
|
+
<img src="https://gitlab.com/lincle/lincle/-/raw/master/static/simple.png" alt="resulting screenshot of simple example" style="max-width:100%;">
|
|
50
|
+
</a>
|
|
51
|
+
</div>
|
|
52
|
+
|
|
53
|
+
> [<h3>CodeSandbox</h4>](https://codesandbox.io/s/react-ag-simple-example-8p38n)
|
|
54
|
+
|
|
55
|
+
```css
|
|
56
|
+
/* styles.css */
|
|
57
|
+
|
|
58
|
+
.App {
|
|
59
|
+
position: absolute;
|
|
60
|
+
overflow: hidden;
|
|
61
|
+
width: 100%;
|
|
62
|
+
height: 100%;
|
|
63
|
+
}
|
|
64
|
+
|
|
65
|
+
.node {
|
|
66
|
+
display: flex;
|
|
67
|
+
align-items: center;
|
|
68
|
+
justify-content: center;
|
|
69
|
+
width: calc(100% - 2px);
|
|
70
|
+
height: calc(100% - 2px);
|
|
71
|
+
border: 1px solid black;
|
|
72
|
+
background-color: white;
|
|
73
|
+
box-shadow: 0 3px 6px rgba(0, 0, 0, 0.16), 0 3px 6px rgba(0, 0, 0, 0.23);
|
|
74
|
+
}
|
|
75
|
+
|
|
76
|
+
.node-oval {
|
|
77
|
+
border-radius: 50%;
|
|
78
|
+
}
|
|
79
|
+
```
|
|
80
|
+
|
|
81
|
+
```ts
|
|
82
|
+
import React, { FunctionComponent, ReactElement } from "react";
|
|
83
|
+
import { Edge, Edges, Graph, Node, Nodes } from "@lincle/react-web-base";
|
|
84
|
+
import "@lincle/react-web-base/dist/main.min.css";
|
|
85
|
+
import "./styles.css";
|
|
86
|
+
|
|
87
|
+
const App: FunctionComponent = (): ReactElement => {
|
|
88
|
+
return (
|
|
89
|
+
<div className="App">
|
|
90
|
+
<Graph id="SimpleDiagram" key="1" nodeHeight={50} nodeWidth={50}>
|
|
91
|
+
<Nodes>
|
|
92
|
+
<Node id={1} key={1} x={50} y={50}>
|
|
93
|
+
<div className="node">Node 1</div>
|
|
94
|
+
</Node>
|
|
95
|
+
<Node
|
|
96
|
+
height={100}
|
|
97
|
+
id={2}
|
|
98
|
+
key={2}
|
|
99
|
+
shape="oval"
|
|
100
|
+
width={200}
|
|
101
|
+
x={100}
|
|
102
|
+
y={150}
|
|
103
|
+
>
|
|
104
|
+
<div className="node node-oval">Node 2</div>
|
|
105
|
+
</Node>
|
|
106
|
+
<Node id={3} key={3} shape="oval" x={150} y={350}>
|
|
107
|
+
<div className="node node-oval">Node 3</div>
|
|
108
|
+
</Node>
|
|
109
|
+
</Nodes>
|
|
110
|
+
<Edges>
|
|
111
|
+
<Edge id={1} key={1} sourceId={1} targetId={2}>
|
|
112
|
+
<circle fill="white" r="3" stroke="black" strokeWidth={2}>
|
|
113
|
+
<title>Bridge</title>
|
|
114
|
+
</circle>
|
|
115
|
+
</Edge>
|
|
116
|
+
<Edge id={2} key={2} line="direct" sourceId={2} targetId={3} />
|
|
117
|
+
</Edges>
|
|
118
|
+
</Graph>
|
|
119
|
+
</div>
|
|
120
|
+
);
|
|
121
|
+
};
|
|
122
|
+
|
|
123
|
+
export default App;
|
|
124
|
+
|
|
125
|
+
```
|
|
126
|
+
|
|
127
|
+
## Component API's
|
|
128
|
+
|
|
129
|
+
**\*** *bolded parameters are required*
|
|
130
|
+
|
|
131
|
+
### `<Graph>`
|
|
132
|
+
|
|
133
|
+
| Parameters | Type | Default | Description |
|
|
134
|
+
|---|---|---|---|
|
|
135
|
+
| **`id`** | `string \| number` | | The unique ID of the graph |
|
|
136
|
+
| edgeFrequency | `number` | `16` | Frequency of edge updates during node movements (in ms) |
|
|
137
|
+
| grid | `false \| [number, number] ` | `[16, 16]` | The background grid space; false to disable. |
|
|
138
|
+
| line | `"curve" \| "direct" \| "step"` | `"step"` | The default curve for the edges |
|
|
139
|
+
| nodeFrequency | `number` | `500` | Frequency of node movements reported (in ms, aside from edges) |
|
|
140
|
+
| nodeHeight | `number` | `50` | The default height for nodes (in px) |
|
|
141
|
+
| nodeWidth | `number` | `50` | The default width for nodes (in px) |
|
|
142
|
+
| shape | `"oval" \| "rectangle"` | `"rectangle"` | The default shape for nodes |
|
|
143
|
+
|
|
144
|
+
### `<Nodes>`
|
|
145
|
+
|
|
146
|
+
| Parameters | Type | Default | Description |
|
|
147
|
+
|---|---|---|---|
|
|
148
|
+
| *none* |
|
|
149
|
+
|
|
150
|
+
### `<Node>`
|
|
151
|
+
|
|
152
|
+
| Parameters | Type | Default | Description |
|
|
153
|
+
|---|---|---|---|
|
|
154
|
+
| **`id`** | `string \| number` | | The unique ID of the node |
|
|
155
|
+
| x | `number` | `0` | The initial `x` coordinate of the node |
|
|
156
|
+
| y | `number` | `0` | The initial `y` coordinate of the node |
|
|
157
|
+
| <td colspan="3">*The following override the defaults provided by `<Graph />`* |
|
|
158
|
+
| height | `number` | `50` | The node height |
|
|
159
|
+
| shape | `'oval' \| 'rectangle'` | `rectangle` | The shape of the node |
|
|
160
|
+
| width | `number` | `50` | The node width |
|
|
161
|
+
|
|
162
|
+
### `<Edges>`
|
|
163
|
+
|
|
164
|
+
| Parameters | Type | Default | Description |
|
|
165
|
+
|---|---|---|---|
|
|
166
|
+
| dash | `boolean \| undefined` | `undefined` | Whether dash should be enabled. Defaults to hover only. |
|
|
167
|
+
|
|
168
|
+
### `<Edge>`
|
|
169
|
+
|
|
170
|
+
| Parameters | Type | Default | Description |
|
|
171
|
+
|---|---|---|---|
|
|
172
|
+
| **`id`** | `string \| number` | | The unique ID for the edge |
|
|
173
|
+
| dash | `boolean \| undefined` | `undefined` | Whether dash should be enabled. Defaults to hover only. |
|
|
174
|
+
| line | `'curve' \| 'direct' \| 'step'` | `direct` | The line shape (overrides default) and not applicable if custom path generator is used. |
|
|
175
|
+
| markerEnd | `string` | | Passed to the default path generated `<path>` SVG |
|
|
176
|
+
| markerStart | `string` | | Passed to the default path generated `<path>` SVG |
|
|
177
|
+
| path | *path `function` - see below* | | Use to generate a custom path component. |
|
|
178
|
+
| **`sourceId`** | `string \| number` | | ID for the source node |
|
|
179
|
+
| **`targetId`** | `string \| number` | | ID for the target node |
|
|
180
|
+
|
|
181
|
+
> ***Note**: The child of `<Edge />` is intended to be an element at the center of the path. The child will be inside an `<SVG />` element and should be an SVG type or wrapped in a `<foreignObject />` element. See examples for details.*
|
|
182
|
+
|
|
183
|
+
### Path `function`
|
|
184
|
+
|
|
185
|
+
Instead of using the `@lincle/react-web-base` provided edges (`curve`, `line`, & `step`), you may opt to generate your own path component:
|
|
186
|
+
|
|
187
|
+
```ts
|
|
188
|
+
(
|
|
189
|
+
source: {
|
|
190
|
+
height: number,
|
|
191
|
+
id: string | number,
|
|
192
|
+
shape: 'oval' | 'rectangle',
|
|
193
|
+
width: number,
|
|
194
|
+
x: number,
|
|
195
|
+
y: number
|
|
196
|
+
},
|
|
197
|
+
target: {
|
|
198
|
+
height: number,
|
|
199
|
+
id: string | number,
|
|
200
|
+
shape: 'oval' | 'rectangle',
|
|
201
|
+
width: number,
|
|
202
|
+
x: number,
|
|
203
|
+
y: number
|
|
204
|
+
},
|
|
205
|
+
children?: ReactNode
|
|
206
|
+
) => Component<SVG type>
|
|
207
|
+
```
|
|
208
|
+
|
|
209
|
+
### `<Grid>`
|
|
210
|
+
|
|
211
|
+
| Parameters | Type | Default | Description |
|
|
212
|
+
|---|---|---|---|
|
|
213
|
+
| children | `SVG` | `<circle>` | The repeated SVG |
|
|
214
|
+
| scale | `number` | `1` | Scales the grid |
|
|
215
|
+
| xOffset | `number` | `0` | Translates the grid left/right |
|
|
216
|
+
| yOffset | `number` | `0` | Translates the grid up/down |
|
|
217
|
+
|
|
218
|
+
### Contexts
|
|
219
|
+
|
|
220
|
+
`<Context>`'s can be taken advantage of to extend the functionality of `@lincle/react-web-base`:
|
|
221
|
+
|
|
222
|
+
| Context | Provides | Description |
|
|
223
|
+
|---|---|---|
|
|
224
|
+
| `<GraphContext>` | `{diagramId: ReactText, nodePosition: NodePositions, edgeSubscriber: EdgeSubscriber, defaultSettings: DefaultSettings}` | Provides the current diagramId and default settings along with classes to subscribe to `<Node>` and `<Edge>` events. |
|
|
225
|
+
| `<GridContext>` | `[number, number]` | Provides the current grid dimensions. |
|
|
@@ -0,0 +1,40 @@
|
|
|
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
|
+
const jsx_runtime_1 = require("react/jsx-runtime");
|
|
7
|
+
const Path_1 = __importDefault(require("../Path"));
|
|
8
|
+
const react_shared_1 = require("@lincle/react-shared");
|
|
9
|
+
const react_1 = require("react");
|
|
10
|
+
const Edge = ({ children, className = '', dash, id: edgeId, line: givenLine, markerEnd, markerStart, path, sourceId, targetId }) => {
|
|
11
|
+
var _a, _b, _c, _d;
|
|
12
|
+
const diagramId = (_a = (0, react_1.useContext)(react_shared_1.GraphContext)) === null || _a === void 0 ? void 0 : _a.diagramId;
|
|
13
|
+
const edgeSubscriber = (_b = (0, react_1.useContext)(react_shared_1.GraphContext)) === null || _b === void 0 ? void 0 : _b.edgeSubscriber;
|
|
14
|
+
const defaultLine = (_d = (_c = (0, react_1.useContext)(react_shared_1.GraphContext)) === null || _c === void 0 ? void 0 : _c.defaultSettings) === null || _d === void 0 ? void 0 : _d.line;
|
|
15
|
+
const line = givenLine !== null && givenLine !== void 0 ? givenLine : defaultLine;
|
|
16
|
+
const [source, setSource] = (0, react_1.useState)();
|
|
17
|
+
const [target, setTarget] = (0, react_1.useState)();
|
|
18
|
+
(0, react_1.useEffect)(() => {
|
|
19
|
+
setSource(edgeSubscriber === null || edgeSubscriber === void 0 ? void 0 : edgeSubscriber.register(edgeId, sourceId, setSource));
|
|
20
|
+
setTarget(edgeSubscriber === null || edgeSubscriber === void 0 ? void 0 : edgeSubscriber.register(edgeId, targetId, setTarget));
|
|
21
|
+
return () => {
|
|
22
|
+
edgeSubscriber === null || edgeSubscriber === void 0 ? void 0 : edgeSubscriber.unregister(edgeId, sourceId);
|
|
23
|
+
edgeSubscriber === null || edgeSubscriber === void 0 ? void 0 : edgeSubscriber.unregister(edgeId, targetId);
|
|
24
|
+
};
|
|
25
|
+
}, []);
|
|
26
|
+
const pathSource = source ? Object.assign(Object.assign({}, source), { x: source.x, y: source.y }) :
|
|
27
|
+
undefined;
|
|
28
|
+
const pathTarget = target ? Object.assign(Object.assign({}, target), { x: target.x, y: target.y }) :
|
|
29
|
+
undefined;
|
|
30
|
+
if (source &&
|
|
31
|
+
target) {
|
|
32
|
+
if (path) {
|
|
33
|
+
return path(pathSource, pathTarget, children);
|
|
34
|
+
}
|
|
35
|
+
return ((0, jsx_runtime_1.jsx)(Path_1.default, { className: `${className} ${dash === true ? 'lincle-base-edge-dash-on' : dash === false ? 'lincle-base-edge-dash-off' : ''}`, diagramId: diagramId, id: edgeId, line: line, markerEnd: markerEnd, markerStart: markerStart, source: pathSource, target: pathTarget, children: children }));
|
|
36
|
+
}
|
|
37
|
+
return null;
|
|
38
|
+
};
|
|
39
|
+
Edge.displayName = 'LincleEdge';
|
|
40
|
+
exports.default = Edge;
|
|
@@ -0,0 +1,8 @@
|
|
|
1
|
+
import { type EdgesProps as EdgesPartialProps } from '..';
|
|
2
|
+
import { type CSSProperties, type FunctionComponent } from 'react';
|
|
3
|
+
declare const Edges: FunctionComponent<EdgesProps>;
|
|
4
|
+
export default Edges;
|
|
5
|
+
export type EdgesProps = EdgesPartialProps & {
|
|
6
|
+
readonly className?: string;
|
|
7
|
+
readonly style?: CSSProperties;
|
|
8
|
+
};
|
|
@@ -0,0 +1,19 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
const jsx_runtime_1 = require("react/jsx-runtime");
|
|
4
|
+
const react_shared_1 = require("@lincle/react-shared");
|
|
5
|
+
const react_1 = require("react");
|
|
6
|
+
const Edges = ({ className = '', children, dash, style }) => {
|
|
7
|
+
var _a;
|
|
8
|
+
const id = (_a = (0, react_1.useContext)(react_shared_1.GraphContext)) === null || _a === void 0 ? void 0 : _a.diagramId;
|
|
9
|
+
const markerId = (0, react_1.useMemo)(() => {
|
|
10
|
+
return id ?
|
|
11
|
+
`${id}-` :
|
|
12
|
+
'';
|
|
13
|
+
}, [
|
|
14
|
+
id
|
|
15
|
+
]);
|
|
16
|
+
return ((0, jsx_runtime_1.jsxs)("svg", { className: `lincle-base-edges ${className} ${dash === true ? 'lincle-base-edge-dash-all' : dash === false ? 'lincle-base-edge-dash-none' : ''}`, style: style, children: [(0, jsx_runtime_1.jsxs)("defs", { children: [(0, jsx_runtime_1.jsx)("marker", { id: `diagram-${markerId}marker-arrow`, markerHeight: '10', markerUnits: 'strokeWidth', markerWidth: '10', orient: 'auto', refX: '9', refY: '5', children: (0, jsx_runtime_1.jsx)("path", { className: 'lincle-base-edge-marker-arrow', d: 'M 0 0 L 10 5 L 0 10 z' }) }), (0, jsx_runtime_1.jsx)("marker", { id: `diagram-${markerId}marker-circle`, markerHeight: '10', markerUnits: 'strokeWidth', markerWidth: '10', orient: 'auto', refX: '5', refY: '5', children: (0, jsx_runtime_1.jsx)("circle", { className: 'lincle-base-edge-marker-circle', cx: '5', cy: '5', r: '3' }) })] }), children] }));
|
|
17
|
+
};
|
|
18
|
+
Edges.displayName = 'LincleEdges';
|
|
19
|
+
exports.default = Edges;
|
|
@@ -0,0 +1,22 @@
|
|
|
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
|
+
const jsx_runtime_1 = require("react/jsx-runtime");
|
|
7
|
+
const GraphContexts_1 = __importDefault(require("../GraphContexts"));
|
|
8
|
+
const react_shared_1 = require("@lincle/react-shared");
|
|
9
|
+
const react_1 = require("react");
|
|
10
|
+
const Graph = ({ children, edgeFrequency, grid, id, line, nodeFrequency, nodeHeight, nodeWidth, shape }) => {
|
|
11
|
+
var _a;
|
|
12
|
+
const diagramId = (_a = (0, react_1.useContext)(react_shared_1.GraphContext)) === null || _a === void 0 ? void 0 : _a.diagramId;
|
|
13
|
+
if (!diagramId && !id) {
|
|
14
|
+
console.error('No ID provided to @lincle/base Graph!');
|
|
15
|
+
return null;
|
|
16
|
+
}
|
|
17
|
+
return diagramId ?
|
|
18
|
+
((0, jsx_runtime_1.jsx)(jsx_runtime_1.Fragment, { children: children })) :
|
|
19
|
+
((0, jsx_runtime_1.jsx)(GraphContexts_1.default, { edgeFrequency: edgeFrequency, grid: grid, id: id, line: line, nodeFrequency: nodeFrequency, nodeHeight: nodeHeight, nodeWidth: nodeWidth, shape: shape, children: children }));
|
|
20
|
+
};
|
|
21
|
+
Graph.displayName = 'LincleGraph';
|
|
22
|
+
exports.default = Graph;
|
|
@@ -0,0 +1,46 @@
|
|
|
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
|
+
const jsx_runtime_1 = require("react/jsx-runtime");
|
|
7
|
+
const Grid_1 = __importDefault(require("../Grid"));
|
|
8
|
+
const react_shared_1 = require("@lincle/react-shared");
|
|
9
|
+
const react_1 = require("react");
|
|
10
|
+
const GraphContexts = ({ children, edgeFrequency = react_shared_1.defaultSettings.edgeFrequency, grid = react_shared_1.defaultSettings.grid, id, line = react_shared_1.defaultSettings.line, nodeFrequency = react_shared_1.defaultSettings.nodeFrequency, nodeHeight = react_shared_1.defaultSettings.height, nodeWidth = react_shared_1.defaultSettings.width, shape = react_shared_1.defaultSettings.shape }) => {
|
|
11
|
+
const diagramId = (0, react_1.useMemo)(() => {
|
|
12
|
+
return id;
|
|
13
|
+
}, []);
|
|
14
|
+
const permanent = (0, react_1.useMemo)(() => {
|
|
15
|
+
console.log(react_shared_1.EdgeSubscriber);
|
|
16
|
+
return {
|
|
17
|
+
diagramId,
|
|
18
|
+
edgeSubscriber: new react_shared_1.EdgeSubscriber(edgeFrequency),
|
|
19
|
+
nodePositions: new react_shared_1.NodePositions()
|
|
20
|
+
};
|
|
21
|
+
}, []);
|
|
22
|
+
const provides = (0, react_1.useMemo)(() => {
|
|
23
|
+
return Object.assign(Object.assign({}, permanent), { defaultSettings: {
|
|
24
|
+
edgeFrequency,
|
|
25
|
+
height: nodeHeight,
|
|
26
|
+
line,
|
|
27
|
+
nodeFrequency,
|
|
28
|
+
shape,
|
|
29
|
+
width: nodeWidth
|
|
30
|
+
} });
|
|
31
|
+
}, [
|
|
32
|
+
permanent,
|
|
33
|
+
edgeFrequency,
|
|
34
|
+
nodeHeight,
|
|
35
|
+
line,
|
|
36
|
+
nodeFrequency,
|
|
37
|
+
shape,
|
|
38
|
+
nodeWidth
|
|
39
|
+
]);
|
|
40
|
+
const hiddenGrid = grid === false ?
|
|
41
|
+
children :
|
|
42
|
+
((0, jsx_runtime_1.jsxs)(react_shared_1.GridContext.Provider, { value: grid, children: [(0, jsx_runtime_1.jsx)(Grid_1.default, {}), children] }));
|
|
43
|
+
return ((0, jsx_runtime_1.jsx)(react_shared_1.GraphContext.Provider, { value: provides, children: hiddenGrid }));
|
|
44
|
+
};
|
|
45
|
+
GraphContexts.displayName = 'LincleGraphContexts';
|
|
46
|
+
exports.default = GraphContexts;
|
|
@@ -0,0 +1,40 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
const jsx_runtime_1 = require("react/jsx-runtime");
|
|
4
|
+
const react_shared_1 = require("@lincle/react-shared");
|
|
5
|
+
const react_1 = require("react");
|
|
6
|
+
const SIZE = 0.4;
|
|
7
|
+
const Circle = ((0, jsx_runtime_1.jsx)("circle", { cx: SIZE, cy: SIZE, fill: 'black', r: SIZE }));
|
|
8
|
+
const Grid = ({ children, scale = 1, xOffset: givenXOffset = 0, yOffset: givenYOffset = 0 }) => {
|
|
9
|
+
var _a;
|
|
10
|
+
const diagramId = (_a = (0, react_1.useContext)(react_shared_1.GraphContext)) === null || _a === void 0 ? void 0 : _a.diagramId;
|
|
11
|
+
const [givenGridX, givenGridY] = (0, react_1.useContext)(react_shared_1.GridContext) || react_shared_1.defaultSettings.grid;
|
|
12
|
+
const id = `lincle-grid-${diagramId}`;
|
|
13
|
+
const gridX = (0, react_1.useMemo)(() => {
|
|
14
|
+
return givenGridX * scale;
|
|
15
|
+
}, [
|
|
16
|
+
givenGridX,
|
|
17
|
+
scale
|
|
18
|
+
]);
|
|
19
|
+
const gridY = (0, react_1.useMemo)(() => {
|
|
20
|
+
return givenGridY * scale;
|
|
21
|
+
}, [
|
|
22
|
+
givenGridY,
|
|
23
|
+
scale
|
|
24
|
+
]);
|
|
25
|
+
const xOffset = (0, react_1.useMemo)(() => {
|
|
26
|
+
return givenXOffset % gridX;
|
|
27
|
+
}, [
|
|
28
|
+
gridX,
|
|
29
|
+
givenXOffset
|
|
30
|
+
]);
|
|
31
|
+
const yOffset = (0, react_1.useMemo)(() => {
|
|
32
|
+
return givenYOffset % gridY;
|
|
33
|
+
}, [
|
|
34
|
+
gridY,
|
|
35
|
+
givenYOffset
|
|
36
|
+
]);
|
|
37
|
+
return ((0, jsx_runtime_1.jsxs)("svg", { className: 'lincle-base-grid', children: [(0, jsx_runtime_1.jsx)("pattern", { height: gridY, id: id, patternUnits: 'userSpaceOnUse', width: gridX, x: xOffset, y: yOffset, children: children !== null && children !== void 0 ? children : Circle }), (0, jsx_runtime_1.jsx)("rect", { fill: `url(#${id})`, height: '100%', width: '100%', x: '0', y: '0' })] }));
|
|
38
|
+
};
|
|
39
|
+
Grid.displayName = 'LincleGrid';
|
|
40
|
+
exports.default = Grid;
|
|
@@ -0,0 +1,125 @@
|
|
|
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
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
14
|
+
const jsx_runtime_1 = require("react/jsx-runtime");
|
|
15
|
+
const react_shared_1 = require("@lincle/react-shared");
|
|
16
|
+
const react_1 = require("react");
|
|
17
|
+
const Node = (_a, ref) => {
|
|
18
|
+
var _b, _c, _d, _e, _f, _g;
|
|
19
|
+
var { className = '', children, height: givenHeight, id: nodeId, shape: givenShape, style, width: givenWidth, x: givenX = 0, y: givenY = 0 } = _a, additionalProperties = __rest(_a, ["className", "children", "height", "id", "shape", "style", "width", "x", "y"]);
|
|
20
|
+
const graphContext = (0, react_1.useContext)(react_shared_1.GraphContext);
|
|
21
|
+
const defaultHeight = (_b = graphContext === null || graphContext === void 0 ? void 0 : graphContext.defaultSettings) === null || _b === void 0 ? void 0 : _b.width;
|
|
22
|
+
const defaultShape = (_c = graphContext === null || graphContext === void 0 ? void 0 : graphContext.defaultSettings) === null || _c === void 0 ? void 0 : _c.shape;
|
|
23
|
+
const defaultWidth = (_d = graphContext === null || graphContext === void 0 ? void 0 : graphContext.defaultSettings) === null || _d === void 0 ? void 0 : _d.width;
|
|
24
|
+
const edgeSubscriber = graphContext === null || graphContext === void 0 ? void 0 : graphContext.edgeSubscriber;
|
|
25
|
+
const nodePositions = graphContext === null || graphContext === void 0 ? void 0 : graphContext.nodePositions;
|
|
26
|
+
const height = (_e = givenHeight !== null && givenHeight !== void 0 ? givenHeight : defaultHeight) !== null && _e !== void 0 ? _e : 0;
|
|
27
|
+
const shape = (_f = givenShape !== null && givenShape !== void 0 ? givenShape : defaultShape) !== null && _f !== void 0 ? _f : 'oval';
|
|
28
|
+
const width = (_g = givenWidth !== null && givenWidth !== void 0 ? givenWidth : defaultWidth) !== null && _g !== void 0 ? _g : 0;
|
|
29
|
+
const { x, y } = (0, react_1.useMemo)(() => {
|
|
30
|
+
var _a;
|
|
31
|
+
if (!(givenX || givenY)) {
|
|
32
|
+
const getNumber = /(-?\d+(\.\d+)?)/ug;
|
|
33
|
+
const [translateX, translateY] = (style === null || style === void 0 ? void 0 : style.transform) ?
|
|
34
|
+
(_a = style.transform.match(getNumber)) !== null && _a !== void 0 ? _a : [
|
|
35
|
+
undefined,
|
|
36
|
+
undefined
|
|
37
|
+
] :
|
|
38
|
+
[
|
|
39
|
+
undefined,
|
|
40
|
+
undefined
|
|
41
|
+
];
|
|
42
|
+
const left = (style === null || style === void 0 ? void 0 : style.left) ?
|
|
43
|
+
style.left :
|
|
44
|
+
undefined;
|
|
45
|
+
const top = (style === null || style === void 0 ? void 0 : style.top) ?
|
|
46
|
+
style.top :
|
|
47
|
+
undefined;
|
|
48
|
+
return {
|
|
49
|
+
x: Number(translateX) || Number(left) || 0,
|
|
50
|
+
y: Number(translateY) || Number(top) || 0
|
|
51
|
+
};
|
|
52
|
+
}
|
|
53
|
+
return {
|
|
54
|
+
x: givenX,
|
|
55
|
+
y: givenY
|
|
56
|
+
};
|
|
57
|
+
}, [
|
|
58
|
+
givenX,
|
|
59
|
+
givenY,
|
|
60
|
+
style
|
|
61
|
+
]);
|
|
62
|
+
(0, react_1.useEffect)(() => {
|
|
63
|
+
nodePositions === null || nodePositions === void 0 ? void 0 : nodePositions.register({
|
|
64
|
+
height,
|
|
65
|
+
id: nodeId,
|
|
66
|
+
shape,
|
|
67
|
+
width,
|
|
68
|
+
x,
|
|
69
|
+
y
|
|
70
|
+
});
|
|
71
|
+
return () => {
|
|
72
|
+
nodePositions === null || nodePositions === void 0 ? void 0 : nodePositions.unregister(nodeId);
|
|
73
|
+
};
|
|
74
|
+
}, []);
|
|
75
|
+
(0, react_1.useEffect)(() => {
|
|
76
|
+
nodePositions === null || nodePositions === void 0 ? void 0 : nodePositions.update({
|
|
77
|
+
height,
|
|
78
|
+
id: nodeId,
|
|
79
|
+
shape,
|
|
80
|
+
width,
|
|
81
|
+
x,
|
|
82
|
+
y
|
|
83
|
+
});
|
|
84
|
+
}, [
|
|
85
|
+
height,
|
|
86
|
+
nodeId,
|
|
87
|
+
nodePositions,
|
|
88
|
+
shape,
|
|
89
|
+
width,
|
|
90
|
+
x,
|
|
91
|
+
y
|
|
92
|
+
]);
|
|
93
|
+
(0, react_1.useEffect)(() => {
|
|
94
|
+
edgeSubscriber === null || edgeSubscriber === void 0 ? void 0 : edgeSubscriber.update({
|
|
95
|
+
height,
|
|
96
|
+
id: nodeId,
|
|
97
|
+
shape,
|
|
98
|
+
width,
|
|
99
|
+
x,
|
|
100
|
+
y
|
|
101
|
+
});
|
|
102
|
+
}, [
|
|
103
|
+
edgeSubscriber,
|
|
104
|
+
nodeId,
|
|
105
|
+
height,
|
|
106
|
+
width,
|
|
107
|
+
x,
|
|
108
|
+
y,
|
|
109
|
+
shape
|
|
110
|
+
]);
|
|
111
|
+
const adjustedStyle = (0, react_1.useMemo)(() => {
|
|
112
|
+
return Object.assign(Object.assign({}, style), { height, transform: (style === null || style === void 0 ? void 0 : style.transform) ?
|
|
113
|
+
style.transform :
|
|
114
|
+
`translate(${x}px, ${y}px) translateZ(0)`, width });
|
|
115
|
+
}, [
|
|
116
|
+
style,
|
|
117
|
+
height,
|
|
118
|
+
width,
|
|
119
|
+
x,
|
|
120
|
+
y
|
|
121
|
+
]);
|
|
122
|
+
return ((0, jsx_runtime_1.jsx)("div", Object.assign({ className: `${className} lincle-base-node`, "data-testid": `node-${nodeId}`, ref: ref, role: 'none', style: adjustedStyle }, additionalProperties, { children: children })));
|
|
123
|
+
};
|
|
124
|
+
Node.displayName = 'LincleNode';
|
|
125
|
+
exports.default = (0, react_1.forwardRef)(Node);
|
|
@@ -0,0 +1,5 @@
|
|
|
1
|
+
import { type Line } from '..';
|
|
2
|
+
import { type Coordinates } from './lines';
|
|
3
|
+
import { type EdgeNodeProps } from '@lincle/react-shared';
|
|
4
|
+
declare const generateOrigins: (target: EdgeNodeProps, source: EdgeNodeProps, line: Line, center?: boolean) => Coordinates;
|
|
5
|
+
export default generateOrigins;
|
|
@@ -0,0 +1,18 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
const lines_1 = require("./lines");
|
|
4
|
+
const generateOrigins = (target, source, line, center) => {
|
|
5
|
+
switch (line) {
|
|
6
|
+
case 'curve': {
|
|
7
|
+
return (0, lines_1.generateCurve)(source, target, center);
|
|
8
|
+
}
|
|
9
|
+
case 'direct': {
|
|
10
|
+
return (0, lines_1.generateDirect)(source, target, center);
|
|
11
|
+
}
|
|
12
|
+
case 'step':
|
|
13
|
+
default: {
|
|
14
|
+
return (0, lines_1.generateStep)(source, target, center);
|
|
15
|
+
}
|
|
16
|
+
}
|
|
17
|
+
};
|
|
18
|
+
exports.default = generateOrigins;
|
|
@@ -0,0 +1,44 @@
|
|
|
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
|
+
const jsx_runtime_1 = require("react/jsx-runtime");
|
|
7
|
+
const generateOrigins_1 = __importDefault(require("./generateOrigins"));
|
|
8
|
+
const react_1 = require("react");
|
|
9
|
+
const Path = ({ children, diagramId, className = '', line, markerEnd, markerStart, source, target }) => {
|
|
10
|
+
const hasChildren = Boolean(children);
|
|
11
|
+
const origins = (0, react_1.useMemo)(() => {
|
|
12
|
+
if (source &&
|
|
13
|
+
target &&
|
|
14
|
+
line) {
|
|
15
|
+
return (0, generateOrigins_1.default)(source, target, line, hasChildren);
|
|
16
|
+
}
|
|
17
|
+
return undefined;
|
|
18
|
+
}, [
|
|
19
|
+
hasChildren,
|
|
20
|
+
line,
|
|
21
|
+
source,
|
|
22
|
+
target
|
|
23
|
+
]);
|
|
24
|
+
const center = (0, react_1.useMemo)(() => {
|
|
25
|
+
var _a, _b;
|
|
26
|
+
return (origins === null || origins === void 0 ? void 0 : origins.center) ?
|
|
27
|
+
((0, jsx_runtime_1.jsx)("g", { height: '1px', transform: `translate(${(_a = origins === null || origins === void 0 ? void 0 : origins.center) === null || _a === void 0 ? void 0 : _a.x},${(_b = origins === null || origins === void 0 ? void 0 : origins.center) === null || _b === void 0 ? void 0 : _b.y})`, width: '1px', children: children })) :
|
|
28
|
+
undefined;
|
|
29
|
+
}, [
|
|
30
|
+
children,
|
|
31
|
+
origins === null || origins === void 0 ? void 0 : origins.center
|
|
32
|
+
]);
|
|
33
|
+
return ((0, jsx_runtime_1.jsxs)(jsx_runtime_1.Fragment, { children: [(0, jsx_runtime_1.jsxs)("g", { children: [(0, jsx_runtime_1.jsx)("path", { className: 'lincle-base-edge-path-border', d: origins === null || origins === void 0 ? void 0 : origins.path, fill: 'transparent' }), (0, jsx_runtime_1.jsx)("path", { className: `${className} lincle-base-edge-path`, d: origins === null || origins === void 0 ? void 0 : origins.path, fill: 'transparent', markerEnd: markerEnd ?
|
|
34
|
+
markerEnd :
|
|
35
|
+
`url(#diagram-${diagramId ?
|
|
36
|
+
`${diagramId}-` :
|
|
37
|
+
''}marker-arrow)`, markerStart: markerStart ?
|
|
38
|
+
markerStart :
|
|
39
|
+
`url(#diagram-${diagramId ?
|
|
40
|
+
`${diagramId}-` :
|
|
41
|
+
''}marker-circle)` })] }), center] }));
|
|
42
|
+
};
|
|
43
|
+
Path.displayName = 'LinclePath';
|
|
44
|
+
exports.default = Path;
|