@mp70/react-networks 0.1.1-alpha → 0.1.5-alpha

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/dist/index.d.ts CHANGED
@@ -1,5 +1,5 @@
1
1
  import React$1 from 'react';
2
- import { NodeProps, EdgeProps } from 'reactflow';
2
+ import { NodeProps, EdgeProps, Edge, Connection } from 'reactflow';
3
3
 
4
4
  /**
5
5
  * Rack device width configuration
@@ -39,7 +39,7 @@ interface PortBlock {
39
39
  * Network node types supported by the diagram
40
40
  * @public
41
41
  */
42
- type NetworkNodeType = 'rack' | 'switch' | 'router' | 'server' | 'fiber' | 'patch-panel' | 'device' | 'vertical-pdu';
42
+ type NetworkNodeType = 'rack' | 'switch' | 'router' | 'server' | 'fiber' | 'patch-panel' | 'device' | 'vertical-pdu' | 'splice' | 'splice-tray' | 'tube' | 'cable';
43
43
  /**
44
44
  * Device status states
45
45
  * @public
@@ -118,6 +118,10 @@ interface NetworkNode {
118
118
  uNumberingDirection?: UNumberingDirection;
119
119
  /** Custom header text for rack nodes */
120
120
  customHeaderText?: string;
121
+ /** Holder position within tray (1-12) for splice nodes */
122
+ holderPosition?: number;
123
+ /** Loss value in dB for splice nodes */
124
+ lossDb?: number;
121
125
  /** Additional custom properties */
122
126
  [key: string]: any;
123
127
  };
