@ankhzet/graph 0.1.0 → 0.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/CHANGELOG.md +20 -0
- package/dist/index.d.ts +676 -0
- package/dist/index.js +2283 -0
- package/dist/index.js.map +1 -0
- package/package.json +6 -6
- package/src/{CircuitGroups.tsx → GraphGroups.tsx} +5 -5
- package/src/LoadNodes.ts +5 -5
- package/src/{CircuitGraph.tsx → ManagedGraph.tsx} +22 -23
- package/src/{CircuitNode.ts → ManagedGraphNode.ts} +3 -3
- package/src/createGraphHandlers.ts +2 -2
- package/src/index.ts +3 -1
- package/src/useNodeSelection.ts +2 -2
- package/src/useNodes.tsx +4 -4
- package/src/utils.ts +3 -5
package/CHANGELOG.md
CHANGED
|
@@ -1,5 +1,25 @@
|
|
|
1
1
|
# @ankhzet/graph
|
|
2
2
|
|
|
3
|
+
## 0.3.0
|
|
4
|
+
|
|
5
|
+
### Minor Changes
|
|
6
|
+
|
|
7
|
+
- Expose types and fix circuit references
|
|
8
|
+
|
|
9
|
+
## 0.2.0
|
|
10
|
+
|
|
11
|
+
### Minor Changes
|
|
12
|
+
|
|
13
|
+
- Fix release
|
|
14
|
+
|
|
15
|
+
### Patch Changes
|
|
16
|
+
|
|
17
|
+
- Updated dependencies
|
|
18
|
+
- @ankhzet/eventual@1.2.0
|
|
19
|
+
- @ankhzet/utils@1.18.0
|
|
20
|
+
- @ankhzet/gcl@1.2.0
|
|
21
|
+
- @ankhzet/ui@0.2.0
|
|
22
|
+
|
|
3
23
|
## 0.1.0
|
|
4
24
|
|
|
5
25
|
### Minor Changes
|
package/dist/index.d.ts
ADDED
|
@@ -0,0 +1,676 @@
|
|
|
1
|
+
import { BitmapFont } from '@pixi/text-bitmap';
|
|
2
|
+
import { ColorSource } from '@pixi/core';
|
|
3
|
+
import { Constructor } from '@ankhzet/utils';
|
|
4
|
+
import { Container } from '@pixi/display';
|
|
5
|
+
import { DisplayObject } from '@pixi/display';
|
|
6
|
+
import { DisposableEventSource } from '@ankhzet/gcl';
|
|
7
|
+
import { Disposer } from '@ankhzet/gcl';
|
|
8
|
+
import { ForwardRefExoticComponent } from 'react';
|
|
9
|
+
import { Graphics } from '@pixi/graphics';
|
|
10
|
+
import { IBitmapFontOptions } from '@pixi/text-bitmap';
|
|
11
|
+
import { IBitmapTextStyle } from '@pixi/text-bitmap';
|
|
12
|
+
import { IEventHandler } from '@ankhzet/eventual';
|
|
13
|
+
import { ITextStyle } from '@pixi/text';
|
|
14
|
+
import { JSX } from 'react/jsx-runtime';
|
|
15
|
+
import { MouseEvent as MouseEvent_2 } from 'react';
|
|
16
|
+
import { PropsWithChildren } from 'react';
|
|
17
|
+
import { Ref } from 'react';
|
|
18
|
+
import { RefAttributes } from 'react';
|
|
19
|
+
import { RefObject } from 'react';
|
|
20
|
+
import { TextStyle } from '@pixi/text';
|
|
21
|
+
import { TouchEvent as TouchEvent_2 } from 'react';
|
|
22
|
+
|
|
23
|
+
declare class Batch extends DisposableEventSource {
|
|
24
|
+
private counter;
|
|
25
|
+
constructor();
|
|
26
|
+
batch(cb: () => void): void;
|
|
27
|
+
begin(): void;
|
|
28
|
+
end(): void;
|
|
29
|
+
and(handler: (batch: this) => void): Disposer;
|
|
30
|
+
}
|
|
31
|
+
|
|
32
|
+
export declare type ClickHandler = (offset: {
|
|
33
|
+
x: number;
|
|
34
|
+
y: number;
|
|
35
|
+
}, e: MouseEvent_2) => void;
|
|
36
|
+
|
|
37
|
+
export declare class ClusteredLayout<Node extends GraphNodeInterface> extends NodesGraph<Node> implements Layout<Node> {
|
|
38
|
+
private cache;
|
|
39
|
+
private hash;
|
|
40
|
+
get center(): Position;
|
|
41
|
+
private splice;
|
|
42
|
+
private align;
|
|
43
|
+
spread(layer: number, nodes: Node['id'][]): number;
|
|
44
|
+
}
|
|
45
|
+
|
|
46
|
+
export declare type ConnectionPoint<Node, Port = Node> = {
|
|
47
|
+
node: Node;
|
|
48
|
+
port: Port;
|
|
49
|
+
};
|
|
50
|
+
|
|
51
|
+
export declare type Connector<ID> = {
|
|
52
|
+
addTarget(node: ID, port: ID): Line;
|
|
53
|
+
removeTarget(node: ID, port: ID): void;
|
|
54
|
+
moveTargetTo(node: ID, port: ID, pos: Position): boolean;
|
|
55
|
+
move(pos: Position): boolean;
|
|
56
|
+
};
|
|
57
|
+
|
|
58
|
+
export declare type ConnectorId<Node extends GraphNodeInterface> = Node['id'] extends string | number ? `${Node['id']}-${Node['id']}` : never;
|
|
59
|
+
|
|
60
|
+
export declare type ConnectorPoint<Node extends GraphNodeInterface, Input extends true | false | void = void> = Position & {
|
|
61
|
+
parent: Node['id'];
|
|
62
|
+
port: Node['id'];
|
|
63
|
+
input: boolean;
|
|
64
|
+
name: string;
|
|
65
|
+
nodes: ConnectionPoint<Node['id']>[];
|
|
66
|
+
} & (Input extends true ? {
|
|
67
|
+
connector: Connector<Node['id']>;
|
|
68
|
+
} : Input extends false ? {
|
|
69
|
+
connector: never;
|
|
70
|
+
} : {
|
|
71
|
+
connector?: Connector<Node['id']>;
|
|
72
|
+
});
|
|
73
|
+
|
|
74
|
+
export declare type Coordinator = {
|
|
75
|
+
grid: number;
|
|
76
|
+
gridSize: Position;
|
|
77
|
+
sizes: {
|
|
78
|
+
grid: Position;
|
|
79
|
+
port: number;
|
|
80
|
+
lane: number;
|
|
81
|
+
space: number;
|
|
82
|
+
};
|
|
83
|
+
snap(value: number): number;
|
|
84
|
+
toGraph: (pos: Position) => Position;
|
|
85
|
+
toData: (pos: Position) => Position;
|
|
86
|
+
};
|
|
87
|
+
|
|
88
|
+
export declare type DragHandler = (offset: {
|
|
89
|
+
x: number;
|
|
90
|
+
y: number;
|
|
91
|
+
}) => void;
|
|
92
|
+
|
|
93
|
+
export declare type DragHandlers = {
|
|
94
|
+
position: {
|
|
95
|
+
x: number;
|
|
96
|
+
y: number;
|
|
97
|
+
};
|
|
98
|
+
onPointer: DragHandler;
|
|
99
|
+
onClick: ClickHandler;
|
|
100
|
+
onUp: DragHandler;
|
|
101
|
+
onDrag: DragHandler;
|
|
102
|
+
onContext: DragHandler;
|
|
103
|
+
};
|
|
104
|
+
|
|
105
|
+
export declare class EdgesSort {
|
|
106
|
+
sort(dependants: Record<string, string[]>, dependencies: Record<string, string[]>, layers: string[][]): void;
|
|
107
|
+
private mutate;
|
|
108
|
+
}
|
|
109
|
+
|
|
110
|
+
export declare const getChannelName: (name: string) => string;
|
|
111
|
+
|
|
112
|
+
export declare class GraphAdapter<Node extends GraphNodeInterface> extends Batch implements Iterable<Node> {
|
|
113
|
+
private readonly renderer;
|
|
114
|
+
private nodes;
|
|
115
|
+
constructor(config: RendererConfig);
|
|
116
|
+
[Symbol.iterator](): ArrayIterator<Node>;
|
|
117
|
+
clear(): void;
|
|
118
|
+
update(): void;
|
|
119
|
+
moveToForeground(node: Node): void;
|
|
120
|
+
hitTest(pos: Position): undefined | HitTestResult<Node>;
|
|
121
|
+
getNodePos(node: Node): Position;
|
|
122
|
+
moveNodeTo(node: Node, pos: Position): void;
|
|
123
|
+
addNode(node: Node): Node;
|
|
124
|
+
removeNode(node: Node): Node;
|
|
125
|
+
get capturing(): Node | undefined;
|
|
126
|
+
releaseNode(): void;
|
|
127
|
+
get translation(): Position;
|
|
128
|
+
translate(pos: Position): void;
|
|
129
|
+
resize(width: number, height: number): void;
|
|
130
|
+
fromGlobal(pos: Position): Position;
|
|
131
|
+
fromLocal(pos: Position): Position;
|
|
132
|
+
mount(element: HTMLElement, options: RendererOptions): () => void;
|
|
133
|
+
unmount(): void;
|
|
134
|
+
layout(): void;
|
|
135
|
+
}
|
|
136
|
+
|
|
137
|
+
export declare type GraphBarrier<N extends GraphNodeInterface> = (node: N) => boolean;
|
|
138
|
+
|
|
139
|
+
export declare function GraphCanvas<Node extends GraphNodeInterface<ID, Data, Render>, ID = any, Data = any, Render = any>({ innerRef, nodes, subset, coordinator, menu, onSelectNode, onContextMenu, ...rest }: GraphNodeProps<Node>): JSX.Element;
|
|
140
|
+
|
|
141
|
+
declare interface GraphDTO {
|
|
142
|
+
title: string;
|
|
143
|
+
x: number;
|
|
144
|
+
y: number;
|
|
145
|
+
args?: Partial<Record<string, string>>;
|
|
146
|
+
}
|
|
147
|
+
|
|
148
|
+
export declare interface GraphHandlers<DTO, Item> {
|
|
149
|
+
onCreate: (data: DTO) => Promise<Item>;
|
|
150
|
+
onEdit: (item: Item) => void;
|
|
151
|
+
onAddPort: (item: Item, input: boolean) => Promise<void>;
|
|
152
|
+
onDisconnectPort: (item: Item, portId: TypeId) => Promise<void>;
|
|
153
|
+
onDeletePort: (item: Item, portId: TypeId) => Promise<void>;
|
|
154
|
+
onDelete: (item: Item) => Promise<void>;
|
|
155
|
+
onMove: (item: Item, pos: Position) => Promise<void>;
|
|
156
|
+
onConnect: (connection: NodeConnection<Item, TypeId>) => Promise<void>;
|
|
157
|
+
onSelect?: (item: Item | null, pos: Position) => void | false;
|
|
158
|
+
onContextMenu?: (item: Item | null, pos: Position) => void | false;
|
|
159
|
+
}
|
|
160
|
+
|
|
161
|
+
export declare abstract class GraphNode<ID, Data = {}, R = any> extends DisposableEventSource implements GraphNodeInterface<ID, Data, R> {
|
|
162
|
+
#private;
|
|
163
|
+
readonly id: ID;
|
|
164
|
+
readonly description: GraphNodeDescriptor<Data>;
|
|
165
|
+
readonly inputs: NodeJoints<ID>;
|
|
166
|
+
readonly outputs: NodeJoints<ID>;
|
|
167
|
+
readonly coordinator: Coordinator;
|
|
168
|
+
constructor({ id, coordinator, inputs, outputs, ...description }: GraphNodeDescriptor<Data> & {
|
|
169
|
+
id: ID;
|
|
170
|
+
inputs?: NodeJoint<ID>[];
|
|
171
|
+
outputs?: NodeJoint<ID>[];
|
|
172
|
+
});
|
|
173
|
+
abstract render(content: R): R;
|
|
174
|
+
abstract getMenu(tag: any, pos: Position): IMenu<any> | undefined;
|
|
175
|
+
abstract handleMenu(data: any): void | false;
|
|
176
|
+
get title(): string;
|
|
177
|
+
get width(): number;
|
|
178
|
+
get height(): number;
|
|
179
|
+
get position(): Position;
|
|
180
|
+
set position({ x, y }: Position);
|
|
181
|
+
isInput(portId: ID, nodeId: ID, nodePortId: ID): boolean;
|
|
182
|
+
isOutput(portId: ID, nodeId: ID, nodePortId: ID): boolean;
|
|
183
|
+
isConnected(port: ID, input: boolean, to: ConnectionPoint<ID>): boolean;
|
|
184
|
+
getNodes(port: ID, input: boolean): ConnectionPoint<ID, ID>[] | undefined;
|
|
185
|
+
connect({ input, connect, port, nodes }: NodeConnectionRequest<ID, GraphNode<ID, Data>>): void;
|
|
186
|
+
move(pos: Position): Position;
|
|
187
|
+
onConnect(handler: IEventHandler<NodeConnection<ID>>): Disposer;
|
|
188
|
+
onMove(handler: IEventHandler<Position>): Disposer;
|
|
189
|
+
}
|
|
190
|
+
|
|
191
|
+
export declare type GraphNodeDescriptor<Data> = Data & {
|
|
192
|
+
title: string;
|
|
193
|
+
coordinator: Coordinator;
|
|
194
|
+
};
|
|
195
|
+
|
|
196
|
+
export declare interface GraphNodeInterface<ID = any, Data = any, Render = any> extends IMenuProvider<any> {
|
|
197
|
+
id: ID;
|
|
198
|
+
inputs: NodeJoints<ID>;
|
|
199
|
+
outputs: NodeJoints<ID>;
|
|
200
|
+
description: GraphNodeDescriptor<Data>;
|
|
201
|
+
position: Position;
|
|
202
|
+
readonly title: string;
|
|
203
|
+
readonly width: number;
|
|
204
|
+
readonly height: number;
|
|
205
|
+
isInput(port: ID, nodeId: ID, nodePortId: ID): boolean;
|
|
206
|
+
isOutput(port: ID, nodeId: ID, nodePortId: ID): boolean;
|
|
207
|
+
isConnected(port: ID, input: boolean, to: ConnectionPoint<ID>): boolean;
|
|
208
|
+
connect(request: NodeConnectionRequest<ID, GraphNodeInterface<ID, Data>>): void;
|
|
209
|
+
move(pos: Position): Position;
|
|
210
|
+
render(content: Render): Render;
|
|
211
|
+
onConnect(handler: IEventHandler<NodeConnection<ID>>): () => void;
|
|
212
|
+
onMove(handler: IEventHandler<Position>): () => void;
|
|
213
|
+
}
|
|
214
|
+
|
|
215
|
+
export declare class GraphNodeJoints<ID> implements NodeJoints<ID> {
|
|
216
|
+
private readonly joints;
|
|
217
|
+
private readonly parentId;
|
|
218
|
+
constructor(parentId: ID, ports: NodeJoint<ID>[]);
|
|
219
|
+
[Symbol.iterator](): Iterator<NodeJoint<ID>>;
|
|
220
|
+
get connected(): NodeJoint<ID>[];
|
|
221
|
+
find(predicate: (joint: NodeJoint<ID>) => boolean): NodeJoint<ID> | undefined;
|
|
222
|
+
map<R>(mapper: (joint: NodeJoint<ID>, index: number) => R): R[];
|
|
223
|
+
has(nodeId: ID, portId?: ID): boolean;
|
|
224
|
+
hasAtPort(portId: ID, nodeId: ID, nodePortId: ID): boolean;
|
|
225
|
+
getPort(nodeId: ID, portId?: ID): ID | undefined;
|
|
226
|
+
connect({ port, target, connect }: NodeJoinRequest<ID>): NodeJoint<ID>;
|
|
227
|
+
getNodes(portId: ID): ConnectionPoint<ID>[] | undefined;
|
|
228
|
+
get ids(): ID[];
|
|
229
|
+
get count(): number;
|
|
230
|
+
}
|
|
231
|
+
|
|
232
|
+
export declare interface GraphNodeProps<Node extends GraphNodeInterface> {
|
|
233
|
+
innerRef?: Ref<GraphRef<Node>>;
|
|
234
|
+
coordinator: Coordinator;
|
|
235
|
+
nodes: Node[];
|
|
236
|
+
subset?: Node['id'][];
|
|
237
|
+
menu: IMenuProvider<any>;
|
|
238
|
+
onSelectNode: (node: Node | null, pos: Position) => void | false;
|
|
239
|
+
onContextMenu: (node: Node | null, pos: Position) => void | false;
|
|
240
|
+
}
|
|
241
|
+
|
|
242
|
+
export declare type GraphRef<Node extends GraphNodeInterface> = {
|
|
243
|
+
graph: GraphAdapter<Node>;
|
|
244
|
+
element?: HTMLDivElement;
|
|
245
|
+
};
|
|
246
|
+
|
|
247
|
+
declare interface GroupableItem<ID> {
|
|
248
|
+
id: ID;
|
|
249
|
+
}
|
|
250
|
+
|
|
251
|
+
export declare type GroupResolver<T extends GroupableItem<any>> = (node: T) => null | undefined | ItemsGroup<T['id']>;
|
|
252
|
+
|
|
253
|
+
export declare interface HitTestResult<Node extends GraphNodeInterface> extends Position {
|
|
254
|
+
node: Node;
|
|
255
|
+
width: number;
|
|
256
|
+
height: number;
|
|
257
|
+
}
|
|
258
|
+
|
|
259
|
+
export declare type Identifiable<ID = TypeId> = {
|
|
260
|
+
id: ID;
|
|
261
|
+
};
|
|
262
|
+
|
|
263
|
+
export declare interface IGraph<Item extends IItem> extends Identifiable {
|
|
264
|
+
items: Item[];
|
|
265
|
+
}
|
|
266
|
+
|
|
267
|
+
export declare interface IItem extends Identifiable, Position {
|
|
268
|
+
isolator: boolean;
|
|
269
|
+
title: string;
|
|
270
|
+
ports: IItemPort<this>[];
|
|
271
|
+
}
|
|
272
|
+
|
|
273
|
+
export declare interface IItemPort<Item> extends Identifiable {
|
|
274
|
+
name: string;
|
|
275
|
+
input: boolean;
|
|
276
|
+
to: Item | null;
|
|
277
|
+
port: string | null;
|
|
278
|
+
}
|
|
279
|
+
|
|
280
|
+
export declare interface IMenu<Data = never> {
|
|
281
|
+
items: IMenuItem<Data>[];
|
|
282
|
+
onChange?: (cb: (diff: {
|
|
283
|
+
added?: IMenuItem[];
|
|
284
|
+
removed?: TypeId[];
|
|
285
|
+
updated?: TypeId[];
|
|
286
|
+
}) => void) => () => void;
|
|
287
|
+
}
|
|
288
|
+
|
|
289
|
+
export declare interface IMenuItem<Data = never> {
|
|
290
|
+
label: string;
|
|
291
|
+
disabled?: boolean;
|
|
292
|
+
group?: boolean;
|
|
293
|
+
separator?: boolean;
|
|
294
|
+
data?: Data;
|
|
295
|
+
}
|
|
296
|
+
|
|
297
|
+
export declare interface IMenuProvider<Data = never> {
|
|
298
|
+
getMenu(tag: any, pos: Position): IMenu<Data> | undefined;
|
|
299
|
+
handleMenu(data: Data): void | false;
|
|
300
|
+
}
|
|
301
|
+
|
|
302
|
+
export declare const isChannelName: (name: string) => boolean;
|
|
303
|
+
|
|
304
|
+
export declare const isEqualIdentifiables: (a: {
|
|
305
|
+
id: any;
|
|
306
|
+
}[], b: {
|
|
307
|
+
id: any;
|
|
308
|
+
}[]) => boolean;
|
|
309
|
+
|
|
310
|
+
export declare type ItemsGroup<ID> = {
|
|
311
|
+
value: string | number;
|
|
312
|
+
label: string;
|
|
313
|
+
ids: ID[];
|
|
314
|
+
};
|
|
315
|
+
|
|
316
|
+
export declare interface Layer<Node extends GraphNodeInterface> {
|
|
317
|
+
[id: string]: Node;
|
|
318
|
+
}
|
|
319
|
+
|
|
320
|
+
export declare class LayeredLayout<Node extends GraphNodeInterface> extends NodesGraph<Node> implements Layout<Node> {
|
|
321
|
+
layers: Layers<Node>;
|
|
322
|
+
private hash;
|
|
323
|
+
get center(): Position;
|
|
324
|
+
spread(layer: number, nodes: Node['id'][]): number;
|
|
325
|
+
findMax(node: Node): number;
|
|
326
|
+
dependants({ id }: Node): Node[];
|
|
327
|
+
get(ids: Node['id'][]): Node[];
|
|
328
|
+
remove(node: Node, layer: number): boolean;
|
|
329
|
+
put(node: Node, layer: number): void;
|
|
330
|
+
findLayer(node: Node): number;
|
|
331
|
+
findLayers(nodes: Node[]): Partial<Record<string, number>>;
|
|
332
|
+
shift(node: Node, fromLayer: number, offset: number, chain?: Node[]): number;
|
|
333
|
+
private all;
|
|
334
|
+
private walk;
|
|
335
|
+
}
|
|
336
|
+
|
|
337
|
+
export declare interface Layers<Node extends GraphNodeInterface> extends Iterable<Layer<Node>> {
|
|
338
|
+
[idx: number]: Layer<Node>;
|
|
339
|
+
}
|
|
340
|
+
|
|
341
|
+
declare interface Layout<Node extends GraphNodeInterface<any, any>> {
|
|
342
|
+
readonly center: Position;
|
|
343
|
+
getSubGraphs(subset?: Node['id'][]): Node['id'][][];
|
|
344
|
+
spread(layer: number, nodes: Node['id'][]): number;
|
|
345
|
+
}
|
|
346
|
+
|
|
347
|
+
export declare class Layouter<Node extends GraphNodeInterface<any, any>> {
|
|
348
|
+
private readonly isBarrier;
|
|
349
|
+
private readonly klass;
|
|
350
|
+
constructor(klass: Constructor<Layout<Node>, [nodes: Node[], isBarrier: GraphBarrier<Node>]>, isBarrier: GraphBarrier<Node>);
|
|
351
|
+
layout(nodes: Node[], subset?: Node['id'][]): Layout<Node>;
|
|
352
|
+
getSubGraphs(nodes: Node[]): Node["id"][][];
|
|
353
|
+
}
|
|
354
|
+
|
|
355
|
+
export declare type Line = {
|
|
356
|
+
moveFromPoint(pos: Position): boolean;
|
|
357
|
+
moveToPoint(pos: Position): boolean;
|
|
358
|
+
setColor(color: number): void;
|
|
359
|
+
update(): void;
|
|
360
|
+
};
|
|
361
|
+
|
|
362
|
+
export declare const ManagedGraph: <Graph extends IGraph<Item>, Item extends IItem, DTO extends GraphDTO>({ innerRef, graph, selected, handlers, children, onExport, ...rest }: PropsWithChildren<ManagedGraphProps<Graph, Item, DTO>>) => JSX.Element;
|
|
363
|
+
|
|
364
|
+
export declare class ManagedGraphNode<Item extends IItem = IItem> extends GraphNode<TypeId, NodeData<Item>, Container> implements IMenuProvider<MenuAction> {
|
|
365
|
+
#private;
|
|
366
|
+
constructor({ finder, item, coordinator, toTitle }: {
|
|
367
|
+
finder: Resolver<Item>;
|
|
368
|
+
item: Item;
|
|
369
|
+
coordinator: Coordinator;
|
|
370
|
+
toTitle: ToTitle<Item>;
|
|
371
|
+
});
|
|
372
|
+
dispose(): void;
|
|
373
|
+
getMenu(tag?: {
|
|
374
|
+
type: 'node' | 'port';
|
|
375
|
+
id: TypeId;
|
|
376
|
+
}): IMenu<any> | undefined;
|
|
377
|
+
handleMenu(data: MenuAction): void | false;
|
|
378
|
+
onAddPortAction(handler: IEventHandler<boolean>): Disposer;
|
|
379
|
+
onDisconnectPortAction(handler: IEventHandler<NodeJoint<TypeId>>): Disposer;
|
|
380
|
+
onDeletePortAction(handler: IEventHandler<NodeJoint<TypeId>>): Disposer;
|
|
381
|
+
onEditAction(handler: IEventHandler<TypeId>): Disposer;
|
|
382
|
+
onDeleteAction(handler: IEventHandler<TypeId>): Disposer;
|
|
383
|
+
setStatus(status: NodeStatus): void;
|
|
384
|
+
setProgress(progress: number): void;
|
|
385
|
+
setSelected(value: boolean): void;
|
|
386
|
+
get item(): Item;
|
|
387
|
+
getItemPort(predicate: (port: IItemPort<Item>) => boolean): IItemPort<Item> | undefined;
|
|
388
|
+
get isSelected(): boolean;
|
|
389
|
+
get isInProgress(): boolean;
|
|
390
|
+
render(content: Container): RectSpinner;
|
|
391
|
+
}
|
|
392
|
+
|
|
393
|
+
export declare interface ManagedGraphProps<Graph extends IGraph<Item>, Item extends IItem, DTO> {
|
|
394
|
+
innerRef?: RefObject<{
|
|
395
|
+
graph: GraphAdapter<ManagedGraphNode<Item>>;
|
|
396
|
+
element?: HTMLDivElement;
|
|
397
|
+
}>;
|
|
398
|
+
graph: Graph;
|
|
399
|
+
selected?: Item[];
|
|
400
|
+
className?: string;
|
|
401
|
+
handlers?: Partial<GraphHandlers<DTO, Item>>;
|
|
402
|
+
onExport?: (graph: Graph) => string;
|
|
403
|
+
}
|
|
404
|
+
|
|
405
|
+
export declare type MenuAction = {
|
|
406
|
+
action: MenuActions.ADD_PORT;
|
|
407
|
+
input: boolean;
|
|
408
|
+
} | {
|
|
409
|
+
action: MenuActions.DISCONNECT_PORT | MenuActions.DELETE_PORT;
|
|
410
|
+
port?: NodeJoint<TypeId>;
|
|
411
|
+
} | {
|
|
412
|
+
action: MenuActions.EDIT_NODE | MenuActions.DELETE_NODE;
|
|
413
|
+
};
|
|
414
|
+
|
|
415
|
+
export declare enum MenuActions {
|
|
416
|
+
EDIT_NODE = 1,
|
|
417
|
+
ADD_PORT = 2,
|
|
418
|
+
DISCONNECT_PORT = 3,
|
|
419
|
+
DELETE_PORT = 4,
|
|
420
|
+
DELETE_NODE = 5
|
|
421
|
+
}
|
|
422
|
+
|
|
423
|
+
export declare type NodeConnection<Node, Port = Node> = {
|
|
424
|
+
connect: boolean;
|
|
425
|
+
input: boolean;
|
|
426
|
+
source: ConnectionPoint<Node, Port>;
|
|
427
|
+
target?: ConnectionPoint<Node, Port>[];
|
|
428
|
+
};
|
|
429
|
+
|
|
430
|
+
export declare type NodeConnectionRequest<ID, Node> = {
|
|
431
|
+
input: boolean;
|
|
432
|
+
connect: boolean;
|
|
433
|
+
port: ID;
|
|
434
|
+
nodes?: RequestedConnection<ID, Node>[];
|
|
435
|
+
};
|
|
436
|
+
|
|
437
|
+
export declare type NodeData<Item> = {
|
|
438
|
+
item: Item;
|
|
439
|
+
status: NodeStatus;
|
|
440
|
+
progress: number;
|
|
441
|
+
};
|
|
442
|
+
|
|
443
|
+
export declare function NodeGroups<Item extends GroupableItem<any>>({ items, resolver, onSelect, children, ...rest }: NodeGroupsProps<Item>): JSX.Element;
|
|
444
|
+
|
|
445
|
+
export declare interface NodeGroupsProps<T extends GroupableItem<any>> extends PropsWithChildren {
|
|
446
|
+
items: T[];
|
|
447
|
+
resolver: GroupResolver<T>;
|
|
448
|
+
onSelect: (group: ItemsGroup<T['id']>) => void;
|
|
449
|
+
}
|
|
450
|
+
|
|
451
|
+
export declare type NodeJoinRequest<ID> = {
|
|
452
|
+
port: ID;
|
|
453
|
+
target?: ConnectionPoint<ID>[];
|
|
454
|
+
connect: boolean;
|
|
455
|
+
};
|
|
456
|
+
|
|
457
|
+
export declare interface NodeJoint<ID> {
|
|
458
|
+
port: ID;
|
|
459
|
+
name: string;
|
|
460
|
+
nodes: ConnectionPoint<ID>[];
|
|
461
|
+
}
|
|
462
|
+
|
|
463
|
+
export declare interface NodeJoints<ID> extends Iterable<NodeJoint<ID>> {
|
|
464
|
+
count: number;
|
|
465
|
+
ids: ID[];
|
|
466
|
+
connect(join: NodeJoinRequest<ID>): NodeJoint<ID>;
|
|
467
|
+
getNodes(portId: ID): ConnectionPoint<ID>[] | undefined;
|
|
468
|
+
getPort(nodeId: ID, portId?: ID): ID | undefined;
|
|
469
|
+
find(predicate: (joint: NodeJoint<ID>) => boolean): NodeJoint<ID> | undefined;
|
|
470
|
+
map<R>(mapper: (joint: NodeJoint<ID>, index: number) => R): R[];
|
|
471
|
+
has(nodeId: ID, portId?: ID): boolean;
|
|
472
|
+
hasAtPort(portId: ID, nodeId: ID, nodePortId: ID): boolean;
|
|
473
|
+
connected: Array<NodeJoint<ID>>;
|
|
474
|
+
}
|
|
475
|
+
|
|
476
|
+
export declare class NodesGraph<Node extends GraphNodeInterface> {
|
|
477
|
+
private readonly _barriers;
|
|
478
|
+
private readonly _isBarrier;
|
|
479
|
+
readonly map: Partial<Record<Node['id'], Node>>;
|
|
480
|
+
readonly nodes: Node[];
|
|
481
|
+
constructor(nodes: Node[], isBarrier: GraphBarrier<Node>);
|
|
482
|
+
protected isBarrier(id: Node['id']): boolean | (Partial<Record<Node["id"], boolean>>[Node["id"]] & {});
|
|
483
|
+
getSubGraphs(subset?: Node['id'][]): Node["id"][][];
|
|
484
|
+
protected inputs(nodeId: Node['id']): any[];
|
|
485
|
+
protected outputs(nodeId: Node['id']): any[];
|
|
486
|
+
protected getConnectedNodes(node: Node, subset?: Node['id'][], target?: Node['id'][]): Node['id'][];
|
|
487
|
+
protected getCenter(mapper: (node: Node) => Position | undefined): {
|
|
488
|
+
x: number;
|
|
489
|
+
y: number;
|
|
490
|
+
};
|
|
491
|
+
}
|
|
492
|
+
|
|
493
|
+
export declare class NodesSort<R extends Relations<K>, K extends string> {
|
|
494
|
+
sort(nodes: GraphNodeInterface<K, any>[]): string[][];
|
|
495
|
+
private walk;
|
|
496
|
+
private split;
|
|
497
|
+
}
|
|
498
|
+
|
|
499
|
+
export declare enum NodeStatus {
|
|
500
|
+
Idle = 1,
|
|
501
|
+
Processing = 2,
|
|
502
|
+
Done = 4,
|
|
503
|
+
Error = 8,
|
|
504
|
+
Selected = 16
|
|
505
|
+
}
|
|
506
|
+
|
|
507
|
+
export declare class PIXIGUI<M> extends Container implements RendererGUI<M> {
|
|
508
|
+
#private;
|
|
509
|
+
static text: (text: any, textStyle?: Partial<Omit< IBitmapTextStyle, "fontName">>) => PIXIText;
|
|
510
|
+
static makeText: (text: string) => PIXIText;
|
|
511
|
+
constructor(menu: IMenuProvider<M>, legendText?: string);
|
|
512
|
+
getMenu(tag: any, pos: Position): IMenu<M> | undefined;
|
|
513
|
+
handleMenu(data: M): void | false;
|
|
514
|
+
get legendText(): string;
|
|
515
|
+
set legendText(text: string);
|
|
516
|
+
set text(text: string);
|
|
517
|
+
get legend(): boolean;
|
|
518
|
+
set legend(value: boolean);
|
|
519
|
+
}
|
|
520
|
+
|
|
521
|
+
declare class PIXIText extends Container {
|
|
522
|
+
#private;
|
|
523
|
+
static makeFont: (id: string, style?: TextStyle | Partial<ITextStyle>, options?: IBitmapFontOptions) => false | BitmapFont;
|
|
524
|
+
static factory: (id: string, style?: TextStyle | Partial<ITextStyle>, options?: IBitmapFontOptions) => (text: any, textStyle?: Partial<Omit<IBitmapTextStyle, "fontName">>) => PIXIText;
|
|
525
|
+
constructor(text: any, style?: Partial<IBitmapTextStyle>);
|
|
526
|
+
set text(text: any);
|
|
527
|
+
get text(): any;
|
|
528
|
+
set tint(color: ColorSource);
|
|
529
|
+
}
|
|
530
|
+
|
|
531
|
+
export declare type Position = {
|
|
532
|
+
x: number;
|
|
533
|
+
y: number;
|
|
534
|
+
};
|
|
535
|
+
|
|
536
|
+
declare class RectSpinner extends Graphics {
|
|
537
|
+
#private;
|
|
538
|
+
readonly sizeX: number;
|
|
539
|
+
readonly sizeY: number;
|
|
540
|
+
readonly lineSize: number;
|
|
541
|
+
readonly color: ColorSource;
|
|
542
|
+
progress: number;
|
|
543
|
+
active: boolean;
|
|
544
|
+
constructor(child: DisplayObject, { lineSize, sizeX, sizeY, radius, color, }: {
|
|
545
|
+
lineSize: number;
|
|
546
|
+
sizeX: number;
|
|
547
|
+
sizeY: number;
|
|
548
|
+
radius: number;
|
|
549
|
+
color: ColorSource;
|
|
550
|
+
});
|
|
551
|
+
setActive(value: boolean): void;
|
|
552
|
+
destroy(_options: any): void;
|
|
553
|
+
hotSwap(child: DisplayObject): void;
|
|
554
|
+
update(progress: number): void;
|
|
555
|
+
}
|
|
556
|
+
|
|
557
|
+
declare type Relations<K extends string | number> = Record<K, K[]>;
|
|
558
|
+
|
|
559
|
+
export declare interface Renderer<N extends GraphNodeInterface> {
|
|
560
|
+
translation: Position;
|
|
561
|
+
center: Position;
|
|
562
|
+
capturing?: N;
|
|
563
|
+
options: RendererOptions;
|
|
564
|
+
mount(element: HTMLElement, options: RendererOptions): () => void;
|
|
565
|
+
unmount(): void;
|
|
566
|
+
resize(width: number, height: number): void;
|
|
567
|
+
translate(pos: Position): void;
|
|
568
|
+
offsetPos(pos: Position, dir?: number): Position;
|
|
569
|
+
fromGlobal(pos: Position): Position;
|
|
570
|
+
fromLocal(pos: Position): Position;
|
|
571
|
+
moveToForeground(node: N): void;
|
|
572
|
+
addNode(node: N): void;
|
|
573
|
+
removeNode(node: N): void;
|
|
574
|
+
getNodePos(node: N): Position;
|
|
575
|
+
moveNodeTo(nodeId: N['id'], pos: Position): void;
|
|
576
|
+
hitTest(pos: Position): undefined | HitTestResult<N>;
|
|
577
|
+
clear(): void;
|
|
578
|
+
render(): void;
|
|
579
|
+
update(): void;
|
|
580
|
+
layout(): void;
|
|
581
|
+
}
|
|
582
|
+
|
|
583
|
+
export declare type RendererConfig = {
|
|
584
|
+
maxFPS: number;
|
|
585
|
+
grid: {
|
|
586
|
+
cellSize: Position;
|
|
587
|
+
colors: ColorSource[];
|
|
588
|
+
};
|
|
589
|
+
gui?: RendererGUI<any>[];
|
|
590
|
+
};
|
|
591
|
+
|
|
592
|
+
export declare type RendererGUI<M> = DisplayObject & IMenuProvider<M>;
|
|
593
|
+
|
|
594
|
+
export declare interface RendererOptions {
|
|
595
|
+
viewport: {
|
|
596
|
+
width: number;
|
|
597
|
+
height: number;
|
|
598
|
+
antialias: boolean;
|
|
599
|
+
transparent: boolean;
|
|
600
|
+
backgroundColor?: number;
|
|
601
|
+
resolution: number;
|
|
602
|
+
};
|
|
603
|
+
}
|
|
604
|
+
|
|
605
|
+
export declare type RequestedConnection<ID, Node> = {
|
|
606
|
+
node: Node;
|
|
607
|
+
port: ID;
|
|
608
|
+
};
|
|
609
|
+
|
|
610
|
+
export declare type Resolver<Item> = (id: TypeId) => Item | undefined;
|
|
611
|
+
|
|
612
|
+
export declare class Store<Item extends {
|
|
613
|
+
id: TypeId;
|
|
614
|
+
}> extends DisposableEventSource implements StoreInterface<Item> {
|
|
615
|
+
all: Item[];
|
|
616
|
+
map: Record<TypeId, Item>;
|
|
617
|
+
constructor(all?: Item[]);
|
|
618
|
+
clear(): void;
|
|
619
|
+
find(predicate: (node: Item) => boolean): Item | undefined;
|
|
620
|
+
filter(predicate: (node: Item) => boolean): Item[];
|
|
621
|
+
get(id: Item['id']): Item | undefined;
|
|
622
|
+
add<T extends Item | Item[]>(nodes: T): T;
|
|
623
|
+
remove(ids: Item['id'] | Item['id'][]): this;
|
|
624
|
+
onChange(handler: IEventHandler): Disposer;
|
|
625
|
+
}
|
|
626
|
+
|
|
627
|
+
export declare interface StoreInterface<Item extends {
|
|
628
|
+
id: ID;
|
|
629
|
+
}, ID = TypeId> {
|
|
630
|
+
all: Item[];
|
|
631
|
+
find(predicate: (node: Item) => boolean): Item | undefined;
|
|
632
|
+
filter(predicate: (node: Item) => boolean): Item[];
|
|
633
|
+
get(id: Item['id']): Item | undefined;
|
|
634
|
+
add<T extends Item | Item[]>(nodes: T): T;
|
|
635
|
+
remove(id: Item['id'] | Item['id'][]): this;
|
|
636
|
+
clear(): void;
|
|
637
|
+
onChange(handler: IEventHandler<{
|
|
638
|
+
diff: Item[];
|
|
639
|
+
added: boolean;
|
|
640
|
+
}>): () => void;
|
|
641
|
+
}
|
|
642
|
+
|
|
643
|
+
export declare type ToTitle<Item> = (item: Item) => string;
|
|
644
|
+
|
|
645
|
+
export declare type TypeId = string;
|
|
646
|
+
|
|
647
|
+
export declare const useDraggable: <E extends HTMLElement>(handlers: DragHandlers) => {
|
|
648
|
+
isDragging: boolean;
|
|
649
|
+
bind: {
|
|
650
|
+
'data-element': string;
|
|
651
|
+
ref: RefObject<E | null>;
|
|
652
|
+
onMouseDown: (e: MouseEvent_2 | TouchEvent_2 | MouseEvent_2 | TouchEvent_2) => void;
|
|
653
|
+
};
|
|
654
|
+
anchor: {
|
|
655
|
+
x: number;
|
|
656
|
+
y: number;
|
|
657
|
+
};
|
|
658
|
+
reset: (pos: {
|
|
659
|
+
x: number;
|
|
660
|
+
y: number;
|
|
661
|
+
}) => void;
|
|
662
|
+
};
|
|
663
|
+
|
|
664
|
+
export declare function useStore<S extends StoreInterface<any>>(init: () => S): [S, S['all']];
|
|
665
|
+
|
|
666
|
+
export declare const Viewport: ForwardRefExoticComponent<ViewportProps & RefAttributes<unknown>>;
|
|
667
|
+
|
|
668
|
+
declare interface ViewportProps {
|
|
669
|
+
handlers: DragHandlers;
|
|
670
|
+
onResize: (rect: {
|
|
671
|
+
width: number;
|
|
672
|
+
height: number;
|
|
673
|
+
}) => void;
|
|
674
|
+
}
|
|
675
|
+
|
|
676
|
+
export { }
|