@html-graph/html-graph 3.5.1 → 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,12 +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;
70
- private readonly group;
71
- private readonly line;
72
- private readonly sourceArrow;
73
- private readonly targetArrow;
73
+ readonly group: SVGGElement;
74
+ readonly line: SVGPathElement;
75
+ readonly sourceArrow: SVGPathElement | null;
76
+ readonly targetArrow: SVGPathElement | null;
74
77
  private readonly arrowLength;
75
78
  private readonly arrowWidth;
76
79
  private readonly curvature;
@@ -80,6 +83,10 @@ export declare class BezierEdgeShape implements EdgeShape {
80
83
  private readonly detourDistance;
81
84
  private readonly hasSourceArrow;
82
85
  private readonly hasTargetArrow;
86
+ private readonly lineShape;
87
+ private readonly createCyclePath;
88
+ private readonly createDetourPath;
89
+ private readonly createLinePath;
83
90
  constructor(params?: BezierEdgeParams);
84
91
  render(params: EdgeRenderParams): void;
85
92
  }
@@ -306,8 +313,11 @@ declare interface ConnectablePortsConfig {
306
313
  readonly connectionPreprocessor?: ConnectionPreprocessor;
307
314
  readonly mouseDownEventVerifier?: MouseEventVerifier;
308
315
  readonly mouseUpEventVerifier?: MouseEventVerifier;
316
+ readonly dragPortDirection?: number | undefined;
309
317
  readonly events?: {
310
318
  readonly onAfterEdgeCreated?: (edgeId: unknown) => void;
319
+ readonly onEdgeCreationInterrupted?: (staticPortId: unknown, isDirect: boolean) => void;
320
+ readonly onEdgeCreationPrevented?: (request: AddEdgeRequest) => void;
311
321
  };
312
322
  }
313
323
  export { ConnectablePortsConfig }
@@ -319,6 +329,8 @@ export declare type ConnectionTypeResolver = (portId: unknown) => "direct" | "re
319
329
 
320
330
  declare type ConstantPriority = number;
321
331
 
332
+ export declare type CreatePathFn = (sourceDirection: Point, targetDirection: Point, to: Point, flipX: number, flipY: number) => string;
333
+
322
334
  declare type CustomPriority = PriorityFn;
323
335
 
