@elicdavis/node-flow 0.1.14 → 0.1.16

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/.mocharc.json ADDED
@@ -0,0 +1,5 @@
1
+ {
2
+ "require": "ts-node/register",
3
+ "spec": "test/**/*.test.ts",
4
+ "extension": ["ts"]
5
+ }
package/dist/index.d.mts CHANGED
@@ -44,12 +44,19 @@ interface ContextMenuConfig {
44
44
  items?: Array<ContextMenuItemConfig>;
45
45
  }
46
46
 
47
+ /** Serializable camera orientation for save/restore. */
48
+ interface CameraOrientation {
49
+ position: Vector2;
50
+ zoom: number;
51
+ }
47
52
  declare class Camera {
48
53
  zoom: number;
49
54
  position: Vector2;
50
55
  constructor();
51
56
  screenSpaceToGraphSpace(screenPosition: Vector2, out: Vector2): void;
52
57
  graphSpaceToScreenSpace(graphPosition: Vector2, out: Vector2): void;
58
+ getOrientation(): CameraOrientation;
59
+ setOrientation(orientation: CameraOrientation): void;
53
60
  reset(): void;
54
61
  }
55
62
 
@@ -65,6 +72,7 @@ interface ConnectionRendererParams {
65
72
  outPort: Port | null;
66
73
  }
67
74
  type ConnectionRenderer = (params: ConnectionRendererParams) => void;
