@lincle/react-web-interactive 0.4.0-next.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 +297 -0
- package/dist/base.d.ts +1 -0
- package/dist/base.js +12 -0
- package/dist/components/Edge/index.d.ts +1 -0
- package/dist/components/Edge/index.js +5 -0
- package/dist/components/Edges/index.d.ts +1 -0
- package/dist/components/Edges/index.js +5 -0
- package/dist/components/Graph/index.d.ts +4 -0
- package/dist/components/Graph/index.js +18 -0
- package/dist/components/GraphContexts/index.d.ts +4 -0
- package/dist/components/GraphContexts/index.js +167 -0
- package/dist/components/Grid/index.d.ts +4 -0
- package/dist/components/Grid/index.js +13 -0
- package/dist/components/Interaction/index.d.ts +4 -0
- package/dist/components/Interaction/index.js +202 -0
- package/dist/components/Node/MoveNode/index.d.ts +4 -0
- package/dist/components/Node/MoveNode/index.js +164 -0
- package/dist/components/Node/PullNode/index.d.ts +4 -0
- package/dist/components/Node/PullNode/index.js +90 -0
- package/dist/components/Node/index.d.ts +4 -0
- package/dist/components/Node/index.js +127 -0
- package/dist/components/Nodes/index.d.ts +1 -0
- package/dist/components/Nodes/index.js +5 -0
- package/dist/components/Path/index.d.ts +1 -0
- package/dist/components/Path/index.js +5 -0
- package/dist/components/Pull/index.d.ts +4 -0
- package/dist/components/Pull/index.js +153 -0
- package/dist/components/index.d.ts +9 -0
- package/dist/components/index.js +24 -0
- package/dist/index.d.ts +2 -0
- package/dist/index.js +18 -0
- package/dist/shared.d.ts +48 -0
- package/dist/shared.js +18 -0
- package/dist/styles.g.css +162 -0
- package/package.json +102 -0
package/README.md
ADDED
|
@@ -0,0 +1,297 @@
|
|
|
1
|
+
<div align="center">
|
|
2
|
+
<h1><code>@lincle/react-web-interactive</code>: An interactive <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-interactive"><img alt="NPM Version" src="https://img.shields.io/npm/v/@lincle/react-web-interactive.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-interactive.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://github.com/semantic-release/semantic-release#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/digested/lincle/commits/master"><img alt="Build Status" src="https://gitlab.com/digested/lincle/badges/master/pipeline.svg" /></a>
|
|
19
|
+
<a href="https://lincle.gitlab.io/lincle/stats/base/coverage/lcov-report/"><img alt="Coverage Report" src="https://gitlab.com/digested/lincle/badges/master/coverage.svg" /></a>
|
|
20
|
+
<a href="https://lincle.gitlab.io/lincle/stats/base/webpack/"><img alt="Build Analysis" src="https://img.shields.io/badge/webpack-stats-blue.svg" /></a>
|
|
21
|
+
</div>
|
|
22
|
+
|
|
23
|
+
**`@lincle/react-web-interactive`** generates a reactive, composable graph/diagram. `@lincle/react-web-interactive` is built on [`@lincle/base`](https://www.npmjs.com/package/@lincle/base) diagram generating capabilities adding interactive functionality.
|
|
24
|
+
|
|
25
|
+
Interactivity is provided by:
|
|
26
|
+
* [`react-map-interaction`](https://www.npmjs.com/package/react-map-interaction) for panning and scaling
|
|
27
|
+
* [`react-draggable`](https://www.npmjs.com/package/react-draggable) for moving of nodes and edges.
|
|
28
|
+
|
|
29
|
+
The nodes are moveable by default. To pull new edges, tap and hold the diagram or press and hold `shift`. To select nodes, press on a node for half a second or hold `ctrl`.
|
|
30
|
+
|
|
31
|
+
> ***Note**: node selection relies on a callback function and is **disabled** if a callback is not provided.*
|
|
32
|
+
|
|
33
|
+
Please see the various testing [demos](https://lincle.gitlab.io/lincle/) for examples.
|
|
34
|
+
|
|
35
|
+
## Installation & Setup
|
|
36
|
+
|
|
37
|
+
Install `@lincle/react-web-interactive` and the peer dependencies `react`, `react-dom`:
|
|
38
|
+
|
|
39
|
+
```
|
|
40
|
+
npm install react react-dom @lincle/react-web-interactive
|
|
41
|
+
```
|
|
42
|
+
|
|
43
|
+
Also include the provided styles file. For example:
|
|
44
|
+
|
|
45
|
+
```
|
|
46
|
+
import '@lincle/react-web-interactive/dist/main.min.css';
|
|
47
|
+
```
|
|
48
|
+
|
|
49
|
+
## Simple Example
|
|
50
|
+
|
|
51
|
+
The following example will generate this diagram:
|
|
52
|
+
|
|
53
|
+
<div align="center">
|
|
54
|
+
<a href="https://gitlab.com/digested/lincle/-/raw/master/static/react-yad-example.png">
|
|
55
|
+
<img src="https://gitlab.com/digested/lincle/-/raw/master/static/react-yad-example.png" alt="resulting screenshot of simple example" style="max-width:100%;">
|
|
56
|
+
</a>
|
|
57
|
+
</div>
|
|
58
|
+
|
|
59
|
+
> [<h3>CodeSandbox</h3>](https://codesandbox.io/s/react-yad-simple-example-cus8v)
|
|
60
|
+
|
|
61
|
+
```css
|
|
62
|
+
.node {
|
|
63
|
+
display: flex;
|
|
64
|
+
align-items: center;
|
|
65
|
+
justify-content: center;
|
|
66
|
+
width: calc(100% - 2px);
|
|
67
|
+
height: calc(100% - 2px);
|
|
68
|
+
cursor: grab;
|
|
69
|
+
border: 1px solid black;
|
|
70
|
+
background-color: white;
|
|
71
|
+
box-shadow: 0 3px 6px rgba(0, 0, 0, 0.16), 0 3px 6px rgba(0, 0, 0, 0.23);
|
|
72
|
+
}
|
|
73
|
+
|
|
74
|
+
.node:active {
|
|
75
|
+
cursor: grabbing;
|
|
76
|
+
}
|
|
77
|
+
|
|
78
|
+
.node-oval {
|
|
79
|
+
border-radius: 50%;
|
|
80
|
+
}
|
|
81
|
+
```
|
|
82
|
+
|
|
83
|
+
```ts
|
|
84
|
+
<Graph
|
|
85
|
+
id='YetAnotherDiagram'
|
|
86
|
+
key='1'
|
|
87
|
+
nodeHeight={50}
|
|
88
|
+
nodeWidth={50}
|
|
89
|
+
onEdgeDrop={handleEdgeDrop}
|
|
90
|
+
>
|
|
91
|
+
<Nodes>
|
|
92
|
+
<Node
|
|
93
|
+
id={1}
|
|
94
|
+
key={1}
|
|
95
|
+
x={50}
|
|
96
|
+
y={50}
|
|
97
|
+
>
|
|
98
|
+
<div styleName='node'>
|
|
99
|
+
Node 1
|
|
100
|
+
</div>
|
|
101
|
+
</Node>
|
|
102
|
+
<Node
|
|
103
|
+
height={100}
|
|
104
|
+
id={2}
|
|
105
|
+
key={2}
|
|
106
|
+
line='direct'
|
|
107
|
+
shape='oval'
|
|
108
|
+
width={200}
|
|
109
|
+
x={100}
|
|
110
|
+
y={150}
|
|
111
|
+
>
|
|
112
|
+
<div styleName='node node-oval'>
|
|
113
|
+
Node 2
|
|
114
|
+
</div>
|
|
115
|
+
</Node>
|
|
116
|
+
<Node
|
|
117
|
+
id={3}
|
|
118
|
+
key={3}
|
|
119
|
+
line='curve'
|
|
120
|
+
shape='oval'
|
|
121
|
+
x={150}
|
|
122
|
+
y={350}
|
|
123
|
+
>
|
|
124
|
+
<div styleName='node node-oval'>
|
|
125
|
+
Node 3
|
|
126
|
+
</div>
|
|
127
|
+
</Node>
|
|
128
|
+
</Nodes>
|
|
129
|
+
<Edges>
|
|
130
|
+
<Edge
|
|
131
|
+
id={1}
|
|
132
|
+
key={1}
|
|
133
|
+
sourceId={1}
|
|
134
|
+
targetId={2}
|
|
135
|
+
>
|
|
136
|
+
<circle
|
|
137
|
+
fill='white'
|
|
138
|
+
r='3'
|
|
139
|
+
stroke='black'
|
|
140
|
+
strokeWidth={2}
|
|
141
|
+
>
|
|
142
|
+
<title>
|
|
143
|
+
Bridge
|
|
144
|
+
</title>
|
|
145
|
+
</circle>
|
|
146
|
+
</Edge>
|
|
147
|
+
<Edge
|
|
148
|
+
id={2}
|
|
149
|
+
key={2}
|
|
150
|
+
line='direct'
|
|
151
|
+
sourceId={2}
|
|
152
|
+
targetId={3}
|
|
153
|
+
/>
|
|
154
|
+
</Edges>
|
|
155
|
+
</Graph>
|
|
156
|
+
```
|
|
157
|
+
|
|
158
|
+
## Component API's
|
|
159
|
+
|
|
160
|
+
**\*** *bolded parameters are required*
|
|
161
|
+
|
|
162
|
+
### `<Graph>`
|
|
163
|
+
|
|
164
|
+
| Parameters | Type | Default | Description |
|
|
165
|
+
|---|---|---|---|
|
|
166
|
+
| **`id`** | `string \| number` | | The unique ID of the graph |
|
|
167
|
+
| disableMove | `boolean` | `false` | Disable moving nodes |
|
|
168
|
+
| disablePan | `boolean` | `false` | Disable panning the diagram |
|
|
169
|
+
| disablePull | `boolean` | `false` | Disable connecting nodes |
|
|
170
|
+
| disableScale | `boolean` | `false` | Disable zooming/scaling the diagram |
|
|
171
|
+
| edgeFrequency | `number` | `16` (*60Hz*) | Frequency of edge updates during node movements (in ms) |
|
|
172
|
+
| grid | `false \| [number, number]` | `[16, 16]` | The background grid space; false to disable. |
|
|
173
|
+
| line | `"curve" \| "direct" \| "step"` | `"step"` | The default curve for the edges |
|
|
174
|
+
| maxScale | `number` | `2` | The maximum zoom/scale of the diagram |
|
|
175
|
+
| minScale | `number` | `0.5` | The minimum zoom/scale of the diagram |
|
|
176
|
+
| mode | `"move" \| "pull"` | `"move"` | Forced interaction state of the diagram (moving nodes or pulling/connectiong them) |
|
|
177
|
+
| nodeFrequency | `number` | `500` | Frequency of node movements reported (in ms, aside from edges) |
|
|
178
|
+
| nodeHeight | `number` | `50` | The default height for nodes (in px) |
|
|
179
|
+
| nodeWidth | `number` | `50` | The default width for nodes (in px) |
|
|
180
|
+
| onEdgeDrop | `(sourceId: string, targetId: string) => void` | | The default callback when an edge is dropped. |
|
|
181
|
+
| onMouseDown | `(event: MouseEvent<HTMLDivElement>) => void` | | Callback passed on main diagram `<div />` |
|
|
182
|
+
| onMouseUp | `(event: MouseEvent<HTMLDivElement>) => void` | | Callback passed on main diagram `<div />` |
|
|
183
|
+
| onNodeDrag | `(event: DraggableEvent, nodeId: ReactText, data: DraggableData) => void` | | Default callback for dropping an edge |
|
|
184
|
+
| onNodeSelect | `(nodeId: ReactText) => void` | | Default callback for selecting a node |
|
|
185
|
+
| onNodeStart | `(event: DraggableEvent, nodeId: ReactText) => void` | | Default callback for nodes |
|
|
186
|
+
| onNodeStop | `(event: DraggableEvent, nodeId: ReactText, data: DraggableData) => void` | | Default callback for nodes |
|
|
187
|
+
| onScale | `(scale: number) => void` | | Callback passed on diagram scale events |
|
|
188
|
+
| onTouchEnd | `(event: TouchEvent<HTMLDivElement>) => void` | | Callback passed on main diagram `<div />` |
|
|
189
|
+
| onTouchStart| `(event: TouchEvent<HTMLDivElement>) => void` | | Callback passed on main diagram `<div />` |
|
|
190
|
+
| onTranslate | `({x: number, y: number}) => void` | | Callback passed on diagram translate events |
|
|
191
|
+
| scale | `number` | `1` | The default zoom/scale of the diagram |
|
|
192
|
+
| shape | `"oval" \| "rectangle"` | `"rectangle"` | The default shape for nodes |
|
|
193
|
+
| snap | `boolean \| [number, number]` | `false` | Snap nodes to grid when moved. If `true` nodes will snap to `grid` dimensions. |
|
|
194
|
+
| xOffset | `number` | `0` | The initial x-axis position of the diagram |
|
|
195
|
+
| yOffset | `number` | `0` | The initial y-axis position of the diagram |
|
|
196
|
+
|
|
197
|
+
### `<GraphContexts>`
|
|
198
|
+
|
|
199
|
+
| Parameters | Type | Default | Description |
|
|
200
|
+
|---|---|---|---|
|
|
201
|
+
| <td colspan="3">*Same API as `<Graph />` ommiting the mouse and touch event passthrough* |
|
|
202
|
+
|
|
203
|
+
The primary purpose of `<GraphContexts>` is to include additional elements in the graph that will share access to the various `<Context.Providers>` - such as `@lincle/minimap`.
|
|
204
|
+
|
|
205
|
+
### `<Nodes>`
|
|
206
|
+
|
|
207
|
+
| Parameters | Type | Default | Description |
|
|
208
|
+
|---|---|---|---|
|
|
209
|
+
| *none* |
|
|
210
|
+
|
|
211
|
+
### `<Node>`
|
|
212
|
+
|
|
213
|
+
| Parameters | Type | Default | Description |
|
|
214
|
+
|---|---|---|---|
|
|
215
|
+
| **`id`** | `string | number` | | The unique ID of the node |
|
|
216
|
+
| x | `number` | `0` | The initial `x` coordinate of the node |
|
|
217
|
+
| y | `number` | `0` | The initial `y` coordinate of the node |
|
|
218
|
+
| <td colspan="3">*The following override the defaults provided by `<Graph />`* |
|
|
219
|
+
| disableMove | `boolean` | `false` | Disable moving this node |
|
|
220
|
+
| disablePull | `boolean` | `false` | Disable connecting this node |
|
|
221
|
+
| height | `number` | `50` | The node height|
|
|
222
|
+
| line | `'curve' \| 'direct' \| 'step'` | | The connector line shape |
|
|
223
|
+
| mode | `"move" \| "pull"` | | The node interactive state (moving node or pulling/connecting) |
|
|
224
|
+
| onDrag | `(event: DraggableEvent, nodeId: ReactText, data: DraggableData) => void` | | Callback for node |
|
|
225
|
+
| onEdgeDrop | `(sourceId: string, targetId: string) => void` | | Callback for dropping an edge |
|
|
226
|
+
| onSelect | `(nodeId: ReactText) => void` | | Callback for selecting a node |
|
|
227
|
+
| onStart | `(event: DraggableEvent, nodeId: ReactText) => void` | | Callback for node |
|
|
228
|
+
| onStop | `(event: DraggableEvent, nodeId: ReactText, data: DraggableData) => void` | | Callback for node |
|
|
229
|
+
| shape | `'oval' \| 'rectangle'` | | The node shape |
|
|
230
|
+
| width | `number` | `50` | The node width |
|
|
231
|
+
|
|
232
|
+
### `<Edges>`
|
|
233
|
+
|
|
234
|
+
| Parameters | Type | Default | Description |
|
|
235
|
+
|---|---|---|---|
|
|
236
|
+
| dash | `boolean \| undefined` | `undefined` | Whether dash should be enabled. Defaults to hover only. |
|
|
237
|
+
|
|
238
|
+
### `<Edge>`
|
|
239
|
+
|
|
240
|
+
| Parameters | Type | Default | Description |
|
|
241
|
+
|---|---|---|---|
|
|
242
|
+
| **`id`** | `string \| number` | | The unique ID for the edge |
|
|
243
|
+
| dash | `boolean \| undefined` | `undefined` | Whether dash should be enabled. Defaults to hover only. |
|
|
244
|
+
| line | `'curve' \| 'direct' \| 'step'` | | The line shape (overrides default) and not applicable if custom path generator is used. |
|
|
245
|
+
| markerEnd | `string` | | Passed to the default path generated `<path>` SVG |
|
|
246
|
+
| markerStart | `string` | | Passed to the default path generated `<path>` SVG |
|
|
247
|
+
| path | *path `function` - see below* | | Use to generate a custom path component. |
|
|
248
|
+
| **`sourceId`** | `string \| number` | | ID for the source node |
|
|
249
|
+
| **`targetId`** | `string \| number` | | ID for the target node |
|
|
250
|
+
|
|
251
|
+
> ***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.*
|
|
252
|
+
|
|
253
|
+
### Path `function`
|
|
254
|
+
|
|
255
|
+
Instead of using the `@lincle/react-web-interactive` provided edges (`curve`, `line`, & `step`), you may opt to generate your own path component:
|
|
256
|
+
|
|
257
|
+
```ts
|
|
258
|
+
(
|
|
259
|
+
source: {
|
|
260
|
+
height: number,
|
|
261
|
+
id: string | number,
|
|
262
|
+
shape: 'oval' | 'rectangle',
|
|
263
|
+
width: number,
|
|
264
|
+
x: number,
|
|
265
|
+
y: number
|
|
266
|
+
},
|
|
267
|
+
target: {
|
|
268
|
+
height: number,
|
|
269
|
+
id: string | number,
|
|
270
|
+
shape: 'oval' | 'rectangle',
|
|
271
|
+
width: number,
|
|
272
|
+
x: number,
|
|
273
|
+
y: number
|
|
274
|
+
},
|
|
275
|
+
children?: ReactNode
|
|
276
|
+
) => Component<SVG type>
|
|
277
|
+
```
|
|
278
|
+
|
|
279
|
+
### `<Grid>`
|
|
280
|
+
|
|
281
|
+
| Parameters | Type | Default | Description |
|
|
282
|
+
|---|---|---|---|
|
|
283
|
+
| children | `SVG` | `<circle>` | The repeated SVG |
|
|
284
|
+
|
|
285
|
+
### Contexts
|
|
286
|
+
|
|
287
|
+
There are several `<Context>`'s used that can be taken advantage of to extend the functionality of `lincle` via their respective `<Context.Provider>`s':
|
|
288
|
+
|
|
289
|
+
| Context | Provides | Description |
|
|
290
|
+
|---|---|---|
|
|
291
|
+
| `<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. |
|
|
292
|
+
| `<GridContext>` | `[number, number]` | Provides the current grid dimensions. |
|
|
293
|
+
| `<ModeContext>` | `{disableMove?: boolean, disablePull?: boolean, givenMode?: 'move' \| 'pull' \| 'select', mode: 'move' \| 'pull' \| 'select', onMode?: 'move' \| 'pull' \| 'select' => void}` | Provides the current graph mode, whether move and pull are enabled on nodes, an optional given override mode, and a function to change the mode. |
|
|
294
|
+
| `<ScaleContext>` | `{scale: number, onScale?: (scale: number) => void}` | Provides the current scale and a function to change the scale. |
|
|
295
|
+
| `<SnapContext>` | `[number, number]` | Provides the current snap dimensions. |
|
|
296
|
+
| `<TranslateContext>` | `{translate: {x: number, y: number}, onTranslate?: (translate: {x: number, y: number}) => void}` | Provides the current graph translation (xOffset and yOffset) and a function to change the translation. |
|
|
297
|
+
| `<TransformContext>` | `{disablePan?: boolean, disableScale?: boolean, maxScale?: number, minScale?: number}` | Provides the rest of the graphs current transform properties. |
|
package/dist/base.d.ts
ADDED
|
@@ -0,0 +1 @@
|
|
|
1
|
+
export { Edge, Edges, Graph, GraphContexts, Grid, Node, Nodes, Path } from '@lincle/react-web-base';
|
package/dist/base.js
ADDED
|
@@ -0,0 +1,12 @@
|
|
|
1
|
+
"use strict";
|
|
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;
|
|
4
|
+
var react_web_base_1 = require("@lincle/react-web-base");
|
|
5
|
+
Object.defineProperty(exports, "Edge", { enumerable: true, get: function () { return react_web_base_1.Edge; } });
|
|
6
|
+
Object.defineProperty(exports, "Edges", { enumerable: true, get: function () { return react_web_base_1.Edges; } });
|
|
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
|
+
Object.defineProperty(exports, "Grid", { enumerable: true, get: function () { return react_web_base_1.Grid; } });
|
|
10
|
+
Object.defineProperty(exports, "Node", { enumerable: true, get: function () { return react_web_base_1.Node; } });
|
|
11
|
+
Object.defineProperty(exports, "Nodes", { enumerable: true, get: function () { return react_web_base_1.Nodes; } });
|
|
12
|
+
Object.defineProperty(exports, "Path", { enumerable: true, get: function () { return react_web_base_1.Path; } });
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
export { Edge as default } from '../../base';
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
export { Edges as default } from '../../base';
|
|
@@ -0,0 +1,18 @@
|
|
|
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 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 }) => {
|
|
11
|
+
if (!id) {
|
|
12
|
+
console.error('No ID provided to @lincle/interactive Graph!');
|
|
13
|
+
return null;
|
|
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 }) }) }));
|
|
16
|
+
};
|
|
17
|
+
Graph.displayName = 'LincleInteractiveGraph';
|
|
18
|
+
exports.default = Graph;
|
|
@@ -0,0 +1,167 @@
|
|
|
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 base_1 = require("../../base");
|
|
8
|
+
const shared_1 = require("../../shared");
|
|
9
|
+
const Grid_1 = __importDefault(require("../Grid"));
|
|
10
|
+
const react_1 = require("react");
|
|
11
|
+
const noGrid = [
|
|
12
|
+
1,
|
|
13
|
+
1
|
|
14
|
+
];
|
|
15
|
+
const GraphContexts = ({ children, disableMove = shared_1.disableMove, disablePan = shared_1.transformDefaults.disablePan, disablePull = shared_1.disablePull, disableScale = shared_1.transformDefaults.disableScale, edgeFrequency = shared_1.defaultSettings.edgeFrequency, grid: givenGrid, id, line = shared_1.defaultSettings.line, maxScale = shared_1.transformDefaults.maxScale, minScale = shared_1.transformDefaults.minScale, mode: givenMode, nodeFrequency = shared_1.defaultSettings.nodeFrequency, nodeHeight = shared_1.defaultSettings.height, nodeWidth = shared_1.defaultSettings.width, onEdgeDrop, onNodeDrag, onNodeSelect, onNodeStart, onNodeStop, onScale, onTranslate, scale: givenScale = shared_1.defaultScale, shape = shared_1.defaultSettings.shape, snap, xOffset = shared_1.translateDefaults.x, yOffset = shared_1.translateDefaults.y }) => {
|
|
16
|
+
const [nodeControls, setNodeControls] = (0, react_1.useState)({
|
|
17
|
+
onEdgeDrop,
|
|
18
|
+
onNodeDrag,
|
|
19
|
+
onNodeSelect,
|
|
20
|
+
onNodeStart,
|
|
21
|
+
onNodeStop
|
|
22
|
+
});
|
|
23
|
+
const NodeControls = (0, react_1.useMemo)(() => {
|
|
24
|
+
return {
|
|
25
|
+
onEdgeDrop,
|
|
26
|
+
onNodeDrag,
|
|
27
|
+
onNodeSelect,
|
|
28
|
+
onNodeStart,
|
|
29
|
+
onNodeStop,
|
|
30
|
+
setNodeControls
|
|
31
|
+
};
|
|
32
|
+
}, [
|
|
33
|
+
onEdgeDrop,
|
|
34
|
+
onNodeDrag,
|
|
35
|
+
onNodeSelect,
|
|
36
|
+
onNodeStart,
|
|
37
|
+
onNodeStop,
|
|
38
|
+
setNodeControls
|
|
39
|
+
]);
|
|
40
|
+
const transform = (0, react_1.useMemo)(() => {
|
|
41
|
+
return {
|
|
42
|
+
disablePan,
|
|
43
|
+
disableScale,
|
|
44
|
+
maxScale,
|
|
45
|
+
minScale
|
|
46
|
+
};
|
|
47
|
+
}, [
|
|
48
|
+
disablePan,
|
|
49
|
+
disableScale,
|
|
50
|
+
maxScale,
|
|
51
|
+
minScale
|
|
52
|
+
]);
|
|
53
|
+
const [mode, setMode] = (0, react_1.useState)(givenMode);
|
|
54
|
+
const handleMode = (0, react_1.useCallback)((newMode) => {
|
|
55
|
+
setMode(newMode);
|
|
56
|
+
}, []);
|
|
57
|
+
const Mode = (0, react_1.useMemo)(() => {
|
|
58
|
+
return {
|
|
59
|
+
disableMove,
|
|
60
|
+
disablePull,
|
|
61
|
+
givenMode,
|
|
62
|
+
mode,
|
|
63
|
+
onMode: handleMode
|
|
64
|
+
};
|
|
65
|
+
}, [
|
|
66
|
+
disableMove,
|
|
67
|
+
disablePull,
|
|
68
|
+
givenMode,
|
|
69
|
+
handleMode,
|
|
70
|
+
mode
|
|
71
|
+
]);
|
|
72
|
+
(0, react_1.useEffect)(() => {
|
|
73
|
+
handleMode(givenMode);
|
|
74
|
+
}, [
|
|
75
|
+
givenMode,
|
|
76
|
+
handleMode
|
|
77
|
+
]);
|
|
78
|
+
const [scale, setScale] = (0, react_1.useState)(givenScale);
|
|
79
|
+
const handleScale = (0, react_1.useCallback)((newScale) => {
|
|
80
|
+
if (onScale) {
|
|
81
|
+
onScale(newScale);
|
|
82
|
+
}
|
|
83
|
+
setScale(newScale);
|
|
84
|
+
}, [
|
|
85
|
+
onScale
|
|
86
|
+
]);
|
|
87
|
+
const Scale = (0, react_1.useMemo)(() => {
|
|
88
|
+
return {
|
|
89
|
+
onScale: handleScale,
|
|
90
|
+
scale
|
|
91
|
+
};
|
|
92
|
+
}, [
|
|
93
|
+
handleScale,
|
|
94
|
+
scale
|
|
95
|
+
]);
|
|
96
|
+
(0, react_1.useEffect)(() => {
|
|
97
|
+
setScale(givenScale);
|
|
98
|
+
}, [
|
|
99
|
+
givenScale
|
|
100
|
+
]);
|
|
101
|
+
const [translate, setTranslate] = (0, react_1.useState)({
|
|
102
|
+
x: xOffset,
|
|
103
|
+
y: yOffset
|
|
104
|
+
});
|
|
105
|
+
const handleTranslate = (0, react_1.useCallback)((newTranslate) => {
|
|
106
|
+
if (onTranslate) {
|
|
107
|
+
onTranslate(newTranslate);
|
|
108
|
+
}
|
|
109
|
+
setTranslate(newTranslate);
|
|
110
|
+
}, [
|
|
111
|
+
onTranslate
|
|
112
|
+
]);
|
|
113
|
+
const Translate = (0, react_1.useMemo)(() => {
|
|
114
|
+
return {
|
|
115
|
+
onTranslate: handleTranslate,
|
|
116
|
+
translate
|
|
117
|
+
};
|
|
118
|
+
}, [
|
|
119
|
+
handleTranslate,
|
|
120
|
+
translate
|
|
121
|
+
]);
|
|
122
|
+
(0, react_1.useEffect)(() => {
|
|
123
|
+
setTranslate({
|
|
124
|
+
x: xOffset,
|
|
125
|
+
y: yOffset
|
|
126
|
+
});
|
|
127
|
+
}, [
|
|
128
|
+
xOffset,
|
|
129
|
+
yOffset
|
|
130
|
+
]);
|
|
131
|
+
const grid = (0, react_1.useMemo)(() => {
|
|
132
|
+
var _a;
|
|
133
|
+
return (_a = (givenGrid === false ?
|
|
134
|
+
noGrid :
|
|
135
|
+
givenGrid)) !== null && _a !== void 0 ? _a : shared_1.defaultSettings.grid;
|
|
136
|
+
}, [
|
|
137
|
+
givenGrid
|
|
138
|
+
]);
|
|
139
|
+
const derivedSnap = (0, react_1.useMemo)(() => {
|
|
140
|
+
if (snap === undefined) {
|
|
141
|
+
return givenGrid === undefined ?
|
|
142
|
+
noGrid :
|
|
143
|
+
grid;
|
|
144
|
+
}
|
|
145
|
+
if (snap === false) {
|
|
146
|
+
return noGrid;
|
|
147
|
+
}
|
|
148
|
+
if (snap === true) {
|
|
149
|
+
return grid;
|
|
150
|
+
}
|
|
151
|
+
return snap;
|
|
152
|
+
}, [
|
|
153
|
+
givenGrid,
|
|
154
|
+
grid,
|
|
155
|
+
snap
|
|
156
|
+
]);
|
|
157
|
+
const hiddenGrid = givenGrid === false ?
|
|
158
|
+
null :
|
|
159
|
+
((0, jsx_runtime_1.jsx)(Grid_1.default, {}));
|
|
160
|
+
const staticContexts = ((0, jsx_runtime_1.jsx)(shared_1.NodeContext.Provider, { value: NodeControls, children: (0, jsx_runtime_1.jsx)(shared_1.SnapContext.Provider, { value: derivedSnap, children: (0, jsx_runtime_1.jsx)(shared_1.TransformContext.Provider, { value: transform, children: (0, jsx_runtime_1.jsx)(shared_1.ModeContext.Provider, { value: Mode, children: (0, jsx_runtime_1.jsx)(shared_1.ScaleContext.Provider, { value: Scale, children: (0, jsx_runtime_1.jsxs)(shared_1.TranslateContext.Provider, { value: Translate, children: [hiddenGrid, children] }) }) }) }) }) }));
|
|
161
|
+
const gridContext = givenGrid === false ?
|
|
162
|
+
staticContexts :
|
|
163
|
+
((0, jsx_runtime_1.jsx)(shared_1.GridContext.Provider, { value: givenGrid !== null && givenGrid !== void 0 ? givenGrid : shared_1.defaultSettings.grid, children: staticContexts }));
|
|
164
|
+
return ((0, jsx_runtime_1.jsx)(base_1.GraphContexts, { edgeFrequency: edgeFrequency, grid: false, id: id, line: line, nodeFrequency: nodeFrequency, nodeHeight: nodeHeight, nodeWidth: nodeWidth, shape: shape, children: gridContext }));
|
|
165
|
+
};
|
|
166
|
+
GraphContexts.displayName = 'LincleInteractiveGraphContexts';
|
|
167
|
+
exports.default = GraphContexts;
|
|
@@ -0,0 +1,13 @@
|
|
|
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 Grid = ({ children }) => {
|
|
8
|
+
const { scale } = (0, react_1.useContext)(shared_1.ScaleContext);
|
|
9
|
+
const { translate } = (0, react_1.useContext)(shared_1.TranslateContext);
|
|
10
|
+
return ((0, jsx_runtime_1.jsx)(base_1.Grid, { scale: scale, xOffset: translate.x, yOffset: translate.y, children: children }));
|
|
11
|
+
};
|
|
12
|
+
Grid.displayName = 'LincleInteractiveGrid';
|
|
13
|
+
exports.default = Grid;
|