@html-graph/html-graph 3.6.0 → 3.7.0

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
@@ -23,65 +23,74 @@ npm i @html-graph/html-graph
23
23
  ```javascript
24
24
  import { CanvasBuilder } from "@html-graph/html-graph";
25
25
 
26
- function createNode({ name, x, y, frontPortId, backPortId }) {
27
- const node = document.createElement("div");
28
- const text = document.createElement("div");
29
- const frontPort = document.createElement("div");
30
- const backPort = document.createElement("div");
26
+ class Application {
27
+ constructor(element) {
28
+ this.canvas = new CanvasBuilder(element)
29
+ .setDefaults({
30
+ edges: {
31
+ shape: {
32
+ hasTargetArrow: true,
33
+ },
34
+ },
35
+ })
36
+ .enableUserDraggableNodes()
37
+ .enableUserTransformableViewport()
38
+ .enableBackground()
39
+ .build();
40
+ }
31
41
 
32
- node.classList.add("node");
33
- frontPort.classList.add("port");
34
- backPort.classList.add("port");
35
- text.innerText = name;
42
+ initGraph() {
43
+ this.canvas
44
+ .addNode(
45
+ this.createNode({
46
+ name: "Node 1",
47
+ x: 200,
48
+ y: 400,
49
+ frontPortId: "node-1-in",
50
+ backPortId: "node-1-out",
51
+ }),
52
+ )
53
+ .addNode(
54
+ this.createNode({
55
+ name: "Node 2",
56
+ x: 600,
57
+ y: 500,
58
+ frontPortId: "node-2-in",
59
+ backPortId: "node-2-out",
60
+ }),
61
+ )
62
+ .addEdge({ from: "node-1-out", to: "node-2-in" });
63
+ }
36
64
 
37
- node.appendChild(frontPort);
38
- node.appendChild(text);
39
- node.appendChild(backPort);
65
+ createNode({ name, x, y, frontPortId, backPortId }) {
66
+ const node = document.createElement("div");
67
+ const text = document.createElement("div");
68
+ const frontPort = document.createElement("div");
69
+ const backPort = document.createElement("div");
40
70
 
41
- return {
42
- element: node,
43
- x: x,
44
- y: y,
45
- ports: [
46
- { id: frontPortId, element: frontPort },
47
- { id: backPortId, element: backPort },
48
- ],
49
- };
71
+ node.classList.add("node");
72
+ frontPort.classList.add("port");
73
+ backPort.classList.add("port");
74
+ text.innerText = name;
75
+
76
+ node.appendChild(frontPort);
77
+ node.appendChild(text);
78
+ node.appendChild(backPort);
79
+
80
+ return {
81
+ element: node,
82
+ x: x,
83
+ y: y,
84
+ ports: [
85
+ { id: frontPortId, element: frontPort },
86
+ { id: backPortId, element: backPort },
87
+ ],
88
+ };
89
+ }
50
90
  }
51
91
 
52
92
  const element = document.getElementById("canvas");
93
+ const app = new Application(element);
53
94
 
54
- const canvas = new CanvasBuilder(element)
55
- .setDefaults({
56
- edges: {
57
- shape: {
58
- hasTargetArrow: true,
59
- },
60
- },
61
- })
62
- .enableUserDraggableNodes()
63
- .enableUserTransformableViewport()
64
- .enableBackground()
65
- .build();
66
-
67
- canvas
68
- .addNode(
69
- createNode({
70
- name: "Node 1",
71
- x: 200,
72
- y: 400,
73
- frontPortId: "node-1-in",
74
- backPortId: "node-1-out",
75
- }),
76
- )
77
- .addNode(
78
- createNode({
79
- name: "Node 2",
80
- x: 600,
81
- y: 500,
82
- frontPortId: "node-2-in",
83
- backPortId: "node-2-out",
84
- }),
85
- )
86
- .addEdge({ from: "node-1-out", to: "node-2-in" });
95
+ app.initGraph();
87
96
  ```
@@ -65,8 +65,15 @@ export declare interface BezierEdgeParams {
65
65
  readonly detourDirection?: number | undefined;
66
66
  }
67
67
 