75
+ declare function DefaultConnectionRenderer(connectionSize: number, connectionColor: string | undefined, mouseOverSize: number, mouseOverColor: string | undefined): ConnectionRenderer;
68
76
  declare class Connection {
69
77
  #private;
70
78
  constructor(inNode: FlowNode | null, inNodePortIndex: number, outNode: FlowNode | null, outNodePortIndex: number, renderer: ConnectionRenderer);
@@ -163,14 +171,43 @@ interface PortConfig {
163
171
  type?: string;
164
172
  description?: string;
165
173
  array?: boolean;
174
+ /**
175
+ * Lets this port connect to a port of any type, instead of only to one
176
+ * declaring the same `type` string. For a port whose type is decided by
177
+ * whatever gets wired into it, where `type` is a placeholder shown to
178
+ * the user rather than a promise about the values passing through.
179
+ */
180
+ anyType?: boolean;
181
+ /**
182
+ * Every type this port takes, when it takes more than one. For a port
183
+ * that works on a single value or an array of them, where `type` is
184
+ * only the one it happens to be showing.
185
+ *
186
+ * An empty or absent list means the port takes exactly its `type`,
187
+ * unless `anyType` says otherwise.
188
+ */
189
+ acceptedTypes?: Array<string>;
166
190
  emptyStyle?: PortStyle;
167
191
  filledStyle?: PortStyle;
168
192
  onConnectionAdded?: ConnectionChangeCallback;
169
193
  onConnectionRemoved?: ConnectionChangeCallback;
170
194
  }
195
+ /**
196
+ * Whether two ports may be connected, going by their types alone. Each port
197
+ * offers the set of types it takes - one entry for an ordinary port, several
198
+ * for a port that takes more than one, and none at all for a port that takes
199
+ * anything. They connect when those sets overlap.
200
+ */
201
+ declare function portsCompatible(a: Port | undefined | null, b: Port | undefined | null): boolean;
171
202
  declare class Port {
172
203
  #private;
173
204
  constructor(node: FlowNode, portType: PortType, config?: PortConfig);
205
+ setDataType(type: string): void;
206
+ setAnyType(anyType: boolean): void;
207
+ /**
208
+ * Scope accepted types to singular type
209
+ */
210
+ settleOn(type: string): void;
174
211
  addConnection(connection: Connection): void;
175
212
  replaceConnection(connection: Connection, index: number): void;
176
213
  addConnectionAddedListener(callback: ConnectionChangeCallback): void;
@@ -178,6 +215,12 @@ declare class Port {
178
215
  addConnectionRemovedListener(callback: ConnectionChangeCallback): void;
179
216
  clearConnection(connection: Connection): void;
180
217
  getDataType(): string;
218
+ acceptsAnyType(): boolean;
219
+ /**
220
+ * Every type this port takes. Empty means it takes anything.
221
+ */
222
+ acceptedTypes(): Array<string>;
223
+ setAcceptedTypes(types: Array<string>): void;
181
224
  getPortType(): PortType;
182
225
  getDisplayName(): string;
183
226
  filledStyleColor(): string;
@@ -306,8 +349,14 @@ declare class FlowNode {
306
349
  addInput(config: PortConfig): Port;
307
350
  addOutput(config: PortConfig): Port;
308
351
  addWidget(widget: Widget): void;
352
+ insertWidget(index: number, widget: Widget): void;
309
353
  removeWidget(widget: Widget): void;
354
+ removeWidgetAt(index: number): Widget | undefined;
355
+ moveWidget(from: number, to: number): void;
356
+ clearWidgets(): void;
310
357
  getWidget(index: number): Widget;
358
+ widgets(): ReadonlyArray<Widget>;
359
+ indexOfWidget(widget: Widget): number;
311
360
  widgetCount(): number;
312
361
  translate(delta: Vector2): void;
313
362
  inBounds(ctx: CanvasRenderingContext2D, camera: Camera, position: Vector2): NodeIntersection;
@@ -505,6 +554,18 @@ declare class NodeFlowGraph {
505
554
  * state used by Ctrl+click and box-select styling via FlowNode.selected()).
506
555
  */
507
556
  getSelectedNodes(): Array<FlowNode>;
557
+ /**
558
+ * Returns a copy of the current camera orientation (screen-space pan + zoom).
559
+ */
560
+ getCamera(): CameraOrientation;
561
+ /**
562
+ * Restores a previously saved camera orientation.
563
+ */
564
+ setCamera(orientation: CameraOrientation): void;
565
+ /**
566
+ * Resets the camera to the default orientation (origin, zoom 1).
567
+ */
568
+ resetCamera(): void;
508
569
  /**
509
570
  * Adjusts camera position and zoom so all nodes fit in view (~10% padding).
510
571
  * Falls back to camera.reset() when there are no nodes.
@@ -828,4 +889,4 @@ declare class WidgetFactory {
828
889
  }
829
890
  declare const GlobalWidgetFactory: WidgetFactory;
830
891
 
831
- export { ButtonWidget, ColorWidget, type ContextMenuConfig, type ContextMenuItemConfig, ContextMenuItemState, FlowNode, type FlowNodeConfig, type FlowNodeGraphConfiguration, type FlowNodeStyle, type FlowNodeTitleConfig, FlowNote, type FlowNoteConfig, GlobalWidgetFactory, type GraphRenderer, ImageWidget, MessageType, NodeFlowGraph, type NodeIntersection, type NodeMessageConfig, NodeState, type NoteAddedCallback, type NoteContentChangeCallback, type NoteDragStartCallback, type NoteDragStopCallback, type NoteRemovedCallback, type NoteSubsystemConfig, type NoteWidthChangeCallback, NumberWidget, Publisher, type PublisherConfig, SliderWidget, StringWidget, TextWidget, Theme, ToggleWidget, type WidgetConfig };
892
+ export { type Box, ButtonWidget, type ButtonWidgetConfig, type CameraOrientation, ColorWidget, type ColorWidgetConfig, Connection, type ConnectionRenderer, type ConnectionRendererParams, type ContextMenuConfig, type ContextMenuItemConfig, ContextMenuItemState, DefaultConnectionRenderer, FlowNode, type FlowNodeConfig, type FlowNodeGraphConfiguration, type FlowNodeStyle, type FlowNodeTitleConfig, FlowNote, type FlowNoteConfig, GlobalWidgetFactory, type GraphRenderer, ImageWidget, type ImageWidgetConfig, MessageType, type NodeCreatedCallback, NodeFactory, type NodeFactoryConfig, NodeFlowGraph, type NodeIntersection, type NodeMessageConfig, NodeState, type NoteAddedCallback, type NoteContentChangeCallback, type NoteDragStartCallback, type NoteDragStopCallback, type NoteRemovedCallback, type NoteSubsystemConfig, type NoteWidthChangeCallback, NumberWidget, type NumberWidgetConfig, Port, type PortConfig, type PortStyle, PortType, Publisher, type PublisherConfig, SliderWidget, type SliderWidgetConfig, StringWidget, type StringWidgetConfig, TextWidget, type TextWidgetConfig, Theme, type ToggleStyleConfig, ToggleWidget, type ToggleWidgetConfig, type Vector2, type Widget, type WidgetBuilder, type WidgetConfig, WidgetFactory, portsCompatible };
package/dist/index.d.ts CHANGED
@@ -44,12 +44,19 @@ interface ContextMenuConfig {
44
44
  items?: Array<ContextMenuItemConfig>;
45
45
  }
46
46
 
47
+ /** Serializable camera orientation for save/restore. */
48
+ interface CameraOrientation {
49
+ position: Vector2;
50
+ zoom: number;
51
+ }
47
52
  declare class Camera {
48
53
  zoom: number;
49
54
  position: Vector2;
50
55
  constructor();
51
56
  screenSpaceToGraphSpace(screenPosition: Vector2, out: Vector2): void;
52
57
  graphSpaceToScreenSpace(graphPosition: Vector2, out: Vector2): void;
58
+ getOrientation(): CameraOrientation;
59
+ setOrientation(orientation: CameraOrientation): void;
53
60
  reset(): void;
54
61
  }
55
62
 
@@ -65,6 +72,7 @@ interface ConnectionRendererParams {
65
72
  outPort: Port | null;
66
73
  }
67
74
  type ConnectionRenderer = (params: ConnectionRendererParams) => void;
75
+ declare function DefaultConnectionRenderer(connectionSize: number, connectionColor: string | undefined, mouseOverSize: number, mouseOverColor: string | undefined): ConnectionRenderer;
68
76
  declare class Connection {
69
77
  #private;
70
78
  constructor(inNode: FlowNode | null, inNodePortIndex: number, outNode: FlowNode | null, outNodePortIndex: number, renderer: ConnectionRenderer);
@@ -163,14 +171,43 @@ interface PortConfig {
163
171
  type?: string;
164
172
  description?: string;
165
173
  array?: boolean;
174
+ /**
175
+ * Lets this port connect to a port of any type, instead of only to one
176
+ * declaring the same `type` string. For a port whose type is decided by
177
+ * whatever gets wired into it, where `type` is a placeholder shown to
178
+ * the user rather than a promise about the values passing through.
179
+ */
180
+ anyType?: boolean;
181
+ /**
182
+ * Every type this port takes, when it takes more than one. For a port
183
+ * that works on a single value or an array of them, where `type` is
184
+ * only the one it happens to be showing.
185
+ *
186
+ * An empty or absent list means the port takes exactly its `type`,
187
+ * unless `anyType` says otherwise.
188
+ */
189
+ acceptedTypes?: Array<string>;
166
190
  emptyStyle?: PortStyle;
167
191
  filledStyle?: PortStyle;
168
192
  onConnectionAdded?: ConnectionChangeCallback;
169
193
  onConnectionRemoved?: ConnectionChangeCallback;
170
194
  }
195
+ /**
196
+ * Whether two ports may be connected, going by their types alone. Each port
197
+ * offers the set of types it takes - one entry for an ordinary port, several
198
+ * for a port that takes more than one, and none at all for a port that takes
199
+ * anything. They connect when those sets overlap.
200
+ */
201
+ declare function portsCompatible(a: Port | undefined | null, b: Port | undefined | null): boolean;
171
202
  declare class Port {
172
203
  #private;
173
204
  constructor(node: FlowNode, portType: PortType, config?: PortConfig);
205
+ setDataType(type: string): void;
206
+ setAnyType(anyType: boolean): void;
207
+ /**
208
+ * Scope accepted types to singular type
209
+ */
210
+ settleOn(type: string): void;
174
211
  addConnection(connection: Connection): void;
175
212
  replaceConnection(connection: Connection, index: number): void;
176
213
  addConnectionAddedListener(callback: ConnectionChangeCallback): void;
@@ -178,6 +215,12 @@ declare class Port {
178
215
  addConnectionRemovedListener(callback: ConnectionChangeCallback): void;
179
216
  clearConnection(connection: Connection): void;
180
217
  getDataType(): string;
218
+ acceptsAnyType(): boolean;
219
+ /**
220
+ * Every type this port takes. Empty means it takes anything.
221
+ */
222
+ acceptedTypes(): Array<string>;
223
+ setAcceptedTypes(types: Array<string>): void;
181
224
  getPortType(): PortType;
182
225
  getDisplayName(): string;
183
226
  filledStyleColor(): string;
@@ -306,8 +349,14 @@ declare class FlowNode {
306
349
  addInput(config: PortConfig): Port;
307
350
  addOutput(config: PortConfig): Port;
308
351
  addWidget(widget: Widget): void;
352
+ insertWidget(index: number, widget: Widget): void;
309
353
  removeWidget(widget: Widget): void;
354
+ removeWidgetAt(index: number): Widget | undefined;
355
+ moveWidget(from: number, to: number): void;
356
+ clearWidgets(): void;
310
357
  getWidget(index: number): Widget;
358
+ widgets(): ReadonlyArray<Widget>;
359
+ indexOfWidget(widget: Widget): number;
311
360
  widgetCount(): number;
312
361
  translate(delta: Vector2): void;
313
362
  inBounds(ctx: CanvasRenderingContext2D, camera: Camera, position: Vector2): NodeIntersection;
@@ -505,6 +554,18 @@ declare class NodeFlowGraph {
505
554
  * state used by Ctrl+click and box-select styling via FlowNode.selected()).
506
555
  */
507
556
  getSelectedNodes(): Array<FlowNode>;
557
+ /**
558
+ * Returns a copy of the current camera orientation (screen-space pan + zoom).
559
+ */
560
+ getCamera(): CameraOrientation;
561
+ /**
562
+ * Restores a previously saved camera orientation.
563
+ */
564
+ setCamera(orientation: CameraOrientation): void;
565
+ /**
566
+ * Resets the camera to the default orientation (origin, zoom 1).
567
+ */
568
+ resetCamera(): void;
508
569
  /**
509
570
  * Adjusts camera position and zoom so all nodes fit in view (~10% padding).
510
571
  * Falls back to camera.reset() when there are no nodes.
@@ -828,4 +889,4 @@ declare class WidgetFactory {
828
889
  }
829
890
  declare const GlobalWidgetFactory: WidgetFactory;
830
891
 
831
- export { ButtonWidget, ColorWidget, type ContextMenuConfig, type ContextMenuItemConfig, ContextMenuItemState, FlowNode, type FlowNodeConfig, type FlowNodeGraphConfiguration, type FlowNodeStyle, type FlowNodeTitleConfig, FlowNote, type FlowNoteConfig, GlobalWidgetFactory, type GraphRenderer, ImageWidget, MessageType, NodeFlowGraph, type NodeIntersection, type NodeMessageConfig, NodeState, type NoteAddedCallback, type NoteContentChangeCallback, type NoteDragStartCallback, type NoteDragStopCallback, type NoteRemovedCallback, type NoteSubsystemConfig, type NoteWidthChangeCallback, NumberWidget, Publisher, type PublisherConfig, SliderWidget, StringWidget, TextWidget, Theme, ToggleWidget, type WidgetConfig };
892
+ export { type Box, ButtonWidget, type ButtonWidgetConfig, type CameraOrientation, ColorWidget, type ColorWidgetConfig, Connection, type ConnectionRenderer, type ConnectionRendererParams, type ContextMenuConfig, type ContextMenuItemConfig, ContextMenuItemState, DefaultConnectionRenderer, FlowNode, type FlowNodeConfig, type FlowNodeGraphConfiguration, type FlowNodeStyle, type FlowNodeTitleConfig, FlowNote, type FlowNoteConfig, GlobalWidgetFactory, type GraphRenderer, ImageWidget, type ImageWidgetConfig, MessageType, type NodeCreatedCallback, NodeFactory, type NodeFactoryConfig, NodeFlowGraph, type NodeIntersection, type NodeMessageConfig, NodeState, type NoteAddedCallback, type NoteContentChangeCallback, type NoteDragStartCallback, type NoteDragStopCallback, type NoteRemovedCallback, type NoteSubsystemConfig, type NoteWidthChangeCallback, NumberWidget, type NumberWidgetConfig, Port, type PortConfig, type PortStyle, PortType, Publisher, type PublisherConfig, SliderWidget, type SliderWidgetConfig, StringWidget, type StringWidgetConfig, TextWidget, type TextWidgetConfig, Theme, type ToggleStyleConfig, ToggleWidget, type ToggleWidgetConfig, type Vector2, type Widget, type WidgetBuilder, type WidgetConfig, WidgetFactory, portsCompatible };