@html-graph/html-graph 0.0.61 → 0.1.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
@@ -6,20 +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/use-cases/020-advanced-demo/index.html">
9
+ <a target="_blank" href="https://html-graph.github.io/use-cases/020-advanced-demo/">
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
13
  Instead of connecting nodes directly this library uses concept of ports, which provide greater fexibility at managing edges.
14
14
  Port is an entity of a node to which edge can be attached to.
15
15
 
16
- Visit <a target="_blank" href="https://html-graph.github.io/use-cases">use cases</a> and [use cases implementation](use-cases).
16
+ Visit <a target="_blank" href="https://html-graph.github.io/use-cases/">use cases</a> and [use cases implementation](use-cases).
17
17
 
18
18
  ## Features:
19
19
 
20
20
  - easy nodes customization using HTML
21
21
  - wide configuration options out of the box
22
- - draggable and scalable canvas with draggable nodes
22
+ - draggable and scalable canvas
23
+ - draggable and resizable nodes
23
24
  - exhaustive set of use cases
24
25
  - typescript support
25
26
  - mobile devices support
@@ -43,6 +44,7 @@ const canvas = new HtmlGraphBuilder()
43
44
  })
44
45
  .setUserDraggableNodes()
45
46
  .setUserTransformableCanvas()
47
+ .setResizeReactiveNodes()
46
48
  .build();
47
49
 
