@html-graph/html-graph 3.1.0 → 3.3.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
@@ -62,6 +62,7 @@ const canvas = new CanvasBuilder()
62
62
  })
63
63
  .enableUserDraggableNodes()
64
64
  .enableUserTransformableViewport()
65
+ .enableBackground()
65
66
  .build();
66
67
 
67
68
  canvas
@@ -42,6 +42,15 @@ declare interface AddPortRequest {
42
42
  readonly direction: number;
43
43
  }
44
44
 
45
+ declare interface BackgroundOptions {
46
+ readonly tileDimensions?: {
47
+ readonly width?: number;
48
+ readonly height?: number;
49
+ };
50
+ readonly renderer?: DotsRenderer | SVGElement;
51
+ readonly maxViewportScale?: number;
52
+ }
53
+
45
54
  export declare interface BezierEdgeParams {
46
55
  readonly color?: string | undefined;
47
56
  readonly width?: number | undefined;
@@ -79,13 +88,19 @@ declare type BezierEdgeShapeConfig = {
79
88
  readonly type?: "bezier" | undefined;
80
89
  } & BezierEdgeParams;
81
90
 
91
+ /**
92
+ * Responsibility: provides graph rendering API for end user
93
+ */
82
94
  export declare class Canvas {
95
+ /**
96
+ * @deprecated access element directly instead
97
+ */
83
98
  readonly element: HTMLElement;
84
99
  private readonly graphStore;
85
100
  private readonly viewportStore;
86
101
  private readonly htmlView;
87
102
  /**
88
- * provides api for accessing graph model
103
+ * provides api for accessing model of rendered graph
89
104
  */
90
105
  readonly graph: Graph;
91
106
  /**
@@ -109,10 +124,17 @@ export declare class Canvas {
109
124
  private readonly onBeforeEdgeRemoved;
110
125
  private readonly onBeforeClear;
111
126
  private readonly onBeforeDestroyEmitter;
127
+ /**
128
+ * emits event just before destruction of canvas
129
+ */
112
130
  readonly onBeforeDestroy: EventHandler<void>;
113
- constructor(element: HTMLElement, graphStore: GraphStore, viewportStore: ViewportStore, htmlView: HtmlView, options: CanvasDefaults);
131
+ constructor(
114
132
  /**
115
- * adds node to graph
133
+ * @deprecated access element directly instead
134
+ */
135
+ element: HTMLElement, graphStore: GraphStore, viewportStore: ViewportStore, htmlView: HtmlView, defaults: CanvasDefaults);
136
+ /**
137
+ * adds new node
116
138
  */
117
139
  addNode(request: AddNodeRequest): Canvas;
118
140
  /**
@@ -120,42 +142,42 @@ export declare class Canvas {
120
142
  */
121
143
  updateNode(nodeId: unknown, request?: UpdateNodeRequest): Canvas;
122
144
  /**
123
- * removes node from graph
145
+ * removes specified node
124
146
  * all the ports of node get unmarked
125
147
  * all the edges adjacent to node get removed
126
148
  */
127
149
  removeNode(nodeId: unknown): Canvas;
128
150
  /**
129
- * marks element as port of node
151
+ * marks specified element as a port for specified node
130
152
  */
131
153
  markPort(request: MarkPortRequest): Canvas;
132
154
  /**
133
- * updates port and attached edges
155
+ * updates port and edges attached to it
134
156
  */
135
157
  updatePort(portId: unknown, request?: UpdatePortRequest): Canvas;
136
158
  /**
137
- * ummarks element as port of node
138
- * all the edges adjacent to port get removed
159
+ * unmarks specified port
160
+ * all the edges adjacent to the port get removed
139
161
  */
140
162
  unmarkPort(portId: unknown): Canvas;
141
163
  /**
142
- * adds edge to graph
164
+ * adds new edge
143
165
  */
144
166
  addEdge(request: AddEdgeRequest): Canvas;
145
167
  /**
146
- * updates edge
168
+ * updates specified edge
147
169
  */
148
170
  updateEdge(edgeId: unknown, request?: UpdateEdgeRequest): Canvas;
149
171
  /**
150
- * removes edge from graph
172
+ * removes specified edge
151
173
  */
152
174
  removeEdge(edgeId: unknown): Canvas;
153
175
  /**
154
- * applies transformation for viewport
176
+ * applies transformation for viewport matrix
155
177
  */
156
178
  patchViewportMatrix(request: PatchMatrixRequest): Canvas;
157
179
  /**
158
- * applies transformation for content
180
+ * applies transformation for content matrix
159
181
  */
160
182
  patchContentMatrix(request: PatchMatrixRequest): Canvas;
161
183
  /**
@@ -170,16 +192,24 @@ export declare class Canvas {
170
192
  destroy(): void;
171
193
  }
172
194
 
195
+ /**
196
+ * Responsibility: Constructs canvas based on specified configuration
197
+ */
173
198
  export declare class CanvasBuilder {
174
199
  private element;
175
200
  private canvasDefaults;
176
201
  private dragOptions;
177
202
  private transformOptions;
203
+ private backgroundOptions;
204
+ private connectablePortsOptions;
178
205
  private virtualScrollOptions;
179
206
  private hasDraggableNode;
180
207
  private hasTransformableViewport;
181
208
  private hasResizeReactiveNodes;
209
+ private hasBackground;
210
+ private hasUserConnectablePorts;
182
211
  private boxRenderingTrigger;
212
+ private readonly window;
183
213
  setElement(element: HTMLElement): CanvasBuilder;
184
214
  /**
185
215
  * specifies default values for graph entities
@@ -201,11 +231,27 @@ export declare class CanvasBuilder {
201
231
  * sets emitter for rendering graph inside bounded area
202
232
  */
203
233
  enableBoxAreaRendering(trigger: EventSubject<RenderingBox>): CanvasBuilder;
234
+ /**
235
+ * enables built-in virtual scroll behavior, when only nodes and edges close
236
+ * to viewport are rendered
237
+ */
204
238
  enableVirtualScroll(options: VirtualScrollOptions): CanvasBuilder;
239
+ /**
240
+ * enables built-in background rendering
241
+ */
242
+ enableBackground(options?: BackgroundOptions): CanvasBuilder;
243
+ /**
244
+ * enables edge creation by dragging one port to another
245
+ */
246
+ enableUserConnectablePorts(options?: ConnectablePortsOptions): CanvasBuilder;
205
247
  /**
206
248
  * builds final canvas
207
249
  */
208
250
  build(): Canvas;
251
+ /**
252
+ * @deprecated
253
+ * CanvasBuilder should be single use object
254
+ */
209
255
  private reset;
210
256
  }
211
257
 
@@ -250,16 +296,34 @@ export declare interface CanvasDefaults {
250
296
 
251
297
  export declare type CenterFn = (width: number, height: number) => Point;
252
298
 
299
+ export declare interface ConnectablePortsOptions {
300
+ readonly connectionTypeResolver?: ConnectionTypeResolver;
301
+ readonly connectionPreprocessor?: ConnectionPreprocessor;
302
+ readonly mouseDownEventVerifier?: MouseEventVerifier;
303
+ readonly events?: {
304
+ readonly onAfterEdgeCreated?: (edgeId: unknown) => void;
305
+ };
306
+ }
307
+
308
+ export declare type ConnectionPreprocessor = (request: AddEdgeRequest) => AddEdgeRequest | null;
309
+
310
+ export declare type ConnectionTypeResolver = (portId: unknown) => "direct" | "reverse" | null;
311
+
253
312
  declare type ConstantPriority = number;
254
313
 
255
314
  declare type CustomPriority = PriorityFn;
256
315
 
316
+ declare interface DotsRenderer {
317
+ readonly radius?: number;
318
+ readonly color?: string;
319
+ }
320
+
257
321
  export declare interface DragOptions {
258
322
  readonly moveOnTop?: boolean;
259
323
  readonly mouse?: {
260
324
  readonly dragCursor?: string | null;
261
- readonly mouseDownEventVerifier?: (event: MouseEvent) => boolean;
262
- readonly mouseUpEventVerifier?: (event: MouseEvent) => boolean;
325
+ readonly mouseDownEventVerifier?: MouseEventVerifier;
326
+ readonly mouseUpEventVerifier?: MouseEventVerifier;
263
327
  };
264
328
  readonly events?: {
265
329
  readonly onNodeDrag?: (payload: NodeDragPayload) => void;
@@ -290,6 +354,9 @@ export declare interface EdgeRenderPort {
290
354
  readonly nodeId: unknown;
291
355
  }
292
356
 
357
+ /**
358
+ * Responsibility: Rendering edge via SVG
359
+ */
293
360
  export declare interface EdgeShape {
294
361
  readonly svg: SVGSVGElement;
295
362
  render(params: EdgeRenderParams): void;
@@ -299,15 +366,24 @@ declare type EdgeShapeConfig = BezierEdgeShapeConfig | StraightEdgeShapeConfig |
299
366
 
300
367
  declare type EdgeShapeFactory = () => EdgeShape;
301
368
 
369
+ /**
370
+ * Responsibility: Provides a way to trigger events
371
+ */
302
372
  export declare interface EventEmitter<T> {
303
373
  emit(payload: T): void;
304
374
  }
305
375
 
376
+ /**
377
+ * Responsibility: Provides a way to handle events
378
+ */
306
379
  export declare interface EventHandler<T> {
307
380
  subscribe(callback: (payload: T) => void): void;
308
381
  unsubscribe(callback: (payload: T) => void): void;
309
382
  }
310
383
 
384
+ /**
385
+ * Responsibility: Connects events and event handlers
386
+ */
311
387
  export declare class EventSubject<T> implements EventEmitter<T>, EventHandler<T> {
312
388
  private readonly callbacks;
313
389
  subscribe(callback: (payload: T) => void): void;
@@ -316,7 +392,7 @@ export declare class EventSubject<T> implements EventEmitter<T>, EventHandler<T>
316
392
  }
317
393
 
318
394
  /**
319
- * This entity is responsible for providing access to end user in a safe way
395
+ * Responsibility: Provides access to graph model for end user
320
396
  */
321
397
  export declare class Graph {
322
398
  private readonly graphStore;
@@ -372,14 +448,14 @@ export declare interface GraphPort {
372
448
  }
373
449
 
374
450
  /**
375
- * This entity is responsible for storing state of graph
451
+ * Responsibility: Stores stae of graph
376
452
  */
377
453
  declare class GraphStore {
378
454
  private readonly nodes;
379
455
  private readonly ports;
380
456
  private readonly edges;
381
- private readonly incommingEdges;
382
- private readonly outcommingEdges;
457
+ private readonly incomingEdges;
458
+ private readonly outcomingEdges;
383
459
  private readonly cycleEdges;
384
460
  private readonly afterNodeAddedEmitter;
385
461
  readonly onAfterNodeAdded: EventHandler<unknown>;
@@ -474,10 +550,17 @@ declare type HorizontalEdgeShapeConfig = {
474
550
  readonly type: "horizontal";
475
551
  } & HorizontalEdgeParams;
476
552
 
553
+ /**
554
+ * Responsibility: Library specific error to throw when unexpected action
555
+ * occured
556
+ */
477
557
  export declare class HtmlGraphError extends Error {
478
558
  readonly name = "HtmlGraphError";
479
559
  }
480
560
 
561
+ /**
562
+ * Responsibility: Provides access to DOM modifications
563
+ */
481
564
  declare interface HtmlView {
482
565
  attachNode(nodeId: unknown): void;
483
566
  detachNode(nodeId: unknown): void;
@@ -507,6 +590,8 @@ export declare interface MarkPortRequest {
507
590
  readonly direction?: number;
508
591
  }
509
592
 
593
+ export declare type MouseEventVerifier = (event: MouseEvent) => boolean;
594
+
510
595
  export declare interface NodeDragPayload {
511
596
  readonly nodeId: unknown;
512
597
  readonly element: HTMLElement;
@@ -535,6 +620,9 @@ declare interface PatchTransformRequest {
535
620
  readonly y?: number;
536
621
  }
537
622
 
623
+ /**
624
+ * Responsibility: Specifies point coordinates
625
+ */
538
626
  export declare interface Point {
539
627
  readonly x: number;
540
628
  readonly y: number;
@@ -548,6 +636,9 @@ declare interface PortPayload {
548
636
 
549
637
  declare type Priority = ConstantPriority | IncrementalPriority | CustomPriority;
550
638
 
639
+ /**
640
+ * Responsibility: Specifies how to determine Z-index of an entity in DOM
641
+ */
551
642
  export declare type PriorityFn = () => number;
552
643
 
553
644
  export declare interface RenderingBox {
@@ -614,8 +705,8 @@ export declare interface TransformOptions {
614
705
  };
615
706
  readonly shift?: {
616
707
  readonly cursor?: string | null;
617
- readonly mouseDownEventVerifier?: (event: MouseEvent) => boolean;
618
- readonly mouseUpEventVerifier?: (event: MouseEvent) => boolean;
708
+ readonly mouseDownEventVerifier?: MouseEventVerifier;
709
+ readonly mouseUpEventVerifier?: MouseEventVerifier;
619
710
  };
620
711
  readonly transformPreprocessor?: TransformPreprocessorOption | TransformPreprocessorOption[];
621
712
  readonly events?: {
@@ -735,19 +826,19 @@ declare type VerticalEdgeShapeConfig = {
735
826
  } & VerticalEdgeParams;
736
827
 
737
828
  /**
738
- * This entity is responsible for providing viewport API
829
+ * Responsibility: Provides access to viewport state for end user
739
830
  */
740
831
  export declare class Viewport {
741
- private readonly transformer;
832
+ private readonly viewportStore;
742
833
  readonly onBeforeUpdated: EventHandler<void>;
743
834
  readonly onAfterUpdated: EventHandler<void>;
744
- constructor(transformer: ViewportStore);
835
+ constructor(viewportStore: ViewportStore);
745
836
  getViewportMatrix(): TransformState;
746
837
  getContentMatrix(): TransformState;
747
838
  }
748
839
 
749
840
  /**
750
- * This entity is responsible for storing viewport transformation
841
+ * Responsibility: Stores viewport transformation state
751
842
  */
752
843
  declare class ViewportStore {
753
844
  private viewportMatrix;