@html-graph/html-graph 0.0.56 → 0.0.58

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 CHANGED
@@ -6,21 +6,21 @@
6
6
 
7
7
  ![CI](https://github.com/html-graph/html-graph/actions/workflows/ci.yml/badge.svg?branch=master)
8
8
 
9
- <a target="_blank" href="https://html-graph.github.io/">
9
+ <a target="_blank" href="https://html-graph.github.io/use-cases/20-advanced-demo/index.html">
10
10
  <img width="100%" src="https://raw.githubusercontent.com/html-graph/html-graph/master/media/full-demo.gif"/>
11
11
  </a>
12
12
 
13
- Visit <a target="_blank" href="https://html-graph.github.io">live demo</a>.
14
-
15
13
  Instead of connecting nodes directly this library uses concept of ports, which provide greater fexibility at managing edges.
16
14
  Port is an entity of a node to which edge can be attached to.
17
15
 
16
+ Visit <a target="_blank" href="https://html-graph.github.io">use cases</a> and [use cases implementation](use-cases).
17
+
18
18
  ## Features:
19
19
 
20
20
  - easy nodes customization using HTML
21
21
  - wide configuration options out of the box
22
22
  - draggable and scalable canvas with draggable nodes
23
- - exhaustive set of examples
23
+ - exhaustive set of use cases
24
24
  - typescript support
25
25
  - mobile devices support
26
26
 
@@ -30,8 +30,8 @@ Port is an entity of a node to which edge can be attached to.
30
30
  npm i @html-graph/html-graph
31
31
  ```
32
32
 
33
- ```typescript
34
- import { HtmlGraphBuilder, AddNodeRequest } from "@html-graph/html-graph";
33
+ ```javascript
34
+ import { HtmlGraphBuilder } from "@html-graph/html-graph";
35
35
 
36
36
  const canvas = new HtmlGraphBuilder()
37
37
  .setOptions({
@@ -48,27 +48,20 @@ const canvas = new HtmlGraphBuilder()
48
48
  .setUserTransformableCanvas()
49
49
  .build();
50
50
 
51
- function createNode(
52
- name: string,
53
- x: number,
54
- y: number,
55
- frontPortId: string,
56
- backPortId: string,
57
- ): AddNodeRequest {
51
+ function createNode({ name, x, y, frontPortId, backPortId }) {
58
52
  const node = document.createElement("div");
59
- node.classList.add("node");
60
-
53
+ const text = document.createElement("div");
61
54
  const frontPort = document.createElement("div");
62
- frontPort.classList.add("port");
63
- node.appendChild(frontPort);
55
+ const backPort = document.createElement("div");
64
56
 
65
- const text = document.createElement("div");
57
+ node.classList.add("node");
58
+ frontPort.classList.add("port");
59
+ backPort.classList.add("port");
66
60
  text.innerText = name;
67
- node.appendChild(text);
68
61
 
69
- const backPort = document.createElement("div");
70
- backPort.classList.add("port");
71
62
  node.appendChild(backPort);
63
+ node.appendChild(text);
64
+ node.appendChild(frontPort);
72
65
 
73
66
  return {
74
67
  element: node,
@@ -81,10 +74,23 @@ function createNode(
81
74
  };
82
75
  }
83
76
 
84
- const node1 = createNode("Node 1", 200, 400, "port-1-1", "port-1-2");
85
- const node2 = createNode("Node 2", 600, 500, "port-2-1", "port-2-2");
77
+ const node1 = createNode({
78
+ name: "Node 1",
79
+ x: 200,
80
+ y: 400,
81
+ frontPortId: "port-1-1",
82
+ backPortId: "port-1-2",
83
+ });
86
84
 
87
- const canvasElement = document.getElementById("canvas")!;
85
+ const node2 = createNode({
86
+ name: "Node 2",
87
+ x: 600,
88
+ y: 500,
89
+ frontPortId: "port-2-1",
90
+ backPortId: "port-2-2",
91
+ });
92
+
93
+ const canvasElement = document.getElementById("canvas");
88
94
 
89
95
  canvas
90
96
  .attach(canvasElement)
@@ -93,9 +99,7 @@ canvas
93
99
  .addEdge({ from: "port-1-2", to: "port-2-1" });
94
100
  ```
95
101
 
96
- Refer to [Use cases](use-cases) for more.
97
-
98
- ## Run examples
102
+ ## Run use cases
99
103
 
100
104
  ```
101
105
  npm install
package/dist/main.d.ts CHANGED
@@ -1,3 +1,10 @@
1
+ declare interface AbstractViewportTransformer {
2
+ getViewportMatrix(): TransformState;
3
+ getContentMatrix(): TransformState;
4
+ patchViewportMatrix(scale: number | null, x: number | null, y: number | null): void;
5
+ patchContentMatrix(scale: number | null, dx: number | null, dy: number | null): void;
6
+ }
7
+
1
8
  export declare interface AddEdgeRequest {
2
9
  readonly id?: unknown;
3
10
  readonly from: string;
@@ -28,14 +35,13 @@ declare type BackgroundOptions = {
28
35
  readonly dotGap?: number;
29
36
  readonly dotRadius?: number;
30
37
  readonly color?: string;
38
+ readonly limit?: number;
31
39
  } | {
32
40
  readonly type: "custom";
33
41
  readonly drawingFn: BackgroundDrawingFn;
34
42
  };
35
43
 
36
44
  export declare class BezierEdgeShape implements EdgeShape {
37
- private readonly color;
38
- private readonly width;
39
45
  private readonly curvature;
40
46
  private readonly arrowLength;
41
47
  private readonly arrowWidth;
@@ -45,7 +51,8 @@ export declare class BezierEdgeShape implements EdgeShape {
45
51
  private readonly sourceArrow;
46
52
  private readonly targetArrow;
47
53
  constructor(color: string, width: number, curvature: number, arrowLength: number, arrowWidth: number, hasSourceArrow: boolean, hasTargetArrow: boolean);
48
- update(x: number, y: number, width: number, height: number, from: PortPayload, to: PortPayload): void;
54
+ update(to: Point, flipX: number, flipY: number, fromDir: number, toDir: number): void;
55
+ private createLinePath;
49
56
  }
50
57
 
51
58
  declare interface BezierEdgeShape_2 {
@@ -155,7 +162,7 @@ export declare class CanvasCore implements Canvas {
155
162
  updateNode(nodeId: unknown, request: UpdateNodeRequest): CanvasCore;
156
163
  removeNode(nodeId: unknown): CanvasCore;
157
164
  markPort(port: MarkPortRequest): CanvasCore;
158
- updatePort(portId: string, request: UpdatePortRequest): CanvasCore;
165
+ updatePort(portId: string, request?: UpdatePortRequest): CanvasCore;
159
166
  unmarkPort(portId: string): CanvasCore;
160
167
  addEdge(edge: AddEdgeRequest): CanvasCore;
161
168
  updateEdge(edgeId: unknown, request: UpdateEdgeRequest): CanvasCore;
@@ -284,8 +291,6 @@ declare interface CustomEdgeShape {
284
291
  declare type CustomPriority = PriorityFn;
285
292
 
286
293
  export declare class CycleCircleEdgeShape implements EdgeShape {
287
- private readonly color;
288
- private readonly width;
289
294
  private readonly arrowLength;
290
295
  private readonly arrowWidth;
291
296
  private readonly radius;
@@ -295,12 +300,11 @@ export declare class CycleCircleEdgeShape implements EdgeShape {
295
300
  private readonly line;
296
301
  private readonly arrow;
297
302
  constructor(color: string, width: number, arrowLength: number, arrowWidth: number, hasArrow: boolean, radius: number, smallRadius: number);
298
- update(x: number, y: number, _width: number, _height: number, from: PortPayload): void;
303
+ update(_to: Point, flipX: number, flipY: number, fromDir: number): void;
304
+ private createLinePath;
299
305
  }
300
306
 
301
307
  export declare class CycleSquareEdgeShape implements EdgeShape {
302
- private readonly color;
303
- private readonly width;
304
308
  private readonly arrowLength;
305
309
  private readonly arrowWidth;
306
310
  private readonly side;
@@ -312,12 +316,11 @@ export declare class CycleSquareEdgeShape implements EdgeShape {
312
316
  private readonly roundness;
313
317
  private readonly linePoints;
314
318
  constructor(color: string, width: number, arrowLength: number, arrowWidth: number, hasArrow: boolean, side: number, minPortOffset: number, roundness: number);
315
- update(x: number, y: number, _width: number, _height: number, from: PortPayload): void;
319
+ update(_to: Point, flipX: number, flipY: number, fromDir: number): void;
320
+ private createLinePath;
316
321
  }
317
322
 
318
323
  export declare class DetourStraightEdgeShape implements EdgeShape {
319
- private readonly color;
320
- private readonly width;
321
324
  private readonly arrowLength;
322
325
  private readonly arrowWidth;
323
326
  private readonly arrowOffset;
@@ -330,11 +333,13 @@ export declare class DetourStraightEdgeShape implements EdgeShape {
330
333
  private readonly detourX;
331
334
  private readonly detourY;
332
335
  constructor(color: string, width: number, arrowLength: number, arrowWidth: number, arrowOffset: number, hasSourceArrow: boolean, hasTargetArrow: boolean, roundness: number, detourDistance: number, detourDirection: number);
333
- update(x: number, y: number, width: number, height: number, from: PortPayload, to: PortPayload): void;
336
+ update(to: Point, flipX: number, flipY: number, fromDir: number, toDir: number): void;
337
+ private createLinePath;
334
338
  }
335
339
 
336
340
  export declare interface DragOptions {
337
341
  grabPriorityStrategy?: "freeze" | "move-on-top";
342
+ dragCursor?: string | null;
338
343
  events?: {
339
344
  onNodeDrag?: (payload: NodeDragPayload) => void;
340
345
  onBeforeNodeDrag?: (payload: NodeDragPayload) => boolean;
@@ -342,15 +347,15 @@ export declare interface DragOptions {
342
347
  }
343
348
 
344
349
  declare interface EdgePayload {
345
- from: string;
346
- to: string;
350
+ readonly from: unknown;
351
+ readonly to: unknown;
347
352
  shape: EdgeShape;
348
353
  priority: number;
349
354
  }
350
355
 
351
356
  export declare interface EdgeShape {
352
357
  readonly svg: SVGSVGElement;
353
- update(x: number, y: number, width: number, height: number, from: PortPayload, to: PortPayload): void;
358
+ update(to: Point, flipX: number, flipY: number, fromDir: number, toDir: number): void;
354
359
  }
355
360
 
356
361
  declare type EdgeShape_2 = BezierEdgeShape_2 | StraightEdgeShape_2 | CustomEdgeShape | HorizontalEdgeShape_2 | VerticalEdgeShape_2;
@@ -393,33 +398,31 @@ declare class GraphStore {
393
398
  private readonly outcommingEdges;
394
399
  private readonly cycleEdges;
395
400
  addNode(nodeId: unknown, element: HTMLElement, x: number, y: number, centerFn: CenterFn, priority: number): void;
396
- getAllNodes(): readonly unknown[];
401
+ getAllNodeIds(): readonly unknown[];
397
402
  getNode(nodeId: unknown): NodePayload | undefined;
398
- getNodePorts(nodeId: unknown): readonly unknown[] | undefined;
399
403
  removeNode(nodeId: unknown): void;
400
404
  addPort(portId: unknown, element: HTMLElement, nodeId: unknown, centerFn: CenterFn, dir: number): void;
401
- getAllPorts(): readonly unknown[];
402
405
  getPort(portId: unknown): PortPayload | undefined;
403
- getPortNode(portId: unknown): unknown | undefined;
406
+ getAllPortIds(): readonly unknown[];
407
+ getNodePortIds(nodeId: unknown): readonly unknown[] | undefined;
408
+ getPortNodeId(portId: unknown): unknown | undefined;
404
409
  removePort(portId: unknown): void;
405
- addEdge(edgeId: unknown, fromPortId: string, toPortId: string, shape: EdgeShape, priority: number): void;
406
- getAllEdges(): readonly unknown[];
410
+ addEdge(edgeId: unknown, fromPortId: unknown, toPortId: unknown, shape: EdgeShape, priority: number): void;
411
+ getAllEdgeIds(): readonly unknown[];
407
412
  getEdge(edgeId: unknown): EdgePayload | undefined;
408
413
  removeEdge(edgeId: unknown): void;
409
- getPortAdjacentEdges(portId: string): readonly unknown[];
410
- getNodeAdjacentEdges(nodeId: unknown): readonly unknown[];
411
414
  clear(): void;
412
- getPortIncomingEdges(portId: unknown): readonly unknown[];
413
- getPortOutcomingEdges(portId: unknown): readonly unknown[];
414
- getPortCycleEdges(portId: unknown): readonly unknown[];
415
- getNodeIncomingEdges(nodeId: unknown): readonly unknown[];
416
- getNodeOutcomingEdges(nodeId: unknown): readonly unknown[];
417
- getNodeCycleEdges(nodeId: unknown): readonly unknown[];
415
+ getPortIncomingEdgeIds(portId: unknown): readonly unknown[];
416
+ getPortOutcomingEdgeIds(portId: unknown): readonly unknown[];
417
+ getPortCycleEdgeIds(portId: unknown): readonly unknown[];
418
+ getPortAdjacentEdgeIds(portId: unknown): readonly unknown[];
419
+ getNodeIncomingEdgeIds(nodeId: unknown): readonly unknown[];
420
+ getNodeOutcomingEdgeIds(nodeId: unknown): readonly unknown[];
421
+ getNodeCycleEdgeIds(nodeId: unknown): readonly unknown[];
422
+ getNodeAdjacentEdgeIds(nodeId: unknown): readonly unknown[];
418
423
  }
419
424
 
420
425
  export declare class HorizontalEdgeShape implements EdgeShape {
421
- private readonly color;
422
- private readonly width;
423
426
  private readonly arrowLength;
424
427
  private readonly arrowWidth;
425
428
  private readonly arrowOffset;
@@ -430,7 +433,8 @@ export declare class HorizontalEdgeShape implements EdgeShape {
430
433
  private readonly sourceArrow;
431
434
  private readonly targetArrow;
432
435
  constructor(color: string, width: number, arrowLength: number, arrowWidth: number, arrowOffset: number, hasSourceArrow: boolean, hasTargetArrow: boolean, roundness: number);
433
- update(x: number, y: number, width: number, height: number, from: PortPayload, to: PortPayload): void;
436
+ update(to: Point, flipX: number, flipY: number, fromDir: number, toDir: number): void;
437
+ private createLinePath;
434
438
  }
435
439
 
436
440
  declare interface HorizontalEdgeShape_2 {
@@ -460,6 +464,10 @@ export declare class HtmlGraphBuilder {
460
464
  build(): Canvas;
461
465
  }
462
466
 
467
+ export declare class HtmlGraphError extends Error {
468
+ readonly name = "HtmlGraphError";
469
+ }
470
+
463
471
  declare type IncrementalPriority = "incremental";
464
472
 
465
473
  export declare type MarkNodePortRequest = {
@@ -503,7 +511,7 @@ export declare interface Point {
503
511
  readonly y: number;
504
512
  }
505
513
 
506
- export declare interface PortPayload {
514
+ declare interface PortPayload {
507
515
  readonly element: HTMLElement;
508
516
  centerFn: CenterFn;
509
517
  direction: number;
@@ -516,27 +524,27 @@ export declare type PriorityFn = () => number;
516
524
  declare class PublicGraphStore {
517
525
  private readonly graphStore;
518
526
  constructor(graphStore: GraphStore);
519
- getAllNodes(): readonly unknown[];
520
- getAllPorts(): readonly unknown[];
527
+ getAllNodeIds(): readonly unknown[];
528
+ getAllPortIds(): readonly unknown[];
521
529
  getNode(nodeId: unknown): GraphNode | null;
522
- getNodePorts(nodeId: unknown): readonly unknown[] | undefined;
530
+ getNodePortIds(nodeId: unknown): readonly unknown[] | undefined;
523
531
  getPort(portId: unknown): GraphPort | null;
524
- getPortNode(portId: string): unknown | null;
525
- getAllEdges(): readonly unknown[];
532
+ getPortNodeId(portId: string): unknown | null;
533
+ getAllEdgeIds(): readonly unknown[];
526
534
  getEdge(edgeId: unknown): GraphEdge | null;
527
- getPortAdjacentEdges(portId: string): readonly unknown[];
528
- getNodeAdjacentEdges(nodeId: unknown): readonly unknown[];
529
- getPortIncomingEdges(portId: unknown): readonly unknown[];
530
- getPortOutcomingEdges(portId: unknown): readonly unknown[];
531
- getPortCycleEdges(portId: unknown): readonly unknown[];
532
- getNodeIncomingEdges(nodeId: unknown): readonly unknown[];
533
- getNodeOutcomingEdges(nodeId: unknown): readonly unknown[];
534
- getNodeCycleEdges(nodeId: unknown): readonly unknown[];
535
+ getPortAdjacentEdgeIds(portId: string): readonly unknown[];
536
+ getNodeAdjacentEdgeIds(nodeId: unknown): readonly unknown[];
537
+ getPortIncomingEdgeIds(portId: unknown): readonly unknown[];
538
+ getPortOutcomingEdgeIds(portId: unknown): readonly unknown[];
539
+ getPortCycleEdgeIds(portId: unknown): readonly unknown[];
540
+ getNodeIncomingEdgeIds(nodeId: unknown): readonly unknown[];
541
+ getNodeOutcomingEdgeIds(nodeId: unknown): readonly unknown[];
542
+ getNodeCycleEdgeIds(nodeId: unknown): readonly unknown[];
535
543
  }
536
544
 
537
545
  export declare class PublicViewportTransformer {
538
546
  private readonly transformer;
539
- constructor(transformer: ViewportTransformer);
547
+ constructor(transformer: AbstractViewportTransformer);
540
548
  getViewportMatrix(): TransformState;
541
549
  getContentMatrix(): TransformState;
542
550
  }
@@ -544,8 +552,6 @@ export declare class PublicViewportTransformer {
544
552
  declare type SharedIncrementalPriority = "shared-incremental";
545
553
 
546
554
  export declare class StraightEdgeShape implements EdgeShape {
547
- private readonly color;
548
- private readonly width;
549
555
  private readonly arrowLength;
550
556
  private readonly arrowWidth;
551
557
  private readonly arrowOffset;
@@ -556,7 +562,8 @@ export declare class StraightEdgeShape implements EdgeShape {
556
562
  private readonly sourceArrow;
557
563
  private readonly targetArrow;
558
564
  constructor(color: string, width: number, arrowLength: number, arrowWidth: number, arrowOffset: number, hasSourceArrow: boolean, hasTargetArrow: boolean, roundness: number);
559
- update(x: number, y: number, width: number, height: number, from: PortPayload, to: PortPayload): void;
565
+ update(to: Point, flipX: number, flipY: number, fromDir: number, toDir: number): void;
566
+ private createLinePath;
560
567
  }
561
568
 
562
569
  declare interface StraightEdgeShape_2 {
@@ -583,6 +590,7 @@ export declare interface TransformOptions {
583
590
  };
584
591
  readonly shift?: {
585
592
  readonly enabled?: boolean;
593
+ readonly cursor?: string | null;
586
594
  };
587
595
  readonly transformPreprocessor?: TransformPreprocessorOption | TransformPreprocessorOption[];
588
596
  readonly events?: {
@@ -655,6 +663,7 @@ export declare class UserDraggableNodesCanvas implements Canvas {
655
663
  private previousTouchCoords;
656
664
  private readonly freezePriority;
657
665
  private readonly window;
666
+ private readonly dragCursor;
658
667
  constructor(canvas: Canvas, dragOptions?: DragOptions);
659
668
  addNode(request: AddNodeRequest): UserDraggableNodesCanvas;
660
669
  updateNode(nodeId: unknown, request: UpdateNodeRequest): UserDraggableNodesCanvas;
@@ -701,6 +710,7 @@ export declare class UserTransformableCanvas implements Canvas {
701
710
  private readonly onTouchMove;
702
711
  private readonly onTouchEnd;
703
712
  private readonly observer;
713
+ private readonly shiftCursor;
704
714
  constructor(canvas: Canvas, options?: TransformOptions | undefined);
705
715
  addNode(node: AddNodeRequest): UserTransformableCanvas;
706
716
  updateNode(nodeId: unknown, request: UpdateNodeRequest): UserTransformableCanvas;
@@ -727,8 +737,6 @@ export declare class UserTransformableCanvas implements Canvas {
727
737
  }
728
738
 
729
739
  export declare class VerticalEdgeShape implements EdgeShape {
730
- private readonly color;
731
- private readonly width;
732
740
  private readonly arrowLength;
733
741
  private readonly arrowWidth;
734
742
  private readonly arrowOffset;
@@ -739,7 +747,8 @@ export declare class VerticalEdgeShape implements EdgeShape {
739
747
  private readonly sourceArrow;
740
748
  private readonly targetArrow;
741
749
  constructor(color: string, width: number, arrowLength: number, arrowWidth: number, arrowOffset: number, hasSourceArrow: boolean, hasTargetArrow: boolean, roundness: number);
742
- update(x: number, y: number, width: number, height: number, from: PortPayload, to: PortPayload): void;
750
+ update(to: Point, flipX: number, flipY: number, fromDir: number, toDir: number): void;
751
+ private createLinePath;
743
752
  }
744
753
 
745
754
  declare interface VerticalEdgeShape_2 {
@@ -757,14 +766,4 @@ declare interface VerticalEdgeShape_2 {
757
766
  readonly detourDirection?: number;
758
767
  }
759
768
 
760
- declare class ViewportTransformer {
761
- private viewportMatrix;
762
- private contentMatrix;
763
- getViewportMatrix(): TransformState;
764
- getContentMatrix(): TransformState;
765
- patchViewportMatrix(scale: number | null, x: number | null, y: number | null): void;
766
- patchContentMatrix(scale: number | null, dx: number | null, dy: number | null): void;
767
- private calculateReverseMatrix;
768
- }
769
-
770
769
  export { }