@html-graph/html-graph 0.0.55 → 0.0.56

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
@@ -31,7 +31,7 @@ npm i @html-graph/html-graph
31
31
  ```
32
32
 
33
33
  ```typescript
34
- import { AddNodePorts, HtmlGraphBuilder } from "@html-graph/html-graph";
34
+ import { HtmlGraphBuilder, AddNodeRequest } from "@html-graph/html-graph";
35
35
 
36
36
  const canvas = new HtmlGraphBuilder()
37
37
  .setOptions({
@@ -50,9 +50,11 @@ const canvas = new HtmlGraphBuilder()
50
50
 
51
51
  function createNode(
52
52
  name: string,
53
+ x: number,
54
+ y: number,
53
55
  frontPortId: string,
54
56
  backPortId: string,
55
- ): [HTMLElement, AddNodePorts] {
57
+ ): AddNodeRequest {
56
58
  const node = document.createElement("div");
57
59
  node.classList.add("node");
58
60
 
@@ -68,33 +70,33 @@ function createNode(
68
70
  backPort.classList.add("port");
69
71
  node.appendChild(backPort);
70
72
 
71
- return [
72
- node,
73
- [
74
- [frontPortId, frontPort],
75
- [backPortId, backPort],
73
+ return {
74
+ element: node,
75
+ x: x,
76
+ y: y,
77
+ ports: [
78
+ { id: frontPortId, element: frontPort },
79
+ { id: backPortId, element: backPort },
76
80
  ],
77
- ];
81
+ };
78
82
  }
79
83
 
80
- const [node1, ports1] = createNode("Node 1", "port-1-1", "port-1-2");
81
- const [node2, ports2] = createNode("Node 2", "port-2-1", "port-2-2");
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");
82
86
 
83
87
  const canvasElement = document.getElementById("canvas")!;
84
88
 
85
89
  canvas
86
90
  .attach(canvasElement)
87
- .addNode({ element: node1, x: 200, y: 400, ports: ports1 })
88
- .addNode({ element: node2, x: 600, y: 500, ports: ports2 })
91
+ .addNode(node1)
92
+ .addNode(node2)
89
93
  .addEdge({ from: "port-1-2", to: "port-2-1" });
90
94
  ```
91
95
 
92
- Refer to [Examples](examples) for more.
96
+ Refer to [Use cases](use-cases) for more.
93
97
 
94
98
  ## Run examples
95
99
 
96
- Use node version >= 20
97
-
98
100
  ```
99
101
  npm install
100
102
  npm run start
package/dist/main.d.ts CHANGED
@@ -1,21 +1,21 @@
1
1
  export declare interface AddEdgeRequest {
2
- id?: unknown;
3
- from: string;
4
- to: string;
5
- options?: EdgeShape_2;
6
- priority?: number;
2
+ readonly id?: unknown;
3
+ readonly from: string;
4
+ readonly to: string;
5
+ readonly shape?: EdgeShape_2;
6
+ readonly priority?: number;
7
7
  }
8
8
 
9
- export declare type AddNodePorts = Iterable<readonly [unknown, MarkNodePortRequest]>;
9
+ export declare type AddNodePorts = Iterable<MarkNodePortRequest>;
10
10
 
11
11
  export declare interface AddNodeRequest {
12
- id?: unknown;
13
- element: HTMLElement;
14
- x: number;
15
- y: number;
16
- ports?: AddNodePorts;
17
- centerFn?: CenterFn;
18
- priority?: number;
12
+ readonly id?: unknown;
13
+ readonly element: HTMLElement;
14
+ readonly x: number;
15
+ readonly y: number;
16
+ readonly ports?: AddNodePorts;
17
+ readonly centerFn?: CenterFn;
18
+ readonly priority?: number;
19
19
  }
20
20
 
21
21
  export declare type BackgroundDrawingFn = (ctx: CanvasRenderingContext2D, transformer: PublicViewportTransformer) => void;
@@ -278,7 +278,7 @@ export declare const createVerticalEdgeShapeFactory: (options: {
278
278
 
279
279
  declare interface CustomEdgeShape {
280
280
  readonly type: "custom";
281
- readonly controllerFactory: EdgeShapeFactory;
281
+ readonly factory: EdgeShapeFactory;
282
282
  }
283
283
 
284
284
  declare type CustomPriority = PriorityFn;
@@ -400,8 +400,8 @@ declare class GraphStore {
400
400
  addPort(portId: unknown, element: HTMLElement, nodeId: unknown, centerFn: CenterFn, dir: number): void;
401
401
  getAllPorts(): readonly unknown[];
402
402
  getPort(portId: unknown): PortPayload | undefined;
403
- getPortNode(portId: string): unknown | undefined;
404
- removePort(portId: string): void;
403
+ getPortNode(portId: unknown): unknown | undefined;
404
+ removePort(portId: unknown): void;
405
405
  addEdge(edgeId: unknown, fromPortId: string, toPortId: string, shape: EdgeShape, priority: number): void;
406
406
  getAllEdges(): readonly unknown[];
407
407
  getEdge(edgeId: unknown): EdgePayload | undefined;
@@ -462,7 +462,8 @@ export declare class HtmlGraphBuilder {
462
462
 
463
463
  declare type IncrementalPriority = "incremental";
464
464
 
465
- export declare type MarkNodePortRequest = HTMLElement | {
465
+ export declare type MarkNodePortRequest = {
466
+ readonly id?: unknown;
466
467
  readonly element: HTMLElement;
467
468
  readonly centerFn?: CenterFn;
468
469
  readonly direction?: number;
@@ -619,7 +620,7 @@ declare interface TransformState {
619
620
  }
620
621
 
621
622
  export declare interface UpdateEdgeRequest {
622
- readonly controller?: EdgeShape;
623
+ readonly shape?: EdgeShape_2;
623
624
  readonly priority?: number;
624
625
  }
625
626
 
@@ -652,7 +653,8 @@ export declare class UserDraggableNodesCanvas implements Canvas {
652
653
  private readonly onCanvasTouchMove;
653
654
  private readonly onCanvasTouchEnd;
654
655
  private previousTouchCoords;
655
- private freezePriority;
656
+ private readonly freezePriority;
657
+ private readonly window;
656
658
  constructor(canvas: Canvas, dragOptions?: DragOptions);
657
659
  addNode(request: AddNodeRequest): UserDraggableNodesCanvas;
658
660
  updateNode(nodeId: unknown, request: UpdateNodeRequest): UserDraggableNodesCanvas;
@@ -669,10 +671,13 @@ export declare class UserDraggableNodesCanvas implements Canvas {
669
671
  attach(element: HTMLElement): UserDraggableNodesCanvas;
670
672
  detach(): UserDraggableNodesCanvas;
671
673
  destroy(): void;
672
- private setCursor;
673
674
  private dragNode;
674
675
  private updateMaxNodePriority;
675
676
  private moveNodeOnTop;
677
+ private cancelMouseDrag;
678
+ private removeMouseDragListeners;
679
+ private cancelTouchDrag;
680
+ private removeTouchDragListeners;
676
681
  }
677
682
 
678
683
  export declare class UserTransformableCanvas implements Canvas {
@@ -681,13 +686,13 @@ export declare class UserTransformableCanvas implements Canvas {
681
686
  readonly model: PublicGraphStore;
682
687
  readonly transformation: PublicViewportTransformer;
683
688
  private element;
684
- private isMoving;
685
689
  private prevTouches;
686
690
  private readonly onTransformFinished;
687
691
  private readonly transformPreprocessor;
688
692
  private readonly isScalable;
689
693
  private readonly isShiftable;
690
694
  private readonly wheelSensitivity;
695
+ private window;
691
696
  private readonly onMouseDown;
692
697
  private readonly onMouseMove;
693
698
  private readonly onMouseUp;
@@ -713,9 +718,12 @@ export declare class UserTransformableCanvas implements Canvas {
713
718
  detach(): UserTransformableCanvas;
714
719
  destroy(): void;
715
720
  private getAverageTouch;
716
- private setCursor;
717
721
  private moveViewport;
718
722
  private scaleViewport;
723
+ private stopMouseDrag;
724
+ private removeMouseDragListeners;
725
+ private stopTouchDrag;
726
+ private removeTouchDragListeners;
719
727
  }
720
728
 
721
729
  export declare class VerticalEdgeShape implements EdgeShape {