@3plate/graph-core 0.1.0 → 0.1.2

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.
@@ -0,0 +1,133 @@
1
+ type Side = 'source' | 'target';
2
+ type MergeOrder = Side[];
3
+ type NodeAlign = 'natural' | 'top' | 'bottom' | 'left' | 'right';
4
+ type Orientation = 'TB' | 'BT' | 'LR' | 'RL';
5
+
6
+ type LayoutStep = 'alignChildren' | 'alignParents' | 'compact';
7
+
8
+ type GraphOptions = {
9
+ mergeOrder?: MergeOrder;
10
+ nodeMargin?: number;
11
+ dummyNodeSize?: number;
12
+ defaultPortOffset?: number;
13
+ nodeAlign?: NodeAlign;
14
+ edgeSpacing?: number;
15
+ turnRadius?: number;
16
+ orientation?: Orientation;
17
+ layerMargin?: number;
18
+ alignIterations?: number;
19
+ alignThreshold?: number;
20
+ separateTrackSets?: boolean;
21
+ layoutSteps?: LayoutStep[] | null;
22
+ };
23
+
24
+ type EdgeAttributes = {
25
+ width?: number;
26
+ style?: string;
27
+ color?: string;
28
+ turnRadius?: number;
29
+ sourceTerminal?: string | null;
30
+ targetTerminal?: string | null;
31
+ };
32
+ type NodeAttributes = {
33
+ strokeWidth?: number;
34
+ strokeStyle?: string;
35
+ };
36
+ type RenderNode<N> = (node: N) => HTMLElement;
37
+ type EdgeStyle = (type: string) => EdgeAttributes;
38
+ type NodeStyle<N> = (node: N) => NodeAttributes;
39
+ type PortStyle = 'inside' | 'outside' | 'custom';
40
+ type CanvasOptions<N> = {
41
+ renderNode?: RenderNode<N>;
42
+ nodeStyle?: NodeStyle<N>;
43
+ edgeStyle?: EdgeStyle;
44
+ width?: number | string;
45
+ height?: number | string;
46
+ portStyle?: PortStyle;
47
+ classPrefix?: string;
48
+ };
49
+
50
+ type StructuredNode<P> = {
51
+ id: string;
52
+ title?: string;
53
+ text?: string;
54
+ ports?: {
55
+ in?: P[];
56
+ out?: P[];
57
+ };
58
+ };
59
+ type StructuredEdge = {
60
+ source: {
61
+ id: string;
62
+ port?: string;
63
+ };
64
+ target: {
65
+ id: string;
66
+ port?: string;
67
+ };
68
+ type?: string;
69
+ };
70
+ type StructuredPort = {
71
+ id: string;
72
+ label: string;
73
+ };
74
+ type Nav = 'first' | 'last' | 'prev' | 'next';
75
+ type NodeProps<N, P> = (node: N) => StructuredNode<P>;
76
+ type EdgeProps<E> = (edge: E) => StructuredEdge;
77
+ type PortProps<P> = (port: P) => StructuredPort;
78
+ type APIOptions<N, E, P> = GraphOptions & CanvasOptions<N> & {
79
+ nodeProps?: NodeProps<N, P>;
80
+ edgeProps?: EdgeProps<E>;
81
+ portProps?: PortProps<P>;
82
+ };
83
+ type APIArguments<N, E, P> = APIOptions<N, E, P> & {
84
+ nodes?: N[];
85
+ edges?: E[];
86
+ };
87
+ declare class API<N, E, P> {
88
+ private state;
89
+ private seq;
90
+ private index;
91
+ private canvas;
92
+ private _options;
93
+ options: Required<APIOptions<N, E, P>>;
94
+ constructor(options: APIOptions<N, E, P>);
95
+ render(): HTMLElement;
96
+ nav(nav: Nav): void;
97
+ private applyDiff;
98
+ addNode(node: N): Promise<void>;
99
+ deleteNode(node: N): Promise<void>;
100
+ updateNode(node: N): Promise<void>;
101
+ addEdge(edge: E): Promise<void>;
102
+ deleteEdge(edge: E): Promise<void>;
103
+ update(callback: (update: Update<N, E>) => void): Promise<void>;
104
+ private measureNodes;
105
+ private getDims;
106
+ private _updateNode;
107
+ private _updateEdge;
108
+ private _addNode;
109
+ private _removeNode;
110
+ private _addEdge;
111
+ private _removeEdge;
112
+ private _onOptionChange;
113
+ }
114
+ declare class Update<N, E> {
115
+ addedNodes: N[];
116
+ removedNodes: N[];
117
+ updatedNodes: N[];
118
+ addedEdges: E[];
119
+ removedEdges: E[];
120
+ updatedEdges: E[];
121
+ desc?: string;
122
+ constructor();
123
+ describe(desc: string): void;
124
+ addNode(node: N): void;
125
+ deleteNode(node: N): void;
126
+ updateNode(node: N): void;
127
+ addEdge(edge: E): void;
128
+ deleteEdge(edge: E): void;
129
+ updateEdge(edge: E): void;
130
+ }
131
+ declare function graph<N, E, P>(args?: APIArguments<N, E, P>): Promise<API<N, E, P>>;
132
+
133
+ export { graph as default, graph };
package/dist/index.d.ts CHANGED
@@ -1,51 +1,133 @@
1
- interface EdgeProps {
2
- sourceId: string;
3
- targetId: string;
4
- label?: string;
5
- sourcePort?: string;
6
- targetPort?: string;
7
- }
8
- type EdgeExtractor<E> = (edge: E) => EdgeProps;
9
- declare class GraphEdge<N, E> {
10
- id: string;
11
- props: EdgeProps;
12
- data: E;
13
- source: GraphNode<N, E>;
14
- target: GraphNode<N, E>;
15
- constructor(props: EdgeProps, data: E, source: GraphNode<N, E>, target: GraphNode<N, E>);
16
- }
1
+ type Side = 'source' | 'target';
2
+ type MergeOrder = Side[];
3
+ type NodeAlign = 'natural' | 'top' | 'bottom' | 'left' | 'right';
4
+ type Orientation = 'TB' | 'BT' | 'LR' | 'RL';
5
+
6
+ type LayoutStep = 'alignChildren' | 'alignParents' | 'compact';
7
+
8
+ type GraphOptions = {
9
+ mergeOrder?: MergeOrder;
10
+ nodeMargin?: number;
11
+ dummyNodeSize?: number;
12
+ defaultPortOffset?: number;
13
+ nodeAlign?: NodeAlign;
14
+ edgeSpacing?: number;
15
+ turnRadius?: number;
16
+ orientation?: Orientation;
17
+ layerMargin?: number;
18
+ alignIterations?: number;
19
+ alignThreshold?: number;
20
+ separateTrackSets?: boolean;
21
+ layoutSteps?: LayoutStep[] | null;
22
+ };
17
23
 
