@html-graph/html-graph 0.0.47 → 0.0.48
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/README.md +2 -3
- package/dist/main.d.ts +49 -103
- package/dist/main.js +281 -378
- package/dist/main.umd.cjs +1 -1
- package/package.json +1 -1
package/README.md
CHANGED
|
@@ -6,8 +6,6 @@
|
|
|
6
6
|
|
|
7
7
|

|
|
8
8
|
|
|
9
|
-
Visit <a target="_blank" href="https://html-graph.github.io">live demo</a>
|
|
10
|
-
|
|
11
9
|
<a target="_blank" href="https://html-graph.github.io/">
|
|
12
10
|
<img width="100%" src="https://raw.githubusercontent.com/html-graph/html-graph/master/media/full-demo.gif"/>
|
|
13
11
|
</a>
|
|
@@ -17,6 +15,8 @@ Port is an entity of the node to which connection can be attached to.
|
|
|
17
15
|
|
|
18
16
|
This library fits for tasks where easy nodes customization and interactiveness are required.
|
|
19
17
|
|
|
18
|
+
Visit <a target="_blank" href="https://html-graph.github.io">live demo</a>
|
|
19
|
+
|
|
20
20
|
## Features:
|
|
21
21
|
|
|
22
22
|
- easy nodes customization using HTML
|
|
@@ -87,7 +87,6 @@ Use node version >= 20
|
|
|
87
87
|
|
|
88
88
|
```
|
|
89
89
|
npm install
|
|
90
|
-
|
|
91
90
|
npm run start
|
|
92
91
|
```
|
|
93
92
|
|
package/dist/main.d.ts
CHANGED
|
@@ -103,31 +103,19 @@ export declare interface Canvas {
|
|
|
103
103
|
/**
|
|
104
104
|
* applies transformation for viewport
|
|
105
105
|
*/
|
|
106
|
-
patchViewportState(
|
|
106
|
+
patchViewportState(request: PatchViewportRequest): Canvas;
|
|
107
107
|
/**
|
|
108
|
-
*
|
|
109
|
-
*/
|
|
110
|
-
moveViewport(apiTransform: MoveViewportRequest): Canvas;
|
|
111
|
-
/**
|
|
112
|
-
* applies scale transformation for content
|
|
113
|
-
*/
|
|
114
|
-
scaleViewport(apiTransform: ScaleViewportRequest): Canvas;
|
|
115
|
-
/**
|
|
116
|
-
* applies shift transformation for content
|
|
108
|
+
* moves viewport to nodes
|
|
117
109
|
*/
|
|
118
110
|
moveToNodes(nodeIds: readonly string[]): Canvas;
|
|
119
111
|
/**
|
|
120
112
|
* updates node absolute coordinates
|
|
121
113
|
*/
|
|
122
|
-
|
|
114
|
+
updateNodeCoordinates(nodeId: string, x: number, y: number): Canvas;
|
|
123
115
|
/**
|
|
124
116
|
* updates connection
|
|
125
117
|
*/
|
|
126
118
|
updateConnection(connectionId: string, request: UpdateConnectionRequest): Canvas;
|
|
127
|
-
/**
|
|
128
|
-
* drags node in viewport
|
|
129
|
-
*/
|
|
130
|
-
dragNode(nodeId: string, dx: number, dy: number): Canvas;
|
|
131
119
|
/**
|
|
132
120
|
* moves specified node on top
|
|
133
121
|
*/
|
|
@@ -172,13 +160,10 @@ export declare class CanvasCore implements Canvas {
|
|
|
172
160
|
unmarkPort(portId: string): CanvasCore;
|
|
173
161
|
addConnection(connection: AddConnectionRequest): CanvasCore;
|
|
174
162
|
removeConnection(connectionId: string): CanvasCore;
|
|
175
|
-
patchViewportState(
|
|
176
|
-
moveViewport(apiTransform: MoveViewportRequest): CanvasCore;
|
|
177
|
-
scaleViewport(apiTransform: ScaleViewportRequest): CanvasCore;
|
|
163
|
+
patchViewportState(request: PatchViewportRequest): CanvasCore;
|
|
178
164
|
moveToNodes(nodeIds: readonly string[]): CanvasCore;
|
|
179
|
-
|
|
165
|
+
updateNodeCoordinates(nodeId: string, x: number, y: number): CanvasCore;
|
|
180
166
|
updateConnection(connectionId: string, request: UpdateConnectionRequest): CanvasCore;
|
|
181
|
-
dragNode(nodeId: string, dx: number, dy: number): CanvasCore;
|
|
182
167
|
clear(): CanvasCore;
|
|
183
168
|
attach(element: HTMLElement): CanvasCore;
|
|
184
169
|
detach(): CanvasCore;
|
|
@@ -286,6 +271,7 @@ export declare class DraggableNodesCanvas implements Canvas {
|
|
|
286
271
|
readonly model: PublicGraphStore;
|
|
287
272
|
private readonly nodes;
|
|
288
273
|
private grabbedNodeId;
|
|
274
|
+
private onNodeDrag;
|
|
289
275
|
private readonly nodeIdGenerator;
|
|
290
276
|
private element;
|
|
291
277
|
private readonly onCanvasMouseUp;
|
|
@@ -294,7 +280,7 @@ export declare class DraggableNodesCanvas implements Canvas {
|
|
|
294
280
|
private readonly onCanvasTouchMove;
|
|
295
281
|
private readonly onCanvasTouchEnd;
|
|
296
282
|
private previousTouchCoords;
|
|
297
|
-
constructor(canvas: Canvas);
|
|
283
|
+
constructor(canvas: Canvas, dragOptions?: DragOptions);
|
|
298
284
|
addNode(node: AddNodeRequest): DraggableNodesCanvas;
|
|
299
285
|
removeNode(nodeId: string): DraggableNodesCanvas;
|
|
300
286
|
markPort(port: MarkPortRequest): DraggableNodesCanvas;
|
|
@@ -302,19 +288,23 @@ export declare class DraggableNodesCanvas implements Canvas {
|
|
|
302
288
|
unmarkPort(portId: string): DraggableNodesCanvas;
|
|
303
289
|
addConnection(connection: AddConnectionRequest): DraggableNodesCanvas;
|
|
304
290
|
removeConnection(connectionId: string): DraggableNodesCanvas;
|
|
305
|
-
patchViewportState(
|
|
306
|
-
moveViewport(apiTransform: MoveViewportRequest): DraggableNodesCanvas;
|
|
307
|
-
scaleViewport(apiTransform: ScaleViewportRequest): DraggableNodesCanvas;
|
|
291
|
+
patchViewportState(request: PatchViewportRequest): DraggableNodesCanvas;
|
|
308
292
|
moveToNodes(nodeIds: readonly string[]): DraggableNodesCanvas;
|
|
309
|
-
|
|
293
|
+
updateNodeCoordinates(nodeId: string, x: number, y: number): DraggableNodesCanvas;
|
|
310
294
|
updateConnection(connectionId: string, request: UpdateConnectionRequest): DraggableNodesCanvas;
|
|
311
|
-
dragNode(nodeId: string, dx: number, dy: number): DraggableNodesCanvas;
|
|
312
295
|
moveNodeOnTop(nodeId: string): DraggableNodesCanvas;
|
|
313
296
|
clear(): DraggableNodesCanvas;
|
|
314
297
|
attach(element: HTMLElement): DraggableNodesCanvas;
|
|
315
298
|
detach(): DraggableNodesCanvas;
|
|
316
299
|
destroy(): void;
|
|
317
300
|
private setCursor;
|
|
301
|
+
private dragNode;
|
|
302
|
+
}
|
|
303
|
+
|
|
304
|
+
export declare interface DragOptions {
|
|
305
|
+
events?: {
|
|
306
|
+
onNodeDrag?: (nodeId: string) => void;
|
|
307
|
+
};
|
|
318
308
|
}
|
|
319
309
|
|
|
320
310
|
declare class GraphStore {
|
|
@@ -326,9 +316,7 @@ declare class GraphStore {
|
|
|
326
316
|
private incommingConnections;
|
|
327
317
|
private outcommingConnections;
|
|
328
318
|
private cycleConnections;
|
|
329
|
-
getAllNodes():
|
|
330
|
-
getAllPorts(): readonly string[];
|
|
331
|
-
getAllConnections(): readonly string[];
|
|
319
|
+
getAllNodes(): Readonly<Record<string, NodePayload>>;
|
|
332
320
|
addNode(nodeId: string, element: HTMLElement, x: number, y: number, centerFn: CenterFn): void;
|
|
333
321
|
hasNode(nodeId: string): boolean;
|
|
334
322
|
getNode(nodeId: string): NodePayload;
|
|
@@ -344,24 +332,25 @@ declare class GraphStore {
|
|
|
344
332
|
getConnection(connectionId: string): ConnectionPayload;
|
|
345
333
|
hasConnection(connectionId: string): boolean;
|
|
346
334
|
removeConnection(connectionId: string): void;
|
|
347
|
-
getPortIncomingConnections(portId: string): readonly string[];
|
|
348
|
-
getPortOutcomingConnections(portId: string): readonly string[];
|
|
349
|
-
getPortCycleConnections(portId: string): readonly string[];
|
|
350
335
|
getPortAdjacentConnections(portId: string): readonly string[];
|
|
351
|
-
getNodeIncomingConnections(nodeId: string): readonly string[];
|
|
352
|
-
getNodeOutcomingConnections(nodeId: string): readonly string[];
|
|
353
|
-
getNodeCycleConnections(nodeId: string): readonly string[];
|
|
354
336
|
getNodeAdjacentConnections(nodeId: string): readonly string[];
|
|
355
337
|
clear(): void;
|
|
338
|
+
private getPortIncomingConnections;
|
|
339
|
+
private getPortOutcomingConnections;
|
|
340
|
+
private getPortCycleConnections;
|
|
341
|
+
private getNodeIncomingConnections;
|
|
342
|
+
private getNodeOutcomingConnections;
|
|
343
|
+
private getNodeCycleConnections;
|
|
356
344
|
}
|
|
357
345
|
|
|
358
346
|
export declare class HtmlGraphBuilder {
|
|
359
347
|
private coreOptions;
|
|
348
|
+
private dragOptions;
|
|
360
349
|
private transformOptions;
|
|
361
350
|
private isDraggable;
|
|
362
351
|
private isTransformable;
|
|
363
352
|
setOptions(options: CoreOptions): HtmlGraphBuilder;
|
|
364
|
-
setDraggableNodes(): HtmlGraphBuilder;
|
|
353
|
+
setDraggableNodes(dragOptions?: DragOptions): HtmlGraphBuilder;
|
|
365
354
|
setTransformableCanvas(options?: TransformOptions): HtmlGraphBuilder;
|
|
366
355
|
build(): Canvas;
|
|
367
356
|
}
|
|
@@ -382,9 +371,11 @@ export declare interface MarkPortRequest {
|
|
|
382
371
|
readonly direction?: number | null;
|
|
383
372
|
}
|
|
384
373
|
|
|
385
|
-
export declare interface
|
|
386
|
-
|
|
387
|
-
|
|
374
|
+
export declare interface NodeItem {
|
|
375
|
+
readonly id: string;
|
|
376
|
+
readonly x: number;
|
|
377
|
+
readonly y: number;
|
|
378
|
+
readonly element: HTMLElement;
|
|
388
379
|
}
|
|
389
380
|
|
|
390
381
|
declare interface NodePayload {
|
|
@@ -394,7 +385,13 @@ declare interface NodePayload {
|
|
|
394
385
|
centerFn: CenterFn;
|
|
395
386
|
}
|
|
396
387
|
|
|
397
|
-
export declare interface
|
|
388
|
+
export declare interface NodeResponse {
|
|
389
|
+
readonly x: number;
|
|
390
|
+
readonly y: number;
|
|
391
|
+
readonly element: HTMLElement;
|
|
392
|
+
}
|
|
393
|
+
|
|
394
|
+
export declare interface PatchViewportRequest {
|
|
398
395
|
scale?: number;
|
|
399
396
|
x?: number;
|
|
400
397
|
y?: number;
|
|
@@ -411,31 +408,8 @@ export declare interface PortPayload {
|
|
|
411
408
|
declare class PublicGraphStore {
|
|
412
409
|
private readonly graphStore;
|
|
413
410
|
constructor(graphStore: GraphStore);
|
|
414
|
-
getNode(nodeId: string):
|
|
415
|
-
|
|
416
|
-
y: number;
|
|
417
|
-
} | null;
|
|
418
|
-
getPort(portId: string): {
|
|
419
|
-
nodeId: string;
|
|
420
|
-
} | null;
|
|
421
|
-
getConnection(connectionId: string): {
|
|
422
|
-
from: string;
|
|
423
|
-
to: string;
|
|
424
|
-
} | null;
|
|
425
|
-
getAllNodes(): readonly string[];
|
|
426
|
-
getAllPorts(): readonly string[];
|
|
427
|
-
getAllConnections(): readonly string[];
|
|
428
|
-
hasNode(nodeId: string): boolean;
|
|
429
|
-
hasPort(portId: string): boolean;
|
|
430
|
-
hasConnection(connectionId: string): boolean;
|
|
431
|
-
getPortIncomingConnections(portId: string): readonly string[];
|
|
432
|
-
getPortOutcomingConnections(portId: string): readonly string[];
|
|
433
|
-
getPortCycleConnections(portId: string): readonly string[];
|
|
434
|
-
getPortAdjacentConnections(portId: string): readonly string[];
|
|
435
|
-
getNodeIncomingConnections(nodeId: string): readonly string[];
|
|
436
|
-
getNodeOutcomingConnections(nodeId: string): readonly string[];
|
|
437
|
-
getNodeCycleConnections(nodeId: string): readonly string[];
|
|
438
|
-
getNodeAdjacentConnections(nodeId: string): readonly string[];
|
|
411
|
+
getNode(nodeId: string): NodeResponse | null;
|
|
412
|
+
getNodes(ids?: readonly string[]): readonly NodeItem[];
|
|
439
413
|
}
|
|
440
414
|
|
|
441
415
|
export declare class PublicViewportTransformer {
|
|
@@ -463,12 +437,6 @@ export declare class PublicViewportTransformer {
|
|
|
463
437
|
getAbsScale(): number;
|
|
464
438
|
}
|
|
465
439
|
|
|
466
|
-
export declare interface ScaleViewportRequest {
|
|
467
|
-
scale: number;
|
|
468
|
-
x?: number;
|
|
469
|
-
y?: number;
|
|
470
|
-
}
|
|
471
|
-
|
|
472
440
|
export declare class StraightConnectionController implements ConnectionController {
|
|
473
441
|
private readonly color;
|
|
474
442
|
private readonly width;
|
|
@@ -505,10 +473,11 @@ export declare class TransformableCanvas implements Canvas {
|
|
|
505
473
|
private element;
|
|
506
474
|
private isMoving;
|
|
507
475
|
private prevTouches;
|
|
476
|
+
private onTransform;
|
|
508
477
|
private readonly isScalable;
|
|
509
478
|
private readonly isShiftable;
|
|
510
|
-
private readonly
|
|
511
|
-
private readonly
|
|
479
|
+
private readonly minViewScale;
|
|
480
|
+
private readonly maxViewScale;
|
|
512
481
|
private readonly wheelSensitivity;
|
|
513
482
|
private readonly onMouseDown;
|
|
514
483
|
private readonly onMouseMove;
|
|
@@ -525,21 +494,19 @@ export declare class TransformableCanvas implements Canvas {
|
|
|
525
494
|
unmarkPort(portId: string): TransformableCanvas;
|
|
526
495
|
addConnection(connection: AddConnectionRequest): TransformableCanvas;
|
|
527
496
|
removeConnection(connectionId: string): TransformableCanvas;
|
|
528
|
-
patchViewportState(
|
|
529
|
-
moveViewport(apiTransform: MoveViewportRequest): TransformableCanvas;
|
|
530
|
-
scaleViewport(apiTransform: ScaleViewportRequest): TransformableCanvas;
|
|
497
|
+
patchViewportState(request: PatchViewportRequest): TransformableCanvas;
|
|
531
498
|
moveToNodes(nodeIds: readonly string[]): TransformableCanvas;
|
|
532
|
-
|
|
499
|
+
updateNodeCoordinates(nodeId: string, x: number, y: number): TransformableCanvas;
|
|
533
500
|
updateConnection(connectionId: string, request: UpdateConnectionRequest): TransformableCanvas;
|
|
534
|
-
dragNode(nodeId: string, dx: number, dy: number): TransformableCanvas;
|
|
535
501
|
moveNodeOnTop(nodeId: string): TransformableCanvas;
|
|
536
502
|
clear(): TransformableCanvas;
|
|
537
503
|
attach(element: HTMLElement): TransformableCanvas;
|
|
538
504
|
detach(): TransformableCanvas;
|
|
539
505
|
destroy(): void;
|
|
540
506
|
private getAverageTouch;
|
|
541
|
-
private checkNextScaleValid;
|
|
542
507
|
private setCursor;
|
|
508
|
+
private moveViewport;
|
|
509
|
+
private scaleViewport;
|
|
543
510
|
}
|
|
544
511
|
|
|
545
512
|
export declare interface TransformOptions {
|
|
@@ -552,6 +519,9 @@ export declare interface TransformOptions {
|
|
|
552
519
|
shift?: {
|
|
553
520
|
enabled?: boolean;
|
|
554
521
|
};
|
|
522
|
+
events?: {
|
|
523
|
+
onTransform?: () => void;
|
|
524
|
+
};
|
|
555
525
|
}
|
|
556
526
|
|
|
557
527
|
declare interface UpdateConnectionRequest {
|
|
@@ -560,30 +530,6 @@ declare interface UpdateConnectionRequest {
|
|
|
560
530
|
|
|
561
531
|
declare class ViewportTransformer {
|
|
562
532
|
private state;
|
|
563
|
-
/**
|
|
564
|
-
* dx2 - traslate x
|
|
565
|
-
* dy2 - traslate y
|
|
566
|
-
*
|
|
567
|
-
* direct transform
|
|
568
|
-
* s1 0 dx1 1 0 dx2
|
|
569
|
-
* 0 s1 dy1 0 1 dy2
|
|
570
|
-
* 0 0 1 0 0 1
|
|
571
|
-
*
|
|
572
|
-
* [s, dx, dy] = [s1, s * dx2 + dx1, s * dy2 + dy1]
|
|
573
|
-
*/
|
|
574
|
-
applyShift(dx: number, dy: number): void;
|
|
575
|
-
/**
|
|
576
|
-
* s2 - scale
|
|
577
|
-
* cx - scale pivot x
|
|
578
|
-
* cy - scale pivot y
|
|
579
|
-
*
|
|
580
|
-
* s1 0 dx1 s2 0 (1 - s2) * cx
|
|
581
|
-
* 0 s1 dy1 0 s2 (1 - s2) * cy
|
|
582
|
-
* 0 0 1 0 0 1
|
|
583
|
-
*
|
|
584
|
-
* [s, dx, dy] = [s1 * s2, s1 * (1 - s2) * cx + dx1, s1 * (1 - s2) * cy + dy1]
|
|
585
|
-
*/
|
|
586
|
-
applyScale(s2: number, cx: number, cy: number): void;
|
|
587
533
|
getViewCoords(xa: number, ya: number): [number, number];
|
|
588
534
|
getViewScale(): number;
|
|
589
535
|
getAbsCoords(xv: number, yv: number): [number, number];
|