68
- export declare class BezierEdgeShape implements EdgeShape {
68
+ /**
69
+ * Responsibility: Providing edge shape connecting ports with bezier line
70
+ */
71
+ export declare class BezierEdgeShape implements StructuredEdgeShape {
69
72
  readonly svg: SVGSVGElement;
73
+ readonly group: SVGGElement;
74
+ readonly line: SVGPathElement;
75
+ readonly sourceArrow: SVGPathElement | null;
76
+ readonly targetArrow: SVGPathElement | null;
70
77
  private readonly arrowLength;
71
78
  private readonly arrowWidth;
72
79
  private readonly curvature;
@@ -76,7 +83,7 @@ export declare class BezierEdgeShape implements EdgeShape {
76
83
  private readonly detourDistance;
77
84
  private readonly hasSourceArrow;
78
85
  private readonly hasTargetArrow;
79
- private readonly genericShape;
86
+ private readonly lineShape;
80
87
  private readonly createCyclePath;
81
88
  private readonly createDetourPath;
82
89
  private readonly createLinePath;
@@ -322,6 +329,8 @@ export declare type ConnectionTypeResolver = (portId: unknown) => "direct" | "re
322
329
 
323
330
  declare type ConstantPriority = number;
324
331
 
332
+ export declare type CreatePathFn = (sourceDirection: Point, targetDirection: Point, to: Point, flipX: number, flipY: number) => string;
333
+
325
334
  declare type CustomPriority = PriorityFn;
326
335
 
327
336
  declare interface DotsRenderer {
@@ -377,7 +386,7 @@ export declare interface EdgeShape {
377
386
 
378
387
  declare type EdgeShapeConfig = BezierEdgeShapeConfig | StraightEdgeShapeConfig | HorizontalEdgeShapeConfig | VerticalEdgeShapeConfig | EdgeShapeFactory;
379
388
 
380
- declare type EdgeShapeFactory = () => EdgeShape;
389
+ declare type EdgeShapeFactory = (edgeId: unknown) => EdgeShape;
381
390
 
382
391
  /**
383
392
  * Responsibility: Provides a way to trigger events
@@ -428,6 +437,7 @@ export declare class Graph {
428
437
  getPort(portId: unknown): GraphPort | null;
429
438
  getAllPortIds(): readonly unknown[];
430
439
  getNodePortIds(nodeId: unknown): readonly unknown[] | null;
440
+ getElementPortsIds(element: HTMLElement): readonly unknown[];
431
441
  getAllEdgeIds(): readonly unknown[];
432
442
  getEdge(edgeId: unknown): GraphEdge | null;
433
443
  getPortIncomingEdgeIds(portId: unknown): readonly unknown[] | null;
@@ -461,7 +471,7 @@ export declare interface GraphPort {
461
471
  }
462
472
 
463
473
  /**
464
- * Responsibility: Stores stae of graph
474
+ * Responsibility: Store state of graph
465
475
  */
466
476
  declare class GraphStore {
467
477
  private readonly nodes;
@@ -470,6 +480,7 @@ declare class GraphStore {
470
480
  private readonly incomingEdges;
471
481
  private readonly outcomingEdges;
472
482
  private readonly cycleEdges;
483
+ private readonly elementPorts;
473
484
  private readonly afterNodeAddedEmitter;
474
485
  readonly onAfterNodeAdded: EventHandler<unknown>;
475
486
  private readonly afterNodeUpdatedEmitter;
@@ -506,6 +517,7 @@ declare class GraphStore {
506
517
  getPort(portId: unknown): PortPayload | undefined;
507
518
  updatePort(portId: unknown, request: UpdatePortRequest_2): void;
508
519
  getAllPortIds(): readonly unknown[];
520
+ getElementPortsIds(element: HTMLElement): readonly unknown[];
509
521
  getNodePortIds(nodeId: unknown): readonly unknown[] | undefined;
510
522
  removePort(portId: unknown): void;
511
523
  addEdge(request: AddEdgeRequest_2): void;
@@ -540,8 +552,16 @@ export declare interface HorizontalEdgeParams {
540
552
  readonly detourDirection?: number | undefined;
541
553
  }
542
554
 
543
- export declare class HorizontalEdgeShape implements EdgeShape {
555
+ /**
556
+ * Responsibility: Providing edge shape connecting ports with horizontal angled
557
+ * line
558
+ */
559
+ export declare class HorizontalEdgeShape implements StructuredEdgeShape {
544
560
  readonly svg: SVGSVGElement;
561
+ readonly group: SVGGElement;
562
+ readonly line: SVGPathElement;
563
+ readonly sourceArrow: SVGPathElement | null;
564
+ readonly targetArrow: SVGPathElement | null;
545
565
  private readonly arrowLength;
546
566
  private readonly arrowWidth;
547
567
  private readonly arrowOffset;
@@ -551,7 +571,7 @@ export declare class HorizontalEdgeShape implements EdgeShape {
551
571
  private readonly detourDistance;
552
572
  private readonly hasSourceArrow;
553
573
  private readonly hasTargetArrow;
554
- private readonly genericShape;
574
+ private readonly lineShape;
555
575
  private readonly createCyclePath;
556
576
  private readonly createDetourPath;
557
577
  private readonly createLinePath;
@@ -590,6 +610,59 @@ declare interface HtmlView {
590
610
 
591
611
  declare type IncrementalPriority = "incremental";
592
612
 
613
+ export declare class InteractiveEdgeError extends Error {
614
+ constructor(message: string);
615
+ }
616
+
617
+ export declare interface InteractiveEdgeParams {
618
+ readonly width?: number;
619
+ }
620
+
621
+ /**
622
+ * Responsibility: Providing handle for attaching interactive behavior to an
623
+ * edge
624
+ */
625
+ export declare class InteractiveEdgeShape implements StructuredEdgeShape {
626
+ private readonly structuredEdge;
627
+ readonly svg: SVGSVGElement;
628
+ readonly group: SVGGElement;
629
+ readonly line: SVGPathElement;
630
+ readonly sourceArrow: SVGPathElement | null;
631
+ readonly targetArrow: SVGPathElement | null;
632
+ readonly handle: SVGGElement;
633
+ private readonly interactiveLine;
634
+ private readonly interactiveSourceArrow;
635
+ private readonly interactiveTargetArrow;
636
+ constructor(structuredEdge: StructuredEdgeShape, params?: InteractiveEdgeParams);
637
+ render(params: EdgeRenderParams): void;
638
+ }
639
+
640
+ export declare interface LineEdgeParams {
641
+ readonly width: number;
642
+ readonly color: string;
643
+ readonly arrowLength: number;
644
+ readonly arrowWidth: number;
645
+ readonly hasSourceArrow: boolean;
646
+ readonly hasTargetArrow: boolean;
647
+ readonly createCyclePath: CreatePathFn;
648
+ readonly createDetourPath: CreatePathFn;
649
+ readonly createLinePath: CreatePathFn;
650
+ }
651
+
652
+ /**
653
+ * Responsibility: Providing low level core for single line structured edges
654
+ */
655
+ export declare class LineEdgeShape implements StructuredEdgeShape {
656
+ private readonly params;
657
+ readonly svg: SVGSVGElement;
658
+ readonly group: SVGGElement;
659
+ readonly line: SVGPathElement;
660
+ readonly sourceArrow: SVGPathElement | null;
661
+ readonly targetArrow: SVGPathElement | null;
662
+ constructor(params: LineEdgeParams);
663
+ render(params: EdgeRenderParams): void;
664
+ }
665
+
593
666
  export declare type MarkNodePortRequest = {
594
667
  readonly id?: unknown | undefined;
595
668
  readonly element: HTMLElement;
@@ -687,8 +760,15 @@ export declare interface StraightEdgeParams {
687
760
  readonly detourDirection?: number | undefined;
688
761
  }
689
762
 
690
- export declare class StraightEdgeShape implements EdgeShape {
763
+ /**
764
+ * Responsibility: Providing edge shape connecting ports with straight line
765
+ */
766
+ export declare class StraightEdgeShape implements StructuredEdgeShape {
691
767
  readonly svg: SVGSVGElement;
768
+ readonly group: SVGGElement;
769
+ readonly line: SVGPathElement;
770
+ readonly sourceArrow: SVGPathElement | null;
771
+ readonly targetArrow: SVGPathElement | null;
692
772
  private readonly arrowLength;
693
773
  private readonly arrowWidth;
694
774
  private readonly arrowOffset;
@@ -698,7 +778,7 @@ export declare class StraightEdgeShape implements EdgeShape {
698
778
  private readonly detourDistance;
699
779
  private readonly hasSourceArrow;
700
780
  private readonly hasTargetArrow;
701
- private readonly genericShape;
781
+ private readonly lineShape;
702
782
  private readonly createCyclePath;
703
783
  private readonly createDetourPath;
704
784
  private readonly createLinePath;
@@ -710,6 +790,16 @@ declare type StraightEdgeShapeConfig = {
710
790
  readonly type: "straight";
711
791
  } & StraightEdgeParams;
712
792
 
793
+ /**
794
+ * Responsibility: Specifying EdgeShape with a standard visual structure
795
+ */
796
+ export declare interface StructuredEdgeShape extends EdgeShape {
797
+ readonly group: SVGGElement;
798
+ readonly line: SVGPathElement;
799
+ readonly sourceArrow: SVGPathElement | null;
800
+ readonly targetArrow: SVGPathElement | null;
801
+ }
802
+
713
803
  export declare interface TransformPayload {
714
804
  readonly scale: number;
715
805
  readonly x: number;
@@ -793,8 +883,16 @@ export declare interface VerticalEdgeParams {
793
883
  readonly detourDirection?: number | undefined;
794
884
  }
795
885
 
796
- export declare class VerticalEdgeShape implements EdgeShape {
886
+ /**
887
+ * Responsibility: Providing edge shape connecting ports with vertical angled
888
+ * line
889
+ */
890
+ export declare class VerticalEdgeShape implements StructuredEdgeShape {
797
891
  readonly svg: SVGSVGElement;
892
+ readonly group: SVGGElement;
893
+ readonly line: SVGPathElement;
894
+ readonly sourceArrow: SVGPathElement | null;
895
+ readonly targetArrow: SVGPathElement | null;
798
896
  private readonly arrowLength;
799
897
  private readonly arrowWidth;
800
898
  private readonly arrowOffset;
@@ -804,7 +902,7 @@ export declare class VerticalEdgeShape implements EdgeShape {
804
902
  private readonly detourDistance;
805
903
  private readonly hasSourceArrow;
806
904
  private readonly hasTargetArrow;
807
- private readonly genericShape;
905
+ private readonly lineShape;
808
906
  private readonly createCyclePath;
809
907
  private readonly createDetourPath;
810
908
  private readonly createLinePath;