@3plate/graph-core 0.1.4 → 0.1.5
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/index.cjs +1374 -297
- package/dist/index.d.cts +253 -15
- package/dist/index.d.ts +253 -15
- package/dist/index.js +1374 -297
- package/package.json +2 -1
package/dist/index.d.cts
CHANGED
|
@@ -4,37 +4,105 @@ type NodeAlign = 'natural' | 'top' | 'bottom' | 'left' | 'right';
|
|
|
4
4
|
type Orientation = 'TB' | 'BT' | 'LR' | 'RL';
|
|
5
5
|
type Nav = 'first' | 'last' | 'prev' | 'next';
|
|
6
6
|
type LayoutStep = 'alignChildren' | 'alignParents' | 'compact';
|
|
7
|
+
type Dims = {
|
|
8
|
+
w: number;
|
|
9
|
+
h: number;
|
|
10
|
+
};
|
|
7
11
|
|
|
8
12
|
type MarkerType = 'arrow' | 'circle' | 'diamond' | 'bar' | 'none';
|
|
9
13
|
|
|
14
|
+
/**
|
|
15
|
+
* Arguments to the API constructor.
|
|
16
|
+
*
|
|
17
|
+
* The caller can specify nodes and edges, or history,
|
|
18
|
+
* but not both.
|
|
19
|
+
*
|
|
20
|
+
* The root element ID is required.
|
|
21
|
+
*/
|
|
10
22
|
type APIArguments<N, E> = {
|
|
23
|
+
/** Options for the API */
|
|
11
24
|
options?: APIOptions<N, E>;
|
|
25
|
+
/** Initial nodes */
|
|
12
26
|
nodes?: N[];
|
|
27
|
+
/** Initial edges */
|
|
13
28
|
edges?: E[];
|
|
29
|
+
/** Initial history */
|
|
14
30
|
history?: Update<N, E>[];
|
|
31
|
+
/** Events */
|
|
32
|
+
events?: EventsOptions<N, E>;
|
|
33
|
+
/** Root element ID */
|
|
15
34
|
root: string;
|
|
16
35
|
};
|
|
36
|
+
/** Options for the API */
|
|
17
37
|
type APIOptions<N, E> = {
|
|
38
|
+
/** Options for the graph */
|
|
18
39
|
graph?: GraphOptions;
|
|
40
|
+
/** Options for the canvas */
|
|
19
41
|
canvas?: CanvasOptions<N>;
|
|
42
|
+
/** Options for node and edge properties */
|
|
20
43
|
props?: PropsOptions<N, E>;
|
|
21
44
|
};
|
|
45
|
+
/** Options for the graph */
|
|
22
46
|
type GraphOptions = {
|
|
47
|
+
/** Order in which edges are merged; see `MergeOrder` */
|
|
23
48
|
mergeOrder?: MergeOrder;
|
|
49
|
+
/** Margin between nodes */
|
|
24
50
|
nodeMargin?: number;
|
|
51
|
+
/** Size of dummy nodes */
|
|
25
52
|
dummyNodeSize?: number;
|
|
53
|
+
/** Alignment of nodes */
|
|
26
54
|
nodeAlign?: NodeAlign;
|
|
55
|
+
/** Spacing between edges */
|
|
27
56
|
edgeSpacing?: number;
|
|
57
|
+
/** Turn radius */
|
|
28
58
|
turnRadius?: number;
|
|
59
|
+
/** Orientation of the graph */
|
|
29
60
|
orientation?: Orientation;
|
|
61
|
+
/** Margin between layers */
|
|
30
62
|
layerMargin?: number;
|
|
63
|
+
/** Number of iterations for alignment */
|
|
31
64
|
alignIterations?: number;
|
|
65
|
+
/** Alignment threshold */
|
|
32
66
|
alignThreshold?: number;
|
|
67
|
+
/** Whether to separate track sets */
|
|
33
68
|
separateTrackSets?: boolean;
|
|
69
|
+
/** Marker size */
|
|
34
70
|
markerSize?: number;
|
|
71
|
+
/** Layout steps */
|
|
35
72
|
layoutSteps?: LayoutStep[] | null;
|
|
36
73
|
};
|
|
37
|
-
|
|
74
|
+
/**
|
|
75
|
+
* Events that can be handled by the user.
|
|
76
|
+
*/
|
|
77
|
+
type EventsOptions<N, E> = {
|
|
78
|
+
/** Called when a node is clicked */
|
|
79
|
+
nodeClick?: (node: N) => void;
|
|
80
|
+
/** Called when an edge is clicked */
|
|
81
|
+
edgeClick?: (edge: E) => void;
|
|
82
|
+
/** Called when a node is double-clicked */
|
|
83
|
+
editNode?: (node: N, callback: (node: N) => void) => void;
|
|
84
|
+
/** Called when a node should be added */
|
|
85
|
+
newNode?: (callback: (node: N) => void) => void;
|
|
86
|
+
/** Called when an edge is double-clicked */
|
|
87
|
+
editEdge?: (edge: E, callback: (edge: E) => void) => void;
|
|
88
|
+
/** Called when a node should be added */
|
|
89
|
+
addNode?: (node: NewNode, callback: (node: N) => void) => void;
|
|
90
|
+
/** Called when an edge should be added */
|
|
91
|
+
addEdge?: (edge: NewEdge<N>, callback: (edge: E) => void) => void;
|
|
92
|
+
/** Called when an edge should be removed */
|
|
93
|
+
removeEdge?: (edge: E, callback: (remove: boolean) => void) => void;
|
|
94
|
+
/** Called when a node should be removed */
|
|
95
|
+
removeNode?: (node: N, callback: (remove: boolean) => void) => void;
|
|
96
|
+
/** Called when a node should be updated */
|
|
97
|
+
updateNode?: (node: N, update: Record<string, any>, callback: (node: N) => void) => void;
|
|
98
|
+
/** Called when an edge should be updated */
|
|
99
|
+
updateEdge?: (edge: E, update: Record<string, any>, callback: (edge: E) => void) => void;
|
|
100
|
+
/** Called when history index/length changes */
|
|
101
|
+
historyChange?: (index: number, length: number) => void;
|
|
102
|
+
};
|
|
103
|
+
/** Function to render a node */
|
|
104
|
+
type RenderNode<N> = (node: N, props?: NodeProps<N>) => HTMLElement;
|
|
105
|
+
/** Color mode */
|
|
38
106
|
type ColorMode = 'light' | 'dark' | 'system';
|
|
39
107
|
/** Canvas background and general colors */
|
|
40
108
|
type CanvasTheme = {
|
|
@@ -72,68 +140,184 @@ type EdgeTheme = {
|
|
|
72
140
|
};
|
|
73
141
|
/** Combined theme with all customizable properties */
|
|
74
142
|
type ThemeVars = CanvasTheme & NodeTheme & PortTheme & EdgeTheme;
|
|
143
|
+
/** Options for the canvas */
|
|
75
144
|
type CanvasOptions<N> = {
|
|
145
|
+
/** Canvas width in pixels or percentage */
|
|
76
146
|
width?: number | string;
|
|
147
|
+
/** Canvas height in pixels or percentage */
|
|
77
148
|
height?: number | string;
|
|
78
|
-
/** Padding inside the canvas viewport
|
|
149
|
+
/** Padding inside the canvas viewport */
|
|
79
150
|
padding?: number;
|
|
80
|
-
|
|
81
|
-
markerSize?: number;
|
|
151
|
+
/** Whether the canvas is editable */
|
|
82
152
|
editable?: boolean;
|
|
153
|
+
/** Whether to enable pan and zoom */
|
|
83
154
|
panZoom?: boolean;
|
|
155
|
+
/** Function to render a node */
|
|
84
156
|
renderNode?: RenderNode<N>;
|
|
157
|
+
/** Color mode */
|
|
85
158
|
colorMode?: ColorMode;
|
|
159
|
+
/** Theme */
|
|
86
160
|
theme?: ThemeVars;
|
|
161
|
+
/** Node type themes */
|
|
87
162
|
nodeTypes?: Record<string, ThemeVars>;
|
|
163
|
+
/** Edge type themes */
|
|
88
164
|
edgeTypes?: Record<string, ThemeVars>;
|
|
165
|
+
/** Marker size in pixels */
|
|
166
|
+
markerSize?: number;
|
|
89
167
|
};
|
|
168
|
+
/** Options for node and edge properties */
|
|
90
169
|
type PropsOptions<N, E> = {
|
|
170
|
+
/** Function to get node properties */
|
|
91
171
|
node?: GetNodeProps<N>;
|
|
172
|
+
/** Function to get edge properties */
|
|
92
173
|
edge?: GetEdgeProps<N, E>;
|
|
93
174
|
};
|
|
175
|
+
/** Update to apply to the graph */
|
|
94
176
|
type Update<N, E> = {
|
|
177
|
+
/** Nodes to add */
|
|
95
178
|
addNodes?: N[];
|
|
179
|
+
/** Nodes to remove */
|
|
96
180
|
removeNodes?: N[];
|
|
181
|
+
/** Nodes to update */
|
|
97
182
|
updateNodes?: N[];
|
|
183
|
+
/** Edges to add */
|
|
98
184
|
addEdges?: E[];
|
|
185
|
+
/** Edges to remove */
|
|
99
186
|
removeEdges?: E[];
|
|
187
|
+
/** Edges to update */
|
|
100
188
|
updateEdges?: E[];
|
|
189
|
+
/** Description of the update */
|
|
101
190
|
description?: string;
|
|
102
191
|
};
|
|
103
|
-
|
|
192
|
+
/** Node properties */
|
|
193
|
+
type NodeProps<N> = NewNode & {
|
|
194
|
+
/** Node ID */
|
|
104
195
|
id?: string;
|
|
196
|
+
/** Function to render a node */
|
|
197
|
+
render?: RenderNode<N>;
|
|
198
|
+
};
|
|
199
|
+
/** New node properties */
|
|
200
|
+
type NewNode = {
|
|
201
|
+
/** Node title */
|
|
105
202
|
title?: string;
|
|
203
|
+
/** Node text */
|
|
106
204
|
text?: string;
|
|
205
|
+
/** Node type */
|
|
107
206
|
type?: string;
|
|
207
|
+
/** Node ports */
|
|
108
208
|
ports?: {
|
|
209
|
+
/** Input ports */
|
|
109
210
|
in?: (string | PortProps)[];
|
|
211
|
+
/** Output ports */
|
|
110
212
|
out?: (string | PortProps)[];
|
|
111
213
|
};
|
|
112
|
-
render?: RenderNode<N>;
|
|
113
214
|
};
|
|
114
|
-
|
|
215
|
+
/** New edge properties */
|
|
216
|
+
type NewEdge<N> = {
|
|
217
|
+
/** Source node */
|
|
218
|
+
source: {
|
|
219
|
+
node: N;
|
|
220
|
+
port?: string;
|
|
221
|
+
marker?: MarkerType;
|
|
222
|
+
};
|
|
223
|
+
target: {
|
|
224
|
+
node: N;
|
|
225
|
+
port?: string;
|
|
226
|
+
marker?: MarkerType;
|
|
227
|
+
};
|
|
228
|
+
type?: string;
|
|
229
|
+
};
|
|
230
|
+
/** Edge end properties */
|
|
231
|
+
type EdgeEnd<N> =
|
|
232
|
+
/** Edge end node ID */
|
|
233
|
+
string |
|
|
234
|
+
/** Edge end node */
|
|
235
|
+
N |
|
|
236
|
+
/** Structured edge end with id */
|
|
237
|
+
{
|
|
238
|
+
/** Edge end node ID */
|
|
115
239
|
id: string;
|
|
240
|
+
/** Edge end port ID */
|
|
116
241
|
port?: string;
|
|
242
|
+
/** Edge end marker type */
|
|
117
243
|
marker?: MarkerType;
|
|
118
|
-
} |
|
|
244
|
+
} |
|
|
245
|
+
/** Structured edge end with node object */
|
|
246
|
+
{
|
|
247
|
+
/** Edge end node object */
|
|
119
248
|
node: N;
|
|
249
|
+
/** Edge end port ID */
|
|
120
250
|
port?: string;
|
|
251
|
+
/** Edge end marker type */
|
|
121
252
|
marker?: MarkerType;
|
|
122
253
|
};
|
|
254
|
+
/** Edge properties */
|
|
123
255
|
type EdgeProps<N> = {
|
|
256
|
+
/** Edge ID */
|
|
124
257
|
id?: string;
|
|
258
|
+
/** Edge label */
|
|
125
259
|
label?: string;
|
|
260
|
+
/** Edge source */
|
|
126
261
|
source: EdgeEnd<N>;
|
|
262
|
+
/** Edge target */
|
|
127
263
|
target: EdgeEnd<N>;
|
|
264
|
+
/** Edge type */
|
|
128
265
|
type?: string;
|
|
129
266
|
};
|
|
267
|
+
/** Port properties */
|
|
130
268
|
type PortProps = {
|
|
269
|
+
/** Port ID */
|
|
131
270
|
id: string;
|
|
271
|
+
/** Port label */
|
|
132
272
|
label?: string;
|
|
133
273
|
};
|
|
274
|
+
/** Function to get node properties */
|
|
134
275
|
type GetNodeProps<N> = (node: N) => NodeProps<N>;
|
|
276
|
+
/** Function to get edge properties */
|
|
135
277
|
type GetEdgeProps<N, E> = (edge: E) => EdgeProps<N>;
|
|
136
278
|
|
|
279
|
+
type SegId = string;
|
|
280
|
+
|
|
281
|
+
type NodeId = string;
|
|
282
|
+
type PortData = {
|
|
283
|
+
id: string;
|
|
284
|
+
label?: string;
|
|
285
|
+
offset?: number;
|
|
286
|
+
size?: number;
|
|
287
|
+
};
|
|
288
|
+
type PublicNodeData = {
|
|
289
|
+
id: NodeId;
|
|
290
|
+
data: any;
|
|
291
|
+
version: number;
|
|
292
|
+
title?: string;
|
|
293
|
+
text?: string;
|
|
294
|
+
type?: string;
|
|
295
|
+
ports: {
|
|
296
|
+
in?: PortData[];
|
|
297
|
+
out?: PortData[];
|
|
298
|
+
};
|
|
299
|
+
render?: RenderNode<any>;
|
|
300
|
+
dims?: Dims;
|
|
301
|
+
};
|
|
302
|
+
|
|
303
|
+
type EdgeId = string;
|
|
304
|
+
type PublicEdgeData = {
|
|
305
|
+
id: string;
|
|
306
|
+
data: any;
|
|
307
|
+
label?: string;
|
|
308
|
+
source: {
|
|
309
|
+
id: string;
|
|
310
|
+
port?: string;
|
|
311
|
+
marker?: MarkerType;
|
|
312
|
+
};
|
|
313
|
+
target: {
|
|
314
|
+
id: string;
|
|
315
|
+
port?: string;
|
|
316
|
+
marker?: MarkerType;
|
|
317
|
+
};
|
|
318
|
+
type?: string;
|
|
319
|
+
};
|
|
320
|
+
|
|
137
321
|
declare class Updater<N, E> {
|
|
138
322
|
update: Update<N, E>;
|
|
139
323
|
constructor();
|
|
@@ -147,6 +331,21 @@ declare class Updater<N, E> {
|
|
|
147
331
|
static add<N, E>(nodes: N[], edges: E[]): Updater<N, E>;
|
|
148
332
|
}
|
|
149
333
|
|
|
334
|
+
type EditEdgeProps = {
|
|
335
|
+
id: string;
|
|
336
|
+
type?: string;
|
|
337
|
+
source: {
|
|
338
|
+
id: string;
|
|
339
|
+
port?: string;
|
|
340
|
+
marker?: MarkerType;
|
|
341
|
+
};
|
|
342
|
+
target: {
|
|
343
|
+
id: string;
|
|
344
|
+
port?: string;
|
|
345
|
+
marker?: MarkerType;
|
|
346
|
+
};
|
|
347
|
+
};
|
|
348
|
+
/** Core graph API */
|
|
150
349
|
declare class API<N, E> {
|
|
151
350
|
private state;
|
|
152
351
|
private seq;
|
|
@@ -157,27 +356,54 @@ declare class API<N, E> {
|
|
|
157
356
|
private nodeIds;
|
|
158
357
|
private edgeIds;
|
|
159
358
|
private nodeVersions;
|
|
359
|
+
private nodeOverrides;
|
|
360
|
+
private edgeOverrides;
|
|
361
|
+
private nodeFields;
|
|
160
362
|
private nextNodeId;
|
|
161
363
|
private nextEdgeId;
|
|
364
|
+
private events;
|
|
162
365
|
private root;
|
|
163
366
|
constructor(args: APIArguments<N, E>);
|
|
367
|
+
/** Current history index (0-based) */
|
|
368
|
+
getHistoryIndex(): number;
|
|
369
|
+
/** Current history length */
|
|
370
|
+
getHistoryLength(): number;
|
|
371
|
+
/** Toggle canvas editable mode without re-creating the graph */
|
|
372
|
+
setEditable(editable: boolean): void;
|
|
373
|
+
private get graph();
|
|
374
|
+
/** Initialize the API */
|
|
164
375
|
init(): Promise<void>;
|
|
376
|
+
/** Navigate to a different state */
|
|
165
377
|
nav(nav: Nav): void;
|
|
166
378
|
private applyDiff;
|
|
167
|
-
|
|
168
|
-
|
|
169
|
-
|
|
170
|
-
|
|
171
|
-
|
|
172
|
-
|
|
173
|
-
|
|
379
|
+
/** Add a node */
|
|
380
|
+
addNode(node: N): Promise<void>;
|
|
381
|
+
/** Delete a node */
|
|
382
|
+
deleteNode(node: N): Promise<void>;
|
|
383
|
+
/** Update a node */
|
|
384
|
+
updateNode(node: N): Promise<void>;
|
|
385
|
+
/** Add an edge */
|
|
386
|
+
addEdge(edge: E): Promise<void>;
|
|
387
|
+
/** Delete an edge */
|
|
388
|
+
deleteEdge(edge: E): Promise<void>;
|
|
389
|
+
/** Update an edge */
|
|
390
|
+
updateEdge(edge: E): Promise<void>;
|
|
391
|
+
/** Perform a batch of updates */
|
|
174
392
|
update(callback: (updater: Updater<N, E>) => void): Promise<void>;
|
|
393
|
+
/** Rebuild the graph from scratch (removes all then re-adds all nodes/edges) */
|
|
394
|
+
rebuild(): Promise<void>;
|
|
395
|
+
private applyUpdate;
|
|
396
|
+
private setNodePositions;
|
|
175
397
|
private measureNodes;
|
|
176
398
|
private parseNode;
|
|
399
|
+
private detectNodeFields;
|
|
400
|
+
getNodeFields(): Map<string, 'string' | 'number' | 'boolean'>;
|
|
177
401
|
private parseEdge;
|
|
178
402
|
private parseEdgeEnd;
|
|
179
403
|
private parseStringEdge;
|
|
180
404
|
private parsePorts;
|
|
405
|
+
getNode(id: NodeId): PublicNodeData;
|
|
406
|
+
getEdge(id: EdgeId): PublicEdgeData;
|
|
181
407
|
private getNodeId;
|
|
182
408
|
private getEdgeId;
|
|
183
409
|
private _addNode;
|
|
@@ -186,6 +412,18 @@ declare class API<N, E> {
|
|
|
186
412
|
private _addEdge;
|
|
187
413
|
private _removeEdge;
|
|
188
414
|
private _updateEdge;
|
|
415
|
+
handleClickNode(id: NodeId): void;
|
|
416
|
+
handleClickEdge(id: SegId): void;
|
|
417
|
+
handleNewNode(): Promise<void>;
|
|
418
|
+
handleNewNodeFrom(source: {
|
|
419
|
+
id: string;
|
|
420
|
+
port?: string;
|
|
421
|
+
}): Promise<void>;
|
|
422
|
+
handleEditNode(id: NodeId): Promise<void>;
|
|
423
|
+
handleEditEdge(id: SegId): Promise<void>;
|
|
424
|
+
handleAddEdge(data: EditEdgeProps): Promise<void>;
|
|
425
|
+
handleDeleteNode(id: NodeId): Promise<void>;
|
|
426
|
+
handleDeleteEdge(id: EdgeId): Promise<void>;
|
|
189
427
|
}
|
|
190
428
|
|
|
191
429
|
declare function graph<N, E>(args?: APIArguments<N, E>): Promise<API<N, E>>;
|