18
- interface NodeProps {
24
+ type EdgeAttributes = {
25
+ width?: number;
26
+ style?: string;
27
+ color?: string;
28
+ turnRadius?: number;
29
+ sourceTerminal?: string | null;
30
+ targetTerminal?: string | null;
31
+ };
32
+ type NodeAttributes = {
33
+ strokeWidth?: number;
34
+ strokeStyle?: string;
35
+ };
36
+ type RenderNode<N> = (node: N) => HTMLElement;
37
+ type EdgeStyle = (type: string) => EdgeAttributes;
38
+ type NodeStyle<N> = (node: N) => NodeAttributes;
39
+ type PortStyle = 'inside' | 'outside' | 'custom';
40
+ type CanvasOptions<N> = {
41
+ renderNode?: RenderNode<N>;
42
+ nodeStyle?: NodeStyle<N>;
43
+ edgeStyle?: EdgeStyle;
44
+ width?: number | string;
45
+ height?: number | string;
46
+ portStyle?: PortStyle;
47
+ classPrefix?: string;
48
+ };
49
+
50
+ type StructuredNode<P> = {
19
51
  id: string;
20
- inPorts?: string[];
21
- outPorts?: string[];
22
- }
23
- type NodeExtractor<N> = (node: N) => NodeProps;
24
- declare class GraphNode<N, E> {
25
- props: NodeProps;
26
- data: N;
27
- pred: Map<GraphEdge<N, E>, GraphNode<N, E> | null> | undefined;
28
- succ: Map<GraphEdge<N, E>, GraphNode<N, E> | null> | undefined;
29
- prior: GraphNode<N, E> | undefined;
30
- constructor(props: NodeProps, data: N);
52
+ title?: string;
53
+ text?: string;
54
+ ports?: {
55
+ in?: P[];
56
+ out?: P[];
57
+ };
58
+ };
59
+ type StructuredEdge = {
60
+ source: {
61
+ id: string;
62
+ port?: string;
63
+ };
64
+ target: {
65
+ id: string;
66
+ port?: string;
67
+ };
68
+ type?: string;
69
+ };
70
+ type StructuredPort = {
71
+ id: string;
72
+ label: string;
73
+ };
74
+ type Nav = 'first' | 'last' | 'prev' | 'next';
75
+ type NodeProps<N, P> = (node: N) => StructuredNode<P>;
76
+ type EdgeProps<E> = (edge: E) => StructuredEdge;
77
+ type PortProps<P> = (port: P) => StructuredPort;
78
+ type APIOptions<N, E, P> = GraphOptions & CanvasOptions<N> & {
79
+ nodeProps?: NodeProps<N, P>;
80
+ edgeProps?: EdgeProps<E>;
81
+ portProps?: PortProps<P>;
82
+ };
83
+ type APIArguments<N, E, P> = APIOptions<N, E, P> & {
84
+ nodes?: N[];
85
+ edges?: E[];
86
+ };
87
+ declare class API<N, E, P> {
88
+ private state;
89
+ private seq;
90
+ private index;
91
+ private canvas;
92
+ private _options;
93
+ options: Required<APIOptions<N, E, P>>;
94
+ constructor(options: APIOptions<N, E, P>);
95
+ render(): HTMLElement;
96
+ nav(nav: Nav): void;
97
+ private applyDiff;
98
+ addNode(node: N): Promise<void>;
99
+ deleteNode(node: N): Promise<void>;
100
+ updateNode(node: N): Promise<void>;
101
+ addEdge(edge: E): Promise<void>;
102
+ deleteEdge(edge: E): Promise<void>;
103
+ update(callback: (update: Update<N, E>) => void): Promise<void>;
104
+ private measureNodes;
105
+ private getDims;
106
+ private _updateNode;
107
+ private _updateEdge;
108
+ private _addNode;
109
+ private _removeNode;
110
+ private _addEdge;
111
+ private _removeEdge;
112
+ private _onOptionChange;
31
113
  }
32
-
33
- declare class Graph<N, E> {
34
- nodeMap: Map<string, GraphNode<N, E> | null> | undefined;
35
- edgeMap: Map<string, GraphEdge<N, E> | null> | undefined;
36
- prior: Graph<N, E> | undefined;
37
- complete: boolean;
38
- numNodes: number;
39
- numEdges: number;
114
+ declare class Update<N, E> {
115
+ addedNodes: N[];
116
+ removedNodes: N[];
117
+ updatedNodes: N[];
118
+ addedEdges: E[];
119
+ removedEdges: E[];
120
+ updatedEdges: E[];
121
+ desc?: string;
40
122
  constructor();
41
- isEmpty(): boolean;
42
- _walk<T>(mapFn: (graph: Graph<N, E>) => Map<string, T | null> | undefined): IterableIterator<T>;
43
- nodes(): IterableIterator<GraphNode<N, E>>;
44
- edges(): IterableIterator<GraphEdge<N, E>>;
45
- getNode(id: string): GraphNode<N, E> | undefined;
46
- getEdge(id: string): GraphEdge<N, E> | undefined;
47
- hasNode(id: string): boolean;
48
- hasEdge(id: string): boolean;
123
+ describe(desc: string): void;
124
+ addNode(node: N): void;
125
+ deleteNode(node: N): void;
126
+ updateNode(node: N): void;
127
+ addEdge(edge: E): void;
128
+ deleteEdge(edge: E): void;
129
+ updateEdge(edge: E): void;
49
130
  }
131
+ declare function graph<N, E, P>(args?: APIArguments<N, E, P>): Promise<API<N, E, P>>;
50
132
 
51
- export { type EdgeExtractor, type EdgeProps, Graph, GraphEdge, GraphNode, type NodeExtractor, type NodeProps };
133
+ export { graph as default, graph };