@dschz/solid-flow 0.1.3 → 0.2.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/LICENSE ADDED
@@ -0,0 +1,21 @@
1
+ MIT License
2
+
3
+ Copyright (c) 2025 Daniel Sanchez
4
+
5
+ Permission is hereby granted, free of charge, to any person obtaining a copy
6
+ of this software and associated documentation files (the "Software"), to deal
7
+ in the Software without restriction, including without limitation the rights
8
+ to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
9
+ copies of the Software, and to permit persons to whom the Software is
10
+ furnished to do so, subject to the following conditions:
11
+
12
+ The above copyright notice and this permission notice shall be included in all
13
+ copies or substantial portions of the Software.
14
+
15
+ THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
16
+ IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
17
+ FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
18
+ AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
19
+ LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
20
+ OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
21
+ SOFTWARE.
package/README.md CHANGED
@@ -2,7 +2,7 @@
2
2
  <img src="https://assets.solidjs.com/banner?project=solid-flow&type=Ecosystem&background=tiles" alt="@dschz/solid-flow banner" />
3
3
  </p>
4
4
 
5
- # @dschz/solid-flow
5
+ # Solid Flow
6
6
 
7
7
  [![License](https://img.shields.io/badge/license-MIT-green)](LICENSE)
8
8
  [![npm](https://img.shields.io/npm/v/@dschz/solid-flow?color=blue)](https://www.npmjs.com/package/@dschz/solid-flow)
@@ -15,10 +15,9 @@
15
15
 
16
16
  ## Current Unsupported Features:
17
17
 
18
- - `onlyRenderVisibleElements` prop: the ability to only render visible elements on screen.
19
- - Note: The prop is defined as part of `SolidFlow` but it is a no-op. During development and benchmarking, it was revealed that use of it degraded rendering performance due to the amount of work done to actually achieve the outcome of the feature. We need to innovate on the implementation to make the performance comparable (ideally better) to the normal performance of rendering all the nodes/edges on screen. As such it is a no-op prop for now.
20
- - Custom MiniMap nodes: the ability to render custom node visuals in the minimap
21
- - Edge Reconnect Anchors: the ability to re-connect already connected edges
18
+ - [onlyRenderVisibleElements](https://github.com/dsnchz/solid-flow/issues/15): render only visible elements.
19
+ - [Custom MiniMap Nodes](https://github.com/dsnchz/solid-flow/issues/12): define custom minimap jsx node elements.
20
+ - [Edge Reconnect Anchors](https://github.com/dsnchz/solid-flow/issues/13): the ability to re-connect already connected edges.
22
21
 
23
22
  ## Key Features
24
23
 
@@ -38,6 +37,9 @@ The easiest way to get the latest version of Solid Flow is to install it via npm
38
37
 
39
38
  ```sh
40
39
  npm install @dschz/solid-flow
40
+ pnpm install @dschz/solid-flow
41
+ yarn install @dschz/solid-flow
42
+ bun install @dschz/solid-flow
41
43
  ```
42
44
 
43
45
  ## Quick Start
@@ -47,6 +49,7 @@ This is a basic example to get you started. For more advanced examples and full
47
49
  ```tsx
48
50
  import {
49
51
  SolidFlow,
52
+ SolidFlowProvider,
50
53
  Controls,
51
54
  Background,
52
55
  MiniMap,
@@ -54,10 +57,24 @@ import {
54
57
  type EdgeConnection,
55
58
  createEdgeStore,
56
59
  createNodeStore,
60
+ type Viewport,
57
61
  } from "@dschz/solid-flow";
58
62
  import "@dschz/solid-flow/styles"; // Required styles
59
63
 
60
- export default function Flow() {
64
+ import { createStore, produce } from "solid-js/store";
65
+
66
+ export default function Page() {
67
+ return (
68
+ <SolidFlowProvider>
69
+ <Flow />
70
+ </SolidFlowProvider>
71
+ )
72
+ }
73
+
74
+ function Flow() {
75
+ // Can invoke useSolidFlow due to parent Page + SolidFlowProvider wrapper. Contains all helper APIs
76
+ const { .. } = useSolidFlow();
77
+
61
78
  // Use createNodeStore and createEdgeStore for reactive state management
62
79
  const [nodes, setNodes] = createNodeStore([
63
80
  {
@@ -85,6 +102,16 @@ export default function Flow() {
85
102
  { id: "e2-3", source: "2", target: "3" },
86
103
  ]);
87
104
 
105
+ const [viewport, setViewport] = createStore<Viewport>({
106
+ x: 100,
107
+ y: 100,
108
+ zoom: 5,
109
+ });
110
+
111
+ const updateViewport = () => {
112
+ setViewport("x", (prev) => prev + 10);
113
+ };
114
+
88
115
  const onConnect = (connection: EdgeConnection) => {
89
116
  /**
90
117
  * Solid Flow updates the node/edge stores internally. The user-land edge store will have the connection inserted by the time onConnect fires so we can just go ahead and update the state of it
@@ -101,6 +128,9 @@ export default function Flow() {
101
128
  <SolidFlow nodes={nodes} edges={edges} onConnect={onConnect} fitView>
102
129
  <Controls />
103
130
  <MiniMap />
131
+ <Panel position="top-left">
132
+ <button onClick={updateViewport}>Update viewport</button>
133
+ </Panel>
104
134
  <Background variant="dots" />
105
135
  </SolidFlow>
106
136
  );
@@ -196,10 +226,10 @@ import { Handle, type NodeProps } from "@dschz/solid-flow";
196
226
  function CustomNode(props: NodeProps<{ label: string }, "custom">) {
197
227
  return (
198
228
  <div class="custom-node" style={{ padding: "10px", background: "white" }}>
199
- <Handle type="target" position="top />
229
+ <Handle type="target" position="top" />
200
230
  <div>{props.data.label}</div>
201
231
  <Handle type="source" position="bottom" id="output-a" />
202
- <Handle type="source" position="bottom id="output-b" style={{ left: "80%" }} />
232
+ <Handle type="source" position="bottom" id="output-b" style={{ left: "80%" }} />
203
233
  </div>
204
234
  );
205
235
  }
@@ -1,7 +1,7 @@
1
1
  import * as solid_js from 'solid-js';
2
2
  import { JSX, ParentProps, ParentComponent, Accessor } from 'solid-js';
3
3
  import * as _xyflow_system from '@xyflow/system';
4
- import { NodeProps as NodeProps$1, NodeBase, InternalNodeBase, EdgeBase, EdgePosition, BezierPathOptions, StepPathOptions, SmoothStepPathOptions, DefaultEdgeOptionsBase, OnReconnect, HandleType, FinalConnectionState, PanOnScrollMode as PanOnScrollMode$1, Position as Position$1, FitViewOptionsBase, ResizeControlVariant as ResizeControlVariant$1, ConnectionMode as ConnectionMode$1, SelectionMode as SelectionMode$1, ConnectionLineType as ConnectionLineType$2, OnBeforeDeleteBase, Connection, XYPosition, Handle as Handle$1, PanelPosition, Viewport, OnMove, OnMoveStart, OnMoveEnd, HandleProps as HandleProps$1, MarkerProps as MarkerProps$1, ShouldResize, OnResizeStart, OnResize, OnResizeEnd, ControlPosition, Align, NodeOrigin, SnapGrid, CoordinateExtent, ColorMode, ProOptions, IsValidConnection, OnError, OnConnectStart, OnConnectEnd, OnReconnectStart, OnReconnectEnd, AriaLabelConfig, ConnectionState, NodeConnection, ZoomInOut, ViewportHelperFunctionOptions, SetCenterOptions, Rect, FitBoundsOptions, HandleConnection, UpdateNodeInternals } from '@xyflow/system';
4
+ import { NodeProps as NodeProps$1, NodeBase, InternalNodeBase, EdgeBase, EdgePosition, BezierPathOptions, StepPathOptions, SmoothStepPathOptions, DefaultEdgeOptionsBase, OnReconnect, HandleType, FinalConnectionState, PanOnScrollMode as PanOnScrollMode$1, Position as Position$1, FitViewOptionsBase, ResizeControlVariant as ResizeControlVariant$1, ConnectionMode as ConnectionMode$1, SelectionMode as SelectionMode$1, ConnectionLineType as ConnectionLineType$2, Connection, OnBeforeDeleteBase, XYPosition, Handle as Handle$1, PanelPosition, Viewport, OnMove, OnMoveStart, OnMoveEnd, HandleProps as HandleProps$1, MarkerProps as MarkerProps$1, EdgeToolbarBaseProps, ShouldResize, OnResizeStart, OnResize, OnResizeEnd, ControlPosition, Align, NodeOrigin, SnapGrid, CoordinateExtent, ColorMode, ZIndexMode, ProOptions, OnError, OnConnectStart, OnConnectEnd, OnReconnectStart, OnReconnectEnd, AriaLabelConfig, ColorModeClass, ConnectionState, NodeConnection, ZoomInOut, ViewportHelperFunctionOptions, SetCenterOptions, Rect, FitBoundsOptions, HandleConnection, UpdateNodeInternals } from '@xyflow/system';
5
5
  export { Align, AriaLabelConfig, BezierPathOptions, Box, ColorMode, ColorModeClass, Connection, ConnectionLineType, ConnectionMode, ControlLinePosition, ControlPosition, CoordinateExtent, Dimensions, EdgeMarker, EdgeMarkerType, FitBounds, FitBoundsOptions, GetBezierPathParams, GetSmoothStepPathParams, GetStraightPathParams, HandleConnection, IsValidConnection, MarkerType, NodeConnection, NodeOrigin, OnConnect, OnConnectEnd, OnConnectStart, OnConnectStartParams, OnError, OnMove, OnMoveEnd, OnMoveStart, OnReconnect, OnReconnectEnd, OnReconnectStart, OnResize, OnResizeEnd, OnResizeStart, OnSelectionDrag, PanOnScrollMode, PanelPosition, Position, ProOptions, Rect, ResizeControlVariant, ResizeDragEvent, ResizeParams, ResizeParamsWithDirection, SelectionMode, SelectionRect, SetCenter, SetCenterOptions, SetViewport, ShouldResize, SmoothStepPathOptions, SnapGrid, Transform, Viewport, ViewportHelperFunctionOptions, XYPosition, XYZPosition, addEdge, getBezierEdgeCenter, getBezierPath, getConnectedEdges, getEdgeCenter, getIncomers, getNodesBounds, getOutgoers, getSmoothStepPath, getStraightPath, getViewportForBounds } from '@xyflow/system';
6
6
  import { Store, SetStoreFunction } from 'solid-js/store';
7
7
 
@@ -274,6 +274,7 @@ type OnBeforeEdgeConnect<EdgeType extends Edge = Edge> = (connection: EdgeConnec
274
274
  type OnEdgeConnect = (connection: EdgeConnection) => void;
275
275
  type OnBeforeReconnect<EdgeType extends Edge = Edge> = (newEdge: EdgeType, oldEdge: EdgeType) => EdgeType | undefined;
276
276
  type OnBeforeDelete<NodeType extends Node = Node, EdgeType extends Edge = Edge> = OnBeforeDeleteBase<NodeType, EdgeType>;
277
+ type IsValidConnection<EdgeType extends Edge = Edge> = (edge: EdgeType | Connection) => boolean;
277
278
  type OnSelectionChange<NodeType extends Node = Node, EdgeType extends Edge = Edge> = (params: {
278
279
  nodes: NodeType[];
279
280
  edges: EdgeType[];
@@ -298,6 +299,8 @@ declare const NodeRenderer: <NodeType extends Node = Node>(props: NodeRendererPr
298
299
  type PaneProps = PaneEvents & {
299
300
  readonly panOnDrag?: boolean | number[];
300
301
  readonly selectionOnDrag?: boolean;
302
+ readonly paneClickDistance?: number;
303
+ readonly autoPanOnSelection?: boolean;
301
304
  readonly onSelectionStart?: (event: PointerEvent) => void;
302
305
  readonly onSelectionEnd?: (event: PointerEvent) => void;
303
306
  };
@@ -328,8 +331,10 @@ type ZoomProps = {
328
331
  readonly zoomOnDoubleClick: boolean;
329
332
  readonly zoomOnPinch: boolean;
330
333
  readonly panOnScroll: boolean;
334
+ readonly panOnScrollSpeed: number;
331
335
  readonly panOnDrag: boolean | number[];
332
336
  readonly paneClickDistance: number;
337
+ readonly selectionOnDrag?: boolean;
333
338
  };
334
339
  declare const Zoom: (props: ParentProps<ZoomProps>) => solid_js.JSX.Element;
335
340
 
@@ -513,6 +518,19 @@ type ControlsProps = {
513
518
  } & Omit<JSX.HTMLAttributes<HTMLDivElement>, "style">;
514
519
  declare const Controls: (props: ParentProps<ControlsProps>) => JSX.Element;
515
520
 
521
+ type EdgeToolbarProps = EdgeToolbarBaseProps & {
522
+ /** If `true`, clicking the toolbar selects the edge it belongs to. */
523
+ readonly selectEdgeOnClick?: boolean;
524
+ } & Omit<JSX.HTMLAttributes<HTMLDivElement>, "style">;
525
+ /**
526
+ * The `<EdgeToolbar />` component renders a toolbar or tooltip for an edge.
527
+ * It must be used inside a custom edge component. By default it is only
528
+ * visible when the edge is selected; pass `isVisible` to control it manually.
529
+ *
530
+ * The toolbar does not scale with the viewport so that its content is always legible.
531
+ */
532
+ declare const EdgeToolbar: (props: ParentProps<EdgeToolbarProps>) => JSX.Element;
533
+
516
534
  type GetMiniMapNodeAttribute<NodeType extends Node> = (node: NodeType) => string;
517
535
  type MiniMapProps<NodeType extends Node> = Omit<JSX.HTMLAttributes<HTMLDivElement>, "style"> & {
518
536
  /** Background color of minimap */
@@ -819,7 +837,7 @@ type SolidFlowProps<NodeType extends Node = Node, EdgeType extends Edge = Edge>
819
837
  * You can pass `null` to use the CSS variable `--xy-edge-stroke` for the marker color.
820
838
  * @example "#b1b1b7"
821
839
  */
822
- readonly defaultMarkerColor?: string;
840
+ readonly defaultMarkerColor?: string | null;
823
841
  /**
824
842
  * Controls if all nodes should be draggable
825
843
  * @default true
@@ -830,6 +848,11 @@ type SolidFlowProps<NodeType extends Node = Node, EdgeType extends Edge = Edge>
830
848
  * @default true
831
849
  */
832
850
  readonly autoPanOnNodeFocus?: boolean;
851
+ /**
852
+ * When `true`, the viewport will pan when a drag selection approaches the edges of the flow container.
853
+ * @default true
854
+ */
855
+ readonly autoPanOnSelection?: boolean;
833
856
  /**
834
857
  * Controls if all nodes should be connectable to each other
835
858
  * @default true
@@ -959,6 +982,14 @@ type SolidFlowProps<NodeType extends Node = Node, EdgeType extends Edge = Edge>
959
982
  * @default true
960
983
  */
961
984
  readonly elevateNodesOnSelect?: boolean;
985
+ /**
986
+ * Controls how z-indexes are calculated for nodes and edges.
987
+ * 'auto' automatically manages z-indexing for selections and sub flows,
988
+ * 'basic' manages z-indexing for selections only, and
989
+ * 'manual' does not apply any automatic z-indexing.
990
+ * @default "basic"
991
+ */
992
+ readonly zIndexMode?: ZIndexMode;
962
993
  /**
963
994
  * Enabling this option will raise the z-index of edges when they are selected,
964
995
  * or when the connected nodes are selected.
@@ -1013,7 +1044,7 @@ type SolidFlowProps<NodeType extends Node = Node, EdgeType extends Edge = Edge>
1013
1044
  * before doing so.
1014
1045
  */
1015
1046
  readonly proOptions?: ProOptions;
1016
- readonly isValidConnection?: IsValidConnection;
1047
+ readonly isValidConnection?: IsValidConnection<EdgeType>;
1017
1048
  /** This event handler is called when the user begins to pan or zoom the viewport */
1018
1049
  readonly onMoveStart?: OnMoveStart;
1019
1050
  /** This event handler is called when the user pans or zooms the viewport */
@@ -1049,7 +1080,7 @@ type SolidFlowProps<NodeType extends Node = Node, EdgeType extends Edge = Edge>
1049
1080
  /** This event gets fired when a user starts to reconnect an edge */
1050
1081
  readonly onReconnectStart?: OnReconnectStart<EdgeType>;
1051
1082
  /** This event gets fired when a user stops reconnecting an edge */
1052
- readonly onReconnectEnd?: OnReconnectEnd<EdgeType>;
1083
+ readonly onReconnectEnd?: OnReconnectEnd<NodeType, EdgeType>;
1053
1084
  /** This handler gets called when an edge is reconnected. You can use it to modify the edge before the update is applied. */
1054
1085
  readonly onBeforeReconnect?: OnBeforeReconnect<EdgeType>;
1055
1086
  /** A connection is started by clicking on a handle */
@@ -1249,6 +1280,17 @@ type NodesInput<TUserNodeTypes extends NodeTypes> = {
1249
1280
  */
1250
1281
  declare const createNodeStore: <TUserNodeTypes extends NodeTypes = Record<string, never>>(nodes: NodesInput<TUserNodeTypes>[]) => readonly [Store<NodesInput<TUserNodeTypes>[]>, SetStoreFunction<NodesInput<TUserNodeTypes>[]>];
1251
1282
 
1283
+ /**
1284
+ * Hook for receiving the current color mode class ('dark' or 'light').
1285
+ *
1286
+ * When the flow's `colorMode` prop is set to `"system"`, this resolves to the
1287
+ * user's current system preference.
1288
+ *
1289
+ * @public
1290
+ * @returns an accessor for the current color mode class
1291
+ */
1292
+ declare function useColorMode(): () => ColorModeClass;
1293
+
1252
1294
  /**
1253
1295
  * Hook for receiving the current connection.
1254
1296
  *
@@ -1281,6 +1323,26 @@ declare function useViewport(): () => _xyflow_system.Viewport;
1281
1323
 
1282
1324
  declare function useHandleEdgeSelect(): (id: string) => void;
1283
1325
 
1326
+ /**
1327
+ * Hook for seeing if all nodes have been measured.
1328
+ *
1329
+ * Returns `false` until every non-hidden node has been rendered and measured.
1330
+ * Useful for running layouting or fitView logic that depends on node dimensions.
1331
+ *
1332
+ * @public
1333
+ * @returns an accessor that indicates whether the nodes are initialized
1334
+ */
1335
+ declare function useNodesInitialized(): () => boolean;
1336
+ /**
1337
+ * Hook for seeing if the viewport is initialized.
1338
+ *
1339
+ * Returns `true` once the pan/zoom instance has been created for the flow.
1340
+ *
1341
+ * @public
1342
+ * @returns an accessor that indicates whether the viewport is initialized
1343
+ */
1344
+ declare function useViewportInitialized(): () => boolean;
1345
+
1284
1346
  /**
1285
1347
  * Hook to get an internal node by id.
1286
1348
  *
@@ -1579,4 +1641,4 @@ declare function useSolidFlow<NodeType extends Node = Node, EdgeType extends Edg
1579
1641
  */
1580
1642
  declare function useUpdateNodeInternals(): UpdateNodeInternals;
1581
1643
 
1582
- export { Background, type BackgroundProps, type BackgroundVariant, BaseEdge, BezierEdge, BezierEdgeInternal, type BezierEdgeProps, type BuiltInEdge, type BuiltInNode, type BuiltInNodeTypes, type ConnectionData, ConnectionLine, type ConnectionLineComponentProps, ControlButton, Controls, type DefaultEdgeOptions, DefaultNode, type DeleteEvents, type Edge, type EdgeConnection, type EdgeEvents, EdgeLabel, EdgeLabelRenderer, type EdgeProps, EdgeReconnectAnchor, type EdgeReconnectEvents, EdgeRenderer, type EdgeTypes, EdgeWrapper, type FitViewOptions, GroupNode, Handle, InputNode, type InternalNode, type KeyDefinition, type KeyDefinitionObject, type KeyModifier, Marker, MarkerDefinition, MiniMap, type Node, type NodeEvents, type NodeGraph, type NodeProps, NodeRenderer, NodeResizer, NodeSelection, type NodeSelectionEvents, NodeToolbar, type NodeToolbarProps, type NodeTypes, NodeWrapper, type OnBeforeDelete, type OnBeforeEdgeConnect, type OnBeforeReconnect, type OnDelete, type OnEdgeConnect, type OnEdgeCreate, type OnSelectionChange, OutputNode, Pane, type PaneEvents, Panel, ResizeControl, Selection, type ShortcutModifier, type ShortcutModifierDefinition, SmoothStepEdge, SmoothStepEdgeInternal, type SmoothStepEdgeProps, SolidFlow, SolidFlowProvider, StepEdge, StepEdgeInternal, type StepEdgeProps, StraightEdge, StraightEdgeInternal, type StraightEdgeProps, ViewportPortal, Zoom, createEdgeStore, createNodeStore, useConnection, useEdges, useHandleEdgeSelect, useInternalNode, useNodeConnections, useNodes, useNodesData, useSolidFlow, useUpdateNodeInternals, useViewport };
1644
+ export { Background, type BackgroundProps, type BackgroundVariant, BaseEdge, BezierEdge, BezierEdgeInternal, type BezierEdgeProps, type BuiltInEdge, type BuiltInNode, type BuiltInNodeTypes, type ConnectionData, ConnectionLine, type ConnectionLineComponentProps, ControlButton, Controls, type DefaultEdgeOptions, DefaultNode, type DeleteEvents, type Edge, type EdgeConnection, type EdgeEvents, EdgeLabel, EdgeLabelRenderer, type EdgeProps, EdgeReconnectAnchor, type EdgeReconnectEvents, EdgeRenderer, EdgeToolbar, type EdgeToolbarProps, type EdgeTypes, EdgeWrapper, type FitViewOptions, GroupNode, Handle, InputNode, type InternalNode, type KeyDefinition, type KeyDefinitionObject, type KeyModifier, Marker, MarkerDefinition, MiniMap, type Node, type NodeEvents, type NodeGraph, type NodeProps, NodeRenderer, NodeResizer, NodeSelection, type NodeSelectionEvents, NodeToolbar, type NodeToolbarProps, type NodeTypes, NodeWrapper, type OnBeforeDelete, type OnBeforeEdgeConnect, type OnBeforeReconnect, type OnDelete, type OnEdgeConnect, type OnEdgeCreate, type OnSelectionChange, OutputNode, Pane, type PaneEvents, Panel, ResizeControl, Selection, type ShortcutModifier, type ShortcutModifierDefinition, SmoothStepEdge, SmoothStepEdgeInternal, type SmoothStepEdgeProps, SolidFlow, SolidFlowProvider, StepEdge, StepEdgeInternal, type StepEdgeProps, StraightEdge, StraightEdgeInternal, type StraightEdgeProps, ViewportPortal, Zoom, createEdgeStore, createNodeStore, useColorMode, useConnection, useEdges, useHandleEdgeSelect, useInternalNode, useNodeConnections, useNodes, useNodesData, useNodesInitialized, useSolidFlow, useUpdateNodeInternals, useViewport, useViewportInitialized };