@3plate/graph-core 0.1.5 → 0.1.7

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.cts CHANGED
@@ -75,6 +75,8 @@ type GraphOptions = {
75
75
  * Events that can be handled by the user.
76
76
  */
77
77
  type EventsOptions<N, E> = {
78
+ /** Called when the API has finished initializing */
79
+ onInit?: () => void;
78
80
  /** Called when a node is clicked */
79
81
  nodeClick?: (node: N) => void;
80
82
  /** Called when an edge is clicked */
@@ -323,11 +325,17 @@ declare class Updater<N, E> {
323
325
  constructor();
324
326
  describe(desc: string): Updater<N, E>;
325
327
  addNode(node: any): Updater<N, E>;
328
+ addNodes(...nodes: any[]): Updater<N, E>;
326
329
  deleteNode(node: any): Updater<N, E>;
330
+ deleteNodes(...nodes: any[]): Updater<N, E>;
327
331
  updateNode(node: any): Updater<N, E>;
332
+ updateNodes(...nodes: any[]): Updater<N, E>;
328
333
  addEdge(edge: any): Updater<N, E>;
334
+ addEdges(...edges: any[]): Updater<N, E>;
329
335
  deleteEdge(edge: any): Updater<N, E>;
336
+ deleteEdges(...edges: any[]): Updater<N, E>;
330
337
  updateEdge(edge: any): Updater<N, E>;
338
+ updateEdges(...edges: any[]): Updater<N, E>;
331
339
  static add<N, E>(nodes: N[], edges: E[]): Updater<N, E>;
332
340
  }
333
341
 
@@ -362,17 +370,23 @@ declare class API<N, E> {
362
370
  private nextNodeId;
363
371
  private nextEdgeId;
364
372
  private events;
365
- private root;
373
+ root: string;
366
374
  constructor(args: APIArguments<N, E>);
375
+ reset(): void;
376
+ /** Initialize the API */
377
+ init(): Promise<void>;
378
+ private applyHistory;
367
379
  /** Current history index (0-based) */
368
380
  getHistoryIndex(): number;
369
381
  /** Current history length */
370
382
  getHistoryLength(): number;
371
383
  /** Toggle canvas editable mode without re-creating the graph */
372
384
  setEditable(editable: boolean): void;
385
+ /** Replace entire history (clears prior) */
386
+ replaceHistory(frames: Update<N, E>[]): Promise<void>;
387
+ /** Rebuild from snapshot (nodes/edges) */
388
+ replaceSnapshot(nodes: N[], edges: E[], description?: string): Promise<void>;
373
389
  private get graph();
374
- /** Initialize the API */
375
- init(): Promise<void>;
376
390
  /** Navigate to a different state */
377
391
  nav(nav: Nav): void;
378
392
  private applyDiff;
@@ -424,8 +438,214 @@ declare class API<N, E> {
424
438
  handleAddEdge(data: EditEdgeProps): Promise<void>;
425
439
  handleDeleteNode(id: NodeId): Promise<void>;
426
440
  handleDeleteEdge(id: EdgeId): Promise<void>;
441
+ /** Update theme and type styles dynamically */
442
+ updateStyles(options: {
443
+ theme?: ThemeVars;
444
+ nodeTypes?: Record<string, ThemeVars>;
445
+ edgeTypes?: Record<string, ThemeVars>;
446
+ }): void;
447
+ /** Update color mode without recreating the canvas */
448
+ setColorMode(colorMode: 'light' | 'dark' | 'system'): void;
449
+ /** Cleanup resources when the graph is destroyed */
450
+ destroy(): void;
451
+ }
452
+
453
+ type SnapshotMessage<N, E> = {
454
+ type: 'snapshot';
455
+ nodes: N[];
456
+ edges: E[];
457
+ description?: string;
458
+ };
459
+ type UpdateMessage<N, E> = {
460
+ type: 'update';
461
+ description?: string;
462
+ } & Update<N, E>;
463
+ type HistoryMessage<N, E> = {
464
+ type: 'history';
465
+ frames: Update<N, E>[];
466
+ };
467
+ type IngestMessage<N, E> = SnapshotMessage<N, E> | UpdateMessage<N, E> | HistoryMessage<N, E>;
468
+ /**
469
+ * Ingest class handles applying ingest messages to an API instance.
470
+ * This is the core ingestion functionality, separate from UI concerns.
471
+ */
472
+ declare class Ingest<N, E> {
473
+ api: API<N, E>;
474
+ constructor(api: API<N, E>);
475
+ /**
476
+ * Apply an incoming ingest message to the API.
477
+ * - snapshot: rebuild state from nodes/edges (clears prior history)
478
+ * - update: apply incremental update
479
+ * - history: initialize from a set of frames (clears prior history)
480
+ */
481
+ apply(msg: IngestMessage<N, E>): Promise<void>;
482
+ }
483
+
484
+ type StatusListener$2 = (status: 'connecting' | 'connected' | 'reconnecting' | 'closed' | 'error', detail?: any) => void;
485
+ declare class WebSocketSource<N, E> {
486
+ private url;
487
+ private ws;
488
+ private onMessage;
489
+ private onStatus?;
490
+ private reconnectMs;
491
+ private closedByUser;
492
+ private connectStartTime;
493
+ private totalTimeoutMs;
494
+ private totalTimeoutTimer;
495
+ constructor(url: string, onMessage: (msg: IngestMessage<N, E>) => void, onStatus?: StatusListener$2, reconnectMs?: number);
496
+ connect(): void;
497
+ disconnect(): void;
498
+ private startTotalTimeout;
499
+ private clearTotalTimeout;
500
+ private open;
501
+ }
502
+
503
+ type StatusListener$1 = (status: 'idle' | 'opened' | 'reading' | 'error' | 'closed', detail?: any) => void;
504
+ declare class FileSystemSource<N, E> {
505
+ private handle;
506
+ private onMessage;
507
+ private onStatus?;
508
+ private timer;
509
+ private lastSize;
510
+ private filename;
511
+ private intervalMs;
512
+ constructor(onMessage: (msg: IngestMessage<N, E>) => void, onStatus?: StatusListener$1, filename?: string, intervalMs?: number);
513
+ openDirectory(): Promise<void>;
514
+ close(): void;
515
+ private startPolling;
516
+ private readNewLines;
517
+ }
518
+
519
+ type StatusListener = (status: 'idle' | 'opened' | 'reading' | 'error' | 'closed', detail?: any) => void;
520
+ declare class FileSource<N, E> {
521
+ private url;
522
+ private onMessage;
523
+ private onStatus?;
524
+ private timer;
525
+ private lastETag;
526
+ private lastContent;
527
+ private intervalMs;
528
+ private closed;
529
+ constructor(url: string, onMessage: (msg: IngestMessage<N, E>) => void, onStatus?: StatusListener, intervalMs?: number);
530
+ connect(): Promise<void>;
531
+ close(): void;
532
+ private startPolling;
533
+ private poll;
534
+ }
535
+
536
+ /**
537
+ * Types for the Playground component
538
+ */
539
+ type ExampleNode = string | {
540
+ id: string;
541
+ title?: string;
542
+ type?: string;
543
+ ports?: {
544
+ in?: string[];
545
+ out?: string[];
546
+ };
547
+ };
548
+ type ExampleEdgeEnd = string | {
549
+ id: string;
550
+ port?: string;
551
+ marker?: 'arrow' | 'circle' | 'diamond' | 'bar';
552
+ };
553
+ type ExampleEdge = string | {
554
+ source: ExampleEdgeEnd;
555
+ target: ExampleEdgeEnd;
556
+ type?: string;
557
+ };
558
+ type ExampleOptions = {
559
+ canvas?: {
560
+ colorMode?: 'light' | 'dark' | 'system';
561
+ nodeTypes?: Record<string, Record<string, string>>;
562
+ edgeTypes?: Record<string, Record<string, string>>;
563
+ };
564
+ };
565
+ type ExampleSource = {
566
+ type: 'file';
567
+ path: string;
568
+ } | {
569
+ type: 'websocket';
570
+ url: string;
571
+ };
572
+ type Example = {
573
+ name: string;
574
+ description?: string;
575
+ nodes: ExampleNode[];
576
+ edges: ExampleEdge[];
577
+ options?: ExampleOptions;
578
+ source?: ExampleSource;
579
+ };
580
+ type PlaygroundOptions = {
581
+ root: string | HTMLElement;
582
+ examples: Record<string, Example>;
583
+ defaultExample?: string;
584
+ };
585
+
586
+ declare class Playground {
587
+ private options;
588
+ private rootElement;
589
+ private currentExample;
590
+ private examples;
591
+ private currentGraph;
592
+ private ingest;
593
+ private isEditable;
594
+ private wsSource;
595
+ private fsSource;
596
+ private fileSource;
597
+ private wsStatus;
598
+ private fsStatus;
599
+ private fileStatus;
600
+ private activeSourceType;
601
+ private wsUrl;
602
+ private sourceModal;
603
+ private helpOverlay;
604
+ private exampleList;
605
+ private graphContainerId;
606
+ constructor(options: PlaygroundOptions);
607
+ init(): Promise<void>;
608
+ private injectStyles;
609
+ private createDOM;
610
+ private setupEventListeners;
611
+ private getResolvedColorMode;
612
+ private getOptions;
613
+ private renderGraph;
614
+ private updateHistoryLabel;
615
+ private connectExampleSource;
616
+ private disconnectAllSources;
617
+ private openHelp;
618
+ private closeHelp;
619
+ private handleIngestMessage;
620
+ private updateSourceIcon;
621
+ private updateWsStatus;
622
+ private updateFsStatus;
623
+ private updateFileStatus;
624
+ private createSourceModal;
625
+ private selectSourceType;
626
+ private updateSourceModalContent;
627
+ private updateSourceModal;
628
+ private openSourceModal;
629
+ private closeSourceModal;
630
+ private handleConnect;
631
+ private handleDisconnect;
632
+ private handleChangeConnection;
633
+ private handleOpenFolder;
634
+ private handleCloseFolder;
635
+ /**
636
+ * Add or update an example
637
+ */
638
+ addExample(key: string, example: Example): void;
639
+ /**
640
+ * Remove an example
641
+ */
642
+ removeExample(key: string): void;
643
+ /**
644
+ * Update the example list in the DOM
645
+ */
646
+ private updateExampleList;
427
647
  }
428
648
 
429
649
  declare function graph<N, E>(args?: APIArguments<N, E>): Promise<API<N, E>>;
430
650
 
431
- export { graph as default, graph };
651
+ export { API, type APIArguments, type APIOptions, type EventsOptions, type Example, type ExampleEdge, type ExampleNode, type ExampleOptions, FileSource, FileSystemSource, type HistoryMessage, Ingest, type IngestMessage, Playground, type PlaygroundOptions, type SnapshotMessage, type Update, type UpdateMessage, Updater, WebSocketSource, graph as default, graph };
package/dist/index.d.ts CHANGED
@@ -75,6 +75,8 @@ type GraphOptions = {
75
75
  * Events that can be handled by the user.
76
76
  */
77
77
  type EventsOptions<N, E> = {
78
+ /** Called when the API has finished initializing */
79
+ onInit?: () => void;
78
80
  /** Called when a node is clicked */
79
81
  nodeClick?: (node: N) => void;
80
82
  /** Called when an edge is clicked */
@@ -323,11 +325,17 @@ declare class Updater<N, E> {
323
325
  constructor();
324
326
  describe(desc: string): Updater<N, E>;
325
327
  addNode(node: any): Updater<N, E>;
328
+ addNodes(...nodes: any[]): Updater<N, E>;
326
329
  deleteNode(node: any): Updater<N, E>;
330
+ deleteNodes(...nodes: any[]): Updater<N, E>;
327
331
  updateNode(node: any): Updater<N, E>;
332
+ updateNodes(...nodes: any[]): Updater<N, E>;
328
333
  addEdge(edge: any): Updater<N, E>;
334
+ addEdges(...edges: any[]): Updater<N, E>;
329
335
  deleteEdge(edge: any): Updater<N, E>;
336
+ deleteEdges(...edges: any[]): Updater<N, E>;
330
337
  updateEdge(edge: any): Updater<N, E>;
338
+ updateEdges(...edges: any[]): Updater<N, E>;
331
339
  static add<N, E>(nodes: N[], edges: E[]): Updater<N, E>;
332
340
  }
333
341
 
@@ -362,17 +370,23 @@ declare class API<N, E> {
362
370
  private nextNodeId;
363
371
  private nextEdgeId;
364
372
  private events;
365
- private root;
373
+ root: string;
366
374
  constructor(args: APIArguments<N, E>);
375
+ reset(): void;
376
+ /** Initialize the API */
377
+ init(): Promise<void>;
378
+ private applyHistory;
367
379
  /** Current history index (0-based) */
368
380
  getHistoryIndex(): number;
369
381
  /** Current history length */
370
382
  getHistoryLength(): number;
371
383
  /** Toggle canvas editable mode without re-creating the graph */
372
384
  setEditable(editable: boolean): void;
385
+ /** Replace entire history (clears prior) */
386
+ replaceHistory(frames: Update<N, E>[]): Promise<void>;
387
+ /** Rebuild from snapshot (nodes/edges) */
388
+ replaceSnapshot(nodes: N[], edges: E[], description?: string): Promise<void>;
373
389
  private get graph();
374
- /** Initialize the API */
375
- init(): Promise<void>;
376
390
  /** Navigate to a different state */
377
391
  nav(nav: Nav): void;
378
392
  private applyDiff;
@@ -424,8 +438,214 @@ declare class API<N, E> {
424
438
  handleAddEdge(data: EditEdgeProps): Promise<void>;
425
439
  handleDeleteNode(id: NodeId): Promise<void>;
426
440
  handleDeleteEdge(id: EdgeId): Promise<void>;
441
+ /** Update theme and type styles dynamically */
442
+ updateStyles(options: {
443
+ theme?: ThemeVars;
444
+ nodeTypes?: Record<string, ThemeVars>;
445
+ edgeTypes?: Record<string, ThemeVars>;
446
+ }): void;
447
+ /** Update color mode without recreating the canvas */
448
+ setColorMode(colorMode: 'light' | 'dark' | 'system'): void;
449
+ /** Cleanup resources when the graph is destroyed */
450
+ destroy(): void;
451
+ }
452
+
453
+ type SnapshotMessage<N, E> = {
454
+ type: 'snapshot';
455
+ nodes: N[];
456
+ edges: E[];
457
+ description?: string;
458
+ };
459
+ type UpdateMessage<N, E> = {
460
+ type: 'update';
461
+ description?: string;
462
+ } & Update<N, E>;
463
+ type HistoryMessage<N, E> = {
464
+ type: 'history';
465
+ frames: Update<N, E>[];
466
+ };
467
+ type IngestMessage<N, E> = SnapshotMessage<N, E> | UpdateMessage<N, E> | HistoryMessage<N, E>;
468
+ /**
469
+ * Ingest class handles applying ingest messages to an API instance.
470
+ * This is the core ingestion functionality, separate from UI concerns.
471
+ */
472
+ declare class Ingest<N, E> {
473
+ api: API<N, E>;
474
+ constructor(api: API<N, E>);
475
+ /**
476
+ * Apply an incoming ingest message to the API.
477
+ * - snapshot: rebuild state from nodes/edges (clears prior history)
478
+ * - update: apply incremental update
479
+ * - history: initialize from a set of frames (clears prior history)
480
+ */
481
+ apply(msg: IngestMessage<N, E>): Promise<void>;
482
+ }
483
+
484
+ type StatusListener$2 = (status: 'connecting' | 'connected' | 'reconnecting' | 'closed' | 'error', detail?: any) => void;
485
+ declare class WebSocketSource<N, E> {
486
+ private url;
487
+ private ws;
488
+ private onMessage;
489
+ private onStatus?;
490
+ private reconnectMs;
491
+ private closedByUser;
492
+ private connectStartTime;
493
+ private totalTimeoutMs;
494
+ private totalTimeoutTimer;
495
+ constructor(url: string, onMessage: (msg: IngestMessage<N, E>) => void, onStatus?: StatusListener$2, reconnectMs?: number);
496
+ connect(): void;
497
+ disconnect(): void;
498
+ private startTotalTimeout;
499
+ private clearTotalTimeout;
500
+ private open;
501
+ }
502
+
503
+ type StatusListener$1 = (status: 'idle' | 'opened' | 'reading' | 'error' | 'closed', detail?: any) => void;
504
+ declare class FileSystemSource<N, E> {
505
+ private handle;
506
+ private onMessage;
507
+ private onStatus?;
508
+ private timer;
509
+ private lastSize;
510
+ private filename;
511
+ private intervalMs;
512
+ constructor(onMessage: (msg: IngestMessage<N, E>) => void, onStatus?: StatusListener$1, filename?: string, intervalMs?: number);
513
+ openDirectory(): Promise<void>;
514
+ close(): void;
515
+ private startPolling;
516
+ private readNewLines;
517
+ }
518
+
519
+ type StatusListener = (status: 'idle' | 'opened' | 'reading' | 'error' | 'closed', detail?: any) => void;
520
+ declare class FileSource<N, E> {
521
+ private url;
522
+ private onMessage;
523
+ private onStatus?;
524
+ private timer;
525
+ private lastETag;
526
+ private lastContent;
527
+ private intervalMs;
528
+ private closed;
529
+ constructor(url: string, onMessage: (msg: IngestMessage<N, E>) => void, onStatus?: StatusListener, intervalMs?: number);
530
+ connect(): Promise<void>;
531
+ close(): void;
532
+ private startPolling;
533
+ private poll;
534
+ }
535
+
536
+ /**
537
+ * Types for the Playground component
538
+ */
539
+ type ExampleNode = string | {
540
+ id: string;
541
+ title?: string;
542
+ type?: string;
543
+ ports?: {
544
+ in?: string[];
545
+ out?: string[];
546
+ };
547
+ };
548
+ type ExampleEdgeEnd = string | {
549
+ id: string;
550
+ port?: string;
551
+ marker?: 'arrow' | 'circle' | 'diamond' | 'bar';
552
+ };
553
+ type ExampleEdge = string | {
554
+ source: ExampleEdgeEnd;
555
+ target: ExampleEdgeEnd;
556
+ type?: string;
557
+ };
558
+ type ExampleOptions = {
559
+ canvas?: {
560
+ colorMode?: 'light' | 'dark' | 'system';
561
+ nodeTypes?: Record<string, Record<string, string>>;
562
+ edgeTypes?: Record<string, Record<string, string>>;
563
+ };
564
+ };
565
+ type ExampleSource = {
566
+ type: 'file';
567
+ path: string;
568
+ } | {
569
+ type: 'websocket';
570
+ url: string;
571
+ };
572
+ type Example = {
573
+ name: string;
574
+ description?: string;
575
+ nodes: ExampleNode[];
576
+ edges: ExampleEdge[];
577
+ options?: ExampleOptions;
578
+ source?: ExampleSource;
579
+ };
580
+ type PlaygroundOptions = {
581
+ root: string | HTMLElement;
582
+ examples: Record<string, Example>;
583
+ defaultExample?: string;
584
+ };
585
+
586
+ declare class Playground {
587
+ private options;
588
+ private rootElement;
589
+ private currentExample;
590
+ private examples;
591
+ private currentGraph;
592
+ private ingest;
593
+ private isEditable;
594
+ private wsSource;
595
+ private fsSource;
596
+ private fileSource;
597
+ private wsStatus;
598
+ private fsStatus;
599
+ private fileStatus;
600
+ private activeSourceType;
601
+ private wsUrl;
602
+ private sourceModal;
603
+ private helpOverlay;
604
+ private exampleList;
605
+ private graphContainerId;
606
+ constructor(options: PlaygroundOptions);
607
+ init(): Promise<void>;
608
+ private injectStyles;
609
+ private createDOM;
610
+ private setupEventListeners;
611
+ private getResolvedColorMode;
612
+ private getOptions;
613
+ private renderGraph;
614
+ private updateHistoryLabel;
615
+ private connectExampleSource;
616
+ private disconnectAllSources;
617
+ private openHelp;
618
+ private closeHelp;
619
+ private handleIngestMessage;
620
+ private updateSourceIcon;
621
+ private updateWsStatus;
622
+ private updateFsStatus;
623
+ private updateFileStatus;
624
+ private createSourceModal;
625
+ private selectSourceType;
626
+ private updateSourceModalContent;
627
+ private updateSourceModal;
628
+ private openSourceModal;
629
+ private closeSourceModal;
630
+ private handleConnect;
631
+ private handleDisconnect;
632
+ private handleChangeConnection;
633
+ private handleOpenFolder;
634
+ private handleCloseFolder;
635
+ /**
636
+ * Add or update an example
637
+ */
638
+ addExample(key: string, example: Example): void;
639
+ /**
640
+ * Remove an example
641
+ */
642
+ removeExample(key: string): void;
643
+ /**
644
+ * Update the example list in the DOM
645
+ */
646
+ private updateExampleList;
427
647
  }
428
648
 
429
649
  declare function graph<N, E>(args?: APIArguments<N, E>): Promise<API<N, E>>;
430
650
 
431
- export { graph as default, graph };
651
+ export { API, type APIArguments, type APIOptions, type EventsOptions, type Example, type ExampleEdge, type ExampleNode, type ExampleOptions, FileSource, FileSystemSource, type HistoryMessage, Ingest, type IngestMessage, Playground, type PlaygroundOptions, type SnapshotMessage, type Update, type UpdateMessage, Updater, WebSocketSource, graph as default, graph };