48
50
  function createNode({ name, x, y, frontPortId, backPortId }) {
package/dist/main.d.ts CHANGED
@@ -43,6 +43,8 @@ declare interface AddPortRequest {
43
43
  readonly direction: number;
44
44
  }
45
45
 
46
+ export declare type BeforeTransformStartedFn = () => void;
47
+
46
48
  export declare class BezierEdgeShape implements EdgeShape {
47
49
  private readonly curvature;
48
50
  private readonly arrowLength;
@@ -102,12 +104,12 @@ export declare interface Canvas {
102
104
  /**
103
105
  * updates port and attached edges
104
106
  */
105
- updatePort(portId: string, request?: UpdatePortRequest): Canvas;
107
+ updatePortMark(portId: unknown, request?: UpdatePortMarkRequest): Canvas;
106
108
  /**
107
109
  * ummarks element as port of node
108
110
  * all the edges adjacent to port get removed
109
111
  */
110
- unmarkPort(portId: string): Canvas;
112
+ unmarkPort(portId: unknown): Canvas;
111
113
  /**
112
114
  * adds edge to graph
113
115
  */
@@ -157,26 +159,23 @@ export declare class CanvasCore implements Canvas {
157
159
  private readonly apiOptions?;
158
160
  readonly transformation: PublicViewportTransformer;
159
161
  readonly model: PublicGraphStore;
160
- private readonly di;
162
+ private readonly canvasController;
161
163
  private readonly edgeShapeFactory;
162
- private readonly nodes;
163
- private readonly nodeIdGenerator;
164
- private readonly nodesResizeObserver;
165
164
  constructor(apiOptions?: CoreOptions | undefined);
165
+ attach(element: HTMLElement): CanvasCore;
166
+ detach(): CanvasCore;
166
167
  addNode(request: AddNodeRequest): CanvasCore;
167
168
  updateNode(nodeId: unknown, request?: UpdateNodeRequest): CanvasCore;
168
169
  removeNode(nodeId: unknown): CanvasCore;
169
- markPort(port: MarkPortRequest): CanvasCore;
170
- updatePort(portId: string, request?: UpdatePortRequest): CanvasCore;
171
- unmarkPort(portId: string): CanvasCore;
172
170
  addEdge(edge: AddEdgeRequest): CanvasCore;
173
171
  updateEdge(edgeId: unknown, request?: UpdateEdgeRequest): CanvasCore;
174
172
  removeEdge(edgeId: unknown): CanvasCore;
173
+ markPort(port: MarkPortRequest): CanvasCore;
174
+ updatePortMark(portId: string, request?: UpdatePortMarkRequest): CanvasCore;
175
+ unmarkPort(portId: string): CanvasCore;
175
176
  patchViewportMatrix(request: PatchMatrixRequest): CanvasCore;
176
177
  patchContentMatrix(request: PatchMatrixRequest): CanvasCore;
177
178
  clear(): CanvasCore;
178
- attach(element: HTMLElement): CanvasCore;
179
- detach(): CanvasCore;
180
179
  destroy(): void;
181
180
  }
182
181
 
@@ -229,59 +228,59 @@ export declare interface CoreOptions {
229
228
  }
230
229
 
231
230
  export declare const createBezierEdgeShapeFactory: (options: {
232
- color: string;
233
- width: number;
234
- arrowLength: number;
235
- arrowWidth: number;
236
- curvature: number;
237
- hasSourceArrow: boolean;
238
- hasTargetArrow: boolean;
239
- cycleRadius: number;
240
- smallCycleRadius: number;
241
- detourDistance: number;
242
- detourDirection: number;
231
+ readonly color: string;
232
+ readonly width: number;
233
+ readonly arrowLength: number;
234
+ readonly arrowWidth: number;
235
+ readonly curvature: number;
236
+ readonly hasSourceArrow: boolean;
237
+ readonly hasTargetArrow: boolean;
238
+ readonly cycleRadius: number;
239
+ readonly smallCycleRadius: number;
240
+ readonly detourDistance: number;
241
+ readonly detourDirection: number;
243
242
  }) => EdgeShapeFactory;
244
243
 
245
244
  export declare const createHorizontalEdgeShapeFactory: (options: {
246
- color: string;
247
- width: number;
248
- arrowLength: number;
249
- arrowWidth: number;
250
- arrowOffset: number;
251
- hasSourceArrow: boolean;
252
- hasTargetArrow: boolean;
253
- cycleSquareSide: number;
254
- roundness: number;
255
- detourDistance: number;
256
- detourDirection: number;
245
+ readonly color: string;
246
+ readonly width: number;
247
+ readonly arrowLength: number;
248
+ readonly arrowWidth: number;
249
+ readonly arrowOffset: number;
250
+ readonly hasSourceArrow: boolean;
251
+ readonly hasTargetArrow: boolean;
252
+ readonly cycleSquareSide: number;
253
+ readonly roundness: number;
254
+ readonly detourDistance: number;
255
+ readonly detourDirection: number;
257
256
  }) => EdgeShapeFactory;
258
257
 
259
258
  export declare const createStraightEdgeShareFactory: (options: {
260
- color: string;
261
- width: number;
262
- arrowLength: number;
263
- arrowWidth: number;
264
- arrowOffset: number;
265
- hasSourceArrow: boolean;
266
- hasTargetArrow: boolean;
267
- cycleSquareSide: number;
268
- roundness: number;
269
- detourDistance: number;
270
- detourDirection: number;
259
+ readonly color: string;
260
+ readonly width: number;
261
+ readonly arrowLength: number;
262
+ readonly arrowWidth: number;
263
+ readonly arrowOffset: number;
264
+ readonly hasSourceArrow: boolean;
265
+ readonly hasTargetArrow: boolean;
266
+ readonly cycleSquareSide: number;
267
+ readonly roundness: number;
268
+ readonly detourDistance: number;
269
+ readonly detourDirection: number;
271
270
  }) => EdgeShapeFactory;
272
271
 
273
272
  export declare const createVerticalEdgeShapeFactory: (options: {
274
- color: string;
275
- width: number;
276
- arrowLength: number;
277
- arrowWidth: number;
278
- arrowOffset: number;
279
- hasSourceArrow: boolean;
280
- hasTargetArrow: boolean;
281
- cycleSquareSide: number;
282
- roundness: number;
283
- detourDistance: number;
284
- detourDirection: number;
273
+ readonly color: string;
274
+ readonly width: number;
275
+ readonly arrowLength: number;
276
+ readonly arrowWidth: number;
277
+ readonly arrowOffset: number;
278
+ readonly hasSourceArrow: boolean;
279
+ readonly hasTargetArrow: boolean;
280
+ readonly cycleSquareSide: number;
281
+ readonly roundness: number;
282
+ readonly detourDistance: number;
283
+ readonly detourDirection: number;
285
284
  }) => EdgeShapeFactory;
286
285
 
287
286
  declare interface CustomEdgeShape {
@@ -353,11 +352,11 @@ export declare class DetourStraightEdgeShape implements EdgeShape {
353
352
  }
354
353
 
355
354
  export declare interface DragOptions {
356
- grabPriorityStrategy?: "freeze" | "move-on-top";
357
- dragCursor?: string | null;
358
- events?: {
359
- onNodeDrag?: (payload: NodeDragPayload) => void;
360
- onBeforeNodeDrag?: (payload: NodeDragPayload) => boolean;
355
+ readonly moveOnTop?: boolean;
356
+ readonly dragCursor?: string | null;
357
+ readonly events?: {
358
+ readonly onNodeDrag?: (payload: NodeDragPayload) => void;
359
+ readonly onBeforeNodeDrag?: (payload: NodeDragPayload) => boolean;
361
360
  };
362
361
  }
363
362
 
@@ -473,9 +472,11 @@ export declare class HtmlGraphBuilder {
473
472
  private transformOptions;
474
473
  private isDraggable;
475
474
  private isTransformable;
475
+ private hasResizeReactiveNodes;
476
476
  setOptions(options: CoreOptions): HtmlGraphBuilder;
477
477
  setUserDraggableNodes(options?: DragOptions): HtmlGraphBuilder;
478
478
  setUserTransformableCanvas(options?: TransformOptions): HtmlGraphBuilder;
479
+ setResizableReactiveNodes(): HtmlGraphBuilder;
479
480
  build(): Canvas;
480
481
  }
481
482
 
@@ -570,8 +571,46 @@ export declare class PublicViewportTransformer {
570
571
  getContentMatrix(): TransformState;
571
572
  }
572
573
 
574
+ export declare class ResizeReactiveNodesCanvas implements Canvas {
575
+ private readonly canvas;
576
+ readonly transformation: PublicViewportTransformer;
577
+ readonly model: PublicGraphStore;
578
+ private readonly nodes;
579
+ private readonly nodeIdGenerator;
580
+ private readonly nodesResizeObserver;
581
+ constructor(canvas: Canvas);
582
+ attach(element: HTMLElement): ResizeReactiveNodesCanvas;
583
+ detach(): ResizeReactiveNodesCanvas;
584
+ addNode(request: AddNodeRequest): ResizeReactiveNodesCanvas;
585
+ updateNode(nodeId: unknown, request?: UpdateNodeRequest): ResizeReactiveNodesCanvas;
586
+ removeNode(nodeId: unknown): ResizeReactiveNodesCanvas;
587
+ markPort(port: MarkPortRequest): ResizeReactiveNodesCanvas;
588
+ updatePortMark(portId: string, request?: UpdatePortMarkRequest): ResizeReactiveNodesCanvas;
589
+ unmarkPort(portId: string): ResizeReactiveNodesCanvas;
590
+ addEdge(edge: AddEdgeRequest): ResizeReactiveNodesCanvas;
591
+ updateEdge(edgeId: unknown, request?: UpdateEdgeRequest): ResizeReactiveNodesCanvas;
592
+ removeEdge(edgeId: unknown): ResizeReactiveNodesCanvas;
593
+ patchViewportMatrix(request: PatchMatrixRequest): ResizeReactiveNodesCanvas;
594
+ patchContentMatrix(request: PatchMatrixRequest): ResizeReactiveNodesCanvas;
595
+ clear(): ResizeReactiveNodesCanvas;
596
+ destroy(): void;
597
+ private reactNodeChange;
598
+ }
599
+
600
+ export declare interface ScaleLimitPreprocessorParams {
601
+ readonly minContentScale: number | null;
602
+ readonly maxContentScale: number | null;
603
+ }
604
+
573
605
  declare type SharedIncrementalPriority = "shared-incremental";
574
606
 
607
+ export declare interface ShiftLimitPreprocessorParams {
608
+ readonly minX: number | null;
609
+ readonly maxX: number | null;
610
+ readonly minY: number | null;
611
+ readonly maxY: number | null;
612
+ }
613
+
575
614
  export declare class StraightEdgeShape implements EdgeShape {
576
615
  private readonly arrowLength;
577
616
  private readonly arrowWidth;
@@ -606,15 +645,14 @@ export declare type TransformFinishedFn = () => void;
606
645
 
607
646
  export declare interface TransformOptions {
608
647
  readonly scale?: {
609
- readonly enabled?: boolean;
610
648
  readonly wheelSensitivity?: number;
611
649
  };
612
650
  readonly shift?: {
613
- readonly enabled?: boolean;
614
651
  readonly cursor?: string | null;
615
652
  };
616
653
  readonly transformPreprocessor?: TransformPreprocessorOption | TransformPreprocessorOption[];
617
654
  readonly events?: {
655
+ readonly onBeforeTransformStarted?: BeforeTransformStartedFn;
618
656
  readonly onTransformFinished?: TransformFinishedFn;
619
657
  };
620
658
  }
@@ -625,7 +663,7 @@ export declare interface TransformPayload {
625
663
  readonly dy: number;
626
664
  }
627
665
 
628
- export declare type TransformPreprocessorFn = (prevTransform: TransformPayload, nextTransform: TransformPayload, canvasWidth: number, canvasHeight: number) => TransformPayload;
666
+ export declare type TransformPreprocessorFn = (params: TransformPreprocessorParams) => TransformPayload;
629
667
 
630
668
  declare type TransformPreprocessorOption = {
631
669
  readonly type: "scale-limit";
@@ -637,10 +675,14 @@ declare type TransformPreprocessorOption = {
637
675
  readonly maxX?: number;
638
676
  readonly minY?: number;
639
677
  readonly maxY?: number;
640
- } | {
641
- readonly type: "custom";
642
- readonly preprocessorFn: TransformPreprocessorFn;
643
- };
678
+ } | TransformPreprocessorFn;
679
+
680
+ export declare interface TransformPreprocessorParams {
681
+ readonly prevTransform: TransformPayload;
682
+ readonly nextTransform: TransformPayload;
683
+ readonly canvasWidth: number;
684
+ readonly canvasHeight: number;
685
+ }
644
686
 
645
687
  declare interface TransformState {
646
688
  readonly scale: number;
@@ -660,7 +702,7 @@ declare interface UpdateNodeRequest {
660
702
  readonly centerFn?: CenterFn;
661
703
  }
662
704
 
663
- declare interface UpdatePortRequest {
705
+ export declare interface UpdatePortMarkRequest {
664
706
  readonly direction?: number;
665
707
  readonly centerFn?: CenterFn;
666
708
  }
@@ -676,21 +718,22 @@ export declare class UserDraggableNodesCanvas implements Canvas {
676
718
  private onBeforeNodeDrag;
677
719
  private readonly nodeIdGenerator;
678
720
  private element;
679
- private readonly onCanvasMouseUp;
680
- private readonly onCanvasMouseMove;
681
- private readonly onCanvasTouchStart;
682
- private readonly onCanvasTouchMove;
683
- private readonly onCanvasTouchEnd;
721
+ private readonly onWindowMouseMove;
722
+ private readonly onWindowMouseUp;
723
+ private readonly onWindowTouchMove;
724
+ private readonly onWindowTouchFinish;
684
725
  private previousTouchCoords;
685
726
  private readonly freezePriority;
686
727
  private readonly window;
687
728
  private readonly dragCursor;
688
729
  constructor(canvas: Canvas, dragOptions?: DragOptions);
730
+ attach(element: HTMLElement): UserDraggableNodesCanvas;
731
+ detach(): UserDraggableNodesCanvas;
689
732
  addNode(request: AddNodeRequest): UserDraggableNodesCanvas;
690
733
  updateNode(nodeId: unknown, request?: UpdateNodeRequest): UserDraggableNodesCanvas;
691
734
  removeNode(nodeId: unknown): UserDraggableNodesCanvas;
692
735
  markPort(port: MarkPortRequest): UserDraggableNodesCanvas;
693
- updatePort(portId: string, request?: UpdatePortRequest): UserDraggableNodesCanvas;
736
+ updatePortMark(portId: string, request?: UpdatePortMarkRequest): UserDraggableNodesCanvas;
694
737
  unmarkPort(portId: string): UserDraggableNodesCanvas;
695
738
  addEdge(edge: AddEdgeRequest): UserDraggableNodesCanvas;
696
739
  updateEdge(edgeId: unknown, request?: UpdateEdgeRequest): UserDraggableNodesCanvas;
@@ -698,8 +741,6 @@ export declare class UserDraggableNodesCanvas implements Canvas {
698
741
  patchViewportMatrix(request: PatchMatrixRequest): UserDraggableNodesCanvas;
699
742
  patchContentMatrix(request: PatchMatrixRequest): UserDraggableNodesCanvas;
700
743
  clear(): UserDraggableNodesCanvas;
701
- attach(element: HTMLElement): UserDraggableNodesCanvas;
702
- detach(): UserDraggableNodesCanvas;
703
744
  destroy(): void;
704
745
  private dragNode;
705
746
  private updateMaxNodePriority;
@@ -712,32 +753,28 @@ export declare class UserDraggableNodesCanvas implements Canvas {
712
753
 
713
754
  export declare class UserTransformableCanvas implements Canvas {
714
755
  private readonly canvas;
715
- private readonly options?;
716
756
  readonly model: PublicGraphStore;
717
757
  readonly transformation: PublicViewportTransformer;
718
758
  private element;
719
759
  private prevTouches;
720
- private readonly onTransformFinished;
721
- private readonly transformPreprocessor;
722
- private readonly isScalable;
723
- private readonly isShiftable;
724
- private readonly wheelSensitivity;
725
760
  private window;
726
761
  private readonly onMouseDown;
727
- private readonly onMouseMove;
728
- private readonly onMouseUp;
762
+ private readonly onWindowMouseMove;
763
+ private readonly onWindowMouseUp;
729
764
  private readonly onWheelScroll;
730
765
  private readonly onTouchStart;
731
- private readonly onTouchMove;
732
- private readonly onTouchEnd;
766
+ private readonly onWindowTouchMove;
767
+ private readonly onWindowTouchFinish;
733
768
  private readonly observer;
734
- private readonly shiftCursor;
735
- constructor(canvas: Canvas, options?: TransformOptions | undefined);
769
+ private readonly options;
770
+ constructor(canvas: Canvas, transformOptions?: TransformOptions);
771
+ attach(element: HTMLElement): UserTransformableCanvas;
772
+ detach(): UserTransformableCanvas;
736
773
  addNode(node: AddNodeRequest): UserTransformableCanvas;
737
774
  updateNode(nodeId: unknown, request?: UpdateNodeRequest): UserTransformableCanvas;
738
775
  removeNode(nodeId: unknown): UserTransformableCanvas;
739
776
  markPort(port: MarkPortRequest): UserTransformableCanvas;
740
- updatePort(portId: string, request?: UpdatePortRequest): UserTransformableCanvas;
777
+ updatePortMark(portId: string, request?: UpdatePortMarkRequest): UserTransformableCanvas;
741
778
  unmarkPort(portId: string): UserTransformableCanvas;
742
779
  addEdge(edge: AddEdgeRequest): UserTransformableCanvas;
743
780
  updateEdge(edgeId: unknown, request?: UpdateEdgeRequest): UserTransformableCanvas;
@@ -745,10 +782,7 @@ export declare class UserTransformableCanvas implements Canvas {
745
782
  patchViewportMatrix(request: PatchMatrixRequest): UserTransformableCanvas;
746
783
  patchContentMatrix(request: PatchMatrixRequest): UserTransformableCanvas;
747
784
  clear(): UserTransformableCanvas;
748
- attach(element: HTMLElement): UserTransformableCanvas;
749
- detach(): UserTransformableCanvas;
750
785
  destroy(): void;
751
- private getAverageTouch;
752
786
  private moveViewport;
753
787
  private scaleViewport;
754
788
  private stopMouseDrag;