@@ -126,7 +130,7 @@ interface NetworkNode {
126
130
  * Network edge types
127
131
  * @public
128
132
  */
129
- type NetworkEdgeType = 'fiber' | 'ethernet' | 'power';
133
+ type NetworkEdgeType = 'fiber' | 'ethernet' | 'power' | 'smoothstep' | 'step';
130
134
  /**
131
135
  * Network edge data structure
132
136
  * @public
@@ -242,6 +246,37 @@ interface FiberCable {
242
246
  to: string;
243
247
  };
244
248
  }
249
+ /**
250
+ * Splice configuration structure
251
+ * @public
252
+ */
253
+ interface SpliceConfig {
254
+ /** Unique splice identifier */
255
+ id: string;
256
+ /** Splice display name */
257
+ name: string;
258
+ /** Holder position within tray (1-12) */
259
+ holder: number;
260
+ /** Loss value in dB */
261
+ lossDb?: number;
262
+ }
263
+ /**
264
+ * Splice tray configuration structure
265
+ * @public
266
+ */
267
+ interface SpliceTrayConfig {
268
+ /** Unique tray identifier */
269
+ id: string;
270
+ /** Tray display name */
271
+ name: string;
272
+ /** Tray position coordinates */
273
+ position: {
274
+ x: number;
275
+ y: number;
276
+ };
277
+ /** Splices in this tray */
278
+ splices: SpliceConfig[];
279
+ }
245
280
  /**
246
281
  * Network diagram component props
247
282
  * @public
@@ -285,6 +320,8 @@ interface NetworkDiagramProps {
285
320
  onFlowMethods?: (methods: {
286
321
  toObject: () => any;
287
322
  setViewport: (viewport: any) => void;
323
+ setNodes: (nodes: any[]) => void;
324
+ setEdges: (edges: any[]) => void;
288
325
  toImage: (options?: any) => Promise<string>;
289
326
  }) => void;
290
327
  /** Show download button */
@@ -295,6 +332,10 @@ interface NetworkDiagramProps {
295
332
  downloadButtonText?: string;
296
333
  /** Download button styling options */
297
334
  downloadButtonStyle?: React.CSSProperties;
335
+ /** Allow reconnecting existing edges from either end */
336
+ allowReconnectExisting?: boolean;
337
+ /** Use smoothstep edges for tube connections (both tube-to-cable and cable-to-tube). Default is fiber. */
338
+ useSmoothstepEdgesForTubes?: boolean;
298
339
  }
299
340
 
300
341
  declare const NetworkDiagram: React$1.FC<NetworkDiagramProps>;
@@ -308,7 +349,9 @@ declare const RackNode: React$1.FC<RackNodeProps>;
308
349
 
309
350
  declare const FiberNode: React$1.FC<NodeProps<NetworkNode['data']>>;
310
351
 
311
- declare const FiberEdge: React$1.FC<EdgeProps<NetworkEdge['data']>>;
352
+ declare const FiberEdge: React$1.FC<EdgeProps<NetworkEdge['data']> & {
353
+ className?: string;
354
+ }>;
312
355
 
313
356
  declare const PowerEdge: React$1.FC<EdgeProps>;
314
357
 
@@ -316,6 +359,30 @@ declare const DeviceNode: React$1.FC<NodeProps<NetworkNode['data']>>;
316
359
 
317
360
  declare const VerticalPDU: React$1.FC<NodeProps<NetworkNode['data']>>;
318
361
 
362
+ declare const SpliceNode: React$1.FC<NodeProps<NetworkNode['data']>>;
363
+
364
+ declare const SpliceTrayNode: React$1.FC<NodeProps<NetworkNode['data']>>;
365
+
366
+ /**
367
+ * TubeNode
368
+ * - Rectangular node representing a buffer tube (horizontal orientation, rotated 180 degrees)
369
+ * - Renders 12 or 24 fiber handles on the top side with TIA-598 colors
370
+ * - Tube border tinted by tube index color (1..12 cycling)
371
+ * - startOn parameter controls handle positioning:
372
+ * - 'left-center' (default): handles centered on top, tube handle on bottom
373
+ * - 'left': handles on left side, tube handle on left
374
+ * - 'right': handles on right side with reversed colors, tube handle on right
375
+ */
376
+ declare const TubeNode: React$1.FC<NodeProps<NetworkNode['data']>>;
377
+
378
+ /**
379
+ * CableNode
380
+ * - Visually mirrors TubeNode but represents an entire cable
381
+ * - Each colored handle corresponds to a tube within the cable
382
+ * - Displays cable summary text (fiber count + cable identifier)
383
+ */
384
+ declare const CableNode: React$1.FC<NodeProps<NetworkNode['data']>>;
385
+
319
386
  interface InventoryRackDTO {
320
387
  id: string | number;
321
388
  name: string;
@@ -459,6 +526,29 @@ declare const updateDeviceUPosition$1: (device: NetworkNode, rack: NetworkNode,
459
526
  */
460
527
  declare const validateAndSnapDevice: (device: NetworkNode, rack: NetworkNode) => NetworkNode;
461
528
 
529
+ /**
530
+ * Snap a splice to the nearest holder position within a tray
531
+ */
532
+ declare const snapToSplicePosition: (splice: NetworkNode, tray: NetworkNode, newPosition: {
533
+ x: number;
534
+ y: number;
535
+ }, allNodes: NetworkNode[]) => {
536
+ x: number;
537
+ y: number;
538
+ holderPosition?: number;
539
+ };
540
+ /**
541
+ * Find the next available holder position
542
+ */
543
+ declare const findNextAvailableHolderPosition: (tray: NetworkNode, splice: NetworkNode, allNodes: NetworkNode[], startFrom?: number) => number;
544
+ /**
545
+ * Calculate splice position based on holder number within a tray
546
+ */
547
+ declare const calculateSplicePositionFromNumber: (tray: NetworkNode, holderPosition: number) => {
548
+ x: number;
549
+ y: number;
550
+ };
551
+
462
552
  /**
463
553
  * Configuration options for building nodes from rack schema
464
554
  */
@@ -502,7 +592,7 @@ interface DevicePlacementValidation {
502
592
  /**
503
593
  * Validate device placements within a rack schema
504
594
  */
505
- declare function validateRackDevicePlacements(rack: RackConfig, options?: RackSchemaOptions): DevicePlacementValidation;
595
+ declare function validateRackDevicePlacements(rack: RackConfig, _options?: RackSchemaOptions): DevicePlacementValidation;
506
596
  /**
507
597
  * Build NetworkNode array from RackConfig array with comprehensive validation
508
598
  */
@@ -524,6 +614,66 @@ declare function addDeviceToRack(racks: RackConfig[], rackId: string, device: Ra
524
614
  */
525
615
  declare function removeDeviceFromRack(racks: RackConfig[], rackId: string, deviceId: string): RackConfig[];
526
616
 
617
+ /**
618
+ * Configuration options for building nodes from splice schema
619
+ */
620
+ interface SpliceSchemaOptions {
621
+ /** How to handle splice placement conflicts */
622
+ conflictPolicy?: 'strict' | 'nearest';
623
+ /** Whether to validate all placements before creating nodes */
624
+ validatePlacements?: boolean;
625
+ }
626
+ /**
627
+ * Error thrown when splice placement conflicts occur in strict mode
628
+ */
629
+ declare class SplicePlacementError extends Error {
630
+ trayId: string;
631
+ spliceId: string;
632
+ holder: number;
633
+ conflictWith?: string | undefined;
634
+ constructor(trayId: string, spliceId: string, holder: number, conflictWith?: string | undefined);
635
+ }
636
+ /**
637
+ * Validation result for splice placement
638
+ */
639
+ interface SplicePlacementValidation {
640
+ isValid: boolean;
641
+ conflicts: Array<{
642
+ spliceId: string;
643
+ holder: number;
644
+ conflictWith: string;
645
+ }>;
646
+ outOfBounds: Array<{
647
+ spliceId: string;
648
+ holder: number;
649
+ max: number;
650
+ }>;
651
+ }
652
+ /**
653
+ * Validate splice placements within a tray schema
654
+ */
655
+ declare function validateSplicePlacements(tray: SpliceTrayConfig, _options?: SpliceSchemaOptions): SplicePlacementValidation;
656
+ /**
657
+ * Build NetworkNode array from SpliceTrayConfig array with comprehensive validation
658
+ */
659
+ declare function buildNodesFromSpliceConfig(trays: SpliceTrayConfig[], options?: SpliceSchemaOptions): NetworkNode[];
660
+ /**
661
+ * Create a SpliceTrayConfig from existing NetworkNode data (reverse operation)
662
+ */
663
+ declare function createSpliceConfigFromNodes(nodes: NetworkNode[]): SpliceTrayConfig[];
664
+ /**
665
+ * Update splice holder position in a splice schema
666
+ */
667
+ declare function updateSpliceHolderPosition(trays: SpliceTrayConfig[], trayId: string, spliceId: string, newHolder: number): SpliceTrayConfig[];
668
+ /**
669
+ * Add a splice to a tray schema
670
+ */
671
+ declare function addSpliceToTray(trays: SpliceTrayConfig[], trayId: string, splice: SpliceConfig, options?: SpliceSchemaOptions): SpliceTrayConfig[];
672
+ /**
673
+ * Remove a splice from a tray schema
674
+ */
675
+ declare function removeSpliceFromTray(trays: SpliceTrayConfig[], trayId: string, spliceId: string): SpliceTrayConfig[];
676
+
527
677
  /**
528
678
  * Power connector utilities for consistent styling across devices and PDUs
529
679
  */
@@ -567,6 +717,118 @@ declare function getPDUPortType(portIndex: number): string;
567
717
  */
568
718
  declare function getDeviceConnectorType(deviceName: string): string;
569
719
 
720
+ /**
721
+ * Get the color code for a device status
722
+ * @param status - The device status
723
+ * @returns Hex color code for the status
724
+ * @public
725
+ */
726
+ declare function getStatusColor(status: DeviceStatus | string): string;
727
+
728
+ /**
729
+ * TIA-598-C standard fiber optic color codes (12 base colors)
730
+ * Colors 1-12: Blue, Orange, Green, Brown, Slate, White, Red, Black, Yellow, Violet, Rose, Aqua
731
+ * @public
732
+ */
733
+ declare const FIBER_COLORS_12: readonly ["#1f77b4", "#ff7f0e", "#2ca02c", "#8c564b", "#708090", "#ffffff", "#d62728", "#000000", "#ffdf00", "#8a2be2", "#ff69b4", "#00ffff"];
734
+ /**
735
+ * Fiber color ID type (1-24)
736
+ * @public
737
+ */
738
+ type FiberColorId = 1 | 2 | 3 | 4 | 5 | 6 | 7 | 8 | 9 | 10 | 11 | 12 | 13 | 14 | 15 | 16 | 17 | 18 | 19 | 20 | 21 | 22 | 23 | 24;
739
+ /**
740
+ * Get the base color for a fiber color ID
741
+ * Colors 13-24 use the same base colors as 1-12
742
+ * @param id - Fiber color ID (1-24)
743
+ * @returns Hex color code
744
+ * @public
745
+ */
746
+ declare function baseColorFor(id: FiberColorId | number): string;
747
+ /**
748
+ * Check if a fiber color ID uses a striped pattern (13-24)
749
+ * @param id - Fiber color ID (1-24)
750
+ * @returns True if the color should be striped
751
+ * @public
752
+ */
753
+ declare function isStriped(id: FiberColorId | number): boolean;
754
+ /**
755
+ * Get CSS properties for a fiber color (solid or striped)
756
+ * Colors 13-24 use a black stripe pattern over the base color
757
+ * @param id - Fiber color ID (1-24)
758
+ * @returns CSS properties for the color
759
+ * @public
760
+ */
761
+ declare function fiberSolidOrStriped(id: FiberColorId | number): React$1.CSSProperties;
762
+ /**
763
+ * Get the hex color code for a fiber color ID
764
+ * @param id - Fiber color ID (1-24)
765
+ * @returns Hex color code
766
+ * @public
767
+ */
768
+ declare function getFiberColor(id: FiberColorId | number): string;
769
+
770
+ /**
771
+ * Calculate the bounding box of a rack node
772
+ * @param rack - The rack node
773
+ * @returns Object with left, right, top, and bottom coordinates
774
+ * @public
775
+ */
776
+ declare function getRackBounds(rack: NetworkNode): {
777
+ left: number;
778
+ right: number;
779
+ top: number;
780
+ bottom: number;
781
+ };
782
+ /**
783
+ * Check if a point is inside a rack's bounds
784
+ * @param point - The point coordinates { x, y }
785
+ * @param rack - The rack node
786
+ * @returns True if the point is inside the rack
787
+ * @public
788
+ */
789
+ declare function isPointInRack(point: {
790
+ x: number;
791
+ y: number;
792
+ }, rack: NetworkNode): boolean;
793
+ /**
794
+ * Find the nearest rack to a point from a list of racks
795
+ * Only considers racks that contain the point
796
+ * @param point - The point coordinates { x, y }
797
+ * @param racks - Array of rack nodes
798
+ * @returns The nearest rack node, or null if no rack contains the point
799
+ * @public
800
+ */
801
+ declare function findNearestRack(point: {
802
+ x: number;
803
+ y: number;
804
+ }, racks: NetworkNode[]): NetworkNode | null;
805
+
806
+ /**
807
+ * Options for replacing an edge in the edges array
808
+ */
809
+ interface ReplaceEdgeOptions {
810
+ /** Existing edges array */
811
+ edges: Edge[];
812
+ /** Connection parameters for the new edge */
813
+ connection: Connection;
814
+ /** Type of edge to create */
815
+ edgeType: 'power' | 'fiber' | 'step' | 'smoothstep';
816
+ /** Function to calculate zIndex for the edge */
817
+ selectEdgeZIndex: (edge: NetworkEdge) => number;
818
+ /** Whether to find edge by source or target */
819
+ findBy: 'source' | 'target';
820
+ /** Optional edge data to set on the new edge */
821
+ data?: NetworkEdge['data'];
822
+ }
823
+ /**
824
+ * Replace an existing edge with a new connection
825
+ * This is used for PDU and switch connections that allow replacing existing edges
826
+ * @param options - Options for edge replacement
827
+ * @returns New edges array with the edge replaced, or null if no existing edge found
828
+ * @public
829
+ */
830
+ declare function replaceEdge(options: ReplaceEdgeOptions): Edge[] | null;
831
+
570
832
  interface NetworkDiagramState {
571
833
  nodes: NetworkNode[];
572
834
  edges: NetworkEdge[];
@@ -600,4 +862,4 @@ declare function useNetworkDiagram(store: NetworkDiagramStore): NetworkDiagramSt
600
862
  declare function useNodes(store: NetworkDiagramStore): NetworkNode[];
601
863
  declare function useEdges(store: NetworkDiagramStore): NetworkEdge[];
602
864
 
603
- export { DeviceNode, DevicePlacementError, type DevicePlacementValidation, type FiberCable, FiberEdge, FiberNode, NetworkDiagram, type NetworkDiagramProps, type NetworkEdge, type NetworkNode, POWER_CONNECTORS, PowerEdge, type RackConfig, type RackDevice, RackNode, type RackSchemaOptions, VerticalPDU, Width, addDeviceToRack, buildNodesFromRackConfig, calculateDevicePositionFromU, createNetworkDiagramStore, createRackConfigFromNodes, findNextAvailableUPosition, generateLayout, getConnectorConfig, getDeviceConnectorType, getPDUPortType, getPowerPortStyle, inventoryCableToNetworkEdge, inventoryDeviceToNetworkNode, inventoryRackToNetworkNode, inventoryToNetworkDiagram, isHighPowerConnector, isUPositionAvailable, removeDeviceFromRack, snapToUPosition, updateDeviceUPosition$1 as updateDeviceUPosition, updateDeviceUPosition as updateDeviceUPositionInSchema, useEdges as useDiagramEdges, useNodes as useDiagramNodes, useNetworkDiagram, validateAndSnapDevice, validateRackDevicePlacements };
865
+ export { CableNode, DeviceNode, DevicePlacementError, type DevicePlacementValidation, FIBER_COLORS_12, type FiberCable, type FiberColorId, FiberEdge, FiberNode, NetworkDiagram, type NetworkDiagramProps, type NetworkEdge, type NetworkNode, POWER_CONNECTORS, type Port, type PortBlock, PowerEdge, type RackConfig, type RackDevice, RackNode, type RackSchemaOptions, type ReplaceEdgeOptions, type SpliceConfig, SpliceNode, SplicePlacementError, type SplicePlacementValidation, type SpliceSchemaOptions, type SpliceTrayConfig, SpliceTrayNode, TubeNode, VerticalPDU, Width, addDeviceToRack, addSpliceToTray, baseColorFor, buildNodesFromRackConfig, buildNodesFromSpliceConfig, calculateDevicePositionFromU, calculateSplicePositionFromNumber, createNetworkDiagramStore, createRackConfigFromNodes, createSpliceConfigFromNodes, fiberSolidOrStriped, findNearestRack, findNextAvailableHolderPosition, findNextAvailableUPosition, generateLayout, getConnectorConfig, getDeviceConnectorType, getFiberColor, getPDUPortType, getPowerPortStyle, getRackBounds, getStatusColor, inventoryCableToNetworkEdge, inventoryDeviceToNetworkNode, inventoryRackToNetworkNode, inventoryToNetworkDiagram, isHighPowerConnector, isPointInRack, isStriped, isUPositionAvailable, removeDeviceFromRack, removeSpliceFromTray, replaceEdge, snapToSplicePosition, snapToUPosition, updateDeviceUPosition$1 as updateDeviceUPosition, updateDeviceUPosition as updateDeviceUPositionInSchema, updateSpliceHolderPosition, useEdges as useDiagramEdges, useNodes as useDiagramNodes, useNetworkDiagram, validateAndSnapDevice, validateRackDevicePlacements, validateSplicePlacements };