@elicdavis/node-flow 0.1.15 → 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
@@ -72,6 +72,7 @@ interface ConnectionRendererParams {
72
72
  outPort: Port | null;
73
73
  }
74
74
  type ConnectionRenderer = (params: ConnectionRendererParams) => void;
75
+ declare function DefaultConnectionRenderer(connectionSize: number, connectionColor: string | undefined, mouseOverSize: number, mouseOverColor: string | undefined): ConnectionRenderer;
75
76
  declare class Connection {
76
77
  #private;
77
78
  constructor(inNode: FlowNode | null, inNodePortIndex: number, outNode: FlowNode | null, outNodePortIndex: number, renderer: ConnectionRenderer);
@@ -170,14 +171,43 @@ interface PortConfig {
170
171
  type?: string;
171
172
  description?: string;
172
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>;
173
190
  emptyStyle?: PortStyle;
174
191
  filledStyle?: PortStyle;
175
192
  onConnectionAdded?: ConnectionChangeCallback;
176
193
  onConnectionRemoved?: ConnectionChangeCallback;
177
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;
178
202
  declare class Port {
179
203
  #private;
180
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;
181
211
  addConnection(connection: Connection): void;
182
212
  replaceConnection(connection: Connection, index: number): void;
183
213
  addConnectionAddedListener(callback: ConnectionChangeCallback): void;
@@ -185,6 +215,12 @@ declare class Port {
185
215
  addConnectionRemovedListener(callback: ConnectionChangeCallback): void;
186
216
  clearConnection(connection: Connection): void;
187
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;
188
224
  getPortType(): PortType;
189
225
  getDisplayName(): string;
190
226
  filledStyleColor(): string;
@@ -313,8 +349,14 @@ declare class FlowNode {
313
349
  addInput(config: PortConfig): Port;
314
350
  addOutput(config: PortConfig): Port;
315
351
  addWidget(widget: Widget): void;
352
+ insertWidget(index: number, widget: Widget): void;
316
353
  removeWidget(widget: Widget): void;
354
+ removeWidgetAt(index: number): Widget | undefined;
355
+ moveWidget(from: number, to: number): void;
356
+ clearWidgets(): void;
317
357
  getWidget(index: number): Widget;
358
+ widgets(): ReadonlyArray<Widget>;
359
+ indexOfWidget(widget: Widget): number;
318
360
  widgetCount(): number;
319
361
  translate(delta: Vector2): void;
320
362
  inBounds(ctx: CanvasRenderingContext2D, camera: Camera, position: Vector2): NodeIntersection;
@@ -847,4 +889,4 @@ declare class WidgetFactory {
847
889
  }
848
890
  declare const GlobalWidgetFactory: WidgetFactory;
849
891
 
850
- export { ButtonWidget, type CameraOrientation, 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
@@ -72,6 +72,7 @@ interface ConnectionRendererParams {
72
72
  outPort: Port | null;
73
73
  }
74
74
  type ConnectionRenderer = (params: ConnectionRendererParams) => void;
75
+ declare function DefaultConnectionRenderer(connectionSize: number, connectionColor: string | undefined, mouseOverSize: number, mouseOverColor: string | undefined): ConnectionRenderer;
75
76
  declare class Connection {
76
77
  #private;
77
78
  constructor(inNode: FlowNode | null, inNodePortIndex: number, outNode: FlowNode | null, outNodePortIndex: number, renderer: ConnectionRenderer);
@@ -170,14 +171,43 @@ interface PortConfig {
170
171
  type?: string;
171
172
  description?: string;
172
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>;
173
190
  emptyStyle?: PortStyle;
174
191
  filledStyle?: PortStyle;
175
192
  onConnectionAdded?: ConnectionChangeCallback;
176
193
  onConnectionRemoved?: ConnectionChangeCallback;
177
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;
178
202
  declare class Port {
179
203
  #private;
180
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;
181
211
  addConnection(connection: Connection): void;
182
212
  replaceConnection(connection: Connection, index: number): void;
183
213
  addConnectionAddedListener(callback: ConnectionChangeCallback): void;
@@ -185,6 +215,12 @@ declare class Port {
185
215
  addConnectionRemovedListener(callback: ConnectionChangeCallback): void;
186
216
  clearConnection(connection: Connection): void;
187
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;
188
224
  getPortType(): PortType;
189
225
  getDisplayName(): string;
190
226
  filledStyleColor(): string;
@@ -313,8 +349,14 @@ declare class FlowNode {
313
349
  addInput(config: PortConfig): Port;
314
350
  addOutput(config: PortConfig): Port;
315
351
  addWidget(widget: Widget): void;
352
+ insertWidget(index: number, widget: Widget): void;
316
353
  removeWidget(widget: Widget): void;
354
+ removeWidgetAt(index: number): Widget | undefined;
355
+ moveWidget(from: number, to: number): void;
356
+ clearWidgets(): void;
317
357
  getWidget(index: number): Widget;
358
+ widgets(): ReadonlyArray<Widget>;
359
+ indexOfWidget(widget: Widget): number;
318
360
  widgetCount(): number;
319
361
  translate(delta: Vector2): void;
320
362
  inBounds(ctx: CanvasRenderingContext2D, camera: Camera, position: Vector2): NodeIntersection;
@@ -847,4 +889,4 @@ declare class WidgetFactory {
847
889
  }
848
890
  declare const GlobalWidgetFactory: WidgetFactory;
849
891
 
850
- export { ButtonWidget, type CameraOrientation, 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 };