@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 +5 -0
- package/dist/index.d.mts +62 -1
- package/dist/index.d.ts +62 -1
- package/dist/index.js +3197 -3337
- package/dist/index.js.map +1 -1
- package/dist/index.mjs +3189 -3337
- package/dist/index.mjs.map +1 -1
- package/package.json +4 -2
- package/src/graph.ts +7 -0
- package/src/index.ts +66 -40
- package/src/markdown/entry.ts +21 -2
- package/src/markdown/lexicalParser.ts +22 -32
- package/src/markdown/syntaxParser.ts +93 -68
- package/src/node.ts +61 -25
- package/src/nodes/subsystem.ts +7 -7
- package/src/organize.ts +276 -181
- package/src/port.ts +130 -7
- package/src/styles/text.ts +8 -0
- package/src/types/text.ts +6 -4
- package/src/utils/string.ts +7 -1
- package/src/widgets/color.ts +5 -6
- package/src/widgets/factory.ts +1 -1
- package/src/widgets/number.ts +2 -2
- package/src/widgets/slider.ts +2 -2
- package/src/widgets/string.ts +2 -2
- package/src/widgets/toggle.ts +2 -2
- package/src/widgets/widget.ts +22 -0
- package/test/markdown.test.ts +165 -0
- package/test/organize.test.ts +156 -0
- package/test/port.test.ts +125 -0
- package/tsconfig.json +6 -2
- package/dist/web/NodeFlow.js +0 -8
- package/dist/web/NodeFlow.js.map +0 -7
package/.mocharc.json
ADDED
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 };
|