324
336
  declare interface DotsRenderer {
@@ -374,7 +386,7 @@ export declare interface EdgeShape {
374
386
 
375
387
  declare type EdgeShapeConfig = BezierEdgeShapeConfig | StraightEdgeShapeConfig | HorizontalEdgeShapeConfig | VerticalEdgeShapeConfig | EdgeShapeFactory;
376
388
 
377
- declare type EdgeShapeFactory = () => EdgeShape;
389
+ declare type EdgeShapeFactory = (edgeId: unknown) => EdgeShape;
378
390
 
379
391
  /**
380
392
  * Responsibility: Provides a way to trigger events
@@ -425,6 +437,7 @@ export declare class Graph {
425
437
  getPort(portId: unknown): GraphPort | null;
426
438
  getAllPortIds(): readonly unknown[];
427
439
  getNodePortIds(nodeId: unknown): readonly unknown[] | null;
440
+ getElementPortsIds(element: HTMLElement): readonly unknown[];
428
441
  getAllEdgeIds(): readonly unknown[];
429
442
  getEdge(edgeId: unknown): GraphEdge | null;
430
443
  getPortIncomingEdgeIds(portId: unknown): readonly unknown[] | null;
@@ -458,7 +471,7 @@ export declare interface GraphPort {
458
471
  }
459
472
 
460
473
  /**
461
- * Responsibility: Stores stae of graph
474
+ * Responsibility: Store state of graph
462
475
  */
463
476
  declare class GraphStore {
464
477
  private readonly nodes;
@@ -467,6 +480,7 @@ declare class GraphStore {
467
480
  private readonly incomingEdges;
468
481
  private readonly outcomingEdges;
469
482
  private readonly cycleEdges;
483
+ private readonly elementPorts;
470
484
  private readonly afterNodeAddedEmitter;
471
485
  readonly onAfterNodeAdded: EventHandler<unknown>;
472
486
  private readonly afterNodeUpdatedEmitter;
@@ -503,6 +517,7 @@ declare class GraphStore {
503
517
  getPort(portId: unknown): PortPayload | undefined;
504
518
  updatePort(portId: unknown, request: UpdatePortRequest_2): void;
505
519
  getAllPortIds(): readonly unknown[];
520
+ getElementPortsIds(element: HTMLElement): readonly unknown[];
506
521
  getNodePortIds(nodeId: unknown): readonly unknown[] | undefined;
507
522
  removePort(portId: unknown): void;
508
523
  addEdge(request: AddEdgeRequest_2): void;
@@ -537,12 +552,16 @@ export declare interface HorizontalEdgeParams {
537
552
  readonly detourDirection?: number | undefined;
538
553
  }
539
554
 
540
- 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 {
541
560
  readonly svg: SVGSVGElement;
542
- private readonly group;
543
- private readonly line;
544
- private readonly sourceArrow;
545
- private readonly targetArrow;
561
+ readonly group: SVGGElement;
562
+ readonly line: SVGPathElement;
563
+ readonly sourceArrow: SVGPathElement | null;
564
+ readonly targetArrow: SVGPathElement | null;
546
565
  private readonly arrowLength;
547
566
  private readonly arrowWidth;
548
567
  private readonly arrowOffset;
@@ -552,6 +571,10 @@ export declare class HorizontalEdgeShape implements EdgeShape {
552
571
  private readonly detourDistance;
553
572
  private readonly hasSourceArrow;
554
573
  private readonly hasTargetArrow;
574
+ private readonly lineShape;
575
+ private readonly createCyclePath;
576
+ private readonly createDetourPath;
577
+ private readonly createLinePath;
555
578
  constructor(params?: HorizontalEdgeParams);
556
579
  render(params: EdgeRenderParams): void;
557
580
  }
@@ -587,6 +610,59 @@ declare interface HtmlView {
587
610
 
588
611
  declare type IncrementalPriority = "incremental";
589
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
+
590
666
  export declare type MarkNodePortRequest = {
591
667
  readonly id?: unknown | undefined;
592
668
  readonly element: HTMLElement;
@@ -684,12 +760,15 @@ export declare interface StraightEdgeParams {
684
760
  readonly detourDirection?: number | undefined;
685
761
  }
686
762
 
687
- 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 {
688
767
  readonly svg: SVGSVGElement;
689
- private readonly group;
690
- private readonly line;
691
- private readonly sourceArrow;
692
- private readonly targetArrow;
768
+ readonly group: SVGGElement;
769
+ readonly line: SVGPathElement;
770
+ readonly sourceArrow: SVGPathElement | null;
771
+ readonly targetArrow: SVGPathElement | null;
693
772
  private readonly arrowLength;
694
773
  private readonly arrowWidth;
695
774
  private readonly arrowOffset;
@@ -699,6 +778,10 @@ export declare class StraightEdgeShape implements EdgeShape {
699
778
  private readonly detourDistance;
700
779
  private readonly hasSourceArrow;
701
780
  private readonly hasTargetArrow;
781
+ private readonly lineShape;
782
+ private readonly createCyclePath;
783
+ private readonly createDetourPath;
784
+ private readonly createLinePath;
702
785
  constructor(params?: StraightEdgeParams);
703
786
  render(params: EdgeRenderParams): void;
704
787
  }
@@ -707,6 +790,16 @@ declare type StraightEdgeShapeConfig = {
707
790
  readonly type: "straight";
708
791
  } & StraightEdgeParams;
709
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
+
710
803
  export declare interface TransformPayload {
711
804
  readonly scale: number;
712
805
  readonly x: number;
@@ -790,12 +883,16 @@ export declare interface VerticalEdgeParams {
790
883
  readonly detourDirection?: number | undefined;
791
884
  }
792
885
 
793
- 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 {
794
891
  readonly svg: SVGSVGElement;
795
- private readonly group;
796
- private readonly line;
797
- private readonly sourceArrow;
798
- private readonly targetArrow;
892
+ readonly group: SVGGElement;
893
+ readonly line: SVGPathElement;
894
+ readonly sourceArrow: SVGPathElement | null;
895
+ readonly targetArrow: SVGPathElement | null;
799
896
  private readonly arrowLength;
800
897
  private readonly arrowWidth;
801
898
  private readonly arrowOffset;
@@ -805,6 +902,10 @@ export declare class VerticalEdgeShape implements EdgeShape {
805
902
  private readonly detourDistance;
806
903
  private readonly hasSourceArrow;
807
904
  private readonly hasTargetArrow;
905
+ private readonly lineShape;
906
+ private readonly createCyclePath;
907
+ private readonly createDetourPath;
908
+ private readonly createLinePath;
808
909
  constructor(params?: VerticalEdgeParams);
809
910
  render(params: EdgeRenderParams): void;
810
911
  }