@3plate/graph-core 0.1.2 → 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 +2378 -812
- package/dist/index.d.cts +368 -70
- package/dist/index.d.ts +368 -70
- package/dist/index.js +2370 -814
- package/package.json +2 -1
package/dist/index.d.cts
CHANGED
|
@@ -2,132 +2,430 @@ type Side = 'source' | 'target';
|
|
|
2
2
|
type MergeOrder = Side[];
|
|
3
3
|
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
|
|
|
12
|
+
type MarkerType = 'arrow' | 'circle' | 'diamond' | 'bar' | 'none';
|
|
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
|
+
*/
|
|
22
|
+
type APIArguments<N, E> = {
|
|
23
|
+
/** Options for the API */
|
|
24
|
+
options?: APIOptions<N, E>;
|
|
25
|
+
/** Initial nodes */
|
|
26
|
+
nodes?: N[];
|
|
27
|
+
/** Initial edges */
|
|
28
|
+
edges?: E[];
|
|
29
|
+
/** Initial history */
|
|
30
|
+
history?: Update<N, E>[];
|
|
31
|
+
/** Events */
|
|
32
|
+
events?: EventsOptions<N, E>;
|
|
33
|
+
/** Root element ID */
|
|
34
|
+
root: string;
|
|
35
|
+
};
|
|
36
|
+
/** Options for the API */
|
|
37
|
+
type APIOptions<N, E> = {
|
|
38
|
+
/** Options for the graph */
|
|
39
|
+
graph?: GraphOptions;
|
|
40
|
+
/** Options for the canvas */
|
|
41
|
+
canvas?: CanvasOptions<N>;
|
|
42
|
+
/** Options for node and edge properties */
|
|
43
|
+
props?: PropsOptions<N, E>;
|
|
44
|
+
};
|
|
45
|
+
/** Options for the graph */
|
|
8
46
|
type GraphOptions = {
|
|
47
|
+
/** Order in which edges are merged; see `MergeOrder` */
|
|
9
48
|
mergeOrder?: MergeOrder;
|
|
49
|
+
/** Margin between nodes */
|
|
10
50
|
nodeMargin?: number;
|
|
51
|
+
/** Size of dummy nodes */
|
|
11
52
|
dummyNodeSize?: number;
|
|
12
|
-
|
|
53
|
+
/** Alignment of nodes */
|
|
13
54
|
nodeAlign?: NodeAlign;
|
|
55
|
+
/** Spacing between edges */
|
|
14
56
|
edgeSpacing?: number;
|
|
57
|
+
/** Turn radius */
|
|
15
58
|
turnRadius?: number;
|
|
59
|
+
/** Orientation of the graph */
|
|
16
60
|
orientation?: Orientation;
|
|
61
|
+
/** Margin between layers */
|
|
17
62
|
layerMargin?: number;
|
|
63
|
+
/** Number of iterations for alignment */
|
|
18
64
|
alignIterations?: number;
|
|
65
|
+
/** Alignment threshold */
|
|
19
66
|
alignThreshold?: number;
|
|
67
|
+
/** Whether to separate track sets */
|
|
20
68
|
separateTrackSets?: boolean;
|
|
69
|
+
/** Marker size */
|
|
70
|
+
markerSize?: number;
|
|
71
|
+
/** Layout steps */
|
|
21
72
|
layoutSteps?: LayoutStep[] | null;
|
|
22
73
|
};
|
|
23
|
-
|
|
24
|
-
|
|
25
|
-
|
|
26
|
-
|
|
27
|
-
|
|
28
|
-
|
|
29
|
-
|
|
30
|
-
|
|
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 */
|
|
106
|
+
type ColorMode = 'light' | 'dark' | 'system';
|
|
107
|
+
/** Canvas background and general colors */
|
|
108
|
+
type CanvasTheme = {
|
|
109
|
+
/** Canvas background color */
|
|
110
|
+
bg?: string;
|
|
111
|
+
/** Shadow color for floating elements */
|
|
112
|
+
shadow?: string;
|
|
31
113
|
};
|
|
32
|
-
|
|
33
|
-
|
|
34
|
-
|
|
114
|
+
/** Node styling properties */
|
|
115
|
+
type NodeTheme = {
|
|
116
|
+
/** Node background color */
|
|
117
|
+
bg?: string;
|
|
118
|
+
/** Node border color */
|
|
119
|
+
border?: string;
|
|
120
|
+
/** Node border color on hover */
|
|
121
|
+
borderHover?: string;
|
|
122
|
+
/** Node border color when selected */
|
|
123
|
+
borderSelected?: string;
|
|
124
|
+
/** Node text color */
|
|
125
|
+
text?: string;
|
|
126
|
+
/** Node secondary text color */
|
|
127
|
+
textMuted?: string;
|
|
35
128
|
};
|
|
36
|
-
|
|
37
|
-
type
|
|
38
|
-
|
|
39
|
-
|
|
129
|
+
/** Port styling properties */
|
|
130
|
+
type PortTheme = {
|
|
131
|
+
/** Port background color */
|
|
132
|
+
bg?: string;
|
|
133
|
+
/** Port background color on hover */
|
|
134
|
+
bgHover?: string;
|
|
135
|
+
};
|
|
136
|
+
/** Edge styling properties */
|
|
137
|
+
type EdgeTheme = {
|
|
138
|
+
/** Edge stroke color */
|
|
139
|
+
color?: string;
|
|
140
|
+
};
|
|
141
|
+
/** Combined theme with all customizable properties */
|
|
142
|
+
type ThemeVars = CanvasTheme & NodeTheme & PortTheme & EdgeTheme;
|
|
143
|
+
/** Options for the canvas */
|
|
40
144
|
type CanvasOptions<N> = {
|
|
41
|
-
|
|
42
|
-
nodeStyle?: NodeStyle<N>;
|
|
43
|
-
edgeStyle?: EdgeStyle;
|
|
145
|
+
/** Canvas width in pixels or percentage */
|
|
44
146
|
width?: number | string;
|
|
147
|
+
/** Canvas height in pixels or percentage */
|
|
45
148
|
height?: number | string;
|
|
46
|
-
|
|
47
|
-
|
|
149
|
+
/** Padding inside the canvas viewport */
|
|
150
|
+
padding?: number;
|
|
151
|
+
/** Whether the canvas is editable */
|
|
152
|
+
editable?: boolean;
|
|
153
|
+
/** Whether to enable pan and zoom */
|
|
154
|
+
panZoom?: boolean;
|
|
155
|
+
/** Function to render a node */
|
|
156
|
+
renderNode?: RenderNode<N>;
|
|
157
|
+
/** Color mode */
|
|
158
|
+
colorMode?: ColorMode;
|
|
159
|
+
/** Theme */
|
|
160
|
+
theme?: ThemeVars;
|
|
161
|
+
/** Node type themes */
|
|
162
|
+
nodeTypes?: Record<string, ThemeVars>;
|
|
163
|
+
/** Edge type themes */
|
|
164
|
+
edgeTypes?: Record<string, ThemeVars>;
|
|
165
|
+
/** Marker size in pixels */
|
|
166
|
+
markerSize?: number;
|
|
167
|
+
};
|
|
168
|
+
/** Options for node and edge properties */
|
|
169
|
+
type PropsOptions<N, E> = {
|
|
170
|
+
/** Function to get node properties */
|
|
171
|
+
node?: GetNodeProps<N>;
|
|
172
|
+
/** Function to get edge properties */
|
|
173
|
+
edge?: GetEdgeProps<N, E>;
|
|
174
|
+
};
|
|
175
|
+
/** Update to apply to the graph */
|
|
176
|
+
type Update<N, E> = {
|
|
177
|
+
/** Nodes to add */
|
|
178
|
+
addNodes?: N[];
|
|
179
|
+
/** Nodes to remove */
|
|
180
|
+
removeNodes?: N[];
|
|
181
|
+
/** Nodes to update */
|
|
182
|
+
updateNodes?: N[];
|
|
183
|
+
/** Edges to add */
|
|
184
|
+
addEdges?: E[];
|
|
185
|
+
/** Edges to remove */
|
|
186
|
+
removeEdges?: E[];
|
|
187
|
+
/** Edges to update */
|
|
188
|
+
updateEdges?: E[];
|
|
189
|
+
/** Description of the update */
|
|
190
|
+
description?: string;
|
|
191
|
+
};
|
|
192
|
+
/** Node properties */
|
|
193
|
+
type NodeProps<N> = NewNode & {
|
|
194
|
+
/** Node ID */
|
|
195
|
+
id?: string;
|
|
196
|
+
/** Function to render a node */
|
|
197
|
+
render?: RenderNode<N>;
|
|
198
|
+
};
|
|
199
|
+
/** New node properties */
|
|
200
|
+
type NewNode = {
|
|
201
|
+
/** Node title */
|
|
202
|
+
title?: string;
|
|
203
|
+
/** Node text */
|
|
204
|
+
text?: string;
|
|
205
|
+
/** Node type */
|
|
206
|
+
type?: string;
|
|
207
|
+
/** Node ports */
|
|
208
|
+
ports?: {
|
|
209
|
+
/** Input ports */
|
|
210
|
+
in?: (string | PortProps)[];
|
|
211
|
+
/** Output ports */
|
|
212
|
+
out?: (string | PortProps)[];
|
|
213
|
+
};
|
|
214
|
+
};
|
|
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 */
|
|
239
|
+
id: string;
|
|
240
|
+
/** Edge end port ID */
|
|
241
|
+
port?: string;
|
|
242
|
+
/** Edge end marker type */
|
|
243
|
+
marker?: MarkerType;
|
|
244
|
+
} |
|
|
245
|
+
/** Structured edge end with node object */
|
|
246
|
+
{
|
|
247
|
+
/** Edge end node object */
|
|
248
|
+
node: N;
|
|
249
|
+
/** Edge end port ID */
|
|
250
|
+
port?: string;
|
|
251
|
+
/** Edge end marker type */
|
|
252
|
+
marker?: MarkerType;
|
|
48
253
|
};
|
|
254
|
+
/** Edge properties */
|
|
255
|
+
type EdgeProps<N> = {
|
|
256
|
+
/** Edge ID */
|
|
257
|
+
id?: string;
|
|
258
|
+
/** Edge label */
|
|
259
|
+
label?: string;
|
|
260
|
+
/** Edge source */
|
|
261
|
+
source: EdgeEnd<N>;
|
|
262
|
+
/** Edge target */
|
|
263
|
+
target: EdgeEnd<N>;
|
|
264
|
+
/** Edge type */
|
|
265
|
+
type?: string;
|
|
266
|
+
};
|
|
267
|
+
/** Port properties */
|
|
268
|
+
type PortProps = {
|
|
269
|
+
/** Port ID */
|
|
270
|
+
id: string;
|
|
271
|
+
/** Port label */
|
|
272
|
+
label?: string;
|
|
273
|
+
};
|
|
274
|
+
/** Function to get node properties */
|
|
275
|
+
type GetNodeProps<N> = (node: N) => NodeProps<N>;
|
|
276
|
+
/** Function to get edge properties */
|
|
277
|
+
type GetEdgeProps<N, E> = (edge: E) => EdgeProps<N>;
|
|
278
|
+
|
|
279
|
+
type SegId = string;
|
|
49
280
|
|
|
50
|
-
type
|
|
281
|
+
type NodeId = string;
|
|
282
|
+
type PortData = {
|
|
51
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;
|
|
52
292
|
title?: string;
|
|
53
293
|
text?: string;
|
|
54
|
-
|
|
55
|
-
|
|
56
|
-
|
|
294
|
+
type?: string;
|
|
295
|
+
ports: {
|
|
296
|
+
in?: PortData[];
|
|
297
|
+
out?: PortData[];
|
|
57
298
|
};
|
|
299
|
+
render?: RenderNode<any>;
|
|
300
|
+
dims?: Dims;
|
|
58
301
|
};
|
|
59
|
-
|
|
302
|
+
|
|
303
|
+
type EdgeId = string;
|
|
304
|
+
type PublicEdgeData = {
|
|
305
|
+
id: string;
|
|
306
|
+
data: any;
|
|
307
|
+
label?: string;
|
|
60
308
|
source: {
|
|
61
309
|
id: string;
|
|
62
310
|
port?: string;
|
|
311
|
+
marker?: MarkerType;
|
|
63
312
|
};
|
|
64
313
|
target: {
|
|
65
314
|
id: string;
|
|
66
315
|
port?: string;
|
|
316
|
+
marker?: MarkerType;
|
|
67
317
|
};
|
|
68
318
|
type?: string;
|
|
69
319
|
};
|
|
70
|
-
|
|
320
|
+
|
|
321
|
+
declare class Updater<N, E> {
|
|
322
|
+
update: Update<N, E>;
|
|
323
|
+
constructor();
|
|
324
|
+
describe(desc: string): Updater<N, E>;
|
|
325
|
+
addNode(node: any): Updater<N, E>;
|
|
326
|
+
deleteNode(node: any): Updater<N, E>;
|
|
327
|
+
updateNode(node: any): Updater<N, E>;
|
|
328
|
+
addEdge(edge: any): Updater<N, E>;
|
|
329
|
+
deleteEdge(edge: any): Updater<N, E>;
|
|
330
|
+
updateEdge(edge: any): Updater<N, E>;
|
|
331
|
+
static add<N, E>(nodes: N[], edges: E[]): Updater<N, E>;
|
|
332
|
+
}
|
|
333
|
+
|
|
334
|
+
type EditEdgeProps = {
|
|
71
335
|
id: string;
|
|
72
|
-
|
|
73
|
-
|
|
74
|
-
|
|
75
|
-
|
|
76
|
-
|
|
77
|
-
|
|
78
|
-
|
|
79
|
-
|
|
80
|
-
|
|
81
|
-
|
|
82
|
-
};
|
|
83
|
-
type APIArguments<N, E, P> = APIOptions<N, E, P> & {
|
|
84
|
-
nodes?: N[];
|
|
85
|
-
edges?: E[];
|
|
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
|
+
};
|
|
86
347
|
};
|
|
87
|
-
|
|
348
|
+
/** Core graph API */
|
|
349
|
+
declare class API<N, E> {
|
|
88
350
|
private state;
|
|
89
351
|
private seq;
|
|
90
352
|
private index;
|
|
91
353
|
private canvas;
|
|
92
|
-
private
|
|
93
|
-
|
|
94
|
-
|
|
95
|
-
|
|
354
|
+
private options;
|
|
355
|
+
private history;
|
|
356
|
+
private nodeIds;
|
|
357
|
+
private edgeIds;
|
|
358
|
+
private nodeVersions;
|
|
359
|
+
private nodeOverrides;
|
|
360
|
+
private edgeOverrides;
|
|
361
|
+
private nodeFields;
|
|
362
|
+
private nextNodeId;
|
|
363
|
+
private nextEdgeId;
|
|
364
|
+
private events;
|
|
365
|
+
private root;
|
|
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 */
|
|
375
|
+
init(): Promise<void>;
|
|
376
|
+
/** Navigate to a different state */
|
|
96
377
|
nav(nav: Nav): void;
|
|
97
378
|
private applyDiff;
|
|
379
|
+
/** Add a node */
|
|
98
380
|
addNode(node: N): Promise<void>;
|
|
381
|
+
/** Delete a node */
|
|
99
382
|
deleteNode(node: N): Promise<void>;
|
|
383
|
+
/** Update a node */
|
|
100
384
|
updateNode(node: N): Promise<void>;
|
|
385
|
+
/** Add an edge */
|
|
101
386
|
addEdge(edge: E): Promise<void>;
|
|
387
|
+
/** Delete an edge */
|
|
102
388
|
deleteEdge(edge: E): Promise<void>;
|
|
103
|
-
|
|
389
|
+
/** Update an edge */
|
|
390
|
+
updateEdge(edge: E): Promise<void>;
|
|
391
|
+
/** Perform a batch of updates */
|
|
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;
|
|
104
397
|
private measureNodes;
|
|
105
|
-
private
|
|
106
|
-
private
|
|
107
|
-
|
|
398
|
+
private parseNode;
|
|
399
|
+
private detectNodeFields;
|
|
400
|
+
getNodeFields(): Map<string, 'string' | 'number' | 'boolean'>;
|
|
401
|
+
private parseEdge;
|
|
402
|
+
private parseEdgeEnd;
|
|
403
|
+
private parseStringEdge;
|
|
404
|
+
private parsePorts;
|
|
405
|
+
getNode(id: NodeId): PublicNodeData;
|
|
406
|
+
getEdge(id: EdgeId): PublicEdgeData;
|
|
407
|
+
private getNodeId;
|
|
408
|
+
private getEdgeId;
|
|
108
409
|
private _addNode;
|
|
109
410
|
private _removeNode;
|
|
411
|
+
private _updateNode;
|
|
110
412
|
private _addEdge;
|
|
111
413
|
private _removeEdge;
|
|
112
|
-
private
|
|
113
|
-
|
|
114
|
-
|
|
115
|
-
|
|
116
|
-
|
|
117
|
-
|
|
118
|
-
|
|
119
|
-
|
|
120
|
-
|
|
121
|
-
|
|
122
|
-
|
|
123
|
-
|
|
124
|
-
|
|
125
|
-
deleteNode(node: N): void;
|
|
126
|
-
updateNode(node: N): void;
|
|
127
|
-
addEdge(edge: E): void;
|
|
128
|
-
deleteEdge(edge: E): void;
|
|
129
|
-
updateEdge(edge: E): void;
|
|
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>;
|
|
130
427
|
}
|
|
131
|
-
|
|
428
|
+
|
|
429
|
+
declare function graph<N, E>(args?: APIArguments<N, E>): Promise<API<N, E>>;
|
|
132
430
|
|
|
133
431
|
export { graph as default, graph };
|